]> git.vomp.tv Git - vompclient.git/blob - vserverselect.cc
Rewrite timers class using std::thread/mutex/cond/chrono
[vompclient.git] / vserverselect.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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vserverselect.h"
22
23 #include "defines.h"
24 #include "input.h"
25 #include "colour.h"
26 #include "video.h"
27 #include "boxstack.h"
28 #include "i18n.h"
29 #include "messagequeue.h"
30
31
32 VServerSelect::VServerSelect(std::vector<VDRServer>& servers, void* treplyTo)
33 {
34   // I tried the whole passing using a reference here, but
35   // the program segfaulted when settitletext tried to new
36   // a char array. so now we have the messy dereferencing...
37   // anyway, now it doesn't use a object wide reference.
38
39   setSize(300, 200);
40   createBuffer();
41   if (Video::getInstance()->getFormat() == Video::PAL)
42   {
43     setPosition(220, 200);
44   }
45   else
46   {
47     setPosition(210, 150);
48   }
49
50   setTitleBarOn(1);
51   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
52   setTitleText(tr("Choose a VDR server"));
53
54   sl.setPosition(10, 30 + 5);
55   sl.setSize(area.w - 20, area.h - 30 - 15);
56   add(&sl);
57
58   sl.addOption(servers[0].name, 0, 1);
59   for(UINT k = 1; k < servers.size(); k++)
60   {
61     sl.addOption(servers[k].name, 0, 0);
62   }
63
64   replyTo = treplyTo;
65 }
66
67 VServerSelect::~VServerSelect()
68 {
69 }
70
71 void VServerSelect::draw()
72 {
73   TBBoxx::draw();
74 }
75
76 int VServerSelect::handleCommand(int command)
77 {
78   switch(command)
79   {
80     case Input::UP:
81     {
82       sl.up();
83       sl.draw();
84       BoxStack::getInstance()->update(this);
85       return 2;
86     }
87     case Input::DOWN:
88     {
89       sl.down();
90       sl.draw();
91       BoxStack::getInstance()->update(this);
92       return 2;
93     }
94     case Input::OK:
95     {
96       Message* m = new Message(); // Question/Answer mech. Better being messages
97       m->to = replyTo;
98       m->message = Message::SERVER_SELECTED;
99       m->parameter = sl.getCurrentOption();
100       MessageQueue::getInstance()->postMessage(m);
101       return 4;
102     }
103   }
104
105   return 1;
106 }
107
108 void VServerSelect::processMessage(Message* m)
109 {
110   if (m->message == Message::MOUSE_MOVE)
111   {
112     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
113     {
114       sl.draw();
115       BoxStack::getInstance()->update(this);
116     }
117   }
118   else if (m->message == Message::MOUSE_LBDOWN)
119   {
120     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
121     {
122       BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
123     }
124   }
125 }