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);
124 boxstack->update(vs);
127 threadWaitForSignal();
133 for(UINT k = 0; k < servers.size(); k++)
135 delete[] servers[k].ip;
136 delete[] servers[k].name;
142 logger->log("VConnect", Log::NOTICE, "Connecting to server at %s", servers[selectedServer].ip);
143 Wol::getInstance()->setWakeUpIP(servers[selectedServer].ip);
144 vdr->setServerIP(servers[selectedServer].ip);
146 // Clear the serverIPs vector
147 for(UINT k = 0; k < servers.size(); k++)
149 delete[] servers[k].ip;
150 delete[] servers[k].name;
154 setOneLiner(tr("Connecting to VDR"));
156 boxstack->update(this);
158 success = vdr->connect();
161 logger->log("Command", Log::DEBUG, "Connected ok, doing login");
162 success = vdr->doLogin();
167 setOneLiner(tr("Login failed"));
173 setOneLiner(tr("Connection failed"));
178 boxstack->update(this);
183 Message* m = new Message(); // Must be done after this thread ends
185 m->to = Command::getInstance();
186 m->message = Message::VDR_CONNECTED;
187 Command::getInstance()->postMessage(m);
190 void VConnect::processMessage(Message* m)
192 if (m->message == Message::SERVER_SELECTED)
194 selectedServer = m->parameter;