]> git.vomp.tv Git - vompclient.git/blob - vrecordingmenu.cc
Connection failed detection
[vompclient.git] / vrecordingmenu.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "vrecordingmenu.h"
22
23 VRecordingMenu::VRecordingMenu()
24 {
25   rec = NULL;
26
27   create(200, 140);
28   if (Video::getInstance()->getFormat() == Video::PAL)
29   {
30     setScreenPos(260, 190);
31   }
32   else
33   {
34     setScreenPos(250, 160);
35   }
36
37   setBackgroundColour(Colour::VIEWBACKGROUND);
38   setTitleBarOn(1);
39   setBorderOn(1);
40   setTitleText(tr("Programme menu"));
41   setTitleBarColour(Colour::TITLEBARBACKGROUND);
42
43   sl.setSurface(surface);
44   sl.setSurfaceOffset(10, 30 + 5);
45   sl.setDimensions(area.w - 20, area.h - 30 - 15);
46   sl.addOption(tr("Play"), 1);
47   sl.addOption(tr("Resume"), 0);
48   sl.addOption(tr("Summary"), 0);
49   sl.addOption(tr("Delete"), 0);
50 }
51
52 VRecordingMenu::~VRecordingMenu()
53 {
54 }
55
56 void VRecordingMenu::setParent(VRecordingList* tvRecList)
57 {
58   vRecList = tvRecList;
59 }
60
61 void VRecordingMenu::setRecording(Recording* trec)
62 {
63   rec = trec;
64 }
65
66 void VRecordingMenu::draw()
67 {
68   View::draw();
69   sl.draw();
70 }
71
72 int VRecordingMenu::handleCommand(int command)
73 {
74   switch(command)
75   {
76     case Remote::DF_UP:
77     case Remote::UP:
78     {
79       sl.up();
80       sl.draw();
81       ViewMan::getInstance()->updateView(this);
82       return 2;
83     }
84     case Remote::DF_DOWN:
85     case Remote::DOWN:
86     {
87       sl.down();
88       sl.draw();
89       ViewMan::getInstance()->updateView(this);
90       return 2;
91     }
92     case Remote::OK:
93     {
94       if (sl.getCurrentOption() == 0)
95       {
96         Message* m = new Message(); // Must be done after this view deleted
97         m->from = this;
98         m->to = vRecList;
99         m->message = Message::PLAY_SELECTED_RECORDING;
100         ViewMan::getInstance()->postMessage(m);
101         return 4;
102       }
103
104       if (sl.getCurrentOption() == 1)
105       {
106         Message* m = new Message(); // Must be done after this view deleted
107         m->from = this;
108         m->to = vRecList;
109         m->message = Message::RESUME_SELECTED_RECORDING;
110         ViewMan::getInstance()->postMessage(m);
111         return 4;
112       }
113
114       if (sl.getCurrentOption() == 2)
115       {
116         char* summary = VDR::getInstance()->getRecordingSummary(rec->fileName);
117         if (!summary && !VDR::getInstance()->isConnected())
118         {
119           Command::getInstance()->connectionLost();
120           return 2;
121         }
122
123         VInfo* vi = new VInfo();
124         vi->setTitleText(tr("Programme summary"));
125         vi->setBorderOn(1);
126         vi->setExitable();
127         if (summary) vi->setMainText(summary);
128         else vi->setMainText(tr("Summary unavailable"));
129         if (Video::getInstance()->getFormat() == Video::PAL)
130         {
131           vi->setScreenPos(120, 130);
132         }
133         else
134         {
135           vi->setScreenPos(110, 90);
136         }
137         vi->create(490, 300);
138         vi->draw();
139         ViewMan::getInstance()->add(vi);
140         ViewMan::getInstance()->updateView(vi);
141
142         if (summary) delete[] summary;
143
144         return 2;
145       }
146       else if (sl.getCurrentOption() == 3)
147       {
148         VQuestion* v = new VQuestion(this);
149         v->create(260, 180);
150         v->setBackgroundColour(Colour::VIEWBACKGROUND);
151         v->setTitleBarColour(Colour::DANGER);
152         v->setTitleBarOn(1);
153         v->setBorderOn(1);
154         v->setTitleText(tr("Delete recording"));
155         v->setMainText(tr("Are you sure you want to delete this recording?"));
156         v->setDefault(VQuestion::NO);
157         if (Video::getInstance()->getFormat() == Video::PAL)
158         {
159           v->setScreenPos(230, 160);
160         }
161         else
162         {
163           v->setScreenPos(220, 140);
164         }
165
166         v->draw();
167         ViewMan::getInstance()->add(v);
168         ViewMan::getInstance()->updateView(v);
169         return 2;
170       }
171     }
172     case Remote::BACK:
173     {
174       return 4;
175     }
176   }
177   // stop command getting to any more views
178   return 1;
179 }
180
181 void VRecordingMenu::processMessage(Message* m)
182 {
183   if (m->message == Message::QUESTION_YES)
184   {
185     if (sl.getCurrentOption() == 3)
186     {
187       Message* m2 = new Message(); // Delete self
188       m2->from = this;
189       m2->to = ViewMan::getInstance();
190       m2->message = Message::CLOSE_ME;
191       ViewMan::getInstance()->postMessage(m2);
192
193       m2 = new Message(); // OK. Want this to delete before this message does its job
194       m2->from = this;
195       m2->to = vRecList;
196       m2->message = Message::DELETE_SELECTED_RECORDING;
197       ViewMan::getInstance()->postMessage(m2);
198     }
199   }
200 }