diff options
author | Midas <vdrportal_midas@gmx.de> | 2010-04-22 12:49:36 +0200 |
---|---|---|
committer | Midas <vdrportal_midas@gmx.de> | 2010-04-22 12:49:36 +0200 |
commit | d8df53ab68aa2031da1d49a8eb8897aa52ae0b2d (patch) | |
tree | c8c569ac7c94f6636c510382d4ba22d639aaa7dd /setup.c | |
parent | 4921cf32c8bda089a21dc4a14ce191ed477f80ff (diff) | |
download | vdr-plugin-block-d8df53ab68aa2031da1d49a8eb8897aa52ae0b2d.tar.gz vdr-plugin-block-d8df53ab68aa2031da1d49a8eb8897aa52ae0b2d.tar.bz2 |
Changed source directory structure.
Diffstat (limited to 'setup.c')
-rw-r--r-- | setup.c | 178 |
1 files changed, 178 insertions, 0 deletions
@@ -0,0 +1,178 @@ +/** + * based on setup.c,v 1.1.1.1 2006/02/26 14:11:02 lordjaxom + * + * version by Midas + * + */ + +#include "setup.h" + +#include <vdr/interface.h> + +cMenuSetupBlock::cMenuSetupBlock(): + cMenuSetupPage() +{ + mEventsData = EventsBlock; // need to use copy constructor + mSetupData = SetupBlock; + Set(); +} + +void cMenuSetupBlock::Set(void) { + int current = Current(); + cOsdItem *item; + + Clear(); + + Add(new cMenuEditBoolItem(tr("Hide Mainmenu Entry"), &mSetupData.HideMenuEntry)); + Add(new cMenuEditIntItem(tr("Message Timeout [s]"), &mSetupData.MessageTimeout, 0, 10)); + + item = new cOsdItem(""); + item->SetSelectable(false); + Add(item); + + item = new cOsdItem(tr("--- Keywords -------------------------------------------------------------------")); + item->SetSelectable(false); + Add(item); + +#define NONKEYWORDITEMS 4 + + int index = 0; + cEventBlock *event = mEventsData.First(); + while (event != NULL) { + Add(new cOsdItem(event->Pattern())); + event = mEventsData.Next(event); + ++index; + } + + SetCurrent(Get(current)); + SetHelpKeys(); + Display(); +} + +void cMenuSetupBlock::SetHelpKeys(void) +{ + const char *red = NULL; + const char *yellow = NULL; + + printf("sethelpkeys, current = %d\n", Current()); + + if (Current() >= NONKEYWORDITEMS) { + red = trVDR("Button$Edit"); + yellow = trVDR("Button$Delete"); + } + SetHelp(red, trVDR("Button$New"), yellow, NULL); +} + +void cMenuSetupBlock::Store(void) +{ + EventsBlock = mEventsData; + EventsBlock.Save(); + + SetupBlock = mSetupData; + SetupStore("HideMenuEntry", SetupBlock.HideMenuEntry); + SetupStore("MessageTimeout", SetupBlock.MessageTimeout); +} + +eOSState cMenuSetupBlock::Edit(void) +{ + if (HasSubMenu() || Current() < NONKEYWORDITEMS) + return osContinue; + + cEventBlock *event = mEventsData.Get(Current() - NONKEYWORDITEMS); + if (event != NULL) + return AddSubMenu(new cMenuSetupEditBlock(event)); + return osContinue; +} + +eOSState cMenuSetupBlock::New(void) +{ + if (HasSubMenu()) + return osContinue; + + mEventsData.Add(new cEventBlock()); + Set(); + return osContinue; +} + +eOSState cMenuSetupBlock::Delete(void) +{ + if (HasSubMenu() || Current() < NONKEYWORDITEMS) + return osContinue; + + cEventBlock *event = mEventsData.Get(Current() - NONKEYWORDITEMS); + if (event != NULL) { + if (Interface->Confirm(tr("Delete keyword?"))) + mEventsData.Del(event); + } + Set(); + return osContinue; +} + +eOSState cMenuSetupBlock::ProcessKey(eKeys Key) { + bool hadSubMenu = HasSubMenu(); + eOSState state = cMenuSetupPage::ProcessKey(Key); + + if (hadSubMenu && !HasSubMenu()) { + Set(); + return state; + } + + switch (state) { + case osUnknown: // normal key handling + switch (Key) { + case kRed: return Edit(); + case kGreen: return New(); + case kYellow: return Delete(); + + default: + break; + } + break; + + default: + break; + } + + if (!HasSubMenu()) + Set(); + + return state; +} + +static const char *ALLOWEDCHARS = "$ abcdefghijklmnopqrstuvwxyz0123456789-_.#~/[]{}()+*^$"; + +cMenuSetupEditBlock::cMenuSetupEditBlock(cEventBlock *Event): + cOsdMenu("", 33), + mEvent(Event), + mData(*Event) +{ + char buf[80]; + snprintf(buf, sizeof(buf), "%s - %s '%s'", trVDR("Setup"), trVDR("Plugin"), "block"); + SetTitle(buf); + Add(new cMenuEditStrItem(tr("Pattern"), mData.mPattern, sizeof(mData.mPattern), tr(ALLOWEDCHARS))); + Add(new cMenuEditBoolItem(tr("Regular Expression"), &mData.mRegularExp)); + Add(new cMenuEditBoolItem(tr("Ignore Case"), &mData.mIgnoreCase)); +} + +eOSState cMenuSetupEditBlock::ProcessKey(eKeys Key) +{ + eOSState state = cOsdMenu::ProcessKey(Key); + + if (state == osUnknown) { + switch (Key) { + case kOk: + if (!mData.Compile()) { + Skins.Message(mtError, tr("Malformed regular expression!")); + state = osContinue; + } else { + *mEvent = mData; + state = osBack; + } + break; + + default: + break; + } + } + return state; +} |