author | zautrix <zautrix> | 2005-11-28 01:23:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 01:23:02 (UTC) |
commit | e08811c2246f63b2b63f9db6b65701344460f3d7 (patch) (unidiff) | |
tree | d450f486a9472d80eb86f605237b828a0e7ffae6 | |
parent | 854d4a0c686962cd73ac7418b5fbf4b2d73adab7 (diff) | |
download | kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.zip kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.gz kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.bz2 |
ync
-rw-r--r-- | korganizer/calendarview.cpp | 17 | ||||
-rw-r--r-- | libkcal/calendar.cpp | 9 | ||||
-rw-r--r-- | libkcal/calendar.h | 3 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 81 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 3 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
7 files changed, 99 insertions, 21 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 8d024c1..1800cf2 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1591,32 +1591,33 @@ void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* t | |||
1591 | des += pref+ id + ","; | 1591 | des += pref+ id + ","; |
1592 | eve->setReadOnly( false ); | 1592 | eve->setReadOnly( false ); |
1593 | eve->setDescription( des ); | 1593 | eve->setDescription( des ); |
1594 | //qDebug("setdes %s ", des.latin1()); | 1594 | //qDebug("setdes %s ", des.latin1()); |
1595 | eve->setReadOnly( true ); | 1595 | eve->setReadOnly( true ); |
1596 | } | 1596 | } |
1597 | eve = lastSync.next(); | 1597 | eve = lastSync.next(); |
1598 | } | 1598 | } |
1599 | 1599 | ||
1600 | } | 1600 | } |
1601 | void CalendarView::checkExternalId( Incidence * inc ) | 1601 | void CalendarView::checkExternalId( Incidence * inc ) |
1602 | { | 1602 | { |
1603 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1603 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1604 | checkExternSyncEvent( lastSync, inc ); | 1604 | checkExternSyncEvent( lastSync, inc ); |
1605 | 1605 | ||
1606 | } | 1606 | } |
1607 | // SSSSSSSSSSSSSSSSSSSSSS | ||
1607 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1608 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1608 | { | 1609 | { |
1609 | 1610 | ||
1610 | bool syncOK = true; | 1611 | bool syncOK = true; |
1611 | int addedEvent = 0; | 1612 | int addedEvent = 0; |
1612 | int addedEventR = 0; | 1613 | int addedEventR = 0; |
1613 | int deletedEventR = 0; | 1614 | int deletedEventR = 0; |
1614 | int deletedEventL = 0; | 1615 | int deletedEventL = 0; |
1615 | int changedLocal = 0; | 1616 | int changedLocal = 0; |
1616 | int changedRemote = 0; | 1617 | int changedRemote = 0; |
1617 | int filteredIN = 0; | 1618 | int filteredIN = 0; |
1618 | int filteredOUT = 0; | 1619 | int filteredOUT = 0; |
1619 | //QPtrList<Event> el = local->rawEvents(); | 1620 | //QPtrList<Event> el = local->rawEvents(); |
1620 | Event* eventR; | 1621 | Event* eventR; |
1621 | QString uid; | 1622 | QString uid; |
1622 | int take; | 1623 | int take; |
@@ -1710,73 +1711,87 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1710 | bar.show(); | 1711 | bar.show(); |
1711 | int modulo = (er.count()/10)+1; | 1712 | int modulo = (er.count()/10)+1; |
1712 | int incCounter = 0; | 1713 | int incCounter = 0; |
1713 | while ( inR ) { | 1714 | while ( inR ) { |
1714 | if ( ! bar.isVisible() ) | 1715 | if ( ! bar.isVisible() ) |
1715 | return false; | 1716 | return false; |
1716 | if ( incCounter % modulo == 0 ) | 1717 | if ( incCounter % modulo == 0 ) |
1717 | bar.setProgress( incCounter ); | 1718 | bar.setProgress( incCounter ); |
1718 | ++incCounter; | 1719 | ++incCounter; |
1719 | uid = inR->uid(); | 1720 | uid = inR->uid(); |
1720 | bool skipIncidence = false; | 1721 | bool skipIncidence = false; |
1721 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1722 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1722 | skipIncidence = true; | 1723 | skipIncidence = true; |
1723 | QString idS; | 1724 | QString idS; |
1724 | qApp->processEvents(); | 1725 | qApp->processEvents(); |
1725 | if ( !skipIncidence ) { | 1726 | if ( !skipIncidence ) { |
1726 | inL = local->incidenceForUid( uid , false , true ); | 1727 | int hasCalId = 0; |
1728 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | ||
1729 | if ( hasCalId && !inL ) | ||
1730 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | ||
1731 | else | ||
1732 | hasCalId = 0; | ||
1727 | if ( inL ) { // maybe conflict - same uid in both calendars | 1733 | if ( inL ) { // maybe conflict - same uid in both calendars |
1734 | if ( hasCalId ) | ||
1735 | qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1()); | ||
1728 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1736 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1729 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1737 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1730 | if ( take == 3 ) | 1738 | if ( take == 3 ) |
1731 | return false; | 1739 | return false; |
1732 | if ( take == 1 ) {// take local ********************** | 1740 | if ( take == 1 ) {// take local ********************** |
1733 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1741 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1734 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1742 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1735 | else | 1743 | else |
1736 | idS = inR->IDStr(); | 1744 | idS = inR->IDStr(); |
1737 | int calID = inR->calID(); | 1745 | int calID = inR->calID(); |
1738 | remote->deleteIncidence( inR ); | 1746 | remote->deleteIncidence( inR ); |
1739 | inR = inL->clone(); | 1747 | inR = inL->clone(); |
1740 | inR->setCalID_block( calID ); | 1748 | inR->setCalID_block( calID ); |
1741 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1749 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1742 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1750 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1743 | inR->setIDStr( idS ); | 1751 | inR->setIDStr( idS ); |
1744 | remote->addIncidence( inR ); | 1752 | remote->addIncidence( inR ); |
1745 | if ( mSyncManager->syncWithDesktop() ) | 1753 | if ( mSyncManager->syncWithDesktop() ) |
1746 | inR->setPilotId( 2 ); | 1754 | inR->setPilotId( 2 ); |
1747 | ++changedRemote; | 1755 | ++changedRemote; |
1748 | } else {// take remote ********************** | 1756 | } else {// take remote ********************** |
1749 | if ( !inL->isReadOnly() ) { | 1757 | if ( !inL->isReadOnly() ) { |
1750 | idS = inL->IDStr(); | 1758 | idS = inL->IDStr(); |
1751 | int pid = inL->pilotId(); | 1759 | int pid = inL->pilotId(); |
1752 | int calID = inL->calID(); | 1760 | int calID = inL->calID(); |
1761 | if ( hasCalId ) | ||
1762 | calID = hasCalId; | ||
1753 | local->deleteIncidence( inL ); | 1763 | local->deleteIncidence( inL ); |
1754 | inL = inR->clone(); | 1764 | inL = inR->clone(); |
1755 | inL->setCalID_block( calID ); | 1765 | inL->setCalID_block( calID ); |
1756 | if ( mSyncManager->syncWithDesktop() ) | 1766 | if ( mSyncManager->syncWithDesktop() ) |
1757 | inL->setPilotId( pid ); | 1767 | inL->setPilotId( pid ); |
1758 | inL->setIDStr( idS ); | 1768 | inL->setIDStr( idS ); |
1759 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1769 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1760 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1770 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1761 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1771 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1762 | } | 1772 | } |
1763 | local->addIncidence( inL ); | 1773 | local->addIncidence( inL ); |
1764 | ++changedLocal; | 1774 | ++changedLocal; |
1765 | } | 1775 | } |
1766 | } | 1776 | } |
1777 | } else { | ||
1778 | // take == 0; events equal | ||
1779 | if ( hasCalId ) | ||
1780 | qDebug("EV EQUALLLL **************************** "); | ||
1781 | |||
1767 | } | 1782 | } |
1768 | } else { // no conflict ********** add or delete remote | 1783 | } else { // no conflict ********** add or delete remote |
1769 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1784 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1770 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1785 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1771 | QString des = eventLSync->description(); | 1786 | QString des = eventLSync->description(); |
1772 | QString pref = "e"; | 1787 | QString pref = "e"; |
1773 | if ( inR->typeID() == todoID ) | 1788 | if ( inR->typeID() == todoID ) |
1774 | pref = "t"; | 1789 | pref = "t"; |
1775 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1790 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1776 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1791 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1777 | //remote->deleteIncidence( inR ); | 1792 | //remote->deleteIncidence( inR ); |
1778 | ++deletedEventR; | 1793 | ++deletedEventR; |
1779 | } else { | 1794 | } else { |
1780 | inR->setLastModified( modifiedCalendar ); | 1795 | inR->setLastModified( modifiedCalendar ); |
1781 | inL = inR->clone(); | 1796 | inL = inR->clone(); |
1782 | inL->setIDStr( ":" ); | 1797 | inL->setIDStr( ":" ); |
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 8535191..1350f6d 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,26 +1,25 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | |||
11 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 13 | Library General Public License for more details. |
15 | 14 | ||
16 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
20 | */ | 19 | */ |
21 | 20 | ||
22 | #include <stdlib.h> | 21 | #include <stdlib.h> |
23 | #include <time.h> | 22 | #include <time.h> |
24 | 23 | ||
25 | #include <kdebug.h> | 24 | #include <kdebug.h> |
26 | #include <kglobal.h> | 25 | #include <kglobal.h> |
@@ -407,51 +406,55 @@ Incidence* Calendar::incidence( const QString& uid ) | |||
407 | 406 | ||
408 | return 0; | 407 | return 0; |
409 | } | 408 | } |
410 | 409 | ||
411 | QPtrList<Todo> Calendar::todos() | 410 | QPtrList<Todo> Calendar::todos() |
412 | { | 411 | { |
413 | QPtrList<Todo> tl = rawTodos(); | 412 | QPtrList<Todo> tl = rawTodos(); |
414 | mFilter->apply( &tl ); | 413 | mFilter->apply( &tl ); |
415 | return tl; | 414 | return tl; |
416 | } | 415 | } |
417 | 416 | ||
418 | // When this is called, the todo have already been added to the calendar. | 417 | // When this is called, the todo have already been added to the calendar. |
419 | // This method is only about linking related todos | 418 | // This method is only about linking related todos |
420 | void Calendar::setupRelations( Incidence *incidence ) | 419 | void Calendar::setupRelations( Incidence *incidence ) |
421 | { | 420 | { |
422 | QString uid = incidence->uid(); | 421 | QString uid = incidence->uid(); |
423 | //qDebug("Calendar::setupRelations "); | 422 | //qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); |
424 | // First, go over the list of orphans and see if this is their parent | 423 | // First, go over the list of orphans and see if this is their parent |
425 | while( Incidence* i = mOrphans[ uid ] ) { | 424 | while( Incidence* i = mOrphans[ uid ] ) { |
426 | mOrphans.remove( uid ); | 425 | mOrphans.remove( uid ); |
427 | i->setRelatedTo( incidence ); | 426 | i->setRelatedTo( incidence ); |
427 | //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); | ||
428 | incidence->addRelation( i ); | 428 | incidence->addRelation( i ); |
429 | mOrphanUids.remove( i->uid() ); | 429 | mOrphanUids.remove( i->uid() ); |
430 | } | 430 | } |
431 | 431 | ||
432 | // Now see about this incidences parent | 432 | // Now see about this incidences parent |
433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
434 | // This incidence has a uid it is related to, but is not registered to it yet | 434 | // This incidence has a uid it is related to, but is not registered to it yet |
435 | // Try to find it | 435 | // Try to find it |
436 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 436 | //qDebug("Test parent for %s", incidence->summary().latin1()); |
437 | Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); | ||
437 | if( parent ) { | 438 | if( parent ) { |
438 | // Found it | 439 | // Found it |
440 | // qDebug("parent found for for %s", incidence->summary().latin1()); | ||
439 | incidence->setRelatedTo( parent ); | 441 | incidence->setRelatedTo( parent ); |
440 | parent->addRelation( incidence ); | 442 | parent->addRelation( incidence ); |
441 | } else { | 443 | } else { |
444 | // qDebug("NO parent found for for %s", incidence->summary().latin1()); | ||
442 | // Not found, put this in the mOrphans list | 445 | // Not found, put this in the mOrphans list |
443 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 446 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
444 | mOrphanUids.insert( incidence->uid(), incidence ); | 447 | mOrphanUids.insert( incidence->uid(), incidence ); |
445 | } | 448 | } |
446 | } | 449 | } |
447 | } | 450 | } |
448 | 451 | ||
449 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 452 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
450 | void Calendar::removeRelations( Incidence *incidence ) | 453 | void Calendar::removeRelations( Incidence *incidence ) |
451 | { | 454 | { |
452 | // qDebug("Calendar::removeRelations "); | 455 | // qDebug("Calendar::removeRelations "); |
453 | QString uid = incidence->uid(); | 456 | QString uid = incidence->uid(); |
454 | 457 | ||
455 | QPtrList<Incidence> relations = incidence->relations(); | 458 | QPtrList<Incidence> relations = incidence->relations(); |
456 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 459 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
457 | if( !mOrphanUids.find( i->uid() ) ) { | 460 | if( !mOrphanUids.find( i->uid() ) ) { |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index f301768..fbc40ad 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -64,33 +64,34 @@ class Calendar : public QObject, public CustomProperties, | |||
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual bool mergeCalendarFile( QString name ) = 0; | 79 | virtual bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0; | 80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ,int * isDup = 0 ) = 0; |
81 | virtual Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0) = 0; | ||
81 | virtual void setSyncEventsReadOnly() = 0; | 82 | virtual void setSyncEventsReadOnly() = 0; |
82 | virtual void setSyncEventsEnabled() = 0; | 83 | virtual void setSyncEventsEnabled() = 0; |
83 | virtual void stopAllTodos() = 0; | 84 | virtual void stopAllTodos() = 0; |
84 | virtual void clearUndo( Incidence * newUndo ); | 85 | virtual void clearUndo( Incidence * newUndo ); |
85 | 86 | ||
86 | /** | 87 | /** |
87 | Sync changes in memory to persistant storage. | 88 | Sync changes in memory to persistant storage. |
88 | */ | 89 | */ |
89 | virtual void save() = 0; | 90 | virtual void save() = 0; |
90 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 91 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
91 | virtual void removeSyncInfo( QString syncProfile) = 0; | 92 | virtual void removeSyncInfo( QString syncProfile) = 0; |
92 | virtual bool isSaving() { return false; } | 93 | virtual bool isSaving() { return false; } |
93 | 94 | ||
94 | /** | 95 | /** |
95 | Return the owner of the calendar's full name. | 96 | Return the owner of the calendar's full name. |
96 | */ | 97 | */ |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index ad8ace3..980663f 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -66,78 +66,129 @@ void CalendarLocal::init() | |||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | 68 | registerObserver( 0 ); |
69 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
70 | close(); | 70 | close(); |
71 | } | 71 | } |
72 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
73 | { | 73 | { |
74 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
75 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
76 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
77 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) | 83 | Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) |
84 | { | 84 | { |
85 | |||
86 | int calID = 0; | ||
87 | if ( isDup && *isDup > 0 ) | ||
88 | calID = *isDup; | ||
85 | Todo *todo;; | 89 | Todo *todo;; |
86 | Incidence *retVal = 0; | 90 | Todo *retVal = 0; |
87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 91 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
88 | if ( todo->uid() == uid ) { | 92 | if ( todo->uid() == uid ) { |
89 | if ( enabledOnly ) | 93 | if( calID ) { |
90 | if ( !todo->calEnabled() ) | 94 | if ( todo->calID() != calID ) |
91 | continue; | 95 | continue; |
96 | } | ||
97 | else { | ||
98 | if ( enabledOnly ) { | ||
99 | if ( !todo->calEnabled() ) { | ||
100 | if ( isDup ) | ||
101 | *isDup = todo->calID(); | ||
102 | continue; | ||
103 | } | ||
104 | } | ||
105 | } | ||
92 | if ( doNotCheckDuplicates ) return todo; | 106 | if ( doNotCheckDuplicates ) return todo; |
93 | if ( retVal ) { | 107 | if ( retVal ) { |
94 | if ( retVal->calID() > todo->calID() ) { | 108 | if ( retVal->calID() > todo->calID() ) { |
109 | if ( isDup ) | ||
110 | *isDup = retVal->calID(); | ||
95 | retVal = todo; | 111 | retVal = todo; |
96 | } | 112 | } |
97 | } else { | 113 | } else { |
98 | retVal = todo; | 114 | retVal = todo; |
99 | } | 115 | } |
100 | } | 116 | } |
101 | } | 117 | } |
118 | return retVal; | ||
119 | } | ||
120 | //if ( isDup) and * isDup == 0: store duplicate found cal id in isDup | ||
121 | //if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly | ||
122 | |||
123 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) | ||
124 | { | ||
125 | int calID = 0; | ||
126 | if ( isDup && *isDup > 0 ) | ||
127 | calID = *isDup; | ||
128 | Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); | ||
102 | if ( retVal ) return retVal; | 129 | if ( retVal ) return retVal; |
103 | Event *event; | 130 | Event *event; |
104 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 131 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
105 | if ( event->uid() == uid ) { | 132 | if ( event->uid() == uid ) { |
106 | if ( enabledOnly ) | 133 | if( calID ) { |
107 | if ( !event->calEnabled() ) | 134 | if ( event->calID() != calID ) |
108 | continue; | 135 | continue; |
136 | } | ||
137 | else { | ||
138 | if ( enabledOnly ) { | ||
139 | if ( !event->calEnabled() ) { | ||
140 | if ( isDup ) | ||
141 | *isDup =event->calID() ; | ||
142 | continue; | ||
143 | } | ||
144 | } | ||
145 | } | ||
109 | if ( doNotCheckDuplicates ) return event; | 146 | if ( doNotCheckDuplicates ) return event; |
110 | if ( retVal ) { | 147 | if ( retVal ) { |
111 | if ( retVal->calID() > event->calID() ) { | 148 | if ( retVal->calID() > event->calID() ) { |
149 | if ( isDup ) | ||
150 | *isDup = retVal->calID(); | ||
112 | retVal = event; | 151 | retVal = event; |
113 | } | 152 | } |
114 | } else { | 153 | } else { |
115 | retVal = event; | 154 | retVal = event; |
116 | } | 155 | } |
117 | } | 156 | } |
118 | } | 157 | } |
119 | if ( retVal ) return retVal; | 158 | if ( retVal ) return retVal; |
120 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
121 | if ( it->uid() == uid ) { | 160 | if ( it->uid() == uid ) { |
122 | if ( enabledOnly ) | 161 | if( calID ) { |
123 | if ( !it->calEnabled() ) | 162 | if ( event->calID() != calID ) |
124 | continue; | 163 | continue; |
164 | } | ||
165 | else { | ||
166 | if ( enabledOnly ) { | ||
167 | if ( !it->calEnabled() ) { | ||
168 | if ( isDup ) | ||
169 | *isDup = it->calID(); | ||
170 | continue; | ||
171 | } | ||
172 | } | ||
173 | } | ||
125 | if ( doNotCheckDuplicates ) return it; | 174 | if ( doNotCheckDuplicates ) return it; |
126 | if ( retVal ) { | 175 | if ( retVal ) { |
127 | if ( retVal->calID() > it->calID() ) { | 176 | if ( retVal->calID() > it->calID() ) { |
177 | if ( isDup ) | ||
178 | *isDup = retVal->calID(); | ||
128 | retVal = it; | 179 | retVal = it; |
129 | } | 180 | } |
130 | } else { | 181 | } else { |
131 | retVal = it; | 182 | retVal = it; |
132 | } | 183 | } |
133 | } | 184 | } |
134 | return retVal; | 185 | return retVal; |
135 | } | 186 | } |
136 | 187 | ||
137 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
138 | { | 189 | { |
139 | // 1 look for raw inc in local | 190 | // 1 look for raw inc in local |
140 | // if inc not in remote, delete in local | 191 | // if inc not in remote, delete in local |
141 | // 2 look for raw inc in remote | 192 | // 2 look for raw inc in remote |
142 | // if inc in local, replace it | 193 | // if inc in local, replace it |
143 | // if not in local, add it to default calendar | 194 | // if not in local, add it to default calendar |
@@ -220,37 +271,33 @@ void CalendarLocal::addCalendar( Calendar* cal ) | |||
220 | ev->setCalID_block( 1 ); | 271 | ev->setCalID_block( 1 ); |
221 | } | 272 | } |
222 | ev->unRegisterObserver( cal ); | 273 | ev->unRegisterObserver( cal ); |
223 | ev->registerObserver( this ); | 274 | ev->registerObserver( this ); |
224 | mEventList.append( ev ); | 275 | mEventList.append( ev ); |
225 | ev = EventList.next(); | 276 | ev = EventList.next(); |
226 | } | 277 | } |
227 | for ( ev = el.first(); ev; ev = el.next() ) { | 278 | for ( ev = el.first(); ev; ev = el.next() ) { |
228 | deleteIncidence ( ev ); | 279 | deleteIncidence ( ev ); |
229 | } | 280 | } |
230 | } | 281 | } |
231 | { | 282 | { |
232 | 283 | ||
233 | QPtrList<Todo> TodoList = cal->rawTodos(); | 284 | QPtrList<Todo> TodoList = cal->rawTodos(); |
234 | Todo * ev = TodoList.first(); | 285 | Todo * ev = TodoList.first(); |
235 | while ( ev ) { | 286 | while ( ev ) { |
236 | QString rel = ev->relatedToUid(); | 287 | ev->resetRelatedTo(); |
237 | if ( !rel.isEmpty() ){ | ||
238 | ev->setRelatedTo ( 0 ); | ||
239 | ev->setRelatedToUid( rel ); | ||
240 | } | ||
241 | ev = TodoList.next(); | 288 | ev = TodoList.next(); |
242 | } | 289 | } |
243 | //TodoList = cal->rawTodos(); | 290 | //TodoList = cal->rawTodos(); |
244 | ev = TodoList.first(); | 291 | ev = TodoList.first(); |
245 | while ( ev ) { | 292 | while ( ev ) { |
246 | ev->unRegisterObserver( cal ); | 293 | ev->unRegisterObserver( cal ); |
247 | ev->registerObserver( this ); | 294 | ev->registerObserver( this ); |
248 | mTodoList.append( ev ); | 295 | mTodoList.append( ev ); |
249 | setupRelations( ev ); | 296 | setupRelations( ev ); |
250 | ev = TodoList.next(); | 297 | ev = TodoList.next(); |
251 | } | 298 | } |
252 | } | 299 | } |
253 | { | 300 | { |
254 | QPtrList<Journal> JournalList = cal->journals(); | 301 | QPtrList<Journal> JournalList = cal->journals(); |
255 | Journal * ev = JournalList.first(); | 302 | Journal * ev = JournalList.first(); |
256 | while ( ev ) { | 303 | while ( ev ) { |
@@ -399,39 +446,43 @@ bool CalendarLocal::addTodo( Todo *todo ) | |||
399 | mTodoList.append( todo ); | 446 | mTodoList.append( todo ); |
400 | 447 | ||
401 | todo->registerObserver( this ); | 448 | todo->registerObserver( this ); |
402 | 449 | ||
403 | // Set up subtask relations | 450 | // Set up subtask relations |
404 | setupRelations( todo ); | 451 | setupRelations( todo ); |
405 | 452 | ||
406 | setModified( true ); | 453 | setModified( true ); |
407 | if ( todo->calID() == 0 ) | 454 | if ( todo->calID() == 0 ) |
408 | todo->setCalID_block( mDefaultCalendar ); | 455 | todo->setCalID_block( mDefaultCalendar ); |
409 | todo->setCalEnabled( true ); | 456 | todo->setCalEnabled( true ); |
410 | return true; | 457 | return true; |
411 | } | 458 | } |
412 | 459 | ||
413 | void CalendarLocal::deleteTodo( Todo *todo ) | 460 | void CalendarLocal::deleteTodo( Todo *todo ) |
414 | { | 461 | { |
462 | QString uid = todo->uid(); | ||
415 | // Handle orphaned children | 463 | // Handle orphaned children |
416 | removeRelations( todo ); | 464 | removeRelations( todo ); |
417 | clearUndo(todo); | 465 | clearUndo(todo); |
418 | 466 | ||
419 | if ( mTodoList.removeRef( todo ) ) { | 467 | if ( mTodoList.removeRef( todo ) ) { |
420 | setModified( true ); | 468 | setModified( true ); |
421 | } | 469 | } |
470 | Todo* dup = todoForUid( uid ); | ||
471 | if ( dup ) | ||
472 | setupRelations( dup ); | ||
422 | } | 473 | } |
423 | 474 | ||
424 | QPtrList<Todo> CalendarLocal::rawTodos() | 475 | QPtrList<Todo> CalendarLocal::rawTodos() |
425 | { | 476 | { |
426 | QPtrList<Todo> el; | 477 | QPtrList<Todo> el; |
427 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 478 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
428 | if ( it->calEnabled() ) el.append( it ); | 479 | if ( it->calEnabled() ) el.append( it ); |
429 | return el; | 480 | return el; |
430 | } | 481 | } |
431 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 482 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
432 | { | 483 | { |
433 | Todo *todo; | 484 | Todo *todo; |
434 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 485 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
435 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 486 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
436 | } | 487 | } |
437 | 488 | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b611704..1ceabce 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -34,33 +34,34 @@ class CalFormat; | |||
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false,int * isDup = 0 ); |
51 | Todo* todoForUid( const QString& uid, bool doNotCheckDuplicates = true, bool enabledOnly = false ,int * isDup = 0 ); | ||
51 | void setSyncEventsReadOnly(); | 52 | void setSyncEventsReadOnly(); |
52 | void setSyncEventsEnabled(); | 53 | void setSyncEventsEnabled(); |
53 | void stopAllTodos(); | 54 | void stopAllTodos(); |
54 | /** | 55 | /** |
55 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 56 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
56 | calendar. Any information already present is lost. | 57 | calendar. Any information already present is lost. |
57 | @return true, if successfull, false on error. | 58 | @return true, if successfull, false on error. |
58 | @param fileName the name of the calendar on disk. | 59 | @param fileName the name of the calendar on disk. |
59 | */ | 60 | */ |
60 | bool load( const QString &fileName ); | 61 | bool load( const QString &fileName ); |
61 | /** | 62 | /** |
62 | Writes out the calendar to disk in the specified \a format. | 63 | Writes out the calendar to disk in the specified \a format. |
63 | CalendarLocal takes ownership of the CalFormat object. | 64 | CalendarLocal takes ownership of the CalFormat object. |
64 | @return true, if successfull, false on error. | 65 | @return true, if successfull, false on error. |
65 | @param fileName the name of the file | 66 | @param fileName the name of the file |
66 | */ | 67 | */ |
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index fe9f854..7dd9bd2 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -507,32 +507,38 @@ QString Incidence::categoriesStrWithSpace() | |||
507 | } | 507 | } |
508 | 508 | ||
509 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 509 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
510 | { | 510 | { |
511 | if (mReadOnly) return; | 511 | if (mReadOnly) return; |
512 | mRelatedToUid = relatedToUid; | 512 | mRelatedToUid = relatedToUid; |
513 | } | 513 | } |
514 | void Incidence::clearRelations() | 514 | void Incidence::clearRelations() |
515 | { | 515 | { |
516 | mRelatedTo = 0; | 516 | mRelatedTo = 0; |
517 | mRelations.clear(); | 517 | mRelations.clear(); |
518 | } | 518 | } |
519 | QString Incidence::relatedToUid() const | 519 | QString Incidence::relatedToUid() const |
520 | { | 520 | { |
521 | return mRelatedToUid; | 521 | return mRelatedToUid; |
522 | } | 522 | } |
523 | void Incidence::resetRelatedTo() | ||
524 | { | ||
525 | QString store = mRelatedToUid; | ||
526 | setRelatedTo( 0 ); | ||
527 | mRelatedToUid = store; | ||
528 | } | ||
523 | 529 | ||
524 | void Incidence::setRelatedTo(Incidence *relatedTo) | 530 | void Incidence::setRelatedTo(Incidence *relatedTo) |
525 | { | 531 | { |
526 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 532 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
527 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 533 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
528 | if (mReadOnly || mRelatedTo == relatedTo) return; | 534 | if (mReadOnly || mRelatedTo == relatedTo) return; |
529 | if(mRelatedTo) { | 535 | if(mRelatedTo) { |
530 | // updated(); | 536 | // updated(); |
531 | mRelatedTo->removeRelation(this); | 537 | mRelatedTo->removeRelation(this); |
532 | } | 538 | } |
533 | mRelatedTo = relatedTo; | 539 | mRelatedTo = relatedTo; |
534 | if (mRelatedTo) { | 540 | if (mRelatedTo) { |
535 | mRelatedTo->addRelation(this); | 541 | mRelatedTo->addRelation(this); |
536 | mRelatedToUid = mRelatedTo->uid(); | 542 | mRelatedToUid = mRelatedTo->uid(); |
537 | } else { | 543 | } else { |
538 | mRelatedToUid = ""; | 544 | mRelatedToUid = ""; |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index dc49640..f89942f 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -160,32 +160,33 @@ class Incidence : public IncidenceBase | |||
160 | QStringList categories() const; | 160 | QStringList categories() const; |
161 | QStringList* categoriesP(); | 161 | QStringList* categoriesP(); |
162 | /** return categories as a comma separated string */ | 162 | /** return categories as a comma separated string */ |
163 | QString categoriesStr(); | 163 | QString categoriesStr(); |
164 | QString categoriesStrWithSpace(); | 164 | QString categoriesStrWithSpace(); |
165 | 165 | ||
166 | /** point at some other event to which the event relates. This function should | 166 | /** point at some other event to which the event relates. This function should |
167 | * only be used when constructing a calendar before the related Event | 167 | * only be used when constructing a calendar before the related Event |
168 | * exists. */ | 168 | * exists. */ |
169 | void setRelatedToUid(const QString &); | 169 | void setRelatedToUid(const QString &); |
170 | /** what event does this one relate to? This function should | 170 | /** what event does this one relate to? This function should |
171 | * only be used when constructing a calendar before the related Event | 171 | * only be used when constructing a calendar before the related Event |
172 | * exists. */ | 172 | * exists. */ |
173 | QString relatedToUid() const; | 173 | QString relatedToUid() const; |
174 | /** point at some other event to which the event relates */ | 174 | /** point at some other event to which the event relates */ |
175 | void setRelatedTo(Incidence *relatedTo); | 175 | void setRelatedTo(Incidence *relatedTo); |
176 | void resetRelatedTo(); | ||
176 | /** what event does this one relate to? */ | 177 | /** what event does this one relate to? */ |
177 | Incidence *relatedTo() const; | 178 | Incidence *relatedTo() const; |
178 | /** All events that are related to this event */ | 179 | /** All events that are related to this event */ |
179 | QPtrList<Incidence> relations() const; | 180 | QPtrList<Incidence> relations() const; |
180 | /** Add an event which is related to this event */ | 181 | /** Add an event which is related to this event */ |
181 | void addRelation(Incidence *); | 182 | void addRelation(Incidence *); |
182 | /** Remove event that is related to this event */ | 183 | /** Remove event that is related to this event */ |
183 | void removeRelation(Incidence *); | 184 | void removeRelation(Incidence *); |
184 | 185 | ||
185 | /** returns the list of dates which are exceptions to the recurrence rule */ | 186 | /** returns the list of dates which are exceptions to the recurrence rule */ |
186 | DateList exDates() const; | 187 | DateList exDates() const; |
187 | /** sets the list of dates which are exceptions to the recurrence rule */ | 188 | /** sets the list of dates which are exceptions to the recurrence rule */ |
188 | void setExDates(const DateList &_exDates); | 189 | void setExDates(const DateList &_exDates); |
189 | void setExDates(const char *dates); | 190 | void setExDates(const char *dates); |
190 | /** Add a date to the list of exceptions of the recurrence rule. */ | 191 | /** Add a date to the list of exceptions of the recurrence rule. */ |
191 | void addExDate(const QDate &date); | 192 | void addExDate(const QDate &date); |