summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-28 11:37:28 (UTC)
committer zautrix <zautrix>2004-10-28 11:37:28 (UTC)
commitaf21c3d45173ece8492850b8c2c5019e7c25d59c (patch) (unidiff)
tree52e60b226372bbe37987df07495b02de321410fe
parent01cd4ef94b8604532181c390e9abd560aebaf372 (diff)
downloadkdepimpi-af21c3d45173ece8492850b8c2c5019e7c25d59c.zip
kdepimpi-af21c3d45173ece8492850b8c2c5019e7c25d59c.tar.gz
kdepimpi-af21c3d45173ece8492850b8c2c5019e7c25d59c.tar.bz2
dtm sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp14
-rw-r--r--korganizer/calendarview.cpp10
2 files changed, 15 insertions, 9 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index bdc5bd8..c75b4bc 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2127,849 +2127,853 @@ void KABCore::clipboardDataChanged()
2127 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2127 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2128 2128
2129} 2129}
2130 2130
2131void KABCore::updateActionMenu() 2131void KABCore::updateActionMenu()
2132{ 2132{
2133 UndoStack *undo = UndoStack::instance(); 2133 UndoStack *undo = UndoStack::instance();
2134 RedoStack *redo = RedoStack::instance(); 2134 RedoStack *redo = RedoStack::instance();
2135 2135
2136 if ( undo->isEmpty() ) 2136 if ( undo->isEmpty() )
2137 mActionUndo->setText( i18n( "Undo" ) ); 2137 mActionUndo->setText( i18n( "Undo" ) );
2138 else 2138 else
2139 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2139 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2140 2140
2141 mActionUndo->setEnabled( !undo->isEmpty() ); 2141 mActionUndo->setEnabled( !undo->isEmpty() );
2142 2142
2143 if ( !redo->top() ) 2143 if ( !redo->top() )
2144 mActionRedo->setText( i18n( "Redo" ) ); 2144 mActionRedo->setText( i18n( "Redo" ) );
2145 else 2145 else
2146 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2146 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2147 2147
2148 mActionRedo->setEnabled( !redo->isEmpty() ); 2148 mActionRedo->setEnabled( !redo->isEmpty() );
2149} 2149}
2150 2150
2151void KABCore::configureKeyBindings() 2151void KABCore::configureKeyBindings()
2152{ 2152{
2153#ifndef KAB_EMBEDDED 2153#ifndef KAB_EMBEDDED
2154 KKeyDialog::configure( actionCollection(), true ); 2154 KKeyDialog::configure( actionCollection(), true );
2155#else //KAB_EMBEDDED 2155#else //KAB_EMBEDDED
2156 qDebug("KABCore::configureKeyBindings() not implemented"); 2156 qDebug("KABCore::configureKeyBindings() not implemented");
2157#endif //KAB_EMBEDDED 2157#endif //KAB_EMBEDDED
2158} 2158}
2159 2159
2160#ifdef KAB_EMBEDDED 2160#ifdef KAB_EMBEDDED
2161void KABCore::configureResources() 2161void KABCore::configureResources()
2162{ 2162{
2163 KRES::KCMKResources dlg( this, "" , 0 ); 2163 KRES::KCMKResources dlg( this, "" , 0 );
2164 2164
2165 if ( !dlg.exec() ) 2165 if ( !dlg.exec() )
2166 return; 2166 return;
2167 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2167 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2168} 2168}
2169#endif //KAB_EMBEDDED 2169#endif //KAB_EMBEDDED
2170 2170
2171 2171
2172/* this method will be called through the QCop interface from Ko/Pi to select addresses 2172/* this method will be called through the QCop interface from Ko/Pi to select addresses
2173 * for the attendees list of an event. 2173 * for the attendees list of an event.
2174 */ 2174 */
2175void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2175void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2176{ 2176{
2177 QStringList nameList; 2177 QStringList nameList;
2178 QStringList emailList; 2178 QStringList emailList;
2179 QStringList uidList; 2179 QStringList uidList;
2180 2180
2181 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2181 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2182 uint i=0; 2182 uint i=0;
2183 for (i=0; i < list.count(); i++) 2183 for (i=0; i < list.count(); i++)
2184 { 2184 {
2185 nameList.append(list[i].realName()); 2185 nameList.append(list[i].realName());
2186 emailList.append(list[i].preferredEmail()); 2186 emailList.append(list[i].preferredEmail());
2187 uidList.append(list[i].uid()); 2187 uidList.append(list[i].uid());
2188 } 2188 }
2189 2189
2190 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2190 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2191 2191
2192} 2192}
2193 2193
2194/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2194/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2195 * to put them into the calendar. 2195 * to put them into the calendar.
2196 */ 2196 */
2197void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2197void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2198{ 2198{
2199 // qDebug("KABCore::requestForBirthdayList"); 2199 // qDebug("KABCore::requestForBirthdayList");
2200 QStringList birthdayList; 2200 QStringList birthdayList;
2201 QStringList anniversaryList; 2201 QStringList anniversaryList;
2202 QStringList realNameList; 2202 QStringList realNameList;
2203 QStringList preferredEmailList; 2203 QStringList preferredEmailList;
2204 QStringList assembledNameList; 2204 QStringList assembledNameList;
2205 QStringList uidList; 2205 QStringList uidList;
2206 2206
2207 KABC::AddressBook::Iterator it; 2207 KABC::AddressBook::Iterator it;
2208 2208
2209 int count = 0; 2209 int count = 0;
2210 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2210 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2211 ++count; 2211 ++count;
2212 } 2212 }
2213 QProgressBar bar(count,0 ); 2213 QProgressBar bar(count,0 );
2214 int w = 300; 2214 int w = 300;
2215 if ( QApplication::desktop()->width() < 320 ) 2215 if ( QApplication::desktop()->width() < 320 )
2216 w = 220; 2216 w = 220;
2217 int h = bar.sizeHint().height() ; 2217 int h = bar.sizeHint().height() ;
2218 int dw = QApplication::desktop()->width(); 2218 int dw = QApplication::desktop()->width();
2219 int dh = QApplication::desktop()->height(); 2219 int dh = QApplication::desktop()->height();
2220 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2220 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2221 bar.show(); 2221 bar.show();
2222 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2222 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2223 qApp->processEvents(); 2223 qApp->processEvents();
2224 2224
2225 QDate bday; 2225 QDate bday;
2226 QString anni; 2226 QString anni;
2227 QString formattedbday; 2227 QString formattedbday;
2228 2228
2229 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2229 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2230 { 2230 {
2231 if ( ! bar.isVisible() ) 2231 if ( ! bar.isVisible() )
2232 return; 2232 return;
2233 bar.setProgress( count++ ); 2233 bar.setProgress( count++ );
2234 qApp->processEvents(); 2234 qApp->processEvents();
2235 bday = (*it).birthday().date(); 2235 bday = (*it).birthday().date();
2236 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2236 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2237 2237
2238 if ( bday.isValid() || !anni.isEmpty()) 2238 if ( bday.isValid() || !anni.isEmpty())
2239 { 2239 {
2240 if (bday.isValid()) 2240 if (bday.isValid())
2241 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2241 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2242 else 2242 else
2243 formattedbday = "NOTVALID"; 2243 formattedbday = "NOTVALID";
2244 if (anni.isEmpty()) 2244 if (anni.isEmpty())
2245 anni = "INVALID"; 2245 anni = "INVALID";
2246 2246
2247 birthdayList.append(formattedbday); 2247 birthdayList.append(formattedbday);
2248 anniversaryList.append(anni); //should be ISODate 2248 anniversaryList.append(anni); //should be ISODate
2249 realNameList.append((*it).realName()); 2249 realNameList.append((*it).realName());
2250 preferredEmailList.append((*it).preferredEmail()); 2250 preferredEmailList.append((*it).preferredEmail());
2251 assembledNameList.append((*it).assembledName()); 2251 assembledNameList.append((*it).assembledName());
2252 uidList.append((*it).uid()); 2252 uidList.append((*it).uid());
2253 2253
2254 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2254 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2255 } 2255 }
2256 } 2256 }
2257 2257
2258 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2258 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2259 2259
2260} 2260}
2261 2261
2262/* this method will be called through the QCop interface from other apps to show details of a contact. 2262/* this method will be called through the QCop interface from other apps to show details of a contact.
2263 */ 2263 */
2264void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2264void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2265{ 2265{
2266 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2266 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2267 2267
2268 QString foundUid = QString::null; 2268 QString foundUid = QString::null;
2269 if ( ! uid.isEmpty() ) { 2269 if ( ! uid.isEmpty() ) {
2270 Addressee adrr = mAddressBook->findByUid( uid ); 2270 Addressee adrr = mAddressBook->findByUid( uid );
2271 if ( !adrr.isEmpty() ) { 2271 if ( !adrr.isEmpty() ) {
2272 foundUid = uid; 2272 foundUid = uid;
2273 } 2273 }
2274 if ( email == "sendbacklist" ) { 2274 if ( email == "sendbacklist" ) {
2275 //qDebug("ssssssssssssssssssssssend "); 2275 //qDebug("ssssssssssssssssssssssend ");
2276 QStringList nameList; 2276 QStringList nameList;
2277 QStringList emailList; 2277 QStringList emailList;
2278 QStringList uidList; 2278 QStringList uidList;
2279 nameList.append(adrr.realName()); 2279 nameList.append(adrr.realName());
2280 emailList = adrr.emails(); 2280 emailList = adrr.emails();
2281 uidList.append( adrr.preferredEmail()); 2281 uidList.append( adrr.preferredEmail());
2282 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2282 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2283 return; 2283 return;
2284 } 2284 }
2285 2285
2286 } 2286 }
2287 2287
2288 if ( email == "sendbacklist" ) 2288 if ( email == "sendbacklist" )
2289 return; 2289 return;
2290 if (foundUid.isEmpty()) 2290 if (foundUid.isEmpty())
2291 { 2291 {
2292 //find the uid of the person first 2292 //find the uid of the person first
2293 Addressee::List namelist; 2293 Addressee::List namelist;
2294 Addressee::List emaillist; 2294 Addressee::List emaillist;
2295 2295
2296 if (!name.isEmpty()) 2296 if (!name.isEmpty())
2297 namelist = mAddressBook->findByName( name ); 2297 namelist = mAddressBook->findByName( name );
2298 2298
2299 if (!email.isEmpty()) 2299 if (!email.isEmpty())
2300 emaillist = mAddressBook->findByEmail( email ); 2300 emaillist = mAddressBook->findByEmail( email );
2301 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2301 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2302 //check if we have a match in Namelist and Emaillist 2302 //check if we have a match in Namelist and Emaillist
2303 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2303 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2304 foundUid = emaillist[0].uid(); 2304 foundUid = emaillist[0].uid();
2305 } 2305 }
2306 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2306 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2307 foundUid = namelist[0].uid(); 2307 foundUid = namelist[0].uid();
2308 else 2308 else
2309 { 2309 {
2310 for (int i = 0; i < namelist.count(); i++) 2310 for (int i = 0; i < namelist.count(); i++)
2311 { 2311 {
2312 for (int j = 0; j < emaillist.count(); j++) 2312 for (int j = 0; j < emaillist.count(); j++)
2313 { 2313 {
2314 if (namelist[i] == emaillist[j]) 2314 if (namelist[i] == emaillist[j])
2315 { 2315 {
2316 foundUid = namelist[i].uid(); 2316 foundUid = namelist[i].uid();
2317 } 2317 }
2318 } 2318 }
2319 } 2319 }
2320 } 2320 }
2321 } 2321 }
2322 else 2322 else
2323 { 2323 {
2324 foundUid = uid; 2324 foundUid = uid;
2325 } 2325 }
2326 2326
2327 if (!foundUid.isEmpty()) 2327 if (!foundUid.isEmpty())
2328 { 2328 {
2329 2329
2330 // raise Ka/Pi if it is in the background 2330 // raise Ka/Pi if it is in the background
2331#ifndef DESKTOP_VERSION 2331#ifndef DESKTOP_VERSION
2332#ifndef KORG_NODCOP 2332#ifndef KORG_NODCOP
2333 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2333 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2334#endif 2334#endif
2335#endif 2335#endif
2336 2336
2337 mMainWindow->showMaximized(); 2337 mMainWindow->showMaximized();
2338 mMainWindow-> raise(); 2338 mMainWindow-> raise();
2339 2339
2340 mViewManager->setSelected( "", false); 2340 mViewManager->setSelected( "", false);
2341 mViewManager->refreshView( "" ); 2341 mViewManager->refreshView( "" );
2342 mViewManager->setSelected( foundUid, true ); 2342 mViewManager->setSelected( foundUid, true );
2343 mViewManager->refreshView( foundUid ); 2343 mViewManager->refreshView( foundUid );
2344 2344
2345 if ( !mMultipleViewsAtOnce ) 2345 if ( !mMultipleViewsAtOnce )
2346 { 2346 {
2347 setDetailsVisible( true ); 2347 setDetailsVisible( true );
2348 mActionDetails->setChecked(true); 2348 mActionDetails->setChecked(true);
2349 } 2349 }
2350 } 2350 }
2351} 2351}
2352 2352
2353void KABCore::whatsnew() 2353void KABCore::whatsnew()
2354{ 2354{
2355 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2355 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2356} 2356}
2357void KABCore::synchowto() 2357void KABCore::synchowto()
2358{ 2358{
2359 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2359 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2360} 2360}
2361void KABCore::kdesynchowto() 2361void KABCore::kdesynchowto()
2362{ 2362{
2363 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); 2363 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" );
2364} 2364}
2365void KABCore::multisynchowto() 2365void KABCore::multisynchowto()
2366{ 2366{
2367 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); 2367 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" );
2368} 2368}
2369void KABCore::faq() 2369void KABCore::faq()
2370{ 2370{
2371 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2371 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2372} 2372}
2373 2373
2374#include <libkcal/syncdefines.h> 2374#include <libkcal/syncdefines.h>
2375 2375
2376KABC::Addressee KABCore::getLastSyncAddressee() 2376KABC::Addressee KABCore::getLastSyncAddressee()
2377{ 2377{
2378 Addressee lse; 2378 Addressee lse;
2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2380 2380
2381 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2381 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2382 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2382 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2383 if (lse.isEmpty()) { 2383 if (lse.isEmpty()) {
2384 qDebug("Creating new last-syncAddressee "); 2384 qDebug("Creating new last-syncAddressee ");
2385 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2385 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2386 QString sum = ""; 2386 QString sum = "";
2387 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2387 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2388 sum = "E: "; 2388 sum = "E: ";
2389 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2389 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2390 lse.setRevision( mLastAddressbookSync ); 2390 lse.setRevision( mLastAddressbookSync );
2391 lse.setCategories( i18n("SyncEvent") ); 2391 lse.setCategories( i18n("SyncEvent") );
2392 mAddressBook->insertAddressee( lse ); 2392 mAddressBook->insertAddressee( lse );
2393 } 2393 }
2394 return lse; 2394 return lse;
2395} 2395}
2396int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2396int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2397{ 2397{
2398 2398
2399 //void setZaurusId(int id); 2399 //void setZaurusId(int id);
2400 // int zaurusId() const; 2400 // int zaurusId() const;
2401 // void setZaurusUid(int id); 2401 // void setZaurusUid(int id);
2402 // int zaurusUid() const; 2402 // int zaurusUid() const;
2403 // void setZaurusStat(int id); 2403 // void setZaurusStat(int id);
2404 // int zaurusStat() const; 2404 // int zaurusStat() const;
2405 // 0 equal 2405 // 0 equal
2406 // 1 take local 2406 // 1 take local
2407 // 2 take remote 2407 // 2 take remote
2408 // 3 cancel 2408 // 3 cancel
2409 QDateTime lastSync = mLastAddressbookSync; 2409 QDateTime lastSync = mLastAddressbookSync;
2410 QDateTime localMod = local->revision(); 2410 QDateTime localMod = local->revision();
2411 QDateTime remoteMod = remote->revision(); 2411 QDateTime remoteMod = remote->revision();
2412 2412
2413 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2413 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2414 2414
2415 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2415 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2416 bool remCh, locCh; 2416 bool remCh, locCh;
2417 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2417 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2418 2418
2419 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2419 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2420 locCh = ( localMod > mLastAddressbookSync ); 2420 locCh = ( localMod > mLastAddressbookSync );
2421 if ( !remCh && ! locCh ) { 2421 if ( !remCh && ! locCh ) {
2422 //qDebug("both not changed "); 2422 //qDebug("both not changed ");
2423 lastSync = localMod.addDays(1); 2423 lastSync = localMod.addDays(1);
2424 if ( mode <= SYNC_PREF_ASK ) 2424 if ( mode <= SYNC_PREF_ASK )
2425 return 0; 2425 return 0;
2426 } else { 2426 } else {
2427 if ( locCh ) { 2427 if ( locCh ) {
2428 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2428 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2429 lastSync = localMod.addDays( -1 ); 2429 lastSync = localMod.addDays( -1 );
2430 if ( !remCh ) 2430 if ( !remCh )
2431 remoteMod =( lastSync.addDays( -1 ) ); 2431 remoteMod =( lastSync.addDays( -1 ) );
2432 } else { 2432 } else {
2433 //qDebug(" not loc changed "); 2433 //qDebug(" not loc changed ");
2434 lastSync = localMod.addDays( 1 ); 2434 lastSync = localMod.addDays( 1 );
2435 if ( remCh ) 2435 if ( remCh )
2436 remoteMod =( lastSync.addDays( 1 ) ); 2436 remoteMod =( lastSync.addDays( 1 ) );
2437 2437
2438 } 2438 }
2439 } 2439 }
2440 full = true; 2440 full = true;
2441 if ( mode < SYNC_PREF_ASK ) 2441 if ( mode < SYNC_PREF_ASK )
2442 mode = SYNC_PREF_ASK; 2442 mode = SYNC_PREF_ASK;
2443 } else { 2443 } else {
2444 if ( localMod == remoteMod ) 2444 if ( localMod == remoteMod )
2445 return 0; 2445 return 0;
2446 2446
2447 } 2447 }
2448 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2448 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2449 2449
2450 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2450 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2451 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2451 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2452 //full = true; //debug only 2452 //full = true; //debug only
2453 if ( full ) { 2453 if ( full ) {
2454 bool equ = ( (*local) == (*remote) ); 2454 bool equ = ( (*local) == (*remote) );
2455 if ( equ ) { 2455 if ( equ ) {
2456 //qDebug("equal "); 2456 //qDebug("equal ");
2457 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2457 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2458 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2458 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2459 } 2459 }
2460 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2460 if ( mode < SYNC_PREF_FORCE_LOCAL )
2461 return 0; 2461 return 0;
2462 2462
2463 }//else //debug only 2463 }//else //debug only
2464 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2464 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2465 } 2465 }
2466 int result; 2466 int result;
2467 bool localIsNew; 2467 bool localIsNew;
2468 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2468 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2469 2469
2470 if ( full && mode < SYNC_PREF_NEWEST ) 2470 if ( full && mode < SYNC_PREF_NEWEST )
2471 mode = SYNC_PREF_ASK; 2471 mode = SYNC_PREF_ASK;
2472 2472
2473 switch( mode ) { 2473 switch( mode ) {
2474 case SYNC_PREF_LOCAL: 2474 case SYNC_PREF_LOCAL:
2475 if ( lastSync > remoteMod ) 2475 if ( lastSync > remoteMod )
2476 return 1; 2476 return 1;
2477 if ( lastSync > localMod ) 2477 if ( lastSync > localMod )
2478 return 2; 2478 return 2;
2479 return 1; 2479 return 1;
2480 break; 2480 break;
2481 case SYNC_PREF_REMOTE: 2481 case SYNC_PREF_REMOTE:
2482 if ( lastSync > remoteMod ) 2482 if ( lastSync > remoteMod )
2483 return 1; 2483 return 1;
2484 if ( lastSync > localMod ) 2484 if ( lastSync > localMod )
2485 return 2; 2485 return 2;
2486 return 2; 2486 return 2;
2487 break; 2487 break;
2488 case SYNC_PREF_NEWEST: 2488 case SYNC_PREF_NEWEST:
2489 if ( localMod > remoteMod ) 2489 if ( localMod > remoteMod )
2490 return 1; 2490 return 1;
2491 else 2491 else
2492 return 2; 2492 return 2;
2493 break; 2493 break;
2494 case SYNC_PREF_ASK: 2494 case SYNC_PREF_ASK:
2495 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2495 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2496 if ( lastSync > remoteMod ) 2496 if ( lastSync > remoteMod )
2497 return 1; 2497 return 1;
2498 if ( lastSync > localMod ) 2498 if ( lastSync > localMod )
2499 return 2; 2499 return 2;
2500 localIsNew = localMod >= remoteMod; 2500 localIsNew = localMod >= remoteMod;
2501 //qDebug("conflict! ************************************** "); 2501 //qDebug("conflict! ************************************** ");
2502 { 2502 {
2503 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2503 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2504 result = acd.executeD(localIsNew); 2504 result = acd.executeD(localIsNew);
2505 return result; 2505 return result;
2506 } 2506 }
2507 break; 2507 break;
2508 case SYNC_PREF_FORCE_LOCAL: 2508 case SYNC_PREF_FORCE_LOCAL:
2509 return 1; 2509 return 1;
2510 break; 2510 break;
2511 case SYNC_PREF_FORCE_REMOTE: 2511 case SYNC_PREF_FORCE_REMOTE:
2512 return 2; 2512 return 2;
2513 break; 2513 break;
2514 2514
2515 default: 2515 default:
2516 // SYNC_PREF_TAKE_BOTH not implemented 2516 // SYNC_PREF_TAKE_BOTH not implemented
2517 break; 2517 break;
2518 } 2518 }
2519 return 0; 2519 return 0;
2520} 2520}
2521 2521
2522 2522
2523bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2523bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2524{ 2524{
2525 bool syncOK = true; 2525 bool syncOK = true;
2526 int addedAddressee = 0; 2526 int addedAddressee = 0;
2527 int addedAddresseeR = 0; 2527 int addedAddresseeR = 0;
2528 int deletedAddresseeR = 0; 2528 int deletedAddresseeR = 0;
2529 int deletedAddresseeL = 0; 2529 int deletedAddresseeL = 0;
2530 int changedLocal = 0; 2530 int changedLocal = 0;
2531 int changedRemote = 0; 2531 int changedRemote = 0;
2532 2532
2533 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2533 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2534 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2534 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2535 2535
2536 //QPtrList<Addressee> el = local->rawAddressees(); 2536 //QPtrList<Addressee> el = local->rawAddressees();
2537 Addressee addresseeR; 2537 Addressee addresseeR;
2538 QString uid; 2538 QString uid;
2539 int take; 2539 int take;
2540 Addressee addresseeL; 2540 Addressee addresseeL;
2541 Addressee addresseeRSync; 2541 Addressee addresseeRSync;
2542 Addressee addresseeLSync; 2542 Addressee addresseeLSync;
2543 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2543 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2544 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2544 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2545 bool fullDateRange = false; 2545 bool fullDateRange = false;
2546 local->resetTempSyncStat(); 2546 local->resetTempSyncStat();
2547 mLastAddressbookSync = QDateTime::currentDateTime(); 2547 mLastAddressbookSync = QDateTime::currentDateTime();
2548 if ( syncManager->syncWithDesktop() ) { 2548 if ( syncManager->syncWithDesktop() ) {
2549 // remote->removeSyncInfo( QString());//remove all info 2549 // remote->removeSyncInfo( QString());//remove all info
2550 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2550 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2551 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2551 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2552 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2552 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2553 } else { 2553 } else {
2554 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 2554 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2555 } 2555 }
2556 } 2556 }
2557 QDateTime modifiedCalendar = mLastAddressbookSync; 2557 QDateTime modifiedCalendar = mLastAddressbookSync;
2558 addresseeLSync = getLastSyncAddressee(); 2558 addresseeLSync = getLastSyncAddressee();
2559 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2559 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2560 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2560 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2561 if ( !addresseeR.isEmpty() ) { 2561 if ( !addresseeR.isEmpty() ) {
2562 addresseeRSync = addresseeR; 2562 addresseeRSync = addresseeR;
2563 remote->removeAddressee(addresseeR ); 2563 remote->removeAddressee(addresseeR );
2564 2564
2565 } else { 2565 } else {
2566 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2566 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2567 addresseeRSync = addresseeLSync ; 2567 addresseeRSync = addresseeLSync ;
2568 } else { 2568 } else {
2569 qDebug("FULLDATE 1"); 2569 qDebug("FULLDATE 1");
2570 fullDateRange = true; 2570 fullDateRange = true;
2571 Addressee newAdd; 2571 Addressee newAdd;
2572 addresseeRSync = newAdd; 2572 addresseeRSync = newAdd;
2573 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2573 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2574 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2574 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2575 addresseeRSync.setRevision( mLastAddressbookSync ); 2575 addresseeRSync.setRevision( mLastAddressbookSync );
2576 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2576 addresseeRSync.setCategories( i18n("SyncAddressee") );
2577 } 2577 }
2578 } 2578 }
2579 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2579 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2580 qDebug("FULLDATE 2"); 2580 qDebug("FULLDATE 2");
2581 fullDateRange = true; 2581 fullDateRange = true;
2582 } 2582 }
2583 if ( ! fullDateRange ) { 2583 if ( ! fullDateRange ) {
2584 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2584 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2585 2585
2586 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2586 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2587 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2587 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2588 fullDateRange = true; 2588 fullDateRange = true;
2589 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2589 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2590 } 2590 }
2591 } 2591 }
2592 // fullDateRange = true; // debug only! 2592 // fullDateRange = true; // debug only!
2593 if ( fullDateRange ) 2593 if ( fullDateRange )
2594 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2594 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2595 else 2595 else
2596 mLastAddressbookSync = addresseeLSync.revision(); 2596 mLastAddressbookSync = addresseeLSync.revision();
2597 // for resyncing if own file has changed 2597 // for resyncing if own file has changed
2598 // PENDING fixme later when implemented 2598 // PENDING fixme later when implemented
2599#if 0 2599#if 0
2600 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2600 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2601 mLastAddressbookSync = loadedFileVersion; 2601 mLastAddressbookSync = loadedFileVersion;
2602 qDebug("setting mLastAddressbookSync "); 2602 qDebug("setting mLastAddressbookSync ");
2603 } 2603 }
2604#endif 2604#endif
2605 2605
2606 //qDebug("*************************** "); 2606 //qDebug("*************************** ");
2607 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2607 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2608 QStringList er = remote->uidList(); 2608 QStringList er = remote->uidList();
2609 Addressee inR ;//= er.first(); 2609 Addressee inR ;//= er.first();
2610 Addressee inL; 2610 Addressee inL;
2611 2611
2612 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2612 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2613 2613
2614 int modulo = (er.count()/10)+1; 2614 int modulo = (er.count()/10)+1;
2615 int incCounter = 0; 2615 int incCounter = 0;
2616 while ( incCounter < er.count()) { 2616 while ( incCounter < er.count()) {
2617 if (syncManager->isProgressBarCanceled()) 2617 if (syncManager->isProgressBarCanceled())
2618 return false; 2618 return false;
2619 if ( incCounter % modulo == 0 ) 2619 if ( incCounter % modulo == 0 )
2620 syncManager->showProgressBar(incCounter); 2620 syncManager->showProgressBar(incCounter);
2621 2621
2622 uid = er[ incCounter ]; 2622 uid = er[ incCounter ];
2623 bool skipIncidence = false; 2623 bool skipIncidence = false;
2624 if ( uid.left(19) == QString("last-syncAddressee-") ) 2624 if ( uid.left(19) == QString("last-syncAddressee-") )
2625 skipIncidence = true; 2625 skipIncidence = true;
2626 QString idS,OidS; 2626 QString idS,OidS;
2627 qApp->processEvents(); 2627 qApp->processEvents();
2628 if ( !skipIncidence ) { 2628 if ( !skipIncidence ) {
2629 inL = local->findByUid( uid ); 2629 inL = local->findByUid( uid );
2630 inR = remote->findByUid( uid ); 2630 inR = remote->findByUid( uid );
2631 //inL.setResource( 0 ); 2631 //inL.setResource( 0 );
2632 //inR.setResource( 0 ); 2632 //inR.setResource( 0 );
2633 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2633 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2634 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2634 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2635 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2635 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2636 //qDebug("take %d %s ", take, inL.summary().latin1()); 2636 //qDebug("take %d %s ", take, inL.summary().latin1());
2637 if ( take == 3 ) 2637 if ( take == 3 )
2638 return false; 2638 return false;
2639 if ( take == 1 ) {// take local 2639 if ( take == 1 ) {// take local **********************
2640 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2640 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2641 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2641 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2642 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2642 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2643 local->insertAddressee( inL, false ); 2643 local->insertAddressee( inL, false );
2644 idS = inR.externalUID(); 2644 idS = inR.externalUID();
2645 OidS = inR.originalExternalUID(); 2645 OidS = inR.originalExternalUID();
2646 } 2646 }
2647 else 2647 else
2648 idS = inR.IDStr(); 2648 idS = inR.IDStr();
2649 remote->removeAddressee( inR ); 2649 remote->removeAddressee( inR );
2650 inR = inL; 2650 inR = inL;
2651 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2651 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2652 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2652 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2653 inR.setOriginalExternalUID( OidS ); 2653 inR.setOriginalExternalUID( OidS );
2654 inR.setExternalUID( idS ); 2654 inR.setExternalUID( idS );
2655 if ( syncManager->syncWithDesktop() ) 2655 if ( syncManager->syncWithDesktop() )
2656 inR.setIDStr("changed" ); 2656 inR.setIDStr("changed" );
2657 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); 2657 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2658 } else { 2658 } else {
2659 inR.setIDStr( idS ); 2659 inR.setIDStr( idS );
2660 } 2660 }
2661 inR.setResource( 0 ); 2661 inR.setResource( 0 );
2662 remote->insertAddressee( inR , false); 2662 remote->insertAddressee( inR , false);
2663 ++changedRemote; 2663 ++changedRemote;
2664 } else { // take == 2 take remote 2664 } else { // take == 2 take remote **********************
2665 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2665 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2666 if ( inR.revision().date().year() < 2004 ) 2666 if ( inR.revision().date().year() < 2004 )
2667 inR.setRevision( modifiedCalendar ); 2667 inR.setRevision( modifiedCalendar );
2668 } 2668 }
2669 idS = inL.IDStr(); 2669 idS = inL.IDStr();
2670 local->removeAddressee( inL ); 2670 local->removeAddressee( inL );
2671 inL = inR; 2671 inL = inR;
2672 inL.setIDStr( idS ); 2672 inL.setIDStr( idS );
2673 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2673 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2674 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2674 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2675 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2675 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2676 } 2676 }
2677 inL.setResource( 0 ); 2677 inL.setResource( 0 );
2678 local->insertAddressee( inL , false ); 2678 local->insertAddressee( inL , false );
2679 ++changedLocal; 2679 ++changedLocal;
2680 } 2680 }
2681 } 2681 }
2682 } 2682 }
2683 } else { // no conflict 2683 } else { // no conflict ********** add or delete remote
2684 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2684 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2685 QString des = addresseeLSync.note(); 2685 QString des = addresseeLSync.note();
2686 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2686 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2687 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2687 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2688 remote->insertAddressee( inR, false ); 2688 remote->insertAddressee( inR, false );
2689 ++deletedAddresseeR; 2689 ++deletedAddresseeR;
2690 } else { 2690 } else {
2691 inR.setRevision( modifiedCalendar ); 2691 inR.setRevision( modifiedCalendar );
2692 remote->insertAddressee( inR, false ); 2692 remote->insertAddressee( inR, false );
2693 inL = inR; 2693 inL = inR;
2694 inL.setIDStr( ":" );
2695 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2696 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2694 inL.setResource( 0 ); 2697 inL.setResource( 0 );
2695 local->insertAddressee( inL , false); 2698 local->insertAddressee( inL , false);
2696 ++addedAddressee; 2699 ++addedAddressee;
2697 } 2700 }
2698 } else { 2701 } else {
2699 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2702 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2700 inR.setRevision( modifiedCalendar ); 2703 inR.setRevision( modifiedCalendar );
2701 remote->insertAddressee( inR, false ); 2704 remote->insertAddressee( inR, false );
2702 inR.setResource( 0 ); 2705 inR.setResource( 0 );
2703 local->insertAddressee( inR, false ); 2706 local->insertAddressee( inR, false );
2704 ++addedAddressee; 2707 ++addedAddressee;
2705 } else { 2708 } else {
2706 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2709 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2707 remote->removeAddressee( inR ); 2710 remote->removeAddressee( inR );
2708 ++deletedAddresseeR; 2711 ++deletedAddresseeR;
2709 } 2712 }
2710 } 2713 }
2711 } 2714 }
2712 } 2715 }
2713 ++incCounter; 2716 ++incCounter;
2714 } 2717 }
2715 er.clear(); 2718 er.clear();
2716 QStringList el = local->uidList(); 2719 QStringList el = local->uidList();
2717 modulo = (el.count()/10)+1; 2720 modulo = (el.count()/10)+1;
2718 2721
2719 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2722 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2720 incCounter = 0; 2723 incCounter = 0;
2721 while ( incCounter < el.count()) { 2724 while ( incCounter < el.count()) {
2722 qApp->processEvents(); 2725 qApp->processEvents();
2723 if (syncManager->isProgressBarCanceled()) 2726 if (syncManager->isProgressBarCanceled())
2724 return false; 2727 return false;
2725 if ( incCounter % modulo == 0 ) 2728 if ( incCounter % modulo == 0 )
2726 syncManager->showProgressBar(incCounter); 2729 syncManager->showProgressBar(incCounter);
2727 uid = el[ incCounter ]; 2730 uid = el[ incCounter ];
2728 bool skipIncidence = false; 2731 bool skipIncidence = false;
2729 if ( uid.left(19) == QString("last-syncAddressee-") ) 2732 if ( uid.left(19) == QString("last-syncAddressee-") )
2730 skipIncidence = true; 2733 skipIncidence = true;
2731 if ( !skipIncidence ) { 2734 if ( !skipIncidence ) {
2732 inL = local->findByUid( uid ); 2735 inL = local->findByUid( uid );
2733 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2736 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2734 inR = remote->findByUid( uid ); 2737 inR = remote->findByUid( uid );
2735 if ( inR.isEmpty() ) { 2738 if ( inR.isEmpty() ) { / no conflict ********** add or delete local
2736 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2739 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2737 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2740 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2738 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2741 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2739 local->removeAddressee( inL ); 2742 local->removeAddressee( inL );
2740 ++deletedAddresseeL; 2743 ++deletedAddresseeL;
2741 } else { 2744 } else {
2742 if ( ! syncManager->mWriteBackExistingOnly ) { 2745 if ( ! syncManager->mWriteBackExistingOnly ) {
2743 inL.removeID(mCurrentSyncDevice ); 2746 inL.removeID(mCurrentSyncDevice );
2744 ++addedAddresseeR; 2747 ++addedAddresseeR;
2745 inL.setRevision( modifiedCalendar ); 2748 inL.setRevision( modifiedCalendar );
2746 local->insertAddressee( inL, false ); 2749 local->insertAddressee( inL, false );
2747 inR = inL; 2750 inR = inL;
2748 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2751 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2749 inR.setResource( 0 ); 2752 inR.setResource( 0 );
2750 remote->insertAddressee( inR, false ); 2753 remote->insertAddressee( inR, false );
2751 } 2754 }
2752 } 2755 }
2753 } else { 2756 } else {
2754 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2757 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2755 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2758 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2756 local->removeAddressee( inL ); 2759 local->removeAddressee( inL );
2757 ++deletedAddresseeL; 2760 ++deletedAddresseeL;
2758 } else { 2761 } else {
2759 if ( ! syncManager->mWriteBackExistingOnly ) { 2762 if ( ! syncManager->mWriteBackExistingOnly ) {
2760 ++addedAddresseeR; 2763 ++addedAddresseeR;
2761 inL.setRevision( modifiedCalendar ); 2764 inL.setRevision( modifiedCalendar );
2762 local->insertAddressee( inL, false ); 2765 local->insertAddressee( inL, false );
2763 inR = inL; 2766 inR = inL;
2767 inR.setIDStr( ":" );
2764 inR.setResource( 0 ); 2768 inR.setResource( 0 );
2765 remote->insertAddressee( inR, false ); 2769 remote->insertAddressee( inR, false );
2766 } 2770 }
2767 } 2771 }
2768 } 2772 }
2769 } 2773 }
2770 } 2774 }
2771 } 2775 }
2772 ++incCounter; 2776 ++incCounter;
2773 } 2777 }
2774 el.clear(); 2778 el.clear();
2775 syncManager->hideProgressBar(); 2779 syncManager->hideProgressBar();
2776 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2780 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2777 // get rid of micro seconds 2781 // get rid of micro seconds
2778 QTime t = mLastAddressbookSync.time(); 2782 QTime t = mLastAddressbookSync.time();
2779 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2783 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2780 addresseeLSync.setRevision( mLastAddressbookSync ); 2784 addresseeLSync.setRevision( mLastAddressbookSync );
2781 addresseeRSync.setRevision( mLastAddressbookSync ); 2785 addresseeRSync.setRevision( mLastAddressbookSync );
2782 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2786 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2783 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2787 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2784 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2788 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2785 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2789 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2786 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2790 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2787 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2791 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2788 addresseeRSync.setNote( "" ) ; 2792 addresseeRSync.setNote( "" ) ;
2789 addresseeLSync.setNote( "" ); 2793 addresseeLSync.setNote( "" );
2790 2794
2791 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2795 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2792 remote->insertAddressee( addresseeRSync, false ); 2796 remote->insertAddressee( addresseeRSync, false );
2793 local->insertAddressee( addresseeLSync, false ); 2797 local->insertAddressee( addresseeLSync, false );
2794 QString mes; 2798 QString mes;
2795 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2799 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2796 qDebug( mes ); 2800 qDebug( mes );
2797 if ( syncManager->mShowSyncSummary ) { 2801 if ( syncManager->mShowSyncSummary ) {
2798 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 2802 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
2799 i18n("KA/Pi Synchronization"),i18n("Write back"))) { 2803 i18n("KA/Pi Synchronization"),i18n("Write back"))) {
2800 qDebug("cancelled "); 2804 qDebug("cancelled ");
2801 return false; 2805 return false;
2802 } 2806 }
2803 } 2807 }
2804 return syncOK; 2808 return syncOK;
2805} 2809}
2806 2810
2807 2811
2808//this is a overwritten callbackmethods from the syncinterface 2812//this is a overwritten callbackmethods from the syncinterface
2809bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2813bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2810{ 2814{
2811 2815
2812 //pending prepare addresseeview for output 2816 //pending prepare addresseeview for output
2813 //pending detect, if remote file has REV field. if not switch to external sync 2817 //pending detect, if remote file has REV field. if not switch to external sync
2814 mGlobalSyncMode = SYNC_MODE_NORMAL; 2818 mGlobalSyncMode = SYNC_MODE_NORMAL;
2815 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2819 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2816 2820
2817 AddressBook abLocal(filename,"syncContact"); 2821 AddressBook abLocal(filename,"syncContact");
2818 bool syncOK = false; 2822 bool syncOK = false;
2819 if ( abLocal.load() ) { 2823 if ( abLocal.load() ) {
2820 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2824 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2821 bool external = false; 2825 bool external = false;
2822 bool isXML = false; 2826 bool isXML = false;
2823 if ( filename.right(4) == ".xml") { 2827 if ( filename.right(4) == ".xml") {
2824 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2828 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2825 isXML = true; 2829 isXML = true;
2826 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2830 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2827 } else { 2831 } else {
2828 external = !manager->mIsKapiFile; 2832 external = !manager->mIsKapiFile;
2829 if ( external ) { 2833 if ( external ) {
2830 qDebug("Setting vcf mode to external "); 2834 qDebug("Setting vcf mode to external ");
2831 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2835 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2832 AddressBook::Iterator it; 2836 AddressBook::Iterator it;
2833 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2837 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2834 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2838 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2835 (*it).computeCsum( mCurrentSyncDevice ); 2839 (*it).computeCsum( mCurrentSyncDevice );
2836 } 2840 }
2837 } 2841 }
2838 } 2842 }
2839 //AddressBook::Iterator it; 2843 //AddressBook::Iterator it;
2840 //QStringList vcards; 2844 //QStringList vcards;
2841 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2845 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2842 // qDebug("Name %s ", (*it).familyName().latin1()); 2846 // qDebug("Name %s ", (*it).familyName().latin1());
2843 //} 2847 //}
2844 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2848 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2845 if ( syncOK ) { 2849 if ( syncOK ) {
2846 if ( syncManager->mWriteBackFile ) 2850 if ( syncManager->mWriteBackFile )
2847 { 2851 {
2848 if ( external ) 2852 if ( external )
2849 abLocal.removeSyncAddressees( !isXML); 2853 abLocal.removeSyncAddressees( !isXML);
2850 qDebug("Saving remote AB "); 2854 qDebug("Saving remote AB ");
2851 if ( ! abLocal.saveAB()) 2855 if ( ! abLocal.saveAB())
2852 qDebug("Error writing back AB to file "); 2856 qDebug("Error writing back AB to file ");
2853 if ( external ) { 2857 if ( external ) {
2854 // afterwrite processing 2858 // afterwrite processing
2855 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); 2859 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
2856 } 2860 }
2857 } 2861 }
2858 } 2862 }
2859 setModified(); 2863 setModified();
2860 2864
2861 } 2865 }
2862 if ( syncOK ) 2866 if ( syncOK )
2863 mViewManager->refreshView(); 2867 mViewManager->refreshView();
2864 return syncOK; 2868 return syncOK;
2865 2869
2866} 2870}
2867void KABCore::removeSyncInfo( QString syncProfile) 2871void KABCore::removeSyncInfo( QString syncProfile)
2868{ 2872{
2869 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2873 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2870 mAddressBook->removeSyncInfo( syncProfile ); 2874 mAddressBook->removeSyncInfo( syncProfile );
2871 setModified(); 2875 setModified();
2872} 2876}
2873 2877
2874 2878
2875//this is a overwritten callbackmethods from the syncinterface 2879//this is a overwritten callbackmethods from the syncinterface
2876bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2880bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2877{ 2881{
2878 if ( resource == "phone" ) 2882 if ( resource == "phone" )
2879 return syncPhone(); 2883 return syncPhone();
2880 disableBR( true ); 2884 disableBR( true );
2881 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2885 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2882 2886
2883 AddressBook abLocal( resource,"syncContact"); 2887 AddressBook abLocal( resource,"syncContact");
2884 bool syncOK = false; 2888 bool syncOK = false;
2885 if ( abLocal.load() ) { 2889 if ( abLocal.load() ) {
2886 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2890 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2887 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2891 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2892 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2889 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2893 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2890 if ( syncOK ) { 2894 if ( syncOK ) {
2891 if ( syncManager->mWriteBackFile ) { 2895 if ( syncManager->mWriteBackFile ) {
2892 abLocal.removeSyncAddressees( false ); 2896 abLocal.removeSyncAddressees( false );
2893 abLocal.saveAB(); 2897 abLocal.saveAB();
2894 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2898 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2895 } 2899 }
2896 } else 2900 } else
2897 message( i18n("Sync cancelled or failed.") ); 2901 message( i18n("Sync cancelled or failed.") );
2898 setModified(); 2902 setModified();
2899 } 2903 }
2900 if ( syncOK ) 2904 if ( syncOK )
2901 mViewManager->refreshView(); 2905 mViewManager->refreshView();
2902 disableBR( false ); 2906 disableBR( false );
2903 return syncOK; 2907 return syncOK;
2904 2908
2905} 2909}
2906void KABCore::message( QString m ) 2910void KABCore::message( QString m )
2907{ 2911{
2908 topLevelWidget()->setCaption( m ); 2912 topLevelWidget()->setCaption( m );
2909 mMessageTimer->start( 15000, true ); 2913 mMessageTimer->start( 15000, true );
2910} 2914}
2911bool KABCore::syncPhone() 2915bool KABCore::syncPhone()
2912{ 2916{
2913 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2917 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2914 QString fileName = getPhoneFile(); 2918 QString fileName = getPhoneFile();
2915 if ( !PhoneAccess::readFromPhone( fileName) ) { 2919 if ( !PhoneAccess::readFromPhone( fileName) ) {
2916 message(i18n("Phone access failed!")); 2920 message(i18n("Phone access failed!"));
2917 return false; 2921 return false;
2918 } 2922 }
2919 AddressBook abLocal( fileName,"syncContact"); 2923 AddressBook abLocal( fileName,"syncContact");
2920 bool syncOK = false; 2924 bool syncOK = false;
2921 { 2925 {
2922 abLocal.importFromFile( fileName ); 2926 abLocal.importFromFile( fileName );
2923 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2927 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2924 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2928 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2925 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2929 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2926 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2930 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2927 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2931 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2928 if ( syncOK ) { 2932 if ( syncOK ) {
2929 if ( syncManager->mWriteBackFile ) { 2933 if ( syncManager->mWriteBackFile ) {
2930 abLocal.removeSyncAddressees( true ); 2934 abLocal.removeSyncAddressees( true );
2931 abLocal.saveABphone( fileName ); 2935 abLocal.saveABphone( fileName );
2932 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2936 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2933 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2937 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2934 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2938 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2935 } 2939 }
2936 } 2940 }
2937 setModified(); 2941 setModified();
2938 } 2942 }
2939 if ( syncOK ) 2943 if ( syncOK )
2940 mViewManager->refreshView(); 2944 mViewManager->refreshView();
2941 return syncOK; 2945 return syncOK;
2942} 2946}
2943void KABCore::getFile( bool success ) 2947void KABCore::getFile( bool success )
2944{ 2948{
2945 if ( ! success ) { 2949 if ( ! success ) {
2946 message( i18n("Error receiving file. Nothing changed!") ); 2950 message( i18n("Error receiving file. Nothing changed!") );
2947 return; 2951 return;
2948 } 2952 }
2949 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2953 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2950 if ( count ) 2954 if ( count )
2951 setModified( true ); 2955 setModified( true );
2952 message( i18n("Pi-Sync successful!") ); 2956 message( i18n("Pi-Sync successful!") );
2953 mViewManager->refreshView(); 2957 mViewManager->refreshView();
2954} 2958}
2955void KABCore::syncFileRequest() 2959void KABCore::syncFileRequest()
2956{ 2960{
2957 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 2961 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2958 syncManager->slotSyncMenu( 999 ); 2962 syncManager->slotSyncMenu( 999 );
2959 } 2963 }
2960 mAddressBook->export2File( sentSyncFile() ); 2964 mAddressBook->export2File( sentSyncFile() );
2961} 2965}
2962QString KABCore::sentSyncFile() 2966QString KABCore::sentSyncFile()
2963{ 2967{
2964#ifdef DESKTOP_VERSION 2968#ifdef DESKTOP_VERSION
2965 return locateLocal( "tmp", "copysyncab.vcf" ); 2969 return locateLocal( "tmp", "copysyncab.vcf" );
2966#else 2970#else
2967 return QString( "/tmp/copysyncab.vcf" ); 2971 return QString( "/tmp/copysyncab.vcf" );
2968#endif 2972#endif
2969} 2973}
2970 2974
2971void KABCore::setCaptionBack() 2975void KABCore::setCaptionBack()
2972{ 2976{
2973 mMessageTimer->stop(); 2977 mMessageTimer->stop();
2974 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2978 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2975} 2979}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 4667918..4e29d6f 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -507,1113 +507,1115 @@ void CalendarView::suspendAlarm()
507void CalendarView::startAlarm( QString mess , QString filename) 507void CalendarView::startAlarm( QString mess , QString filename)
508{ 508{
509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
511 511
512} 512}
513 513
514void CalendarView::checkNextTimerAlarm() 514void CalendarView::checkNextTimerAlarm()
515{ 515{
516 mCalendar->checkAlarmForIncidence( 0, true ); 516 mCalendar->checkAlarmForIncidence( 0, true );
517} 517}
518 518
519void CalendarView::computeAlarm( QString msg ) 519void CalendarView::computeAlarm( QString msg )
520{ 520{
521 521
522 QString mess = msg; 522 QString mess = msg;
523 QString mAlarmMessage = mess.mid( 9 ); 523 QString mAlarmMessage = mess.mid( 9 );
524 QString filename = MainWindow::resourcePath(); 524 QString filename = MainWindow::resourcePath();
525 filename += "koalarm.wav"; 525 filename += "koalarm.wav";
526 QString tempfilename; 526 QString tempfilename;
527 if ( mess.left( 13 ) == "suspend_alarm") { 527 if ( mess.left( 13 ) == "suspend_alarm") {
528 bool error = false; 528 bool error = false;
529 int len = mess.mid( 13 ).find("+++"); 529 int len = mess.mid( 13 ).find("+++");
530 if ( len < 2 ) 530 if ( len < 2 )
531 error = true; 531 error = true;
532 else { 532 else {
533 tempfilename = mess.mid( 13, len ); 533 tempfilename = mess.mid( 13, len );
534 if ( !QFile::exists( tempfilename ) ) 534 if ( !QFile::exists( tempfilename ) )
535 error = true; 535 error = true;
536 } 536 }
537 if ( ! error ) { 537 if ( ! error ) {
538 filename = tempfilename; 538 filename = tempfilename;
539 } 539 }
540 mAlarmMessage = mess.mid( 13+len+3 ); 540 mAlarmMessage = mess.mid( 13+len+3 );
541 //qDebug("suspend file %s ",tempfilename.latin1() ); 541 //qDebug("suspend file %s ",tempfilename.latin1() );
542 startAlarm( mAlarmMessage, filename); 542 startAlarm( mAlarmMessage, filename);
543 return; 543 return;
544 } 544 }
545 if ( mess.left( 11 ) == "timer_alarm") { 545 if ( mess.left( 11 ) == "timer_alarm") {
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 // 0 equal 717 // 0 equal
718 // 1 take local 718 // 1 take local
719 // 2 take remote 719 // 2 take remote
720 // 3 cancel 720 // 3 cancel
721 QDateTime lastSync = mLastCalendarSync; 721 QDateTime lastSync = mLastCalendarSync;
722 QDateTime localMod = local->lastModified(); 722 QDateTime localMod = local->lastModified();
723 QDateTime remoteMod = remote->lastModified(); 723 QDateTime remoteMod = remote->lastModified();
724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
725 bool remCh, locCh; 725 bool remCh, locCh;
726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
727 //if ( remCh ) 727 //if ( remCh )
728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
729 locCh = ( localMod > mLastCalendarSync ); 729 locCh = ( localMod > mLastCalendarSync );
730 if ( !remCh && ! locCh ) { 730 if ( !remCh && ! locCh ) {
731 //qDebug("both not changed "); 731 //qDebug("both not changed ");
732 lastSync = localMod.addDays(1); 732 lastSync = localMod.addDays(1);
733 if ( mode <= SYNC_PREF_ASK ) 733 if ( mode <= SYNC_PREF_ASK )
734 return 0; 734 return 0;
735 } else { 735 } else {
736 if ( locCh ) { 736 if ( locCh ) {
737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
738 lastSync = localMod.addDays( -1 ); 738 lastSync = localMod.addDays( -1 );
739 if ( !remCh ) 739 if ( !remCh )
740 remoteMod = ( lastSync.addDays( -1 ) ); 740 remoteMod = ( lastSync.addDays( -1 ) );
741 } else { 741 } else {
742 //qDebug(" not loc changed "); 742 //qDebug(" not loc changed ");
743 lastSync = localMod.addDays( 1 ); 743 lastSync = localMod.addDays( 1 );
744 if ( remCh ) 744 if ( remCh )
745 remoteMod =( lastSync.addDays( 1 ) ); 745 remoteMod =( lastSync.addDays( 1 ) );
746 746
747 } 747 }
748 } 748 }
749 full = true; 749 full = true;
750 if ( mode < SYNC_PREF_ASK ) 750 if ( mode < SYNC_PREF_ASK )
751 mode = SYNC_PREF_ASK; 751 mode = SYNC_PREF_ASK;
752 } else { 752 } else {
753 if ( localMod == remoteMod ) 753 if ( localMod == remoteMod )
754 // if ( local->revision() == remote->revision() ) 754 // if ( local->revision() == remote->revision() )
755 return 0; 755 return 0;
756 756
757 } 757 }
758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
759 759
760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
762 //full = true; //debug only 762 //full = true; //debug only
763 if ( full ) { 763 if ( full ) {
764 bool equ = false; 764 bool equ = false;
765 if ( local->type() == "Event" ) { 765 if ( local->type() == "Event" ) {
766 equ = (*((Event*) local) == *((Event*) remote)); 766 equ = (*((Event*) local) == *((Event*) remote));
767 } 767 }
768 else if ( local->type() =="Todo" ) 768 else if ( local->type() =="Todo" )
769 equ = (*((Todo*) local) == (*(Todo*) remote)); 769 equ = (*((Todo*) local) == (*(Todo*) remote));
770 else if ( local->type() =="Journal" ) 770 else if ( local->type() =="Journal" )
771 equ = (*((Journal*) local) == *((Journal*) remote)); 771 equ = (*((Journal*) local) == *((Journal*) remote));
772 if ( equ ) { 772 if ( equ ) {
773 //qDebug("equal "); 773 //qDebug("equal ");
774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
776 } 776 }
777 if ( mode < SYNC_PREF_FORCE_LOCAL ) 777 if ( mode < SYNC_PREF_FORCE_LOCAL )
778 return 0; 778 return 0;
779 779
780 }//else //debug only 780 }//else //debug only
781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
782 } 782 }
783 int result; 783 int result;
784 bool localIsNew; 784 bool localIsNew;
785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 785 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
786 786
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remoteMod ) 792 if ( lastSync > remoteMod )
793 return 1; 793 return 1;
794 if ( lastSync > localMod ) 794 if ( lastSync > localMod )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( localMod > remoteMod ) 806 if ( localMod > remoteMod )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
813 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
814 return 1; 814 return 1;
815 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 localIsNew = localMod >= remoteMod; 818 localIsNew = localMod >= remoteMod;
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 mLastCalendarSync = QDateTime::currentDateTime(); 929 mLastCalendarSync = QDateTime::currentDateTime();
930 if ( mSyncManager->syncWithDesktop() ) { 930 if ( mSyncManager->syncWithDesktop() ) {
931 remote->resetPilotStat(1); 931 remote->resetPilotStat(1);
932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
935 } else { 935 } else {
936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); 936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime ");
937 } 937 }
938 } 938 }
939 QDateTime modifiedCalendar = mLastCalendarSync;; 939 QDateTime modifiedCalendar = mLastCalendarSync;;
940 eventLSync = getLastSyncEvent(); 940 eventLSync = getLastSyncEvent();
941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
942 if ( eventR ) { 942 if ( eventR ) {
943 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
944 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
945 945
946 } else { 946 } else {
947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
948 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 } 958 }
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( mSyncManager->syncWithDesktop() ) { 970 if ( mSyncManager->syncWithDesktop() ) {
971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
972 } 972 }
973 if ( fullDateRange ) 973 if ( fullDateRange )
974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
975 else 975 else
976 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
977 // for resyncing if own file has changed 977 // for resyncing if own file has changed
978 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
979 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
980 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
981 } 981 }
982 //qDebug("*************************** "); 982 //qDebug("*************************** ");
983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
984 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
985 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
986 Incidence* inL; 986 Incidence* inL;
987 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
988 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
989 989
990 int w = 300; 990 int w = 300;
991 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
992 w = 220; 992 w = 220;
993 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
994 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
995 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
997 bar.show(); 997 bar.show();
998 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
999 int incCounter = 0; 999 int incCounter = 0;
1000 while ( inR ) { 1000 while ( inR ) {
1001 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
1002 return false; 1002 return false;
1003 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
1004 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
1005 ++incCounter; 1005 ++incCounter;
1006 uid = inR->uid(); 1006 uid = inR->uid();
1007 bool skipIncidence = false; 1007 bool skipIncidence = false;
1008 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1009 skipIncidence = true; 1009 skipIncidence = true;
1010 QString idS; 1010 QString idS;
1011 qApp->processEvents(); 1011 qApp->processEvents();
1012 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1013 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1014 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local **********************
1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1022 else 1022 else
1023 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1024 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1025 inR = inL->clone(); 1025 inR = inL->clone();
1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1028 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1029 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1030 if ( mSyncManager->syncWithDesktop() ) 1030 if ( mSyncManager->syncWithDesktop() )
1031 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1032 ++changedRemote; 1032 ++changedRemote;
1033 } else { 1033 } else {// take remote **********************
1034 idS = inL->IDStr(); 1034 idS = inL->IDStr();
1035 int pid = inL->pilotId(); 1035 int pid = inL->pilotId();
1036 local->deleteIncidence( inL ); 1036 local->deleteIncidence( inL );
1037 inL = inR->clone(); 1037 inL = inR->clone();
1038 if ( mSyncManager->syncWithDesktop() ) 1038 if ( mSyncManager->syncWithDesktop() )
1039 inL->setPilotId( pid ); 1039 inL->setPilotId( pid );
1040 inL->setIDStr( idS ); 1040 inL->setIDStr( idS );
1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1044 } 1044 }
1045 local->addIncidence( inL ); 1045 local->addIncidence( inL );
1046 ++changedLocal; 1046 ++changedLocal;
1047 } 1047 }
1048 } 1048 }
1049 } else { // no conflict 1049 } else { // no conflict ********** add or delete remote
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1051 QString des = eventLSync->description(); 1051 QString des = eventLSync->description();
1052 QString pref = "e"; 1052 QString pref = "e";
1053 if ( inR->type() == "Todo" ) 1053 if ( inR->type() == "Todo" )
1054 pref = "t"; 1054 pref = "t";
1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1057 //remote->deleteIncidence( inR ); 1057 //remote->deleteIncidence( inR );
1058 ++deletedEventR; 1058 ++deletedEventR;
1059 } else { 1059 } else {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 inL = inR->clone(); 1061 inL = inR->clone();
1062 inL->setIDStr( ":" ); 1062 inL->setIDStr( ":" );
1063 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1064 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1063 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1064 ++addedEvent; 1066 ++addedEvent;
1065 } 1067 }
1066 } else { 1068 } else {
1067 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1068 inR->setLastModified( modifiedCalendar ); 1070 inR->setLastModified( modifiedCalendar );
1069 inL = inR->clone(); 1071 inL = inR->clone();
1070 inL->setIDStr( ":" ); 1072 inL->setIDStr( ":" );
1071 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1072 ++addedEvent; 1074 ++addedEvent;
1073 } else { 1075 } else {
1074 checkExternSyncEvent(eventRSyncSharp, inR); 1076 checkExternSyncEvent(eventRSyncSharp, inR);
1075 remote->deleteIncidence( inR ); 1077 remote->deleteIncidence( inR );
1076 ++deletedEventR; 1078 ++deletedEventR;
1077 } 1079 }
1078 } 1080 }
1079 } 1081 }
1080 } 1082 }
1081 inR = er.next(); 1083 inR = er.next();
1082 } 1084 }
1083 QPtrList<Incidence> el = local->rawIncidences(); 1085 QPtrList<Incidence> el = local->rawIncidences();
1084 inL = el.first(); 1086 inL = el.first();
1085 modulo = (el.count()/10)+1; 1087 modulo = (el.count()/10)+1;
1086 bar.setCaption (i18n("Add / remove events") ); 1088 bar.setCaption (i18n("Add / remove events") );
1087 bar.setTotalSteps ( el.count() ) ; 1089 bar.setTotalSteps ( el.count() ) ;
1088 bar.show(); 1090 bar.show();
1089 incCounter = 0; 1091 incCounter = 0;
1090 1092
1091 while ( inL ) { 1093 while ( inL ) {
1092 1094
1093 qApp->processEvents(); 1095 qApp->processEvents();
1094 if ( ! bar.isVisible() ) 1096 if ( ! bar.isVisible() )
1095 return false; 1097 return false;
1096 if ( incCounter % modulo == 0 ) 1098 if ( incCounter % modulo == 0 )
1097 bar.setProgress( incCounter ); 1099 bar.setProgress( incCounter );
1098 ++incCounter; 1100 ++incCounter;
1099 uid = inL->uid(); 1101 uid = inL->uid();
1100 bool skipIncidence = false; 1102 bool skipIncidence = false;
1101 if ( uid.left(15) == QString("last-syncEvent-") ) 1103 if ( uid.left(15) == QString("last-syncEvent-") )
1102 skipIncidence = true; 1104 skipIncidence = true;
1103 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1105 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1104 skipIncidence = true; 1106 skipIncidence = true;
1105 if ( !skipIncidence ) { 1107 if ( !skipIncidence ) {
1106 inR = remote->incidence( uid ); 1108 inR = remote->incidence( uid );
1107 if ( ! inR ) { 1109 if ( ! inR ) { // no conflict ********** add or delete local
1108 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1110 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1109 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1111 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1110 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1111 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1112 ++deletedEventL; 1114 ++deletedEventL;
1113 } else { 1115 } else {
1114 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1116 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1115 inL->removeID(mCurrentSyncDevice ); 1117 inL->removeID(mCurrentSyncDevice );
1116 ++addedEventR; 1118 ++addedEventR;
1117 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1119 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1118 inL->setLastModified( modifiedCalendar ); 1120 inL->setLastModified( modifiedCalendar );
1119 inR = inL->clone(); 1121 inR = inL->clone();
1120 inR->setIDStr( ":" ); 1122 inR->setIDStr( ":" );
1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1123 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1122 remote->addIncidence( inR ); 1124 remote->addIncidence( inR );
1123 } 1125 }
1124 } 1126 }
1125 } else { 1127 } else {
1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1128 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1127 checkExternSyncEvent(eventLSyncSharp, inL); 1129 checkExternSyncEvent(eventLSyncSharp, inL);
1128 local->deleteIncidence( inL ); 1130 local->deleteIncidence( inL );
1129 ++deletedEventL; 1131 ++deletedEventL;
1130 } else { 1132 } else {
1131 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1133 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1132 ++addedEventR; 1134 ++addedEventR;
1133 inL->setLastModified( modifiedCalendar ); 1135 inL->setLastModified( modifiedCalendar );
1134 inR = inL->clone(); 1136 inR = inL->clone();
1135 inR->setIDStr( ":" ); 1137 inR->setIDStr( ":" );
1136 remote->addIncidence( inR ); 1138 remote->addIncidence( inR );
1137 } 1139 }
1138 } 1140 }
1139 } 1141 }
1140 } 1142 }
1141 } 1143 }
1142 inL = el.next(); 1144 inL = el.next();
1143 } 1145 }
1144 int delFut = 0; 1146 int delFut = 0;
1145 int remRem = 0; 1147 int remRem = 0;
1146 if ( mSyncManager->mWriteBackInFuture ) { 1148 if ( mSyncManager->mWriteBackInFuture ) {
1147 er = remote->rawIncidences(); 1149 er = remote->rawIncidences();
1148 remRem = er.count(); 1150 remRem = er.count();
1149 inR = er.first(); 1151 inR = er.first();
1150 QDateTime dt; 1152 QDateTime dt;
1151 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1153 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1152 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1154 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1153 while ( inR ) { 1155 while ( inR ) {
1154 if ( inR->type() == "Todo" ) { 1156 if ( inR->type() == "Todo" ) {
1155 Todo * t = (Todo*)inR; 1157 Todo * t = (Todo*)inR;
1156 if ( t->hasDueDate() ) 1158 if ( t->hasDueDate() )
1157 dt = t->dtDue(); 1159 dt = t->dtDue();
1158 else 1160 else
1159 dt = cur.addSecs( 62 ); 1161 dt = cur.addSecs( 62 );
1160 } 1162 }
1161 else if (inR->type() == "Event" ) { 1163 else if (inR->type() == "Event" ) {
1162 bool ok; 1164 bool ok;
1163 dt = inR->getNextOccurence( cur, &ok ); 1165 dt = inR->getNextOccurence( cur, &ok );
1164 if ( !ok ) 1166 if ( !ok )
1165 dt = cur.addSecs( -62 ); 1167 dt = cur.addSecs( -62 );
1166 } 1168 }
1167 else 1169 else
1168 dt = inR->dtStart(); 1170 dt = inR->dtStart();
1169 if ( dt < cur || dt > end ) { 1171 if ( dt < cur || dt > end ) {
1170 remote->deleteIncidence( inR ); 1172 remote->deleteIncidence( inR );
1171 ++delFut; 1173 ++delFut;
1172 } 1174 }
1173 inR = er.next(); 1175 inR = er.next();
1174 } 1176 }
1175 } 1177 }
1176 bar.hide(); 1178 bar.hide();
1177 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1179 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1178 eventLSync->setReadOnly( false ); 1180 eventLSync->setReadOnly( false );
1179 eventLSync->setDtStart( mLastCalendarSync ); 1181 eventLSync->setDtStart( mLastCalendarSync );
1180 eventRSync->setDtStart( mLastCalendarSync ); 1182 eventRSync->setDtStart( mLastCalendarSync );
1181 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1183 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1182 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1184 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1183 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1185 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1184 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1186 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1185 eventLSync->setReadOnly( true ); 1187 eventLSync->setReadOnly( true );
1186 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1188 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1187 remote->addEvent( eventRSync ); 1189 remote->addEvent( eventRSync );
1188 else 1190 else
1189 delete eventRSync; 1191 delete eventRSync;
1190 QString mes; 1192 QString mes;
1191 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1193 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1192 QString delmess; 1194 QString delmess;
1193 if ( delFut ) { 1195 if ( delFut ) {
1194 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1196 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1195 mes += delmess; 1197 mes += delmess;
1196 } 1198 }
1197 mCalendar->checkAlarmForIncidence( 0, true ); 1199 mCalendar->checkAlarmForIncidence( 0, true );
1198 qDebug( mes ); 1200 qDebug( mes );
1199 if ( mSyncManager->mShowSyncSummary ) { 1201 if ( mSyncManager->mShowSyncSummary ) {
1200 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1202 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1201 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1203 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1202 qDebug("cancelled "); 1204 qDebug("cancelled ");
1203 return false; 1205 return false;
1204 } 1206 }
1205 } 1207 }
1206 return syncOK; 1208 return syncOK;
1207} 1209}
1208 1210
1209void CalendarView::setSyncDevice( QString s ) 1211void CalendarView::setSyncDevice( QString s )
1210{ 1212{
1211 mCurrentSyncDevice= s; 1213 mCurrentSyncDevice= s;
1212} 1214}
1213void CalendarView::setSyncName( QString s ) 1215void CalendarView::setSyncName( QString s )
1214{ 1216{
1215 mCurrentSyncName= s; 1217 mCurrentSyncName= s;
1216} 1218}
1217bool CalendarView::syncCalendar(QString filename, int mode) 1219bool CalendarView::syncCalendar(QString filename, int mode)
1218{ 1220{
1219 //qDebug("syncCalendar %s ", filename.latin1()); 1221 //qDebug("syncCalendar %s ", filename.latin1());
1220 mGlobalSyncMode = SYNC_MODE_NORMAL; 1222 mGlobalSyncMode = SYNC_MODE_NORMAL;
1221 CalendarLocal* calendar = new CalendarLocal(); 1223 CalendarLocal* calendar = new CalendarLocal();
1222 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1224 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1223 FileStorage* storage = new FileStorage( calendar ); 1225 FileStorage* storage = new FileStorage( calendar );
1224 bool syncOK = false; 1226 bool syncOK = false;
1225 storage->setFileName( filename ); 1227 storage->setFileName( filename );
1226 // qDebug("loading ... "); 1228 // qDebug("loading ... ");
1227 if ( storage->load() ) { 1229 if ( storage->load() ) {
1228 getEventViewerDialog()->setSyncMode( true ); 1230 getEventViewerDialog()->setSyncMode( true );
1229 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1231 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1230 getEventViewerDialog()->setSyncMode( false ); 1232 getEventViewerDialog()->setSyncMode( false );
1231 if ( syncOK ) { 1233 if ( syncOK ) {
1232 if ( mSyncManager->mWriteBackFile ) 1234 if ( mSyncManager->mWriteBackFile )
1233 { 1235 {
1234 storage->setSaveFormat( new ICalFormat() ); 1236 storage->setSaveFormat( new ICalFormat() );
1235 storage->save(); 1237 storage->save();
1236 } 1238 }
1237 } 1239 }
1238 setModified( true ); 1240 setModified( true );
1239 } 1241 }
1240 delete storage; 1242 delete storage;
1241 delete calendar; 1243 delete calendar;
1242 if ( syncOK ) 1244 if ( syncOK )
1243 updateView(); 1245 updateView();
1244 return syncOK; 1246 return syncOK;
1245} 1247}
1246 1248
1247void CalendarView::syncExternal( int mode ) 1249void CalendarView::syncExternal( int mode )
1248{ 1250{
1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1251 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1250 1252
1251 qApp->processEvents(); 1253 qApp->processEvents();
1252 CalendarLocal* calendar = new CalendarLocal(); 1254 CalendarLocal* calendar = new CalendarLocal();
1253 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1255 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1254 bool syncOK = false; 1256 bool syncOK = false;
1255 bool loadSuccess = false; 1257 bool loadSuccess = false;
1256 PhoneFormat* phoneFormat = 0; 1258 PhoneFormat* phoneFormat = 0;
1257 emit tempDisableBR(true); 1259 emit tempDisableBR(true);
1258#ifndef DESKTOP_VERSION 1260#ifndef DESKTOP_VERSION
1259 SharpFormat* sharpFormat = 0; 1261 SharpFormat* sharpFormat = 0;
1260 if ( mode == 0 ) { // sharp 1262 if ( mode == 0 ) { // sharp
1261 sharpFormat = new SharpFormat () ; 1263 sharpFormat = new SharpFormat () ;
1262 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1264 loadSuccess = sharpFormat->load( calendar, mCalendar );
1263 1265
1264 } else 1266 } else
1265#endif 1267#endif
1266 if ( mode == 1 ) { // phone 1268 if ( mode == 1 ) { // phone
1267 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1269 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1268 mSyncManager->mPhoneDevice, 1270 mSyncManager->mPhoneDevice,
1269 mSyncManager->mPhoneConnection, 1271 mSyncManager->mPhoneConnection,
1270 mSyncManager->mPhoneModel); 1272 mSyncManager->mPhoneModel);
1271 loadSuccess = phoneFormat->load( calendar,mCalendar); 1273 loadSuccess = phoneFormat->load( calendar,mCalendar);
1272 1274
1273 } else { 1275 } else {
1274 emit tempDisableBR(false); 1276 emit tempDisableBR(false);
1275 return; 1277 return;
1276 } 1278 }
1277 if ( loadSuccess ) { 1279 if ( loadSuccess ) {
1278 getEventViewerDialog()->setSyncMode( true ); 1280 getEventViewerDialog()->setSyncMode( true );
1279 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1281 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1280 getEventViewerDialog()->setSyncMode( false ); 1282 getEventViewerDialog()->setSyncMode( false );
1281 qApp->processEvents(); 1283 qApp->processEvents();
1282 if ( syncOK ) { 1284 if ( syncOK ) {
1283 if ( mSyncManager->mWriteBackFile ) 1285 if ( mSyncManager->mWriteBackFile )
1284 { 1286 {
1285 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1287 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1286 Incidence* inc = iL.first(); 1288 Incidence* inc = iL.first();
1287 if ( phoneFormat ) { 1289 if ( phoneFormat ) {
1288 while ( inc ) { 1290 while ( inc ) {
1289 inc->removeID(mCurrentSyncDevice); 1291 inc->removeID(mCurrentSyncDevice);
1290 inc = iL.next(); 1292 inc = iL.next();
1291 } 1293 }
1292 } 1294 }
1293#ifndef DESKTOP_VERSION 1295#ifndef DESKTOP_VERSION
1294 if ( sharpFormat ) 1296 if ( sharpFormat )
1295 sharpFormat->save(calendar); 1297 sharpFormat->save(calendar);
1296#endif 1298#endif
1297 if ( phoneFormat ) 1299 if ( phoneFormat )
1298 phoneFormat->save(calendar); 1300 phoneFormat->save(calendar);
1299 iL = calendar->rawIncidences(); 1301 iL = calendar->rawIncidences();
1300 inc = iL.first(); 1302 inc = iL.first();
1301 Incidence* loc; 1303 Incidence* loc;
1302 while ( inc ) { 1304 while ( inc ) {
1303 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1305 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1304 loc = mCalendar->incidence(inc->uid() ); 1306 loc = mCalendar->incidence(inc->uid() );
1305 if ( loc ) { 1307 if ( loc ) {
1306 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1308 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1307 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1309 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1308 } 1310 }
1309 } 1311 }
1310 inc = iL.next(); 1312 inc = iL.next();
1311 } 1313 }
1312 Incidence* lse = getLastSyncEvent(); 1314 Incidence* lse = getLastSyncEvent();
1313 if ( lse ) { 1315 if ( lse ) {
1314 lse->setReadOnly( false ); 1316 lse->setReadOnly( false );
1315 lse->setDescription( "" ); 1317 lse->setDescription( "" );
1316 lse->setReadOnly( true ); 1318 lse->setReadOnly( true );
1317 } 1319 }
1318 } 1320 }
1319 } else { 1321 } else {
1320 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1322 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1321 } 1323 }
1322 setModified( true ); 1324 setModified( true );
1323 } else { 1325 } else {
1324 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1326 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1325 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1327 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1326 question, i18n("Ok")) ; 1328 question, i18n("Ok")) ;
1327 1329
1328 } 1330 }
1329 delete calendar; 1331 delete calendar;
1330 updateView(); 1332 updateView();
1331 emit tempDisableBR(false); 1333 emit tempDisableBR(false);
1332 return ;//syncOK; 1334 return ;//syncOK;
1333 1335
1334} 1336}
1335 1337
1336bool CalendarView::importBday() 1338bool CalendarView::importBday()
1337{ 1339{
1338#ifndef KORG_NOKABC 1340#ifndef KORG_NOKABC
1339 1341
1340#ifdef DESKTOP_VERSION 1342#ifdef DESKTOP_VERSION
1341 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1343 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1342 KABC::AddressBook::Iterator it; 1344 KABC::AddressBook::Iterator it;
1343 int count = 0; 1345 int count = 0;
1344 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1346 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1345 ++count; 1347 ++count;
1346 } 1348 }
1347 QProgressBar bar(count,0 ); 1349 QProgressBar bar(count,0 );
1348 int w = 300; 1350 int w = 300;
1349 if ( QApplication::desktop()->width() < 320 ) 1351 if ( QApplication::desktop()->width() < 320 )
1350 w = 220; 1352 w = 220;
1351 int h = bar.sizeHint().height() ; 1353 int h = bar.sizeHint().height() ;
1352 int dw = QApplication::desktop()->width(); 1354 int dw = QApplication::desktop()->width();
1353 int dh = QApplication::desktop()->height(); 1355 int dh = QApplication::desktop()->height();
1354 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1356 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1355 bar.show(); 1357 bar.show();
1356 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1358 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1357 qApp->processEvents(); 1359 qApp->processEvents();
1358 count = 0; 1360 count = 0;
1359 int addCount = 0; 1361 int addCount = 0;
1360 KCal::Attendee* a = 0; 1362 KCal::Attendee* a = 0;
1361 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1363 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1362 if ( ! bar.isVisible() ) 1364 if ( ! bar.isVisible() )
1363 return false; 1365 return false;
1364 bar.setProgress( count++ ); 1366 bar.setProgress( count++ );
1365 qApp->processEvents(); 1367 qApp->processEvents();
1366 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1368 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1367 if ( (*it).birthday().date().isValid() ){ 1369 if ( (*it).birthday().date().isValid() ){
1368 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1370 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1369 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1371 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1370 ++addCount; 1372 ++addCount;
1371 } 1373 }
1372 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1374 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1373 if ( anni.isValid() ){ 1375 if ( anni.isValid() ){
1374 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1376 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1375 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1377 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1376 ++addCount; 1378 ++addCount;
1377 } 1379 }
1378 } 1380 }
1379 updateView(); 1381 updateView();
1380 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1382 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1381#else //DESKTOP_VERSION 1383#else //DESKTOP_VERSION
1382 1384
1383 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1385 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1384 // the result should now arrive through method insertBirthdays 1386 // the result should now arrive through method insertBirthdays
1385 1387
1386#endif //DESKTOP_VERSION 1388#endif //DESKTOP_VERSION
1387 1389
1388#endif //KORG_NOKABC 1390#endif //KORG_NOKABC
1389 1391
1390 1392
1391 return true; 1393 return true;
1392} 1394}
1393 1395
1394// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1396// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1395void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1397void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1396 const QStringList& anniversaryList, const QStringList& realNameList, 1398 const QStringList& anniversaryList, const QStringList& realNameList,
1397 const QStringList& emailList, const QStringList& assembledNameList, 1399 const QStringList& emailList, const QStringList& assembledNameList,
1398 const QStringList& uidList) 1400 const QStringList& uidList)
1399{ 1401{
1400 qDebug("CalendarView::insertBirthdays"); 1402 qDebug("CalendarView::insertBirthdays");
1401 if (uid == this->name()) 1403 if (uid == this->name())
1402 { 1404 {
1403 int count = birthdayList.count(); 1405 int count = birthdayList.count();
1404 int addCount = 0; 1406 int addCount = 0;
1405 KCal::Attendee* a = 0; 1407 KCal::Attendee* a = 0;
1406 1408
1407 qDebug("CalView 1 %i", count); 1409 qDebug("CalView 1 %i", count);
1408 1410
1409 QProgressBar bar(count,0 ); 1411 QProgressBar bar(count,0 );
1410 int w = 300; 1412 int w = 300;
1411 if ( QApplication::desktop()->width() < 320 ) 1413 if ( QApplication::desktop()->width() < 320 )
1412 w = 220; 1414 w = 220;
1413 int h = bar.sizeHint().height() ; 1415 int h = bar.sizeHint().height() ;
1414 int dw = QApplication::desktop()->width(); 1416 int dw = QApplication::desktop()->width();
1415 int dh = QApplication::desktop()->height(); 1417 int dh = QApplication::desktop()->height();
1416 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1418 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1417 bar.show(); 1419 bar.show();
1418 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1420 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1419 qApp->processEvents(); 1421 qApp->processEvents();
1420 1422
1421 QDate birthday; 1423 QDate birthday;
1422 QDate anniversary; 1424 QDate anniversary;
1423 QString realName; 1425 QString realName;
1424 QString email; 1426 QString email;
1425 QString assembledName; 1427 QString assembledName;
1426 QString uid; 1428 QString uid;
1427 bool ok = true; 1429 bool ok = true;
1428 for ( int i = 0; i < count; i++) 1430 for ( int i = 0; i < count; i++)
1429 { 1431 {
1430 if ( ! bar.isVisible() ) 1432 if ( ! bar.isVisible() )
1431 return; 1433 return;
1432 bar.setProgress( i ); 1434 bar.setProgress( i );
1433 qApp->processEvents(); 1435 qApp->processEvents();
1434 1436
1435 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1437 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1436 if (!ok) { 1438 if (!ok) {
1437 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1439 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1438 } 1440 }
1439 1441
1440 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1442 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1441 if (!ok) { 1443 if (!ok) {
1442 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1444 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1443 } 1445 }
1444 realName = realNameList[i]; 1446 realName = realNameList[i];
1445 email = emailList[i]; 1447 email = emailList[i];
1446 assembledName = assembledNameList[i]; 1448 assembledName = assembledNameList[i];
1447 uid = uidList[i]; 1449 uid = uidList[i];
1448 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1450 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1449 1451
1450 if ( birthday.isValid() ){ 1452 if ( birthday.isValid() ){
1451 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1453 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1452 KCal::Attendee::ReqParticipant,uid) ; 1454 KCal::Attendee::ReqParticipant,uid) ;
1453 if ( addAnniversary( birthday, assembledName, a, true ) ) 1455 if ( addAnniversary( birthday, assembledName, a, true ) )
1454 ++addCount; 1456 ++addCount;
1455 } 1457 }
1456 1458
1457 if ( anniversary.isValid() ){ 1459 if ( anniversary.isValid() ){
1458 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1460 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1459 KCal::Attendee::ReqParticipant,uid) ; 1461 KCal::Attendee::ReqParticipant,uid) ;
1460 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1462 if ( addAnniversary( anniversary, assembledName, a, false ) )
1461 ++addCount; 1463 ++addCount;
1462 } 1464 }
1463 } 1465 }
1464 1466
1465 updateView(); 1467 updateView();
1466 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1468 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1467 1469
1468 } 1470 }
1469 1471
1470} 1472}
1471 1473
1472 1474
1473 1475
1474bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1476bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1475{ 1477{
1476 //qDebug("addAnni "); 1478 //qDebug("addAnni ");
1477 Event * ev = new Event(); 1479 Event * ev = new Event();
1478 if ( a ) { 1480 if ( a ) {
1479 ev->addAttendee( a ); 1481 ev->addAttendee( a );
1480 } 1482 }
1481 QString kind; 1483 QString kind;
1482 if ( birthday ) 1484 if ( birthday )
1483 kind = i18n( "Birthday" ); 1485 kind = i18n( "Birthday" );
1484 else 1486 else
1485 kind = i18n( "Anniversary" ); 1487 kind = i18n( "Anniversary" );
1486 ev->setSummary( name + " - " + kind ); 1488 ev->setSummary( name + " - " + kind );
1487 ev->setOrganizer(a->email()); 1489 ev->setOrganizer(a->email());
1488 ev->setCategories( kind ); 1490 ev->setCategories( kind );
1489 ev->setDtStart( QDateTime(date) ); 1491 ev->setDtStart( QDateTime(date) );
1490 ev->setDtEnd( QDateTime(date) ); 1492 ev->setDtEnd( QDateTime(date) );
1491 ev->setFloats( true ); 1493 ev->setFloats( true );
1492 Recurrence * rec = ev->recurrence(); 1494 Recurrence * rec = ev->recurrence();
1493 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1495 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1494 rec->addYearlyNum( date.month() ); 1496 rec->addYearlyNum( date.month() );
1495 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1497 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1496 delete ev; 1498 delete ev;
1497 return false; 1499 return false;
1498 } 1500 }
1499 return true; 1501 return true;
1500 1502
1501} 1503}
1502bool CalendarView::importQtopia( const QString &categories, 1504bool CalendarView::importQtopia( const QString &categories,
1503 const QString &datebook, 1505 const QString &datebook,
1504 const QString &todolist ) 1506 const QString &todolist )
1505{ 1507{
1506 1508
1507 QtopiaFormat qtopiaFormat; 1509 QtopiaFormat qtopiaFormat;
1508 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1510 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1509 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1511 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1510 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1512 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1511 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1513 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1512 1514
1513 updateView(); 1515 updateView();
1514 return true; 1516 return true;
1515 1517
1516#if 0 1518#if 0
1517 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1519 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1518 mCurrentSyncDevice = "qtopia-XML"; 1520 mCurrentSyncDevice = "qtopia-XML";
1519 if ( mSyncManager->mAskForPreferences ) 1521 if ( mSyncManager->mAskForPreferences )
1520 edit_sync_options(); 1522 edit_sync_options();
1521 qApp->processEvents(); 1523 qApp->processEvents();
1522 CalendarLocal* calendar = new CalendarLocal(); 1524 CalendarLocal* calendar = new CalendarLocal();
1523 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1525 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1524 bool syncOK = false; 1526 bool syncOK = false;
1525 QtopiaFormat qtopiaFormat; 1527 QtopiaFormat qtopiaFormat;
1526 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1528 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1527 bool loadOk = true; 1529 bool loadOk = true;
1528 if ( !categories.isEmpty() ) 1530 if ( !categories.isEmpty() )
1529 loadOk = qtopiaFormat.load( calendar, categories ); 1531 loadOk = qtopiaFormat.load( calendar, categories );
1530 if ( loadOk && !datebook.isEmpty() ) 1532 if ( loadOk && !datebook.isEmpty() )
1531 loadOk = qtopiaFormat.load( calendar, datebook ); 1533 loadOk = qtopiaFormat.load( calendar, datebook );
1532 if ( loadOk && !todolist.isEmpty() ) 1534 if ( loadOk && !todolist.isEmpty() )
1533 loadOk = qtopiaFormat.load( calendar, todolist ); 1535 loadOk = qtopiaFormat.load( calendar, todolist );
1534 1536
1535 if ( loadOk ) { 1537 if ( loadOk ) {
1536 getEventViewerDialog()->setSyncMode( true ); 1538 getEventViewerDialog()->setSyncMode( true );
1537 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1539 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1538 getEventViewerDialog()->setSyncMode( false ); 1540 getEventViewerDialog()->setSyncMode( false );
1539 qApp->processEvents(); 1541 qApp->processEvents();
1540 if ( syncOK ) { 1542 if ( syncOK ) {
1541 if ( mSyncManager->mWriteBackFile ) 1543 if ( mSyncManager->mWriteBackFile )
1542 { 1544 {
1543 // write back XML file 1545 // write back XML file
1544 1546
1545 } 1547 }
1546 setModified( true ); 1548 setModified( true );
1547 } 1549 }
1548 } else { 1550 } else {
1549 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1551 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1550 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1552 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1551 question, i18n("Ok")) ; 1553 question, i18n("Ok")) ;
1552 } 1554 }
1553 delete calendar; 1555 delete calendar;
1554 updateView(); 1556 updateView();
1555 return syncOK; 1557 return syncOK;
1556 1558
1557 1559
1558#endif 1560#endif
1559 1561
1560} 1562}
1561 1563
1562void CalendarView::setSyncEventsReadOnly() 1564void CalendarView::setSyncEventsReadOnly()
1563{ 1565{
1564 Event * ev; 1566 Event * ev;
1565 QPtrList<Event> eL = mCalendar->rawEvents(); 1567 QPtrList<Event> eL = mCalendar->rawEvents();
1566 ev = eL.first(); 1568 ev = eL.first();
1567 while ( ev ) { 1569 while ( ev ) {
1568 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1570 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1569 ev->setReadOnly( true ); 1571 ev->setReadOnly( true );
1570 ev = eL.next(); 1572 ev = eL.next();
1571 } 1573 }
1572} 1574}
1573bool CalendarView::openCalendar(QString filename, bool merge) 1575bool CalendarView::openCalendar(QString filename, bool merge)
1574{ 1576{
1575 1577
1576 if (filename.isEmpty()) { 1578 if (filename.isEmpty()) {
1577 return false; 1579 return false;
1578 } 1580 }
1579 1581
1580 if (!QFile::exists(filename)) { 1582 if (!QFile::exists(filename)) {
1581 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1583 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1582 return false; 1584 return false;
1583 } 1585 }
1584 1586
1585 globalFlagBlockAgenda = 1; 1587 globalFlagBlockAgenda = 1;
1586 if (!merge) mCalendar->close(); 1588 if (!merge) mCalendar->close();
1587 1589
1588 mStorage->setFileName( filename ); 1590 mStorage->setFileName( filename );
1589 1591
1590 if ( mStorage->load() ) { 1592 if ( mStorage->load() ) {
1591 if ( merge ) ;//setModified( true ); 1593 if ( merge ) ;//setModified( true );
1592 else { 1594 else {
1593 //setModified( true ); 1595 //setModified( true );
1594 mViewManager->setDocumentId( filename ); 1596 mViewManager->setDocumentId( filename );
1595 mDialogManager->setDocumentId( filename ); 1597 mDialogManager->setDocumentId( filename );
1596 mTodoList->setDocumentId( filename ); 1598 mTodoList->setDocumentId( filename );
1597 } 1599 }
1598 globalFlagBlockAgenda = 2; 1600 globalFlagBlockAgenda = 2;
1599 // if ( getLastSyncEvent() ) 1601 // if ( getLastSyncEvent() )
1600 // getLastSyncEvent()->setReadOnly( true ); 1602 // getLastSyncEvent()->setReadOnly( true );
1601 mCalendar->reInitAlarmSettings(); 1603 mCalendar->reInitAlarmSettings();
1602 setSyncEventsReadOnly(); 1604 setSyncEventsReadOnly();
1603 updateUnmanagedViews(); 1605 updateUnmanagedViews();
1604 updateView(); 1606 updateView();
1605 if ( filename != MainWindow::defaultFileName() ) { 1607 if ( filename != MainWindow::defaultFileName() ) {
1606 saveCalendar( MainWindow::defaultFileName() ); 1608 saveCalendar( MainWindow::defaultFileName() );
1607 } else { 1609 } else {
1608 QFileInfo finf ( MainWindow::defaultFileName()); 1610 QFileInfo finf ( MainWindow::defaultFileName());
1609 if ( finf.exists() ) { 1611 if ( finf.exists() ) {
1610 setLoadedFileVersion( finf.lastModified () ); 1612 setLoadedFileVersion( finf.lastModified () );
1611 } 1613 }
1612 } 1614 }
1613 return true; 1615 return true;
1614 } else { 1616 } else {
1615 // while failing to load, the calendar object could 1617 // while failing to load, the calendar object could
1616 // have become partially populated. Clear it out. 1618 // have become partially populated. Clear it out.
1617 if ( !merge ) { 1619 if ( !merge ) {
1618 mCalendar->close(); 1620 mCalendar->close();
1619 mViewManager->setDocumentId( filename ); 1621 mViewManager->setDocumentId( filename );