2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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.
31 #include "vserverselect.h"
33 VConnect::VConnect(char* tServer)
35 boxstack = BoxStack::getInstance();
36 vdr = VDR::getInstance();
37 logger = Log::getInstance();
41 if (Video::getInstance()->getFormat() == Video::PAL)
43 setPosition(170, 200);
47 setPosition(160, 150);
58 vdr->cancelFindingServer();
65 logger->log("VConnect", Log::DEBUG, "Draw done");
68 int VConnect::handleCommand(int command)
78 void VConnect::threadMethod()
86 if (server) // Server is specified, fake a servers array
89 vdrserver.ip = new char[strlen(server)+1];
90 strcpy(vdrserver.ip, server);
91 vdrserver.name = new char[1];
92 vdrserver.name[0] = '\0';
93 servers.push_back(vdrserver);
97 setOneLiner(tr("Locating server"));
99 boxstack->update(this);
101 vdr->findServers(servers);
104 for(UINT k = 0; k < servers.size(); k++)
106 delete[] servers[k].ip;
107 delete[] servers[k].name;
114 if (servers.size() == 1)
121 VServerSelect* vs = new VServerSelect(servers, this);
123 boxstack->add(vs); // FIXME - do this better - perhaps post message to Command
124 // Otherwise it will be using BoxStack without the Command mutex locked
125 boxstack->update(vs);
128 threadWaitForSignal();
134 for(UINT k = 0; k < servers.size(); k++)
136 delete[] servers[k].ip;
137 delete[] servers[k].name;
143 logger->log("VConnect", Log::NOTICE, "Connecting to server at %s", servers[selectedServer].ip);
144 Wol::getInstance()->setWakeUpIP(servers[selectedServer].ip);
145 vdr->setServerIP(servers[selectedServer].ip);
147 // Clear the serverIPs vector
148 for(UINT k = 0; k < servers.size(); k++)
150 delete[] servers[k].ip;
151 delete[] servers[k].name;
155 setOneLiner(tr("Connecting to VDR"));
157 boxstack->update(this);
159 success = vdr->connect();
162 logger->log("Command", Log::DEBUG, "Connected ok, doing login");
163 success = vdr->doLogin();
168 setOneLiner(tr("Login failed"));
174 setOneLiner(tr("Connection failed"));
179 boxstack->update(this);
184 Message* m = new Message(); // Must be done after this thread ends
186 m->to = Command::getInstance();
187 m->message = Message::VDR_CONNECTED;
188 Command::getInstance()->postMessage(m);
191 void VConnect::processMessage(Message* m)
193 if (m->message == Message::SERVER_SELECTED)
195 selectedServer = m->parameter;