summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/mainwindowimp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index b0a1dd9..1e16b97 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,464 +1,464 @@
1 1
2#include "mainwindowimp.h" 2#include "mainwindowimp.h"
3#include "addconnectionimp.h" 3#include "addconnectionimp.h"
4#include "interfaceinformationimp.h" 4#include "interfaceinformationimp.h"
5#include "interfacesetupimp.h" 5#include "interfacesetupimp.h"
6#include "interfaces.h" 6#include "interfaces.h"
7#include "module.h" 7#include "module.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <qpe/qcopenvelope_qws.h> 10#include <qpe/qcopenvelope_qws.h>
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12#include <qpe/config.h> 12#include <qpe/config.h>
13#include <qpe/qlibrary.h> 13#include <qpe/qlibrary.h>
14#include <qpe/resource.h> 14#include <qpe/resource.h>
15 15
16/* QT */ 16/* QT */
17#include <qpushbutton.h> 17#include <qpushbutton.h>
18#include <qlistbox.h> 18#include <qlistbox.h>
19#include <qlineedit.h> 19#include <qlineedit.h>
20#include <qlistview.h> 20#include <qlistview.h>
21#include <qheader.h> 21#include <qheader.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qtabwidget.h> // in order to disable the profiles tab 23#include <qtabwidget.h> // in order to disable the profiles tab
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25 25
26 26
27#if QT_VERSION < 300 27#if QT_VERSION < 300
28#include <qlist.h> 28#include <qlist.h>
29#else 29#else
30#include <qptrlist.h> 30#include <qptrlist.h>
31#endif 31#endif
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qtextstream.h> 34#include <qtextstream.h>
35#include <qregexp.h> 35#include <qregexp.h>
36 36
37/* STD */ 37/* STD */
38#include <net/if.h> 38#include <net/if.h>
39#include <sys/ioctl.h> 39#include <sys/ioctl.h>
40#include <sys/socket.h> 40#include <sys/socket.h>
41 41
42#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 42#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
43#define _PROCNETDEV "/proc/net/dev" 43#define _PROCNETDEV "/proc/net/dev"
44 44
45MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 45MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
46{ 46{
47 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 47 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
48 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 48 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
49 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 49 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
50 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 50 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
51 51
52 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 52 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
53 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 53 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
54 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 54 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
55 55
56 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 56 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
57 57
58 //FIXME: disable profiles for the moment: 58 //FIXME: disable profiles for the moment:
59 tabWidget->setTabEnabled( tab, false ); 59 tabWidget->setTabEnabled( tab, false );
60 60
61 // Load connections. 61 // Load connections.
62 // /usr/local/kde/lib/libinterfaces.la 62 // /usr/local/kde/lib/libinterfaces.la
63#ifdef QWS 63#ifdef QWS
64 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 64 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
65#else 65#else
66 loader = KLibLoader::self(); 66 loader = KLibLoader::self();
67 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); 67 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib"));
68#endif 68#endif
69 getAllInterfaces(); 69 getAllInterfaces();
70 70
71 Interfaces i; 71 Interfaces i;
72 QStringList list = i.getInterfaceList(); 72 QStringList list = i.getInterfaceList();
73 QMap<QString, Interface*>::Iterator it; 73 QMap<QString, Interface*>::Iterator it;
74 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 74 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
75 { 75 {
76 /* 76 /*
77 * we skipped it in getAllInterfaces now 77 * we skipped it in getAllInterfaces now
78 * we need to ignore it as well 78 * we need to ignore it as well
79 */ 79 */
80 if (m_handledIfaces.contains( *ni) ) 80 if (m_handledIfaces.contains( *ni) )
81 { 81 {
82 qDebug("Not up iface handled by module"); 82 qDebug("Not up iface handled by module");
83 continue; 83 continue;
84 } 84 }
85 bool found = false; 85 bool found = false;
86 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 86 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
87 { 87 {
88 if(it.key() == (*ni)) 88 if(it.key() == (*ni))
89 found = true; 89 found = true;
90 } 90 }
91 if(!found) 91 if(!found)
92 { 92 {
93 if(!(*ni).contains("_")) 93 if(!(*ni).contains("_"))
94 { 94 {
95 Interface *i = new Interface(this, *ni, false); 95 Interface *i = new Interface(this, *ni, false);
96 i->setAttached(false); 96 i->setAttached(false);
97 i->setHardwareName(tr("Disconnected")); 97 i->setHardwareName(tr("Disconnected"));
98 interfaceNames.insert(i->getInterfaceName(), i); 98 interfaceNames.insert(i->getInterfaceName(), i);
99 updateInterface(i); 99 updateInterface(i);
100 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 100 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
101 } 101 }
102 } 102 }
103 } 103 }
104 104
105 //getInterfaceList(); 105 //getInterfaceList();
106 connectionList->header()->hide(); 106 connectionList->header()->hide();
107 107
108 Config cfg("NetworkSetup"); 108 Config cfg("NetworkSetup");
109 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 109 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
110 for ( QStringList::Iterator it = profiles.begin(); 110 for ( QStringList::Iterator it = profiles.begin();
111 it != profiles.end(); ++it) 111 it != profiles.end(); ++it)
112 profilesList->insertItem((*it)); 112 profilesList->insertItem((*it));
113 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 113 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
114 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 114 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
115 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 115 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
116 116
117 QFile file(scheme); 117 QFile file(scheme);
118 if ( file.open(IO_ReadOnly) ) 118 if ( file.open(IO_ReadOnly) )
119 { // file opened successfully 119 { // file opened successfully
120 QTextStream stream( &file ); // use a text stream 120 QTextStream stream( &file ); // use a text stream
121 while ( !stream.eof() ) 121 while ( !stream.eof() )
122 { // until end of file... 122 { // until end of file...
123 QString line = stream.readLine(); // line of text excluding '\n' 123 QString line = stream.readLine(); // line of text excluding '\n'
124 if(line.contains("SCHEME")) 124 if(line.contains("SCHEME"))
125 { 125 {
126 line = line.mid(7, line.length()); 126 line = line.mid(7, line.length());
127 currentProfileLabel->setText(line); 127 currentProfileLabel->setText(line);
128 break; 128 break;
129 } 129 }
130 } 130 }
131 file.close(); 131 file.close();
132 } 132 }
133 makeChannel(); 133 makeChannel();
134} 134}
135 135
136/** 136/**
137 * Deconstructor. Save profiles. Delete loaded libraries. 137 * Deconstructor. Save profiles. Delete loaded libraries.
138 */ 138 */
139MainWindowImp::~MainWindowImp() 139MainWindowImp::~MainWindowImp()
140{ 140{
141 // Save profiles. 141 // Save profiles.
142 Config cfg("NetworkSetup"); 142 Config cfg("NetworkSetup");
143 cfg.setGroup("General"); 143 cfg.setGroup("General");
144 cfg.writeEntry("Profiles", profiles.join(" ")); 144 cfg.writeEntry("Profiles", profiles.join(" "));
145 145
146 // Delete all interfaces that don't have owners. 146 // Delete all interfaces that don't have owners.
147 QMap<Interface*, QListViewItem*>::Iterator iIt; 147 QMap<Interface*, QListViewItem*>::Iterator iIt;
148 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 148 for( iIt = items.begin(); iIt != items.end(); ++iIt )
149 { 149 {
150 if(iIt.key()->getModuleOwner() == NULL) 150 if(iIt.key()->getModuleOwner() == NULL)
151 delete iIt.key(); 151 delete iIt.key();
152 } 152 }
153 153
154#ifdef QWS 154#ifdef QWS
155 // Delete Modules and Libraries 155 // Delete Modules and Libraries
156 QMap<Module*, QLibrary*>::Iterator it; 156 QMap<Module*, QLibrary*>::Iterator it;
157 for( it = libraries.begin(); it != libraries.end(); ++it ) 157 for( it = libraries.begin(); it != libraries.end(); ++it )
158 { 158 {
159 delete it.key(); 159 delete it.key();
160 // I wonder why I can't delete the libraries 160 // I wonder why I can't delete the libraries
161 // What fucking shit this is. 161 // What fucking shit this is.
162 //delete it.data(); 162 //delete it.data();
163 } 163 }
164#else 164#else
165 // klibloader automaticly deletes the libraries for us... 165 // klibloader automaticly deletes the libraries for us...
166#endif 166#endif
167} 167}
168 168
169/** 169/**
170 * Query the kernel for all of the interfaces. 170 * Query the kernel for all of the interfaces.
171 */ 171 */
172void MainWindowImp::getAllInterfaces() 172void MainWindowImp::getAllInterfaces()
173{ 173{
174 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 174 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
175 if(sockfd == -1) 175 if(sockfd == -1)
176 return; 176 return;
177 177
178 struct ifreq ifr; 178 struct ifreq ifr;
179 QStringList ifaces; 179 QStringList ifaces;
180 QFile procFile(QString(_PROCNETDEV)); 180 QFile procFile(QString(_PROCNETDEV));
181 int result; 181 int result;
182 Interface *i; 182 Interface *i;
183 183
184 if (! procFile.exists()) 184 if (! procFile.exists())
185 { 185 {
186 struct ifreq ifrs[100]; 186 struct ifreq ifrs[100];
187 struct ifconf ifc; 187 struct ifconf ifc;
188 ifc.ifc_len = sizeof(ifrs); 188 ifc.ifc_len = sizeof(ifrs);
189 ifc.ifc_req = ifrs; 189 ifc.ifc_req = ifrs;
190 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 190 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
191 191
192 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 192 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
193 { 193 {
194 struct ifreq *pifr = &ifrs[i]; 194 struct ifreq *pifr = &ifrs[i];
195 195
196 ifaces += pifr->ifr_name; 196 ifaces += pifr->ifr_name;
197 } 197 }
198 } 198 }
199 else 199 else
200 { 200 {
201 procFile.open(IO_ReadOnly); 201 procFile.open(IO_ReadOnly);
202 QString line; 202 QString line;
203 QTextStream procTs(&procFile); 203 QTextStream procTs(&procFile);
204 int loc = -1; 204 int loc = -1;
205 205
206 procTs.readLine(); // eat a line 206 procTs.readLine(); // eat a line
207 procTs.readLine(); // eat a line 207 procTs.readLine(); // eat a line
208 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 208 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
209 { 209 {
210 if((loc = line.find(":")) != -1) 210 if((loc = line.find(":")) != -1)
211 { 211 {
212 ifaces += line.left(loc); 212 ifaces += line.left(loc);
213 } 213 }
214 } 214 }
215 } 215 }
216 216
217 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 217 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
218 { 218 {
219 int flags = 0; 219 int flags = 0;
220 if ( m_handledIfaces.contains( (*it) ) ) 220 if ( m_handledIfaces.contains( (*it) ) )
221 { 221 {
222 qDebug(" %s is handled by a module", (*it).latin1() ); 222 qDebug(" %s is handled by a module", (*it).latin1() );
223 continue; 223 continue;
224 } 224 }
225 // int family; 225 // int family;
226 i = NULL; 226 i = NULL;
227 227
228 strcpy(ifr.ifr_name, (*it).latin1()); 228 strcpy(ifr.ifr_name, (*it).latin1());
229 229
230 struct ifreq ifcopy; 230 struct ifreq ifcopy;
231 ifcopy = ifr; 231 ifcopy = ifr;
232 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 232 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
233 flags = ifcopy.ifr_flags; 233 flags = ifcopy.ifr_flags;
234 i = new Interface(this, ifr.ifr_name, false); 234 i = new Interface(this, ifr.ifr_name, false);
235 i->setAttached(true); 235 i->setAttached(true);
236 if ((flags & IFF_UP) == IFF_UP) 236 if ((flags & IFF_UP) == IFF_UP)
237 i->setStatus(true); 237 i->setStatus(true);
238 else 238 else
239 i->setStatus(false); 239 i->setStatus(false);
240 240
241 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 241 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
242 i->setHardwareName("Ethernet"); 242 i->setHardwareName("Ethernet");
243 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 243 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
244 i->setHardwareName("Point to Point"); 244 i->setHardwareName("Point to Point");
245 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 245 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
246 i->setHardwareName("Multicast"); 246 i->setHardwareName("Multicast");
247 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 247 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
248 i->setHardwareName("Loopback"); 248 i->setHardwareName("Loopback");
249 else 249 else
250 i->setHardwareName("Unknown"); 250 i->setHardwareName("Unknown");
251 251
252 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); 252 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
253 interfaceNames.insert(i->getInterfaceName(), i); 253 interfaceNames.insert(i->getInterfaceName(), i);
254 updateInterface(i); 254 updateInterface(i);
255 connect(i, SIGNAL(updateInterface(Interface *)), 255 connect(i, SIGNAL(updateInterface(Interface*)),
256 this, SLOT(updateInterface(Interface *))); 256 this, SLOT(updateInterface(Interface*)));
257 } 257 }
258 // now lets ask the plugins too ;) 258 // now lets ask the plugins too ;)
259 QMap<Module*, QLibrary*>::Iterator it; 259 QMap<Module*, QLibrary*>::Iterator it;
260 QList<Interface> ilist; 260 QList<Interface> ilist;
261 for( it = libraries.begin(); it != libraries.end(); ++it ) 261 for( it = libraries.begin(); it != libraries.end(); ++it )
262 { 262 {
263 if(it.key()) 263 if(it.key())
264 { 264 {
265 ilist = it.key()->getInterfaces(); 265 ilist = it.key()->getInterfaces();
266 for( i = ilist.first(); i != 0; i = ilist.next() ) 266 for( i = ilist.first(); i != 0; i = ilist.next() )
267 { 267 {
268 qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() ); 268 qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() );
269 interfaceNames.insert(i->getInterfaceName(), i); 269 interfaceNames.insert(i->getInterfaceName(), i);
270 updateInterface(i); 270 updateInterface(i);
271 connect(i, SIGNAL(updateInterface(Interface *)), 271 connect(i, SIGNAL(updateInterface(Interface*)),
272 this, SLOT(updateInterface(Interface *))); 272 this, SLOT(updateInterface(Interface*)));
273 } 273 }
274 } 274 }
275 } 275 }
276} 276}
277 277
278/** 278/**
279 * Load all modules that are found in the path 279 * Load all modules that are found in the path
280 * @param path a directory that is scaned for any plugins that can be loaded 280 * @param path a directory that is scaned for any plugins that can be loaded
281 * and attempts to load them 281 * and attempts to load them
282 */ 282 */
283void MainWindowImp::loadModules(const QString &path) 283void MainWindowImp::loadModules(const QString &path)
284{ 284{
285#ifdef DEBUG 285#ifdef DEBUG
286 qDebug("MainWindowImp::loadModules: %s", path.latin1()); 286 qDebug("MainWindowImp::loadModules: %s", path.latin1());
287#endif 287#endif
288 QDir d(path); 288 QDir d(path);
289 if(!d.exists()) 289 if(!d.exists())
290 return; 290 return;
291 291
292 // Don't want sym links 292 // Don't want sym links
293 d.setFilter( QDir::Files | QDir::NoSymLinks ); 293 d.setFilter( QDir::Files | QDir::NoSymLinks );
294 const QFileInfoList *list = d.entryInfoList(); 294 const QFileInfoList *list = d.entryInfoList();
295 QFileInfoListIterator it( *list ); 295 QFileInfoListIterator it( *list );
296 QFileInfo *fi; 296 QFileInfo *fi;
297 while ( (fi=it.current()) ) 297 while ( (fi=it.current()) )
298 { 298 {
299#ifdef QWS 299#ifdef QWS
300 if(fi->fileName().contains(".so")) 300 if(fi->fileName().contains(".so"))
301 { 301 {
302#else 302#else
303 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")) 303 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_"))
304 { 304 {
305#endif 305#endif
306 loadPlugin(path + "/" + fi->fileName()); 306 loadPlugin(path + "/" + fi->fileName());
307 qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1()); 307 qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1());
308 } 308 }
309 ++it; 309 ++it;
310 } 310 }
311} 311}
312 312
313/** 313/**
314 * Attempt to load a function and resolve a function. 314 * Attempt to load a function and resolve a function.
315 * @param pluginFileName - the name of the file in which to attempt to load 315 * @param pluginFileName - the name of the file in which to attempt to load
316 * @param resolveString - function pointer to resolve 316 * @param resolveString - function pointer to resolve
317 * @return pointer to the function with name resolveString or NULL 317 * @return pointer to the function with name resolveString or NULL
318 */ 318 */
319Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 319Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
320{ 320{
321#ifdef DEBUG 321#ifdef DEBUG
322 qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1()); 322 qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1());
323#endif 323#endif
324#ifdef QWS 324#ifdef QWS
325 QLibrary *lib = new QLibrary(pluginFileName); 325 QLibrary *lib = new QLibrary(pluginFileName);
326 void *functionPointer = lib->resolve(resolveString); 326 void *functionPointer = lib->resolve(resolveString);
327 if( !functionPointer ) 327 if( !functionPointer )
328 { 328 {
329#ifdef DEBUG 329#ifdef DEBUG
330 qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1()); 330 qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1());
331#endif 331#endif
332 delete lib; 332 delete lib;
333 return NULL; 333 return NULL;
334 } 334 }
335 // Try to get an object. 335 // Try to get an object.
336 Module *object = ((Module* (*)()) functionPointer)(); 336 Module *object = ((Module* (*)()) functionPointer)();
337 if(object == NULL) 337 if(object == NULL)
338 { 338 {
339#ifdef DEBUG 339#ifdef DEBUG
340 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 340 qDebug("MainWindowImp: Couldn't create object, but did load library!");
341#endif 341#endif
342 delete lib; 342 delete lib;
343 return NULL; 343 return NULL;
344 } 344 }
345 345
346 m_handledIfaces += object->handledInterfaceNames(); 346 m_handledIfaces += object->handledInterfaceNames();
347 // Store for deletion later 347 // Store for deletion later
348 libraries.insert(object, lib); 348 libraries.insert(object, lib);
349 return object; 349 return object;
350 350
351#else 351#else
352 QLibrary *lib = loader->library(pluginFileName); 352 QLibrary *lib = loader->library(pluginFileName);
353 if( !lib || !lib->hasSymbol(resolveString) ) 353 if( !lib || !lib->hasSymbol(resolveString) )
354 { 354 {
355 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 355 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
356 return NULL; 356 return NULL;
357 } 357 }
358 // Try to get an object. 358 // Try to get an object.
359 Module *object = ((Module* (*)()) lib->symbol(resolveString))(); 359 Module *object = ((Module* (*)()) lib->symbol(resolveString))();
360 if(object == NULL) 360 if(object == NULL)
361 { 361 {
362#ifdef DEBUG 362#ifdef DEBUG
363 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 363 qDebug("MainWindowImp: Couldn't create object, but did load library!");
364#endif 364#endif
365 return NULL; 365 return NULL;
366 } 366 }
367#ifdef DEBUG 367#ifdef DEBUG
368 qDebug("MainWindowImp::loadPlugin:: Found object, storing."); 368 qDebug("MainWindowImp::loadPlugin:: Found object, storing.");
369#endif 369#endif
370 // Store for deletion later 370 // Store for deletion later
371 libraries.insert(object, lib); 371 libraries.insert(object, lib);
372 return object; 372 return object;
373#endif 373#endif
374} 374}
375 375
376/** 376/**
377 * The Add button was clicked. Bring up the add dialog and if OK is hit 377 * The Add button was clicked. Bring up the add dialog and if OK is hit
378 * load the plugin and append it to the list 378 * load the plugin and append it to the list
379 */ 379 */
380void MainWindowImp::addClicked() 380void MainWindowImp::addClicked()
381{ 381{
382 QMap<Module*, QLibrary*>::Iterator it; 382 QMap<Module*, QLibrary*>::Iterator it;
383 QMap<QString, QString> list; 383 QMap<QString, QString> list;
384 QMap<QString, Module*> newInterfaceOwners; 384 QMap<QString, Module*> newInterfaceOwners;
385 385
386 for( it = libraries.begin(); it != libraries.end(); ++it ) 386 for( it = libraries.begin(); it != libraries.end(); ++it )
387 { 387 {
388 if(it.key()) 388 if(it.key())
389 { 389 {
390 (it.key())->possibleNewInterfaces(list); 390 (it.key())->possibleNewInterfaces(list);
391 } 391 }
392 } 392 }
393 // See if the list has anything that we can add. 393 // See if the list has anything that we can add.
394 if(list.count() == 0) 394 if(list.count() == 0)
395 { 395 {
396 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 396 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
397 return; 397 return;
398 } 398 }
399 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 399 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
400 addNewConnection.addConnections(list); 400 addNewConnection.addConnections(list);
401 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 401 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
402 { 402 {
403 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 403 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
404 if(!item) 404 if(!item)
405 return; 405 return;
406 406
407 for( it = libraries.begin(); it != libraries.end(); ++it ) 407 for( it = libraries.begin(); it != libraries.end(); ++it )
408 { 408 {
409 if(it.key()) 409 if(it.key())
410 { 410 {
411 Interface *i = (it.key())->addNewInterface(item->text(0)); 411 Interface *i = (it.key())->addNewInterface(item->text(0));
412 if(i) 412 if(i)
413 { 413 {
414 qDebug("iface name %s",i->getInterfaceName().latin1()); 414 qDebug("iface name %s",i->getInterfaceName().latin1());
415 interfaceNames.insert(i->getInterfaceName(), i); 415 interfaceNames.insert(i->getInterfaceName(), i);
416 updateInterface(i); 416 updateInterface(i);
417 } 417 }
418 } 418 }
419 } 419 }
420 } 420 }
421} 421}
422 422
423/** 423/**
424 * Prompt the user to see if they really want to do this. 424 * Prompt the user to see if they really want to do this.
425 * If they do then remove from the list and unload. 425 * If they do then remove from the list and unload.
426 */ 426 */
427void MainWindowImp::removeClicked() 427void MainWindowImp::removeClicked()
428{ 428{
429 QListViewItem *item = connectionList->currentItem(); 429 QListViewItem *item = connectionList->currentItem();
430 if(!item) 430 if(!item)
431 { 431 {
432 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 432 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
433 return; 433 return;
434 } 434 }
435 435
436 Interface *i = interfaceItems[item]; 436 Interface *i = interfaceItems[item];
437 if(i->getModuleOwner() == NULL) 437 if(i->getModuleOwner() == NULL)
438 { 438 {
439 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 439 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
440 } 440 }
441 else 441 else
442 { 442 {
443 if(!i->getModuleOwner()->remove(i)) 443 if(!i->getModuleOwner()->remove(i))
444 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 444 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
445 else 445 else
446 { 446 {
447 delete item; 447 delete item;
448 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 448 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
449 } 449 }
450 } 450 }
451} 451}
452 452
453/** 453/**
454 * Pull up the configure about the currently selected interface. 454 * Pull up the configure about the currently selected interface.
455 * Report an error if no interface is selected. 455 * Report an error if no interface is selected.
456 * If the interface has a module owner then request its configure. 456 * If the interface has a module owner then request its configure.
457 */ 457 */
458void MainWindowImp::configureClicked() 458void MainWindowImp::configureClicked()
459{ 459{
460 QListViewItem *item = connectionList->currentItem(); 460 QListViewItem *item = connectionList->currentItem();
461 if(!item) 461 if(!item)
462 { 462 {
463 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 463 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
464 return; 464 return;
@@ -523,226 +523,226 @@ void MainWindowImp::informationClicked()
523} 523}
524 524
525/** 525/**
526 * Update this interface. If no QListViewItem exists create one. 526 * Update this interface. If no QListViewItem exists create one.
527 * @param Interface* pointer to the interface that needs to be updated. 527 * @param Interface* pointer to the interface that needs to be updated.
528 */ 528 */
529void MainWindowImp::updateInterface(Interface *i) 529void MainWindowImp::updateInterface(Interface *i)
530{ 530{
531 if(!advancedUserMode) 531 if(!advancedUserMode)
532 { 532 {
533 if(i->getInterfaceName() == "lo") 533 if(i->getInterfaceName() == "lo")
534 return; 534 return;
535 } 535 }
536 536
537 QListViewItem *item = NULL; 537 QListViewItem *item = NULL;
538 538
539 // Find the interface, making it if needed. 539 // Find the interface, making it if needed.
540 if(items.find(i) == items.end()) 540 if(items.find(i) == items.end())
541 { 541 {
542 item = new QListViewItem(connectionList, "", "", ""); 542 item = new QListViewItem(connectionList, "", "", "");
543 // See if you can't find a module owner for this interface 543 // See if you can't find a module owner for this interface
544 QMap<Module*, QLibrary*>::Iterator it; 544 QMap<Module*, QLibrary*>::Iterator it;
545 for( it = libraries.begin(); it != libraries.end(); ++it ) 545 for( it = libraries.begin(); it != libraries.end(); ++it )
546 { 546 {
547 if(it.key()->isOwner(i)) 547 if(it.key()->isOwner(i))
548 i->setModuleOwner(it.key()); 548 i->setModuleOwner(it.key());
549 } 549 }
550 items.insert(i, item); 550 items.insert(i, item);
551 interfaceItems.insert(item, i); 551 interfaceItems.insert(item, i);
552 } 552 }
553 else 553 else
554 item = items[i]; 554 item = items[i];
555 555
556 // Update the icons and information 556 // Update the icons and information
557#ifdef QWS 557#ifdef QWS
558 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 558 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
559#else 559#else
560 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 560 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
561#endif 561#endif
562 562
563 QString typeName = "lan"; 563 QString typeName = "lan";
564 if(i->getInterfaceName() == "lo") 564 if(i->getInterfaceName() == "lo")
565 typeName = "lo"; 565 typeName = "lo";
566 if(i->getInterfaceName().contains("irda")) 566 if(i->getInterfaceName().contains("irda"))
567 typeName = "irda"; 567 typeName = "irda";
568 if(i->getInterfaceName().contains("wlan")) 568 if(i->getInterfaceName().contains("wlan"))
569 typeName = "wlan"; 569 typeName = "wlan";
570 if(i->getInterfaceName().contains("usb")) 570 if(i->getInterfaceName().contains("usb"))
571 typeName = "usb"; 571 typeName = "usb";
572 572
573 if(!i->isAttached()) 573 if(!i->isAttached())
574 typeName = "connect_no"; 574 typeName = "connect_no";
575 // Actually try to use the Module 575 // Actually try to use the Module
576 if(i->getModuleOwner() != NULL) 576 if(i->getModuleOwner() != NULL)
577 typeName = i->getModuleOwner()->getPixmapName(i); 577 typeName = i->getModuleOwner()->getPixmapName(i);
578 578
579#ifdef QWS 579#ifdef QWS
580 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 580 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
581#else 581#else
582 item->setPixmap(1, (SmallIcon(typeName))); 582 item->setPixmap(1, (SmallIcon(typeName)));
583#endif 583#endif
584 item->setText(2, i->getHardwareName()); 584 item->setText(2, i->getHardwareName());
585 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 585 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
586 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 586 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
587} 587}
588 588
589void MainWindowImp::newProfileChanged(const QString& newText) 589void MainWindowImp::newProfileChanged(const QString& newText)
590{ 590{
591 if(newText.length() > 0) 591 if(newText.length() > 0)
592 newProfileButton->setEnabled(true); 592 newProfileButton->setEnabled(true);
593 else 593 else
594 newProfileButton->setEnabled(false); 594 newProfileButton->setEnabled(false);
595} 595}
596 596
597/** 597/**
598 * Adds a new profile to the list of profiles. 598 * Adds a new profile to the list of profiles.
599 * Don't add profiles that already exists. 599 * Don't add profiles that already exists.
600 * Appends to the list and QStringList 600 * Appends to the list and QStringList
601 */ 601 */
602void MainWindowImp::addProfile() 602void MainWindowImp::addProfile()
603{ 603{
604 QString newProfileName = newProfile->text(); 604 QString newProfileName = newProfile->text();
605 if(profiles.grep(newProfileName).count() > 0) 605 if(profiles.grep(newProfileName).count() > 0)
606 { 606 {
607 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 607 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
608 return; 608 return;
609 } 609 }
610 profiles.append(newProfileName); 610 profiles.append(newProfileName);
611 profilesList->insertItem(newProfileName); 611 profilesList->insertItem(newProfileName);
612} 612}
613 613
614/** 614/**
615 * Removes the currently selected profile in the combo. 615 * Removes the currently selected profile in the combo.
616 * Doesn't delete if there are less then 2 profiles. 616 * Doesn't delete if there are less then 2 profiles.
617 */ 617 */
618void MainWindowImp::removeProfile() 618void MainWindowImp::removeProfile()
619{ 619{
620 if(profilesList->count() <= 1) 620 if(profilesList->count() <= 1)
621 { 621 {
622 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 622 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
623 return; 623 return;
624 } 624 }
625 QString profileToRemove = profilesList->currentText(); 625 QString profileToRemove = profilesList->currentText();
626 if(profileToRemove == "All") 626 if(profileToRemove == "All")
627 { 627 {
628 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 628 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
629 return; 629 return;
630 } 630 }
631 // Can't remove the curent profile 631 // Can't remove the curent profile
632 if(profileToRemove == currentProfileLabel->text()) 632 if(profileToRemove == currentProfileLabel->text())
633 { 633 {
634 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 634 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
635 return; 635 return;
636 636
637 } 637 }
638 638
639 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) 639 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
640 { 640 {
641 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 641 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
642 profilesList->clear(); 642 profilesList->clear();
643 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 643 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
644 profilesList->insertItem((*it)); 644 profilesList->insertItem((*it));
645 645
646 // Remove any interface settings and mappings. 646 // Remove any interface settings and mappings.
647 Interfaces interfaces; 647 Interfaces interfaces;
648 // Go through them one by one 648 // Go through them one by one
649 QMap<Interface*, QListViewItem*>::Iterator it; 649 QMap<Interface*, QListViewItem*>::Iterator it;
650 for( it = items.begin(); it != items.end(); ++it ) 650 for( it = items.begin(); it != items.end(); ++it )
651 { 651 {
652 QString interfaceName = it.key()->getInterfaceName(); 652 QString interfaceName = it.key()->getInterfaceName();
653 qDebug(interfaceName.latin1()); 653 qDebug(interfaceName.latin1());
654 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) 654 if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
655 { 655 {
656 interfaces.removeInterface(); 656 interfaces.removeInterface();
657 if(interfaces.setMapping(interfaceName)) 657 if(interfaces.setMapping(interfaceName))
658 { 658 {
659 if(profilesList->count() == 1) 659 if(profilesList->count() == 1)
660 interfaces.removeMapping(); 660 interfaces.removeMapping();
661 else 661 else
662 { 662 {
663 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 663 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
664 } 664 }
665 } 665 }
666 interfaces.write(); 666 interfaces.write();
667 break; 667 break;
668 } 668 }
669 } 669 }
670 } 670 }
671} 671}
672 672
673/** 673/**
674 * A new profile has been selected, change. 674 * A new profile has been selected, change.
675 * @param newProfile the new profile. 675 * @param newProfile the new profile.
676 */ 676 */
677void MainWindowImp::changeProfile() 677void MainWindowImp::changeProfile()
678{ 678{
679 if(profilesList->currentItem() == -1) 679 if(profilesList->currentItem() == -1)
680 { 680 {
681 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 681 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
682 return; 682 return;
683 } 683 }
684 QString newProfile = profilesList->text(profilesList->currentItem()); 684 QString newProfile = profilesList->text(profilesList->currentItem());
685 if(newProfile != currentProfileLabel->text()) 685 if(newProfile != currentProfileLabel->text())
686 { 686 {
687 currentProfileLabel->setText(newProfile); 687 currentProfileLabel->setText(newProfile);
688 QFile::remove(scheme); 688 QFile::remove(scheme);
689 QFile file(scheme); 689 QFile file(scheme);
690 if ( file.open(IO_ReadWrite) ) 690 if ( file.open(IO_ReadWrite) )
691 { 691 {
692 QTextStream stream( &file ); 692 QTextStream stream( &file );
693 stream << QString("SCHEME=%1").arg(newProfile); 693 stream << QString("SCHEME=%1").arg(newProfile);
694 file.close(); 694 file.close();
695 } 695 }
696 // restart all up devices? 696 // restart all up devices?
697 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 697 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
698 { 698 {
699 // Go through them one by one 699 // Go through them one by one
700 QMap<Interface*, QListViewItem*>::Iterator it; 700 QMap<Interface*, QListViewItem*>::Iterator it;
701 for( it = items.begin(); it != items.end(); ++it ) 701 for( it = items.begin(); it != items.end(); ++it )
702 { 702 {
703 if(it.key()->getStatus() == true) 703 if(it.key()->getStatus() == true)
704 it.key()->restart(); 704 it.key()->restart();
705 } 705 }
706 } 706 }
707 } 707 }
708 // TODO change the profile in the modules 708 // TODO change the profile in the modules
709} 709}
710 710
711 711
712void MainWindowImp::makeChannel() 712void MainWindowImp::makeChannel()
713{ 713{
714 channel = new QCopChannel( "QPE/Application/networksettings", this ); 714 channel = new QCopChannel( "QPE/Application/networksettings", this );
715 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 715 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
716 this, SLOT(receive(const QCString&, const QByteArray&)) ); 716 this, SLOT(receive(const QCString&,const QByteArray&)) );
717} 717}
718 718
719void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 719void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
720{ 720{
721 bool found = false; 721 bool found = false;
722 qDebug("MainWindowImp::receive QCop msg >"+msg+"<"); 722 qDebug("MainWindowImp::receive QCop msg >"+msg+"<");
723 if (msg == "raise") 723 if (msg == "raise")
724 { 724 {
725 raise(); 725 raise();
726 return; 726 return;
727 } 727 }
728 728
729 QString dest = msg.left(msg.find("(")); 729 QString dest = msg.left(msg.find("("));
730 QCString param = msg.right(msg.length() - msg.find("(") - 1); 730 QCString param = msg.right(msg.length() - msg.find("(") - 1);
731 param = param.left( param.length() - 1 ); 731 param = param.left( param.length() - 1 );
732 qDebug("dest >%s< param >"+param+"<",dest.latin1()); 732 qDebug("dest >%s< param >"+param+"<",dest.latin1());
733 733
734 QMap<Module*, QLibrary*>::Iterator it; 734 QMap<Module*, QLibrary*>::Iterator it;
735 for( it = libraries.begin(); it != libraries.end(); ++it ) 735 for( it = libraries.begin(); it != libraries.end(); ++it )
736 { 736 {
737 qDebug("plugin >%s<", it.key()->type().latin1() ); 737 qDebug("plugin >%s<", it.key()->type().latin1() );
738 if(it.key()->type() == dest) 738 if(it.key()->type() == dest)
739 { 739 {
740 it.key()->receive( param, arg ); 740 it.key()->receive( param, arg );
741 found = true; 741 found = true;
742 } 742 }
743 } 743 }
744 744
745 745
746 if (found) QPEApplication::setKeepRunning(); 746 if (found) QPEApplication::setKeepRunning();
747 else qDebug("Huh what do ya want"); 747 else qDebug("Huh what do ya want");
748} 748}