-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,627 +1,626 @@ | |||
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"); |
218 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | 218 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) |
219 | i->setHardwareName("Loopback"); | 219 | i->setHardwareName("Loopback"); |
220 | else | 220 | else |
221 | i->setHardwareName("Unknown"); | 221 | i->setHardwareName("Unknown"); |
222 | 222 | ||
223 | qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); | 223 | qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); |
224 | interfaceNames.insert(i->getInterfaceName(), i); | 224 | interfaceNames.insert(i->getInterfaceName(), i); |
225 | updateInterface(i); | 225 | updateInterface(i); |
226 | connect(i, SIGNAL(updateInterface(Interface *)), | 226 | connect(i, SIGNAL(updateInterface(Interface *)), |
227 | this, SLOT(updateInterface(Interface *))); | 227 | this, SLOT(updateInterface(Interface *))); |
228 | } | 228 | } |
229 | // now lets ask the plugins too ;) | 229 | // now lets ask the plugins too ;) |
230 | QMap<Module*, QLibrary*>::Iterator it; | 230 | QMap<Module*, QLibrary*>::Iterator it; |
231 | QList<Interface> ilist; | 231 | QList<Interface> ilist; |
232 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 232 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
233 | if(it.key()){ | 233 | if(it.key()){ |
234 | ilist = it.key()->getInterfaces(); | 234 | ilist = it.key()->getInterfaces(); |
235 | for( i = ilist.first(); i != 0; i = ilist.next() ){ | 235 | for( i = ilist.first(); i != 0; i = ilist.next() ){ |
236 | qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() ); | 236 | qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() ); |
237 | interfaceNames.insert(i->getInterfaceName(), i); | 237 | interfaceNames.insert(i->getInterfaceName(), i); |
238 | updateInterface(i); | 238 | updateInterface(i); |
239 | connect(i, SIGNAL(updateInterface(Interface *)), | 239 | connect(i, SIGNAL(updateInterface(Interface *)), |
240 | this, SLOT(updateInterface(Interface *))); | 240 | this, SLOT(updateInterface(Interface *))); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | /** | 246 | /** |
247 | * Load all modules that are found in the path | 247 | * Load all modules that are found in the path |
248 | * @param path a directory that is scaned for any plugins that can be loaded | 248 | * @param path a directory that is scaned for any plugins that can be loaded |
249 | * and attempts to load them | 249 | * and attempts to load them |
250 | */ | 250 | */ |
251 | void MainWindowImp::loadModules(const QString &path){ | 251 | void MainWindowImp::loadModules(const QString &path){ |
252 | #ifdef DEBUG | 252 | #ifdef DEBUG |
253 | qDebug("MainWindowImp::loadModules: %s", path.latin1()); | 253 | qDebug("MainWindowImp::loadModules: %s", path.latin1()); |
254 | #endif | 254 | #endif |
255 | QDir d(path); | 255 | QDir d(path); |
256 | if(!d.exists()) | 256 | if(!d.exists()) |
257 | return; | 257 | return; |
258 | 258 | ||
259 | // Don't want sym links | 259 | // Don't want sym links |
260 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 260 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
261 | const QFileInfoList *list = d.entryInfoList(); | 261 | const QFileInfoList *list = d.entryInfoList(); |
262 | QFileInfoListIterator it( *list ); | 262 | QFileInfoListIterator it( *list ); |
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(){ |
537 | QString newProfileName = newProfile->text(); | 536 | QString newProfileName = newProfile->text(); |
538 | if(profiles.grep(newProfileName).count() > 0){ | 537 | if(profiles.grep(newProfileName).count() > 0){ |
539 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); | 538 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); |
540 | return; | 539 | return; |
541 | } | 540 | } |
542 | profiles.append(newProfileName); | 541 | profiles.append(newProfileName); |
543 | profilesList->insertItem(newProfileName); | 542 | profilesList->insertItem(newProfileName); |
544 | } | 543 | } |
545 | 544 | ||
546 | /** | 545 | /** |
547 | * Removes the currently selected profile in the combo. | 546 | * Removes the currently selected profile in the combo. |
548 | * Doesn't delete if there are less then 2 profiles. | 547 | * Doesn't delete if there are less then 2 profiles. |
549 | */ | 548 | */ |
550 | void MainWindowImp::removeProfile(){ | 549 | void MainWindowImp::removeProfile(){ |
551 | if(profilesList->count() <= 1){ | 550 | if(profilesList->count() <= 1){ |
552 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); | 551 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); |
553 | return; | 552 | return; |
554 | } | 553 | } |
555 | QString profileToRemove = profilesList->currentText(); | 554 | QString profileToRemove = profilesList->currentText(); |
556 | if(profileToRemove == "All"){ | 555 | if(profileToRemove == "All"){ |
557 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); | 556 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); |
558 | return; | 557 | return; |
559 | } | 558 | } |
560 | // Can't remove the curent profile | 559 | // Can't remove the curent profile |
561 | if(profileToRemove == currentProfileLabel->text()){ | 560 | if(profileToRemove == currentProfileLabel->text()){ |
562 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); | 561 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); |
563 | return; | 562 | return; |
564 | 563 | ||
565 | } | 564 | } |
566 | 565 | ||
567 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 566 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
568 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 567 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
569 | profilesList->clear(); | 568 | profilesList->clear(); |
570 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 569 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
571 | profilesList->insertItem((*it)); | 570 | profilesList->insertItem((*it)); |
572 | 571 | ||
573 | // Remove any interface settings and mappings. | 572 | // Remove any interface settings and mappings. |
574 | Interfaces interfaces; | 573 | Interfaces interfaces; |
575 | // Go through them one by one | 574 | // Go through them one by one |
576 | QMap<Interface*, QListViewItem*>::Iterator it; | 575 | QMap<Interface*, QListViewItem*>::Iterator it; |
577 | for( it = items.begin(); it != items.end(); ++it ){ | 576 | for( it = items.begin(); it != items.end(); ++it ){ |
578 | QString interfaceName = it.key()->getInterfaceName(); | 577 | QString interfaceName = it.key()->getInterfaceName(); |
579 | qDebug(interfaceName.latin1()); | 578 | qDebug(interfaceName.latin1()); |
580 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | 579 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ |
581 | interfaces.removeInterface(); | 580 | interfaces.removeInterface(); |
582 | if(interfaces.setMapping(interfaceName)){ | 581 | if(interfaces.setMapping(interfaceName)){ |
583 | if(profilesList->count() == 1) | 582 | if(profilesList->count() == 1) |
584 | interfaces.removeMapping(); | 583 | interfaces.removeMapping(); |
585 | else{ | 584 | else{ |
586 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | 585 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); |
587 | } | 586 | } |
588 | } | 587 | } |
589 | interfaces.write(); | 588 | interfaces.write(); |
590 | break; | 589 | break; |
591 | } | 590 | } |
592 | } | 591 | } |
593 | } | 592 | } |
594 | } | 593 | } |
595 | 594 | ||
596 | /** | 595 | /** |
597 | * A new profile has been selected, change. | 596 | * A new profile has been selected, change. |
598 | * @param newProfile the new profile. | 597 | * @param newProfile the new profile. |
599 | */ | 598 | */ |
600 | void MainWindowImp::changeProfile(){ | 599 | void MainWindowImp::changeProfile(){ |
601 | if(profilesList->currentItem() == -1){ | 600 | if(profilesList->currentItem() == -1){ |
602 | QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); | 601 | QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); |
603 | return; | 602 | return; |
604 | } | 603 | } |
605 | QString newProfile = profilesList->text(profilesList->currentItem()); | 604 | QString newProfile = profilesList->text(profilesList->currentItem()); |
606 | if(newProfile != currentProfileLabel->text()){ | 605 | if(newProfile != currentProfileLabel->text()){ |
607 | currentProfileLabel->setText(newProfile); | 606 | currentProfileLabel->setText(newProfile); |
608 | QFile::remove(scheme); | 607 | QFile::remove(scheme); |
609 | QFile file(scheme); | 608 | QFile file(scheme); |
610 | if ( file.open(IO_ReadWrite) ) { | 609 | if ( file.open(IO_ReadWrite) ) { |
611 | QTextStream stream( &file ); | 610 | QTextStream stream( &file ); |
612 | stream << QString("SCHEME=%1").arg(newProfile); | 611 | stream << QString("SCHEME=%1").arg(newProfile); |
613 | file.close(); | 612 | file.close(); |
614 | } | 613 | } |
615 | // restart all up devices? | 614 | // restart all up devices? |
616 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 615 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
617 | // Go through them one by one | 616 | // Go through them one by one |
618 | QMap<Interface*, QListViewItem*>::Iterator it; | 617 | QMap<Interface*, QListViewItem*>::Iterator it; |
619 | for( it = items.begin(); it != items.end(); ++it ){ | 618 | for( it = items.begin(); it != items.end(); ++it ){ |
620 | if(it.key()->getStatus() == true) | 619 | if(it.key()->getStatus() == true) |
621 | it.key()->restart(); | 620 | it.key()->restart(); |
622 | } | 621 | } |
623 | } | 622 | } |
624 | } | 623 | } |
625 | // TODO change the profile in the modules | 624 | // TODO change the profile in the modules |
626 | } | 625 | } |
627 | 626 | ||