summaryrefslogtreecommitdiff
path: root/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c172
1 files changed, 66 insertions, 106 deletions
diff --git a/menu.c b/menu.c
index 286820ef..18cf0500 100644
--- a/menu.c
+++ b/menu.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: menu.c 1.218 2002/10/19 15:33:37 kls Exp $
+ * $Id: menu.c 1.219 2002/10/20 12:03:13 kls Exp $
*/
#include "menu.h"
@@ -24,6 +24,7 @@
#include "remote.h"
#include "sources.h"
#include "status.h"
+#include "timers.h"
#include "videodir.h"
#define MENUTIMEOUT 120 // seconds
@@ -617,17 +618,14 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key)
class cMenuChannelItem : public cOsdItem {
private:
- int index;
cChannel *channel;
public:
- cMenuChannelItem(int Index, cChannel *Channel);
+ cMenuChannelItem(cChannel *Channel);
virtual void Set(void);
- void SetIndex(int Index);
};
-cMenuChannelItem::cMenuChannelItem(int Index, cChannel *Channel)
+cMenuChannelItem::cMenuChannelItem(cChannel *Channel)
{
- index = Index;
channel = Channel;
if (channel->GroupSep())
SetColor(clrCyan, clrBackground);
@@ -644,15 +642,11 @@ void cMenuChannelItem::Set(void)
SetText(buffer, false);
}
-void cMenuChannelItem::SetIndex(int Index)
-{
- index = Index;
- Set();
-}
-
// --- cMenuChannels ---------------------------------------------------------
class cMenuChannels : public cOsdMenu {
+private:
+ void Propagate(void);
protected:
eOSState Switch(void);
eOSState Edit(void);
@@ -673,12 +667,22 @@ cMenuChannels::cMenuChannels(void)
int curr = ((channel = Channels.GetByNumber(cDevice::CurrentChannel())) != NULL) ? channel->Index() : -1;
while ((channel = Channels.Get(i)) != NULL) {
- Add(new cMenuChannelItem(i, channel), i == curr);
+ Add(new cMenuChannelItem(channel), i == curr);
i++;
}
SetHelp(tr("Edit"), tr("New"), tr("Delete"), tr("Mark"));
}
+void cMenuChannels::Propagate(void)
+{
+ Channels.ReNumber();
+ Channels.Save();
+ for (cMenuChannelItem *ci = (cMenuChannelItem *)First(); ci; ci = (cMenuChannelItem *)ci->Next())
+ ci->Set();
+ Timers.Save(); // channel numbering has changed!
+ Display();
+}
+
eOSState cMenuChannels::Switch(void)
{
cChannel *ch = Channels.Get(Current());
@@ -702,7 +706,7 @@ eOSState cMenuChannels::New(void)
cChannel *channel = new cChannel(Channels.Get(Current()));
Channels.Add(channel);
Channels.ReNumber();
- Add(new cMenuChannelItem(channel->Index()/*XXX*/, channel), true);
+ Add(new cMenuChannelItem(channel), true);
Channels.Save();
isyslog("channel %d added", channel->Number());
return AddSubMenu(new cMenuEditChannel(Current()));
@@ -715,36 +719,17 @@ eOSState cMenuChannels::Del(void)
cChannel *channel = Channels.Get(Index);
int DeletedChannel = channel->Number();
// Check if there is a timer using this channel:
- for (cTimer *ti = Timers.First(); ti; ti = (cTimer *)ti->Next()) {
- if (ti->channel == DeletedChannel) {
+ for (cTimer *ti = Timers.First(); ti; ti = Timers.Next(ti)) {
+ if (ti->Channel() == channel) {
Interface->Error(tr("Channel is being used by a timer!"));
return osContinue;
}
}
if (Interface->Confirm(tr("Delete channel?"))) {
- // Move and renumber the channels:
Channels.Del(channel);
- Channels.ReNumber();
cOsdMenu::Del(Index);
- int i = 0;
- for (cMenuChannelItem *ci = (cMenuChannelItem *)First(); ci; ci = (cMenuChannelItem *)ci->Next())
- ci->SetIndex(i++);
- Channels.Save();
+ Propagate();
isyslog("channel %d deleted", DeletedChannel);
- // Fix the timers:
- bool TimersModified = false;
- for (cTimer *ti = Timers.First(); ti; ti = (cTimer *)ti->Next()) {
- int OldChannel = ti->channel;
- if (ti->channel > DeletedChannel)
- ti->channel--;
- if (ti->channel != OldChannel) {
- TimersModified = true;
- isyslog("timer %d: channel changed from %d to %d", ti->Index() + 1, OldChannel, ti->channel);
- }
- }
- if (TimersModified)
- Timers.Save();
- Display();
}
}
return osContinue;
@@ -754,35 +739,10 @@ void cMenuChannels::Move(int From, int To)
{
int FromNumber = Channels.Get(From)->Number();
int ToNumber = Channels.Get(To)->Number();
- // Move and renumber the channels:
Channels.Move(From, To);
- Channels.ReNumber();
cOsdMenu::Move(From, To);
- int i = 0;
- for (cMenuChannelItem *ci = (cMenuChannelItem *)First(); ci; ci = (cMenuChannelItem *)ci->Next())
- ci->SetIndex(i++);
- Channels.Save();
+ Propagate();
isyslog("channel %d moved to %d", FromNumber, ToNumber);
- // Fix the timers:
- bool TimersModified = false;
- From++; // user visible channel numbers start with '1'
- To++;
- for (cTimer *ti = Timers.First(); ti; ti = (cTimer *)ti->Next()) {
- int OldChannel = ti->channel;
- if (ti->channel == FromNumber)
- ti->channel = ToNumber;
- else if (ti->channel > FromNumber && ti->channel <= ToNumber)
- ti->channel--;
- else if (ti->channel < FromNumber && ti->channel >= ToNumber)
- ti->channel++;
- if (ti->channel != OldChannel) {
- TimersModified = true;
- isyslog("timer %d: channel changed from %d to %d", ti->Index() + 1, OldChannel, ti->channel);
- }
- }
- if (TimersModified)
- Timers.Save();
- Display();
}
eOSState cMenuChannels::ProcessKey(eKeys Key)
@@ -835,6 +795,7 @@ class cMenuEditTimer : public cOsdMenu {
private:
cTimer *timer;
cTimer data;
+ int channel;
cMenuEditDateItem *firstday;
void SetFirstDayItem(void);
public:
@@ -851,12 +812,12 @@ cMenuEditTimer::cMenuEditTimer(int Index, bool New)
data = *timer;
if (New)
data.active = 1;
+ channel = data.Channel()->Number();
Add(new cMenuEditBoolItem(tr("Active"), &data.active));
- Add(new cMenuEditChanItem(tr("Channel"), &data.channel));
+ Add(new cMenuEditChanItem(tr("Channel"), &channel));
Add(new cMenuEditDayItem( tr("Day"), &data.day));
Add(new cMenuEditTimeItem(tr("Start"), &data.start));
Add(new cMenuEditTimeItem(tr("Stop"), &data.stop));
-//TODO VPS???
Add(new cMenuEditIntItem( tr("Priority"), &data.priority, 0, MAXPRIORITY));
Add(new cMenuEditIntItem( tr("Lifetime"), &data.lifetime, 0, MAXLIFETIME));
Add(new cMenuEditStrItem( tr("File"), data.file, sizeof(data.file), tr(FileNameChars)));
@@ -884,15 +845,24 @@ eOSState cMenuEditTimer::ProcessKey(eKeys Key)
if (state == osUnknown) {
switch (Key) {
- case kOk: if (!*data.file)
- strcpy(data.file, Channels.GetChannelNameByNumber(data.channel));
- if (timer && memcmp(timer, &data, sizeof(data)) != 0) {
- *timer = data;
- if (timer->active)
- timer->active = 1; // allows external programs to mark active timers with values > 1 and recognize if the user has modified them
- Timers.Save();
- isyslog("timer %d modified (%s)", timer->Index() + 1, timer->active ? "active" : "inactive");
- }
+ case kOk: {
+ cChannel *ch = Channels.GetByNumber(channel);
+ if (ch)
+ data.channel = ch;
+ else {
+ Interface->Error(tr("*** Invalid Channel ***"));
+ break;
+ }
+ if (!*data.file)
+ strcpy(data.file, data.Channel()->Name());
+ if (timer && memcmp(timer, &data, sizeof(data)) != 0) {
+ *timer = data;
+ if (timer->active)
+ timer->active = 1; // allows external programs to mark active timers with values > 1 and recognize if the user has modified them
+ Timers.Save();
+ isyslog("timer %d modified (%s)", timer->Index() + 1, timer->active ? "active" : "inactive");
+ }
+ }
return osBack;
case kRed:
case kGreen:
@@ -933,14 +903,14 @@ void cMenuTimerItem::Set(void)
{
char *buffer = NULL;
asprintf(&buffer, "%c\t%d\t%s\t%02d:%02d\t%02d:%02d\t%s",
- !timer->active ? ' ' : timer->firstday ? '!' : timer->recording ? '#' : '>',
- timer->channel,
- timer->PrintDay(timer->day),
- timer->start / 100,
- timer->start % 100,
- timer->stop / 100,
- timer->stop % 100,
- timer->file);
+ !timer->Active() ? ' ' : timer->FirstDay() ? '!' : timer->Recording() ? '#' : '>',
+ timer->Channel()->Number(),
+ timer->PrintDay(timer->Day()),
+ timer->Start() / 100,
+ timer->Start() % 100,
+ timer->Stop() / 100,
+ timer->Stop() % 100,
+ timer->File());
SetText(buffer, false);
}
@@ -985,23 +955,13 @@ eOSState cMenuTimers::OnOff(void)
{
cTimer *timer = CurrentTimer();
if (timer) {
- if (timer->IsSingleEvent())
- timer->active = !timer->active;
- else if (timer->firstday) {
- timer->firstday = 0;
- timer->active = false;
- }
- else if (timer->active)
- timer->Skip();
- else
- timer->active = true;
- timer->Matches(); // refresh start and end time
+ timer->OnOff();
RefreshCurrent();
DisplayCurrent(true);
- if (timer->firstday)
+ if (timer->FirstDay())
isyslog("timer %d first day set to %s", timer->Index() + 1, timer->PrintFirstDay());
else
- isyslog("timer %d %sactivated", timer->Index() + 1, timer->active ? "" : "de");
+ isyslog("timer %d %sactivated", timer->Index() + 1, timer->Active() ? "" : "de");
Timers.Save();
}
return osContinue;
@@ -1032,7 +992,7 @@ eOSState cMenuTimers::Del(void)
// Check if this timer is active:
cTimer *ti = CurrentTimer();
if (ti) {
- if (!ti->recording) {
+ if (!ti->Recording()) {
if (Interface->Confirm(tr("Delete timer?"))) {
int Index = ti->Index();
Timers.Del(ti);
@@ -1062,8 +1022,8 @@ eOSState cMenuTimers::Summary(void)
if (HasSubMenu() || Count() == 0)
return osContinue;
cTimer *ti = CurrentTimer();
- if (ti && ti->summary && *ti->summary)
- return AddSubMenu(new cMenuText(tr("Summary"), ti->summary));
+ if (ti && !isempty(ti->Summary()))
+ return AddSubMenu(new cMenuText(tr("Summary"), ti->Summary()));
return Edit(); // convenience for people not using the Summary feature ;-)
}
@@ -2675,7 +2635,7 @@ cRecordControl::cRecordControl(cDevice *Device, cTimer *Timer)
timer = new cTimer(true);
Timers.Add(timer);
Timers.Save();
- asprintf(&instantId, cDevice::NumDevices() > 1 ? "%s - %d" : "%s", Channels.GetChannelNameByNumber(timer->channel), device->CardIndex() + 1);
+ asprintf(&instantId, cDevice::NumDevices() > 1 ? "%s - %d" : "%s", timer->Channel()->Name(), device->CardIndex() + 1);
}
timer->SetPending(true);
timer->SetRecording(true);
@@ -2692,8 +2652,8 @@ cRecordControl::cRecordControl(cDevice *Device, cTimer *Timer)
cRecording Recording(timer, Title, Subtitle, Summary);
fileName = strdup(Recording.FileName());
cRecordingUserCommand::InvokeCommand(RUC_BEFORERECORDING, fileName);
- cChannel *ch = Channels.GetByNumber(timer->channel);
- recorder = new cRecorder(fileName, ch->Ca(), timer->priority, ch->Vpid(), ch->Apid1(), ch->Apid2(), ch->Dpid1(), ch->Dpid2());
+ const cChannel *ch = timer->Channel();
+ recorder = new cRecorder(fileName, ch->Ca(), timer->Priority(), ch->Vpid(), ch->Apid1(), ch->Apid2(), ch->Dpid1(), ch->Dpid2());
if (device->AttachReceiver(recorder)) {
Recording.WriteSummary();
cStatus::MsgRecording(device, Recording.Name());
@@ -2713,8 +2673,8 @@ cRecordControl::~cRecordControl()
bool cRecordControl::GetEventInfo(void)
{
- cChannel *channel = Channels.GetByNumber(timer->channel);
- time_t Time = timer->active == taActInst ? timer->StartTime() + INSTANT_REC_EPG_LOOKAHEAD : timer->StartTime() + (timer->StopTime() - timer->StartTime()) / 2;
+ const cChannel *channel = timer->Channel();
+ time_t Time = timer->Active() == taActInst ? timer->StartTime() + INSTANT_REC_EPG_LOOKAHEAD : timer->StartTime() + (timer->StopTime() - timer->StartTime()) / 2;
for (int seconds = 0; seconds <= MAXWAIT4EPGINFO; seconds++) {
{
cMutexLock MutexLock;
@@ -2759,7 +2719,7 @@ bool cRecordControl::Process(time_t t)
{
if (!recorder || !timer || !timer->Matches(t))
return false;
- AssertFreeDiskSpace(timer->priority);
+ AssertFreeDiskSpace(timer->Priority());
return true;
}
@@ -2769,12 +2729,12 @@ cRecordControl *cRecordControls::RecordControls[MAXRECORDCONTROLS] = { NULL };
bool cRecordControls::Start(cTimer *Timer)
{
- int ch = Timer ? Timer->channel : cDevice::CurrentChannel();
+ int ch = Timer ? Timer->Channel()->Number() : cDevice::CurrentChannel();
cChannel *channel = Channels.GetByNumber(ch);
if (channel) {
bool NeedsDetachReceivers = false;
- cDevice *device = cDevice::GetDevice(channel, Timer ? Timer->priority : Setup.DefaultPriority, &NeedsDetachReceivers);
+ cDevice *device = cDevice::GetDevice(channel, Timer ? Timer->Priority() : Setup.DefaultPriority, &NeedsDetachReceivers);
if (device) {
if (NeedsDetachReceivers)
Stop(device);
@@ -2789,7 +2749,7 @@ bool cRecordControls::Start(cTimer *Timer)
}
}
}
- else if (!Timer || (Timer->priority >= Setup.PrimaryLimit && !Timer->pending))
+ else if (!Timer || (Timer->Priority() >= Setup.PrimaryLimit && !Timer->Pending()))
isyslog("no free DVB device to record channel %d!", ch);
}
else