kpilot Library API Documentation

JPilotProxy-factory.cc

00001 /* JPilotProxy-factory.cc                                         KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 ** Copyright (C) 2002 by Reinhold Kainhofer
00005 **
00006 ** This file defines the factory for the JPilotProxy-conduit plugin.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 #include <qdir.h>
00033 #include <kinstance.h>
00034 #include <kaboutdata.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <dirent.h>
00038 #include "kpilotlink.h"
00039 #include "kconfig.h"
00040 #include "JPilotProxy-factory.moc"
00041 
00042 
00043 extern "C"
00044 {
00045 
00046 void *init_libJPilotProxy() {
00047         FUNCTIONSETUP;
00048 //      K_EXPORT_COMPONENT_FACTORY( libkspread, KSpreadFactory )
00049         return new JPilotProxyConduitFactory;
00050 }
00051 
00052 };
00053 
00054 
00055 bool JPilotProxyConduitFactory::pluginsloaded=false;
00056 QString JPilotProxyConduitFactory::settingsGroup=CSL1("JPilotPluginProxy");
00057 QString JPilotProxyConduitFactory::PluginPathes=CSL1("PluginPathes");
00058 QString JPilotProxyConduitFactory::LoadedPlugins=CSL1("LoadedPlugins");
00059 
00060 KAboutData *JPilotProxyConduitFactory::fAbout = 0L;
00061 PluginList_t *JPilotProxyConduitFactory::plugins=0L;
00062 
00063 JPilotProxyConduitFactory::JPilotProxyConduitFactory(QObject *p, const char *n) :
00064                 KLibFactory(p,n)  {
00065         FUNCTIONSETUP;
00066         fConfig=0L;
00067         plugins=new PluginList_t();
00068         // load the library containing the JPilot API functions. If this fails, any plugin will probably crash KPilot, so just exit!!!
00069         apilib=KLibLoader::self()->globalLibrary("libJPilotAPI");
00070 
00071 #ifdef DEBUG
00072         if (!apilib) 
00073         {
00074                 DEBUGCONDUIT << fname 
00075                         << ": JPilotAPI library could not be loaded\n  error ["
00076                         << KLibLoader::self()->lastErrorMessage()<<"]" << endl;
00077         }
00078         else 
00079         {
00080                 DEBUGCONDUIT << fname << ": loaded JPilotAPI library" << endl;
00081         }
00082 #endif
00083 
00084   jp_logf(4, "testing...");
00085 
00086         fInstance = new KInstance(n);
00087         fAbout = new KAboutData(n,
00088                 I18N_NOOP("JPilotProxy Conduit for KPilot"),
00089                 KPILOT_VERSION,
00090                 I18N_NOOP("Configures the JPilotProxy Conduit for KPilot"),
00091                 KAboutData::License_GPL,
00092                 "(C) 2002, Reinhold F. Kainhofer");
00093         fAbout->addAuthor("Dan Pilone", I18N_NOOP("Original Author of KPilot"));
00094         fAbout->addAuthor("Adriaan de Groot", I18N_NOOP("Maintainer of KPilot"), "groot@kde.org", "http://www.cs.kun.nl/~adridg/kpilot");
00095         fAbout->addAuthor("Judd Montgomery", I18N_NOOP("Author of JPilot"),     "judd@engineer.com", "http://www.jpilot.org/");
00096         fAbout->addAuthor("Reinhold Kainhofer", I18N_NOOP("Original author and maintainer of this conduit"), "reinhold@kainhofer.com", "http://reinhold.kainhofer.com");
00097 }
00098 
00099 JPilotProxyConduitFactory::~JPilotProxyConduitFactory() {
00100         FUNCTIONSETUP;
00101 
00102         PluginIterator_t it(*plugins); // iterator for plugin list
00103         for ( ; it.current(); ++it ) {
00104 #ifdef DEBUG
00105                 DEBUGCONDUIT << "unloading library "
00106                         << it.current()->info.fullpath
00107                         << " (" << it.current()->info.name
00108                         << "), address=" << it.current()->lib << endl;
00109 #endif
00110                 it.current()->exit_cleanup();
00111         }
00112         if (apilib) KLibLoader::self()->unloadLibrary(apilib->fileName());
00113 
00114         KPILOT_DELETE(fInstance);
00115         KPILOT_DELETE(fAbout);
00116 }
00117 
00118 /* virtual */ QObject *JPilotProxyConduitFactory::createObject( QObject *p,
00119         const char *n, const char *c, const QStringList &a) {
00120         FUNCTIONSETUP;
00121 
00122 #ifdef DEBUG
00123         DEBUGCONDUIT << fname << ": Creating object of class "  << c << endl;
00124 #endif
00125 
00126         if (qstrcmp(c,"ConduitConfig")==0) {
00127                 QWidget *w = dynamic_cast<QWidget *>(p);
00128 
00129                 if (w) {
00130                         return createSetupWidget(w,n,a);
00131                 } else {
00132 #ifdef DEBUG
00133                         DEBUGCONDUIT << fname << ": Couldn't cast parent to widget." << endl;
00134 #endif
00135                         return 0L;
00136                 }
00137         }
00138 
00139         if (qstrcmp(c,"SyncAction")==0) {
00140                 KPilotDeviceLink *d = dynamic_cast<KPilotDeviceLink *>(p);
00141 
00142                 if (d) {
00143                         return createConduit(d,n,a);
00144                 } else {
00145                         kdError() << k_funcinfo
00146                                 << ": Couldn't cast to KPilotDeviceLink."
00147                                 << endl;
00148                 }
00149         }
00150 
00151         return 0L;
00152 }
00153 
00154 JPlugin*JPilotProxyConduitFactory::addPlugin( QString path, bool on) {
00155         FUNCTIONSETUP;
00156         // TODO: search the plugin list if the plugin was already loaded
00157         JPlugin*newplugin=new JPlugin( path );
00158 #ifdef DEBUG
00159         DEBUGCONDUIT<<"successfully created a JPlugin instance for "<<path<<endl;
00160 #endif
00161         if (newplugin->loaded) {
00162                 newplugin->info.sync_on=on;
00163 #ifdef DEBUG
00164                 DEBUGCONDUIT<<"loading "<<path<<" was successful"<<endl;
00165 #endif
00166                 // if the plugin was loaded successfully, insert it into the list of plugins
00167                 plugins->append(newplugin);
00168                 jp_startup_info si;
00169                 si.base_dir="/usr/local";
00170                 newplugin->startup(&si);
00171                 return newplugin;
00172         } else delete newplugin;
00173         return 0;
00174 }
00175 
00176 // This is not yet optimal, but should work for now...
00177 int JPilotProxyConduitFactory::removePlugin( QString path) {
00178         FUNCTIONSETUP;
00179         
00180         JPlugin*plugintodel=NULL;
00181 
00182         PluginIterator_t it(*plugins); // iterator for plugin list
00183         for ( ; it.current(); ++it ) {
00184                 JPlugin *plug = it.current();
00185                 if (plug->lib && strcmp(plug->info.fullpath, path)) plugintodel=plug;
00186         }
00187 
00188         if (plugintodel) {
00189                 plugins->take(plugins->find(plugintodel));
00190                 plugintodel->exit_cleanup();
00191                 delete plugintodel;
00192         }
00193 }
00194 
00195 int JPilotProxyConduitFactory::addPluginPath(QString path, KConfig*fC) {
00196         FUNCTIONSETUP;
00197         // find the list of possible plugins in the directory given by path
00198         QDir dir(path);
00199         QStringList plugs=dir.entryList("*.so");
00200 
00201         for (QStringList::Iterator it = plugs.begin(); it != plugs.end(); ++it ) {
00202 #ifdef DEBUG
00203                 DEBUGCONDUIT<<"Load plugin "<<(*it)<<endl;
00204 #endif
00205                 bool on=false;
00206                 if (fC) {
00207                         KConfigGroupSaver cfgs(fC, settingsGroup);
00208                         on=fC->readBoolEntry(*it);
00209                 }
00210                 addPlugin(dir.absFilePath(*it), on);
00211         }
00212 }
00213 
00214 int JPilotProxyConduitFactory::loadPlugins(KConfig*fC) {
00215         FUNCTIONSETUP;
00216         if (!fC) return -1;
00217                 
00218         KConfigGroupSaver cfgs(fC, settingsGroup);
00219         
00220         QStringList pathes=fC->readListEntry(PluginPathes);
00221         for (QStringList::Iterator it = pathes.begin(); it != pathes.end(); ++it ) {
00222                 addPluginPath(*it, fC);
00223         }
00224         // now load the individual plugins...
00225         QStringList plugs=fC->readListEntry(LoadedPlugins);
00226         for (QStringList::Iterator it = plugs.begin(); it != plugs.end(); ++it ) {
00227                 addPlugin(*it, fC->readBoolEntry(*it));
00228         }
00229         pluginsloaded=true;
00230         
00231         QStringList loadedplugs;
00232         // TODO: Write out the plugin list to the config file.
00233 /*XXX   PluginIterator_t it(*plugins); // iterator for plugin list
00234         for ( ; it.current(); ++it ) {
00235                 loadedplugs.append(it.current()->info.fullpath);
00236                 // TODO:...
00237 //              QStringList pluginfo();
00238 //              fConfig->
00239         }*/
00240         
00241 }
00242 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:43 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001