summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3e42ec0..e37a7ad 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -70,88 +70,107 @@ CalendarLocal::~CalendarLocal()
70} 70}
71bool CalendarLocal::mergeCalendarFile( QString name ) 71bool CalendarLocal::mergeCalendarFile( QString name )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 74 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 76 mergeCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81 81
82Incidence* CalendarLocal::incidenceForUid( const QString& uid ) 82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 83{
84 Todo *todo;; 84 Todo *todo;;
85 Incidence *retVal = 0; 85 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 87 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo;
88 if ( retVal ) { 89 if ( retVal ) {
89 if ( retVal->calID() > todo->calID() ) { 90 if ( retVal->calID() > todo->calID() ) {
90 retVal = todo; 91 retVal = todo;
91 } 92 }
92 } else { 93 } else {
93 retVal = todo; 94 retVal = todo;
94 } 95 }
95 } 96 }
96 } 97 }
97 if ( retVal ) return retVal; 98 if ( retVal ) return retVal;
98 Event *event; 99 Event *event;
99 for ( event = mEventList.first(); event; event = mEventList.next() ) { 100 for ( event = mEventList.first(); event; event = mEventList.next() ) {
100 if ( event->uid() == uid ) { 101 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event;
101 if ( retVal ) { 103 if ( retVal ) {
102 if ( retVal->calID() > event->calID() ) { 104 if ( retVal->calID() > event->calID() ) {
103 retVal = event; 105 retVal = event;
104 } 106 }
105 } else { 107 } else {
106 retVal = event; 108 retVal = event;
107 } 109 }
108 } 110 }
109 } 111 }
110 if ( retVal ) return retVal; 112 if ( retVal ) return retVal;
111 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
112 if ( it->uid() == uid ) { 114 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it;
113 if ( retVal ) { 116 if ( retVal ) {
114 if ( retVal->calID() > it->calID() ) { 117 if ( retVal->calID() > it->calID() ) {
115 retVal = it; 118 retVal = it;
116 } 119 }
117 } else { 120 } else {
118 retVal = it; 121 retVal = it;
119 } 122 }
120 } 123 }
121 return retVal; 124 return retVal;
122} 125}
123 126
124bool CalendarLocal::mergeCalendar( Calendar* remote ) 127bool CalendarLocal::mergeCalendar( Calendar* remote )
125{ 128{
129 // 1 look for raw inc in local
130 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote
132 // if inc in local, replace it
133 // if not in local, add it to default calendar
134 QPtrList<Incidence> localInc = rawIncidences();
135 Incidence* inL = localInc.first();
136 while ( inL ) {
137 if ( ! inL->isReadOnly () )
138 if ( !remote->incidenceForUid( inL->uid(), true ))
139 deleteIncidence( inL );
140 inL = localInc.next();
141 }
126 QPtrList<Incidence> er = remote->rawIncidences(); 142 QPtrList<Incidence> er = remote->rawIncidences();
127 Incidence* inR = er.first(); 143 Incidence* inR = er.first();
128 Incidence* inL;
129 while ( inR ) { 144 while ( inR ) {
130 inL = incidenceForUid( inR->uid() ); 145 inL = incidenceForUid( inR->uid(),false );
131 if ( inL ) { 146 if ( inL ) {
147 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
132 int calID = inL->calID(); 148 int calID = inL->calID();
133 deleteIncidence( inL ); 149 deleteIncidence( inL );
134 inL = inR->clone(); 150 inL = inR->clone();
135 inL->setCalID( calID ); 151 inL->setCalID( calID );
136 addIncidence( inL ); 152 addIncidence( inL );
153 }
137 } else { 154 } else {
138 inL = inR->clone(); 155 inL = inR->clone();
139 inL->setCalID( 0 );// add to default cal 156 inL->setCalID( 0 );// add to default cal
140 addIncidence( inL ); 157 addIncidence( inL );
141 } 158 }
142 inR = er.next(); 159 inR = er.next();
143 } 160 }
144 return true; 161 return true;
145} 162}
163
164
146bool CalendarLocal::addCalendarFile( QString name, int id ) 165bool CalendarLocal::addCalendarFile( QString name, int id )
147{ 166{
148 CalendarLocal calendar( timeZoneId() ); 167 CalendarLocal calendar( timeZoneId() );
149 calendar.setDefaultCalendar( id ); 168 calendar.setDefaultCalendar( id );
150 if ( calendar.load( name ) ) { 169 if ( calendar.load( name ) ) {
151 addCalendar( &calendar ); 170 addCalendar( &calendar );
152 return true; 171 return true;
153 } 172 }
154 return false; 173 return false;
155} 174}
156void CalendarLocal::setSyncEventsReadOnly() 175void CalendarLocal::setSyncEventsReadOnly()
157{ 176{