author | zautrix <zautrix> | 2005-11-25 17:41:25 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-25 17:41:25 (UTC) |
commit | 279e183c0325cd9565605f60af0215bb9bfdc825 (patch) (unidiff) | |
tree | 43ab776cd108874819e7c6e73070a7d989a9078f /korganizer/calendarview.cpp | |
parent | 794a5204686ad9bfc16172b01db35f1f3b7683e5 (diff) | |
download | kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.zip kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.gz kdepimpi-279e183c0325cd9565605f60af0215bb9bfdc825.tar.bz2 |
sync
-rw-r--r-- | korganizer/calendarview.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 8965d3b..307027a 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -337,64 +337,65 @@ private: | |||
337 | QRadioButton* addCatBut; | 337 | QRadioButton* addCatBut; |
338 | }; | 338 | }; |
339 | 339 | ||
340 | 340 | ||
341 | 341 | ||
342 | CalendarView::CalendarView( CalendarResources *calendar, | 342 | CalendarView::CalendarView( CalendarResources *calendar, |
343 | QWidget *parent, const char *name ) | 343 | QWidget *parent, const char *name ) |
344 | : CalendarViewBase( parent, name ), | 344 | : CalendarViewBase( parent, name ), |
345 | mCalendar( calendar ), | 345 | mCalendar( calendar ), |
346 | mResourceManager( calendar->resourceManager() ) | 346 | mResourceManager( calendar->resourceManager() ) |
347 | { | 347 | { |
348 | 348 | ||
349 | mEventEditor = 0; | 349 | mEventEditor = 0; |
350 | mTodoEditor = 0; | 350 | mTodoEditor = 0; |
351 | 351 | ||
352 | init(); | 352 | init(); |
353 | } | 353 | } |
354 | 354 | ||
355 | CalendarView::CalendarView( Calendar *calendar, | 355 | CalendarView::CalendarView( Calendar *calendar, |
356 | QWidget *parent, const char *name ) | 356 | QWidget *parent, const char *name ) |
357 | : CalendarViewBase( parent, name ), | 357 | : CalendarViewBase( parent, name ), |
358 | mCalendar( calendar ), | 358 | mCalendar( calendar ), |
359 | mResourceManager( 0 ) | 359 | mResourceManager( 0 ) |
360 | { | 360 | { |
361 | 361 | ||
362 | mEventEditor = 0; | 362 | mEventEditor = 0; |
363 | mTodoEditor = 0; | 363 | mTodoEditor = 0; |
364 | init(); | 364 | init(); |
365 | } | 365 | } |
366 | 366 | ||
367 | void CalendarView::init() | 367 | void CalendarView::init() |
368 | { | 368 | { |
369 | mMultiResourceSync = false; | ||
369 | flag_blockConflict = false; | 370 | flag_blockConflict = false; |
370 | flag_blockScrollBar = false; | 371 | flag_blockScrollBar = false; |
371 | flag_checkFileFirsttime = true; | 372 | flag_checkFileFirsttime = true; |
372 | flag_clearallviewsEventDisplay = false; | 373 | flag_clearallviewsEventDisplay = false; |
373 | flag_clearallviewsupdateView = false; | 374 | flag_clearallviewsupdateView = false; |
374 | mNextAlarmDateTime = QDateTime::currentDateTime(); | 375 | mNextAlarmDateTime = QDateTime::currentDateTime(); |
375 | setFocusPolicy (NoFocus ); | 376 | setFocusPolicy (NoFocus ); |
376 | mViewerCallerIsSearchDialog = false; | 377 | mViewerCallerIsSearchDialog = false; |
377 | mBlockShowDates = false; | 378 | mBlockShowDates = false; |
378 | mConflictingEvent = 0; | 379 | mConflictingEvent = 0; |
379 | mDatePickerMode = 0; | 380 | mDatePickerMode = 0; |
380 | mCurrentSyncDevice = ""; | 381 | mCurrentSyncDevice = ""; |
381 | mViewManager = new KOViewManager( this ); | 382 | mViewManager = new KOViewManager( this ); |
382 | mDialogManager = new KODialogManager( this ); | 383 | mDialogManager = new KODialogManager( this ); |
383 | mEventViewerDialog = 0; | 384 | mEventViewerDialog = 0; |
384 | mModified = false; | 385 | mModified = false; |
385 | mReadOnly = false; | 386 | mReadOnly = false; |
386 | mSelectedIncidence = 0; | 387 | mSelectedIncidence = 0; |
387 | mCalPrinter = 0; | 388 | mCalPrinter = 0; |
388 | mFilters.setAutoDelete(true); | 389 | mFilters.setAutoDelete(true); |
389 | 390 | ||
390 | mCalendar->registerObserver( this ); | 391 | mCalendar->registerObserver( this ); |
391 | // TODO: Make sure that view is updated, when calendar is changed. | 392 | // TODO: Make sure that view is updated, when calendar is changed. |
392 | 393 | ||
393 | mStorage = new FileStorage( mCalendar ); | 394 | mStorage = new FileStorage( mCalendar ); |
394 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); | 395 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); |
395 | 396 | ||
396 | QBoxLayout *topLayout = (QBoxLayout*)layout(); | 397 | QBoxLayout *topLayout = (QBoxLayout*)layout(); |
397 | #ifndef KORG_NOSPLITTER | 398 | #ifndef KORG_NOSPLITTER |
398 | // create the main layout frames. | 399 | // create the main layout frames. |
399 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); | 400 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); |
400 | topLayout->addWidget(mPanner); | 401 | topLayout->addWidget(mPanner); |
@@ -1523,64 +1524,65 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b | |||
1523 | return result; | 1524 | return result; |
1524 | 1525 | ||
1525 | break; | 1526 | break; |
1526 | case SYNC_PREF_FORCE_LOCAL: | 1527 | case SYNC_PREF_FORCE_LOCAL: |
1527 | return 1; | 1528 | return 1; |
1528 | break; | 1529 | break; |
1529 | case SYNC_PREF_FORCE_REMOTE: | 1530 | case SYNC_PREF_FORCE_REMOTE: |
1530 | return 2; | 1531 | return 2; |
1531 | break; | 1532 | break; |
1532 | 1533 | ||
1533 | default: | 1534 | default: |
1534 | // SYNC_PREF_TAKE_BOTH not implemented | 1535 | // SYNC_PREF_TAKE_BOTH not implemented |
1535 | break; | 1536 | break; |
1536 | } | 1537 | } |
1537 | return 0; | 1538 | return 0; |
1538 | } | 1539 | } |
1539 | Event* CalendarView::getLastSyncEvent() | 1540 | Event* CalendarView::getLastSyncEvent() |
1540 | { | 1541 | { |
1541 | Event* lse; | 1542 | Event* lse; |
1542 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 1543 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
1543 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 1544 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
1544 | if (!lse) { | 1545 | if (!lse) { |
1545 | lse = new Event(); | 1546 | lse = new Event(); |
1546 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1547 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1547 | QString sum = ""; | 1548 | QString sum = ""; |
1548 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1549 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1549 | sum = "E: "; | 1550 | sum = "E: "; |
1550 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1551 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1551 | lse->setDtStart( mLastCalendarSync ); | 1552 | lse->setDtStart( mLastCalendarSync ); |
1552 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1553 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1553 | lse->setCategories( i18n("SyncEvent") ); | 1554 | lse->setCategories( i18n("SyncEvent") ); |
1554 | lse->setReadOnly( true ); | 1555 | lse->setReadOnly( true ); |
1556 | lse->setCalID( 1 ); | ||
1555 | mCalendar->addEvent( lse ); | 1557 | mCalendar->addEvent( lse ); |
1556 | } | 1558 | } |
1557 | 1559 | ||
1558 | return lse; | 1560 | return lse; |
1559 | 1561 | ||
1560 | } | 1562 | } |
1561 | 1563 | ||
1562 | // we check, if the to delete event has a id for a profile | 1564 | // we check, if the to delete event has a id for a profile |
1563 | // if yes, we set this id in the profile to delete | 1565 | // if yes, we set this id in the profile to delete |
1564 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1566 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1565 | { | 1567 | { |
1566 | if ( lastSync.count() == 0 ) { | 1568 | if ( lastSync.count() == 0 ) { |
1567 | //qDebug(" lastSync.count() == 0"); | 1569 | //qDebug(" lastSync.count() == 0"); |
1568 | return; | 1570 | return; |
1569 | } | 1571 | } |
1570 | if ( toDelete->typeID() == journalID ) | 1572 | if ( toDelete->typeID() == journalID ) |
1571 | return; | 1573 | return; |
1572 | 1574 | ||
1573 | Event* eve = lastSync.first(); | 1575 | Event* eve = lastSync.first(); |
1574 | 1576 | ||
1575 | while ( eve ) { | 1577 | while ( eve ) { |
1576 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1578 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1577 | if ( !id.isEmpty() ) { | 1579 | if ( !id.isEmpty() ) { |
1578 | QString des = eve->description(); | 1580 | QString des = eve->description(); |
1579 | QString pref = "e"; | 1581 | QString pref = "e"; |
1580 | if ( toDelete->typeID() == todoID ) | 1582 | if ( toDelete->typeID() == todoID ) |
1581 | pref = "t"; | 1583 | pref = "t"; |
1582 | des += pref+ id + ","; | 1584 | des += pref+ id + ","; |
1583 | eve->setReadOnly( false ); | 1585 | eve->setReadOnly( false ); |
1584 | eve->setDescription( des ); | 1586 | eve->setDescription( des ); |
1585 | //qDebug("setdes %s ", des.latin1()); | 1587 | //qDebug("setdes %s ", des.latin1()); |
1586 | eve->setReadOnly( true ); | 1588 | eve->setReadOnly( true ); |
@@ -1873,74 +1875,79 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1873 | if ( mSyncManager->mWriteBackInFuture ) { | 1875 | if ( mSyncManager->mWriteBackInFuture ) { |
1874 | er = remote->rawIncidences(); | 1876 | er = remote->rawIncidences(); |
1875 | remRem = er.count(); | 1877 | remRem = er.count(); |
1876 | inR = er.first(); | 1878 | inR = er.first(); |
1877 | QDateTime dt; | 1879 | QDateTime dt; |
1878 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1880 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1879 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1881 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1880 | while ( inR ) { | 1882 | while ( inR ) { |
1881 | if ( inR->typeID() == todoID ) { | 1883 | if ( inR->typeID() == todoID ) { |
1882 | Todo * t = (Todo*)inR; | 1884 | Todo * t = (Todo*)inR; |
1883 | if ( t->hasDueDate() ) | 1885 | if ( t->hasDueDate() ) |
1884 | dt = t->dtDue(); | 1886 | dt = t->dtDue(); |
1885 | else | 1887 | else |
1886 | dt = cur.addSecs( 62 ); | 1888 | dt = cur.addSecs( 62 ); |
1887 | } | 1889 | } |
1888 | else if (inR->typeID() == eventID ) { | 1890 | else if (inR->typeID() == eventID ) { |
1889 | bool ok; | 1891 | bool ok; |
1890 | dt = inR->getNextOccurence( cur, &ok ); | 1892 | dt = inR->getNextOccurence( cur, &ok ); |
1891 | if ( !ok ) | 1893 | if ( !ok ) |
1892 | dt = cur.addSecs( -62 ); | 1894 | dt = cur.addSecs( -62 ); |
1893 | } | 1895 | } |
1894 | else | 1896 | else |
1895 | dt = inR->dtStart(); | 1897 | dt = inR->dtStart(); |
1896 | if ( dt < cur || dt > end ) { | 1898 | if ( dt < cur || dt > end ) { |
1897 | remote->deleteIncidence( inR ); | 1899 | remote->deleteIncidence( inR ); |
1898 | ++delFut; | 1900 | ++delFut; |
1899 | } | 1901 | } |
1900 | inR = er.next(); | 1902 | inR = er.next(); |
1901 | } | 1903 | } |
1902 | } | 1904 | } |
1903 | bar.hide(); | 1905 | bar.hide(); |
1904 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1906 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1907 | if ( mMultiResourceSync ) { | ||
1908 | remote->removeSyncInfo( "" ); //all | ||
1909 | |||
1910 | } else { | ||
1905 | eventLSync->setReadOnly( false ); | 1911 | eventLSync->setReadOnly( false ); |
1906 | eventLSync->setDtStart( mLastCalendarSync ); | 1912 | eventLSync->setDtStart( mLastCalendarSync ); |
1907 | eventRSync->setDtStart( mLastCalendarSync ); | 1913 | eventRSync->setDtStart( mLastCalendarSync ); |
1908 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1914 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1909 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1915 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1910 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1916 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1911 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1917 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1912 | eventLSync->setReadOnly( true ); | 1918 | eventLSync->setReadOnly( true ); |
1919 | } | ||
1913 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1920 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1914 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... | 1921 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... |
1915 | remote->addEvent( eventRSync ); | 1922 | remote->addEvent( eventRSync ); |
1916 | else | 1923 | else |
1917 | delete eventRSync; | 1924 | delete eventRSync; |
1918 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1925 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1919 | QString mes; | 1926 | QString mes; |
1920 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); | 1927 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); |
1921 | QString delmess; | 1928 | QString delmess; |
1922 | if ( delFut ) { | 1929 | if ( delFut ) { |
1923 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); | 1930 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1924 | mes += delmess; | 1931 | mes += delmess; |
1925 | } | 1932 | } |
1926 | mes = i18n("Local calendar changed!\n") +mes; | 1933 | mes = i18n("Local calendar changed!\n") +mes; |
1927 | mCalendar->checkAlarmForIncidence( 0, true ); | 1934 | mCalendar->checkAlarmForIncidence( 0, true ); |
1928 | qDebug( mes ); | 1935 | qDebug( mes ); |
1929 | if ( mSyncManager->mShowSyncSummary ) { | 1936 | if ( mSyncManager->mShowSyncSummary ) { |
1930 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1937 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1931 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1938 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1932 | qDebug("KO: WB cancelled "); | 1939 | qDebug("KO: WB cancelled "); |
1933 | mSyncManager->mWriteBackFile = false; | 1940 | mSyncManager->mWriteBackFile = false; |
1934 | return syncOK; | 1941 | return syncOK; |
1935 | } | 1942 | } |
1936 | } | 1943 | } |
1937 | return syncOK; | 1944 | return syncOK; |
1938 | } | 1945 | } |
1939 | 1946 | ||
1940 | void CalendarView::setSyncDevice( QString s ) | 1947 | void CalendarView::setSyncDevice( QString s ) |
1941 | { | 1948 | { |
1942 | mCurrentSyncDevice= s; | 1949 | mCurrentSyncDevice= s; |
1943 | } | 1950 | } |
1944 | void CalendarView::setSyncName( QString s ) | 1951 | void CalendarView::setSyncName( QString s ) |
1945 | { | 1952 | { |
1946 | mCurrentSyncName= s; | 1953 | mCurrentSyncName= s; |
@@ -2406,64 +2413,90 @@ bool CalendarView::openCalendar(QString filename, bool merge) | |||
2406 | } | 2413 | } |
2407 | return true; | 2414 | return true; |
2408 | } else { | 2415 | } else { |
2409 | // while failing to load, the calendar object could | 2416 | // while failing to load, the calendar object could |
2410 | // have become partially populated. Clear it out. | 2417 | // have become partially populated. Clear it out. |
2411 | if ( !merge ) { | 2418 | if ( !merge ) { |
2412 | mCalendar->close(); | 2419 | mCalendar->close(); |
2413 | mViewManager->setDocumentId( filename ); | 2420 | mViewManager->setDocumentId( filename ); |
2414 | mDialogManager->setDocumentId( filename ); | 2421 | mDialogManager->setDocumentId( filename ); |
2415 | mTodoList->setDocumentId( filename ); | 2422 | mTodoList->setDocumentId( filename ); |
2416 | } | 2423 | } |
2417 | 2424 | ||
2418 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 2425 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
2419 | 2426 | ||
2420 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 2427 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
2421 | globalFlagBlockAgenda = 2; | 2428 | globalFlagBlockAgenda = 2; |
2422 | mCalendar->reInitAlarmSettings(); | 2429 | mCalendar->reInitAlarmSettings(); |
2423 | setSyncEventsReadOnly(); | 2430 | setSyncEventsReadOnly(); |
2424 | updateUnmanagedViews(); | 2431 | updateUnmanagedViews(); |
2425 | updateView(); | 2432 | updateView(); |
2426 | } | 2433 | } |
2427 | return false; | 2434 | return false; |
2428 | } | 2435 | } |
2429 | void CalendarView::mergeFile( QString fn ) | 2436 | void CalendarView::mergeFile( QString fn ) |
2430 | { | 2437 | { |
2431 | clearAllViews(); | 2438 | clearAllViews(); |
2432 | mCalendar->mergeCalendarFile( fn ); | 2439 | mCalendar->mergeCalendarFile( fn ); |
2433 | mCalendar->reInitAlarmSettings(); | 2440 | mCalendar->reInitAlarmSettings(); |
2434 | setSyncEventsReadOnly(); | 2441 | setSyncEventsReadOnly(); |
2435 | updateUnmanagedViews(); | 2442 | updateUnmanagedViews(); |
2436 | updateView(); | 2443 | updateView(); |
2437 | } | 2444 | } |
2445 | void CalendarView::mergeFileResource( QString fn ,QString resource ) | ||
2446 | { | ||
2447 | |||
2448 | if ( resource == "ALL" ) { | ||
2449 | mergeFile( fn ); | ||
2450 | return; | ||
2451 | } | ||
2452 | |||
2453 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); | ||
2454 | if ( !exclusiveResource ) { | ||
2455 | qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); | ||
2456 | return; | ||
2457 | } | ||
2458 | clearAllViews(); | ||
2459 | mCalendar->setCalendarRemove( exclusiveResource ); | ||
2460 | int def = mCalendar->defaultCalendar(); | ||
2461 | mCalendar->setDefaultCalendar(exclusiveResource); | ||
2462 | if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { | ||
2463 | qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); | ||
2464 | } | ||
2465 | mCalendar->setDefaultCalendar( def ); | ||
2466 | mCalendar->reInitAlarmSettings(); | ||
2467 | setSyncEventsReadOnly(); | ||
2468 | updateUnmanagedViews(); | ||
2469 | updateView(); | ||
2470 | } | ||
2438 | void CalendarView::showOpenError() | 2471 | void CalendarView::showOpenError() |
2439 | { | 2472 | { |
2440 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 2473 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
2441 | } | 2474 | } |
2442 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 2475 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
2443 | { | 2476 | { |
2444 | loadedFileVersion = dt; | 2477 | loadedFileVersion = dt; |
2445 | } | 2478 | } |
2446 | bool CalendarView::checkFileChanged(QString fn) | 2479 | bool CalendarView::checkFileChanged(QString fn) |
2447 | { | 2480 | { |
2448 | QFileInfo finf ( fn ); | 2481 | QFileInfo finf ( fn ); |
2449 | if ( !finf.exists() ) | 2482 | if ( !finf.exists() ) |
2450 | return true; | 2483 | return true; |
2451 | QDateTime dt = finf.lastModified (); | 2484 | QDateTime dt = finf.lastModified (); |
2452 | if ( dt <= loadedFileVersion ) | 2485 | if ( dt <= loadedFileVersion ) |
2453 | return false; | 2486 | return false; |
2454 | return true; | 2487 | return true; |
2455 | 2488 | ||
2456 | } | 2489 | } |
2457 | void CalendarView::watchSavedFile() | 2490 | void CalendarView::watchSavedFile() |
2458 | { | 2491 | { |
2459 | QFileInfo finf ( MainWindow::defaultFileName()); | 2492 | QFileInfo finf ( MainWindow::defaultFileName()); |
2460 | if ( !finf.exists() ) | 2493 | if ( !finf.exists() ) |
2461 | return; | 2494 | return; |
2462 | QDateTime dt = finf.lastModified (); | 2495 | QDateTime dt = finf.lastModified (); |
2463 | if ( dt < loadedFileVersion ) { | 2496 | if ( dt < loadedFileVersion ) { |
2464 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 2497 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
2465 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 2498 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
2466 | return; | 2499 | return; |
2467 | } | 2500 | } |
2468 | loadedFileVersion = dt; | 2501 | loadedFileVersion = dt; |
2469 | } | 2502 | } |
@@ -2493,100 +2526,118 @@ bool CalendarView::checkAllFileVersions() | |||
2493 | } | 2526 | } |
2494 | } | 2527 | } |
2495 | cal = calendars.next(); | 2528 | cal = calendars.next(); |
2496 | } | 2529 | } |
2497 | loadedFileVersion = storeTemp; | 2530 | loadedFileVersion = storeTemp; |
2498 | return true; | 2531 | return true; |
2499 | } | 2532 | } |
2500 | bool CalendarView::checkFileVersion(QString fn) | 2533 | bool CalendarView::checkFileVersion(QString fn) |
2501 | { | 2534 | { |
2502 | QFileInfo finf ( fn ); | 2535 | QFileInfo finf ( fn ); |
2503 | if ( !finf.exists() ) | 2536 | if ( !finf.exists() ) |
2504 | return true; | 2537 | return true; |
2505 | QDateTime dt = finf.lastModified (); | 2538 | QDateTime dt = finf.lastModified (); |
2506 | //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); | 2539 | //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); |
2507 | //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); | 2540 | //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); |
2508 | if ( dt <= loadedFileVersion ) | 2541 | if ( dt <= loadedFileVersion ) |
2509 | return true; | 2542 | return true; |
2510 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , | 2543 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , |
2511 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 2544 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
2512 | i18n("Sync+save")); | 2545 | i18n("Sync+save")); |
2513 | 2546 | ||
2514 | if ( km == KMessageBox::Cancel ) | 2547 | if ( km == KMessageBox::Cancel ) |
2515 | return false; | 2548 | return false; |
2516 | if ( km == KMessageBox::Yes ) | 2549 | if ( km == KMessageBox::Yes ) |
2517 | return true; | 2550 | return true; |
2518 | 2551 | ||
2519 | setSyncDevice("deleteaftersync" ); | 2552 | setSyncDevice("deleteaftersync" ); |
2520 | mSyncManager->mAskForPreferences = true; | 2553 | mSyncManager->mAskForPreferences = true; |
2521 | mSyncManager->mSyncAlgoPrefs = 3; | 2554 | mSyncManager->mSyncAlgoPrefs = 3; |
2522 | mSyncManager->mWriteBackFile = false; | 2555 | mSyncManager->mWriteBackFile = false; |
2523 | mSyncManager->mWriteBackExistingOnly = false; | 2556 | mSyncManager->mWriteBackExistingOnly = false; |
2524 | mSyncManager->mShowSyncSummary = false; | 2557 | mSyncManager->mShowSyncSummary = false; |
2558 | mMultiResourceSync = false; | ||
2525 | syncCalendar( fn, 3 ); | 2559 | syncCalendar( fn, 3 ); |
2526 | Event * e = getLastSyncEvent(); | 2560 | Event * e = getLastSyncEvent(); |
2527 | if ( e ) | 2561 | if ( e ) |
2528 | mCalendar->deleteEvent( e ); | 2562 | mCalendar->deleteEvent( e ); |
2529 | return true; | 2563 | return true; |
2530 | } | 2564 | } |
2531 | bool CalendarView::saveCalendars() | 2565 | bool CalendarView::saveCalendars() |
2532 | { | 2566 | { |
2533 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2567 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2534 | KopiCalendarFile * cal = calendars.first(); | 2568 | KopiCalendarFile * cal = calendars.first(); |
2535 | mCalendar->setDefaultCalendar( 1 ); | 2569 | mCalendar->setDefaultCalendar( 1 ); |
2536 | mCalendar->setDefaultCalendarEnabledOnly(); | 2570 | mCalendar->setDefaultCalendarEnabledOnly(); |
2537 | QString saveError; | 2571 | QString saveError; |
2538 | if ( !saveCalendar( MainWindow::defaultFileName() ) ) | 2572 | if ( !saveCalendar( MainWindow::defaultFileName() ) ) |
2539 | saveError = cal->mName +"\n"; | 2573 | saveError = cal->mName +"\n"; |
2540 | cal = calendars.next(); | 2574 | cal = calendars.next(); |
2541 | while ( cal ) { | 2575 | while ( cal ) { |
2542 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2576 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2543 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2577 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2544 | mCalendar->setDefaultCalendarEnabledOnly(); | 2578 | mCalendar->setDefaultCalendarEnabledOnly(); |
2545 | if ( saveCalendar( cal->mFileName ) ) | 2579 | if ( saveCalendar( cal->mFileName ) ) |
2546 | cal->mLoadDt = QDateTime::currentDateTime(); | 2580 | cal->mLoadDt = QDateTime::currentDateTime(); |
2547 | else | 2581 | else |
2548 | saveError += cal->mName + "\n"; | 2582 | saveError += cal->mName + "\n"; |
2549 | } | 2583 | } |
2550 | cal = calendars.next(); | 2584 | cal = calendars.next(); |
2551 | } | 2585 | } |
2552 | restoreCalendarSettings(); | 2586 | restoreCalendarSettings(); |
2553 | //saveError = "test error"; | 2587 | //saveError = "test error"; |
2554 | if ( !saveError.isEmpty() ) { | 2588 | if ( !saveError.isEmpty() ) { |
2555 | saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; | 2589 | saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; |
2556 | KMessageBox::error(this, saveError, i18n("Error saving data")); | 2590 | KMessageBox::error(this, saveError, i18n("Error saving data")); |
2557 | return false; | 2591 | return false; |
2558 | } | 2592 | } |
2559 | return true; | 2593 | return true; |
2560 | } | 2594 | } |
2595 | bool CalendarView::saveCalendarResource(QString filename, QString resource) | ||
2596 | { | ||
2597 | if ( resource == "ALL" ) | ||
2598 | return saveCalendar( filename ); | ||
2599 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); | ||
2600 | if ( !exclusiveResource ) { | ||
2601 | qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() ); | ||
2602 | return false; | ||
2603 | } | ||
2604 | mCalendar->setDefaultCalendar( exclusiveResource ); | ||
2605 | mCalendar->setDefaultCalendarEnabledOnly(); | ||
2606 | mCalendar->setSyncEventsEnabled(); | ||
2607 | bool res = saveCalendar( filename ); | ||
2608 | restoreCalendarSettings(); | ||
2609 | return res; | ||
2610 | |||
2611 | } | ||
2561 | bool CalendarView::saveCalendar( QString filename ) | 2612 | bool CalendarView::saveCalendar( QString filename ) |
2562 | { | 2613 | { |
2563 | 2614 | ||
2564 | // Store back all unsaved data into calendar object | 2615 | // Store back all unsaved data into calendar object |
2565 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 2616 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
2566 | if ( mViewManager->currentView() ) | 2617 | if ( mViewManager->currentView() ) |
2567 | mViewManager->currentView()->flushView(); | 2618 | mViewManager->currentView()->flushView(); |
2568 | 2619 | ||
2569 | 2620 | ||
2570 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); | 2621 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); |
2571 | mStorage->setSaveFormat( new ICalFormat() ); | 2622 | mStorage->setSaveFormat( new ICalFormat() ); |
2572 | mStorage->setFileName( filename ); | 2623 | mStorage->setFileName( filename ); |
2573 | bool success; | 2624 | bool success; |
2574 | success = mStorage->save(); | 2625 | success = mStorage->save(); |
2575 | if ( !success ) { | 2626 | if ( !success ) { |
2576 | return false; | 2627 | return false; |
2577 | } | 2628 | } |
2578 | if ( filename == MainWindow::defaultFileName() ) { | 2629 | if ( filename == MainWindow::defaultFileName() ) { |
2579 | setLoadedFileVersion( lfv ); | 2630 | setLoadedFileVersion( lfv ); |
2580 | watchSavedFile(); | 2631 | watchSavedFile(); |
2581 | } | 2632 | } |
2582 | return true; | 2633 | return true; |
2583 | } | 2634 | } |
2584 | 2635 | ||
2585 | void CalendarView::closeCalendar() | 2636 | void CalendarView::closeCalendar() |
2586 | { | 2637 | { |
2587 | 2638 | ||
2588 | // child windows no longer valid | 2639 | // child windows no longer valid |
2589 | clearAllViews(); | 2640 | clearAllViews(); |
2590 | emit closingDown(); | 2641 | emit closingDown(); |
2591 | 2642 | ||
2592 | mCalendar->close(); | 2643 | mCalendar->close(); |
@@ -5003,65 +5054,69 @@ void CalendarView::purgeCompleted() | |||
5003 | i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); | 5054 | i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); |
5004 | 5055 | ||
5005 | if (result == KMessageBox::Continue) { | 5056 | if (result == KMessageBox::Continue) { |
5006 | 5057 | ||
5007 | QPtrList<Todo> todoCal; | 5058 | QPtrList<Todo> todoCal; |
5008 | QPtrList<Todo> rootTodos; | 5059 | QPtrList<Todo> rootTodos; |
5009 | //QPtrList<Incidence> rel; | 5060 | //QPtrList<Incidence> rel; |
5010 | Todo *aTodo; | 5061 | Todo *aTodo; |
5011 | todoCal = calendar()->todos(); | 5062 | todoCal = calendar()->todos(); |
5012 | for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { | 5063 | for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { |
5013 | if ( !aTodo->relatedTo() ) | 5064 | if ( !aTodo->relatedTo() ) |
5014 | rootTodos.append( aTodo ); | 5065 | rootTodos.append( aTodo ); |
5015 | } | 5066 | } |
5016 | for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { | 5067 | for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { |
5017 | removeCompletedSubTodos( aTodo ); | 5068 | removeCompletedSubTodos( aTodo ); |
5018 | } | 5069 | } |
5019 | 5070 | ||
5020 | updateView(); | 5071 | updateView(); |
5021 | } | 5072 | } |
5022 | } | 5073 | } |
5023 | 5074 | ||
5024 | void CalendarView::slotCalendarChanged() | 5075 | void CalendarView::slotCalendarChanged() |
5025 | { | 5076 | { |
5026 | ; | 5077 | ; |
5027 | } | 5078 | } |
5028 | 5079 | ||
5029 | void CalendarView::keyPressEvent ( QKeyEvent *e) | 5080 | void CalendarView::keyPressEvent ( QKeyEvent *e) |
5030 | { | 5081 | { |
5031 | //qDebug("CalendarView::keyPressEvent "); | 5082 | //qDebug("CalendarView::keyPressEvent "); |
5032 | e->ignore(); | 5083 | e->ignore(); |
5033 | } | 5084 | } |
5034 | 5085 | ||
5086 | void CalendarView::multiResourceSyncStart( bool start ) | ||
5087 | { | ||
5088 | mMultiResourceSync = start; | ||
5035 | 5089 | ||
5090 | } | ||
5036 | bool CalendarView::sync(KSyncManager* manager, QString filename, int mode,QString resource) | 5091 | bool CalendarView::sync(KSyncManager* manager, QString filename, int mode,QString resource) |
5037 | { | 5092 | { |
5038 | 5093 | ||
5039 | if ( manager != mSyncManager) | 5094 | if ( manager != mSyncManager) |
5040 | qDebug("KO: Internal error-1. SyncManager mismatch "); | 5095 | qDebug("KO: Internal error-1. SyncManager mismatch "); |
5041 | if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { | 5096 | if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { |
5042 | qDebug("KO: SyncKDE request detected!"); | 5097 | qDebug("KO: SyncKDE request detected!"); |
5043 | } | 5098 | } |
5044 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); | 5099 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); |
5045 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); | 5100 | mCurrentSyncName = mSyncManager->getCurrentSyncName(); |
5046 | if ( !resource.isEmpty() ) { | 5101 | if ( !resource.isEmpty() ) { |
5047 | int exclusiveSyncResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); | 5102 | int exclusiveSyncResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); |
5048 | qDebug( "KO: Sync request for resource: %s", resource.latin1() ); | 5103 | qDebug( "KO: Sync request for resource: %s", resource.latin1() ); |
5049 | 5104 | ||
5050 | if ( !exclusiveSyncResource ) { | 5105 | if ( !exclusiveSyncResource ) { |
5051 | qDebug( "KO: Requested sync resource not found: %s", resource.latin1() ); | 5106 | qDebug( "KO: Requested sync resource not found: %s", resource.latin1() ); |
5052 | return false; | 5107 | return false; |
5053 | } | 5108 | } |
5054 | mCalendar->setDefaultCalendar( exclusiveSyncResource ); | 5109 | mCalendar->setDefaultCalendar( exclusiveSyncResource ); |
5055 | mCalendar->setDefaultCalendarEnabledOnly(); | 5110 | mCalendar->setDefaultCalendarEnabledOnly(); |
5056 | } | 5111 | } |
5057 | bool result = syncCalendar( filename, mode ); | 5112 | bool result = syncCalendar( filename, mode ); |
5058 | if ( !resource.isEmpty() ) | 5113 | if ( !resource.isEmpty() ) |
5059 | restoreCalendarSettings(); | 5114 | restoreCalendarSettings(); |
5060 | return result; | 5115 | return result; |
5061 | } | 5116 | } |
5062 | bool CalendarView::syncExternal(KSyncManager* manager, QString resource) | 5117 | bool CalendarView::syncExternal(KSyncManager* manager, QString resource) |
5063 | { | 5118 | { |
5064 | //mSyncManager = manager; | 5119 | //mSyncManager = manager; |
5065 | if ( manager != mSyncManager) | 5120 | if ( manager != mSyncManager) |
5066 | qDebug("KO: Internal error-2. SyncManager mismatch "); | 5121 | qDebug("KO: Internal error-2. SyncManager mismatch "); |
5067 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); | 5122 | mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); |