]> git.vomp.tv Git - vompclient.git/blob - vserverselect.cc
Compile fix for MVP re: location change of hmsf
[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 "remote.h"
25 #include "colour.h"
26 #include "video.h"
27 #include "boxstack.h"
28 #include "i18n.h"
29 #include "command.h"
30
31
32 VServerSelect::VServerSelect(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 Remote::DF_UP:
81     case Remote::UP:
82     {
83       sl.up();
84       sl.draw();
85       BoxStack::getInstance()->update(this);
86       return 2;
87     }
88     case Remote::DF_DOWN:
89     case Remote::DOWN:
90     {
91       sl.down();
92       sl.draw();
93       BoxStack::getInstance()->update(this);
94       return 2;
95     }
96     case Remote::OK:
97     {
98       Message* m = new Message(); // Question/Answer mech. Better being messages
99       m->to = replyTo;
100       m->message = Message::SERVER_SELECTED;
101       m->parameter.num = sl.getCurrentOption();
102       Command::getInstance()->postMessageNoLock(m);
103       return 4;
104     }
105   }
106
107   return 1;
108 }
109
110 void VServerSelect::processMessage(Message* m)
111 {
112   if (m->message == Message::MOUSE_MOVE)
113   {
114     if (sl.mouseMove((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
115     {
116       sl.draw();
117       BoxStack::getInstance()->update(this);
118     }
119   }
120   else if (m->message == Message::MOUSE_LBDOWN)
121   {
122     if (sl.mouseLBDOWN((m->parameter.num>>16)-getScreenX(),(m->parameter.num&0xFFFF)-getScreenY()))
123     {
124       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
125     }
126   }
127 }