-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_taskedit.c
127 lines (107 loc) · 3.9 KB
/
menu_taskedit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright (C) 2007 Christian Wieninger
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
The author can be reached at cwieninger@gmx.de
The project's page is at http://winni.vdr-developer.org/taskman
*/
#include <string>
#include <vector>
#include "menu_taskedit.h"
#include "i18n.h"
using namespace std;
const char TimeSpecChars[] = "0123456789, -*/";
const char WeekdaySpecChars[] = "0123456, -*/";
// --- cMenuTaskEdit -------------------------------------------------------
cMenuTaskEdit::cMenuTaskEdit(cTask* Task, bool New)
:cOsdMenu(tr("Task settings"), 25), task(Task)
{
AnnounceModes[0] = strdup(trVDR("no"));
AnnounceModes[1] = strdup(tr("Start"));
AnnounceModes[2] = strdup(tr("End"));
AnnounceModes[3] = strdup(tr("Start and end"));
addIfConfirmed = New;
data = *Task;
Set();
}
cMenuTaskEdit::~cMenuTaskEdit()
{
for(int i=0; i<4; i++) free(AnnounceModes[i]);
}
void cMenuTaskEdit::Set()
{
int current = Current();
Clear();
Add(new cMenuEditBoolItem(trVDR("Active"), &data.enabled));
Add(new cMenuEditStrItem(tr("Description"), data.name, sizeof(data.name), trVDR(FileNameChars)));
Add(new cMenuEditStrItem(tr("Command"), data.cmd, sizeof(data.cmd), trVDR(FileNameChars)));
Add(new cMenuEditStrItem(tr("Minute"), data.minute, sizeof(data.minute), TimeSpecChars));
Add(new cMenuEditStrItem(tr("Hour"), data.hour, sizeof(data.hour), TimeSpecChars));
Add(new cMenuEditStrItem(tr("Day of week"), data.dayofweek, sizeof(data.dayofweek), WeekdaySpecChars));
Add(new cMenuEditStrItem(tr("Day"), data.dayofmonth, sizeof(data.dayofmonth), TimeSpecChars));
Add(new cMenuEditStrItem(tr("Month"), data.month, sizeof(data.month), TimeSpecChars));
Add(new cMenuEditBoolItem(tr("Wakeup VDR"), &data.wakeup));
Add(new cMenuEditBoolItem(tr("Shutdown VDR"), &data.shutdown));
Add(new cMenuEditStraItem(tr("OSD announce"), &data.announceMode, 4, AnnounceModes));
Add(new cMenuEditIntItem(tr("Save ... logs"), &data.logging, 0, 9999));
Add(new cMenuEditIntItem(tr("Kill after ... minutes"), &data.killAfterMins, 0, 9999));
// Info block
cOsdItem* pInfoItem = new cOsdItem(tr("Next executions:"));
pInfoItem->SetSelectable(false);
Add(pInfoItem);
time_t nextExecution = time(NULL);
for(int i=0; i<2; i++)
{
char* info = NULL;
nextExecution = data.NextExecution(nextExecution + 60);
if (nextExecution)
{
if (asprintf(&info, "%s %s", *DateString(nextExecution), *TimeString(nextExecution)) == -1) continue;
pInfoItem = new cOsdItem(info);
free(info);
pInfoItem->SetSelectable(false);
Add(pInfoItem);
}
}
SetCurrent(Get(current));
Display();
}
eOSState cMenuTaskEdit::ProcessKey(eKeys Key)
{
eOSState state = cOsdMenu::ProcessKey(Key);
if (Key == kOk)
Set();
if (state == osUnknown) {
switch (Key) {
case kOk:
{
string oldName = task->Name();
*task = data;
if (addIfConfirmed)
{
cMutexLock TasksLock(&Tasks);
task->SetId(Tasks.GetNewId());
Tasks.Add(task);
}
else if (oldName != task->Name())
task->taskLog.Rename(oldName);
Tasks.Save();
addIfConfirmed = false;
}
return osBack;
default:
break;
}
}
return state;
}