summaryrefslogtreecommitdiff
authorzecke <zecke>2004-10-14 01:26:40 (UTC)
committer zecke <zecke>2004-10-14 01:26:40 (UTC)
commita1aed5edd5ccef77d79ccdd2d74f5c029d037617 (patch) (unidiff)
tree64f8342d651e968478df58d1a98db978e950b372
parentb17b6c77af35b610d236321279d3f18eb3060c90 (diff)
downloadopie-a1aed5edd5ccef77d79ccdd2d74f5c029d037617.zip
opie-a1aed5edd5ccef77d79ccdd2d74f5c029d037617.tar.gz
opie-a1aed5edd5ccef77d79ccdd2d74f5c029d037617.tar.bz2
Old Patch from BRANCH 1.0 to install Translations of the Plugins
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp56
1 files changed, 13 insertions, 43 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index a4a2875..fb7d7c9 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -1,624 +1,594 @@
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
46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 46MainWindowImp::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 //remove tab with no function 53 //remove tab with no function
54 tabWidget->removePage( tab ); 54 tabWidget->removePage( tab );
55 55
56 // Load connections. 56 // Load connections.
57 // /usr/local/kde/lib/libinterfaces.la 57 // /usr/local/kde/lib/libinterfaces.la
58#ifdef QWS
59 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 58 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
60#else
61 loader = KLibLoader::self();
62 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib"));
63#endif
64 getAllInterfaces(); 59 getAllInterfaces();
65 60
66 Interfaces i; 61 Interfaces i;
67 QStringList list = i.getInterfaceList(); 62 QStringList list = i.getInterfaceList();
68 QMap<QString, Interface*>::Iterator it; 63 QMap<QString, Interface*>::Iterator it;
69 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 64 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
70 { 65 {
71 /* 66 /*
72 * we skipped it in getAllInterfaces now 67 * we skipped it in getAllInterfaces now
73 * we need to ignore it as well 68 * we need to ignore it as well
74 */ 69 */
75 if (m_handledIfaces.contains( *ni) ) 70 if (m_handledIfaces.contains( *ni) )
76 { 71 {
77 odebug << "Not up iface handled by module" << oendl; 72 odebug << "Not up iface handled by module" << oendl;
78 continue; 73 continue;
79 } 74 }
80 bool found = false; 75 bool found = false;
81 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
82 { 77 {
83 if(it.key() == (*ni)) 78 if(it.key() == (*ni))
84 found = true; 79 found = true;
85 } 80 }
86 if(!found) 81 if(!found)
87 { 82 {
88 if(!(*ni).contains("_")) 83 if(!(*ni).contains("_"))
89 { 84 {
90 Interface *i = new Interface(this, *ni, false); 85 Interface *i = new Interface(this, *ni, false);
91 i->setAttached(false); 86 i->setAttached(false);
92 i->setHardwareName(tr("Disconnected")); 87 i->setHardwareName(tr("Disconnected"));
93 interfaceNames.insert(i->getInterfaceName(), i); 88 interfaceNames.insert(i->getInterfaceName(), i);
94 updateInterface(i); 89 updateInterface(i);
95 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); 90 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
96 } 91 }
97 } 92 }
98 } 93 }
99 94
100 //getInterfaceList(); 95 //getInterfaceList();
101 connectionList->header()->hide(); 96 connectionList->header()->hide();
102 97
103 Config cfg("NetworkSetup"); 98 Config cfg("NetworkSetup");
104 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 99 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
105 for ( QStringList::Iterator it = profiles.begin(); 100 for ( QStringList::Iterator it = profiles.begin();
106 it != profiles.end(); ++it) 101 it != profiles.end(); ++it)
107 profilesList->insertItem((*it)); 102 profilesList->insertItem((*it));
108 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 103 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
109 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 104 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
110 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 105 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
111 106
112 QFile file(scheme); 107 QFile file(scheme);
113 if ( file.open(IO_ReadOnly) ) 108 if ( file.open(IO_ReadOnly) )
114 { // file opened successfully 109 { // file opened successfully
115 QTextStream stream( &file ); // use a text stream 110 QTextStream stream( &file ); // use a text stream
116 while ( !stream.eof() ) 111 while ( !stream.eof() )
117 { // until end of file... 112 { // until end of file...
118 QString line = stream.readLine(); // line of text excluding '\n' 113 QString line = stream.readLine(); // line of text excluding '\n'
119 if(line.contains("SCHEME")) 114 if(line.contains("SCHEME"))
120 { 115 {
121 line = line.mid(7, line.length()); 116 line = line.mid(7, line.length());
122 currentProfileLabel->setText(line); 117 currentProfileLabel->setText(line);
123 break; 118 break;
124 } 119 }
125 } 120 }
126 file.close(); 121 file.close();
127 } 122 }
128 makeChannel(); 123 makeChannel();
129} 124}
130 125
131/** 126/**
132 * Deconstructor. Save profiles. Delete loaded libraries. 127 * Deconstructor. Save profiles. Delete loaded libraries.
133 */ 128 */
134MainWindowImp::~MainWindowImp() 129MainWindowImp::~MainWindowImp()
135{ 130{
136 // Save profiles. 131 // Save profiles.
137 Config cfg("NetworkSetup"); 132 Config cfg("NetworkSetup");
138 cfg.setGroup("General"); 133 cfg.setGroup("General");
139 cfg.writeEntry("Profiles", profiles.join(" ")); 134 cfg.writeEntry("Profiles", profiles.join(" "));
140 135
141 // Delete all interfaces that don't have owners. 136 // Delete all interfaces that don't have owners.
142 QMap<Interface*, QListViewItem*>::Iterator iIt; 137 QMap<Interface*, QListViewItem*>::Iterator iIt;
143 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 138 for( iIt = items.begin(); iIt != items.end(); ++iIt )
144 { 139 {
145 if(iIt.key()->getModuleOwner() == NULL) 140 if(iIt.key()->getModuleOwner() == NULL)
146 delete iIt.key(); 141 delete iIt.key();
147 } 142 }
148 143
149#ifdef QWS
150 // Delete Modules and Libraries 144 // Delete Modules and Libraries
151 QMap<Module*, QLibrary*>::Iterator it; 145 QMap<Module*, QLibrary*>::Iterator it;
152 for( it = libraries.begin(); it != libraries.end(); ++it ) 146 for( it = libraries.begin(); it != libraries.end(); ++it )
153 { 147 {
154 delete it.key(); 148 delete it.key();
155 // I wonder why I can't delete the libraries 149 // I wonder why I can't delete the libraries
156 // What fucking shit this is. 150 // What fucking shit this is.
157 //delete it.data(); 151 //delete it.data();
158 } 152 }
159#else
160 // klibloader automaticly deletes the libraries for us...
161#endif
162} 153}
163 154
164/** 155/**
165 * Query the kernel for all of the interfaces. 156 * Query the kernel for all of the interfaces.
166 */ 157 */
167void MainWindowImp::getAllInterfaces() 158void MainWindowImp::getAllInterfaces()
168{ 159{
169 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 160 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
170 if(sockfd == -1) 161 if(sockfd == -1)
171 return; 162 return;
172 163
173 struct ifreq ifr; 164 struct ifreq ifr;
174 QStringList ifaces; 165 QStringList ifaces;
175 QFile procFile(QString(_PROCNETDEV)); 166 QFile procFile(QString(_PROCNETDEV));
176 int result; 167 int result;
177 Interface *i; 168 Interface *i;
178 169
179 if (! procFile.exists()) 170 if (! procFile.exists())
180 { 171 {
181 struct ifreq ifrs[100]; 172 struct ifreq ifrs[100];
182 struct ifconf ifc; 173 struct ifconf ifc;
183 ifc.ifc_len = sizeof(ifrs); 174 ifc.ifc_len = sizeof(ifrs);
184 ifc.ifc_req = ifrs; 175 ifc.ifc_req = ifrs;
185 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 176 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
186 177
187 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 178 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
188 { 179 {
189 struct ifreq *pifr = &ifrs[i]; 180 struct ifreq *pifr = &ifrs[i];
190 181
191 ifaces += pifr->ifr_name; 182 ifaces += pifr->ifr_name;
192 } 183 }
193 } 184 }
194 else 185 else
195 { 186 {
196 procFile.open(IO_ReadOnly); 187 procFile.open(IO_ReadOnly);
197 QString line; 188 QString line;
198 QTextStream procTs(&procFile); 189 QTextStream procTs(&procFile);
199 int loc = -1; 190 int loc = -1;
200 191
201 procTs.readLine(); // eat a line 192 procTs.readLine(); // eat a line
202 procTs.readLine(); // eat a line 193 procTs.readLine(); // eat a line
203 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 194 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
204 { 195 {
205 if((loc = line.find(":")) != -1) 196 if((loc = line.find(":")) != -1)
206 { 197 {
207 ifaces += line.left(loc); 198 ifaces += line.left(loc);
208 } 199 }
209 } 200 }
210 } 201 }
211 202
212 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 203 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
213 { 204 {
214 int flags = 0; 205 int flags = 0;
215 if ( m_handledIfaces.contains( (*it) ) ) 206 if ( m_handledIfaces.contains( (*it) ) )
216 { 207 {
217 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 208 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
218 continue; 209 continue;
219 } 210 }
220 // int family; 211 // int family;
221 i = NULL; 212 i = NULL;
222 213
223 strcpy(ifr.ifr_name, (*it).latin1()); 214 strcpy(ifr.ifr_name, (*it).latin1());
224 215
225 struct ifreq ifcopy; 216 struct ifreq ifcopy;
226 ifcopy = ifr; 217 ifcopy = ifr;
227 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 218 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
228 flags = ifcopy.ifr_flags; 219 flags = ifcopy.ifr_flags;
229 i = new Interface(this, ifr.ifr_name, false); 220 i = new Interface(this, ifr.ifr_name, false);
230 i->setAttached(true); 221 i->setAttached(true);
231 if ((flags & IFF_UP) == IFF_UP) 222 if ((flags & IFF_UP) == IFF_UP)
232 i->setStatus(true); 223 i->setStatus(true);
233 else 224 else
234 i->setStatus(false); 225 i->setStatus(false);
235 226
236 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 227 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
237 i->setHardwareName("Ethernet"); 228 i->setHardwareName("Ethernet");
238 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 229 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
239 i->setHardwareName("Point to Point"); 230 i->setHardwareName("Point to Point");
240 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 231 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
241 i->setHardwareName("Multicast"); 232 i->setHardwareName("Multicast");
242 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 233 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
243 i->setHardwareName("Loopback"); 234 i->setHardwareName("Loopback");
244 else 235 else
245 i->setHardwareName("Unknown"); 236 i->setHardwareName("Unknown");
246 237
247 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 238 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
248 interfaceNames.insert(i->getInterfaceName(), i); 239 interfaceNames.insert(i->getInterfaceName(), i);
249 updateInterface(i); 240 updateInterface(i);
250 connect(i, SIGNAL(updateInterface(Interface*)), 241 connect(i, SIGNAL(updateInterface(Interface*)),
251 this, SLOT(updateInterface(Interface*))); 242 this, SLOT(updateInterface(Interface*)));
252 } 243 }
253 // now lets ask the plugins too ;) 244 // now lets ask the plugins too ;)
254 QMap<Module*, QLibrary*>::Iterator it; 245 QMap<Module*, QLibrary*>::Iterator it;
255 QList<Interface> ilist; 246 QList<Interface> ilist;
256 for( it = libraries.begin(); it != libraries.end(); ++it ) 247 for( it = libraries.begin(); it != libraries.end(); ++it )
257 { 248 {
258 if(it.key()) 249 if(it.key())
259 { 250 {
260 ilist = it.key()->getInterfaces(); 251 ilist = it.key()->getInterfaces();
261 for( i = ilist.first(); i != 0; i = ilist.next() ) 252 for( i = ilist.first(); i != 0; i = ilist.next() )
262 { 253 {
263 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 254 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
264 interfaceNames.insert(i->getInterfaceName(), i); 255 interfaceNames.insert(i->getInterfaceName(), i);
265 updateInterface(i); 256 updateInterface(i);
266 connect(i, SIGNAL(updateInterface(Interface*)), 257 connect(i, SIGNAL(updateInterface(Interface*)),
267 this, SLOT(updateInterface(Interface*))); 258 this, SLOT(updateInterface(Interface*)));
268 } 259 }
269 } 260 }
270 } 261 }
271} 262}
272 263
273/** 264/**
274 * Load all modules that are found in the path 265 * Load all modules that are found in the path
275 * @param path a directory that is scaned for any plugins that can be loaded 266 * @param path a directory that is scaned for any plugins that can be loaded
276 * and attempts to load them 267 * and attempts to load them
277 */ 268 */
278void MainWindowImp::loadModules(const QString &path) 269void MainWindowImp::loadModules(const QString &path)
279{ 270{
280#ifdef DEBUG 271#ifdef DEBUG
281 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 272 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
282#endif 273#endif
283 QDir d(path); 274 QDir d(path);
284 if(!d.exists()) 275 if(!d.exists())
285 return; 276 return;
286 277
278 QString lang = ::getenv("LANG");
287 // Don't want sym links 279 // Don't want sym links
288 d.setFilter( QDir::Files | QDir::NoSymLinks ); 280 d.setFilter( QDir::Files | QDir::NoSymLinks );
289 const QFileInfoList *list = d.entryInfoList(); 281 const QFileInfoList *list = d.entryInfoList();
290 QFileInfoListIterator it( *list ); 282 QFileInfoListIterator it( *list );
291 QFileInfo *fi; 283 QFileInfo *fi;
292 while ( (fi=it.current()) ) 284 while ( (fi=it.current()) )
293 { 285 {
294#ifdef QWS
295 if(fi->fileName().contains(".so")) 286 if(fi->fileName().contains(".so"))
296 { 287 {
297#else 288 /* if loaded install translation */
298 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")) 289 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){
299 { 290 QTranslator *trans = new QTranslator(qApp);
300#endif 291 QString fn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm";
301 loadPlugin(path + "/" + fi->fileName()); 292 if( trans->load( fn ) )
293 qApp->installTranslator( trans );
294 else
295 delete trans;
296 }
302 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; 297 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
303 } 298 }
304 ++it; 299 ++it;
305 } 300 }
306} 301}
307 302
308/** 303/**
309 * Attempt to load a function and resolve a function. 304 * Attempt to load a function and resolve a function.
310 * @param pluginFileName - the name of the file in which to attempt to load 305 * @param pluginFileName - the name of the file in which to attempt to load
311 * @param resolveString - function pointer to resolve 306 * @param resolveString - function pointer to resolve
312 * @return pointer to the function with name resolveString or NULL 307 * @return pointer to the function with name resolveString or NULL
313 */ 308 */
314Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 309Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
315{ 310{
316#ifdef DEBUG 311#ifdef DEBUG
317 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; 312 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
318#endif 313#endif
319#ifdef QWS
320 QLibrary *lib = new QLibrary(pluginFileName); 314 QLibrary *lib = new QLibrary(pluginFileName);
321 void *functionPointer = lib->resolve(resolveString); 315 void *functionPointer = lib->resolve(resolveString);
322 if( !functionPointer ) 316 if( !functionPointer )
323 { 317 {
324#ifdef DEBUG 318#ifdef DEBUG
325 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; 319 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
326#endif 320#endif
327 delete lib; 321 delete lib;
328 return NULL; 322 return 0;
329 } 323 }
330 // Try to get an object. 324 // Try to get an object.
331 Module *object = ((Module* (*)()) functionPointer)(); 325 Module *object = ((Module* (*)()) functionPointer)();
332 if(object == NULL) 326 if(object == 0)
333 { 327 {
334#ifdef DEBUG 328#ifdef DEBUG
335 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 329 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
336#endif 330#endif
337 delete lib; 331 delete lib;
338 return NULL; 332 return 0;
339 } 333 }
340 334
341 m_handledIfaces += object->handledInterfaceNames(); 335 m_handledIfaces += object->handledInterfaceNames();
342 // Store for deletion later 336 // Store for deletion later
343 libraries.insert(object, lib); 337 libraries.insert(object, lib);
344 return object; 338 return object;
345
346#else
347 QLibrary *lib = loader->library(pluginFileName);
348 if( !lib || !lib->hasSymbol(resolveString) )
349 {
350 odebug << QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1() << oendl;
351 return NULL;
352 }
353 // Try to get an object.
354 Module *object = ((Module* (*)()) lib->symbol(resolveString))();
355 if(object == NULL)
356 {
357#ifdef DEBUG
358 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
359#endif
360 return NULL;
361 }
362#ifdef DEBUG
363 odebug << "MainWindowImp::loadPlugin:: Found object, storing." << oendl;
364#endif
365 // Store for deletion later
366 libraries.insert(object, lib);
367 return object;
368#endif
369} 339}
370 340
371/** 341/**
372 * The Add button was clicked. Bring up the add dialog and if OK is hit 342 * The Add button was clicked. Bring up the add dialog and if OK is hit
373 * load the plugin and append it to the list 343 * load the plugin and append it to the list
374 */ 344 */
375void MainWindowImp::addClicked() 345void MainWindowImp::addClicked()
376{ 346{
377 QMap<Module*, QLibrary*>::Iterator it; 347 QMap<Module*, QLibrary*>::Iterator it;
378 QMap<QString, QString> list; 348 QMap<QString, QString> list;
379 QMap<QString, Module*> newInterfaceOwners; 349 QMap<QString, Module*> newInterfaceOwners;
380 350
381 for( it = libraries.begin(); it != libraries.end(); ++it ) 351 for( it = libraries.begin(); it != libraries.end(); ++it )
382 { 352 {
383 if(it.key()) 353 if(it.key())
384 { 354 {
385 (it.key())->possibleNewInterfaces(list); 355 (it.key())->possibleNewInterfaces(list);
386 } 356 }
387 } 357 }
388 // See if the list has anything that we can add. 358 // See if the list has anything that we can add.
389 if(list.count() == 0) 359 if(list.count() == 0)
390 { 360 {
391 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 361 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
392 return; 362 return;
393 } 363 }
394 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 364 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
395 addNewConnection.addConnections(list); 365 addNewConnection.addConnections(list);
396 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 366 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
397 { 367 {
398 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 368 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
399 if(!item) 369 if(!item)
400 return; 370 return;
401 371
402 for( it = libraries.begin(); it != libraries.end(); ++it ) 372 for( it = libraries.begin(); it != libraries.end(); ++it )
403 { 373 {
404 if(it.key()) 374 if(it.key())
405 { 375 {
406 Interface *i = (it.key())->addNewInterface(item->text(0)); 376 Interface *i = (it.key())->addNewInterface(item->text(0));
407 if(i) 377 if(i)
408 { 378 {
409 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; 379 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
410 interfaceNames.insert(i->getInterfaceName(), i); 380 interfaceNames.insert(i->getInterfaceName(), i);
411 updateInterface(i); 381 updateInterface(i);
412 } 382 }
413 } 383 }
414 } 384 }
415 } 385 }
416} 386}
417 387
418/** 388/**
419 * Prompt the user to see if they really want to do this. 389 * Prompt the user to see if they really want to do this.
420 * If they do then remove from the list and unload. 390 * If they do then remove from the list and unload.
421 */ 391 */
422void MainWindowImp::removeClicked() 392void MainWindowImp::removeClicked()
423{ 393{
424 QListViewItem *item = connectionList->currentItem(); 394 QListViewItem *item = connectionList->currentItem();
425 if(!item) 395 if(!item)
426 { 396 {
427 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 397 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
428 return; 398 return;
429 } 399 }
430 400
431 Interface *i = interfaceItems[item]; 401 Interface *i = interfaceItems[item];
432 if(i->getModuleOwner() == NULL) 402 if(i->getModuleOwner() == NULL)
433 { 403 {
434 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 404 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
435 } 405 }
436 else 406 else
437 { 407 {
438 if(!i->getModuleOwner()->remove(i)) 408 if(!i->getModuleOwner()->remove(i))
439 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 409 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
440 else 410 else
441 { 411 {
442 delete item; 412 delete item;
443 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 413 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
444 } 414 }
445 } 415 }
446} 416}
447 417
448/** 418/**
449 * Pull up the configure about the currently selected interface. 419 * Pull up the configure about the currently selected interface.
450 * Report an error if no interface is selected. 420 * Report an error if no interface is selected.
451 * If the interface has a module owner then request its configure. 421 * If the interface has a module owner then request its configure.
452 */ 422 */
453void MainWindowImp::configureClicked() 423void MainWindowImp::configureClicked()
454{ 424{
455 QListViewItem *item = connectionList->currentItem(); 425 QListViewItem *item = connectionList->currentItem();
456 if(!item) 426 if(!item)
457 { 427 {
458 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 428 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
459 return; 429 return;
460 } 430 }
461 431
462 QString currentProfileText = currentProfileLabel->text(); 432 QString currentProfileText = currentProfileLabel->text();
463 if(currentProfileText.upper() == "ALL"); 433 if(currentProfileText.upper() == "ALL");
464 currentProfileText = ""; 434 currentProfileText = "";
465 435
466 Interface *i = interfaceItems[item]; 436 Interface *i = interfaceItems[item];
467 437
468 if(i->getModuleOwner()) 438 if(i->getModuleOwner())
469 { 439 {
470 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 440 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
471 if(moduleConfigure != NULL) 441 if(moduleConfigure != NULL)
472 { 442 {
473 i->getModuleOwner()->setProfile(currentProfileText); 443 i->getModuleOwner()->setProfile(currentProfileText);
474 QPEApplication::showWidget( moduleConfigure ); 444 QPEApplication::showWidget( moduleConfigure );
475 return; 445 return;
476 } 446 }
477 } 447 }
478 448
479 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); 449 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp );
480 configure->setProfile(currentProfileText); 450 configure->setProfile(currentProfileText);
481 QPEApplication::showDialog( configure ); 451 QPEApplication::showDialog( configure );
482} 452}
483 453
484/** 454/**
485 * Pull up the information about the currently selected interface. 455 * Pull up the information about the currently selected interface.
486 * Report an error if no interface is selected. 456 * Report an error if no interface is selected.
487 * If the interface has a module owner then request its configure. 457 * If the interface has a module owner then request its configure.
488 */ 458 */
489void MainWindowImp::informationClicked() 459void MainWindowImp::informationClicked()
490{ 460{
491 QListViewItem *item = connectionList->currentItem(); 461 QListViewItem *item = connectionList->currentItem();
492 if(!item) 462 if(!item)
493 { 463 {
494 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 464 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
495 return; 465 return;
496 } 466 }
497 467
498 Interface *i = interfaceItems[item]; 468 Interface *i = interfaceItems[item];
499 // if(!i->isAttached()){ 469 // if(!i->isAttached()){
500 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 470 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
501 // return; 471 // return;
502 // } 472 // }
503 473
504 if(i->getModuleOwner()) 474 if(i->getModuleOwner())
505 { 475 {
506 QWidget *moduleInformation = i->getModuleOwner()->information(i); 476 QWidget *moduleInformation = i->getModuleOwner()->information(i);
507 if(moduleInformation != NULL) 477 if(moduleInformation != NULL)
508 { 478 {
509 QPEApplication::showWidget( moduleInformation ); 479 QPEApplication::showWidget( moduleInformation );
510#ifdef DEBUG 480#ifdef DEBUG
511 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; 481 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
512#endif 482#endif
513 return; 483 return;
514 } 484 }
515 } 485 }
516 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); 486 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp);
517 QPEApplication::showWidget( information ); 487 QPEApplication::showWidget( information );
518} 488}
519 489
520/** 490/**
521 * Update this interface. If no QListViewItem exists create one. 491 * Update this interface. If no QListViewItem exists create one.
522 * @param Interface* pointer to the interface that needs to be updated. 492 * @param Interface* pointer to the interface that needs to be updated.
523 */ 493 */
524void MainWindowImp::updateInterface(Interface *i) 494void MainWindowImp::updateInterface(Interface *i)
525{ 495{
526 if(!advancedUserMode) 496 if(!advancedUserMode)
527 { 497 {
528 if(i->getInterfaceName() == "lo") 498 if(i->getInterfaceName() == "lo")
529 return; 499 return;
530 } 500 }
531 501
532 QListViewItem *item = NULL; 502 QListViewItem *item = NULL;
533 503
534 // Find the interface, making it if needed. 504 // Find the interface, making it if needed.
535 if(items.find(i) == items.end()) 505 if(items.find(i) == items.end())
536 { 506 {
537 item = new QListViewItem(connectionList, "", "", ""); 507 item = new QListViewItem(connectionList, "", "", "");
538 // See if you can't find a module owner for this interface 508 // See if you can't find a module owner for this interface
539 QMap<Module*, QLibrary*>::Iterator it; 509 QMap<Module*, QLibrary*>::Iterator it;
540 for( it = libraries.begin(); it != libraries.end(); ++it ) 510 for( it = libraries.begin(); it != libraries.end(); ++it )
541 { 511 {
542 if(it.key()->isOwner(i)) 512 if(it.key()->isOwner(i))
543 i->setModuleOwner(it.key()); 513 i->setModuleOwner(it.key());
544 } 514 }
545 items.insert(i, item); 515 items.insert(i, item);
546 interfaceItems.insert(item, i); 516 interfaceItems.insert(item, i);
547 } 517 }
548 else 518 else
549 item = items[i]; 519 item = items[i];
550 520
551 // Update the icons and information 521 // Update the icons and information
552#ifdef QWS 522#ifdef QWS
553 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 523 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
554#else 524#else
555 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 525 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
556#endif 526#endif
557 527
558 QString typeName = "lan"; 528 QString typeName = "lan";
559 if(i->getInterfaceName() == "lo") 529 if(i->getInterfaceName() == "lo")
560 typeName = "lo"; 530 typeName = "lo";
561 if(i->getInterfaceName().contains("irda")) 531 if(i->getInterfaceName().contains("irda"))
562 typeName = "irda"; 532 typeName = "irda";
563 if(i->getInterfaceName().contains("wlan")) 533 if(i->getInterfaceName().contains("wlan"))
564 typeName = "wlan"; 534 typeName = "wlan";
565 if(i->getInterfaceName().contains("usb")) 535 if(i->getInterfaceName().contains("usb"))
566 typeName = "usb"; 536 typeName = "usb";
567 537
568 if(!i->isAttached()) 538 if(!i->isAttached())
569 typeName = "connect_no"; 539 typeName = "connect_no";
570 // Actually try to use the Module 540 // Actually try to use the Module
571 if(i->getModuleOwner() != NULL) 541 if(i->getModuleOwner() != NULL)
572 typeName = i->getModuleOwner()->getPixmapName(i); 542 typeName = i->getModuleOwner()->getPixmapName(i);
573 543
574#ifdef QWS 544#ifdef QWS
575 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 545 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
576#else 546#else
577 item->setPixmap(1, (SmallIcon(typeName))); 547 item->setPixmap(1, (SmallIcon(typeName)));
578#endif 548#endif
579 item->setText(2, i->getHardwareName()); 549 item->setText(2, i->getHardwareName());
580 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 550 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
581 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 551 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
582} 552}
583 553
584void MainWindowImp::newProfileChanged(const QString& newText) 554void MainWindowImp::newProfileChanged(const QString& newText)
585{ 555{
586 if(newText.length() > 0) 556 if(newText.length() > 0)
587 newProfileButton->setEnabled(true); 557 newProfileButton->setEnabled(true);
588 else 558 else
589 newProfileButton->setEnabled(false); 559 newProfileButton->setEnabled(false);
590} 560}
591 561
592/** 562/**
593 * Adds a new profile to the list of profiles. 563 * Adds a new profile to the list of profiles.
594 * Don't add profiles that already exists. 564 * Don't add profiles that already exists.
595 * Appends to the list and QStringList 565 * Appends to the list and QStringList
596 */ 566 */
597void MainWindowImp::addProfile() 567void MainWindowImp::addProfile()
598{ 568{
599 QString newProfileName = newProfile->text(); 569 QString newProfileName = newProfile->text();
600 if(profiles.grep(newProfileName).count() > 0) 570 if(profiles.grep(newProfileName).count() > 0)
601 { 571 {
602 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 572 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
603 return; 573 return;
604 } 574 }
605 profiles.append(newProfileName); 575 profiles.append(newProfileName);
606 profilesList->insertItem(newProfileName); 576 profilesList->insertItem(newProfileName);
607} 577}
608 578
609/** 579/**
610 * Removes the currently selected profile in the combo. 580 * Removes the currently selected profile in the combo.
611 * Doesn't delete if there are less then 2 profiles. 581 * Doesn't delete if there are less then 2 profiles.
612 */ 582 */
613void MainWindowImp::removeProfile() 583void MainWindowImp::removeProfile()
614{ 584{
615 if(profilesList->count() <= 1) 585 if(profilesList->count() <= 1)
616 { 586 {
617 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 587 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
618 return; 588 return;
619 } 589 }
620 QString profileToRemove = profilesList->currentText(); 590 QString profileToRemove = profilesList->currentText();
621 if(profileToRemove == "All") 591 if(profileToRemove == "All")
622 { 592 {
623 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 593 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
624 return; 594 return;