JPilotProxy-factory.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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);
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 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
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
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
00177 int JPilotProxyConduitFactory::removePlugin( QString path) {
00178 FUNCTIONSETUP;
00179
00180 JPlugin*plugintodel=NULL;
00181
00182 PluginIterator_t it(*plugins);
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
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
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
00233
00234
00235
00236
00237
00238
00239
00240
00241 }
00242
This file is part of the documentation for kdelibs Version 3.1.4.