plugin.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
00031
00032
00033 #include "options.h"
00034
00035 #include <stdlib.h>
00036
00037 #include <qstringlist.h>
00038 #include <qfileinfo.h>
00039 #include <qdir.h>
00040
00041 #include <dcopclient.h>
00042 #include <kapplication.h>
00043
00044 #include "pilotSerialDatabase.h"
00045 #include "pilotLocalDatabase.h"
00046
00047 #include "plugin.moc"
00048
00049
00050
00051
00052 ConduitConfig::ConduitConfig(QWidget *parent,
00053 const char *name,
00054 const QStringList &args) :
00055 UIDialog(parent,name,PluginUtility::isModal(args)),
00056 fConfig(0L)
00057 {
00058 FUNCTIONSETUP;
00059 }
00060
00061
00062 ConduitConfig::~ConduitConfig()
00063 {
00064 FUNCTIONSETUP;
00065 }
00066
00067 ConduitAction::ConduitAction(KPilotDeviceLink *p,
00068 const char *name,
00069 const QStringList &args) :
00070 SyncAction(p,name),
00071 fConfig(0L),
00072 fDatabase(0L),
00073 fLocalDatabase(0L),
00074 fTest(args.contains(CSL1("--test"))),
00075 fBackup(args.contains(CSL1("--backup"))),
00076 fLocal(args.contains(CSL1("--local")))
00077 {
00078 FUNCTIONSETUP;
00079
00080 #ifdef DEBUG
00081 for (QStringList::ConstIterator it = args.begin();
00082 it != args.end();
00083 ++it)
00084 {
00085 DEBUGCONDUIT << fname << ": " << *it << endl;
00086 }
00087 #endif
00088 }
00089
00090 ConduitAction::~ConduitAction()
00091 {
00092 FUNCTIONSETUP;
00093 KPILOT_DELETE(fDatabase);
00094 KPILOT_DELETE(fLocalDatabase);
00095 }
00096
00097 bool ConduitAction::openDatabases_(const QString &name, bool *retrieved)
00098 {
00099 FUNCTIONSETUP;
00100
00101 #ifdef DEBUG
00102 DEBUGCONDUIT << fname
00103 << ": Trying to open database "
00104 << name << endl;
00105 #endif
00106
00107 fLocalDatabase = new PilotLocalDatabase(name);
00108
00109 if (!fLocalDatabase)
00110 {
00111 kdWarning() << k_funcinfo
00112 << ": Could not initialize object for local copy of database \""
00113 << name
00114 << "\"" << endl;
00115 return false;
00116 }
00117
00118
00119 if (!fLocalDatabase->isDBOpen() )
00120 {
00121 QString dbpath(dynamic_cast<PilotLocalDatabase*>(fLocalDatabase)->dbPathName());
00122 KPILOT_DELETE(fLocalDatabase);
00123 #ifdef DEBUG
00124 DEBUGCONDUIT << fname
00125 << ": Backup database "<< dbpath <<" could not be opened. Will fetch a copy from the palm and do a full sync"<<endl;
00126 #endif
00127 struct DBInfo dbinfo;
00128 if (fHandle->findDatabase(name.latin1(), &dbinfo)<0 )
00129 {
00130 #ifdef DEBUG
00131 DEBUGCONDUIT << fname
00132 << ": Could not get DBInfo for "<<name<<"! "<<endl;
00133 #endif
00134 return false;
00135 }
00136 #ifdef DEBUG
00137 DEBUGCONDUIT << fname
00138 << ": Found Palm database: "<<dbinfo.name<<endl
00139 <<"type = "<< dbinfo.type<<endl
00140 <<"creator = "<< dbinfo.creator<<endl
00141 <<"version = "<< dbinfo.version<<endl
00142 <<"index = "<< dbinfo.index<<endl;
00143 #endif
00144 dbinfo.flags &= ~dlpDBFlagOpen;
00145
00146
00147 QFileInfo fi(dbpath);
00148 if (!fi.exists()) {
00149 QDir d(fi.dir(TRUE));
00150 #ifdef DEBUG
00151 DEBUGCONDUIT << fname << ": Creating backup directory "<<d.absPath()<<endl;
00152 #endif
00153 d.mkdir(d.absPath());
00154 }
00155 if (!fHandle->retrieveDatabase(dbpath, &dbinfo) )
00156 {
00157 #ifdef DEBUG
00158 DEBUGCONDUIT << fname << ": Could not retrieve database "<<name<<" from the handheld."<<endl;
00159 #endif
00160 return false;
00161 }
00162 fLocalDatabase = new PilotLocalDatabase(name);
00163 if (!fLocalDatabase || !fLocalDatabase->isDBOpen())
00164 {
00165 #ifdef DEBUG
00166 DEBUGCONDUIT << fname << ": local backup of database "<<name<<" could not be initialized."<<endl;
00167 #endif
00168 return false;
00169 }
00170 if (retrieved) *retrieved=true;
00171 }
00172
00173
00174 fDatabase = new PilotSerialDatabase(pilotSocket(), name ,
00175 this, name.latin1() );
00176
00177 if (!fDatabase)
00178 {
00179 kdWarning() << k_funcinfo
00180 << ": Could not open database \""
00181 << name
00182 << "\" on the pilot."
00183 << endl;
00184 }
00185
00186 return (fDatabase && fDatabase->isDBOpen() &&
00187 fLocalDatabase && fLocalDatabase->isDBOpen() );
00188 }
00189
00190
00191 bool ConduitAction::openDatabases_(const QString &dbName,const QString &localPath)
00192 {
00193 FUNCTIONSETUP;
00194 #ifdef DEBUG
00195 DEBUGCONDUIT << fname << ": Doing local test mode for " << dbName << endl;
00196 #endif
00197 if (localPath.isNull())
00198 {
00199 #ifdef DEBUG
00200 DEBUGCONDUIT << fname
00201 << ": local mode test for one database only."
00202 << endl;
00203 #endif
00204 fDatabase = new PilotLocalDatabase(dbName);
00205 fLocalDatabase = 0L;
00206 return false;
00207 }
00208
00209 fDatabase = new PilotLocalDatabase(localPath,dbName);
00210 fLocalDatabase= new PilotLocalDatabase(dbName);
00211 if (!fLocalDatabase || !fDatabase)
00212 {
00213 const QString *where2 = PilotLocalDatabase::getDBPath();
00214
00215 QString none = CSL1("<null>");
00216 #ifdef DEBUG
00217 DEBUGCONDUIT << fname
00218 << ": Could not open both local copies of \""
00219 << dbName
00220 << "\"" << endl
00221 << "Using \""
00222 << (where2 ? *where2 : none)
00223 << "\" and \""
00224 << (localPath.isEmpty() ? localPath : none)
00225 << "\""
00226 << endl;
00227 #endif
00228 }
00229 #ifdef DEBUG
00230 if (fLocalDatabase)
00231 {
00232 DEBUGCONDUIT << fname
00233 << ": Opened local database "
00234 << fLocalDatabase->dbPathName()
00235 << (fLocalDatabase->isDBOpen() ? " OK" : "")
00236 << endl;
00237 }
00238 if (fDatabase)
00239 {
00240 DEBUGCONDUIT << fname
00241 << ": Opened database "
00242 << fDatabase->dbPathName()
00243 << (fDatabase->isDBOpen() ? " OK" : "")
00244 << endl;
00245 }
00246 #endif
00247
00248 return (fDatabase && fLocalDatabase);
00249 }
00250
00251 bool ConduitAction::openDatabases(const QString &dbName, bool*retrieved)
00252 {
00253 FUNCTIONSETUP;
00254
00255
00256
00257
00258
00259
00260 #ifdef DEBUG
00261 DEBUGCONDUIT << fname
00262 << ": Mode="
00263 << (isTest() ? "test " : "")
00264 << (isLocal() ? "local " : "")
00265 << endl ;
00266 #endif
00267
00268 if (isTest() && isLocal())
00269 {
00270 return openDatabases_(dbName,CSL1("/tmp/"));
00271 }
00272 else
00273 {
00274 return openDatabases_(dbName, retrieved);
00275 }
00276 }
00277
00278 int PluginUtility::findHandle(const QStringList &a)
00279 {
00280 FUNCTIONSETUP;
00281
00282 int handle = -1;
00283 for (QStringList::ConstIterator i = a.begin();
00284 i != a.end(); ++i)
00285 {
00286 if ((*i).left(7) == CSL1("handle="))
00287 {
00288 QString s = (*i).mid(7);
00289 if (s.isEmpty()) continue;
00290
00291 handle = s.toInt();
00292 #ifdef DEBUG
00293 DEBUGCONDUIT << fname
00294 << ": Got handle "
00295 << handle
00296 << endl;
00297 #endif
00298 if (handle<1)
00299 {
00300 kdWarning() << k_funcinfo
00301 << ": Improbable handle value found."
00302 << endl;
00303 }
00304 return handle;
00305 }
00306 }
00307
00308 #ifdef DEBUG
00309 DEBUGCONDUIT << fname
00310 << ": No handle= parameter found."
00311 << endl;
00312 #endif
00313
00314 return -1;
00315 }
00316
00317 bool PluginUtility::isModal(const QStringList &a)
00318 {
00319 return a.contains(CSL1("modal"));
00320 }
00321
00322 bool PluginUtility::isRunning(const QCString &n)
00323 {
00324 FUNCTIONSETUP;
00325
00326 DCOPClient *dcop = KApplication::kApplication()->dcopClient();
00327 QCStringList apps = dcop->registeredApplications();
00328 return apps.contains(n);
00329 }
This file is part of the documentation for kdelibs Version 3.1.4.