summaryrefslogtreecommitdiff
path: root/noncore
authorzecke <zecke>2004-10-14 01:26:40 (UTC)
committer zecke <zecke>2004-10-14 01:26:40 (UTC)
commita1aed5edd5ccef77d79ccdd2d74f5c029d037617 (patch) (unidiff)
tree64f8342d651e968478df58d1a98db978e950b372 /noncore
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 (limited to 'noncore') (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
@@ -46,30 +46,25 @@
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) )
@@ -137,37 +132,33 @@ MainWindowImp::~MainWindowImp()
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;
@@ -275,106 +266,85 @@ void MainWindowImp::getAllInterfaces()
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