diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2002-11-10 15:50:21 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2002-11-10 15:50:21 +0100 |
commit | 9fee2b67abb2594c5db2ca9f66525cb09e7b5cc7 (patch) | |
tree | 9d9326af17fcee00a08e55f52d268fd4e5943129 /menu.c | |
parent | c67fe26e66a93b450ed46ca83b5502c47fe28eb3 (diff) | |
download | vdr-9fee2b67abb2594c5db2ca9f66525cb09e7b5cc7.tar.gz vdr-9fee2b67abb2594c5db2ca9f66525cb09e7b5cc7.tar.bz2 |
First step towards a 'unique channel ID'
Diffstat (limited to 'menu.c')
-rw-r--r-- | menu.c | 93 |
1 files changed, 57 insertions, 36 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: menu.c 1.222 2002/11/01 12:15:45 kls Exp $ + * $Id: menu.c 1.223 2002/11/10 12:32:42 kls Exp $ */ #include "menu.h" @@ -546,16 +546,18 @@ private: cChannel data; void Setup(void); public: - cMenuEditChannel(int Index); + cMenuEditChannel(cChannel *Channel, bool New = false); virtual eOSState ProcessKey(eKeys Key); }; -cMenuEditChannel::cMenuEditChannel(int Index) +cMenuEditChannel::cMenuEditChannel(cChannel *Channel, bool New) :cOsdMenu(tr("Edit channel"), 14) { - channel = Channels.Get(Index); + channel = Channel; if (channel) { data = *channel; + if (New) + channel = NULL; Setup(); } } @@ -603,10 +605,26 @@ eOSState cMenuEditChannel::ProcessKey(eKeys Key) if (state == osUnknown) { if (Key == kOk) { - if (channel) - *channel = data; - Channels.Save(); - state = osBack; + if (Channels.HasUniqueChannelID(&data, channel)) { + if (channel) { + *channel = data; + isyslog("edited channel %d %s", channel->Number(), data.ToText()); + state = osBack; + } + else { + channel = new cChannel; + *channel = data; + Channels.Add(channel); + Channels.ReNumber(); + isyslog("added channel %d %s", channel->Number(), data.ToText()); + state = osUser1; + } + Channels.Save(); + } + else { + Interface->Error(tr("Channel settings are not unique!")); + state = osContinue; + } } } if (Key != kNone && (data.source & cSource::st_Mask) != (oldSource & cSource::st_Mask)) @@ -696,10 +714,8 @@ eOSState cMenuChannels::Edit(void) if (HasSubMenu() || Count() == 0) return osContinue; cChannel *ch = Channels.Get(Current()); - if (ch) { - isyslog("editing channel %d", ch->Number()); - return AddSubMenu(new cMenuEditChannel(Current())); - } + if (ch) + return AddSubMenu(new cMenuEditChannel(ch)); return osContinue; } @@ -707,13 +723,7 @@ eOSState cMenuChannels::New(void) { if (HasSubMenu()) return osContinue; - cChannel *channel = new cChannel(Channels.Get(Current())); - Channels.Add(channel); - Channels.ReNumber(); - Add(new cMenuChannelItem(channel), true); - Channels.Save(); - isyslog("channel %d added", channel->Number()); - return AddSubMenu(new cMenuEditChannel(Current())); + return AddSubMenu(new cMenuEditChannel(Channels.Get(Current()), true)); } eOSState cMenuChannels::Del(void) @@ -753,16 +763,27 @@ eOSState cMenuChannels::ProcessKey(eKeys Key) { eOSState state = cOsdMenu::ProcessKey(Key); - if (state == osUnknown) { - switch (Key) { - case kOk: return Switch(); - case kRed: return Edit(); - case kGreen: return New(); - case kYellow: return Del(); - case kBlue: Mark(); break; - default: break; - } - } + switch (state) { + case osUser1: { + cChannel *channel = Channels.Last(); + if (channel) { + Add(new cMenuChannelItem(channel), true); + return CloseSubMenu(); + } + } + break; + default: + if (state == osUnknown) { + switch (Key) { + case kOk: return Switch(); + case kRed: return Edit(); + case kGreen: return New(); + case kYellow: return Del(); + case kBlue: Mark(); break; + default: break; + } + } + } return state; } @@ -1068,7 +1089,7 @@ cMenuEvent::cMenuEvent(const cEventInfo *EventInfo, bool CanSwitch) { eventInfo = EventInfo; if (eventInfo) { - cChannel *channel = Channels.GetByServiceID(eventInfo->GetServiceID()); + cChannel *channel = Channels.GetByChannelID(eventInfo->GetChannelID()); if (channel) { char *buffer; asprintf(&buffer, "%-17.*s\t%.*s %s - %s", 17, channel->Name(), 5, eventInfo->GetDate(), eventInfo->GetTimeString(), eventInfo->GetEndTimeString()); @@ -1162,7 +1183,7 @@ cMenuWhatsOn::cMenuWhatsOn(const cSchedules *Schedules, bool Now, int CurrentCha pArray[num] = Now ? Schedule->GetPresentEvent() : Schedule->GetFollowingEvent(); if (pArray[num]) { - cChannel *channel = Channels.GetByServiceID(pArray[num]->GetServiceID()); + cChannel *channel = Channels.GetByChannelID(pArray[num]->GetChannelID()); if (channel) { pArray[num]->SetChannelNumber(channel->Number()); num++; @@ -1192,7 +1213,7 @@ eOSState cMenuWhatsOn::Switch(void) { cMenuWhatsOnItem *item = (cMenuWhatsOnItem *)Get(Current()); if (item) { - cChannel *channel = Channels.GetByServiceID(item->eventInfo->GetServiceID()); + cChannel *channel = Channels.GetByChannelID(item->eventInfo->GetChannelID()); if (channel && cDevice::PrimaryDevice()->SwitchChannel(channel, true)) return osEnd; } @@ -1313,7 +1334,7 @@ void cMenuSchedule::PrepareSchedule(cChannel *Channel) SetTitle(buffer); free(buffer); if (schedules) { - const cSchedule *Schedule = Channel->Sid() ? schedules->GetSchedule(Channel->Sid()) : schedules->GetSchedule(); + const cSchedule *Schedule = schedules->GetSchedule(Channel->GetChannelID()); int num = Schedule->NumEvents(); const cEventInfo **pArray = MALLOC(const cEventInfo *, num); if (pArray) { @@ -1376,7 +1397,7 @@ eOSState cMenuSchedule::ProcessKey(eKeys Key) if (!now && !next) { int ChannelNr = 0; if (Count()) { - cChannel *channel = Channels.GetByServiceID(((cMenuScheduleItem *)Get(Current()))->eventInfo->GetServiceID()); + cChannel *channel = Channels.GetByChannelID(((cMenuScheduleItem *)Get(Current()))->eventInfo->GetChannelID()); if (channel) ChannelNr = channel->Number(); } @@ -1403,7 +1424,7 @@ eOSState cMenuSchedule::ProcessKey(eKeys Key) now = next = false; const cEventInfo *ei = cMenuWhatsOn::ScheduleEventInfo(); if (ei) { - cChannel *channel = Channels.GetByServiceID(ei->GetServiceID()); + cChannel *channel = Channels.GetByChannelID(ei->GetChannelID()); if (channel) { PrepareSchedule(channel); if (channel->Number() != cDevice::CurrentChannel()) { @@ -2713,7 +2734,7 @@ bool cRecordControl::GetEventInfo(void) cMutexLock MutexLock; const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock); if (Schedules) { - const cSchedule *Schedule = Schedules->GetSchedule(channel->Sid()); + const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID()); if (Schedule) { eventInfo = Schedule->GetEventAround(Time); if (eventInfo) { |