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