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