]> git.vomp.tv Git - vompclient.git/blob - vtimerlist.cc
*** empty log message ***
[vompclient.git] / vtimerlist.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 "vtimerlist.h"
22
23 VTimerList::VTimerList(RecTimerList* trtl)
24 {
25   recTimerList = trtl;
26
27   clockRegion.x = 420;
28   clockRegion.y = 0;
29   clockRegion.w = 150;
30   clockRegion.h = 30;
31
32   create(570, 420);
33   if (Video::getInstance()->getFormat() == Video::PAL)
34   {
35     setScreenPos(80, 70);
36   }
37   else
38   {
39     setScreenPos(70, 35);
40   }
41
42
43   setBackgroundColour(Colour::VIEWBACKGROUND);
44   setTitleBarOn(1);
45   setTitleText(tr("Timers"));
46   setTitleBarColour(Colour::TITLEBARBACKGROUND);
47
48   sl.setSurface(surface);
49   sl.setSurfaceOffset(10, 30 + 5);
50   sl.setDimensions(area.w - 20, area.h - 30 - 15 - 30);
51
52   drawData();
53 }
54
55 VTimerList::~VTimerList()
56 {
57   Timers::getInstance()->cancelTimer(this, 1);
58   if (recTimerList)
59   {
60     for (UINT i = 0; i < recTimerList->size(); i++)
61     {
62       delete (*recTimerList)[i];
63     }
64
65     recTimerList->clear();
66     delete recTimerList;
67   }
68 }
69
70 void VTimerList::drawData()
71 {
72   char strA[300];
73   char strB[300];
74
75   struct tm* btime;
76
77   sl.addColumn(0);
78   sl.addColumn(110);
79
80   RecTimer* recTimer;
81   int first = 1;
82
83   for (UINT i = 0; i < recTimerList->size(); i++)
84   {
85     recTimer = (*recTimerList)[i];
86     btime = localtime((time_t*)&recTimer->startTime);
87     strftime(strA, 299, "%d/%m %H:%M ", btime);
88     snprintf(strB, 299, "%s\t%s", strA, recTimer->getName());
89     recTimer->index = sl.addOption(strB, first);
90     first = 0;
91   }
92 }
93
94 void VTimerList::drawClock()
95 {
96   // Blank the area first
97   rectangle(area.w - 150, 0, 150, 30, titleBarColour);
98
99   char timeString[20];
100   time_t t;
101   time(&t);
102   struct tm* tms = localtime(&t);
103   strftime(timeString, 19, "%d/%m %H:%M:%S", tms);
104   drawTextRJ(timeString, 560, 5, Colour::LIGHTTEXT);
105
106   Timers::getInstance()->setTimer(this, 1, t + 1);
107 }
108
109 void VTimerList::draw()
110 {
111   View::draw();
112   sl.draw();
113
114   // Put the status stuff at the bottom
115
116   WSymbol w;
117   w.setSurface(surface);
118
119   w.nextSymbol = WSymbol::UP;
120   w.setSurfaceOffset(20, 385);
121   w.draw();
122
123   w.nextSymbol = WSymbol::DOWN;
124   w.setSurfaceOffset(50, 385);
125   w.draw();
126
127   w.nextSymbol = WSymbol::SKIPBACK;
128   w.setSurfaceOffset(85, 385);
129   w.draw();
130
131   w.nextSymbol = WSymbol::SKIPFORWARD;
132   w.setSurfaceOffset(115, 385);
133   w.draw();
134
135   drawTextRJ("[ok] = edit", 560, 385, Colour::LIGHTTEXT);
136
137   doShowingBar();
138   drawClock();
139 }
140
141 void VTimerList::doShowingBar()
142 {
143   int topOption = sl.getTopOption() + 1;
144   if (sl.getNumOptions() == 0) topOption = 0;
145
146   rectangle(220, 385, 180, 25, Colour::VIEWBACKGROUND);
147   char showing[200];
148   sprintf(showing, tr("%i to %i of %i"), topOption, sl.getBottomOption(), sl.getNumOptions());
149   drawText(showing, 220, 385, Colour::LIGHTTEXT);
150 }
151
152 void VTimerList::timercall(int clientReference)
153 {
154   drawClock();
155   ViewMan::getInstance()->updateView(this, &clockRegion);
156 }
157
158 int VTimerList::handleCommand(int command)
159 {
160   switch(command)
161   {
162     case Remote::DF_UP:
163     case Remote::UP:
164     {
165       sl.up();
166       sl.draw();
167
168       doShowingBar();
169       ViewMan::getInstance()->updateView(this);
170       return 2;
171     }
172     case Remote::DF_DOWN:
173     case Remote::DOWN:
174     {
175       sl.down();
176       sl.draw();
177
178       doShowingBar();
179       ViewMan::getInstance()->updateView(this);
180       return 2;
181     }
182     case Remote::SKIPBACK:
183     {
184       sl.pageUp();
185       sl.draw();
186
187       doShowingBar();
188       ViewMan::getInstance()->updateView(this);
189       return 2;
190     }
191     case Remote::SKIPFORWARD:
192     {
193       sl.pageDown();
194       sl.draw();
195
196       doShowingBar();
197       ViewMan::getInstance()->updateView(this);
198       return 2;
199     }
200     case Remote::OK:
201     {
202       RecTimer* recTimer = NULL;
203       if (recTimerList)
204       {
205         int currentOption = sl.getCurrentOption();
206
207         for (UINT i = 0; i < recTimerList->size(); i++)
208         {
209           recTimer = (*recTimerList)[i];
210           if (currentOption == recTimer->index) break;
211         }
212       }
213
214       if (recTimer == NULL) return 2;
215
216       // recTimer is the one you want FIXME
217
218       return 2;
219     }
220     case Remote::BACK:
221     {
222       return 4;
223     }
224   }
225   // stop command getting to any more views
226   return 1;
227 }