From 37db3b185c199e3eb07c8d3b2f42beea2ab5d2d3 Mon Sep 17 00:00:00 2001 From: kamel5 Date: Sat, 9 Nov 2019 13:23:36 +0100 Subject: [PATCH] Refactor cRecMenuEditTimer --- recmenus.c | 57 ++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/recmenus.c b/recmenus.c index 87c871b..bd1ff8e 100644 --- a/recmenus.c +++ b/recmenus.c @@ -409,23 +409,21 @@ cRecMenuConfirmRerunUsed::cRecMenuConfirmRerunUsed(const cEvent *original, const } // --- cRecMenuEditTimer --------------------------------------------------------- -cRecMenuEditTimer::cRecMenuEditTimer(const cTimer *timer, eRecMenuState nextState) { - SetWidthPercent(70); +cRecMenuEditTimer::cRecMenuEditTimer(const cTimer *timer, eRecMenuState nextState) { // OK if (!timer) return; + + SetWidthPercent(70); originalTimer = timer; - cString title(""); - cString channelName(""); - if (timer->Event()) - title = timer->Event()->Title(); - if (timer->Channel()) - channelName = timer->Channel()->Name(); - cString infoText = cString::sprintf("%s:\n %s, %s", tr("Edit Timer"), *title, *channelName); - cRecMenuItemInfo *infoItem = new cRecMenuItemInfo(*infoText, true); - infoItem->CalculateHeight(width - 2 * border); - AddMenuItemInitial(infoItem); - timerActive = false; + + const cString line1 = tr("Edit Timer"); + const cString line2 = (timer->Event() && timer->Event()->Title()) ? timer->Event()->Title() : ""; + const cString line3 = (timer->Channel() && timer->Channel()->Name()) ? timer->Channel()->Name() : ""; + + AddHeader(new cRecMenuItemInfo(*line1, 3, *line2, *line3, "", width - 2 * border, true)); + AddFooter(new cRecMenuItemButtonYesNo(tr("Save"), tr("Cancel"), nextState, (nextState == rmsTimelineTimerSave) ? rmsTimeline : rmsClose, false)); + if (config.useRemoteTimers && pRemoteTimers) { RemoteTimers_GetMatch_v1_0 rtMatch; rtMatch.event = timer->Event(); @@ -443,24 +441,19 @@ cRecMenuEditTimer::cRecMenuEditTimer(const cTimer *timer, eRecMenuState nextStat prio = timer->Priority(); lifetime = timer->Lifetime(); strncpy(folder, GetDirectoryFromTimer(timer->File()).c_str(), TEXTINPUTLENGTH); - - AddMenuItemInitial(new cRecMenuItemBool(tr("Timer Active"), true, &timerActive)); - AddMenuItemInitial(new cRecMenuItemInt(tr("Priority"), 0, MAXPRIORITY, false, &prio)); - AddMenuItemInitial(new cRecMenuItemInt(tr("Lifetime"), 0, MAXLIFETIME, false, &lifetime)); - AddMenuItemInitial(new cRecMenuItemDay(tr("Day"), false, &day)); - AddMenuItemInitial(new cRecMenuItemTime(tr("Timer start time"), false, &start)); - AddMenuItemInitial(new cRecMenuItemTime(tr("Timer stop time"), false, &stop)); - cString fileInfo = cString::sprintf("%s:\n%s", tr("Timer File"), timer->File()); - cRecMenuItemInfo *fileInfoItem = new cRecMenuItemInfo(*fileInfo, false); - fileInfoItem->CalculateHeight(width - 2 * border); - AddMenuItemInitial(fileInfoItem); - AddMenuItemInitial(new cRecMenuItemSelectDirectory(tr("New Folder"), std::string(folder), false, folder)); - if (nextState == rmsTimelineTimerSave) { - AddMenuItemInitial(new cRecMenuItemButton(tr("Delete Timer"), rmsTimelineTimerDelete, false, false)); - AddMenuItemInitial(new cRecMenuItemButtonYesNo(tr("Save"), tr("Cancel"), nextState, rmsTimeline, false)); - } else { - AddMenuItemInitial(new cRecMenuItemButtonYesNo(tr("Save"), tr("Cancel"), nextState, rmsClose, false)); - } + + AddMenuItem(new cRecMenuItemBool(tr("Timer Active"), true, &timerActive)); + AddMenuItem(new cRecMenuItemInt(tr("Priority"), 0, MAXPRIORITY, false, &prio)); + AddMenuItem(new cRecMenuItemInt(tr("Lifetime"), 0, MAXLIFETIME, false, &lifetime)); + AddMenuItem(new cRecMenuItemDay(tr("Day"), false, &day)); + AddMenuItem(new cRecMenuItemTime(tr("Timer start time"), false, &start)); + AddMenuItem(new cRecMenuItemTime(tr("Timer stop time"), false, &stop)); + AddMenuItem(new cRecMenuItemInfo(tr("Timer File"), 2, timer->File() ? timer->File() : "", "", "", width - 2 * border, false)); + AddMenuItem(new cRecMenuItemSelectDirectory(tr("New Folder"), std::string(folder), false, folder)); + + if (nextState == rmsTimelineTimerSave) + AddMenuItem(new cRecMenuItemButton(tr("Delete Timer"), rmsTimelineTimerDelete, false)); + CalculateHeight(); CreatePixmap(); Arrange(); @@ -485,7 +478,7 @@ cTimer *cRecMenuEditTimer::GetTimer(void) { std::string newFile = originalTimer->File(); size_t found = newFile.find_last_of('~'); if (found != std::string::npos) { - std::string fileName = newFile.substr(found+1); + std::string fileName = newFile.substr(found + 1); if (newFolder.size() > 0) newFile = *cString::sprintf("%s~%s", newFolder.c_str(), fileName.c_str()); else