summaryrefslogtreecommitdiff
authorkergoth <kergoth>2003-04-10 19:59:43 (UTC)
committer kergoth <kergoth>2003-04-10 19:59:43 (UTC)
commit6d5cc2d076a93ee56b898f91fc22adb29acc6f9d (patch) (unidiff)
treea828b3afeb7d65a15c82c2d01e539679cfbe97c4
parent481e92dc3ef3f789208fd696aca62d87dafff9ae (diff)
downloadopie-6d5cc2d076a93ee56b898f91fc22adb29acc6f9d.zip
opie-6d5cc2d076a93ee56b898f91fc22adb29acc6f9d.tar.gz
opie-6d5cc2d076a93ee56b898f91fc22adb29acc6f9d.tar.bz2
No qt3 widget flags!!!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index da21c05..765b522 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,587 +1,587 @@
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#include "module.h" 6#include "module.h"
7 7
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlineedit.h> 10#include <qlineedit.h>
11#include <qlistview.h> 11#include <qlistview.h>
12#include <qheader.h> 12#include <qheader.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16 16
17#ifdef QWS 17#ifdef QWS
18 #include <qpe/config.h> 18 #include <qpe/config.h>
19 #include <qpe/qlibrary.h> 19 #include <qpe/qlibrary.h>
20 #include <qpe/resource.h> 20 #include <qpe/resource.h>
21 #include <qpe/qpeapplication.h> 21 #include <qpe/qpeapplication.h>
22#else 22#else
23 #include <klibloader.h> 23 #include <klibloader.h>
24 #define QLibrary KLibrary 24 #define QLibrary KLibrary
25 #include <kconfig.h> 25 #include <kconfig.h>
26 #define Config KConfig 26 #define Config KConfig
27 #include <kapplication.h> 27 #include <kapplication.h>
28 #include <kstandarddirs.h> 28 #include <kstandarddirs.h>
29 #include <kiconloader.h> 29 #include <kiconloader.h>
30 #define showMaximized show 30 #define showMaximized show
31#endif 31#endif
32 32
33#if QT_VERSION < 300 33#if QT_VERSION < 300
34#include <qlist.h> 34#include <qlist.h>
35#else 35#else
36#include <qptrlist.h> 36#include <qptrlist.h>
37#endif 37#endif
38#include <qdir.h> 38#include <qdir.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qregexp.h> 41#include <qregexp.h>
42 42
43#include <net/if.h> 43#include <net/if.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45 45
46#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 46#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
47 47
48MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ 48MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){
49 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 49 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
50 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 50 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
51 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 51 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
52 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 52 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
53 53
54 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 54 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
55 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 55 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
56 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 56 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
57 57
58 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 58 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
59 // Load connections. 59 // Load connections.
60 // /usr/local/kde/lib/libinterfaces.la 60 // /usr/local/kde/lib/libinterfaces.la
61#ifdef QWS 61#ifdef QWS
62 loadModules(QPEApplication::qpeDir() + "/plugins/networksettings"); 62 loadModules(QPEApplication::qpeDir() + "/plugins/networksettings");
63#else 63#else
64 loader = KLibLoader::self(); 64 loader = KLibLoader::self();
65 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); 65 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib"));
66#endif 66#endif
67 getAllInterfaces(); 67 getAllInterfaces();
68 68
69 Interfaces i; 69 Interfaces i;
70 QStringList list = i.getInterfaceList(); 70 QStringList list = i.getInterfaceList();
71 QMap<QString, Interface*>::Iterator it; 71 QMap<QString, Interface*>::Iterator it;
72 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 72 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
73 bool found = false; 73 bool found = false;
74 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 74 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
75 if(it.key() == (*ni)) 75 if(it.key() == (*ni))
76 found = true; 76 found = true;
77 } 77 }
78 if(!found){ 78 if(!found){
79 if(!(*ni).contains("_")){ 79 if(!(*ni).contains("_")){
80 Interface *i = new Interface(this, *ni, false); 80 Interface *i = new Interface(this, *ni, false);
81 i->setAttached(false); 81 i->setAttached(false);
82 i->setHardwareName("Disconnected"); 82 i->setHardwareName("Disconnected");
83 interfaceNames.insert(i->getInterfaceName(), i); 83 interfaceNames.insert(i->getInterfaceName(), i);
84 updateInterface(i); 84 updateInterface(i);
85 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 85 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
86 } 86 }
87 } 87 }
88 } 88 }
89 89
90 //getInterfaceList(); 90 //getInterfaceList();
91 connectionList->header()->hide(); 91 connectionList->header()->hide();
92 92
93 Config cfg("NetworkSetup"); 93 Config cfg("NetworkSetup");
94 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 94 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
95 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 95 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
96 profilesList->insertItem((*it)); 96 profilesList->insertItem((*it));
97 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 97 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
98 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 98 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
99 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 99 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
100 100
101 QFile file(scheme); 101 QFile file(scheme);
102 if ( file.open(IO_ReadOnly) ) { // file opened successfully 102 if ( file.open(IO_ReadOnly) ) { // file opened successfully
103 QTextStream stream( &file ); // use a text stream 103 QTextStream stream( &file ); // use a text stream
104 while ( !stream.eof() ) { // until end of file... 104 while ( !stream.eof() ) { // until end of file...
105 QString line = stream.readLine(); // line of text excluding '\n' 105 QString line = stream.readLine(); // line of text excluding '\n'
106 if(line.contains("SCHEME")){ 106 if(line.contains("SCHEME")){
107 line = line.mid(7, line.length()); 107 line = line.mid(7, line.length());
108 currentProfileLabel->setText(line); 108 currentProfileLabel->setText(line);
109 break; 109 break;
110 } 110 }
111 } 111 }
112 file.close(); 112 file.close();
113 } 113 }
114} 114}
115 115
116/** 116/**
117 * Deconstructor. Save profiles. Delete loaded libraries. 117 * Deconstructor. Save profiles. Delete loaded libraries.
118 */ 118 */
119MainWindowImp::~MainWindowImp(){ 119MainWindowImp::~MainWindowImp(){
120 // Save profiles. 120 // Save profiles.
121 Config cfg("NetworkSetup"); 121 Config cfg("NetworkSetup");
122 cfg.setGroup("General"); 122 cfg.setGroup("General");
123 cfg.writeEntry("Profiles", profiles.join(" ")); 123 cfg.writeEntry("Profiles", profiles.join(" "));
124 124
125 // Delete all interfaces that don't have owners. 125 // Delete all interfaces that don't have owners.
126 QMap<Interface*, QListViewItem*>::Iterator iIt; 126 QMap<Interface*, QListViewItem*>::Iterator iIt;
127 for( iIt = items.begin(); iIt != items.end(); ++iIt ){ 127 for( iIt = items.begin(); iIt != items.end(); ++iIt ){
128 if(iIt.key()->getModuleOwner() == NULL) 128 if(iIt.key()->getModuleOwner() == NULL)
129 delete iIt.key(); 129 delete iIt.key();
130 } 130 }
131 131
132#ifdef QWS 132#ifdef QWS
133 // Delete Modules and Libraries 133 // Delete Modules and Libraries
134 QMap<Module*, QLibrary*>::Iterator it; 134 QMap<Module*, QLibrary*>::Iterator it;
135 for( it = libraries.begin(); it != libraries.end(); ++it ){ 135 for( it = libraries.begin(); it != libraries.end(); ++it ){
136 delete it.key(); 136 delete it.key();
137 // I wonder why I can't delete the libraries 137 // I wonder why I can't delete the libraries
138 // What fucking shit this is. 138 // What fucking shit this is.
139 //delete it.data(); 139 //delete it.data();
140 } 140 }
141#else 141#else
142 // klibloader automaticly deletes the libraries for us... 142 // klibloader automaticly deletes the libraries for us...
143#endif 143#endif
144} 144}
145 145
146/** 146/**
147 * Query the kernel for all of the interfaces. 147 * Query the kernel for all of the interfaces.
148 */ 148 */
149void MainWindowImp::getAllInterfaces(){ 149void MainWindowImp::getAllInterfaces(){
150 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); 150 int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
151 if(sockfd == -1) 151 if(sockfd == -1)
152 return; 152 return;
153 153
154 char buf[8*1024]; 154 char buf[8*1024];
155 struct ifconf ifc; 155 struct ifconf ifc;
156 ifc.ifc_len = sizeof(buf); 156 ifc.ifc_len = sizeof(buf);
157 ifc.ifc_req = (struct ifreq *) buf; 157 ifc.ifc_req = (struct ifreq *) buf;
158 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 158 int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
159 159
160 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 160 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){
161 struct ifreq *ifr =(struct ifreq *) ptr; 161 struct ifreq *ifr =(struct ifreq *) ptr;
162 int len = sizeof(struct sockaddr); 162 int len = sizeof(struct sockaddr);
163#ifdef HAVE_SOCKADDR_SA_LEN 163#ifdef HAVE_SOCKADDR_SA_LEN
164 if (ifr->ifr_addr.sa_len > len) 164 if (ifr->ifr_addr.sa_len > len)
165 len = ifr->ifr_addr.sa_len; /* length > 16 */ 165 len = ifr->ifr_addr.sa_len; /* length > 16 */
166#endif 166#endif
167 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 167 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
168 168
169 int flags; 169 int flags;
170 struct sockaddr_in *sinptr; 170 struct sockaddr_in *sinptr;
171 Interface *i = NULL; 171 Interface *i = NULL;
172 switch (ifr->ifr_addr.sa_family){ 172 switch (ifr->ifr_addr.sa_family){
173 case AF_INET: 173 case AF_INET:
174 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; 174 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
175 flags=0; 175 flags=0;
176 176
177 struct ifreq ifcopy; 177 struct ifreq ifcopy;
178 ifcopy=*ifr; 178 ifcopy=*ifr;
179 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); 179 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
180 flags=ifcopy.ifr_flags; 180 flags=ifcopy.ifr_flags;
181 i = new Interface(this, ifr->ifr_name, false); 181 i = new Interface(this, ifr->ifr_name, false);
182 i->setAttached(true); 182 i->setAttached(true);
183 if ((flags & IFF_UP) == IFF_UP) 183 if ((flags & IFF_UP) == IFF_UP)
184 i->setStatus(true); 184 i->setStatus(true);
185 else 185 else
186 i->setStatus(false); 186 i->setStatus(false);
187 187
188 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 188 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
189 i->setHardwareName("Ethernet"); 189 i->setHardwareName("Ethernet");
190 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 190 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
191 i->setHardwareName("Point to Point"); 191 i->setHardwareName("Point to Point");
192 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 192 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
193 i->setHardwareName("Multicast"); 193 i->setHardwareName("Multicast");
194 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 194 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
195 i->setHardwareName("Loopback"); 195 i->setHardwareName("Loopback");
196 else 196 else
197 i->setHardwareName("Unknown"); 197 i->setHardwareName("Unknown");
198 198
199 interfaceNames.insert(i->getInterfaceName(), i); 199 interfaceNames.insert(i->getInterfaceName(), i);
200 updateInterface(i); 200 updateInterface(i);
201 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 201 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
202 break; 202 break;
203 203
204 default: 204 default:
205 qDebug(ifr->ifr_name); 205 qDebug(ifr->ifr_name);
206 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); 206 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1());
207 break; 207 break;
208 } 208 }
209 } 209 }
210} 210}
211 211
212/** 212/**
213 * Load all modules that are found in the path 213 * Load all modules that are found in the path
214 * @param path a directory that is scaned for any plugins that can be loaded 214 * @param path a directory that is scaned for any plugins that can be loaded
215 * and attempts to load them 215 * and attempts to load them
216 */ 216 */
217void MainWindowImp::loadModules(const QString &path){ 217void MainWindowImp::loadModules(const QString &path){
218#ifdef DEBUG 218#ifdef DEBUG
219 qDebug("MainWindowImp::loadModules: %s", path.latin1()); 219 qDebug("MainWindowImp::loadModules: %s", path.latin1());
220#endif 220#endif
221 QDir d(path); 221 QDir d(path);
222 if(!d.exists()) 222 if(!d.exists())
223 return; 223 return;
224 224
225 // Don't want sym links 225 // Don't want sym links
226 d.setFilter( QDir::Files | QDir::NoSymLinks ); 226 d.setFilter( QDir::Files | QDir::NoSymLinks );
227 const QFileInfoList *list = d.entryInfoList(); 227 const QFileInfoList *list = d.entryInfoList();
228 QFileInfoListIterator it( *list ); 228 QFileInfoListIterator it( *list );
229 QFileInfo *fi; 229 QFileInfo *fi;
230 while ( (fi=it.current()) ) { 230 while ( (fi=it.current()) ) {
231 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ 231 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){
232 loadPlugin(path + "/" + fi->fileName()); 232 loadPlugin(path + "/" + fi->fileName());
233 } 233 }
234 ++it; 234 ++it;
235 } 235 }
236} 236}
237 237
238/** 238/**
239 * Attempt to load a function and resolve a function. 239 * Attempt to load a function and resolve a function.
240 * @param pluginFileName - the name of the file in which to attempt to load 240 * @param pluginFileName - the name of the file in which to attempt to load
241 * @param resolveString - function pointer to resolve 241 * @param resolveString - function pointer to resolve
242 * @return pointer to the function with name resolveString or NULL 242 * @return pointer to the function with name resolveString or NULL
243 */ 243 */
244Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ 244Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){
245#ifdef DEBUG 245#ifdef DEBUG
246 qDebug("MainWindowImp::loadPlugin: %s", pluginFileName.latin1()); 246 qDebug("MainWindowImp::loadPlugin: %s", pluginFileName.latin1());
247#endif 247#endif
248#ifdef QWS 248#ifdef QWS
249 QLibrary *lib = new QLibrary(pluginFileName); 249 QLibrary *lib = new QLibrary(pluginFileName);
250 void *functionPointer = lib->resolve(resolveString); 250 void *functionPointer = lib->resolve(resolveString);
251 if( !functionPointer ){ 251 if( !functionPointer ){
252#ifdef DEBUG 252#ifdef DEBUG
253 qDebug("MainWindowImp::loadPlugin: File: %s is not a plugin, but though was.", pluginFileName.latin1()); 253 qDebug("MainWindowImp::loadPlugin: File: %s is not a plugin, but though was.", pluginFileName.latin1());
254#endif 254#endif
255 delete lib; 255 delete lib;
256 return NULL; 256 return NULL;
257 } 257 }
258 // Try to get an object. 258 // Try to get an object.
259 Module *object = ((Module* (*)()) functionPointer)(); 259 Module *object = ((Module* (*)()) functionPointer)();
260 if(object == NULL){ 260 if(object == NULL){
261#ifdef DEBUG 261#ifdef DEBUG
262 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 262 qDebug("MainWindowImp: Couldn't create object, but did load library!");
263#endif 263#endif
264 delete lib; 264 delete lib;
265 return NULL; 265 return NULL;
266 } 266 }
267 267
268 // Store for deletion later 268 // Store for deletion later
269 libraries.insert(object, lib); 269 libraries.insert(object, lib);
270 return object; 270 return object;
271 271
272#else 272#else
273 QLibrary *lib = loader->library(pluginFileName); 273 QLibrary *lib = loader->library(pluginFileName);
274 if( !lib || !lib->hasSymbol(resolveString) ){ 274 if( !lib || !lib->hasSymbol(resolveString) ){
275#ifdef DEBUG 275#ifdef DEBUG
276 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 276 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
277#endif 277#endif
278 return NULL; 278 return NULL;
279 } 279 }
280 // Try to get an object. 280 // Try to get an object.
281 Module *object = ((Module* (*)()) lib->symbol(resolveString))(); 281 Module *object = ((Module* (*)()) lib->symbol(resolveString))();
282 if(object == NULL){ 282 if(object == NULL){
283#ifdef DEBUG 283#ifdef DEBUG
284 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 284 qDebug("MainWindowImp: Couldn't create object, but did load library!");
285#endif 285#endif
286 return NULL; 286 return NULL;
287 } 287 }
288#ifdef DEBUG 288#ifdef DEBUG
289 qDebug("MainWindowImp::loadPlugin:: Found object, storing."); 289 qDebug("MainWindowImp::loadPlugin:: Found object, storing.");
290#endif 290#endif
291 // Store for deletion later 291 // Store for deletion later
292 libraries.insert(object, lib); 292 libraries.insert(object, lib);
293 return object; 293 return object;
294#endif 294#endif
295} 295}
296 296
297/** 297/**
298 * The Add button was clicked. Bring up the add dialog and if OK is hit 298 * The Add button was clicked. Bring up the add dialog and if OK is hit
299 * load the plugin and append it to the list 299 * load the plugin and append it to the list
300 */ 300 */
301void MainWindowImp::addClicked(){ 301void MainWindowImp::addClicked(){
302 QMap<Module*, QLibrary*>::Iterator it; 302 QMap<Module*, QLibrary*>::Iterator it;
303 QMap<QString, QString> list; 303 QMap<QString, QString> list;
304 QMap<QString, Module*> newInterfaceOwners; 304 QMap<QString, Module*> newInterfaceOwners;
305 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 305 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
306 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 306 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
307 for( it = libraries.begin(); it != libraries.end(); ++it ){ 307 for( it = libraries.begin(); it != libraries.end(); ++it ){
308 if(it.key()){ 308 if(it.key()){
309 (it.key())->possibleNewInterfaces(list); 309 (it.key())->possibleNewInterfaces(list);
310 } 310 }
311 } 311 }
312 // See if the list has anything that we can add. 312 // See if the list has anything that we can add.
313 if(list.count() == 0){ 313 if(list.count() == 0){
314 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 314 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
315 return; 315 return;
316 } 316 }
317 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 317 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
318 addNewConnection.addConnections(list); 318 addNewConnection.addConnections(list);
319 addNewConnection.showMaximized(); 319 addNewConnection.showMaximized();
320 if(QDialog::Accepted == addNewConnection.exec()){ 320 if(QDialog::Accepted == addNewConnection.exec()){
321 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 321 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
322 if(!item) 322 if(!item)
323 return; 323 return;
324 324
325 for( it = libraries.begin(); it != libraries.end(); ++it ){ 325 for( it = libraries.begin(); it != libraries.end(); ++it ){
326 if(it.key()){ 326 if(it.key()){
327 Interface *i = (it.key())->addNewInterface(item->text(0)); 327 Interface *i = (it.key())->addNewInterface(item->text(0));
328 if(i){ 328 if(i){
329 interfaceNames.insert(i->getInterfaceName(), i); 329 interfaceNames.insert(i->getInterfaceName(), i);
330 updateInterface(i); 330 updateInterface(i);
331 } 331 }
332 } 332 }
333 } 333 }
334 } 334 }
335} 335}
336 336
337/** 337/**
338 * Prompt the user to see if they really want to do this. 338 * Prompt the user to see if they really want to do this.
339 * If they do then remove from the list and unload. 339 * If they do then remove from the list and unload.
340 */ 340 */
341void MainWindowImp::removeClicked(){ 341void MainWindowImp::removeClicked(){
342 QListViewItem *item = connectionList->currentItem(); 342 QListViewItem *item = connectionList->currentItem();
343 if(!item) { 343 if(!item) {
344 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 344 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
345 return; 345 return;
346 } 346 }
347 347
348 Interface *i = interfaceItems[item]; 348 Interface *i = interfaceItems[item];
349 if(i->getModuleOwner() == NULL){ 349 if(i->getModuleOwner() == NULL){
350 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 350 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
351 } 351 }
352 else{ 352 else{
353 if(!i->getModuleOwner()->remove(i)) 353 if(!i->getModuleOwner()->remove(i))
354 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); 354 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
355 else{ 355 else{
356 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 356 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
357 // TODO memory managment.... 357 // TODO memory managment....
358 // who deletes the interface? 358 // who deletes the interface?
359 } 359 }
360 } 360 }
361} 361}
362 362
363/** 363/**
364 * Pull up the configure about the currently selected interface. 364 * Pull up the configure about the currently selected interface.
365 * Report an error if no interface is selected. 365 * Report an error if no interface is selected.
366 * If the interface has a module owner then request its configure. 366 * If the interface has a module owner then request its configure.
367 */ 367 */
368void MainWindowImp::configureClicked(){ 368void MainWindowImp::configureClicked(){
369 QListViewItem *item = connectionList->currentItem(); 369 QListViewItem *item = connectionList->currentItem();
370 if(!item){ 370 if(!item){
371 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); 371 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
372 return; 372 return;
373 } 373 }
374 374
375 Interface *i = interfaceItems[item]; 375 Interface *i = interfaceItems[item];
376 if(i->getModuleOwner()){ 376 if(i->getModuleOwner()){
377 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 377 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
378 if(moduleConfigure != NULL){ 378 if(moduleConfigure != NULL){
379 moduleConfigure->showMaximized(); 379 moduleConfigure->showMaximized();
380 return; 380 return;
381 } 381 }
382 } 382 }
383 383
384 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); 384 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose );
385 QString currentProfileText = currentProfileLabel->text(); 385 QString currentProfileText = currentProfileLabel->text();
386 if(currentProfileText.upper() == "ALL"); 386 if(currentProfileText.upper() == "ALL");
387 currentProfileText = ""; 387 currentProfileText = "";
388 configure->setProfile(currentProfileText); 388 configure->setProfile(currentProfileText);
389 configure->showMaximized(); 389 configure->showMaximized();
390} 390}
391 391
392/** 392/**
393 * Pull up the information about the currently selected interface. 393 * Pull up the information about the currently selected interface.
394 * Report an error if no interface is selected. 394 * Report an error if no interface is selected.
395 * If the interface has a module owner then request its configure. 395 * If the interface has a module owner then request its configure.
396 */ 396 */
397void MainWindowImp::informationClicked(){ 397void MainWindowImp::informationClicked(){
398 QListViewItem *item = connectionList->currentItem(); 398 QListViewItem *item = connectionList->currentItem();
399 if(!item){ 399 if(!item){
400 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 400 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
401 return; 401 return;
402 } 402 }
403 403
404 Interface *i = interfaceItems[item]; 404 Interface *i = interfaceItems[item];
405 if(!i->isAttached()){ 405 if(!i->isAttached()){
406 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 406 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
407 return; 407 return;
408 } 408 }
409 409
410 if(i->getModuleOwner()){ 410 if(i->getModuleOwner()){
411 QWidget *moduleInformation = i->getModuleOwner()->information(i); 411 QWidget *moduleInformation = i->getModuleOwner()->information(i);
412 if(moduleInformation != NULL){ 412 if(moduleInformation != NULL){
413 moduleInformation->showMaximized(); 413 moduleInformation->showMaximized();
414#ifdef DEBUG 414#ifdef DEBUG
415 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); 415 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed.");
416#endif 416#endif
417 return; 417 return;
418 } 418 }
419 } 419 }
420 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WType_Dialog); 420 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog);
421 information->showMaximized(); 421 information->showMaximized();
422} 422}
423 423
424/** 424/**
425 * Update this interface. If no QListViewItem exists create one. 425 * Update this interface. If no QListViewItem exists create one.
426 * @param Interface* pointer to the interface that needs to be updated. 426 * @param Interface* pointer to the interface that needs to be updated.
427 */ 427 */
428void MainWindowImp::updateInterface(Interface *i){ 428void MainWindowImp::updateInterface(Interface *i){
429 if(!advancedUserMode){ 429 if(!advancedUserMode){
430 if(i->getInterfaceName() == "lo") 430 if(i->getInterfaceName() == "lo")
431 return; 431 return;
432 } 432 }
433 433
434 QListViewItem *item = NULL; 434 QListViewItem *item = NULL;
435 435
436 // Find the interface, making it if needed. 436 // Find the interface, making it if needed.
437 if(items.find(i) == items.end()){ 437 if(items.find(i) == items.end()){
438 item = new QListViewItem(connectionList, "", "", ""); 438 item = new QListViewItem(connectionList, "", "", "");
439 // See if you can't find a module owner for this interface 439 // See if you can't find a module owner for this interface
440 QMap<Module*, QLibrary*>::Iterator it; 440 QMap<Module*, QLibrary*>::Iterator it;
441 for( it = libraries.begin(); it != libraries.end(); ++it ){ 441 for( it = libraries.begin(); it != libraries.end(); ++it ){
442 if(it.key()->isOwner(i)) 442 if(it.key()->isOwner(i))
443 i->setModuleOwner(it.key()); 443 i->setModuleOwner(it.key());
444 } 444 }
445 items.insert(i, item); 445 items.insert(i, item);
446 interfaceItems.insert(item, i); 446 interfaceItems.insert(item, i);
447 } 447 }
448 else 448 else
449 item = items[i]; 449 item = items[i];
450 450
451 // Update the icons and information 451 // Update the icons and information
452#ifdef QWS 452#ifdef QWS
453 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 453 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
454#else 454#else
455 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 455 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
456#endif 456#endif
457 457
458 QString typeName = "lan"; 458 QString typeName = "lan";
459 if(i->getHardwareName().contains("Local Loopback")) 459 if(i->getHardwareName().contains("Local Loopback"))
460 typeName = "lo"; 460 typeName = "lo";
461 if(i->getInterfaceName().contains("irda")) 461 if(i->getInterfaceName().contains("irda"))
462 typeName = "irda"; 462 typeName = "irda";
463 if(i->getInterfaceName().contains("wlan")) 463 if(i->getInterfaceName().contains("wlan"))
464 typeName = "wlan"; 464 typeName = "wlan";
465 if(i->getInterfaceName().contains("usb")) 465 if(i->getInterfaceName().contains("usb"))
466 typeName = "usb"; 466 typeName = "usb";
467 467
468 if(!i->isAttached()) 468 if(!i->isAttached())
469 typeName = "connect_no"; 469 typeName = "connect_no";
470 // Actually try to use the Module 470 // Actually try to use the Module
471 if(i->getModuleOwner() != NULL) 471 if(i->getModuleOwner() != NULL)
472 typeName = i->getModuleOwner()->getPixmapName(i); 472 typeName = i->getModuleOwner()->getPixmapName(i);
473 473
474#ifdef QWS 474#ifdef QWS
475 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 475 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
476#else 476#else
477 item->setPixmap(1, (SmallIcon(typeName))); 477 item->setPixmap(1, (SmallIcon(typeName)));
478#endif 478#endif
479 item->setText(2, i->getHardwareName()); 479 item->setText(2, i->getHardwareName());
480 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 480 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
481 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 481 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
482} 482}
483 483
484void MainWindowImp::newProfileChanged(const QString& newText){ 484void MainWindowImp::newProfileChanged(const QString& newText){
485 if(newText.length() > 0) 485 if(newText.length() > 0)
486 newProfileButton->setEnabled(true); 486 newProfileButton->setEnabled(true);
487 else 487 else
488 newProfileButton->setEnabled(false); 488 newProfileButton->setEnabled(false);
489} 489}
490 490
491/** 491/**
492 * Adds a new profile to the list of profiles. 492 * Adds a new profile to the list of profiles.
493 * Don't add profiles that already exists. 493 * Don't add profiles that already exists.
494 * Appends to the list and QStringList 494 * Appends to the list and QStringList
495 */ 495 */
496void MainWindowImp::addProfile(){ 496void MainWindowImp::addProfile(){
497 QString newProfileName = newProfile->text(); 497 QString newProfileName = newProfile->text();
498 if(profiles.grep(newProfileName).count() > 0){ 498 if(profiles.grep(newProfileName).count() > 0){
499 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 499 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
500 return; 500 return;
501 } 501 }
502 profiles.append(newProfileName); 502 profiles.append(newProfileName);
503 profilesList->insertItem(newProfileName); 503 profilesList->insertItem(newProfileName);
504} 504}
505 505
506/** 506/**
507 * Removes the currently selected profile in the combo. 507 * Removes the currently selected profile in the combo.
508 * Doesn't delete if there are less then 2 profiles. 508 * Doesn't delete if there are less then 2 profiles.
509 */ 509 */
510void MainWindowImp::removeProfile(){ 510void MainWindowImp::removeProfile(){
511 if(profilesList->count() <= 1){ 511 if(profilesList->count() <= 1){
512 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 512 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
513 return; 513 return;
514 } 514 }
515 QString profileToRemove = profilesList->currentText(); 515 QString profileToRemove = profilesList->currentText();
516 if(profileToRemove == "All"){ 516 if(profileToRemove == "All"){
517 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 517 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
518 return; 518 return;
519 } 519 }
520 // Can't remove the curent profile 520 // Can't remove the curent profile
521 if(profileToRemove == currentProfileLabel->text()){ 521 if(profileToRemove == currentProfileLabel->text()){
522 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 522 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
523 return; 523 return;
524 524
525 } 525 }
526 526
527 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 527 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
528 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 528 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
529 profilesList->clear(); 529 profilesList->clear();
530 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 530 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
531 profilesList->insertItem((*it)); 531 profilesList->insertItem((*it));
532 532
533 // Remove any interface settings and mappings. 533 // Remove any interface settings and mappings.
534 Interfaces interfaces; 534 Interfaces interfaces;
535 // Go through them one by one 535 // Go through them one by one
536 QMap<Interface*, QListViewItem*>::Iterator it; 536 QMap<Interface*, QListViewItem*>::Iterator it;
537 for( it = items.begin(); it != items.end(); ++it ){ 537 for( it = items.begin(); it != items.end(); ++it ){
538 QString interfaceName = it.key()->getInterfaceName(); 538 QString interfaceName = it.key()->getInterfaceName();
539 qDebug(interfaceName.latin1()); 539 qDebug(interfaceName.latin1());
540 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ 540 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
541 interfaces.removeInterface(); 541 interfaces.removeInterface();
542 if(interfaces.setMapping(interfaceName)){ 542 if(interfaces.setMapping(interfaceName)){
543 if(profilesList->count() == 1) 543 if(profilesList->count() == 1)
544 interfaces.removeMapping(); 544 interfaces.removeMapping();
545 else{ 545 else{
546 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 546 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
547 } 547 }
548 } 548 }
549 interfaces.write(); 549 interfaces.write();
550 break; 550 break;
551 } 551 }
552 } 552 }
553 } 553 }
554} 554}
555 555
556/** 556/**
557 * A new profile has been selected, change. 557 * A new profile has been selected, change.
558 * @param newProfile the new profile. 558 * @param newProfile the new profile.
559 */ 559 */
560void MainWindowImp::changeProfile(){ 560void MainWindowImp::changeProfile(){
561 if(profilesList->currentItem() == -1){ 561 if(profilesList->currentItem() == -1){
562 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 562 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
563 return; 563 return;
564 } 564 }
565 QString newProfile = profilesList->text(profilesList->currentItem()); 565 QString newProfile = profilesList->text(profilesList->currentItem());
566 if(newProfile != currentProfileLabel->text()){ 566 if(newProfile != currentProfileLabel->text()){
567 currentProfileLabel->setText(newProfile); 567 currentProfileLabel->setText(newProfile);
568 QFile::remove(scheme); 568 QFile::remove(scheme);
569 QFile file(scheme); 569 QFile file(scheme);
570 if ( file.open(IO_ReadWrite) ) { 570 if ( file.open(IO_ReadWrite) ) {
571 QTextStream stream( &file ); 571 QTextStream stream( &file );
572 stream << QString("SCHEME=%1").arg(newProfile); 572 stream << QString("SCHEME=%1").arg(newProfile);
573 file.close(); 573 file.close();
574 } 574 }
575 // restart all up devices? 575 // restart all up devices?
576 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 576 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
577 // Go through them one by one 577 // Go through them one by one
578 QMap<Interface*, QListViewItem*>::Iterator it; 578 QMap<Interface*, QListViewItem*>::Iterator it;
579 for( it = items.begin(); it != items.end(); ++it ){ 579 for( it = items.begin(); it != items.end(); ++it ){
580 if(it.key()->getStatus() == true) 580 if(it.key()->getStatus() == true)
581 it.key()->restart(); 581 it.key()->restart();
582 } 582 }
583 } 583 }
584 } 584 }
585 // TODO change the profile in the modules 585 // TODO change the profile in the modules
586} 586}
587 587