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 | |||
@@ -136,108 +136,125 @@ MainWindowImp::~MainWindowImp(){ | |||
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")){ |
@@ -295,50 +312,49 @@ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString & | |||
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); |