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