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 #include "options.h"
00030
00031 #include <qdir.h>
00032 #include <kinstance.h>
00033 #include <kaboutdata.h>
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <dirent.h>
00037 #include "kpilotlink.h"
00038 #include "kconfig.h"
00039 #include "JPilotProxy-factory.moc"
00040
00041
00042 extern "C"
00043 {
00044
00045 void *init_conduit_JPilotProxy() {
00046 FUNCTIONSETUP;
00047
00048 return new JPilotProxyConduitFactory;
00049 }
00050
00051 };
00052
00053
00054 bool JPilotProxyConduitFactory::pluginsloaded=false;
00055 QString JPilotProxyConduitFactory::settingsGroup="JPilotPluginProxy";
00056 QString JPilotProxyConduitFactory::PluginPathes="PluginPathes";
00057 QString JPilotProxyConduitFactory::LoadedPlugins="LoadedPlugins";
00058
00059 KAboutData *JPilotProxyConduitFactory::fAbout = 0L;
00060 PluginList_t *JPilotProxyConduitFactory::plugins=0L;
00061
00062 JPilotProxyConduitFactory::JPilotProxyConduitFactory(QObject *p, const char *n) :
00063 KLibFactory(p,n) {
00064 FUNCTIONSETUP;
00065 fConfig=0L;
00066 plugins=new PluginList_t();
00067
00068 apilib=KLibLoader::self()->globalLibrary("libJPilotAPI");
00069 #ifdef DEBUG
00070 if (!apilib) DEBUGCONDUIT << fname << ": JPilotAPI library could not be loaded\n error ["<<KLibLoader::self()->lastErrorMessage()<<"]" << endl;
00071 else DEBUGCONDUIT << fname << ": loaded JPilotAPI library" << endl;
00072 #endif
00073 jp_logf(4, "testing...");
00074
00075 fInstance = new KInstance(n);
00076 fAbout = new KAboutData(n,
00077 I18N_NOOP("JPilotProxy Conduit for KPilot"),
00078 KPILOT_VERSION,
00079 I18N_NOOP("Configures the JPilotProxy Conduit for KPilot"),
00080 KAboutData::License_GPL,
00081 "(C) 2002, Reinhold F. Kainhofer");
00082 fAbout->addAuthor("Reinhold Kainhofer", I18N_NOOP("Original author and maintainer of this conduit"), "reinhold@kainhofer.com", "http://reinhold.kainhofer.com");
00083 fAbout->addCredit("Judd Montgomery", I18N_NOOP("Author of JPilot"), "judd@engineer.com", "http://www.jpilot.org/");
00084 }
00085
00086 JPilotProxyConduitFactory::~JPilotProxyConduitFactory() {
00087 FUNCTIONSETUP;
00088
00089 PluginIterator_t it(*plugins);
00090 for ( ; it.current(); ++it ) {
00091 #ifdef DEBUG
00092 DEBUGCONDUIT<<"unloading library "<< it.current()->info.fullpath<<" ("<<it.current()->info.name<<"), address="<<it.current()->lib<<endl;
00093 #endif
00094 it.current()->exit_cleanup();
00095 }
00096 if (apilib) KLibLoader::self()->unloadLibrary(apilib->fileName());
00097
00098 KPILOT_DELETE(fInstance);
00099 KPILOT_DELETE(fAbout);
00100 }
00101
00102 QObject *JPilotProxyConduitFactory::createObject( QObject *p,
00103 const char *n, const char *c, const QStringList &a) {
00104 FUNCTIONSETUP;
00105
00106 #ifdef DEBUG
00107 DEBUGCONDUIT << fname << ": Creating object of class " << c << endl;
00108 #endif
00109
00110 if (qstrcmp(c,"ConduitConfig")==0) {
00111 QWidget *w = dynamic_cast<QWidget *>(p);
00112
00113 if (w) {
00114 return createSetupWidget(w,n,a);
00115 } else {
00116 #ifdef DEBUG
00117 DEBUGCONDUIT << fname << ": Couldn't cast parent to widget." << endl;
00118 #endif
00119 return 0L;
00120 }
00121 }
00122
00123 if (qstrcmp(c,"SyncAction")==0) {
00124 KPilotDeviceLink *d = dynamic_cast<KPilotDeviceLink *>(p);
00125
00126 if (d) {
00127 return createConduit(d,n,a);
00128 } else {
00129 kdError() << k_funcinfo
00130 << ": Couldn't cast to KPilotDeviceLink."
00131 << endl;
00132 }
00133 }
00134
00135 return 0L;
00136 }
00137
00138 JPlugin*JPilotProxyConduitFactory::addPlugin( QString path, bool on) {
00139 FUNCTIONSETUP;
00140
00141 JPlugin*newplugin=new JPlugin( path );
00142 #ifdef DEBUG
00143 DEBUGCONDUIT<<"successfully created a JPlugin instance for "<<path<<endl;
00144 #endif
00145 if (newplugin->loaded) {
00146 newplugin->info.sync_on=on;
00147 #ifdef DEBUG
00148 DEBUGCONDUIT<<"loading "<<path<<" was successful"<<endl;
00149 #endif
00150
00151 plugins->append(newplugin);
00152 jp_startup_info si;
00153 si.base_dir="/usr/local";
00154 newplugin->startup(&si);
00155 return newplugin;
00156 } else delete newplugin;
00157 return 0;
00158 }
00159
00160
00161 int JPilotProxyConduitFactory::removePlugin( QString path) {
00162 FUNCTIONSETUP;
00163
00164 JPlugin*plugintodel=NULL;
00165
00166 PluginIterator_t it(*plugins);
00167 for ( ; it.current(); ++it ) {
00168 JPlugin *plug = it.current();
00169 if (plug->lib && strcmp(plug->info.fullpath, path)) plugintodel=plug;
00170 }
00171
00172 if (plugintodel) {
00173 plugins->take(plugins->find(plugintodel));
00174 plugintodel->exit_cleanup();
00175 delete plugintodel;
00176 }
00177 }
00178
00179 int JPilotProxyConduitFactory::addPluginPath(QString path, KConfig*fC) {
00180 FUNCTIONSETUP;
00181
00182 QDir dir(path);
00183 QStringList plugs=dir.entryList("*.so");
00184
00185 for (QStringList::Iterator it = plugs.begin(); it != plugs.end(); ++it ) {
00186 #ifdef DEBUG
00187 DEBUGCONDUIT<<"Load plugin "<<(*it)<<endl;
00188 #endif
00189 bool on=false;
00190 if (fC) {
00191 KConfigGroupSaver cfgs(fC, settingsGroup);
00192 on=fC->readBoolEntry(*it);
00193 }
00194 addPlugin(dir.absFilePath(*it), on);
00195 }
00196 }
00197
00198 int JPilotProxyConduitFactory::loadPlugins(KConfig*fC) {
00199 FUNCTIONSETUP;
00200 if (!fC) return -1;
00201
00202 KConfigGroupSaver cfgs(fC, settingsGroup);
00203
00204 QStringList pathes=fC->readListEntry(PluginPathes);
00205 for (QStringList::Iterator it = pathes.begin(); it != pathes.end(); ++it ) {
00206 addPluginPath(*it, fC);
00207 }
00208
00209 QStringList plugs=fC->readListEntry(LoadedPlugins);
00210 for (QStringList::Iterator it = plugs.begin(); it != plugs.end(); ++it ) {
00211 addPlugin(*it, fC->readBoolEntry(*it));
00212 }
00213 pluginsloaded=true;
00214
00215 QStringList loadedplugs;
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 }
00226
This file is part of the documentation for kpilot Library Version 3.2.2.