summaryrefslogtreecommitdiff
path: root/library/network.cpp
Unidiff
Diffstat (limited to 'library/network.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/network.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/library/network.cpp b/library/network.cpp
index e6d2781..185b147 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,203 +1,209 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "qpe/network.h" 22#include "qpe/network.h"
23#include "qpe/networkinterface.h" 23#include "qpe/networkinterface.h"
24#include "qpe/global.h" 24#include "qpe/global.h"
25#include "qpe/config.h" 25#include "qpe/config.h"
26#include "qpe/resource.h" 26#include "qpe/resource.h"
27#include "qpe/qpeapplication.h" 27#include "qpe/qpeapplication.h"
28#ifdef QWS
28#include <qpe/qcopenvelope_qws.h> 29#include <qpe/qcopenvelope_qws.h>
30#endif
29#include <qpe/qlibrary.h> 31#include <qpe/qlibrary.h>
30 32
31#include <qlistbox.h> 33#include <qlistbox.h>
32#include <qdir.h> 34#include <qdir.h>
33#include <qlayout.h> 35#include <qlayout.h>
34#include <qdict.h> 36#include <qdict.h>
35#include <qtranslator.h> 37#include <qtranslator.h>
36 38
37#include <stdlib.h> 39#include <stdlib.h>
38 40
41#ifndef QT_NO_COP
39class NetworkEmitter : public QCopChannel { 42class NetworkEmitter : public QCopChannel {
40 Q_OBJECT 43 Q_OBJECT
41public: 44public:
42 NetworkEmitter() : QCopChannel("QPE/Network",qApp) 45 NetworkEmitter() : QCopChannel("QPE/Network",qApp)
43 { 46 {
44 } 47 }
45 48
46 void receive(const QCString &msg, const QByteArray&) 49 void receive(const QCString &msg, const QByteArray&)
47 { 50 {
48 if ( msg == "choicesChanged()" ) 51 if ( msg == "choicesChanged()" )
49 emit changed(); 52 emit changed();
50 } 53 }
51 54
52signals: 55signals:
53 void changed(); 56 void changed();
54}; 57};
55 58
56/*! 59/*!
57 \internal 60 \internal
58 61
59 Requests that the service \a choice be started. The \a password is 62 Requests that the service \a choice be started. The \a password is
60 the password to use if required. 63 the password to use if required.
61*/ 64*/
62void Network::start(const QString& choice, const QString& password) 65void Network::start(const QString& choice, const QString& password)
63{ 66{
64 QCopEnvelope e("QPE/Network", "start(QString,QString)"); 67 QCopEnvelope e("QPE/Network", "start(QString,QString)");
65 e << choice << password; 68 e << choice << password;
66} 69}
67 70
68/*! 71/*!
69 \class Network network.h 72 \class Network network.h
70 \brief The Network class provides network access functionality. 73 \brief The Network class provides network access functionality.
74 \internal
71*/ 75*/
72 76
73// copy the proxy settings of the active config over to the Proxies.conf file 77// copy the proxy settings of the active config over to the Proxies.conf file
74/*! 78/*!
75 \internal 79 \internal
76*/ 80*/
77void Network::writeProxySettings( Config &cfg ) 81void Network::writeProxySettings( Config &cfg )
78{ 82{
79 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); 83 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
80 proxy.setGroup("Properties"); 84 proxy.setGroup("Properties");
81 cfg.setGroup("Proxy"); 85 cfg.setGroup("Proxy");
82 proxy.writeEntry("type", cfg.readEntry("type") ); 86 proxy.writeEntry("type", cfg.readEntry("type") );
83 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); 87 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
84 proxy.writeEntry("httphost", cfg.readEntry("httphost") ); 88 proxy.writeEntry("httphost", cfg.readEntry("httphost") );
85 proxy.writeEntry("httpport", cfg.readEntry("httpport") ); 89 proxy.writeEntry("httpport", cfg.readEntry("httpport") );
86 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); 90 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
87 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); 91 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
88 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); 92 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
89 cfg.setGroup("Properties"); 93 cfg.setGroup("Properties");
90} 94}
91 95
92 96
93 97
94/*! 98/*!
95 \internal 99 \internal
96 100
97 Stops the current network service. 101 Stops the current network service.
98*/ 102*/
99void Network::stop() 103void Network::stop()
100{ 104{
101 QCopEnvelope e("QPE/Network", "stop()"); 105 QCopEnvelope e("QPE/Network", "stop()");
102} 106}
103 107
104static NetworkEmitter *emitter = 0; 108static NetworkEmitter *emitter = 0;
105 109
106/*! 110/*!
107 \internal 111 \internal
108*/ 112*/
109void Network::connectChoiceChange(QObject* receiver, const char* slot) 113void Network::connectChoiceChange(QObject* receiver, const char* slot)
110{ 114{
111 if ( !emitter ) 115 if ( !emitter )
112 emitter = new NetworkEmitter; 116 emitter = new NetworkEmitter;
113 QObject::connect(emitter,SIGNAL(changed()),receiver,slot); 117 QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
114} 118}
115 119
120 #endif// QT_NO_COP
116/*! 121/*!
117 \internal 122 \internal
118*/ 123*/
119QString Network::settingsDir() 124QString Network::settingsDir()
120{ 125{
121 return Global::applicationFileName("Network", "modules"); 126 return Global::applicationFileName("Network", "modules");
122} 127}
123 128
129#ifndef QT_NO_COP
124/*! 130/*!
125 \internal 131 \internal
126*/ 132*/
127QStringList Network::choices(QListBox* lb, const QString& dir) 133QStringList Network::choices(QListBox* lb, const QString& dir)
128{ 134{
129 QStringList list; 135 QStringList list;
130 136
131 if ( lb ) 137 if ( lb )
132 lb->clear(); 138 lb->clear();
133 139
134 QString adir = dir.isEmpty() ? settingsDir() : dir; 140 QString adir = dir.isEmpty() ? settingsDir() : dir;
135 QDir settingsdir(adir); 141 QDir settingsdir(adir);
136 settingsdir.mkdir(adir); 142 settingsdir.mkdir(adir);
137 143
138 QStringList files = settingsdir.entryList("*.conf"); 144 QStringList files = settingsdir.entryList("*.conf");
139 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { 145 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
140 QString filename = settingsdir.filePath(*it); 146 QString filename = settingsdir.filePath(*it);
141 Config cfg(filename, Config::File); 147 Config cfg(filename, Config::File);
142 cfg.setGroup("Info"); 148 cfg.setGroup("Info");
143 if ( lb ) 149 if ( lb )
144 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), 150 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
145 cfg.readEntry("Name")); 151 cfg.readEntry("Name"));
146 list.append(filename); 152 list.append(filename);
147 } 153 }
148 154
149 return list; 155 return list;
150} 156}
151 157
152class NetworkServer : public QCopChannel { 158class NetworkServer : public QCopChannel {
153 Q_OBJECT 159 Q_OBJECT
154public: 160public:
155 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent) 161 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
156 { 162 {
157 up = FALSE; 163 up = FALSE;
158 examineNetworks( TRUE ); 164 examineNetworks( TRUE );
159 QCopChannel* card = new QCopChannel("QPE/Card",parent); 165 QCopChannel* card = new QCopChannel("QPE/Card",parent);
160 connect(card,SIGNAL(received(const QCString &, const QByteArray&)), 166 connect(card,SIGNAL(received(const QCString &, const QByteArray&)),
161 this,SLOT(cardMessage(const QCString &, const QByteArray&))); 167 this,SLOT(cardMessage(const QCString &, const QByteArray&)));
162 } 168 }
163 169
164 ~NetworkServer() 170 ~NetworkServer()
165 { 171 {
166 stop(); 172 stop();
167 } 173 }
168 174
169 bool networkOnline() const 175 bool networkOnline() const
170 { 176 {
171 return up; 177 return up;
172 } 178 }
173 179
174private: 180private:
175 void receive(const QCString &msg, const QByteArray& data) 181 void receive(const QCString &msg, const QByteArray& data)
176 { 182 {
177 if ( msg == "start(QString,QString)" ) { 183 if ( msg == "start(QString,QString)" ) {
178 QDataStream stream(data,IO_ReadOnly); 184 QDataStream stream(data,IO_ReadOnly);
179 QString file,password; 185 QString file,password;
180 stream >> file >> password; 186 stream >> file >> password;
181 if ( file.isEmpty() ) { 187 if ( file.isEmpty() ) {
182 QStringList l = Network::choices(); 188 QStringList l = Network::choices();
183 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { 189 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
184 Config cfg(*i,Config::File); 190 Config cfg(*i,Config::File);
185 cfg.setGroup("Info"); 191 cfg.setGroup("Info");
186 QString type = cfg.readEntry("Type"); 192 QString type = cfg.readEntry("Type");
187 NetworkInterface* plugin = Network::loadPlugin(type); 193 NetworkInterface* plugin = Network::loadPlugin(type);
188 cfg.setGroup("Properties"); 194 cfg.setGroup("Properties");
189 if ( plugin && plugin->isAvailable(cfg) ) { 195 if ( plugin && plugin->isAvailable(cfg) ) {
190 file = *i; 196 file = *i;
191 break; 197 break;
192 } 198 }
193 } 199 }
194 if ( file.isEmpty() ) { 200 if ( file.isEmpty() ) {
195 QCopEnvelope("QPE/Network", "failed()"); 201 QCopEnvelope("QPE/Network", "failed()");
196 return; 202 return;
197 } 203 }
198 } 204 }
199 start(file,password); 205 start(file,password);
200 } else if ( msg == "stop()" ) { 206 } else if ( msg == "stop()" ) {
201 stop(); 207 stop();
202 } else if ( msg == "choicesChanged()" ) { 208 } else if ( msg == "choicesChanged()" ) {
203 examineNetworks(); 209 examineNetworks();
@@ -392,48 +398,49 @@ int Network::addStateWidgets(QWidget* parent)
392 QString type = cfg.readEntry("Type"); 398 QString type = cfg.readEntry("Type");
393 NetworkInterface* plugin = Network::loadPlugin(type); 399 NetworkInterface* plugin = Network::loadPlugin(type);
394 cfg.setGroup("Properties"); 400 cfg.setGroup("Properties");
395 if ( plugin ) { 401 if ( plugin ) {
396 QWidget* w; 402 QWidget* w;
397 if ( (w=plugin->addStateWidget(parent,cfg)) ) { 403 if ( (w=plugin->addStateWidget(parent,cfg)) ) {
398 n++; 404 n++;
399 vb->addWidget(w); 405 vb->addWidget(w);
400 } 406 }
401 } 407 }
402 } 408 }
403 return n; 409 return n;
404} 410}
405 411
406static QDict<NetworkInterface> *ifaces; 412static QDict<NetworkInterface> *ifaces;
407 413
408/*! 414/*!
409 \internal 415 \internal
410*/ 416*/
411NetworkInterface* Network::loadPlugin(const QString& type) 417NetworkInterface* Network::loadPlugin(const QString& type)
412{ 418{
413#ifndef QT_NO_COMPONENT 419#ifndef QT_NO_COMPONENT
414 if ( !ifaces ) ifaces = new QDict<NetworkInterface>; 420 if ( !ifaces ) ifaces = new QDict<NetworkInterface>;
415 NetworkInterface *iface = ifaces->find(type); 421 NetworkInterface *iface = ifaces->find(type);
416 if ( !iface ) { 422 if ( !iface ) {
417 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; 423 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so";
418 QLibrary lib(libfile); 424 QLibrary lib(libfile);
419 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) 425 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK )
420 return 0; 426 return 0;
421 ifaces->insert(type,iface); 427 ifaces->insert(type,iface);
422 QStringList langs = Global::languageList(); 428 QStringList langs = Global::languageList();
423 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 429 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
424 QString lang = *it; 430 QString lang = *it;
425 QTranslator * trans = new QTranslator(qApp); 431 QTranslator * trans = new QTranslator(qApp);
426 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; 432 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm";
427 if ( trans->load( tfn )) 433 if ( trans->load( tfn ))
428 qApp->installTranslator( trans ); 434 qApp->installTranslator( trans );
429 else 435 else
430 delete trans; 436 delete trans;
431 } 437 }
432 } 438 }
433 return iface; 439 return iface;
434#else 440#else
435 return 0; 441 return 0;
436#endif 442#endif
437} 443}
438 444
439#include "network.moc" 445#include "network.moc"
446 #endif// QT_NO_COP