Diffstat (limited to 'noncore/net/networksetup/mainwindowimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 196 |
1 files changed, 92 insertions, 104 deletions
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 7261c58..48ef9b3 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -1,150 +1,235 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addconnectionimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | |||
7 | #include "module.h" | 6 | #include "module.h" |
8 | 7 | ||
9 | #include "kprocess.h" | ||
10 | |||
11 | #include <qpushbutton.h> | 8 | #include <qpushbutton.h> |
12 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
13 | #include <qlineedit.h> | 10 | #include <qlineedit.h> |
14 | #include <qlistview.h> | 11 | #include <qlistview.h> |
15 | #include <qheader.h> | 12 | #include <qheader.h> |
16 | #include <qlabel.h> | 13 | #include <qlabel.h> |
17 | 14 | ||
18 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
19 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
20 | 17 | ||
21 | #include <qpe/config.h> | 18 | #include <qpe/config.h> |
22 | #include <qpe/qlibrary.h> | 19 | #include <qpe/qlibrary.h> |
23 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
24 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
25 | 22 | ||
26 | #include <qlist.h> | 23 | #include <qlist.h> |
27 | #include <qdir.h> | 24 | #include <qdir.h> |
28 | #include <qfile.h> | 25 | #include <qfile.h> |
29 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
30 | 27 | ||
31 | #define TEMP_ALL "/tmp/ifconfig-a" | 28 | #include <net/if.h> |
32 | #define TEMP_UP "/tmp/ifconfig" | 29 | #include <sys/ioctl.h> |
33 | 30 | ||
34 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 31 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
35 | 32 | ||
36 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 33 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
37 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 34 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
38 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 35 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
39 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 36 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
40 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 37 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
41 | 38 | ||
42 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 39 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
43 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 40 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
44 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 41 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
45 | 42 | ||
46 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 43 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
47 | // Load connections. | 44 | // Load connections. |
48 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 45 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
49 | getInterfaceList(); | 46 | getAllInterfaces(); |
50 | connectionList->header()->hide(); | ||
51 | 47 | ||
48 | Interfaces i; | ||
49 | QStringList list = i.getInterfaceList(); | ||
50 | QMap<QString, Interface*>::Iterator it; | ||
51 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | ||
52 | bool found = false; | ||
53 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | ||
54 | if(it.key() == (*ni)) | ||
55 | found = true; | ||
56 | } | ||
57 | if(!found){ | ||
58 | if(!(*ni).contains("_")){ | ||
59 | Interface *i = new Interface(this, *ni, false); | ||
60 | i->setAttached(false); | ||
61 | i->setHardwareName("Disconnected"); | ||
62 | interfaceNames.insert(i->getInterfaceName(), i); | ||
63 | updateInterface(i); | ||
64 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | //getInterfaceList(); | ||
70 | connectionList->header()->hide(); | ||
52 | 71 | ||
53 | Config cfg("NetworkSetup"); | 72 | Config cfg("NetworkSetup"); |
54 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 73 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
55 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 74 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
56 | profilesList->insertItem((*it)); | 75 | profilesList->insertItem((*it)); |
57 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 76 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
58 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 77 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
59 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 78 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
60 | 79 | ||
61 | QFile file(scheme); | 80 | QFile file(scheme); |
62 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 81 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
63 | QTextStream stream( &file ); // use a text stream | 82 | QTextStream stream( &file ); // use a text stream |
64 | while ( !stream.eof() ) { // until end of file... | 83 | while ( !stream.eof() ) { // until end of file... |
65 | QString line = stream.readLine(); // line of text excluding '\n' | 84 | QString line = stream.readLine(); // line of text excluding '\n' |
66 | if(line.contains("SCHEME")){ | 85 | if(line.contains("SCHEME")){ |
67 | line = line.mid(7, line.length()); | 86 | line = line.mid(7, line.length()); |
68 | currentProfileLabel->setText(line); | 87 | currentProfileLabel->setText(line); |
69 | break; | 88 | break; |
70 | } | 89 | } |
71 | } | 90 | } |
72 | file.close(); | 91 | file.close(); |
73 | } | 92 | } |
74 | } | 93 | } |
75 | 94 | ||
76 | /** | 95 | /** |
77 | * Deconstructor. Save profiles. Delete loaded libraries. | 96 | * Deconstructor. Save profiles. Delete loaded libraries. |
78 | */ | 97 | */ |
79 | MainWindowImp::~MainWindowImp(){ | 98 | MainWindowImp::~MainWindowImp(){ |
80 | // Save profiles. | 99 | // Save profiles. |
81 | Config cfg("NetworkSetup"); | 100 | Config cfg("NetworkSetup"); |
82 | cfg.setGroup("General"); | 101 | cfg.setGroup("General"); |
83 | cfg.writeEntry("Profiles", profiles.join(" ")); | 102 | cfg.writeEntry("Profiles", profiles.join(" ")); |
84 | 103 | ||
85 | // Delete all interfaces that don't have owners. | 104 | // Delete all interfaces that don't have owners. |
86 | QMap<Interface*, QListViewItem*>::Iterator iIt; | 105 | QMap<Interface*, QListViewItem*>::Iterator iIt; |
87 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | 106 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ |
88 | if(iIt.key()->getModuleOwner() == NULL) | 107 | if(iIt.key()->getModuleOwner() == NULL) |
89 | delete iIt.key(); | 108 | delete iIt.key(); |
90 | } | 109 | } |
91 | 110 | ||
92 | // Delete Modules and Libraries | 111 | // Delete Modules and Libraries |
93 | QMap<Module*, QLibrary*>::Iterator it; | 112 | QMap<Module*, QLibrary*>::Iterator it; |
94 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 113 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
95 | delete it.key(); | 114 | delete it.key(); |
96 | // I wonder why I can't delete the libraries | 115 | // I wonder why I can't delete the libraries |
97 | // What fucking shit this is. | 116 | // What fucking shit this is. |
98 | //delete it.data(); | 117 | //delete it.data(); |
99 | } | 118 | } |
100 | } | 119 | } |
101 | 120 | ||
102 | /** | 121 | /** |
122 | * Query the kernel for all of the interfaces. | ||
123 | */ | ||
124 | void MainWindowImp::getAllInterfaces(){ | ||
125 | int sockfd = socket(AF_INET, SOCK_DGRAM, 0); | ||
126 | if(sockfd == -1) | ||
127 | return; | ||
128 | |||
129 | char buf[8*1024]; | ||
130 | struct ifconf ifc; | ||
131 | ifc.ifc_len = sizeof(buf); | ||
132 | ifc.ifc_req = (struct ifreq *) buf; | ||
133 | int result=ioctl(sockfd, SIOCGIFCONF, &ifc); | ||
134 | |||
135 | for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ | ||
136 | struct ifreq *ifr =(struct ifreq *) ptr; | ||
137 | int len = sizeof(struct sockaddr); | ||
138 | #ifdef HAVE_SOCKADDR_SA_LEN | ||
139 | if (ifr->ifr_addr.sa_len > len) | ||
140 | len = ifr->ifr_addr.sa_len; /* length > 16 */ | ||
141 | #endif | ||
142 | ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ | ||
143 | |||
144 | int flags; | ||
145 | struct sockaddr_in *sinptr; | ||
146 | Interface *i = NULL; | ||
147 | switch (ifr->ifr_addr.sa_family){ | ||
148 | case AF_INET: | ||
149 | sinptr = (struct sockaddr_in *) &ifr->ifr_addr; | ||
150 | flags=0; | ||
151 | |||
152 | struct ifreq ifcopy; | ||
153 | ifcopy=*ifr; | ||
154 | result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); | ||
155 | flags=ifcopy.ifr_flags; | ||
156 | i = new Interface(this, ifr->ifr_name, false); | ||
157 | i->setAttached(true); | ||
158 | if ((flags & IFF_UP) == IFF_UP) | ||
159 | i->setStatus(true); | ||
160 | else | ||
161 | i->setStatus(false); | ||
162 | |||
163 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | ||
164 | i->setHardwareName("Ethernet"); | ||
165 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | ||
166 | i->setHardwareName("Point to Point"); | ||
167 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | ||
168 | i->setHardwareName("Multicast"); | ||
169 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | ||
170 | i->setHardwareName("Loopback"); | ||
171 | else | ||
172 | i->setHardwareName("Unknown"); | ||
173 | |||
174 | interfaceNames.insert(i->getInterfaceName(), i); | ||
175 | updateInterface(i); | ||
176 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
177 | break; | ||
178 | |||
179 | default: | ||
180 | qDebug(ifr->ifr_name); | ||
181 | qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | /** | ||
103 | * Load all modules that are found in the path | 188 | * Load all modules that are found in the path |
104 | * @param path a directory that is scaned for any plugins that can be loaded | 189 | * @param path a directory that is scaned for any plugins that can be loaded |
105 | * and attempts to load them | 190 | * and attempts to load them |
106 | */ | 191 | */ |
107 | void MainWindowImp::loadModules(QString path){ | 192 | void MainWindowImp::loadModules(QString path){ |
108 | //qDebug(path.latin1()); | 193 | //qDebug(path.latin1()); |
109 | QDir d(path); | 194 | QDir d(path); |
110 | if(!d.exists()) | 195 | if(!d.exists()) |
111 | return; | 196 | return; |
112 | 197 | ||
113 | // Don't want sym links | 198 | // Don't want sym links |
114 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 199 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
115 | const QFileInfoList *list = d.entryInfoList(); | 200 | const QFileInfoList *list = d.entryInfoList(); |
116 | QFileInfoListIterator it( *list ); | 201 | QFileInfoListIterator it( *list ); |
117 | QFileInfo *fi; | 202 | QFileInfo *fi; |
118 | while ( (fi=it.current()) ) { | 203 | while ( (fi=it.current()) ) { |
119 | if(fi->fileName().contains(".so")){ | 204 | if(fi->fileName().contains(".so")){ |
120 | loadPlugin(path + "/" + fi->fileName()); | 205 | loadPlugin(path + "/" + fi->fileName()); |
121 | } | 206 | } |
122 | ++it; | 207 | ++it; |
123 | } | 208 | } |
124 | } | 209 | } |
125 | 210 | ||
126 | /** | 211 | /** |
127 | * Attempt to load a function and resolve a function. | 212 | * Attempt to load a function and resolve a function. |
128 | * @param pluginFileName - the name of the file in which to attempt to load | 213 | * @param pluginFileName - the name of the file in which to attempt to load |
129 | * @param resolveString - function pointer to resolve | 214 | * @param resolveString - function pointer to resolve |
130 | * @return pointer to the function with name resolveString or NULL | 215 | * @return pointer to the function with name resolveString or NULL |
131 | */ | 216 | */ |
132 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 217 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
133 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 218 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
134 | QLibrary *lib = new QLibrary(pluginFileName); | 219 | QLibrary *lib = new QLibrary(pluginFileName); |
135 | void *functionPointer = lib->resolve(resolveString); | 220 | void *functionPointer = lib->resolve(resolveString); |
136 | if( !functionPointer ){ | 221 | if( !functionPointer ){ |
137 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 222 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
138 | delete lib; | 223 | delete lib; |
139 | return NULL; | 224 | return NULL; |
140 | } | 225 | } |
141 | 226 | ||
142 | // Try to get an object. | 227 | // Try to get an object. |
143 | Module *object = ((Module* (*)()) functionPointer)(); | 228 | Module *object = ((Module* (*)()) functionPointer)(); |
144 | if(object == NULL){ | 229 | if(object == NULL){ |
145 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 230 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
146 | delete lib; | 231 | delete lib; |
147 | return NULL; | 232 | return NULL; |
148 | } | 233 | } |
149 | 234 | ||
150 | // Store for deletion later | 235 | // Store for deletion later |
@@ -236,193 +321,96 @@ void MainWindowImp::configureClicked(){ | |||
236 | if(moduleConfigure != NULL){ | 321 | if(moduleConfigure != NULL){ |
237 | moduleConfigure->showMaximized(); | 322 | moduleConfigure->showMaximized(); |
238 | moduleConfigure->show(); | 323 | moduleConfigure->show(); |
239 | return; | 324 | return; |
240 | } | 325 | } |
241 | } | 326 | } |
242 | 327 | ||
243 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); | 328 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose); |
244 | QString currentProfileText = currentProfileLabel->text(); | 329 | QString currentProfileText = currentProfileLabel->text(); |
245 | if(currentProfileText.upper() == "ALL"); | 330 | if(currentProfileText.upper() == "ALL"); |
246 | currentProfileText = ""; | 331 | currentProfileText = ""; |
247 | configure->setProfile(currentProfileText); | 332 | configure->setProfile(currentProfileText); |
248 | configure->showMaximized(); | 333 | configure->showMaximized(); |
249 | configure->show(); | 334 | configure->show(); |
250 | } | 335 | } |
251 | 336 | ||
252 | /** | 337 | /** |
253 | * Pull up the information about the currently selected interface. | 338 | * Pull up the information about the currently selected interface. |
254 | * Report an error if no interface is selected. | 339 | * Report an error if no interface is selected. |
255 | * If the interface has a module owner then request its configure. | 340 | * If the interface has a module owner then request its configure. |
256 | */ | 341 | */ |
257 | void MainWindowImp::informationClicked(){ | 342 | void MainWindowImp::informationClicked(){ |
258 | QListViewItem *item = connectionList->currentItem(); | 343 | QListViewItem *item = connectionList->currentItem(); |
259 | if(!item){ | 344 | if(!item){ |
260 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 345 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
261 | return; | 346 | return; |
262 | } | 347 | } |
263 | 348 | ||
264 | Interface *i = interfaceItems[item]; | 349 | Interface *i = interfaceItems[item]; |
265 | if(!i->isAttached()){ | 350 | if(!i->isAttached()){ |
266 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 351 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
267 | return; | 352 | return; |
268 | } | 353 | } |
269 | 354 | ||
270 | if(i->getModuleOwner()){ | 355 | if(i->getModuleOwner()){ |
271 | QWidget *moduleInformation = i->getModuleOwner()->information(i); | 356 | QWidget *moduleInformation = i->getModuleOwner()->information(i); |
272 | if(moduleInformation != NULL){ | 357 | if(moduleInformation != NULL){ |
273 | moduleInformation->showMaximized(); | 358 | moduleInformation->showMaximized(); |
274 | moduleInformation->show(); | 359 | moduleInformation->show(); |
275 | return; | 360 | return; |
276 | } | 361 | } |
277 | } | 362 | } |
278 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 363 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
279 | information->showMaximized(); | 364 | information->showMaximized(); |
280 | information->show(); | 365 | information->show(); |
281 | } | 366 | } |
282 | 367 | ||
283 | /** | 368 | /** |
284 | * Aquire the list of active interfaces from ifconfig | ||
285 | * Call ifconfig and ifconfig -a | ||
286 | */ | ||
287 | void MainWindowImp::getInterfaceList(){ | ||
288 | KShellProcess *processAll = new KShellProcess(); | ||
289 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | ||
290 | connect(processAll, SIGNAL(processExited(KProcess *)), | ||
291 | this, SLOT(jobDone(KProcess *))); | ||
292 | threads.insert(processAll, TEMP_ALL); | ||
293 | |||
294 | KShellProcess *process = new KShellProcess(); | ||
295 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | ||
296 | connect(process, SIGNAL(processExited(KProcess *)), | ||
297 | this, SLOT(jobDone(KProcess *))); | ||
298 | threads.insert(process, TEMP_UP); | ||
299 | |||
300 | processAll->start(KShellProcess::NotifyOnExit); | ||
301 | process->start(KShellProcess::NotifyOnExit); | ||
302 | } | ||
303 | |||
304 | void MainWindowImp::jobDone(KProcess *process){ | ||
305 | QString fileName = threads[process]; | ||
306 | threads.remove(process); | ||
307 | delete process; | ||
308 | |||
309 | QFile file(fileName); | ||
310 | if (!file.open(IO_ReadOnly)){ | ||
311 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | ||
312 | return; | ||
313 | } | ||
314 | |||
315 | QTextStream stream( &file ); | ||
316 | QString line; | ||
317 | while ( !stream.eof() ) { | ||
318 | line = stream.readLine(); | ||
319 | int space = line.find(" "); | ||
320 | if(space > 1){ | ||
321 | // We have found an interface | ||
322 | QString interfaceName = line.mid(0, space); | ||
323 | Interface *i; | ||
324 | // We have found an interface | ||
325 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | ||
326 | // See if we already have it | ||
327 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | ||
328 | if(fileName == TEMP_ALL) | ||
329 | i = new Interface(this, interfaceName, false); | ||
330 | else | ||
331 | i = new Interface(this, interfaceName, true); | ||
332 | i->setAttached(true); | ||
333 | |||
334 | QString hardName = "Ethernet"; | ||
335 | int hardwareName = line.find("Link encap:"); | ||
336 | int macAddress = line.find("HWaddr"); | ||
337 | if(macAddress == -1) | ||
338 | macAddress = line.length(); | ||
339 | if(hardwareName != -1) | ||
340 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); | ||
341 | |||
342 | interfaceNames.insert(i->getInterfaceName(), i); | ||
343 | updateInterface(i); | ||
344 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
345 | } | ||
346 | // It was an interface we already had. | ||
347 | else{ | ||
348 | if(fileName != TEMP_ALL) | ||
349 | (interfaceNames[interfaceName])->setStatus(true); | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | file.close(); | ||
354 | QFile::remove(fileName); | ||
355 | |||
356 | if(threads.count() == 0){ | ||
357 | Interfaces i; | ||
358 | QStringList list = i.getInterfaceList(); | ||
359 | QMap<QString, Interface*>::Iterator it; | ||
360 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | ||
361 | bool found = false; | ||
362 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | ||
363 | if(it.key() == (*ni)) | ||
364 | found = true; | ||
365 | } | ||
366 | if(!found){ | ||
367 | if(!(*ni).contains("_")){ | ||
368 | Interface *i = new Interface(this, *ni, false); | ||
369 | i->setAttached(false); | ||
370 | i->setHardwareName("Disconnected"); | ||
371 | interfaceNames.insert(i->getInterfaceName(), i); | ||
372 | updateInterface(i); | ||
373 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | ||
374 | } | ||
375 | } | ||
376 | } | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * Update this interface. If no QListViewItem exists create one. | 369 | * Update this interface. If no QListViewItem exists create one. |
382 | * @param Interface* pointer to the interface that needs to be updated. | 370 | * @param Interface* pointer to the interface that needs to be updated. |
383 | */ | 371 | */ |
384 | void MainWindowImp::updateInterface(Interface *i){ | 372 | void MainWindowImp::updateInterface(Interface *i){ |
385 | if(!advancedUserMode){ | 373 | if(!advancedUserMode){ |
386 | if(i->getInterfaceName() == "lo") | 374 | if(i->getInterfaceName() == "lo") |
387 | return; | 375 | return; |
388 | } | 376 | } |
389 | 377 | ||
390 | QListViewItem *item = NULL; | 378 | QListViewItem *item = NULL; |
391 | 379 | ||
392 | // Find the interface, making it if needed. | 380 | // Find the interface, making it if needed. |
393 | if(items.find(i) == items.end()){ | 381 | if(items.find(i) == items.end()){ |
394 | item = new QListViewItem(connectionList, "", "", ""); | 382 | item = new QListViewItem(connectionList, "", "", ""); |
395 | // See if you can't find a module owner for this interface | 383 | // See if you can't find a module owner for this interface |
396 | QMap<Module*, QLibrary*>::Iterator it; | 384 | QMap<Module*, QLibrary*>::Iterator it; |
397 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 385 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
398 | if(it.key()->isOwner(i)) | 386 | if(it.key()->isOwner(i)) |
399 | i->setModuleOwner(it.key()); | 387 | i->setModuleOwner(it.key()); |
400 | } | 388 | } |
401 | items.insert(i, item); | 389 | items.insert(i, item); |
402 | interfaceItems.insert(item, i); | 390 | interfaceItems.insert(item, i); |
403 | } | 391 | } |
404 | else | 392 | else |
405 | item = items[i]; | 393 | item = items[i]; |
406 | 394 | ||
407 | // Update the icons and information | 395 | // Update the icons and information |
408 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 396 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
409 | 397 | ||
410 | QString typeName = "lan"; | 398 | QString typeName = "lan"; |
411 | if(i->getHardwareName().contains("Local Loopback")) | 399 | if(i->getHardwareName().contains("Local Loopback")) |
412 | typeName = "lo"; | 400 | typeName = "lo"; |
413 | if(i->getInterfaceName().contains("irda")) | 401 | if(i->getInterfaceName().contains("irda")) |
414 | typeName = "irda"; | 402 | typeName = "irda"; |
415 | if(i->getInterfaceName().contains("wlan")) | 403 | if(i->getInterfaceName().contains("wlan")) |
416 | typeName = "wlan"; | 404 | typeName = "wlan"; |
417 | if(i->getInterfaceName().contains("usb")) | 405 | if(i->getInterfaceName().contains("usb")) |
418 | typeName = "usb"; | 406 | typeName = "usb"; |
419 | 407 | ||
420 | if(!i->isAttached()) | 408 | if(!i->isAttached()) |
421 | typeName = "connect_no"; | 409 | typeName = "connect_no"; |
422 | // Actually try to use the Module | 410 | // Actually try to use the Module |
423 | if(i->getModuleOwner() != NULL) | 411 | if(i->getModuleOwner() != NULL) |
424 | typeName = i->getModuleOwner()->getPixmapName(i); | 412 | typeName = i->getModuleOwner()->getPixmapName(i); |
425 | 413 | ||
426 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 414 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
427 | item->setText(2, i->getHardwareName()); | 415 | item->setText(2, i->getHardwareName()); |
428 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 416 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |