Automatically deleting duplicate channels when reading channels.conf

This commit is contained in:
Klaus Schmidinger 2005-05-06 13:49:01 +02:00
parent 6db0e99996
commit b3c1f1bb73
4 changed files with 32 additions and 11 deletions

View File

@ -3491,3 +3491,6 @@ Video Disk Recorder Revision History
Reinhard Nissl). Reinhard Nissl).
- Fixed a bug in libsi's SubtitlingDescriptor::getLength() (thanks to Marco - Fixed a bug in libsi's SubtitlingDescriptor::getLength() (thanks to Marco
Schlüßler). Schlüßler).
- When reading the channels.conf file, duplicate channels (i.e. ones that have
the same channel ID) are now automatically deleted and only the first one is
actually stored.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.c 1.36 2005/03/19 15:56:38 kls Exp $ * $Id: channels.c 1.37 2005/05/06 13:46:57 kls Exp $
*/ */
#include "channels.h" #include "channels.h"
@ -648,7 +648,7 @@ cString cChannel::ToText(void) const
return ToText(this); return ToText(this);
} }
bool cChannel::Parse(const char *s, bool AllowNonUniqueID) bool cChannel::Parse(const char *s)
{ {
bool ok = true; bool ok = true;
if (*s == ':') { if (*s == ':') {
@ -791,10 +791,6 @@ bool cChannel::Parse(const char *s, bool AllowNonUniqueID)
esyslog("ERROR: channel data results in invalid ID!"); esyslog("ERROR: channel data results in invalid ID!");
return false; return false;
} }
if (!AllowNonUniqueID && Channels.GetByChannelID(GetChannelID())) {
esyslog("ERROR: channel data not unique!");
return false;
}
} }
else else
return false; return false;
@ -817,9 +813,30 @@ cChannels::cChannels(void)
modified = CHANNELSMOD_NONE; modified = CHANNELSMOD_NONE;
} }
void cChannels::DeleteDuplicateChannels(void)
{
for (cChannel *channel = First(); channel; channel = Next(channel)) {
if (!channel->GroupSep()) {
tChannelID ChannelID = channel->GetChannelID();
cChannel *other = Next(channel);
while (other) {
cChannel *d = NULL;
if (!other->GroupSep() && other->GetChannelID() == ChannelID)
d = other;
other = Next(other);
if (d) {
dsyslog("deleting duplicate channel %s", *d->ToText());
Del(d);
}
}
}
}
}
bool cChannels::Load(const char *FileName, bool AllowComments, bool MustExist) bool cChannels::Load(const char *FileName, bool AllowComments, bool MustExist)
{ {
if (cConfig<cChannel>::Load(FileName, AllowComments, MustExist)) { if (cConfig<cChannel>::Load(FileName, AllowComments, MustExist)) {
DeleteDuplicateChannels();
ReNumber(); ReNumber();
return true; return true;
} }

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: channels.h 1.26 2005/02/20 14:05:24 kls Exp $ * $Id: channels.h 1.27 2005/05/06 13:47:06 kls Exp $
*/ */
#ifndef __CHANNELS_H #ifndef __CHANNELS_H
@ -135,7 +135,7 @@ public:
~cChannel(); ~cChannel();
cChannel& operator= (const cChannel &Channel); cChannel& operator= (const cChannel &Channel);
cString ToText(void) const; cString ToText(void) const;
bool Parse(const char *s, bool AllowNonUniqueID = false); bool Parse(const char *s);
bool Save(FILE *f); bool Save(FILE *f);
const char *Name(void) const { return name; } const char *Name(void) const { return name; }
const char *ShortName(bool OrName = false) const { return (OrName && isempty(shortName)) ? name : shortName; } const char *ShortName(bool OrName = false) const { return (OrName && isempty(shortName)) ? name : shortName; }
@ -198,6 +198,7 @@ private:
int maxNumber; int maxNumber;
int modified; int modified;
int beingEdited; int beingEdited;
void DeleteDuplicateChannels(void);
public: public:
cChannels(void); cChannels(void);
bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false); bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false);

View File

@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured * and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection. * graphical interface that sits on top of an SVDRP connection.
* *
* $Id: svdrp.c 1.69 2005/03/20 15:04:00 kls Exp $ * $Id: svdrp.c 1.70 2005/05/06 13:47:39 kls Exp $
*/ */
#include "svdrp.h" #include "svdrp.h"
@ -875,7 +875,7 @@ void cSVDRP::CmdMODC(const char *Option)
cChannel *channel = Channels.GetByNumber(n); cChannel *channel = Channels.GetByNumber(n);
if (channel) { if (channel) {
cChannel ch; cChannel ch;
if (ch.Parse(tail, true)) { if (ch.Parse(tail)) {
if (Channels.HasUniqueChannelID(&ch, channel)) { if (Channels.HasUniqueChannelID(&ch, channel)) {
*channel = ch; *channel = ch;
Channels.ReNumber(); Channels.ReNumber();
@ -948,7 +948,7 @@ void cSVDRP::CmdNEWC(const char *Option)
{ {
if (*Option) { if (*Option) {
cChannel ch; cChannel ch;
if (ch.Parse(Option, true)) { if (ch.Parse(Option)) {
if (Channels.HasUniqueChannelID(&ch)) { if (Channels.HasUniqueChannelID(&ch)) {
cChannel *channel = new cChannel; cChannel *channel = new cChannel;
*channel = ch; *channel = ch;