summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-09-10 18:00:00 +0200
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2000-09-10 18:00:00 +0200
commit76c331181a23f97d5e3f2b55c4741ef4e521242d (patch)
tree2653e97d41826894c9950c8a0ee798667aca9c9c /config.c
parent48fea259ae5ed3ac19bcc4152341252b9df39128 (diff)
downloadvdr-patch-lnbsharing-76c331181a23f97d5e3f2b55c4741ef4e521242d.tar.gz
vdr-patch-lnbsharing-76c331181a23f97d5e3f2b55c4741ef4e521242d.tar.bz2
Version 0.63vdr-0.63
- The new "Setup" menu allows the user to configure several parameters to his/her personal taste (see MANUAL for details). - Workaround for a driver timing problem in cDvbApi::Cmd(), which sometimes caused the OSD to no longer be displayed (thanks to Niels de Carpentier). - Added the '-m486' option to the compiler call. - If a channel name contains a colon (':') it is now replaced with a '|' in channels.conf. - Not everybody appears to like the "page scrolling" mechanism introduced by Heino Goldenstein in version 0.61, so this is now configurable via the "Setup" menu. - The new 'dvbrc2vdr' tool (thanks to Plamen Ganev!) can be used to convert 'dvbrc' channel files into 'vdr' format. - Channels can now be "grouped" (thanks to Plamen Ganev!). See MANUAL for details. There is currently no mechanism to define and maintain "Channel groups" via the menu, so you'll have to insert "Channel group" control lines into your 'channels.conf' file manually (for example with a text editor). - Started a new file named FORMATS with a description of the various file formats used by VDR. - The "Primary DVB interface" can now be chosen via the "Setup" menu. - Display of the "current/next" information when switching channels can now be disabled via the "Setup" menu. - The "current/next" display now only shows those lines that actually contain information. - When directly selecting a channel by entering the channel number, the digits entered so far together with the name of that channel are displayed on the OSD (suggested by Martin Hammerschmid).
Diffstat (limited to 'config.c')
-rw-r--r--config.c232
1 files changed, 199 insertions, 33 deletions
diff --git a/config.c b/config.c
index af5be87..0a965ee 100644
--- a/config.c
+++ b/config.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: config.c 1.18 2000/09/03 09:20:22 kls Exp $
+ * $Id: config.c 1.22 2000/09/10 15:07:15 kls Exp $
*/
#include "config.h"
@@ -196,11 +196,22 @@ cChannel::cChannel(const cChannel *Channel)
apid = Channel ? Channel->apid : 256;
ca = Channel ? Channel->ca : 0;
pnr = Channel ? Channel->pnr : 0;
+ groupSep = Channel ? Channel->groupSep : false;
}
const char *cChannel::ToText(cChannel *Channel)
{
- asprintf(&buffer, "%s:%d:%c:%d:%d:%d:%d:%d:%d\n", Channel->name, Channel->frequency, Channel->polarization, Channel->diseqc, Channel->srate, Channel->vpid, Channel->apid, Channel->ca, Channel->pnr);
+ char buf[MaxChannelName * 2];
+ char *s = Channel->name;
+ if (strchr(s, ':')) {
+ s = strcpy(buf, s);
+ strreplace(s, ':', '|');
+ }
+ delete buffer;
+ if (Channel->groupSep)
+ asprintf(&buffer, ":%s\n", s);
+ else
+ asprintf(&buffer, "%s:%d:%c:%d:%d:%d:%d:%d:%d\n", s, Channel->frequency, Channel->polarization, Channel->diseqc, Channel->srate, Channel->vpid, Channel->apid, Channel->ca, Channel->pnr);
return buffer;
}
@@ -212,13 +223,27 @@ const char *cChannel::ToText(void)
bool cChannel::Parse(const char *s)
{
char *buffer = NULL;
- if (9 == sscanf(s, "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d", &buffer, &frequency, &polarization, &diseqc, &srate, &vpid, &apid, &ca, &pnr)) {
- strncpy(name, buffer, MaxChannelName - 1);
- name[strlen(buffer)] = 0;
- delete buffer;
- return true;
+ if (*s == ':') {
+ if (*++s) {
+ strn0cpy(name, s, MaxChannelName);
+ name[strlen(name) - 1] = 0; // strip the '\n'
+ groupSep = true;
+ }
+ else
+ return false;
}
- return false;
+ else {
+ groupSep = false;
+ int fields = sscanf(s, "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d", &buffer, &frequency, &polarization, &diseqc, &srate, &vpid, &apid, &ca, &pnr);
+ if (fields == 9) {
+ strn0cpy(name, buffer, MaxChannelName);
+ delete buffer;
+ }
+ else
+ return false;
+ }
+ strreplace(name, '|', ':');
+ return true;
}
bool cChannel::Save(FILE *f)
@@ -230,9 +255,9 @@ bool cChannel::Switch(cDvbApi *DvbApi)
{
if (!DvbApi)
DvbApi = cDvbApi::PrimaryDvbApi;
- if (!DvbApi->Recording()) {
- isyslog(LOG_INFO, "switching to channel %d", Index() + 1);
- CurrentChannel = Index();
+ if (!DvbApi->Recording() && !groupSep) {
+ isyslog(LOG_INFO, "switching to channel %d", number);
+ CurrentChannel = number;
for (int i = 3; i--;) {
if (DvbApi->SetChannel(frequency, polarization, diseqc, srate, vpid, apid, ca, pnr)) {
EIT.SetProgramNumber(pnr);
@@ -242,22 +267,10 @@ bool cChannel::Switch(cDvbApi *DvbApi)
}
return false;
}
- Interface.Info("Channel locked (recording)!");
+ Interface.Info(DvbApi->Recording() ? "Channel locked (recording)!" : name);
return false;
}
-bool cChannel::SwitchTo(int i, cDvbApi *DvbApi)
-{
- cChannel *channel = Channels.Get(i);
- return channel && channel->Switch(DvbApi);
-}
-
-const char *cChannel::GetChannelName(int i)
-{
- cChannel *channel = Channels.Get(i);
- return channel ? channel->name : NULL;
-}
-
// -- cTimer -----------------------------------------------------------------
char *cTimer::buffer = NULL;
@@ -267,7 +280,8 @@ cTimer::cTimer(bool Instant)
startTime = stopTime = 0;
recording = false;
active = Instant;
- channel = CurrentChannel + 1;
+ cChannel *ch = Channels.GetByNumber(CurrentChannel);
+ channel = ch ? ch->number : 0;
time_t t = time(NULL);
struct tm *now = localtime(&t);
day = now->tm_mday;
@@ -280,8 +294,8 @@ cTimer::cTimer(bool Instant)
lifetime = 99;
*file = 0;
summary = NULL;
- if (Instant)
- snprintf(file, sizeof(file), "@%s", cChannel::GetChannelName(CurrentChannel));
+ if (Instant && ch)
+ snprintf(file, sizeof(file), "@%s", ch->name);
}
cTimer::~cTimer()
@@ -299,6 +313,7 @@ cTimer& cTimer::operator= (const cTimer &Timer)
const char *cTimer::ToText(cTimer *Timer)
{
+ delete buffer;
asprintf(&buffer, "%d:%d:%s:%04d:%04d:%d:%d:%s:%s\n", Timer->active, Timer->channel, PrintDay(Timer->day), Timer->start, Timer->stop, Timer->priority, Timer->lifetime, Timer->file, Timer->summary ? Timer->summary : "");
return buffer;
}
@@ -368,11 +383,7 @@ bool cTimer::Parse(const char *s)
if (8 <= sscanf(s, "%d:%d:%a[^:]:%d:%d:%d:%d:%a[^:\n]:%a[^\n]", &active, &channel, &buffer1, &start, &stop, &priority, &lifetime, &buffer2, &summary)) {
//TODO add more plausibility checks
day = ParseDay(buffer1);
- int l = strlen(buffer2);
- if (l >= MaxFileName)
- l = MaxFileName - 1;
- strncpy(file, buffer2, l);
- file[l] = 0;
+ strn0cpy(file, buffer2, MaxFileName);
delete buffer1;
delete buffer2;
return day != 0;
@@ -470,10 +481,87 @@ cKeys Keys;
// -- cChannels --------------------------------------------------------------
-int CurrentChannel = 0;
+int CurrentChannel = 1;
+int CurrentGroup = -1;
cChannels Channels;
+bool cChannels::Load(const char *FileName)
+{
+ if (cConfig<cChannel>::Load(FileName)) {
+ ReNumber();
+ return true;
+ }
+ return false;
+}
+
+int cChannels::GetNextGroup(int Idx)
+{
+ cChannel *channel = Get(++Idx);
+ while (channel && !channel->groupSep)
+ channel = Get(++Idx);
+ return channel ? Idx : -1;
+}
+
+int cChannels::GetPrevGroup(int Idx)
+{
+ cChannel *channel = Get(--Idx);
+ while (channel && !channel->groupSep)
+ channel = Get(--Idx);
+ return channel ? Idx : -1;
+}
+
+int cChannels::GetNextNormal(int Idx)
+{
+ cChannel *channel = Get(++Idx);
+ while (channel && channel->groupSep)
+ channel = Get(++Idx);
+ return channel ? Idx : -1;
+}
+
+void cChannels::ReNumber( void )
+{
+ int Number = 0;
+ cChannel *ch = (cChannel *)First();
+ while (ch) {
+ if (!ch->groupSep)
+ ch->number = ++Number;
+ ch = (cChannel *)ch->Next();
+ }
+ maxNumber = Number;
+}
+
+cChannel *cChannels::GetByNumber(int Number)
+{
+ cChannel *channel = (cChannel *)First();
+ while (channel) {
+ if (channel->number == Number)
+ return channel;
+ channel = (cChannel *)channel->Next();
+ }
+ return NULL;
+}
+
+bool cChannels::SwitchTo(int Number, cDvbApi *DvbApi)
+{
+ cChannel *channel = GetByNumber(Number);
+ return channel && channel->Switch(DvbApi);
+}
+
+const char *cChannels::GetChannelNameByNumber(int Number)
+{
+ cChannel *channel = GetByNumber(Number);
+ return channel ? channel->name : NULL;
+}
+
+eKeys cChannels::ShowChannel(int Number, bool Switched, bool Group)
+{
+ cChannel *channel = Group ? Get(Number) : GetByNumber(Number);
+ if (channel)
+ return Interface.DisplayChannel(channel->number, channel->name, !Switched || Setup.ShowInfoOnChSwitch);
+ return kNone;
+}
+
// -- cTimers ----------------------------------------------------------------
cTimers Timers;
@@ -489,3 +577,81 @@ cTimer *cTimers::GetTimer(cTimer *Timer)
return NULL;
}
+// -- cSetup -----------------------------------------------------------------
+
+cSetup Setup;
+
+char *cSetup::fileName = NULL;
+
+cSetup::cSetup(void)
+{
+ PrimaryDVB = 1;
+ ShowInfoOnChSwitch = 1;
+ MenuScrollPage = 1;
+}
+
+bool cSetup::Parse(char *s)
+{
+ const char *Delimiters = " \t\n=";
+ char *Name = strtok(s, Delimiters);
+ char *Value = strtok(NULL, Delimiters);
+ if (Name && Value) {
+ if (!strcasecmp(Name, "PrimaryDVB")) PrimaryDVB = atoi(Value);
+ else if (!strcasecmp(Name, "ShowInfoOnChSwitch")) ShowInfoOnChSwitch = atoi(Value);
+ else if (!strcasecmp(Name, "MenuScrollPage")) MenuScrollPage = atoi(Value);
+ else
+ return false;
+ return true;
+ }
+ return false;
+}
+
+bool cSetup::Load(const char *FileName)
+{
+ isyslog(LOG_INFO, "loading %s", FileName);
+ delete fileName;
+ fileName = strdup(FileName);
+ FILE *f = fopen(fileName, "r");
+ if (f) {
+ int line = 0;
+ char buffer[MaxBuffer];
+ bool result = true;
+ while (fgets(buffer, sizeof(buffer), f) > 0) {
+ line++;
+ if (*buffer != '#' && !Parse(buffer)) {
+ esyslog(LOG_ERR, "error in %s, line %d\n", fileName, line);
+ result = false;
+ break;
+ }
+ }
+ fclose(f);
+ return result;
+ }
+ else
+ LOG_ERROR_STR(FileName);
+ return false;
+}
+
+bool cSetup::Save(const char *FileName)
+{
+ if (!FileName)
+ FileName = fileName;
+ if (FileName) {
+ FILE *f = fopen(FileName, "w");
+ if (f) {
+ fprintf(f, "# VDR Setup\n");
+ fprintf(f, "PrimaryDVB = %d\n", PrimaryDVB);
+ fprintf(f, "ShowInfoOnChSwitch = %d\n", ShowInfoOnChSwitch);
+ fprintf(f, "MenuScrollPage = %d\n", MenuScrollPage);
+ fclose(f);
+ isyslog(LOG_INFO, "saved setup to %s", FileName);
+ return true;
+ }
+ else
+ LOG_ERROR_STR(FileName);
+ }
+ else
+ esyslog(LOG_ERR, "attempt to save setup without file name");
+ return false;
+}
+