summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp55
-rw-r--r--korganizer/calendarview.cpp8
-rw-r--r--libkcal/calendar.cpp16
-rw-r--r--libkcal/calendar.h1
4 files changed, 56 insertions, 24 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 03571b9..755e792 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -1,248 +1,255 @@
1/******************************************************************************* 1/*******************************************************************************
2 * main.cpp * 2 * main.cpp *
3 * * 3 * *
4 * 4 *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 * * 10 * *
11 * This program is distributed in the hope that it will be useful, * 11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. * 14 * GNU General Public License for more details. *
15 * * 15 * *
16 * You should have received a copy of the GNU General Public License * 16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software * 17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * * 19 * *
20 * As a special exception, permission is given to link this program * 20 * As a special exception, permission is given to link this program *
21 * with any edition of Qt, and distribute the resulting executable, * 21 * with any edition of Qt, and distribute the resulting executable, *
22 * without including the source code for Qt in the source distribution. * 22 * without including the source code for Qt in the source distribution. *
23 * * 23 * *
24 ******************************************************************************/ 24 ******************************************************************************/
25 25
26#ifdef HAVE_CONFIG_H 26#ifdef HAVE_CONFIG_H
27#include "config.h" 27#include "config.h"
28#endif 28#endif
29 29
30#if TIME_WITH_SYS_TIME 30#if TIME_WITH_SYS_TIME
31# include <sys/time.h> 31# include <sys/time.h>
32# include <time.h> 32# include <time.h>
33#else 33#else
34# if HAVE_SYS_TIME_H 34# if HAVE_SYS_TIME_H
35# include <sys/time.h> 35# include <sys/time.h>
36# else 36# else
37# include <time.h> 37# include <time.h>
38# endif 38# endif
39#endif 39#endif
40 40
41#include <kcmdlineargs.h> 41#include <kcmdlineargs.h>
42#include <kaboutdata.h> 42#include <kaboutdata.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kglobal.h> 44#include <kglobal.h>
45#include <kconfig.h> 45#include <kconfig.h>
46#include <kstandarddirs.h> 46#include <kstandarddirs.h>
47#include <kdebug.h> 47#include <kdebug.h>
48 48
49#include <libkcal/calformat.h> 49#include <libkcal/calformat.h>
50#include <libkcal/calendarresources.h> 50#include <libkcal/calendarresources.h>
51#include <libkcal/resourcelocal.h> 51#include <libkcal/resourcelocal.h>
52#include <libkcal/filestorage.h> 52#include <libkcal/filestorage.h>
53#include <libkcal/icalformat.h> 53#include <libkcal/icalformat.h>
54 54
55#include <qdatetime.h> 55#include <qdatetime.h>
56#include <qfile.h> 56#include <qfile.h>
57#include <qdir.h> 57#include <qdir.h>
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60#include <iostream> 60#include <iostream>
61 61
62using namespace KCal; 62using namespace KCal;
63using namespace std; 63using namespace std;
64 64
65static const char progName[] = "kdecalendar"; 65static const char progName[] = "kdecalendar";
66static const char progDisplay[] = "KDE_Calendar"; 66static const char progDisplay[] = "KDE_Calendar";
67static const char progVersion[] = "33.1/3"; 67static const char progVersion[] = "33.1/3";
68static const char progDesc[] = "A command line interface to KDE calendars"; 68static const char progDesc[] = "A command line interface to KDE calendars";
69 69
70 70
71static KCmdLineOptions options[] = 71static KCmdLineOptions options[] =
72 { 72 {
73 { "dump", 73 { "dump",
74 I18N_NOOP( "Dumps calendar" ), 0 }, 74 I18N_NOOP( "Dumps calendar" ), 0 },
75 { "read", 75 { "read",
76 I18N_NOOP( "Reads calendar" ), 0 }, 76 I18N_NOOP( "Reads calendar" ), 0 },
77 KCmdLineLastOption 77 KCmdLineLastOption
78 }; 78 };
79 79
80int main( int argc, char *argv[] ) 80int main( int argc, char *argv[] )
81{ 81{
82 KAboutData aboutData( 82 KAboutData aboutData(
83 progName, // internal program name 83 progName, // internal program name
84 I18N_NOOP( progDisplay ), // displayable program name. 84 I18N_NOOP( progDisplay ), // displayable program name.
85 progVersion, // version string 85 progVersion, // version string
86 I18N_NOOP( progDesc ), // short porgram description 86 I18N_NOOP( progDesc ), // short porgram description
87 KAboutData::License_GPL, // license type 87 KAboutData::License_GPL, // license type
88 "(c) 2004, Lutz Rogowski", // copyright statement 88 "(c) 2004, Lutz Rogowski", // copyright statement
89 0, // any free form text 89 0, // any free form text
90 "", // program home page address 90 "", // program home page address
91 "bugs.kde.org" // bug report email address 91 "bugs.kde.org" // bug report email address
92 ); 92 );
93 93
94 94
95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
96 // for QApplication/KApplication (no KDE or Qt options) 96 // for QApplication/KApplication (no KDE or Qt options)
97 KCmdLineArgs::init( argc, argv, &aboutData, true ); 97 KCmdLineArgs::init( argc, argv, &aboutData, true );
98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
99 99
100 KInstance ins ( progName ); 100 KInstance ins ( progName );
101 101
102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
103 103
104 bool read = false; 104 bool read = false;
105 if ( args->isSet( "read" ) ) { 105 if ( args->isSet( "read" ) ) {
106 read = true; 106 read = true;
107 qDebug("read "); 107 qDebug("read ");
108 } 108 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
110 CalendarResources *calendarResource = 0; 110 CalendarResources *calendarResource = 0;
111 CalendarLocal *localCalendar = 0; 111 CalendarLocal *localCalendar = 0;
112 KConfig c( locate( "config", "korganizerrc" ) ); 112 KConfig c( locate( "config", "korganizerrc" ) );
113 c.setGroup( "Time & Date" ); 113 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" ); 114 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz ); 115 calendarResource = new CalendarResources( tz );
116 calendarResource->readConfig(); 116 calendarResource->readConfig();
117 calendarResource->load(); 117 calendarResource->load();
118 qDebug("************************************* "); 118 qDebug("************************************* ");
119 qDebug("**************kdecaldump************* "); 119 qDebug("**************kdecaldump************* ");
120 qDebug("************************************* "); 120 qDebug("************************************* ");
121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); 121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
122 122
123 if ( !read ) { 123 if ( !read ) {
124 localCalendar = new CalendarLocal(); 124 localCalendar = new CalendarLocal();
125 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 125 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
126 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 126 KCal::Incidence::List allInc = calendarResource->rawIncidences();
127 Incidence::List::ConstIterator it; 127 Incidence::List::ConstIterator it;
128 int num = 0; 128 int num = 0;
129 for( it = allInc.begin(); it != allInc.end(); ++it ) { 129 for( it = allInc.begin(); it != allInc.end(); ++it ) {
130 ResourceCalendar * re = calendarResource->resource( (*it) ); 130 ResourceCalendar * re = calendarResource->resource( (*it) );
131 if ( re && !re->readOnly() ) { 131 if ( re && !re->readOnly() ) {
132 ++num; 132 ++num;
133 Incidence* cl = (*it)->clone(); 133 Incidence* cl = (*it)->clone();
134 cl->setLastModified( (*it)->lastModified() ); 134 cl->setLastModified( (*it)->lastModified() );
135 if ( cl->type() == "Journal" ) 135 if ( cl->type() == "Journal" )
136 localCalendar->addJournal( (Journal *) cl ); 136 localCalendar->addJournal( (Journal *) cl );
137 else if ( cl->type() == "Todo" ) 137 else if ( cl->type() == "Todo" )
138 localCalendar->addTodo( (Todo *) cl ); 138 localCalendar->addTodo( (Todo *) cl );
139 else if ( cl->type() == "Event" ) 139 else if ( cl->type() == "Event" )
140 localCalendar->addEvent( (Event *) cl ); 140 localCalendar->addEvent( (Event *) cl );
141 } 141 }
142 } 142 }
143 143
144 FileStorage* storage = new FileStorage( calendarResource ); 144 FileStorage* storage = new FileStorage( calendarResource );
145 storage->setFileName( fileName ); 145 storage->setFileName( fileName );
146 storage->setSaveFormat( new ICalFormat() ); 146 storage->setSaveFormat( new ICalFormat() );
147 storage->save(); 147 storage->save();
148 delete storage; 148 delete storage;
149 qDebug("************************************* "); 149 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** "); 150 qDebug("************kdecaldump*************** ");
151 qDebug("************************************* "); 151 qDebug("************************************* ");
152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
153 153
154 } else { 154 } else {
155 qDebug("*************************load"); 155 qDebug("*************************load");
156 localCalendar = new CalendarLocal(); 156 localCalendar = new CalendarLocal();
157 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 157 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
158 FileStorage* storage = new FileStorage( localCalendar ); 158 FileStorage* storage = new FileStorage( localCalendar );
159 storage->setFileName( fileName ); 159 storage->setFileName( fileName );
160 int num = 0; 160 int num = 0;
161 int del = 0; 161 int del = 0;
162 int add = 0; 162 int add = 0;
163 if ( storage->load() ) { 163 if ( storage->load() ) {
164 qDebug("*************************loaded!"); 164 qDebug("*************************loaded!");
165 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 165 KCal::Incidence::List newInc = localCalendar->rawIncidences();
166 Incidence::List::ConstIterator it; 166 Incidence::List::ConstIterator it;
167 for( it = newInc.begin(); it != newInc.end(); ++it ) { 167 for( it = newInc.begin(); it != newInc.end(); ++it ) {
168 Incidence* cl = (*it)->clone(); 168 if ( (*it)->pilotId() > 0 ) { //changed
169 Incidence *incOld = calendarResource->incidence( cl->uid() ); 169 Incidence* cl = (*it)->clone();
170 ResourceCalendar * res = 0; 170 Incidence *incOld = calendarResource->incidence( cl->uid() );
171 if ( incOld ) 171 ResourceCalendar * res = 0;
172 res = calendarResource->resource( incOld ); 172 if ( incOld )
173 if ( res ) { 173 res = calendarResource->resource( incOld );
174 ++num; 174 if ( res ) {
175 if ( incOld->type() == "Journal" ) 175 cl->setPilotId( incOld->pilotId() );
176 calendarResource->deleteJournal( (Journal *) incOld ); 176 ++num;
177 else if ( incOld->type() == "Todo" )
178 calendarResource->deleteTodo( (Todo *) incOld );
179 else if ( incOld->type() == "Event" )
180 calendarResource->deleteEvent( (Event *) incOld );
181
182 if ( cl->type() == "Journal" )
183 calendarResource->addJournal( (Journal *) cl, res );
184 else if ( cl->type() == "Todo" )
185 calendarResource->addTodo( (Todo *) cl, res );
186 else if ( cl->type() == "Event" )
187 calendarResource->addEvent( (Event *) cl, res );
188
189 } else {
190 if ( incOld ) {
191 qDebug("ERROR: no resource found for old incidence ");
192 if ( incOld->type() == "Journal" ) 177 if ( incOld->type() == "Journal" )
193 calendarResource->deleteJournal( (Journal *) incOld ); 178 calendarResource->deleteJournal( (Journal *) incOld );
194 else if ( incOld->type() == "Todo" ) 179 else if ( incOld->type() == "Todo" )
195 calendarResource->deleteTodo( (Todo *) incOld ); 180 calendarResource->deleteTodo( (Todo *) incOld );
196 else if ( incOld->type() == "Event" ) 181 else if ( incOld->type() == "Event" )
197 calendarResource->deleteEvent( (Event *) incOld ); 182 calendarResource->deleteEvent( (Event *) incOld );
183
184 if ( cl->type() == "Journal" )
185 calendarResource->addJournal( (Journal *) cl, res );
186 else if ( cl->type() == "Todo" )
187 calendarResource->addTodo( (Todo *) cl, res );
188 else if ( cl->type() == "Event" )
189 calendarResource->addEvent( (Event *) cl, res );
190
191 } else {
192 if ( incOld ) {
193 qDebug("ERROR: no resource found for old incidence ");
194 if ( incOld->type() == "Journal" )
195 calendarResource->deleteJournal( (Journal *) incOld );
196 else if ( incOld->type() == "Todo" )
197 calendarResource->deleteTodo( (Todo *) incOld );
198 else if ( incOld->type() == "Event" )
199 calendarResource->deleteEvent( (Event *) incOld );
198 200
201 }
202 calendarResource->addIncidence( cl );
203 ++add;
199 } 204 }
205 } else { // added
206 Incidence* cl = (*it)->clone();
200 calendarResource->addIncidence( cl ); 207 calendarResource->addIncidence( cl );
201 ++add; 208 ++add;
202 } 209 }
203 } 210 }
204 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 211 KCal::Incidence::List allInc = calendarResource->rawIncidences();
205 212
206 for( it = allInc.begin(); it != allInc.end(); ++it ) { 213 for( it = allInc.begin(); it != allInc.end(); ++it ) {
207 ResourceCalendar * re = calendarResource->resource( (*it) ); 214 ResourceCalendar * re = calendarResource->resource( (*it) );
208 if ( re && !re->readOnly() ) { 215 if ( re && !re->readOnly() ) {
209 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 216 Incidence* cl = localCalendar->incidence( (*it)->uid() );
210 if ( !cl ) { 217 if ( !cl ) {
211 ++del; 218 ++del;
212 cl = (*it); 219 cl = (*it);
213 if ( cl->type() == "Journal" ) 220 if ( cl->type() == "Journal" )
214 calendarResource->deleteJournal( (Journal *) cl ); 221 calendarResource->deleteJournal( (Journal *) cl );
215 else if ( cl->type() == "Todo" ) 222 else if ( cl->type() == "Todo" )
216 calendarResource->deleteTodo( (Todo *) cl ); 223 calendarResource->deleteTodo( (Todo *) cl );
217 else if ( cl->type() == "Event" ) 224 else if ( cl->type() == "Event" )
218 calendarResource->deleteEvent( (Event *) cl ); 225 calendarResource->deleteEvent( (Event *) cl );
219 //QDateTime lm = cl->lastModified(); 226 //QDateTime lm = cl->lastModified();
220 //cl->setResources( (*it)->resources() ); 227 //cl->setResources( (*it)->resources() );
221 //cl->setLastModified(lm); 228 //cl->setLastModified(lm);
222 } 229 }
223 } 230 }
224 } 231 }
225 232
226 calendarResource->save(); 233 calendarResource->save();
227 qDebug("************************************* "); 234 qDebug("************************************* ");
228 qDebug("************kdecaldump*************** "); 235 qDebug("************kdecaldump*************** ");
229 qDebug("************************************* "); 236 qDebug("************************************* ");
230 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 237 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
231 238
232 } else 239 } else
233 qDebug("ERROR loading file %s",fileName.latin1() ); 240 qDebug("ERROR loading file %s",fileName.latin1() );
234 241
235 } 242 }
236 243
237 if ( localCalendar ) { 244 if ( localCalendar ) {
238 localCalendar->close(); 245 localCalendar->close();
239 delete localCalendar; 246 delete localCalendar;
240 } 247 }
241 if ( calendarResource ) { 248 if ( calendarResource ) {
242 calendarResource->close(); 249 calendarResource->close();
243 delete calendarResource; 250 delete calendarResource;
244 } 251 }
245 252
246 qDebug("ente "); 253 qDebug("ente ");
247 return 0; 254 return 0;
248} 255}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1f8ad5b..f727cd4 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -679,606 +679,614 @@ QDate 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 //void setZaurusId(int id); 717 //void setZaurusId(int id);
718 // int zaurusId() const; 718 // int zaurusId() const;
719 // void setZaurusUid(int id); 719 // void setZaurusUid(int id);
720 // int zaurusUid() const; 720 // int zaurusUid() const;
721 // void setZaurusStat(int id); 721 // void setZaurusStat(int id);
722 // int zaurusStat() const; 722 // int zaurusStat() const;
723 // 0 equal 723 // 0 equal
724 // 1 take local 724 // 1 take local
725 // 2 take remote 725 // 2 take remote
726 // 3 cancel 726 // 3 cancel
727 QDateTime lastSync = mLastCalendarSync; 727 QDateTime lastSync = mLastCalendarSync;
728 QDateTime localMod = local->lastModified(); 728 QDateTime localMod = local->lastModified();
729 QDateTime remoteMod = remote->lastModified(); 729 QDateTime remoteMod = remote->lastModified();
730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
731 bool remCh, locCh; 731 bool remCh, locCh;
732 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 732 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
733 //if ( remCh ) 733 //if ( remCh )
734 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 734 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
735 locCh = ( localMod > mLastCalendarSync ); 735 locCh = ( localMod > mLastCalendarSync );
736 if ( !remCh && ! locCh ) { 736 if ( !remCh && ! locCh ) {
737 //qDebug("both not changed "); 737 //qDebug("both not changed ");
738 lastSync = localMod.addDays(1); 738 lastSync = localMod.addDays(1);
739 if ( mode <= SYNC_PREF_ASK ) 739 if ( mode <= SYNC_PREF_ASK )
740 return 0; 740 return 0;
741 } else { 741 } else {
742 if ( locCh ) { 742 if ( locCh ) {
743 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 743 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
744 lastSync = localMod.addDays( -1 ); 744 lastSync = localMod.addDays( -1 );
745 if ( !remCh ) 745 if ( !remCh )
746 remoteMod = ( lastSync.addDays( -1 ) ); 746 remoteMod = ( lastSync.addDays( -1 ) );
747 } else { 747 } else {
748 //qDebug(" not loc changed "); 748 //qDebug(" not loc changed ");
749 lastSync = localMod.addDays( 1 ); 749 lastSync = localMod.addDays( 1 );
750 if ( remCh ) 750 if ( remCh )
751 remoteMod =( lastSync.addDays( 1 ) ); 751 remoteMod =( lastSync.addDays( 1 ) );
752 752
753 } 753 }
754 } 754 }
755 full = true; 755 full = true;
756 if ( mode < SYNC_PREF_ASK ) 756 if ( mode < SYNC_PREF_ASK )
757 mode = SYNC_PREF_ASK; 757 mode = SYNC_PREF_ASK;
758 } else { 758 } else {
759 if ( localMod == remoteMod ) 759 if ( localMod == remoteMod )
760 if ( local->revision() == remote->revision() ) 760 if ( local->revision() == remote->revision() )
761 return 0; 761 return 0;
762 762
763 } 763 }
764 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 764 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
765 765
766 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 766 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
767 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 767 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
768 //full = true; //debug only 768 //full = true; //debug only
769 if ( full ) { 769 if ( full ) {
770 bool equ = false; 770 bool equ = false;
771 if ( local->type() == "Event" ) { 771 if ( local->type() == "Event" ) {
772 equ = (*((Event*) local) == *((Event*) remote)); 772 equ = (*((Event*) local) == *((Event*) remote));
773 } 773 }
774 else if ( local->type() =="Todo" ) 774 else if ( local->type() =="Todo" )
775 equ = (*((Todo*) local) == (*(Todo*) remote)); 775 equ = (*((Todo*) local) == (*(Todo*) remote));
776 else if ( local->type() =="Journal" ) 776 else if ( local->type() =="Journal" )
777 equ = (*((Journal*) local) == *((Journal*) remote)); 777 equ = (*((Journal*) local) == *((Journal*) remote));
778 if ( equ ) { 778 if ( equ ) {
779 //qDebug("equal "); 779 //qDebug("equal ");
780 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 780 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
781 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 781 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
782 } 782 }
783 if ( mode < SYNC_PREF_FORCE_LOCAL ) 783 if ( mode < SYNC_PREF_FORCE_LOCAL )
784 return 0; 784 return 0;
785 785
786 }//else //debug only 786 }//else //debug only
787 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 787 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
788 } 788 }
789 int result; 789 int result;
790 bool localIsNew; 790 bool localIsNew;
791 //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() ); 791 //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() );
792 792
793 if ( full && mode < SYNC_PREF_NEWEST ) 793 if ( full && mode < SYNC_PREF_NEWEST )
794 mode = SYNC_PREF_ASK; 794 mode = SYNC_PREF_ASK;
795 795
796 switch( mode ) { 796 switch( mode ) {
797 case SYNC_PREF_LOCAL: 797 case SYNC_PREF_LOCAL:
798 if ( lastSync > remoteMod ) 798 if ( lastSync > remoteMod )
799 return 1; 799 return 1;
800 if ( lastSync > localMod ) 800 if ( lastSync > localMod )
801 return 2; 801 return 2;
802 return 1; 802 return 1;
803 break; 803 break;
804 case SYNC_PREF_REMOTE: 804 case SYNC_PREF_REMOTE:
805 if ( lastSync > remoteMod ) 805 if ( lastSync > remoteMod )
806 return 1; 806 return 1;
807 if ( lastSync > localMod ) 807 if ( lastSync > localMod )
808 return 2; 808 return 2;
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_NEWEST: 811 case SYNC_PREF_NEWEST:
812 if ( localMod > remoteMod ) 812 if ( localMod > remoteMod )
813 return 1; 813 return 1;
814 else 814 else
815 return 2; 815 return 2;
816 break; 816 break;
817 case SYNC_PREF_ASK: 817 case SYNC_PREF_ASK:
818 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 818 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
819 if ( lastSync > remoteMod ) 819 if ( lastSync > remoteMod )
820 return 1; 820 return 1;
821 if ( lastSync > localMod ) 821 if ( lastSync > localMod )
822 return 2; 822 return 2;
823 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 823 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
824 localIsNew = localMod >= remoteMod; 824 localIsNew = localMod >= remoteMod;
825 if ( localIsNew ) 825 if ( localIsNew )
826 getEventViewerDialog()->setColorMode( 1 ); 826 getEventViewerDialog()->setColorMode( 1 );
827 else 827 else
828 getEventViewerDialog()->setColorMode( 2 ); 828 getEventViewerDialog()->setColorMode( 2 );
829 getEventViewerDialog()->setIncidence(local); 829 getEventViewerDialog()->setIncidence(local);
830 if ( localIsNew ) 830 if ( localIsNew )
831 getEventViewerDialog()->setColorMode( 2 ); 831 getEventViewerDialog()->setColorMode( 2 );
832 else 832 else
833 getEventViewerDialog()->setColorMode( 1 ); 833 getEventViewerDialog()->setColorMode( 1 );
834 getEventViewerDialog()->addIncidence(remote); 834 getEventViewerDialog()->addIncidence(remote);
835 getEventViewerDialog()->setColorMode( 0 ); 835 getEventViewerDialog()->setColorMode( 0 );
836 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 836 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
837 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 837 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
838 getEventViewerDialog()->showMe(); 838 getEventViewerDialog()->showMe();
839 result = getEventViewerDialog()->executeS( localIsNew ); 839 result = getEventViewerDialog()->executeS( localIsNew );
840 return result; 840 return result;
841 841
842 break; 842 break;
843 case SYNC_PREF_FORCE_LOCAL: 843 case SYNC_PREF_FORCE_LOCAL:
844 return 1; 844 return 1;
845 break; 845 break;
846 case SYNC_PREF_FORCE_REMOTE: 846 case SYNC_PREF_FORCE_REMOTE:
847 return 2; 847 return 2;
848 break; 848 break;
849 849
850 default: 850 default:
851 // SYNC_PREF_TAKE_BOTH not implemented 851 // SYNC_PREF_TAKE_BOTH not implemented
852 break; 852 break;
853 } 853 }
854 return 0; 854 return 0;
855} 855}
856Event* CalendarView::getLastSyncEvent() 856Event* CalendarView::getLastSyncEvent()
857{ 857{
858 Event* lse; 858 Event* lse;
859 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 859 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
860 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 860 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
861 if (!lse) { 861 if (!lse) {
862 lse = new Event(); 862 lse = new Event();
863 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
864 QString sum = ""; 864 QString sum = "";
865 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 865 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
866 sum = "E: "; 866 sum = "E: ";
867 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 867 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
868 lse->setDtStart( mLastCalendarSync ); 868 lse->setDtStart( mLastCalendarSync );
869 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 869 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
870 lse->setCategories( i18n("SyncEvent") ); 870 lse->setCategories( i18n("SyncEvent") );
871 lse->setReadOnly( true ); 871 lse->setReadOnly( true );
872 mCalendar->addEvent( lse ); 872 mCalendar->addEvent( lse );
873 } 873 }
874 874
875 return lse; 875 return lse;
876 876
877} 877}
878 878
879// we check, if the to delete event has a id for a profile 879// we check, if the to delete event has a id for a profile
880// if yes, we set this id in the profile to delete 880// if yes, we set this id in the profile to delete
881void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 881void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
882{ 882{
883 if ( lastSync.count() == 0 ) { 883 if ( lastSync.count() == 0 ) {
884 //qDebug(" lastSync.count() == 0"); 884 //qDebug(" lastSync.count() == 0");
885 return; 885 return;
886 } 886 }
887 if ( toDelete->type() == "Journal" ) 887 if ( toDelete->type() == "Journal" )
888 return; 888 return;
889 889
890 Event* eve = lastSync.first(); 890 Event* eve = lastSync.first();
891 891
892 while ( eve ) { 892 while ( eve ) {
893 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 893 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
894 if ( !id.isEmpty() ) { 894 if ( !id.isEmpty() ) {
895 QString des = eve->description(); 895 QString des = eve->description();
896 QString pref = "e"; 896 QString pref = "e";
897 if ( toDelete->type() == "Todo" ) 897 if ( toDelete->type() == "Todo" )
898 pref = "t"; 898 pref = "t";
899 des += pref+ id + ","; 899 des += pref+ id + ",";
900 eve->setReadOnly( false ); 900 eve->setReadOnly( false );
901 eve->setDescription( des ); 901 eve->setDescription( des );
902 //qDebug("setdes %s ", des.latin1()); 902 //qDebug("setdes %s ", des.latin1());
903 eve->setReadOnly( true ); 903 eve->setReadOnly( true );
904 } 904 }
905 eve = lastSync.next(); 905 eve = lastSync.next();
906 } 906 }
907 907
908} 908}
909void CalendarView::checkExternalId( Incidence * inc ) 909void CalendarView::checkExternalId( Incidence * inc )
910{ 910{
911 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 911 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
912 checkExternSyncEvent( lastSync, inc ); 912 checkExternSyncEvent( lastSync, inc );
913 913
914} 914}
915bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 915bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
916{ 916{
917 bool syncOK = true; 917 bool syncOK = true;
918 int addedEvent = 0; 918 int addedEvent = 0;
919 int addedEventR = 0; 919 int addedEventR = 0;
920 int deletedEventR = 0; 920 int deletedEventR = 0;
921 int deletedEventL = 0; 921 int deletedEventL = 0;
922 int changedLocal = 0; 922 int changedLocal = 0;
923 int changedRemote = 0; 923 int changedRemote = 0;
924 //QPtrList<Event> el = local->rawEvents(); 924 //QPtrList<Event> el = local->rawEvents();
925 Event* eventR; 925 Event* eventR;
926 QString uid; 926 QString uid;
927 int take; 927 int take;
928 Event* eventL; 928 Event* eventL;
929 Event* eventRSync; 929 Event* eventRSync;
930 Event* eventLSync; 930 Event* eventLSync;
931 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 931 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
932 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 932 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
933 bool fullDateRange = false; 933 bool fullDateRange = false;
934 local->resetTempSyncStat(); 934 local->resetTempSyncStat();
935#ifdef DESKTOP_VERSION
936 //Needed for KDE - OL sync
937 local->resetPilotStat();
938 remote->resetPilotStat();
939#endif
935 mLastCalendarSync = QDateTime::currentDateTime(); 940 mLastCalendarSync = QDateTime::currentDateTime();
936 QDateTime modifiedCalendar = mLastCalendarSync;; 941 QDateTime modifiedCalendar = mLastCalendarSync;;
937 eventLSync = getLastSyncEvent(); 942 eventLSync = getLastSyncEvent();
938 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 943 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
939 if ( eventR ) { 944 if ( eventR ) {
940 eventRSync = (Event*) eventR->clone(); 945 eventRSync = (Event*) eventR->clone();
941 remote->deleteEvent(eventR ); 946 remote->deleteEvent(eventR );
942 947
943 } else { 948 } else {
944 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 949 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
945 eventRSync = (Event*)eventLSync->clone(); 950 eventRSync = (Event*)eventLSync->clone();
946 } else { 951 } else {
947 fullDateRange = true; 952 fullDateRange = true;
948 eventRSync = new Event(); 953 eventRSync = new Event();
949 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 954 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
950 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 955 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
951 eventRSync->setDtStart( mLastCalendarSync ); 956 eventRSync->setDtStart( mLastCalendarSync );
952 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 957 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
953 eventRSync->setCategories( i18n("SyncEvent") ); 958 eventRSync->setCategories( i18n("SyncEvent") );
954 } 959 }
955 } 960 }
956 if ( eventLSync->dtStart() == mLastCalendarSync ) 961 if ( eventLSync->dtStart() == mLastCalendarSync )
957 fullDateRange = true; 962 fullDateRange = true;
958 963
959 if ( ! fullDateRange ) { 964 if ( ! fullDateRange ) {
960 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 965 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
961 966
962 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 967 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
963 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 968 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
964 fullDateRange = true; 969 fullDateRange = true;
965 } 970 }
966 } 971 }
967 if ( fullDateRange ) 972 if ( fullDateRange )
968 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 973 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
969 else 974 else
970 mLastCalendarSync = eventLSync->dtStart(); 975 mLastCalendarSync = eventLSync->dtStart();
971 // for resyncing if own file has changed 976 // for resyncing if own file has changed
972 if ( mCurrentSyncDevice == "deleteaftersync" ) { 977 if ( mCurrentSyncDevice == "deleteaftersync" ) {
973 mLastCalendarSync = loadedFileVersion; 978 mLastCalendarSync = loadedFileVersion;
974 qDebug("setting mLastCalendarSync "); 979 qDebug("setting mLastCalendarSync ");
975 } 980 }
976 //qDebug("*************************** "); 981 //qDebug("*************************** ");
977 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 982 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
978 QPtrList<Incidence> er = remote->rawIncidences(); 983 QPtrList<Incidence> er = remote->rawIncidences();
979 Incidence* inR = er.first(); 984 Incidence* inR = er.first();
980 Incidence* inL; 985 Incidence* inL;
981 QProgressBar bar( er.count(),0 ); 986 QProgressBar bar( er.count(),0 );
982 bar.setCaption (i18n("Syncing - close to abort!") ); 987 bar.setCaption (i18n("Syncing - close to abort!") );
983 988
984 int w = 300; 989 int w = 300;
985 if ( QApplication::desktop()->width() < 320 ) 990 if ( QApplication::desktop()->width() < 320 )
986 w = 220; 991 w = 220;
987 int h = bar.sizeHint().height() ; 992 int h = bar.sizeHint().height() ;
988 int dw = QApplication::desktop()->width(); 993 int dw = QApplication::desktop()->width();
989 int dh = QApplication::desktop()->height(); 994 int dh = QApplication::desktop()->height();
990 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 995 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
991 bar.show(); 996 bar.show();
992 int modulo = (er.count()/10)+1; 997 int modulo = (er.count()/10)+1;
993 int incCounter = 0; 998 int incCounter = 0;
994 while ( inR ) { 999 while ( inR ) {
995 if ( ! bar.isVisible() ) 1000 if ( ! bar.isVisible() )
996 return false; 1001 return false;
997 if ( incCounter % modulo == 0 ) 1002 if ( incCounter % modulo == 0 )
998 bar.setProgress( incCounter ); 1003 bar.setProgress( incCounter );
999 ++incCounter; 1004 ++incCounter;
1000 uid = inR->uid(); 1005 uid = inR->uid();
1001 bool skipIncidence = false; 1006 bool skipIncidence = false;
1002 if ( uid.left(15) == QString("last-syncEvent-") ) 1007 if ( uid.left(15) == QString("last-syncEvent-") )
1003 skipIncidence = true; 1008 skipIncidence = true;
1004 QString idS; 1009 QString idS;
1005 qApp->processEvents(); 1010 qApp->processEvents();
1006 if ( !skipIncidence ) { 1011 if ( !skipIncidence ) {
1007 inL = local->incidence( uid ); 1012 inL = local->incidence( uid );
1008 if ( inL ) { // maybe conflict - same uid in both calendars 1013 if ( inL ) { // maybe conflict - same uid in both calendars
1009 int maxrev = inL->revision(); 1014 int maxrev = inL->revision();
1010 if ( maxrev < inR->revision() ) 1015 if ( maxrev < inR->revision() )
1011 maxrev = inR->revision(); 1016 maxrev = inR->revision();
1012 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1017 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1013 //qDebug("take %d %s ", take, inL->summary().latin1()); 1018 //qDebug("take %d %s ", take, inL->summary().latin1());
1014 if ( take == 3 ) 1019 if ( take == 3 )
1015 return false; 1020 return false;
1016 if ( take == 1 ) {// take local 1021 if ( take == 1 ) {// take local
1017 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1022 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1018 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1023 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1019 else 1024 else
1020 idS = inR->IDStr(); 1025 idS = inR->IDStr();
1021 remote->deleteIncidence( inR ); 1026 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1027 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1028 inL->setRevision( maxrev );
1024 inR = inL->clone(); 1029 inR = inL->clone();
1025 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1030 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1026 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1031 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1027 inR->setIDStr( idS ); 1032 inR->setIDStr( idS );
1028 remote->addIncidence( inR ); 1033 remote->addIncidence( inR );
1034#ifdef DESKTOP_VERSION
1035 inR->setPilotId( 1 );
1036#endif
1029 ++changedRemote; 1037 ++changedRemote;
1030 } else { 1038 } else {
1031 if ( inR->revision() < maxrev ) 1039 if ( inR->revision() < maxrev )
1032 inR->setRevision( maxrev ); 1040 inR->setRevision( maxrev );
1033 idS = inL->IDStr(); 1041 idS = inL->IDStr();
1034 local->deleteIncidence( inL ); 1042 local->deleteIncidence( inL );
1035 inL = inR->clone(); 1043 inL = inR->clone();
1036 inL->setIDStr( idS ); 1044 inL->setIDStr( idS );
1037 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1045 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1038 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1046 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1039 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1047 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1040 } 1048 }
1041 local->addIncidence( inL ); 1049 local->addIncidence( inL );
1042 ++changedLocal; 1050 ++changedLocal;
1043 } 1051 }
1044 } 1052 }
1045 } else { // no conflict 1053 } else { // no conflict
1046 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1054 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1047 QString des = eventLSync->description(); 1055 QString des = eventLSync->description();
1048 QString pref = "e"; 1056 QString pref = "e";
1049 if ( inR->type() == "Todo" ) 1057 if ( inR->type() == "Todo" )
1050 pref = "t"; 1058 pref = "t";
1051 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1059 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1052 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1060 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1053 //remote->deleteIncidence( inR ); 1061 //remote->deleteIncidence( inR );
1054 ++deletedEventR; 1062 ++deletedEventR;
1055 } else { 1063 } else {
1056 inR->setLastModified( modifiedCalendar ); 1064 inR->setLastModified( modifiedCalendar );
1057 inL = inR->clone(); 1065 inL = inR->clone();
1058 local->addIncidence( inL ); 1066 local->addIncidence( inL );
1059 ++addedEvent; 1067 ++addedEvent;
1060 } 1068 }
1061 } else { 1069 } else {
1062 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1070 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1063 inR->setLastModified( modifiedCalendar ); 1071 inR->setLastModified( modifiedCalendar );
1064 local->addIncidence( inR->clone() ); 1072 local->addIncidence( inR->clone() );
1065 ++addedEvent; 1073 ++addedEvent;
1066 } else { 1074 } else {
1067 checkExternSyncEvent(eventRSyncSharp, inR); 1075 checkExternSyncEvent(eventRSyncSharp, inR);
1068 remote->deleteIncidence( inR ); 1076 remote->deleteIncidence( inR );
1069 ++deletedEventR; 1077 ++deletedEventR;
1070 } 1078 }
1071 } 1079 }
1072 } 1080 }
1073 } 1081 }
1074 inR = er.next(); 1082 inR = er.next();
1075 } 1083 }
1076 QPtrList<Incidence> el = local->rawIncidences(); 1084 QPtrList<Incidence> el = local->rawIncidences();
1077 inL = el.first(); 1085 inL = el.first();
1078 modulo = (el.count()/10)+1; 1086 modulo = (el.count()/10)+1;
1079 bar.setCaption (i18n("Add / remove events") ); 1087 bar.setCaption (i18n("Add / remove events") );
1080 bar.setTotalSteps ( el.count() ) ; 1088 bar.setTotalSteps ( el.count() ) ;
1081 bar.show(); 1089 bar.show();
1082 incCounter = 0; 1090 incCounter = 0;
1083 1091
1084 while ( inL ) { 1092 while ( inL ) {
1085 1093
1086 qApp->processEvents(); 1094 qApp->processEvents();
1087 if ( ! bar.isVisible() ) 1095 if ( ! bar.isVisible() )
1088 return false; 1096 return false;
1089 if ( incCounter % modulo == 0 ) 1097 if ( incCounter % modulo == 0 )
1090 bar.setProgress( incCounter ); 1098 bar.setProgress( incCounter );
1091 ++incCounter; 1099 ++incCounter;
1092 uid = inL->uid(); 1100 uid = inL->uid();
1093 bool skipIncidence = false; 1101 bool skipIncidence = false;
1094 if ( uid.left(15) == QString("last-syncEvent-") ) 1102 if ( uid.left(15) == QString("last-syncEvent-") )
1095 skipIncidence = true; 1103 skipIncidence = true;
1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1104 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1097 skipIncidence = true; 1105 skipIncidence = true;
1098 if ( !skipIncidence ) { 1106 if ( !skipIncidence ) {
1099 inR = remote->incidence( uid ); 1107 inR = remote->incidence( uid );
1100 if ( ! inR ) { 1108 if ( ! inR ) {
1101 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1109 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1102 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1110 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1111 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1112 local->deleteIncidence( inL );
1105 ++deletedEventL; 1113 ++deletedEventL;
1106 } else { 1114 } else {
1107 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1115 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1108 inL->removeID(mCurrentSyncDevice ); 1116 inL->removeID(mCurrentSyncDevice );
1109 ++addedEventR; 1117 ++addedEventR;
1110 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1118 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1111 inL->setLastModified( modifiedCalendar ); 1119 inL->setLastModified( modifiedCalendar );
1112 inR = inL->clone(); 1120 inR = inL->clone();
1113 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1121 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1114 remote->addIncidence( inR ); 1122 remote->addIncidence( inR );
1115 } 1123 }
1116 } 1124 }
1117 } else { 1125 } else {
1118 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1126 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1119 checkExternSyncEvent(eventLSyncSharp, inL); 1127 checkExternSyncEvent(eventLSyncSharp, inL);
1120 local->deleteIncidence( inL ); 1128 local->deleteIncidence( inL );
1121 ++deletedEventL; 1129 ++deletedEventL;
1122 } else { 1130 } else {
1123 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1131 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1124 ++addedEventR; 1132 ++addedEventR;
1125 inL->setLastModified( modifiedCalendar ); 1133 inL->setLastModified( modifiedCalendar );
1126 remote->addIncidence( inL->clone() ); 1134 remote->addIncidence( inL->clone() );
1127 } 1135 }
1128 } 1136 }
1129 } 1137 }
1130 } 1138 }
1131 } 1139 }
1132 inL = el.next(); 1140 inL = el.next();
1133 } 1141 }
1134 int delFut = 0; 1142 int delFut = 0;
1135 int remRem = 0; 1143 int remRem = 0;
1136 if ( mSyncManager->mWriteBackInFuture ) { 1144 if ( mSyncManager->mWriteBackInFuture ) {
1137 er = remote->rawIncidences(); 1145 er = remote->rawIncidences();
1138 remRem = er.count(); 1146 remRem = er.count();
1139 inR = er.first(); 1147 inR = er.first();
1140 QDateTime dt; 1148 QDateTime dt;
1141 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1149 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1142 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1150 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1143 while ( inR ) { 1151 while ( inR ) {
1144 if ( inR->type() == "Todo" ) { 1152 if ( inR->type() == "Todo" ) {
1145 Todo * t = (Todo*)inR; 1153 Todo * t = (Todo*)inR;
1146 if ( t->hasDueDate() ) 1154 if ( t->hasDueDate() )
1147 dt = t->dtDue(); 1155 dt = t->dtDue();
1148 else 1156 else
1149 dt = cur.addSecs( 62 ); 1157 dt = cur.addSecs( 62 );
1150 } 1158 }
1151 else if (inR->type() == "Event" ) { 1159 else if (inR->type() == "Event" ) {
1152 bool ok; 1160 bool ok;
1153 dt = inR->getNextOccurence( cur, &ok ); 1161 dt = inR->getNextOccurence( cur, &ok );
1154 if ( !ok ) 1162 if ( !ok )
1155 dt = cur.addSecs( -62 ); 1163 dt = cur.addSecs( -62 );
1156 } 1164 }
1157 else 1165 else
1158 dt = inR->dtStart(); 1166 dt = inR->dtStart();
1159 if ( dt < cur || dt > end ) { 1167 if ( dt < cur || dt > end ) {
1160 remote->deleteIncidence( inR ); 1168 remote->deleteIncidence( inR );
1161 ++delFut; 1169 ++delFut;
1162 } 1170 }
1163 inR = er.next(); 1171 inR = er.next();
1164 } 1172 }
1165 } 1173 }
1166 bar.hide(); 1174 bar.hide();
1167 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1175 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1168 eventLSync->setReadOnly( false ); 1176 eventLSync->setReadOnly( false );
1169 eventLSync->setDtStart( mLastCalendarSync ); 1177 eventLSync->setDtStart( mLastCalendarSync );
1170 eventRSync->setDtStart( mLastCalendarSync ); 1178 eventRSync->setDtStart( mLastCalendarSync );
1171 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1179 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1172 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1180 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1173 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1181 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1174 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1182 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1175 eventLSync->setReadOnly( true ); 1183 eventLSync->setReadOnly( true );
1176 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1184 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1177 remote->addEvent( eventRSync ); 1185 remote->addEvent( eventRSync );
1178 QString mes; 1186 QString mes;
1179 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 ); 1187 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 );
1180 QString delmess; 1188 QString delmess;
1181 if ( delFut ) { 1189 if ( delFut ) {
1182 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); 1190 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);
1183 mes += delmess; 1191 mes += delmess;
1184 } 1192 }
1185 if ( mSyncManager->mShowSyncSummary ) { 1193 if ( mSyncManager->mShowSyncSummary ) {
1186 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1194 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1187 } 1195 }
1188 qDebug( mes ); 1196 qDebug( mes );
1189 mCalendar->checkAlarmForIncidence( 0, true ); 1197 mCalendar->checkAlarmForIncidence( 0, true );
1190 return syncOK; 1198 return syncOK;
1191} 1199}
1192 1200
1193void CalendarView::setSyncDevice( QString s ) 1201void CalendarView::setSyncDevice( QString s )
1194{ 1202{
1195 mCurrentSyncDevice= s; 1203 mCurrentSyncDevice= s;
1196} 1204}
1197void CalendarView::setSyncName( QString s ) 1205void CalendarView::setSyncName( QString s )
1198{ 1206{
1199 mCurrentSyncName= s; 1207 mCurrentSyncName= s;
1200} 1208}
1201bool CalendarView::syncCalendar(QString filename, int mode) 1209bool CalendarView::syncCalendar(QString filename, int mode)
1202{ 1210{
1203 //qDebug("syncCalendar %s ", filename.latin1()); 1211 //qDebug("syncCalendar %s ", filename.latin1());
1204 mGlobalSyncMode = SYNC_MODE_NORMAL; 1212 mGlobalSyncMode = SYNC_MODE_NORMAL;
1205 CalendarLocal* calendar = new CalendarLocal(); 1213 CalendarLocal* calendar = new CalendarLocal();
1206 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1214 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1207 FileStorage* storage = new FileStorage( calendar ); 1215 FileStorage* storage = new FileStorage( calendar );
1208 bool syncOK = false; 1216 bool syncOK = false;
1209 storage->setFileName( filename ); 1217 storage->setFileName( filename );
1210 // qDebug("loading ... "); 1218 // qDebug("loading ... ");
1211 if ( storage->load() ) { 1219 if ( storage->load() ) {
1212 getEventViewerDialog()->setSyncMode( true ); 1220 getEventViewerDialog()->setSyncMode( true );
1213 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1221 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1214 getEventViewerDialog()->setSyncMode( false ); 1222 getEventViewerDialog()->setSyncMode( false );
1215 if ( syncOK ) { 1223 if ( syncOK ) {
1216 if ( mSyncManager->mWriteBackFile ) 1224 if ( mSyncManager->mWriteBackFile )
1217 { 1225 {
1218 storage->setSaveFormat( new ICalFormat() ); 1226 storage->setSaveFormat( new ICalFormat() );
1219 storage->save(); 1227 storage->save();
1220 } 1228 }
1221 } 1229 }
1222 setModified( true ); 1230 setModified( true );
1223 } 1231 }
1224 delete storage; 1232 delete storage;
1225 delete calendar; 1233 delete calendar;
1226 if ( syncOK ) 1234 if ( syncOK )
1227 updateView(); 1235 updateView();
1228 return syncOK; 1236 return syncOK;
1229} 1237}
1230 1238
1231void CalendarView::syncExternal( int mode ) 1239void CalendarView::syncExternal( int mode )
1232{ 1240{
1233 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1241 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1234 1242
1235 qApp->processEvents(); 1243 qApp->processEvents();
1236 CalendarLocal* calendar = new CalendarLocal(); 1244 CalendarLocal* calendar = new CalendarLocal();
1237 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1245 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1238 bool syncOK = false; 1246 bool syncOK = false;
1239 bool loadSuccess = false; 1247 bool loadSuccess = false;
1240 PhoneFormat* phoneFormat = 0; 1248 PhoneFormat* phoneFormat = 0;
1241#ifndef DESKTOP_VERSION 1249#ifndef DESKTOP_VERSION
1242 SharpFormat* sharpFormat = 0; 1250 SharpFormat* sharpFormat = 0;
1243 if ( mode == 0 ) { // sharp 1251 if ( mode == 0 ) { // sharp
1244 sharpFormat = new SharpFormat () ; 1252 sharpFormat = new SharpFormat () ;
1245 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1253 loadSuccess = sharpFormat->load( calendar, mCalendar );
1246 1254
1247 } else 1255 } else
1248#endif 1256#endif
1249 if ( mode == 1 ) { // phone 1257 if ( mode == 1 ) { // phone
1250 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1258 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1251 mSyncManager->mPhoneDevice, 1259 mSyncManager->mPhoneDevice,
1252 mSyncManager->mPhoneConnection, 1260 mSyncManager->mPhoneConnection,
1253 mSyncManager->mPhoneModel); 1261 mSyncManager->mPhoneModel);
1254 loadSuccess = phoneFormat->load( calendar,mCalendar); 1262 loadSuccess = phoneFormat->load( calendar,mCalendar);
1255 1263
1256 } else 1264 } else
1257 return; 1265 return;
1258 if ( loadSuccess ) { 1266 if ( loadSuccess ) {
1259 getEventViewerDialog()->setSyncMode( true ); 1267 getEventViewerDialog()->setSyncMode( true );
1260 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1268 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1261 getEventViewerDialog()->setSyncMode( false ); 1269 getEventViewerDialog()->setSyncMode( false );
1262 qApp->processEvents(); 1270 qApp->processEvents();
1263 if ( syncOK ) { 1271 if ( syncOK ) {
1264 if ( mSyncManager->mWriteBackFile ) 1272 if ( mSyncManager->mWriteBackFile )
1265 { 1273 {
1266 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1274 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1267 Incidence* inc = iL.first(); 1275 Incidence* inc = iL.first();
1268 if ( phoneFormat ) { 1276 if ( phoneFormat ) {
1269 while ( inc ) { 1277 while ( inc ) {
1270 inc->removeID(mCurrentSyncDevice); 1278 inc->removeID(mCurrentSyncDevice);
1271 inc = iL.next(); 1279 inc = iL.next();
1272 } 1280 }
1273 } 1281 }
1274#ifndef DESKTOP_VERSION 1282#ifndef DESKTOP_VERSION
1275 if ( sharpFormat ) 1283 if ( sharpFormat )
1276 sharpFormat->save(calendar); 1284 sharpFormat->save(calendar);
1277#endif 1285#endif
1278 if ( phoneFormat ) 1286 if ( phoneFormat )
1279 phoneFormat->save(calendar); 1287 phoneFormat->save(calendar);
1280 iL = calendar->rawIncidences(); 1288 iL = calendar->rawIncidences();
1281 inc = iL.first(); 1289 inc = iL.first();
1282 Incidence* loc; 1290 Incidence* loc;
1283 while ( inc ) { 1291 while ( inc ) {
1284 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1292 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index a3977d7..eeb5f48 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,441 +1,457 @@
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 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h" 33#include "syncdefines.h"
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); 41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") );
42} 42}
43 43
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void Calendar::init()
52{ 52{
53 mObserver = 0; 53 mObserver = 0;
54 mNewObserver = false; 54 mNewObserver = false;
55 55
56 mModified = false; 56 mModified = false;
57 57
58 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
62 62
63 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 64 // even that good of one at that.
65// srandom(time(0)); 65// srandom(time(0));
66 66
67 // user information... 67 // user information...
68 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
70 70
71#if 0 71#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 75 extern long int timezone;
76 struct tm *now; 76 struct tm *now;
77 time_t curtime; 77 time_t curtime;
78 curtime = time(0); 78 curtime = time(0);
79 now = localtime(&curtime); 79 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 81 if (now->tm_isdst)
82 hourOff += 1; 82 hourOff += 1;
83 QString tzStr; 83 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
85 hourOff, 85 hourOff,
86 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
87 87
88 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
89 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 91 } else {
92 tzStr = tmpStr; 92 tzStr = tmpStr;
93 } 93 }
94 94
95 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 101 }
102 102
103 setTimeZone(tzStr); 103 setTimeZone(tzStr);
104#endif 104#endif
105 105
106// KOPrefs::instance()->writeConfig(); 106// KOPrefs::instance()->writeConfig();
107} 107}
108 108
109Calendar::~Calendar() 109Calendar::~Calendar()
110{ 110{
111 delete mDefaultFilter; 111 delete mDefaultFilter;
112} 112}
113 113
114const QString &Calendar::getOwner() const 114const QString &Calendar::getOwner() const
115{ 115{
116 return mOwner; 116 return mOwner;
117} 117}
118 118
119void Calendar::setOwner(const QString &os) 119void Calendar::setOwner(const QString &os)
120{ 120{
121 int i; 121 int i;
122 mOwner = os; 122 mOwner = os;
123 i = mOwner.find(','); 123 i = mOwner.find(',');
124 if (i != -1) 124 if (i != -1)
125 mOwner = mOwner.left(i); 125 mOwner = mOwner.left(i);
126 126
127 setModified( true ); 127 setModified( true );
128} 128}
129 129
130void Calendar::setTimeZone(const QString & tz) 130void Calendar::setTimeZone(const QString & tz)
131{ 131{
132 bool neg = FALSE; 132 bool neg = FALSE;
133 int hours, minutes; 133 int hours, minutes;
134 QString tmpStr(tz); 134 QString tmpStr(tz);
135 135
136 if (tmpStr.left(1) == "-") 136 if (tmpStr.left(1) == "-")
137 neg = TRUE; 137 neg = TRUE;
138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
139 tmpStr.remove(0, 1); 139 tmpStr.remove(0, 1);
140 hours = tmpStr.left(2).toInt(); 140 hours = tmpStr.left(2).toInt();
141 if (tmpStr.length() > 2) 141 if (tmpStr.length() > 2)
142 minutes = tmpStr.right(2).toInt(); 142 minutes = tmpStr.right(2).toInt();
143 else 143 else
144 minutes = 0; 144 minutes = 0;
145 mTimeZone = (60*hours+minutes); 145 mTimeZone = (60*hours+minutes);
146 if (neg) 146 if (neg)
147 mTimeZone = -mTimeZone; 147 mTimeZone = -mTimeZone;
148 mLocalTime = false; 148 mLocalTime = false;
149 149
150 setModified( true ); 150 setModified( true );
151} 151}
152 152
153QString Calendar::getTimeZoneStr() const 153QString Calendar::getTimeZoneStr() const
154{ 154{
155 if (mLocalTime) 155 if (mLocalTime)
156 return ""; 156 return "";
157 QString tmpStr; 157 QString tmpStr;
158 int hours = abs(mTimeZone / 60); 158 int hours = abs(mTimeZone / 60);
159 int minutes = abs(mTimeZone % 60); 159 int minutes = abs(mTimeZone % 60);
160 bool neg = mTimeZone < 0; 160 bool neg = mTimeZone < 0;
161 161
162 tmpStr.sprintf("%c%.2d%.2d", 162 tmpStr.sprintf("%c%.2d%.2d",
163 (neg ? '-' : '+'), 163 (neg ? '-' : '+'),
164 hours, minutes); 164 hours, minutes);
165 return tmpStr; 165 return tmpStr;
166} 166}
167 167
168void Calendar::setTimeZone(int tz) 168void Calendar::setTimeZone(int tz)
169{ 169{
170 mTimeZone = tz; 170 mTimeZone = tz;
171 mLocalTime = false; 171 mLocalTime = false;
172 172
173 setModified( true ); 173 setModified( true );
174} 174}
175 175
176int Calendar::getTimeZone() const 176int Calendar::getTimeZone() const
177{ 177{
178 return mTimeZone; 178 return mTimeZone;
179} 179}
180 180
181void Calendar::setTimeZoneId(const QString &id) 181void Calendar::setTimeZoneId(const QString &id)
182{ 182{
183 mTimeZoneId = id; 183 mTimeZoneId = id;
184 mLocalTime = false; 184 mLocalTime = false;
185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
186 if ( mTimeZone > 1000) 186 if ( mTimeZone > 1000)
187 setLocalTime(); 187 setLocalTime();
188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
189 setModified( true ); 189 setModified( true );
190} 190}
191 191
192QString Calendar::timeZoneId() const 192QString Calendar::timeZoneId() const
193{ 193{
194 return mTimeZoneId; 194 return mTimeZoneId;
195} 195}
196 196
197void Calendar::setLocalTime() 197void Calendar::setLocalTime()
198{ 198{
199 //qDebug("Calendar::setLocalTime() "); 199 //qDebug("Calendar::setLocalTime() ");
200 mLocalTime = true; 200 mLocalTime = true;
201 mTimeZone = 0; 201 mTimeZone = 0;
202 mTimeZoneId = ""; 202 mTimeZoneId = "";
203 203
204 setModified( true ); 204 setModified( true );
205} 205}
206 206
207bool Calendar::isLocalTime() const 207bool Calendar::isLocalTime() const
208{ 208{
209 return mLocalTime; 209 return mLocalTime;
210} 210}
211 211
212const QString &Calendar::getEmail() 212const QString &Calendar::getEmail()
213{ 213{
214 return mOwnerEmail; 214 return mOwnerEmail;
215} 215}
216 216
217void Calendar::setEmail(const QString &e) 217void Calendar::setEmail(const QString &e)
218{ 218{
219 mOwnerEmail = e; 219 mOwnerEmail = e;
220 220
221 setModified( true ); 221 setModified( true );
222} 222}
223 223
224void Calendar::setFilter(CalFilter *filter) 224void Calendar::setFilter(CalFilter *filter)
225{ 225{
226 mFilter = filter; 226 mFilter = filter;
227} 227}
228 228
229CalFilter *Calendar::filter() 229CalFilter *Calendar::filter()
230{ 230{
231 return mFilter; 231 return mFilter;
232} 232}
233 233
234QPtrList<Incidence> Calendar::incidences() 234QPtrList<Incidence> Calendar::incidences()
235{ 235{
236 QPtrList<Incidence> incidences; 236 QPtrList<Incidence> incidences;
237 237
238 Incidence *i; 238 Incidence *i;
239 239
240 QPtrList<Event> e = events(); 240 QPtrList<Event> e = events();
241 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 241 for( i = e.first(); i; i = e.next() ) incidences.append( i );
242 242
243 QPtrList<Todo> t = todos(); 243 QPtrList<Todo> t = todos();
244 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 244 for( i = t.first(); i; i = t.next() ) incidences.append( i );
245 245
246 QPtrList<Journal> j = journals(); 246 QPtrList<Journal> j = journals();
247 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 247 for( i = j.first(); i; i = j.next() ) incidences.append( i );
248 248
249 return incidences; 249 return incidences;
250} 250}
251
252void Calendar::resetPilotStat()
253{
254 QPtrList<Incidence> incidences;
255
256 Incidence *i;
257
258 QPtrList<Event> e = rawEvents();
259 for( i = e.first(); i; i = e.next() ) i->setPilotId( 0 );
260
261 QPtrList<Todo> t = rawTodos();
262 for( i = t.first(); i; i = t.next() ) i->setPilotId( 0 );
263
264 QPtrList<Journal> j = journals();
265 for( i = j.first(); i; i = j.next() ) i->setPilotId( 0 );
266}
251void Calendar::resetTempSyncStat() 267void Calendar::resetTempSyncStat()
252{ 268{
253 QPtrList<Incidence> incidences; 269 QPtrList<Incidence> incidences;
254 270
255 Incidence *i; 271 Incidence *i;
256 272
257 QPtrList<Event> e = rawEvents(); 273 QPtrList<Event> e = rawEvents();
258 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 274 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
259 275
260 QPtrList<Todo> t = rawTodos(); 276 QPtrList<Todo> t = rawTodos();
261 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 277 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
262 278
263 QPtrList<Journal> j = journals(); 279 QPtrList<Journal> j = journals();
264 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 280 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
265} 281}
266QPtrList<Incidence> Calendar::rawIncidences() 282QPtrList<Incidence> Calendar::rawIncidences()
267{ 283{
268 QPtrList<Incidence> incidences; 284 QPtrList<Incidence> incidences;
269 285
270 Incidence *i; 286 Incidence *i;
271 287
272 QPtrList<Event> e = rawEvents(); 288 QPtrList<Event> e = rawEvents();
273 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 289 for( i = e.first(); i; i = e.next() ) incidences.append( i );
274 290
275 QPtrList<Todo> t = rawTodos(); 291 QPtrList<Todo> t = rawTodos();
276 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 292 for( i = t.first(); i; i = t.next() ) incidences.append( i );
277 293
278 QPtrList<Journal> j = journals(); 294 QPtrList<Journal> j = journals();
279 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 295 for( i = j.first(); i; i = j.next() ) incidences.append( i );
280 296
281 return incidences; 297 return incidences;
282} 298}
283 299
284QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 300QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
285{ 301{
286 QPtrList<Event> el = rawEventsForDate(date,sorted); 302 QPtrList<Event> el = rawEventsForDate(date,sorted);
287 mFilter->apply(&el); 303 mFilter->apply(&el);
288 return el; 304 return el;
289} 305}
290 306
291QPtrList<Event> Calendar::events( const QDateTime &qdt ) 307QPtrList<Event> Calendar::events( const QDateTime &qdt )
292{ 308{
293 QPtrList<Event> el = rawEventsForDate(qdt); 309 QPtrList<Event> el = rawEventsForDate(qdt);
294 mFilter->apply(&el); 310 mFilter->apply(&el);
295 return el; 311 return el;
296} 312}
297 313
298QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 314QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
299 bool inclusive) 315 bool inclusive)
300{ 316{
301 QPtrList<Event> el = rawEvents(start,end,inclusive); 317 QPtrList<Event> el = rawEvents(start,end,inclusive);
302 mFilter->apply(&el); 318 mFilter->apply(&el);
303 return el; 319 return el;
304} 320}
305 321
306QPtrList<Event> Calendar::events() 322QPtrList<Event> Calendar::events()
307{ 323{
308 QPtrList<Event> el = rawEvents(); 324 QPtrList<Event> el = rawEvents();
309 mFilter->apply(&el); 325 mFilter->apply(&el);
310 return el; 326 return el;
311} 327}
312 328
313 329
314bool Calendar::addIncidence(Incidence *i) 330bool Calendar::addIncidence(Incidence *i)
315{ 331{
316 Incidence::AddVisitor<Calendar> v(this); 332 Incidence::AddVisitor<Calendar> v(this);
317 333
318 return i->accept(v); 334 return i->accept(v);
319} 335}
320void Calendar::deleteIncidence(Incidence *in) 336void Calendar::deleteIncidence(Incidence *in)
321{ 337{
322 if ( in->type() == "Event" ) 338 if ( in->type() == "Event" )
323 deleteEvent( (Event*) in ); 339 deleteEvent( (Event*) in );
324 else if ( in->type() =="Todo" ) 340 else if ( in->type() =="Todo" )
325 deleteTodo( (Todo*) in); 341 deleteTodo( (Todo*) in);
326 else if ( in->type() =="Journal" ) 342 else if ( in->type() =="Journal" )
327 deleteJournal( (Journal*) in ); 343 deleteJournal( (Journal*) in );
328} 344}
329 345
330Incidence* Calendar::incidence( const QString& uid ) 346Incidence* Calendar::incidence( const QString& uid )
331{ 347{
332 Incidence* i; 348 Incidence* i;
333 349
334 if( (i = todo( uid )) != 0 ) 350 if( (i = todo( uid )) != 0 )
335 return i; 351 return i;
336 if( (i = event( uid )) != 0 ) 352 if( (i = event( uid )) != 0 )
337 return i; 353 return i;
338 if( (i = journal( uid )) != 0 ) 354 if( (i = journal( uid )) != 0 )
339 return i; 355 return i;
340 356
341 return 0; 357 return 0;
342} 358}
343 359
344QPtrList<Todo> Calendar::todos() 360QPtrList<Todo> Calendar::todos()
345{ 361{
346 QPtrList<Todo> tl = rawTodos(); 362 QPtrList<Todo> tl = rawTodos();
347 mFilter->apply( &tl ); 363 mFilter->apply( &tl );
348 return tl; 364 return tl;
349} 365}
350 366
351// When this is called, the todo have already been added to the calendar. 367// When this is called, the todo have already been added to the calendar.
352// This method is only about linking related todos 368// This method is only about linking related todos
353void Calendar::setupRelations( Incidence *incidence ) 369void Calendar::setupRelations( Incidence *incidence )
354{ 370{
355 QString uid = incidence->uid(); 371 QString uid = incidence->uid();
356 //qDebug("Calendar::setupRelations "); 372 //qDebug("Calendar::setupRelations ");
357 // First, go over the list of orphans and see if this is their parent 373 // First, go over the list of orphans and see if this is their parent
358 while( Incidence* i = mOrphans[ uid ] ) { 374 while( Incidence* i = mOrphans[ uid ] ) {
359 mOrphans.remove( uid ); 375 mOrphans.remove( uid );
360 i->setRelatedTo( incidence ); 376 i->setRelatedTo( incidence );
361 incidence->addRelation( i ); 377 incidence->addRelation( i );
362 mOrphanUids.remove( i->uid() ); 378 mOrphanUids.remove( i->uid() );
363 } 379 }
364 380
365 // Now see about this incidences parent 381 // Now see about this incidences parent
366 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 382 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
367 // This incidence has a uid it is related to, but is not registered to it yet 383 // This incidence has a uid it is related to, but is not registered to it yet
368 // Try to find it 384 // Try to find it
369 Incidence* parent = this->incidence( incidence->relatedToUid() ); 385 Incidence* parent = this->incidence( incidence->relatedToUid() );
370 if( parent ) { 386 if( parent ) {
371 // Found it 387 // Found it
372 incidence->setRelatedTo( parent ); 388 incidence->setRelatedTo( parent );
373 parent->addRelation( incidence ); 389 parent->addRelation( incidence );
374 } else { 390 } else {
375 // Not found, put this in the mOrphans list 391 // Not found, put this in the mOrphans list
376 mOrphans.insert( incidence->relatedToUid(), incidence ); 392 mOrphans.insert( incidence->relatedToUid(), incidence );
377 mOrphanUids.insert( incidence->uid(), incidence ); 393 mOrphanUids.insert( incidence->uid(), incidence );
378 } 394 }
379 } 395 }
380} 396}
381 397
382// If a task with subtasks is deleted, move it's subtasks to the orphans list 398// If a task with subtasks is deleted, move it's subtasks to the orphans list
383void Calendar::removeRelations( Incidence *incidence ) 399void Calendar::removeRelations( Incidence *incidence )
384{ 400{
385 // qDebug("Calendar::removeRelations "); 401 // qDebug("Calendar::removeRelations ");
386 QString uid = incidence->uid(); 402 QString uid = incidence->uid();
387 403
388 QPtrList<Incidence> relations = incidence->relations(); 404 QPtrList<Incidence> relations = incidence->relations();
389 for( Incidence* i = relations.first(); i; i = relations.next() ) 405 for( Incidence* i = relations.first(); i; i = relations.next() )
390 if( !mOrphanUids.find( i->uid() ) ) { 406 if( !mOrphanUids.find( i->uid() ) ) {
391 mOrphans.insert( uid, i ); 407 mOrphans.insert( uid, i );
392 mOrphanUids.insert( i->uid(), i ); 408 mOrphanUids.insert( i->uid(), i );
393 i->setRelatedTo( 0 ); 409 i->setRelatedTo( 0 );
394 i->setRelatedToUid( uid ); 410 i->setRelatedToUid( uid );
395 } 411 }
396 412
397 // If this incidence is related to something else, tell that about it 413 // If this incidence is related to something else, tell that about it
398 if( incidence->relatedTo() ) 414 if( incidence->relatedTo() )
399 incidence->relatedTo()->removeRelation( incidence ); 415 incidence->relatedTo()->removeRelation( incidence );
400 416
401 // Remove this one from the orphans list 417 // Remove this one from the orphans list
402 if( mOrphanUids.remove( uid ) ) 418 if( mOrphanUids.remove( uid ) )
403 // This incidence is located in the orphans list - it should be removed 419 // This incidence is located in the orphans list - it should be removed
404 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 420 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
405 // Removing wasn't that easy 421 // Removing wasn't that easy
406 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 422 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
407 if( it.current()->uid() == uid ) { 423 if( it.current()->uid() == uid ) {
408 mOrphans.remove( it.currentKey() ); 424 mOrphans.remove( it.currentKey() );
409 break; 425 break;
410 } 426 }
411 } 427 }
412 } 428 }
413} 429}
414 430
415void Calendar::registerObserver( Observer *observer ) 431void Calendar::registerObserver( Observer *observer )
416{ 432{
417 mObserver = observer; 433 mObserver = observer;
418 mNewObserver = true; 434 mNewObserver = true;
419} 435}
420 436
421void Calendar::setModified( bool modified ) 437void Calendar::setModified( bool modified )
422{ 438{
423 if ( mObserver ) mObserver->calendarModified( modified, this ); 439 if ( mObserver ) mObserver->calendarModified( modified, this );
424 if ( modified != mModified || mNewObserver ) { 440 if ( modified != mModified || mNewObserver ) {
425 mNewObserver = false; 441 mNewObserver = false;
426 // if ( mObserver ) mObserver->calendarModified( modified, this ); 442 // if ( mObserver ) mObserver->calendarModified( modified, this );
427 mModified = modified; 443 mModified = modified;
428 } 444 }
429} 445}
430 446
431void Calendar::setLoadedProductId( const QString &id ) 447void Calendar::setLoadedProductId( const QString &id )
432{ 448{
433 mLoadedProductId = id; 449 mLoadedProductId = id;
434} 450}
435 451
436QString Calendar::loadedProductId() 452QString Calendar::loadedProductId()
437{ 453{
438 return mLoadedProductId; 454 return mLoadedProductId;
439} 455}
440 456
441//#include "calendar.moc" 457//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index c45d81f..d5294eb 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,325 +1,326 @@
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) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 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 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 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 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 void deleteIncidence(Incidence *in); 68 void deleteIncidence(Incidence *in);
69 void resetTempSyncStat(); 69 void resetTempSyncStat();
70 void resetPilotStat();
70 /** 71 /**
71 Clears out the current calendar, freeing all used memory etc. 72 Clears out the current calendar, freeing all used memory etc.
72 */ 73 */
73 virtual void close() = 0; 74 virtual void close() = 0;
74 75
75 /** 76 /**
76 Sync changes in memory to persistant storage. 77 Sync changes in memory to persistant storage.
77 */ 78 */
78 virtual void save() = 0; 79 virtual void save() = 0;
79 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 80 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
80 virtual bool isSaving() { return false; } 81 virtual bool isSaving() { return false; }
81 82
82 /** 83 /**
83 Return the owner of the calendar's full name. 84 Return the owner of the calendar's full name.
84 */ 85 */
85 const QString &getOwner() const; 86 const QString &getOwner() const;
86 /** 87 /**
87 Set the owner of the calendar. Should be owner's full name. 88 Set the owner of the calendar. Should be owner's full name.
88 */ 89 */
89 void setOwner( const QString &os ); 90 void setOwner( const QString &os );
90 /** 91 /**
91 Return the email address of the calendar owner. 92 Return the email address of the calendar owner.
92 */ 93 */
93 const QString &getEmail(); 94 const QString &getEmail();
94 /** 95 /**
95 Set the email address of the calendar owner. 96 Set the email address of the calendar owner.
96 */ 97 */
97 void setEmail( const QString & ); 98 void setEmail( const QString & );
98 99
99 /** 100 /**
100 Set time zone from a timezone string (e.g. -2:00) 101 Set time zone from a timezone string (e.g. -2:00)
101 */ 102 */
102 void setTimeZone( const QString &tz ); 103 void setTimeZone( const QString &tz );
103 /** 104 /**
104 Set time zone from a minutes value (e.g. -60) 105 Set time zone from a minutes value (e.g. -60)
105 */ 106 */
106 void setTimeZone( int tz ); 107 void setTimeZone( int tz );
107 /** 108 /**
108 Return time zone as offest in minutes. 109 Return time zone as offest in minutes.
109 */ 110 */
110 int getTimeZone() const; 111 int getTimeZone() const;
111 /** 112 /**
112 Compute an ISO 8601 format string from the time zone. 113 Compute an ISO 8601 format string from the time zone.
113 */ 114 */
114 QString getTimeZoneStr() const; 115 QString getTimeZoneStr() const;
115 /** 116 /**
116 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 117 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
117 values). 118 values).
118 */ 119 */
119 void setTimeZoneId( const QString & ); 120 void setTimeZoneId( const QString & );
120 /** 121 /**
121 Return time zone id. 122 Return time zone id.
122 */ 123 */
123 QString timeZoneId() const; 124 QString timeZoneId() const;
124 /** 125 /**
125 Use local time, not UTC or a time zone. 126 Use local time, not UTC or a time zone.
126 */ 127 */
127 void setLocalTime(); 128 void setLocalTime();
128 /** 129 /**
129 Return whether local time is being used. 130 Return whether local time is being used.
130 */ 131 */
131 bool isLocalTime() const; 132 bool isLocalTime() const;
132 133
133 /** 134 /**
134 Add an incidence to calendar. 135 Add an incidence to calendar.
135 136
136 @return true on success, false on error. 137 @return true on success, false on error.
137 */ 138 */
138 virtual bool addIncidence( Incidence * ); 139 virtual bool addIncidence( Incidence * );
139 /** 140 /**
140 Return filtered list of all incidences of this calendar. 141 Return filtered list of all incidences of this calendar.
141 */ 142 */
142 virtual QPtrList<Incidence> incidences(); 143 virtual QPtrList<Incidence> incidences();
143 144
144 /** 145 /**
145 Return unfiltered list of all incidences of this calendar. 146 Return unfiltered list of all incidences of this calendar.
146 */ 147 */
147 virtual QPtrList<Incidence> rawIncidences(); 148 virtual QPtrList<Incidence> rawIncidences();
148 149
149 /** 150 /**
150 Adds a Event to this calendar object. 151 Adds a Event to this calendar object.
151 @param anEvent a pointer to the event to add 152 @param anEvent a pointer to the event to add
152 153
153 @return true on success, false on error. 154 @return true on success, false on error.
154 */ 155 */
155 virtual bool addEventNoDup( Event *event ) = 0; 156 virtual bool addEventNoDup( Event *event ) = 0;
156 virtual bool addAnniversaryNoDup( Event *event ) = 0; 157 virtual bool addAnniversaryNoDup( Event *event ) = 0;
157 virtual bool addEvent( Event *anEvent ) = 0; 158 virtual bool addEvent( Event *anEvent ) = 0;
158 /** 159 /**
159 Delete event from calendar. 160 Delete event from calendar.
160 */ 161 */
161 virtual void deleteEvent( Event * ) = 0; 162 virtual void deleteEvent( Event * ) = 0;
162 /** 163 /**
163 Retrieves an event on the basis of the unique string ID. 164 Retrieves an event on the basis of the unique string ID.
164 */ 165 */
165 virtual Event *event( const QString &UniqueStr ) = 0; 166 virtual Event *event( const QString &UniqueStr ) = 0;
166 virtual Event *event( QString, QString ) = 0; 167 virtual Event *event( QString, QString ) = 0;
167 /** 168 /**
168 Builds and then returns a list of all events that match for the 169 Builds and then returns a list of all events that match for the
169 date specified. useful for dayView, etc. etc. 170 date specified. useful for dayView, etc. etc.
170 The calendar filter is applied. 171 The calendar filter is applied.
171 */ 172 */
172 QPtrList<Event> events( const QDate &date, bool sorted = false); 173 QPtrList<Event> events( const QDate &date, bool sorted = false);
173 /** 174 /**
174 Get events, which occur on the given date. 175 Get events, which occur on the given date.
175 The calendar filter is applied. 176 The calendar filter is applied.
176 */ 177 */
177 QPtrList<Event> events( const QDateTime &qdt ); 178 QPtrList<Event> events( const QDateTime &qdt );
178 /** 179 /**
179 Get events in a range of dates. If inclusive is set to true, only events 180 Get events in a range of dates. If inclusive is set to true, only events
180 are returned, which are completely included in the range. 181 are returned, which are completely included in the range.
181 The calendar filter is applied. 182 The calendar filter is applied.
182 */ 183 */
183 QPtrList<Event> events( const QDate &start, const QDate &end, 184 QPtrList<Event> events( const QDate &start, const QDate &end,
184 bool inclusive = false); 185 bool inclusive = false);
185 /** 186 /**
186 Return filtered list of all events in calendar. 187 Return filtered list of all events in calendar.
187 */ 188 */
188 virtual QPtrList<Event> events(); 189 virtual QPtrList<Event> events();
189 /** 190 /**
190 Return unfiltered list of all events in calendar. 191 Return unfiltered list of all events in calendar.
191 */ 192 */
192 virtual QPtrList<Event> rawEvents() = 0; 193 virtual QPtrList<Event> rawEvents() = 0;
193 194
194 /** 195 /**
195 Add a todo to the todolist. 196 Add a todo to the todolist.
196 197
197 @return true on success, false on error. 198 @return true on success, false on error.
198 */ 199 */
199 virtual bool addTodo( Todo *todo ) = 0; 200 virtual bool addTodo( Todo *todo ) = 0;
200 virtual bool addTodoNoDup( Todo *todo ) = 0; 201 virtual bool addTodoNoDup( Todo *todo ) = 0;
201 /** 202 /**
202 Remove a todo from the todolist. 203 Remove a todo from the todolist.
203 */ 204 */
204 virtual void deleteTodo( Todo * ) = 0; 205 virtual void deleteTodo( Todo * ) = 0;
205 virtual void deleteJournal( Journal * ) = 0; 206 virtual void deleteJournal( Journal * ) = 0;
206 /** 207 /**
207 Return filterd list of todos. 208 Return filterd list of todos.
208 */ 209 */
209 virtual QPtrList<Todo> todos(); 210 virtual QPtrList<Todo> todos();
210 /** 211 /**
211 Searches todolist for an event with this unique string identifier, 212 Searches todolist for an event with this unique string identifier,
212 returns a pointer or null. 213 returns a pointer or null.
213 */ 214 */
214 virtual Todo *todo( const QString &uid ) = 0; 215 virtual Todo *todo( const QString &uid ) = 0;
215 virtual Todo *todo( QString, QString ) = 0; 216 virtual Todo *todo( QString, QString ) = 0;
216 /** 217 /**
217 Returns list of todos due on the specified date. 218 Returns list of todos due on the specified date.
218 */ 219 */
219 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 220 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
220 /** 221 /**
221 Return unfiltered list of todos. 222 Return unfiltered list of todos.
222 */ 223 */
223 virtual QPtrList<Todo> rawTodos() = 0; 224 virtual QPtrList<Todo> rawTodos() = 0;
224 225
225 /** 226 /**
226 Add a Journal entry to calendar. 227 Add a Journal entry to calendar.
227 228
228 @return true on success, false on error. 229 @return true on success, false on error.
229 */ 230 */
230 virtual bool addJournal( Journal * ) = 0; 231 virtual bool addJournal( Journal * ) = 0;
231 /** 232 /**
232 Return Journal for given date. 233 Return Journal for given date.
233 */ 234 */
234 virtual Journal *journal( const QDate & ) = 0; 235 virtual Journal *journal( const QDate & ) = 0;
235 /** 236 /**
236 Return Journal with given UID. 237 Return Journal with given UID.
237 */ 238 */
238 virtual Journal *journal( const QString &UID ) = 0; 239 virtual Journal *journal( const QString &UID ) = 0;
239 /** 240 /**
240 Return list of all Journal entries. 241 Return list of all Journal entries.
241 */ 242 */
242 virtual QPtrList<Journal> journals() = 0; 243 virtual QPtrList<Journal> journals() = 0;
243 244
244 /** 245 /**
245 Searches all incidence types for an incidence with this unique 246 Searches all incidence types for an incidence with this unique
246 string identifier, returns a pointer or null. 247 string identifier, returns a pointer or null.
247 */ 248 */
248 Incidence* incidence( const QString&UID ); 249 Incidence* incidence( const QString&UID );
249 250
250 /** 251 /**
251 Setup relations for an incidence. 252 Setup relations for an incidence.
252 */ 253 */
253 virtual void setupRelations( Incidence * ); 254 virtual void setupRelations( Incidence * );
254 /** 255 /**
255 Remove all relations to an incidence 256 Remove all relations to an incidence
256 */ 257 */
257 virtual void removeRelations( Incidence * ); 258 virtual void removeRelations( Incidence * );
258 259
259 /** 260 /**
260 Set calendar filter, which filters events for the events() functions. 261 Set calendar filter, which filters events for the events() functions.
261 The Filter object is owned by the caller. 262 The Filter object is owned by the caller.
262 */ 263 */
263 void setFilter( CalFilter * ); 264 void setFilter( CalFilter * );
264 /** 265 /**
265 Return calendar filter. 266 Return calendar filter.
266 */ 267 */
267 CalFilter *filter(); 268 CalFilter *filter();
268 virtual QDateTime nextAlarm( int daysTo ) = 0; 269 virtual QDateTime nextAlarm( int daysTo ) = 0;
269 virtual QString nextSummary( ) const = 0; 270 virtual QString nextSummary( ) const = 0;
270 virtual void reInitAlarmSettings() = 0; 271 virtual void reInitAlarmSettings() = 0;
271 virtual QDateTime nextAlarmEventDateTime() const = 0; 272 virtual QDateTime nextAlarmEventDateTime() const = 0;
272 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 273 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
273 /** 274 /**
274 Return all alarms, which ocur in the given time interval. 275 Return all alarms, which ocur in the given time interval.
275 */ 276 */
276 virtual Alarm::List alarms( const QDateTime &from, 277 virtual Alarm::List alarms( const QDateTime &from,
277 const QDateTime &to ) = 0; 278 const QDateTime &to ) = 0;
278 279
279 class Observer { 280 class Observer {
280 public: 281 public:
281 virtual void calendarModified( bool, Calendar * ) = 0; 282 virtual void calendarModified( bool, Calendar * ) = 0;
282 }; 283 };
283 284
284 void registerObserver( Observer * ); 285 void registerObserver( Observer * );
285 286
286 void setModified( bool ); 287 void setModified( bool );
287 288
288 /** 289 /**
289 Set product id returned by loadedProductId(). This function is only 290 Set product id returned by loadedProductId(). This function is only
290 useful for the calendar loading code. 291 useful for the calendar loading code.
291 */ 292 */
292 void setLoadedProductId( const QString & ); 293 void setLoadedProductId( const QString & );
293 /** 294 /**
294 Return product id taken from file that has been loaded. Returns 295 Return product id taken from file that has been loaded. Returns
295 QString::null, if no calendar has been loaded. 296 QString::null, if no calendar has been loaded.
296 */ 297 */
297 QString loadedProductId(); 298 QString loadedProductId();
298 299
299 signals: 300 signals:
300 void calendarChanged(); 301 void calendarChanged();
301 void calendarSaved(); 302 void calendarSaved();
302 void calendarLoaded(); 303 void calendarLoaded();
303 void addAlarm(const QDateTime &qdt, const QString &noti ); 304 void addAlarm(const QDateTime &qdt, const QString &noti );
304 void removeAlarm(const QDateTime &qdt, const QString &noti ); 305 void removeAlarm(const QDateTime &qdt, const QString &noti );
305 306
306 protected: 307 protected:
307 /** 308 /**
308 Get unfiltered events, which occur on the given date. 309 Get unfiltered events, which occur on the given date.
309 */ 310 */
310 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 311 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
311 /** 312 /**
312 Get unfiltered events, which occur on the given date. 313 Get unfiltered events, which occur on the given date.
313 */ 314 */
314 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 315 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
315 bool sorted = false ) = 0; 316 bool sorted = false ) = 0;
316 /** 317 /**
317 Get events in a range of dates. If inclusive is set to true, only events 318 Get events in a range of dates. If inclusive is set to true, only events
318 are returned, which are completely included in the range. 319 are returned, which are completely included in the range.
319 */ 320 */
320 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 321 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
321 bool inclusive = false ) = 0; 322 bool inclusive = false ) = 0;
322 Incidence *mNextAlarmIncidence; 323 Incidence *mNextAlarmIncidence;
323 324
324private: 325private:
325 void init(); 326 void init();