2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 Command* Command::instance = NULL;
39 Command* Command::getInstance()
46 if (initted) return 0;
49 logger = Log::getInstance();
50 viewman = ViewMan::getInstance();
51 remote = Remote::getInstance();
53 if (!logger || !viewman || !remote)
62 int Command::shutdown()
64 if (!initted) return 0;
71 // VDR::getInstance()->cancelFindingServer();
82 Video* video = Video::getInstance();
84 UCHAR screenSize = video->getFormat();
86 // moved from startup because surface delete doesn't work
90 Led::getInstance()->on();
94 v->create(video->getScreenWidth(), video->getScreenHeight());
95 v->setBackgroundColour(Colour::VIDEOBLUE);
99 viewman->removeView(v);
102 wallpaper = new VWallpaper();
103 if (screenSize == Video::PAL)
105 logger->log("Command", Log::DEBUG, "PAL wallpaper selected");
106 wallpaper->init("/wallpaperPAL.jpg");
110 logger->log("Command", Log::DEBUG, "NTSC wallpaper selected");
111 wallpaper->init("/wallpaperNTSC.jpg");
115 viewman->add(wallpaper);
117 VConnect* vconnect = new VConnect();
118 viewman->add(vconnect);
125 button = remote->getButtonPress(2); // FIXME why is this set to 2 and not 0? so it can quit
126 if ((button == Remote::NA_NONE) || (button == Remote::NA_UNKNOWN)) continue;
128 if (button != Remote::NA_SIGNAL) handleCommand(button);
129 processMessageQueue();
133 void Command::postMessage(Message* m)
135 MessageQueue::postMessage(m);
136 kill(mainPid, SIGURG);
139 void Command::processMessage(Message* m)
141 logger->log("Command", Log::DEBUG, "processing message %i", m->message);
145 case Message::STANDBY:
150 case Message::STOP_PLAYBACK:
152 handleCommand(Remote::STOP); // an odd way of doing it, but so simple
155 case Message::STREAM_END:
157 // post a message to ViewMan and then run the viewman message queue
158 Message* m = new Message();
159 m->message = Message::STREAM_END;
160 m->to = VVideoLive::getInstance();
161 viewman->postMessage(m);
162 handleCommand(Remote::NA_NONE);
165 case Message::VDR_CONNECTED:
167 doJustConnected((VConnect*)m->from);
173 void Command::handleCommand(int button)
175 if (isStandby && (button != Remote::POWER)) return;
177 if (viewman->handleCommand(button)) return;
179 // command was not handled
183 case Remote::DF_LEFT:
184 case Remote::DF_RIGHT:
185 case Remote::VOLUMEUP:
186 case Remote::VOLUMEDOWN:
188 VVolume* v = new VVolume();
189 v->handleCommand(button); // this will draw+show
191 viewman->timedDelete(v, 2, 1);
196 VMute* v = new VMute();
200 viewman->timedDelete(v, 2, 1);
211 Osd::getInstance()->screenShot("/out.jpg");
218 void Command::doStandby()
222 Video::getInstance()->signalOn();
223 Led::getInstance()->on();
227 VConnect* vconnect = new VConnect();
228 viewman->add(vconnect);
233 Video::getInstance()->signalOff();
234 viewman->removeAll();
237 VDR::getInstance()->configSave("General", "Last Power State", "Off");
238 VDR::getInstance()->disconnect();
239 Led::getInstance()->off();
244 void Command::doReboot()
246 VDR::getInstance()->disconnect();
248 logger->log("Command", Log::NOTICE, "Reboot");
249 reboot(LINUX_REBOOT_CMD_RESTART);
252 void Command::doJustConnected(VConnect* vconnect)
255 Video* video = Video::getInstance();
256 viewman->removeView(vconnect, 0, 1);
258 VInfo* vi = new VInfo();
259 vi->create(400, 200);
260 if (video->getFormat() == Video::PAL)
261 vi->setScreenPos(170, 200);
263 vi->setScreenPos(160, 150);
265 vi->setMainText(tr("\n Connected, loading config"));
271 VDR* vdr = VDR::getInstance();
274 // Power off if first boot and config says so
279 config = vdr->configLoad("General", "Power After Boot");
283 if (!strcasecmp(config, "On"))
285 logger->log("Command", Log::INFO, "Config says Power After Boot = On");
287 else if (!strcasecmp(config, "Off"))
289 logger->log("Command", Log::INFO, "Config says Power After Boot = Off");
294 else if (!strcasecmp(config, "Last state"))
296 char* lastPowerState = vdr->configLoad("General", "Last Power State");
299 if (!strcasecmp(lastPowerState, "On"))
301 logger->log("Command", Log::INFO, "Config says Last Power State = On");
303 else if (!strcasecmp(lastPowerState, "Off"))
305 logger->log("Command", Log::INFO, "Config says Last Power State = Off");
312 logger->log("Command", Log::INFO, "Config General/Last Power State not understood");
317 logger->log("Command", Log::INFO, "Config General/Last Power State not found");
322 logger->log("Command", Log::INFO, "Config/Power After Boot not understood");
328 logger->log("Command", Log::INFO, "Config General/Power After Boot not found");
333 // Go S-Video if config says so
335 config = vdr->configLoad("TV", "Connection");
339 if (!strcasecmp(config, "S-Video"))
341 logger->log("Command", Log::INFO, "Switching to S-Video as Connection=%s", config);
342 video->setConnection(Video::SVIDEO);
346 logger->log("Command", Log::INFO, "Switching to RGB/Composite as Connection=%s", config);
347 video->setConnection(Video::COMPOSITERGB);
353 logger->log("Command", Log::INFO, "Config TV/S-Video not found");
358 config = vdr->configLoad("General", "Remote type");
362 if (!strcasecmp(config, "New"))
364 logger->log("Command", Log::INFO, "Switching to New remote type");
365 remote->setRemoteType(Remote::NEWREMOTE);
369 logger->log("Command", Log::INFO, "Switching to Old remote type");
370 remote->setRemoteType(Remote::OLDREMOTE);
376 logger->log("Command", Log::INFO, "Config General/Remote type not found");
377 remote->setRemoteType(Remote::OLDREMOTE);
380 // Get TV aspect ratio
382 config = vdr->configLoad("TV", "Aspect");
385 if (!strcasecmp(config, "16:9"))
387 logger->log("Command", Log::INFO, "/// Switching to TV aspect 16:9");
388 video->setTVsize(Video::ASPECT16X9);
392 logger->log("Command", Log::INFO, "/// Switching to TV aspect 4:3");
393 video->setTVsize(Video::ASPECT4X3);
399 logger->log("Command", Log::INFO, "Config TV/Aspect type not found, going 4:3");
400 video->setTVsize(Video::ASPECT4X3);
403 config = vdr->configLoad("TV", "Widemode");
406 if (!strcasecmp(config, "Letterbox"))
408 logger->log("Command", Log::INFO, "Setting letterbox mode");
409 video->setMode(Video::LETTERBOX);
413 logger->log("Command", Log::INFO, "Setting chop-sides mode");
414 video->setMode(Video::NORMAL);
420 logger->log("Command", Log::INFO, "Config TV/Widemode not found, Setting chop-sides mode");
421 video->setMode(Video::NORMAL);
426 // Save power state = on
428 vdr->configSave("General", "Last Power State", "On");
431 viewman->removeView(vi);
433 VWelcome* vw = new VWelcome();
437 // viewman->redrawAll();
440 handleCommand(Remote::DOWN);
441 handleCommand(Remote::DOWN);
442 handleCommand(Remote::OK);
443 handleCommand(Remote::DOWN);
444 handleCommand(Remote::DOWN);
445 handleCommand(Remote::DOWN);
446 handleCommand(Remote::OK);
447 handleCommand(Remote::OK);
448 handleCommand(Remote::UP);
449 handleCommand(Remote::OK);
450 handleCommand(Remote::DF_LEFT);
451 handleCommand(Remote::OK);
452 handleCommand(Remote::BACK);