-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index abf5663..a0b3113 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,217 +1,217 @@ | |||
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 | #include <qtabwidget.h> // in order to disable the profiles tab | 14 | #include <qtabwidget.h> // in order to disable the profiles tab |
15 | 15 | ||
16 | #include <qmessagebox.h> | 16 | #include <qmessagebox.h> |
17 | 17 | ||
18 | #ifdef QWS | 18 | #ifdef QWS |
19 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
20 | #include <qpe/qlibrary.h> | 20 | #include <qpe/qlibrary.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #else | 23 | #else |
24 | #include <klibloader.h> | 24 | #include <klibloader.h> |
25 | #define QLibrary KLibrary | 25 | #define QLibrary KLibrary |
26 | #include <kconfig.h> | 26 | #include <kconfig.h> |
27 | #define Config KConfig | 27 | #define Config KConfig |
28 | #include <kapplication.h> | 28 | #include <kapplication.h> |
29 | #include <kstandarddirs.h> | 29 | #include <kstandarddirs.h> |
30 | #include <kiconloader.h> | 30 | #include <kiconloader.h> |
31 | #define showMaximized show | 31 | #define showMaximized show |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #if QT_VERSION < 300 | 34 | #if QT_VERSION < 300 |
35 | #include <qlist.h> | 35 | #include <qlist.h> |
36 | #else | 36 | #else |
37 | #include <qptrlist.h> | 37 | #include <qptrlist.h> |
38 | #endif | 38 | #endif |
39 | #include <qdir.h> | 39 | #include <qdir.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qregexp.h> | 42 | #include <qregexp.h> |
43 | 43 | ||
44 | #include <net/if.h> | 44 | #include <net/if.h> |
45 | #include <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
46 | #include <sys/socket.h> | 46 | #include <sys/socket.h> |
47 | 47 | ||
48 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 48 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
49 | #define _PROCNETDEV "/proc/net/dev" | 49 | #define _PROCNETDEV "/proc/net/dev" |
50 | 50 | ||
51 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ | 51 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ |
52 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 52 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
53 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 53 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
54 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 54 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
55 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 55 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
56 | 56 | ||
57 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 57 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
58 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 58 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
59 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 59 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
60 | 60 | ||
61 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 61 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
62 | 62 | ||
63 | //FIXME: disable profiles for the moment: | 63 | //FIXME: disable profiles for the moment: |
64 | tabWidget->setTabEnabled( tab, false ); | 64 | tabWidget->setTabEnabled( tab, false ); |
65 | 65 | ||
66 | // Load connections. | 66 | // Load connections. |
67 | // /usr/local/kde/lib/libinterfaces.la | 67 | // /usr/local/kde/lib/libinterfaces.la |
68 | #ifdef QWS | 68 | #ifdef QWS |
69 | loadModules(QPEApplication::qpeDir() + "/plugins/networksettings"); | 69 | loadModules(QPEApplication::qpeDir() + "/plugins/networksettings"); |
70 | #else | 70 | #else |
71 | loader = KLibLoader::self(); | 71 | loader = KLibLoader::self(); |
72 | loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); | 72 | loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); |
73 | #endif | 73 | #endif |
74 | getAllInterfaces(); | 74 | getAllInterfaces(); |
75 | 75 | ||
76 | Interfaces i; | 76 | Interfaces i; |
77 | QStringList list = i.getInterfaceList(); | 77 | QStringList list = i.getInterfaceList(); |
78 | QMap<QString, Interface*>::Iterator it; | 78 | QMap<QString, Interface*>::Iterator it; |
79 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 79 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
80 | bool found = false; | 80 | bool found = false; |
81 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 81 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
82 | if(it.key() == (*ni)) | 82 | if(it.key() == (*ni)) |
83 | found = true; | 83 | found = true; |
84 | } | 84 | } |
85 | if(!found){ | 85 | if(!found){ |
86 | if(!(*ni).contains("_")){ | 86 | if(!(*ni).contains("_")){ |
87 | Interface *i = new Interface(this, *ni, false); | 87 | Interface *i = new Interface(this, *ni, false); |
88 | i->setAttached(false); | 88 | i->setAttached(false); |
89 | i->setHardwareName("Disconnected"); | 89 | i->setHardwareName(tr("Disconnected")); |
90 | interfaceNames.insert(i->getInterfaceName(), i); | 90 | interfaceNames.insert(i->getInterfaceName(), i); |
91 | updateInterface(i); | 91 | updateInterface(i); |
92 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 92 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | //getInterfaceList(); | 97 | //getInterfaceList(); |
98 | connectionList->header()->hide(); | 98 | connectionList->header()->hide(); |
99 | 99 | ||
100 | Config cfg("NetworkSetup"); | 100 | Config cfg("NetworkSetup"); |
101 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 101 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
102 | for ( QStringList::Iterator it = profiles.begin(); | 102 | for ( QStringList::Iterator it = profiles.begin(); |
103 | it != profiles.end(); ++it) | 103 | it != profiles.end(); ++it) |
104 | profilesList->insertItem((*it)); | 104 | profilesList->insertItem((*it)); |
105 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 105 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
106 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 106 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
107 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 107 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
108 | 108 | ||
109 | QFile file(scheme); | 109 | QFile file(scheme); |
110 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 110 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
111 | QTextStream stream( &file ); // use a text stream | 111 | QTextStream stream( &file ); // use a text stream |
112 | while ( !stream.eof() ) { // until end of file... | 112 | while ( !stream.eof() ) { // until end of file... |
113 | QString line = stream.readLine(); // line of text excluding '\n' | 113 | QString line = stream.readLine(); // line of text excluding '\n' |
114 | if(line.contains("SCHEME")){ | 114 | if(line.contains("SCHEME")){ |
115 | line = line.mid(7, line.length()); | 115 | line = line.mid(7, line.length()); |
116 | currentProfileLabel->setText(line); | 116 | currentProfileLabel->setText(line); |
117 | break; | 117 | break; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | file.close(); | 120 | file.close(); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | /** | 124 | /** |
125 | * Deconstructor. Save profiles. Delete loaded libraries. | 125 | * Deconstructor. Save profiles. Delete loaded libraries. |
126 | */ | 126 | */ |
127 | MainWindowImp::~MainWindowImp(){ | 127 | MainWindowImp::~MainWindowImp(){ |
128 | // Save profiles. | 128 | // Save profiles. |
129 | Config cfg("NetworkSetup"); | 129 | Config cfg("NetworkSetup"); |
130 | cfg.setGroup("General"); | 130 | cfg.setGroup("General"); |
131 | cfg.writeEntry("Profiles", profiles.join(" ")); | 131 | cfg.writeEntry("Profiles", profiles.join(" ")); |
132 | 132 | ||
133 | // Delete all interfaces that don't have owners. | 133 | // Delete all interfaces that don't have owners. |
134 | QMap<Interface*, QListViewItem*>::Iterator iIt; | 134 | QMap<Interface*, QListViewItem*>::Iterator iIt; |
135 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | 135 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ |
136 | if(iIt.key()->getModuleOwner() == NULL) | 136 | if(iIt.key()->getModuleOwner() == NULL) |
137 | delete iIt.key(); | 137 | delete iIt.key(); |
138 | } | 138 | } |
139 | 139 | ||
140 | #ifdef QWS | 140 | #ifdef QWS |
141 | // Delete Modules and Libraries | 141 | // Delete Modules and Libraries |
142 | QMap<Module*, QLibrary*>::Iterator it; | 142 | QMap<Module*, QLibrary*>::Iterator it; |
143 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 143 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
144 | delete it.key(); | 144 | delete it.key(); |
145 | // I wonder why I can't delete the libraries | 145 | // I wonder why I can't delete the libraries |
146 | // What fucking shit this is. | 146 | // What fucking shit this is. |
147 | //delete it.data(); | 147 | //delete it.data(); |
148 | } | 148 | } |
149 | #else | 149 | #else |
150 | // klibloader automaticly deletes the libraries for us... | 150 | // klibloader automaticly deletes the libraries for us... |
151 | #endif | 151 | #endif |
152 | } | 152 | } |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * Query the kernel for all of the interfaces. | 155 | * Query the kernel for all of the interfaces. |
156 | */ | 156 | */ |
157 | void MainWindowImp::getAllInterfaces(){ | 157 | void MainWindowImp::getAllInterfaces(){ |
158 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); | 158 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); |
159 | if(sockfd == -1) | 159 | if(sockfd == -1) |
160 | return; | 160 | return; |
161 | 161 | ||
162 | struct ifreq ifr; | 162 | struct ifreq ifr; |
163 | QStringList ifaces; | 163 | QStringList ifaces; |
164 | QFile procFile(QString(_PROCNETDEV)); | 164 | QFile procFile(QString(_PROCNETDEV)); |
165 | int result; | 165 | int result; |
166 | Interface *i; | 166 | Interface *i; |
167 | 167 | ||
168 | if (! procFile.exists()) { | 168 | if (! procFile.exists()) { |
169 | struct ifreq ifrs[100]; | 169 | struct ifreq ifrs[100]; |
170 | struct ifconf ifc; | 170 | struct ifconf ifc; |
171 | ifc.ifc_len = sizeof(ifrs); | 171 | ifc.ifc_len = sizeof(ifrs); |
172 | ifc.ifc_req = ifrs; | 172 | ifc.ifc_req = ifrs; |
173 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); | 173 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); |
174 | 174 | ||
175 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { | 175 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { |
176 | struct ifreq *pifr = &ifrs[i]; | 176 | struct ifreq *pifr = &ifrs[i]; |
177 | 177 | ||
178 | ifaces += pifr->ifr_name; | 178 | ifaces += pifr->ifr_name; |
179 | } | 179 | } |
180 | } else { | 180 | } else { |
181 | procFile.open(IO_ReadOnly); | 181 | procFile.open(IO_ReadOnly); |
182 | QString line; | 182 | QString line; |
183 | QTextStream procTs(&procFile); | 183 | QTextStream procTs(&procFile); |
184 | int loc = -1; | 184 | int loc = -1; |
185 | 185 | ||
186 | procTs.readLine(); // eat a line | 186 | procTs.readLine(); // eat a line |
187 | procTs.readLine(); // eat a line | 187 | procTs.readLine(); // eat a line |
188 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { | 188 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { |
189 | if((loc = line.find(":")) != -1) { | 189 | if((loc = line.find(":")) != -1) { |
190 | ifaces += line.left(loc); | 190 | ifaces += line.left(loc); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { | 195 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { |
196 | int flags = 0, family; | 196 | int flags = 0, family; |
197 | i = NULL; | 197 | i = NULL; |
198 | 198 | ||
199 | strcpy(ifr.ifr_name, (*it).latin1()); | 199 | strcpy(ifr.ifr_name, (*it).latin1()); |
200 | 200 | ||
201 | struct ifreq ifcopy; | 201 | struct ifreq ifcopy; |
202 | ifcopy = ifr; | 202 | ifcopy = ifr; |
203 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); | 203 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); |
204 | flags = ifcopy.ifr_flags; | 204 | flags = ifcopy.ifr_flags; |
205 | i = new Interface(this, ifr.ifr_name, false); | 205 | i = new Interface(this, ifr.ifr_name, false); |
206 | i->setAttached(true); | 206 | i->setAttached(true); |
207 | if ((flags & IFF_UP) == IFF_UP) | 207 | if ((flags & IFF_UP) == IFF_UP) |
208 | i->setStatus(true); | 208 | i->setStatus(true); |
209 | else | 209 | else |
210 | i->setStatus(false); | 210 | i->setStatus(false); |
211 | 211 | ||
212 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | 212 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) |
213 | i->setHardwareName("Ethernet"); | 213 | i->setHardwareName("Ethernet"); |
214 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | 214 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) |
215 | i->setHardwareName("Point to Point"); | 215 | i->setHardwareName("Point to Point"); |
216 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | 216 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) |
217 | i->setHardwareName("Multicast"); | 217 | i->setHardwareName("Multicast"); |
@@ -263,274 +263,273 @@ void MainWindowImp::loadModules(const QString &path){ | |||
263 | QFileInfo *fi; | 263 | QFileInfo *fi; |
264 | while ( (fi=it.current()) ) { | 264 | while ( (fi=it.current()) ) { |
265 | #ifdef QWS | 265 | #ifdef QWS |
266 | if(fi->fileName().contains(".so")){ | 266 | if(fi->fileName().contains(".so")){ |
267 | #else | 267 | #else |
268 | if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ | 268 | if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ |
269 | #endif | 269 | #endif |
270 | loadPlugin(path + "/" + fi->fileName()); | 270 | loadPlugin(path + "/" + fi->fileName()); |
271 | qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1()); | 271 | qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1()); |
272 | } | 272 | } |
273 | ++it; | 273 | ++it; |
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
277 | /** | 277 | /** |
278 | * Attempt to load a function and resolve a function. | 278 | * Attempt to load a function and resolve a function. |
279 | * @param pluginFileName - the name of the file in which to attempt to load | 279 | * @param pluginFileName - the name of the file in which to attempt to load |
280 | * @param resolveString - function pointer to resolve | 280 | * @param resolveString - function pointer to resolve |
281 | * @return pointer to the function with name resolveString or NULL | 281 | * @return pointer to the function with name resolveString or NULL |
282 | */ | 282 | */ |
283 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ | 283 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ |
284 | #ifdef DEBUG | 284 | #ifdef DEBUG |
285 | qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1()); | 285 | qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1()); |
286 | #endif | 286 | #endif |
287 | #ifdef QWS | 287 | #ifdef QWS |
288 | QLibrary *lib = new QLibrary(pluginFileName); | 288 | QLibrary *lib = new QLibrary(pluginFileName); |
289 | void *functionPointer = lib->resolve(resolveString); | 289 | void *functionPointer = lib->resolve(resolveString); |
290 | if( !functionPointer ){ | 290 | if( !functionPointer ){ |
291 | #ifdef DEBUG | 291 | #ifdef DEBUG |
292 | qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1()); | 292 | qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1()); |
293 | #endif | 293 | #endif |
294 | delete lib; | 294 | delete lib; |
295 | return NULL; | 295 | return NULL; |
296 | } | 296 | } |
297 | // Try to get an object. | 297 | // Try to get an object. |
298 | Module *object = ((Module* (*)()) functionPointer)(); | 298 | Module *object = ((Module* (*)()) functionPointer)(); |
299 | if(object == NULL){ | 299 | if(object == NULL){ |
300 | #ifdef DEBUG | 300 | #ifdef DEBUG |
301 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 301 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
302 | #endif | 302 | #endif |
303 | delete lib; | 303 | delete lib; |
304 | return NULL; | 304 | return NULL; |
305 | } | 305 | } |
306 | 306 | ||
307 | // Store for deletion later | 307 | // Store for deletion later |
308 | libraries.insert(object, lib); | 308 | libraries.insert(object, lib); |
309 | return object; | 309 | return object; |
310 | 310 | ||
311 | #else | 311 | #else |
312 | QLibrary *lib = loader->library(pluginFileName); | 312 | QLibrary *lib = loader->library(pluginFileName); |
313 | if( !lib || !lib->hasSymbol(resolveString) ){ | 313 | if( !lib || !lib->hasSymbol(resolveString) ){ |
314 | qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 314 | qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
315 | return NULL; | 315 | return NULL; |
316 | } | 316 | } |
317 | // Try to get an object. | 317 | // Try to get an object. |
318 | Module *object = ((Module* (*)()) lib->symbol(resolveString))(); | 318 | Module *object = ((Module* (*)()) lib->symbol(resolveString))(); |
319 | if(object == NULL){ | 319 | if(object == NULL){ |
320 | #ifdef DEBUG | 320 | #ifdef DEBUG |
321 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 321 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
322 | #endif | 322 | #endif |
323 | return NULL; | 323 | return NULL; |
324 | } | 324 | } |
325 | #ifdef DEBUG | 325 | #ifdef DEBUG |
326 | qDebug("MainWindowImp::loadPlugin:: Found object, storing."); | 326 | qDebug("MainWindowImp::loadPlugin:: Found object, storing."); |
327 | #endif | 327 | #endif |
328 | // Store for deletion later | 328 | // Store for deletion later |
329 | libraries.insert(object, lib); | 329 | libraries.insert(object, lib); |
330 | return object; | 330 | return object; |
331 | #endif | 331 | #endif |
332 | } | 332 | } |
333 | 333 | ||
334 | /** | 334 | /** |
335 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 335 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
336 | * load the plugin and append it to the list | 336 | * load the plugin and append it to the list |
337 | */ | 337 | */ |
338 | void MainWindowImp::addClicked(){ | 338 | void MainWindowImp::addClicked(){ |
339 | QMap<Module*, QLibrary*>::Iterator it; | 339 | QMap<Module*, QLibrary*>::Iterator it; |
340 | QMap<QString, QString> list; | 340 | QMap<QString, QString> list; |
341 | QMap<QString, Module*> newInterfaceOwners; | 341 | QMap<QString, Module*> newInterfaceOwners; |
342 | 342 | ||
343 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 343 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
344 | if(it.key()){ | 344 | if(it.key()){ |
345 | (it.key())->possibleNewInterfaces(list); | 345 | (it.key())->possibleNewInterfaces(list); |
346 | } | 346 | } |
347 | } | 347 | } |
348 | // See if the list has anything that we can add. | 348 | // See if the list has anything that we can add. |
349 | if(list.count() == 0){ | 349 | if(list.count() == 0){ |
350 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); | 350 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 353 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
354 | addNewConnection.addConnections(list); | 354 | addNewConnection.addConnections(list); |
355 | addNewConnection.showMaximized(); | 355 | addNewConnection.showMaximized(); |
356 | if(QDialog::Accepted == addNewConnection.exec()){ | 356 | if(QDialog::Accepted == addNewConnection.exec()){ |
357 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 357 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
358 | if(!item) | 358 | if(!item) |
359 | return; | 359 | return; |
360 | 360 | ||
361 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 361 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
362 | if(it.key()){ | 362 | if(it.key()){ |
363 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 363 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
364 | if(i){ | 364 | if(i){ |
365 | qDebug("iface name %s",i->getInterfaceName().latin1()); | 365 | qDebug("iface name %s",i->getInterfaceName().latin1()); |
366 | interfaceNames.insert(i->getInterfaceName(), i); | 366 | interfaceNames.insert(i->getInterfaceName(), i); |
367 | updateInterface(i); | 367 | updateInterface(i); |
368 | } | 368 | } |
369 | } | 369 | } |
370 | } | 370 | } |
371 | } | 371 | } |
372 | } | 372 | } |
373 | 373 | ||
374 | /** | 374 | /** |
375 | * Prompt the user to see if they really want to do this. | 375 | * Prompt the user to see if they really want to do this. |
376 | * If they do then remove from the list and unload. | 376 | * If they do then remove from the list and unload. |
377 | */ | 377 | */ |
378 | void MainWindowImp::removeClicked(){ | 378 | void MainWindowImp::removeClicked(){ |
379 | QListViewItem *item = connectionList->currentItem(); | 379 | QListViewItem *item = connectionList->currentItem(); |
380 | if(!item) { | 380 | if(!item) { |
381 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 381 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
382 | return; | 382 | return; |
383 | } | 383 | } |
384 | 384 | ||
385 | Interface *i = interfaceItems[item]; | 385 | Interface *i = interfaceItems[item]; |
386 | if(i->getModuleOwner() == NULL){ | 386 | if(i->getModuleOwner() == NULL){ |
387 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); | 387 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); |
388 | } | 388 | } |
389 | else{ | 389 | else{ |
390 | if(!i->getModuleOwner()->remove(i)) | 390 | if(!i->getModuleOwner()->remove(i)) |
391 | QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); | 391 | QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); |
392 | else{ | 392 | else{ |
393 | QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); | 393 | delete item; |
394 | // TODO memory managment.... | 394 | // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); |
395 | // who deletes the interface? | ||
396 | } | 395 | } |
397 | } | 396 | } |
398 | } | 397 | } |
399 | 398 | ||
400 | /** | 399 | /** |
401 | * Pull up the configure about the currently selected interface. | 400 | * Pull up the configure about the currently selected interface. |
402 | * Report an error if no interface is selected. | 401 | * Report an error if no interface is selected. |
403 | * If the interface has a module owner then request its configure. | 402 | * If the interface has a module owner then request its configure. |
404 | */ | 403 | */ |
405 | void MainWindowImp::configureClicked(){ | 404 | void MainWindowImp::configureClicked(){ |
406 | QListViewItem *item = connectionList->currentItem(); | 405 | QListViewItem *item = connectionList->currentItem(); |
407 | if(!item){ | 406 | if(!item){ |
408 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); | 407 | QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); |
409 | return; | 408 | return; |
410 | } | 409 | } |
411 | 410 | ||
412 | QString currentProfileText = currentProfileLabel->text(); | 411 | QString currentProfileText = currentProfileLabel->text(); |
413 | if(currentProfileText.upper() == "ALL"); | 412 | if(currentProfileText.upper() == "ALL"); |
414 | currentProfileText = ""; | 413 | currentProfileText = ""; |
415 | 414 | ||
416 | Interface *i = interfaceItems[item]; | 415 | Interface *i = interfaceItems[item]; |
417 | 416 | ||
418 | if(i->getModuleOwner()){ | 417 | if(i->getModuleOwner()){ |
419 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); | 418 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); |
420 | if(moduleConfigure != NULL){ | 419 | if(moduleConfigure != NULL){ |
421 | i->getModuleOwner()->setProfile(currentProfileText); | 420 | i->getModuleOwner()->setProfile(currentProfileText); |
422 | moduleConfigure->showMaximized(); | 421 | moduleConfigure->showMaximized(); |
423 | return; | 422 | return; |
424 | } | 423 | } |
425 | } | 424 | } |
426 | 425 | ||
427 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); | 426 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); |
428 | configure->setProfile(currentProfileText); | 427 | configure->setProfile(currentProfileText); |
429 | configure->showMaximized(); | 428 | configure->showMaximized(); |
430 | } | 429 | } |
431 | 430 | ||
432 | /** | 431 | /** |
433 | * Pull up the information about the currently selected interface. | 432 | * Pull up the information about the currently selected interface. |
434 | * Report an error if no interface is selected. | 433 | * Report an error if no interface is selected. |
435 | * If the interface has a module owner then request its configure. | 434 | * If the interface has a module owner then request its configure. |
436 | */ | 435 | */ |
437 | void MainWindowImp::informationClicked(){ | 436 | void MainWindowImp::informationClicked(){ |
438 | QListViewItem *item = connectionList->currentItem(); | 437 | QListViewItem *item = connectionList->currentItem(); |
439 | if(!item){ | 438 | if(!item){ |
440 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 439 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
441 | return; | 440 | return; |
442 | } | 441 | } |
443 | 442 | ||
444 | Interface *i = interfaceItems[item]; | 443 | Interface *i = interfaceItems[item]; |
445 | // if(!i->isAttached()){ | 444 | // if(!i->isAttached()){ |
446 | // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 445 | // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
447 | // return; | 446 | // return; |
448 | // } | 447 | // } |
449 | 448 | ||
450 | if(i->getModuleOwner()){ | 449 | if(i->getModuleOwner()){ |
451 | QWidget *moduleInformation = i->getModuleOwner()->information(i); | 450 | QWidget *moduleInformation = i->getModuleOwner()->information(i); |
452 | if(moduleInformation != NULL){ | 451 | if(moduleInformation != NULL){ |
453 | moduleInformation->showMaximized(); | 452 | moduleInformation->showMaximized(); |
454 | #ifdef DEBUG | 453 | #ifdef DEBUG |
455 | qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); | 454 | qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); |
456 | #endif | 455 | #endif |
457 | return; | 456 | return; |
458 | } | 457 | } |
459 | } | 458 | } |
460 | InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); | 459 | InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); |
461 | information->showMaximized(); | 460 | information->showMaximized(); |
462 | } | 461 | } |
463 | 462 | ||
464 | /** | 463 | /** |
465 | * Update this interface. If no QListViewItem exists create one. | 464 | * Update this interface. If no QListViewItem exists create one. |
466 | * @param Interface* pointer to the interface that needs to be updated. | 465 | * @param Interface* pointer to the interface that needs to be updated. |
467 | */ | 466 | */ |
468 | void MainWindowImp::updateInterface(Interface *i){ | 467 | void MainWindowImp::updateInterface(Interface *i){ |
469 | if(!advancedUserMode){ | 468 | if(!advancedUserMode){ |
470 | if(i->getInterfaceName() == "lo") | 469 | if(i->getInterfaceName() == "lo") |
471 | return; | 470 | return; |
472 | } | 471 | } |
473 | 472 | ||
474 | QListViewItem *item = NULL; | 473 | QListViewItem *item = NULL; |
475 | 474 | ||
476 | // Find the interface, making it if needed. | 475 | // Find the interface, making it if needed. |
477 | if(items.find(i) == items.end()){ | 476 | if(items.find(i) == items.end()){ |
478 | item = new QListViewItem(connectionList, "", "", ""); | 477 | item = new QListViewItem(connectionList, "", "", ""); |
479 | // See if you can't find a module owner for this interface | 478 | // See if you can't find a module owner for this interface |
480 | QMap<Module*, QLibrary*>::Iterator it; | 479 | QMap<Module*, QLibrary*>::Iterator it; |
481 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 480 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
482 | if(it.key()->isOwner(i)) | 481 | if(it.key()->isOwner(i)) |
483 | i->setModuleOwner(it.key()); | 482 | i->setModuleOwner(it.key()); |
484 | } | 483 | } |
485 | items.insert(i, item); | 484 | items.insert(i, item); |
486 | interfaceItems.insert(item, i); | 485 | interfaceItems.insert(item, i); |
487 | } | 486 | } |
488 | else | 487 | else |
489 | item = items[i]; | 488 | item = items[i]; |
490 | 489 | ||
491 | // Update the icons and information | 490 | // Update the icons and information |
492 | #ifdef QWS | 491 | #ifdef QWS |
493 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 492 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
494 | #else | 493 | #else |
495 | item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); | 494 | item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); |
496 | #endif | 495 | #endif |
497 | 496 | ||
498 | QString typeName = "lan"; | 497 | QString typeName = "lan"; |
499 | if(i->getHardwareName().contains("Local Loopback")) | 498 | if(i->getHardwareName().contains("Local Loopback")) |
500 | typeName = "lo"; | 499 | typeName = "lo"; |
501 | if(i->getInterfaceName().contains("irda")) | 500 | if(i->getInterfaceName().contains("irda")) |
502 | typeName = "irda"; | 501 | typeName = "irda"; |
503 | if(i->getInterfaceName().contains("wlan")) | 502 | if(i->getInterfaceName().contains("wlan")) |
504 | typeName = "wlan"; | 503 | typeName = "wlan"; |
505 | if(i->getInterfaceName().contains("usb")) | 504 | if(i->getInterfaceName().contains("usb")) |
506 | typeName = "usb"; | 505 | typeName = "usb"; |
507 | 506 | ||
508 | if(!i->isAttached()) | 507 | if(!i->isAttached()) |
509 | typeName = "connect_no"; | 508 | typeName = "connect_no"; |
510 | // Actually try to use the Module | 509 | // Actually try to use the Module |
511 | if(i->getModuleOwner() != NULL) | 510 | if(i->getModuleOwner() != NULL) |
512 | typeName = i->getModuleOwner()->getPixmapName(i); | 511 | typeName = i->getModuleOwner()->getPixmapName(i); |
513 | 512 | ||
514 | #ifdef QWS | 513 | #ifdef QWS |
515 | item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); | 514 | item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); |
516 | #else | 515 | #else |
517 | item->setPixmap(1, (SmallIcon(typeName))); | 516 | item->setPixmap(1, (SmallIcon(typeName))); |
518 | #endif | 517 | #endif |
519 | item->setText(2, i->getHardwareName()); | 518 | item->setText(2, i->getHardwareName()); |
520 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 519 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
521 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 520 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
522 | } | 521 | } |
523 | 522 | ||
524 | void MainWindowImp::newProfileChanged(const QString& newText){ | 523 | void MainWindowImp::newProfileChanged(const QString& newText){ |
525 | if(newText.length() > 0) | 524 | if(newText.length() > 0) |
526 | newProfileButton->setEnabled(true); | 525 | newProfileButton->setEnabled(true); |
527 | else | 526 | else |
528 | newProfileButton->setEnabled(false); | 527 | newProfileButton->setEnabled(false); |
529 | } | 528 | } |
530 | 529 | ||
531 | /** | 530 | /** |
532 | * Adds a new profile to the list of profiles. | 531 | * Adds a new profile to the list of profiles. |
533 | * Don't add profiles that already exists. | 532 | * Don't add profiles that already exists. |
534 | * Appends to the list and QStringList | 533 | * Appends to the list and QStringList |
535 | */ | 534 | */ |
536 | void MainWindowImp::addProfile(){ | 535 | void MainWindowImp::addProfile(){ |