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);
147 // Clear the serverIPs vector
148 for(UINT k = 0; k < servers.size(); k++)
150 delete[] servers[k].ip;
151 delete[] servers[k].name;
156 setOneLiner(tr("Connecting to VDR"));
158 boxstack->update(this);
160 success = vdr->connect();
163 logger->log("VConnect", Log::DEBUG, "Connected ok, doing login");
164 unsigned int version_server,version_client;
165 success = vdr->doLogin(&version_server,&version_client);
170 if (version_server!=version_client) {
172 sprintf(buffer,"Protocoll mismatch s: %x c: %x",version_server,version_client);
175 setOneLiner(tr("Login failed"));
182 setOneLiner(tr("Connection failed"));
187 boxstack->update(this);
192 logger->log("VConnect", Log::INFO, "Send VDR connected message");
193 Message* m = new Message(); // Must be done after this thread ends
195 m->to = Command::getInstance();
196 m->message = Message::VDR_CONNECTED;
197 Command::getInstance()->postMessage(m);
200 void VConnect::processMessage(Message* m)
202 if (m->message == Message::SERVER_SELECTED)
204 selectedServer = m->parameter;