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 #include "options.h"
00032
00033 #include <qfile.h>
00034
00035 #include <dcopclient.h>
00036 #include <ktempfile.h>
00037
00038
00039 #include <kapplication.h>
00040 #include "kroupware.h"
00041 #include "kpilotConfig.h"
00042
00043 static const char *kroupware_id =
00044 "$Id: kroupware.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00045
00046 KroupwareSync::KroupwareSync(bool pre,int parts,KPilotDeviceLink *p) :
00047 SyncAction(p,pre ? "KroupwarePreSync" : "KroupwarePostSync"),
00048 fPre(pre),
00049 fParts(parts)
00050 {
00051 (void) kroupware_id;
00052 }
00053
00054 bool KroupwareSync::exec()
00055 {
00056 FUNCTIONSETUP;
00057 if (fPre)
00058 {
00059 preSync();
00060 }
00061 else
00062 {
00063 postSync();
00064 }
00065
00066 emit syncDone(this);
00067 return true;
00068 }
00069
00070 void KroupwareSync::cleanupConfig()
00071 {
00072
00073
00074 KConfig* c = KPilotSettings::self()->config();
00075 c->setGroup("todoOptions");
00076 if ( c->hasKey( "CalFileBackup") ) {
00077 QString fn = c->readPathEntry( "CalFileBackup" );
00078 if ( fn != CSL1("empty") ) {
00079 c->writePathEntry( "CalFile" ,fn );
00080 c->writeEntry( "CalFileBackup" , "empty" );
00081 }
00082 }
00083 c->setGroup("vcalOptions");
00084 if ( c->hasKey( "CalFileBackup") ) {
00085 QString fn = c->readPathEntry( "CalFileBackup" );
00086 if ( fn != CSL1("empty") ) {
00087 c->writePathEntry( "CalFile" ,fn );
00088 c->writeEntry( "CalFileBackup" , "empty" );
00089 }
00090 }
00091 c->setGroup("Abbrowser-conduit");
00092 c->writeEntry( "KMailTempFile" , "empty" );
00093 KPilotSettings::writeConfig();
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 void KroupwareSync::start_syncCal_TodosWithKMail( bool cal, bool todos )
00103 {
00104 if ( !cal && ! todos )
00105 return;
00106 KConfig*c = KPilotSettings::self()->config();
00107 DCOPClient *client = kapp->dcopClient();
00108 KTempFile tempfile;
00109 QString filename = tempfile.name();
00110 QByteArray data, reply_data;
00111 QCString reply_type;
00112 QDataStream arg(data, IO_WriteOnly);
00113 arg << filename;
00114 if (!client->call( "kmail" ,
00115 "KOrganizerSyncIface",
00116 "pullSyncData(QString)",
00117 data,
00118 reply_type,
00119 reply_data)) {
00120 logMessage( CSL1("Calling KMail over DCOP failed!" ));
00121 logMessage(CSL1("Not syncing calendars with KMail"));
00122 logMessage(CSL1("Not syncing to-dos with KMail"));
00123 }
00124 else {
00125 logMessage(CSL1("Calling Cal/Todo over DCOP succeeded"));
00126
00127 _syncWithKMail = true;
00128 if ( todos ) {
00129 logMessage( i18n("Syncing to-dos with KMail" ));
00130 c->setGroup("todoOptions");
00131 QString fn = c->readPathEntry( "CalFile" );
00132 c->writePathEntry( "CalFileBackup" ,fn );
00133 c->writePathEntry( "CalFile" ,filename );
00134 }
00135 else
00136 logMessage( CSL1("Not syncing todos with KMail" ));
00137 if ( cal ) {
00138 logMessage( i18n("Syncing calendar with KMail" ));
00139 c->setGroup("vcalOptions");
00140 QString fn = c->readPathEntry( "CalFile" );
00141 c->writePathEntry( "CalFileBackup" ,fn );
00142 c->writePathEntry( "CalFile" ,filename );
00143 }
00144 else
00145 logMessage( CSL1("Not syncing calendar with KMail" ));
00146 }
00147 KPilotSettings::self()->writeConfig();
00148 }
00149
00150 void KroupwareSync::start_syncAddWithKMail()
00151 {
00152 logMessage( CSL1("Syncing Addresses with KMail" ));
00153 DCOPClient *client = kapp->dcopClient();
00154 KTempFile tempfile;
00155 QString filename = tempfile.name();
00156 QByteArray data, reply_data;
00157 QCString reply_type;
00158 QDataStream arg(data, IO_WriteOnly);
00159 arg << filename;
00160 if (!client->call( "kmail" ,
00161 "KMailIface",
00162 "requestAddresses(QString)",
00163 data,
00164 reply_type,
00165 reply_data)) {
00166 logMessage(CSL1("Calling KMail over DCOP failed!" ));
00167 logMessage(CSL1("Not syncing Addresses with KMail"));
00168 }
00169 else {
00170
00171 KConfig*c = KPilotSettings::self()->config();
00172 logMessage(CSL1("Calling addresses over DCOP succeeded"));
00173 c->setGroup("Abbrowser-conduit");
00174 c->writePathEntry( "KMailTempFile" , filename );
00175 KPilotSettings::self()->writeConfig();
00176 }
00177 }
00178 void KroupwareSync::start_syncNotesWithKMail()
00179 {
00180 logMessage( i18n("Syncing Notes with Mail" ));
00181 logMessage( CSL1("Syncing Notes-sorry not implemented" ));
00182 }
00183
00184 void KroupwareSync::end_syncCal_TodosWithKMail( bool cal, bool todos)
00185 {
00186 if ( !cal && ! todos )
00187 return;
00188 QString filename;
00189 KConfig*c=KPilotSettings::self()->config();
00190 if ( todos ) {
00191 logMessage( i18n("Rewriting to-dos to KMail..." ));
00192 c->setGroup("todoOptions");
00193 filename = c->readPathEntry( "CalFile" );
00194 c->writePathEntry( "CalFile", c->readPathEntry( "CalFileBackup" ) );
00195 c->writeEntry( "CalFileBackup", "empty");
00196 }
00197 if ( cal ) {
00198 logMessage( i18n("Rewriting Calendar to KMail" ));
00199 c->setGroup("vcalOptions");
00200 filename = c->readPathEntry( "CalFile" );
00201 QString tf = c->readPathEntry( "CalFileBackup" ) ;
00202 c->writePathEntry( "CalFile" , tf );
00203 c->writeEntry( "CalFileBackup" ,"empty");
00204 }
00205 KPilotSettings::writeConfig();
00206 if ( !filename.isEmpty() ) {
00207 logMessage(CSL1("Try to call KMail via DCOP to finish sync..."));
00208
00209 DCOPClient *client = kapp->dcopClient();
00210 QByteArray data, reply_data;
00211 QCString reply_type;
00212 QDataStream arg(data, IO_WriteOnly);
00213 arg << filename;
00214 if (!client->call( "kmail" ,
00215 "KOrganizerSyncIface",
00216 "pushSyncData(QString)",
00217 data,
00218 reply_type,
00219 reply_data)) {
00220 logMessage( CSL1("Calling KMail over DCOP failed!" ));
00221 logMessage( CSL1("Sync is not complete"));
00222 logMessage( CSL1("Data from Palm stored in file:"));
00223 logMessage(filename);
00224 } else {
00225 logMessage(CSL1("Calling over DCOP succeeded"));
00226 logMessage(CSL1("Sync to KMail has finished successfully"));
00227 }
00228 QFile::remove( filename );
00229 }
00230 }
00231 void KroupwareSync::end_syncAddWithKMail()
00232 {
00233 logMessage( i18n("Syncing KMail with Addresses " ));
00234 DCOPClient *client = kapp->dcopClient();
00235
00236 KConfig*c = KPilotSettings::self()->config();
00237 c->setGroup("Abbrowser-conduit");
00238 QString filename = c->readPathEntry( "KMailTempFile" );
00239 c->writeEntry( "KMailTempFile" , "empty" );
00240 KPilotSettings::writeConfig();
00241 QByteArray data, reply_data;
00242 QCString reply_type;
00243 QDataStream arg(data, IO_WriteOnly);
00244 arg << filename;
00245 arg << QStringList();
00246 if (!client->call( "kmail" ,
00247 "KMailIface",
00248 "storeAddresses(QString, QStringList)",
00249 data,
00250 reply_type,
00251 reply_data)) {
00252 logMessage(CSL1("Calling KMail over DCOP failed!" ));
00253 logMessage(CSL1("Not syncing Addresses with KMail"));
00254 }
00255 else {
00256 logMessage(CSL1("Calling store addresses over DCOP succeeded"));
00257 }
00258
00259 }
00260 void KroupwareSync::end_syncNotesWithKMail()
00261 {
00262 logMessage( i18n("Syncing KMail with Notes" ));
00263 logMessage( CSL1("Syncing Notes-sorry not implemented" ));
00264 }
00265
00266
00267
00268 bool KroupwareSync::startKMail(QString *error)
00269 {
00270 FUNCTIONSETUP;
00271
00272 QCString kmdcop;
00273 QString mess;
00274 int pid;
00275
00276 return KApplication::startServiceByDesktopName(CSL1("kmail"),
00277 QString::null,
00278 error,
00279 &kmdcop,
00280 &pid
00281 )==0;
00282 }
00283
00284
00285 void KroupwareSync::preSync()
00286 {
00287 cleanupConfig();
00288 start_syncCal_TodosWithKMail( fParts & Cal, fParts & Todo );
00289 if (fParts & Notes)
00290 {
00291 start_syncNotesWithKMail();
00292 }
00293 if (fParts & Address)
00294 {
00295 start_syncAddWithKMail();
00296 }
00297 }
00298
00299 void KroupwareSync::postSync()
00300 {
00301 cleanupConfig();
00302 end_syncCal_TodosWithKMail( fParts & Cal, fParts & Todo );
00303 if (fParts & Notes)
00304 {
00305 end_syncNotesWithKMail();
00306 }
00307 if (fParts & Address)
00308 {
00309 end_syncAddWithKMail();
00310 }
00311 }
00312
00313
00314