kpilot/lib
plugin.cc00001
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
00031
00032
00033
00034 #include "options.h"
00035
00036 #include <stdlib.h>
00037
00038 #include <qstringlist.h>
00039 #include <qfileinfo.h>
00040 #include <qdir.h>
00041 #include <qregexp.h>
00042
00043 #include <dcopclient.h>
00044 #include <kapplication.h>
00045 #include <kmessagebox.h>
00046 #include <kstandarddirs.h>
00047 #include <klibloader.h>
00048
00049 #include "pilotSerialDatabase.h"
00050 #include "pilotLocalDatabase.h"
00051
00052 #include "plugin.moc"
00053
00054 ConduitConfigBase::ConduitConfigBase(QWidget *parent,
00055 const char *name) :
00056 QObject(parent,name),
00057 fModified(false),
00058 fWidget(0L),
00059 fConduitName(i18n("Unnamed"))
00060 {
00061 FUNCTIONSETUP;
00062 }
00063
00064 ConduitConfigBase::~ConduitConfigBase()
00065 {
00066 FUNCTIONSETUP;
00067 }
00068
00069 void ConduitConfigBase::modified()
00070 {
00071 fModified=true;
00072 emit changed(true);
00073 }
00074
00075 QString ConduitConfigBase::maybeSaveText() const
00076 {
00077 FUNCTIONSETUP;
00078
00079 return i18n("<qt>The <i>%1</i> conduit's settings have been changed. Do you "
00080 "want to save the changes before continuing?</qt>").arg(this->conduitName());
00081 }
00082
00083 bool ConduitConfigBase::maybeSave()
00084 {
00085 FUNCTIONSETUP;
00086
00087 if (!isModified()) return true;
00088
00089 int r = KMessageBox::questionYesNoCancel(fWidget,
00090 maybeSaveText(),
00091 i18n("%1 Conduit").arg(this->conduitName()), KStdGuiItem::save(), KStdGuiItem::discard());
00092 if (r == KMessageBox::Cancel) return false;
00093 if (r == KMessageBox::Yes) commit();
00094 return true;
00095 }
00096
00097 ConduitAction::ConduitAction(KPilotLink *p,
00098 const char *name,
00099 const QStringList &args) :
00100 SyncAction(p,name),
00101 fDatabase(0L),
00102 fLocalDatabase(0L),
00103 fSyncDirection(args),
00104 fConflictResolution(SyncAction::eAskUser),
00105 fFirstSync(false)
00106 {
00107 FUNCTIONSETUP;
00108
00109 QString cResolution(args.grep(QRegExp(CSL1("--conflictResolution \\d*"))).first());
00110 if (cResolution.isEmpty())
00111 {
00112 fConflictResolution=(SyncAction::ConflictResolution)
00113 cResolution.replace(QRegExp(CSL1("--conflictResolution (\\d*)")), CSL1("\\1")).toInt();
00114 }
00115
00116 for (QStringList::ConstIterator it = args.begin();
00117 it != args.end();
00118 ++it)
00119 {
00120 DEBUGLIBRARY << fname << ": " << *it << endl;
00121 }
00122
00123 DEBUGLIBRARY << fname << ": Direction=" << fSyncDirection.name() << endl;
00124 }
00125
00126 ConduitAction::~ConduitAction()
00127 {
00128 FUNCTIONSETUP;
00129 KPILOT_DELETE(fDatabase);
00130 KPILOT_DELETE(fLocalDatabase);
00131 }
00132
00133 bool ConduitAction::openDatabases(const QString &name, bool *retrieved)
00134 {
00135 FUNCTIONSETUP;
00136
00137 DEBUGLIBRARY << fname
00138 << ": Trying to open database "
00139 << name << endl;
00140 DEBUGLIBRARY << fname
00141 << ": Mode="
00142 << (syncMode().isTest() ? "test " : "")
00143 << (syncMode().isLocal() ? "local " : "")
00144 << endl ;
00145
00146 KPILOT_DELETE(fLocalDatabase);
00147
00148 QString localPathName = PilotLocalDatabase::getDBPath() + name;
00149 PilotLocalDatabase *localDB = new PilotLocalDatabase( localPathName );
00150
00151 if (!localDB)
00152 {
00153 kdWarning() << k_funcinfo
00154 << ": Could not initialize object for local copy of database \""
00155 << name
00156 << "\"" << endl;
00157 if (retrieved) *retrieved = false;
00158 return false;
00159 }
00160
00161
00162 if (!localDB->isOpen() )
00163 {
00164 QString dbpath(localDB->dbPathName());
00165 KPILOT_DELETE(localDB);
00166 DEBUGLIBRARY << fname
00167 << ": Backup database " << dbpath
00168 << " not found." << endl;
00169 struct DBInfo dbinfo;
00170
00171
00172 if (deviceLink()->findDatabase(Pilot::toPilot( name ), &dbinfo)<0 )
00173 {
00174 kdWarning() << k_funcinfo
00175 << ": Could not get DBInfo for " << name << endl;
00176 if (retrieved) *retrieved = false;
00177 return false;
00178 }
00179
00180 DEBUGLIBRARY << fname
00181 << ": Found Palm database: " << dbinfo.name <<endl
00182 << fname << ": type = " << dbinfo.type
00183 << " creator = " << dbinfo.creator
00184 << " version = " << dbinfo.version
00185 << " index = " << dbinfo.index << endl;
00186 dbinfo.flags &= ~dlpDBFlagOpen;
00187
00188
00189 QFileInfo fi(dbpath);
00190 QString path(QFileInfo(dbpath).dir(true).absPath());
00191 if (!path.endsWith(CSL1("/"))) path.append(CSL1("/"));
00192 if (!KStandardDirs::exists(path))
00193 {
00194 DEBUGLIBRARY << fname << ": Trying to create path for database: <"
00195 << path << ">" << endl;
00196 KStandardDirs::makeDir(path);
00197 }
00198 if (!KStandardDirs::exists(path))
00199 {
00200 DEBUGLIBRARY << fname << ": Database directory does not exist." << endl;
00201 if (retrieved) *retrieved = false;
00202 return false;
00203 }
00204
00205 if (!deviceLink()->retrieveDatabase(dbpath, &dbinfo) )
00206 {
00207 kdWarning() << k_funcinfo << ": Could not retrieve database "<<name<<" from the handheld."<<endl;
00208 if (retrieved) *retrieved = false;
00209 return false;
00210 }
00211 localDB = new PilotLocalDatabase( localPathName );
00212 if (!localDB || !localDB->isOpen())
00213 {
00214 kdWarning() << k_funcinfo << ": local backup of database "<<name<<" could not be initialized."<<endl;
00215 if (retrieved) *retrieved = false;
00216 return false;
00217 }
00218 if (retrieved) *retrieved=true;
00219 }
00220 fLocalDatabase = localDB;
00221
00222 fDatabase = deviceLink()->database( name );
00223
00224 if (!fDatabase)
00225 {
00226 kdWarning() << k_funcinfo
00227 << ": Could not open database \""
00228 << name
00229 << "\" on the pilot."
00230 << endl;
00231 }
00232
00233 return (fDatabase && fDatabase->isOpen() &&
00234 fLocalDatabase && fLocalDatabase->isOpen() );
00235 }
00236
00237
00238 bool ConduitAction::changeSync(SyncMode::Mode m)
00239 {
00240 FUNCTIONSETUP;
00241
00242 if ( fSyncDirection.isSync() && SyncMode::eFullSync == m)
00243 {
00244 fSyncDirection.setMode(m);
00245 return true;
00246 }
00247 return false;
00248 }
00249
00250
00251 namespace PluginUtility
00252 {
00253
00254 QString findArgument(const QStringList &a, const QString &arg)
00255 {
00256 FUNCTIONSETUP;
00257
00258 QString search;
00259
00260 if (arg.startsWith( CSL1("--") ))
00261 {
00262 search = arg;
00263 }
00264 else
00265 {
00266 search = CSL1("--") + arg;
00267 }
00268 search.append( CSL1("=") );
00269
00270
00271 QStringList::ConstIterator end = a.end();
00272 for (QStringList::ConstIterator i = a.begin(); i != end; ++i)
00273 {
00274 if ((*i).startsWith( search ))
00275 {
00276 QString s = (*i).mid(search.length());
00277 return s;
00278 }
00279 }
00280
00281 return QString::null;
00282 }
00283
00284 bool isRunning(const QCString &n)
00285 {
00286 DCOPClient *dcop = KApplication::kApplication()->dcopClient();
00287 QCStringList apps = dcop->registeredApplications();
00288 return apps.contains(n);
00289 }
00290
00291
00292 unsigned long pluginVersion(const KLibrary *lib)
00293 {
00294 QString symbol = CSL1("version_");
00295 symbol.append(lib->name());
00296
00297 if (!lib->hasSymbol(symbol.latin1())) return 0;
00298
00299 unsigned long *p = (unsigned long *)(lib->symbol(symbol.latin1()));
00300 return *p;
00301 }
00302
00303
00304 QString pluginVersionString(const KLibrary *lib)
00305 {
00306 QString symbol= CSL1("id_");
00307 symbol.append(lib->name());
00308
00309 if (!lib->hasSymbol(symbol.latin1())) return QString::null;
00310
00311 return QString::fromLatin1(*((const char **)(lib->symbol(symbol.latin1()))));
00312 }
00313
00314
00315 }
00316
|