-rw-r--r-- | korganizer/calendarview.cpp | 16 | ||||
-rw-r--r-- | libkcal/alarm.cpp | 36 | ||||
-rw-r--r-- | libkcal/recurrence.cpp | 56 | ||||
-rw-r--r-- | libkcal/sharpformat.cpp | 7 |
4 files changed, 94 insertions, 21 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 258bd43..94cc97d 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1,3155 +1,3161 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Requires the Qt and KDE widget libraries, available at no cost at | 4 | Requires the Qt and KDE widget libraries, available at no cost at |
5 | http://www.troll.no and http://www.kde.org respectively | 5 | http://www.troll.no and http://www.kde.org respectively |
6 | 6 | ||
7 | Copyright (c) 1997, 1998, 1999 | 7 | Copyright (c) 1997, 1998, 1999 |
8 | Preston Brown (preston.brown@yale.edu) | 8 | Preston Brown (preston.brown@yale.edu) |
9 | Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) | 9 | Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) |
10 | Ian Dawes (iadawes@globalserve.net) | 10 | Ian Dawes (iadawes@globalserve.net) |
11 | Laszlo Boloni (boloni@cs.purdue.edu) | 11 | Laszlo Boloni (boloni@cs.purdue.edu) |
12 | 12 | ||
13 | Copyright (c) 2000, 2001, 2002 | 13 | Copyright (c) 2000, 2001, 2002 |
14 | Cornelius Schumacher <schumacher@kde.org> | 14 | Cornelius Schumacher <schumacher@kde.org> |
15 | 15 | ||
16 | This program is free software; you can redistribute it and/or modify | 16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | 17 | it under the terms of the GNU General Public License as published by |
18 | the Free Software Foundation; either version 2 of the License, or | 18 | the Free Software Foundation; either version 2 of the License, or |
19 | (at your option) any later version. | 19 | (at your option) any later version. |
20 | 20 | ||
21 | This program is distributed in the hope that it will be useful, | 21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
24 | GNU General Public License for more details. | 24 | GNU General Public License for more details. |
25 | 25 | ||
26 | You should have received a copy of the GNU General Public License | 26 | You should have received a copy of the GNU General Public License |
27 | along with this program; if not, write to the Free Software | 27 | along with this program; if not, write to the Free Software |
28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | 32 | ||
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qradiobutton.h> | 34 | #include <qradiobutton.h> |
35 | #include <qbuttongroup.h> | 35 | #include <qbuttongroup.h> |
36 | #include <qlayout.h> | 36 | #include <qlayout.h> |
37 | #include <qclipboard.h> | 37 | #include <qclipboard.h> |
38 | #include <qcursor.h> | 38 | #include <qcursor.h> |
39 | #include <qmessagebox.h> | 39 | #include <qmessagebox.h> |
40 | #include <qprogressbar.h> | 40 | #include <qprogressbar.h> |
41 | #include <qmultilineedit.h> | 41 | #include <qmultilineedit.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qwidgetstack.h> | 43 | #include <qwidgetstack.h> |
44 | #include <qptrlist.h> | 44 | #include <qptrlist.h> |
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | #include <qgroupbox.h> | 46 | #include <qgroupbox.h> |
47 | #include <qfile.h> | 47 | #include <qfile.h> |
48 | #include <qdir.h> | 48 | #include <qdir.h> |
49 | #ifndef KORG_NOSPLITTER | 49 | #ifndef KORG_NOSPLITTER |
50 | #include <qsplitter.h> | 50 | #include <qsplitter.h> |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #include <kglobal.h> | 53 | #include <kglobal.h> |
54 | #include <kdebug.h> | 54 | #include <kdebug.h> |
55 | #include <kstandarddirs.h> | 55 | #include <kstandarddirs.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | #include <kmessagebox.h> | 57 | #include <kmessagebox.h> |
58 | #include <knotifyclient.h> | 58 | #include <knotifyclient.h> |
59 | #include <kconfig.h> | 59 | #include <kconfig.h> |
60 | 60 | ||
61 | #include <libkdepim/ksyncprefsdialog.h> | 61 | #include <libkdepim/ksyncprefsdialog.h> |
62 | #include <krun.h> | 62 | #include <krun.h> |
63 | #include <kdirwatch.h> | 63 | #include <kdirwatch.h> |
64 | #include <libkdepim/kdatepicker.h> | 64 | #include <libkdepim/kdatepicker.h> |
65 | #include <libkdepim/ksyncprofile.h> | 65 | #include <libkdepim/ksyncprofile.h> |
66 | 66 | ||
67 | #include <libkcal/vcaldrag.h> | 67 | #include <libkcal/vcaldrag.h> |
68 | #include <libkcal/icaldrag.h> | 68 | #include <libkcal/icaldrag.h> |
69 | #include <libkcal/icalformat.h> | 69 | #include <libkcal/icalformat.h> |
70 | #include <libkcal/vcalformat.h> | 70 | #include <libkcal/vcalformat.h> |
71 | #include <libkcal/scheduler.h> | 71 | #include <libkcal/scheduler.h> |
72 | #include <libkcal/calendarlocal.h> | 72 | #include <libkcal/calendarlocal.h> |
73 | #include <libkcal/journal.h> | 73 | #include <libkcal/journal.h> |
74 | #include <libkcal/calfilter.h> | 74 | #include <libkcal/calfilter.h> |
75 | #include <libkcal/attendee.h> | 75 | #include <libkcal/attendee.h> |
76 | #include <libkcal/dndfactory.h> | 76 | #include <libkcal/dndfactory.h> |
77 | #include <libkcal/freebusy.h> | 77 | #include <libkcal/freebusy.h> |
78 | #include <libkcal/filestorage.h> | 78 | #include <libkcal/filestorage.h> |
79 | #include <libkcal/calendarresources.h> | 79 | #include <libkcal/calendarresources.h> |
80 | #include <libkcal/qtopiaformat.h> | 80 | #include <libkcal/qtopiaformat.h> |
81 | #include "../kalarmd/alarmdialog.h" | 81 | #include "../kalarmd/alarmdialog.h" |
82 | 82 | ||
83 | #ifndef DESKTOP_VERSION | 83 | #ifndef DESKTOP_VERSION |
84 | #include <libkcal/sharpformat.h> | 84 | #include <libkcal/sharpformat.h> |
85 | #endif | 85 | #endif |
86 | #include <libkcal/phoneformat.h> | 86 | #include <libkcal/phoneformat.h> |
87 | #ifndef KORG_NOMAIL | 87 | #ifndef KORG_NOMAIL |
88 | #include "komailclient.h" | 88 | #include "komailclient.h" |
89 | #endif | 89 | #endif |
90 | #ifndef KORG_NOPRINTER | 90 | #ifndef KORG_NOPRINTER |
91 | #include "calprinter.h" | 91 | #include "calprinter.h" |
92 | #endif | 92 | #endif |
93 | #ifndef KORG_NOPLUGINS | 93 | #ifndef KORG_NOPLUGINS |
94 | #include "kocore.h" | 94 | #include "kocore.h" |
95 | #endif | 95 | #endif |
96 | #include "koeventeditor.h" | 96 | #include "koeventeditor.h" |
97 | #include "kotodoeditor.h" | 97 | #include "kotodoeditor.h" |
98 | #include "koprefs.h" | 98 | #include "koprefs.h" |
99 | #include "koeventviewerdialog.h" | 99 | #include "koeventviewerdialog.h" |
100 | #include "publishdialog.h" | 100 | #include "publishdialog.h" |
101 | #include "kofilterview.h" | 101 | #include "kofilterview.h" |
102 | #include "koglobals.h" | 102 | #include "koglobals.h" |
103 | #include "koviewmanager.h" | 103 | #include "koviewmanager.h" |
104 | #include "koagendaview.h" | 104 | #include "koagendaview.h" |
105 | #include "kodialogmanager.h" | 105 | #include "kodialogmanager.h" |
106 | #include "outgoingdialog.h" | 106 | #include "outgoingdialog.h" |
107 | #include "incomingdialog.h" | 107 | #include "incomingdialog.h" |
108 | #include "statusdialog.h" | 108 | #include "statusdialog.h" |
109 | #include "kdatenavigator.h" | 109 | #include "kdatenavigator.h" |
110 | #include "kotodoview.h" | 110 | #include "kotodoview.h" |
111 | #include "datenavigator.h" | 111 | #include "datenavigator.h" |
112 | #include "resourceview.h" | 112 | #include "resourceview.h" |
113 | #include "navigatorbar.h" | 113 | #include "navigatorbar.h" |
114 | #include "searchdialog.h" | 114 | #include "searchdialog.h" |
115 | #include "mainwindow.h" | 115 | #include "mainwindow.h" |
116 | 116 | ||
117 | #include "calendarview.h" | 117 | #include "calendarview.h" |
118 | #ifndef DESKTOP_VERSION | 118 | #ifndef DESKTOP_VERSION |
119 | #include <qtopia/alarmserver.h> | 119 | #include <qtopia/alarmserver.h> |
120 | #endif | 120 | #endif |
121 | #ifndef _WIN32_ | 121 | #ifndef _WIN32_ |
122 | #include <stdlib.h> | 122 | #include <stdlib.h> |
123 | #include <stdio.h> | 123 | #include <stdio.h> |
124 | #include <unistd.h> | 124 | #include <unistd.h> |
125 | #else | 125 | #else |
126 | #include <qprocess.h> | 126 | #include <qprocess.h> |
127 | #endif | 127 | #endif |
128 | using namespace KOrg; | 128 | using namespace KOrg; |
129 | using namespace KCal; | 129 | using namespace KCal; |
130 | extern int globalFlagBlockAgenda; | 130 | extern int globalFlagBlockAgenda; |
131 | extern int globalFlagBlockStartup; | 131 | extern int globalFlagBlockStartup; |
132 | 132 | ||
133 | 133 | ||
134 | 134 | ||
135 | class KOBeamPrefs : public QDialog | 135 | class KOBeamPrefs : public QDialog |
136 | { | 136 | { |
137 | public: | 137 | public: |
138 | KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : | 138 | KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : |
139 | QDialog( parent, name, true ) | 139 | QDialog( parent, name, true ) |
140 | { | 140 | { |
141 | setCaption( i18n("Beam Options") ); | 141 | setCaption( i18n("Beam Options") ); |
142 | QVBoxLayout* lay = new QVBoxLayout( this ); | 142 | QVBoxLayout* lay = new QVBoxLayout( this ); |
143 | lay->setSpacing( 3 ); | 143 | lay->setSpacing( 3 ); |
144 | lay->setMargin( 3 ); | 144 | lay->setMargin( 3 ); |
145 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); | 145 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); |
146 | lay->addWidget( format ); | 146 | lay->addWidget( format ); |
147 | format->setExclusive ( true ) ; | 147 | format->setExclusive ( true ) ; |
148 | QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); | 148 | QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); |
149 | lay->addWidget( time ); time->setExclusive ( true ) ; | 149 | lay->addWidget( time ); time->setExclusive ( true ) ; |
150 | vcal = new QRadioButton(" vCalendar ", format ); | 150 | vcal = new QRadioButton(" vCalendar ", format ); |
151 | ical = new QRadioButton(" iCalendar ", format ); | 151 | ical = new QRadioButton(" iCalendar ", format ); |
152 | vcal->setChecked( true ); | 152 | vcal->setChecked( true ); |
153 | tz = new QRadioButton(i18n(" With timezone "), time ); | 153 | tz = new QRadioButton(i18n(" With timezone "), time ); |
154 | local = new QRadioButton(i18n(" Local time "), time ); | 154 | local = new QRadioButton(i18n(" Local time "), time ); |
155 | tz->setChecked( true ); | 155 | tz->setChecked( true ); |
156 | QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); | 156 | QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); |
157 | lay->addWidget( ok ); | 157 | lay->addWidget( ok ); |
158 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 158 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
159 | lay->addWidget( cancel ); | 159 | lay->addWidget( cancel ); |
160 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 160 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
161 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 161 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
162 | resize( 200, 200 ); | 162 | resize( 200, 200 ); |
163 | } | 163 | } |
164 | 164 | ||
165 | bool beamVcal() { return vcal->isChecked(); } | 165 | bool beamVcal() { return vcal->isChecked(); } |
166 | bool beamLocal() { return local->isChecked(); } | 166 | bool beamLocal() { return local->isChecked(); } |
167 | private: | 167 | private: |
168 | QRadioButton* vcal, *ical, *local, *tz; | 168 | QRadioButton* vcal, *ical, *local, *tz; |
169 | }; | 169 | }; |
170 | class KOCatPrefs : public QDialog | 170 | class KOCatPrefs : public QDialog |
171 | { | 171 | { |
172 | public: | 172 | public: |
173 | KOCatPrefs( QWidget *parent=0, const char *name=0 ) : | 173 | KOCatPrefs( QWidget *parent=0, const char *name=0 ) : |
174 | QDialog( parent, name, true ) | 174 | QDialog( parent, name, true ) |
175 | { | 175 | { |
176 | setCaption( i18n("Manage new Categories") ); | 176 | setCaption( i18n("Manage new Categories") ); |
177 | QVBoxLayout* lay = new QVBoxLayout( this ); | 177 | QVBoxLayout* lay = new QVBoxLayout( this ); |
178 | lay->setSpacing( 3 ); | 178 | lay->setSpacing( 3 ); |
179 | lay->setMargin( 3 ); | 179 | lay->setMargin( 3 ); |
180 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); | 180 | QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); |
181 | lay->addWidget( lab ); | 181 | lay->addWidget( lab ); |
182 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); | 182 | QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); |
183 | lay->addWidget( format ); | 183 | lay->addWidget( format ); |
184 | format->setExclusive ( true ) ; | 184 | format->setExclusive ( true ) ; |
185 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); | 185 | addCatBut = new QRadioButton(i18n("Add to category list"), format ); |
186 | new QRadioButton(i18n("Remove from Events/Todos"), format ); | 186 | new QRadioButton(i18n("Remove from Events/Todos"), format ); |
187 | addCatBut->setChecked( true ); | 187 | addCatBut->setChecked( true ); |
188 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | 188 | QPushButton * ok = new QPushButton( i18n("OK"), this ); |
189 | lay->addWidget( ok ); | 189 | lay->addWidget( ok ); |
190 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | 190 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); |
191 | lay->addWidget( cancel ); | 191 | lay->addWidget( cancel ); |
192 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | 192 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); |
193 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | 193 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); |
194 | resize( 200, 200 ); | 194 | resize( 200, 200 ); |
195 | } | 195 | } |
196 | 196 | ||
197 | bool addCat() { return addCatBut->isChecked(); } | 197 | bool addCat() { return addCatBut->isChecked(); } |
198 | private: | 198 | private: |
199 | QRadioButton* addCatBut; | 199 | QRadioButton* addCatBut; |
200 | }; | 200 | }; |
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | CalendarView::CalendarView( CalendarResources *calendar, | 204 | CalendarView::CalendarView( CalendarResources *calendar, |
205 | QWidget *parent, const char *name ) | 205 | QWidget *parent, const char *name ) |
206 | : CalendarViewBase( parent, name ), | 206 | : CalendarViewBase( parent, name ), |
207 | mCalendar( calendar ), | 207 | mCalendar( calendar ), |
208 | mResourceManager( calendar->resourceManager() ) | 208 | mResourceManager( calendar->resourceManager() ) |
209 | { | 209 | { |
210 | 210 | ||
211 | mEventEditor = 0; | 211 | mEventEditor = 0; |
212 | mTodoEditor = 0; | 212 | mTodoEditor = 0; |
213 | 213 | ||
214 | init(); | 214 | init(); |
215 | } | 215 | } |
216 | 216 | ||
217 | CalendarView::CalendarView( Calendar *calendar, | 217 | CalendarView::CalendarView( Calendar *calendar, |
218 | QWidget *parent, const char *name ) | 218 | QWidget *parent, const char *name ) |
219 | : CalendarViewBase( parent, name ), | 219 | : CalendarViewBase( parent, name ), |
220 | mCalendar( calendar ), | 220 | mCalendar( calendar ), |
221 | mResourceManager( 0 ) | 221 | mResourceManager( 0 ) |
222 | { | 222 | { |
223 | 223 | ||
224 | mEventEditor = 0; | 224 | mEventEditor = 0; |
225 | mTodoEditor = 0; | 225 | mTodoEditor = 0; |
226 | init();} | 226 | init();} |
227 | 227 | ||
228 | void CalendarView::init() | 228 | void CalendarView::init() |
229 | { | 229 | { |
230 | beamDialog = new KOBeamPrefs(); | 230 | beamDialog = new KOBeamPrefs(); |
231 | mDatePickerMode = 0; | 231 | mDatePickerMode = 0; |
232 | mCurrentSyncDevice = ""; | 232 | mCurrentSyncDevice = ""; |
233 | writeLocale(); | 233 | writeLocale(); |
234 | mViewManager = new KOViewManager( this ); | 234 | mViewManager = new KOViewManager( this ); |
235 | mDialogManager = new KODialogManager( this ); | 235 | mDialogManager = new KODialogManager( this ); |
236 | mEventViewerDialog = 0; | 236 | mEventViewerDialog = 0; |
237 | mModified = false; | 237 | mModified = false; |
238 | mReadOnly = false; | 238 | mReadOnly = false; |
239 | mSelectedIncidence = 0; | 239 | mSelectedIncidence = 0; |
240 | mCalPrinter = 0; | 240 | mCalPrinter = 0; |
241 | mFilters.setAutoDelete(true); | 241 | mFilters.setAutoDelete(true); |
242 | 242 | ||
243 | mCalendar->registerObserver( this ); | 243 | mCalendar->registerObserver( this ); |
244 | // TODO: Make sure that view is updated, when calendar is changed. | 244 | // TODO: Make sure that view is updated, when calendar is changed. |
245 | 245 | ||
246 | mStorage = new FileStorage( mCalendar ); | 246 | mStorage = new FileStorage( mCalendar ); |
247 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); | 247 | mNavigator = new DateNavigator( this, "datevav", mViewManager ); |
248 | 248 | ||
249 | QBoxLayout *topLayout = (QBoxLayout*)layout(); | 249 | QBoxLayout *topLayout = (QBoxLayout*)layout(); |
250 | #ifndef KORG_NOSPLITTER | 250 | #ifndef KORG_NOSPLITTER |
251 | // create the main layout frames. | 251 | // create the main layout frames. |
252 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); | 252 | mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); |
253 | topLayout->addWidget(mPanner); | 253 | topLayout->addWidget(mPanner); |
254 | 254 | ||
255 | mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, | 255 | mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, |
256 | "CalendarView::LeftFrame"); | 256 | "CalendarView::LeftFrame"); |
257 | mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); | 257 | mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); |
258 | 258 | ||
259 | mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, | 259 | mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, |
260 | "CalendarView::DateNavigator", QDate::currentDate() ); | 260 | "CalendarView::DateNavigator", QDate::currentDate() ); |
261 | mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); | 261 | mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); |
262 | mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); | 262 | mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); |
263 | mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); | 263 | mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); |
264 | 264 | ||
265 | #ifdef KORG_NORESOURCEVIEW | 265 | #ifdef KORG_NORESOURCEVIEW |
266 | mResourceView = 0; | 266 | mResourceView = 0; |
267 | #else | 267 | #else |
268 | if ( mResourceManager ) { | 268 | if ( mResourceManager ) { |
269 | mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); | 269 | mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); |
270 | mResourceView->updateView(); | 270 | mResourceView->updateView(); |
271 | connect( mResourceView, SIGNAL( resourcesChanged() ), | 271 | connect( mResourceView, SIGNAL( resourcesChanged() ), |
272 | SLOT( updateView() ) ); | 272 | SLOT( updateView() ) ); |
273 | } else { | 273 | } else { |
274 | mResourceView = 0; | 274 | mResourceView = 0; |
275 | } | 275 | } |
276 | #endif | 276 | #endif |
277 | QWidget *rightBox = new QWidget( mPanner ); | 277 | QWidget *rightBox = new QWidget( mPanner ); |
278 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); | 278 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); |
279 | 279 | ||
280 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); | 280 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); |
281 | rightLayout->addWidget( mNavigatorBar ); | 281 | rightLayout->addWidget( mNavigatorBar ); |
282 | 282 | ||
283 | mRightFrame = new QWidgetStack( rightBox ); | 283 | mRightFrame = new QWidgetStack( rightBox ); |
284 | rightLayout->addWidget( mRightFrame, 1 ); | 284 | rightLayout->addWidget( mRightFrame, 1 ); |
285 | 285 | ||
286 | mLeftFrame = mLeftSplitter; | 286 | mLeftFrame = mLeftSplitter; |
287 | #else | 287 | #else |
288 | QWidget *mainBox = new QWidget( this ); | 288 | QWidget *mainBox = new QWidget( this ); |
289 | QWidget *leftFrame = new QWidget( mainBox ); | 289 | QWidget *leftFrame = new QWidget( mainBox ); |
290 | 290 | ||
291 | QBoxLayout * mainBoxLayout; | 291 | QBoxLayout * mainBoxLayout; |
292 | QBoxLayout * leftFrameLayout; | 292 | QBoxLayout * leftFrameLayout; |
293 | if ( KOPrefs::instance()->mVerticalScreen ) { | 293 | if ( KOPrefs::instance()->mVerticalScreen ) { |
294 | mainBoxLayout = new QVBoxLayout(mainBox); | 294 | mainBoxLayout = new QVBoxLayout(mainBox); |
295 | leftFrameLayout = new QHBoxLayout(leftFrame ); | 295 | leftFrameLayout = new QHBoxLayout(leftFrame ); |
296 | } else { | 296 | } else { |
297 | mainBoxLayout = new QHBoxLayout(mainBox); | 297 | mainBoxLayout = new QHBoxLayout(mainBox); |
298 | leftFrameLayout = new QVBoxLayout(leftFrame ); | 298 | leftFrameLayout = new QVBoxLayout(leftFrame ); |
299 | } | 299 | } |
300 | topLayout->addWidget( mainBox ); | 300 | topLayout->addWidget( mainBox ); |
301 | mainBoxLayout->addWidget (leftFrame); | 301 | mainBoxLayout->addWidget (leftFrame); |
302 | mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, | 302 | mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, |
303 | "CalendarView::DateNavigator", QDate::currentDate()); | 303 | "CalendarView::DateNavigator", QDate::currentDate()); |
304 | // mDateNavigator->blockSignals( true ); | 304 | // mDateNavigator->blockSignals( true ); |
305 | leftFrameLayout->addWidget( mDateNavigator ); | 305 | leftFrameLayout->addWidget( mDateNavigator ); |
306 | mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); | 306 | mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); |
307 | mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); | 307 | mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); |
308 | 308 | ||
309 | if ( QApplication::desktop()->width() < 480 ) { | 309 | if ( QApplication::desktop()->width() < 480 ) { |
310 | leftFrameLayout->addWidget(mFilterView); | 310 | leftFrameLayout->addWidget(mFilterView); |
311 | leftFrameLayout->addWidget(mTodoList, 2 ); | 311 | leftFrameLayout->addWidget(mTodoList, 2 ); |
312 | 312 | ||
313 | } else { | 313 | } else { |
314 | leftFrameLayout->addWidget(mTodoList,2 ); | 314 | leftFrameLayout->addWidget(mTodoList,2 ); |
315 | leftFrameLayout->addWidget(mFilterView ); | 315 | leftFrameLayout->addWidget(mFilterView ); |
316 | } | 316 | } |
317 | mFilterView->hide(); | 317 | mFilterView->hide(); |
318 | QWidget *rightBox = new QWidget( mainBox ); | 318 | QWidget *rightBox = new QWidget( mainBox ); |
319 | mainBoxLayout->addWidget ( rightBox, 10 ); | 319 | mainBoxLayout->addWidget ( rightBox, 10 ); |
320 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); | 320 | QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); |
321 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); | 321 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); |
322 | mRightFrame = new QWidgetStack( rightBox ); | 322 | mRightFrame = new QWidgetStack( rightBox ); |
323 | rightLayout->addWidget( mNavigatorBar ); | 323 | rightLayout->addWidget( mNavigatorBar ); |
324 | rightLayout->addWidget( mRightFrame, 10 ); | 324 | rightLayout->addWidget( mRightFrame, 10 ); |
325 | 325 | ||
326 | mLeftFrame = leftFrame; | 326 | mLeftFrame = leftFrame; |
327 | if ( KOPrefs::instance()->mVerticalScreen ) { | 327 | if ( KOPrefs::instance()->mVerticalScreen ) { |
328 | mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); | 328 | mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); |
329 | leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); | 329 | leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); |
330 | } else { | 330 | } else { |
331 | mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); | 331 | mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); |
332 | leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); | 332 | leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); |
333 | } | 333 | } |
334 | 334 | ||
335 | //qDebug("Calendarview Size %d %d ", width(), height()); | 335 | //qDebug("Calendarview Size %d %d ", width(), height()); |
336 | #endif | 336 | #endif |
337 | 337 | ||
338 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 338 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
339 | SLOT( showDates( const KCal::DateList & ) ) ); | 339 | SLOT( showDates( const KCal::DateList & ) ) ); |
340 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 340 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
341 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 341 | mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
342 | 342 | ||
343 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), | 343 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), |
344 | mNavigator, SLOT( selectPreviousYear() ) ); | 344 | mNavigator, SLOT( selectPreviousYear() ) ); |
345 | connect( mNavigatorBar, SIGNAL( goNextYear() ), | 345 | connect( mNavigatorBar, SIGNAL( goNextYear() ), |
346 | mNavigator, SLOT( selectNextYear() ) ); | 346 | mNavigator, SLOT( selectNextYear() ) ); |
347 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), | 347 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), |
348 | mNavigator, SLOT( selectPreviousMonth() ) ); | 348 | mNavigator, SLOT( selectPreviousMonth() ) ); |
349 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), | 349 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), |
350 | mNavigator, SLOT( selectNextMonth() ) ); | 350 | mNavigator, SLOT( selectNextMonth() ) ); |
351 | 351 | ||
352 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 352 | connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
353 | mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); | 353 | mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); |
354 | 354 | ||
355 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), | 355 | connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), |
356 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); | 356 | mNavigator, SLOT( selectWeek( const QDate & ) ) ); |
357 | 357 | ||
358 | connect( mDateNavigator, SIGNAL( goPrevYear() ), | 358 | connect( mDateNavigator, SIGNAL( goPrevYear() ), |
359 | mNavigator, SLOT( selectPreviousYear() ) ); | 359 | mNavigator, SLOT( selectPreviousYear() ) ); |
360 | connect( mDateNavigator, SIGNAL( goNextYear() ), | 360 | connect( mDateNavigator, SIGNAL( goNextYear() ), |
361 | mNavigator, SLOT( selectNextYear() ) ); | 361 | mNavigator, SLOT( selectNextYear() ) ); |
362 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), | 362 | connect( mDateNavigator, SIGNAL( goPrevMonth() ), |
363 | mNavigator, SLOT( selectPreviousMonth() ) ); | 363 | mNavigator, SLOT( selectPreviousMonth() ) ); |
364 | connect( mDateNavigator, SIGNAL( goNextMonth() ), | 364 | connect( mDateNavigator, SIGNAL( goNextMonth() ), |
365 | mNavigator, SLOT( selectNextMonth() ) ); | 365 | mNavigator, SLOT( selectNextMonth() ) ); |
366 | 366 | ||
367 | connect( mDateNavigator, SIGNAL( goPrevious() ), | 367 | connect( mDateNavigator, SIGNAL( goPrevious() ), |
368 | mNavigator, SLOT( selectPrevious() ) ); | 368 | mNavigator, SLOT( selectPrevious() ) ); |
369 | connect( mDateNavigator, SIGNAL( goNext() ), | 369 | connect( mDateNavigator, SIGNAL( goNext() ), |
370 | mNavigator, SLOT( selectNext() ) ); | 370 | mNavigator, SLOT( selectNext() ) ); |
371 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), | 371 | connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), |
372 | mNavigator, SLOT( slotMonthSelect( int ) ) ); | 372 | mNavigator, SLOT( slotMonthSelect( int ) ) ); |
373 | connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), | 373 | connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), |
374 | mNavigator, SLOT( slotMonthSelect( int ) ) ); | 374 | mNavigator, SLOT( slotMonthSelect( int ) ) ); |
375 | 375 | ||
376 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), | 376 | connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), |
377 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); | 377 | mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); |
378 | 378 | ||
379 | connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), | 379 | connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), |
380 | SLOT( eventAdded( Event *) ) ); | 380 | SLOT( eventAdded( Event *) ) ); |
381 | 381 | ||
382 | connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); | 382 | connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); |
383 | 383 | ||
384 | connect( this, SIGNAL( configChanged() ), | 384 | connect( this, SIGNAL( configChanged() ), |
385 | mDateNavigator, SLOT( updateConfig() ) ); | 385 | mDateNavigator, SLOT( updateConfig() ) ); |
386 | 386 | ||
387 | connect( mTodoList, SIGNAL( newTodoSignal() ), | 387 | connect( mTodoList, SIGNAL( newTodoSignal() ), |
388 | SLOT( newTodo() ) ); | 388 | SLOT( newTodo() ) ); |
389 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), | 389 | connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), |
390 | SLOT( newSubTodo( Todo * ) ) ); | 390 | SLOT( newSubTodo( Todo * ) ) ); |
391 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), | 391 | connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), |
392 | SLOT( editTodo( Todo * ) ) ); | 392 | SLOT( editTodo( Todo * ) ) ); |
393 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), | 393 | connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), |
394 | SLOT( showTodo( Todo *) ) ); | 394 | SLOT( showTodo( Todo *) ) ); |
395 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), | 395 | connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), |
396 | SLOT( deleteTodo( Todo *) ) ); | 396 | SLOT( deleteTodo( Todo *) ) ); |
397 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); | 397 | connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); |
398 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), | 398 | connect( mTodoList, SIGNAL( purgeCompletedSignal() ), |
399 | SLOT( purgeCompleted() ) ); | 399 | SLOT( purgeCompleted() ) ); |
400 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), | 400 | connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), |
401 | SIGNAL( todoModified( Todo *, int ) ) ); | 401 | SIGNAL( todoModified( Todo *, int ) ) ); |
402 | 402 | ||
403 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), | 403 | connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), |
404 | this, SLOT ( cloneIncidence( Incidence * ) ) ); | 404 | this, SLOT ( cloneIncidence( Incidence * ) ) ); |
405 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), | 405 | connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), |
406 | this, SLOT (cancelIncidence( Incidence * ) ) ); | 406 | this, SLOT (cancelIncidence( Incidence * ) ) ); |
407 | 407 | ||
408 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), | 408 | connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), |
409 | this, SLOT ( moveIncidence( Incidence * ) ) ); | 409 | this, SLOT ( moveIncidence( Incidence * ) ) ); |
410 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), | 410 | connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), |
411 | this, SLOT ( beamIncidence( Incidence * ) ) ); | 411 | this, SLOT ( beamIncidence( Incidence * ) ) ); |
412 | 412 | ||
413 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), | 413 | connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), |
414 | this, SLOT ( todo_unsub( Todo * ) ) ); | 414 | this, SLOT ( todo_unsub( Todo * ) ) ); |
415 | 415 | ||
416 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, | 416 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, |
417 | SLOT( updateTodo( Todo *, int ) ) ); | 417 | SLOT( updateTodo( Todo *, int ) ) ); |
418 | connect( this, SIGNAL( todoModified( Todo *, int )), this, | 418 | connect( this, SIGNAL( todoModified( Todo *, int )), this, |
419 | SLOT( changeTodoDisplay( Todo *, int ) ) ); | 419 | SLOT( changeTodoDisplay( Todo *, int ) ) ); |
420 | 420 | ||
421 | 421 | ||
422 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); | 422 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); |
423 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); | 423 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); |
424 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); | 424 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); |
425 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); | 425 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); |
426 | 426 | ||
427 | 427 | ||
428 | 428 | ||
429 | 429 | ||
430 | 430 | ||
431 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), | 431 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), |
432 | SLOT(checkClipboard())); | 432 | SLOT(checkClipboard())); |
433 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), | 433 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), |
434 | SLOT( processTodoListSelection( Incidence * ) ) ); | 434 | SLOT( processTodoListSelection( Incidence * ) ) ); |
435 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); | 435 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); |
436 | 436 | ||
437 | // kdDebug() << "CalendarView::CalendarView() done" << endl; | 437 | // kdDebug() << "CalendarView::CalendarView() done" << endl; |
438 | 438 | ||
439 | mDateFrame = new QVBox(0,0,WType_Popup); | 439 | mDateFrame = new QVBox(0,0,WType_Popup); |
440 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 440 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
441 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 441 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
442 | mDateFrame->setLineWidth(3); | 442 | mDateFrame->setLineWidth(3); |
443 | mDateFrame->hide(); | 443 | mDateFrame->hide(); |
444 | mDateFrame->setCaption( i18n( "Pick a date to display")); | 444 | mDateFrame->setCaption( i18n( "Pick a date to display")); |
445 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); | 445 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); |
446 | 446 | ||
447 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); | 447 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); |
448 | 448 | ||
449 | mEventEditor = mDialogManager->getEventEditor(); | 449 | mEventEditor = mDialogManager->getEventEditor(); |
450 | mTodoEditor = mDialogManager->getTodoEditor(); | 450 | mTodoEditor = mDialogManager->getTodoEditor(); |
451 | 451 | ||
452 | mFlagEditDescription = false; | 452 | mFlagEditDescription = false; |
453 | 453 | ||
454 | mSuspendTimer = new QTimer( this ); | 454 | mSuspendTimer = new QTimer( this ); |
455 | mAlarmTimer = new QTimer( this ); | 455 | mAlarmTimer = new QTimer( this ); |
456 | mRecheckAlarmTimer = new QTimer( this ); | 456 | mRecheckAlarmTimer = new QTimer( this ); |
457 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); | 457 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); |
458 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); | 458 | connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); |
459 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); | 459 | connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); |
460 | mAlarmDialog = new AlarmDialog( this ); | 460 | mAlarmDialog = new AlarmDialog( this ); |
461 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); | 461 | connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); |
462 | mAlarmDialog->setServerNotification( false ); | 462 | mAlarmDialog->setServerNotification( false ); |
463 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); | 463 | mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | CalendarView::~CalendarView() | 467 | CalendarView::~CalendarView() |
468 | { | 468 | { |
469 | // kdDebug() << "~CalendarView()" << endl; | 469 | // kdDebug() << "~CalendarView()" << endl; |
470 | //qDebug("CalendarView::~CalendarView() "); | 470 | //qDebug("CalendarView::~CalendarView() "); |
471 | delete mDialogManager; | 471 | delete mDialogManager; |
472 | delete mViewManager; | 472 | delete mViewManager; |
473 | delete mStorage; | 473 | delete mStorage; |
474 | delete mDateFrame ; | 474 | delete mDateFrame ; |
475 | delete beamDialog; | 475 | delete beamDialog; |
476 | //kdDebug() << "~CalendarView() done" << endl; | 476 | //kdDebug() << "~CalendarView() done" << endl; |
477 | } | 477 | } |
478 | void CalendarView::timerAlarm() | 478 | void CalendarView::timerAlarm() |
479 | { | 479 | { |
480 | //qDebug("CalendarView::timerAlarm() "); | 480 | //qDebug("CalendarView::timerAlarm() "); |
481 | computeAlarm(mAlarmNotification ); | 481 | computeAlarm(mAlarmNotification ); |
482 | } | 482 | } |
483 | 483 | ||
484 | void CalendarView::suspendAlarm() | 484 | void CalendarView::suspendAlarm() |
485 | { | 485 | { |
486 | //qDebug(" CalendarView::suspendAlarm() "); | 486 | //qDebug(" CalendarView::suspendAlarm() "); |
487 | computeAlarm(mSuspendAlarmNotification ); | 487 | computeAlarm(mSuspendAlarmNotification ); |
488 | 488 | ||
489 | } | 489 | } |
490 | 490 | ||
491 | void CalendarView::startAlarm( QString mess , QString filename) | 491 | void CalendarView::startAlarm( QString mess , QString filename) |
492 | { | 492 | { |
493 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 493 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
494 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); | 494 | QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); |
495 | 495 | ||
496 | } | 496 | } |
497 | 497 | ||
498 | void CalendarView::checkNextTimerAlarm() | 498 | void CalendarView::checkNextTimerAlarm() |
499 | { | 499 | { |
500 | mCalendar->checkAlarmForIncidence( 0, true ); | 500 | mCalendar->checkAlarmForIncidence( 0, true ); |
501 | } | 501 | } |
502 | 502 | ||
503 | void CalendarView::computeAlarm( QString msg ) | 503 | void CalendarView::computeAlarm( QString msg ) |
504 | { | 504 | { |
505 | 505 | ||
506 | QString mess = msg; | 506 | QString mess = msg; |
507 | QString mAlarmMessage = mess.mid( 9 ); | 507 | QString mAlarmMessage = mess.mid( 9 ); |
508 | QString filename = MainWindow::resourcePath(); | 508 | QString filename = MainWindow::resourcePath(); |
509 | filename += "koalarm.wav"; | 509 | filename += "koalarm.wav"; |
510 | QString tempfilename; | 510 | QString tempfilename; |
511 | if ( mess.left( 13 ) == "suspend_alarm") { | 511 | if ( mess.left( 13 ) == "suspend_alarm") { |
512 | bool error = false; | 512 | bool error = false; |
513 | int len = mess.mid( 13 ).find("+++"); | 513 | int len = mess.mid( 13 ).find("+++"); |
514 | if ( len < 2 ) | 514 | if ( len < 2 ) |
515 | error = true; | 515 | error = true; |
516 | else { | 516 | else { |
517 | tempfilename = mess.mid( 13, len ); | 517 | tempfilename = mess.mid( 13, len ); |
518 | if ( !QFile::exists( tempfilename ) ) | 518 | if ( !QFile::exists( tempfilename ) ) |
519 | error = true; | 519 | error = true; |
520 | } | 520 | } |
521 | if ( ! error ) { | 521 | if ( ! error ) { |
522 | filename = tempfilename; | 522 | filename = tempfilename; |
523 | } | 523 | } |
524 | mAlarmMessage = mess.mid( 13+len+3 ); | 524 | mAlarmMessage = mess.mid( 13+len+3 ); |
525 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 525 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
526 | startAlarm( mAlarmMessage, filename); | 526 | startAlarm( mAlarmMessage, filename); |
527 | return; | 527 | return; |
528 | } | 528 | } |
529 | if ( mess.left( 11 ) == "timer_alarm") { | 529 | if ( mess.left( 11 ) == "timer_alarm") { |
530 | //mTimerTime = 0; | 530 | //mTimerTime = 0; |
531 | startAlarm( mess.mid( 11 ), filename ); | 531 | startAlarm( mess.mid( 11 ), filename ); |
532 | return; | 532 | return; |
533 | } | 533 | } |
534 | if ( mess.left( 10 ) == "proc_alarm") { | 534 | if ( mess.left( 10 ) == "proc_alarm") { |
535 | bool error = false; | 535 | bool error = false; |
536 | int len = mess.mid( 10 ).find("+++"); | 536 | int len = mess.mid( 10 ).find("+++"); |
537 | if ( len < 2 ) | 537 | if ( len < 2 ) |
538 | error = true; | 538 | error = true; |
539 | else { | 539 | else { |
540 | tempfilename = mess.mid( 10, len ); | 540 | tempfilename = mess.mid( 10, len ); |
541 | if ( !QFile::exists( tempfilename ) ) | 541 | if ( !QFile::exists( tempfilename ) ) |
542 | error = true; | 542 | error = true; |
543 | } | 543 | } |
544 | if ( error ) { | 544 | if ( error ) { |
545 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 545 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
546 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 546 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
547 | } else { | 547 | } else { |
548 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 548 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
549 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 549 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
550 | #ifndef _WIN32_ | 550 | #ifndef _WIN32_ |
551 | if ( vfork () == 0 ) { | 551 | if ( vfork () == 0 ) { |
552 | execl ( tempfilename.latin1(), 0 ); | 552 | execl ( tempfilename.latin1(), 0 ); |
553 | return; | 553 | return; |
554 | } | 554 | } |
555 | #else | 555 | #else |
556 | QProcess* p = new QProcess(); | 556 | QProcess* p = new QProcess(); |
557 | p->addArgument( tempfilename.latin1() ); | 557 | p->addArgument( tempfilename.latin1() ); |
558 | p->start(); | 558 | p->start(); |
559 | return; | 559 | return; |
560 | #endif | 560 | #endif |
561 | 561 | ||
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | 564 | ||
565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 565 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
566 | } | 566 | } |
567 | if ( mess.left( 11 ) == "audio_alarm") { | 567 | if ( mess.left( 11 ) == "audio_alarm") { |
568 | bool error = false; | 568 | bool error = false; |
569 | int len = mess.mid( 11 ).find("+++"); | 569 | int len = mess.mid( 11 ).find("+++"); |
570 | if ( len < 2 ) | 570 | if ( len < 2 ) |
571 | error = true; | 571 | error = true; |
572 | else { | 572 | else { |
573 | tempfilename = mess.mid( 11, len ); | 573 | tempfilename = mess.mid( 11, len ); |
574 | if ( !QFile::exists( tempfilename ) ) | 574 | if ( !QFile::exists( tempfilename ) ) |
575 | error = true; | 575 | error = true; |
576 | } | 576 | } |
577 | if ( ! error ) { | 577 | if ( ! error ) { |
578 | filename = tempfilename; | 578 | filename = tempfilename; |
579 | } | 579 | } |
580 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 580 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
581 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 581 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
582 | } | 582 | } |
583 | if ( mess.left( 9 ) == "cal_alarm") { | 583 | if ( mess.left( 9 ) == "cal_alarm") { |
584 | mAlarmMessage = mess.mid( 9 ) ; | 584 | mAlarmMessage = mess.mid( 9 ) ; |
585 | } | 585 | } |
586 | 586 | ||
587 | startAlarm( mAlarmMessage, filename ); | 587 | startAlarm( mAlarmMessage, filename ); |
588 | 588 | ||
589 | 589 | ||
590 | } | 590 | } |
591 | 591 | ||
592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 592 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
593 | { | 593 | { |
594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 594 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
595 | 595 | ||
596 | mSuspendAlarmNotification = noti; | 596 | mSuspendAlarmNotification = noti; |
597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 597 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 598 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
599 | mSuspendTimer->start( ms , true ); | 599 | mSuspendTimer->start( ms , true ); |
600 | 600 | ||
601 | } | 601 | } |
602 | 602 | ||
603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 603 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
604 | { | 604 | { |
605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 605 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 606 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
607 | #ifndef DESKTOP_VERSION | 607 | #ifndef DESKTOP_VERSION |
608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); | 608 | AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); |
609 | #endif | 609 | #endif |
610 | return; | 610 | return; |
611 | } | 611 | } |
612 | int maxSec; | 612 | int maxSec; |
613 | //maxSec = 5; //testing only | 613 | //maxSec = 5; //testing only |
614 | maxSec = 86400+3600; // one day+1hour | 614 | maxSec = 86400+3600; // one day+1hour |
615 | mAlarmNotification = noti; | 615 | mAlarmNotification = noti; |
616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 616 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
617 | if ( sec > maxSec ) { | 617 | if ( sec > maxSec ) { |
618 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 618 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 619 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
620 | return; | 620 | return; |
621 | } else { | 621 | } else { |
622 | mRecheckAlarmTimer->stop(); | 622 | mRecheckAlarmTimer->stop(); |
623 | } | 623 | } |
624 | //qDebug("Alarm timer started with secs: %d ", sec); | 624 | //qDebug("Alarm timer started with secs: %d ", sec); |
625 | mAlarmTimer->start( sec *1000 , true ); | 625 | mAlarmTimer->start( sec *1000 , true ); |
626 | 626 | ||
627 | } | 627 | } |
628 | // called by mRecheckAlarmTimer to get next alarm | 628 | // called by mRecheckAlarmTimer to get next alarm |
629 | // we need this, because a QTimer has only a max range of 25 days | 629 | // we need this, because a QTimer has only a max range of 25 days |
630 | void CalendarView::recheckTimerAlarm() | 630 | void CalendarView::recheckTimerAlarm() |
631 | { | 631 | { |
632 | mAlarmTimer->stop(); | 632 | mAlarmTimer->stop(); |
633 | mRecheckAlarmTimer->stop(); | 633 | mRecheckAlarmTimer->stop(); |
634 | mCalendar->checkAlarmForIncidence( 0, true ); | 634 | mCalendar->checkAlarmForIncidence( 0, true ); |
635 | } | 635 | } |
636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 636 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
637 | { | 637 | { |
638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 638 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 639 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
640 | #ifndef DESKTOP_VERSION | 640 | #ifndef DESKTOP_VERSION |
641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); | 641 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); |
642 | #endif | 642 | #endif |
643 | return; | 643 | return; |
644 | } | 644 | } |
645 | mAlarmTimer->stop(); | 645 | mAlarmTimer->stop(); |
646 | } | 646 | } |
647 | void CalendarView::selectWeekNum ( int num ) | 647 | void CalendarView::selectWeekNum ( int num ) |
648 | { | 648 | { |
649 | dateNavigator()->selectWeek( num ); | 649 | dateNavigator()->selectWeek( num ); |
650 | mViewManager->showWeekView(); | 650 | mViewManager->showWeekView(); |
651 | } | 651 | } |
652 | KOViewManager *CalendarView::viewManager() | 652 | KOViewManager *CalendarView::viewManager() |
653 | { | 653 | { |
654 | return mViewManager; | 654 | return mViewManager; |
655 | } | 655 | } |
656 | 656 | ||
657 | KODialogManager *CalendarView::dialogManager() | 657 | KODialogManager *CalendarView::dialogManager() |
658 | { | 658 | { |
659 | return mDialogManager; | 659 | return mDialogManager; |
660 | } | 660 | } |
661 | 661 | ||
662 | QDate CalendarView::startDate() | 662 | QDate CalendarView::startDate() |
663 | { | 663 | { |
664 | DateList dates = mNavigator->selectedDates(); | 664 | DateList dates = mNavigator->selectedDates(); |
665 | 665 | ||
666 | return dates.first(); | 666 | return dates.first(); |
667 | } | 667 | } |
668 | 668 | ||
669 | QDate CalendarView::endDate() | 669 | QDate CalendarView::endDate() |
670 | { | 670 | { |
671 | DateList dates = mNavigator->selectedDates(); | 671 | DateList dates = mNavigator->selectedDates(); |
672 | 672 | ||
673 | return dates.last(); | 673 | return dates.last(); |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | void CalendarView::createPrinter() | 677 | void CalendarView::createPrinter() |
678 | { | 678 | { |
679 | #ifndef KORG_NOPRINTER | 679 | #ifndef KORG_NOPRINTER |
680 | if (!mCalPrinter) { | 680 | if (!mCalPrinter) { |
681 | mCalPrinter = new CalPrinter(this, mCalendar); | 681 | mCalPrinter = new CalPrinter(this, mCalendar); |
682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 682 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
683 | } | 683 | } |
684 | #endif | 684 | #endif |
685 | } | 685 | } |
686 | 686 | ||
687 | void CalendarView::confSync() | 687 | void CalendarView::confSync() |
688 | { | 688 | { |
689 | static KSyncPrefsDialog* sp = 0; | 689 | static KSyncPrefsDialog* sp = 0; |
690 | if ( ! sp ) { | 690 | if ( ! sp ) { |
691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 691 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
692 | } | 692 | } |
693 | sp->usrReadConfig(); | 693 | sp->usrReadConfig(); |
694 | #ifndef DESKTOP_VERSION | 694 | #ifndef DESKTOP_VERSION |
695 | sp->showMaximized(); | 695 | sp->showMaximized(); |
696 | #else | 696 | #else |
697 | sp->show(); | 697 | sp->show(); |
698 | #endif | 698 | #endif |
699 | sp->exec(); | 699 | sp->exec(); |
700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 700 | KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 701 | KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
702 | } | 702 | } |
703 | 703 | ||
704 | 704 | ||
705 | //KOPrefs::instance()->mWriteBackFile | 705 | //KOPrefs::instance()->mWriteBackFile |
706 | //KOPrefs::instance()->mWriteBackExistingOnly | 706 | //KOPrefs::instance()->mWriteBackExistingOnly |
707 | 707 | ||
708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 708 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 709 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 710 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 711 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 712 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 713 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
714 | 714 | ||
715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 715 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
716 | { | 716 | { |
717 | 717 | ||
718 | //void setZaurusId(int id); | 718 | //void setZaurusId(int id); |
719 | // int zaurusId() const; | 719 | // int zaurusId() const; |
720 | // void setZaurusUid(int id); | 720 | // void setZaurusUid(int id); |
721 | // int zaurusUid() const; | 721 | // int zaurusUid() const; |
722 | // void setZaurusStat(int id); | 722 | // void setZaurusStat(int id); |
723 | // int zaurusStat() const; | 723 | // int zaurusStat() const; |
724 | // 0 equal | 724 | // 0 equal |
725 | // 1 take local | 725 | // 1 take local |
726 | // 2 take remote | 726 | // 2 take remote |
727 | // 3 cancel | 727 | // 3 cancel |
728 | QDateTime lastSync = mLastCalendarSync; | 728 | QDateTime lastSync = mLastCalendarSync; |
729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 729 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
730 | bool remCh, locCh; | 730 | bool remCh, locCh; |
731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 731 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
732 | if ( remCh ) | 732 | if ( remCh ) |
733 | qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 733 | qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
734 | locCh = ( local->lastModified() > mLastCalendarSync ); | 734 | locCh = ( local->lastModified() > mLastCalendarSync ); |
735 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); | 735 | //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); |
736 | if ( !remCh && ! locCh ) { | 736 | if ( !remCh && ! locCh ) { |
737 | qDebug("both not changed "); | 737 | qDebug("both not changed "); |
738 | lastSync = local->lastModified().addDays(1); | 738 | lastSync = local->lastModified().addDays(1); |
739 | } else { | 739 | } else { |
740 | if ( locCh ) { | 740 | if ( locCh ) { |
741 | qDebug("loc changed %d", local->revision() ); | 741 | qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); |
742 | lastSync = local->lastModified().addDays( -1 ); | 742 | lastSync = local->lastModified().addDays( -1 ); |
743 | if ( !remCh ) | 743 | if ( !remCh ) |
744 | remote->setLastModified( lastSync.addDays( -1 ) ); | 744 | remote->setLastModified( lastSync.addDays( -1 ) ); |
745 | } else { | 745 | } else { |
746 | qDebug(" not loc changed "); | 746 | qDebug(" not loc changed "); |
747 | lastSync = local->lastModified().addDays( 1 ); | 747 | lastSync = local->lastModified().addDays( 1 ); |
748 | if ( remCh ) | 748 | if ( remCh ) |
749 | remote->setLastModified( lastSync.addDays( 1 ) ); | 749 | remote->setLastModified( lastSync.addDays( 1 ) ); |
750 | 750 | ||
751 | } | 751 | } |
752 | } | 752 | } |
753 | full = true; | 753 | full = true; |
754 | if ( mode < SYNC_PREF_ASK ) | 754 | if ( mode < SYNC_PREF_ASK ) |
755 | mode = SYNC_PREF_ASK; | 755 | mode = SYNC_PREF_ASK; |
756 | } else { | 756 | } else { |
757 | if ( local->lastModified() == remote->lastModified() ) | 757 | if ( local->lastModified() == remote->lastModified() ) |
758 | if ( local->revision() == remote->revision() ) | 758 | if ( local->revision() == remote->revision() ) |
759 | return 0; | 759 | return 0; |
760 | 760 | ||
761 | } | 761 | } |
762 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 762 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
763 | 763 | ||
764 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 764 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); |
765 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 765 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
766 | //full = true; //debug only | 766 | //full = true; //debug only |
767 | if ( full ) { | 767 | if ( full ) { |
768 | bool equ = false; | 768 | bool equ = false; |
769 | if ( local->type() == "Event" ) { | 769 | if ( local->type() == "Event" ) { |
770 | equ = (*((Event*) local) == *((Event*) remote)); | 770 | equ = (*((Event*) local) == *((Event*) remote)); |
771 | } | 771 | } |
772 | else if ( local->type() =="Todo" ) | 772 | else if ( local->type() =="Todo" ) |
773 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 773 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
774 | else if ( local->type() =="Journal" ) | 774 | else if ( local->type() =="Journal" ) |
775 | equ = (*((Journal*) local) == *((Journal*) remote)); | 775 | equ = (*((Journal*) local) == *((Journal*) remote)); |
776 | if ( equ ) { | 776 | if ( equ ) { |
777 | //qDebug("equal "); | 777 | //qDebug("equal "); |
778 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 778 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
779 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 779 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
780 | } | 780 | } |
781 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 781 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
782 | return 0; | 782 | return 0; |
783 | 783 | ||
784 | }//else //debug only | 784 | }//else //debug only |
785 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 785 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
786 | } | 786 | } |
787 | int result; | 787 | int result; |
788 | bool localIsNew; | 788 | bool localIsNew; |
789 | qDebug("mLastCalendarSync %s lastsync %s --- local %s remote %s ",mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 789 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
790 | 790 | ||
791 | if ( full && mode < SYNC_PREF_NEWEST ) | 791 | if ( full && mode < SYNC_PREF_NEWEST ) |
792 | mode = SYNC_PREF_ASK; | 792 | mode = SYNC_PREF_ASK; |
793 | 793 | ||
794 | switch( mode ) { | 794 | switch( mode ) { |
795 | case SYNC_PREF_LOCAL: | 795 | case SYNC_PREF_LOCAL: |
796 | if ( lastSync > remote->lastModified() ) | 796 | if ( lastSync > remote->lastModified() ) |
797 | return 1; | 797 | return 1; |
798 | if ( lastSync > local->lastModified() ) | 798 | if ( lastSync > local->lastModified() ) |
799 | return 2; | 799 | return 2; |
800 | return 1; | 800 | return 1; |
801 | break; | 801 | break; |
802 | case SYNC_PREF_REMOTE: | 802 | case SYNC_PREF_REMOTE: |
803 | if ( lastSync > remote->lastModified() ) | 803 | if ( lastSync > remote->lastModified() ) |
804 | return 1; | 804 | return 1; |
805 | if ( lastSync > local->lastModified() ) | 805 | if ( lastSync > local->lastModified() ) |
806 | return 2; | 806 | return 2; |
807 | return 2; | 807 | return 2; |
808 | break; | 808 | break; |
809 | case SYNC_PREF_NEWEST: | 809 | case SYNC_PREF_NEWEST: |
810 | if ( local->lastModified() > remote->lastModified() ) | 810 | if ( local->lastModified() > remote->lastModified() ) |
811 | return 1; | 811 | return 1; |
812 | else | 812 | else |
813 | return 2; | 813 | return 2; |
814 | break; | 814 | break; |
815 | case SYNC_PREF_ASK: | 815 | case SYNC_PREF_ASK: |
816 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 816 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
817 | if ( lastSync > remote->lastModified() ) | 817 | if ( lastSync > remote->lastModified() ) |
818 | return 1; | 818 | return 1; |
819 | if ( lastSync > local->lastModified() ) | 819 | if ( lastSync > local->lastModified() ) |
820 | return 2; | 820 | return 2; |
821 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); | 821 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); |
822 | localIsNew = local->lastModified() >= remote->lastModified(); | 822 | localIsNew = local->lastModified() >= remote->lastModified(); |
823 | if ( localIsNew ) | 823 | if ( localIsNew ) |
824 | getEventViewerDialog()->setColorMode( 1 ); | 824 | getEventViewerDialog()->setColorMode( 1 ); |
825 | else | 825 | else |
826 | getEventViewerDialog()->setColorMode( 2 ); | 826 | getEventViewerDialog()->setColorMode( 2 ); |
827 | getEventViewerDialog()->setIncidence(local); | 827 | getEventViewerDialog()->setIncidence(local); |
828 | if ( localIsNew ) | 828 | if ( localIsNew ) |
829 | getEventViewerDialog()->setColorMode( 2 ); | 829 | getEventViewerDialog()->setColorMode( 2 ); |
830 | else | 830 | else |
831 | getEventViewerDialog()->setColorMode( 1 ); | 831 | getEventViewerDialog()->setColorMode( 1 ); |
832 | getEventViewerDialog()->addIncidence(remote); | 832 | getEventViewerDialog()->addIncidence(remote); |
833 | getEventViewerDialog()->setColorMode( 0 ); | 833 | getEventViewerDialog()->setColorMode( 0 ); |
834 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 834 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
835 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 835 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
836 | getEventViewerDialog()->showMe(); | 836 | getEventViewerDialog()->showMe(); |
837 | result = getEventViewerDialog()->executeS( localIsNew ); | 837 | result = getEventViewerDialog()->executeS( localIsNew ); |
838 | return result; | 838 | return result; |
839 | 839 | ||
840 | break; | 840 | break; |
841 | case SYNC_PREF_FORCE_LOCAL: | 841 | case SYNC_PREF_FORCE_LOCAL: |
842 | return 1; | 842 | return 1; |
843 | break; | 843 | break; |
844 | case SYNC_PREF_FORCE_REMOTE: | 844 | case SYNC_PREF_FORCE_REMOTE: |
845 | return 2; | 845 | return 2; |
846 | break; | 846 | break; |
847 | 847 | ||
848 | default: | 848 | default: |
849 | // SYNC_PREF_TAKE_BOTH not implemented | 849 | // SYNC_PREF_TAKE_BOTH not implemented |
850 | break; | 850 | break; |
851 | } | 851 | } |
852 | return 0; | 852 | return 0; |
853 | } | 853 | } |
854 | Event* CalendarView::getLastSyncEvent() | 854 | Event* CalendarView::getLastSyncEvent() |
855 | { | 855 | { |
856 | Event* lse; | 856 | Event* lse; |
857 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 857 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
858 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 858 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
859 | if (!lse) { | 859 | if (!lse) { |
860 | lse = new Event(); | 860 | lse = new Event(); |
861 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 861 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
862 | QString sum = ""; | 862 | QString sum = ""; |
863 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 863 | if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
864 | sum = "E: "; | 864 | sum = "E: "; |
865 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 865 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
866 | lse->setDtStart( mLastCalendarSync ); | 866 | lse->setDtStart( mLastCalendarSync ); |
867 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 867 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
868 | lse->setCategories( i18n("SyncEvent") ); | 868 | lse->setCategories( i18n("SyncEvent") ); |
869 | lse->setReadOnly( true ); | 869 | lse->setReadOnly( true ); |
870 | mCalendar->addEvent( lse ); | 870 | mCalendar->addEvent( lse ); |
871 | } | 871 | } |
872 | 872 | ||
873 | return lse; | 873 | return lse; |
874 | 874 | ||
875 | } | 875 | } |
876 | // probaly useless | 876 | // probaly useless |
877 | void CalendarView::setupExternSyncProfiles() | 877 | void CalendarView::setupExternSyncProfiles() |
878 | { | 878 | { |
879 | Event* lse; | 879 | Event* lse; |
880 | mExternLastSyncEvent.clear(); | 880 | mExternLastSyncEvent.clear(); |
881 | int i; | 881 | int i; |
882 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { | 882 | for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { |
883 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); | 883 | lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); |
884 | if ( lse ) | 884 | if ( lse ) |
885 | mExternLastSyncEvent.append( lse ); | 885 | mExternLastSyncEvent.append( lse ); |
886 | else | 886 | else |
887 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); | 887 | qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); |
888 | } | 888 | } |
889 | 889 | ||
890 | } | 890 | } |
891 | // we check, if the to delete event has a id for a profile | 891 | // we check, if the to delete event has a id for a profile |
892 | // if yes, we set this id in the profile to delete | 892 | // if yes, we set this id in the profile to delete |
893 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 893 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
894 | { | 894 | { |
895 | if ( lastSync.count() == 0 ) { | 895 | if ( lastSync.count() == 0 ) { |
896 | //qDebug(" lastSync.count() == 0"); | 896 | //qDebug(" lastSync.count() == 0"); |
897 | return; | 897 | return; |
898 | } | 898 | } |
899 | if ( toDelete->type() == "Journal" ) | 899 | if ( toDelete->type() == "Journal" ) |
900 | return; | 900 | return; |
901 | 901 | ||
902 | Event* eve = lastSync.first(); | 902 | Event* eve = lastSync.first(); |
903 | 903 | ||
904 | while ( eve ) { | 904 | while ( eve ) { |
905 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 905 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
906 | if ( !id.isEmpty() ) { | 906 | if ( !id.isEmpty() ) { |
907 | QString des = eve->description(); | 907 | QString des = eve->description(); |
908 | QString pref = "e"; | 908 | QString pref = "e"; |
909 | if ( toDelete->type() == "Todo" ) | 909 | if ( toDelete->type() == "Todo" ) |
910 | pref = "t"; | 910 | pref = "t"; |
911 | des += pref+ id + ","; | 911 | des += pref+ id + ","; |
912 | eve->setReadOnly( false ); | 912 | eve->setReadOnly( false ); |
913 | eve->setDescription( des ); | 913 | eve->setDescription( des ); |
914 | //qDebug("setdes %s ", des.latin1()); | 914 | //qDebug("setdes %s ", des.latin1()); |
915 | eve->setReadOnly( true ); | 915 | eve->setReadOnly( true ); |
916 | } | 916 | } |
917 | eve = lastSync.next(); | 917 | eve = lastSync.next(); |
918 | } | 918 | } |
919 | 919 | ||
920 | } | 920 | } |
921 | void CalendarView::checkExternalId( Incidence * inc ) | 921 | void CalendarView::checkExternalId( Incidence * inc ) |
922 | { | 922 | { |
923 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 923 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
924 | checkExternSyncEvent( lastSync, inc ); | 924 | checkExternSyncEvent( lastSync, inc ); |
925 | 925 | ||
926 | } | 926 | } |
927 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 927 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
928 | { | 928 | { |
929 | bool syncOK = true; | 929 | bool syncOK = true; |
930 | int addedEvent = 0; | 930 | int addedEvent = 0; |
931 | int addedEventR = 0; | 931 | int addedEventR = 0; |
932 | int deletedEventR = 0; | 932 | int deletedEventR = 0; |
933 | int deletedEventL = 0; | 933 | int deletedEventL = 0; |
934 | int changedLocal = 0; | 934 | int changedLocal = 0; |
935 | int changedRemote = 0; | 935 | int changedRemote = 0; |
936 | //QPtrList<Event> el = local->rawEvents(); | 936 | //QPtrList<Event> el = local->rawEvents(); |
937 | Event* eventR; | 937 | Event* eventR; |
938 | QString uid; | 938 | QString uid; |
939 | int take; | 939 | int take; |
940 | Event* eventL; | 940 | Event* eventL; |
941 | Event* eventRSync; | 941 | Event* eventRSync; |
942 | Event* eventLSync; | 942 | Event* eventLSync; |
943 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 943 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
944 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 944 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
945 | bool fullDateRange = false; | 945 | bool fullDateRange = false; |
946 | local->resetTempSyncStat(); | 946 | local->resetTempSyncStat(); |
947 | mLastCalendarSync = QDateTime::currentDateTime(); | 947 | mLastCalendarSync = QDateTime::currentDateTime(); |
948 | QDateTime modifiedCalendar = mLastCalendarSync;; | 948 | QDateTime modifiedCalendar = mLastCalendarSync;; |
949 | eventLSync = getLastSyncEvent(); | 949 | eventLSync = getLastSyncEvent(); |
950 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 950 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
951 | if ( eventR ) { | 951 | if ( eventR ) { |
952 | eventRSync = (Event*) eventR->clone(); | 952 | eventRSync = (Event*) eventR->clone(); |
953 | remote->deleteEvent(eventR ); | 953 | remote->deleteEvent(eventR ); |
954 | 954 | ||
955 | } else { | 955 | } else { |
956 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 956 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
957 | eventRSync = (Event*)eventLSync->clone(); | 957 | eventRSync = (Event*)eventLSync->clone(); |
958 | } else { | 958 | } else { |
959 | fullDateRange = true; | 959 | fullDateRange = true; |
960 | eventRSync = new Event(); | 960 | eventRSync = new Event(); |
961 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 961 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
962 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 962 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
963 | eventRSync->setDtStart( mLastCalendarSync ); | 963 | eventRSync->setDtStart( mLastCalendarSync ); |
964 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 964 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
965 | eventRSync->setCategories( i18n("SyncEvent") ); | 965 | eventRSync->setCategories( i18n("SyncEvent") ); |
966 | } | 966 | } |
967 | } | 967 | } |
968 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 968 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
969 | fullDateRange = true; | 969 | fullDateRange = true; |
970 | 970 | ||
971 | if ( ! fullDateRange ) { | 971 | if ( ! fullDateRange ) { |
972 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 972 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
973 | 973 | ||
974 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 974 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
975 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 975 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
976 | fullDateRange = true; | 976 | fullDateRange = true; |
977 | } | 977 | } |
978 | } | 978 | } |
979 | if ( fullDateRange ) | 979 | if ( fullDateRange ) |
980 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 980 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
981 | else | 981 | else |
982 | mLastCalendarSync = eventLSync->dtStart(); | 982 | mLastCalendarSync = eventLSync->dtStart(); |
983 | // for resyncing if own file has changed | 983 | // for resyncing if own file has changed |
984 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 984 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
985 | mLastCalendarSync = loadedFileVersion; | 985 | mLastCalendarSync = loadedFileVersion; |
986 | qDebug("setting mLastCalendarSync "); | 986 | qDebug("setting mLastCalendarSync "); |
987 | } | 987 | } |
988 | //qDebug("*************************** "); | 988 | //qDebug("*************************** "); |
989 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); | 989 | qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); |
990 | QPtrList<Incidence> er = remote->rawIncidences(); | 990 | QPtrList<Incidence> er = remote->rawIncidences(); |
991 | Incidence* inR = er.first(); | 991 | Incidence* inR = er.first(); |
992 | Incidence* inL; | 992 | Incidence* inL; |
993 | QProgressBar bar( er.count(),0 ); | 993 | QProgressBar bar( er.count(),0 ); |
994 | bar.setCaption (i18n("Syncing - close to abort!") ); | 994 | bar.setCaption (i18n("Syncing - close to abort!") ); |
995 | 995 | ||
996 | int w = 300; | 996 | int w = 300; |
997 | if ( QApplication::desktop()->width() < 320 ) | 997 | if ( QApplication::desktop()->width() < 320 ) |
998 | w = 220; | 998 | w = 220; |
999 | int h = bar.sizeHint().height() ; | 999 | int h = bar.sizeHint().height() ; |
1000 | int dw = QApplication::desktop()->width(); | 1000 | int dw = QApplication::desktop()->width(); |
1001 | int dh = QApplication::desktop()->height(); | 1001 | int dh = QApplication::desktop()->height(); |
1002 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1002 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1003 | bar.show(); | 1003 | bar.show(); |
1004 | int modulo = (er.count()/10)+1; | 1004 | int modulo = (er.count()/10)+1; |
1005 | int incCounter = 0; | 1005 | int incCounter = 0; |
1006 | while ( inR ) { | 1006 | while ( inR ) { |
1007 | if ( ! bar.isVisible() ) | 1007 | if ( ! bar.isVisible() ) |
1008 | return false; | 1008 | return false; |
1009 | if ( incCounter % modulo == 0 ) | 1009 | if ( incCounter % modulo == 0 ) |
1010 | bar.setProgress( incCounter ); | 1010 | bar.setProgress( incCounter ); |
1011 | ++incCounter; | 1011 | ++incCounter; |
1012 | uid = inR->uid(); | 1012 | uid = inR->uid(); |
1013 | bool skipIncidence = false; | 1013 | bool skipIncidence = false; |
1014 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1014 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1015 | skipIncidence = true; | 1015 | skipIncidence = true; |
1016 | 1016 | ||
1017 | qApp->processEvents(); | 1017 | qApp->processEvents(); |
1018 | if ( !skipIncidence ) { | 1018 | if ( !skipIncidence ) { |
1019 | inL = local->incidence( uid ); | 1019 | inL = local->incidence( uid ); |
1020 | if ( inL ) { // maybe conflict - same uid in both calendars | 1020 | if ( inL ) { // maybe conflict - same uid in both calendars |
1021 | int maxrev = inL->revision(); | 1021 | int maxrev = inL->revision(); |
1022 | if ( maxrev < inR->revision() ) | 1022 | if ( maxrev < inR->revision() ) |
1023 | maxrev = inR->revision(); | 1023 | maxrev = inR->revision(); |
1024 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1024 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1025 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1025 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1026 | if ( take == 3 ) | 1026 | if ( take == 3 ) |
1027 | return false; | 1027 | return false; |
1028 | if ( take == 1 ) {// take local | 1028 | if ( take == 1 ) {// take local |
1029 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1029 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1030 | remote->deleteIncidence( inR ); | 1030 | remote->deleteIncidence( inR ); |
1031 | if ( inL->revision() < maxrev ) | 1031 | if ( inL->revision() < maxrev ) |
1032 | inL->setRevision( maxrev ); | 1032 | inL->setRevision( maxrev ); |
1033 | remote->addIncidence( inL->clone() ); | 1033 | inR = inL->clone(); |
1034 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
1035 | remote->addIncidence( inR ); | ||
1034 | ++changedRemote; | 1036 | ++changedRemote; |
1035 | } else { | 1037 | } else { |
1036 | if ( inR->revision() < maxrev ) | 1038 | if ( inR->revision() < maxrev ) |
1037 | inR->setRevision( maxrev ); | 1039 | inR->setRevision( maxrev ); |
1038 | local->deleteIncidence( inL ); | 1040 | local->deleteIncidence( inL ); |
1039 | local->addIncidence( inR->clone() ); | 1041 | local->addIncidence( inR->clone() ); |
1040 | ++changedLocal; | 1042 | ++changedLocal; |
1041 | } | 1043 | } |
1042 | } | 1044 | } |
1043 | } else { // no conflict | 1045 | } else { // no conflict |
1044 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1046 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1045 | QString des = eventLSync->description(); | 1047 | QString des = eventLSync->description(); |
1046 | QString pref = "e"; | 1048 | QString pref = "e"; |
1047 | if ( inR->type() == "Todo" ) | 1049 | if ( inR->type() == "Todo" ) |
1048 | pref = "t"; | 1050 | pref = "t"; |
1049 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1051 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1050 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1052 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1051 | //remote->deleteIncidence( inR ); | 1053 | //remote->deleteIncidence( inR ); |
1052 | ++deletedEventR; | 1054 | ++deletedEventR; |
1053 | } else { | 1055 | } else { |
1054 | inR->setLastModified( modifiedCalendar ); | 1056 | inR->setLastModified( modifiedCalendar ); |
1055 | local->addIncidence( inR->clone() ); | 1057 | inL = inR->clone(); |
1058 | local->addIncidence( inL ); | ||
1056 | ++addedEvent; | 1059 | ++addedEvent; |
1057 | } | 1060 | } |
1058 | } else { | 1061 | } else { |
1059 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1062 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1060 | inR->setLastModified( modifiedCalendar ); | 1063 | inR->setLastModified( modifiedCalendar ); |
1061 | local->addIncidence( inR->clone() ); | 1064 | local->addIncidence( inR->clone() ); |
1062 | ++addedEvent; | 1065 | ++addedEvent; |
1063 | } else { | 1066 | } else { |
1064 | checkExternSyncEvent(eventRSyncSharp, inR); | 1067 | checkExternSyncEvent(eventRSyncSharp, inR); |
1065 | remote->deleteIncidence( inR ); | 1068 | remote->deleteIncidence( inR ); |
1066 | ++deletedEventR; | 1069 | ++deletedEventR; |
1067 | } | 1070 | } |
1068 | } | 1071 | } |
1069 | } | 1072 | } |
1070 | } | 1073 | } |
1071 | inR = er.next(); | 1074 | inR = er.next(); |
1072 | } | 1075 | } |
1073 | QPtrList<Incidence> el = local->rawIncidences(); | 1076 | QPtrList<Incidence> el = local->rawIncidences(); |
1074 | inL = el.first(); | 1077 | inL = el.first(); |
1075 | modulo = (el.count()/10)+1; | 1078 | modulo = (el.count()/10)+1; |
1076 | bar.setCaption (i18n("Add / remove events") ); | 1079 | bar.setCaption (i18n("Add / remove events") ); |
1077 | bar.setTotalSteps ( el.count() ) ; | 1080 | bar.setTotalSteps ( el.count() ) ; |
1078 | bar.show(); | 1081 | bar.show(); |
1079 | incCounter = 0; | 1082 | incCounter = 0; |
1080 | 1083 | ||
1081 | while ( inL ) { | 1084 | while ( inL ) { |
1082 | 1085 | ||
1083 | qApp->processEvents(); | 1086 | qApp->processEvents(); |
1084 | if ( ! bar.isVisible() ) | 1087 | if ( ! bar.isVisible() ) |
1085 | return false; | 1088 | return false; |
1086 | if ( incCounter % modulo == 0 ) | 1089 | if ( incCounter % modulo == 0 ) |
1087 | bar.setProgress( incCounter ); | 1090 | bar.setProgress( incCounter ); |
1088 | ++incCounter; | 1091 | ++incCounter; |
1089 | uid = inL->uid(); | 1092 | uid = inL->uid(); |
1090 | bool skipIncidence = false; | 1093 | bool skipIncidence = false; |
1091 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1094 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1092 | skipIncidence = true; | 1095 | skipIncidence = true; |
1093 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1096 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1094 | skipIncidence = true; | 1097 | skipIncidence = true; |
1095 | if ( !skipIncidence ) { | 1098 | if ( !skipIncidence ) { |
1096 | inR = remote->incidence( uid ); | 1099 | inR = remote->incidence( uid ); |
1097 | if ( ! inR ) { | 1100 | if ( ! inR ) { |
1098 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1101 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1099 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1102 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1100 | local->deleteIncidence( inL ); | 1103 | local->deleteIncidence( inL ); |
1101 | ++deletedEventL; | 1104 | ++deletedEventL; |
1102 | } else { | 1105 | } else { |
1103 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1106 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1104 | inL->removeID(mCurrentSyncDevice ); | 1107 | inL->removeID(mCurrentSyncDevice ); |
1105 | ++addedEventR; | 1108 | ++addedEventR; |
1109 | qDebug("remote added Incidence %s ", inL->summary().latin1()); | ||
1106 | inL->setLastModified( modifiedCalendar ); | 1110 | inL->setLastModified( modifiedCalendar ); |
1107 | remote->addIncidence( inL->clone() ); | 1111 | inR = inL->clone(); |
1112 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
1113 | remote->addIncidence( inR ); | ||
1108 | } | 1114 | } |
1109 | } | 1115 | } |
1110 | } else { | 1116 | } else { |
1111 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1117 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1112 | checkExternSyncEvent(eventLSyncSharp, inL); | 1118 | checkExternSyncEvent(eventLSyncSharp, inL); |
1113 | local->deleteIncidence( inL ); | 1119 | local->deleteIncidence( inL ); |
1114 | ++deletedEventL; | 1120 | ++deletedEventL; |
1115 | } else { | 1121 | } else { |
1116 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1122 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1117 | ++addedEventR; | 1123 | ++addedEventR; |
1118 | inL->setLastModified( modifiedCalendar ); | 1124 | inL->setLastModified( modifiedCalendar ); |
1119 | remote->addIncidence( inL->clone() ); | 1125 | remote->addIncidence( inL->clone() ); |
1120 | } | 1126 | } |
1121 | } | 1127 | } |
1122 | } | 1128 | } |
1123 | } | 1129 | } |
1124 | } | 1130 | } |
1125 | inL = el.next(); | 1131 | inL = el.next(); |
1126 | } | 1132 | } |
1127 | int delFut = 0; | 1133 | int delFut = 0; |
1128 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 1134 | if ( KOPrefs::instance()->mWriteBackInFuture ) { |
1129 | er = remote->rawIncidences(); | 1135 | er = remote->rawIncidences(); |
1130 | inR = er.first(); | 1136 | inR = er.first(); |
1131 | QDateTime dt; | 1137 | QDateTime dt; |
1132 | QDateTime cur = QDateTime::currentDateTime(); | 1138 | QDateTime cur = QDateTime::currentDateTime(); |
1133 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | 1139 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); |
1134 | while ( inR ) { | 1140 | while ( inR ) { |
1135 | if ( inR->type() == "Todo" ) { | 1141 | if ( inR->type() == "Todo" ) { |
1136 | Todo * t = (Todo*)inR; | 1142 | Todo * t = (Todo*)inR; |
1137 | if ( t->hasDueDate() ) | 1143 | if ( t->hasDueDate() ) |
1138 | dt = t->dtDue(); | 1144 | dt = t->dtDue(); |
1139 | else | 1145 | else |
1140 | dt = cur.addSecs( 62 ); | 1146 | dt = cur.addSecs( 62 ); |
1141 | } | 1147 | } |
1142 | else if (inR->type() == "Event" ) { | 1148 | else if (inR->type() == "Event" ) { |
1143 | bool ok; | 1149 | bool ok; |
1144 | dt = inR->getNextOccurence( cur, &ok ); | 1150 | dt = inR->getNextOccurence( cur, &ok ); |
1145 | if ( !ok ) | 1151 | if ( !ok ) |
1146 | dt = cur.addSecs( -62 ); | 1152 | dt = cur.addSecs( -62 ); |
1147 | } | 1153 | } |
1148 | else | 1154 | else |
1149 | dt = inR->dtStart(); | 1155 | dt = inR->dtStart(); |
1150 | if ( dt < cur || dt > end ) { | 1156 | if ( dt < cur || dt > end ) { |
1151 | remote->deleteIncidence( inR ); | 1157 | remote->deleteIncidence( inR ); |
1152 | ++delFut; | 1158 | ++delFut; |
1153 | } | 1159 | } |
1154 | inR = er.next(); | 1160 | inR = er.next(); |
1155 | } | 1161 | } |
1156 | } | 1162 | } |
1157 | bar.hide(); | 1163 | bar.hide(); |
1158 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1164 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1159 | eventLSync->setReadOnly( false ); | 1165 | eventLSync->setReadOnly( false ); |
1160 | eventLSync->setDtStart( mLastCalendarSync ); | 1166 | eventLSync->setDtStart( mLastCalendarSync ); |
1161 | eventRSync->setDtStart( mLastCalendarSync ); | 1167 | eventRSync->setDtStart( mLastCalendarSync ); |
1162 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1168 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1163 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1169 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1164 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1170 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1165 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1171 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1166 | eventLSync->setReadOnly( true ); | 1172 | eventLSync->setReadOnly( true ); |
1167 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 1173 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
1168 | remote->addEvent( eventRSync ); | 1174 | remote->addEvent( eventRSync ); |
1169 | QString mes; | 1175 | QString mes; |
1170 | 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 ); | 1176 | 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 ); |
1171 | QString delmess; | 1177 | QString delmess; |
1172 | if ( delFut ) { | 1178 | if ( delFut ) { |
1173 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | 1179 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); |
1174 | mes += delmess; | 1180 | mes += delmess; |
1175 | } | 1181 | } |
1176 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 1182 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
1177 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1183 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1178 | } | 1184 | } |
1179 | qDebug( mes ); | 1185 | qDebug( mes ); |
1180 | mCalendar->checkAlarmForIncidence( 0, true ); | 1186 | mCalendar->checkAlarmForIncidence( 0, true ); |
1181 | return syncOK; | 1187 | return syncOK; |
1182 | } | 1188 | } |
1183 | 1189 | ||
1184 | void CalendarView::setSyncDevice( QString s ) | 1190 | void CalendarView::setSyncDevice( QString s ) |
1185 | { | 1191 | { |
1186 | mCurrentSyncDevice= s; | 1192 | mCurrentSyncDevice= s; |
1187 | } | 1193 | } |
1188 | void CalendarView::setSyncName( QString s ) | 1194 | void CalendarView::setSyncName( QString s ) |
1189 | { | 1195 | { |
1190 | mCurrentSyncName= s; | 1196 | mCurrentSyncName= s; |
1191 | } | 1197 | } |
1192 | bool CalendarView::syncCalendar(QString filename, int mode) | 1198 | bool CalendarView::syncCalendar(QString filename, int mode) |
1193 | { | 1199 | { |
1194 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1200 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1195 | CalendarLocal* calendar = new CalendarLocal(); | 1201 | CalendarLocal* calendar = new CalendarLocal(); |
1196 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1202 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1197 | FileStorage* storage = new FileStorage( calendar ); | 1203 | FileStorage* storage = new FileStorage( calendar ); |
1198 | bool syncOK = false; | 1204 | bool syncOK = false; |
1199 | storage->setFileName( filename ); | 1205 | storage->setFileName( filename ); |
1200 | // qDebug("loading ... "); | 1206 | // qDebug("loading ... "); |
1201 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1207 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1202 | getEventViewerDialog()->setSyncMode( true ); | 1208 | getEventViewerDialog()->setSyncMode( true ); |
1203 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1209 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1204 | getEventViewerDialog()->setSyncMode( false ); | 1210 | getEventViewerDialog()->setSyncMode( false ); |
1205 | if ( syncOK ) { | 1211 | if ( syncOK ) { |
1206 | if ( KOPrefs::instance()->mWriteBackFile ) | 1212 | if ( KOPrefs::instance()->mWriteBackFile ) |
1207 | { | 1213 | { |
1208 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1214 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1209 | storage->save(); | 1215 | storage->save(); |
1210 | } | 1216 | } |
1211 | } | 1217 | } |
1212 | setModified( true ); | 1218 | setModified( true ); |
1213 | } | 1219 | } |
1214 | delete storage; | 1220 | delete storage; |
1215 | delete calendar; | 1221 | delete calendar; |
1216 | if ( syncOK ) | 1222 | if ( syncOK ) |
1217 | updateView(); | 1223 | updateView(); |
1218 | return syncOK; | 1224 | return syncOK; |
1219 | } | 1225 | } |
1220 | void CalendarView::syncPhone() | 1226 | void CalendarView::syncPhone() |
1221 | { | 1227 | { |
1222 | syncExternal( 1 ); | 1228 | syncExternal( 1 ); |
1223 | } | 1229 | } |
1224 | void CalendarView::syncExternal( int mode ) | 1230 | void CalendarView::syncExternal( int mode ) |
1225 | { | 1231 | { |
1226 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1232 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1227 | //mCurrentSyncDevice = "sharp-DTM"; | 1233 | //mCurrentSyncDevice = "sharp-DTM"; |
1228 | if ( KOPrefs::instance()->mAskForPreferences ) | 1234 | if ( KOPrefs::instance()->mAskForPreferences ) |
1229 | edit_sync_options(); | 1235 | edit_sync_options(); |
1230 | qApp->processEvents(); | 1236 | qApp->processEvents(); |
1231 | CalendarLocal* calendar = new CalendarLocal(); | 1237 | CalendarLocal* calendar = new CalendarLocal(); |
1232 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1238 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1233 | bool syncOK = false; | 1239 | bool syncOK = false; |
1234 | bool loadSuccess = false; | 1240 | bool loadSuccess = false; |
1235 | PhoneFormat* phoneFormat = 0; | 1241 | PhoneFormat* phoneFormat = 0; |
1236 | #ifndef DESKTOP_VERSION | 1242 | #ifndef DESKTOP_VERSION |
1237 | SharpFormat* sharpFormat = 0; | 1243 | SharpFormat* sharpFormat = 0; |
1238 | if ( mode == 0 ) { // sharp | 1244 | if ( mode == 0 ) { // sharp |
1239 | sharpFormat = new SharpFormat () ; | 1245 | sharpFormat = new SharpFormat () ; |
1240 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1246 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1241 | 1247 | ||
1242 | } else | 1248 | } else |
1243 | #endif | 1249 | #endif |
1244 | if ( mode == 1 ) { // phone | 1250 | if ( mode == 1 ) { // phone |
1245 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1251 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1246 | KOPrefs::instance()->mPhoneDevice, | 1252 | KOPrefs::instance()->mPhoneDevice, |
1247 | KOPrefs::instance()->mPhoneConnection, | 1253 | KOPrefs::instance()->mPhoneConnection, |
1248 | KOPrefs::instance()->mPhoneModel); | 1254 | KOPrefs::instance()->mPhoneModel); |
1249 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1255 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1250 | 1256 | ||
1251 | } else | 1257 | } else |
1252 | return; | 1258 | return; |
1253 | if ( loadSuccess ) { | 1259 | if ( loadSuccess ) { |
1254 | getEventViewerDialog()->setSyncMode( true ); | 1260 | getEventViewerDialog()->setSyncMode( true ); |
1255 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1261 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1256 | getEventViewerDialog()->setSyncMode( false ); | 1262 | getEventViewerDialog()->setSyncMode( false ); |
1257 | qApp->processEvents(); | 1263 | qApp->processEvents(); |
1258 | if ( syncOK ) { | 1264 | if ( syncOK ) { |
1259 | if ( KOPrefs::instance()->mWriteBackFile ) | 1265 | if ( KOPrefs::instance()->mWriteBackFile ) |
1260 | { | 1266 | { |
1261 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1267 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1262 | Incidence* inc = iL.first(); | 1268 | Incidence* inc = iL.first(); |
1263 | if ( phoneFormat ) { | 1269 | if ( phoneFormat ) { |
1264 | while ( inc ) { | 1270 | while ( inc ) { |
1265 | inc->removeID(mCurrentSyncDevice); | 1271 | inc->removeID(mCurrentSyncDevice); |
1266 | inc = iL.next(); | 1272 | inc = iL.next(); |
1267 | } | 1273 | } |
1268 | } | 1274 | } |
1269 | #ifndef DESKTOP_VERSION | 1275 | #ifndef DESKTOP_VERSION |
1270 | if ( sharpFormat ) | 1276 | if ( sharpFormat ) |
1271 | sharpFormat->save(calendar); | 1277 | sharpFormat->save(calendar); |
1272 | #endif | 1278 | #endif |
1273 | if ( phoneFormat ) | 1279 | if ( phoneFormat ) |
1274 | phoneFormat->save(calendar); | 1280 | phoneFormat->save(calendar); |
1275 | iL = calendar->rawIncidences(); | 1281 | iL = calendar->rawIncidences(); |
1276 | inc = iL.first(); | 1282 | inc = iL.first(); |
1277 | Incidence* loc; | 1283 | Incidence* loc; |
1278 | while ( inc ) { | 1284 | while ( inc ) { |
1279 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1285 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1280 | loc = mCalendar->incidence(inc->uid() ); | 1286 | loc = mCalendar->incidence(inc->uid() ); |
1281 | if ( loc ) { | 1287 | if ( loc ) { |
1282 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1288 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1283 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1289 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1284 | } | 1290 | } |
1285 | } | 1291 | } |
1286 | inc = iL.next(); | 1292 | inc = iL.next(); |
1287 | } | 1293 | } |
1288 | Incidence* lse = getLastSyncEvent(); | 1294 | Incidence* lse = getLastSyncEvent(); |
1289 | if ( lse ) { | 1295 | if ( lse ) { |
1290 | lse->setReadOnly( false ); | 1296 | lse->setReadOnly( false ); |
1291 | lse->setDescription( "" ); | 1297 | lse->setDescription( "" ); |
1292 | lse->setReadOnly( true ); | 1298 | lse->setReadOnly( true ); |
1293 | } | 1299 | } |
1294 | } | 1300 | } |
1295 | } | 1301 | } |
1296 | setModified( true ); | 1302 | setModified( true ); |
1297 | } else { | 1303 | } else { |
1298 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1304 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1299 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1305 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1300 | question, i18n("Ok")) ; | 1306 | question, i18n("Ok")) ; |
1301 | 1307 | ||
1302 | } | 1308 | } |
1303 | delete calendar; | 1309 | delete calendar; |
1304 | updateView(); | 1310 | updateView(); |
1305 | return ;//syncOK; | 1311 | return ;//syncOK; |
1306 | 1312 | ||
1307 | } | 1313 | } |
1308 | void CalendarView::syncSharp() | 1314 | void CalendarView::syncSharp() |
1309 | { | 1315 | { |
1310 | syncExternal( 0 ); | 1316 | syncExternal( 0 ); |
1311 | 1317 | ||
1312 | } | 1318 | } |
1313 | 1319 | ||
1314 | 1320 | ||
1315 | #include <kabc/stdaddressbook.h> | 1321 | #include <kabc/stdaddressbook.h> |
1316 | bool CalendarView::importBday() | 1322 | bool CalendarView::importBday() |
1317 | { | 1323 | { |
1318 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1324 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1319 | KABC::AddressBook::Iterator it; | 1325 | KABC::AddressBook::Iterator it; |
1320 | int count = 0; | 1326 | int count = 0; |
1321 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1327 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1322 | ++count; | 1328 | ++count; |
1323 | } | 1329 | } |
1324 | QProgressBar bar(count,0 ); | 1330 | QProgressBar bar(count,0 ); |
1325 | int w = 300; | 1331 | int w = 300; |
1326 | if ( QApplication::desktop()->width() < 320 ) | 1332 | if ( QApplication::desktop()->width() < 320 ) |
1327 | w = 220; | 1333 | w = 220; |
1328 | int h = bar.sizeHint().height() ; | 1334 | int h = bar.sizeHint().height() ; |
1329 | int dw = QApplication::desktop()->width(); | 1335 | int dw = QApplication::desktop()->width(); |
1330 | int dh = QApplication::desktop()->height(); | 1336 | int dh = QApplication::desktop()->height(); |
1331 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1337 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1332 | bar.show(); | 1338 | bar.show(); |
1333 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1339 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1334 | qApp->processEvents(); | 1340 | qApp->processEvents(); |
1335 | count = 0; | 1341 | count = 0; |
1336 | int addCount = 0; | 1342 | int addCount = 0; |
1337 | KCal::Attendee* a = 0; | 1343 | KCal::Attendee* a = 0; |
1338 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1344 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1339 | if ( ! bar.isVisible() ) | 1345 | if ( ! bar.isVisible() ) |
1340 | return false; | 1346 | return false; |
1341 | bar.setProgress( count++ ); | 1347 | bar.setProgress( count++ ); |
1342 | qApp->processEvents(); | 1348 | qApp->processEvents(); |
1343 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1349 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1344 | if ( (*it).birthday().date().isValid() ){ | 1350 | if ( (*it).birthday().date().isValid() ){ |
1345 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1351 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1346 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1352 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1347 | ++addCount; | 1353 | ++addCount; |
1348 | } | 1354 | } |
1349 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1355 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1350 | if ( anni.isValid() ){ | 1356 | if ( anni.isValid() ){ |
1351 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1357 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1352 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1358 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1353 | ++addCount; | 1359 | ++addCount; |
1354 | } | 1360 | } |
1355 | } | 1361 | } |
1356 | updateView(); | 1362 | updateView(); |
1357 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1363 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1358 | return true; | 1364 | return true; |
1359 | } | 1365 | } |
1360 | 1366 | ||
1361 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1367 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1362 | { | 1368 | { |
1363 | //qDebug("addAnni "); | 1369 | //qDebug("addAnni "); |
1364 | Event * ev = new Event(); | 1370 | Event * ev = new Event(); |
1365 | if ( a ) { | 1371 | if ( a ) { |
1366 | ev->addAttendee( a ); | 1372 | ev->addAttendee( a ); |
1367 | } | 1373 | } |
1368 | QString kind; | 1374 | QString kind; |
1369 | if ( birthday ) | 1375 | if ( birthday ) |
1370 | kind = i18n( "Birthday" ); | 1376 | kind = i18n( "Birthday" ); |
1371 | else | 1377 | else |
1372 | kind = i18n( "Anniversary" ); | 1378 | kind = i18n( "Anniversary" ); |
1373 | ev->setSummary( name + " - " + kind ); | 1379 | ev->setSummary( name + " - " + kind ); |
1374 | ev->setOrganizer( "nobody@nowhere" ); | 1380 | ev->setOrganizer( "nobody@nowhere" ); |
1375 | ev->setCategories( kind ); | 1381 | ev->setCategories( kind ); |
1376 | ev->setDtStart( QDateTime(date) ); | 1382 | ev->setDtStart( QDateTime(date) ); |
1377 | ev->setDtEnd( QDateTime(date) ); | 1383 | ev->setDtEnd( QDateTime(date) ); |
1378 | ev->setFloats( true ); | 1384 | ev->setFloats( true ); |
1379 | Recurrence * rec = ev->recurrence(); | 1385 | Recurrence * rec = ev->recurrence(); |
1380 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1386 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1381 | rec->addYearlyNum( date.month() ); | 1387 | rec->addYearlyNum( date.month() ); |
1382 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1388 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1383 | delete ev; | 1389 | delete ev; |
1384 | return false; | 1390 | return false; |
1385 | } | 1391 | } |
1386 | return true; | 1392 | return true; |
1387 | 1393 | ||
1388 | } | 1394 | } |
1389 | bool CalendarView::importQtopia( const QString &categories, | 1395 | bool CalendarView::importQtopia( const QString &categories, |
1390 | const QString &datebook, | 1396 | const QString &datebook, |
1391 | const QString &todolist ) | 1397 | const QString &todolist ) |
1392 | { | 1398 | { |
1393 | 1399 | ||
1394 | QtopiaFormat qtopiaFormat; | 1400 | QtopiaFormat qtopiaFormat; |
1395 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1401 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1396 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1402 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1397 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1403 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1398 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1404 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1399 | 1405 | ||
1400 | updateView(); | 1406 | updateView(); |
1401 | return true; | 1407 | return true; |
1402 | 1408 | ||
1403 | #if 0 | 1409 | #if 0 |
1404 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1410 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1405 | mCurrentSyncDevice = "qtopia-XML"; | 1411 | mCurrentSyncDevice = "qtopia-XML"; |
1406 | if ( KOPrefs::instance()->mAskForPreferences ) | 1412 | if ( KOPrefs::instance()->mAskForPreferences ) |
1407 | edit_sync_options(); | 1413 | edit_sync_options(); |
1408 | qApp->processEvents(); | 1414 | qApp->processEvents(); |
1409 | CalendarLocal* calendar = new CalendarLocal(); | 1415 | CalendarLocal* calendar = new CalendarLocal(); |
1410 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1416 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1411 | bool syncOK = false; | 1417 | bool syncOK = false; |
1412 | QtopiaFormat qtopiaFormat; | 1418 | QtopiaFormat qtopiaFormat; |
1413 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1419 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1414 | bool loadOk = true; | 1420 | bool loadOk = true; |
1415 | if ( !categories.isEmpty() ) | 1421 | if ( !categories.isEmpty() ) |
1416 | loadOk = qtopiaFormat.load( calendar, categories ); | 1422 | loadOk = qtopiaFormat.load( calendar, categories ); |
1417 | if ( loadOk && !datebook.isEmpty() ) | 1423 | if ( loadOk && !datebook.isEmpty() ) |
1418 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1424 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1419 | if ( loadOk && !todolist.isEmpty() ) | 1425 | if ( loadOk && !todolist.isEmpty() ) |
1420 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1426 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1421 | 1427 | ||
1422 | if ( loadOk ) { | 1428 | if ( loadOk ) { |
1423 | getEventViewerDialog()->setSyncMode( true ); | 1429 | getEventViewerDialog()->setSyncMode( true ); |
1424 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1430 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1425 | getEventViewerDialog()->setSyncMode( false ); | 1431 | getEventViewerDialog()->setSyncMode( false ); |
1426 | qApp->processEvents(); | 1432 | qApp->processEvents(); |
1427 | if ( syncOK ) { | 1433 | if ( syncOK ) { |
1428 | if ( KOPrefs::instance()->mWriteBackFile ) | 1434 | if ( KOPrefs::instance()->mWriteBackFile ) |
1429 | { | 1435 | { |
1430 | // write back XML file | 1436 | // write back XML file |
1431 | 1437 | ||
1432 | } | 1438 | } |
1433 | setModified( true ); | 1439 | setModified( true ); |
1434 | } | 1440 | } |
1435 | } else { | 1441 | } else { |
1436 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1442 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1437 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1443 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1438 | question, i18n("Ok")) ; | 1444 | question, i18n("Ok")) ; |
1439 | } | 1445 | } |
1440 | delete calendar; | 1446 | delete calendar; |
1441 | updateView(); | 1447 | updateView(); |
1442 | return syncOK; | 1448 | return syncOK; |
1443 | 1449 | ||
1444 | 1450 | ||
1445 | #endif | 1451 | #endif |
1446 | 1452 | ||
1447 | } | 1453 | } |
1448 | 1454 | ||
1449 | void CalendarView::setSyncEventsReadOnly() | 1455 | void CalendarView::setSyncEventsReadOnly() |
1450 | { | 1456 | { |
1451 | Event * ev; | 1457 | Event * ev; |
1452 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1458 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1453 | ev = eL.first(); | 1459 | ev = eL.first(); |
1454 | while ( ev ) { | 1460 | while ( ev ) { |
1455 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1461 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1456 | ev->setReadOnly( true ); | 1462 | ev->setReadOnly( true ); |
1457 | ev = eL.next(); | 1463 | ev = eL.next(); |
1458 | } | 1464 | } |
1459 | } | 1465 | } |
1460 | bool CalendarView::openCalendar(QString filename, bool merge) | 1466 | bool CalendarView::openCalendar(QString filename, bool merge) |
1461 | { | 1467 | { |
1462 | 1468 | ||
1463 | if (filename.isEmpty()) { | 1469 | if (filename.isEmpty()) { |
1464 | return false; | 1470 | return false; |
1465 | } | 1471 | } |
1466 | 1472 | ||
1467 | if (!QFile::exists(filename)) { | 1473 | if (!QFile::exists(filename)) { |
1468 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1474 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1469 | return false; | 1475 | return false; |
1470 | } | 1476 | } |
1471 | 1477 | ||
1472 | globalFlagBlockAgenda = 1; | 1478 | globalFlagBlockAgenda = 1; |
1473 | if (!merge) mCalendar->close(); | 1479 | if (!merge) mCalendar->close(); |
1474 | 1480 | ||
1475 | mStorage->setFileName( filename ); | 1481 | mStorage->setFileName( filename ); |
1476 | 1482 | ||
1477 | if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { | 1483 | if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { |
1478 | if ( merge ) ;//setModified( true ); | 1484 | if ( merge ) ;//setModified( true ); |
1479 | else { | 1485 | else { |
1480 | //setModified( true ); | 1486 | //setModified( true ); |
1481 | mViewManager->setDocumentId( filename ); | 1487 | mViewManager->setDocumentId( filename ); |
1482 | mDialogManager->setDocumentId( filename ); | 1488 | mDialogManager->setDocumentId( filename ); |
1483 | mTodoList->setDocumentId( filename ); | 1489 | mTodoList->setDocumentId( filename ); |
1484 | } | 1490 | } |
1485 | globalFlagBlockAgenda = 2; | 1491 | globalFlagBlockAgenda = 2; |
1486 | // if ( getLastSyncEvent() ) | 1492 | // if ( getLastSyncEvent() ) |
1487 | // getLastSyncEvent()->setReadOnly( true ); | 1493 | // getLastSyncEvent()->setReadOnly( true ); |
1488 | mCalendar->reInitAlarmSettings(); | 1494 | mCalendar->reInitAlarmSettings(); |
1489 | setSyncEventsReadOnly(); | 1495 | setSyncEventsReadOnly(); |
1490 | updateUnmanagedViews(); | 1496 | updateUnmanagedViews(); |
1491 | updateView(); | 1497 | updateView(); |
1492 | if ( filename != MainWindow::defaultFileName() ) | 1498 | if ( filename != MainWindow::defaultFileName() ) |
1493 | saveCalendar( MainWindow::defaultFileName() ); | 1499 | saveCalendar( MainWindow::defaultFileName() ); |
1494 | loadedFileVersion = QDateTime::currentDateTime(); | 1500 | loadedFileVersion = QDateTime::currentDateTime(); |
1495 | return true; | 1501 | return true; |
1496 | } else { | 1502 | } else { |
1497 | // while failing to load, the calendar object could | 1503 | // while failing to load, the calendar object could |
1498 | // have become partially populated. Clear it out. | 1504 | // have become partially populated. Clear it out. |
1499 | if ( !merge ) mCalendar->close(); | 1505 | if ( !merge ) mCalendar->close(); |
1500 | 1506 | ||
1501 | KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1507 | KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1502 | 1508 | ||
1503 | globalFlagBlockAgenda = 2; | 1509 | globalFlagBlockAgenda = 2; |
1504 | updateView(); | 1510 | updateView(); |
1505 | } | 1511 | } |
1506 | return false; | 1512 | return false; |
1507 | } | 1513 | } |
1508 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1514 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1509 | { | 1515 | { |
1510 | loadedFileVersion = dt; | 1516 | loadedFileVersion = dt; |
1511 | } | 1517 | } |
1512 | bool CalendarView::checkFileChanged(QString fn) | 1518 | bool CalendarView::checkFileChanged(QString fn) |
1513 | { | 1519 | { |
1514 | QFileInfo finf ( fn ); | 1520 | QFileInfo finf ( fn ); |
1515 | if ( !finf.exists() ) | 1521 | if ( !finf.exists() ) |
1516 | return true; | 1522 | return true; |
1517 | QDateTime dt = finf.lastModified (); | 1523 | QDateTime dt = finf.lastModified (); |
1518 | if ( dt <= loadedFileVersion ) | 1524 | if ( dt <= loadedFileVersion ) |
1519 | return false; | 1525 | return false; |
1520 | return true; | 1526 | return true; |
1521 | 1527 | ||
1522 | } | 1528 | } |
1523 | bool CalendarView::checkFileVersion(QString fn) | 1529 | bool CalendarView::checkFileVersion(QString fn) |
1524 | { | 1530 | { |
1525 | QFileInfo finf ( fn ); | 1531 | QFileInfo finf ( fn ); |
1526 | if ( !finf.exists() ) | 1532 | if ( !finf.exists() ) |
1527 | return true; | 1533 | return true; |
1528 | QDateTime dt = finf.lastModified (); | 1534 | QDateTime dt = finf.lastModified (); |
1529 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 1535 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
1530 | //qDebug("file on disk version %s",dt.toString().latin1()); | 1536 | //qDebug("file on disk version %s",dt.toString().latin1()); |
1531 | if ( dt <= loadedFileVersion ) | 1537 | if ( dt <= loadedFileVersion ) |
1532 | return true; | 1538 | return true; |
1533 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , | 1539 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , |
1534 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 1540 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
1535 | i18n("Sync+save")); | 1541 | i18n("Sync+save")); |
1536 | 1542 | ||
1537 | if ( km == KMessageBox::Cancel ) | 1543 | if ( km == KMessageBox::Cancel ) |
1538 | return false; | 1544 | return false; |
1539 | if ( km == KMessageBox::Yes ) | 1545 | if ( km == KMessageBox::Yes ) |
1540 | return true; | 1546 | return true; |
1541 | 1547 | ||
1542 | setSyncDevice("deleteaftersync" ); | 1548 | setSyncDevice("deleteaftersync" ); |
1543 | KOPrefs::instance()->mAskForPreferences = true; | 1549 | KOPrefs::instance()->mAskForPreferences = true; |
1544 | KOPrefs::instance()->mSyncAlgoPrefs = 3; | 1550 | KOPrefs::instance()->mSyncAlgoPrefs = 3; |
1545 | KOPrefs::instance()->mWriteBackFile = false; | 1551 | KOPrefs::instance()->mWriteBackFile = false; |
1546 | KOPrefs::instance()->mWriteBackExistingOnly = false; | 1552 | KOPrefs::instance()->mWriteBackExistingOnly = false; |
1547 | KOPrefs::instance()->mShowSyncSummary = false; | 1553 | KOPrefs::instance()->mShowSyncSummary = false; |
1548 | syncCalendar( fn, 3 ); | 1554 | syncCalendar( fn, 3 ); |
1549 | Event * e = getLastSyncEvent(); | 1555 | Event * e = getLastSyncEvent(); |
1550 | mCalendar->deleteEvent ( e ); | 1556 | mCalendar->deleteEvent ( e ); |
1551 | updateView(); | 1557 | updateView(); |
1552 | return true; | 1558 | return true; |
1553 | } | 1559 | } |
1554 | 1560 | ||
1555 | bool CalendarView::saveCalendar( QString filename ) | 1561 | bool CalendarView::saveCalendar( QString filename ) |
1556 | { | 1562 | { |
1557 | 1563 | ||
1558 | // Store back all unsaved data into calendar object | 1564 | // Store back all unsaved data into calendar object |
1559 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 1565 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
1560 | if ( mViewManager->currentView() ) | 1566 | if ( mViewManager->currentView() ) |
1561 | mViewManager->currentView()->flushView(); | 1567 | mViewManager->currentView()->flushView(); |
1562 | 1568 | ||
1563 | //mStorage->setFileName( filename ); | 1569 | //mStorage->setFileName( filename ); |
1564 | 1570 | ||
1565 | mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 1571 | mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
1566 | mStorage->setFileName( filename ); | 1572 | mStorage->setFileName( filename ); |
1567 | bool success; | 1573 | bool success; |
1568 | success = mStorage->save(); | 1574 | success = mStorage->save(); |
1569 | if ( !success ) { | 1575 | if ( !success ) { |
1570 | return false; | 1576 | return false; |
1571 | } | 1577 | } |
1572 | 1578 | ||
1573 | return true; | 1579 | return true; |
1574 | } | 1580 | } |
1575 | 1581 | ||
1576 | void CalendarView::closeCalendar() | 1582 | void CalendarView::closeCalendar() |
1577 | { | 1583 | { |
1578 | 1584 | ||
1579 | // child windows no longer valid | 1585 | // child windows no longer valid |
1580 | emit closingDown(); | 1586 | emit closingDown(); |
1581 | 1587 | ||
1582 | mCalendar->close(); | 1588 | mCalendar->close(); |
1583 | setModified(false); | 1589 | setModified(false); |
1584 | updateView(); | 1590 | updateView(); |
1585 | } | 1591 | } |
1586 | 1592 | ||
1587 | void CalendarView::archiveCalendar() | 1593 | void CalendarView::archiveCalendar() |
1588 | { | 1594 | { |
1589 | mDialogManager->showArchiveDialog(); | 1595 | mDialogManager->showArchiveDialog(); |
1590 | } | 1596 | } |
1591 | 1597 | ||
1592 | 1598 | ||
1593 | void CalendarView::readSettings() | 1599 | void CalendarView::readSettings() |
1594 | { | 1600 | { |
1595 | 1601 | ||
1596 | 1602 | ||
1597 | // mViewManager->showAgendaView(); | 1603 | // mViewManager->showAgendaView(); |
1598 | QString str; | 1604 | QString str; |
1599 | //qDebug("CalendarView::readSettings() "); | 1605 | //qDebug("CalendarView::readSettings() "); |
1600 | // read settings from the KConfig, supplying reasonable | 1606 | // read settings from the KConfig, supplying reasonable |
1601 | // defaults where none are to be found | 1607 | // defaults where none are to be found |
1602 | KConfig *config = KOGlobals::config(); | 1608 | KConfig *config = KOGlobals::config(); |
1603 | #ifndef KORG_NOSPLITTER | 1609 | #ifndef KORG_NOSPLITTER |
1604 | config->setGroup("KOrganizer Geometry"); | 1610 | config->setGroup("KOrganizer Geometry"); |
1605 | 1611 | ||
1606 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 1612 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
1607 | if (sizes.count() != 2) { | 1613 | if (sizes.count() != 2) { |
1608 | sizes << mDateNavigator->minimumSizeHint().width(); | 1614 | sizes << mDateNavigator->minimumSizeHint().width(); |
1609 | sizes << 300; | 1615 | sizes << 300; |
1610 | } | 1616 | } |
1611 | mPanner->setSizes(sizes); | 1617 | mPanner->setSizes(sizes); |
1612 | 1618 | ||
1613 | sizes = config->readIntListEntry("Separator2"); | 1619 | sizes = config->readIntListEntry("Separator2"); |
1614 | if ( ( mResourceView && sizes.count() == 4 ) || | 1620 | if ( ( mResourceView && sizes.count() == 4 ) || |
1615 | ( !mResourceView && sizes.count() == 3 ) ) { | 1621 | ( !mResourceView && sizes.count() == 3 ) ) { |
1616 | mLeftSplitter->setSizes(sizes); | 1622 | mLeftSplitter->setSizes(sizes); |
1617 | } | 1623 | } |
1618 | #endif | 1624 | #endif |
1619 | globalFlagBlockAgenda = 1; | 1625 | globalFlagBlockAgenda = 1; |
1620 | mViewManager->showAgendaView(); | 1626 | mViewManager->showAgendaView(); |
1621 | //mViewManager->readSettings( config ); | 1627 | //mViewManager->readSettings( config ); |
1622 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 1628 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
1623 | readFilterSettings(config); | 1629 | readFilterSettings(config); |
1624 | config->setGroup( "Views" ); | 1630 | config->setGroup( "Views" ); |
1625 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 1631 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
1626 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 1632 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
1627 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 1633 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
1628 | else mNavigator->selectDates( dateCount ); | 1634 | else mNavigator->selectDates( dateCount ); |
1629 | // mViewManager->readSettings( config ); | 1635 | // mViewManager->readSettings( config ); |
1630 | updateConfig(); | 1636 | updateConfig(); |
1631 | globalFlagBlockAgenda = 2; | 1637 | globalFlagBlockAgenda = 2; |
1632 | mViewManager->readSettings( config ); | 1638 | mViewManager->readSettings( config ); |
1633 | #ifdef DESKTOP_VERSION | 1639 | #ifdef DESKTOP_VERSION |
1634 | config->setGroup("WidgetLayout"); | 1640 | config->setGroup("WidgetLayout"); |
1635 | QStringList list; | 1641 | QStringList list; |
1636 | list = config->readListEntry("MainLayout"); | 1642 | list = config->readListEntry("MainLayout"); |
1637 | int x,y,w,h; | 1643 | int x,y,w,h; |
1638 | if ( ! list.isEmpty() ) { | 1644 | if ( ! list.isEmpty() ) { |
1639 | x = list[0].toInt(); | 1645 | x = list[0].toInt(); |
1640 | y = list[1].toInt(); | 1646 | y = list[1].toInt(); |
1641 | w = list[2].toInt(); | 1647 | w = list[2].toInt(); |
1642 | h = list[3].toInt(); | 1648 | h = list[3].toInt(); |
1643 | topLevelWidget()->setGeometry(x,y,w,h); | 1649 | topLevelWidget()->setGeometry(x,y,w,h); |
1644 | 1650 | ||
1645 | } else { | 1651 | } else { |
1646 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 1652 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
1647 | } | 1653 | } |
1648 | list = config->readListEntry("EditEventLayout"); | 1654 | list = config->readListEntry("EditEventLayout"); |
1649 | if ( ! list.isEmpty() ) { | 1655 | if ( ! list.isEmpty() ) { |
1650 | x = list[0].toInt(); | 1656 | x = list[0].toInt(); |
1651 | y = list[1].toInt(); | 1657 | y = list[1].toInt(); |
1652 | w = list[2].toInt(); | 1658 | w = list[2].toInt(); |
1653 | h = list[3].toInt(); | 1659 | h = list[3].toInt(); |
1654 | mEventEditor->setGeometry(x,y,w,h); | 1660 | mEventEditor->setGeometry(x,y,w,h); |
1655 | 1661 | ||
1656 | } | 1662 | } |
1657 | list = config->readListEntry("EditTodoLayout"); | 1663 | list = config->readListEntry("EditTodoLayout"); |
1658 | if ( ! list.isEmpty() ) { | 1664 | if ( ! list.isEmpty() ) { |
1659 | x = list[0].toInt(); | 1665 | x = list[0].toInt(); |
1660 | y = list[1].toInt(); | 1666 | y = list[1].toInt(); |
1661 | w = list[2].toInt(); | 1667 | w = list[2].toInt(); |
1662 | h = list[3].toInt(); | 1668 | h = list[3].toInt(); |
1663 | mTodoEditor->setGeometry(x,y,w,h); | 1669 | mTodoEditor->setGeometry(x,y,w,h); |
1664 | 1670 | ||
1665 | } | 1671 | } |
1666 | list = config->readListEntry("ViewerLayout"); | 1672 | list = config->readListEntry("ViewerLayout"); |
1667 | if ( ! list.isEmpty() ) { | 1673 | if ( ! list.isEmpty() ) { |
1668 | x = list[0].toInt(); | 1674 | x = list[0].toInt(); |
1669 | y = list[1].toInt(); | 1675 | y = list[1].toInt(); |
1670 | w = list[2].toInt(); | 1676 | w = list[2].toInt(); |
1671 | h = list[3].toInt(); | 1677 | h = list[3].toInt(); |
1672 | getEventViewerDialog()->setGeometry(x,y,w,h); | 1678 | getEventViewerDialog()->setGeometry(x,y,w,h); |
1673 | } | 1679 | } |
1674 | #endif | 1680 | #endif |
1675 | 1681 | ||
1676 | } | 1682 | } |
1677 | 1683 | ||
1678 | 1684 | ||
1679 | void CalendarView::writeSettings() | 1685 | void CalendarView::writeSettings() |
1680 | { | 1686 | { |
1681 | // kdDebug() << "CalendarView::writeSettings" << endl; | 1687 | // kdDebug() << "CalendarView::writeSettings" << endl; |
1682 | 1688 | ||
1683 | KConfig *config = KOGlobals::config(); | 1689 | KConfig *config = KOGlobals::config(); |
1684 | 1690 | ||
1685 | #ifndef KORG_NOSPLITTER | 1691 | #ifndef KORG_NOSPLITTER |
1686 | config->setGroup("KOrganizer Geometry"); | 1692 | config->setGroup("KOrganizer Geometry"); |
1687 | 1693 | ||
1688 | QValueList<int> list = mPanner->sizes(); | 1694 | QValueList<int> list = mPanner->sizes(); |
1689 | config->writeEntry("Separator1",list); | 1695 | config->writeEntry("Separator1",list); |
1690 | 1696 | ||
1691 | list = mLeftSplitter->sizes(); | 1697 | list = mLeftSplitter->sizes(); |
1692 | config->writeEntry("Separator2",list); | 1698 | config->writeEntry("Separator2",list); |
1693 | #endif | 1699 | #endif |
1694 | 1700 | ||
1695 | mViewManager->writeSettings( config ); | 1701 | mViewManager->writeSettings( config ); |
1696 | mTodoList->saveLayout(config,QString("Todo Layout")); | 1702 | mTodoList->saveLayout(config,QString("Todo Layout")); |
1697 | mDialogManager->writeSettings( config ); | 1703 | mDialogManager->writeSettings( config ); |
1698 | //KOPrefs::instance()->usrWriteConfig(); | 1704 | //KOPrefs::instance()->usrWriteConfig(); |
1699 | KOPrefs::instance()->writeConfig(); | 1705 | KOPrefs::instance()->writeConfig(); |
1700 | 1706 | ||
1701 | writeFilterSettings(config); | 1707 | writeFilterSettings(config); |
1702 | 1708 | ||
1703 | config->setGroup( "Views" ); | 1709 | config->setGroup( "Views" ); |
1704 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); | 1710 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); |
1705 | 1711 | ||
1706 | #ifdef DESKTOP_VERSION | 1712 | #ifdef DESKTOP_VERSION |
1707 | config->setGroup("WidgetLayout"); | 1713 | config->setGroup("WidgetLayout"); |
1708 | QStringList list ;//= config->readListEntry("MainLayout"); | 1714 | QStringList list ;//= config->readListEntry("MainLayout"); |
1709 | int x,y,w,h; | 1715 | int x,y,w,h; |
1710 | QWidget* wid; | 1716 | QWidget* wid; |
1711 | wid = topLevelWidget(); | 1717 | wid = topLevelWidget(); |
1712 | x = wid->geometry().x(); | 1718 | x = wid->geometry().x(); |
1713 | y = wid->geometry().y(); | 1719 | y = wid->geometry().y(); |
1714 | w = wid->width(); | 1720 | w = wid->width(); |
1715 | h = wid->height(); | 1721 | h = wid->height(); |
1716 | list.clear(); | 1722 | list.clear(); |
1717 | list << QString::number( x ); | 1723 | list << QString::number( x ); |
1718 | list << QString::number( y ); | 1724 | list << QString::number( y ); |
1719 | list << QString::number( w ); | 1725 | list << QString::number( w ); |
1720 | list << QString::number( h ); | 1726 | list << QString::number( h ); |
1721 | config->writeEntry("MainLayout",list ); | 1727 | config->writeEntry("MainLayout",list ); |
1722 | 1728 | ||
1723 | wid = mEventEditor; | 1729 | wid = mEventEditor; |
1724 | x = wid->geometry().x(); | 1730 | x = wid->geometry().x(); |
1725 | y = wid->geometry().y(); | 1731 | y = wid->geometry().y(); |
1726 | w = wid->width(); | 1732 | w = wid->width(); |
1727 | h = wid->height(); | 1733 | h = wid->height(); |
1728 | list.clear(); | 1734 | list.clear(); |
1729 | list << QString::number( x ); | 1735 | list << QString::number( x ); |
1730 | list << QString::number( y ); | 1736 | list << QString::number( y ); |
1731 | list << QString::number( w ); | 1737 | list << QString::number( w ); |
1732 | list << QString::number( h ); | 1738 | list << QString::number( h ); |
1733 | config->writeEntry("EditEventLayout",list ); | 1739 | config->writeEntry("EditEventLayout",list ); |
1734 | 1740 | ||
1735 | wid = mTodoEditor; | 1741 | wid = mTodoEditor; |
1736 | x = wid->geometry().x(); | 1742 | x = wid->geometry().x(); |
1737 | y = wid->geometry().y(); | 1743 | y = wid->geometry().y(); |
1738 | w = wid->width(); | 1744 | w = wid->width(); |
1739 | h = wid->height(); | 1745 | h = wid->height(); |
1740 | list.clear(); | 1746 | list.clear(); |
1741 | list << QString::number( x ); | 1747 | list << QString::number( x ); |
1742 | list << QString::number( y ); | 1748 | list << QString::number( y ); |
1743 | list << QString::number( w ); | 1749 | list << QString::number( w ); |
1744 | list << QString::number( h ); | 1750 | list << QString::number( h ); |
1745 | config->writeEntry("EditTodoLayout",list ); | 1751 | config->writeEntry("EditTodoLayout",list ); |
1746 | wid = getEventViewerDialog(); | 1752 | wid = getEventViewerDialog(); |
1747 | x = wid->geometry().x(); | 1753 | x = wid->geometry().x(); |
1748 | y = wid->geometry().y(); | 1754 | y = wid->geometry().y(); |
1749 | w = wid->width(); | 1755 | w = wid->width(); |
1750 | h = wid->height(); | 1756 | h = wid->height(); |
1751 | list.clear(); | 1757 | list.clear(); |
1752 | list << QString::number( x ); | 1758 | list << QString::number( x ); |
1753 | list << QString::number( y ); | 1759 | list << QString::number( y ); |
1754 | list << QString::number( w ); | 1760 | list << QString::number( w ); |
1755 | list << QString::number( h ); | 1761 | list << QString::number( h ); |
1756 | config->writeEntry("ViewerLayout",list ); | 1762 | config->writeEntry("ViewerLayout",list ); |
1757 | wid = mDialogManager->getSearchDialog(); | 1763 | wid = mDialogManager->getSearchDialog(); |
1758 | if ( wid ) { | 1764 | if ( wid ) { |
1759 | x = wid->geometry().x(); | 1765 | x = wid->geometry().x(); |
1760 | y = wid->geometry().y(); | 1766 | y = wid->geometry().y(); |
1761 | w = wid->width(); | 1767 | w = wid->width(); |
1762 | h = wid->height(); | 1768 | h = wid->height(); |
1763 | list.clear(); | 1769 | list.clear(); |
1764 | list << QString::number( x ); | 1770 | list << QString::number( x ); |
1765 | list << QString::number( y ); | 1771 | list << QString::number( y ); |
1766 | list << QString::number( w ); | 1772 | list << QString::number( w ); |
1767 | list << QString::number( h ); | 1773 | list << QString::number( h ); |
1768 | config->writeEntry("SearchLayout",list ); | 1774 | config->writeEntry("SearchLayout",list ); |
1769 | } | 1775 | } |
1770 | #endif | 1776 | #endif |
1771 | 1777 | ||
1772 | 1778 | ||
1773 | config->sync(); | 1779 | config->sync(); |
1774 | } | 1780 | } |
1775 | 1781 | ||
1776 | void CalendarView::readFilterSettings(KConfig *config) | 1782 | void CalendarView::readFilterSettings(KConfig *config) |
1777 | { | 1783 | { |
1778 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; | 1784 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; |
1779 | 1785 | ||
1780 | mFilters.clear(); | 1786 | mFilters.clear(); |
1781 | 1787 | ||
1782 | config->setGroup("General"); | 1788 | config->setGroup("General"); |
1783 | QStringList filterList = config->readListEntry("CalendarFilters"); | 1789 | QStringList filterList = config->readListEntry("CalendarFilters"); |
1784 | 1790 | ||
1785 | QStringList::ConstIterator it = filterList.begin(); | 1791 | QStringList::ConstIterator it = filterList.begin(); |
1786 | QStringList::ConstIterator end = filterList.end(); | 1792 | QStringList::ConstIterator end = filterList.end(); |
1787 | while(it != end) { | 1793 | while(it != end) { |
1788 | // kdDebug() << " filter: " << (*it) << endl; | 1794 | // kdDebug() << " filter: " << (*it) << endl; |
1789 | 1795 | ||
1790 | CalFilter *filter; | 1796 | CalFilter *filter; |
1791 | filter = new CalFilter(*it); | 1797 | filter = new CalFilter(*it); |
1792 | config->setGroup("Filter_" + (*it)); | 1798 | config->setGroup("Filter_" + (*it)); |
1793 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); | 1799 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); |
1794 | filter->setCriteria(config->readNumEntry("Criteria",0)); | 1800 | filter->setCriteria(config->readNumEntry("Criteria",0)); |
1795 | filter->setCategoryList(config->readListEntry("CategoryList")); | 1801 | filter->setCategoryList(config->readListEntry("CategoryList")); |
1796 | mFilters.append(filter); | 1802 | mFilters.append(filter); |
1797 | 1803 | ||
1798 | ++it; | 1804 | ++it; |
1799 | } | 1805 | } |
1800 | 1806 | ||
1801 | if (mFilters.count() == 0) { | 1807 | if (mFilters.count() == 0) { |
1802 | CalFilter *filter = new CalFilter(i18n("Default")); | 1808 | CalFilter *filter = new CalFilter(i18n("Default")); |
1803 | mFilters.append(filter); | 1809 | mFilters.append(filter); |
1804 | } | 1810 | } |
1805 | mFilterView->updateFilters(); | 1811 | mFilterView->updateFilters(); |
1806 | config->setGroup("FilterView"); | 1812 | config->setGroup("FilterView"); |
1807 | 1813 | ||
1808 | mFilterView->blockSignals(true); | 1814 | mFilterView->blockSignals(true); |
1809 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); | 1815 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); |
1810 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); | 1816 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); |
1811 | mFilterView->blockSignals(false); | 1817 | mFilterView->blockSignals(false); |
1812 | // We do it manually to avoid it being done twice by the above calls | 1818 | // We do it manually to avoid it being done twice by the above calls |
1813 | updateFilter(); | 1819 | updateFilter(); |
1814 | } | 1820 | } |
1815 | 1821 | ||
1816 | void CalendarView::writeFilterSettings(KConfig *config) | 1822 | void CalendarView::writeFilterSettings(KConfig *config) |
1817 | { | 1823 | { |
1818 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; | 1824 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; |
1819 | 1825 | ||
1820 | QStringList filterList; | 1826 | QStringList filterList; |
1821 | 1827 | ||
1822 | CalFilter *filter = mFilters.first(); | 1828 | CalFilter *filter = mFilters.first(); |
1823 | while(filter) { | 1829 | while(filter) { |
1824 | // kdDebug() << " fn: " << filter->name() << endl; | 1830 | // kdDebug() << " fn: " << filter->name() << endl; |
1825 | filterList << filter->name(); | 1831 | filterList << filter->name(); |
1826 | config->setGroup("Filter_" + filter->name()); | 1832 | config->setGroup("Filter_" + filter->name()); |
1827 | config->writeEntry("Criteria",filter->criteria()); | 1833 | config->writeEntry("Criteria",filter->criteria()); |
1828 | config->writeEntry("CategoryList",filter->categoryList()); | 1834 | config->writeEntry("CategoryList",filter->categoryList()); |
1829 | filter = mFilters.next(); | 1835 | filter = mFilters.next(); |
1830 | } | 1836 | } |
1831 | config->setGroup("General"); | 1837 | config->setGroup("General"); |
1832 | config->writeEntry("CalendarFilters",filterList); | 1838 | config->writeEntry("CalendarFilters",filterList); |
1833 | 1839 | ||
1834 | config->setGroup("FilterView"); | 1840 | config->setGroup("FilterView"); |
1835 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); | 1841 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); |
1836 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); | 1842 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); |
1837 | } | 1843 | } |
1838 | 1844 | ||
1839 | 1845 | ||
1840 | void CalendarView::goToday() | 1846 | void CalendarView::goToday() |
1841 | { | 1847 | { |
1842 | mNavigator->selectToday(); | 1848 | mNavigator->selectToday(); |
1843 | } | 1849 | } |
1844 | 1850 | ||
1845 | void CalendarView::goNext() | 1851 | void CalendarView::goNext() |
1846 | { | 1852 | { |
1847 | mNavigator->selectNext(); | 1853 | mNavigator->selectNext(); |
1848 | } | 1854 | } |
1849 | 1855 | ||
1850 | void CalendarView::goPrevious() | 1856 | void CalendarView::goPrevious() |
1851 | { | 1857 | { |
1852 | mNavigator->selectPrevious(); | 1858 | mNavigator->selectPrevious(); |
1853 | } | 1859 | } |
1854 | void CalendarView::goNextMonth() | 1860 | void CalendarView::goNextMonth() |
1855 | { | 1861 | { |
1856 | mNavigator->selectNextMonth(); | 1862 | mNavigator->selectNextMonth(); |
1857 | } | 1863 | } |
1858 | 1864 | ||
1859 | void CalendarView::goPreviousMonth() | 1865 | void CalendarView::goPreviousMonth() |
1860 | { | 1866 | { |
1861 | mNavigator->selectPreviousMonth(); | 1867 | mNavigator->selectPreviousMonth(); |
1862 | } | 1868 | } |
1863 | void CalendarView::writeLocale() | 1869 | void CalendarView::writeLocale() |
1864 | { | 1870 | { |
1865 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); | 1871 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); |
1866 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); | 1872 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); |
1867 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); | 1873 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); |
1868 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); | 1874 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); |
1869 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; | 1875 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; |
1870 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); | 1876 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); |
1871 | dummy = KOPrefs::instance()->mUserDateFormatShort; | 1877 | dummy = KOPrefs::instance()->mUserDateFormatShort; |
1872 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); | 1878 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); |
1873 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, | 1879 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, |
1874 | KOPrefs::instance()->mDaylightsavingStart, | 1880 | KOPrefs::instance()->mDaylightsavingStart, |
1875 | KOPrefs::instance()->mDaylightsavingEnd ); | 1881 | KOPrefs::instance()->mDaylightsavingEnd ); |
1876 | KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); | 1882 | KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); |
1877 | } | 1883 | } |
1878 | void CalendarView::updateConfig() | 1884 | void CalendarView::updateConfig() |
1879 | { | 1885 | { |
1880 | writeLocale(); | 1886 | writeLocale(); |
1881 | if ( KOPrefs::instance()->mUseAppColors ) | 1887 | if ( KOPrefs::instance()->mUseAppColors ) |
1882 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); | 1888 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); |
1883 | emit configChanged(); | 1889 | emit configChanged(); |
1884 | mTodoList->updateConfig(); | 1890 | mTodoList->updateConfig(); |
1885 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); | 1891 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); |
1886 | mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1892 | mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1887 | // To make the "fill window" configurations work | 1893 | // To make the "fill window" configurations work |
1888 | //mViewManager->raiseCurrentView(); | 1894 | //mViewManager->raiseCurrentView(); |
1889 | } | 1895 | } |
1890 | 1896 | ||
1891 | 1897 | ||
1892 | void CalendarView::eventChanged(Event *event) | 1898 | void CalendarView::eventChanged(Event *event) |
1893 | { | 1899 | { |
1894 | changeEventDisplay(event,KOGlobals::EVENTEDITED); | 1900 | changeEventDisplay(event,KOGlobals::EVENTEDITED); |
1895 | //updateUnmanagedViews(); | 1901 | //updateUnmanagedViews(); |
1896 | } | 1902 | } |
1897 | 1903 | ||
1898 | void CalendarView::eventAdded(Event *event) | 1904 | void CalendarView::eventAdded(Event *event) |
1899 | { | 1905 | { |
1900 | changeEventDisplay(event,KOGlobals::EVENTADDED); | 1906 | changeEventDisplay(event,KOGlobals::EVENTADDED); |
1901 | } | 1907 | } |
1902 | 1908 | ||
1903 | void CalendarView::eventToBeDeleted(Event *) | 1909 | void CalendarView::eventToBeDeleted(Event *) |
1904 | { | 1910 | { |
1905 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; | 1911 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; |
1906 | } | 1912 | } |
1907 | 1913 | ||
1908 | void CalendarView::eventDeleted() | 1914 | void CalendarView::eventDeleted() |
1909 | { | 1915 | { |
1910 | changeEventDisplay(0,KOGlobals::EVENTDELETED); | 1916 | changeEventDisplay(0,KOGlobals::EVENTDELETED); |
1911 | } | 1917 | } |
1912 | void CalendarView::changeTodoDisplay(Todo *which, int action) | 1918 | void CalendarView::changeTodoDisplay(Todo *which, int action) |
1913 | { | 1919 | { |
1914 | changeIncidenceDisplay((Incidence *)which, action); | 1920 | changeIncidenceDisplay((Incidence *)which, action); |
1915 | mDateNavigator->updateView(); | 1921 | mDateNavigator->updateView(); |
1916 | //mDialogManager->updateSearchDialog(); | 1922 | //mDialogManager->updateSearchDialog(); |
1917 | 1923 | ||
1918 | if (which) { | 1924 | if (which) { |
1919 | mViewManager->currentView()->updateView(); | 1925 | mViewManager->currentView()->updateView(); |
1920 | //mTodoList->updateView(); | 1926 | //mTodoList->updateView(); |
1921 | } | 1927 | } |
1922 | 1928 | ||
1923 | } | 1929 | } |
1924 | 1930 | ||
1925 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) | 1931 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) |
1926 | { | 1932 | { |
1927 | updateUnmanagedViews(); | 1933 | updateUnmanagedViews(); |
1928 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); | 1934 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); |
1929 | if ( action == KOGlobals::EVENTDELETED ) { //delete | 1935 | if ( action == KOGlobals::EVENTDELETED ) { //delete |
1930 | mCalendar->checkAlarmForIncidence( 0, true ); | 1936 | mCalendar->checkAlarmForIncidence( 0, true ); |
1931 | if ( mEventViewerDialog ) | 1937 | if ( mEventViewerDialog ) |
1932 | mEventViewerDialog->hide(); | 1938 | mEventViewerDialog->hide(); |
1933 | } | 1939 | } |
1934 | else | 1940 | else |
1935 | mCalendar->checkAlarmForIncidence( which , false ); | 1941 | mCalendar->checkAlarmForIncidence( which , false ); |
1936 | } | 1942 | } |
1937 | 1943 | ||
1938 | // most of the changeEventDisplays() right now just call the view's | 1944 | // most of the changeEventDisplays() right now just call the view's |
1939 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. | 1945 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. |
1940 | void CalendarView::changeEventDisplay(Event *which, int action) | 1946 | void CalendarView::changeEventDisplay(Event *which, int action) |
1941 | { | 1947 | { |
1942 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; | 1948 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; |
1943 | changeIncidenceDisplay((Incidence *)which, action); | 1949 | changeIncidenceDisplay((Incidence *)which, action); |
1944 | mDateNavigator->updateView(); | 1950 | mDateNavigator->updateView(); |
1945 | //mDialogManager->updateSearchDialog(); | 1951 | //mDialogManager->updateSearchDialog(); |
1946 | 1952 | ||
1947 | if (which) { | 1953 | if (which) { |
1948 | // If there is an event view visible update the display | 1954 | // If there is an event view visible update the display |
1949 | mViewManager->currentView()->changeEventDisplay(which,action); | 1955 | mViewManager->currentView()->changeEventDisplay(which,action); |
1950 | // TODO: check, if update needed | 1956 | // TODO: check, if update needed |
1951 | // if (which->getTodoStatus()) { | 1957 | // if (which->getTodoStatus()) { |
1952 | mTodoList->updateView(); | 1958 | mTodoList->updateView(); |
1953 | // } | 1959 | // } |
1954 | } else { | 1960 | } else { |
1955 | mViewManager->currentView()->updateView(); | 1961 | mViewManager->currentView()->updateView(); |
1956 | } | 1962 | } |
1957 | } | 1963 | } |
1958 | 1964 | ||
1959 | 1965 | ||
1960 | void CalendarView::updateTodoViews() | 1966 | void CalendarView::updateTodoViews() |
1961 | { | 1967 | { |
1962 | 1968 | ||
1963 | mTodoList->updateView(); | 1969 | mTodoList->updateView(); |
1964 | mViewManager->currentView()->updateView(); | 1970 | mViewManager->currentView()->updateView(); |
1965 | 1971 | ||
1966 | } | 1972 | } |
1967 | 1973 | ||
1968 | 1974 | ||
1969 | void CalendarView::updateView(const QDate &start, const QDate &end) | 1975 | void CalendarView::updateView(const QDate &start, const QDate &end) |
1970 | { | 1976 | { |
1971 | mTodoList->updateView(); | 1977 | mTodoList->updateView(); |
1972 | mViewManager->updateView(start, end); | 1978 | mViewManager->updateView(start, end); |
1973 | //mDateNavigator->updateView(); | 1979 | //mDateNavigator->updateView(); |
1974 | } | 1980 | } |
1975 | 1981 | ||
1976 | void CalendarView::updateView() | 1982 | void CalendarView::updateView() |
1977 | { | 1983 | { |
1978 | DateList tmpList = mNavigator->selectedDates(); | 1984 | DateList tmpList = mNavigator->selectedDates(); |
1979 | 1985 | ||
1980 | // We assume that the navigator only selects consecutive days. | 1986 | // We assume that the navigator only selects consecutive days. |
1981 | updateView( tmpList.first(), tmpList.last() ); | 1987 | updateView( tmpList.first(), tmpList.last() ); |
1982 | } | 1988 | } |
1983 | 1989 | ||
1984 | void CalendarView::updateUnmanagedViews() | 1990 | void CalendarView::updateUnmanagedViews() |
1985 | { | 1991 | { |
1986 | mDateNavigator->updateDayMatrix(); | 1992 | mDateNavigator->updateDayMatrix(); |
1987 | } | 1993 | } |
1988 | 1994 | ||
1989 | int CalendarView::msgItemDelete() | 1995 | int CalendarView::msgItemDelete() |
1990 | { | 1996 | { |
1991 | return KMessageBox::warningContinueCancel(this, | 1997 | return KMessageBox::warningContinueCancel(this, |
1992 | i18n("This item will be\npermanently deleted."), | 1998 | i18n("This item will be\npermanently deleted."), |
1993 | i18n("KO/Pi Confirmation"),i18n("Delete")); | 1999 | i18n("KO/Pi Confirmation"),i18n("Delete")); |
1994 | } | 2000 | } |
1995 | 2001 | ||
1996 | 2002 | ||
1997 | void CalendarView::edit_cut() | 2003 | void CalendarView::edit_cut() |
1998 | { | 2004 | { |
1999 | Event *anEvent=0; | 2005 | Event *anEvent=0; |
2000 | 2006 | ||
2001 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2007 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2002 | 2008 | ||
2003 | if (mViewManager->currentView()->isEventView()) { | 2009 | if (mViewManager->currentView()->isEventView()) { |
2004 | if ( incidence && incidence->type() == "Event" ) { | 2010 | if ( incidence && incidence->type() == "Event" ) { |
2005 | anEvent = static_cast<Event *>(incidence); | 2011 | anEvent = static_cast<Event *>(incidence); |
2006 | } | 2012 | } |
2007 | } | 2013 | } |
2008 | 2014 | ||
2009 | if (!anEvent) { | 2015 | if (!anEvent) { |
2010 | KNotifyClient::beep(); | 2016 | KNotifyClient::beep(); |
2011 | return; | 2017 | return; |
2012 | } | 2018 | } |
2013 | DndFactory factory( mCalendar ); | 2019 | DndFactory factory( mCalendar ); |
2014 | factory.cutEvent(anEvent); | 2020 | factory.cutEvent(anEvent); |
2015 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2021 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2016 | } | 2022 | } |
2017 | 2023 | ||
2018 | void CalendarView::edit_copy() | 2024 | void CalendarView::edit_copy() |
2019 | { | 2025 | { |
2020 | Event *anEvent=0; | 2026 | Event *anEvent=0; |
2021 | 2027 | ||
2022 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2028 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2023 | 2029 | ||
2024 | if (mViewManager->currentView()->isEventView()) { | 2030 | if (mViewManager->currentView()->isEventView()) { |
2025 | if ( incidence && incidence->type() == "Event" ) { | 2031 | if ( incidence && incidence->type() == "Event" ) { |
2026 | anEvent = static_cast<Event *>(incidence); | 2032 | anEvent = static_cast<Event *>(incidence); |
2027 | } | 2033 | } |
2028 | } | 2034 | } |
2029 | 2035 | ||
2030 | if (!anEvent) { | 2036 | if (!anEvent) { |
2031 | KNotifyClient::beep(); | 2037 | KNotifyClient::beep(); |
2032 | return; | 2038 | return; |
2033 | } | 2039 | } |
2034 | DndFactory factory( mCalendar ); | 2040 | DndFactory factory( mCalendar ); |
2035 | factory.copyEvent(anEvent); | 2041 | factory.copyEvent(anEvent); |
2036 | } | 2042 | } |
2037 | 2043 | ||
2038 | void CalendarView::edit_paste() | 2044 | void CalendarView::edit_paste() |
2039 | { | 2045 | { |
2040 | QDate date = mNavigator->selectedDates().first(); | 2046 | QDate date = mNavigator->selectedDates().first(); |
2041 | 2047 | ||
2042 | DndFactory factory( mCalendar ); | 2048 | DndFactory factory( mCalendar ); |
2043 | Event *pastedEvent = factory.pasteEvent( date ); | 2049 | Event *pastedEvent = factory.pasteEvent( date ); |
2044 | 2050 | ||
2045 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); | 2051 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); |
2046 | } | 2052 | } |
2047 | 2053 | ||
2048 | void CalendarView::edit_options() | 2054 | void CalendarView::edit_options() |
2049 | { | 2055 | { |
2050 | mDialogManager->showOptionsDialog(); | 2056 | mDialogManager->showOptionsDialog(); |
2051 | //writeSettings(); | 2057 | //writeSettings(); |
2052 | } | 2058 | } |
2053 | void CalendarView::edit_sync_options() | 2059 | void CalendarView::edit_sync_options() |
2054 | { | 2060 | { |
2055 | //mDialogManager->showSyncOptions(); | 2061 | //mDialogManager->showSyncOptions(); |
2056 | //KOPrefs::instance()->mSyncAlgoPrefs | 2062 | //KOPrefs::instance()->mSyncAlgoPrefs |
2057 | QDialog dia( this, "dia", true ); | 2063 | QDialog dia( this, "dia", true ); |
2058 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 2064 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
2059 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 2065 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
2060 | QVBoxLayout lay ( &dia ); | 2066 | QVBoxLayout lay ( &dia ); |
2061 | lay.setSpacing( 2 ); | 2067 | lay.setSpacing( 2 ); |
2062 | lay.setMargin( 3 ); | 2068 | lay.setMargin( 3 ); |
2063 | lay.addWidget(&gr); | 2069 | lay.addWidget(&gr); |
2064 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 2070 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
2065 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 2071 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
2066 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 2072 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
2067 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 2073 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
2068 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 2074 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
2069 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 2075 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
2070 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 2076 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
2071 | QPushButton pb ( "OK", &dia); | 2077 | QPushButton pb ( "OK", &dia); |
2072 | lay.addWidget( &pb ); | 2078 | lay.addWidget( &pb ); |
2073 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 2079 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
2074 | switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { | 2080 | switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { |
2075 | case 0: | 2081 | case 0: |
2076 | loc.setChecked( true); | 2082 | loc.setChecked( true); |
2077 | break; | 2083 | break; |
2078 | case 1: | 2084 | case 1: |
2079 | rem.setChecked( true ); | 2085 | rem.setChecked( true ); |
2080 | break; | 2086 | break; |
2081 | case 2: | 2087 | case 2: |
2082 | newest.setChecked( true); | 2088 | newest.setChecked( true); |
2083 | break; | 2089 | break; |
2084 | case 3: | 2090 | case 3: |
2085 | ask.setChecked( true); | 2091 | ask.setChecked( true); |
2086 | break; | 2092 | break; |
2087 | case 4: | 2093 | case 4: |
2088 | f_loc.setChecked( true); | 2094 | f_loc.setChecked( true); |
2089 | break; | 2095 | break; |
2090 | case 5: | 2096 | case 5: |
2091 | f_rem.setChecked( true); | 2097 | f_rem.setChecked( true); |
2092 | break; | 2098 | break; |
2093 | case 6: | 2099 | case 6: |
2094 | // both.setChecked( true); | 2100 | // both.setChecked( true); |
2095 | break; | 2101 | break; |
2096 | default: | 2102 | default: |
2097 | break; | 2103 | break; |
2098 | } | 2104 | } |
2099 | if ( dia.exec() ) { | 2105 | if ( dia.exec() ) { |
2100 | KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 2106 | KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
2101 | } | 2107 | } |
2102 | 2108 | ||
2103 | } | 2109 | } |
2104 | 2110 | ||
2105 | void CalendarView::slotSelectPickerDate( QDate d) | 2111 | void CalendarView::slotSelectPickerDate( QDate d) |
2106 | { | 2112 | { |
2107 | mDateFrame->hide(); | 2113 | mDateFrame->hide(); |
2108 | if ( mDatePickerMode == 1 ) { | 2114 | if ( mDatePickerMode == 1 ) { |
2109 | mNavigator->slotDaySelect( d ); | 2115 | mNavigator->slotDaySelect( d ); |
2110 | } else if ( mDatePickerMode == 2 ) { | 2116 | } else if ( mDatePickerMode == 2 ) { |
2111 | if ( mMoveIncidence->type() == "Todo" ) { | 2117 | if ( mMoveIncidence->type() == "Todo" ) { |
2112 | Todo * to = (Todo *) mMoveIncidence; | 2118 | Todo * to = (Todo *) mMoveIncidence; |
2113 | QTime tim; | 2119 | QTime tim; |
2114 | if ( to->hasDueDate() ) | 2120 | if ( to->hasDueDate() ) |
2115 | tim = to->dtDue().time(); | 2121 | tim = to->dtDue().time(); |
2116 | else { | 2122 | else { |
2117 | tim = QTime ( 0,0,0 ); | 2123 | tim = QTime ( 0,0,0 ); |
2118 | to->setFloats( true ); | 2124 | to->setFloats( true ); |
2119 | to->setHasDueDate( true ); | 2125 | to->setHasDueDate( true ); |
2120 | } | 2126 | } |
2121 | QDateTime dt ( d,tim ); | 2127 | QDateTime dt ( d,tim ); |
2122 | to->setDtDue( dt ); | 2128 | to->setDtDue( dt ); |
2123 | todoChanged( to ); | 2129 | todoChanged( to ); |
2124 | } else { | 2130 | } else { |
2125 | QTime tim = mMoveIncidence->dtStart().time(); | 2131 | QTime tim = mMoveIncidence->dtStart().time(); |
2126 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); | 2132 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); |
2127 | QDateTime dt ( d,tim ); | 2133 | QDateTime dt ( d,tim ); |
2128 | mMoveIncidence->setDtStart( dt ); | 2134 | mMoveIncidence->setDtStart( dt ); |
2129 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); | 2135 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); |
2130 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); | 2136 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); |
2131 | } | 2137 | } |
2132 | 2138 | ||
2133 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); | 2139 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); |
2134 | } | 2140 | } |
2135 | } | 2141 | } |
2136 | 2142 | ||
2137 | void CalendarView::removeCategories() | 2143 | void CalendarView::removeCategories() |
2138 | { | 2144 | { |
2139 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2145 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2140 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2146 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2141 | QStringList catIncList; | 2147 | QStringList catIncList; |
2142 | QStringList newCatList; | 2148 | QStringList newCatList; |
2143 | Incidence* inc = incList.first(); | 2149 | Incidence* inc = incList.first(); |
2144 | int i; | 2150 | int i; |
2145 | int count = 0; | 2151 | int count = 0; |
2146 | while ( inc ) { | 2152 | while ( inc ) { |
2147 | newCatList.clear(); | 2153 | newCatList.clear(); |
2148 | catIncList = inc->categories() ; | 2154 | catIncList = inc->categories() ; |
2149 | for( i = 0; i< catIncList.count(); ++i ) { | 2155 | for( i = 0; i< catIncList.count(); ++i ) { |
2150 | if ( catList.contains (catIncList[i])) | 2156 | if ( catList.contains (catIncList[i])) |
2151 | newCatList.append( catIncList[i] ); | 2157 | newCatList.append( catIncList[i] ); |
2152 | } | 2158 | } |
2153 | newCatList.sort(); | 2159 | newCatList.sort(); |
2154 | inc->setCategories( newCatList.join(",") ); | 2160 | inc->setCategories( newCatList.join(",") ); |
2155 | inc = incList.next(); | 2161 | inc = incList.next(); |
2156 | } | 2162 | } |
2157 | } | 2163 | } |
2158 | 2164 | ||
2159 | int CalendarView::addCategories() | 2165 | int CalendarView::addCategories() |
2160 | { | 2166 | { |
2161 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2167 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2162 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2168 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2163 | QStringList catIncList; | 2169 | QStringList catIncList; |
2164 | Incidence* inc = incList.first(); | 2170 | Incidence* inc = incList.first(); |
2165 | int i; | 2171 | int i; |
2166 | int count = 0; | 2172 | int count = 0; |
2167 | while ( inc ) { | 2173 | while ( inc ) { |
2168 | catIncList = inc->categories() ; | 2174 | catIncList = inc->categories() ; |
2169 | for( i = 0; i< catIncList.count(); ++i ) { | 2175 | for( i = 0; i< catIncList.count(); ++i ) { |
2170 | if ( !catList.contains (catIncList[i])) { | 2176 | if ( !catList.contains (catIncList[i])) { |
2171 | catList.append( catIncList[i] ); | 2177 | catList.append( catIncList[i] ); |
2172 | //qDebug("add cat %s ", catIncList[i].latin1()); | 2178 | //qDebug("add cat %s ", catIncList[i].latin1()); |
2173 | ++count; | 2179 | ++count; |
2174 | } | 2180 | } |
2175 | } | 2181 | } |
2176 | inc = incList.next(); | 2182 | inc = incList.next(); |
2177 | } | 2183 | } |
2178 | catList.sort(); | 2184 | catList.sort(); |
2179 | KOPrefs::instance()->mCustomCategories = catList; | 2185 | KOPrefs::instance()->mCustomCategories = catList; |
2180 | return count; | 2186 | return count; |
2181 | } | 2187 | } |
2182 | 2188 | ||
2183 | void CalendarView::manageCategories() | 2189 | void CalendarView::manageCategories() |
2184 | { | 2190 | { |
2185 | KOCatPrefs* cp = new KOCatPrefs(); | 2191 | KOCatPrefs* cp = new KOCatPrefs(); |
2186 | cp->show(); | 2192 | cp->show(); |
2187 | int w =cp->sizeHint().width() ; | 2193 | int w =cp->sizeHint().width() ; |
2188 | int h = cp->sizeHint().height() ; | 2194 | int h = cp->sizeHint().height() ; |
2189 | int dw = QApplication::desktop()->width(); | 2195 | int dw = QApplication::desktop()->width(); |
2190 | int dh = QApplication::desktop()->height(); | 2196 | int dh = QApplication::desktop()->height(); |
2191 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2197 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2192 | if ( !cp->exec() ) { | 2198 | if ( !cp->exec() ) { |
2193 | delete cp; | 2199 | delete cp; |
2194 | return; | 2200 | return; |
2195 | } | 2201 | } |
2196 | int count = 0; | 2202 | int count = 0; |
2197 | if ( cp->addCat() ) { | 2203 | if ( cp->addCat() ) { |
2198 | count = addCategories(); | 2204 | count = addCategories(); |
2199 | if ( count ) { | 2205 | if ( count ) { |
2200 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); | 2206 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); |
2201 | writeSettings(); | 2207 | writeSettings(); |
2202 | } | 2208 | } |
2203 | } else { | 2209 | } else { |
2204 | removeCategories(); | 2210 | removeCategories(); |
2205 | updateView(); | 2211 | updateView(); |
2206 | } | 2212 | } |
2207 | delete cp; | 2213 | delete cp; |
2208 | } | 2214 | } |
2209 | 2215 | ||
2210 | void CalendarView::beamIncidence(Incidence * Inc) | 2216 | void CalendarView::beamIncidence(Incidence * Inc) |
2211 | { | 2217 | { |
2212 | QPtrList<Incidence> delSel ; | 2218 | QPtrList<Incidence> delSel ; |
2213 | delSel.append(Inc); | 2219 | delSel.append(Inc); |
2214 | beamIncidenceList( delSel ); | 2220 | beamIncidenceList( delSel ); |
2215 | } | 2221 | } |
2216 | void CalendarView::beamCalendar() | 2222 | void CalendarView::beamCalendar() |
2217 | { | 2223 | { |
2218 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); | 2224 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); |
2219 | //qDebug("beamCalendar() "); | 2225 | //qDebug("beamCalendar() "); |
2220 | beamIncidenceList( delSel ); | 2226 | beamIncidenceList( delSel ); |
2221 | } | 2227 | } |
2222 | void CalendarView::beamFilteredCalendar() | 2228 | void CalendarView::beamFilteredCalendar() |
2223 | { | 2229 | { |
2224 | QPtrList<Incidence> delSel = mCalendar->incidences(); | 2230 | QPtrList<Incidence> delSel = mCalendar->incidences(); |
2225 | //qDebug("beamFilteredCalendar() "); | 2231 | //qDebug("beamFilteredCalendar() "); |
2226 | beamIncidenceList( delSel ); | 2232 | beamIncidenceList( delSel ); |
2227 | } | 2233 | } |
2228 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) | 2234 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) |
2229 | { | 2235 | { |
2230 | if ( beamDialog->exec () == QDialog::Rejected ) | 2236 | if ( beamDialog->exec () == QDialog::Rejected ) |
2231 | return; | 2237 | return; |
2232 | 2238 | ||
2233 | QString fn = "/tmp/kopibeamfile"; | 2239 | QString fn = "/tmp/kopibeamfile"; |
2234 | QString mes; | 2240 | QString mes; |
2235 | bool createbup = true; | 2241 | bool createbup = true; |
2236 | if ( createbup ) { | 2242 | if ( createbup ) { |
2237 | QString description = "\n"; | 2243 | QString description = "\n"; |
2238 | CalendarLocal* cal = new CalendarLocal(); | 2244 | CalendarLocal* cal = new CalendarLocal(); |
2239 | if ( beamDialog->beamLocal() ) | 2245 | if ( beamDialog->beamLocal() ) |
2240 | cal->setLocalTime(); | 2246 | cal->setLocalTime(); |
2241 | else | 2247 | else |
2242 | cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 2248 | cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
2243 | Incidence *incidence = delSel.first(); | 2249 | Incidence *incidence = delSel.first(); |
2244 | bool addText = false; | 2250 | bool addText = false; |
2245 | if ( delSel.count() < 10 ) | 2251 | if ( delSel.count() < 10 ) |
2246 | addText = true; | 2252 | addText = true; |
2247 | else { | 2253 | else { |
2248 | description.sprintf(i18n(" %d items?"),delSel.count() ); | 2254 | description.sprintf(i18n(" %d items?"),delSel.count() ); |
2249 | } | 2255 | } |
2250 | while ( incidence ) { | 2256 | while ( incidence ) { |
2251 | Incidence *in = incidence->clone(); | 2257 | Incidence *in = incidence->clone(); |
2252 | if ( addText ) | 2258 | if ( addText ) |
2253 | description += in->summary() + "\n"; | 2259 | description += in->summary() + "\n"; |
2254 | cal->addIncidence( in ); | 2260 | cal->addIncidence( in ); |
2255 | incidence = delSel.next(); | 2261 | incidence = delSel.next(); |
2256 | } | 2262 | } |
2257 | if ( beamDialog->beamVcal() ) { | 2263 | if ( beamDialog->beamVcal() ) { |
2258 | fn += ".vcs"; | 2264 | fn += ".vcs"; |
2259 | FileStorage storage( cal, fn, new VCalFormat ); | 2265 | FileStorage storage( cal, fn, new VCalFormat ); |
2260 | storage.save(); | 2266 | storage.save(); |
2261 | } else { | 2267 | } else { |
2262 | fn += ".ics"; | 2268 | fn += ".ics"; |
2263 | FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2269 | FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2264 | storage.save(); | 2270 | storage.save(); |
2265 | } | 2271 | } |
2266 | delete cal; | 2272 | delete cal; |
2267 | mes = i18n("KO/Pi: Ready for beaming"); | 2273 | mes = i18n("KO/Pi: Ready for beaming"); |
2268 | setCaption(mes); | 2274 | setCaption(mes); |
2269 | 2275 | ||
2270 | #ifndef DESKTOP_VERSION | 2276 | #ifndef DESKTOP_VERSION |
2271 | Ir *ir = new Ir( this ); | 2277 | Ir *ir = new Ir( this ); |
2272 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 2278 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
2273 | ir->send( fn, description, "text/x-vCalendar" ); | 2279 | ir->send( fn, description, "text/x-vCalendar" ); |
2274 | #endif | 2280 | #endif |
2275 | } | 2281 | } |
2276 | } | 2282 | } |
2277 | void CalendarView::beamDone( Ir *ir ) | 2283 | void CalendarView::beamDone( Ir *ir ) |
2278 | { | 2284 | { |
2279 | #ifndef DESKTOP_VERSION | 2285 | #ifndef DESKTOP_VERSION |
2280 | delete ir; | 2286 | delete ir; |
2281 | #endif | 2287 | #endif |
2282 | } | 2288 | } |
2283 | 2289 | ||
2284 | void CalendarView::moveIncidence(Incidence * inc ) | 2290 | void CalendarView::moveIncidence(Incidence * inc ) |
2285 | { | 2291 | { |
2286 | if ( !inc ) return; | 2292 | if ( !inc ) return; |
2287 | // qDebug("showDatePickerForIncidence( ) "); | 2293 | // qDebug("showDatePickerForIncidence( ) "); |
2288 | if ( mDateFrame->isVisible() ) | 2294 | if ( mDateFrame->isVisible() ) |
2289 | mDateFrame->hide(); | 2295 | mDateFrame->hide(); |
2290 | else { | 2296 | else { |
2291 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; | 2297 | int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; |
2292 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; | 2298 | int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; |
2293 | int dw = QApplication::desktop()->width(); | 2299 | int dw = QApplication::desktop()->width(); |
2294 | int dh = QApplication::desktop()->height(); | 2300 | int dh = QApplication::desktop()->height(); |
2295 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2301 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2296 | mDateFrame->show(); | 2302 | mDateFrame->show(); |
2297 | } | 2303 | } |
2298 | mDatePickerMode = 2; | 2304 | mDatePickerMode = 2; |
2299 | mMoveIncidence = inc ; | 2305 | mMoveIncidence = inc ; |
2300 | QDate da; | 2306 | QDate da; |
2301 | if ( mMoveIncidence->type() == "Todo" ) { | 2307 | if ( mMoveIncidence->type() == "Todo" ) { |
2302 | Todo * to = (Todo *) mMoveIncidence; | 2308 | Todo * to = (Todo *) mMoveIncidence; |
2303 | if ( to->hasDueDate() ) | 2309 | if ( to->hasDueDate() ) |
2304 | da = to->dtDue().date(); | 2310 | da = to->dtDue().date(); |
2305 | else | 2311 | else |
2306 | da = QDate::currentDate(); | 2312 | da = QDate::currentDate(); |
2307 | } else { | 2313 | } else { |
2308 | da = mMoveIncidence->dtStart().date(); | 2314 | da = mMoveIncidence->dtStart().date(); |
2309 | } | 2315 | } |
2310 | mDatePicker->setDate( da ); | 2316 | mDatePicker->setDate( da ); |
2311 | } | 2317 | } |
2312 | void CalendarView::showDatePicker( ) | 2318 | void CalendarView::showDatePicker( ) |
2313 | { | 2319 | { |
2314 | //qDebug("CalendarView::showDatePicker( ) "); | 2320 | //qDebug("CalendarView::showDatePicker( ) "); |
2315 | if ( mDateFrame->isVisible() ) | 2321 | if ( mDateFrame->isVisible() ) |
2316 | mDateFrame->hide(); | 2322 | mDateFrame->hide(); |
2317 | else { | 2323 | else { |
2318 | int w =mDatePicker->sizeHint().width() ; | 2324 | int w =mDatePicker->sizeHint().width() ; |
2319 | int h = mDatePicker->sizeHint().height() ; | 2325 | int h = mDatePicker->sizeHint().height() ; |
2320 | int dw = QApplication::desktop()->width(); | 2326 | int dw = QApplication::desktop()->width(); |
2321 | int dh = QApplication::desktop()->height(); | 2327 | int dh = QApplication::desktop()->height(); |
2322 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2328 | mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2323 | mDateFrame->show(); | 2329 | mDateFrame->show(); |
2324 | } | 2330 | } |
2325 | mDatePickerMode = 1; | 2331 | mDatePickerMode = 1; |
2326 | mDatePicker->setDate( mNavigator->selectedDates().first() ); | 2332 | mDatePicker->setDate( mNavigator->selectedDates().first() ); |
2327 | } | 2333 | } |
2328 | 2334 | ||
2329 | void CalendarView::showEventEditor() | 2335 | void CalendarView::showEventEditor() |
2330 | { | 2336 | { |
2331 | #ifdef DESKTOP_VERSION | 2337 | #ifdef DESKTOP_VERSION |
2332 | mEventEditor->show(); | 2338 | mEventEditor->show(); |
2333 | #else | 2339 | #else |
2334 | mEventEditor->showMaximized(); | 2340 | mEventEditor->showMaximized(); |
2335 | #endif | 2341 | #endif |
2336 | } | 2342 | } |
2337 | void CalendarView::showTodoEditor() | 2343 | void CalendarView::showTodoEditor() |
2338 | { | 2344 | { |
2339 | #ifdef DESKTOP_VERSION | 2345 | #ifdef DESKTOP_VERSION |
2340 | mTodoEditor->show(); | 2346 | mTodoEditor->show(); |
2341 | #else | 2347 | #else |
2342 | mTodoEditor->showMaximized(); | 2348 | mTodoEditor->showMaximized(); |
2343 | #endif | 2349 | #endif |
2344 | } | 2350 | } |
2345 | void CalendarView::cancelIncidence(Incidence * inc ) | 2351 | void CalendarView::cancelIncidence(Incidence * inc ) |
2346 | { | 2352 | { |
2347 | inc->setCancelled( ! inc->cancelled() ); | 2353 | inc->setCancelled( ! inc->cancelled() ); |
2348 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); | 2354 | changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); |
2349 | updateView(); | 2355 | updateView(); |
2350 | } | 2356 | } |
2351 | void CalendarView::cloneIncidence(Incidence * orgInc ) | 2357 | void CalendarView::cloneIncidence(Incidence * orgInc ) |
2352 | { | 2358 | { |
2353 | Incidence * newInc = orgInc->clone(); | 2359 | Incidence * newInc = orgInc->clone(); |
2354 | newInc->recreate(); | 2360 | newInc->recreate(); |
2355 | 2361 | ||
2356 | if ( newInc->type() == "Todo" ) { | 2362 | if ( newInc->type() == "Todo" ) { |
2357 | Todo* t = (Todo*) newInc; | 2363 | Todo* t = (Todo*) newInc; |
2358 | mTodoEditor->editTodo( t ); | 2364 | mTodoEditor->editTodo( t ); |
2359 | showTodoEditor(); | 2365 | showTodoEditor(); |
2360 | if ( mTodoEditor->exec() ) { | 2366 | if ( mTodoEditor->exec() ) { |
2361 | mCalendar->addTodo( t ); | 2367 | mCalendar->addTodo( t ); |
2362 | updateView(); | 2368 | updateView(); |
2363 | } else { | 2369 | } else { |
2364 | delete t; | 2370 | delete t; |
2365 | } | 2371 | } |
2366 | } | 2372 | } |
2367 | else { | 2373 | else { |
2368 | Event* e = (Event*) newInc; | 2374 | Event* e = (Event*) newInc; |
2369 | mEventEditor->editEvent( e ); | 2375 | mEventEditor->editEvent( e ); |
2370 | showEventEditor(); | 2376 | showEventEditor(); |
2371 | if ( mEventEditor->exec() ) { | 2377 | if ( mEventEditor->exec() ) { |
2372 | mCalendar->addEvent( e ); | 2378 | mCalendar->addEvent( e ); |
2373 | updateView(); | 2379 | updateView(); |
2374 | } else { | 2380 | } else { |
2375 | delete e; | 2381 | delete e; |
2376 | } | 2382 | } |
2377 | } | 2383 | } |
2378 | } | 2384 | } |
2379 | 2385 | ||
2380 | void CalendarView::newEvent() | 2386 | void CalendarView::newEvent() |
2381 | { | 2387 | { |
2382 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. | 2388 | // TODO: Replace this code by a common eventDurationHint of KOBaseView. |
2383 | KOAgendaView *aView = mViewManager->agendaView(); | 2389 | KOAgendaView *aView = mViewManager->agendaView(); |
2384 | if (aView) { | 2390 | if (aView) { |
2385 | if (aView->selectionStart().isValid()) { | 2391 | if (aView->selectionStart().isValid()) { |
2386 | if (aView->selectedIsAllDay()) { | 2392 | if (aView->selectedIsAllDay()) { |
2387 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); | 2393 | newEvent(aView->selectionStart(),aView->selectionEnd(),true); |
2388 | } else { | 2394 | } else { |
2389 | newEvent(aView->selectionStart(),aView->selectionEnd()); | 2395 | newEvent(aView->selectionStart(),aView->selectionEnd()); |
2390 | } | 2396 | } |
2391 | return; | 2397 | return; |
2392 | } | 2398 | } |
2393 | } | 2399 | } |
2394 | 2400 | ||
2395 | QDate date = mNavigator->selectedDates().first(); | 2401 | QDate date = mNavigator->selectedDates().first(); |
2396 | QDateTime current = QDateTime::currentDateTime(); | 2402 | QDateTime current = QDateTime::currentDateTime(); |
2397 | if ( date <= current.date() ) { | 2403 | if ( date <= current.date() ) { |
2398 | int hour = current.time().hour() +1; | 2404 | int hour = current.time().hour() +1; |
2399 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), | 2405 | newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), |
2400 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2406 | QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2401 | } else | 2407 | } else |
2402 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), | 2408 | newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), |
2403 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + | 2409 | QDateTime( date, QTime( KOPrefs::instance()->mStartTime + |
2404 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); | 2410 | KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); |
2405 | } | 2411 | } |
2406 | 2412 | ||
2407 | void CalendarView::newEvent(QDateTime fh) | 2413 | void CalendarView::newEvent(QDateTime fh) |
2408 | { | 2414 | { |
2409 | newEvent(fh, | 2415 | newEvent(fh, |
2410 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); | 2416 | QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); |
2411 | } | 2417 | } |
2412 | 2418 | ||
2413 | void CalendarView::newEvent(QDate dt) | 2419 | void CalendarView::newEvent(QDate dt) |
2414 | { | 2420 | { |
2415 | newEvent(QDateTime(dt, QTime(0,0,0)), | 2421 | newEvent(QDateTime(dt, QTime(0,0,0)), |
2416 | QDateTime(dt, QTime(0,0,0)), true); | 2422 | QDateTime(dt, QTime(0,0,0)), true); |
2417 | } | 2423 | } |
2418 | 2424 | ||
2419 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) | 2425 | void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) |
2420 | { | 2426 | { |
2421 | 2427 | ||
2422 | mEventEditor->newEvent(fromHint,toHint,allDay); | 2428 | mEventEditor->newEvent(fromHint,toHint,allDay); |
2423 | if ( mFilterView->filtersEnabled() ) { | 2429 | if ( mFilterView->filtersEnabled() ) { |
2424 | CalFilter *filter = mFilterView->selectedFilter(); | 2430 | CalFilter *filter = mFilterView->selectedFilter(); |
2425 | if (filter && filter->showCategories()) { | 2431 | if (filter && filter->showCategories()) { |
2426 | mEventEditor->setCategories(filter->categoryList().join(",") ); | 2432 | mEventEditor->setCategories(filter->categoryList().join(",") ); |
2427 | } | 2433 | } |
2428 | if ( filter ) | 2434 | if ( filter ) |
2429 | mEventEditor->setSecrecy( filter->getSecrecy() ); | 2435 | mEventEditor->setSecrecy( filter->getSecrecy() ); |
2430 | } | 2436 | } |
2431 | showEventEditor(); | 2437 | showEventEditor(); |
2432 | } | 2438 | } |
2433 | void CalendarView::todoAdded(Todo * t) | 2439 | void CalendarView::todoAdded(Todo * t) |
2434 | { | 2440 | { |
2435 | 2441 | ||
2436 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); | 2442 | changeTodoDisplay ( t ,KOGlobals::EVENTADDED); |
2437 | updateTodoViews(); | 2443 | updateTodoViews(); |
2438 | } | 2444 | } |
2439 | void CalendarView::todoChanged(Todo * t) | 2445 | void CalendarView::todoChanged(Todo * t) |
2440 | { | 2446 | { |
2441 | emit todoModified( t, 4 ); | 2447 | emit todoModified( t, 4 ); |
2442 | // updateTodoViews(); | 2448 | // updateTodoViews(); |
2443 | } | 2449 | } |
2444 | void CalendarView::todoToBeDeleted(Todo *) | 2450 | void CalendarView::todoToBeDeleted(Todo *) |
2445 | { | 2451 | { |
2446 | //qDebug("todoToBeDeleted(Todo *) "); | 2452 | //qDebug("todoToBeDeleted(Todo *) "); |
2447 | updateTodoViews(); | 2453 | updateTodoViews(); |
2448 | } | 2454 | } |
2449 | void CalendarView::todoDeleted() | 2455 | void CalendarView::todoDeleted() |
2450 | { | 2456 | { |
2451 | //qDebug(" todoDeleted()"); | 2457 | //qDebug(" todoDeleted()"); |
2452 | updateTodoViews(); | 2458 | updateTodoViews(); |
2453 | } | 2459 | } |
2454 | 2460 | ||
2455 | 2461 | ||
2456 | 2462 | ||
2457 | void CalendarView::newTodo() | 2463 | void CalendarView::newTodo() |
2458 | { | 2464 | { |
2459 | 2465 | ||
2460 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); | 2466 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); |
2461 | if ( mFilterView->filtersEnabled() ) { | 2467 | if ( mFilterView->filtersEnabled() ) { |
2462 | CalFilter *filter = mFilterView->selectedFilter(); | 2468 | CalFilter *filter = mFilterView->selectedFilter(); |
2463 | if (filter && filter->showCategories()) { | 2469 | if (filter && filter->showCategories()) { |
2464 | mTodoEditor->setCategories(filter->categoryList().join(",") ); | 2470 | mTodoEditor->setCategories(filter->categoryList().join(",") ); |
2465 | } | 2471 | } |
2466 | if ( filter ) | 2472 | if ( filter ) |
2467 | mTodoEditor->setSecrecy( filter->getSecrecy() ); | 2473 | mTodoEditor->setSecrecy( filter->getSecrecy() ); |
2468 | } | 2474 | } |
2469 | showTodoEditor(); | 2475 | showTodoEditor(); |
2470 | } | 2476 | } |
2471 | 2477 | ||
2472 | void CalendarView::newSubTodo() | 2478 | void CalendarView::newSubTodo() |
2473 | { | 2479 | { |
2474 | Todo *todo = selectedTodo(); | 2480 | Todo *todo = selectedTodo(); |
2475 | if ( todo ) newSubTodo( todo ); | 2481 | if ( todo ) newSubTodo( todo ); |
2476 | } | 2482 | } |
2477 | 2483 | ||
2478 | void CalendarView::newSubTodo(Todo *parentEvent) | 2484 | void CalendarView::newSubTodo(Todo *parentEvent) |
2479 | { | 2485 | { |
2480 | 2486 | ||
2481 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); | 2487 | mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); |
2482 | showTodoEditor(); | 2488 | showTodoEditor(); |
2483 | } | 2489 | } |
2484 | 2490 | ||
2485 | void CalendarView::newFloatingEvent() | 2491 | void CalendarView::newFloatingEvent() |
2486 | { | 2492 | { |
2487 | DateList tmpList = mNavigator->selectedDates(); | 2493 | DateList tmpList = mNavigator->selectedDates(); |
2488 | QDate date = tmpList.first(); | 2494 | QDate date = tmpList.first(); |
2489 | 2495 | ||
2490 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), | 2496 | newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), |
2491 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); | 2497 | QDateTime( date, QTime( 12, 0, 0 ) ), true ); |
2492 | } | 2498 | } |
2493 | 2499 | ||
2494 | 2500 | ||
2495 | void CalendarView::editEvent( Event *event ) | 2501 | void CalendarView::editEvent( Event *event ) |
2496 | { | 2502 | { |
2497 | 2503 | ||
2498 | if ( !event ) return; | 2504 | if ( !event ) return; |
2499 | if ( event->isReadOnly() ) { | 2505 | if ( event->isReadOnly() ) { |
2500 | showEvent( event ); | 2506 | showEvent( event ); |
2501 | return; | 2507 | return; |
2502 | } | 2508 | } |
2503 | mEventEditor->editEvent( event , mFlagEditDescription); | 2509 | mEventEditor->editEvent( event , mFlagEditDescription); |
2504 | showEventEditor(); | 2510 | showEventEditor(); |
2505 | } | 2511 | } |
2506 | void CalendarView::editJournal( Journal *jour ) | 2512 | void CalendarView::editJournal( Journal *jour ) |
2507 | { | 2513 | { |
2508 | if ( !jour ) return; | 2514 | if ( !jour ) return; |
2509 | mDialogManager->hideSearchDialog(); | 2515 | mDialogManager->hideSearchDialog(); |
2510 | mViewManager->showJournalView(); | 2516 | mViewManager->showJournalView(); |
2511 | mNavigator->slotDaySelect( jour->dtStart().date() ); | 2517 | mNavigator->slotDaySelect( jour->dtStart().date() ); |
2512 | } | 2518 | } |
2513 | void CalendarView::editTodo( Todo *todo ) | 2519 | void CalendarView::editTodo( Todo *todo ) |
2514 | { | 2520 | { |
2515 | if ( !todo ) return; | 2521 | if ( !todo ) return; |
2516 | 2522 | ||
2517 | if ( todo->isReadOnly() ) { | 2523 | if ( todo->isReadOnly() ) { |
2518 | showTodo( todo ); | 2524 | showTodo( todo ); |
2519 | return; | 2525 | return; |
2520 | } | 2526 | } |
2521 | mTodoEditor->editTodo( todo ,mFlagEditDescription); | 2527 | mTodoEditor->editTodo( todo ,mFlagEditDescription); |
2522 | showTodoEditor(); | 2528 | showTodoEditor(); |
2523 | 2529 | ||
2524 | } | 2530 | } |
2525 | 2531 | ||
2526 | KOEventViewerDialog* CalendarView::getEventViewerDialog() | 2532 | KOEventViewerDialog* CalendarView::getEventViewerDialog() |
2527 | { | 2533 | { |
2528 | if ( !mEventViewerDialog ) { | 2534 | if ( !mEventViewerDialog ) { |
2529 | mEventViewerDialog = new KOEventViewerDialog(this); | 2535 | mEventViewerDialog = new KOEventViewerDialog(this); |
2530 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); | 2536 | connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); |
2531 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); | 2537 | connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); |
2532 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), | 2538 | connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), |
2533 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); | 2539 | dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); |
2534 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), | 2540 | connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), |
2535 | viewManager(), SLOT( showAgendaView( bool ) ) ); | 2541 | viewManager(), SLOT( showAgendaView( bool ) ) ); |
2536 | mEventViewerDialog->resize( 640, 480 ); | 2542 | mEventViewerDialog->resize( 640, 480 ); |
2537 | 2543 | ||
2538 | } | 2544 | } |
2539 | return mEventViewerDialog; | 2545 | return mEventViewerDialog; |
2540 | } | 2546 | } |
2541 | void CalendarView::showEvent(Event *event) | 2547 | void CalendarView::showEvent(Event *event) |
2542 | { | 2548 | { |
2543 | getEventViewerDialog()->setEvent(event); | 2549 | getEventViewerDialog()->setEvent(event); |
2544 | getEventViewerDialog()->showMe(); | 2550 | getEventViewerDialog()->showMe(); |
2545 | } | 2551 | } |
2546 | 2552 | ||
2547 | void CalendarView::showTodo(Todo *event) | 2553 | void CalendarView::showTodo(Todo *event) |
2548 | { | 2554 | { |
2549 | getEventViewerDialog()->setTodo(event); | 2555 | getEventViewerDialog()->setTodo(event); |
2550 | getEventViewerDialog()->showMe(); | 2556 | getEventViewerDialog()->showMe(); |
2551 | } | 2557 | } |
2552 | void CalendarView::showJournal( Journal *jour ) | 2558 | void CalendarView::showJournal( Journal *jour ) |
2553 | { | 2559 | { |
2554 | getEventViewerDialog()->setJournal(jour); | 2560 | getEventViewerDialog()->setJournal(jour); |
2555 | getEventViewerDialog()->showMe(); | 2561 | getEventViewerDialog()->showMe(); |
2556 | 2562 | ||
2557 | } | 2563 | } |
2558 | // void CalendarView::todoModified (Todo *event, int changed) | 2564 | // void CalendarView::todoModified (Todo *event, int changed) |
2559 | // { | 2565 | // { |
2560 | // // if (mDialogList.find (event) != mDialogList.end ()) { | 2566 | // // if (mDialogList.find (event) != mDialogList.end ()) { |
2561 | // // kdDebug() << "Todo modified and open" << endl; | 2567 | // // kdDebug() << "Todo modified and open" << endl; |
2562 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; | 2568 | // // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; |
2563 | // // temp->modified (changed); | 2569 | // // temp->modified (changed); |
2564 | 2570 | ||
2565 | // // } | 2571 | // // } |
2566 | 2572 | ||
2567 | // mViewManager->updateView(); | 2573 | // mViewManager->updateView(); |
2568 | // } | 2574 | // } |
2569 | 2575 | ||
2570 | void CalendarView::appointment_show() | 2576 | void CalendarView::appointment_show() |
2571 | { | 2577 | { |
2572 | Event *anEvent = 0; | 2578 | Event *anEvent = 0; |
2573 | 2579 | ||
2574 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2580 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2575 | 2581 | ||
2576 | if (mViewManager->currentView()->isEventView()) { | 2582 | if (mViewManager->currentView()->isEventView()) { |
2577 | if ( incidence && incidence->type() == "Event" ) { | 2583 | if ( incidence && incidence->type() == "Event" ) { |
2578 | anEvent = static_cast<Event *>(incidence); | 2584 | anEvent = static_cast<Event *>(incidence); |
2579 | } | 2585 | } |
2580 | } | 2586 | } |
2581 | 2587 | ||
2582 | if (!anEvent) { | 2588 | if (!anEvent) { |
2583 | KNotifyClient::beep(); | 2589 | KNotifyClient::beep(); |
2584 | return; | 2590 | return; |
2585 | } | 2591 | } |
2586 | 2592 | ||
2587 | showEvent(anEvent); | 2593 | showEvent(anEvent); |
2588 | } | 2594 | } |
2589 | 2595 | ||
2590 | void CalendarView::appointment_edit() | 2596 | void CalendarView::appointment_edit() |
2591 | { | 2597 | { |
2592 | Event *anEvent = 0; | 2598 | Event *anEvent = 0; |
2593 | 2599 | ||
2594 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2600 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2595 | 2601 | ||
2596 | if (mViewManager->currentView()->isEventView()) { | 2602 | if (mViewManager->currentView()->isEventView()) { |
2597 | if ( incidence && incidence->type() == "Event" ) { | 2603 | if ( incidence && incidence->type() == "Event" ) { |
2598 | anEvent = static_cast<Event *>(incidence); | 2604 | anEvent = static_cast<Event *>(incidence); |
2599 | } | 2605 | } |
2600 | } | 2606 | } |
2601 | 2607 | ||
2602 | if (!anEvent) { | 2608 | if (!anEvent) { |
2603 | KNotifyClient::beep(); | 2609 | KNotifyClient::beep(); |
2604 | return; | 2610 | return; |
2605 | } | 2611 | } |
2606 | 2612 | ||
2607 | editEvent(anEvent); | 2613 | editEvent(anEvent); |
2608 | } | 2614 | } |
2609 | 2615 | ||
2610 | void CalendarView::appointment_delete() | 2616 | void CalendarView::appointment_delete() |
2611 | { | 2617 | { |
2612 | Event *anEvent = 0; | 2618 | Event *anEvent = 0; |
2613 | 2619 | ||
2614 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2620 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2615 | 2621 | ||
2616 | if (mViewManager->currentView()->isEventView()) { | 2622 | if (mViewManager->currentView()->isEventView()) { |
2617 | if ( incidence && incidence->type() == "Event" ) { | 2623 | if ( incidence && incidence->type() == "Event" ) { |
2618 | anEvent = static_cast<Event *>(incidence); | 2624 | anEvent = static_cast<Event *>(incidence); |
2619 | } | 2625 | } |
2620 | } | 2626 | } |
2621 | 2627 | ||
2622 | if (!anEvent) { | 2628 | if (!anEvent) { |
2623 | KNotifyClient::beep(); | 2629 | KNotifyClient::beep(); |
2624 | return; | 2630 | return; |
2625 | } | 2631 | } |
2626 | 2632 | ||
2627 | deleteEvent(anEvent); | 2633 | deleteEvent(anEvent); |
2628 | } | 2634 | } |
2629 | 2635 | ||
2630 | void CalendarView::todo_unsub(Todo *anTodo ) | 2636 | void CalendarView::todo_unsub(Todo *anTodo ) |
2631 | { | 2637 | { |
2632 | // Todo *anTodo = selectedTodo(); | 2638 | // Todo *anTodo = selectedTodo(); |
2633 | if (!anTodo) return; | 2639 | if (!anTodo) return; |
2634 | if (!anTodo->relatedTo()) return; | 2640 | if (!anTodo->relatedTo()) return; |
2635 | anTodo->relatedTo()->removeRelation(anTodo); | 2641 | anTodo->relatedTo()->removeRelation(anTodo); |
2636 | anTodo->setRelatedTo(0); | 2642 | anTodo->setRelatedTo(0); |
2637 | anTodo->updated(); | 2643 | anTodo->updated(); |
2638 | anTodo->setRelatedToUid(""); | 2644 | anTodo->setRelatedToUid(""); |
2639 | setModified(true); | 2645 | setModified(true); |
2640 | updateView(); | 2646 | updateView(); |
2641 | } | 2647 | } |
2642 | 2648 | ||
2643 | void CalendarView::deleteTodo(Todo *todo) | 2649 | void CalendarView::deleteTodo(Todo *todo) |
2644 | { | 2650 | { |
2645 | if (!todo) { | 2651 | if (!todo) { |
2646 | KNotifyClient::beep(); | 2652 | KNotifyClient::beep(); |
2647 | return; | 2653 | return; |
2648 | } | 2654 | } |
2649 | if (KOPrefs::instance()->mConfirm) { | 2655 | if (KOPrefs::instance()->mConfirm) { |
2650 | switch (msgItemDelete()) { | 2656 | switch (msgItemDelete()) { |
2651 | case KMessageBox::Continue: // OK | 2657 | case KMessageBox::Continue: // OK |
2652 | if (!todo->relations().isEmpty()) { | 2658 | if (!todo->relations().isEmpty()) { |
2653 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2659 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2654 | i18n("Delete To-Do")); | 2660 | i18n("Delete To-Do")); |
2655 | } else { | 2661 | } else { |
2656 | checkExternalId( todo ); | 2662 | checkExternalId( todo ); |
2657 | calendar()->deleteTodo(todo); | 2663 | calendar()->deleteTodo(todo); |
2658 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2664 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2659 | updateView(); | 2665 | updateView(); |
2660 | } | 2666 | } |
2661 | break; | 2667 | break; |
2662 | } // switch | 2668 | } // switch |
2663 | } else { | 2669 | } else { |
2664 | if (!todo->relations().isEmpty()) { | 2670 | if (!todo->relations().isEmpty()) { |
2665 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), | 2671 | KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), |
2666 | i18n("Delete To-Do")); | 2672 | i18n("Delete To-Do")); |
2667 | } else { | 2673 | } else { |
2668 | checkExternalId( todo ); | 2674 | checkExternalId( todo ); |
2669 | mCalendar->deleteTodo(todo); | 2675 | mCalendar->deleteTodo(todo); |
2670 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); | 2676 | changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); |
2671 | updateView(); | 2677 | updateView(); |
2672 | } | 2678 | } |
2673 | } | 2679 | } |
2674 | emit updateSearchDialog(); | 2680 | emit updateSearchDialog(); |
2675 | } | 2681 | } |
2676 | void CalendarView::deleteJournal(Journal *jour) | 2682 | void CalendarView::deleteJournal(Journal *jour) |
2677 | { | 2683 | { |
2678 | if (!jour) { | 2684 | if (!jour) { |
2679 | KNotifyClient::beep(); | 2685 | KNotifyClient::beep(); |
2680 | return; | 2686 | return; |
2681 | } | 2687 | } |
2682 | if (KOPrefs::instance()->mConfirm) { | 2688 | if (KOPrefs::instance()->mConfirm) { |
2683 | switch (msgItemDelete()) { | 2689 | switch (msgItemDelete()) { |
2684 | case KMessageBox::Continue: // OK | 2690 | case KMessageBox::Continue: // OK |
2685 | calendar()->deleteJournal(jour); | 2691 | calendar()->deleteJournal(jour); |
2686 | updateView(); | 2692 | updateView(); |
2687 | break; | 2693 | break; |
2688 | } // switch | 2694 | } // switch |
2689 | } else { | 2695 | } else { |
2690 | calendar()->deleteJournal(jour);; | 2696 | calendar()->deleteJournal(jour);; |
2691 | updateView(); | 2697 | updateView(); |
2692 | } | 2698 | } |
2693 | emit updateSearchDialog(); | 2699 | emit updateSearchDialog(); |
2694 | } | 2700 | } |
2695 | 2701 | ||
2696 | void CalendarView::deleteEvent(Event *anEvent) | 2702 | void CalendarView::deleteEvent(Event *anEvent) |
2697 | { | 2703 | { |
2698 | if (!anEvent) { | 2704 | if (!anEvent) { |
2699 | KNotifyClient::beep(); | 2705 | KNotifyClient::beep(); |
2700 | return; | 2706 | return; |
2701 | } | 2707 | } |
2702 | 2708 | ||
2703 | if (anEvent->recurrence()->doesRecur()) { | 2709 | if (anEvent->recurrence()->doesRecur()) { |
2704 | QDate itemDate = mViewManager->currentSelectionDate(); | 2710 | QDate itemDate = mViewManager->currentSelectionDate(); |
2705 | int km; | 2711 | int km; |
2706 | if (!itemDate.isValid()) { | 2712 | if (!itemDate.isValid()) { |
2707 | //kdDebug() << "Date Not Valid" << endl; | 2713 | //kdDebug() << "Date Not Valid" << endl; |
2708 | if (KOPrefs::instance()->mConfirm) { | 2714 | if (KOPrefs::instance()->mConfirm) { |
2709 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2715 | km = KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2710 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), | 2716 | i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), |
2711 | i18n("KO/Pi Confirmation"),i18n("Delete All")); | 2717 | i18n("KO/Pi Confirmation"),i18n("Delete All")); |
2712 | if ( km == KMessageBox::Continue ) | 2718 | if ( km == KMessageBox::Continue ) |
2713 | km = KMessageBox::No; // No = all below | 2719 | km = KMessageBox::No; // No = all below |
2714 | } else | 2720 | } else |
2715 | km = KMessageBox::No; | 2721 | km = KMessageBox::No; |
2716 | } else { | 2722 | } else { |
2717 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + | 2723 | km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + |
2718 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ | 2724 | i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ |
2719 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), | 2725 | KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), |
2720 | i18n("KO/Pi Confirmation"),i18n("Current"), | 2726 | i18n("KO/Pi Confirmation"),i18n("Current"), |
2721 | i18n("All")); | 2727 | i18n("All")); |
2722 | } | 2728 | } |
2723 | switch(km) { | 2729 | switch(km) { |
2724 | 2730 | ||
2725 | case KMessageBox::No: // Continue // all | 2731 | case KMessageBox::No: // Continue // all |
2726 | //qDebug("KMessageBox::No "); | 2732 | //qDebug("KMessageBox::No "); |
2727 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2733 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2728 | schedule(Scheduler::Cancel,anEvent); | 2734 | schedule(Scheduler::Cancel,anEvent); |
2729 | 2735 | ||
2730 | checkExternalId( anEvent); | 2736 | checkExternalId( anEvent); |
2731 | mCalendar->deleteEvent(anEvent); | 2737 | mCalendar->deleteEvent(anEvent); |
2732 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); | 2738 | changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); |
2733 | break; | 2739 | break; |
2734 | 2740 | ||
2735 | // Disabled because it does not work | 2741 | // Disabled because it does not work |
2736 | //#if 0 | 2742 | //#if 0 |
2737 | case KMessageBox::Yes: // just this one | 2743 | case KMessageBox::Yes: // just this one |
2738 | //QDate qd = mNavigator->selectedDates().first(); | 2744 | //QDate qd = mNavigator->selectedDates().first(); |
2739 | //if (!qd.isValid()) { | 2745 | //if (!qd.isValid()) { |
2740 | // kdDebug() << "no date selected, or invalid date" << endl; | 2746 | // kdDebug() << "no date selected, or invalid date" << endl; |
2741 | // KNotifyClient::beep(); | 2747 | // KNotifyClient::beep(); |
2742 | // return; | 2748 | // return; |
2743 | //} | 2749 | //} |
2744 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); | 2750 | //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); |
2745 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { | 2751 | if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { |
2746 | anEvent->addExDate(itemDate); | 2752 | anEvent->addExDate(itemDate); |
2747 | int duration = anEvent->recurrence()->duration(); | 2753 | int duration = anEvent->recurrence()->duration(); |
2748 | if ( duration > 0 ) { | 2754 | if ( duration > 0 ) { |
2749 | anEvent->recurrence()->setDuration( duration - 1 ); | 2755 | anEvent->recurrence()->setDuration( duration - 1 ); |
2750 | } | 2756 | } |
2751 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); | 2757 | changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); |
2752 | } | 2758 | } |
2753 | break; | 2759 | break; |
2754 | //#endif | 2760 | //#endif |
2755 | } // switch | 2761 | } // switch |
2756 | } else { | 2762 | } else { |
2757 | if (KOPrefs::instance()->mConfirm) { | 2763 | if (KOPrefs::instance()->mConfirm) { |
2758 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + | 2764 | switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + |
2759 | i18n("\nAre you sure you want\nto delete this event?"), | 2765 | i18n("\nAre you sure you want\nto delete this event?"), |
2760 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { | 2766 | i18n("KO/Pi Confirmation"),i18n("Delete"))) { |
2761 | case KMessageBox::Continue: // OK | 2767 | case KMessageBox::Continue: // OK |
2762 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2768 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2763 | schedule(Scheduler::Cancel,anEvent); | 2769 | schedule(Scheduler::Cancel,anEvent); |
2764 | checkExternalId( anEvent); | 2770 | checkExternalId( anEvent); |
2765 | mCalendar->deleteEvent(anEvent); | 2771 | mCalendar->deleteEvent(anEvent); |
2766 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2772 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2767 | break; | 2773 | break; |
2768 | } // switch | 2774 | } // switch |
2769 | } else { | 2775 | } else { |
2770 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) | 2776 | if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) |
2771 | schedule(Scheduler::Cancel,anEvent); | 2777 | schedule(Scheduler::Cancel,anEvent); |
2772 | checkExternalId( anEvent); | 2778 | checkExternalId( anEvent); |
2773 | mCalendar->deleteEvent(anEvent); | 2779 | mCalendar->deleteEvent(anEvent); |
2774 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2780 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2775 | } | 2781 | } |
2776 | } // if-else | 2782 | } // if-else |
2777 | emit updateSearchDialog(); | 2783 | emit updateSearchDialog(); |
2778 | } | 2784 | } |
2779 | 2785 | ||
2780 | bool CalendarView::deleteEvent(const QString &uid) | 2786 | bool CalendarView::deleteEvent(const QString &uid) |
2781 | { | 2787 | { |
2782 | Event *ev = mCalendar->event(uid); | 2788 | Event *ev = mCalendar->event(uid); |
2783 | if (ev) { | 2789 | if (ev) { |
2784 | deleteEvent(ev); | 2790 | deleteEvent(ev); |
2785 | return true; | 2791 | return true; |
2786 | } else { | 2792 | } else { |
2787 | return false; | 2793 | return false; |
2788 | } | 2794 | } |
2789 | } | 2795 | } |
2790 | 2796 | ||
2791 | /*****************************************************************************/ | 2797 | /*****************************************************************************/ |
2792 | 2798 | ||
2793 | void CalendarView::action_mail() | 2799 | void CalendarView::action_mail() |
2794 | { | 2800 | { |
2795 | #ifndef KORG_NOMAIL | 2801 | #ifndef KORG_NOMAIL |
2796 | KOMailClient mailClient; | 2802 | KOMailClient mailClient; |
2797 | 2803 | ||
2798 | Incidence *incidence = currentSelection(); | 2804 | Incidence *incidence = currentSelection(); |
2799 | 2805 | ||
2800 | if (!incidence) { | 2806 | if (!incidence) { |
2801 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2807 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2802 | return; | 2808 | return; |
2803 | } | 2809 | } |
2804 | if(incidence->attendeeCount() == 0 ) { | 2810 | if(incidence->attendeeCount() == 0 ) { |
2805 | KMessageBox::sorry(this, | 2811 | KMessageBox::sorry(this, |
2806 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2812 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2807 | return; | 2813 | return; |
2808 | } | 2814 | } |
2809 | 2815 | ||
2810 | CalendarLocal cal_tmp; | 2816 | CalendarLocal cal_tmp; |
2811 | Event *event = 0; | 2817 | Event *event = 0; |
2812 | Event *ev = 0; | 2818 | Event *ev = 0; |
2813 | if ( incidence && incidence->type() == "Event" ) { | 2819 | if ( incidence && incidence->type() == "Event" ) { |
2814 | event = static_cast<Event *>(incidence); | 2820 | event = static_cast<Event *>(incidence); |
2815 | ev = new Event(*event); | 2821 | ev = new Event(*event); |
2816 | cal_tmp.addEvent(ev); | 2822 | cal_tmp.addEvent(ev); |
2817 | } | 2823 | } |
2818 | ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); | 2824 | ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); |
2819 | QString attachment = mForm.toString( &cal_tmp ); | 2825 | QString attachment = mForm.toString( &cal_tmp ); |
2820 | if (ev) delete(ev); | 2826 | if (ev) delete(ev); |
2821 | 2827 | ||
2822 | mailClient.mailAttendees(currentSelection(), attachment); | 2828 | mailClient.mailAttendees(currentSelection(), attachment); |
2823 | 2829 | ||
2824 | #endif | 2830 | #endif |
2825 | 2831 | ||
2826 | #if 0 | 2832 | #if 0 |
2827 | Event *anEvent = 0; | 2833 | Event *anEvent = 0; |
2828 | if (mViewManager->currentView()->isEventView()) { | 2834 | if (mViewManager->currentView()->isEventView()) { |
2829 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); | 2835 | anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); |
2830 | } | 2836 | } |
2831 | 2837 | ||
2832 | if (!anEvent) { | 2838 | if (!anEvent) { |
2833 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); | 2839 | KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); |
2834 | return; | 2840 | return; |
2835 | } | 2841 | } |
2836 | if(anEvent->attendeeCount() == 0 ) { | 2842 | if(anEvent->attendeeCount() == 0 ) { |
2837 | KMessageBox::sorry(this, | 2843 | KMessageBox::sorry(this, |
2838 | i18n("Can't generate mail:\nNo attendees defined.\n")); | 2844 | i18n("Can't generate mail:\nNo attendees defined.\n")); |
2839 | return; | 2845 | return; |
2840 | } | 2846 | } |
2841 | 2847 | ||
2842 | mailobject.emailEvent(anEvent); | 2848 | mailobject.emailEvent(anEvent); |
2843 | #endif | 2849 | #endif |
2844 | } | 2850 | } |
2845 | 2851 | ||
2846 | 2852 | ||
2847 | void CalendarView::schedule_publish(Incidence *incidence) | 2853 | void CalendarView::schedule_publish(Incidence *incidence) |
2848 | { | 2854 | { |
2849 | Event *event = 0; | 2855 | Event *event = 0; |
2850 | Todo *todo = 0; | 2856 | Todo *todo = 0; |
2851 | 2857 | ||
2852 | if (incidence == 0) { | 2858 | if (incidence == 0) { |
2853 | incidence = mViewManager->currentView()->selectedIncidences().first(); | 2859 | incidence = mViewManager->currentView()->selectedIncidences().first(); |
2854 | if (incidence == 0) { | 2860 | if (incidence == 0) { |
2855 | incidence = mTodoList->selectedIncidences().first(); | 2861 | incidence = mTodoList->selectedIncidences().first(); |
2856 | } | 2862 | } |
2857 | } | 2863 | } |
2858 | if ( incidence && incidence->type() == "Event" ) { | 2864 | if ( incidence && incidence->type() == "Event" ) { |
2859 | event = static_cast<Event *>(incidence); | 2865 | event = static_cast<Event *>(incidence); |
2860 | } else { | 2866 | } else { |
2861 | if ( incidence && incidence->type() == "Todo" ) { | 2867 | if ( incidence && incidence->type() == "Todo" ) { |
2862 | todo = static_cast<Todo *>(incidence); | 2868 | todo = static_cast<Todo *>(incidence); |
2863 | } | 2869 | } |
2864 | } | 2870 | } |
2865 | 2871 | ||
2866 | if (!event && !todo) { | 2872 | if (!event && !todo) { |
2867 | KMessageBox::sorry(this,i18n("No event selected.")); | 2873 | KMessageBox::sorry(this,i18n("No event selected.")); |
2868 | return; | 2874 | return; |
2869 | } | 2875 | } |
2870 | 2876 | ||
2871 | PublishDialog *publishdlg = new PublishDialog(); | 2877 | PublishDialog *publishdlg = new PublishDialog(); |
2872 | if (incidence->attendeeCount()>0) { | 2878 | if (incidence->attendeeCount()>0) { |
2873 | QPtrList<Attendee> attendees = incidence->attendees(); | 2879 | QPtrList<Attendee> attendees = incidence->attendees(); |
2874 | attendees.first(); | 2880 | attendees.first(); |
2875 | while ( attendees.current()!=0 ) { | 2881 | while ( attendees.current()!=0 ) { |
2876 | publishdlg->addAttendee(attendees.current()); | 2882 | publishdlg->addAttendee(attendees.current()); |
2877 | attendees.next(); | 2883 | attendees.next(); |
2878 | } | 2884 | } |
2879 | } | 2885 | } |
2880 | bool send = true; | 2886 | bool send = true; |
2881 | if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { | 2887 | if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { |
2882 | if ( publishdlg->exec() != QDialog::Accepted ) | 2888 | if ( publishdlg->exec() != QDialog::Accepted ) |
2883 | send = false; | 2889 | send = false; |
2884 | } | 2890 | } |
2885 | if ( send ) { | 2891 | if ( send ) { |
2886 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 2892 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
2887 | if ( event ) { | 2893 | if ( event ) { |
2888 | Event *ev = new Event(*event); | 2894 | Event *ev = new Event(*event); |
2889 | ev->registerObserver(0); | 2895 | ev->registerObserver(0); |
2890 | ev->clearAttendees(); | 2896 | ev->clearAttendees(); |
2891 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { | 2897 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { |
2892 | delete(ev); | 2898 | delete(ev); |
2893 | } | 2899 | } |
2894 | } else { | 2900 | } else { |
2895 | if ( todo ) { | 2901 | if ( todo ) { |
2896 | Todo *ev = new Todo(*todo); | 2902 | Todo *ev = new Todo(*todo); |
2897 | ev->registerObserver(0); | 2903 | ev->registerObserver(0); |
2898 | ev->clearAttendees(); | 2904 | ev->clearAttendees(); |
2899 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { | 2905 | if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { |
2900 | delete(ev); | 2906 | delete(ev); |
2901 | } | 2907 | } |
2902 | } | 2908 | } |
2903 | } | 2909 | } |
2904 | } | 2910 | } |
2905 | delete publishdlg; | 2911 | delete publishdlg; |
2906 | } | 2912 | } |
2907 | 2913 | ||
2908 | void CalendarView::schedule_request(Incidence *incidence) | 2914 | void CalendarView::schedule_request(Incidence *incidence) |
2909 | { | 2915 | { |
2910 | schedule(Scheduler::Request,incidence); | 2916 | schedule(Scheduler::Request,incidence); |
2911 | } | 2917 | } |
2912 | 2918 | ||
2913 | void CalendarView::schedule_refresh(Incidence *incidence) | 2919 | void CalendarView::schedule_refresh(Incidence *incidence) |
2914 | { | 2920 | { |
2915 | schedule(Scheduler::Refresh,incidence); | 2921 | schedule(Scheduler::Refresh,incidence); |
2916 | } | 2922 | } |
2917 | 2923 | ||
2918 | void CalendarView::schedule_cancel(Incidence *incidence) | 2924 | void CalendarView::schedule_cancel(Incidence *incidence) |
2919 | { | 2925 | { |
2920 | schedule(Scheduler::Cancel,incidence); | 2926 | schedule(Scheduler::Cancel,incidence); |
2921 | } | 2927 | } |
2922 | 2928 | ||
2923 | void CalendarView::schedule_add(Incidence *incidence) | 2929 | void CalendarView::schedule_add(Incidence *incidence) |
2924 | { | 2930 | { |
2925 | schedule(Scheduler::Add,incidence); | 2931 | schedule(Scheduler::Add,incidence); |
2926 | } | 2932 | } |
2927 | 2933 | ||
2928 | void CalendarView::schedule_reply(Incidence *incidence) | 2934 | void CalendarView::schedule_reply(Incidence *incidence) |
2929 | { | 2935 | { |
2930 | schedule(Scheduler::Reply,incidence); | 2936 | schedule(Scheduler::Reply,incidence); |
2931 | } | 2937 | } |
2932 | 2938 | ||
2933 | void CalendarView::schedule_counter(Incidence *incidence) | 2939 | void CalendarView::schedule_counter(Incidence *incidence) |
2934 | { | 2940 | { |
2935 | schedule(Scheduler::Counter,incidence); | 2941 | schedule(Scheduler::Counter,incidence); |
2936 | } | 2942 | } |
2937 | 2943 | ||
2938 | void CalendarView::schedule_declinecounter(Incidence *incidence) | 2944 | void CalendarView::schedule_declinecounter(Incidence *incidence) |
2939 | { | 2945 | { |
2940 | schedule(Scheduler::Declinecounter,incidence); | 2946 | schedule(Scheduler::Declinecounter,incidence); |
2941 | } | 2947 | } |
2942 | 2948 | ||
2943 | void CalendarView::schedule_publish_freebusy(int daysToPublish) | 2949 | void CalendarView::schedule_publish_freebusy(int daysToPublish) |
2944 | { | 2950 | { |
2945 | QDateTime start = QDateTime::currentDateTime(); | 2951 | QDateTime start = QDateTime::currentDateTime(); |
2946 | QDateTime end = start.addDays(daysToPublish); | 2952 | QDateTime end = start.addDays(daysToPublish); |
2947 | 2953 | ||
2948 | FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); | 2954 | FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); |
2949 | freebusy->setOrganizer(KOPrefs::instance()->email()); | 2955 | freebusy->setOrganizer(KOPrefs::instance()->email()); |
2950 | 2956 | ||
2951 | 2957 | ||
2952 | PublishDialog *publishdlg = new PublishDialog(); | 2958 | PublishDialog *publishdlg = new PublishDialog(); |
2953 | if ( publishdlg->exec() == QDialog::Accepted ) { | 2959 | if ( publishdlg->exec() == QDialog::Accepted ) { |
2954 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 2960 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
2955 | if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { | 2961 | if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { |
2956 | delete(freebusy); | 2962 | delete(freebusy); |
2957 | } | 2963 | } |
2958 | } | 2964 | } |
2959 | delete publishdlg; | 2965 | delete publishdlg; |
2960 | } | 2966 | } |
2961 | 2967 | ||
2962 | void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) | 2968 | void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) |
2963 | { | 2969 | { |
2964 | Event *event = 0; | 2970 | Event *event = 0; |
2965 | Todo *todo = 0; | 2971 | Todo *todo = 0; |
2966 | 2972 | ||
2967 | if (incidence == 0) { | 2973 | if (incidence == 0) { |
2968 | incidence = mViewManager->currentView()->selectedIncidences().first(); | 2974 | incidence = mViewManager->currentView()->selectedIncidences().first(); |
2969 | if (incidence == 0) { | 2975 | if (incidence == 0) { |
2970 | incidence = mTodoList->selectedIncidences().first(); | 2976 | incidence = mTodoList->selectedIncidences().first(); |
2971 | } | 2977 | } |
2972 | } | 2978 | } |
2973 | if ( incidence && incidence->type() == "Event" ) { | 2979 | if ( incidence && incidence->type() == "Event" ) { |
2974 | event = static_cast<Event *>(incidence); | 2980 | event = static_cast<Event *>(incidence); |
2975 | } | 2981 | } |
2976 | if ( incidence && incidence->type() == "Todo" ) { | 2982 | if ( incidence && incidence->type() == "Todo" ) { |
2977 | todo = static_cast<Todo *>(incidence); | 2983 | todo = static_cast<Todo *>(incidence); |
2978 | } | 2984 | } |
2979 | 2985 | ||
2980 | if (!event && !todo) { | 2986 | if (!event && !todo) { |
2981 | KMessageBox::sorry(this,i18n("No event selected.")); | 2987 | KMessageBox::sorry(this,i18n("No event selected.")); |
2982 | return; | 2988 | return; |
2983 | } | 2989 | } |
2984 | 2990 | ||
2985 | if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { | 2991 | if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { |
2986 | KMessageBox::sorry(this,i18n("The event has no attendees.")); | 2992 | KMessageBox::sorry(this,i18n("The event has no attendees.")); |
2987 | return; | 2993 | return; |
2988 | } | 2994 | } |
2989 | 2995 | ||
2990 | Event *ev = 0; | 2996 | Event *ev = 0; |
2991 | if (event) ev = new Event(*event); | 2997 | if (event) ev = new Event(*event); |
2992 | Todo *to = 0; | 2998 | Todo *to = 0; |
2993 | if (todo) to = new Todo(*todo); | 2999 | if (todo) to = new Todo(*todo); |
2994 | 3000 | ||
2995 | if (method == Scheduler::Reply || method == Scheduler::Refresh) { | 3001 | if (method == Scheduler::Reply || method == Scheduler::Refresh) { |
2996 | Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); | 3002 | Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); |
2997 | if (!me) { | 3003 | if (!me) { |
2998 | KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); | 3004 | KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); |
2999 | return; | 3005 | return; |
3000 | } | 3006 | } |
3001 | if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { | 3007 | if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { |
3002 | StatusDialog *statdlg = new StatusDialog(this); | 3008 | StatusDialog *statdlg = new StatusDialog(this); |
3003 | if (!statdlg->exec()==QDialog::Accepted) return; | 3009 | if (!statdlg->exec()==QDialog::Accepted) return; |
3004 | me->setStatus( statdlg->status() ); | 3010 | me->setStatus( statdlg->status() ); |
3005 | delete(statdlg); | 3011 | delete(statdlg); |
3006 | } | 3012 | } |
3007 | Attendee *menew = new Attendee(*me); | 3013 | Attendee *menew = new Attendee(*me); |
3008 | if (ev) { | 3014 | if (ev) { |
3009 | ev->clearAttendees(); | 3015 | ev->clearAttendees(); |
3010 | ev->addAttendee(menew,false); | 3016 | ev->addAttendee(menew,false); |
3011 | } else { | 3017 | } else { |
3012 | if (to) { | 3018 | if (to) { |
3013 | todo->clearAttendees(); | 3019 | todo->clearAttendees(); |
3014 | todo->addAttendee(menew,false); | 3020 | todo->addAttendee(menew,false); |
3015 | } | 3021 | } |
3016 | } | 3022 | } |
3017 | } | 3023 | } |
3018 | 3024 | ||
3019 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); | 3025 | OutgoingDialog *dlg = mDialogManager->outgoingDialog(); |
3020 | if (ev) { | 3026 | if (ev) { |
3021 | if ( !dlg->addMessage(ev,method) ) delete(ev); | 3027 | if ( !dlg->addMessage(ev,method) ) delete(ev); |
3022 | } else { | 3028 | } else { |
3023 | if (to) { | 3029 | if (to) { |
3024 | if ( !dlg->addMessage(to,method) ) delete(to); | 3030 | if ( !dlg->addMessage(to,method) ) delete(to); |
3025 | } | 3031 | } |
3026 | } | 3032 | } |
3027 | } | 3033 | } |
3028 | 3034 | ||
3029 | void CalendarView::openAddressbook() | 3035 | void CalendarView::openAddressbook() |
3030 | { | 3036 | { |
3031 | KRun::runCommand("kaddressbook"); | 3037 | KRun::runCommand("kaddressbook"); |
3032 | } | 3038 | } |
3033 | 3039 | ||
3034 | void CalendarView::setModified(bool modified) | 3040 | void CalendarView::setModified(bool modified) |
3035 | { | 3041 | { |
3036 | if ( modified ) | 3042 | if ( modified ) |
3037 | emit signalmodified(); | 3043 | emit signalmodified(); |
3038 | if (mModified != modified) { | 3044 | if (mModified != modified) { |
3039 | mModified = modified; | 3045 | mModified = modified; |
3040 | emit modifiedChanged(mModified); | 3046 | emit modifiedChanged(mModified); |
3041 | } | 3047 | } |
3042 | } | 3048 | } |
3043 | 3049 | ||
3044 | bool CalendarView::isReadOnly() | 3050 | bool CalendarView::isReadOnly() |
3045 | { | 3051 | { |
3046 | return mReadOnly; | 3052 | return mReadOnly; |
3047 | } | 3053 | } |
3048 | 3054 | ||
3049 | void CalendarView::setReadOnly(bool readOnly) | 3055 | void CalendarView::setReadOnly(bool readOnly) |
3050 | { | 3056 | { |
3051 | if (mReadOnly != readOnly) { | 3057 | if (mReadOnly != readOnly) { |
3052 | mReadOnly = readOnly; | 3058 | mReadOnly = readOnly; |
3053 | emit readOnlyChanged(mReadOnly); | 3059 | emit readOnlyChanged(mReadOnly); |
3054 | } | 3060 | } |
3055 | } | 3061 | } |
3056 | 3062 | ||
3057 | bool CalendarView::isModified() | 3063 | bool CalendarView::isModified() |
3058 | { | 3064 | { |
3059 | return mModified; | 3065 | return mModified; |
3060 | } | 3066 | } |
3061 | 3067 | ||
3062 | void CalendarView::printSetup() | 3068 | void CalendarView::printSetup() |
3063 | { | 3069 | { |
3064 | #ifndef KORG_NOPRINTER | 3070 | #ifndef KORG_NOPRINTER |
3065 | createPrinter(); | 3071 | createPrinter(); |
3066 | 3072 | ||
3067 | mCalPrinter->setupPrinter(); | 3073 | mCalPrinter->setupPrinter(); |
3068 | #endif | 3074 | #endif |
3069 | } | 3075 | } |
3070 | 3076 | ||
3071 | void CalendarView::print() | 3077 | void CalendarView::print() |
3072 | { | 3078 | { |
3073 | #ifndef KORG_NOPRINTER | 3079 | #ifndef KORG_NOPRINTER |
3074 | createPrinter(); | 3080 | createPrinter(); |
3075 | 3081 | ||
3076 | DateList tmpDateList = mNavigator->selectedDates(); | 3082 | DateList tmpDateList = mNavigator->selectedDates(); |
3077 | mCalPrinter->print(CalPrinter::Month, | 3083 | mCalPrinter->print(CalPrinter::Month, |
3078 | tmpDateList.first(), tmpDateList.last()); | 3084 | tmpDateList.first(), tmpDateList.last()); |
3079 | #endif | 3085 | #endif |
3080 | } | 3086 | } |
3081 | 3087 | ||
3082 | void CalendarView::printPreview() | 3088 | void CalendarView::printPreview() |
3083 | { | 3089 | { |
3084 | #ifndef KORG_NOPRINTER | 3090 | #ifndef KORG_NOPRINTER |
3085 | kdDebug() << "CalendarView::printPreview()" << endl; | 3091 | kdDebug() << "CalendarView::printPreview()" << endl; |
3086 | 3092 | ||
3087 | createPrinter(); | 3093 | createPrinter(); |
3088 | 3094 | ||
3089 | DateList tmpDateList = mNavigator->selectedDates(); | 3095 | DateList tmpDateList = mNavigator->selectedDates(); |
3090 | 3096 | ||
3091 | mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), | 3097 | mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), |
3092 | tmpDateList.last()); | 3098 | tmpDateList.last()); |
3093 | #endif | 3099 | #endif |
3094 | } | 3100 | } |
3095 | 3101 | ||
3096 | void CalendarView::exportICalendar() | 3102 | void CalendarView::exportICalendar() |
3097 | { | 3103 | { |
3098 | QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); | 3104 | QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); |
3099 | 3105 | ||
3100 | // Force correct extension | 3106 | // Force correct extension |
3101 | if (filename.right(4) != ".ics") filename += ".ics"; | 3107 | if (filename.right(4) != ".ics") filename += ".ics"; |
3102 | 3108 | ||
3103 | FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 3109 | FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
3104 | storage.save(); | 3110 | storage.save(); |
3105 | } | 3111 | } |
3106 | 3112 | ||
3107 | bool CalendarView::exportVCalendar( QString filename ) | 3113 | bool CalendarView::exportVCalendar( QString filename ) |
3108 | { | 3114 | { |
3109 | if (mCalendar->journals().count() > 0) { | 3115 | if (mCalendar->journals().count() > 0) { |
3110 | int result = KMessageBox::warningContinueCancel(this, | 3116 | int result = KMessageBox::warningContinueCancel(this, |
3111 | i18n("The journal entries can not be\nexported to a vCalendar file."), | 3117 | i18n("The journal entries can not be\nexported to a vCalendar file."), |
3112 | i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), | 3118 | i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), |
3113 | true); | 3119 | true); |
3114 | if (result != KMessageBox::Continue) return false; | 3120 | if (result != KMessageBox::Continue) return false; |
3115 | } | 3121 | } |
3116 | 3122 | ||
3117 | //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); | 3123 | //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); |
3118 | 3124 | ||
3119 | // Force correct extension | 3125 | // Force correct extension |
3120 | if (filename.right(4) != ".vcs") filename += ".vcs"; | 3126 | if (filename.right(4) != ".vcs") filename += ".vcs"; |
3121 | 3127 | ||
3122 | FileStorage storage( mCalendar, filename, new VCalFormat ); | 3128 | FileStorage storage( mCalendar, filename, new VCalFormat ); |
3123 | return storage.save(); | 3129 | return storage.save(); |
3124 | 3130 | ||
3125 | } | 3131 | } |
3126 | 3132 | ||
3127 | void CalendarView::eventUpdated(Incidence *) | 3133 | void CalendarView::eventUpdated(Incidence *) |
3128 | { | 3134 | { |
3129 | setModified(); | 3135 | setModified(); |
3130 | // Don't call updateView here. The code, which has caused the update of the | 3136 | // Don't call updateView here. The code, which has caused the update of the |
3131 | // event is responsible for updating the view. | 3137 | // event is responsible for updating the view. |
3132 | // updateView(); | 3138 | // updateView(); |
3133 | } | 3139 | } |
3134 | 3140 | ||
3135 | void CalendarView::adaptNavigationUnits() | 3141 | void CalendarView::adaptNavigationUnits() |
3136 | { | 3142 | { |
3137 | if (mViewManager->currentView()->isEventView()) { | 3143 | if (mViewManager->currentView()->isEventView()) { |
3138 | int days = mViewManager->currentView()->currentDateCount(); | 3144 | int days = mViewManager->currentView()->currentDateCount(); |
3139 | if (days == 1) { | 3145 | if (days == 1) { |
3140 | emit changeNavStringPrev(i18n("&Previous Day")); | 3146 | emit changeNavStringPrev(i18n("&Previous Day")); |
3141 | emit changeNavStringNext(i18n("&Next Day")); | 3147 | emit changeNavStringNext(i18n("&Next Day")); |
3142 | } else { | 3148 | } else { |
3143 | emit changeNavStringPrev(i18n("&Previous Week")); | 3149 | emit changeNavStringPrev(i18n("&Previous Week")); |
3144 | emit changeNavStringNext(i18n("&Next Week")); | 3150 | emit changeNavStringNext(i18n("&Next Week")); |
3145 | } | 3151 | } |
3146 | } | 3152 | } |
3147 | } | 3153 | } |
3148 | 3154 | ||
3149 | void CalendarView::processMainViewSelection( Incidence *incidence ) | 3155 | void CalendarView::processMainViewSelection( Incidence *incidence ) |
3150 | { | 3156 | { |
3151 | if ( incidence ) mTodoList->clearSelection(); | 3157 | if ( incidence ) mTodoList->clearSelection(); |
3152 | processIncidenceSelection( incidence ); | 3158 | processIncidenceSelection( incidence ); |
3153 | } | 3159 | } |
3154 | 3160 | ||
3155 | void CalendarView::processTodoListSelection( Incidence *incidence ) | 3161 | void CalendarView::processTodoListSelection( Incidence *incidence ) |
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp index 29e6205..1fc7169 100644 --- a/libkcal/alarm.cpp +++ b/libkcal/alarm.cpp | |||
@@ -1,423 +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) 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 | #include <kdebug.h> | 22 | #include <kdebug.h> |
23 | 23 | ||
24 | #include "incidence.h" | 24 | #include "incidence.h" |
25 | #include "todo.h" | 25 | #include "todo.h" |
26 | 26 | ||
27 | #include "alarm.h" | 27 | #include "alarm.h" |
28 | 28 | ||
29 | using namespace KCal; | 29 | using namespace KCal; |
30 | #include <qwidget.h> | 30 | #include <qwidget.h> |
31 | Alarm::Alarm(Incidence *parent) | 31 | Alarm::Alarm(Incidence *parent) |
32 | : mParent(parent), | 32 | : mParent(parent), |
33 | mType(Audio), | 33 | mType(Audio), |
34 | mDescription(""), // to make operator==() not fail | 34 | mDescription(""), // to make operator==() not fail |
35 | mFile(""), // to make operator==() not fail | 35 | mFile(""), // to make operator==() not fail |
36 | mMailSubject(""), // to make operator==() not fail | 36 | mMailSubject(""), // to make operator==() not fail |
37 | mAlarmSnoozeTime(5), | 37 | mAlarmSnoozeTime(5), |
38 | mAlarmRepeatCount(0), | 38 | mAlarmRepeatCount(0), |
39 | mEndOffset(false), | 39 | mEndOffset(false), |
40 | mHasTime(false), | 40 | mHasTime(false), |
41 | mAlarmEnabled(false) | 41 | mAlarmEnabled(false) |
42 | { | 42 | { |
43 | 43 | ||
44 | } | 44 | } |
45 | 45 | ||
46 | Alarm::~Alarm() | 46 | Alarm::~Alarm() |
47 | { | 47 | { |
48 | } | 48 | } |
49 | 49 | ||
50 | bool Alarm::operator==( const Alarm& rhs ) const | 50 | bool Alarm::operator==( const Alarm& rhs ) const |
51 | { | 51 | { |
52 | |||
52 | if ( mType != rhs.mType || | 53 | if ( mType != rhs.mType || |
53 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || | 54 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || |
54 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || | 55 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || |
55 | mAlarmEnabled != rhs.mAlarmEnabled || | 56 | mAlarmEnabled != rhs.mAlarmEnabled || |
56 | mHasTime != rhs.mHasTime) | 57 | mHasTime != rhs.mHasTime) |
57 | return false; | 58 | return false; |
58 | 59 | ||
60 | #if 0 | ||
61 | if ( mType != rhs.mType ) { | ||
62 | |||
63 | qDebug("aaa1 "); | ||
64 | return false; | ||
65 | } | ||
66 | |||
67 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { | ||
68 | |||
69 | qDebug("aaa2 "); | ||
70 | return false; | ||
71 | } | ||
72 | |||
73 | |||
74 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { | ||
75 | |||
76 | qDebug("aaa3 "); | ||
77 | return false; | ||
78 | } | ||
79 | |||
80 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { | ||
81 | |||
82 | qDebug("aaa4 "); | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | if ( mHasTime != rhs.mHasTime ) { | ||
87 | |||
88 | qDebug("aaa5 "); | ||
89 | return false; | ||
90 | } | ||
91 | #endif | ||
92 | |||
93 | |||
59 | if (mHasTime) { | 94 | if (mHasTime) { |
60 | if (mAlarmTime != rhs.mAlarmTime) | 95 | if (mAlarmTime != rhs.mAlarmTime) |
61 | return false; | 96 | return false; |
62 | } else { | 97 | } else { |
63 | if (mOffset != rhs.mOffset || | 98 | if (mOffset != rhs.mOffset || |
64 | mEndOffset != rhs.mEndOffset) | 99 | mEndOffset != rhs.mEndOffset) |
65 | return false; | 100 | return false; |
66 | } | 101 | } |
67 | |||
68 | switch (mType) { | 102 | switch (mType) { |
69 | case Display: | 103 | case Display: |
70 | return mDescription == rhs.mDescription; | 104 | return mDescription == rhs.mDescription; |
71 | 105 | ||
72 | case Email: | 106 | case Email: |
73 | return mDescription == rhs.mDescription && | 107 | return mDescription == rhs.mDescription && |
74 | mMailAttachFiles == rhs.mMailAttachFiles && | 108 | mMailAttachFiles == rhs.mMailAttachFiles && |
75 | mMailAddresses == rhs.mMailAddresses && | 109 | mMailAddresses == rhs.mMailAddresses && |
76 | mMailSubject == rhs.mMailSubject; | 110 | mMailSubject == rhs.mMailSubject; |
77 | 111 | ||
78 | case Procedure: | 112 | case Procedure: |
79 | return mFile == rhs.mFile && | 113 | return mFile == rhs.mFile && |
80 | mDescription == rhs.mDescription; | 114 | mDescription == rhs.mDescription; |
81 | 115 | ||
82 | case Audio: | 116 | case Audio: |
83 | return mFile == rhs.mFile; | 117 | return mFile == rhs.mFile; |
84 | 118 | ||
85 | case Invalid: | 119 | case Invalid: |
86 | break; | 120 | break; |
87 | } | 121 | } |
88 | return false; | 122 | return false; |
89 | } | 123 | } |
90 | 124 | ||
91 | void Alarm::setType(Alarm::Type type) | 125 | void Alarm::setType(Alarm::Type type) |
92 | { | 126 | { |
93 | if (type == mType) | 127 | if (type == mType) |
94 | return; | 128 | return; |
95 | 129 | ||
96 | switch (type) { | 130 | switch (type) { |
97 | case Display: | 131 | case Display: |
98 | mDescription = ""; | 132 | mDescription = ""; |
99 | break; | 133 | break; |
100 | case Procedure: | 134 | case Procedure: |
101 | mFile = mDescription = ""; | 135 | mFile = mDescription = ""; |
102 | break; | 136 | break; |
103 | case Audio: | 137 | case Audio: |
104 | mFile = ""; | 138 | mFile = ""; |
105 | break; | 139 | break; |
106 | case Email: | 140 | case Email: |
107 | mMailSubject = mDescription = ""; | 141 | mMailSubject = mDescription = ""; |
108 | mMailAddresses.clear(); | 142 | mMailAddresses.clear(); |
109 | mMailAttachFiles.clear(); | 143 | mMailAttachFiles.clear(); |
110 | break; | 144 | break; |
111 | case Invalid: | 145 | case Invalid: |
112 | break; | 146 | break; |
113 | default: | 147 | default: |
114 | return; | 148 | return; |
115 | } | 149 | } |
116 | mType = type; | 150 | mType = type; |
117 | mParent->updated(); | 151 | mParent->updated(); |
118 | } | 152 | } |
119 | 153 | ||
120 | Alarm::Type Alarm::type() const | 154 | Alarm::Type Alarm::type() const |
121 | { | 155 | { |
122 | return mType; | 156 | return mType; |
123 | } | 157 | } |
124 | 158 | ||
125 | void Alarm::setAudioAlarm(const QString &audioFile) | 159 | void Alarm::setAudioAlarm(const QString &audioFile) |
126 | { | 160 | { |
127 | mType = Audio; | 161 | mType = Audio; |
128 | mFile = audioFile; | 162 | mFile = audioFile; |
129 | mParent->updated(); | 163 | mParent->updated(); |
130 | } | 164 | } |
131 | 165 | ||
132 | void Alarm::setAudioFile(const QString &audioFile) | 166 | void Alarm::setAudioFile(const QString &audioFile) |
133 | { | 167 | { |
134 | if (mType == Audio) { | 168 | if (mType == Audio) { |
135 | mFile = audioFile; | 169 | mFile = audioFile; |
136 | mParent->updated(); | 170 | mParent->updated(); |
137 | } | 171 | } |
138 | } | 172 | } |
139 | 173 | ||
140 | QString Alarm::audioFile() const | 174 | QString Alarm::audioFile() const |
141 | { | 175 | { |
142 | return (mType == Audio) ? mFile : QString::null; | 176 | return (mType == Audio) ? mFile : QString::null; |
143 | } | 177 | } |
144 | 178 | ||
145 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) | 179 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) |
146 | { | 180 | { |
147 | mType = Procedure; | 181 | mType = Procedure; |
148 | mFile = programFile; | 182 | mFile = programFile; |
149 | mDescription = arguments; | 183 | mDescription = arguments; |
150 | mParent->updated(); | 184 | mParent->updated(); |
151 | } | 185 | } |
152 | 186 | ||
153 | void Alarm::setProgramFile(const QString &programFile) | 187 | void Alarm::setProgramFile(const QString &programFile) |
154 | { | 188 | { |
155 | if (mType == Procedure) { | 189 | if (mType == Procedure) { |
156 | mFile = programFile; | 190 | mFile = programFile; |
157 | mParent->updated(); | 191 | mParent->updated(); |
158 | } | 192 | } |
159 | } | 193 | } |
160 | 194 | ||
161 | QString Alarm::programFile() const | 195 | QString Alarm::programFile() const |
162 | { | 196 | { |
163 | return (mType == Procedure) ? mFile : QString::null; | 197 | return (mType == Procedure) ? mFile : QString::null; |
164 | } | 198 | } |
165 | 199 | ||
166 | void Alarm::setProgramArguments(const QString &arguments) | 200 | void Alarm::setProgramArguments(const QString &arguments) |
167 | { | 201 | { |
168 | if (mType == Procedure) { | 202 | if (mType == Procedure) { |
169 | mDescription = arguments; | 203 | mDescription = arguments; |
170 | mParent->updated(); | 204 | mParent->updated(); |
171 | } | 205 | } |
172 | } | 206 | } |
173 | 207 | ||
174 | QString Alarm::programArguments() const | 208 | QString Alarm::programArguments() const |
175 | { | 209 | { |
176 | return (mType == Procedure) ? mDescription : QString::null; | 210 | return (mType == Procedure) ? mDescription : QString::null; |
177 | } | 211 | } |
178 | 212 | ||
179 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, | 213 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, |
180 | const QValueList<Person> &addressees, const QStringList &attachments) | 214 | const QValueList<Person> &addressees, const QStringList &attachments) |
181 | { | 215 | { |
182 | mType = Email; | 216 | mType = Email; |
183 | mMailSubject = subject; | 217 | mMailSubject = subject; |
184 | mDescription = text; | 218 | mDescription = text; |
185 | mMailAddresses = addressees; | 219 | mMailAddresses = addressees; |
186 | mMailAttachFiles = attachments; | 220 | mMailAttachFiles = attachments; |
187 | mParent->updated(); | 221 | mParent->updated(); |
188 | } | 222 | } |
189 | 223 | ||
190 | void Alarm::setMailAddress(const Person &mailAddress) | 224 | void Alarm::setMailAddress(const Person &mailAddress) |
191 | { | 225 | { |
192 | if (mType == Email) { | 226 | if (mType == Email) { |
193 | mMailAddresses.clear(); | 227 | mMailAddresses.clear(); |
194 | mMailAddresses += mailAddress; | 228 | mMailAddresses += mailAddress; |
195 | mParent->updated(); | 229 | mParent->updated(); |
196 | } | 230 | } |
197 | } | 231 | } |
198 | 232 | ||
199 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) | 233 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) |
200 | { | 234 | { |
201 | if (mType == Email) { | 235 | if (mType == Email) { |
202 | mMailAddresses = mailAddresses; | 236 | mMailAddresses = mailAddresses; |
203 | mParent->updated(); | 237 | mParent->updated(); |
204 | } | 238 | } |
205 | } | 239 | } |
206 | 240 | ||
207 | void Alarm::addMailAddress(const Person &mailAddress) | 241 | void Alarm::addMailAddress(const Person &mailAddress) |
208 | { | 242 | { |
209 | if (mType == Email) { | 243 | if (mType == Email) { |
210 | mMailAddresses += mailAddress; | 244 | mMailAddresses += mailAddress; |
211 | mParent->updated(); | 245 | mParent->updated(); |
212 | } | 246 | } |
213 | } | 247 | } |
214 | 248 | ||
215 | QValueList<Person> Alarm::mailAddresses() const | 249 | QValueList<Person> Alarm::mailAddresses() const |
216 | { | 250 | { |
217 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); | 251 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); |
218 | } | 252 | } |
219 | 253 | ||
220 | void Alarm::setMailSubject(const QString &mailAlarmSubject) | 254 | void Alarm::setMailSubject(const QString &mailAlarmSubject) |
221 | { | 255 | { |
222 | if (mType == Email) { | 256 | if (mType == Email) { |
223 | mMailSubject = mailAlarmSubject; | 257 | mMailSubject = mailAlarmSubject; |
224 | mParent->updated(); | 258 | mParent->updated(); |
225 | } | 259 | } |
226 | } | 260 | } |
227 | 261 | ||
228 | QString Alarm::mailSubject() const | 262 | QString Alarm::mailSubject() const |
229 | { | 263 | { |
230 | return (mType == Email) ? mMailSubject : QString::null; | 264 | return (mType == Email) ? mMailSubject : QString::null; |
231 | } | 265 | } |
232 | 266 | ||
233 | void Alarm::setMailAttachment(const QString &mailAttachFile) | 267 | void Alarm::setMailAttachment(const QString &mailAttachFile) |
234 | { | 268 | { |
235 | if (mType == Email) { | 269 | if (mType == Email) { |
236 | mMailAttachFiles.clear(); | 270 | mMailAttachFiles.clear(); |
237 | mMailAttachFiles += mailAttachFile; | 271 | mMailAttachFiles += mailAttachFile; |
238 | mParent->updated(); | 272 | mParent->updated(); |
239 | } | 273 | } |
240 | } | 274 | } |
241 | 275 | ||
242 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) | 276 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) |
243 | { | 277 | { |
244 | if (mType == Email) { | 278 | if (mType == Email) { |
245 | mMailAttachFiles = mailAttachFiles; | 279 | mMailAttachFiles = mailAttachFiles; |
246 | mParent->updated(); | 280 | mParent->updated(); |
247 | } | 281 | } |
248 | } | 282 | } |
249 | 283 | ||
250 | void Alarm::addMailAttachment(const QString &mailAttachFile) | 284 | void Alarm::addMailAttachment(const QString &mailAttachFile) |
251 | { | 285 | { |
252 | if (mType == Email) { | 286 | if (mType == Email) { |
253 | mMailAttachFiles += mailAttachFile; | 287 | mMailAttachFiles += mailAttachFile; |
254 | mParent->updated(); | 288 | mParent->updated(); |
255 | } | 289 | } |
256 | } | 290 | } |
257 | 291 | ||
258 | QStringList Alarm::mailAttachments() const | 292 | QStringList Alarm::mailAttachments() const |
259 | { | 293 | { |
260 | return (mType == Email) ? mMailAttachFiles : QStringList(); | 294 | return (mType == Email) ? mMailAttachFiles : QStringList(); |
261 | } | 295 | } |
262 | 296 | ||
263 | void Alarm::setMailText(const QString &text) | 297 | void Alarm::setMailText(const QString &text) |
264 | { | 298 | { |
265 | if (mType == Email) { | 299 | if (mType == Email) { |
266 | mDescription = text; | 300 | mDescription = text; |
267 | mParent->updated(); | 301 | mParent->updated(); |
268 | } | 302 | } |
269 | } | 303 | } |
270 | 304 | ||
271 | QString Alarm::mailText() const | 305 | QString Alarm::mailText() const |
272 | { | 306 | { |
273 | return (mType == Email) ? mDescription : QString::null; | 307 | return (mType == Email) ? mDescription : QString::null; |
274 | } | 308 | } |
275 | 309 | ||
276 | void Alarm::setDisplayAlarm(const QString &text) | 310 | void Alarm::setDisplayAlarm(const QString &text) |
277 | { | 311 | { |
278 | mType = Display; | 312 | mType = Display; |
279 | mDescription = text; | 313 | mDescription = text; |
280 | mParent->updated(); | 314 | mParent->updated(); |
281 | } | 315 | } |
282 | 316 | ||
283 | void Alarm::setText(const QString &text) | 317 | void Alarm::setText(const QString &text) |
284 | { | 318 | { |
285 | if (mType == Display) { | 319 | if (mType == Display) { |
286 | mDescription = text; | 320 | mDescription = text; |
287 | mParent->updated(); | 321 | mParent->updated(); |
288 | } | 322 | } |
289 | } | 323 | } |
290 | 324 | ||
291 | QString Alarm::text() const | 325 | QString Alarm::text() const |
292 | { | 326 | { |
293 | return (mType == Display) ? mDescription : QString::null; | 327 | return (mType == Display) ? mDescription : QString::null; |
294 | } | 328 | } |
295 | 329 | ||
296 | void Alarm::setTime(const QDateTime &alarmTime) | 330 | void Alarm::setTime(const QDateTime &alarmTime) |
297 | { | 331 | { |
298 | mAlarmTime = alarmTime; | 332 | mAlarmTime = alarmTime; |
299 | mHasTime = true; | 333 | mHasTime = true; |
300 | 334 | ||
301 | mParent->updated(); | 335 | mParent->updated(); |
302 | } | 336 | } |
303 | int Alarm::offset() | 337 | int Alarm::offset() |
304 | { | 338 | { |
305 | if ( hasTime() ) { | 339 | if ( hasTime() ) { |
306 | if (mParent->type()=="Todo") { | 340 | if (mParent->type()=="Todo") { |
307 | Todo *t = static_cast<Todo*>(mParent); | 341 | Todo *t = static_cast<Todo*>(mParent); |
308 | return t->dtDue().secsTo( mAlarmTime ) ; | 342 | return t->dtDue().secsTo( mAlarmTime ) ; |
309 | } else | 343 | } else |
310 | return mParent->dtStart().secsTo( mAlarmTime ) ; | 344 | return mParent->dtStart().secsTo( mAlarmTime ) ; |
311 | } | 345 | } |
312 | else | 346 | else |
313 | { | 347 | { |
314 | return mOffset.asSeconds(); | 348 | return mOffset.asSeconds(); |
315 | } | 349 | } |
316 | 350 | ||
317 | } | 351 | } |
318 | 352 | ||
319 | 353 | ||
320 | QDateTime Alarm::time() const | 354 | QDateTime Alarm::time() const |
321 | { | 355 | { |
322 | if ( hasTime() ) | 356 | if ( hasTime() ) |
323 | return mAlarmTime; | 357 | return mAlarmTime; |
324 | else | 358 | else |
325 | { | 359 | { |
326 | if (mParent->type()=="Todo") { | 360 | if (mParent->type()=="Todo") { |
327 | Todo *t = static_cast<Todo*>(mParent); | 361 | Todo *t = static_cast<Todo*>(mParent); |
328 | return mOffset.end( t->dtDue() ); | 362 | return mOffset.end( t->dtDue() ); |
329 | } else if (mEndOffset) { | 363 | } else if (mEndOffset) { |
330 | return mOffset.end( mParent->dtEnd() ); | 364 | return mOffset.end( mParent->dtEnd() ); |
331 | } else { | 365 | } else { |
332 | return mOffset.end( mParent->dtStart() ); | 366 | return mOffset.end( mParent->dtStart() ); |
333 | } | 367 | } |
334 | } | 368 | } |
335 | } | 369 | } |
336 | 370 | ||
337 | bool Alarm::hasTime() const | 371 | bool Alarm::hasTime() const |
338 | { | 372 | { |
339 | return mHasTime; | 373 | return mHasTime; |
340 | } | 374 | } |
341 | 375 | ||
342 | void Alarm::setSnoozeTime(int alarmSnoozeTime) | 376 | void Alarm::setSnoozeTime(int alarmSnoozeTime) |
343 | { | 377 | { |
344 | mAlarmSnoozeTime = alarmSnoozeTime; | 378 | mAlarmSnoozeTime = alarmSnoozeTime; |
345 | mParent->updated(); | 379 | mParent->updated(); |
346 | } | 380 | } |
347 | 381 | ||
348 | int Alarm::snoozeTime() const | 382 | int Alarm::snoozeTime() const |
349 | { | 383 | { |
350 | return mAlarmSnoozeTime; | 384 | return mAlarmSnoozeTime; |
351 | } | 385 | } |
352 | 386 | ||
353 | void Alarm::setRepeatCount(int alarmRepeatCount) | 387 | void Alarm::setRepeatCount(int alarmRepeatCount) |
354 | { | 388 | { |
355 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; | 389 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; |
356 | 390 | ||
357 | mAlarmRepeatCount = alarmRepeatCount; | 391 | mAlarmRepeatCount = alarmRepeatCount; |
358 | mParent->updated(); | 392 | mParent->updated(); |
359 | } | 393 | } |
360 | 394 | ||
361 | int Alarm::repeatCount() const | 395 | int Alarm::repeatCount() const |
362 | { | 396 | { |
363 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; | 397 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; |
364 | return mAlarmRepeatCount; | 398 | return mAlarmRepeatCount; |
365 | } | 399 | } |
366 | 400 | ||
367 | void Alarm::toggleAlarm() | 401 | void Alarm::toggleAlarm() |
368 | { | 402 | { |
369 | mAlarmEnabled = !mAlarmEnabled; | 403 | mAlarmEnabled = !mAlarmEnabled; |
370 | mParent->updated(); | 404 | mParent->updated(); |
371 | } | 405 | } |
372 | 406 | ||
373 | void Alarm::setEnabled(bool enable) | 407 | void Alarm::setEnabled(bool enable) |
374 | { | 408 | { |
375 | mAlarmEnabled = enable; | 409 | mAlarmEnabled = enable; |
376 | mParent->updated(); | 410 | mParent->updated(); |
377 | } | 411 | } |
378 | 412 | ||
379 | bool Alarm::enabled() const | 413 | bool Alarm::enabled() const |
380 | { | 414 | { |
381 | return mAlarmEnabled; | 415 | return mAlarmEnabled; |
382 | } | 416 | } |
383 | 417 | ||
384 | void Alarm::setStartOffset( const Duration &offset ) | 418 | void Alarm::setStartOffset( const Duration &offset ) |
385 | { | 419 | { |
386 | mOffset = offset; | 420 | mOffset = offset; |
387 | mEndOffset = false; | 421 | mEndOffset = false; |
388 | mHasTime = false; | 422 | mHasTime = false; |
389 | mParent->updated(); | 423 | mParent->updated(); |
390 | } | 424 | } |
391 | 425 | ||
392 | Duration Alarm::startOffset() const | 426 | Duration Alarm::startOffset() const |
393 | { | 427 | { |
394 | return (mHasTime || mEndOffset) ? 0 : mOffset; | 428 | return (mHasTime || mEndOffset) ? 0 : mOffset; |
395 | } | 429 | } |
396 | 430 | ||
397 | bool Alarm::hasStartOffset() const | 431 | bool Alarm::hasStartOffset() const |
398 | { | 432 | { |
399 | return !mHasTime && !mEndOffset; | 433 | return !mHasTime && !mEndOffset; |
400 | } | 434 | } |
401 | 435 | ||
402 | bool Alarm::hasEndOffset() const | 436 | bool Alarm::hasEndOffset() const |
403 | { | 437 | { |
404 | return !mHasTime && mEndOffset; | 438 | return !mHasTime && mEndOffset; |
405 | } | 439 | } |
406 | 440 | ||
407 | void Alarm::setEndOffset( const Duration &offset ) | 441 | void Alarm::setEndOffset( const Duration &offset ) |
408 | { | 442 | { |
409 | mOffset = offset; | 443 | mOffset = offset; |
410 | mEndOffset = true; | 444 | mEndOffset = true; |
411 | mHasTime = false; | 445 | mHasTime = false; |
412 | mParent->updated(); | 446 | mParent->updated(); |
413 | } | 447 | } |
414 | 448 | ||
415 | Duration Alarm::endOffset() const | 449 | Duration Alarm::endOffset() const |
416 | { | 450 | { |
417 | return (mHasTime || !mEndOffset) ? 0 : mOffset; | 451 | return (mHasTime || !mEndOffset) ? 0 : mOffset; |
418 | } | 452 | } |
419 | 453 | ||
420 | void Alarm::setParent( Incidence *parent ) | 454 | void Alarm::setParent( Incidence *parent ) |
421 | { | 455 | { |
422 | mParent = parent; | 456 | mParent = parent; |
423 | } | 457 | } |
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index dd74e10..e84f672 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -1,2184 +1,2216 @@ | |||
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 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> | 5 | Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <limits.h> | 23 | #include <limits.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 "incidence.h" | 29 | #include "incidence.h" |
30 | 30 | ||
31 | #include "recurrence.h" | 31 | #include "recurrence.h" |
32 | 32 | ||
33 | using namespace KCal; | 33 | using namespace KCal; |
34 | 34 | ||
35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; | 35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; |
36 | 36 | ||
37 | 37 | ||
38 | Recurrence::Recurrence(Incidence *parent, int compatVersion) | 38 | Recurrence::Recurrence(Incidence *parent, int compatVersion) |
39 | : recurs(rNone), // by default, it's not a recurring event | 39 | : recurs(rNone), // by default, it's not a recurring event |
40 | rWeekStart(1), // default is Monday | 40 | rWeekStart(1), // default is Monday |
41 | rDays(7), | 41 | rDays(7), |
42 | mFloats(parent ? parent->doesFloat() : false), | 42 | mFloats(parent ? parent->doesFloat() : false), |
43 | mRecurReadOnly(false), | 43 | mRecurReadOnly(false), |
44 | mRecurExDatesCount(0), | 44 | mRecurExDatesCount(0), |
45 | mFeb29YearlyType(mFeb29YearlyDefaultType), | 45 | mFeb29YearlyType(mFeb29YearlyDefaultType), |
46 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), | 46 | mCompatVersion(compatVersion ? compatVersion : INT_MAX), |
47 | mCompatRecurs(rNone), | 47 | mCompatRecurs(rNone), |
48 | mCompatDuration(0), | 48 | mCompatDuration(0), |
49 | mParent(parent) | 49 | mParent(parent) |
50 | { | 50 | { |
51 | rMonthDays.setAutoDelete( true ); | 51 | rMonthDays.setAutoDelete( true ); |
52 | rMonthPositions.setAutoDelete( true ); | 52 | rMonthPositions.setAutoDelete( true ); |
53 | rYearNums.setAutoDelete( true ); | 53 | rYearNums.setAutoDelete( true ); |
54 | } | 54 | } |
55 | 55 | ||
56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) | 56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) |
57 | : recurs(r.recurs), | 57 | : recurs(r.recurs), |
58 | rWeekStart(r.rWeekStart), | 58 | rWeekStart(r.rWeekStart), |
59 | rDays(r.rDays.copy()), | 59 | rDays(r.rDays.copy()), |
60 | rFreq(r.rFreq), | 60 | rFreq(r.rFreq), |
61 | rDuration(r.rDuration), | 61 | rDuration(r.rDuration), |
62 | rEndDateTime(r.rEndDateTime), | 62 | rEndDateTime(r.rEndDateTime), |
63 | mRecurStart(r.mRecurStart), | 63 | mRecurStart(r.mRecurStart), |
64 | mFloats(r.mFloats), | 64 | mFloats(r.mFloats), |
65 | mRecurReadOnly(r.mRecurReadOnly), | 65 | mRecurReadOnly(r.mRecurReadOnly), |
66 | mRecurExDatesCount(r.mRecurExDatesCount), | 66 | mRecurExDatesCount(r.mRecurExDatesCount), |
67 | mFeb29YearlyType(r.mFeb29YearlyType), | 67 | mFeb29YearlyType(r.mFeb29YearlyType), |
68 | mCompatVersion(r.mCompatVersion), | 68 | mCompatVersion(r.mCompatVersion), |
69 | mCompatRecurs(r.mCompatRecurs), | 69 | mCompatRecurs(r.mCompatRecurs), |
70 | mCompatDuration(r.mCompatDuration), | 70 | mCompatDuration(r.mCompatDuration), |
71 | mParent(parent) | 71 | mParent(parent) |
72 | { | 72 | { |
73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { | 73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { |
74 | rMonthPos *tmp = new rMonthPos; | 74 | rMonthPos *tmp = new rMonthPos; |
75 | tmp->rPos = mp.current()->rPos; | 75 | tmp->rPos = mp.current()->rPos; |
76 | tmp->negative = mp.current()->negative; | 76 | tmp->negative = mp.current()->negative; |
77 | tmp->rDays = mp.current()->rDays.copy(); | 77 | tmp->rDays = mp.current()->rDays.copy(); |
78 | rMonthPositions.append(tmp); | 78 | rMonthPositions.append(tmp); |
79 | } | 79 | } |
80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { | 80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { |
81 | int *tmp = new int; | 81 | int *tmp = new int; |
82 | *tmp = *md.current(); | 82 | *tmp = *md.current(); |
83 | rMonthDays.append(tmp); | 83 | rMonthDays.append(tmp); |
84 | } | 84 | } |
85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { | 85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { |
86 | int *tmp = new int; | 86 | int *tmp = new int; |
87 | *tmp = *yn.current(); | 87 | *tmp = *yn.current(); |
88 | rYearNums.append(tmp); | 88 | rYearNums.append(tmp); |
89 | } | 89 | } |
90 | rMonthDays.setAutoDelete( true ); | 90 | rMonthDays.setAutoDelete( true ); |
91 | rMonthPositions.setAutoDelete( true ); | 91 | rMonthPositions.setAutoDelete( true ); |
92 | rYearNums.setAutoDelete( true ); | 92 | rYearNums.setAutoDelete( true ); |
93 | } | 93 | } |
94 | 94 | ||
95 | Recurrence::~Recurrence() | 95 | Recurrence::~Recurrence() |
96 | { | 96 | { |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | bool Recurrence::operator==( const Recurrence& r2 ) const | 100 | bool Recurrence::operator==( const Recurrence& r2 ) const |
101 | { | 101 | { |
102 | 102 | ||
103 | // the following line is obvious | 103 | // the following line is obvious |
104 | if ( recurs == rNone && r2.recurs == rNone ) | 104 | if ( recurs == rNone && r2.recurs == rNone ) |
105 | return true; | 105 | return true; |
106 | // we need the above line, because two non recurring events may | 106 | // we need the above line, because two non recurring events may |
107 | // differ in the other settings, because one (or both) | 107 | // differ in the other settings, because one (or both) |
108 | // may be not initialized properly | 108 | // may be not initialized properly |
109 | |||
109 | if ( recurs != r2.recurs | 110 | if ( recurs != r2.recurs |
110 | || rFreq != r2.rFreq | 111 | || rFreq != r2.rFreq |
111 | || rDuration != r2.rDuration | 112 | || rDuration != r2.rDuration |
112 | || !rDuration && rEndDateTime != r2.rEndDateTime | 113 | || !rDuration && rEndDateTime != r2.rEndDateTime |
113 | || mRecurStart != r2.mRecurStart | 114 | || mRecurStart != r2.mRecurStart |
114 | || mFloats != r2.mFloats | 115 | || mFloats != r2.mFloats |
115 | || mRecurReadOnly != r2.mRecurReadOnly | 116 | || mRecurReadOnly != r2.mRecurReadOnly |
116 | || mRecurExDatesCount != r2.mRecurExDatesCount ) | 117 | || mRecurExDatesCount != r2.mRecurExDatesCount ) |
117 | return false; | 118 | return false; |
118 | // no need to compare mCompat* and mParent | 119 | // no need to compare mCompat* and mParent |
119 | // OK to compare the pointers | 120 | // OK to compare the pointers |
120 | switch ( recurs ) | 121 | switch ( recurs ) |
121 | { | 122 | { |
122 | case rWeekly: | 123 | case rWeekly: |
123 | return rDays == r2.rDays | 124 | return rDays == r2.rDays |
124 | && rWeekStart == r2.rWeekStart; | 125 | && rWeekStart == r2.rWeekStart; |
125 | case rMonthlyPos: | 126 | case rMonthlyPos: { |
126 | return rMonthPositions.count() == r2.rMonthPositions.count(); | 127 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; |
127 | case rMonthlyDay: | 128 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
128 | return rMonthDays.count() == r2.rMonthDays.count(); | 129 | if ( !MonthPositions.count() ) |
129 | case rYearlyPos: | 130 | return false; |
130 | return rYearNums.count() == r2.rYearNums.count() | 131 | if ( !MonthPositions2.count() ) |
131 | && rMonthPositions.count() == r2.rMonthPositions.count(); | 132 | return false; |
132 | case rYearlyMonth: | 133 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
133 | return rYearNums.count() == r2.rYearNums.count() | 134 | } |
134 | && mFeb29YearlyType == r2.mFeb29YearlyType; | 135 | case rMonthlyDay: { |
135 | case rYearlyDay: | 136 | QPtrList<int> MonthDays = rMonthDays ; |
136 | return rYearNums == r2.rYearNums; | 137 | QPtrList<int> MonthDays2 = r2.rMonthDays ; |
138 | if ( !MonthDays.count() ) | ||
139 | return false; | ||
140 | if ( !MonthDays2.count() ) | ||
141 | return false; | ||
142 | return *MonthDays.first() == *MonthDays2.first() ; | ||
143 | } | ||
144 | case rYearlyPos: { | ||
145 | |||
146 | QPtrList<int> YearNums = rYearNums; | ||
147 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
148 | if ( *YearNums.first() != *YearNums2.first() ) | ||
149 | return false; | ||
150 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | ||
151 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | ||
152 | if ( !MonthPositions.count() ) | ||
153 | return false; | ||
154 | if ( !MonthPositions2.count() ) | ||
155 | return false; | ||
156 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | ||
157 | |||
158 | } | ||
159 | case rYearlyMonth: { | ||
160 | QPtrList<int> YearNums = rYearNums; | ||
161 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
162 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); | ||
163 | } | ||
164 | case rYearlyDay: { | ||
165 | QPtrList<int> YearNums = rYearNums; | ||
166 | QPtrList<int> YearNums2 = r2.rYearNums; | ||
167 | return ( *YearNums.first() == *YearNums2.first() ); | ||
168 | } | ||
137 | case rNone: | 169 | case rNone: |
138 | case rMinutely: | 170 | case rMinutely: |
139 | case rHourly: | 171 | case rHourly: |
140 | case rDaily: | 172 | case rDaily: |
141 | default: | 173 | default: |
142 | return true; | 174 | return true; |
143 | } | 175 | } |
144 | } | 176 | } |
145 | /* | 177 | /* |
146 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) | 178 | bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) |
147 | { | 179 | { |
148 | if ( l1.count() != l2.count() ) | 180 | if ( l1.count() != l2.count() ) |
149 | return false; | 181 | return false; |
150 | int count = l1.count(); | 182 | int count = l1.count(); |
151 | int i; | 183 | int i; |
152 | for ( i = 0; i < count ; ++i ) { | 184 | for ( i = 0; i < count ; ++i ) { |
153 | // if ( l1.at(i) != l2.at(i) ) | 185 | // if ( l1.at(i) != l2.at(i) ) |
154 | return false; | 186 | return false; |
155 | qDebug("compüare "); | 187 | qDebug("compüare "); |
156 | } | 188 | } |
157 | return true; | 189 | return true; |
158 | } | 190 | } |
159 | */ | 191 | */ |
160 | QString Recurrence::recurrenceText() const | 192 | QString Recurrence::recurrenceText() const |
161 | { | 193 | { |
162 | QString recurText = i18n("No"); | 194 | QString recurText = i18n("No"); |
163 | if ( recurs == Recurrence::rMinutely ) | 195 | if ( recurs == Recurrence::rMinutely ) |
164 | recurText = i18n("minutely"); | 196 | recurText = i18n("minutely"); |
165 | else if ( recurs == Recurrence::rHourly ) | 197 | else if ( recurs == Recurrence::rHourly ) |
166 | recurText = i18n("hourly"); | 198 | recurText = i18n("hourly"); |
167 | else if ( recurs == Recurrence::rDaily ) | 199 | else if ( recurs == Recurrence::rDaily ) |
168 | recurText = i18n("daily"); | 200 | recurText = i18n("daily"); |
169 | else if ( recurs == Recurrence::rWeekly ) | 201 | else if ( recurs == Recurrence::rWeekly ) |
170 | recurText = i18n("weekly"); | 202 | recurText = i18n("weekly"); |
171 | else if ( recurs == Recurrence::rMonthlyPos ) | 203 | else if ( recurs == Recurrence::rMonthlyPos ) |
172 | recurText = i18n("monthly"); | 204 | recurText = i18n("monthly"); |
173 | else if ( recurs == Recurrence::rMonthlyDay ) | 205 | else if ( recurs == Recurrence::rMonthlyDay ) |
174 | recurText = i18n("day-monthly"); | 206 | recurText = i18n("day-monthly"); |
175 | else if ( recurs == Recurrence::rYearlyMonth ) | 207 | else if ( recurs == Recurrence::rYearlyMonth ) |
176 | recurText = i18n("month-yearly"); | 208 | recurText = i18n("month-yearly"); |
177 | else if ( recurs == Recurrence::rYearlyDay ) | 209 | else if ( recurs == Recurrence::rYearlyDay ) |
178 | recurText = i18n("day-yearly"); | 210 | recurText = i18n("day-yearly"); |
179 | else if ( recurs == Recurrence::rYearlyPos ) | 211 | else if ( recurs == Recurrence::rYearlyPos ) |
180 | recurText = i18n("position-yearly"); | 212 | recurText = i18n("position-yearly"); |
181 | return recurText; | 213 | return recurText; |
182 | } | 214 | } |
183 | 215 | ||
184 | void Recurrence::setCompatVersion(int version) | 216 | void Recurrence::setCompatVersion(int version) |
185 | { | 217 | { |
186 | mCompatVersion = version ? version : INT_MAX; | 218 | mCompatVersion = version ? version : INT_MAX; |
187 | } | 219 | } |
188 | 220 | ||
189 | ushort Recurrence::doesRecur() const | 221 | ushort Recurrence::doesRecur() const |
190 | { | 222 | { |
191 | return recurs; | 223 | return recurs; |
192 | } | 224 | } |
193 | 225 | ||
194 | bool Recurrence::recursOnPure(const QDate &qd) const | 226 | bool Recurrence::recursOnPure(const QDate &qd) const |
195 | { | 227 | { |
196 | switch(recurs) { | 228 | switch(recurs) { |
197 | case rMinutely: | 229 | case rMinutely: |
198 | return recursSecondly(qd, rFreq*60); | 230 | return recursSecondly(qd, rFreq*60); |
199 | case rHourly: | 231 | case rHourly: |
200 | return recursSecondly(qd, rFreq*3600); | 232 | return recursSecondly(qd, rFreq*3600); |
201 | case rDaily: | 233 | case rDaily: |
202 | return recursDaily(qd); | 234 | return recursDaily(qd); |
203 | case rWeekly: | 235 | case rWeekly: |
204 | return recursWeekly(qd); | 236 | return recursWeekly(qd); |
205 | case rMonthlyPos: | 237 | case rMonthlyPos: |
206 | case rMonthlyDay: | 238 | case rMonthlyDay: |
207 | return recursMonthly(qd); | 239 | return recursMonthly(qd); |
208 | case rYearlyMonth: | 240 | case rYearlyMonth: |
209 | return recursYearlyByMonth(qd); | 241 | return recursYearlyByMonth(qd); |
210 | case rYearlyDay: | 242 | case rYearlyDay: |
211 | return recursYearlyByDay(qd); | 243 | return recursYearlyByDay(qd); |
212 | case rYearlyPos: | 244 | case rYearlyPos: |
213 | return recursYearlyByPos(qd); | 245 | return recursYearlyByPos(qd); |
214 | default: | 246 | default: |
215 | return false; | 247 | return false; |
216 | case rNone: | 248 | case rNone: |
217 | return false; | 249 | return false; |
218 | } // case | 250 | } // case |
219 | return false; | 251 | return false; |
220 | } | 252 | } |
221 | 253 | ||
222 | bool Recurrence::recursAtPure(const QDateTime &dt) const | 254 | bool Recurrence::recursAtPure(const QDateTime &dt) const |
223 | { | 255 | { |
224 | switch(recurs) { | 256 | switch(recurs) { |
225 | case rMinutely: | 257 | case rMinutely: |
226 | return recursMinutelyAt(dt, rFreq); | 258 | return recursMinutelyAt(dt, rFreq); |
227 | case rHourly: | 259 | case rHourly: |
228 | return recursMinutelyAt(dt, rFreq*60); | 260 | return recursMinutelyAt(dt, rFreq*60); |
229 | default: | 261 | default: |
230 | if (dt.time() != mRecurStart.time()) | 262 | if (dt.time() != mRecurStart.time()) |
231 | return false; | 263 | return false; |
232 | switch(recurs) { | 264 | switch(recurs) { |
233 | case rDaily: | 265 | case rDaily: |
234 | return recursDaily(dt.date()); | 266 | return recursDaily(dt.date()); |
235 | case rWeekly: | 267 | case rWeekly: |
236 | return recursWeekly(dt.date()); | 268 | return recursWeekly(dt.date()); |
237 | case rMonthlyPos: | 269 | case rMonthlyPos: |
238 | case rMonthlyDay: | 270 | case rMonthlyDay: |
239 | return recursMonthly(dt.date()); | 271 | return recursMonthly(dt.date()); |
240 | case rYearlyMonth: | 272 | case rYearlyMonth: |
241 | return recursYearlyByMonth(dt.date()); | 273 | return recursYearlyByMonth(dt.date()); |
242 | case rYearlyDay: | 274 | case rYearlyDay: |
243 | return recursYearlyByDay(dt.date()); | 275 | return recursYearlyByDay(dt.date()); |
244 | case rYearlyPos: | 276 | case rYearlyPos: |
245 | return recursYearlyByPos(dt.date()); | 277 | return recursYearlyByPos(dt.date()); |
246 | default: | 278 | default: |
247 | return false; | 279 | return false; |
248 | case rNone: | 280 | case rNone: |
249 | return false; | 281 | return false; |
250 | } | 282 | } |
251 | } // case | 283 | } // case |
252 | return false; | 284 | return false; |
253 | } | 285 | } |
254 | 286 | ||
255 | QDate Recurrence::endDate() const | 287 | QDate Recurrence::endDate() const |
256 | { | 288 | { |
257 | int count = 0; | 289 | int count = 0; |
258 | QDate end; | 290 | QDate end; |
259 | if (recurs != rNone) { | 291 | if (recurs != rNone) { |
260 | if (rDuration < 0) | 292 | if (rDuration < 0) |
261 | return QDate(); // infinite recurrence | 293 | return QDate(); // infinite recurrence |
262 | if (rDuration == 0) | 294 | if (rDuration == 0) |
263 | return rEndDateTime.date(); | 295 | return rEndDateTime.date(); |
264 | 296 | ||
265 | // The end date is determined by the recurrence count | 297 | // The end date is determined by the recurrence count |
266 | QDate dStart = mRecurStart.date(); | 298 | QDate dStart = mRecurStart.date(); |
267 | switch (recurs) | 299 | switch (recurs) |
268 | { | 300 | { |
269 | case rMinutely: | 301 | case rMinutely: |
270 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); | 302 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); |
271 | case rHourly: | 303 | case rHourly: |
272 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); | 304 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); |
273 | case rDaily: | 305 | case rDaily: |
274 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 306 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
275 | 307 | ||
276 | case rWeekly: | 308 | case rWeekly: |
277 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 309 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
278 | break; | 310 | break; |
279 | case rMonthlyPos: | 311 | case rMonthlyPos: |
280 | case rMonthlyDay: | 312 | case rMonthlyDay: |
281 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 313 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
282 | break; | 314 | break; |
283 | case rYearlyMonth: | 315 | case rYearlyMonth: |
284 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 316 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
285 | break; | 317 | break; |
286 | case rYearlyDay: | 318 | case rYearlyDay: |
287 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 319 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
288 | break; | 320 | break; |
289 | case rYearlyPos: | 321 | case rYearlyPos: |
290 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 322 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
291 | break; | 323 | break; |
292 | default: | 324 | default: |
293 | // catch-all. Should never get here. | 325 | // catch-all. Should never get here. |
294 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 326 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
295 | break; | 327 | break; |
296 | } | 328 | } |
297 | } | 329 | } |
298 | if (!count) | 330 | if (!count) |
299 | return QDate(); // error - there is no recurrence | 331 | return QDate(); // error - there is no recurrence |
300 | return end; | 332 | return end; |
301 | } | 333 | } |
302 | 334 | ||
303 | QDateTime Recurrence::endDateTime() const | 335 | QDateTime Recurrence::endDateTime() const |
304 | { | 336 | { |
305 | int count = 0; | 337 | int count = 0; |
306 | QDate end; | 338 | QDate end; |
307 | if (recurs != rNone) { | 339 | if (recurs != rNone) { |
308 | if (rDuration < 0) | 340 | if (rDuration < 0) |
309 | return QDateTime(); // infinite recurrence | 341 | return QDateTime(); // infinite recurrence |
310 | if (rDuration == 0) | 342 | if (rDuration == 0) |
311 | return rEndDateTime; | 343 | return rEndDateTime; |
312 | 344 | ||
313 | // The end date is determined by the recurrence count | 345 | // The end date is determined by the recurrence count |
314 | QDate dStart = mRecurStart.date(); | 346 | QDate dStart = mRecurStart.date(); |
315 | switch (recurs) | 347 | switch (recurs) |
316 | { | 348 | { |
317 | case rMinutely: | 349 | case rMinutely: |
318 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); | 350 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); |
319 | case rHourly: | 351 | case rHourly: |
320 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); | 352 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); |
321 | case rDaily: | 353 | case rDaily: |
322 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 354 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
323 | 355 | ||
324 | case rWeekly: | 356 | case rWeekly: |
325 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 357 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
326 | break; | 358 | break; |
327 | case rMonthlyPos: | 359 | case rMonthlyPos: |
328 | case rMonthlyDay: | 360 | case rMonthlyDay: |
329 | count = monthlyCalc(END_DATE_AND_COUNT, end); | 361 | count = monthlyCalc(END_DATE_AND_COUNT, end); |
330 | break; | 362 | break; |
331 | case rYearlyMonth: | 363 | case rYearlyMonth: |
332 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); | 364 | count = yearlyMonthCalc(END_DATE_AND_COUNT, end); |
333 | break; | 365 | break; |
334 | case rYearlyDay: | 366 | case rYearlyDay: |
335 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); | 367 | count = yearlyDayCalc(END_DATE_AND_COUNT, end); |
336 | break; | 368 | break; |
337 | case rYearlyPos: | 369 | case rYearlyPos: |
338 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); | 370 | count = yearlyPosCalc(END_DATE_AND_COUNT, end); |
339 | break; | 371 | break; |
340 | default: | 372 | default: |
341 | // catch-all. Should never get here. | 373 | // catch-all. Should never get here. |
342 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; | 374 | kdDebug(5800) << "Control should never reach here in endDate()!" << endl; |
343 | break; | 375 | break; |
344 | } | 376 | } |
345 | } | 377 | } |
346 | if (!count) | 378 | if (!count) |
347 | return QDateTime(); // error - there is no recurrence | 379 | return QDateTime(); // error - there is no recurrence |
348 | return QDateTime(end, mRecurStart.time()); | 380 | return QDateTime(end, mRecurStart.time()); |
349 | } | 381 | } |
350 | 382 | ||
351 | int Recurrence::durationTo(const QDate &date) const | 383 | int Recurrence::durationTo(const QDate &date) const |
352 | { | 384 | { |
353 | QDate d = date; | 385 | QDate d = date; |
354 | return recurCalc(COUNT_TO_DATE, d); | 386 | return recurCalc(COUNT_TO_DATE, d); |
355 | } | 387 | } |
356 | 388 | ||
357 | int Recurrence::durationTo(const QDateTime &datetime) const | 389 | int Recurrence::durationTo(const QDateTime &datetime) const |
358 | { | 390 | { |
359 | QDateTime dt = datetime; | 391 | QDateTime dt = datetime; |
360 | return recurCalc(COUNT_TO_DATE, dt); | 392 | return recurCalc(COUNT_TO_DATE, dt); |
361 | } | 393 | } |
362 | 394 | ||
363 | void Recurrence::unsetRecurs() | 395 | void Recurrence::unsetRecurs() |
364 | { | 396 | { |
365 | if (mRecurReadOnly) return; | 397 | if (mRecurReadOnly) return; |
366 | recurs = rNone; | 398 | recurs = rNone; |
367 | rMonthPositions.clear(); | 399 | rMonthPositions.clear(); |
368 | rMonthDays.clear(); | 400 | rMonthDays.clear(); |
369 | rYearNums.clear(); | 401 | rYearNums.clear(); |
370 | } | 402 | } |
371 | 403 | ||
372 | void Recurrence::setRecurStart(const QDateTime &start) | 404 | void Recurrence::setRecurStart(const QDateTime &start) |
373 | { | 405 | { |
374 | mRecurStart = start; | 406 | mRecurStart = start; |
375 | mFloats = false; | 407 | mFloats = false; |
376 | switch (recurs) | 408 | switch (recurs) |
377 | { | 409 | { |
378 | case rMinutely: | 410 | case rMinutely: |
379 | case rHourly: | 411 | case rHourly: |
380 | break; | 412 | break; |
381 | case rDaily: | 413 | case rDaily: |
382 | case rWeekly: | 414 | case rWeekly: |
383 | case rMonthlyPos: | 415 | case rMonthlyPos: |
384 | case rMonthlyDay: | 416 | case rMonthlyDay: |
385 | case rYearlyMonth: | 417 | case rYearlyMonth: |
386 | case rYearlyDay: | 418 | case rYearlyDay: |
387 | case rYearlyPos: | 419 | case rYearlyPos: |
388 | default: | 420 | default: |
389 | rEndDateTime.setTime(start.time()); | 421 | rEndDateTime.setTime(start.time()); |
390 | break; | 422 | break; |
391 | } | 423 | } |
392 | } | 424 | } |
393 | 425 | ||
394 | void Recurrence::setRecurStart(const QDate &start) | 426 | void Recurrence::setRecurStart(const QDate &start) |
395 | { | 427 | { |
396 | mRecurStart.setDate(start); | 428 | mRecurStart.setDate(start); |
397 | mRecurStart.setTime(QTime(0,0,0)); | 429 | mRecurStart.setTime(QTime(0,0,0)); |
398 | switch (recurs) | 430 | switch (recurs) |
399 | { | 431 | { |
400 | case rMinutely: | 432 | case rMinutely: |
401 | case rHourly: | 433 | case rHourly: |
402 | break; | 434 | break; |
403 | case rDaily: | 435 | case rDaily: |
404 | case rWeekly: | 436 | case rWeekly: |
405 | case rMonthlyPos: | 437 | case rMonthlyPos: |
406 | case rMonthlyDay: | 438 | case rMonthlyDay: |
407 | case rYearlyMonth: | 439 | case rYearlyMonth: |
408 | case rYearlyDay: | 440 | case rYearlyDay: |
409 | case rYearlyPos: | 441 | case rYearlyPos: |
410 | default: | 442 | default: |
411 | mFloats = true; | 443 | mFloats = true; |
412 | break; | 444 | break; |
413 | } | 445 | } |
414 | } | 446 | } |
415 | 447 | ||
416 | void Recurrence::setFloats(bool f) | 448 | void Recurrence::setFloats(bool f) |
417 | { | 449 | { |
418 | switch (recurs) | 450 | switch (recurs) |
419 | { | 451 | { |
420 | case rDaily: | 452 | case rDaily: |
421 | case rWeekly: | 453 | case rWeekly: |
422 | case rMonthlyPos: | 454 | case rMonthlyPos: |
423 | case rMonthlyDay: | 455 | case rMonthlyDay: |
424 | case rYearlyMonth: | 456 | case rYearlyMonth: |
425 | case rYearlyDay: | 457 | case rYearlyDay: |
426 | case rYearlyPos: | 458 | case rYearlyPos: |
427 | break; | 459 | break; |
428 | case rMinutely: | 460 | case rMinutely: |
429 | case rHourly: | 461 | case rHourly: |
430 | default: | 462 | default: |
431 | return; // can't set sub-daily to floating | 463 | return; // can't set sub-daily to floating |
432 | } | 464 | } |
433 | mFloats = f; | 465 | mFloats = f; |
434 | if (f) { | 466 | if (f) { |
435 | mRecurStart.setTime(QTime(0,0,0)); | 467 | mRecurStart.setTime(QTime(0,0,0)); |
436 | rEndDateTime.setTime(QTime(0,0,0)); | 468 | rEndDateTime.setTime(QTime(0,0,0)); |
437 | } | 469 | } |
438 | } | 470 | } |
439 | 471 | ||
440 | int Recurrence::frequency() const | 472 | int Recurrence::frequency() const |
441 | { | 473 | { |
442 | return rFreq; | 474 | return rFreq; |
443 | } | 475 | } |
444 | 476 | ||
445 | int Recurrence::duration() const | 477 | int Recurrence::duration() const |
446 | { | 478 | { |
447 | return rDuration; | 479 | return rDuration; |
448 | } | 480 | } |
449 | 481 | ||
450 | void Recurrence::setDuration(int _rDuration) | 482 | void Recurrence::setDuration(int _rDuration) |
451 | { | 483 | { |
452 | if (mRecurReadOnly) return; | 484 | if (mRecurReadOnly) return; |
453 | if (_rDuration > 0) { | 485 | if (_rDuration > 0) { |
454 | rDuration = _rDuration; | 486 | rDuration = _rDuration; |
455 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, | 487 | // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, |
456 | // so explicitly setting the duration means no backwards compatibility is needed. | 488 | // so explicitly setting the duration means no backwards compatibility is needed. |
457 | mCompatDuration = 0; | 489 | mCompatDuration = 0; |
458 | } | 490 | } |
459 | } | 491 | } |
460 | 492 | ||
461 | QString Recurrence::endDateStr(bool shortfmt) const | 493 | QString Recurrence::endDateStr(bool shortfmt) const |
462 | { | 494 | { |
463 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); | 495 | return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); |
464 | } | 496 | } |
465 | 497 | ||
466 | const QBitArray &Recurrence::days() const | 498 | const QBitArray &Recurrence::days() const |
467 | { | 499 | { |
468 | return rDays; | 500 | return rDays; |
469 | } | 501 | } |
470 | 502 | ||
471 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const | 503 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const |
472 | { | 504 | { |
473 | return rMonthPositions; | 505 | return rMonthPositions; |
474 | } | 506 | } |
475 | 507 | ||
476 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const | 508 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const |
477 | { | 509 | { |
478 | return rMonthPositions; | 510 | return rMonthPositions; |
479 | } | 511 | } |
480 | 512 | ||
481 | const QPtrList<int> &Recurrence::monthDays() const | 513 | const QPtrList<int> &Recurrence::monthDays() const |
482 | { | 514 | { |
483 | return rMonthDays; | 515 | return rMonthDays; |
484 | } | 516 | } |
485 | 517 | ||
486 | void Recurrence::setMinutely(int _rFreq, int _rDuration) | 518 | void Recurrence::setMinutely(int _rFreq, int _rDuration) |
487 | { | 519 | { |
488 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 520 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
489 | return; | 521 | return; |
490 | setDailySub(rMinutely, _rFreq, _rDuration); | 522 | setDailySub(rMinutely, _rFreq, _rDuration); |
491 | } | 523 | } |
492 | 524 | ||
493 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) | 525 | void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) |
494 | { | 526 | { |
495 | if (mRecurReadOnly) return; | 527 | if (mRecurReadOnly) return; |
496 | rEndDateTime = _rEndDateTime; | 528 | rEndDateTime = _rEndDateTime; |
497 | setDailySub(rMinutely, _rFreq, 0); | 529 | setDailySub(rMinutely, _rFreq, 0); |
498 | } | 530 | } |
499 | 531 | ||
500 | void Recurrence::setHourly(int _rFreq, int _rDuration) | 532 | void Recurrence::setHourly(int _rFreq, int _rDuration) |
501 | { | 533 | { |
502 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 534 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
503 | return; | 535 | return; |
504 | setDailySub(rHourly, _rFreq, _rDuration); | 536 | setDailySub(rHourly, _rFreq, _rDuration); |
505 | } | 537 | } |
506 | 538 | ||
507 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) | 539 | void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) |
508 | { | 540 | { |
509 | if (mRecurReadOnly) return; | 541 | if (mRecurReadOnly) return; |
510 | rEndDateTime = _rEndDateTime; | 542 | rEndDateTime = _rEndDateTime; |
511 | setDailySub(rHourly, _rFreq, 0); | 543 | setDailySub(rHourly, _rFreq, 0); |
512 | } | 544 | } |
513 | 545 | ||
514 | void Recurrence::setDaily(int _rFreq, int _rDuration) | 546 | void Recurrence::setDaily(int _rFreq, int _rDuration) |
515 | { | 547 | { |
516 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 548 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
517 | return; | 549 | return; |
518 | setDailySub(rDaily, _rFreq, _rDuration); | 550 | setDailySub(rDaily, _rFreq, _rDuration); |
519 | } | 551 | } |
520 | 552 | ||
521 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) | 553 | void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) |
522 | { | 554 | { |
523 | if (mRecurReadOnly) return; | 555 | if (mRecurReadOnly) return; |
524 | rEndDateTime.setDate(_rEndDate); | 556 | rEndDateTime.setDate(_rEndDate); |
525 | rEndDateTime.setTime(mRecurStart.time()); | 557 | rEndDateTime.setTime(mRecurStart.time()); |
526 | setDailySub(rDaily, _rFreq, 0); | 558 | setDailySub(rDaily, _rFreq, 0); |
527 | } | 559 | } |
528 | 560 | ||
529 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 561 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
530 | int _rDuration, int _rWeekStart) | 562 | int _rDuration, int _rWeekStart) |
531 | { | 563 | { |
532 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 564 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
533 | return; | 565 | return; |
534 | recurs = rWeekly; | 566 | recurs = rWeekly; |
535 | 567 | ||
536 | rFreq = _rFreq; | 568 | rFreq = _rFreq; |
537 | rDays = _rDays; | 569 | rDays = _rDays; |
538 | rWeekStart = _rWeekStart; | 570 | rWeekStart = _rWeekStart; |
539 | rDuration = _rDuration; | 571 | rDuration = _rDuration; |
540 | if (mCompatVersion < 310 && _rDuration > 0) { | 572 | if (mCompatVersion < 310 && _rDuration > 0) { |
541 | // Backwards compatibility for KDE < 3.1. | 573 | // Backwards compatibility for KDE < 3.1. |
542 | // rDuration was set to the number of time periods to recur, | 574 | // rDuration was set to the number of time periods to recur, |
543 | // with week start always on a Monday. | 575 | // with week start always on a Monday. |
544 | // Convert this to the number of occurrences. | 576 | // Convert this to the number of occurrences. |
545 | mCompatDuration = _rDuration; | 577 | mCompatDuration = _rDuration; |
546 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); | 578 | int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); |
547 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); | 579 | QDate end(mRecurStart.date().addDays(weeks * rFreq)); |
548 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly | 580 | rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly |
549 | rDuration = weeklyCalc(COUNT_TO_DATE, end); | 581 | rDuration = weeklyCalc(COUNT_TO_DATE, end); |
550 | } else { | 582 | } else { |
551 | mCompatDuration = 0; | 583 | mCompatDuration = 0; |
552 | } | 584 | } |
553 | rMonthPositions.clear(); | 585 | rMonthPositions.clear(); |
554 | rMonthDays.clear(); | 586 | rMonthDays.clear(); |
555 | if (mParent) mParent->updated(); | 587 | if (mParent) mParent->updated(); |
556 | } | 588 | } |
557 | 589 | ||
558 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, | 590 | void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, |
559 | const QDate &_rEndDate, int _rWeekStart) | 591 | const QDate &_rEndDate, int _rWeekStart) |
560 | { | 592 | { |
561 | if (mRecurReadOnly) return; | 593 | if (mRecurReadOnly) return; |
562 | recurs = rWeekly; | 594 | recurs = rWeekly; |
563 | 595 | ||
564 | rFreq = _rFreq; | 596 | rFreq = _rFreq; |
565 | rDays = _rDays; | 597 | rDays = _rDays; |
566 | rWeekStart = _rWeekStart; | 598 | rWeekStart = _rWeekStart; |
567 | rEndDateTime.setDate(_rEndDate); | 599 | rEndDateTime.setDate(_rEndDate); |
568 | rEndDateTime.setTime(mRecurStart.time()); | 600 | rEndDateTime.setTime(mRecurStart.time()); |
569 | rDuration = 0; // set to 0 because there is an end date | 601 | rDuration = 0; // set to 0 because there is an end date |
570 | mCompatDuration = 0; | 602 | mCompatDuration = 0; |
571 | rMonthPositions.clear(); | 603 | rMonthPositions.clear(); |
572 | rMonthDays.clear(); | 604 | rMonthDays.clear(); |
573 | rYearNums.clear(); | 605 | rYearNums.clear(); |
574 | if (mParent) mParent->updated(); | 606 | if (mParent) mParent->updated(); |
575 | } | 607 | } |
576 | 608 | ||
577 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) | 609 | void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) |
578 | { | 610 | { |
579 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 611 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
580 | return; | 612 | return; |
581 | recurs = type; | 613 | recurs = type; |
582 | 614 | ||
583 | rFreq = _rFreq; | 615 | rFreq = _rFreq; |
584 | rDuration = _rDuration; | 616 | rDuration = _rDuration; |
585 | if (mCompatVersion < 310) | 617 | if (mCompatVersion < 310) |
586 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 618 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
587 | rYearNums.clear(); | 619 | rYearNums.clear(); |
588 | if (mParent) mParent->updated(); | 620 | if (mParent) mParent->updated(); |
589 | } | 621 | } |
590 | 622 | ||
591 | void Recurrence::setMonthly(short type, int _rFreq, | 623 | void Recurrence::setMonthly(short type, int _rFreq, |
592 | const QDate &_rEndDate) | 624 | const QDate &_rEndDate) |
593 | { | 625 | { |
594 | if (mRecurReadOnly) return; | 626 | if (mRecurReadOnly) return; |
595 | recurs = type; | 627 | recurs = type; |
596 | 628 | ||
597 | rFreq = _rFreq; | 629 | rFreq = _rFreq; |
598 | rEndDateTime.setDate(_rEndDate); | 630 | rEndDateTime.setDate(_rEndDate); |
599 | rEndDateTime.setTime(mRecurStart.time()); | 631 | rEndDateTime.setTime(mRecurStart.time()); |
600 | rDuration = 0; // set to 0 because there is an end date | 632 | rDuration = 0; // set to 0 because there is an end date |
601 | mCompatDuration = 0; | 633 | mCompatDuration = 0; |
602 | rYearNums.clear(); | 634 | rYearNums.clear(); |
603 | if (mParent) mParent->updated(); | 635 | if (mParent) mParent->updated(); |
604 | } | 636 | } |
605 | 637 | ||
606 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) | 638 | void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) |
607 | { | 639 | { |
608 | if (recurs == rMonthlyPos) | 640 | if (recurs == rMonthlyPos) |
609 | addMonthlyPos_(_rPos, _rDays); | 641 | addMonthlyPos_(_rPos, _rDays); |
610 | } | 642 | } |
611 | 643 | ||
612 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) | 644 | void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) |
613 | { | 645 | { |
614 | if (mRecurReadOnly | 646 | if (mRecurReadOnly |
615 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number | 647 | || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number |
616 | return; | 648 | return; |
617 | 649 | ||
618 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { | 650 | for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { |
619 | int itPos = it->negative ? -it->rPos : it->rPos; | 651 | int itPos = it->negative ? -it->rPos : it->rPos; |
620 | if (_rPos == itPos) { | 652 | if (_rPos == itPos) { |
621 | // This week is already in the list. | 653 | // This week is already in the list. |
622 | // Combine the specified days with those in the list. | 654 | // Combine the specified days with those in the list. |
623 | it->rDays |= _rDays; | 655 | it->rDays |= _rDays; |
624 | if (mParent) mParent->updated(); | 656 | if (mParent) mParent->updated(); |
625 | return; | 657 | return; |
626 | } | 658 | } |
627 | } | 659 | } |
628 | // Add the new position to the list | 660 | // Add the new position to the list |
629 | rMonthPos *tmpPos = new rMonthPos; | 661 | rMonthPos *tmpPos = new rMonthPos; |
630 | if (_rPos > 0) { | 662 | if (_rPos > 0) { |
631 | tmpPos->rPos = _rPos; | 663 | tmpPos->rPos = _rPos; |
632 | tmpPos->negative = false; | 664 | tmpPos->negative = false; |
633 | } else { | 665 | } else { |
634 | tmpPos->rPos = -_rPos; // take abs() | 666 | tmpPos->rPos = -_rPos; // take abs() |
635 | tmpPos->negative = true; | 667 | tmpPos->negative = true; |
636 | } | 668 | } |
637 | tmpPos->rDays = _rDays; | 669 | tmpPos->rDays = _rDays; |
638 | tmpPos->rDays.detach(); | 670 | tmpPos->rDays.detach(); |
639 | rMonthPositions.append(tmpPos); | 671 | rMonthPositions.append(tmpPos); |
640 | 672 | ||
641 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 673 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
642 | // Backwards compatibility for KDE < 3.1. | 674 | // Backwards compatibility for KDE < 3.1. |
643 | // rDuration was set to the number of time periods to recur. | 675 | // rDuration was set to the number of time periods to recur. |
644 | // Convert this to the number of occurrences. | 676 | // Convert this to the number of occurrences. |
645 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 677 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
646 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 678 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
647 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 679 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
648 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 680 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
649 | rDuration = recurCalc(COUNT_TO_DATE, end); | 681 | rDuration = recurCalc(COUNT_TO_DATE, end); |
650 | } | 682 | } |
651 | 683 | ||
652 | if (mParent) mParent->updated(); | 684 | if (mParent) mParent->updated(); |
653 | } | 685 | } |
654 | 686 | ||
655 | void Recurrence::addMonthlyDay(short _rDay) | 687 | void Recurrence::addMonthlyDay(short _rDay) |
656 | { | 688 | { |
657 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) | 689 | if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) |
658 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number | 690 | || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number |
659 | return; | 691 | return; |
660 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { | 692 | for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { |
661 | if (_rDay == *it) | 693 | if (_rDay == *it) |
662 | return; // this day is already in the list - avoid duplication | 694 | return; // this day is already in the list - avoid duplication |
663 | } | 695 | } |
664 | int *tmpDay = new int; | 696 | int *tmpDay = new int; |
665 | *tmpDay = _rDay; | 697 | *tmpDay = _rDay; |
666 | rMonthDays.append(tmpDay); | 698 | rMonthDays.append(tmpDay); |
667 | 699 | ||
668 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 700 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
669 | // Backwards compatibility for KDE < 3.1. | 701 | // Backwards compatibility for KDE < 3.1. |
670 | // rDuration was set to the number of time periods to recur. | 702 | // rDuration was set to the number of time periods to recur. |
671 | // Convert this to the number of occurrences. | 703 | // Convert this to the number of occurrences. |
672 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; | 704 | int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; |
673 | int month = mRecurStart.date().month() - 1 + monthsAhead; | 705 | int month = mRecurStart.date().month() - 1 + monthsAhead; |
674 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); | 706 | QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); |
675 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 707 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
676 | rDuration = recurCalc(COUNT_TO_DATE, end); | 708 | rDuration = recurCalc(COUNT_TO_DATE, end); |
677 | } | 709 | } |
678 | 710 | ||
679 | if (mParent) mParent->updated(); | 711 | if (mParent) mParent->updated(); |
680 | } | 712 | } |
681 | 713 | ||
682 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) | 714 | void Recurrence::setYearly(int type, int _rFreq, int _rDuration) |
683 | { | 715 | { |
684 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 716 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
685 | return; | 717 | return; |
686 | if (mCompatVersion < 310) | 718 | if (mCompatVersion < 310) |
687 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 719 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
688 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); | 720 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); |
689 | } | 721 | } |
690 | 722 | ||
691 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) | 723 | void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) |
692 | { | 724 | { |
693 | if (mRecurReadOnly) return; | 725 | if (mRecurReadOnly) return; |
694 | rEndDateTime.setDate(_rEndDate); | 726 | rEndDateTime.setDate(_rEndDate); |
695 | rEndDateTime.setTime(mRecurStart.time()); | 727 | rEndDateTime.setTime(mRecurStart.time()); |
696 | mCompatDuration = 0; | 728 | mCompatDuration = 0; |
697 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); | 729 | setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); |
698 | } | 730 | } |
699 | 731 | ||
700 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) | 732 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) |
701 | { | 733 | { |
702 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) | 734 | if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) |
703 | return; | 735 | return; |
704 | if (mCompatVersion < 310) | 736 | if (mCompatVersion < 310) |
705 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; | 737 | mCompatDuration = (_rDuration > 0) ? _rDuration : 0; |
706 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); | 738 | setYearly_(rYearlyMonth, type, _rFreq, _rDuration); |
707 | } | 739 | } |
708 | 740 | ||
709 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) | 741 | void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) |
710 | { | 742 | { |
711 | if (mRecurReadOnly) return; | 743 | if (mRecurReadOnly) return; |
712 | rEndDateTime.setDate(_rEndDate); | 744 | rEndDateTime.setDate(_rEndDate); |
713 | rEndDateTime.setTime(mRecurStart.time()); | 745 | rEndDateTime.setTime(mRecurStart.time()); |
714 | mCompatDuration = 0; | 746 | mCompatDuration = 0; |
715 | setYearly_(rYearlyMonth, type, _rFreq, 0); | 747 | setYearly_(rYearlyMonth, type, _rFreq, 0); |
716 | } | 748 | } |
717 | 749 | ||
718 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) | 750 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) |
719 | { | 751 | { |
720 | if (recurs == rYearlyPos) | 752 | if (recurs == rYearlyPos) |
721 | addMonthlyPos_(_rPos, _rDays); | 753 | addMonthlyPos_(_rPos, _rDays); |
722 | } | 754 | } |
723 | 755 | ||
724 | const QPtrList<int> &Recurrence::yearNums() const | 756 | const QPtrList<int> &Recurrence::yearNums() const |
725 | { | 757 | { |
726 | return rYearNums; | 758 | return rYearNums; |
727 | } | 759 | } |
728 | void Recurrence::addYearlyMonth(short _rPos ) | 760 | void Recurrence::addYearlyMonth(short _rPos ) |
729 | { | 761 | { |
730 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number | 762 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number |
731 | return; | 763 | return; |
732 | rMonthPos *tmpPos = new rMonthPos; | 764 | rMonthPos *tmpPos = new rMonthPos; |
733 | if ( _rPos > 0) { | 765 | if ( _rPos > 0) { |
734 | tmpPos->rPos = _rPos; | 766 | tmpPos->rPos = _rPos; |
735 | tmpPos->negative = false; | 767 | tmpPos->negative = false; |
736 | } else { | 768 | } else { |
737 | tmpPos->rPos = -_rPos; // take abs() | 769 | tmpPos->rPos = -_rPos; // take abs() |
738 | tmpPos->negative = true; | 770 | tmpPos->negative = true; |
739 | } | 771 | } |
740 | rMonthPositions.append(tmpPos); | 772 | rMonthPositions.append(tmpPos); |
741 | } | 773 | } |
742 | void Recurrence::addYearlyNum(short _rNum) | 774 | void Recurrence::addYearlyNum(short _rNum) |
743 | { | 775 | { |
744 | if (mRecurReadOnly | 776 | if (mRecurReadOnly |
745 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) | 777 | || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) |
746 | || _rNum <= 0) // invalid day/month number | 778 | || _rNum <= 0) // invalid day/month number |
747 | return; | 779 | return; |
748 | 780 | ||
749 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { | 781 | if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { |
750 | // Backwards compatibility for KDE < 3.1. | 782 | // Backwards compatibility for KDE < 3.1. |
751 | // Dates were stored as day numbers, with a fiddle to take account of leap years. | 783 | // Dates were stored as day numbers, with a fiddle to take account of leap years. |
752 | // Convert the day number to a month. | 784 | // Convert the day number to a month. |
753 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) | 785 | if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) |
754 | return; // invalid day number | 786 | return; // invalid day number |
755 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); | 787 | _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); |
756 | } else | 788 | } else |
757 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 | 789 | if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 |
758 | || recurs == rYearlyDay && _rNum > 366) | 790 | || recurs == rYearlyDay && _rNum > 366) |
759 | return; // invalid day number | 791 | return; // invalid day number |
760 | 792 | ||
761 | uint i = 0; | 793 | uint i = 0; |
762 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { | 794 | for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { |
763 | if (_rNum == *it) | 795 | if (_rNum == *it) |
764 | return; // this day/month is already in the list - avoid duplication | 796 | return; // this day/month is already in the list - avoid duplication |
765 | ++i; | 797 | ++i; |
766 | } | 798 | } |
767 | 799 | ||
768 | int *tmpNum = new int; | 800 | int *tmpNum = new int; |
769 | *tmpNum = _rNum; | 801 | *tmpNum = _rNum; |
770 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position | 802 | rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position |
771 | 803 | ||
772 | if (mCompatVersion < 310 && mCompatDuration > 0) { | 804 | if (mCompatVersion < 310 && mCompatDuration > 0) { |
773 | // Backwards compatibility for KDE < 3.1. | 805 | // Backwards compatibility for KDE < 3.1. |
774 | // rDuration was set to the number of time periods to recur. | 806 | // rDuration was set to the number of time periods to recur. |
775 | // Convert this to the number of occurrences. | 807 | // Convert this to the number of occurrences. |
776 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); | 808 | QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); |
777 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly | 809 | rDuration = INT_MAX; // ensure that recurCalc() does its job correctly |
778 | rDuration = recurCalc(COUNT_TO_DATE, end); | 810 | rDuration = recurCalc(COUNT_TO_DATE, end); |
779 | } | 811 | } |
780 | 812 | ||
781 | if (mParent) mParent->updated(); | 813 | if (mParent) mParent->updated(); |
782 | } | 814 | } |
783 | 815 | ||
784 | 816 | ||
785 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const | 817 | QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const |
786 | { | 818 | { |
787 | if (last) | 819 | if (last) |
788 | *last = false; | 820 | *last = false; |
789 | int freq; | 821 | int freq; |
790 | switch (recurs) | 822 | switch (recurs) |
791 | { | 823 | { |
792 | case rMinutely: | 824 | case rMinutely: |
793 | freq = rFreq * 60; | 825 | freq = rFreq * 60; |
794 | break; | 826 | break; |
795 | case rHourly: | 827 | case rHourly: |
796 | freq = rFreq * 3600; | 828 | freq = rFreq * 3600; |
797 | break; | 829 | break; |
798 | case rDaily: | 830 | case rDaily: |
799 | case rWeekly: | 831 | case rWeekly: |
800 | case rMonthlyPos: | 832 | case rMonthlyPos: |
801 | case rMonthlyDay: | 833 | case rMonthlyDay: |
802 | case rYearlyMonth: | 834 | case rYearlyMonth: |
803 | case rYearlyDay: | 835 | case rYearlyDay: |
804 | case rYearlyPos: { | 836 | case rYearlyPos: { |
805 | QDate preDate = preDateTime.date(); | 837 | QDate preDate = preDateTime.date(); |
806 | if (!mFloats && mRecurStart.time() > preDateTime.time()) | 838 | if (!mFloats && mRecurStart.time() > preDateTime.time()) |
807 | preDate = preDate.addDays(-1); | 839 | preDate = preDate.addDays(-1); |
808 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); | 840 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); |
809 | } | 841 | } |
810 | default: | 842 | default: |
811 | return QDateTime(); | 843 | return QDateTime(); |
812 | } | 844 | } |
813 | 845 | ||
814 | // It's a sub-daily recurrence | 846 | // It's a sub-daily recurrence |
815 | if (preDateTime < mRecurStart) | 847 | if (preDateTime < mRecurStart) |
816 | return mRecurStart; | 848 | return mRecurStart; |
817 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; | 849 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; |
818 | if (rDuration > 0) { | 850 | if (rDuration > 0) { |
819 | if (count > rDuration) | 851 | if (count > rDuration) |
820 | return QDateTime(); | 852 | return QDateTime(); |
821 | if (last && count == rDuration) | 853 | if (last && count == rDuration) |
822 | *last = true; | 854 | *last = true; |
823 | } | 855 | } |
824 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 856 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
825 | if (rDuration == 0) { | 857 | if (rDuration == 0) { |
826 | if (endtime > rEndDateTime) | 858 | if (endtime > rEndDateTime) |
827 | return QDateTime(); | 859 | return QDateTime(); |
828 | if (last && endtime == rEndDateTime) | 860 | if (last && endtime == rEndDateTime) |
829 | *last = true; | 861 | *last = true; |
830 | } | 862 | } |
831 | return endtime; | 863 | return endtime; |
832 | } | 864 | } |
833 | 865 | ||
834 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const | 866 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const |
835 | { | 867 | { |
836 | if (last) | 868 | if (last) |
837 | *last = false; | 869 | *last = false; |
838 | switch (recurs) | 870 | switch (recurs) |
839 | { | 871 | { |
840 | case rMinutely: | 872 | case rMinutely: |
841 | case rHourly: | 873 | case rHourly: |
842 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); | 874 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); |
843 | case rDaily: | 875 | case rDaily: |
844 | case rWeekly: | 876 | case rWeekly: |
845 | case rMonthlyPos: | 877 | case rMonthlyPos: |
846 | case rMonthlyDay: | 878 | case rMonthlyDay: |
847 | case rYearlyMonth: | 879 | case rYearlyMonth: |
848 | case rYearlyDay: | 880 | case rYearlyDay: |
849 | case rYearlyPos: | 881 | case rYearlyPos: |
850 | return getNextDateNoTime(preDate, last); | 882 | return getNextDateNoTime(preDate, last); |
851 | default: | 883 | default: |
852 | return QDate(); | 884 | return QDate(); |
853 | } | 885 | } |
854 | } | 886 | } |
855 | 887 | ||
856 | 888 | ||
857 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const | 889 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const |
858 | { | 890 | { |
859 | if (last) | 891 | if (last) |
860 | *last = false; | 892 | *last = false; |
861 | int freq; | 893 | int freq; |
862 | switch (recurs) | 894 | switch (recurs) |
863 | { | 895 | { |
864 | case rMinutely: | 896 | case rMinutely: |
865 | freq = rFreq * 60; | 897 | freq = rFreq * 60; |
866 | break; | 898 | break; |
867 | case rHourly: | 899 | case rHourly: |
868 | freq = rFreq * 3600; | 900 | freq = rFreq * 3600; |
869 | break; | 901 | break; |
870 | case rDaily: | 902 | case rDaily: |
871 | case rWeekly: | 903 | case rWeekly: |
872 | case rMonthlyPos: | 904 | case rMonthlyPos: |
873 | case rMonthlyDay: | 905 | case rMonthlyDay: |
874 | case rYearlyMonth: | 906 | case rYearlyMonth: |
875 | case rYearlyDay: | 907 | case rYearlyDay: |
876 | case rYearlyPos: { | 908 | case rYearlyPos: { |
877 | QDate afterDate = afterDateTime.date(); | 909 | QDate afterDate = afterDateTime.date(); |
878 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) | 910 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) |
879 | afterDate = afterDate.addDays(1); | 911 | afterDate = afterDate.addDays(1); |
880 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); | 912 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); |
881 | } | 913 | } |
882 | default: | 914 | default: |
883 | return QDateTime(); | 915 | return QDateTime(); |
884 | } | 916 | } |
885 | 917 | ||
886 | // It's a sub-daily recurrence | 918 | // It's a sub-daily recurrence |
887 | if (afterDateTime <= mRecurStart) | 919 | if (afterDateTime <= mRecurStart) |
888 | return QDateTime(); | 920 | return QDateTime(); |
889 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; | 921 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; |
890 | if (rDuration > 0) { | 922 | if (rDuration > 0) { |
891 | if (count > rDuration) | 923 | if (count > rDuration) |
892 | count = rDuration; | 924 | count = rDuration; |
893 | if (last && count == rDuration) | 925 | if (last && count == rDuration) |
894 | *last = true; | 926 | *last = true; |
895 | } | 927 | } |
896 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 928 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
897 | if (rDuration == 0) { | 929 | if (rDuration == 0) { |
898 | if (endtime > rEndDateTime) | 930 | if (endtime > rEndDateTime) |
899 | endtime = rEndDateTime; | 931 | endtime = rEndDateTime; |
900 | if (last && endtime == rEndDateTime) | 932 | if (last && endtime == rEndDateTime) |
901 | *last = true; | 933 | *last = true; |
902 | } | 934 | } |
903 | return endtime; | 935 | return endtime; |
904 | } | 936 | } |
905 | 937 | ||
906 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const | 938 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const |
907 | { | 939 | { |
908 | if (last) | 940 | if (last) |
909 | *last = false; | 941 | *last = false; |
910 | switch (recurs) | 942 | switch (recurs) |
911 | { | 943 | { |
912 | case rMinutely: | 944 | case rMinutely: |
913 | case rHourly: | 945 | case rHourly: |
914 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); | 946 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); |
915 | case rDaily: | 947 | case rDaily: |
916 | case rWeekly: | 948 | case rWeekly: |
917 | case rMonthlyPos: | 949 | case rMonthlyPos: |
918 | case rMonthlyDay: | 950 | case rMonthlyDay: |
919 | case rYearlyMonth: | 951 | case rYearlyMonth: |
920 | case rYearlyDay: | 952 | case rYearlyDay: |
921 | case rYearlyPos: | 953 | case rYearlyPos: |
922 | return getPreviousDateNoTime(afterDate, last); | 954 | return getPreviousDateNoTime(afterDate, last); |
923 | default: | 955 | default: |
924 | return QDate(); | 956 | return QDate(); |
925 | } | 957 | } |
926 | } | 958 | } |
927 | 959 | ||
928 | 960 | ||
929 | /***************************** PROTECTED FUNCTIONS ***************************/ | 961 | /***************************** PROTECTED FUNCTIONS ***************************/ |
930 | 962 | ||
931 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const | 963 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const |
932 | { | 964 | { |
933 | if ((qd >= mRecurStart.date()) && | 965 | if ((qd >= mRecurStart.date()) && |
934 | ((rDuration > 0) && (qd <= endDate()) || | 966 | ((rDuration > 0) && (qd <= endDate()) || |
935 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || | 967 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || |
936 | (rDuration == -1))) { | 968 | (rDuration == -1))) { |
937 | // The date queried falls within the range of the event. | 969 | // The date queried falls within the range of the event. |
938 | if (secondFreq < 24*3600) | 970 | if (secondFreq < 24*3600) |
939 | return true; // the event recurs at least once each day | 971 | return true; // the event recurs at least once each day |
940 | int after = mRecurStart.secsTo(QDateTime(qd)); | 972 | int after = mRecurStart.secsTo(QDateTime(qd)); |
941 | if (after / secondFreq != (after + 24*3600) / secondFreq) | 973 | if (after / secondFreq != (after + 24*3600) / secondFreq) |
942 | return true; | 974 | return true; |
943 | } | 975 | } |
944 | return false; | 976 | return false; |
945 | } | 977 | } |
946 | 978 | ||
947 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const | 979 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const |
948 | { | 980 | { |
949 | if ((dt >= mRecurStart) && | 981 | if ((dt >= mRecurStart) && |
950 | ((rDuration > 0) && (dt <= endDateTime()) || | 982 | ((rDuration > 0) && (dt <= endDateTime()) || |
951 | ((rDuration == 0) && (dt <= rEndDateTime)) || | 983 | ((rDuration == 0) && (dt <= rEndDateTime)) || |
952 | (rDuration == -1))) { | 984 | (rDuration == -1))) { |
953 | // The time queried falls within the range of the event. | 985 | // The time queried falls within the range of the event. |
954 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) | 986 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) |
955 | return true; | 987 | return true; |
956 | } | 988 | } |
957 | return false; | 989 | return false; |
958 | } | 990 | } |
959 | 991 | ||
960 | bool Recurrence::recursDaily(const QDate &qd) const | 992 | bool Recurrence::recursDaily(const QDate &qd) const |
961 | { | 993 | { |
962 | QDate dStart = mRecurStart.date(); | 994 | QDate dStart = mRecurStart.date(); |
963 | if ((dStart.daysTo(qd) % rFreq) == 0) { | 995 | if ((dStart.daysTo(qd) % rFreq) == 0) { |
964 | // The date is a day which recurs | 996 | // The date is a day which recurs |
965 | if (qd >= dStart | 997 | if (qd >= dStart |
966 | && ((rDuration > 0 && qd <= endDate()) || | 998 | && ((rDuration > 0 && qd <= endDate()) || |
967 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 999 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
968 | rDuration == -1)) { | 1000 | rDuration == -1)) { |
969 | // The date queried falls within the range of the event. | 1001 | // The date queried falls within the range of the event. |
970 | return true; | 1002 | return true; |
971 | } | 1003 | } |
972 | } | 1004 | } |
973 | return false; | 1005 | return false; |
974 | } | 1006 | } |
975 | 1007 | ||
976 | bool Recurrence::recursWeekly(const QDate &qd) const | 1008 | bool Recurrence::recursWeekly(const QDate &qd) const |
977 | { | 1009 | { |
978 | QDate dStart = mRecurStart.date(); | 1010 | QDate dStart = mRecurStart.date(); |
979 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { | 1011 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { |
980 | // The date is in a week which recurs | 1012 | // The date is in a week which recurs |
981 | if (qd >= dStart | 1013 | if (qd >= dStart |
982 | && ((rDuration > 0 && qd <= endDate()) || | 1014 | && ((rDuration > 0 && qd <= endDate()) || |
983 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1015 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
984 | rDuration == -1)) { | 1016 | rDuration == -1)) { |
985 | // The date queried falls within the range of the event. | 1017 | // The date queried falls within the range of the event. |
986 | // check if the bits set match today. | 1018 | // check if the bits set match today. |
987 | int i = qd.dayOfWeek()-1; | 1019 | int i = qd.dayOfWeek()-1; |
988 | if (rDays.testBit((uint) i)) | 1020 | if (rDays.testBit((uint) i)) |
989 | return true; | 1021 | return true; |
990 | } | 1022 | } |
991 | } | 1023 | } |
992 | return false; | 1024 | return false; |
993 | } | 1025 | } |
994 | 1026 | ||
995 | bool Recurrence::recursMonthly(const QDate &qd) const | 1027 | bool Recurrence::recursMonthly(const QDate &qd) const |
996 | { | 1028 | { |
997 | QDate dStart = mRecurStart.date(); | 1029 | QDate dStart = mRecurStart.date(); |
998 | int year = qd.year(); | 1030 | int year = qd.year(); |
999 | int month = qd.month(); | 1031 | int month = qd.month(); |
1000 | int day = qd.day(); | 1032 | int day = qd.day(); |
1001 | // calculate how many months ahead this date is from the original | 1033 | // calculate how many months ahead this date is from the original |
1002 | // event's date | 1034 | // event's date |
1003 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); | 1035 | int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); |
1004 | if ((monthsAhead % rFreq) == 0) { | 1036 | if ((monthsAhead % rFreq) == 0) { |
1005 | // The date is in a month which recurs | 1037 | // The date is in a month which recurs |
1006 | if (qd >= dStart | 1038 | if (qd >= dStart |
1007 | && ((rDuration > 0 && qd <= endDate()) || | 1039 | && ((rDuration > 0 && qd <= endDate()) || |
1008 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1040 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1009 | rDuration == -1)) { | 1041 | rDuration == -1)) { |
1010 | // The date queried falls within the range of the event. | 1042 | // The date queried falls within the range of the event. |
1011 | QValueList<int> days; | 1043 | QValueList<int> days; |
1012 | int daysInMonth = qd.daysInMonth(); | 1044 | int daysInMonth = qd.daysInMonth(); |
1013 | if (recurs == rMonthlyDay) | 1045 | if (recurs == rMonthlyDay) |
1014 | getMonthlyDayDays(days, daysInMonth); | 1046 | getMonthlyDayDays(days, daysInMonth); |
1015 | else if (recurs == rMonthlyPos) | 1047 | else if (recurs == rMonthlyPos) |
1016 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); | 1048 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); |
1017 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1049 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1018 | if (*it == day) | 1050 | if (*it == day) |
1019 | return true; | 1051 | return true; |
1020 | } | 1052 | } |
1021 | // no dates matched | 1053 | // no dates matched |
1022 | } | 1054 | } |
1023 | } | 1055 | } |
1024 | return false; | 1056 | return false; |
1025 | } | 1057 | } |
1026 | 1058 | ||
1027 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const | 1059 | bool Recurrence::recursYearlyByMonth(const QDate &qd) const |
1028 | { | 1060 | { |
1029 | QDate dStart = mRecurStart.date(); | 1061 | QDate dStart = mRecurStart.date(); |
1030 | int startDay = dStart.day(); | 1062 | int startDay = dStart.day(); |
1031 | int qday = qd.day(); | 1063 | int qday = qd.day(); |
1032 | int qmonth = qd.month(); | 1064 | int qmonth = qd.month(); |
1033 | int qyear = qd.year(); | 1065 | int qyear = qd.year(); |
1034 | bool match = (qday == startDay); | 1066 | bool match = (qday == startDay); |
1035 | if (!match && startDay == 29 && dStart.month() == 2) { | 1067 | if (!match && startDay == 29 && dStart.month() == 2) { |
1036 | // It's a recurrence on February 29th | 1068 | // It's a recurrence on February 29th |
1037 | switch (mFeb29YearlyType) { | 1069 | switch (mFeb29YearlyType) { |
1038 | case rFeb28: | 1070 | case rFeb28: |
1039 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) | 1071 | if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) |
1040 | match = true; | 1072 | match = true; |
1041 | break; | 1073 | break; |
1042 | case rMar1: | 1074 | case rMar1: |
1043 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { | 1075 | if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { |
1044 | qmonth = 2; | 1076 | qmonth = 2; |
1045 | match = true; | 1077 | match = true; |
1046 | } | 1078 | } |
1047 | break; | 1079 | break; |
1048 | case rFeb29: | 1080 | case rFeb29: |
1049 | break; | 1081 | break; |
1050 | } | 1082 | } |
1051 | } | 1083 | } |
1052 | 1084 | ||
1053 | if (match) { | 1085 | if (match) { |
1054 | // The day of the month matches. Calculate how many years ahead | 1086 | // The day of the month matches. Calculate how many years ahead |
1055 | // this date is from the original event's date. | 1087 | // this date is from the original event's date. |
1056 | int yearsAhead = (qyear - dStart.year()); | 1088 | int yearsAhead = (qyear - dStart.year()); |
1057 | if (yearsAhead % rFreq == 0) { | 1089 | if (yearsAhead % rFreq == 0) { |
1058 | // The date is in a year which recurs | 1090 | // The date is in a year which recurs |
1059 | if (qd >= dStart | 1091 | if (qd >= dStart |
1060 | && ((rDuration > 0 && qd <= endDate()) || | 1092 | && ((rDuration > 0 && qd <= endDate()) || |
1061 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1093 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1062 | rDuration == -1)) { | 1094 | rDuration == -1)) { |
1063 | // The date queried falls within the range of the event. | 1095 | // The date queried falls within the range of the event. |
1064 | int i = qmonth; | 1096 | int i = qmonth; |
1065 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1097 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1066 | if (i == *qlin.current()) | 1098 | if (i == *qlin.current()) |
1067 | return true; | 1099 | return true; |
1068 | } | 1100 | } |
1069 | } | 1101 | } |
1070 | } | 1102 | } |
1071 | } | 1103 | } |
1072 | return false; | 1104 | return false; |
1073 | } | 1105 | } |
1074 | 1106 | ||
1075 | bool Recurrence::recursYearlyByPos(const QDate &qd) const | 1107 | bool Recurrence::recursYearlyByPos(const QDate &qd) const |
1076 | { | 1108 | { |
1077 | QDate dStart = mRecurStart.date(); | 1109 | QDate dStart = mRecurStart.date(); |
1078 | int year = qd.year(); | 1110 | int year = qd.year(); |
1079 | int month = qd.month(); | 1111 | int month = qd.month(); |
1080 | int day = qd.day(); | 1112 | int day = qd.day(); |
1081 | // calculate how many years ahead this date is from the original | 1113 | // calculate how many years ahead this date is from the original |
1082 | // event's date | 1114 | // event's date |
1083 | int yearsAhead = (year - dStart.year()); | 1115 | int yearsAhead = (year - dStart.year()); |
1084 | if (yearsAhead % rFreq == 0) { | 1116 | if (yearsAhead % rFreq == 0) { |
1085 | // The date is in a year which recurs | 1117 | // The date is in a year which recurs |
1086 | if (qd >= dStart | 1118 | if (qd >= dStart |
1087 | && ((rDuration > 0 && qd <= endDate()) || | 1119 | && ((rDuration > 0 && qd <= endDate()) || |
1088 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1120 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1089 | rDuration == -1)) { | 1121 | rDuration == -1)) { |
1090 | // The date queried falls within the range of the event. | 1122 | // The date queried falls within the range of the event. |
1091 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1123 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1092 | if (month == *qlin.current()) { | 1124 | if (month == *qlin.current()) { |
1093 | // The month recurs | 1125 | // The month recurs |
1094 | QValueList<int> days; | 1126 | QValueList<int> days; |
1095 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); | 1127 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); |
1096 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1128 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1097 | if (*it == day) | 1129 | if (*it == day) |
1098 | return true; | 1130 | return true; |
1099 | } | 1131 | } |
1100 | } | 1132 | } |
1101 | } | 1133 | } |
1102 | } | 1134 | } |
1103 | } | 1135 | } |
1104 | return false; | 1136 | return false; |
1105 | } | 1137 | } |
1106 | 1138 | ||
1107 | bool Recurrence::recursYearlyByDay(const QDate &qd) const | 1139 | bool Recurrence::recursYearlyByDay(const QDate &qd) const |
1108 | { | 1140 | { |
1109 | QDate dStart = mRecurStart.date(); | 1141 | QDate dStart = mRecurStart.date(); |
1110 | // calculate how many years ahead this date is from the original | 1142 | // calculate how many years ahead this date is from the original |
1111 | // event's date | 1143 | // event's date |
1112 | int yearsAhead = (qd.year() - dStart.year()); | 1144 | int yearsAhead = (qd.year() - dStart.year()); |
1113 | if (yearsAhead % rFreq == 0) { | 1145 | if (yearsAhead % rFreq == 0) { |
1114 | // The date is in a year which recurs | 1146 | // The date is in a year which recurs |
1115 | if (qd >= dStart | 1147 | if (qd >= dStart |
1116 | && ((rDuration > 0 && qd <= endDate()) || | 1148 | && ((rDuration > 0 && qd <= endDate()) || |
1117 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1149 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1118 | rDuration == -1)) { | 1150 | rDuration == -1)) { |
1119 | // The date queried falls within the range of the event. | 1151 | // The date queried falls within the range of the event. |
1120 | int i = qd.dayOfYear(); | 1152 | int i = qd.dayOfYear(); |
1121 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1153 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1122 | if (i == *qlin.current()) | 1154 | if (i == *qlin.current()) |
1123 | return true; | 1155 | return true; |
1124 | } | 1156 | } |
1125 | } | 1157 | } |
1126 | } | 1158 | } |
1127 | return false; | 1159 | return false; |
1128 | } | 1160 | } |
1129 | 1161 | ||
1130 | /* Get the date of the next recurrence, after the specified date. | 1162 | /* Get the date of the next recurrence, after the specified date. |
1131 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the | 1163 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the |
1132 | * last recurrence, else false. | 1164 | * last recurrence, else false. |
1133 | * Reply = date of next recurrence, or invalid date if none. | 1165 | * Reply = date of next recurrence, or invalid date if none. |
1134 | */ | 1166 | */ |
1135 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | 1167 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const |
1136 | { | 1168 | { |
1137 | if (last) | 1169 | if (last) |
1138 | *last = false; | 1170 | *last = false; |
1139 | QDate dStart = mRecurStart.date(); | 1171 | QDate dStart = mRecurStart.date(); |
1140 | if (preDate < dStart) | 1172 | if (preDate < dStart) |
1141 | return dStart; | 1173 | return dStart; |
1142 | QDate earliestDate = preDate.addDays(1); | 1174 | QDate earliestDate = preDate.addDays(1); |
1143 | QDate nextDate; | 1175 | QDate nextDate; |
1144 | 1176 | ||
1145 | switch (recurs) { | 1177 | switch (recurs) { |
1146 | case rDaily: | 1178 | case rDaily: |
1147 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); | 1179 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); |
1148 | break; | 1180 | break; |
1149 | 1181 | ||
1150 | case rWeekly: { | 1182 | case rWeekly: { |
1151 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1183 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart |
1152 | int earliestDayOfWeek = earliestDate.dayOfWeek(); | 1184 | int earliestDayOfWeek = earliestDate.dayOfWeek(); |
1153 | int weeksAhead = start.daysTo(earliestDate) / 7; | 1185 | int weeksAhead = start.daysTo(earliestDate) / 7; |
1154 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1186 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1155 | weeksAhead -= notThisWeek; // latest week which recurred | 1187 | weeksAhead -= notThisWeek; // latest week which recurred |
1156 | int weekday = 0; | 1188 | int weekday = 0; |
1157 | // First check for any remaining day this week, if this week is a recurring week | 1189 | // First check for any remaining day this week, if this week is a recurring week |
1158 | if (!notThisWeek) | 1190 | if (!notThisWeek) |
1159 | weekday = getFirstDayInWeek(earliestDayOfWeek); | 1191 | weekday = getFirstDayInWeek(earliestDayOfWeek); |
1160 | // Check for a day in the next scheduled week | 1192 | // Check for a day in the next scheduled week |
1161 | if (!weekday && earliestDayOfWeek > 1) | 1193 | if (!weekday && earliestDayOfWeek > 1) |
1162 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; | 1194 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; |
1163 | if (weekday) | 1195 | if (weekday) |
1164 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); | 1196 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); |
1165 | break; | 1197 | break; |
1166 | } | 1198 | } |
1167 | case rMonthlyDay: | 1199 | case rMonthlyDay: |
1168 | case rMonthlyPos: { | 1200 | case rMonthlyPos: { |
1169 | int startYear = dStart.year(); | 1201 | int startYear = dStart.year(); |
1170 | int startMonth = dStart.month(); // 1..12 | 1202 | int startMonth = dStart.month(); // 1..12 |
1171 | int earliestYear = earliestDate.year(); | 1203 | int earliestYear = earliestDate.year(); |
1172 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; | 1204 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; |
1173 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1205 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1174 | monthsAhead -= notThisMonth; // latest month which recurred | 1206 | monthsAhead -= notThisMonth; // latest month which recurred |
1175 | // Check for the first later day in the current month | 1207 | // Check for the first later day in the current month |
1176 | if (!notThisMonth) | 1208 | if (!notThisMonth) |
1177 | nextDate = getFirstDateInMonth(earliestDate); | 1209 | nextDate = getFirstDateInMonth(earliestDate); |
1178 | if (!nextDate.isValid() && earliestDate.day() > 1) { | 1210 | if (!nextDate.isValid() && earliestDate.day() > 1) { |
1179 | // Check for a day in the next scheduled month | 1211 | // Check for a day in the next scheduled month |
1180 | int months = startMonth - 1 + monthsAhead + rFreq; | 1212 | int months = startMonth - 1 + monthsAhead + rFreq; |
1181 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); | 1213 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); |
1182 | } | 1214 | } |
1183 | break; | 1215 | break; |
1184 | } | 1216 | } |
1185 | case rYearlyMonth: | 1217 | case rYearlyMonth: |
1186 | case rYearlyPos: | 1218 | case rYearlyPos: |
1187 | case rYearlyDay: { | 1219 | case rYearlyDay: { |
1188 | int startYear = dStart.year(); | 1220 | int startYear = dStart.year(); |
1189 | int yearsAhead = earliestDate.year() - startYear; | 1221 | int yearsAhead = earliestDate.year() - startYear; |
1190 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1222 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1191 | yearsAhead -= notThisYear; // latest year which recurred | 1223 | yearsAhead -= notThisYear; // latest year which recurred |
1192 | // Check for the first later date in the current year | 1224 | // Check for the first later date in the current year |
1193 | if (!notThisYear) | 1225 | if (!notThisYear) |
1194 | nextDate = getFirstDateInYear(earliestDate); | 1226 | nextDate = getFirstDateInYear(earliestDate); |
1195 | // Check for a date in the next scheduled year | 1227 | // Check for a date in the next scheduled year |
1196 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) | 1228 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) |
1197 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); | 1229 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); |
1198 | break; | 1230 | break; |
1199 | } | 1231 | } |
1200 | case rNone: | 1232 | case rNone: |
1201 | default: | 1233 | default: |
1202 | return QDate(); | 1234 | return QDate(); |
1203 | } | 1235 | } |
1204 | 1236 | ||
1205 | if (rDuration >= 0 && nextDate.isValid()) { | 1237 | if (rDuration >= 0 && nextDate.isValid()) { |
1206 | // Check that the date found is within the range of the recurrence | 1238 | // Check that the date found is within the range of the recurrence |
1207 | QDate end = endDate(); | 1239 | QDate end = endDate(); |
1208 | if (nextDate > end) | 1240 | if (nextDate > end) |
1209 | return QDate(); | 1241 | return QDate(); |
1210 | if (last && nextDate == end) | 1242 | if (last && nextDate == end) |
1211 | *last = true; | 1243 | *last = true; |
1212 | } | 1244 | } |
1213 | return nextDate; | 1245 | return nextDate; |
1214 | } | 1246 | } |
1215 | 1247 | ||
1216 | /* Get the date of the last previous recurrence, before the specified date. | 1248 | /* Get the date of the last previous recurrence, before the specified date. |
1217 | * Reply = date of previous recurrence, or invalid date if none. | 1249 | * Reply = date of previous recurrence, or invalid date if none. |
1218 | */ | 1250 | */ |
1219 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const | 1251 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const |
1220 | { | 1252 | { |
1221 | if (last) | 1253 | if (last) |
1222 | *last = false; | 1254 | *last = false; |
1223 | QDate dStart = mRecurStart.date(); | 1255 | QDate dStart = mRecurStart.date(); |
1224 | QDate latestDate = afterDate.addDays(-1); | 1256 | QDate latestDate = afterDate.addDays(-1); |
1225 | if (latestDate < dStart) | 1257 | if (latestDate < dStart) |
1226 | return QDate(); | 1258 | return QDate(); |
1227 | QDate prevDate; | 1259 | QDate prevDate; |
1228 | 1260 | ||
1229 | switch (recurs) { | 1261 | switch (recurs) { |
1230 | case rDaily: | 1262 | case rDaily: |
1231 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); | 1263 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); |
1232 | break; | 1264 | break; |
1233 | 1265 | ||
1234 | case rWeekly: { | 1266 | case rWeekly: { |
1235 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1267 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart |
1236 | int latestDayOfWeek = latestDate.dayOfWeek(); | 1268 | int latestDayOfWeek = latestDate.dayOfWeek(); |
1237 | int weeksAhead = start.daysTo(latestDate) / 7; | 1269 | int weeksAhead = start.daysTo(latestDate) / 7; |
1238 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1270 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1239 | weeksAhead -= notThisWeek; // latest week which recurred | 1271 | weeksAhead -= notThisWeek; // latest week which recurred |
1240 | int weekday = 0; | 1272 | int weekday = 0; |
1241 | // First check for any previous day this week, if this week is a recurring week | 1273 | // First check for any previous day this week, if this week is a recurring week |
1242 | if (!notThisWeek) | 1274 | if (!notThisWeek) |
1243 | weekday = getLastDayInWeek(latestDayOfWeek); | 1275 | weekday = getLastDayInWeek(latestDayOfWeek); |
1244 | // Check for a day in the previous scheduled week | 1276 | // Check for a day in the previous scheduled week |
1245 | if (!weekday) { | 1277 | if (!weekday) { |
1246 | int weekEnd = (rWeekStart + 5)%7 + 1; | 1278 | int weekEnd = (rWeekStart + 5)%7 + 1; |
1247 | if (latestDayOfWeek < weekEnd) { | 1279 | if (latestDayOfWeek < weekEnd) { |
1248 | if (!notThisWeek) | 1280 | if (!notThisWeek) |
1249 | weeksAhead -= rFreq; | 1281 | weeksAhead -= rFreq; |
1250 | weekday = getLastDayInWeek(weekEnd); | 1282 | weekday = getLastDayInWeek(weekEnd); |
1251 | } | 1283 | } |
1252 | } | 1284 | } |
1253 | if (weekday) | 1285 | if (weekday) |
1254 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); | 1286 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); |
1255 | break; | 1287 | break; |
1256 | } | 1288 | } |
1257 | case rMonthlyDay: | 1289 | case rMonthlyDay: |
1258 | case rMonthlyPos: { | 1290 | case rMonthlyPos: { |
1259 | int startYear = dStart.year(); | 1291 | int startYear = dStart.year(); |
1260 | int startMonth = dStart.month(); // 1..12 | 1292 | int startMonth = dStart.month(); // 1..12 |
1261 | int latestYear = latestDate.year(); | 1293 | int latestYear = latestDate.year(); |
1262 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; | 1294 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; |
1263 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1295 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1264 | monthsAhead -= notThisMonth; // latest month which recurred | 1296 | monthsAhead -= notThisMonth; // latest month which recurred |
1265 | // Check for the last earlier day in the current month | 1297 | // Check for the last earlier day in the current month |
1266 | if (!notThisMonth) | 1298 | if (!notThisMonth) |
1267 | prevDate = getLastDateInMonth(latestDate); | 1299 | prevDate = getLastDateInMonth(latestDate); |
1268 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { | 1300 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { |
1269 | // Check for a day in the previous scheduled month | 1301 | // Check for a day in the previous scheduled month |
1270 | if (!notThisMonth) | 1302 | if (!notThisMonth) |
1271 | monthsAhead -= rFreq; | 1303 | monthsAhead -= rFreq; |
1272 | int months = startMonth + monthsAhead; // get the month after the one that recurs | 1304 | int months = startMonth + monthsAhead; // get the month after the one that recurs |
1273 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); | 1305 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); |
1274 | } | 1306 | } |
1275 | break; | 1307 | break; |
1276 | } | 1308 | } |
1277 | case rYearlyMonth: | 1309 | case rYearlyMonth: |
1278 | case rYearlyPos: | 1310 | case rYearlyPos: |
1279 | case rYearlyDay: { | 1311 | case rYearlyDay: { |
1280 | int startYear = dStart.year(); | 1312 | int startYear = dStart.year(); |
1281 | int yearsAhead = latestDate.year() - startYear; | 1313 | int yearsAhead = latestDate.year() - startYear; |
1282 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1314 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1283 | yearsAhead -= notThisYear; // latest year which recurred | 1315 | yearsAhead -= notThisYear; // latest year which recurred |
1284 | // Check for the first later date in the current year | 1316 | // Check for the first later date in the current year |
1285 | if (!notThisYear) | 1317 | if (!notThisYear) |
1286 | prevDate = getLastDateInYear(latestDate); | 1318 | prevDate = getLastDateInYear(latestDate); |
1287 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { | 1319 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { |
1288 | // Check for a date in the next scheduled year | 1320 | // Check for a date in the next scheduled year |
1289 | if (!notThisYear) | 1321 | if (!notThisYear) |
1290 | yearsAhead -= rFreq; | 1322 | yearsAhead -= rFreq; |
1291 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); | 1323 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); |
1292 | } | 1324 | } |
1293 | break; | 1325 | break; |
1294 | } | 1326 | } |
1295 | case rNone: | 1327 | case rNone: |
1296 | default: | 1328 | default: |
1297 | return QDate(); | 1329 | return QDate(); |
1298 | } | 1330 | } |
1299 | 1331 | ||
1300 | if (prevDate.isValid()) { | 1332 | if (prevDate.isValid()) { |
1301 | // Check that the date found is within the range of the recurrence | 1333 | // Check that the date found is within the range of the recurrence |
1302 | if (prevDate < dStart) | 1334 | if (prevDate < dStart) |
1303 | return QDate(); | 1335 | return QDate(); |
1304 | if (rDuration >= 0) { | 1336 | if (rDuration >= 0) { |
1305 | QDate end = endDate(); | 1337 | QDate end = endDate(); |
1306 | if (prevDate >= end) { | 1338 | if (prevDate >= end) { |
1307 | if (last) | 1339 | if (last) |
1308 | *last = true; | 1340 | *last = true; |
1309 | return end; | 1341 | return end; |
1310 | } | 1342 | } |
1311 | } | 1343 | } |
1312 | } | 1344 | } |
1313 | return prevDate; | 1345 | return prevDate; |
1314 | } | 1346 | } |
1315 | 1347 | ||
1316 | void Recurrence::setDailySub(short type, int freq, int duration) | 1348 | void Recurrence::setDailySub(short type, int freq, int duration) |
1317 | { | 1349 | { |
1318 | recurs = type; | 1350 | recurs = type; |
1319 | rFreq = freq; | 1351 | rFreq = freq; |
1320 | rDuration = duration; | 1352 | rDuration = duration; |
1321 | rMonthPositions.clear(); | 1353 | rMonthPositions.clear(); |
1322 | rMonthDays.clear(); | 1354 | rMonthDays.clear(); |
1323 | rYearNums.clear(); | 1355 | rYearNums.clear(); |
1324 | if (type != rDaily) | 1356 | if (type != rDaily) |
1325 | mFloats = false; // sub-daily types can't be floating | 1357 | mFloats = false; // sub-daily types can't be floating |
1326 | 1358 | ||
1327 | if (mParent) mParent->updated(); | 1359 | if (mParent) mParent->updated(); |
1328 | } | 1360 | } |
1329 | 1361 | ||
1330 | void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration) | 1362 | void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration) |
1331 | { | 1363 | { |
1332 | recurs = type; | 1364 | recurs = type; |
1333 | if (mCompatVersion < 310 && type == rYearlyDay) { | 1365 | if (mCompatVersion < 310 && type == rYearlyDay) { |
1334 | mCompatRecurs = rYearlyDay; | 1366 | mCompatRecurs = rYearlyDay; |
1335 | recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month | 1367 | recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month |
1336 | feb29type = rMar1; // retain the same day number in the year | 1368 | feb29type = rMar1; // retain the same day number in the year |
1337 | } | 1369 | } |
1338 | 1370 | ||
1339 | mFeb29YearlyType = feb29type; | 1371 | mFeb29YearlyType = feb29type; |
1340 | rFreq = freq; | 1372 | rFreq = freq; |
1341 | rDuration = duration; | 1373 | rDuration = duration; |
1342 | if (type != rYearlyPos) | 1374 | if (type != rYearlyPos) |
1343 | rMonthPositions.clear(); | 1375 | rMonthPositions.clear(); |
1344 | rMonthDays.clear(); | 1376 | rMonthDays.clear(); |
1345 | if (mParent) mParent->updated(); | 1377 | if (mParent) mParent->updated(); |
1346 | } | 1378 | } |
1347 | 1379 | ||
1348 | int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const | 1380 | int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const |
1349 | { | 1381 | { |
1350 | QDate enddate = endtime.date(); | 1382 | QDate enddate = endtime.date(); |
1351 | switch (func) { | 1383 | switch (func) { |
1352 | case END_DATE_AND_COUNT: | 1384 | case END_DATE_AND_COUNT: |
1353 | if (rDuration < 0) { | 1385 | if (rDuration < 0) { |
1354 | endtime = QDateTime(); | 1386 | endtime = QDateTime(); |
1355 | return 0; // infinite recurrence | 1387 | return 0; // infinite recurrence |
1356 | } | 1388 | } |
1357 | if (rDuration == 0) { | 1389 | if (rDuration == 0) { |
1358 | endtime = rEndDateTime; | 1390 | endtime = rEndDateTime; |
1359 | func = COUNT_TO_DATE; | 1391 | func = COUNT_TO_DATE; |
1360 | } | 1392 | } |
1361 | break; | 1393 | break; |
1362 | case COUNT_TO_DATE: | 1394 | case COUNT_TO_DATE: |
1363 | // Count recurrences up to and including the specified date/time. | 1395 | // Count recurrences up to and including the specified date/time. |
1364 | if (endtime < mRecurStart) | 1396 | if (endtime < mRecurStart) |
1365 | return 0; | 1397 | return 0; |
1366 | if (rDuration == 0 && endtime > rEndDateTime) | 1398 | if (rDuration == 0 && endtime > rEndDateTime) |
1367 | enddate = rEndDateTime.date(); | 1399 | enddate = rEndDateTime.date(); |
1368 | else if (!mFloats && mRecurStart.time() > endtime.time()) | 1400 | else if (!mFloats && mRecurStart.time() > endtime.time()) |
1369 | enddate = enddate.addDays(-1); | 1401 | enddate = enddate.addDays(-1); |
1370 | break; | 1402 | break; |
1371 | case NEXT_AFTER_DATE: | 1403 | case NEXT_AFTER_DATE: |
1372 | // Find next recurrence AFTER endtime | 1404 | // Find next recurrence AFTER endtime |
1373 | if (endtime < mRecurStart) { | 1405 | if (endtime < mRecurStart) { |
1374 | endtime = mRecurStart; | 1406 | endtime = mRecurStart; |
1375 | return 1; | 1407 | return 1; |
1376 | } | 1408 | } |
1377 | if (rDuration == 0 && endtime >= rEndDateTime) { | 1409 | if (rDuration == 0 && endtime >= rEndDateTime) { |
1378 | endtime = QDateTime(); | 1410 | endtime = QDateTime(); |
1379 | return 0; | 1411 | return 0; |
1380 | } | 1412 | } |
1381 | if (!mFloats && mRecurStart.time() > endtime.time()) | 1413 | if (!mFloats && mRecurStart.time() > endtime.time()) |
1382 | enddate = enddate.addDays(-1); | 1414 | enddate = enddate.addDays(-1); |
1383 | break; | 1415 | break; |
1384 | default: | 1416 | default: |
1385 | endtime = QDateTime(); | 1417 | endtime = QDateTime(); |
1386 | return 0; | 1418 | return 0; |
1387 | } | 1419 | } |
1388 | 1420 | ||
1389 | int count = 0; // default = error | 1421 | int count = 0; // default = error |
1390 | bool timed = false; | 1422 | bool timed = false; |
1391 | switch (recurs) { | 1423 | switch (recurs) { |
1392 | case rMinutely: | 1424 | case rMinutely: |
1393 | timed = true; | 1425 | timed = true; |
1394 | count = secondlyCalc(func, endtime, rFreq*60); | 1426 | count = secondlyCalc(func, endtime, rFreq*60); |
1395 | break; | 1427 | break; |
1396 | case rHourly: | 1428 | case rHourly: |
1397 | timed = true; | 1429 | timed = true; |
1398 | count = secondlyCalc(func, endtime, rFreq*3600); | 1430 | count = secondlyCalc(func, endtime, rFreq*3600); |
1399 | break; | 1431 | break; |
1400 | case rDaily: | 1432 | case rDaily: |
1401 | count = dailyCalc(func, enddate); | 1433 | count = dailyCalc(func, enddate); |
1402 | break; | 1434 | break; |
1403 | case rWeekly: | 1435 | case rWeekly: |
1404 | count = weeklyCalc(func, enddate); | 1436 | count = weeklyCalc(func, enddate); |
1405 | break; | 1437 | break; |
1406 | case rMonthlyPos: | 1438 | case rMonthlyPos: |
1407 | case rMonthlyDay: | 1439 | case rMonthlyDay: |
1408 | count = monthlyCalc(func, enddate); | 1440 | count = monthlyCalc(func, enddate); |
1409 | break; | 1441 | break; |
1410 | case rYearlyMonth: | 1442 | case rYearlyMonth: |
1411 | count = yearlyMonthCalc(func, enddate); | 1443 | count = yearlyMonthCalc(func, enddate); |
1412 | break; | 1444 | break; |
1413 | case rYearlyPos: | 1445 | case rYearlyPos: |
1414 | count = yearlyPosCalc(func, enddate); | 1446 | count = yearlyPosCalc(func, enddate); |
1415 | break; | 1447 | break; |
1416 | case rYearlyDay: | 1448 | case rYearlyDay: |
1417 | count = yearlyDayCalc(func, enddate); | 1449 | count = yearlyDayCalc(func, enddate); |
1418 | break; | 1450 | break; |
1419 | default: | 1451 | default: |
1420 | break; | 1452 | break; |
1421 | } | 1453 | } |
1422 | 1454 | ||
1423 | switch (func) { | 1455 | switch (func) { |
1424 | case END_DATE_AND_COUNT: | 1456 | case END_DATE_AND_COUNT: |
1425 | case NEXT_AFTER_DATE: | 1457 | case NEXT_AFTER_DATE: |
1426 | if (count == 0) | 1458 | if (count == 0) |
1427 | endtime = QDateTime(); | 1459 | endtime = QDateTime(); |
1428 | else if (!timed) { | 1460 | else if (!timed) { |
1429 | endtime.setDate(enddate); | 1461 | endtime.setDate(enddate); |
1430 | endtime.setTime(mRecurStart.time()); | 1462 | endtime.setTime(mRecurStart.time()); |
1431 | } | 1463 | } |
1432 | break; | 1464 | break; |
1433 | case COUNT_TO_DATE: | 1465 | case COUNT_TO_DATE: |
1434 | break; | 1466 | break; |
1435 | } | 1467 | } |
1436 | return count; | 1468 | return count; |
1437 | } | 1469 | } |
1438 | 1470 | ||
1439 | int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const | 1471 | int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const |
1440 | { | 1472 | { |
1441 | QDateTime endtime(enddate, QTime(23,59,59)); | 1473 | QDateTime endtime(enddate, QTime(23,59,59)); |
1442 | switch (func) { | 1474 | switch (func) { |
1443 | case END_DATE_AND_COUNT: | 1475 | case END_DATE_AND_COUNT: |
1444 | if (rDuration < 0) { | 1476 | if (rDuration < 0) { |
1445 | enddate = QDate(); | 1477 | enddate = QDate(); |
1446 | return 0; // infinite recurrence | 1478 | return 0; // infinite recurrence |
1447 | } | 1479 | } |
1448 | if (rDuration == 0) { | 1480 | if (rDuration == 0) { |
1449 | enddate = rEndDateTime.date(); | 1481 | enddate = rEndDateTime.date(); |
1450 | func = COUNT_TO_DATE; | 1482 | func = COUNT_TO_DATE; |
1451 | } | 1483 | } |
1452 | break; | 1484 | break; |
1453 | case COUNT_TO_DATE: | 1485 | case COUNT_TO_DATE: |
1454 | // Count recurrences up to and including the specified date. | 1486 | // Count recurrences up to and including the specified date. |
1455 | if (enddate < mRecurStart.date()) | 1487 | if (enddate < mRecurStart.date()) |
1456 | return 0; | 1488 | return 0; |
1457 | if (rDuration == 0 && enddate > rEndDateTime.date()) { | 1489 | if (rDuration == 0 && enddate > rEndDateTime.date()) { |
1458 | enddate = rEndDateTime.date(); | 1490 | enddate = rEndDateTime.date(); |
1459 | endtime.setDate(enddate); | 1491 | endtime.setDate(enddate); |
1460 | } | 1492 | } |
1461 | break; | 1493 | break; |
1462 | case NEXT_AFTER_DATE: | 1494 | case NEXT_AFTER_DATE: |
1463 | if (enddate < mRecurStart.date()) { | 1495 | if (enddate < mRecurStart.date()) { |
1464 | enddate = mRecurStart.date(); | 1496 | enddate = mRecurStart.date(); |
1465 | return 1; | 1497 | return 1; |
1466 | } | 1498 | } |
1467 | if (rDuration == 0 && enddate >= rEndDateTime.date()) { | 1499 | if (rDuration == 0 && enddate >= rEndDateTime.date()) { |
1468 | enddate = QDate(); | 1500 | enddate = QDate(); |
1469 | return 0; | 1501 | return 0; |
1470 | } | 1502 | } |
1471 | break; | 1503 | break; |
1472 | default: | 1504 | default: |
1473 | enddate = QDate(); | 1505 | enddate = QDate(); |
1474 | return 0; | 1506 | return 0; |
1475 | } | 1507 | } |
1476 | 1508 | ||
1477 | int count = 0; // default = error | 1509 | int count = 0; // default = error |
1478 | bool timed = false; | 1510 | bool timed = false; |
1479 | switch (recurs) { | 1511 | switch (recurs) { |
1480 | case rMinutely: | 1512 | case rMinutely: |
1481 | timed = true; | 1513 | timed = true; |
1482 | count = secondlyCalc(func, endtime, rFreq*60); | 1514 | count = secondlyCalc(func, endtime, rFreq*60); |
1483 | break; | 1515 | break; |
1484 | case rHourly: | 1516 | case rHourly: |
1485 | timed = true; | 1517 | timed = true; |
1486 | count = secondlyCalc(func, endtime, rFreq*3600); | 1518 | count = secondlyCalc(func, endtime, rFreq*3600); |
1487 | break; | 1519 | break; |
1488 | case rDaily: | 1520 | case rDaily: |
1489 | count = dailyCalc(func, enddate); | 1521 | count = dailyCalc(func, enddate); |
1490 | break; | 1522 | break; |
1491 | case rWeekly: | 1523 | case rWeekly: |
1492 | count = weeklyCalc(func, enddate); | 1524 | count = weeklyCalc(func, enddate); |
1493 | break; | 1525 | break; |
1494 | case rMonthlyPos: | 1526 | case rMonthlyPos: |
1495 | case rMonthlyDay: | 1527 | case rMonthlyDay: |
1496 | count = monthlyCalc(func, enddate); | 1528 | count = monthlyCalc(func, enddate); |
1497 | break; | 1529 | break; |
1498 | case rYearlyMonth: | 1530 | case rYearlyMonth: |
1499 | count = yearlyMonthCalc(func, enddate); | 1531 | count = yearlyMonthCalc(func, enddate); |
1500 | break; | 1532 | break; |
1501 | case rYearlyPos: | 1533 | case rYearlyPos: |
1502 | count = yearlyPosCalc(func, enddate); | 1534 | count = yearlyPosCalc(func, enddate); |
1503 | break; | 1535 | break; |
1504 | case rYearlyDay: | 1536 | case rYearlyDay: |
1505 | count = yearlyDayCalc(func, enddate); | 1537 | count = yearlyDayCalc(func, enddate); |
1506 | break; | 1538 | break; |
1507 | default: | 1539 | default: |
1508 | break; | 1540 | break; |
1509 | } | 1541 | } |
1510 | 1542 | ||
1511 | switch (func) { | 1543 | switch (func) { |
1512 | case END_DATE_AND_COUNT: | 1544 | case END_DATE_AND_COUNT: |
1513 | case NEXT_AFTER_DATE: | 1545 | case NEXT_AFTER_DATE: |
1514 | if (count == 0) | 1546 | if (count == 0) |
1515 | endtime = QDate(); | 1547 | endtime = QDate(); |
1516 | else if (timed) | 1548 | else if (timed) |
1517 | enddate = endtime.date(); | 1549 | enddate = endtime.date(); |
1518 | break; | 1550 | break; |
1519 | case COUNT_TO_DATE: | 1551 | case COUNT_TO_DATE: |
1520 | break; | 1552 | break; |
1521 | } | 1553 | } |
1522 | return count; | 1554 | return count; |
1523 | } | 1555 | } |
1524 | 1556 | ||
1525 | /* Find count and, depending on 'func', the end date/time of a secondly recurrence. | 1557 | /* Find count and, depending on 'func', the end date/time of a secondly recurrence. |
1526 | * Reply = total number of occurrences up to 'endtime', or 0 if error. | 1558 | * Reply = total number of occurrences up to 'endtime', or 0 if error. |
1527 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the | 1559 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the |
1528 | * recurrence end date/time. | 1560 | * recurrence end date/time. |
1529 | */ | 1561 | */ |
1530 | int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const | 1562 | int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const |
1531 | { | 1563 | { |
1532 | switch (func) { | 1564 | switch (func) { |
1533 | case END_DATE_AND_COUNT: | 1565 | case END_DATE_AND_COUNT: |
1534 | endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq); | 1566 | endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq); |
1535 | return rDuration + mRecurExDatesCount; | 1567 | return rDuration + mRecurExDatesCount; |
1536 | case COUNT_TO_DATE: { | 1568 | case COUNT_TO_DATE: { |
1537 | int n = mRecurStart.secsTo(endtime)/freq + 1; | 1569 | int n = mRecurStart.secsTo(endtime)/freq + 1; |
1538 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) | 1570 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) |
1539 | return rDuration + mRecurExDatesCount; | 1571 | return rDuration + mRecurExDatesCount; |
1540 | return n; | 1572 | return n; |
1541 | } | 1573 | } |
1542 | case NEXT_AFTER_DATE: { | 1574 | case NEXT_AFTER_DATE: { |
1543 | int count = mRecurStart.secsTo(endtime) / freq + 2; | 1575 | int count = mRecurStart.secsTo(endtime) / freq + 2; |
1544 | if (rDuration > 0 && count > rDuration) | 1576 | if (rDuration > 0 && count > rDuration) |
1545 | return 0; | 1577 | return 0; |
1546 | endtime = mRecurStart.addSecs((count - 1)*freq); | 1578 | endtime = mRecurStart.addSecs((count - 1)*freq); |
1547 | return count; | 1579 | return count; |
1548 | } | 1580 | } |
1549 | } | 1581 | } |
1550 | return 0; | 1582 | return 0; |
1551 | } | 1583 | } |
1552 | 1584 | ||
1553 | /* Find count and, depending on 'func', the end date of a daily recurrence. | 1585 | /* Find count and, depending on 'func', the end date of a daily recurrence. |
1554 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1586 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1555 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1587 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1556 | * recurrence end date. | 1588 | * recurrence end date. |
1557 | */ | 1589 | */ |
1558 | int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const | 1590 | int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const |
1559 | { | 1591 | { |
1560 | QDate dStart = mRecurStart.date(); | 1592 | QDate dStart = mRecurStart.date(); |
1561 | switch (func) { | 1593 | switch (func) { |
1562 | case END_DATE_AND_COUNT: | 1594 | case END_DATE_AND_COUNT: |
1563 | enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq); | 1595 | enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq); |
1564 | return rDuration + mRecurExDatesCount; | 1596 | return rDuration + mRecurExDatesCount; |
1565 | case COUNT_TO_DATE: { | 1597 | case COUNT_TO_DATE: { |
1566 | int n = dStart.daysTo(enddate)/rFreq + 1; | 1598 | int n = dStart.daysTo(enddate)/rFreq + 1; |
1567 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) | 1599 | if (rDuration > 0 && n > rDuration + mRecurExDatesCount) |
1568 | return rDuration + mRecurExDatesCount; | 1600 | return rDuration + mRecurExDatesCount; |
1569 | return n; | 1601 | return n; |
1570 | } | 1602 | } |
1571 | case NEXT_AFTER_DATE: { | 1603 | case NEXT_AFTER_DATE: { |
1572 | int count = dStart.daysTo(enddate) / rFreq + 2; | 1604 | int count = dStart.daysTo(enddate) / rFreq + 2; |
1573 | if (rDuration > 0 && count > rDuration) | 1605 | if (rDuration > 0 && count > rDuration) |
1574 | return 0; | 1606 | return 0; |
1575 | enddate = dStart.addDays((count - 1)*rFreq); | 1607 | enddate = dStart.addDays((count - 1)*rFreq); |
1576 | return count; | 1608 | return count; |
1577 | } | 1609 | } |
1578 | } | 1610 | } |
1579 | return 0; | 1611 | return 0; |
1580 | } | 1612 | } |
1581 | 1613 | ||
1582 | /* Find count and, depending on 'func', the end date of a weekly recurrence. | 1614 | /* Find count and, depending on 'func', the end date of a weekly recurrence. |
1583 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1615 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1584 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1616 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1585 | * recurrence end date. | 1617 | * recurrence end date. |
1586 | */ | 1618 | */ |
1587 | int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const | 1619 | int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const |
1588 | { | 1620 | { |
1589 | int daysPerWeek = 0; | 1621 | int daysPerWeek = 0; |
1590 | for (int i = 0; i < 7; ++i) { | 1622 | for (int i = 0; i < 7; ++i) { |
1591 | if (rDays.testBit((uint)i)) | 1623 | if (rDays.testBit((uint)i)) |
1592 | ++daysPerWeek; | 1624 | ++daysPerWeek; |
1593 | } | 1625 | } |
1594 | if (!daysPerWeek) | 1626 | if (!daysPerWeek) |
1595 | return 0; // there are no days to recur on | 1627 | return 0; // there are no days to recur on |
1596 | 1628 | ||
1597 | switch (func) { | 1629 | switch (func) { |
1598 | case END_DATE_AND_COUNT: | 1630 | case END_DATE_AND_COUNT: |
1599 | return weeklyCalcEndDate(enddate, daysPerWeek); | 1631 | return weeklyCalcEndDate(enddate, daysPerWeek); |
1600 | case COUNT_TO_DATE: | 1632 | case COUNT_TO_DATE: |
1601 | return weeklyCalcToDate(enddate, daysPerWeek); | 1633 | return weeklyCalcToDate(enddate, daysPerWeek); |
1602 | case NEXT_AFTER_DATE: | 1634 | case NEXT_AFTER_DATE: |
1603 | return weeklyCalcNextAfter(enddate, daysPerWeek); | 1635 | return weeklyCalcNextAfter(enddate, daysPerWeek); |
1604 | } | 1636 | } |
1605 | return 0; | 1637 | return 0; |
1606 | } | 1638 | } |
1607 | 1639 | ||
1608 | int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const | 1640 | int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const |
1609 | { | 1641 | { |
1610 | int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7 | 1642 | int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7 |
1611 | int countGone = 0; | 1643 | int countGone = 0; |
1612 | int daysGone = 0; | 1644 | int daysGone = 0; |
1613 | uint countTogo = rDuration + mRecurExDatesCount; | 1645 | uint countTogo = rDuration + mRecurExDatesCount; |
1614 | if (startDayOfWeek != rWeekStart) { | 1646 | if (startDayOfWeek != rWeekStart) { |
1615 | // Check what remains of the start week | 1647 | // Check what remains of the start week |
1616 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1648 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1617 | ++daysGone; | 1649 | ++daysGone; |
1618 | if (rDays.testBit((uint)i)) { | 1650 | if (rDays.testBit((uint)i)) { |
1619 | ++countGone; | 1651 | ++countGone; |
1620 | if (--countTogo == 0) | 1652 | if (--countTogo == 0) |
1621 | break; | 1653 | break; |
1622 | } | 1654 | } |
1623 | } | 1655 | } |
1624 | daysGone += 7 * (rFreq - 1); | 1656 | daysGone += 7 * (rFreq - 1); |
1625 | } | 1657 | } |
1626 | if (countTogo) { | 1658 | if (countTogo) { |
1627 | // Skip the remaining whole weeks | 1659 | // Skip the remaining whole weeks |
1628 | // Leave at least 1 recurrence remaining, in order to get its date | 1660 | // Leave at least 1 recurrence remaining, in order to get its date |
1629 | int wholeWeeks = (countTogo - 1) / daysPerWeek; | 1661 | int wholeWeeks = (countTogo - 1) / daysPerWeek; |
1630 | daysGone += wholeWeeks * 7 * rFreq; | 1662 | daysGone += wholeWeeks * 7 * rFreq; |
1631 | countGone += wholeWeeks * daysPerWeek; | 1663 | countGone += wholeWeeks * daysPerWeek; |
1632 | countTogo -= wholeWeeks * daysPerWeek; | 1664 | countTogo -= wholeWeeks * daysPerWeek; |
1633 | // Check the last week in the recurrence | 1665 | // Check the last week in the recurrence |
1634 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1666 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1635 | ++daysGone; | 1667 | ++daysGone; |
1636 | if (rDays.testBit((uint)i)) { | 1668 | if (rDays.testBit((uint)i)) { |
1637 | ++countGone; | 1669 | ++countGone; |
1638 | if (--countTogo == 0) | 1670 | if (--countTogo == 0) |
1639 | break; | 1671 | break; |
1640 | } | 1672 | } |
1641 | } | 1673 | } |
1642 | } | 1674 | } |
1643 | enddate = mRecurStart.date().addDays(daysGone); | 1675 | enddate = mRecurStart.date().addDays(daysGone); |
1644 | return countGone; | 1676 | return countGone; |
1645 | } | 1677 | } |
1646 | 1678 | ||
1647 | int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const | 1679 | int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const |
1648 | { | 1680 | { |
1649 | QDate dStart = mRecurStart.date(); | 1681 | QDate dStart = mRecurStart.date(); |
1650 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 | 1682 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 |
1651 | int countGone = 0; | 1683 | int countGone = 0; |
1652 | int daysGone = 0; | 1684 | int daysGone = 0; |
1653 | int totalDays = dStart.daysTo(enddate) + 1; | 1685 | int totalDays = dStart.daysTo(enddate) + 1; |
1654 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 1686 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
1655 | 1687 | ||
1656 | if (startDayOfWeek != rWeekStart) { | 1688 | if (startDayOfWeek != rWeekStart) { |
1657 | // Check what remains of the start week | 1689 | // Check what remains of the start week |
1658 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1690 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1659 | if (rDays.testBit((uint)i)) { | 1691 | if (rDays.testBit((uint)i)) { |
1660 | if (++countGone >= countMax) | 1692 | if (++countGone >= countMax) |
1661 | return countMax; | 1693 | return countMax; |
1662 | } | 1694 | } |
1663 | if (++daysGone == totalDays) | 1695 | if (++daysGone == totalDays) |
1664 | return countGone; | 1696 | return countGone; |
1665 | } | 1697 | } |
1666 | daysGone += 7 * (rFreq - 1); | 1698 | daysGone += 7 * (rFreq - 1); |
1667 | if (daysGone >= totalDays) | 1699 | if (daysGone >= totalDays) |
1668 | return countGone; | 1700 | return countGone; |
1669 | } | 1701 | } |
1670 | // Skip the remaining whole weeks | 1702 | // Skip the remaining whole weeks |
1671 | int wholeWeeks = (totalDays - daysGone) / 7; | 1703 | int wholeWeeks = (totalDays - daysGone) / 7; |
1672 | countGone += (wholeWeeks / rFreq) * daysPerWeek; | 1704 | countGone += (wholeWeeks / rFreq) * daysPerWeek; |
1673 | if (countGone >= countMax) | 1705 | if (countGone >= countMax) |
1674 | return countMax; | 1706 | return countMax; |
1675 | daysGone += wholeWeeks * 7; | 1707 | daysGone += wholeWeeks * 7; |
1676 | if (daysGone >= totalDays // have we reached the end date? | 1708 | if (daysGone >= totalDays // have we reached the end date? |
1677 | || wholeWeeks % rFreq) // is end week a recurrence week? | 1709 | || wholeWeeks % rFreq) // is end week a recurrence week? |
1678 | return countGone; | 1710 | return countGone; |
1679 | 1711 | ||
1680 | // Check the last week in the recurrence | 1712 | // Check the last week in the recurrence |
1681 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1713 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1682 | if (rDays.testBit((uint)i)) { | 1714 | if (rDays.testBit((uint)i)) { |
1683 | if (++countGone >= countMax) | 1715 | if (++countGone >= countMax) |
1684 | return countMax; | 1716 | return countMax; |
1685 | } | 1717 | } |
1686 | if (++daysGone == totalDays) | 1718 | if (++daysGone == totalDays) |
1687 | return countGone; | 1719 | return countGone; |
1688 | } | 1720 | } |
1689 | return countGone; | 1721 | return countGone; |
1690 | } | 1722 | } |
1691 | 1723 | ||
1692 | int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const | 1724 | int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const |
1693 | { | 1725 | { |
1694 | QDate dStart = mRecurStart.date(); | 1726 | QDate dStart = mRecurStart.date(); |
1695 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 | 1727 | int startDayOfWeek = dStart.dayOfWeek(); // 1..7 |
1696 | int totalDays = dStart.daysTo(enddate) + 1; | 1728 | int totalDays = dStart.daysTo(enddate) + 1; |
1697 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 1729 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
1698 | int countGone = 0; | 1730 | int countGone = 0; |
1699 | int daysGone = 0; | 1731 | int daysGone = 0; |
1700 | int recurWeeks; | 1732 | int recurWeeks; |
1701 | 1733 | ||
1702 | if (startDayOfWeek != rWeekStart) { | 1734 | if (startDayOfWeek != rWeekStart) { |
1703 | // Check what remains of the start week | 1735 | // Check what remains of the start week |
1704 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { | 1736 | for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { |
1705 | ++daysGone; | 1737 | ++daysGone; |
1706 | if (rDays.testBit((uint)i)) { | 1738 | if (rDays.testBit((uint)i)) { |
1707 | ++countGone; | 1739 | ++countGone; |
1708 | if (daysGone > totalDays) | 1740 | if (daysGone > totalDays) |
1709 | goto ex; | 1741 | goto ex; |
1710 | if (--countTogo == 0) | 1742 | if (--countTogo == 0) |
1711 | return 0; | 1743 | return 0; |
1712 | } | 1744 | } |
1713 | } | 1745 | } |
1714 | daysGone += 7 * (rFreq - 1); | 1746 | daysGone += 7 * (rFreq - 1); |
1715 | } | 1747 | } |
1716 | 1748 | ||
1717 | // Skip the remaining whole weeks | 1749 | // Skip the remaining whole weeks |
1718 | recurWeeks = (totalDays - daysGone) / (7 * rFreq); | 1750 | recurWeeks = (totalDays - daysGone) / (7 * rFreq); |
1719 | if (recurWeeks) { | 1751 | if (recurWeeks) { |
1720 | int n = recurWeeks * daysPerWeek; | 1752 | int n = recurWeeks * daysPerWeek; |
1721 | if (static_cast<uint>(n) > countTogo) | 1753 | if (static_cast<uint>(n) > countTogo) |
1722 | return 0; // reached end of recurrence | 1754 | return 0; // reached end of recurrence |
1723 | countGone += n; | 1755 | countGone += n; |
1724 | countTogo -= n; | 1756 | countTogo -= n; |
1725 | daysGone += recurWeeks * 7 * rFreq; | 1757 | daysGone += recurWeeks * 7 * rFreq; |
1726 | } | 1758 | } |
1727 | 1759 | ||
1728 | // Check the last week or two in the recurrence | 1760 | // Check the last week or two in the recurrence |
1729 | for ( ; ; ) { | 1761 | for ( ; ; ) { |
1730 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { | 1762 | for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { |
1731 | ++daysGone; | 1763 | ++daysGone; |
1732 | if (rDays.testBit((uint)i)) { | 1764 | if (rDays.testBit((uint)i)) { |
1733 | ++countGone; | 1765 | ++countGone; |
1734 | if (daysGone > totalDays) | 1766 | if (daysGone > totalDays) |
1735 | goto ex; | 1767 | goto ex; |
1736 | if (--countTogo == 0) | 1768 | if (--countTogo == 0) |
1737 | return 0; | 1769 | return 0; |
1738 | } | 1770 | } |
1739 | } | 1771 | } |
1740 | daysGone += 7 * (rFreq - 1); | 1772 | daysGone += 7 * (rFreq - 1); |
1741 | } | 1773 | } |
1742 | ex: | 1774 | ex: |
1743 | enddate = dStart.addDays(daysGone); | 1775 | enddate = dStart.addDays(daysGone); |
1744 | return countGone; | 1776 | return countGone; |
1745 | } | 1777 | } |
1746 | 1778 | ||
1747 | /* Find count and, depending on 'func', the end date of a monthly recurrence. | 1779 | /* Find count and, depending on 'func', the end date of a monthly recurrence. |
1748 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 1780 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
1749 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 1781 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
1750 | * recurrence end date. | 1782 | * recurrence end date. |
1751 | */ | 1783 | */ |
1752 | struct Recurrence::MonthlyData { | 1784 | struct Recurrence::MonthlyData { |
1753 | const Recurrence *recurrence; | 1785 | const Recurrence *recurrence; |
1754 | int year; // current year | 1786 | int year; // current year |
1755 | int month; // current month 0..11 | 1787 | int month; // current month 0..11 |
1756 | int day; // current day of month 1..31 | 1788 | int day; // current day of month 1..31 |
1757 | bool varies; // true if recurring days vary between different months | 1789 | bool varies; // true if recurring days vary between different months |
1758 | private: | 1790 | private: |
1759 | QValueList<int> days28, days29, days30, days31; // recurring days in months of each length | 1791 | QValueList<int> days28, days29, days30, days31; // recurring days in months of each length |
1760 | QValueList<int> *recurDays[4]; | 1792 | QValueList<int> *recurDays[4]; |
1761 | public: | 1793 | public: |
1762 | MonthlyData(const Recurrence* r, const QDate &date) | 1794 | MonthlyData(const Recurrence* r, const QDate &date) |
1763 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) | 1795 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) |
1764 | { recurDays[0] = &days28; | 1796 | { recurDays[0] = &days28; |
1765 | recurDays[1] = &days29; | 1797 | recurDays[1] = &days29; |
1766 | recurDays[2] = &days30; | 1798 | recurDays[2] = &days30; |
1767 | recurDays[3] = &days31; | 1799 | recurDays[3] = &days31; |
1768 | varies = (recurrence->recurs == rMonthlyPos) | 1800 | varies = (recurrence->recurs == rMonthlyPos) |
1769 | ? true : recurrence->getMonthlyDayDays(days31, 31); | 1801 | ? true : recurrence->getMonthlyDayDays(days31, 31); |
1770 | } | 1802 | } |
1771 | const QValueList<int>* dayList() const { | 1803 | const QValueList<int>* dayList() const { |
1772 | if (!varies) | 1804 | if (!varies) |
1773 | return &days31; | 1805 | return &days31; |
1774 | QDate startOfMonth(year, month + 1, 1); | 1806 | QDate startOfMonth(year, month + 1, 1); |
1775 | int daysInMonth = startOfMonth.daysInMonth(); | 1807 | int daysInMonth = startOfMonth.daysInMonth(); |
1776 | QValueList<int>* days = recurDays[daysInMonth - 28]; | 1808 | QValueList<int>* days = recurDays[daysInMonth - 28]; |
1777 | if (recurrence->recurs == rMonthlyPos) | 1809 | if (recurrence->recurs == rMonthlyPos) |
1778 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); | 1810 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); |
1779 | else if (days->isEmpty()) | 1811 | else if (days->isEmpty()) |
1780 | recurrence->getMonthlyDayDays(*days, daysInMonth); | 1812 | recurrence->getMonthlyDayDays(*days, daysInMonth); |
1781 | return days; | 1813 | return days; |
1782 | } | 1814 | } |
1783 | int yearMonth() const { return year*12 + month; } | 1815 | int yearMonth() const { return year*12 + month; } |
1784 | void addMonths(int diff) { month += diff; year += month / 12; month %= 12; } | 1816 | void addMonths(int diff) { month += diff; year += month / 12; month %= 12; } |
1785 | QDate date() const { return QDate(year, month + 1, day); } | 1817 | QDate date() const { return QDate(year, month + 1, day); } |
1786 | }; | 1818 | }; |
1787 | 1819 | ||
1788 | int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const | 1820 | int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const |
1789 | { | 1821 | { |
1790 | if (recurs == rMonthlyPos && rMonthPositions.isEmpty() | 1822 | if (recurs == rMonthlyPos && rMonthPositions.isEmpty() |
1791 | || recurs == rMonthlyDay && rMonthDays.isEmpty()) | 1823 | || recurs == rMonthlyDay && rMonthDays.isEmpty()) |
1792 | return 0; | 1824 | return 0; |
1793 | 1825 | ||
1794 | MonthlyData data(this, mRecurStart.date()); | 1826 | MonthlyData data(this, mRecurStart.date()); |
1795 | switch (func) { | 1827 | switch (func) { |
1796 | case END_DATE_AND_COUNT: | 1828 | case END_DATE_AND_COUNT: |
1797 | return monthlyCalcEndDate(enddate, data); | 1829 | return monthlyCalcEndDate(enddate, data); |
1798 | case COUNT_TO_DATE: | 1830 | case COUNT_TO_DATE: |
1799 | return monthlyCalcToDate(enddate, data); | 1831 | return monthlyCalcToDate(enddate, data); |
1800 | case NEXT_AFTER_DATE: | 1832 | case NEXT_AFTER_DATE: |
1801 | return monthlyCalcNextAfter(enddate, data); | 1833 | return monthlyCalcNextAfter(enddate, data); |
1802 | } | 1834 | } |
1803 | return 0; | 1835 | return 0; |
1804 | } | 1836 | } |
1805 | 1837 | ||
1806 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const | 1838 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const |
1807 | { | 1839 | { |
1808 | uint countTogo = rDuration + mRecurExDatesCount; | 1840 | uint countTogo = rDuration + mRecurExDatesCount; |
1809 | int countGone = 0; | 1841 | int countGone = 0; |
1810 | QValueList<int>::ConstIterator it; | 1842 | QValueList<int>::ConstIterator it; |
1811 | const QValueList<int>* days = data.dayList(); | 1843 | const QValueList<int>* days = data.dayList(); |
1812 | 1844 | ||
1813 | if (data.day > 1) { | 1845 | if (data.day > 1) { |
1814 | // Check what remains of the start month | 1846 | // Check what remains of the start month |
1815 | for (it = days->begin(); it != days->end(); ++it) { | 1847 | for (it = days->begin(); it != days->end(); ++it) { |
1816 | if (*it >= data.day) { | 1848 | if (*it >= data.day) { |
1817 | ++countGone; | 1849 | ++countGone; |
1818 | if (--countTogo == 0) { | 1850 | if (--countTogo == 0) { |
1819 | data.day = *it; | 1851 | data.day = *it; |
1820 | break; | 1852 | break; |
1821 | } | 1853 | } |
1822 | } | 1854 | } |
1823 | } | 1855 | } |
1824 | if (countTogo) { | 1856 | if (countTogo) { |
1825 | data.day = 1; | 1857 | data.day = 1; |
1826 | data.addMonths(rFreq); | 1858 | data.addMonths(rFreq); |
1827 | } | 1859 | } |
1828 | } | 1860 | } |
1829 | if (countTogo) { | 1861 | if (countTogo) { |
1830 | if (data.varies) { | 1862 | if (data.varies) { |
1831 | // The number of recurrence days varies from month to month, | 1863 | // The number of recurrence days varies from month to month, |
1832 | // so we need to check month by month. | 1864 | // so we need to check month by month. |
1833 | for ( ; ; ) { | 1865 | for ( ; ; ) { |
1834 | days = data.dayList(); | 1866 | days = data.dayList(); |
1835 | uint n = days->count(); // number of recurrence days in this month | 1867 | uint n = days->count(); // number of recurrence days in this month |
1836 | if (n >= countTogo) | 1868 | if (n >= countTogo) |
1837 | break; | 1869 | break; |
1838 | countTogo -= n; | 1870 | countTogo -= n; |
1839 | countGone += n; | 1871 | countGone += n; |
1840 | data.addMonths(rFreq); | 1872 | data.addMonths(rFreq); |
1841 | } | 1873 | } |
1842 | } else { | 1874 | } else { |
1843 | // The number of recurrences is the same every month, | 1875 | // The number of recurrences is the same every month, |
1844 | // so skip the month-by-month check. | 1876 | // so skip the month-by-month check. |
1845 | // Skip the remaining whole months, but leave at least | 1877 | // Skip the remaining whole months, but leave at least |
1846 | // 1 recurrence remaining, in order to get its date. | 1878 | // 1 recurrence remaining, in order to get its date. |
1847 | int daysPerMonth = days->count(); | 1879 | int daysPerMonth = days->count(); |
1848 | int wholeMonths = (countTogo - 1) / daysPerMonth; | 1880 | int wholeMonths = (countTogo - 1) / daysPerMonth; |
1849 | data.addMonths(wholeMonths * rFreq); | 1881 | data.addMonths(wholeMonths * rFreq); |
1850 | countGone += wholeMonths * daysPerMonth; | 1882 | countGone += wholeMonths * daysPerMonth; |
1851 | countTogo -= wholeMonths * daysPerMonth; | 1883 | countTogo -= wholeMonths * daysPerMonth; |
1852 | } | 1884 | } |
1853 | if (countTogo) { | 1885 | if (countTogo) { |
1854 | // Check the last month in the recurrence | 1886 | // Check the last month in the recurrence |
1855 | for (it = days->begin(); it != days->end(); ++it) { | 1887 | for (it = days->begin(); it != days->end(); ++it) { |
1856 | ++countGone; | 1888 | ++countGone; |
1857 | if (--countTogo == 0) { | 1889 | if (--countTogo == 0) { |
1858 | data.day = *it; | 1890 | data.day = *it; |
1859 | break; | 1891 | break; |
1860 | } | 1892 | } |
1861 | } | 1893 | } |
1862 | } | 1894 | } |
1863 | } | 1895 | } |
1864 | enddate = data.date(); | 1896 | enddate = data.date(); |
1865 | return countGone; | 1897 | return countGone; |
1866 | } | 1898 | } |
1867 | 1899 | ||
1868 | int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const | 1900 | int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const |
1869 | { | 1901 | { |
1870 | int countGone = 0; | 1902 | int countGone = 0; |
1871 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 1903 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
1872 | int endYear = enddate.year(); | 1904 | int endYear = enddate.year(); |
1873 | int endMonth = enddate.month() - 1; // zero-based | 1905 | int endMonth = enddate.month() - 1; // zero-based |
1874 | int endDay = enddate.day(); | 1906 | int endDay = enddate.day(); |
1875 | int endYearMonth = endYear*12 + endMonth; | 1907 | int endYearMonth = endYear*12 + endMonth; |
1876 | QValueList<int>::ConstIterator it; | 1908 | QValueList<int>::ConstIterator it; |
1877 | const QValueList<int>* days = data.dayList(); | 1909 | const QValueList<int>* days = data.dayList(); |
1878 | 1910 | ||
1879 | if (data.day > 1) { | 1911 | if (data.day > 1) { |
1880 | // Check what remains of the start month | 1912 | // Check what remains of the start month |
1881 | for (it = days->begin(); it != days->end(); ++it) { | 1913 | for (it = days->begin(); it != days->end(); ++it) { |
1882 | if (*it >= data.day) { | 1914 | if (*it >= data.day) { |
1883 | if (data.yearMonth() == endYearMonth && *it > endDay) | 1915 | if (data.yearMonth() == endYearMonth && *it > endDay) |
1884 | return countGone; | 1916 | return countGone; |
1885 | if (++countGone >= countMax) | 1917 | if (++countGone >= countMax) |
1886 | return countMax; | 1918 | return countMax; |
1887 | } | 1919 | } |
1888 | } | 1920 | } |
1889 | data.day = 1; | 1921 | data.day = 1; |
1890 | data.addMonths(rFreq); | 1922 | data.addMonths(rFreq); |
1891 | } | 1923 | } |
1892 | 1924 | ||
1893 | if (data.varies) { | 1925 | if (data.varies) { |
1894 | // The number of recurrence days varies from month to month, | 1926 | // The number of recurrence days varies from month to month, |
1895 | // so we need to check month by month. | 1927 | // so we need to check month by month. |
1896 | while (data.yearMonth() < endYearMonth) { | 1928 | while (data.yearMonth() < endYearMonth) { |
1897 | countGone += data.dayList()->count(); | 1929 | countGone += data.dayList()->count(); |
1898 | if (countGone >= countMax) | 1930 | if (countGone >= countMax) |
1899 | return countMax; | 1931 | return countMax; |
1900 | data.addMonths(rFreq); | 1932 | data.addMonths(rFreq); |
1901 | } | 1933 | } |
1902 | days = data.dayList(); | 1934 | days = data.dayList(); |
1903 | } else { | 1935 | } else { |
1904 | // The number of recurrences is the same every month, | 1936 | // The number of recurrences is the same every month, |
1905 | // so skip the month-by-month check. | 1937 | // so skip the month-by-month check. |
1906 | // Skip the remaining whole months. | 1938 | // Skip the remaining whole months. |
1907 | int daysPerMonth = days->count(); | 1939 | int daysPerMonth = days->count(); |
1908 | int wholeMonths = endYearMonth - data.yearMonth(); | 1940 | int wholeMonths = endYearMonth - data.yearMonth(); |
1909 | countGone += (wholeMonths / rFreq) * daysPerMonth; | 1941 | countGone += (wholeMonths / rFreq) * daysPerMonth; |
1910 | if (countGone >= countMax) | 1942 | if (countGone >= countMax) |
1911 | return countMax; | 1943 | return countMax; |
1912 | if (wholeMonths % rFreq) | 1944 | if (wholeMonths % rFreq) |
1913 | return countGone; // end year isn't a recurrence year | 1945 | return countGone; // end year isn't a recurrence year |
1914 | data.year = endYear; | 1946 | data.year = endYear; |
1915 | data.month = endMonth; | 1947 | data.month = endMonth; |
1916 | } | 1948 | } |
1917 | 1949 | ||
1918 | // Check the last month in the recurrence | 1950 | // Check the last month in the recurrence |
1919 | for (it = days->begin(); it != days->end(); ++it) { | 1951 | for (it = days->begin(); it != days->end(); ++it) { |
1920 | if (*it > endDay) | 1952 | if (*it > endDay) |
1921 | return countGone; | 1953 | return countGone; |
1922 | if (++countGone >= countMax) | 1954 | if (++countGone >= countMax) |
1923 | return countMax; | 1955 | return countMax; |
1924 | } | 1956 | } |
1925 | return countGone; | 1957 | return countGone; |
1926 | } | 1958 | } |
1927 | 1959 | ||
1928 | int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const | 1960 | int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const |
1929 | { | 1961 | { |
1930 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 1962 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
1931 | int countGone = 0; | 1963 | int countGone = 0; |
1932 | int endYear = enddate.year(); | 1964 | int endYear = enddate.year(); |
1933 | int endDay = enddate.day(); | 1965 | int endDay = enddate.day(); |
1934 | int endYearMonth = endYear*12 + enddate.month() - 1; | 1966 | int endYearMonth = endYear*12 + enddate.month() - 1; |
1935 | QValueList<int>::ConstIterator it; | 1967 | QValueList<int>::ConstIterator it; |
1936 | const QValueList<int>* days = data.dayList(); | 1968 | const QValueList<int>* days = data.dayList(); |
1937 | 1969 | ||
1938 | if (data.day > 1) { | 1970 | if (data.day > 1) { |
1939 | // Check what remains of the start month | 1971 | // Check what remains of the start month |
1940 | for (it = days->begin(); it != days->end(); ++it) { | 1972 | for (it = days->begin(); it != days->end(); ++it) { |
1941 | if (*it >= data.day) { | 1973 | if (*it >= data.day) { |
1942 | ++countGone; | 1974 | ++countGone; |
1943 | if (data.yearMonth() == endYearMonth && *it > endDay) { | 1975 | if (data.yearMonth() == endYearMonth && *it > endDay) { |
1944 | data.day = *it; | 1976 | data.day = *it; |
1945 | goto ex; | 1977 | goto ex; |
1946 | } | 1978 | } |
1947 | if (--countTogo == 0) | 1979 | if (--countTogo == 0) |
1948 | return 0; | 1980 | return 0; |
1949 | } | 1981 | } |
1950 | } | 1982 | } |
1951 | data.day = 1; | 1983 | data.day = 1; |
1952 | data.addMonths(rFreq); | 1984 | data.addMonths(rFreq); |
1953 | } | 1985 | } |
1954 | 1986 | ||
1955 | if (data.varies) { | 1987 | if (data.varies) { |
1956 | // The number of recurrence days varies from month to month, | 1988 | // The number of recurrence days varies from month to month, |
1957 | // so we need to check month by month. | 1989 | // so we need to check month by month. |
1958 | while (data.yearMonth() <= endYearMonth) { | 1990 | while (data.yearMonth() <= endYearMonth) { |
1959 | days = data.dayList(); | 1991 | days = data.dayList(); |
1960 | uint n = days->count(); // number of recurrence days in this month | 1992 | uint n = days->count(); // number of recurrence days in this month |
1961 | if (data.yearMonth() == endYearMonth && days->last() > endDay) | 1993 | if (data.yearMonth() == endYearMonth && days->last() > endDay) |
1962 | break; | 1994 | break; |
1963 | if (n >= countTogo) | 1995 | if (n >= countTogo) |
1964 | return 0; | 1996 | return 0; |
1965 | countGone += n; | 1997 | countGone += n; |
1966 | countTogo -= n; | 1998 | countTogo -= n; |
1967 | data.addMonths(rFreq); | 1999 | data.addMonths(rFreq); |
1968 | } | 2000 | } |
1969 | days = data.dayList(); | 2001 | days = data.dayList(); |
1970 | } else { | 2002 | } else { |
1971 | // The number of recurrences is the same every month, | 2003 | // The number of recurrences is the same every month, |
1972 | // so skip the month-by-month check. | 2004 | // so skip the month-by-month check. |
1973 | // Skip the remaining whole months to at least end year/month. | 2005 | // Skip the remaining whole months to at least end year/month. |
1974 | int daysPerMonth = days->count(); | 2006 | int daysPerMonth = days->count(); |
1975 | int elapsed = endYearMonth - data.yearMonth(); | 2007 | int elapsed = endYearMonth - data.yearMonth(); |
1976 | int recurMonths = (elapsed + rFreq - 1) / rFreq; | 2008 | int recurMonths = (elapsed + rFreq - 1) / rFreq; |
1977 | if (elapsed % rFreq == 0 && days->last() <= endDay) | 2009 | if (elapsed % rFreq == 0 && days->last() <= endDay) |
1978 | ++recurMonths; // required month is after endYearMonth | 2010 | ++recurMonths; // required month is after endYearMonth |
1979 | if (recurMonths) { | 2011 | if (recurMonths) { |
1980 | int n = recurMonths * daysPerMonth; | 2012 | int n = recurMonths * daysPerMonth; |
1981 | if (static_cast<uint>(n) > countTogo) | 2013 | if (static_cast<uint>(n) > countTogo) |
1982 | return 0; // reached end of recurrence | 2014 | return 0; // reached end of recurrence |
1983 | countTogo -= n; | 2015 | countTogo -= n; |
1984 | countGone += n; | 2016 | countGone += n; |
1985 | data.addMonths(recurMonths * rFreq); | 2017 | data.addMonths(recurMonths * rFreq); |
1986 | } | 2018 | } |
1987 | } | 2019 | } |
1988 | 2020 | ||
1989 | // Check the last month in the recurrence | 2021 | // Check the last month in the recurrence |
1990 | for (it = days->begin(); it != days->end(); ++it) { | 2022 | for (it = days->begin(); it != days->end(); ++it) { |
1991 | ++countGone; | 2023 | ++countGone; |
1992 | if (data.yearMonth() > endYearMonth || *it > endDay) { | 2024 | if (data.yearMonth() > endYearMonth || *it > endDay) { |
1993 | data.day = *it; | 2025 | data.day = *it; |
1994 | break; | 2026 | break; |
1995 | } | 2027 | } |
1996 | if (--countTogo == 0) | 2028 | if (--countTogo == 0) |
1997 | return 0; | 2029 | return 0; |
1998 | } | 2030 | } |
1999 | ex: | 2031 | ex: |
2000 | enddate = data.date(); | 2032 | enddate = data.date(); |
2001 | return countGone; | 2033 | return countGone; |
2002 | } | 2034 | } |
2003 | 2035 | ||
2004 | 2036 | ||
2005 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. | 2037 | /* Find count and, depending on 'func', the end date of an annual recurrence by date. |
2006 | * Reply = total number of occurrences up to 'enddate', or 0 if error. | 2038 | * Reply = total number of occurrences up to 'enddate', or 0 if error. |
2007 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the | 2039 | * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the |
2008 | * recurrence end date. | 2040 | * recurrence end date. |
2009 | */ | 2041 | */ |
2010 | struct Recurrence::YearlyMonthData { | 2042 | struct Recurrence::YearlyMonthData { |
2011 | const Recurrence *recurrence; | 2043 | const Recurrence *recurrence; |
2012 | int year; // current year | 2044 | int year; // current year |
2013 | int month; // current month 1..12 | 2045 | int month; // current month 1..12 |
2014 | int day; // current day of month 1..31 | 2046 | int day; // current day of month 1..31 |
2015 | bool leapyear; // true if February 29th recurs and current year is a leap year | 2047 | bool leapyear; // true if February 29th recurs and current year is a leap year |
2016 | bool feb29; // true if February 29th recurs | 2048 | bool feb29; // true if February 29th recurs |
2017 | private: | 2049 | private: |
2018 | QValueList<int> months; // recurring months in non-leap years 1..12 | 2050 | QValueList<int> months; // recurring months in non-leap years 1..12 |
2019 | QValueList<int> leapMonths; // recurring months in leap years 1..12 | 2051 | QValueList<int> leapMonths; // recurring months in leap years 1..12 |
2020 | public: | 2052 | public: |
2021 | YearlyMonthData(const Recurrence* r, const QDate &date) | 2053 | YearlyMonthData(const Recurrence* r, const QDate &date) |
2022 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) | 2054 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) |
2023 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); | 2055 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); |
2024 | leapyear = feb29 && QDate::leapYear(year); | 2056 | leapyear = feb29 && QDate::leapYear(year); |
2025 | } | 2057 | } |
2026 | const QValueList<int>* monthList() const | 2058 | const QValueList<int>* monthList() const |
2027 | { return leapyear ? &leapMonths : &months; } | 2059 | { return leapyear ? &leapMonths : &months; } |
2028 | const QValueList<int>* leapMonthList() const { return &leapMonths; } | 2060 | const QValueList<int>* leapMonthList() const { return &leapMonths; } |
2029 | QDate date() const { return QDate(year, month, day); } | 2061 | QDate date() const { return QDate(year, month, day); } |
2030 | }; | 2062 | }; |
2031 | 2063 | ||
2032 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const | 2064 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const |
2033 | { | 2065 | { |
2034 | if (rYearNums.isEmpty()) | 2066 | if (rYearNums.isEmpty()) |
2035 | return 0; | 2067 | return 0; |
2036 | YearlyMonthData data(this, mRecurStart.date()); | 2068 | YearlyMonthData data(this, mRecurStart.date()); |
2037 | switch (func) { | 2069 | switch (func) { |
2038 | case END_DATE_AND_COUNT: | 2070 | case END_DATE_AND_COUNT: |
2039 | return yearlyMonthCalcEndDate(enddate, data); | 2071 | return yearlyMonthCalcEndDate(enddate, data); |
2040 | case COUNT_TO_DATE: | 2072 | case COUNT_TO_DATE: |
2041 | return yearlyMonthCalcToDate(enddate, data); | 2073 | return yearlyMonthCalcToDate(enddate, data); |
2042 | case NEXT_AFTER_DATE: | 2074 | case NEXT_AFTER_DATE: |
2043 | return yearlyMonthCalcNextAfter(enddate, data); | 2075 | return yearlyMonthCalcNextAfter(enddate, data); |
2044 | } | 2076 | } |
2045 | return 0; | 2077 | return 0; |
2046 | } | 2078 | } |
2047 | 2079 | ||
2048 | // Find total count and end date of an annual recurrence by date. | 2080 | // Find total count and end date of an annual recurrence by date. |
2049 | // Reply = total number of occurrences. | 2081 | // Reply = total number of occurrences. |
2050 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const | 2082 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const |
2051 | { | 2083 | { |
2052 | uint countTogo = rDuration + mRecurExDatesCount; | 2084 | uint countTogo = rDuration + mRecurExDatesCount; |
2053 | int countGone = 0; | 2085 | int countGone = 0; |
2054 | QValueList<int>::ConstIterator it; | 2086 | QValueList<int>::ConstIterator it; |
2055 | const QValueList<int>* mons = data.monthList(); // get recurring months for this year | 2087 | const QValueList<int>* mons = data.monthList(); // get recurring months for this year |
2056 | 2088 | ||
2057 | if (data.month > 1) { | 2089 | if (data.month > 1) { |
2058 | // Check what remains of the start year | 2090 | // Check what remains of the start year |
2059 | for (it = mons->begin(); it != mons->end(); ++it) { | 2091 | for (it = mons->begin(); it != mons->end(); ++it) { |
2060 | if (*it >= data.month) { | 2092 | if (*it >= data.month) { |
2061 | ++countGone; | 2093 | ++countGone; |
2062 | if (--countTogo == 0) { | 2094 | if (--countTogo == 0) { |
2063 | data.month = *it; | 2095 | data.month = *it; |
2064 | if (data.month == 2 && data.feb29 && !data.leapyear) { | 2096 | if (data.month == 2 && data.feb29 && !data.leapyear) { |
2065 | // The recurrence should end on February 29th, but it's a non-leap year | 2097 | // The recurrence should end on February 29th, but it's a non-leap year |
2066 | switch (mFeb29YearlyType) { | 2098 | switch (mFeb29YearlyType) { |
2067 | case rFeb28: | 2099 | case rFeb28: |
2068 | data.day = 28; | 2100 | data.day = 28; |
2069 | break; | 2101 | break; |
2070 | case rMar1: | 2102 | case rMar1: |
2071 | data.month = 3; | 2103 | data.month = 3; |
2072 | data.day = 1; | 2104 | data.day = 1; |
2073 | break; | 2105 | break; |
2074 | case rFeb29: | 2106 | case rFeb29: |
2075 | break; | 2107 | break; |
2076 | } | 2108 | } |
2077 | } | 2109 | } |
2078 | break; | 2110 | break; |
2079 | } | 2111 | } |
2080 | } | 2112 | } |
2081 | } | 2113 | } |
2082 | if (countTogo) { | 2114 | if (countTogo) { |
2083 | data.month = 1; | 2115 | data.month = 1; |
2084 | data.year += rFreq; | 2116 | data.year += rFreq; |
2085 | } | 2117 | } |
2086 | } | 2118 | } |
2087 | if (countTogo) { | 2119 | if (countTogo) { |
2088 | if (data.feb29 && mFeb29YearlyType == rFeb29) { | 2120 | if (data.feb29 && mFeb29YearlyType == rFeb29) { |
2089 | // The number of recurrences is different on leap years, | 2121 | // The number of recurrences is different on leap years, |
2090 | // so check year-by-year. | 2122 | // so check year-by-year. |
2091 | for ( ; ; ) { | 2123 | for ( ; ; ) { |
2092 | mons = data.monthList(); | 2124 | mons = data.monthList(); |
2093 | uint n = mons->count(); | 2125 | uint n = mons->count(); |
2094 | if (n >= countTogo) | 2126 | if (n >= countTogo) |
2095 | break; | 2127 | break; |
2096 | countTogo -= n; | 2128 | countTogo -= n; |
2097 | countGone += n; | 2129 | countGone += n; |
2098 | data.year += rFreq; | 2130 | data.year += rFreq; |
2099 | } | 2131 | } |
2100 | } else { | 2132 | } else { |
2101 | // The number of recurrences is the same every year, | 2133 | // The number of recurrences is the same every year, |
2102 | // so skip the year-by-year check. | 2134 | // so skip the year-by-year check. |
2103 | // Skip the remaining whole years, but leave at least | 2135 | // Skip the remaining whole years, but leave at least |
2104 | // 1 recurrence remaining, in order to get its date. | 2136 | // 1 recurrence remaining, in order to get its date. |
2105 | int monthsPerYear = mons->count(); | 2137 | int monthsPerYear = mons->count(); |
2106 | int wholeYears = (countTogo - 1) / monthsPerYear; | 2138 | int wholeYears = (countTogo - 1) / monthsPerYear; |
2107 | data.year += wholeYears * rFreq; | 2139 | data.year += wholeYears * rFreq; |
2108 | countGone += wholeYears * monthsPerYear; | 2140 | countGone += wholeYears * monthsPerYear; |
2109 | countTogo -= wholeYears * monthsPerYear; | 2141 | countTogo -= wholeYears * monthsPerYear; |
2110 | } | 2142 | } |
2111 | if (countTogo) { | 2143 | if (countTogo) { |
2112 | // Check the last year in the recurrence | 2144 | // Check the last year in the recurrence |
2113 | for (it = mons->begin(); it != mons->end(); ++it) { | 2145 | for (it = mons->begin(); it != mons->end(); ++it) { |
2114 | ++countGone; | 2146 | ++countGone; |
2115 | if (--countTogo == 0) { | 2147 | if (--countTogo == 0) { |
2116 | data.month = *it; | 2148 | data.month = *it; |
2117 | if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) { | 2149 | if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) { |
2118 | // The recurrence should end on February 29th, but it's a non-leap year | 2150 | // The recurrence should end on February 29th, but it's a non-leap year |
2119 | switch (mFeb29YearlyType) { | 2151 | switch (mFeb29YearlyType) { |
2120 | case rFeb28: | 2152 | case rFeb28: |
2121 | data.day = 28; | 2153 | data.day = 28; |
2122 | break; | 2154 | break; |
2123 | case rMar1: | 2155 | case rMar1: |
2124 | data.month = 3; | 2156 | data.month = 3; |
2125 | data.day = 1; | 2157 | data.day = 1; |
2126 | break; | 2158 | break; |
2127 | case rFeb29: | 2159 | case rFeb29: |
2128 | break; | 2160 | break; |
2129 | } | 2161 | } |
2130 | } | 2162 | } |
2131 | break; | 2163 | break; |
2132 | } | 2164 | } |
2133 | } | 2165 | } |
2134 | } | 2166 | } |
2135 | } | 2167 | } |
2136 | enddate = data.date(); | 2168 | enddate = data.date(); |
2137 | return countGone; | 2169 | return countGone; |
2138 | } | 2170 | } |
2139 | 2171 | ||
2140 | // Find count of an annual recurrence by date. | 2172 | // Find count of an annual recurrence by date. |
2141 | // Reply = total number of occurrences up to 'enddate'. | 2173 | // Reply = total number of occurrences up to 'enddate'. |
2142 | int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const | 2174 | int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const |
2143 | { | 2175 | { |
2144 | int countGone = 0; | 2176 | int countGone = 0; |
2145 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 2177 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
2146 | int endYear = enddate.year(); | 2178 | int endYear = enddate.year(); |
2147 | int endMonth = enddate.month(); | 2179 | int endMonth = enddate.month(); |
2148 | int endDay = enddate.day(); | 2180 | int endDay = enddate.day(); |
2149 | if (endDay < data.day) { | 2181 | if (endDay < data.day) { |
2150 | /* The end day of the month is earlier than the recurrence day of the month. | 2182 | /* The end day of the month is earlier than the recurrence day of the month. |
2151 | * If Feb 29th recurs and: | 2183 | * If Feb 29th recurs and: |
2152 | * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month | 2184 | * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month |
2153 | * if enddate is Feb 28th on a non-leap year. | 2185 | * if enddate is Feb 28th on a non-leap year. |
2154 | * 2) it recurs on Mar 1st in non-leap years, allow the end month to be | 2186 | * 2) it recurs on Mar 1st in non-leap years, allow the end month to be |
2155 | * adjusted to February, to simplify calculations. | 2187 | * adjusted to February, to simplify calculations. |
2156 | */ | 2188 | */ |
2157 | if (data.feb29 && !QDate::leapYear(endYear) | 2189 | if (data.feb29 && !QDate::leapYear(endYear) |
2158 | && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) { | 2190 | && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) { |
2159 | } | 2191 | } |
2160 | else if (--endMonth == 0) { | 2192 | else if (--endMonth == 0) { |
2161 | endMonth = 12; | 2193 | endMonth = 12; |
2162 | --endYear; | 2194 | --endYear; |
2163 | } | 2195 | } |
2164 | } | 2196 | } |
2165 | QValueList<int>::ConstIterator it; | 2197 | QValueList<int>::ConstIterator it; |
2166 | const QValueList<int>* mons = data.monthList(); | 2198 | const QValueList<int>* mons = data.monthList(); |
2167 | 2199 | ||
2168 | if (data.month > 1) { | 2200 | if (data.month > 1) { |
2169 | // Check what remains of the start year | 2201 | // Check what remains of the start year |
2170 | for (it = mons->begin(); it != mons->end(); ++it) { | 2202 | for (it = mons->begin(); it != mons->end(); ++it) { |
2171 | if (*it >= data.month) { | 2203 | if (*it >= data.month) { |
2172 | if (data.year == endYear && *it > endMonth) | 2204 | if (data.year == endYear && *it > endMonth) |
2173 | return countGone; | 2205 | return countGone; |
2174 | if (++countGone >= countMax) | 2206 | if (++countGone >= countMax) |
2175 | return countMax; | 2207 | return countMax; |
2176 | } | 2208 | } |
2177 | } | 2209 | } |
2178 | data.month = 1; | 2210 | data.month = 1; |
2179 | data.year += rFreq; | 2211 | data.year += rFreq; |
2180 | } | 2212 | } |
2181 | if (data.feb29 && mFeb29YearlyType == rFeb29) { | 2213 | if (data.feb29 && mFeb29YearlyType == rFeb29) { |
2182 | // The number of recurrences is different on leap years, | 2214 | // The number of recurrences is different on leap years, |
2183 | // so check year-by-year. | 2215 | // so check year-by-year. |
2184 | while (data.year < endYear) { | 2216 | while (data.year < endYear) { |
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index defdb09..89eb72f 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -1,1018 +1,1019 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 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 <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qxml.h> | 32 | #include <qxml.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | 38 | ||
39 | #include "calendar.h" | 39 | #include "calendar.h" |
40 | #include "alarm.h" | 40 | #include "alarm.h" |
41 | #include "recurrence.h" | 41 | #include "recurrence.h" |
42 | #include "calendarlocal.h" | 42 | #include "calendarlocal.h" |
43 | 43 | ||
44 | #include "sharpformat.h" | 44 | #include "sharpformat.h" |
45 | #include "syncdefines.h" | 45 | #include "syncdefines.h" |
46 | 46 | ||
47 | using namespace KCal; | 47 | using namespace KCal; |
48 | 48 | ||
49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY | 49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY |
50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
51 | 51 | ||
52 | //ARSD silentalarm = 0 | 52 | //ARSD silentalarm = 0 |
53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly | 53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly |
54 | // 12 RFRQ | 54 | // 12 RFRQ |
55 | // 13 RPOS pos = 4. monday in month | 55 | // 13 RPOS pos = 4. monday in month |
56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun | 56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun |
57 | // 15 REND 0 = no end/ 1 = end | 57 | // 15 REND 0 = no end/ 1 = end |
58 | // 16 REDT rec end dt | 58 | // 16 REDT rec end dt |
59 | //ALSD | 59 | //ALSD |
60 | //ALED | 60 | //ALED |
61 | //MDAY | 61 | //MDAY |
62 | 62 | ||
63 | class SharpParser : public QObject | 63 | class SharpParser : public QObject |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { | 66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { |
67 | oldCategories = 0; | 67 | oldCategories = 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) | 70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) |
71 | { | 71 | { |
72 | int i = 1; | 72 | int i = 1; |
73 | bool skip = true; | 73 | bool skip = true; |
74 | int max = attList.count() -2; | 74 | int max = attList.count() -2; |
75 | while ( i < max ) { | 75 | while ( i < max ) { |
76 | if ( !attList[i].isEmpty() ) { | 76 | if ( !attList[i].isEmpty() ) { |
77 | skip = false; | 77 | skip = false; |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | ++i ; | 80 | ++i ; |
81 | } | 81 | } |
82 | if ( skip ) | 82 | if ( skip ) |
83 | return false; | 83 | return false; |
84 | ulong cSum = SharpFormat::getCsum(attList ); | 84 | ulong cSum = SharpFormat::getCsum(attList ); |
85 | 85 | ||
86 | if ( qName == "Event" ) { | 86 | if ( qName == "Event" ) { |
87 | Event *event; | 87 | Event *event; |
88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); | 88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); |
89 | if ( event ) | 89 | if ( event ) |
90 | event = (Event*)event->clone(); | 90 | event = (Event*)event->clone(); |
91 | else | 91 | else |
92 | event = new Event; | 92 | event = new Event; |
93 | event->setID("Sharp_DTM", attList[0] ); | 93 | event->setID("Sharp_DTM", attList[0] ); |
94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); | 94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); |
95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
96 | 96 | ||
97 | event->setSummary( attList[2] ); | 97 | event->setSummary( attList[2] ); |
98 | event->setLocation( attList[3] ); | 98 | event->setLocation( attList[3] ); |
99 | event->setDescription( attList[4] ); | 99 | event->setDescription( attList[4] ); |
100 | if ( attList[7] == "1" ) { | 100 | if ( attList[7] == "1" ) { |
101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); | 101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); |
102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); | 102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); |
103 | event->setFloats( true ); | 103 | event->setFloats( true ); |
104 | } else { | 104 | } else { |
105 | event->setFloats( false ); | 105 | event->setFloats( false ); |
106 | event->setDtStart( fromString( attList[5] ) ); | 106 | event->setDtStart( fromString( attList[5] ) ); |
107 | event->setDtEnd( fromString( attList[6] )); | 107 | event->setDtEnd( fromString( attList[6] )); |
108 | } | 108 | } |
109 | 109 | ||
110 | QString rtype = attList[11]; | 110 | QString rtype = attList[11]; |
111 | if ( rtype != "255" ) { | 111 | if ( rtype != "255" ) { |
112 | // qDebug("recurs "); | 112 | // qDebug("recurs "); |
113 | QDate startDate = event->dtStart().date(); | 113 | QDate startDate = event->dtStart().date(); |
114 | 114 | ||
115 | QString freqStr = attList[12]; | 115 | QString freqStr = attList[12]; |
116 | int freq = freqStr.toInt(); | 116 | int freq = freqStr.toInt(); |
117 | 117 | ||
118 | QString hasEndDateStr = attList[15] ; | 118 | QString hasEndDateStr = attList[15] ; |
119 | bool hasEndDate = hasEndDateStr == "1"; | 119 | bool hasEndDate = hasEndDateStr == "1"; |
120 | 120 | ||
121 | QString endDateStr = attList[16]; | 121 | QString endDateStr = attList[16]; |
122 | QDate endDate = fromString( endDateStr ).date(); | 122 | QDate endDate = fromString( endDateStr ).date(); |
123 | 123 | ||
124 | QString weekDaysStr = attList[14]; | 124 | QString weekDaysStr = attList[14]; |
125 | uint weekDaysNum = weekDaysStr.toInt(); | 125 | uint weekDaysNum = weekDaysStr.toInt(); |
126 | 126 | ||
127 | QBitArray weekDays( 7 ); | 127 | QBitArray weekDays( 7 ); |
128 | int i; | 128 | int i; |
129 | int bb = 1; | 129 | int bb = 1; |
130 | for( i = 1; i <= 7; ++i ) { | 130 | for( i = 1; i <= 7; ++i ) { |
131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
132 | bb = 2 << (i-1); | 132 | bb = 2 << (i-1); |
133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
134 | } | 134 | } |
135 | // qDebug("next "); | 135 | // qDebug("next "); |
136 | QString posStr = attList[13]; | 136 | QString posStr = attList[13]; |
137 | int pos = posStr.toInt(); | 137 | int pos = posStr.toInt(); |
138 | Recurrence *r = event->recurrence(); | 138 | Recurrence *r = event->recurrence(); |
139 | 139 | ||
140 | if ( rtype == "0" ) { | 140 | if ( rtype == "0" ) { |
141 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 141 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
142 | else r->setDaily( freq, -1 ); | 142 | else r->setDaily( freq, -1 ); |
143 | } else if ( rtype == "1" ) { | 143 | } else if ( rtype == "1" ) { |
144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
145 | else r->setWeekly( freq, weekDays, -1 ); | 145 | else r->setWeekly( freq, weekDays, -1 ); |
146 | } else if ( rtype == "3" ) { | 146 | } else if ( rtype == "3" ) { |
147 | if ( hasEndDate ) | 147 | if ( hasEndDate ) |
148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
149 | else | 149 | else |
150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
151 | r->addMonthlyDay( startDate.day() ); | 151 | r->addMonthlyDay( startDate.day() ); |
152 | } else if ( rtype == "2" ) { | 152 | } else if ( rtype == "2" ) { |
153 | if ( hasEndDate ) | 153 | if ( hasEndDate ) |
154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
155 | else | 155 | else |
156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
157 | QBitArray days( 7 ); | 157 | QBitArray days( 7 ); |
158 | days.fill( false ); | 158 | days.fill( false ); |
159 | days.setBit( startDate.dayOfWeek() - 1 ); | 159 | days.setBit( startDate.dayOfWeek() - 1 ); |
160 | r->addMonthlyPos( pos, days ); | 160 | r->addMonthlyPos( pos, days ); |
161 | } else if ( rtype == "4" ) { | 161 | } else if ( rtype == "4" ) { |
162 | if ( hasEndDate ) | 162 | if ( hasEndDate ) |
163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
164 | else | 164 | else |
165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
166 | r->addYearlyNum( startDate.month() ); | 166 | r->addYearlyNum( startDate.month() ); |
167 | } | 167 | } |
168 | } else { | 168 | } else { |
169 | event->recurrence()->unsetRecurs(); | 169 | event->recurrence()->unsetRecurs(); |
170 | } | 170 | } |
171 | 171 | ||
172 | QString categoryList = attList[1] ; | 172 | QString categoryList = attList[1] ; |
173 | event->setCategories( lookupCategories( categoryList ) ); | 173 | event->setCategories( lookupCategories( categoryList ) ); |
174 | 174 | ||
175 | // strange 0 semms to mean: alarm enabled | 175 | // strange 0 semms to mean: alarm enabled |
176 | if ( attList[8] == "0" ) { | 176 | if ( attList[8] == "0" ) { |
177 | Alarm *alarm; | 177 | Alarm *alarm; |
178 | if ( event->alarms().count() > 0 ) | 178 | if ( event->alarms().count() > 0 ) |
179 | alarm = event->alarms().first(); | 179 | alarm = event->alarms().first(); |
180 | else { | 180 | else { |
181 | alarm = new Alarm( event ); | 181 | alarm = new Alarm( event ); |
182 | event->addAlarm( alarm ); | 182 | event->addAlarm( alarm ); |
183 | alarm->setType( Alarm::Audio ); | ||
183 | } | 184 | } |
184 | alarm->setType( Alarm::Audio ); | 185 | //alarm->setType( Alarm::Audio ); |
185 | alarm->setEnabled( true ); | 186 | alarm->setEnabled( true ); |
186 | int alarmOffset = attList[9].toInt(); | 187 | int alarmOffset = attList[9].toInt(); |
187 | alarm->setStartOffset( alarmOffset * -60 ); | 188 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | 189 | } else { |
189 | Alarm *alarm; | 190 | Alarm *alarm; |
190 | if ( event->alarms().count() > 0 ) { | 191 | if ( event->alarms().count() > 0 ) { |
191 | alarm = event->alarms().first(); | 192 | alarm = event->alarms().first(); |
192 | alarm->setType( Alarm::Audio ); | 193 | alarm->setType( Alarm::Audio ); |
193 | alarm->setStartOffset( -60*15 ); | 194 | alarm->setStartOffset( -60*15 ); |
194 | alarm->setEnabled( false ); | 195 | alarm->setEnabled( false ); |
195 | } | 196 | } |
196 | } | 197 | } |
197 | 198 | ||
198 | mCalendar->addEvent( event); | 199 | mCalendar->addEvent( event); |
199 | } else if ( qName == "Todo" ) { | 200 | } else if ( qName == "Todo" ) { |
200 | Todo *todo; | 201 | Todo *todo; |
201 | 202 | ||
202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 203 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
203 | if (todo ) | 204 | if (todo ) |
204 | todo = (Todo*)todo->clone(); | 205 | todo = (Todo*)todo->clone(); |
205 | else | 206 | else |
206 | todo = new Todo; | 207 | todo = new Todo; |
207 | 208 | ||
208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 209 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
209 | // 0 1 2 3 4 5 6 7 8 | 210 | // 0 1 2 3 4 5 6 7 8 |
210 | //1,,,,,1,4,Loch zumachen,"" | 211 | //1,,,,,1,4,Loch zumachen,"" |
211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 212 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " |
212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes | 213 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
213 | 214 | ||
214 | todo->setID( "Sharp_DTM", attList[0]); | 215 | todo->setID( "Sharp_DTM", attList[0]); |
215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 216 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 217 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
217 | 218 | ||
218 | todo->setSummary( attList[7] ); | 219 | todo->setSummary( attList[7] ); |
219 | todo->setDescription( attList[8]); | 220 | todo->setDescription( attList[8]); |
220 | 221 | ||
221 | int priority = attList[6].toInt(); | 222 | int priority = attList[6].toInt(); |
222 | if ( priority == 0 ) priority = 3; | 223 | if ( priority == 0 ) priority = 3; |
223 | todo->setPriority( priority ); | 224 | todo->setPriority( priority ); |
224 | 225 | ||
225 | QString categoryList = attList[1]; | 226 | QString categoryList = attList[1]; |
226 | todo->setCategories( lookupCategories( categoryList ) ); | 227 | todo->setCategories( lookupCategories( categoryList ) ); |
227 | 228 | ||
228 | 229 | ||
229 | 230 | ||
230 | QString hasDateStr = attList[3]; // due | 231 | QString hasDateStr = attList[3]; // due |
231 | if ( !hasDateStr.isEmpty() ) { | 232 | if ( !hasDateStr.isEmpty() ) { |
232 | if ( hasDateStr.right(6) == "000000" ) { | 233 | if ( hasDateStr.right(6) == "000000" ) { |
233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 234 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
234 | todo->setFloats( true ); | 235 | todo->setFloats( true ); |
235 | } | 236 | } |
236 | else { | 237 | else { |
237 | todo->setDtDue( fromString( hasDateStr ) ); | 238 | todo->setDtDue( fromString( hasDateStr ) ); |
238 | todo->setFloats( false ); | 239 | todo->setFloats( false ); |
239 | } | 240 | } |
240 | 241 | ||
241 | todo->setHasDueDate( true ); | 242 | todo->setHasDueDate( true ); |
242 | } | 243 | } |
243 | hasDateStr = attList[2];//start | 244 | hasDateStr = attList[2];//start |
244 | if ( !hasDateStr.isEmpty() ) { | 245 | if ( !hasDateStr.isEmpty() ) { |
245 | 246 | ||
246 | todo->setDtStart( fromString( hasDateStr ) ); | 247 | todo->setDtStart( fromString( hasDateStr ) ); |
247 | todo->setHasStartDate( true); | 248 | todo->setHasStartDate( true); |
248 | } else | 249 | } else |
249 | todo->setHasStartDate( false ); | 250 | todo->setHasStartDate( false ); |
250 | hasDateStr = attList[4];//completed | 251 | hasDateStr = attList[4];//completed |
251 | if ( !hasDateStr.isEmpty() ) { | 252 | if ( !hasDateStr.isEmpty() ) { |
252 | todo->setCompleted(fromString( hasDateStr ) ); | 253 | todo->setCompleted(fromString( hasDateStr ) ); |
253 | } | 254 | } |
254 | QString completedStr = attList[5]; | 255 | QString completedStr = attList[5]; |
255 | if ( completedStr == "0" ) | 256 | if ( completedStr == "0" ) |
256 | todo->setCompleted( true ); | 257 | todo->setCompleted( true ); |
257 | else | 258 | else |
258 | todo->setCompleted( false ); | 259 | todo->setCompleted( false ); |
259 | mCalendar->addTodo( todo ); | 260 | mCalendar->addTodo( todo ); |
260 | 261 | ||
261 | } else if ( qName == "Category" ) { | 262 | } else if ( qName == "Category" ) { |
262 | /* | 263 | /* |
263 | QString id = attributes.value( "id" ); | 264 | QString id = attributes.value( "id" ); |
264 | QString name = attributes.value( "name" ); | 265 | QString name = attributes.value( "name" ); |
265 | setCategory( id, name ); | 266 | setCategory( id, name ); |
266 | */ | 267 | */ |
267 | } | 268 | } |
268 | //qDebug("end "); | 269 | //qDebug("end "); |
269 | return true; | 270 | return true; |
270 | } | 271 | } |
271 | 272 | ||
272 | 273 | ||
273 | void setCategoriesList ( QStringList * c ) | 274 | void setCategoriesList ( QStringList * c ) |
274 | { | 275 | { |
275 | oldCategories = c; | 276 | oldCategories = c; |
276 | } | 277 | } |
277 | 278 | ||
278 | QDateTime fromString ( QString s, bool useTz = true ) { | 279 | QDateTime fromString ( QString s, bool useTz = true ) { |
279 | QDateTime dt; | 280 | QDateTime dt; |
280 | int y,m,t,h,min,sec; | 281 | int y,m,t,h,min,sec; |
281 | y = s.mid(0,4).toInt(); | 282 | y = s.mid(0,4).toInt(); |
282 | m = s.mid(4,2).toInt(); | 283 | m = s.mid(4,2).toInt(); |
283 | t = s.mid(6,2).toInt(); | 284 | t = s.mid(6,2).toInt(); |
284 | h = s.mid(9,2).toInt(); | 285 | h = s.mid(9,2).toInt(); |
285 | min = s.mid(11,2).toInt(); | 286 | min = s.mid(11,2).toInt(); |
286 | sec = s.mid(13,2).toInt(); | 287 | sec = s.mid(13,2).toInt(); |
287 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 288 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
288 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 289 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
289 | if ( useTz ) | 290 | if ( useTz ) |
290 | dt = dt.addSecs ( offset*60); | 291 | dt = dt.addSecs ( offset*60); |
291 | return dt; | 292 | return dt; |
292 | 293 | ||
293 | } | 294 | } |
294 | protected: | 295 | protected: |
295 | QDateTime toDateTime( const QString &value ) | 296 | QDateTime toDateTime( const QString &value ) |
296 | { | 297 | { |
297 | QDateTime dt; | 298 | QDateTime dt; |
298 | dt.setTime_t( value.toUInt() ); | 299 | dt.setTime_t( value.toUInt() ); |
299 | 300 | ||
300 | return dt; | 301 | return dt; |
301 | } | 302 | } |
302 | 303 | ||
303 | QStringList lookupCategories( const QString &categoryList ) | 304 | QStringList lookupCategories( const QString &categoryList ) |
304 | { | 305 | { |
305 | QStringList categoryIds = QStringList::split( ";", categoryList ); | 306 | QStringList categoryIds = QStringList::split( ";", categoryList ); |
306 | QStringList categories; | 307 | QStringList categories; |
307 | QStringList::ConstIterator it; | 308 | QStringList::ConstIterator it; |
308 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { | 309 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { |
309 | QString cate = category( *it ); | 310 | QString cate = category( *it ); |
310 | if ( oldCategories ) { | 311 | if ( oldCategories ) { |
311 | if ( ! oldCategories->contains( cate ) ) | 312 | if ( ! oldCategories->contains( cate ) ) |
312 | oldCategories->append( cate ); | 313 | oldCategories->append( cate ); |
313 | } | 314 | } |
314 | categories.append(cate ); | 315 | categories.append(cate ); |
315 | } | 316 | } |
316 | return categories; | 317 | return categories; |
317 | } | 318 | } |
318 | 319 | ||
319 | private: | 320 | private: |
320 | Calendar *mCalendar; | 321 | Calendar *mCalendar; |
321 | QStringList * oldCategories; | 322 | QStringList * oldCategories; |
322 | static QString category( const QString &id ) | 323 | static QString category( const QString &id ) |
323 | { | 324 | { |
324 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); | 325 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); |
325 | if ( it == mCategoriesMap.end() ) return id; | 326 | if ( it == mCategoriesMap.end() ) return id; |
326 | else return *it; | 327 | else return *it; |
327 | } | 328 | } |
328 | 329 | ||
329 | static void setCategory( const QString &id, const QString &name ) | 330 | static void setCategory( const QString &id, const QString &name ) |
330 | { | 331 | { |
331 | mCategoriesMap.insert( id, name ); | 332 | mCategoriesMap.insert( id, name ); |
332 | } | 333 | } |
333 | 334 | ||
334 | static QMap<QString,QString> mCategoriesMap; | 335 | static QMap<QString,QString> mCategoriesMap; |
335 | }; | 336 | }; |
336 | 337 | ||
337 | QMap<QString,QString> SharpParser::mCategoriesMap; | 338 | QMap<QString,QString> SharpParser::mCategoriesMap; |
338 | 339 | ||
339 | SharpFormat::SharpFormat() | 340 | SharpFormat::SharpFormat() |
340 | { | 341 | { |
341 | mCategories = 0; | 342 | mCategories = 0; |
342 | } | 343 | } |
343 | 344 | ||
344 | SharpFormat::~SharpFormat() | 345 | SharpFormat::~SharpFormat() |
345 | { | 346 | { |
346 | } | 347 | } |
347 | ulong SharpFormat::getCsum( const QStringList & attList) | 348 | ulong SharpFormat::getCsum( const QStringList & attList) |
348 | { | 349 | { |
349 | int max = attList.count() -1; | 350 | int max = attList.count() -1; |
350 | ulong cSum = 0; | 351 | ulong cSum = 0; |
351 | int j,k,i; | 352 | int j,k,i; |
352 | int add; | 353 | int add; |
353 | for ( i = 1; i < max ; ++i ) { | 354 | for ( i = 1; i < max ; ++i ) { |
354 | QString s = attList[i]; | 355 | QString s = attList[i]; |
355 | if ( ! s.isEmpty() ){ | 356 | if ( ! s.isEmpty() ){ |
356 | j = s.length(); | 357 | j = s.length(); |
357 | for ( k = 0; k < j; ++k ) { | 358 | for ( k = 0; k < j; ++k ) { |
358 | int mul = k +1; | 359 | int mul = k +1; |
359 | add = s[k].unicode (); | 360 | add = s[k].unicode (); |
360 | if ( k < 16 ) | 361 | if ( k < 16 ) |
361 | mul = mul * mul; | 362 | mul = mul * mul; |
362 | add = add * mul *i*i*i; | 363 | add = add * mul *i*i*i; |
363 | cSum += add; | 364 | cSum += add; |
364 | } | 365 | } |
365 | } | 366 | } |
366 | } | 367 | } |
367 | return cSum; | 368 | return cSum; |
368 | 369 | ||
369 | } | 370 | } |
370 | #include <stdlib.h> | 371 | #include <stdlib.h> |
371 | #define DEBUGMODE false | 372 | //#define DEBUGMODE false |
373 | #define DEBUGMODE true | ||
372 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 374 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
373 | { | 375 | { |
374 | 376 | ||
375 | 377 | ||
376 | bool debug = DEBUGMODE; | 378 | bool debug = DEBUGMODE; |
377 | //debug = true; | ||
378 | QString text; | 379 | QString text; |
379 | QString codec = "utf8"; | 380 | QString codec = "utf8"; |
380 | QLabel status ( i18n("Reading events ..."), 0 ); | 381 | QLabel status ( i18n("Reading events ..."), 0 ); |
381 | 382 | ||
382 | int w = status.sizeHint().width()+20 ; | 383 | int w = status.sizeHint().width()+20 ; |
383 | if ( w < 200 ) w = 200; | 384 | if ( w < 200 ) w = 200; |
384 | int h = status.sizeHint().height()+20 ; | 385 | int h = status.sizeHint().height()+20 ; |
385 | int dw = QApplication::desktop()->width(); | 386 | int dw = QApplication::desktop()->width(); |
386 | int dh = QApplication::desktop()->height(); | 387 | int dh = QApplication::desktop()->height(); |
387 | status.setCaption(i18n("Reading DTM Data") ); | 388 | status.setCaption(i18n("Reading DTM Data") ); |
388 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 389 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
389 | status.show(); | 390 | status.show(); |
390 | status.raise(); | 391 | status.raise(); |
391 | qApp->processEvents(); | 392 | qApp->processEvents(); |
392 | QString fileName; | 393 | QString fileName; |
393 | if ( ! debug ) { | 394 | if ( ! debug ) { |
394 | fileName = "/tmp/kopitempout"; | 395 | fileName = "/tmp/kopitempout"; |
395 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; | 396 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; |
396 | system ( command.latin1() ); | 397 | system ( command.latin1() ); |
397 | } else { | 398 | } else { |
398 | fileName = "/tmp/events.txt"; | 399 | fileName = "/tmp/events.txt"; |
399 | 400 | ||
400 | } | 401 | } |
401 | QFile file( fileName ); | 402 | QFile file( fileName ); |
402 | if (!file.open( IO_ReadOnly ) ) { | 403 | if (!file.open( IO_ReadOnly ) ) { |
403 | return false; | 404 | return false; |
404 | 405 | ||
405 | } | 406 | } |
406 | QTextStream ts( &file ); | 407 | QTextStream ts( &file ); |
407 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 408 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
408 | text = ts.read(); | 409 | text = ts.read(); |
409 | file.close(); | 410 | file.close(); |
410 | status.setText( i18n("Processing events ...") ); | 411 | status.setText( i18n("Processing events ...") ); |
411 | status.raise(); | 412 | status.raise(); |
412 | qApp->processEvents(); | 413 | qApp->processEvents(); |
413 | fromString2Cal( calendar, existngCal, text, "Event" ); | 414 | fromString2Cal( calendar, existngCal, text, "Event" ); |
414 | status.setText( i18n("Reading todos ...") ); | 415 | status.setText( i18n("Reading todos ...") ); |
415 | qApp->processEvents(); | 416 | qApp->processEvents(); |
416 | if ( ! debug ) { | 417 | if ( ! debug ) { |
417 | fileName = "/tmp/kopitempout"; | 418 | fileName = "/tmp/kopitempout"; |
418 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; | 419 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; |
419 | system ( command.latin1() ); | 420 | system ( command.latin1() ); |
420 | } else { | 421 | } else { |
421 | fileName = "/tmp/todo.txt"; | 422 | fileName = "/tmp/todo.txt"; |
422 | } | 423 | } |
423 | file.setName( fileName ); | 424 | file.setName( fileName ); |
424 | if (!file.open( IO_ReadOnly ) ) { | 425 | if (!file.open( IO_ReadOnly ) ) { |
425 | return false; | 426 | return false; |
426 | 427 | ||
427 | } | 428 | } |
428 | ts.setDevice( &file ); | 429 | ts.setDevice( &file ); |
429 | text = ts.read(); | 430 | text = ts.read(); |
430 | file.close(); | 431 | file.close(); |
431 | 432 | ||
432 | status.setText( i18n("Processing todos ...") ); | 433 | status.setText( i18n("Processing todos ...") ); |
433 | status.raise(); | 434 | status.raise(); |
434 | qApp->processEvents(); | 435 | qApp->processEvents(); |
435 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 436 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
436 | return true; | 437 | return true; |
437 | } | 438 | } |
438 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 439 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
439 | { | 440 | { |
440 | int retval = -1; | 441 | int retval = -1; |
441 | QStringList templist; | 442 | QStringList templist; |
442 | QString tempString; | 443 | QString tempString; |
443 | int start = 0; | 444 | int start = 0; |
444 | int len = answer.length(); | 445 | int len = answer.length(); |
445 | int end = answer.find ("\n",start)+1; | 446 | int end = answer.find ("\n",start)+1; |
446 | bool ok = true; | 447 | bool ok = true; |
447 | start = end; | 448 | start = end; |
448 | int ccc = 0; | 449 | int ccc = 0; |
449 | while ( start > 0 ) { | 450 | while ( start > 0 ) { |
450 | templist.clear(); | 451 | templist.clear(); |
451 | ok = true; | 452 | ok = true; |
452 | int loopCount = 0; | 453 | int loopCount = 0; |
453 | while ( ok ) { | 454 | while ( ok ) { |
454 | ++loopCount; | 455 | ++loopCount; |
455 | if ( loopCount > 25 ) { | 456 | if ( loopCount > 25 ) { |
456 | qDebug("KO: Error in while loop"); | 457 | qDebug("KO: Error in while loop"); |
457 | ok = false; | 458 | ok = false; |
458 | start = 0; | 459 | start = 0; |
459 | break; | 460 | break; |
460 | } | 461 | } |
461 | if ( ok ) | 462 | if ( ok ) |
462 | tempString = getPart( answer, ok, start ); | 463 | tempString = getPart( answer, ok, start ); |
463 | if ( start >= len || start == 0 ) { | 464 | if ( start >= len || start == 0 ) { |
464 | start = 0; | 465 | start = 0; |
465 | ok = false; | 466 | ok = false; |
466 | } | 467 | } |
467 | if ( tempString.right(1) =="\n" ) | 468 | if ( tempString.right(1) =="\n" ) |
468 | tempString = tempString.left( tempString.length()-1); | 469 | tempString = tempString.left( tempString.length()-1); |
469 | 470 | ||
470 | templist.append( tempString ); | 471 | templist.append( tempString ); |
471 | } | 472 | } |
472 | ++ccc; | 473 | ++ccc; |
473 | if ( ccc == 2 && loopCount < 25 ) { | 474 | if ( ccc == 2 && loopCount < 25 ) { |
474 | start = 0; | 475 | start = 0; |
475 | bool ok; | 476 | bool ok; |
476 | int newnum = templist[0].toInt( &ok ); | 477 | int newnum = templist[0].toInt( &ok ); |
477 | if ( ok && newnum > 0) { | 478 | if ( ok && newnum > 0) { |
478 | retval = newnum; | 479 | retval = newnum; |
479 | inc->setID( "Sharp_DTM",templist[0] ); | 480 | inc->setID( "Sharp_DTM",templist[0] ); |
480 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 481 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
481 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 482 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
482 | } | 483 | } |
483 | } | 484 | } |
484 | } | 485 | } |
485 | //qDebug("getNumFromRecord returning : %d ", retval); | 486 | //qDebug("getNumFromRecord returning : %d ", retval); |
486 | return retval; | 487 | return retval; |
487 | } | 488 | } |
488 | bool SharpFormat::save( Calendar *calendar) | 489 | bool SharpFormat::save( Calendar *calendar) |
489 | { | 490 | { |
490 | 491 | ||
491 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 492 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
492 | int w = status.sizeHint().width()+20 ; | 493 | int w = status.sizeHint().width()+20 ; |
493 | if ( w < 200 ) w = 200; | 494 | if ( w < 200 ) w = 200; |
494 | int h = status.sizeHint().height()+20 ; | 495 | int h = status.sizeHint().height()+20 ; |
495 | int dw = QApplication::desktop()->width(); | 496 | int dw = QApplication::desktop()->width(); |
496 | int dh = QApplication::desktop()->height(); | 497 | int dh = QApplication::desktop()->height(); |
497 | status.setCaption(i18n("Writing DTM Data") ); | 498 | status.setCaption(i18n("Writing DTM Data") ); |
498 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 499 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
499 | status.show(); | 500 | status.show(); |
500 | status.raise(); | 501 | status.raise(); |
501 | qApp->processEvents(); | 502 | qApp->processEvents(); |
502 | bool debug = DEBUGMODE; | 503 | bool debug = DEBUGMODE; |
503 | QString codec = "utf8"; | 504 | QString codec = "utf8"; |
504 | QString answer; | 505 | QString answer; |
505 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 506 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
506 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 507 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
507 | QString command; | 508 | QString command; |
508 | QPtrList<Event> er = calendar->rawEvents(); | 509 | QPtrList<Event> er = calendar->rawEvents(); |
509 | Event* ev = er.first(); | 510 | Event* ev = er.first(); |
510 | QString fileName = "/tmp/kopitempout"; | 511 | QString fileName = "/tmp/kopitempout"; |
511 | int i = 0; | 512 | int i = 0; |
512 | QString changeString = ePrefix; | 513 | QString changeString = ePrefix; |
513 | QString deleteString = ePrefix; | 514 | QString deleteString = ePrefix; |
514 | bool deleteEnt = false; | 515 | bool deleteEnt = false; |
515 | bool changeEnt = false; | 516 | bool changeEnt = false; |
516 | QString message = i18n("Processing event # "); | 517 | QString message = i18n("Processing event # "); |
517 | int procCount = 0; | 518 | int procCount = 0; |
518 | while ( ev ) { | 519 | while ( ev ) { |
519 | //qDebug("i %d ", ++i); | 520 | //qDebug("i %d ", ++i); |
520 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 521 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
521 | status.setText ( message + QString::number ( ++procCount ) ); | 522 | status.setText ( message + QString::number ( ++procCount ) ); |
522 | qApp->processEvents(); | 523 | qApp->processEvents(); |
523 | QString eString = getEventString( ev ); | 524 | QString eString = getEventString( ev ); |
524 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 525 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
525 | // deleting empty strings does not work. | 526 | // deleting empty strings does not work. |
526 | // we write first and x and then delete the record with the x | 527 | // we write first and x and then delete the record with the x |
527 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 528 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
528 | changeString += eString + "\n"; | 529 | changeString += eString + "\n"; |
529 | deleteString += eString + "\n"; | 530 | deleteString += eString + "\n"; |
530 | deleteEnt = true; | 531 | deleteEnt = true; |
531 | changeEnt = true; | 532 | changeEnt = true; |
532 | } | 533 | } |
533 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 534 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
534 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 535 | command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
535 | system ( command.utf8() ); | 536 | system ( command.utf8() ); |
536 | QFile file( fileName ); | 537 | QFile file( fileName ); |
537 | if (!file.open( IO_ReadOnly ) ) { | 538 | if (!file.open( IO_ReadOnly ) ) { |
538 | return false; | 539 | return false; |
539 | 540 | ||
540 | } | 541 | } |
541 | QTextStream ts( &file ); | 542 | QTextStream ts( &file ); |
542 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 543 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
543 | answer = ts.read(); | 544 | answer = ts.read(); |
544 | file.close(); | 545 | file.close(); |
545 | //qDebug("answer \n%s ", answer.latin1()); | 546 | //qDebug("answer \n%s ", answer.latin1()); |
546 | getNumFromRecord( answer, ev ) ; | 547 | getNumFromRecord( answer, ev ) ; |
547 | 548 | ||
548 | } | 549 | } |
549 | else { // change existing | 550 | else { // change existing |
550 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 551 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
551 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 552 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
552 | changeString += eString + "\n"; | 553 | changeString += eString + "\n"; |
553 | changeEnt = true; | 554 | changeEnt = true; |
554 | 555 | ||
555 | } | 556 | } |
556 | } | 557 | } |
557 | ev = er.next(); | 558 | ev = er.next(); |
558 | } | 559 | } |
559 | status.setText ( i18n("Changing events ...") ); | 560 | status.setText ( i18n("Changing events ...") ); |
560 | qApp->processEvents(); | 561 | qApp->processEvents(); |
561 | //qDebug("changing... "); | 562 | //qDebug("changing... "); |
562 | if ( changeEnt ) { | 563 | if ( changeEnt ) { |
563 | QFile file( fileName ); | 564 | QFile file( fileName ); |
564 | if (!file.open( IO_WriteOnly ) ) { | 565 | if (!file.open( IO_WriteOnly ) ) { |
565 | return false; | 566 | return false; |
566 | 567 | ||
567 | } | 568 | } |
568 | QTextStream ts( &file ); | 569 | QTextStream ts( &file ); |
569 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 570 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
570 | ts << changeString ; | 571 | ts << changeString ; |
571 | file.close(); | 572 | file.close(); |
572 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 573 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
573 | system ( command.latin1() ); | 574 | system ( command.latin1() ); |
574 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 575 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
575 | 576 | ||
576 | } | 577 | } |
577 | status.setText ( i18n("Deleting events ...") ); | 578 | status.setText ( i18n("Deleting events ...") ); |
578 | qApp->processEvents(); | 579 | qApp->processEvents(); |
579 | //qDebug("deleting... "); | 580 | //qDebug("deleting... "); |
580 | if ( deleteEnt ) { | 581 | if ( deleteEnt ) { |
581 | QFile file( fileName ); | 582 | QFile file( fileName ); |
582 | if (!file.open( IO_WriteOnly ) ) { | 583 | if (!file.open( IO_WriteOnly ) ) { |
583 | return false; | 584 | return false; |
584 | 585 | ||
585 | } | 586 | } |
586 | QTextStream ts( &file ); | 587 | QTextStream ts( &file ); |
587 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 588 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
588 | ts << deleteString; | 589 | ts << deleteString; |
589 | file.close(); | 590 | file.close(); |
590 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 591 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
591 | system ( command.latin1() ); | 592 | system ( command.latin1() ); |
592 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 593 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
593 | } | 594 | } |
594 | 595 | ||
595 | 596 | ||
596 | changeString = tPrefix; | 597 | changeString = tPrefix; |
597 | deleteString = tPrefix; | 598 | deleteString = tPrefix; |
598 | status.setText ( i18n("Processing todos ...") ); | 599 | status.setText ( i18n("Processing todos ...") ); |
599 | qApp->processEvents(); | 600 | qApp->processEvents(); |
600 | QPtrList<Todo> tl = calendar->rawTodos(); | 601 | QPtrList<Todo> tl = calendar->rawTodos(); |
601 | Todo* to = tl.first(); | 602 | Todo* to = tl.first(); |
602 | i = 0; | 603 | i = 0; |
603 | message = i18n("Processing todo # "); | 604 | message = i18n("Processing todo # "); |
604 | procCount = 0; | 605 | procCount = 0; |
605 | while ( to ) { | 606 | while ( to ) { |
606 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 607 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
607 | status.setText ( message + QString::number ( ++procCount ) ); | 608 | status.setText ( message + QString::number ( ++procCount ) ); |
608 | qApp->processEvents(); | 609 | qApp->processEvents(); |
609 | QString eString = getTodoString( to ); | 610 | QString eString = getTodoString( to ); |
610 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 611 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
611 | // deleting empty strings does not work. | 612 | // deleting empty strings does not work. |
612 | // we write first and x and then delete the record with the x | 613 | // we write first and x and then delete the record with the x |
613 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 614 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
614 | changeString += eString + "\n"; | 615 | changeString += eString + "\n"; |
615 | deleteString += eString + "\n"; | 616 | deleteString += eString + "\n"; |
616 | deleteEnt = true; | 617 | deleteEnt = true; |
617 | changeEnt = true; | 618 | changeEnt = true; |
618 | } | 619 | } |
619 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 620 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
620 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; | 621 | command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; |
621 | system ( command.utf8() ); | 622 | system ( command.utf8() ); |
622 | QFile file( fileName ); | 623 | QFile file( fileName ); |
623 | if (!file.open( IO_ReadOnly ) ) { | 624 | if (!file.open( IO_ReadOnly ) ) { |
624 | return false; | 625 | return false; |
625 | 626 | ||
626 | } | 627 | } |
627 | QTextStream ts( &file ); | 628 | QTextStream ts( &file ); |
628 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 629 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
629 | answer = ts.read(); | 630 | answer = ts.read(); |
630 | file.close(); | 631 | file.close(); |
631 | //qDebug("answer \n%s ", answer.latin1()); | 632 | //qDebug("answer \n%s ", answer.latin1()); |
632 | getNumFromRecord( answer, to ) ; | 633 | getNumFromRecord( answer, to ) ; |
633 | 634 | ||
634 | } | 635 | } |
635 | else { // change existing | 636 | else { // change existing |
636 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 637 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
637 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 638 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
638 | changeString += eString + "\n"; | 639 | changeString += eString + "\n"; |
639 | changeEnt = true; | 640 | changeEnt = true; |
640 | 641 | ||
641 | } | 642 | } |
642 | } | 643 | } |
643 | 644 | ||
644 | to = tl.next(); | 645 | to = tl.next(); |
645 | } | 646 | } |
646 | status.setText ( i18n("Changing todos ...") ); | 647 | status.setText ( i18n("Changing todos ...") ); |
647 | qApp->processEvents(); | 648 | qApp->processEvents(); |
648 | //qDebug("changing... "); | 649 | //qDebug("changing... "); |
649 | if ( changeEnt ) { | 650 | if ( changeEnt ) { |
650 | QFile file( fileName ); | 651 | QFile file( fileName ); |
651 | if (!file.open( IO_WriteOnly ) ) { | 652 | if (!file.open( IO_WriteOnly ) ) { |
652 | return false; | 653 | return false; |
653 | 654 | ||
654 | } | 655 | } |
655 | QTextStream ts( &file ); | 656 | QTextStream ts( &file ); |
656 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 657 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
657 | ts << changeString ; | 658 | ts << changeString ; |
658 | file.close(); | 659 | file.close(); |
659 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 660 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
660 | system ( command.latin1() ); | 661 | system ( command.latin1() ); |
661 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 662 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
662 | 663 | ||
663 | } | 664 | } |
664 | status.setText ( i18n("Deleting todos ...") ); | 665 | status.setText ( i18n("Deleting todos ...") ); |
665 | qApp->processEvents(); | 666 | qApp->processEvents(); |
666 | //qDebug("deleting... "); | 667 | //qDebug("deleting... "); |
667 | if ( deleteEnt ) { | 668 | if ( deleteEnt ) { |
668 | QFile file( fileName ); | 669 | QFile file( fileName ); |
669 | if (!file.open( IO_WriteOnly ) ) { | 670 | if (!file.open( IO_WriteOnly ) ) { |
670 | return false; | 671 | return false; |
671 | 672 | ||
672 | } | 673 | } |
673 | QTextStream ts( &file ); | 674 | QTextStream ts( &file ); |
674 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 675 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
675 | ts << deleteString; | 676 | ts << deleteString; |
676 | file.close(); | 677 | file.close(); |
677 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 678 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
678 | system ( command.latin1() ); | 679 | system ( command.latin1() ); |
679 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 680 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
680 | } | 681 | } |
681 | 682 | ||
682 | return true; | 683 | return true; |
683 | } | 684 | } |
684 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 685 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
685 | { | 686 | { |
686 | QString datestr; | 687 | QString datestr; |
687 | QString timestr; | 688 | QString timestr; |
688 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 689 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
689 | QDateTime dt; | 690 | QDateTime dt; |
690 | if (useTZ) | 691 | if (useTZ) |
691 | dt = dti.addSecs ( -(offset*60)); | 692 | dt = dti.addSecs ( -(offset*60)); |
692 | else | 693 | else |
693 | dt = dti; | 694 | dt = dti; |
694 | if(dt.date().isValid()){ | 695 | if(dt.date().isValid()){ |
695 | const QDate& date = dt.date(); | 696 | const QDate& date = dt.date(); |
696 | datestr.sprintf("%04d%02d%02d", | 697 | datestr.sprintf("%04d%02d%02d", |
697 | date.year(), date.month(), date.day()); | 698 | date.year(), date.month(), date.day()); |
698 | } | 699 | } |
699 | if(dt.time().isValid()){ | 700 | if(dt.time().isValid()){ |
700 | const QTime& time = dt.time(); | 701 | const QTime& time = dt.time(); |
701 | timestr.sprintf("T%02d%02d%02d", | 702 | timestr.sprintf("T%02d%02d%02d", |
702 | time.hour(), time.minute(), time.second()); | 703 | time.hour(), time.minute(), time.second()); |
703 | } | 704 | } |
704 | return datestr + timestr; | 705 | return datestr + timestr; |
705 | } | 706 | } |
706 | QString SharpFormat::getEventString( Event* event ) | 707 | QString SharpFormat::getEventString( Event* event ) |
707 | { | 708 | { |
708 | QStringList list; | 709 | QStringList list; |
709 | list.append( event->getID("Sharp_DTM") ); | 710 | list.append( event->getID("Sharp_DTM") ); |
710 | list.append( event->categories().join(",") ); | 711 | list.append( event->categories().join(",") ); |
711 | if ( !event->summary().isEmpty() ) | 712 | if ( !event->summary().isEmpty() ) |
712 | list.append( event->summary() ); | 713 | list.append( event->summary() ); |
713 | else | 714 | else |
714 | list.append("" ); | 715 | list.append("" ); |
715 | if ( !event->location().isEmpty() ) | 716 | if ( !event->location().isEmpty() ) |
716 | list.append( event->location() ); | 717 | list.append( event->location() ); |
717 | else | 718 | else |
718 | list.append("" ); | 719 | list.append("" ); |
719 | if ( !event->description().isEmpty() ) | 720 | if ( !event->description().isEmpty() ) |
720 | list.append( event->description() ); | 721 | list.append( event->description() ); |
721 | else | 722 | else |
722 | list.append( "" ); | 723 | list.append( "" ); |
723 | if ( event->doesFloat () ) { | 724 | if ( event->doesFloat () ) { |
724 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 725 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
725 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 726 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
726 | list.append( "1" ); | 727 | list.append( "1" ); |
727 | 728 | ||
728 | } | 729 | } |
729 | else { | 730 | else { |
730 | list.append( dtToString( event->dtStart()) ); | 731 | list.append( dtToString( event->dtStart()) ); |
731 | list.append( dtToString( event->dtEnd()) ); //6 | 732 | list.append( dtToString( event->dtEnd()) ); //6 |
732 | list.append( "0" ); | 733 | list.append( "0" ); |
733 | } | 734 | } |
734 | bool noAlarm = true; | 735 | bool noAlarm = true; |
735 | if ( event->alarms().count() > 0 ) { | 736 | if ( event->alarms().count() > 0 ) { |
736 | Alarm * al = event->alarms().first(); | 737 | Alarm * al = event->alarms().first(); |
737 | if ( al->enabled() ) { | 738 | if ( al->enabled() ) { |
738 | noAlarm = false; | 739 | noAlarm = false; |
739 | list.append( "0" ); // yes, 0 == alarm | 740 | list.append( "0" ); // yes, 0 == alarm |
740 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 741 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
741 | if ( al->type() == Alarm::Audio ) | 742 | if ( al->type() == Alarm::Audio ) |
742 | list.append( "1" ); // type audio | 743 | list.append( "1" ); // type audio |
743 | else | 744 | else |
744 | list.append( "0" ); // type silent | 745 | list.append( "0" ); // type silent |
745 | } | 746 | } |
746 | } | 747 | } |
747 | if ( noAlarm ) { | 748 | if ( noAlarm ) { |
748 | list.append( "1" ); // yes, 1 == no alarm | 749 | list.append( "1" ); // yes, 1 == no alarm |
749 | list.append( "0" ); // no alarm offset | 750 | list.append( "0" ); // no alarm offset |
750 | list.append( "1" ); // type | 751 | list.append( "1" ); // type |
751 | } | 752 | } |
752 | // next is: 11 | 753 | // next is: 11 |
753 | // next is: 11-16 are recurrence | 754 | // next is: 11-16 are recurrence |
754 | Recurrence* rec = event->recurrence(); | 755 | Recurrence* rec = event->recurrence(); |
755 | 756 | ||
756 | bool writeEndDate = false; | 757 | bool writeEndDate = false; |
757 | switch ( rec->doesRecur() ) | 758 | switch ( rec->doesRecur() ) |
758 | { | 759 | { |
759 | case Recurrence::rDaily: // 0 | 760 | case Recurrence::rDaily: // 0 |
760 | list.append( "0" ); | 761 | list.append( "0" ); |
761 | list.append( QString::number( rec->frequency() ));//12 | 762 | list.append( QString::number( rec->frequency() ));//12 |
762 | list.append( "0" ); | 763 | list.append( "0" ); |
763 | list.append( "0" ); | 764 | list.append( "0" ); |
764 | writeEndDate = true; | 765 | writeEndDate = true; |
765 | break; | 766 | break; |
766 | case Recurrence::rWeekly:// 1 | 767 | case Recurrence::rWeekly:// 1 |
767 | list.append( "1" ); | 768 | list.append( "1" ); |
768 | list.append( QString::number( rec->frequency()) );//12 | 769 | list.append( QString::number( rec->frequency()) );//12 |
769 | list.append( "0" ); | 770 | list.append( "0" ); |
770 | { | 771 | { |
771 | int days = 0; | 772 | int days = 0; |
772 | QBitArray weekDays = rec->days(); | 773 | QBitArray weekDays = rec->days(); |
773 | int i; | 774 | int i; |
774 | for( i = 1; i <= 7; ++i ) { | 775 | for( i = 1; i <= 7; ++i ) { |
775 | if ( weekDays[i-1] ) { | 776 | if ( weekDays[i-1] ) { |
776 | days += 1 << (i-1); | 777 | days += 1 << (i-1); |
777 | } | 778 | } |
778 | } | 779 | } |
779 | list.append( QString::number( days ) ); | 780 | list.append( QString::number( days ) ); |
780 | } | 781 | } |
781 | //pending weekdays | 782 | //pending weekdays |
782 | writeEndDate = true; | 783 | writeEndDate = true; |
783 | 784 | ||
784 | break; | 785 | break; |
785 | case Recurrence::rMonthlyPos:// 2 | 786 | case Recurrence::rMonthlyPos:// 2 |
786 | list.append( "2" ); | 787 | list.append( "2" ); |
787 | list.append( QString::number( rec->frequency()) );//12 | 788 | list.append( QString::number( rec->frequency()) );//12 |
788 | 789 | ||
789 | writeEndDate = true; | 790 | writeEndDate = true; |
790 | { | 791 | { |
791 | int count = 1; | 792 | int count = 1; |
792 | QPtrList<Recurrence::rMonthPos> rmp; | 793 | QPtrList<Recurrence::rMonthPos> rmp; |
793 | rmp = rec->monthPositions(); | 794 | rmp = rec->monthPositions(); |
794 | if ( rmp.first()->negative ) | 795 | if ( rmp.first()->negative ) |
795 | count = 5 - rmp.first()->rPos - 1; | 796 | count = 5 - rmp.first()->rPos - 1; |
796 | else | 797 | else |
797 | count = rmp.first()->rPos - 1; | 798 | count = rmp.first()->rPos - 1; |
798 | list.append( QString::number( count ) ); | 799 | list.append( QString::number( count ) ); |
799 | 800 | ||
800 | } | 801 | } |
801 | 802 | ||
802 | list.append( "0" ); | 803 | list.append( "0" ); |
803 | break; | 804 | break; |
804 | case Recurrence::rMonthlyDay:// 3 | 805 | case Recurrence::rMonthlyDay:// 3 |
805 | list.append( "3" ); | 806 | list.append( "3" ); |
806 | list.append( QString::number( rec->frequency()) );//12 | 807 | list.append( QString::number( rec->frequency()) );//12 |
807 | list.append( "0" ); | 808 | list.append( "0" ); |
808 | list.append( "0" ); | 809 | list.append( "0" ); |
809 | writeEndDate = true; | 810 | writeEndDate = true; |
810 | break; | 811 | break; |
811 | case Recurrence::rYearlyMonth://4 | 812 | case Recurrence::rYearlyMonth://4 |
812 | list.append( "4" ); | 813 | list.append( "4" ); |
813 | list.append( QString::number( rec->frequency()) );//12 | 814 | list.append( QString::number( rec->frequency()) );//12 |
814 | list.append( "0" ); | 815 | list.append( "0" ); |
815 | list.append( "0" ); | 816 | list.append( "0" ); |
816 | writeEndDate = true; | 817 | writeEndDate = true; |
817 | break; | 818 | break; |
818 | 819 | ||
819 | default: | 820 | default: |
820 | list.append( "255" ); | 821 | list.append( "255" ); |
821 | list.append( QString() ); | 822 | list.append( QString() ); |
822 | list.append( "0" ); | 823 | list.append( "0" ); |
823 | list.append( QString() ); | 824 | list.append( QString() ); |
824 | list.append( "0" ); | 825 | list.append( "0" ); |
825 | list.append( "20991231T000000" ); | 826 | list.append( "20991231T000000" ); |
826 | break; | 827 | break; |
827 | } | 828 | } |
828 | if ( writeEndDate ) { | 829 | if ( writeEndDate ) { |
829 | 830 | ||
830 | if ( rec->endDate().isValid() ) { // 15 + 16 | 831 | if ( rec->endDate().isValid() ) { // 15 + 16 |
831 | list.append( "1" ); | 832 | list.append( "1" ); |
832 | list.append( dtToString( rec->endDate()) ); | 833 | list.append( dtToString( rec->endDate()) ); |
833 | } else { | 834 | } else { |
834 | list.append( "0" ); | 835 | list.append( "0" ); |
835 | list.append( "20991231T000000" ); | 836 | list.append( "20991231T000000" ); |
836 | } | 837 | } |
837 | 838 | ||
838 | } | 839 | } |
839 | if ( event->doesFloat () ) { | 840 | if ( event->doesFloat () ) { |
840 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | 841 | list.append( dtToString( event->dtStart(), false ).left( 8 )); |
841 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | 842 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 |
842 | 843 | ||
843 | } | 844 | } |
844 | else { | 845 | else { |
845 | list.append( QString() ); | 846 | list.append( QString() ); |
846 | list.append( QString() ); | 847 | list.append( QString() ); |
847 | 848 | ||
848 | } | 849 | } |
849 | if (event->dtStart().date() == event->dtEnd().date() ) | 850 | if (event->dtStart().date() == event->dtEnd().date() ) |
850 | list.append( "0" ); | 851 | list.append( "0" ); |
851 | else | 852 | else |
852 | list.append( "1" ); | 853 | list.append( "1" ); |
853 | 854 | ||
854 | 855 | ||
855 | for(QStringList::Iterator it=list.begin(); | 856 | for(QStringList::Iterator it=list.begin(); |
856 | it!=list.end(); ++it){ | 857 | it!=list.end(); ++it){ |
857 | QString& s = (*it); | 858 | QString& s = (*it); |
858 | s.replace(QRegExp("\""), "\"\""); | 859 | s.replace(QRegExp("\""), "\"\""); |
859 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 860 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
860 | s.prepend('\"'); | 861 | s.prepend('\"'); |
861 | s.append('\"'); | 862 | s.append('\"'); |
862 | } else if(s.isEmpty() && !s.isNull()){ | 863 | } else if(s.isEmpty() && !s.isNull()){ |
863 | s = "\"\""; | 864 | s = "\"\""; |
864 | } | 865 | } |
865 | } | 866 | } |
866 | return list.join(","); | 867 | return list.join(","); |
867 | 868 | ||
868 | 869 | ||
869 | } | 870 | } |
870 | QString SharpFormat::getTodoString( Todo* todo ) | 871 | QString SharpFormat::getTodoString( Todo* todo ) |
871 | { | 872 | { |
872 | QStringList list; | 873 | QStringList list; |
873 | list.append( todo->getID("Sharp_DTM") ); | 874 | list.append( todo->getID("Sharp_DTM") ); |
874 | list.append( todo->categories().join(",") ); | 875 | list.append( todo->categories().join(",") ); |
875 | 876 | ||
876 | if ( todo->hasStartDate() ) { | 877 | if ( todo->hasStartDate() ) { |
877 | list.append( dtToString( todo->dtStart()) ); | 878 | list.append( dtToString( todo->dtStart()) ); |
878 | } else | 879 | } else |
879 | list.append( QString() ); | 880 | list.append( QString() ); |
880 | 881 | ||
881 | if ( todo->hasDueDate() ) { | 882 | if ( todo->hasDueDate() ) { |
882 | QTime tim; | 883 | QTime tim; |
883 | if ( todo->doesFloat()) { | 884 | if ( todo->doesFloat()) { |
884 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | 885 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; |
885 | } else { | 886 | } else { |
886 | list.append( dtToString(todo->dtDue() ) ); | 887 | list.append( dtToString(todo->dtDue() ) ); |
887 | } | 888 | } |
888 | } else | 889 | } else |
889 | list.append( QString() ); | 890 | list.append( QString() ); |
890 | 891 | ||
891 | if ( todo->isCompleted() ) { | 892 | if ( todo->isCompleted() ) { |
892 | list.append( dtToString( todo->completed()) ); | 893 | list.append( dtToString( todo->completed()) ); |
893 | list.append( "0" ); // yes 0 == completed | 894 | list.append( "0" ); // yes 0 == completed |
894 | } else { | 895 | } else { |
895 | list.append( dtToString( todo->completed()) ); | 896 | list.append( dtToString( todo->completed()) ); |
896 | list.append( "1" ); | 897 | list.append( "1" ); |
897 | } | 898 | } |
898 | list.append( QString::number( todo->priority() )); | 899 | list.append( QString::number( todo->priority() )); |
899 | if( ! todo->summary().isEmpty() ) | 900 | if( ! todo->summary().isEmpty() ) |
900 | list.append( todo->summary() ); | 901 | list.append( todo->summary() ); |
901 | else | 902 | else |
902 | list.append( "" ); | 903 | list.append( "" ); |
903 | if (! todo->description().isEmpty() ) | 904 | if (! todo->description().isEmpty() ) |
904 | list.append( todo->description() ); | 905 | list.append( todo->description() ); |
905 | else | 906 | else |
906 | list.append( "" ); | 907 | list.append( "" ); |
907 | for(QStringList::Iterator it=list.begin(); | 908 | for(QStringList::Iterator it=list.begin(); |
908 | it!=list.end(); ++it){ | 909 | it!=list.end(); ++it){ |
909 | QString& s = (*it); | 910 | QString& s = (*it); |
910 | s.replace(QRegExp("\""), "\"\""); | 911 | s.replace(QRegExp("\""), "\"\""); |
911 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 912 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
912 | s.prepend('\"'); | 913 | s.prepend('\"'); |
913 | s.append('\"'); | 914 | s.append('\"'); |
914 | } else if(s.isEmpty() && !s.isNull()){ | 915 | } else if(s.isEmpty() && !s.isNull()){ |
915 | s = "\"\""; | 916 | s = "\"\""; |
916 | } | 917 | } |
917 | } | 918 | } |
918 | return list.join(","); | 919 | return list.join(","); |
919 | } | 920 | } |
920 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) | 921 | QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) |
921 | { | 922 | { |
922 | //qDebug("start %d ", start); | 923 | //qDebug("start %d ", start); |
923 | 924 | ||
924 | QString retval =""; | 925 | QString retval =""; |
925 | if ( text.at(start) == '"' ) { | 926 | if ( text.at(start) == '"' ) { |
926 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { | 927 | if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { |
927 | start = start +2; | 928 | start = start +2; |
928 | if ( text.mid( start,1) == "," ) { | 929 | if ( text.mid( start,1) == "," ) { |
929 | start += 1; | 930 | start += 1; |
930 | } | 931 | } |
931 | retval = ""; | 932 | retval = ""; |
932 | if ( text.mid( start,1) == "\n" ) { | 933 | if ( text.mid( start,1) == "\n" ) { |
933 | start += 1; | 934 | start += 1; |
934 | ok = false; | 935 | ok = false; |
935 | } | 936 | } |
936 | return retval; | 937 | return retval; |
937 | } | 938 | } |
938 | int hk = start+1; | 939 | int hk = start+1; |
939 | hk = text.find ('"',hk); | 940 | hk = text.find ('"',hk); |
940 | while ( text.at(hk+1) == '"' ) | 941 | while ( text.at(hk+1) == '"' ) |
941 | hk = text.find ('"',hk+2); | 942 | hk = text.find ('"',hk+2); |
942 | retval = text.mid( start+1, hk-start-1); | 943 | retval = text.mid( start+1, hk-start-1); |
943 | start = hk+1; | 944 | start = hk+1; |
944 | retval.replace( QRegExp("\"\""), "\""); | 945 | retval.replace( QRegExp("\"\""), "\""); |
945 | if ( text.mid( start,1) == "," ) { | 946 | if ( text.mid( start,1) == "," ) { |
946 | start += 1; | 947 | start += 1; |
947 | } | 948 | } |
948 | if ( text.mid( start,1) == "\n" ) { | 949 | if ( text.mid( start,1) == "\n" ) { |
949 | start += 1; | 950 | start += 1; |
950 | ok = false; | 951 | ok = false; |
951 | } | 952 | } |
952 | //qDebug("retval***%s*** ",retval.latin1() ); | 953 | //qDebug("retval***%s*** ",retval.latin1() ); |
953 | return retval; | 954 | return retval; |
954 | 955 | ||
955 | } else { | 956 | } else { |
956 | int nl = text.find ("\n",start); | 957 | int nl = text.find ("\n",start); |
957 | int kom = text.find (',',start); | 958 | int kom = text.find (',',start); |
958 | if ( kom < nl ) { | 959 | if ( kom < nl ) { |
959 | // qDebug("kom < nl %d ", kom); | 960 | // qDebug("kom < nl %d ", kom); |
960 | retval = text.mid(start, kom-start); | 961 | retval = text.mid(start, kom-start); |
961 | start = kom+1; | 962 | start = kom+1; |
962 | return retval; | 963 | return retval; |
963 | } else { | 964 | } else { |
964 | if ( nl == kom ) { | 965 | if ( nl == kom ) { |
965 | // qDebug(" nl == kom "); | 966 | // qDebug(" nl == kom "); |
966 | start = 0; | 967 | start = 0; |
967 | ok = false; | 968 | ok = false; |
968 | return "0"; | 969 | return "0"; |
969 | } | 970 | } |
970 | // qDebug(" nl < kom ", nl); | 971 | // qDebug(" nl < kom ", nl); |
971 | retval = text.mid( start, nl-start); | 972 | retval = text.mid( start, nl-start); |
972 | ok = false; | 973 | ok = false; |
973 | start = nl+1; | 974 | start = nl+1; |
974 | return retval; | 975 | return retval; |
975 | } | 976 | } |
976 | } | 977 | } |
977 | } | 978 | } |
978 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) | 979 | bool SharpFormat::fromString( Calendar *calendar, const QString & text) |
979 | { | 980 | { |
980 | return false; | 981 | return false; |
981 | } | 982 | } |
982 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) | 983 | bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) |
983 | { | 984 | { |
984 | // qDebug("test %s ", text.latin1()); | 985 | // qDebug("test %s ", text.latin1()); |
985 | QStringList templist; | 986 | QStringList templist; |
986 | QString tempString; | 987 | QString tempString; |
987 | int start = 0; | 988 | int start = 0; |
988 | int len = text.length(); | 989 | int len = text.length(); |
989 | int end = text.find ("\n",start)+1; | 990 | int end = text.find ("\n",start)+1; |
990 | bool ok = true; | 991 | bool ok = true; |
991 | start = end; | 992 | start = end; |
992 | SharpParser handler( calendar ); | 993 | SharpParser handler( calendar ); |
993 | handler.setCategoriesList( mCategories ); | 994 | handler.setCategoriesList( mCategories ); |
994 | while ( start > 0 ) { | 995 | while ( start > 0 ) { |
995 | templist.clear(); | 996 | templist.clear(); |
996 | ok = true; | 997 | ok = true; |
997 | while ( ok ) { | 998 | while ( ok ) { |
998 | tempString = getPart( text, ok, start ); | 999 | tempString = getPart( text, ok, start ); |
999 | if ( start >= len || start == 0 ) { | 1000 | if ( start >= len || start == 0 ) { |
1000 | start = 0; | 1001 | start = 0; |
1001 | ok = false; | 1002 | ok = false; |
1002 | } | 1003 | } |
1003 | if ( tempString.right(1) =="\n" ) | 1004 | if ( tempString.right(1) =="\n" ) |
1004 | tempString = tempString.left( tempString.length()-1); | 1005 | tempString = tempString.left( tempString.length()-1); |
1005 | //if ( ok ) | 1006 | //if ( ok ) |
1006 | templist.append( tempString ); | 1007 | templist.append( tempString ); |
1007 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); | 1008 | //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); |
1008 | } | 1009 | } |
1009 | handler.startElement( existingCalendar, templist, type ); | 1010 | handler.startElement( existingCalendar, templist, type ); |
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | return false; | 1013 | return false; |
1013 | } | 1014 | } |
1014 | 1015 | ||
1015 | QString SharpFormat::toString( Calendar * ) | 1016 | QString SharpFormat::toString( Calendar * ) |
1016 | { | 1017 | { |
1017 | return QString::null; | 1018 | return QString::null; |
1018 | } | 1019 | } |