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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* menu.cpp: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <signal.h>
#include <vdr/menu.h>
#include <vdr/font.h>
#include "menu.h"
#include "debug.h"
cOsdMarkAd::cOsdMarkAd(struct sRecording *Entry) {
entry = Entry;
const char *status;
switch (entry->status) {
case 'R':
status = tr("running");
break;
case 'S':
status = tr("sleeping");
break;
case 'D':
status = tr("inactive");
break;
case 'Z':
status = tr("zombie");
break;
case 'T':
status = tr("stopped");
break;
default:
status = tr("unknown");
break;
}
char *buf = nullptr;
if (asprintf(&buf, "%s\t %s", entry->title ? entry->title : entry->fileName,status) != -1) {
ALLOC(strlen(buf)+1, "buf");
SetText(buf,true);
FREE(strlen(buf)+1, "buf");
free(buf);
}
else {
// fallback
SetText(entry->title ? entry->title : entry->fileName, true);
}
}
cMenuMarkAd::cMenuMarkAd(cStatusMarkAd *Status):cOsdMenu(tr("markad status"), 15) {
status = Status;
int width = 0;
cSkinDisplayMenu *disp=DisplayMenu();
if (disp) {
width = disp->GetTextAreaWidth();
}
if (!width) width = Setup.OSDWidth;
int AvgCharWidth = Setup.FontOsdSize * 3 / 5; // see skins.c
if (AvgCharWidth < 1) AvgCharWidth = 1;
int tab = (width - 10 * AvgCharWidth) / AvgCharWidth;
SetCols(tab);
if (write()) {
cOsdMarkAd *osd = static_cast<cOsdMarkAd *>(Get(Current()));
if ((osd) && (osd->Selectable())) {
SetHelpText(osd->GetEntry());
}
}
else {
SetHelpText(nullptr);
}
lastpos = 0;
}
bool cMenuMarkAd::write() {
Clear();
bool header=false;
status->Check(); // refresh list of running markad tasks
struct sRecording *Entry=nullptr;
status->ResetActPos();
do {
status->GetNextActive(&Entry);
if (Entry) {
if (!header) {
header=true;
Add(new cOsdItem(tr("Recording\t Status"),osUnknown,false)); // freed by vdr on menu close
}
cOsdMarkAd *osd = new cOsdMarkAd(Entry); // freed by vdr on menu close
if (osd) {
Add(osd);
if (osd->Index()==lastpos) SetCurrent(osd);
}
}
}
while (Entry);
if (!header) {
Add(new cOsdItem(tr("no running markad found"),osUnknown,false),true); // freed by vdr on menu close
lastpos=0;
}
Display();
return header;
}
void cMenuMarkAd::SetHelpText(struct sRecording *Entry) {
if (!Entry) {
SetHelp(nullptr,nullptr);
return;
}
switch (Entry->status) {
case 'R':
case 'S':
SetHelp(tr("Pause"),nullptr);
break;
case 'D':
case 'Z':
SetHelp(nullptr,nullptr);
break;
case 'T':
SetHelp(nullptr,tr("Continue"));
break;
default:
SetHelp(nullptr,nullptr);
break;
}
}
eOSState cMenuMarkAd::ProcessKey(eKeys Key) {
cOsdMarkAd *osd;
eOSState state=osUnknown;
switch (Key) {
case kRed:
osd=static_cast<cOsdMarkAd *>(Get(Current()));
if ((osd) && (osd->Selectable())) {
struct sRecording *entry=osd->GetEntry();
if ((entry) && (entry->pid) && (entry->status!='T')) {
dsyslog("sending TSTP to %i",entry->pid);
kill(entry->pid,SIGTSTP);
entry->changedByUser=true;
SetHelp(nullptr,tr("Continue"));
}
}
break;
case kGreen:
osd=static_cast<cOsdMarkAd *>(Get(Current()));
if ((osd) && (osd->Selectable())) {
struct sRecording *entry=osd->GetEntry();
if ((entry) && (entry->pid)) {
dsyslog("sending CONT to %i",entry->pid);
kill(entry->pid,SIGCONT);
entry->changedByUser=true;
SetHelp(tr("Pause"),nullptr);
}
}
break;
case kUp:
CursorUp();
osd=static_cast<cOsdMarkAd *>(Get(Current()));
if ((osd) && (osd->Selectable())) {
SetHelpText(osd->GetEntry());
lastpos=Current();
}
break;
case kDown:
CursorDown();
osd=static_cast<cOsdMarkAd *>(Get(Current()));
if ((osd) && (osd->Selectable())) {
SetHelpText(osd->GetEntry());
lastpos=Current();
}
break;
case kOk:
state = osBack;
break;
case kNone:
if (time(nullptr)>(last+2)) {
if (write()) {
cOsdMarkAd *osdCurrent = static_cast<cOsdMarkAd *>(Get(Current()));
if ((osdCurrent) && (osdCurrent->Selectable())) {
SetHelpText(osdCurrent->GetEntry());
}
}
else {
SetHelpText(nullptr);
}
last = time(nullptr);
}
break;
default:
state = cOsdMenu::ProcessKey(Key);
break;
}
return state;
}
|