kpilot Library API Documentation

kroupware.cc

00001 /* kroupware.cc KPilot 00002 ** 00003 ** Copyright still to be determined. 00004 ** 00005 ** This file defines the actions taken when KPilot 00006 ** is Kroupware-enabled. Basically it just does a 00007 ** little communication with the local Kroupware agent (KMail). 00008 */ 00009 00010 /* 00011 ** This program is free software; you can redistribute it and/or modify 00012 ** it under the terms of the GNU General Public License as published by 00013 ** the Free Software Foundation; either version 2 of the License, or 00014 ** (at your option) any later version. 00015 ** 00016 ** This program is distributed in the hope that it will be useful, 00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 ** GNU General Public License for more details. 00020 ** 00021 ** You should have received a copy of the GNU General Public License 00022 ** along with this program in a file called COPYING; if not, write to 00023 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00024 ** MA 02111-1307, USA. 00025 */ 00026 00027 /* 00028 ** Bug reports and questions can be sent to kde-pim@kde.org 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,v 1.8 2003/06/28 23:07:24 danimo Exp $"; 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 /* virtual */ bool KroupwareSync::exec() 00055 { 00056 FUNCTIONSETUP; 00057 if (fPre) 00058 { 00059 preSync(); 00060 } 00061 else 00062 { 00063 postSync(); 00064 } 00065 // delayDone(); 00066 emit syncDone(this); 00067 return true; 00068 } 00069 00070 void KroupwareSync::cleanupConfig() 00071 { 00072 // tempfile check in case app has terminated during sync 00073 KPilotConfigSettings &c = KPilotConfig::getConfig(); 00074 c.setGroup("todoOptions"); 00075 if ( c.hasKey( "CalFileBackup") ) { 00076 QString fn = c.readPathEntry( "CalFileBackup" ); 00077 if ( fn != CSL1("empty") ) { 00078 c.writePathEntry( "CalFile" ,fn ); 00079 c.writeEntry( "CalFileBackup" , "empty" ); 00080 } 00081 } 00082 c.setGroup("vcalOptions"); 00083 if ( c.hasKey( "CalFileBackup") ) { 00084 QString fn = c.readPathEntry( "CalFileBackup" ); 00085 if ( fn != CSL1("empty") ) { 00086 c.writePathEntry( "CalFile" ,fn ); 00087 c.writeEntry( "CalFileBackup" , "empty" ); 00088 } 00089 } 00090 c.setGroup("Abbrowser-conduit"); 00091 c.writeEntry( "KMailTempFile" , "empty" ); 00092 c.sync(); 00093 } 00094 00095 // For the log messages, I've added TODO_I18N to the 00096 // ones I consider relevant for the user. The rest is 00097 // really debug info, and shouldn't go to the normal 00098 // sync log for the user. 00099 // 00100 void KroupwareSync::start_syncCal_TodosWithKMail( bool cal, bool todos ) 00101 { 00102 if ( !cal && ! todos ) 00103 return; 00104 KPilotConfigSettings &c = KPilotConfig::getConfig(); 00105 DCOPClient *client = kapp->dcopClient(); 00106 KTempFile tempfile; 00107 QString filename = tempfile.name(); 00108 QByteArray data, reply_data; 00109 QCString reply_type; 00110 QDataStream arg(data, IO_WriteOnly); 00111 arg << filename; 00112 if (!client->call( "kmail" , 00113 "KOrganizerSyncIface", 00114 "pullSyncData(QString)", 00115 data, 00116 reply_type, 00117 reply_data)) { 00118 logMessage( CSL1("Calling KMail over DCOP failed!" )); 00119 logMessage(CSL1("Not syncing Calendars with KMail")); 00120 logMessage(CSL1("Not syncing Todos with KMail")); 00121 } 00122 else { 00123 logMessage(CSL1("Calling Cal/Todo over DCOP succeeded")); 00124 // now prepare for syncing 00125 _syncWithKMail = true; 00126 if ( todos ) { 00127 logMessage( TODO_I18N("Syncing todos with KMail" )); 00128 c.setGroup("todoOptions"); 00129 QString fn = c.readPathEntry( "CalFile" ); 00130 c.writePathEntry( "CalFileBackup" ,fn ); 00131 c.writePathEntry( "CalFile" ,filename ); 00132 } 00133 else 00134 logMessage( CSL1("Not syncing todos with KMail" )); 00135 if ( cal ) { 00136 logMessage( TODO_I18N("Syncing calendar with KMail" )); 00137 c.setGroup("vcalOptions"); 00138 QString fn = c.readPathEntry( "CalFile" ); 00139 c.writePathEntry( "CalFileBackup" ,fn ); 00140 c.writePathEntry( "CalFile" ,filename ); 00141 } 00142 else 00143 logMessage( CSL1("Not syncing calendar with KMail" )); 00144 } 00145 c.sync(); 00146 } 00147 00148 void KroupwareSync::start_syncAddWithKMail() 00149 { 00150 logMessage( CSL1("Syncing Addresses with KMail" )); 00151 DCOPClient *client = kapp->dcopClient(); 00152 KTempFile tempfile; 00153 QString filename = tempfile.name(); 00154 QByteArray data, reply_data; 00155 QCString reply_type; 00156 QDataStream arg(data, IO_WriteOnly); 00157 arg << filename; 00158 if (!client->call( "kmail" , 00159 "KMailIface", 00160 "requestAddresses(QString)", 00161 data, 00162 reply_type, 00163 reply_data)) { 00164 logMessage(CSL1("Calling KMail over DCOP failed!" )); 00165 logMessage(CSL1("Not syncing Addresses with KMail")); 00166 } 00167 else { 00168 KPilotConfigSettings &c = KPilotConfig::getConfig(); 00169 logMessage(CSL1("Calling addresses over DCOP succeeded")); 00170 c.setGroup("Abbrowser-conduit"); 00171 c.writePathEntry( "KMailTempFile" , filename ); 00172 c.sync(); 00173 } 00174 } 00175 void KroupwareSync::start_syncNotesWithKMail() 00176 { 00177 logMessage( TODO_I18N("Syncing Notes with Mail" )); 00178 logMessage( CSL1("Syncing Notes-sorry not implemented" )); 00179 } 00180 00181 void KroupwareSync::end_syncCal_TodosWithKMail( bool cal, bool todos) 00182 { 00183 if ( !cal && ! todos ) 00184 return; 00185 QString filename; 00186 KPilotConfigSettings &c = KPilotConfig::getConfig(); 00187 if ( todos ) { 00188 logMessage( TODO_I18N("Rewriting Todos to KMail..." )); 00189 c.setGroup("todoOptions"); 00190 filename = c.readPathEntry( "CalFile" ); 00191 c.writePathEntry( "CalFile" ,c.readPathEntry( "CalFileBackup" ) ); 00192 c.writeEntry( "CalFileBackup" ,"empty"); 00193 } 00194 if ( cal ) { 00195 logMessage( TODO_I18N("Rewriting Calendar to KMail" )); 00196 c.setGroup("vcalOptions"); 00197 filename = c.readPathEntry( "CalFile" ); 00198 QString tf = c.readPathEntry( "CalFileBackup" ) ; 00199 c.writePathEntry( "CalFile" , tf ); 00200 c.writeEntry( "CalFileBackup" ,"empty"); 00201 } 00202 c.sync(); 00203 if ( !filename.isEmpty() ) { 00204 logMessage(CSL1("Try to call KMail via DCOP to finish sync...")); 00205 // try DCOP connection to KMail 00206 DCOPClient *client = kapp->dcopClient(); 00207 QByteArray data, reply_data; 00208 QCString reply_type; 00209 QDataStream arg(data, IO_WriteOnly); 00210 arg << filename; 00211 if (!client->call( "kmail" /*"korganizer" kmdcop */, 00212 "KOrganizerSyncIface", 00213 "pushSyncData(QString)", 00214 data, 00215 reply_type, 00216 reply_data)) { 00217 logMessage( CSL1("Calling KMail over DCOP failed!" )); 00218 logMessage( CSL1("Sync is not complete")); 00219 logMessage( CSL1("Data from Palm stored in file:")); 00220 logMessage(filename); 00221 } else { 00222 logMessage(CSL1("Calling over DCOP succeeded")); 00223 logMessage(CSL1("Sync to KMail has finished successfully")); 00224 } 00225 QFile::remove( filename ); 00226 } 00227 } 00228 void KroupwareSync::end_syncAddWithKMail() 00229 { 00230 logMessage( TODO_I18N("Syncing KMail with Addresses " )); 00231 DCOPClient *client = kapp->dcopClient(); 00232 KPilotConfigSettings &c = KPilotConfig::getConfig(); 00233 c.setGroup("Abbrowser-conduit"); 00234 QString filename = c.readPathEntry( "KMailTempFile" ); 00235 c.writeEntry( "KMailTempFile" , "empty" ); 00236 c.sync(); 00237 QByteArray data, reply_data; 00238 QCString reply_type; 00239 QDataStream arg(data, IO_WriteOnly); 00240 arg << filename; 00241 arg << QStringList(); 00242 if (!client->call( "kmail" , 00243 "KMailIface", 00244 "storeAddresses(QString, QStringList)", 00245 data, 00246 reply_type, 00247 reply_data)) { 00248 logMessage(CSL1("Calling KMail over DCOP failed!" )); 00249 logMessage(CSL1("Not syncing Addresses with KMail")); 00250 } 00251 else { 00252 logMessage(CSL1("Calling store addresses over DCOP succeeded")); 00253 } 00254 //QFile::remove( filename ); 00255 } 00256 void KroupwareSync::end_syncNotesWithKMail() 00257 { 00258 logMessage( TODO_I18N("Syncing KMail with Notes" )); 00259 logMessage( CSL1("Syncing Notes-sorry not implemented" )); 00260 } 00261 00262 00263 00264 /* static */ bool KroupwareSync::startKMail(QString *error) 00265 { 00266 FUNCTIONSETUP; 00267 00268 QCString kmdcop; 00269 QString mess; 00270 int pid; 00271 00272 return KApplication::startServiceByDesktopName(CSL1("kmail"), 00273 QString::null, 00274 error, 00275 &kmdcop, 00276 &pid 00277 )==0; 00278 } 00279 00280 00281 void KroupwareSync::preSync() 00282 { 00283 cleanupConfig(); 00284 start_syncCal_TodosWithKMail( fParts & Cal, fParts & Todo ); 00285 if (fParts & Notes) 00286 { 00287 start_syncNotesWithKMail(); 00288 } 00289 if (fParts & Address) 00290 { 00291 start_syncAddWithKMail(); 00292 } 00293 } 00294 00295 void KroupwareSync::postSync() 00296 { 00297 cleanupConfig(); 00298 end_syncCal_TodosWithKMail( fParts & Cal, fParts & Todo ); 00299 if (fParts & Notes) 00300 { 00301 end_syncNotesWithKMail(); 00302 } 00303 if (fParts & Address) 00304 { 00305 end_syncAddWithKMail(); 00306 } 00307 } 00308 00309 00310
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003