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