summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-07-10 20:11:56 (UTC)
committer zautrix <zautrix>2005-07-10 20:11:56 (UTC)
commitf06311e58cb5887fd673eb1c2c48acf7cd987ad9 (patch) (unidiff)
tree301c74302cdddaa3716d79117023228005ebd265
parentcb784d21ad22ab72a4e3231974f67816185675fd (diff)
downloadkdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.zip
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.gz
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.bz2
smarter faster conflict search
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--bin/kdepim/WhatsNew.txt1
-rw-r--r--korganizer/calendarview.cpp72
-rw-r--r--libkcal/event.cpp20
-rw-r--r--libkcal/event.h1
4 files changed, 71 insertions, 23 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt
index 1f06f1e..c0d63e5 100644
--- a/bin/kdepim/WhatsNew.txt
+++ b/bin/kdepim/WhatsNew.txt
@@ -1,273 +1,274 @@
1Info about the changes in new versions of KDE-Pim/Pi 1Info about the changes in new versions of KDE-Pim/Pi
2 2
3********** VERSION 2.1.16 ************ 3********** VERSION 2.1.16 ************
4 4
5Fixed a problem with the menu bar in KO/Pi and using the "Menu" hardware key on the Zaurus. 5Fixed a problem with the menu bar in KO/Pi and using the "Menu" hardware key on the Zaurus.
6Added columns for datetime in todo view: Last modified, created and last modified subtodo 6Added columns for datetime in todo view: Last modified, created and last modified subtodo
7Fixed a bug in agenda view displaying recurring multiday events which are longer than two days. 7Fixed a bug in agenda view displaying recurring multiday events which are longer than two days.
8Made conflict detection up to 4 times faster.
8 9
9********** VERSION 2.1.15 ************ 10********** VERSION 2.1.15 ************
10 11
11Fixed two layout problems on the Z: 12Fixed two layout problems on the Z:
12Made the with of the newly added buttons on the Quick-Todo smaller. 13Made the with of the newly added buttons on the Quick-Todo smaller.
13Made listweek layout in 2 columns on the Z760 in portait screen and full menubar visible. 14Made listweek layout in 2 columns on the Z760 in portait screen and full menubar visible.
14 15
15 16
16********** VERSION 2.1.14 ************ 17********** VERSION 2.1.14 ************
17 18
18Added some buttons to the KO/Pi Quick-todo line to make it possible to quickly access some todo view layout settings like display all flat/open/close and hide/show running/done. 19Added some buttons to the KO/Pi Quick-todo line to make it possible to quickly access some todo view layout settings like display all flat/open/close and hide/show running/done.
19Added a button to add a subtodo quickly. 20Added a button to add a subtodo quickly.
20 21
21Added a possibility to search for conflicting events. (In the Action menu. Keyboard shortcut "q", shift+q or ctrl +q ). 22Added a possibility to search for conflicting events. (In the Action menu. Keyboard shortcut "q", shift+q or ctrl +q ).
22Added an option to change the layout of the list week to column mode. 23Added an option to change the layout of the list week to column mode.
23 24
24Fixed some usability problems in pi-sync mode by adding some progress information about file transfer. 25Fixed some usability problems in pi-sync mode by adding some progress information about file transfer.
25 26
26Fixed pi-sync problems with the new multi calendar feature. 27Fixed pi-sync problems with the new multi calendar feature.
27Now pi-sync behaviour should be: 28Now pi-sync behaviour should be:
281) Local sends file request ( as usual ) 291) Local sends file request ( as usual )
292) Remote sends file which contains data of all enabled ( the calendar where the "eye" column is checked ) calendars. 302) Remote sends file which contains data of all enabled ( the calendar where the "eye" column is checked ) calendars.
303) Local syncs with data, adds new entries to default calendar and sends file back ( as usual ). 313) Local syncs with data, adds new entries to default calendar and sends file back ( as usual ).
31 If the data which local receives contains entries which are on disabled calendars on local this entries are updated and not added as duplicates to the default calendar. 32 If the data which local receives contains entries which are on disabled calendars on local this entries are updated and not added as duplicates to the default calendar.
324) Remote updates the data and adds new entries to default calendar. Readonly entries are not changed on remote. 334) Remote updates the data and adds new entries to default calendar. Readonly entries are not changed on remote.
33 If the data which remote receives contains entries which are on disabled calendars on remote this entries are updated and not added as duplicates to the default calendar. 34 If the data which remote receives contains entries which are on disabled calendars on remote this entries are updated and not added as duplicates to the default calendar.
34 35
35Summary: 36Summary:
36No new item ( new created after the last sync ) in a disabled calendar is propagated to the sync partner. Readonly items are synced and added/changed on the sync partner if it is not readonly on the sync partner. 37No new item ( new created after the last sync ) in a disabled calendar is propagated to the sync partner. Readonly items are synced and added/changed on the sync partner if it is not readonly on the sync partner.
37If you have different calendars on remote and local and some of them disabled you may get some "strange" bahaviour. 38If you have different calendars on remote and local and some of them disabled you may get some "strange" bahaviour.
38Well, the syncing has become quite complicated ... you should have no problems if you enable all calendars. 39Well, the syncing has become quite complicated ... you should have no problems if you enable all calendars.
39 40
40********** VERSION 2.1.13 ************ 41********** VERSION 2.1.13 ************
41 42
42Fixed a problem in KA/Pi search. 43Fixed a problem in KA/Pi search.
43Fixed some minor problems in KO/Pi. 44Fixed some minor problems in KO/Pi.
44Added calendar selection possibility to the todo view popup and to the event/todo/journal editor. 45Added calendar selection possibility to the todo view popup and to the event/todo/journal editor.
45 46
46Fixed memory usage problems in KA/Pi: 47Fixed memory usage problems in KA/Pi:
47When loading data KA/Pi did load the file data twice. 48When loading data KA/Pi did load the file data twice.
48Example: 49Example:
49 A 600k file did consume 1200k memory during loading process. 50 A 600k file did consume 1200k memory during loading process.
50 This is fixed, it does now consume only 600k during loading process. 51 This is fixed, it does now consume only 600k during loading process.
51When saving data KA/Pi did consume a lot of memory for the data parsing during the save process. 52When saving data KA/Pi did consume a lot of memory for the data parsing during the save process.
52This is fixed. 53This is fixed.
53Example: 54Example:
54 Before saving a 600k file KA/Pi did consume 21.7 Meg of Ram. 55 Before saving a 600k file KA/Pi did consume 21.7 Meg of Ram.
55 When saving KA/Pi did consume 28.6 Meg of Ram. That causes a crash on the Zaurus because there was no memeory left in the system. 56 When saving KA/Pi did consume 28.6 Meg of Ram. That causes a crash on the Zaurus because there was no memeory left in the system.
56 Now KA/Pi is consuming on saving the same data 22.0 Meg of Ram during the save process. 57 Now KA/Pi is consuming on saving the same data 22.0 Meg of Ram during the save process.
57Note: The memory usage of KA/Pi after the data is loaded/saved has not changed. 58Note: The memory usage of KA/Pi after the data is loaded/saved has not changed.
58The saving of data may be a bit slower now. 59The saving of data may be a bit slower now.
59 60
60Fixed memory usage problems in KO/Pi: 61Fixed memory usage problems in KO/Pi:
61When KO/Pi did save the data to file, it did not release the used buffers after saving. 62When KO/Pi did save the data to file, it did not release the used buffers after saving.
62The used buffer was released after saving the next time, but there was new buffer space allocated again on that save operation. 63The used buffer was released after saving the next time, but there was new buffer space allocated again on that save operation.
63This is fixed. 64This is fixed.
64Example: 65Example:
65 When saving a 400k file KO/Pi do now use 400k less memory now. 66 When saving a 400k file KO/Pi do now use 400k less memory now.
66 67
67Optimized memory usage in KO/Pi Agenda view: 68Optimized memory usage in KO/Pi Agenda view:
68KO/Pi is storing some paint information in extra buffers for faster repainting of the agenda view. 69KO/Pi is storing some paint information in extra buffers for faster repainting of the agenda view.
69These buffers were not made smaller (i.e. downsized) because of performance reasons. 70These buffers were not made smaller (i.e. downsized) because of performance reasons.
70The handling of these buffers are now much smarter: 71The handling of these buffers are now much smarter:
71Two (of six) buffers are removed completely. 72Two (of six) buffers are removed completely.
72The remaing four buffers are now downsized after not using the agenda view for 45 seconds. 73The remaing four buffers are now downsized after not using the agenda view for 45 seconds.
73Such that the memory usage of KO/Pi is smaller now in general ( because 2 buffers are removed) and is much smaller when not using the agenda view. That is very important when using fastload for KO/Pi. 74Such that the memory usage of KO/Pi is smaller now in general ( because 2 buffers are removed) and is much smaller when not using the agenda view. That is very important when using fastload for KO/Pi.
74 75
75Worst case example ( for a maximum size agenda content): 76Worst case example ( for a maximum size agenda content):
76 When resizing the agenda content to a large scale, KO/Pi did use 17Meg of mem ( and did not use less memory until it was stopped). Now KO/Pi is using on the same operation only 14.3 Meg of mem and after 45 seconds not using the agenda view it uses only 9.4 Meg of mem. 77 When resizing the agenda content to a large scale, KO/Pi did use 17Meg of mem ( and did not use less memory until it was stopped). Now KO/Pi is using on the same operation only 14.3 Meg of mem and after 45 seconds not using the agenda view it uses only 9.4 Meg of mem.
77 78
78When switching to an unused Agenda view now KO/Pi is upizing the buffers again. This takes less than a second. Such that switching to Agenda view (after not using it for more than 45 seconds) is now a bit slower. 79When switching to an unused Agenda view now KO/Pi is upizing the buffers again. This takes less than a second. Such that switching to Agenda view (after not using it for more than 45 seconds) is now a bit slower.
79 80
80Summary: 81Summary:
81Many memory wasting problems of KA/Pi and KO/Pi fixed such that it is better to use on the Zaurus. 82Many memory wasting problems of KA/Pi and KO/Pi fixed such that it is better to use on the Zaurus.
82 83
83********** VERSION 2.1.12 ************ 84********** VERSION 2.1.12 ************
84 85
85KO/Pi: 86KO/Pi:
86Many small usability fixes, e.g. rearranged the popup menus such that they are better to use on the Zaurus. 87Many small usability fixes, e.g. rearranged the popup menus such that they are better to use on the Zaurus.
87Fixed a problem with the month view when file was saved but KO/Pi was not the active window. 88Fixed a problem with the month view when file was saved but KO/Pi was not the active window.
88Fixed some problems in the resource config dialog (e.g. added a warning if you set all calendars to read-only). 89Fixed some problems in the resource config dialog (e.g. added a warning if you set all calendars to read-only).
89Fixed some other small problems. 90Fixed some other small problems.
90 91
91********** VERSION 2.1.11 ************ 92********** VERSION 2.1.11 ************
92 93
93KO/Pi: 94KO/Pi:
94Because we can have many calendars now in KO/Pi we can have more than one journal entry per day. 95Because we can have many calendars now in KO/Pi we can have more than one journal entry per day.
95Added features to handle (and add ) more than one journal entry per day. 96Added features to handle (and add ) more than one journal entry per day.
96Added option for a journal title. 97Added option for a journal title.
97 98
98Added info about the calendar, the item belongs to, to the event/todo/journal viewer. 99Added info about the calendar, the item belongs to, to the event/todo/journal viewer.
99Fixed a problem of the alarm of completed recurring todos. 100Fixed a problem of the alarm of completed recurring todos.
100Added to the event/todo editor to set quickly the category of an item. 101Added to the event/todo editor to set quickly the category of an item.
101 102
102 103
103Fixed some problems when calling KO/Pi or KA/Pi from the alarm applet. 104Fixed some problems when calling KO/Pi or KA/Pi from the alarm applet.
104 105
105Added KA/Pi multi sync to the multi sync called from the alarm applet. 106Added KA/Pi multi sync to the multi sync called from the alarm applet.
106 107
107********** VERSION 2.1.10 ************ 108********** VERSION 2.1.10 ************
108 109
109KO/Pi: 110KO/Pi:
110Importing Birthdays will now create another file resource "Birthdays" and import the birthday data from KA/Pi into that file. 111Importing Birthdays will now create another file resource "Birthdays" and import the birthday data from KA/Pi into that file.
111When a multidayevent is selected in monthview all occurences of this event in the monthview are now hightlighted. 112When a multidayevent is selected in monthview all occurences of this event in the monthview are now hightlighted.
112Fixed a bug in searching for a small timerange, i.e. one day. 113Fixed a bug in searching for a small timerange, i.e. one day.
113 114
114KA/Pi: 115KA/Pi:
115Fixed two problems in csv export. 116Fixed two problems in csv export.
116Fixed problems when calling the contact selection dialog from KO/Pi or OM/Pi. 117Fixed problems when calling the contact selection dialog from KO/Pi or OM/Pi.
117 118
118********** VERSION 2.1.9 ************ 119********** VERSION 2.1.9 ************
119 120
120KO/Pi: 121KO/Pi:
121Fixed some problems of the new search options in the search dialog. 122Fixed some problems of the new search options in the search dialog.
122Fixed some problems in the new resource config options. 123Fixed some problems in the new resource config options.
123Changed the recurrence edit of events and todos such that the recurrence edit page now is notified about a change of the start date on the first page. 124Changed the recurrence edit of events and todos such that the recurrence edit page now is notified about a change of the start date on the first page.
124Fixed a problem creating new events in the agenda view if at the day/time is already an agenda item shown: 125Fixed a problem creating new events in the agenda view if at the day/time is already an agenda item shown:
125Now you can click on the bottom/top of an allday agenda item or on the left/right side of an agenda item to get the "new todo/new event" popup. 126Now you can click on the bottom/top of an allday agenda item or on the left/right side of an agenda item to get the "new todo/new event" popup.
126 127
127Fixed a problem in recurrence range in syncing with DTM. 128Fixed a problem in recurrence range in syncing with DTM.
128 129
129KA/Pi: 130KA/Pi:
130Made it posiible to show in the contact overview the details of all data available for that contact( e.g. office, spouse, children, nickname ...) 131Made it posiible to show in the contact overview the details of all data available for that contact( e.g. office, spouse, children, nickname ...)
131 132
132PwM/Pi: 133PwM/Pi:
133Added "sec" to the timeout config settings to make it clear the timeout values are seconds. 134Added "sec" to the timeout config settings to make it clear the timeout values are seconds.
134 135
135********** VERSION 2.1.8 ************ 136********** VERSION 2.1.8 ************
136 137
137KO/Pi: 138KO/Pi:
138Added info about the completion state of a todo in the ListView/Searchdialog. 139Added info about the completion state of a todo in the ListView/Searchdialog.
139If in TodoView is selected "do not show compledted todos" then completed todos are not shown in the ListView as well. 140If in TodoView is selected "do not show compledted todos" then completed todos are not shown in the ListView as well.
140Fixed some updating problems when changing the filter. 141Fixed some updating problems when changing the filter.
141 142
142KA/Pi: 143KA/Pi:
143In the addressee selection dialog now the formatted name is shown, if not empty. 144In the addressee selection dialog now the formatted name is shown, if not empty.
144Added a column "category" to the addressee selection dialog to make it possible to sort addressees after category. 145Added a column "category" to the addressee selection dialog to make it possible to sort addressees after category.
145Now in the addressee selection dialog a selected contact is remove with a single click from the selected list. 146Now in the addressee selection dialog a selected contact is remove with a single click from the selected list.
146 147
147Fixed in the file selector on the Zaurus the problem that symbolic links to files/dirs were ignored. 148Fixed in the file selector on the Zaurus the problem that symbolic links to files/dirs were ignored.
148Fixed the sorting for size in the file selector on the Z. 149Fixed the sorting for size in the file selector on the Z.
149 150
150Changed the color selection dialog on the Zaurus to a more user friendly version. 151Changed the color selection dialog on the Zaurus to a more user friendly version.
151 152
152********** VERSION 2.1.7 ************ 153********** VERSION 2.1.7 ************
153 154
154KO/Pi: 155KO/Pi:
155Fixed several problems in the new Resource handling. 156Fixed several problems in the new Resource handling.
156Added more options to the search dialog. 157Added more options to the search dialog.
157Fixed a problem in the Month view. 158Fixed a problem in the Month view.
158Added more options to the dialog when setting a todo to stopped. 159Added more options to the dialog when setting a todo to stopped.
159 160
160Fixed two small problems in KO/Pi Alarm applet. 161Fixed two small problems in KO/Pi Alarm applet.
161 162
162********** VERSION 2.1.6 ************ 163********** VERSION 2.1.6 ************
163 164
164This release is for testing only. 165This release is for testing only.
165 166
166KO/Pi: 167KO/Pi:
167Added to the list view (the list view is used in search dialog as well) the possibility to print it. 168Added to the list view (the list view is used in search dialog as well) the possibility to print it.
168Added to the list view the possibility to hide entries, if you do not want to print all entries of the list view. 169Added to the list view the possibility to hide entries, if you do not want to print all entries of the list view.
169Added to the list view the possibility to add all subtodos of selected todos to an export/beam. 170Added to the list view the possibility to add all subtodos of selected todos to an export/beam.
170Added to the search dialog the possibility to make an additive search such that you can get a better list for export/printout. 171Added to the search dialog the possibility to make an additive search such that you can get a better list for export/printout.
171Added to the search dialog the possibility to hide the checkboxes such that there is more space for the list view on the Zaurus. 172Added to the search dialog the possibility to hide the checkboxes such that there is more space for the list view on the Zaurus.
172Fixed a problem in the AlarmTimer Applet: Now utf8 messages are displayed properly. 173Fixed a problem in the AlarmTimer Applet: Now utf8 messages are displayed properly.
173 174
174Added support for multiple calendar files in KO/Pi. Only local ical (*.ics) files are supported as calendars. 175Added support for multiple calendar files in KO/Pi. Only local ical (*.ics) files are supported as calendars.
175In the sync profile config it is still missing to specify a particular calendar to sync with this profile. That setting will be added later. 176In the sync profile config it is still missing to specify a particular calendar to sync with this profile. That setting will be added later.
176Now on every sync the set of calendars is synced which are enabled in the resource view. 177Now on every sync the set of calendars is synced which are enabled in the resource view.
177 178
178A calendar is enabled in the resource view if the "eye" column is checked. 179A calendar is enabled in the resource view if the "eye" column is checked.
179You can set a calendar to be the default for new items( "+" column ). 180You can set a calendar to be the default for new items( "+" column ).
180You can tell KO/Pi to ignore all alarm of a calendar ( "bell" column ) and you can set it readonly. 181You can tell KO/Pi to ignore all alarm of a calendar ( "bell" column ) and you can set it readonly.
181To find out how to add a new calendar and how to remove a calendar is left as an exercise to the reader ... 182To find out how to add a new calendar and how to remove a calendar is left as an exercise to the reader ...
182 183
183 184
184********** VERSION 2.1.5 ************ 185********** VERSION 2.1.5 ************
185 186
186This is the new stable version. 187This is the new stable version.
187Bugfix: 188Bugfix:
188Fixed a problem with agenda popup on the desktop in KO/Pi. 189Fixed a problem with agenda popup on the desktop in KO/Pi.
189Fixed a crash when reloading file, e.g. after a passive pi-sync synchronization. 190Fixed a crash when reloading file, e.g. after a passive pi-sync synchronization.
190Added config option to not display completed todos in agenda view. 191Added config option to not display completed todos in agenda view.
191Addressee view is now using the formatted name, if defined. 192Addressee view is now using the formatted name, if defined.
192That makes it possible to display "lastname, firstname" in that view now. 193That makes it possible to display "lastname, firstname" in that view now.
193To set the formatted name for all contacts, please use menu: 194To set the formatted name for all contacts, please use menu:
194Edit->Change->Set formatted name. 195Edit->Change->Set formatted name.
195Fixed the bug in KA/Pi that is was not possible to add images to a contact on Windows. 196Fixed the bug in KA/Pi that is was not possible to add images to a contact on Windows.
196 197
197********** VERSION 2.1.4 ************ 198********** VERSION 2.1.4 ************
198 199
199Fixed two more bugs in the KA/Pi CSV import dialog: 200Fixed two more bugs in the KA/Pi CSV import dialog:
200Made it possible to read multi-line fields and import it to the "Note" field. 201Made it possible to read multi-line fields and import it to the "Note" field.
201Fixed a problem in mapping custom fields, whatever a custem field is... 202Fixed a problem in mapping custom fields, whatever a custem field is...
202 203
203********** VERSION 2.1.3 ************ 204********** VERSION 2.1.3 ************
204 205
205Changed the menu structure of the alarm applet: 206Changed the menu structure of the alarm applet:
206Moved "Simulate" to " Play Beeps" submenu and re-added "Todo List". 207Moved "Simulate" to " Play Beeps" submenu and re-added "Todo List".
207 208
208Fixed several problems in the KA/Pi CSV import dialog: 209Fixed several problems in the KA/Pi CSV import dialog:
209Added "Category", made codec configureable and made it possible to map many fields to the "Note" field. 210Added "Category", made codec configureable and made it possible to map many fields to the "Note" field.
210 211
211 212
212********** VERSION 2.1.2 ************ 213********** VERSION 2.1.2 ************
213 214
214Fixed a problem closing the alarm dialog on Zaurus with "OK" button. 215Fixed a problem closing the alarm dialog on Zaurus with "OK" button.
215 216
216Fixed a problem when importing data from Outlook with mutiple categories set. 217Fixed a problem when importing data from Outlook with mutiple categories set.
217 218
218Changed display of days in datenavigator: 219Changed display of days in datenavigator:
219Birthdays are now blue, not dark green. 220Birthdays are now blue, not dark green.
220When todo view is shown, no birtdays are shown and days with due todos are shown blue. 221When todo view is shown, no birtdays are shown and days with due todos are shown blue.
221When journal view is shown, only holidays are shown and days with journals are blue. 222When journal view is shown, only holidays are shown and days with journals are blue.
222 223
223Added Backup options to global config: 224Added Backup options to global config:
224You can create now x-daily backups for KO/Pi, KA/Pi (for file resources only, file resource is the standard type) and PwM/Pi ( all files you will open ). 225You can create now x-daily backups for KO/Pi, KA/Pi (for file resources only, file resource is the standard type) and PwM/Pi ( all files you will open ).
225It is recommended to use another HDD/Memory card for the backup directory. If (very useful on the Zaurus) the specified backup directory does not exist you are asked if you want to try again to create a backup. That makes it possible to insert your memory card in the Zaurus and then trying again. 226It is recommended to use another HDD/Memory card for the backup directory. If (very useful on the Zaurus) the specified backup directory does not exist you are asked if you want to try again to create a backup. That makes it possible to insert your memory card in the Zaurus and then trying again.
226The backup is created when the application wants to save for the first time on a backup-day. You can specify the amount of backups and the day interval of backups. 227The backup is created when the application wants to save for the first time on a backup-day. You can specify the amount of backups and the day interval of backups.
227 228
228********** VERSION 2.1.1 ************ 229********** VERSION 2.1.1 ************
229 230
230Stable release 2.1.1! 231Stable release 2.1.1!
231 232
232KO/Pi: 233KO/Pi:
233Fixed one problem in the layout of the edit dialogs on the Zaurus with 640x480 display. 234Fixed one problem in the layout of the edit dialogs on the Zaurus with 640x480 display.
234 235
235********** VERSION 2.1.0 ************ 236********** VERSION 2.1.0 ************
236 237
237Stable release 2.1.0! 238Stable release 2.1.0!
238 239
239Summary of changes/fixes compared to version 2.0.6: 240Summary of changes/fixes compared to version 2.0.6:
240 241
241Many bugs of version 2.0.6 fixed. 242Many bugs of version 2.0.6 fixed.
242Most of them were small bugs, but some of them were important. 243Most of them were small bugs, but some of them were important.
243It is recommended to use version 2.1.0 and not version 2.0.6. 244It is recommended to use version 2.1.0 and not version 2.0.6.
244 245
245Important changes: 246Important changes:
246 247
247Added recurring todos to KO/Pi. 248Added recurring todos to KO/Pi.
248 249
249Added global application font settings (for all KDE-Pim/Pi apps) to the general settings. 250Added global application font settings (for all KDE-Pim/Pi apps) to the general settings.
250 251
251Made Passwordmanager PwM/Pi more userfriendly: Rearranged some toolbar icons, optimized setting of focus, fixed layout problems and more. 252Made Passwordmanager PwM/Pi more userfriendly: Rearranged some toolbar icons, optimized setting of focus, fixed layout problems and more.
252 253
253Datenavigator can now display many months. Very useful on the desktop. 254Datenavigator can now display many months. Very useful on the desktop.
254 255
255KO/Pi alarm applet changed: Made buttons in alarm dialog much bigger and other usebility enhancements. 256KO/Pi alarm applet changed: Made buttons in alarm dialog much bigger and other usebility enhancements.
256 257
257Made alarm sound working on Linux desktop. 258Made alarm sound working on Linux desktop.
258 259
259Made KO/Pi and KA/Pi running from a memory stick. Please read storage HowTo for details. 260Made KO/Pi and KA/Pi running from a memory stick. Please read storage HowTo for details.
260 261
261Added timetracking feature in KO/Pi todo view. Please read timetraker HowTo for details. 262Added timetracking feature in KO/Pi todo view. Please read timetraker HowTo for details.
262 263
263Many other usebility enhancements. 264Many other usebility enhancements.
264Special thanks to Ben for his suggestions! 265Special thanks to Ben for his suggestions!
265 266
266You can find the complete changelog 267You can find the complete changelog
267from version 1.7.7 to 2.1.0 268from version 1.7.7 to 2.1.0
268in the source package or on 269in the source package or on
269 270
270http://www.pi-sync.net/html/changelog.html 271http://www.pi-sync.net/html/changelog.html
271 272
272 273
273 274
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a9e402e..427d71b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,4823 +1,4849 @@
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 (preton.brown@yale.edu) 8 Preston Brown (preton.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#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "koagenda.h" 107#include "koagenda.h"
108#include "kodialogmanager.h" 108#include "kodialogmanager.h"
109#include "outgoingdialog.h" 109#include "outgoingdialog.h"
110#include "incomingdialog.h" 110#include "incomingdialog.h"
111#include "datenavigatorcontainer.h" 111#include "datenavigatorcontainer.h"
112#include "statusdialog.h" 112#include "statusdialog.h"
113#include "kdatenavigator.h" 113#include "kdatenavigator.h"
114#include "kotodoview.h" 114#include "kotodoview.h"
115#include "datenavigator.h" 115#include "datenavigator.h"
116#include "resourceview.h" 116#include "resourceview.h"
117#include "navigatorbar.h" 117#include "navigatorbar.h"
118#include "searchdialog.h" 118#include "searchdialog.h"
119#include "mainwindow.h" 119#include "mainwindow.h"
120#include "categoryeditdialog.h" 120#include "categoryeditdialog.h"
121 121
122#include "calendarview.h" 122#include "calendarview.h"
123#ifndef DESKTOP_VERSION 123#ifndef DESKTOP_VERSION
124#include <qtopia/alarmserver.h> 124#include <qtopia/alarmserver.h>
125#endif 125#endif
126#ifndef _WIN32_ 126#ifndef _WIN32_
127#include <stdlib.h> 127#include <stdlib.h>
128#include <stdio.h> 128#include <stdio.h>
129#include <unistd.h> 129#include <unistd.h>
130#else 130#else
131#include <qprocess.h> 131#include <qprocess.h>
132#endif 132#endif
133 133
134#ifdef DESKTOP_VERSION 134#ifdef DESKTOP_VERSION
135#include <kabc/stdaddressbook.h> 135#include <kabc/stdaddressbook.h>
136#endif 136#endif
137using namespace KOrg; 137using namespace KOrg;
138using namespace KCal; 138using namespace KCal;
139extern int globalFlagBlockAgenda; 139extern int globalFlagBlockAgenda;
140extern int globalFlagBlockStartup; 140extern int globalFlagBlockStartup;
141 141
142 142
143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
144 144
145{ 145{
146 mAlarms = alarms; 146 mAlarms = alarms;
147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
148 QString mText = "<table width=\"100%\">\n"; 148 QString mText = "<table width=\"100%\">\n";
149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
150#ifdef DESKTOP_VERSION 150#ifdef DESKTOP_VERSION
151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
152#else 152#else
153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
154#endif 154#endif
155 // mText += "<img src=\""; 155 // mText += "<img src=\"";
156 // mText += ipath; 156 // mText += ipath;
157 // mText += "\">"; 157 // mText += "\">";
158 //mEventDate = QDate::currentDate(); 158 //mEventDate = QDate::currentDate();
159#ifdef DESKTOP_VERSION 159#ifdef DESKTOP_VERSION
160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
161#else 161#else
162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
163#endif 163#endif
164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
165 165
166 Incidence * inc = getNextInc( start ); 166 Incidence * inc = getNextInc( start );
167 int time = 0; 167 int time = 0;
168 //mText += "<table>"; 168 //mText += "<table>";
169 while ( inc ) { 169 while ( inc ) {
170 QDateTime dt ; 170 QDateTime dt ;
171 QString tempText = "<a "; 171 QString tempText = "<a ";
172 bool ok; 172 bool ok;
173 dt = inc->getNextOccurence( start, &ok ); 173 dt = inc->getNextOccurence( start, &ok );
174 if ( !ok ) continue; 174 if ( !ok ) continue;
175 if ( inc->typeID() == eventID ) { 175 if ( inc->typeID() == eventID ) {
176 tempText += "href=\"event:"; 176 tempText += "href=\"event:";
177 } else if ( inc->typeID() == todoID ) { 177 } else if ( inc->typeID() == todoID ) {
178 tempText += "href=\"todo:"; 178 tempText += "href=\"todo:";
179 } 179 }
180 tempText += inc->uid() + "\">"; 180 tempText += inc->uid() + "\">";
181 if ( inc->typeID() == todoID ) 181 if ( inc->typeID() == todoID )
182 tempText += i18n("Todo: "); 182 tempText += i18n("Todo: ");
183 if ( inc->summary().length() > 0 ) 183 if ( inc->summary().length() > 0 )
184 tempText += inc->summary(); 184 tempText += inc->summary();
185 else 185 else
186 tempText += i18n("-no summary-"); 186 tempText += i18n("-no summary-");
187 QString timestr; 187 QString timestr;
188 if (!inc->doesFloat()) 188 if (!inc->doesFloat())
189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
190 else 190 else
191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
192 if ( dt.date() < QDate::currentDate() && time == 0 ) { 192 if ( dt.date() < QDate::currentDate() && time == 0 ) {
193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
194 mText += "<table>"; 194 mText += "<table>";
195 time = 1; 195 time = 1;
196 } 196 }
197 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 197 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
198 if ( time > 0 ) 198 if ( time > 0 )
199 mText +="</table>"; 199 mText +="</table>";
200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
201 mText += "<table>"; 201 mText += "<table>";
202 time = 2; 202 time = 2;
203 203
204 } 204 }
205 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 205 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
206 if ( time > 0 ) 206 if ( time > 0 )
207 mText +="</table>"; 207 mText +="</table>";
208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
209 mText += "<table>"; 209 mText += "<table>";
210 time = 3; 210 time = 3;
211 } 211 }
212 mText +="<tr><td><b>"; 212 mText +="<tr><td><b>";
213 mText += timestr; 213 mText += timestr;
214 mText += "</b></td><td>"; 214 mText += "</b></td><td>";
215 mText += tempText; 215 mText += tempText;
216 mText += "</td></tr>\n"; 216 mText += "</td></tr>\n";
217 inc = getNextInc( start ); 217 inc = getNextInc( start );
218 } 218 }
219 mText +="</table>"; 219 mText +="</table>";
220 setText( mText ); 220 setText( mText );
221} 221}
222 222
223MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 223MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
224{ 224{
225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
226} 226}
227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
228{ 228{
229 QDateTime dt ; 229 QDateTime dt ;
230 Incidence * retInc; 230 Incidence * retInc;
231 Incidence * inc = mAlarms.first(); 231 Incidence * inc = mAlarms.first();
232 if ( inc == 0 ) 232 if ( inc == 0 )
233 return 0; 233 return 0;
234 bool ok; 234 bool ok;
235 dt = inc->getNextOccurence( start, &ok ); 235 dt = inc->getNextOccurence( start, &ok );
236 if ( ! ok ) return 0; 236 if ( ! ok ) return 0;
237 QDateTime dtn ; 237 QDateTime dtn ;
238 retInc = inc; 238 retInc = inc;
239 inc = mAlarms.next(); 239 inc = mAlarms.next();
240 while ( inc ) { 240 while ( inc ) {
241 dtn = inc->getNextOccurence( start, &ok ); 241 dtn = inc->getNextOccurence( start, &ok );
242 if ( ! ok ) return 0; 242 if ( ! ok ) return 0;
243 if ( dtn < dt ) { 243 if ( dtn < dt ) {
244 dt = dtn; 244 dt = dtn;
245 retInc = inc; 245 retInc = inc;
246 } 246 }
247 inc = mAlarms.next(); 247 inc = mAlarms.next();
248 } 248 }
249 mAlarms.remove( retInc ); 249 mAlarms.remove( retInc );
250 return retInc; 250 return retInc;
251 251
252} 252}
253void MissedAlarmTextBrowser::setSource(const QString & n) 253void MissedAlarmTextBrowser::setSource(const QString & n)
254{ 254{
255 if (n.startsWith("event:")) { 255 if (n.startsWith("event:")) {
256#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
257 emit showIncidence(n.mid(8)); 257 emit showIncidence(n.mid(8));
258#else 258#else
259 emit showIncidence(n.mid(6)); 259 emit showIncidence(n.mid(6));
260#endif 260#endif
261 return; 261 return;
262 } else if (n.startsWith("todo:")) { 262 } else if (n.startsWith("todo:")) {
263#ifdef DESKTOP_VERSION 263#ifdef DESKTOP_VERSION
264 emit showIncidence(n.mid(7)); 264 emit showIncidence(n.mid(7));
265#else 265#else
266 emit showIncidence(n.mid(5)); 266 emit showIncidence(n.mid(5));
267#endif 267#endif
268 return; 268 return;
269 } 269 }
270} 270}
271 271
272 272
273class KOBeamPrefs : public QDialog 273class KOBeamPrefs : public QDialog
274{ 274{
275 public: 275 public:
276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
277 QDialog( parent, name, true ) 277 QDialog( parent, name, true )
278 { 278 {
279 setCaption( i18n("Beam Options") ); 279 setCaption( i18n("Beam Options") );
280 QVBoxLayout* lay = new QVBoxLayout( this ); 280 QVBoxLayout* lay = new QVBoxLayout( this );
281 lay->setSpacing( 3 ); 281 lay->setSpacing( 3 );
282 lay->setMargin( 3 ); 282 lay->setMargin( 3 );
283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
284 lay->addWidget( format ); 284 lay->addWidget( format );
285 format->setExclusive ( true ) ; 285 format->setExclusive ( true ) ;
286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
287 lay->addWidget( time ); time->setExclusive ( true ) ; 287 lay->addWidget( time ); time->setExclusive ( true ) ;
288 vcal = new QRadioButton(" vCalendar ", format ); 288 vcal = new QRadioButton(" vCalendar ", format );
289 ical = new QRadioButton(" iCalendar ", format ); 289 ical = new QRadioButton(" iCalendar ", format );
290 vcal->setChecked( true ); 290 vcal->setChecked( true );
291 tz = new QRadioButton(i18n(" With timezone "), time ); 291 tz = new QRadioButton(i18n(" With timezone "), time );
292 local = new QRadioButton(i18n(" Local time "), time ); 292 local = new QRadioButton(i18n(" Local time "), time );
293 tz->setChecked( true ); 293 tz->setChecked( true );
294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
295 lay->addWidget( ok ); 295 lay->addWidget( ok );
296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
297 lay->addWidget( cancel ); 297 lay->addWidget( cancel );
298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
300 resize( 200, 200 ); 300 resize( 200, 200 );
301 } 301 }
302 302
303 bool beamVcal() { return vcal->isChecked(); } 303 bool beamVcal() { return vcal->isChecked(); }
304 bool beamLocal() { return local->isChecked(); } 304 bool beamLocal() { return local->isChecked(); }
305private: 305private:
306 QRadioButton* vcal, *ical, *local, *tz; 306 QRadioButton* vcal, *ical, *local, *tz;
307}; 307};
308class KOCatPrefs : public QDialog 308class KOCatPrefs : public QDialog
309{ 309{
310 public: 310 public:
311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
312 QDialog( parent, name, true ) 312 QDialog( parent, name, true )
313 { 313 {
314 setCaption( i18n("Manage new Categories") ); 314 setCaption( i18n("Manage new Categories") );
315 QVBoxLayout* lay = new QVBoxLayout( this ); 315 QVBoxLayout* lay = new QVBoxLayout( this );
316 lay->setSpacing( 3 ); 316 lay->setSpacing( 3 );
317 lay->setMargin( 3 ); 317 lay->setMargin( 3 );
318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this ); 318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this );
319 lay->addWidget( lab ); 319 lay->addWidget( lab );
320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
321 lay->addWidget( format ); 321 lay->addWidget( format );
322 format->setExclusive ( true ) ; 322 format->setExclusive ( true ) ;
323 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 323 addCatBut = new QRadioButton(i18n("Add to category list"), format );
324 new QRadioButton(i18n("Remove from Events/Todos"), format ); 324 new QRadioButton(i18n("Remove from Events/Todos"), format );
325 addCatBut->setChecked( true ); 325 addCatBut->setChecked( true );
326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this ); 326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this );
327 lay->addWidget( ok ); 327 lay->addWidget( ok );
328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
329 lay->addWidget( cancel ); 329 lay->addWidget( cancel );
330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
332 resize( 200, 200 ); 332 resize( 200, 200 );
333 } 333 }
334 334
335 bool addCat() { return addCatBut->isChecked(); } 335 bool addCat() { return addCatBut->isChecked(); }
336private: 336private:
337 QRadioButton* addCatBut; 337 QRadioButton* addCatBut;
338}; 338};
339 339
340 340
341 341
342CalendarView::CalendarView( CalendarResources *calendar, 342CalendarView::CalendarView( CalendarResources *calendar,
343 QWidget *parent, const char *name ) 343 QWidget *parent, const char *name )
344 : CalendarViewBase( parent, name ), 344 : CalendarViewBase( parent, name ),
345 mCalendar( calendar ), 345 mCalendar( calendar ),
346 mResourceManager( calendar->resourceManager() ) 346 mResourceManager( calendar->resourceManager() )
347{ 347{
348 348
349 mEventEditor = 0; 349 mEventEditor = 0;
350 mTodoEditor = 0; 350 mTodoEditor = 0;
351 351
352 init(); 352 init();
353} 353}
354 354
355CalendarView::CalendarView( Calendar *calendar, 355CalendarView::CalendarView( Calendar *calendar,
356 QWidget *parent, const char *name ) 356 QWidget *parent, const char *name )
357 : CalendarViewBase( parent, name ), 357 : CalendarViewBase( parent, name ),
358 mCalendar( calendar ), 358 mCalendar( calendar ),
359 mResourceManager( 0 ) 359 mResourceManager( 0 )
360{ 360{
361 361
362 mEventEditor = 0; 362 mEventEditor = 0;
363 mTodoEditor = 0; 363 mTodoEditor = 0;
364 init(); 364 init();
365} 365}
366 366
367void CalendarView::init() 367void CalendarView::init()
368{ 368{
369 mNextAlarmDateTime = QDateTime::currentDateTime(); 369 mNextAlarmDateTime = QDateTime::currentDateTime();
370 setFocusPolicy (NoFocus ); 370 setFocusPolicy (NoFocus );
371 mViewerCallerIsSearchDialog = false; 371 mViewerCallerIsSearchDialog = false;
372 mBlockShowDates = false; 372 mBlockShowDates = false;
373 373
374 mDatePickerMode = 0; 374 mDatePickerMode = 0;
375 mCurrentSyncDevice = ""; 375 mCurrentSyncDevice = "";
376 mViewManager = new KOViewManager( this ); 376 mViewManager = new KOViewManager( this );
377 mDialogManager = new KODialogManager( this ); 377 mDialogManager = new KODialogManager( this );
378 mEventViewerDialog = 0; 378 mEventViewerDialog = 0;
379 mModified = false; 379 mModified = false;
380 mReadOnly = false; 380 mReadOnly = false;
381 mSelectedIncidence = 0; 381 mSelectedIncidence = 0;
382 mCalPrinter = 0; 382 mCalPrinter = 0;
383 mFilters.setAutoDelete(true); 383 mFilters.setAutoDelete(true);
384 384
385 mCalendar->registerObserver( this ); 385 mCalendar->registerObserver( this );
386 // TODO: Make sure that view is updated, when calendar is changed. 386 // TODO: Make sure that view is updated, when calendar is changed.
387 387
388 mStorage = new FileStorage( mCalendar ); 388 mStorage = new FileStorage( mCalendar );
389 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 389 mNavigator = new DateNavigator( this, "datevav", mViewManager );
390 390
391 QBoxLayout *topLayout = (QBoxLayout*)layout(); 391 QBoxLayout *topLayout = (QBoxLayout*)layout();
392#ifndef KORG_NOSPLITTER 392#ifndef KORG_NOSPLITTER
393 // create the main layout frames. 393 // create the main layout frames.
394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
395 topLayout->addWidget(mPanner); 395 topLayout->addWidget(mPanner);
396 396
397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
398 "CalendarView::LeftFrame"); 398 "CalendarView::LeftFrame");
399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
400 400
401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
402 "CalendarView::DateNavigator" ); 402 "CalendarView::DateNavigator" );
403 403
404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
406 mTodoList->setNavigator( mNavigator ); 406 mTodoList->setNavigator( mNavigator );
407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
408 408
409#ifdef KORG_NORESOURCEVIEW 409#ifdef KORG_NORESOURCEVIEW
410 mResourceView = 0; 410 mResourceView = 0;
411#else 411#else
412 if ( mResourceManager ) { 412 if ( mResourceManager ) {
413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
414 mResourceView->updateView(); 414 mResourceView->updateView();
415 connect( mResourceView, SIGNAL( resourcesChanged() ), 415 connect( mResourceView, SIGNAL( resourcesChanged() ),
416 SLOT( updateView() ) ); 416 SLOT( updateView() ) );
417 } else { 417 } else {
418 mResourceView = 0; 418 mResourceView = 0;
419 } 419 }
420#endif 420#endif
421 QWidget *rightBox = new QWidget( mPanner ); 421 QWidget *rightBox = new QWidget( mPanner );
422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
423 423
424 mRightFrame = new QWidgetStack( rightBox ); 424 mRightFrame = new QWidgetStack( rightBox );
425 rightLayout->addWidget( mRightFrame, 1 ); 425 rightLayout->addWidget( mRightFrame, 1 );
426 426
427 mLeftFrame = mLeftSplitter; 427 mLeftFrame = mLeftSplitter;
428#else 428#else
429 //QWidget *mainBox = new QWidget( this ); 429 //QWidget *mainBox = new QWidget( this );
430 //QWidget *leftFrame = new QWidget( mainBox ); 430 //QWidget *leftFrame = new QWidget( mainBox );
431 //QBoxLayout * mainBoxLayout; 431 //QBoxLayout * mainBoxLayout;
432 if ( KOPrefs::instance()->mVerticalScreen ) { 432 if ( KOPrefs::instance()->mVerticalScreen ) {
433 //mainBoxLayout = new QVBoxLayout(mainBox); 433 //mainBoxLayout = new QVBoxLayout(mainBox);
434 //leftFrameLayout = new QHBoxLayout(leftFrame ); 434 //leftFrameLayout = new QHBoxLayout(leftFrame );
435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
439 } else { 439 } else {
440 //mainBoxLayout = new QHBoxLayout(mainBox); 440 //mainBoxLayout = new QHBoxLayout(mainBox);
441 //leftFrameLayout = new QVBoxLayout(leftFrame ); 441 //leftFrameLayout = new QVBoxLayout(leftFrame );
442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
446 } 446 }
447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
448 //QBoxLayout * leftFrameLayout; 448 //QBoxLayout * leftFrameLayout;
449 topLayout->addWidget( mMainFrame ); 449 topLayout->addWidget( mMainFrame );
450#ifdef DESKTOP_VERSION 450#ifdef DESKTOP_VERSION
451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this ); 451 mDateScrollBar = new QScrollBar ( 1, 365, 1,30, 200,QScrollBar::Horizontal, this );
452 topLayout->addWidget( mDateScrollBar ); 452 topLayout->addWidget( mDateScrollBar );
453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) ); 453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) );
454 if ( QApplication::desktop()->width() < 800 ) 454 if ( QApplication::desktop()->width() < 800 )
455 mDateScrollBar->hide(); 455 mDateScrollBar->hide();
456#endif 456#endif
457 //mainBoxLayout->addWidget (mLeftFrame); 457 //mainBoxLayout->addWidget (mLeftFrame);
458 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 458 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
459 "CalendarView::DateNavigator" ); 459 "CalendarView::DateNavigator" );
460#if 0 460#if 0
461 // FIXME 461 // FIXME
462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
463 "CalendarView::DateNavigator", QDate::currentDate()); 463 "CalendarView::DateNavigator", QDate::currentDate());
464#endif 464#endif
465 // mDateNavigator->blockSignals( true ); 465 // mDateNavigator->blockSignals( true );
466 //leftFrameLayout->addWidget( mDateNavigator ); 466 //leftFrameLayout->addWidget( mDateNavigator );
467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); 472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) );
473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); 474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); 478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() ));
479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
480 480
481 mTodoList->setNavigator( mNavigator ); 481 mTodoList->setNavigator( mNavigator );
482#if 0 482#if 0
483 if ( QApplication::desktop()->width() < 480 ) { 483 if ( QApplication::desktop()->width() < 480 ) {
484 leftFrameLayout->addWidget(mFilterView); 484 leftFrameLayout->addWidget(mFilterView);
485 leftFrameLayout->addWidget(mTodoList, 2 ); 485 leftFrameLayout->addWidget(mTodoList, 2 );
486 486
487 } else { 487 } else {
488 leftFrameLayout->addWidget(mTodoList,2 ); 488 leftFrameLayout->addWidget(mTodoList,2 );
489 leftFrameLayout->addWidget(mFilterView ); 489 leftFrameLayout->addWidget(mFilterView );
490 } 490 }
491#endif 491#endif
492 mFilterView->hide(); 492 mFilterView->hide();
493 mCalEditView->hide(); 493 mCalEditView->hide();
494 QWidget *rightBox = new QWidget( mMainFrame ); 494 QWidget *rightBox = new QWidget( mMainFrame );
495 //mainBoxLayout->addWidget ( rightBox, 10 ); 495 //mainBoxLayout->addWidget ( rightBox, 10 );
496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
497 mRightFrame = new QWidgetStack( rightBox ); 497 mRightFrame = new QWidgetStack( rightBox );
498 rightLayout->addWidget( mRightFrame, 10 ); 498 rightLayout->addWidget( mRightFrame, 10 );
499 499
500 //mLeftFrame = (QWidget *)leftFrame; 500 //mLeftFrame = (QWidget *)leftFrame;
501 if ( KOPrefs::instance()->mVerticalScreen ) { 501 if ( KOPrefs::instance()->mVerticalScreen ) {
502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
506 } else { 506 } else {
507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
510 } 510 }
511 if ( !KOPrefs::instance()->mShowDateNavigator) 511 if ( !KOPrefs::instance()->mShowDateNavigator)
512 mDateNavigator->hide(); 512 mDateNavigator->hide();
513 //qDebug("Calendarview Size %d %d ", width(), height()); 513 //qDebug("Calendarview Size %d %d ", width(), height());
514#endif 514#endif
515 515
516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
517 SLOT( showDates( const KCal::DateList & ) ) ); 517 SLOT( showDates( const KCal::DateList & ) ) );
518 518
519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
521 521
522 522
523 523
524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
525 mViewManager, SLOT( showMonth( const QDate & ) ) ); 525 mViewManager, SLOT( showMonth( const QDate & ) ) );
526 526
527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
528 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 528 mNavigator, SLOT( selectWeek( const QDate & ) ) );
529 529
530 connect( mDateNavigator, SIGNAL( goPrevYear() ), 530 connect( mDateNavigator, SIGNAL( goPrevYear() ),
531 mNavigator, SLOT( selectPreviousYear() ) ); 531 mNavigator, SLOT( selectPreviousYear() ) );
532 connect( mDateNavigator, SIGNAL( goNextYear() ), 532 connect( mDateNavigator, SIGNAL( goNextYear() ),
533 mNavigator, SLOT( selectNextYear() ) ); 533 mNavigator, SLOT( selectNextYear() ) );
534 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 534 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
535 mNavigator, SLOT( selectPreviousMonth() ) ); 535 mNavigator, SLOT( selectPreviousMonth() ) );
536 connect( mDateNavigator, SIGNAL( goNextMonth() ), 536 connect( mDateNavigator, SIGNAL( goNextMonth() ),
537 mNavigator, SLOT( selectNextMonth() ) ); 537 mNavigator, SLOT( selectNextMonth() ) );
538 538
539 connect( mDateNavigator, SIGNAL( goPrevious() ), 539 connect( mDateNavigator, SIGNAL( goPrevious() ),
540 mNavigator, SLOT( selectPrevious() ) ); 540 mNavigator, SLOT( selectPrevious() ) );
541 connect( mDateNavigator, SIGNAL( goNext() ), 541 connect( mDateNavigator, SIGNAL( goNext() ),
542 mNavigator, SLOT( selectNext() ) ); 542 mNavigator, SLOT( selectNext() ) );
543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
544 mNavigator, SLOT( slotMonthSelect( int ) ) ); 544 mNavigator, SLOT( slotMonthSelect( int ) ) );
545 545
546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
548#if 0 548#if 0
549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
550 SLOT( incidenceAdded( Incidence *) ) ); 550 SLOT( incidenceAdded( Incidence *) ) );
551#endif 551#endif
552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
553 553
554 connect( this, SIGNAL( configChanged() ), 554 connect( this, SIGNAL( configChanged() ),
555 mDateNavigator, SLOT( updateConfig() ) ); 555 mDateNavigator, SLOT( updateConfig() ) );
556 556
557 connect( mTodoList, SIGNAL( newTodoSignal() ), 557 connect( mTodoList, SIGNAL( newTodoSignal() ),
558 SLOT( newTodo() ) ); 558 SLOT( newTodo() ) );
559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
560 SLOT( newSubTodo( Todo * ) ) ); 560 SLOT( newSubTodo( Todo * ) ) );
561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
562 SLOT( editTodo( Todo * ) ) ); 562 SLOT( editTodo( Todo * ) ) );
563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
564 SLOT( showTodo( Todo *) ) ); 564 SLOT( showTodo( Todo *) ) );
565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
566 SLOT( deleteTodo( Todo *) ) ); 566 SLOT( deleteTodo( Todo *) ) );
567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
569 SLOT( purgeCompleted() ) ); 569 SLOT( purgeCompleted() ) );
570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
571 SIGNAL( todoModified( Todo *, int ) ) ); 571 SIGNAL( todoModified( Todo *, int ) ) );
572 572
573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
574 this, SLOT ( cloneIncidence( Incidence * ) ) ); 574 this, SLOT ( cloneIncidence( Incidence * ) ) );
575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
576 this, SLOT (cancelIncidence( Incidence * ) ) ); 576 this, SLOT (cancelIncidence( Incidence * ) ) );
577 577
578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
579 this, SLOT ( moveIncidence( Incidence * ) ) ); 579 this, SLOT ( moveIncidence( Incidence * ) ) );
580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
581 this, SLOT ( beamIncidence( Incidence * ) ) ); 581 this, SLOT ( beamIncidence( Incidence * ) ) );
582 582
583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
584 this, SLOT ( todo_unsub( Todo * ) ) ); 584 this, SLOT ( todo_unsub( Todo * ) ) );
585 585
586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
587 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 587 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
589 SLOT( updateTodo( Todo *, int ) ) ); 589 SLOT( updateTodo( Todo *, int ) ) );
590 connect( this, SIGNAL( todoModified( Todo *, int )), this, 590 connect( this, SIGNAL( todoModified( Todo *, int )), this,
591 SLOT( changeTodoDisplay( Todo *, int ) ) ); 591 SLOT( changeTodoDisplay( Todo *, int ) ) );
592 592
593 593
594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
598 598
599 599
600 600
601 601
602 602
603 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 603 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
604 SLOT(checkClipboard())); 604 SLOT(checkClipboard()));
605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
606 SLOT( processTodoListSelection( Incidence * ) ) ); 606 SLOT( processTodoListSelection( Incidence * ) ) );
607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
608 608
609 // kdDebug() << "CalendarView::CalendarView() done" << endl; 609 // kdDebug() << "CalendarView::CalendarView() done" << endl;
610 610
611 mDateFrame = new QVBox(0,0,WType_Popup); 611 mDateFrame = new QVBox(0,0,WType_Popup);
612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
614 mDateFrame->setLineWidth(3); 614 mDateFrame->setLineWidth(3);
615 mDateFrame->hide(); 615 mDateFrame->hide();
616 mDateFrame->setCaption( i18n( "Pick a date to display")); 616 mDateFrame->setCaption( i18n( "Pick a date to display"));
617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
618 618
619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
620 620
621 mEventEditor = mDialogManager->getEventEditor(); 621 mEventEditor = mDialogManager->getEventEditor();
622 mTodoEditor = mDialogManager->getTodoEditor(); 622 mTodoEditor = mDialogManager->getTodoEditor();
623 623
624 mFlagEditDescription = false; 624 mFlagEditDescription = false;
625 625
626 mSuspendTimer = new QTimer( this ); 626 mSuspendTimer = new QTimer( this );
627 mAlarmTimer = new QTimer( this ); 627 mAlarmTimer = new QTimer( this );
628 mRecheckAlarmTimer = new QTimer( this ); 628 mRecheckAlarmTimer = new QTimer( this );
629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
632 mAlarmDialog = new AlarmDialog( this ); 632 mAlarmDialog = new AlarmDialog( this );
633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
634 mAlarmDialog->setServerNotification( false ); 634 mAlarmDialog->setServerNotification( false );
635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
636 636
637 637
638#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
639//US listen for arriving address resultsets 639//US listen for arriving address resultsets
640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
642#endif 642#endif
643 mDateNavigator->setCalendar( mCalendar ); 643 mDateNavigator->setCalendar( mCalendar );
644} 644}
645 645
646 646
647CalendarView::~CalendarView() 647CalendarView::~CalendarView()
648{ 648{
649 // kdDebug() << "~CalendarView()" << endl; 649 // kdDebug() << "~CalendarView()" << endl;
650 //qDebug("CalendarView::~CalendarView() "); 650 //qDebug("CalendarView::~CalendarView() ");
651 delete mDialogManager; 651 delete mDialogManager;
652 delete mViewManager; 652 delete mViewManager;
653 delete mStorage; 653 delete mStorage;
654 delete mDateFrame ; 654 delete mDateFrame ;
655 delete mEventViewerDialog; 655 delete mEventViewerDialog;
656 //kdDebug() << "~CalendarView() done" << endl; 656 //kdDebug() << "~CalendarView() done" << endl;
657} 657}
658 658
659 659
660void CalendarView::nextConflict( bool all, bool allday ) 660void CalendarView::nextConflict( bool all, bool allday )
661{ 661{
662 662 static bool block = false;
663 if ( block ) return;
664 block = true;
663 QPtrList<Event> testlist = mCalendar->events(); 665 QPtrList<Event> testlist = mCalendar->events();
664 Event * test = testlist.first(); 666 Event * test = testlist.first();
665 while ( test ) { 667 while ( test ) {
666 test->setTagged( false ); 668 test->setTagged( false );
667 test = testlist.next(); 669 test = testlist.next();
668 } 670 }
669 QTime st ( 0,0,0); 671 QTime st ( 0,0,0);
670 if ( mViewManager->currentView() == mViewManager->agendaView() ) 672 if ( mViewManager->currentView() == mViewManager->agendaView() )
671 st = mViewManager->agendaView()->agenda()->getEndTime(); 673 st = mViewManager->agendaView()->agenda()->getEndTime();
672 //qDebug("time %s ", st.toString().latin1()); 674 //qDebug("time %s ", st.toString().latin1());
673 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
674 QDateTime conflict; 676 QDateTime conflict;
675 QDateTime retVal; 677 QDateTime retVal;
676 bool found = false; 678 bool found = false;
677 Event * cE = 0; 679 Event * cE = 0;
678 Event * cE2 = 0; 680 Event * cE2 = 0;
679 QPtrList<Event> testlist2 = testlist; 681 QPtrList<Event> testlist2 = testlist;
680 test = testlist.first(); 682 test = testlist.first();
681 bool skip = false; 683 bool skip = false;
682 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
685 //QTime tm;
686 //tm.start();
683 while ( test ) { 687 while ( test ) {
684 qApp->processEvents(); 688 qApp->processEvents();
685 skip = false; 689 skip = false;
686 if ( !all ) skip = ( allday != test->doesFloat() ); 690 if ( !all ) skip = ( allday != test->doesFloat() );
687 if ( !skip ) { 691 if ( !skip ) {
692 if ( found )
693 skip = !test->matchTime( &startDT, &conflict );
694 else
695 skip = !test->matchTime( &startDT, 0 );
696 }
697 if ( !skip ) {
688 Event * test2 = testlist2.first(); 698 Event * test2 = testlist2.first();
689 while ( test2 ) { 699 while ( test2 ) {
690 skip = false; 700 skip = test2->isTagged();
691 if ( !all ) skip = ( allday != test2->doesFloat() ); 701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() );
702 if ( !skip ) {
703 if ( found )
704 skip = !test2->matchTime( &startDT, &conflict );
705 else
706 skip = !test2->matchTime( &startDT, 0 );
707 }
692 if ( !skip ) { 708 if ( !skip ) {
693 if ( !test2->isTagged() ) { 709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
694 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 710 //qDebug("overlap ");
695 //qDebug("overlap "); 711 if ( ! found ) {
696 if ( ! found ) { 712 if ( retVal >= startDT ) {
697 if ( retVal >= startDT ) { 713 conflict = retVal;
698 conflict = retVal; 714 cE = test;
699 cE = test; 715 cE2 = test2;
700 cE2 = test2; 716 found = true;
701 found = true; 717 }
702 } 718 } else {
703 } else { 719 if ( retVal >= startDT && retVal < conflict ) {
704 if ( retVal >= startDT && retVal < conflict ) { 720 conflict = retVal;
705 conflict = retVal; 721 cE = test;
706 cE = test; 722 cE2 = test2;
707 cE2 = test2;
708 }
709 } 723 }
710 } 724 }
711 } 725 }
712 } 726 }
713 test2 = testlist2.next(); 727 test2 = testlist2.next();
714 } 728 }
715 } 729 }
716 test->setTagged( true ); 730 test->setTagged( true );
717 test = testlist.next(); 731 test = testlist.next();
718 } 732 }
733 //qDebug("Search time : %d", tm.elapsed());
719 if ( found ) { 734 if ( found ) {
720 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
721 mViewManager->showDayView(); 736 mViewManager->showDayView();
722 mNavigator->slotDaySelect( conflict.date() ); 737 mNavigator->slotDaySelect( conflict.date() );
723 int hour = conflict.time().hour(); 738 int hour = conflict.time().hour();
724 mViewManager->agendaView()->setStartHour( hour ); 739 mViewManager->agendaView()->setStartHour( hour );
725 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
741 block = false;
726 return; 742 return;
727 } 743 }
728 744
729 topLevelWidget()->setCaption( i18n("No conflict found") ); 745 topLevelWidget()->setCaption( i18n("No conflict found") );
730 qDebug("No conflict found "); 746 qDebug("No conflict found ");
747 block = false;
731 return; 748 return;
732} 749}
733 750
734void CalendarView::conflictAll() 751void CalendarView::conflictAll()
735{ 752{
736 nextConflict ( true, true ); 753 nextConflict ( true, true );
737} 754}
738void CalendarView::conflictAllday() 755void CalendarView::conflictAllday()
739{ 756{
740 nextConflict ( false, true ); 757 nextConflict ( false, true );
741} 758}
742void CalendarView::conflictNotAll() 759void CalendarView::conflictNotAll()
743{ 760{
744 nextConflict ( false, false ); 761 nextConflict ( false, false );
745} 762}
746 763
747void CalendarView::setCalReadOnly( int id, bool readO ) 764void CalendarView::setCalReadOnly( int id, bool readO )
748{ 765{
749 if ( readO ) { 766 if ( readO ) {
750 emit save(); 767 emit save();
751 } 768 }
752 mCalendar->setReadOnly( id, readO ); 769 mCalendar->setReadOnly( id, readO );
753} 770}
754void CalendarView::setScrollBarStep(int val ) 771void CalendarView::setScrollBarStep(int val )
755{ 772{
756#ifdef DESKTOP_VERSION 773#ifdef DESKTOP_VERSION
757 mDateScrollBar->setLineStep ( val ); 774 mDateScrollBar->setLineStep ( val );
758#endif 775#endif
759} 776}
760void CalendarView::scrollBarValue(int val ) 777void CalendarView::scrollBarValue(int val )
761{ 778{
762#ifdef DESKTOP_VERSION 779#ifdef DESKTOP_VERSION
763 if ( QApplication::desktop()->width() < 800 ) return; 780 if ( QApplication::desktop()->width() < 800 ) return;
764 static bool block = false; 781 static bool block = false;
765 if ( block ) return; 782 if ( block ) return;
766 block = true; 783 block = true;
767 int count = mNavigator->selectedDates().count(); 784 int count = mNavigator->selectedDates().count();
768 int day = mNavigator->selectedDates().first().dayOfYear(); 785 int day = mNavigator->selectedDates().first().dayOfYear();
769 int stepdays = val; 786 int stepdays = val;
770 if ( mDateScrollBar->lineStep () <= count ) { 787 if ( mDateScrollBar->lineStep () <= count ) {
771 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 788 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
772 //qDebug("VAL %d ",val ); 789 //qDebug("VAL %d ",val );
773 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 790 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
774 stepdays = day+stepdays; 791 stepdays = day+stepdays;
775 if ( stepdays < 0 ) stepdays = 0; 792 if ( stepdays < 0 ) stepdays = 0;
776 } 793 }
777 if ( stepdays == day ) { 794 if ( stepdays == day ) {
778 block = false; 795 block = false;
779 return; 796 return;
780 } 797 }
781 int year = mNavigator->selectedDates().first().year(); 798 int year = mNavigator->selectedDates().first().year();
782 QDate d ( year,1,1 ); 799 QDate d ( year,1,1 );
783 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 800 mNavigator->selectDates( d.addDays( stepdays-1) , count );
784 block = false; 801 block = false;
785#endif 802#endif
786 803
787} 804}
788void CalendarView::updateView(const QDate &start, const QDate &end) 805void CalendarView::updateView(const QDate &start, const QDate &end)
789{ 806{
790#ifdef DESKTOP_VERSION 807#ifdef DESKTOP_VERSION
791 if ( ! mDateScrollBar->draggingSlider () ) { 808 if ( ! mDateScrollBar->draggingSlider () ) {
792 int dof = start.dayOfYear(); 809 int dof = start.dayOfYear();
793 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 810 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
794 if ( dof != mDateScrollBar->value() ) { 811 if ( dof != mDateScrollBar->value() ) {
795 mDateScrollBar->blockSignals( true ); 812 mDateScrollBar->blockSignals( true );
796 mDateScrollBar->setValue( start.dayOfYear()); 813 mDateScrollBar->setValue( start.dayOfYear());
797 mDateScrollBar->blockSignals( false ); 814 mDateScrollBar->blockSignals( false );
798 } 815 }
799 } 816 }
800#endif 817#endif
801 mTodoList->updateView(); 818 mTodoList->updateView();
802 mViewManager->updateView(start, end); 819 mViewManager->updateView(start, end);
803 //mDateNavigator->updateView(); 820 //mDateNavigator->updateView();
804} 821}
805 822
806 823
807 824
808void CalendarView::checkFiles() 825void CalendarView::checkFiles()
809{ 826{
810 QString message; 827 QString message;
811 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 828 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
812 KopiCalendarFile * cal = calendars.first(); 829 KopiCalendarFile * cal = calendars.first();
813 while ( cal ) { 830 while ( cal ) {
814 if ( cal->mErrorOnLoad ) { 831 if ( cal->mErrorOnLoad ) {
815 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 832 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
816 } 833 }
817 cal = calendars.next(); 834 cal = calendars.next();
818 } 835 }
819 if ( !message.isEmpty() ) { 836 if ( !message.isEmpty() ) {
820 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); 837 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0);
821 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 838 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
822 } 839 }
823 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 840 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
824} 841}
825void CalendarView::checkAlarms() 842void CalendarView::checkAlarms()
826{ 843{
827 844
828 845
829 KConfig *config = KOGlobals::config(); 846 KConfig *config = KOGlobals::config();
830 config->setGroup( "AppRun" ); 847 config->setGroup( "AppRun" );
831 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 848 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
832 int daysto = dt.daysTo( QDate::currentDate() ); 849 int daysto = dt.daysTo( QDate::currentDate() );
833 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 850 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
834 dt = dt.addDays( days ); 851 dt = dt.addDays( days );
835 int secto = dt.secsTo( QDateTime::currentDateTime() ); 852 int secto = dt.secsTo( QDateTime::currentDateTime() );
836 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 853 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
837 //qDebug("KO: Reading program stop %d ", secs); 854 //qDebug("KO: Reading program stop %d ", secs);
838 //secs -= ( 3600 * 24*3 ); // debug only 855 //secs -= ( 3600 * 24*3 ); // debug only
839 QDateTime latest = dt.addSecs ( secs ); 856 QDateTime latest = dt.addSecs ( secs );
840 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 857 qDebug("KO: Last termination on %s ", latest.toString().latin1());
841 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 858 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
842 QPtrList<Incidence> el = mCalendar->rawIncidences(); 859 QPtrList<Incidence> el = mCalendar->rawIncidences();
843 QPtrList<Incidence> al; 860 QPtrList<Incidence> al;
844 Incidence* inL = el.first(); 861 Incidence* inL = el.first();
845 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 862 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
846 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 863 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
847 while ( inL ) { 864 while ( inL ) {
848 bool ok = false; 865 bool ok = false;
849 int offset = 0; 866 int offset = 0;
850 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 867 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
851 if ( ok ) { 868 if ( ok ) {
852 //qDebug("OK %s",next.toString().latin1()); 869 //qDebug("OK %s",next.toString().latin1());
853 if ( next < cur ) { 870 if ( next < cur ) {
854 al.append( inL ); 871 al.append( inL );
855 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 872 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
856 } 873 }
857 } 874 }
858 inL = el.next(); 875 inL = el.next();
859 } 876 }
860 if ( al.count() ) { 877 if ( al.count() ) {
861 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 878 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
862 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 879 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
863 QVBoxLayout* lay = new QVBoxLayout( dia ); 880 QVBoxLayout* lay = new QVBoxLayout( dia );
864 lay->setSpacing( 0 ); 881 lay->setSpacing( 0 );
865 lay->setMargin( 0 ); 882 lay->setMargin( 0 );
866 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 883 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
867 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 884 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
868 lay->addWidget( matb ); 885 lay->addWidget( matb );
869 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 886 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
870 int wid = 210; 887 int wid = 210;
871 int x = QApplication::desktop()->width() - wid - 7; 888 int x = QApplication::desktop()->width() - wid - 7;
872 int y = QApplication::desktop()->height() - wid - 70; 889 int y = QApplication::desktop()->height() - wid - 70;
873 dia->setGeometry ( x,y,wid,wid); 890 dia->setGeometry ( x,y,wid,wid);
874 } else { 891 } else {
875 int si = 220; 892 int si = 220;
876 if ( QApplication::desktop()->width() > 470 ) 893 if ( QApplication::desktop()->width() > 470 )
877 si = 400; 894 si = 400;
878 dia->resize(si,si/2); 895 dia->resize(si,si/2);
879 } 896 }
880 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 897 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
881 dia->show(); 898 dia->show();
882 899
883 } 900 }
884} 901}
885void CalendarView::showDay( QDate d ) 902void CalendarView::showDay( QDate d )
886{ 903{
887 dateNavigator()->blockSignals( true ); 904 dateNavigator()->blockSignals( true );
888 dateNavigator()->selectDate( d ); 905 dateNavigator()->selectDate( d );
889 dateNavigator()->blockSignals( false ); 906 dateNavigator()->blockSignals( false );
890 mViewManager->showDayView(); 907 mViewManager->showDayView();
891 //dateNavigator()->selectDate( d ); 908 //dateNavigator()->selectDate( d );
892} 909}
893void CalendarView::timerAlarm() 910void CalendarView::timerAlarm()
894{ 911{
895 //qDebug("CalendarView::timerAlarm() "); 912 //qDebug("CalendarView::timerAlarm() ");
896 computeAlarm(mAlarmNotification ); 913 computeAlarm(mAlarmNotification );
897} 914}
898 915
899void CalendarView::suspendAlarm() 916void CalendarView::suspendAlarm()
900{ 917{
901 //qDebug(" CalendarView::suspendAlarm() "); 918 //qDebug(" CalendarView::suspendAlarm() ");
902 computeAlarm(mSuspendAlarmNotification ); 919 computeAlarm(mSuspendAlarmNotification );
903 920
904} 921}
905 922
906void CalendarView::startAlarm( QString mess , QString filename) 923void CalendarView::startAlarm( QString mess , QString filename)
907{ 924{
908 925
909 topLevelWidget()->showNormal(); 926 topLevelWidget()->showNormal();
910 topLevelWidget()->setActiveWindow(); 927 topLevelWidget()->setActiveWindow();
911 topLevelWidget()->raise(); 928 topLevelWidget()->raise();
912 929
913 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 930 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
914 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 931 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
915 932
916} 933}
917 934
918void CalendarView::checkNextTimerAlarm() 935void CalendarView::checkNextTimerAlarm()
919{ 936{
920 mCalendar->checkAlarmForIncidence( 0, true ); 937 mCalendar->checkAlarmForIncidence( 0, true );
921} 938}
922 939
923void CalendarView::computeAlarm( QString msg ) 940void CalendarView::computeAlarm( QString msg )
924{ 941{
925 942
926 QString mess = msg; 943 QString mess = msg;
927 QString mAlarmMessage = mess.mid( 9 ); 944 QString mAlarmMessage = mess.mid( 9 );
928 QString filename = MainWindow::resourcePath(); 945 QString filename = MainWindow::resourcePath();
929 filename += "koalarm.wav"; 946 filename += "koalarm.wav";
930 QString tempfilename; 947 QString tempfilename;
931 if ( mess.left( 13 ) == "suspend_alarm") { 948 if ( mess.left( 13 ) == "suspend_alarm") {
932 bool error = false; 949 bool error = false;
933 int len = mess.mid( 13 ).find("+++"); 950 int len = mess.mid( 13 ).find("+++");
934 if ( len < 2 ) 951 if ( len < 2 )
935 error = true; 952 error = true;
936 else { 953 else {
937 tempfilename = mess.mid( 13, len ); 954 tempfilename = mess.mid( 13, len );
938 if ( !QFile::exists( tempfilename ) ) 955 if ( !QFile::exists( tempfilename ) )
939 error = true; 956 error = true;
940 } 957 }
941 if ( ! error ) { 958 if ( ! error ) {
942 filename = tempfilename; 959 filename = tempfilename;
943 } 960 }
944 mAlarmMessage = mess.mid( 13+len+3 ); 961 mAlarmMessage = mess.mid( 13+len+3 );
945 //qDebug("suspend file %s ",tempfilename.latin1() ); 962 //qDebug("suspend file %s ",tempfilename.latin1() );
946 startAlarm( mAlarmMessage, filename); 963 startAlarm( mAlarmMessage, filename);
947 return; 964 return;
948 } 965 }
949 if ( mess.left( 11 ) == "timer_alarm") { 966 if ( mess.left( 11 ) == "timer_alarm") {
950 //mTimerTime = 0; 967 //mTimerTime = 0;
951 startAlarm( mess.mid( 11 ), filename ); 968 startAlarm( mess.mid( 11 ), filename );
952 return; 969 return;
953 } 970 }
954 if ( mess.left( 10 ) == "proc_alarm") { 971 if ( mess.left( 10 ) == "proc_alarm") {
955 bool error = false; 972 bool error = false;
956 int len = mess.mid( 10 ).find("+++"); 973 int len = mess.mid( 10 ).find("+++");
957 if ( len < 2 ) 974 if ( len < 2 )
958 error = true; 975 error = true;
959 else { 976 else {
960 tempfilename = mess.mid( 10, len ); 977 tempfilename = mess.mid( 10, len );
961 if ( !QFile::exists( tempfilename ) ) 978 if ( !QFile::exists( tempfilename ) )
962 error = true; 979 error = true;
963 } 980 }
964 if ( error ) { 981 if ( error ) {
965 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 982 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
966 mAlarmMessage += mess.mid( 10+len+3+9 ); 983 mAlarmMessage += mess.mid( 10+len+3+9 );
967 } else { 984 } else {
968 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 985 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
969 //qDebug("-----system command %s ",tempfilename.latin1() ); 986 //qDebug("-----system command %s ",tempfilename.latin1() );
970#ifndef _WIN32_ 987#ifndef _WIN32_
971 if ( vfork () == 0 ) { 988 if ( vfork () == 0 ) {
972 execl ( tempfilename.latin1(), 0 ); 989 execl ( tempfilename.latin1(), 0 );
973 return; 990 return;
974 } 991 }
975#else 992#else
976 QProcess* p = new QProcess(); 993 QProcess* p = new QProcess();
977 p->addArgument( tempfilename.latin1() ); 994 p->addArgument( tempfilename.latin1() );
978 p->start(); 995 p->start();
979 return; 996 return;
980#endif 997#endif
981 998
982 return; 999 return;
983 } 1000 }
984 1001
985 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 1002 //qDebug("+++++++system command %s ",tempfilename.latin1() );
986 } 1003 }
987 if ( mess.left( 11 ) == "audio_alarm") { 1004 if ( mess.left( 11 ) == "audio_alarm") {
988 bool error = false; 1005 bool error = false;
989 int len = mess.mid( 11 ).find("+++"); 1006 int len = mess.mid( 11 ).find("+++");
990 if ( len < 2 ) 1007 if ( len < 2 )
991 error = true; 1008 error = true;
992 else { 1009 else {
993 tempfilename = mess.mid( 11, len ); 1010 tempfilename = mess.mid( 11, len );
994 if ( !QFile::exists( tempfilename ) ) 1011 if ( !QFile::exists( tempfilename ) )
995 error = true; 1012 error = true;
996 } 1013 }
997 if ( ! error ) { 1014 if ( ! error ) {
998 filename = tempfilename; 1015 filename = tempfilename;
999 } 1016 }
1000 mAlarmMessage = mess.mid( 11+len+3+9 ); 1017 mAlarmMessage = mess.mid( 11+len+3+9 );
1001 //qDebug("audio file command %s ",tempfilename.latin1() ); 1018 //qDebug("audio file command %s ",tempfilename.latin1() );
1002 } 1019 }
1003 if ( mess.left( 9 ) == "cal_alarm") { 1020 if ( mess.left( 9 ) == "cal_alarm") {
1004 mAlarmMessage = mess.mid( 9 ) ; 1021 mAlarmMessage = mess.mid( 9 ) ;
1005 } 1022 }
1006 1023
1007 startAlarm( mAlarmMessage, filename ); 1024 startAlarm( mAlarmMessage, filename );
1008 1025
1009 1026
1010} 1027}
1011 1028
1012void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1029void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1013{ 1030{
1014 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1031 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1015 1032
1016 mSuspendAlarmNotification = noti; 1033 mSuspendAlarmNotification = noti;
1017 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1034 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1018 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1035 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1019 mSuspendTimer->start( ms , true ); 1036 mSuspendTimer->start( ms , true );
1020 1037
1021} 1038}
1022 1039
1023void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1040void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1024{ 1041{
1025 mNextAlarmDateTime = qdt; 1042 mNextAlarmDateTime = qdt;
1026 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1043 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1027 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1044 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1028#ifndef DESKTOP_VERSION 1045#ifndef DESKTOP_VERSION
1029 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1046 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1030#endif 1047#endif
1031 return; 1048 return;
1032 } 1049 }
1033 int maxSec; 1050 int maxSec;
1034 //maxSec = 5; //testing only 1051 //maxSec = 5; //testing only
1035 maxSec = 86400+3600; // one day+1hour 1052 maxSec = 86400+3600; // one day+1hour
1036 mAlarmNotification = noti; 1053 mAlarmNotification = noti;
1037 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1054 int sec = QDateTime::currentDateTime().secsTo( qdt );
1038 if ( sec > maxSec ) { 1055 if ( sec > maxSec ) {
1039 mRecheckAlarmTimer->start( maxSec * 1000 ); 1056 mRecheckAlarmTimer->start( maxSec * 1000 );
1040 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1057 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1041 return; 1058 return;
1042 } else { 1059 } else {
1043 mRecheckAlarmTimer->stop(); 1060 mRecheckAlarmTimer->stop();
1044 } 1061 }
1045 //qDebug("Alarm timer started with secs: %d ", sec); 1062 //qDebug("Alarm timer started with secs: %d ", sec);
1046 mAlarmTimer->start( sec *1000 , true ); 1063 mAlarmTimer->start( sec *1000 , true );
1047 1064
1048} 1065}
1049// called by mRecheckAlarmTimer to get next alarm 1066// called by mRecheckAlarmTimer to get next alarm
1050// we need this, because a QTimer has only a max range of 25 days 1067// we need this, because a QTimer has only a max range of 25 days
1051void CalendarView::recheckTimerAlarm() 1068void CalendarView::recheckTimerAlarm()
1052{ 1069{
1053 mAlarmTimer->stop(); 1070 mAlarmTimer->stop();
1054 mRecheckAlarmTimer->stop(); 1071 mRecheckAlarmTimer->stop();
1055 mCalendar->checkAlarmForIncidence( 0, true ); 1072 mCalendar->checkAlarmForIncidence( 0, true );
1056} 1073}
1057#ifndef DESKTOP_VERSION 1074#ifndef DESKTOP_VERSION
1058void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1075void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1059#else 1076#else
1060void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1077void CalendarView::removeAlarm(const QDateTime &, const QString & )
1061#endif 1078#endif
1062{ 1079{
1063 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1080 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1064 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1081 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1065#ifndef DESKTOP_VERSION 1082#ifndef DESKTOP_VERSION
1066 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1083 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1067#endif 1084#endif
1068 return; 1085 return;
1069 } 1086 }
1070 mAlarmTimer->stop(); 1087 mAlarmTimer->stop();
1071} 1088}
1072void CalendarView::selectWeekNum ( int num ) 1089void CalendarView::selectWeekNum ( int num )
1073{ 1090{
1074 dateNavigator()->blockSignals( true ); 1091 dateNavigator()->blockSignals( true );
1075 dateNavigator()->selectWeek( num ); 1092 dateNavigator()->selectWeek( num );
1076 dateNavigator()->blockSignals( false ); 1093 dateNavigator()->blockSignals( false );
1077 mViewManager->showWeekView(); 1094 mViewManager->showWeekView();
1078} 1095}
1079KOViewManager *CalendarView::viewManager() 1096KOViewManager *CalendarView::viewManager()
1080{ 1097{
1081 return mViewManager; 1098 return mViewManager;
1082} 1099}
1083 1100
1084KODialogManager *CalendarView::dialogManager() 1101KODialogManager *CalendarView::dialogManager()
1085{ 1102{
1086 return mDialogManager; 1103 return mDialogManager;
1087} 1104}
1088 1105
1089QDate CalendarView::startDate() 1106QDate CalendarView::startDate()
1090{ 1107{
1091 DateList dates = mNavigator->selectedDates(); 1108 DateList dates = mNavigator->selectedDates();
1092 1109
1093 return dates.first(); 1110 return dates.first();
1094} 1111}
1095 1112
1096QDate CalendarView::endDate() 1113QDate CalendarView::endDate()
1097{ 1114{
1098 DateList dates = mNavigator->selectedDates(); 1115 DateList dates = mNavigator->selectedDates();
1099 1116
1100 return dates.last(); 1117 return dates.last();
1101} 1118}
1102 1119
1103 1120
1104void CalendarView::createPrinter() 1121void CalendarView::createPrinter()
1105{ 1122{
1106#ifndef KORG_NOPRINTER 1123#ifndef KORG_NOPRINTER
1107 if (!mCalPrinter) { 1124 if (!mCalPrinter) {
1108 mCalPrinter = new CalPrinter(this, mCalendar); 1125 mCalPrinter = new CalPrinter(this, mCalendar);
1109 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1126 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1110 } 1127 }
1111#endif 1128#endif
1112} 1129}
1113 1130
1114 1131
1115//KOPrefs::instance()->mWriteBackFile 1132//KOPrefs::instance()->mWriteBackFile
1116//KOPrefs::instance()->mWriteBackExistingOnly 1133//KOPrefs::instance()->mWriteBackExistingOnly
1117 1134
1118// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1135// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1119// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1136// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1120// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1137// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1121// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1138// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1122// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1139// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1123// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1140// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1124 1141
1125int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1142int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1126{ 1143{
1127 1144
1128 // 0 equal 1145 // 0 equal
1129 // 1 take local 1146 // 1 take local
1130 // 2 take remote 1147 // 2 take remote
1131 // 3 cancel 1148 // 3 cancel
1132 QDateTime lastSync = mLastCalendarSync; 1149 QDateTime lastSync = mLastCalendarSync;
1133 QDateTime localMod = local->lastModified(); 1150 QDateTime localMod = local->lastModified();
1134 QDateTime remoteMod = remote->lastModified(); 1151 QDateTime remoteMod = remote->lastModified();
1135 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1152 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1136 bool remCh, locCh; 1153 bool remCh, locCh;
1137 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1154 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1138 //if ( remCh ) 1155 //if ( remCh )
1139 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1156 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1140 locCh = ( localMod > mLastCalendarSync ); 1157 locCh = ( localMod > mLastCalendarSync );
1141 if ( !remCh && ! locCh ) { 1158 if ( !remCh && ! locCh ) {
1142 //qDebug("both not changed "); 1159 //qDebug("both not changed ");
1143 lastSync = localMod.addDays(1); 1160 lastSync = localMod.addDays(1);
1144 if ( mode <= SYNC_PREF_ASK ) 1161 if ( mode <= SYNC_PREF_ASK )
1145 return 0; 1162 return 0;
1146 } else { 1163 } else {
1147 if ( locCh ) { 1164 if ( locCh ) {
1148 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1165 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1149 lastSync = localMod.addDays( -1 ); 1166 lastSync = localMod.addDays( -1 );
1150 if ( !remCh ) 1167 if ( !remCh )
1151 remoteMod = ( lastSync.addDays( -1 ) ); 1168 remoteMod = ( lastSync.addDays( -1 ) );
1152 } else { 1169 } else {
1153 //qDebug(" not loc changed "); 1170 //qDebug(" not loc changed ");
1154 lastSync = localMod.addDays( 1 ); 1171 lastSync = localMod.addDays( 1 );
1155 if ( remCh ) 1172 if ( remCh )
1156 remoteMod =( lastSync.addDays( 1 ) ); 1173 remoteMod =( lastSync.addDays( 1 ) );
1157 1174
1158 } 1175 }
1159 } 1176 }
1160 full = true; 1177 full = true;
1161 if ( mode < SYNC_PREF_ASK ) 1178 if ( mode < SYNC_PREF_ASK )
1162 mode = SYNC_PREF_ASK; 1179 mode = SYNC_PREF_ASK;
1163 } else { 1180 } else {
1164 if ( localMod == remoteMod ) 1181 if ( localMod == remoteMod )
1165 // if ( local->revision() == remote->revision() ) 1182 // if ( local->revision() == remote->revision() )
1166 return 0; 1183 return 0;
1167 1184
1168 } 1185 }
1169 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1186 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1170 1187
1171 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1188 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1172 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1189 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1173 //full = true; //debug only 1190 //full = true; //debug only
1174 if ( full ) { 1191 if ( full ) {
1175 bool equ = false; 1192 bool equ = false;
1176 if ( local->typeID() == eventID ) { 1193 if ( local->typeID() == eventID ) {
1177 equ = (*((Event*) local) == *((Event*) remote)); 1194 equ = (*((Event*) local) == *((Event*) remote));
1178 } 1195 }
1179 else if ( local->typeID() == todoID ) 1196 else if ( local->typeID() == todoID )
1180 equ = (*((Todo*) local) == (*(Todo*) remote)); 1197 equ = (*((Todo*) local) == (*(Todo*) remote));
1181 else if ( local->typeID() == journalID ) 1198 else if ( local->typeID() == journalID )
1182 equ = (*((Journal*) local) == *((Journal*) remote)); 1199 equ = (*((Journal*) local) == *((Journal*) remote));
1183 if ( equ ) { 1200 if ( equ ) {
1184 //qDebug("equal "); 1201 //qDebug("equal ");
1185 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1202 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1186 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1203 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1187 } 1204 }
1188 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1205 if ( mode < SYNC_PREF_FORCE_LOCAL )
1189 return 0; 1206 return 0;
1190 1207
1191 }//else //debug only 1208 }//else //debug only
1192 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1209 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1193 } 1210 }
1194 int result; 1211 int result;
1195 bool localIsNew; 1212 bool localIsNew;
1196 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1213 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1197 1214
1198 1215
1199 // ************************************************ 1216 // ************************************************
1200 // ************************************************ 1217 // ************************************************
1201 // ************************************************ 1218 // ************************************************
1202 // We may have that lastSync > remoteMod AND lastSync > localMod 1219 // We may have that lastSync > remoteMod AND lastSync > localMod
1203 // BUT remoteMod != localMod 1220 // BUT remoteMod != localMod
1204 1221
1205 1222
1206 if ( full && mode < SYNC_PREF_NEWEST ) 1223 if ( full && mode < SYNC_PREF_NEWEST )
1207 mode = SYNC_PREF_ASK; 1224 mode = SYNC_PREF_ASK;
1208 1225
1209 switch( mode ) { 1226 switch( mode ) {
1210 case SYNC_PREF_LOCAL: 1227 case SYNC_PREF_LOCAL:
1211 if ( lastSync > remoteMod ) 1228 if ( lastSync > remoteMod )
1212 return 1; 1229 return 1;
1213 if ( lastSync > localMod ) 1230 if ( lastSync > localMod )
1214 return 2; 1231 return 2;
1215 return 1; 1232 return 1;
1216 break; 1233 break;
1217 case SYNC_PREF_REMOTE: 1234 case SYNC_PREF_REMOTE:
1218 if ( lastSync > localMod ) 1235 if ( lastSync > localMod )
1219 return 2; 1236 return 2;
1220 if ( lastSync > remoteMod ) 1237 if ( lastSync > remoteMod )
1221 return 1; 1238 return 1;
1222 return 2; 1239 return 2;
1223 break; 1240 break;
1224 case SYNC_PREF_NEWEST: 1241 case SYNC_PREF_NEWEST:
1225 if ( localMod >= remoteMod ) 1242 if ( localMod >= remoteMod )
1226 return 1; 1243 return 1;
1227 else 1244 else
1228 return 2; 1245 return 2;
1229 break; 1246 break;
1230 case SYNC_PREF_ASK: 1247 case SYNC_PREF_ASK:
1231 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1248 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1232 if ( lastSync > remoteMod && lastSync > localMod) 1249 if ( lastSync > remoteMod && lastSync > localMod)
1233 return 0; 1250 return 0;
1234 if ( lastSync > remoteMod ) 1251 if ( lastSync > remoteMod )
1235 return 1; 1252 return 1;
1236 if ( lastSync > localMod ) 1253 if ( lastSync > localMod )
1237 return 2; 1254 return 2;
1238 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1255 qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1239 localIsNew = localMod >= remoteMod; 1256 localIsNew = localMod >= remoteMod;
1240 if ( localIsNew ) 1257 if ( localIsNew )
1241 getEventViewerDialog()->setColorMode( 1 ); 1258 getEventViewerDialog()->setColorMode( 1 );
1242 else 1259 else
1243 getEventViewerDialog()->setColorMode( 2 ); 1260 getEventViewerDialog()->setColorMode( 2 );
1244 getEventViewerDialog()->setIncidence(local); 1261 getEventViewerDialog()->setIncidence(local);
1245 if ( localIsNew ) 1262 if ( localIsNew )
1246 getEventViewerDialog()->setColorMode( 2 ); 1263 getEventViewerDialog()->setColorMode( 2 );
1247 else 1264 else
1248 getEventViewerDialog()->setColorMode( 1 ); 1265 getEventViewerDialog()->setColorMode( 1 );
1249 getEventViewerDialog()->addIncidence(remote); 1266 getEventViewerDialog()->addIncidence(remote);
1250 getEventViewerDialog()->setColorMode( 0 ); 1267 getEventViewerDialog()->setColorMode( 0 );
1251 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1268 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1252 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1269 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1253 getEventViewerDialog()->showMe(); 1270 getEventViewerDialog()->showMe();
1254 result = getEventViewerDialog()->executeS( localIsNew ); 1271 result = getEventViewerDialog()->executeS( localIsNew );
1255 return result; 1272 return result;
1256 1273
1257 break; 1274 break;
1258 case SYNC_PREF_FORCE_LOCAL: 1275 case SYNC_PREF_FORCE_LOCAL:
1259 return 1; 1276 return 1;
1260 break; 1277 break;
1261 case SYNC_PREF_FORCE_REMOTE: 1278 case SYNC_PREF_FORCE_REMOTE:
1262 return 2; 1279 return 2;
1263 break; 1280 break;
1264 1281
1265 default: 1282 default:
1266 // SYNC_PREF_TAKE_BOTH not implemented 1283 // SYNC_PREF_TAKE_BOTH not implemented
1267 break; 1284 break;
1268 } 1285 }
1269 return 0; 1286 return 0;
1270} 1287}
1271Event* CalendarView::getLastSyncEvent() 1288Event* CalendarView::getLastSyncEvent()
1272{ 1289{
1273 Event* lse; 1290 Event* lse;
1274 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1291 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1275 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1292 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1276 if (!lse) { 1293 if (!lse) {
1277 lse = new Event(); 1294 lse = new Event();
1278 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1295 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1279 QString sum = ""; 1296 QString sum = "";
1280 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1297 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1281 sum = "E: "; 1298 sum = "E: ";
1282 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1299 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1283 lse->setDtStart( mLastCalendarSync ); 1300 lse->setDtStart( mLastCalendarSync );
1284 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1301 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1285 lse->setCategories( i18n("SyncEvent") ); 1302 lse->setCategories( i18n("SyncEvent") );
1286 lse->setReadOnly( true ); 1303 lse->setReadOnly( true );
1287 mCalendar->addEvent( lse ); 1304 mCalendar->addEvent( lse );
1288 } 1305 }
1289 1306
1290 return lse; 1307 return lse;
1291 1308
1292} 1309}
1293 1310
1294// we check, if the to delete event has a id for a profile 1311// we check, if the to delete event has a id for a profile
1295// if yes, we set this id in the profile to delete 1312// if yes, we set this id in the profile to delete
1296void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1313void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1297{ 1314{
1298 if ( lastSync.count() == 0 ) { 1315 if ( lastSync.count() == 0 ) {
1299 //qDebug(" lastSync.count() == 0"); 1316 //qDebug(" lastSync.count() == 0");
1300 return; 1317 return;
1301 } 1318 }
1302 if ( toDelete->typeID() == journalID ) 1319 if ( toDelete->typeID() == journalID )
1303 return; 1320 return;
1304 1321
1305 Event* eve = lastSync.first(); 1322 Event* eve = lastSync.first();
1306 1323
1307 while ( eve ) { 1324 while ( eve ) {
1308 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1325 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1309 if ( !id.isEmpty() ) { 1326 if ( !id.isEmpty() ) {
1310 QString des = eve->description(); 1327 QString des = eve->description();
1311 QString pref = "e"; 1328 QString pref = "e";
1312 if ( toDelete->typeID() == todoID ) 1329 if ( toDelete->typeID() == todoID )
1313 pref = "t"; 1330 pref = "t";
1314 des += pref+ id + ","; 1331 des += pref+ id + ",";
1315 eve->setReadOnly( false ); 1332 eve->setReadOnly( false );
1316 eve->setDescription( des ); 1333 eve->setDescription( des );
1317 //qDebug("setdes %s ", des.latin1()); 1334 //qDebug("setdes %s ", des.latin1());
1318 eve->setReadOnly( true ); 1335 eve->setReadOnly( true );
1319 } 1336 }
1320 eve = lastSync.next(); 1337 eve = lastSync.next();
1321 } 1338 }
1322 1339
1323} 1340}
1324void CalendarView::checkExternalId( Incidence * inc ) 1341void CalendarView::checkExternalId( Incidence * inc )
1325{ 1342{
1326 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1343 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1327 checkExternSyncEvent( lastSync, inc ); 1344 checkExternSyncEvent( lastSync, inc );
1328 1345
1329} 1346}
1330bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1347bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1331{ 1348{
1332 bool syncOK = true; 1349 bool syncOK = true;
1333 int addedEvent = 0; 1350 int addedEvent = 0;
1334 int addedEventR = 0; 1351 int addedEventR = 0;
1335 int deletedEventR = 0; 1352 int deletedEventR = 0;
1336 int deletedEventL = 0; 1353 int deletedEventL = 0;
1337 int changedLocal = 0; 1354 int changedLocal = 0;
1338 int changedRemote = 0; 1355 int changedRemote = 0;
1339 int filteredIN = 0; 1356 int filteredIN = 0;
1340 int filteredOUT = 0; 1357 int filteredOUT = 0;
1341 //QPtrList<Event> el = local->rawEvents(); 1358 //QPtrList<Event> el = local->rawEvents();
1342 Event* eventR; 1359 Event* eventR;
1343 QString uid; 1360 QString uid;
1344 int take; 1361 int take;
1345 Event* eventRSync; 1362 Event* eventRSync;
1346 Event* eventLSync; 1363 Event* eventLSync;
1347 clearAllViews(); 1364 clearAllViews();
1348 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1365 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1349 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1366 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1350 bool fullDateRange = false; 1367 bool fullDateRange = false;
1351 local->resetTempSyncStat(); 1368 local->resetTempSyncStat();
1352 mLastCalendarSync = QDateTime::currentDateTime(); 1369 mLastCalendarSync = QDateTime::currentDateTime();
1353 if ( mSyncManager->syncWithDesktop() ) { 1370 if ( mSyncManager->syncWithDesktop() ) {
1354 remote->resetPilotStat(1); 1371 remote->resetPilotStat(1);
1355 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1372 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1356 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1373 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1357 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1374 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1358 } else { 1375 } else {
1359 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1376 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1360 } 1377 }
1361 } 1378 }
1362 QDateTime modifiedCalendar = mLastCalendarSync; 1379 QDateTime modifiedCalendar = mLastCalendarSync;
1363 eventLSync = getLastSyncEvent(); 1380 eventLSync = getLastSyncEvent();
1364 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1381 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1365 if ( eventR ) { 1382 if ( eventR ) {
1366 qDebug("last-syncEvent on remote found "); 1383 qDebug("last-syncEvent on remote found ");
1367 eventRSync = (Event*) eventR->clone(); 1384 eventRSync = (Event*) eventR->clone();
1368 remote->deleteEvent(eventR ); 1385 remote->deleteEvent(eventR );
1369 1386
1370 } else { 1387 } else {
1371 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1388 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1372 eventRSync = (Event*)eventLSync->clone(); 1389 eventRSync = (Event*)eventLSync->clone();
1373 } else { 1390 } else {
1374 fullDateRange = true; 1391 fullDateRange = true;
1375 eventRSync = new Event(); 1392 eventRSync = new Event();
1376 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1393 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1377 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1394 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1378 eventRSync->setDtStart( mLastCalendarSync ); 1395 eventRSync->setDtStart( mLastCalendarSync );
1379 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1396 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1380 eventRSync->setCategories( i18n("SyncEvent") ); 1397 eventRSync->setCategories( i18n("SyncEvent") );
1381 } 1398 }
1382 } 1399 }
1383 if ( eventLSync->dtStart() == mLastCalendarSync ) 1400 if ( eventLSync->dtStart() == mLastCalendarSync )
1384 fullDateRange = true; 1401 fullDateRange = true;
1385 1402
1386 if ( ! fullDateRange ) { 1403 if ( ! fullDateRange ) {
1387 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1404 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1388 1405
1389 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1406 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1390 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1407 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1391 fullDateRange = true; 1408 fullDateRange = true;
1392 } 1409 }
1393 } 1410 }
1394 if ( mSyncManager->syncWithDesktop() ) { 1411 if ( mSyncManager->syncWithDesktop() ) {
1395 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1412 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1396 } 1413 }
1397 if ( fullDateRange ) 1414 if ( fullDateRange )
1398 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1415 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1399 else 1416 else
1400 mLastCalendarSync = eventLSync->dtStart(); 1417 mLastCalendarSync = eventLSync->dtStart();
1401 // for resyncing if own file has changed 1418 // for resyncing if own file has changed
1402 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1419 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1403 mLastCalendarSync = loadedFileVersion; 1420 mLastCalendarSync = loadedFileVersion;
1404 //qDebug("setting mLastCalendarSync "); 1421 //qDebug("setting mLastCalendarSync ");
1405 } 1422 }
1406 //qDebug("*************************** "); 1423 //qDebug("*************************** ");
1407 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1424 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1408 QPtrList<Incidence> er = remote->rawIncidences(); 1425 QPtrList<Incidence> er = remote->rawIncidences();
1409 Incidence* inR = er.first(); 1426 Incidence* inR = er.first();
1410 Incidence* inL; 1427 Incidence* inL;
1411 QProgressBar bar( er.count(),0 ); 1428 QProgressBar bar( er.count(),0 );
1412 bar.setCaption (i18n("Syncing - close to abort!") ); 1429 bar.setCaption (i18n("Syncing - close to abort!") );
1413 1430
1414 // ************** setting up filter ************* 1431 // ************** setting up filter *************
1415 CalFilter *filterIN = 0; 1432 CalFilter *filterIN = 0;
1416 CalFilter *filterOUT = 0; 1433 CalFilter *filterOUT = 0;
1417 CalFilter *filter = mFilters.first(); 1434 CalFilter *filter = mFilters.first();
1418 while(filter) { 1435 while(filter) {
1419 if ( filter->name() == mSyncManager->mFilterInCal ) 1436 if ( filter->name() == mSyncManager->mFilterInCal )
1420 filterIN = filter; 1437 filterIN = filter;
1421 if ( filter->name() == mSyncManager->mFilterOutCal ) 1438 if ( filter->name() == mSyncManager->mFilterOutCal )
1422 filterOUT = filter; 1439 filterOUT = filter;
1423 filter = mFilters.next(); 1440 filter = mFilters.next();
1424 } 1441 }
1425 int w = 300; 1442 int w = 300;
1426 if ( QApplication::desktop()->width() < 320 ) 1443 if ( QApplication::desktop()->width() < 320 )
1427 w = 220; 1444 w = 220;
1428 int h = bar.sizeHint().height() ; 1445 int h = bar.sizeHint().height() ;
1429 int dw = QApplication::desktop()->width(); 1446 int dw = QApplication::desktop()->width();
1430 int dh = QApplication::desktop()->height(); 1447 int dh = QApplication::desktop()->height();
1431 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1448 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1432 bar.show(); 1449 bar.show();
1433 int modulo = (er.count()/10)+1; 1450 int modulo = (er.count()/10)+1;
1434 int incCounter = 0; 1451 int incCounter = 0;
1435 while ( inR ) { 1452 while ( inR ) {
1436 if ( ! bar.isVisible() ) 1453 if ( ! bar.isVisible() )
1437 return false; 1454 return false;
1438 if ( incCounter % modulo == 0 ) 1455 if ( incCounter % modulo == 0 )
1439 bar.setProgress( incCounter ); 1456 bar.setProgress( incCounter );
1440 ++incCounter; 1457 ++incCounter;
1441 uid = inR->uid(); 1458 uid = inR->uid();
1442 bool skipIncidence = false; 1459 bool skipIncidence = false;
1443 if ( uid.left(15) == QString("last-syncEvent-") ) 1460 if ( uid.left(15) == QString("last-syncEvent-") )
1444 skipIncidence = true; 1461 skipIncidence = true;
1445 QString idS; 1462 QString idS;
1446 qApp->processEvents(); 1463 qApp->processEvents();
1447 if ( !skipIncidence ) { 1464 if ( !skipIncidence ) {
1448 inL = local->incidenceForUid( uid , false ); 1465 inL = local->incidenceForUid( uid , false );
1449 if ( inL ) { // maybe conflict - same uid in both calendars 1466 if ( inL ) { // maybe conflict - same uid in both calendars
1450 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1467 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1451 //qDebug("take %d %s ", take, inL->summary().latin1()); 1468 //qDebug("take %d %s ", take, inL->summary().latin1());
1452 if ( take == 3 ) 1469 if ( take == 3 )
1453 return false; 1470 return false;
1454 if ( take == 1 ) {// take local ********************** 1471 if ( take == 1 ) {// take local **********************
1455 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1472 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1456 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1473 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1457 else 1474 else
1458 idS = inR->IDStr(); 1475 idS = inR->IDStr();
1459 int calID = inR->calID(); 1476 int calID = inR->calID();
1460 remote->deleteIncidence( inR ); 1477 remote->deleteIncidence( inR );
1461 inR = inL->clone(); 1478 inR = inL->clone();
1462 inR->setCalID( calID ); 1479 inR->setCalID( calID );
1463 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1480 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1464 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1481 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1465 inR->setIDStr( idS ); 1482 inR->setIDStr( idS );
1466 remote->addIncidence( inR ); 1483 remote->addIncidence( inR );
1467 if ( mSyncManager->syncWithDesktop() ) 1484 if ( mSyncManager->syncWithDesktop() )
1468 inR->setPilotId( 2 ); 1485 inR->setPilotId( 2 );
1469 ++changedRemote; 1486 ++changedRemote;
1470 } else {// take remote ********************** 1487 } else {// take remote **********************
1471 if ( !inL->isReadOnly() ) { 1488 if ( !inL->isReadOnly() ) {
1472 idS = inL->IDStr(); 1489 idS = inL->IDStr();
1473 int pid = inL->pilotId(); 1490 int pid = inL->pilotId();
1474 int calID = inL->calID(); 1491 int calID = inL->calID();
1475 local->deleteIncidence( inL ); 1492 local->deleteIncidence( inL );
1476 inL = inR->clone(); 1493 inL = inR->clone();
1477 inL->setCalID( calID ); 1494 inL->setCalID( calID );
1478 if ( mSyncManager->syncWithDesktop() ) 1495 if ( mSyncManager->syncWithDesktop() )
1479 inL->setPilotId( pid ); 1496 inL->setPilotId( pid );
1480 inL->setIDStr( idS ); 1497 inL->setIDStr( idS );
1481 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1498 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1482 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1483 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1484 } 1501 }
1485 local->addIncidence( inL ); 1502 local->addIncidence( inL );
1486 ++changedLocal; 1503 ++changedLocal;
1487 } 1504 }
1488 } 1505 }
1489 } 1506 }
1490 } else { // no conflict ********** add or delete remote 1507 } else { // no conflict ********** add or delete remote
1491 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1508 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1492 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1509 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1493 QString des = eventLSync->description(); 1510 QString des = eventLSync->description();
1494 QString pref = "e"; 1511 QString pref = "e";
1495 if ( inR->typeID() == todoID ) 1512 if ( inR->typeID() == todoID )
1496 pref = "t"; 1513 pref = "t";
1497 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1514 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1498 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1515 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1499 //remote->deleteIncidence( inR ); 1516 //remote->deleteIncidence( inR );
1500 ++deletedEventR; 1517 ++deletedEventR;
1501 } else { 1518 } else {
1502 inR->setLastModified( modifiedCalendar ); 1519 inR->setLastModified( modifiedCalendar );
1503 inL = inR->clone(); 1520 inL = inR->clone();
1504 inL->setIDStr( ":" ); 1521 inL->setIDStr( ":" );
1505 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1522 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1506 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1523 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1507 1524
1508 inL->setCalID( 0 );// add to default cal 1525 inL->setCalID( 0 );// add to default cal
1509 local->addIncidence( inL ); 1526 local->addIncidence( inL );
1510 ++addedEvent; 1527 ++addedEvent;
1511 1528
1512 } 1529 }
1513 } else { 1530 } else {
1514 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1531 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1515 inR->setLastModified( modifiedCalendar ); 1532 inR->setLastModified( modifiedCalendar );
1516 inL = inR->clone(); 1533 inL = inR->clone();
1517 inL->setIDStr( ":" ); 1534 inL->setIDStr( ":" );
1518 inL->setCalID( 0 );// add to default cal 1535 inL->setCalID( 0 );// add to default cal
1519 local->addIncidence( inL ); 1536 local->addIncidence( inL );
1520 ++addedEvent; 1537 ++addedEvent;
1521 1538
1522 } else { 1539 } else {
1523 checkExternSyncEvent(eventRSyncSharp, inR); 1540 checkExternSyncEvent(eventRSyncSharp, inR);
1524 remote->deleteIncidence( inR ); 1541 remote->deleteIncidence( inR );
1525 ++deletedEventR; 1542 ++deletedEventR;
1526 } 1543 }
1527 } 1544 }
1528 } else { 1545 } else {
1529 ++filteredIN; 1546 ++filteredIN;
1530 } 1547 }
1531 } 1548 }
1532 } 1549 }
1533 inR = er.next(); 1550 inR = er.next();
1534 } 1551 }
1535 QPtrList<Incidence> el = local->rawIncidences(); 1552 QPtrList<Incidence> el = local->rawIncidences();
1536 inL = el.first(); 1553 inL = el.first();
1537 modulo = (el.count()/10)+1; 1554 modulo = (el.count()/10)+1;
1538 bar.setCaption (i18n("Add / remove events") ); 1555 bar.setCaption (i18n("Add / remove events") );
1539 bar.setTotalSteps ( el.count() ) ; 1556 bar.setTotalSteps ( el.count() ) ;
1540 bar.show(); 1557 bar.show();
1541 incCounter = 0; 1558 incCounter = 0;
1542 1559
1543 while ( inL ) { 1560 while ( inL ) {
1544 1561
1545 qApp->processEvents(); 1562 qApp->processEvents();
1546 if ( ! bar.isVisible() ) 1563 if ( ! bar.isVisible() )
1547 return false; 1564 return false;
1548 if ( incCounter % modulo == 0 ) 1565 if ( incCounter % modulo == 0 )
1549 bar.setProgress( incCounter ); 1566 bar.setProgress( incCounter );
1550 ++incCounter; 1567 ++incCounter;
1551 uid = inL->uid(); 1568 uid = inL->uid();
1552 bool skipIncidence = false; 1569 bool skipIncidence = false;
1553 if ( uid.left(15) == QString("last-syncEvent-") ) 1570 if ( uid.left(15) == QString("last-syncEvent-") )
1554 skipIncidence = true; 1571 skipIncidence = true;
1555 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1572 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1556 skipIncidence = true; 1573 skipIncidence = true;
1557 if ( !skipIncidence ) { 1574 if ( !skipIncidence ) {
1558 inR = remote->incidenceForUid( uid , true ); 1575 inR = remote->incidenceForUid( uid , true );
1559 if ( ! inR ) { 1576 if ( ! inR ) {
1560 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1577 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1561 // no conflict ********** add or delete local 1578 // no conflict ********** add or delete local
1562 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1579 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1563 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1580 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1564 checkExternSyncEvent(eventLSyncSharp, inL); 1581 checkExternSyncEvent(eventLSyncSharp, inL);
1565 local->deleteIncidence( inL ); 1582 local->deleteIncidence( inL );
1566 ++deletedEventL; 1583 ++deletedEventL;
1567 } else { 1584 } else {
1568 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1585 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1569 inL->removeID(mCurrentSyncDevice ); 1586 inL->removeID(mCurrentSyncDevice );
1570 ++addedEventR; 1587 ++addedEventR;
1571 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1588 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1572 inL->setLastModified( modifiedCalendar ); 1589 inL->setLastModified( modifiedCalendar );
1573 inR = inL->clone(); 1590 inR = inL->clone();
1574 inR->setIDStr( ":" ); 1591 inR->setIDStr( ":" );
1575 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1592 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1576 inR->setCalID( 0 );// add to default cal 1593 inR->setCalID( 0 );// add to default cal
1577 remote->addIncidence( inR ); 1594 remote->addIncidence( inR );
1578 } 1595 }
1579 } 1596 }
1580 } else { 1597 } else {
1581 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1598 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1582 checkExternSyncEvent(eventLSyncSharp, inL); 1599 checkExternSyncEvent(eventLSyncSharp, inL);
1583 local->deleteIncidence( inL ); 1600 local->deleteIncidence( inL );
1584 ++deletedEventL; 1601 ++deletedEventL;
1585 } else { 1602 } else {
1586 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1603 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1587 ++addedEventR; 1604 ++addedEventR;
1588 inL->setLastModified( modifiedCalendar ); 1605 inL->setLastModified( modifiedCalendar );
1589 inR = inL->clone(); 1606 inR = inL->clone();
1590 inR->setIDStr( ":" ); 1607 inR->setIDStr( ":" );
1591 inR->setCalID( 0 );// add to default cal 1608 inR->setCalID( 0 );// add to default cal
1592 remote->addIncidence( inR ); 1609 remote->addIncidence( inR );
1593 } 1610 }
1594 } 1611 }
1595 } 1612 }
1596 } else { 1613 } else {
1597 ++filteredOUT; 1614 ++filteredOUT;
1598 } 1615 }
1599 } 1616 }
1600 } 1617 }
1601 inL = el.next(); 1618 inL = el.next();
1602 } 1619 }
1603 int delFut = 0; 1620 int delFut = 0;
1604 int remRem = 0; 1621 int remRem = 0;
1605 if ( mSyncManager->mWriteBackInFuture ) { 1622 if ( mSyncManager->mWriteBackInFuture ) {
1606 er = remote->rawIncidences(); 1623 er = remote->rawIncidences();
1607 remRem = er.count(); 1624 remRem = er.count();
1608 inR = er.first(); 1625 inR = er.first();
1609 QDateTime dt; 1626 QDateTime dt;
1610 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1627 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1611 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1628 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1612 while ( inR ) { 1629 while ( inR ) {
1613 if ( inR->typeID() == todoID ) { 1630 if ( inR->typeID() == todoID ) {
1614 Todo * t = (Todo*)inR; 1631 Todo * t = (Todo*)inR;
1615 if ( t->hasDueDate() ) 1632 if ( t->hasDueDate() )
1616 dt = t->dtDue(); 1633 dt = t->dtDue();
1617 else 1634 else
1618 dt = cur.addSecs( 62 ); 1635 dt = cur.addSecs( 62 );
1619 } 1636 }
1620 else if (inR->typeID() == eventID ) { 1637 else if (inR->typeID() == eventID ) {
1621 bool ok; 1638 bool ok;
1622 dt = inR->getNextOccurence( cur, &ok ); 1639 dt = inR->getNextOccurence( cur, &ok );
1623 if ( !ok ) 1640 if ( !ok )
1624 dt = cur.addSecs( -62 ); 1641 dt = cur.addSecs( -62 );
1625 } 1642 }
1626 else 1643 else
1627 dt = inR->dtStart(); 1644 dt = inR->dtStart();
1628 if ( dt < cur || dt > end ) { 1645 if ( dt < cur || dt > end ) {
1629 remote->deleteIncidence( inR ); 1646 remote->deleteIncidence( inR );
1630 ++delFut; 1647 ++delFut;
1631 } 1648 }
1632 inR = er.next(); 1649 inR = er.next();
1633 } 1650 }
1634 } 1651 }
1635 bar.hide(); 1652 bar.hide();
1636 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1653 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1637 eventLSync->setReadOnly( false ); 1654 eventLSync->setReadOnly( false );
1638 eventLSync->setDtStart( mLastCalendarSync ); 1655 eventLSync->setDtStart( mLastCalendarSync );
1639 eventRSync->setDtStart( mLastCalendarSync ); 1656 eventRSync->setDtStart( mLastCalendarSync );
1640 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1657 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1641 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1658 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1642 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1659 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1643 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1660 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1644 eventLSync->setReadOnly( true ); 1661 eventLSync->setReadOnly( true );
1645 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1662 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1646 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1663 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1647 remote->addEvent( eventRSync ); 1664 remote->addEvent( eventRSync );
1648 else 1665 else
1649 delete eventRSync; 1666 delete eventRSync;
1650 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1667 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1651 QString mes; 1668 QString mes;
1652 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1669 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1653 QString delmess; 1670 QString delmess;
1654 if ( delFut ) { 1671 if ( delFut ) {
1655 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1672 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1656 mes += delmess; 1673 mes += delmess;
1657 } 1674 }
1658 mes = i18n("Local calendar changed!\n") +mes; 1675 mes = i18n("Local calendar changed!\n") +mes;
1659 mCalendar->checkAlarmForIncidence( 0, true ); 1676 mCalendar->checkAlarmForIncidence( 0, true );
1660 qDebug( mes ); 1677 qDebug( mes );
1661 if ( mSyncManager->mShowSyncSummary ) { 1678 if ( mSyncManager->mShowSyncSummary ) {
1662 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1679 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1663 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1680 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1664 qDebug("KO: WB cancelled "); 1681 qDebug("KO: WB cancelled ");
1665 mSyncManager->mWriteBackFile = false; 1682 mSyncManager->mWriteBackFile = false;
1666 return syncOK; 1683 return syncOK;
1667 } 1684 }
1668 } 1685 }
1669 return syncOK; 1686 return syncOK;
1670} 1687}
1671 1688
1672void CalendarView::setSyncDevice( QString s ) 1689void CalendarView::setSyncDevice( QString s )
1673{ 1690{
1674 mCurrentSyncDevice= s; 1691 mCurrentSyncDevice= s;
1675} 1692}
1676void CalendarView::setSyncName( QString s ) 1693void CalendarView::setSyncName( QString s )
1677{ 1694{
1678 mCurrentSyncName= s; 1695 mCurrentSyncName= s;
1679} 1696}
1680bool CalendarView::syncCalendar(QString filename, int mode) 1697bool CalendarView::syncCalendar(QString filename, int mode)
1681{ 1698{
1682 //qDebug("syncCalendar %s ", filename.latin1()); 1699 //qDebug("syncCalendar %s ", filename.latin1());
1683 mGlobalSyncMode = SYNC_MODE_NORMAL; 1700 mGlobalSyncMode = SYNC_MODE_NORMAL;
1684 CalendarLocal* calendar = new CalendarLocal(); 1701 CalendarLocal* calendar = new CalendarLocal();
1685 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1702 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1686 FileStorage* storage = new FileStorage( calendar ); 1703 FileStorage* storage = new FileStorage( calendar );
1687 bool syncOK = false; 1704 bool syncOK = false;
1688 storage->setFileName( filename ); 1705 storage->setFileName( filename );
1689 // qDebug("loading ... "); 1706 // qDebug("loading ... ");
1690 if ( storage->load() ) { 1707 if ( storage->load() ) {
1691 getEventViewerDialog()->setSyncMode( true ); 1708 getEventViewerDialog()->setSyncMode( true );
1692 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1709 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1693 getEventViewerDialog()->setSyncMode( false ); 1710 getEventViewerDialog()->setSyncMode( false );
1694 if ( syncOK ) { 1711 if ( syncOK ) {
1695 if ( mSyncManager->mWriteBackFile ) 1712 if ( mSyncManager->mWriteBackFile )
1696 { 1713 {
1697 storage->setSaveFormat( new ICalFormat() ); 1714 storage->setSaveFormat( new ICalFormat() );
1698 storage->save(); 1715 storage->save();
1699 } 1716 }
1700 } 1717 }
1701 setModified( true ); 1718 setModified( true );
1702 } 1719 }
1703 delete storage; 1720 delete storage;
1704 delete calendar; 1721 delete calendar;
1705 if ( syncOK ) 1722 if ( syncOK )
1706 updateView(); 1723 updateView();
1707 return syncOK; 1724 return syncOK;
1708} 1725}
1709 1726
1710void CalendarView::syncExternal( int mode ) 1727void CalendarView::syncExternal( int mode )
1711{ 1728{
1712 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1729 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1713 1730
1714 qApp->processEvents(); 1731 qApp->processEvents();
1715 CalendarLocal* calendar = new CalendarLocal(); 1732 CalendarLocal* calendar = new CalendarLocal();
1716 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1733 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1717 bool syncOK = false; 1734 bool syncOK = false;
1718 bool loadSuccess = false; 1735 bool loadSuccess = false;
1719 PhoneFormat* phoneFormat = 0; 1736 PhoneFormat* phoneFormat = 0;
1720 emit tempDisableBR(true); 1737 emit tempDisableBR(true);
1721#ifndef DESKTOP_VERSION 1738#ifndef DESKTOP_VERSION
1722 SharpFormat* sharpFormat = 0; 1739 SharpFormat* sharpFormat = 0;
1723 if ( mode == 0 ) { // sharp 1740 if ( mode == 0 ) { // sharp
1724 sharpFormat = new SharpFormat () ; 1741 sharpFormat = new SharpFormat () ;
1725 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1742 loadSuccess = sharpFormat->load( calendar, mCalendar );
1726 1743
1727 } else 1744 } else
1728#endif 1745#endif
1729 if ( mode == 1 ) { // phone 1746 if ( mode == 1 ) { // phone
1730 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1747 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1731 mSyncManager->mPhoneDevice, 1748 mSyncManager->mPhoneDevice,
1732 mSyncManager->mPhoneConnection, 1749 mSyncManager->mPhoneConnection,
1733 mSyncManager->mPhoneModel); 1750 mSyncManager->mPhoneModel);
1734 loadSuccess = phoneFormat->load( calendar,mCalendar); 1751 loadSuccess = phoneFormat->load( calendar,mCalendar);
1735 1752
1736 } else { 1753 } else {
1737 emit tempDisableBR(false); 1754 emit tempDisableBR(false);
1738 return; 1755 return;
1739 } 1756 }
1740 if ( loadSuccess ) { 1757 if ( loadSuccess ) {
1741 getEventViewerDialog()->setSyncMode( true ); 1758 getEventViewerDialog()->setSyncMode( true );
1742 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1759 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1743 getEventViewerDialog()->setSyncMode( false ); 1760 getEventViewerDialog()->setSyncMode( false );
1744 qApp->processEvents(); 1761 qApp->processEvents();
1745 if ( syncOK ) { 1762 if ( syncOK ) {
1746 if ( mSyncManager->mWriteBackFile ) 1763 if ( mSyncManager->mWriteBackFile )
1747 { 1764 {
1748 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1765 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1749 Incidence* inc = iL.first(); 1766 Incidence* inc = iL.first();
1750 if ( phoneFormat ) { 1767 if ( phoneFormat ) {
1751 while ( inc ) { 1768 while ( inc ) {
1752 inc->removeID(mCurrentSyncDevice); 1769 inc->removeID(mCurrentSyncDevice);
1753 inc = iL.next(); 1770 inc = iL.next();
1754 } 1771 }
1755 } 1772 }
1756#ifndef DESKTOP_VERSION 1773#ifndef DESKTOP_VERSION
1757 if ( sharpFormat ) 1774 if ( sharpFormat )
1758 sharpFormat->save(calendar); 1775 sharpFormat->save(calendar);
1759#endif 1776#endif
1760 if ( phoneFormat ) 1777 if ( phoneFormat )
1761 phoneFormat->save(calendar); 1778 phoneFormat->save(calendar);
1762 iL = calendar->rawIncidences(); 1779 iL = calendar->rawIncidences();
1763 inc = iL.first(); 1780 inc = iL.first();
1764 Incidence* loc; 1781 Incidence* loc;
1765 while ( inc ) { 1782 while ( inc ) {
1766 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1783 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1767 loc = mCalendar->incidence(inc->uid() ); 1784 loc = mCalendar->incidence(inc->uid() );
1768 if ( loc ) { 1785 if ( loc ) {
1769 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1786 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1770 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1787 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1771 } 1788 }
1772 } 1789 }
1773 inc = iL.next(); 1790 inc = iL.next();
1774 } 1791 }
1775 Incidence* lse = getLastSyncEvent(); 1792 Incidence* lse = getLastSyncEvent();
1776 if ( lse ) { 1793 if ( lse ) {
1777 lse->setReadOnly( false ); 1794 lse->setReadOnly( false );
1778 lse->setDescription( "" ); 1795 lse->setDescription( "" );
1779 lse->setReadOnly( true ); 1796 lse->setReadOnly( true );
1780 } 1797 }
1781 } 1798 }
1782 } else { 1799 } else {
1783 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1800 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1784 } 1801 }
1785 setModified( true ); 1802 setModified( true );
1786 } else { 1803 } else {
1787 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1804 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1788 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1805 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1789 question, i18n("Ok")) ; 1806 question, i18n("Ok")) ;
1790 1807
1791 } 1808 }
1792 delete calendar; 1809 delete calendar;
1793 updateView(); 1810 updateView();
1794 emit tempDisableBR(false); 1811 emit tempDisableBR(false);
1795 return ;//syncOK; 1812 return ;//syncOK;
1796 1813
1797} 1814}
1798 1815
1799bool CalendarView::importBday() 1816bool CalendarView::importBday()
1800{ 1817{
1801#ifndef KORG_NOKABC 1818#ifndef KORG_NOKABC
1802 1819
1803#ifdef DESKTOP_VERSION 1820#ifdef DESKTOP_VERSION
1804 int curCal = mCalendar->defaultCalendar(); 1821 int curCal = mCalendar->defaultCalendar();
1805 int bd = mCalEditView->getBirtdayID(); 1822 int bd = mCalEditView->getBirtdayID();
1806 if ( bd == 0 ) 1823 if ( bd == 0 )
1807 return false; 1824 return false;
1808 mCalendar->setDefaultCalendar( bd ); 1825 mCalendar->setDefaultCalendar( bd );
1809 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1826 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1810 KABC::AddressBook::Iterator it; 1827 KABC::AddressBook::Iterator it;
1811 int count = 0; 1828 int count = 0;
1812 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1813 ++count; 1830 ++count;
1814 } 1831 }
1815 QProgressBar bar(count,0 ); 1832 QProgressBar bar(count,0 );
1816 int w = 300; 1833 int w = 300;
1817 if ( QApplication::desktop()->width() < 320 ) 1834 if ( QApplication::desktop()->width() < 320 )
1818 w = 220; 1835 w = 220;
1819 int h = bar.sizeHint().height() ; 1836 int h = bar.sizeHint().height() ;
1820 int dw = QApplication::desktop()->width(); 1837 int dw = QApplication::desktop()->width();
1821 int dh = QApplication::desktop()->height(); 1838 int dh = QApplication::desktop()->height();
1822 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1839 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1823 bar.show(); 1840 bar.show();
1824 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1841 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1825 qApp->processEvents(); 1842 qApp->processEvents();
1826 count = 0; 1843 count = 0;
1827 int addCount = 0; 1844 int addCount = 0;
1828 KCal::Attendee* a = 0; 1845 KCal::Attendee* a = 0;
1829 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1846 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1830 if ( ! bar.isVisible() ) 1847 if ( ! bar.isVisible() )
1831 return false; 1848 return false;
1832 bar.setProgress( count++ ); 1849 bar.setProgress( count++ );
1833 qApp->processEvents(); 1850 qApp->processEvents();
1834 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1851 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1835 if ( (*it).birthday().date().isValid() ){ 1852 if ( (*it).birthday().date().isValid() ){
1836 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1853 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1837 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1854 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1838 ++addCount; 1855 ++addCount;
1839 } 1856 }
1840 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1857 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1841 if ( anni.isValid() ){ 1858 if ( anni.isValid() ){
1842 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1859 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1843 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1860 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1844 ++addCount; 1861 ++addCount;
1845 } 1862 }
1846 } 1863 }
1847 mCalendar->setDefaultCalendar( curCal ); 1864 mCalendar->setDefaultCalendar( curCal );
1848 updateView(); 1865 updateView();
1849 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1866 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1850#else //DESKTOP_VERSION 1867#else //DESKTOP_VERSION
1851 1868
1852 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1869 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1853 // the result should now arrive through method insertBirthdays 1870 // the result should now arrive through method insertBirthdays
1854 1871
1855#endif //DESKTOP_VERSION 1872#endif //DESKTOP_VERSION
1856 1873
1857#endif //KORG_NOKABC 1874#endif //KORG_NOKABC
1858 1875
1859 1876
1860 return true; 1877 return true;
1861} 1878}
1862 1879
1863// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1880// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1864void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1881void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1865 const QStringList& anniversaryList, const QStringList& realNameList, 1882 const QStringList& anniversaryList, const QStringList& realNameList,
1866 const QStringList& emailList, const QStringList& assembledNameList, 1883 const QStringList& emailList, const QStringList& assembledNameList,
1867 const QStringList& uidList) 1884 const QStringList& uidList)
1868{ 1885{
1869 1886
1870 //qDebug("KO::CalendarView::insertBirthdays"); 1887 //qDebug("KO::CalendarView::insertBirthdays");
1871 if (uid == this->name()) 1888 if (uid == this->name())
1872 { 1889 {
1873 int curCal = mCalendar->defaultCalendar(); 1890 int curCal = mCalendar->defaultCalendar();
1874 int bd = mCalEditView->getBirtdayID(); 1891 int bd = mCalEditView->getBirtdayID();
1875 if ( bd == 0 ) 1892 if ( bd == 0 )
1876 return; 1893 return;
1877 mCalendar->setDefaultCalendar( bd ); 1894 mCalendar->setDefaultCalendar( bd );
1878 1895
1879 1896
1880 int count = birthdayList.count(); 1897 int count = birthdayList.count();
1881 int addCount = 0; 1898 int addCount = 0;
1882 KCal::Attendee* a = 0; 1899 KCal::Attendee* a = 0;
1883 1900
1884 //qDebug("CalView 1 %i", count); 1901 //qDebug("CalView 1 %i", count);
1885 1902
1886 QProgressBar bar(count,0 ); 1903 QProgressBar bar(count,0 );
1887 int w = 300; 1904 int w = 300;
1888 if ( QApplication::desktop()->width() < 320 ) 1905 if ( QApplication::desktop()->width() < 320 )
1889 w = 220; 1906 w = 220;
1890 int h = bar.sizeHint().height() ; 1907 int h = bar.sizeHint().height() ;
1891 int dw = QApplication::desktop()->width(); 1908 int dw = QApplication::desktop()->width();
1892 int dh = QApplication::desktop()->height(); 1909 int dh = QApplication::desktop()->height();
1893 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1910 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1894 bar.show(); 1911 bar.show();
1895 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1912 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1896 qApp->processEvents(); 1913 qApp->processEvents();
1897 1914
1898 QDate birthday; 1915 QDate birthday;
1899 QDate anniversary; 1916 QDate anniversary;
1900 QString realName; 1917 QString realName;
1901 QString email; 1918 QString email;
1902 QString assembledName; 1919 QString assembledName;
1903 QString uid; 1920 QString uid;
1904 bool ok = true; 1921 bool ok = true;
1905 for ( int i = 0; i < count; i++) 1922 for ( int i = 0; i < count; i++)
1906 { 1923 {
1907 if ( ! bar.isVisible() ) 1924 if ( ! bar.isVisible() )
1908 return; 1925 return;
1909 bar.setProgress( i ); 1926 bar.setProgress( i );
1910 qApp->processEvents(); 1927 qApp->processEvents();
1911 1928
1912 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1929 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1913 if (!ok) { 1930 if (!ok) {
1914 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1931 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1915 } 1932 }
1916 1933
1917 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1934 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1918 if (!ok) { 1935 if (!ok) {
1919 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1936 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1920 } 1937 }
1921 realName = realNameList[i]; 1938 realName = realNameList[i];
1922 email = emailList[i]; 1939 email = emailList[i];
1923 assembledName = assembledNameList[i]; 1940 assembledName = assembledNameList[i];
1924 uid = uidList[i]; 1941 uid = uidList[i];
1925 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1942 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1926 1943
1927 if ( birthday.isValid() ){ 1944 if ( birthday.isValid() ){
1928 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1945 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1929 KCal::Attendee::ReqParticipant,uid) ; 1946 KCal::Attendee::ReqParticipant,uid) ;
1930 if ( addAnniversary( birthday, assembledName, a, true ) ) 1947 if ( addAnniversary( birthday, assembledName, a, true ) )
1931 ++addCount; 1948 ++addCount;
1932 } 1949 }
1933 1950
1934 if ( anniversary.isValid() ){ 1951 if ( anniversary.isValid() ){
1935 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1952 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1936 KCal::Attendee::ReqParticipant,uid) ; 1953 KCal::Attendee::ReqParticipant,uid) ;
1937 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1954 if ( addAnniversary( anniversary, assembledName, a, false ) )
1938 ++addCount; 1955 ++addCount;
1939 } 1956 }
1940 } 1957 }
1941 1958
1942 mCalendar->setDefaultCalendar( curCal ); 1959 mCalendar->setDefaultCalendar( curCal );
1943 updateView(); 1960 updateView();
1944 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1961 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1945 1962
1946 } 1963 }
1947 1964
1948} 1965}
1949 1966
1950 1967
1951 1968
1952bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1969bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1953{ 1970{
1954 //qDebug("addAnni "); 1971 //qDebug("addAnni ");
1955 Event * ev = new Event(); 1972 Event * ev = new Event();
1956 ev->setOrganizer(KOPrefs::instance()->email()); 1973 ev->setOrganizer(KOPrefs::instance()->email());
1957 if ( a ) { 1974 if ( a ) {
1958 ev->addAttendee( a ); 1975 ev->addAttendee( a );
1959 } 1976 }
1960 QString kind; 1977 QString kind;
1961 if ( birthday ) { 1978 if ( birthday ) {
1962 kind = i18n( "Birthday" ); 1979 kind = i18n( "Birthday" );
1963 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1980 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1964 } 1981 }
1965 else { 1982 else {
1966 kind = i18n( "Anniversary" ); 1983 kind = i18n( "Anniversary" );
1967 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1984 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1968 } 1985 }
1969 ev->setCategories( kind ); 1986 ev->setCategories( kind );
1970 ev->setDtStart( QDateTime(date) ); 1987 ev->setDtStart( QDateTime(date) );
1971 ev->setDtEnd( QDateTime(date) ); 1988 ev->setDtEnd( QDateTime(date) );
1972 ev->setFloats( true ); 1989 ev->setFloats( true );
1973 Recurrence * rec = ev->recurrence(); 1990 Recurrence * rec = ev->recurrence();
1974 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1991 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1975 rec->addYearlyNum( date.month() ); 1992 rec->addYearlyNum( date.month() );
1976 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1993 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1977 delete ev; 1994 delete ev;
1978 return false; 1995 return false;
1979 } 1996 }
1980 return true; 1997 return true;
1981 1998
1982} 1999}
1983bool CalendarView::importQtopia( const QString &categories, 2000bool CalendarView::importQtopia( const QString &categories,
1984 const QString &datebook, 2001 const QString &datebook,
1985 const QString &todolist ) 2002 const QString &todolist )
1986{ 2003{
1987 2004
1988 QtopiaFormat qtopiaFormat; 2005 QtopiaFormat qtopiaFormat;
1989 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2006 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1990 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 2007 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1991 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 2008 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1992 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 2009 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1993 2010
1994 updateView(); 2011 updateView();
1995 return true; 2012 return true;
1996 2013
1997#if 0 2014#if 0
1998 mGlobalSyncMode = SYNC_MODE_QTOPIA; 2015 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1999 mCurrentSyncDevice = "qtopia-XML"; 2016 mCurrentSyncDevice = "qtopia-XML";
2000 if ( mSyncManager->mAskForPreferences ) 2017 if ( mSyncManager->mAskForPreferences )
2001 edit_sync_options(); 2018 edit_sync_options();
2002 qApp->processEvents(); 2019 qApp->processEvents();
2003 CalendarLocal* calendar = new CalendarLocal(); 2020 CalendarLocal* calendar = new CalendarLocal();
2004 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2021 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2005 bool syncOK = false; 2022 bool syncOK = false;
2006 QtopiaFormat qtopiaFormat; 2023 QtopiaFormat qtopiaFormat;
2007 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2024 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2008 bool loadOk = true; 2025 bool loadOk = true;
2009 if ( !categories.isEmpty() ) 2026 if ( !categories.isEmpty() )
2010 loadOk = qtopiaFormat.load( calendar, categories ); 2027 loadOk = qtopiaFormat.load( calendar, categories );
2011 if ( loadOk && !datebook.isEmpty() ) 2028 if ( loadOk && !datebook.isEmpty() )
2012 loadOk = qtopiaFormat.load( calendar, datebook ); 2029 loadOk = qtopiaFormat.load( calendar, datebook );
2013 if ( loadOk && !todolist.isEmpty() ) 2030 if ( loadOk && !todolist.isEmpty() )
2014 loadOk = qtopiaFormat.load( calendar, todolist ); 2031 loadOk = qtopiaFormat.load( calendar, todolist );
2015 2032
2016 if ( loadOk ) { 2033 if ( loadOk ) {
2017 getEventViewerDialog()->setSyncMode( true ); 2034 getEventViewerDialog()->setSyncMode( true );
2018 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2035 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2019 getEventViewerDialog()->setSyncMode( false ); 2036 getEventViewerDialog()->setSyncMode( false );
2020 qApp->processEvents(); 2037 qApp->processEvents();
2021 if ( syncOK ) { 2038 if ( syncOK ) {
2022 if ( mSyncManager->mWriteBackFile ) 2039 if ( mSyncManager->mWriteBackFile )
2023 { 2040 {
2024 // write back XML file 2041 // write back XML file
2025 2042
2026 } 2043 }
2027 setModified( true ); 2044 setModified( true );
2028 } 2045 }
2029 } else { 2046 } else {
2030 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2047 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2031 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2048 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2032 question, i18n("Ok")) ; 2049 question, i18n("Ok")) ;
2033 } 2050 }
2034 delete calendar; 2051 delete calendar;
2035 updateView(); 2052 updateView();
2036 return syncOK; 2053 return syncOK;
2037 2054
2038 2055
2039#endif 2056#endif
2040 2057
2041} 2058}
2042 2059
2043void CalendarView::setSyncEventsReadOnly() 2060void CalendarView::setSyncEventsReadOnly()
2044{ 2061{
2045 mCalendar->setSyncEventsReadOnly(); 2062 mCalendar->setSyncEventsReadOnly();
2046} 2063}
2047 2064
2048bool CalendarView::loadCalendars() 2065bool CalendarView::loadCalendars()
2049{ 2066{
2050 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2067 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2051 KopiCalendarFile * cal = calendars.first(); 2068 KopiCalendarFile * cal = calendars.first();
2052 mCalendar->setDefaultCalendar( 1 ); 2069 mCalendar->setDefaultCalendar( 1 );
2053 openCalendar( MainWindow::defaultFileName(), false ); 2070 openCalendar( MainWindow::defaultFileName(), false );
2054 cal = calendars.next(); 2071 cal = calendars.next();
2055 while ( cal ) { 2072 while ( cal ) {
2056 addCalendar( cal ); 2073 addCalendar( cal );
2057 cal = calendars.next(); 2074 cal = calendars.next();
2058 } 2075 }
2059 restoreCalendarSettings(); 2076 restoreCalendarSettings();
2060 return true; 2077 return true;
2061} 2078}
2062bool CalendarView::restoreCalendarSettings() 2079bool CalendarView::restoreCalendarSettings()
2063{ 2080{
2064 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2081 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2065 KopiCalendarFile * cal = calendars.first(); 2082 KopiCalendarFile * cal = calendars.first();
2066 while ( cal ) { 2083 while ( cal ) {
2067 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2084 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2068 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2085 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2069 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2086 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2070 if ( cal->isStandard ) 2087 if ( cal->isStandard )
2071 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2088 mCalendar->setDefaultCalendar( cal->mCalNumber );
2072 cal = calendars.next(); 2089 cal = calendars.next();
2073 } 2090 }
2074 setSyncEventsReadOnly(); 2091 setSyncEventsReadOnly();
2075 mCalendar->reInitAlarmSettings(); 2092 mCalendar->reInitAlarmSettings();
2076 updateUnmanagedViews(); 2093 updateUnmanagedViews();
2077 updateView(); 2094 updateView();
2078 return true; 2095 return true;
2079} 2096}
2080void CalendarView::addCalendarId( int id ) 2097void CalendarView::addCalendarId( int id )
2081{ 2098{
2082 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2099 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2083 if ( cal ) 2100 if ( cal )
2084 addCalendar( cal ); 2101 addCalendar( cal );
2085} 2102}
2086bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2103bool CalendarView::addCalendar( KopiCalendarFile * cal )
2087{ 2104{
2088 cal->mErrorOnLoad = false; 2105 cal->mErrorOnLoad = false;
2089 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2106 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2090 cal->mLoadDt = QDateTime::currentDateTime(); 2107 cal->mLoadDt = QDateTime::currentDateTime();
2091 return true; 2108 return true;
2092 } 2109 }
2093 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2110 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2094 cal->mErrorOnLoad = true; 2111 cal->mErrorOnLoad = true;
2095 return false; 2112 return false;
2096} 2113}
2097bool CalendarView::openCalendar(QString filename, bool merge) 2114bool CalendarView::openCalendar(QString filename, bool merge)
2098{ 2115{
2099 2116
2100 if (filename.isEmpty()) { 2117 if (filename.isEmpty()) {
2101 return false; 2118 return false;
2102 } 2119 }
2103 2120
2104 if (!QFile::exists(filename)) { 2121 if (!QFile::exists(filename)) {
2105 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2122 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2106 return false; 2123 return false;
2107 } 2124 }
2108 2125
2109 globalFlagBlockAgenda = 1; 2126 globalFlagBlockAgenda = 1;
2110 clearAllViews(); 2127 clearAllViews();
2111 if (!merge) { 2128 if (!merge) {
2112 mViewManager->setDocumentId( filename ); 2129 mViewManager->setDocumentId( filename );
2113 mCalendar->close(); 2130 mCalendar->close();
2114 } 2131 }
2115 mStorage->setFileName( filename ); 2132 mStorage->setFileName( filename );
2116 2133
2117 if ( mStorage->load() ) { 2134 if ( mStorage->load() ) {
2118 if ( merge ) ;//setModified( true ); 2135 if ( merge ) ;//setModified( true );
2119 else { 2136 else {
2120 //setModified( true ); 2137 //setModified( true );
2121 mViewManager->setDocumentId( filename ); 2138 mViewManager->setDocumentId( filename );
2122 mDialogManager->setDocumentId( filename ); 2139 mDialogManager->setDocumentId( filename );
2123 mTodoList->setDocumentId( filename ); 2140 mTodoList->setDocumentId( filename );
2124 } 2141 }
2125 globalFlagBlockAgenda = 2; 2142 globalFlagBlockAgenda = 2;
2126 // if ( getLastSyncEvent() ) 2143 // if ( getLastSyncEvent() )
2127 // getLastSyncEvent()->setReadOnly( true ); 2144 // getLastSyncEvent()->setReadOnly( true );
2128 mCalendar->reInitAlarmSettings(); 2145 mCalendar->reInitAlarmSettings();
2129 setSyncEventsReadOnly(); 2146 setSyncEventsReadOnly();
2130 updateUnmanagedViews(); 2147 updateUnmanagedViews();
2131 updateView(); 2148 updateView();
2132 if ( filename != MainWindow::defaultFileName() ) { 2149 if ( filename != MainWindow::defaultFileName() ) {
2133 saveCalendar( MainWindow::defaultFileName() ); 2150 saveCalendar( MainWindow::defaultFileName() );
2134 } else { 2151 } else {
2135 QFileInfo finf ( MainWindow::defaultFileName()); 2152 QFileInfo finf ( MainWindow::defaultFileName());
2136 if ( finf.exists() ) { 2153 if ( finf.exists() ) {
2137 setLoadedFileVersion( finf.lastModified () ); 2154 setLoadedFileVersion( finf.lastModified () );
2138 } 2155 }
2139 } 2156 }
2140 return true; 2157 return true;
2141 } else { 2158 } else {
2142 // while failing to load, the calendar object could 2159 // while failing to load, the calendar object could
2143 // have become partially populated. Clear it out. 2160 // have become partially populated. Clear it out.
2144 if ( !merge ) { 2161 if ( !merge ) {
2145 mCalendar->close(); 2162 mCalendar->close();
2146 mViewManager->setDocumentId( filename ); 2163 mViewManager->setDocumentId( filename );
2147 mDialogManager->setDocumentId( filename ); 2164 mDialogManager->setDocumentId( filename );
2148 mTodoList->setDocumentId( filename ); 2165 mTodoList->setDocumentId( filename );
2149 } 2166 }
2150 2167
2151 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2168 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2152 2169
2153 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2170 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2154 globalFlagBlockAgenda = 2; 2171 globalFlagBlockAgenda = 2;
2155 mCalendar->reInitAlarmSettings(); 2172 mCalendar->reInitAlarmSettings();
2156 setSyncEventsReadOnly(); 2173 setSyncEventsReadOnly();
2157 updateUnmanagedViews(); 2174 updateUnmanagedViews();
2158 updateView(); 2175 updateView();
2159 } 2176 }
2160 return false; 2177 return false;
2161} 2178}
2162void CalendarView::mergeFile( QString fn ) 2179void CalendarView::mergeFile( QString fn )
2163{ 2180{
2164 clearAllViews(); 2181 clearAllViews();
2165 mCalendar->mergeCalendarFile( fn ); 2182 mCalendar->mergeCalendarFile( fn );
2166 mCalendar->reInitAlarmSettings(); 2183 mCalendar->reInitAlarmSettings();
2167 setSyncEventsReadOnly(); 2184 setSyncEventsReadOnly();
2168 updateUnmanagedViews(); 2185 updateUnmanagedViews();
2169 updateView(); 2186 updateView();
2170} 2187}
2171void CalendarView::showOpenError() 2188void CalendarView::showOpenError()
2172{ 2189{
2173 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2190 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2174} 2191}
2175void CalendarView::setLoadedFileVersion(QDateTime dt) 2192void CalendarView::setLoadedFileVersion(QDateTime dt)
2176{ 2193{
2177 loadedFileVersion = dt; 2194 loadedFileVersion = dt;
2178} 2195}
2179bool CalendarView::checkFileChanged(QString fn) 2196bool CalendarView::checkFileChanged(QString fn)
2180{ 2197{
2181 QFileInfo finf ( fn ); 2198 QFileInfo finf ( fn );
2182 if ( !finf.exists() ) 2199 if ( !finf.exists() )
2183 return true; 2200 return true;
2184 QDateTime dt = finf.lastModified (); 2201 QDateTime dt = finf.lastModified ();
2185 if ( dt <= loadedFileVersion ) 2202 if ( dt <= loadedFileVersion )
2186 return false; 2203 return false;
2187 return true; 2204 return true;
2188 2205
2189} 2206}
2190void CalendarView::watchSavedFile() 2207void CalendarView::watchSavedFile()
2191{ 2208{
2192 QFileInfo finf ( MainWindow::defaultFileName()); 2209 QFileInfo finf ( MainWindow::defaultFileName());
2193 if ( !finf.exists() ) 2210 if ( !finf.exists() )
2194 return; 2211 return;
2195 QDateTime dt = finf.lastModified (); 2212 QDateTime dt = finf.lastModified ();
2196 if ( dt < loadedFileVersion ) { 2213 if ( dt < loadedFileVersion ) {
2197 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2214 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2198 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2215 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2199 return; 2216 return;
2200 } 2217 }
2201 loadedFileVersion = dt; 2218 loadedFileVersion = dt;
2202} 2219}
2203bool CalendarView::checkAllFileVersions() 2220bool CalendarView::checkAllFileVersions()
2204{ 2221{
2205 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2222 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2206 KopiCalendarFile * cal = calendars.first(); 2223 KopiCalendarFile * cal = calendars.first();
2207 mCalendar->setDefaultCalendar( 1 ); 2224 mCalendar->setDefaultCalendar( 1 );
2208 mCalendar->setDefaultCalendarEnabledOnly(); 2225 mCalendar->setDefaultCalendarEnabledOnly();
2209 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2226 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2210 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2227 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2211 restoreCalendarSettings(); 2228 restoreCalendarSettings();
2212 return false; 2229 return false;
2213 } 2230 }
2214 } 2231 }
2215 cal = calendars.next(); 2232 cal = calendars.next();
2216 QDateTime storeTemp = loadedFileVersion; 2233 QDateTime storeTemp = loadedFileVersion;
2217 while ( cal ) { 2234 while ( cal ) {
2218 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2235 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2219 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2236 mCalendar->setDefaultCalendar( cal->mCalNumber );
2220 mCalendar->setDefaultCalendarEnabledOnly(); 2237 mCalendar->setDefaultCalendarEnabledOnly();
2221 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2238 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2222 if ( !checkFileVersion(cal->mFileName )) { 2239 if ( !checkFileVersion(cal->mFileName )) {
2223 loadedFileVersion = storeTemp; 2240 loadedFileVersion = storeTemp;
2224 restoreCalendarSettings(); 2241 restoreCalendarSettings();
2225 return false; 2242 return false;
2226 } 2243 }
2227 } 2244 }
2228 cal = calendars.next(); 2245 cal = calendars.next();
2229 } 2246 }
2230 loadedFileVersion = storeTemp; 2247 loadedFileVersion = storeTemp;
2231 return true; 2248 return true;
2232} 2249}
2233bool CalendarView::checkFileVersion(QString fn) 2250bool CalendarView::checkFileVersion(QString fn)
2234{ 2251{
2235 QFileInfo finf ( fn ); 2252 QFileInfo finf ( fn );
2236 if ( !finf.exists() ) 2253 if ( !finf.exists() )
2237 return true; 2254 return true;
2238 QDateTime dt = finf.lastModified (); 2255 QDateTime dt = finf.lastModified ();
2239 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2256 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2240 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2257 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2241 if ( dt <= loadedFileVersion ) 2258 if ( dt <= loadedFileVersion )
2242 return true; 2259 return true;
2243 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2260 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2244 i18n("KO/Pi Warning"),i18n("Overwrite"), 2261 i18n("KO/Pi Warning"),i18n("Overwrite"),
2245 i18n("Sync+save")); 2262 i18n("Sync+save"));
2246 2263
2247 if ( km == KMessageBox::Cancel ) 2264 if ( km == KMessageBox::Cancel )
2248 return false; 2265 return false;
2249 if ( km == KMessageBox::Yes ) 2266 if ( km == KMessageBox::Yes )
2250 return true; 2267 return true;
2251 2268
2252 setSyncDevice("deleteaftersync" ); 2269 setSyncDevice("deleteaftersync" );
2253 mSyncManager->mAskForPreferences = true; 2270 mSyncManager->mAskForPreferences = true;
2254 mSyncManager->mSyncAlgoPrefs = 3; 2271 mSyncManager->mSyncAlgoPrefs = 3;
2255 mSyncManager->mWriteBackFile = false; 2272 mSyncManager->mWriteBackFile = false;
2256 mSyncManager->mWriteBackExistingOnly = false; 2273 mSyncManager->mWriteBackExistingOnly = false;
2257 mSyncManager->mShowSyncSummary = false; 2274 mSyncManager->mShowSyncSummary = false;
2258 syncCalendar( fn, 3 ); 2275 syncCalendar( fn, 3 );
2259 Event * e = getLastSyncEvent(); 2276 Event * e = getLastSyncEvent();
2260 if ( e ) 2277 if ( e )
2261 mCalendar->deleteEvent( e ); 2278 mCalendar->deleteEvent( e );
2262 return true; 2279 return true;
2263} 2280}
2264bool CalendarView::saveCalendars() 2281bool CalendarView::saveCalendars()
2265{ 2282{
2266 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2283 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2267 KopiCalendarFile * cal = calendars.first(); 2284 KopiCalendarFile * cal = calendars.first();
2268 mCalendar->setDefaultCalendar( 1 ); 2285 mCalendar->setDefaultCalendar( 1 );
2269 mCalendar->setDefaultCalendarEnabledOnly(); 2286 mCalendar->setDefaultCalendarEnabledOnly();
2270 saveCalendar( MainWindow::defaultFileName() ); 2287 saveCalendar( MainWindow::defaultFileName() );
2271 cal = calendars.next(); 2288 cal = calendars.next();
2272 while ( cal ) { 2289 while ( cal ) {
2273 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2290 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2274 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2291 mCalendar->setDefaultCalendar( cal->mCalNumber );
2275 mCalendar->setDefaultCalendarEnabledOnly(); 2292 mCalendar->setDefaultCalendarEnabledOnly();
2276 if ( saveCalendar( cal->mFileName ) ) 2293 if ( saveCalendar( cal->mFileName ) )
2277 cal->mLoadDt = QDateTime::currentDateTime(); 2294 cal->mLoadDt = QDateTime::currentDateTime();
2278 } 2295 }
2279 cal = calendars.next(); 2296 cal = calendars.next();
2280 } 2297 }
2281 restoreCalendarSettings(); 2298 restoreCalendarSettings();
2282 return true; 2299 return true;
2283} 2300}
2284bool CalendarView::saveCalendar( QString filename ) 2301bool CalendarView::saveCalendar( QString filename )
2285{ 2302{
2286 2303
2287 // Store back all unsaved data into calendar object 2304 // Store back all unsaved data into calendar object
2288 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2305 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2289 if ( mViewManager->currentView() ) 2306 if ( mViewManager->currentView() )
2290 mViewManager->currentView()->flushView(); 2307 mViewManager->currentView()->flushView();
2291 2308
2292 2309
2293 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2310 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2294 mStorage->setSaveFormat( new ICalFormat() ); 2311 mStorage->setSaveFormat( new ICalFormat() );
2295 mStorage->setFileName( filename ); 2312 mStorage->setFileName( filename );
2296 bool success; 2313 bool success;
2297 success = mStorage->save(); 2314 success = mStorage->save();
2298 if ( !success ) { 2315 if ( !success ) {
2299 return false; 2316 return false;
2300 } 2317 }
2301 if ( filename == MainWindow::defaultFileName() ) { 2318 if ( filename == MainWindow::defaultFileName() ) {
2302 setLoadedFileVersion( lfv ); 2319 setLoadedFileVersion( lfv );
2303 watchSavedFile(); 2320 watchSavedFile();
2304 } 2321 }
2305 return true; 2322 return true;
2306} 2323}
2307 2324
2308void CalendarView::closeCalendar() 2325void CalendarView::closeCalendar()
2309{ 2326{
2310 2327
2311 // child windows no longer valid 2328 // child windows no longer valid
2312 clearAllViews(); 2329 clearAllViews();
2313 emit closingDown(); 2330 emit closingDown();
2314 2331
2315 mCalendar->close(); 2332 mCalendar->close();
2316 setModified(false); 2333 setModified(false);
2317 updateView(); 2334 updateView();
2318} 2335}
2319 2336
2320void CalendarView::archiveCalendar() 2337void CalendarView::archiveCalendar()
2321{ 2338{
2322 mDialogManager->showArchiveDialog(); 2339 mDialogManager->showArchiveDialog();
2323} 2340}
2324 2341
2325 2342
2326void CalendarView::readSettings() 2343void CalendarView::readSettings()
2327{ 2344{
2328 2345
2329 2346
2330 // mViewManager->showAgendaView(); 2347 // mViewManager->showAgendaView();
2331 QString str; 2348 QString str;
2332 //qDebug("CalendarView::readSettings() "); 2349 //qDebug("CalendarView::readSettings() ");
2333 // read settings from the KConfig, supplying reasonable 2350 // read settings from the KConfig, supplying reasonable
2334 // defaults where none are to be found 2351 // defaults where none are to be found
2335 KConfig *config = KOGlobals::config(); 2352 KConfig *config = KOGlobals::config();
2336#ifndef KORG_NOSPLITTER 2353#ifndef KORG_NOSPLITTER
2337 config->setGroup("KOrganizer Geometry"); 2354 config->setGroup("KOrganizer Geometry");
2338 2355
2339 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2356 QValueList<int> sizes = config->readIntListEntry("Separator1");
2340 if (sizes.count() != 2) { 2357 if (sizes.count() != 2) {
2341 sizes << mDateNavigator->minimumSizeHint().width(); 2358 sizes << mDateNavigator->minimumSizeHint().width();
2342 sizes << 300; 2359 sizes << 300;
2343 } 2360 }
2344 mPanner->setSizes(sizes); 2361 mPanner->setSizes(sizes);
2345 2362
2346 sizes = config->readIntListEntry("Separator2"); 2363 sizes = config->readIntListEntry("Separator2");
2347 if ( ( mResourceView && sizes.count() == 4 ) || 2364 if ( ( mResourceView && sizes.count() == 4 ) ||
2348 ( !mResourceView && sizes.count() == 3 ) ) { 2365 ( !mResourceView && sizes.count() == 3 ) ) {
2349 mLeftSplitter->setSizes(sizes); 2366 mLeftSplitter->setSizes(sizes);
2350 } 2367 }
2351#endif 2368#endif
2352 globalFlagBlockAgenda = 1; 2369 globalFlagBlockAgenda = 1;
2353 mViewManager->showAgendaView(); 2370 mViewManager->showAgendaView();
2354 //mViewManager->readSettings( config ); 2371 //mViewManager->readSettings( config );
2355 mTodoList->restoreLayout(config,QString("Todo Layout")); 2372 mTodoList->restoreLayout(config,QString("Todo Layout"));
2356 readFilterSettings(config); 2373 readFilterSettings(config);
2357 2374
2358#ifdef DESKTOP_VERSION 2375#ifdef DESKTOP_VERSION
2359 config->setGroup("WidgetLayout"); 2376 config->setGroup("WidgetLayout");
2360 QStringList list; 2377 QStringList list;
2361 list = config->readListEntry("MainLayout"); 2378 list = config->readListEntry("MainLayout");
2362 int x,y,w,h; 2379 int x,y,w,h;
2363 if ( ! list.isEmpty() ) { 2380 if ( ! list.isEmpty() ) {
2364 x = list[0].toInt(); 2381 x = list[0].toInt();
2365 y = list[1].toInt(); 2382 y = list[1].toInt();
2366 w = list[2].toInt(); 2383 w = list[2].toInt();
2367 h = list[3].toInt(); 2384 h = list[3].toInt();
2368 KApplication::testCoords( &x,&y,&w,&h ); 2385 KApplication::testCoords( &x,&y,&w,&h );
2369 topLevelWidget()->setGeometry(x,y,w,h); 2386 topLevelWidget()->setGeometry(x,y,w,h);
2370 2387
2371 } else { 2388 } else {
2372 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2389 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2373 } 2390 }
2374 list = config->readListEntry("EditEventLayout"); 2391 list = config->readListEntry("EditEventLayout");
2375 if ( ! list.isEmpty() ) { 2392 if ( ! list.isEmpty() ) {
2376 x = list[0].toInt(); 2393 x = list[0].toInt();
2377 y = list[1].toInt(); 2394 y = list[1].toInt();
2378 w = list[2].toInt(); 2395 w = list[2].toInt();
2379 h = list[3].toInt(); 2396 h = list[3].toInt();
2380 KApplication::testCoords( &x,&y,&w,&h ); 2397 KApplication::testCoords( &x,&y,&w,&h );
2381 mEventEditor->setGeometry(x,y,w,h); 2398 mEventEditor->setGeometry(x,y,w,h);
2382 2399
2383 } 2400 }
2384 list = config->readListEntry("EditTodoLayout"); 2401 list = config->readListEntry("EditTodoLayout");
2385 if ( ! list.isEmpty() ) { 2402 if ( ! list.isEmpty() ) {
2386 x = list[0].toInt(); 2403 x = list[0].toInt();
2387 y = list[1].toInt(); 2404 y = list[1].toInt();
2388 w = list[2].toInt(); 2405 w = list[2].toInt();
2389 h = list[3].toInt(); 2406 h = list[3].toInt();
2390 KApplication::testCoords( &x,&y,&w,&h ); 2407 KApplication::testCoords( &x,&y,&w,&h );
2391 mTodoEditor->setGeometry(x,y,w,h); 2408 mTodoEditor->setGeometry(x,y,w,h);
2392 2409
2393 } 2410 }
2394 list = config->readListEntry("ViewerLayout"); 2411 list = config->readListEntry("ViewerLayout");
2395 if ( ! list.isEmpty() ) { 2412 if ( ! list.isEmpty() ) {
2396 x = list[0].toInt(); 2413 x = list[0].toInt();
2397 y = list[1].toInt(); 2414 y = list[1].toInt();
2398 w = list[2].toInt(); 2415 w = list[2].toInt();
2399 h = list[3].toInt(); 2416 h = list[3].toInt();
2400 KApplication::testCoords( &x,&y,&w,&h ); 2417 KApplication::testCoords( &x,&y,&w,&h );
2401 getEventViewerDialog()->setGeometry(x,y,w,h); 2418 getEventViewerDialog()->setGeometry(x,y,w,h);
2402 } 2419 }
2403#endif 2420#endif
2404 config->setGroup( "Views" ); 2421 config->setGroup( "Views" );
2405 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2422 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2406 2423
2407 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2424 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2408 2425
2409 int resetval = 0; 2426 int resetval = 0;
2410 int maxVal = 0; 2427 int maxVal = 0;
2411 if (sizes.count() != 3) { 2428 if (sizes.count() != 3) {
2412 if ( KOPrefs::instance()->mVerticalScreen ) { 2429 if ( KOPrefs::instance()->mVerticalScreen ) {
2413 resetval = mDateNavigator->sizeHint().width()+2; 2430 resetval = mDateNavigator->sizeHint().width()+2;
2414 } else { 2431 } else {
2415 resetval = mDateNavigator->sizeHint().height()+2; 2432 resetval = mDateNavigator->sizeHint().height()+2;
2416 } 2433 }
2417 } 2434 }
2418 if ( resetval ) { 2435 if ( resetval ) {
2419 sizes.clear(); 2436 sizes.clear();
2420 if ( KOPrefs::instance()->mVerticalScreen ) { 2437 if ( KOPrefs::instance()->mVerticalScreen ) {
2421 maxVal = QApplication::desktop()->width() -10; 2438 maxVal = QApplication::desktop()->width() -10;
2422 } else { 2439 } else {
2423 maxVal = QApplication::desktop()->height()-10; 2440 maxVal = QApplication::desktop()->height()-10;
2424 } 2441 }
2425 sizes << resetval; 2442 sizes << resetval;
2426 if ( maxVal < resetval + resetval) 2443 if ( maxVal < resetval + resetval)
2427 resetval = maxVal - resetval; 2444 resetval = maxVal - resetval;
2428 sizes << resetval; 2445 sizes << resetval;
2429 sizes << 100; 2446 sizes << 100;
2430 } 2447 }
2431 mLeftFrame->setSizes(sizes); 2448 mLeftFrame->setSizes(sizes);
2432 sizes = config->readIntListEntry("Main Splitter Frame"); 2449 sizes = config->readIntListEntry("Main Splitter Frame");
2433 resetval = 0; 2450 resetval = 0;
2434 maxVal = 0; 2451 maxVal = 0;
2435 if (sizes.count() != 2) { 2452 if (sizes.count() != 2) {
2436 if ( !KOPrefs::instance()->mVerticalScreen ) { 2453 if ( !KOPrefs::instance()->mVerticalScreen ) {
2437 resetval = mDateNavigator->sizeHint().width()+2; 2454 resetval = mDateNavigator->sizeHint().width()+2;
2438 } else { 2455 } else {
2439 resetval = mDateNavigator->sizeHint().height()+2; 2456 resetval = mDateNavigator->sizeHint().height()+2;
2440 } 2457 }
2441 } 2458 }
2442 if ( resetval ) { 2459 if ( resetval ) {
2443 sizes.clear(); 2460 sizes.clear();
2444 if ( !KOPrefs::instance()->mVerticalScreen ) { 2461 if ( !KOPrefs::instance()->mVerticalScreen ) {
2445 maxVal = QApplication::desktop()->width() -10; 2462 maxVal = QApplication::desktop()->width() -10;
2446 } else { 2463 } else {
2447 maxVal = QApplication::desktop()->height()-10; 2464 maxVal = QApplication::desktop()->height()-10;
2448 } 2465 }
2449 sizes << resetval; 2466 sizes << resetval;
2450 if ( maxVal < resetval + resetval) 2467 if ( maxVal < resetval + resetval)
2451 resetval = maxVal - resetval; 2468 resetval = maxVal - resetval;
2452 sizes << resetval; 2469 sizes << resetval;
2453 } 2470 }
2454 mMainFrame->setSizes(sizes); 2471 mMainFrame->setSizes(sizes);
2455 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2472 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2456 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2473 else if ( dateCount == 7 ) mNavigator->selectWeek();
2457 else mNavigator->selectDates( dateCount ); 2474 else mNavigator->selectDates( dateCount );
2458 // mViewManager->readSettings( config ); 2475 // mViewManager->readSettings( config );
2459 updateConfig(); 2476 updateConfig();
2460 globalFlagBlockAgenda = 2; 2477 globalFlagBlockAgenda = 2;
2461 mViewManager->readSettings( config ); 2478 mViewManager->readSettings( config );
2462 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2479 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2463} 2480}
2464 2481
2465void CalendarView::checkSuspendAlarm() 2482void CalendarView::checkSuspendAlarm()
2466{ 2483{
2467 if ( mSuspendTimer->isActive() ) { 2484 if ( mSuspendTimer->isActive() ) {
2468 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2485 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2469 } 2486 }
2470} 2487}
2471void CalendarView::writeSettings() 2488void CalendarView::writeSettings()
2472{ 2489{
2473 // kdDebug() << "CalendarView::writeSettings" << endl; 2490 // kdDebug() << "CalendarView::writeSettings" << endl;
2474 2491
2475 KConfig *config = KOGlobals::config(); 2492 KConfig *config = KOGlobals::config();
2476 2493
2477 mViewManager->writeSettings( config ); 2494 mViewManager->writeSettings( config );
2478 mTodoList->saveLayout(config,QString("Todo Layout")); 2495 mTodoList->saveLayout(config,QString("Todo Layout"));
2479 mDialogManager->writeSettings( config ); 2496 mDialogManager->writeSettings( config );
2480 //KOPrefs::instance()->usrWriteConfig(); 2497 //KOPrefs::instance()->usrWriteConfig();
2481 KOPrefs::instance()->writeConfig(); 2498 KOPrefs::instance()->writeConfig();
2482 2499
2483 writeFilterSettings(config); 2500 writeFilterSettings(config);
2484 config->setGroup( "AppRun" ); 2501 config->setGroup( "AppRun" );
2485 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2502 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2486 int days = dt.daysTo( QDate::currentDate() ); 2503 int days = dt.daysTo( QDate::currentDate() );
2487 dt = dt.addDays( days ); 2504 dt = dt.addDays( days );
2488 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2505 int secs = dt.secsTo( QDateTime::currentDateTime() );
2489 config->writeEntry( "LatestProgramStopDays", days ); 2506 config->writeEntry( "LatestProgramStopDays", days );
2490 config->writeEntry( "LatestProgramStopSecs", secs ); 2507 config->writeEntry( "LatestProgramStopSecs", secs );
2491 //qDebug("KO: Writing stop time: %d ", secs); 2508 //qDebug("KO: Writing stop time: %d ", secs);
2492 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2509 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2493 //QDateTime latest = dt.addSecs ( secs ); 2510 //QDateTime latest = dt.addSecs ( secs );
2494 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2511 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2495 config->setGroup( "Views" ); 2512 config->setGroup( "Views" );
2496 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2513 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2497 2514
2498#if 0 2515#if 0
2499 qDebug("********************* "); 2516 qDebug("********************* ");
2500 qDebug("Testcode secsto "); 2517 qDebug("Testcode secsto ");
2501 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2518 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2502 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2519 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2503 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2520 int secsto = dt_nodaylight.secsTo( dt_daylight );
2504 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2521 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2505 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2522 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2506 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2523 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2507 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2524 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2508 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2525 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2509 qDebug("********************* testcode end"); 2526 qDebug("********************* testcode end");
2510 2527
2511#endif 2528#endif
2512 2529
2513 QValueList<int> listINT = mLeftFrame->sizes(); 2530 QValueList<int> listINT = mLeftFrame->sizes();
2514 config->writeEntry("Left Splitter Frame",listINT); 2531 config->writeEntry("Left Splitter Frame",listINT);
2515 QValueList<int> listINT2 = mMainFrame->sizes(); 2532 QValueList<int> listINT2 = mMainFrame->sizes();
2516 config->writeEntry("Main Splitter Frame",listINT2); 2533 config->writeEntry("Main Splitter Frame",listINT2);
2517#ifdef DESKTOP_VERSION 2534#ifdef DESKTOP_VERSION
2518 config->setGroup("WidgetLayout"); 2535 config->setGroup("WidgetLayout");
2519 QStringList list ;//= config->readListEntry("MainLayout"); 2536 QStringList list ;//= config->readListEntry("MainLayout");
2520 int x,y,w,h; 2537 int x,y,w,h;
2521 QWidget* wid; 2538 QWidget* wid;
2522 wid = topLevelWidget(); 2539 wid = topLevelWidget();
2523 x = wid->geometry().x(); 2540 x = wid->geometry().x();
2524 y = wid->geometry().y(); 2541 y = wid->geometry().y();
2525 w = wid->width(); 2542 w = wid->width();
2526 h = wid->height(); 2543 h = wid->height();
2527 list.clear(); 2544 list.clear();
2528 list << QString::number( x ); 2545 list << QString::number( x );
2529 list << QString::number( y ); 2546 list << QString::number( y );
2530 list << QString::number( w ); 2547 list << QString::number( w );
2531 list << QString::number( h ); 2548 list << QString::number( h );
2532 config->writeEntry("MainLayout",list ); 2549 config->writeEntry("MainLayout",list );
2533 2550
2534 wid = mEventEditor; 2551 wid = mEventEditor;
2535 x = wid->geometry().x(); 2552 x = wid->geometry().x();
2536 y = wid->geometry().y(); 2553 y = wid->geometry().y();
2537 w = wid->width(); 2554 w = wid->width();
2538 h = wid->height(); 2555 h = wid->height();
2539 list.clear(); 2556 list.clear();
2540 list << QString::number( x ); 2557 list << QString::number( x );
2541 list << QString::number( y ); 2558 list << QString::number( y );
2542 list << QString::number( w ); 2559 list << QString::number( w );
2543 list << QString::number( h ); 2560 list << QString::number( h );
2544 config->writeEntry("EditEventLayout",list ); 2561 config->writeEntry("EditEventLayout",list );
2545 2562
2546 wid = mTodoEditor; 2563 wid = mTodoEditor;
2547 x = wid->geometry().x(); 2564 x = wid->geometry().x();
2548 y = wid->geometry().y(); 2565 y = wid->geometry().y();
2549 w = wid->width(); 2566 w = wid->width();
2550 h = wid->height(); 2567 h = wid->height();
2551 list.clear(); 2568 list.clear();
2552 list << QString::number( x ); 2569 list << QString::number( x );
2553 list << QString::number( y ); 2570 list << QString::number( y );
2554 list << QString::number( w ); 2571 list << QString::number( w );
2555 list << QString::number( h ); 2572 list << QString::number( h );
2556 config->writeEntry("EditTodoLayout",list ); 2573 config->writeEntry("EditTodoLayout",list );
2557 wid = getEventViewerDialog(); 2574 wid = getEventViewerDialog();
2558 x = wid->geometry().x(); 2575 x = wid->geometry().x();
2559 y = wid->geometry().y(); 2576 y = wid->geometry().y();
2560 w = wid->width(); 2577 w = wid->width();
2561 h = wid->height(); 2578 h = wid->height();
2562 list.clear(); 2579 list.clear();
2563 list << QString::number( x ); 2580 list << QString::number( x );
2564 list << QString::number( y ); 2581 list << QString::number( y );
2565 list << QString::number( w ); 2582 list << QString::number( w );
2566 list << QString::number( h ); 2583 list << QString::number( h );
2567 config->writeEntry("ViewerLayout",list ); 2584 config->writeEntry("ViewerLayout",list );
2568 wid = mDialogManager->getSearchDialog(); 2585 wid = mDialogManager->getSearchDialog();
2569 if ( wid ) { 2586 if ( wid ) {
2570 x = wid->geometry().x(); 2587 x = wid->geometry().x();
2571 y = wid->geometry().y(); 2588 y = wid->geometry().y();
2572 w = wid->width(); 2589 w = wid->width();
2573 h = wid->height(); 2590 h = wid->height();
2574 list.clear(); 2591 list.clear();
2575 list << QString::number( x ); 2592 list << QString::number( x );
2576 list << QString::number( y ); 2593 list << QString::number( y );
2577 list << QString::number( w ); 2594 list << QString::number( w );
2578 list << QString::number( h ); 2595 list << QString::number( h );
2579 config->writeEntry("SearchLayout",list ); 2596 config->writeEntry("SearchLayout",list );
2580 } 2597 }
2581#endif 2598#endif
2582 2599
2583 2600
2584 config->sync(); 2601 config->sync();
2585} 2602}
2586 2603
2587void CalendarView::readFilterSettings(KConfig *config) 2604void CalendarView::readFilterSettings(KConfig *config)
2588{ 2605{
2589 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2606 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2590 2607
2591 mFilters.clear(); 2608 mFilters.clear();
2592 2609
2593 config->setGroup("General"); 2610 config->setGroup("General");
2594 QStringList filterList = config->readListEntry("CalendarFilters"); 2611 QStringList filterList = config->readListEntry("CalendarFilters");
2595 2612
2596 QStringList::ConstIterator it = filterList.begin(); 2613 QStringList::ConstIterator it = filterList.begin();
2597 QStringList::ConstIterator end = filterList.end(); 2614 QStringList::ConstIterator end = filterList.end();
2598 while(it != end) { 2615 while(it != end) {
2599 // kdDebug() << " filter: " << (*it) << endl; 2616 // kdDebug() << " filter: " << (*it) << endl;
2600 2617
2601 CalFilter *filter; 2618 CalFilter *filter;
2602 filter = new CalFilter(*it); 2619 filter = new CalFilter(*it);
2603 config->setGroup("Filter_" + (*it).utf8()); 2620 config->setGroup("Filter_" + (*it).utf8());
2604 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2621 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2605 filter->setCriteria(config->readNumEntry("Criteria",0)); 2622 filter->setCriteria(config->readNumEntry("Criteria",0));
2606 filter->setCategoryList(config->readListEntry("CategoryList")); 2623 filter->setCategoryList(config->readListEntry("CategoryList"));
2607 mFilters.append(filter); 2624 mFilters.append(filter);
2608 2625
2609 ++it; 2626 ++it;
2610 } 2627 }
2611 2628
2612 if (mFilters.count() == 0) { 2629 if (mFilters.count() == 0) {
2613 CalFilter *filter = new CalFilter(i18n("Default")); 2630 CalFilter *filter = new CalFilter(i18n("Default"));
2614 mFilters.append(filter); 2631 mFilters.append(filter);
2615 } 2632 }
2616 mFilterView->updateFilters(); 2633 mFilterView->updateFilters();
2617 config->setGroup("FilterView"); 2634 config->setGroup("FilterView");
2618 2635
2619 mFilterView->blockSignals(true); 2636 mFilterView->blockSignals(true);
2620 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2637 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2621 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2638 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2622 mFilterView->blockSignals(false); 2639 mFilterView->blockSignals(false);
2623 // We do it manually to avoid it being done twice by the above calls 2640 // We do it manually to avoid it being done twice by the above calls
2624 updateFilter(); 2641 updateFilter();
2625} 2642}
2626 2643
2627void CalendarView::writeFilterSettings(KConfig *config) 2644void CalendarView::writeFilterSettings(KConfig *config)
2628{ 2645{
2629 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2646 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2630 2647
2631 QStringList filterList; 2648 QStringList filterList;
2632 2649
2633 CalFilter *filter = mFilters.first(); 2650 CalFilter *filter = mFilters.first();
2634 while(filter) { 2651 while(filter) {
2635 // kdDebug() << " fn: " << filter->name() << endl; 2652 // kdDebug() << " fn: " << filter->name() << endl;
2636 filterList << filter->name(); 2653 filterList << filter->name();
2637 config->setGroup("Filter_" + filter->name().utf8()); 2654 config->setGroup("Filter_" + filter->name().utf8());
2638 config->writeEntry("Criteria",filter->criteria()); 2655 config->writeEntry("Criteria",filter->criteria());
2639 config->writeEntry("CategoryList",filter->categoryList()); 2656 config->writeEntry("CategoryList",filter->categoryList());
2640 filter = mFilters.next(); 2657 filter = mFilters.next();
2641 } 2658 }
2642 config->setGroup("General"); 2659 config->setGroup("General");
2643 config->writeEntry("CalendarFilters",filterList); 2660 config->writeEntry("CalendarFilters",filterList);
2644 2661
2645 config->setGroup("FilterView"); 2662 config->setGroup("FilterView");
2646 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2663 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2647 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2664 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2648} 2665}
2649 2666
2650 2667
2651void CalendarView::goToday() 2668void CalendarView::goToday()
2652{ 2669{
2653 if ( mViewManager->currentView()->isMonthView() ) 2670 if ( mViewManager->currentView()->isMonthView() )
2654 mNavigator->selectTodayMonth(); 2671 mNavigator->selectTodayMonth();
2655 else 2672 else
2656 mNavigator->selectToday(); 2673 mNavigator->selectToday();
2657} 2674}
2658 2675
2659void CalendarView::goNext() 2676void CalendarView::goNext()
2660{ 2677{
2661 mNavigator->selectNext(); 2678 mNavigator->selectNext();
2662} 2679}
2663 2680
2664void CalendarView::goPrevious() 2681void CalendarView::goPrevious()
2665{ 2682{
2666 mNavigator->selectPrevious(); 2683 mNavigator->selectPrevious();
2667} 2684}
2668void CalendarView::goNextMonth() 2685void CalendarView::goNextMonth()
2669{ 2686{
2670 mNavigator->selectNextMonth(); 2687 mNavigator->selectNextMonth();
2671} 2688}
2672 2689
2673void CalendarView::goPreviousMonth() 2690void CalendarView::goPreviousMonth()
2674{ 2691{
2675 mNavigator->selectPreviousMonth(); 2692 mNavigator->selectPreviousMonth();
2676} 2693}
2677 2694
2678void CalendarView::updateConfig() 2695void CalendarView::updateConfig()
2679{ 2696{
2680 if ( KOPrefs::instance()->mUseAppColors ) 2697 if ( KOPrefs::instance()->mUseAppColors )
2681 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2698 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2682 emit configChanged(); 2699 emit configChanged();
2683 mTodoList->updateConfig(); 2700 mTodoList->updateConfig();
2684 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2701 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2685 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2686 // To make the "fill window" configurations work 2703 // To make the "fill window" configurations work
2687 //mViewManager->raiseCurrentView(); 2704 //mViewManager->raiseCurrentView();
2688} 2705}
2689 2706
2690 2707
2691void CalendarView::eventChanged(Event *event) 2708void CalendarView::eventChanged(Event *event)
2692{ 2709{
2693 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2710 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2694 //updateUnmanagedViews(); 2711 //updateUnmanagedViews();
2695} 2712}
2696 2713
2697void CalendarView::eventAdded(Event *event) 2714void CalendarView::eventAdded(Event *event)
2698{ 2715{
2699 changeEventDisplay(event,KOGlobals::EVENTADDED); 2716 changeEventDisplay(event,KOGlobals::EVENTADDED);
2700} 2717}
2701 2718
2702void CalendarView::eventToBeDeleted(Event *) 2719void CalendarView::eventToBeDeleted(Event *)
2703{ 2720{
2704 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2721 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2705} 2722}
2706 2723
2707void CalendarView::eventDeleted() 2724void CalendarView::eventDeleted()
2708{ 2725{
2709 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2726 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2710} 2727}
2711void CalendarView::changeTodoDisplay(Todo *which, int action) 2728void CalendarView::changeTodoDisplay(Todo *which, int action)
2712{ 2729{
2713 changeIncidenceDisplay((Incidence *)which, action); 2730 changeIncidenceDisplay((Incidence *)which, action);
2714 mDateNavigator->updateView(); //LR 2731 mDateNavigator->updateView(); //LR
2715 //mDialogManager->updateSearchDialog(); 2732 //mDialogManager->updateSearchDialog();
2716 2733
2717 if (which) { 2734 if (which) {
2718 mViewManager->updateWNview(); 2735 mViewManager->updateWNview();
2719 //mTodoList->updateView(); 2736 //mTodoList->updateView();
2720 } 2737 }
2721 2738
2722} 2739}
2723 2740
2724void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2741void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2725{ 2742{
2726 updateUnmanagedViews(); 2743 updateUnmanagedViews();
2727 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2744 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2728 if ( action == KOGlobals::EVENTDELETED ) { //delete 2745 if ( action == KOGlobals::EVENTDELETED ) { //delete
2729 mCalendar->checkAlarmForIncidence( 0, true ); 2746 mCalendar->checkAlarmForIncidence( 0, true );
2730 if ( mEventViewerDialog ) 2747 if ( mEventViewerDialog )
2731 mEventViewerDialog->hide(); 2748 mEventViewerDialog->hide();
2732 } 2749 }
2733 else 2750 else
2734 mCalendar->checkAlarmForIncidence( which , false ); 2751 mCalendar->checkAlarmForIncidence( which , false );
2735} 2752}
2736 2753
2737// most of the changeEventDisplays() right now just call the view's 2754// most of the changeEventDisplays() right now just call the view's
2738// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2755// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2739void CalendarView::changeEventDisplay(Event *which, int action) 2756void CalendarView::changeEventDisplay(Event *which, int action)
2740{ 2757{
2741 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2758 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2742 changeIncidenceDisplay((Incidence *)which, action); 2759 changeIncidenceDisplay((Incidence *)which, action);
2743 static bool clearallviews = false; 2760 static bool clearallviews = false;
2744 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2745 if ( clearallviews ) { 2762 if ( clearallviews ) {
2746 clearAllViews(); 2763 clearAllViews();
2747 clearallviews = false; 2764 clearallviews = false;
2748 } 2765 }
2749 return; 2766 return;
2750 } 2767 }
2751 clearallviews = true; 2768 clearallviews = true;
2752 mDateNavigator->updateView(); 2769 mDateNavigator->updateView();
2753 //mDialogManager->updateSearchDialog(); 2770 //mDialogManager->updateSearchDialog();
2754 if (which) { 2771 if (which) {
2755 // If there is an event view visible update the display 2772 // If there is an event view visible update the display
2756 mViewManager->currentView()->changeEventDisplay(which,action); 2773 mViewManager->currentView()->changeEventDisplay(which,action);
2757 // TODO: check, if update needed 2774 // TODO: check, if update needed
2758 // if (which->getTodoStatus()) { 2775 // if (which->getTodoStatus()) {
2759 mTodoList->updateView(); 2776 mTodoList->updateView();
2760 if ( action != KOGlobals::EVENTDELETED ) { 2777 if ( action != KOGlobals::EVENTDELETED ) {
2761 mConflictingEvent = which ; 2778 mConflictingEvent = which ;
2762 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2779 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) );
2763 } 2780 }
2764 // } 2781 // }
2765 } else { 2782 } else {
2766 mViewManager->currentView()->updateView(); 2783 mViewManager->currentView()->updateView();
2767 } 2784 }
2768} 2785}
2769void CalendarView::checkConflictForEvent() 2786void CalendarView::checkConflictForEvent()
2770{ 2787{
2771 2788
2772 if (!KOPrefs::instance()->mConfirm) 2789 if (!KOPrefs::instance()->mConfirm)
2773 return; 2790 return;
2774 if ( ! mConflictingEvent ) return; 2791 if ( ! mConflictingEvent ) return;
2775 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2792 QDateTime current = QDateTime::currentDateTime();
2793 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) {
2794 mConflictingEvent = 0;
2795 return;
2796 }
2776 QPtrList<Event> testlist = mCalendar->events(); 2797 QPtrList<Event> testlist = mCalendar->events();
2777 Event * test = testlist.first(); 2798 Event * test = testlist.first();
2778 QDateTime conflict; 2799 QDateTime conflict;
2779 QDateTime retVal; 2800 QDateTime retVal;
2780 bool found = false; 2801 bool found = false;
2781 Event * cE = 0; 2802 Event * cE = 0;
2782 QDateTime current = QDateTime::currentDateTime(); 2803 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2783 while ( test ) { 2804 while ( test ) {
2784 qApp->processEvents(); 2805 qApp->processEvents();
2785 if ( !test->doesFloat() ) { 2806 bool skip = false;
2807 if ( found )
2808 skip = !test->matchTime( &current, &conflict );
2809 else
2810 skip = !test->matchTime( &current, 0 );
2811 if ( !skip && !test->doesFloat() ) {
2786 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2812 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2787 if ( ! found ) { 2813 if ( ! found ) {
2788 conflict = retVal; 2814 conflict = retVal;
2789 cE = test; 2815 cE = test;
2790 } else { 2816 } else {
2791 if ( retVal < conflict ) { 2817 if ( retVal < conflict ) {
2792 conflict = retVal; 2818 conflict = retVal;
2793 cE = test; 2819 cE = test;
2794 } 2820 }
2795 } 2821 }
2796 found = true; 2822 found = true;
2797 } 2823 }
2798 } 2824 }
2799 test = testlist.next(); 2825 test = testlist.next();
2800 } 2826 }
2801 if ( found ) { 2827 if ( found ) {
2802 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2828 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2803 qApp->processEvents(); 2829 qApp->processEvents();
2804 int km = KMessageBox::warningContinueCancel(this,mess, 2830 int km = KMessageBox::warningContinueCancel(this,mess,
2805 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2831 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2806 if ( km != KMessageBox::Continue ) 2832 if ( km != KMessageBox::Continue )
2807 return; 2833 return;
2808 2834
2809 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2835 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2810 mViewManager->showDayView(); 2836 mViewManager->showDayView();
2811 mNavigator->slotDaySelect( conflict.date() ); 2837 mNavigator->slotDaySelect( conflict.date() );
2812 int hour = conflict.time().hour(); 2838 int hour = conflict.time().hour();
2813 mViewManager->agendaView()->setStartHour( hour ); 2839 mViewManager->agendaView()->setStartHour( hour );
2814 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2840 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2815 } else 2841 } else
2816 topLevelWidget()->setCaption( i18n("No conflict found") ); 2842 topLevelWidget()->setCaption( i18n("No conflict found") );
2817 mConflictingEvent = 0; 2843 mConflictingEvent = 0;
2818 return; 2844 return;
2819 2845
2820} 2846}
2821 2847
2822void CalendarView::updateTodoViews() 2848void CalendarView::updateTodoViews()
2823{ 2849{
2824 mTodoList->updateView(); 2850 mTodoList->updateView();
2825 mViewManager->currentView()->updateView(); 2851 mViewManager->currentView()->updateView();
2826 2852
2827} 2853}
2828 2854
2829 2855
2830 2856
2831void CalendarView::clearAllViews() 2857void CalendarView::clearAllViews()
2832{ 2858{
2833 mTodoList->clearList(); 2859 mTodoList->clearList();
2834 mViewManager->clearAllViews(); 2860 mViewManager->clearAllViews();
2835 SearchDialog * sd = mDialogManager->getSearchDialog(); 2861 SearchDialog * sd = mDialogManager->getSearchDialog();
2836 if ( sd ) { 2862 if ( sd ) {
2837 KOListView* kol = sd->listview(); 2863 KOListView* kol = sd->listview();
2838 if ( kol ) 2864 if ( kol )
2839 kol->clearList(); 2865 kol->clearList();
2840 } 2866 }
2841} 2867}
2842void CalendarView::updateView() 2868void CalendarView::updateView()
2843{ 2869{
2844 static bool clearallviews = false; 2870 static bool clearallviews = false;
2845 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2871 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2846 if ( clearallviews ) { 2872 if ( clearallviews ) {
2847 clearAllViews(); 2873 clearAllViews();
2848 clearallviews = false; 2874 clearallviews = false;
2849 } 2875 }
2850 return; 2876 return;
2851 } 2877 }
2852 clearallviews = true; 2878 clearallviews = true;
2853 DateList tmpList = mNavigator->selectedDates(); 2879 DateList tmpList = mNavigator->selectedDates();
2854 2880
2855 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2881 if ( KOPrefs::instance()->mHideNonStartedTodos )
2856 mTodoList->updateView(); 2882 mTodoList->updateView();
2857 // We assume that the navigator only selects consecutive days. 2883 // We assume that the navigator only selects consecutive days.
2858 updateView( tmpList.first(), tmpList.last() ); 2884 updateView( tmpList.first(), tmpList.last() );
2859} 2885}
2860 2886
2861void CalendarView::updateUnmanagedViews() 2887void CalendarView::updateUnmanagedViews()
2862{ 2888{
2863 mDateNavigator->updateDayMatrix(); 2889 mDateNavigator->updateDayMatrix();
2864} 2890}
2865 2891
2866int CalendarView::msgItemDelete(const QString name) 2892int CalendarView::msgItemDelete(const QString name)
2867{ 2893{
2868 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2894 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2869 i18n("This item will be\npermanently deleted."), 2895 i18n("This item will be\npermanently deleted."),
2870 i18n("KO/Pi Confirmation"),i18n("Delete")); 2896 i18n("KO/Pi Confirmation"),i18n("Delete"));
2871} 2897}
2872 2898
2873 2899
2874void CalendarView::edit_cut() 2900void CalendarView::edit_cut()
2875{ 2901{
2876 Event *anEvent=0; 2902 Event *anEvent=0;
2877 2903
2878 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2904 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2879 2905
2880 if (mViewManager->currentView()->isEventView()) { 2906 if (mViewManager->currentView()->isEventView()) {
2881 if ( incidence && incidence->typeID() == eventID ) { 2907 if ( incidence && incidence->typeID() == eventID ) {
2882 anEvent = static_cast<Event *>(incidence); 2908 anEvent = static_cast<Event *>(incidence);
2883 } 2909 }
2884 } 2910 }
2885 2911
2886 if (!anEvent) { 2912 if (!anEvent) {
2887 KNotifyClient::beep(); 2913 KNotifyClient::beep();
2888 return; 2914 return;
2889 } 2915 }
2890 DndFactory factory( mCalendar ); 2916 DndFactory factory( mCalendar );
2891 factory.cutIncidence(anEvent); 2917 factory.cutIncidence(anEvent);
2892 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2918 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2893} 2919}
2894 2920
2895void CalendarView::edit_copy() 2921void CalendarView::edit_copy()
2896{ 2922{
2897 Event *anEvent=0; 2923 Event *anEvent=0;
2898 2924
2899 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2925 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2900 2926
2901 if (mViewManager->currentView()->isEventView()) { 2927 if (mViewManager->currentView()->isEventView()) {
2902 if ( incidence && incidence->typeID() == eventID ) { 2928 if ( incidence && incidence->typeID() == eventID ) {
2903 anEvent = static_cast<Event *>(incidence); 2929 anEvent = static_cast<Event *>(incidence);
2904 } 2930 }
2905 } 2931 }
2906 2932
2907 if (!anEvent) { 2933 if (!anEvent) {
2908 KNotifyClient::beep(); 2934 KNotifyClient::beep();
2909 return; 2935 return;
2910 } 2936 }
2911 DndFactory factory( mCalendar ); 2937 DndFactory factory( mCalendar );
2912 factory.copyIncidence(anEvent); 2938 factory.copyIncidence(anEvent);
2913} 2939}
2914 2940
2915void CalendarView::edit_paste() 2941void CalendarView::edit_paste()
2916{ 2942{
2917 QDate date = mNavigator->selectedDates().first(); 2943 QDate date = mNavigator->selectedDates().first();
2918 2944
2919 DndFactory factory( mCalendar ); 2945 DndFactory factory( mCalendar );
2920 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2946 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2921 2947
2922 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2948 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2923} 2949}
2924void CalendarView::edit_global_options() 2950void CalendarView::edit_global_options()
2925{ 2951{
2926 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2952 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2927 emit save(); 2953 emit save();
2928 emit saveStopTimer(); 2954 emit saveStopTimer();
2929 mDialogManager->showGlobalOptionsDialog(); 2955 mDialogManager->showGlobalOptionsDialog();
2930 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2956 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2931 emit saveStopTimer(); 2957 emit saveStopTimer();
2932 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2958 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2933 i18n("Timezone settings"),i18n("Reload"))) { 2959 i18n("Timezone settings"),i18n("Reload"))) {
2934 qDebug("KO: TZ reload cancelled "); 2960 qDebug("KO: TZ reload cancelled ");
2935 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2961 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2936 return; 2962 return;
2937 } 2963 }
2938 qDebug("KO: Timezone change "); 2964 qDebug("KO: Timezone change ");
2939 loadCalendars(); 2965 loadCalendars();
2940 setModified(true); 2966 setModified(true);
2941 } 2967 }
2942 else 2968 else
2943 qDebug("KO: No tz change "); 2969 qDebug("KO: No tz change ");
2944} 2970}
2945void CalendarView::edit_options() 2971void CalendarView::edit_options()
2946{ 2972{
2947 mDialogManager->showOptionsDialog(); 2973 mDialogManager->showOptionsDialog();
2948} 2974}
2949 2975
2950 2976
2951void CalendarView::slotSelectPickerDate( QDate d) 2977void CalendarView::slotSelectPickerDate( QDate d)
2952{ 2978{
2953 mDateFrame->hide(); 2979 mDateFrame->hide();
2954 if ( mDatePickerMode == 1 ) { 2980 if ( mDatePickerMode == 1 ) {
2955 mNavigator->slotDaySelect( d ); 2981 mNavigator->slotDaySelect( d );
2956 } else if ( mDatePickerMode == 2 ) { 2982 } else if ( mDatePickerMode == 2 ) {
2957 if ( mMoveIncidence->typeID() == todoID ) { 2983 if ( mMoveIncidence->typeID() == todoID ) {
2958 Todo * to = (Todo *) mMoveIncidence; 2984 Todo * to = (Todo *) mMoveIncidence;
2959 QTime tim; 2985 QTime tim;
2960 int len = 0; 2986 int len = 0;
2961 if ( to->hasStartDate() && to->hasDueDate() ) 2987 if ( to->hasStartDate() && to->hasDueDate() )
2962 len = to->dtStart().secsTo( to->dtDue()); 2988 len = to->dtStart().secsTo( to->dtDue());
2963 if ( to->hasDueDate() ) 2989 if ( to->hasDueDate() )
2964 tim = to->dtDue().time(); 2990 tim = to->dtDue().time();
2965 else { 2991 else {
2966 tim = QTime ( 0,0,0 ); 2992 tim = QTime ( 0,0,0 );
2967 to->setFloats( true ); 2993 to->setFloats( true );
2968 to->setHasDueDate( true ); 2994 to->setHasDueDate( true );
2969 } 2995 }
2970 QDateTime dt ( d,tim ); 2996 QDateTime dt ( d,tim );
2971 to->setDtDue( dt ); 2997 to->setDtDue( dt );
2972 2998
2973 if ( to->hasStartDate() ) { 2999 if ( to->hasStartDate() ) {
2974 if ( len>0 ) 3000 if ( len>0 )
2975 to->setDtStart(to->dtDue().addSecs( -len )); 3001 to->setDtStart(to->dtDue().addSecs( -len ));
2976 else 3002 else
2977 if (to->dtStart() > to->dtDue() ) 3003 if (to->dtStart() > to->dtDue() )
2978 to->setDtStart(to->dtDue().addDays( -3 )); 3004 to->setDtStart(to->dtDue().addDays( -3 ));
2979 } 3005 }
2980 3006
2981 todoChanged( to ); 3007 todoChanged( to );
2982 } else if ( mMoveIncidence->typeID() == eventID ) { 3008 } else if ( mMoveIncidence->typeID() == eventID ) {
2983 if ( mMoveIncidence->doesRecur() ) { 3009 if ( mMoveIncidence->doesRecur() ) {
2984#if 0 3010#if 0
2985 // PENDING implement this 3011 // PENDING implement this
2986 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 3012 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2987 mCalendar()->addIncidence( newInc ); 3013 mCalendar()->addIncidence( newInc );
2988 if ( mMoveIncidence->typeID() == todoID ) 3014 if ( mMoveIncidence->typeID() == todoID )
2989 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 3015 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2990 else 3016 else
2991 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 3017 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2992 mMoveIncidence = newInc; 3018 mMoveIncidence = newInc;
2993 3019
2994#endif 3020#endif
2995 } 3021 }
2996 QTime tim = mMoveIncidence->dtStart().time(); 3022 QTime tim = mMoveIncidence->dtStart().time();
2997 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 3023 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2998 QDateTime dt ( d,tim ); 3024 QDateTime dt ( d,tim );
2999 mMoveIncidence->setDtStart( dt ); 3025 mMoveIncidence->setDtStart( dt );
3000 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 3026 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
3001 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 3027 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
3002 } else if ( mMoveIncidence->typeID() == journalID ) { 3028 } else if ( mMoveIncidence->typeID() == journalID ) {
3003 QTime tim = mMoveIncidence->dtStart().time(); 3029 QTime tim = mMoveIncidence->dtStart().time();
3004 QDateTime dt ( d,tim ); 3030 QDateTime dt ( d,tim );
3005 mMoveIncidence->setDtStart( dt ); 3031 mMoveIncidence->setDtStart( dt );
3006 updateView(); 3032 updateView();
3007 } 3033 }
3008 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3034 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
3009 } 3035 }
3010} 3036}
3011 3037
3012void CalendarView::removeCategories() 3038void CalendarView::removeCategories()
3013{ 3039{
3014 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3040 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3015 QStringList catList = KOPrefs::instance()->mCustomCategories; 3041 QStringList catList = KOPrefs::instance()->mCustomCategories;
3016 QStringList catIncList; 3042 QStringList catIncList;
3017 QStringList newCatList; 3043 QStringList newCatList;
3018 Incidence* inc = incList.first(); 3044 Incidence* inc = incList.first();
3019 uint i; 3045 uint i;
3020 while ( inc ) { 3046 while ( inc ) {
3021 newCatList.clear(); 3047 newCatList.clear();
3022 catIncList = inc->categories() ; 3048 catIncList = inc->categories() ;
3023 for( i = 0; i< catIncList.count(); ++i ) { 3049 for( i = 0; i< catIncList.count(); ++i ) {
3024 if ( catList.contains (catIncList[i])) 3050 if ( catList.contains (catIncList[i]))
3025 newCatList.append( catIncList[i] ); 3051 newCatList.append( catIncList[i] );
3026 } 3052 }
3027 newCatList.sort(); 3053 newCatList.sort();
3028 inc->setCategories( newCatList.join(",") ); 3054 inc->setCategories( newCatList.join(",") );
3029 inc = incList.next(); 3055 inc = incList.next();
3030 } 3056 }
3031} 3057}
3032 3058
3033int CalendarView::addCategories() 3059int CalendarView::addCategories()
3034{ 3060{
3035 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3061 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3036 QStringList catList = KOPrefs::instance()->mCustomCategories; 3062 QStringList catList = KOPrefs::instance()->mCustomCategories;
3037 QStringList catIncList; 3063 QStringList catIncList;
3038 Incidence* inc = incList.first(); 3064 Incidence* inc = incList.first();
3039 uint i; 3065 uint i;
3040 int count = 0; 3066 int count = 0;
3041 while ( inc ) { 3067 while ( inc ) {
3042 catIncList = inc->categories() ; 3068 catIncList = inc->categories() ;
3043 for( i = 0; i< catIncList.count(); ++i ) { 3069 for( i = 0; i< catIncList.count(); ++i ) {
3044 if ( !catList.contains (catIncList[i])) { 3070 if ( !catList.contains (catIncList[i])) {
3045 catList.append( catIncList[i] ); 3071 catList.append( catIncList[i] );
3046 //qDebug("add cat %s ", catIncList[i].latin1()); 3072 //qDebug("add cat %s ", catIncList[i].latin1());
3047 ++count; 3073 ++count;
3048 } 3074 }
3049 } 3075 }
3050 inc = incList.next(); 3076 inc = incList.next();
3051 } 3077 }
3052 catList.sort(); 3078 catList.sort();
3053 KOPrefs::instance()->mCustomCategories = catList; 3079 KOPrefs::instance()->mCustomCategories = catList;
3054 return count; 3080 return count;
3055} 3081}
3056 3082
3057void CalendarView::editCategories() 3083void CalendarView::editCategories()
3058{ 3084{
3059 qDebug("CalendarView::editCategories() "); 3085 qDebug("CalendarView::editCategories() ");
3060 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3086 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3061 ced.exec(); 3087 ced.exec();
3062} 3088}
3063void CalendarView::manageCategories() 3089void CalendarView::manageCategories()
3064{ 3090{
3065 KOCatPrefs* cp = new KOCatPrefs(); 3091 KOCatPrefs* cp = new KOCatPrefs();
3066 cp->show(); 3092 cp->show();
3067 int w =cp->sizeHint().width() ; 3093 int w =cp->sizeHint().width() ;
3068 int h = cp->sizeHint().height() ; 3094 int h = cp->sizeHint().height() ;
3069 int dw = QApplication::desktop()->width(); 3095 int dw = QApplication::desktop()->width();
3070 int dh = QApplication::desktop()->height(); 3096 int dh = QApplication::desktop()->height();
3071 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3097 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3072 if ( !cp->exec() ) { 3098 if ( !cp->exec() ) {
3073 delete cp; 3099 delete cp;
3074 return; 3100 return;
3075 } 3101 }
3076 int count = 0; 3102 int count = 0;
3077 if ( cp->addCat() ) { 3103 if ( cp->addCat() ) {
3078 count = addCategories(); 3104 count = addCategories();
3079 if ( count ) { 3105 if ( count ) {
3080 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3106 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3081 writeSettings(); 3107 writeSettings();
3082 } else 3108 } else
3083 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3109 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3084 } else { 3110 } else {
3085 removeCategories(); 3111 removeCategories();
3086 updateView(); 3112 updateView();
3087 } 3113 }
3088 delete cp; 3114 delete cp;
3089} 3115}
3090 3116
3091void CalendarView::beamIncidence(Incidence * Inc) 3117void CalendarView::beamIncidence(Incidence * Inc)
3092{ 3118{
3093 QPtrList<Incidence> delSel ; 3119 QPtrList<Incidence> delSel ;
3094 delSel.append(Inc); 3120 delSel.append(Inc);
3095 beamIncidenceList( delSel ); 3121 beamIncidenceList( delSel );
3096} 3122}
3097void CalendarView::beamCalendar() 3123void CalendarView::beamCalendar()
3098{ 3124{
3099 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3125 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3100 //qDebug("beamCalendar() "); 3126 //qDebug("beamCalendar() ");
3101 beamIncidenceList( delSel ); 3127 beamIncidenceList( delSel );
3102} 3128}
3103void CalendarView::beamFilteredCalendar() 3129void CalendarView::beamFilteredCalendar()
3104{ 3130{
3105 QPtrList<Incidence> delSel = mCalendar->incidences(); 3131 QPtrList<Incidence> delSel = mCalendar->incidences();
3106 //qDebug("beamFilteredCalendar() "); 3132 //qDebug("beamFilteredCalendar() ");
3107 beamIncidenceList( delSel ); 3133 beamIncidenceList( delSel );
3108} 3134}
3109void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3135void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3110{ 3136{
3111 3137
3112 KOBeamPrefs beamDialog; 3138 KOBeamPrefs beamDialog;
3113 if ( beamDialog.exec () == QDialog::Rejected ) 3139 if ( beamDialog.exec () == QDialog::Rejected )
3114 return; 3140 return;
3115#ifdef DESKTOP_VERSION 3141#ifdef DESKTOP_VERSION
3116 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3142 QString fn = locateLocal( "tmp", "kopibeamfile" );
3117#else 3143#else
3118 QString fn = "/tmp/kopibeamfile"; 3144 QString fn = "/tmp/kopibeamfile";
3119#endif 3145#endif
3120 QString mes; 3146 QString mes;
3121 bool createbup = true; 3147 bool createbup = true;
3122 if ( createbup ) { 3148 if ( createbup ) {
3123 QString description = "\n"; 3149 QString description = "\n";
3124 CalendarLocal* cal = new CalendarLocal(); 3150 CalendarLocal* cal = new CalendarLocal();
3125 if ( beamDialog.beamLocal() ) 3151 if ( beamDialog.beamLocal() )
3126 cal->setLocalTime(); 3152 cal->setLocalTime();
3127 else 3153 else
3128 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3154 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3129 Incidence *incidence = delSel.first(); 3155 Incidence *incidence = delSel.first();
3130 bool addText = false; 3156 bool addText = false;
3131 if ( delSel.count() < 10 ) 3157 if ( delSel.count() < 10 )
3132 addText = true; 3158 addText = true;
3133 else { 3159 else {
3134 description.sprintf(i18n(" %d items?"),delSel.count() ); 3160 description.sprintf(i18n(" %d items?"),delSel.count() );
3135 } 3161 }
3136 while ( incidence ) { 3162 while ( incidence ) {
3137 Incidence *in = incidence->clone(); 3163 Incidence *in = incidence->clone();
3138 if ( ! in->summary().isEmpty() ) { 3164 if ( ! in->summary().isEmpty() ) {
3139 in->setDescription(""); 3165 in->setDescription("");
3140 } else { 3166 } else {
3141 in->setSummary( in->description().left(20)); 3167 in->setSummary( in->description().left(20));
3142 in->setDescription(""); 3168 in->setDescription("");
3143 } 3169 }
3144 if ( addText ) 3170 if ( addText )
3145 description += in->summary() + "\n"; 3171 description += in->summary() + "\n";
3146 cal->addIncidence( in ); 3172 cal->addIncidence( in );
3147 incidence = delSel.next(); 3173 incidence = delSel.next();
3148 } 3174 }
3149 if ( beamDialog.beamVcal() ) { 3175 if ( beamDialog.beamVcal() ) {
3150 fn += ".vcs"; 3176 fn += ".vcs";
3151 FileStorage storage( cal, fn, new VCalFormat ); 3177 FileStorage storage( cal, fn, new VCalFormat );
3152 storage.save(); 3178 storage.save();
3153 } else { 3179 } else {
3154 fn += ".ics"; 3180 fn += ".ics";
3155 FileStorage storage( cal, fn, new ICalFormat( ) ); 3181 FileStorage storage( cal, fn, new ICalFormat( ) );
3156 storage.save(); 3182 storage.save();
3157 } 3183 }
3158 delete cal; 3184 delete cal;
3159 mes = i18n("KO/Pi: Ready for beaming"); 3185 mes = i18n("KO/Pi: Ready for beaming");
3160 topLevelWidget()->setCaption(mes); 3186 topLevelWidget()->setCaption(mes);
3161 KApplication::convert2latin1( fn ); 3187 KApplication::convert2latin1( fn );
3162#ifndef DESKTOP_VERSION 3188#ifndef DESKTOP_VERSION
3163 Ir *ir = new Ir( this ); 3189 Ir *ir = new Ir( this );
3164 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3190 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3165 ir->send( fn, description, "text/x-vCalendar" ); 3191 ir->send( fn, description, "text/x-vCalendar" );
3166#endif 3192#endif
3167 } 3193 }
3168} 3194}
3169 3195
3170#ifndef DESKTOP_VERSION 3196#ifndef DESKTOP_VERSION
3171void CalendarView::beamDone( Ir *ir ) 3197void CalendarView::beamDone( Ir *ir )
3172{ 3198{
3173 delete ir; 3199 delete ir;
3174 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3200 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3175 topLevelWidget()->raise(); 3201 topLevelWidget()->raise();
3176} 3202}
3177#else 3203#else
3178void CalendarView::beamDone( Ir *){;} 3204void CalendarView::beamDone( Ir *){;}
3179#endif 3205#endif
3180void CalendarView::moveIncidence(Incidence * inc ) 3206void CalendarView::moveIncidence(Incidence * inc )
3181{ 3207{
3182 if ( !inc ) return; 3208 if ( !inc ) return;
3183 showDatePickerPopup(); 3209 showDatePickerPopup();
3184 mDatePickerMode = 2; 3210 mDatePickerMode = 2;
3185 mMoveIncidence = inc ; 3211 mMoveIncidence = inc ;
3186 QDate da; 3212 QDate da;
3187 if ( mMoveIncidence->typeID() == todoID ) { 3213 if ( mMoveIncidence->typeID() == todoID ) {
3188 Todo * to = (Todo *) mMoveIncidence; 3214 Todo * to = (Todo *) mMoveIncidence;
3189 if ( to->hasDueDate() ) 3215 if ( to->hasDueDate() )
3190 da = to->dtDue().date(); 3216 da = to->dtDue().date();
3191 else 3217 else
3192 da = QDate::currentDate(); 3218 da = QDate::currentDate();
3193 } else { 3219 } else {
3194 da = mMoveIncidence->dtStart().date(); 3220 da = mMoveIncidence->dtStart().date();
3195 } 3221 }
3196 //PENDING set date for recurring incidence to date of recurrence 3222 //PENDING set date for recurring incidence to date of recurrence
3197 //mMoveIncidenceOldDate; 3223 //mMoveIncidenceOldDate;
3198 mDatePicker->setDate( da ); 3224 mDatePicker->setDate( da );
3199} 3225}
3200void CalendarView::showDatePickerPopup() 3226void CalendarView::showDatePickerPopup()
3201{ 3227{
3202 if ( mDateFrame->isVisible() ) 3228 if ( mDateFrame->isVisible() )
3203 mDateFrame->hide(); 3229 mDateFrame->hide();
3204 else { 3230 else {
3205 int offX = 0, offY = 0; 3231 int offX = 0, offY = 0;
3206#ifdef DESKTOP_VERSION 3232#ifdef DESKTOP_VERSION
3207 int w =mDatePicker->sizeHint().width() ; 3233 int w =mDatePicker->sizeHint().width() ;
3208 int h = mDatePicker->sizeHint().height() ; 3234 int h = mDatePicker->sizeHint().height() ;
3209 int dw = topLevelWidget()->width(); 3235 int dw = topLevelWidget()->width();
3210 int dh = topLevelWidget()->height(); 3236 int dh = topLevelWidget()->height();
3211 offX = topLevelWidget()->x(); 3237 offX = topLevelWidget()->x();
3212 offY = topLevelWidget()->y(); 3238 offY = topLevelWidget()->y();
3213#else 3239#else
3214 int w =mDatePicker->sizeHint().width() ; 3240 int w =mDatePicker->sizeHint().width() ;
3215 int h = mDatePicker->sizeHint().height() ; 3241 int h = mDatePicker->sizeHint().height() ;
3216 int dw = QApplication::desktop()->width(); 3242 int dw = QApplication::desktop()->width();
3217 int dh = QApplication::desktop()->height(); 3243 int dh = QApplication::desktop()->height();
3218#endif 3244#endif
3219 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3245 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3220 mDateFrame->show(); 3246 mDateFrame->show();
3221 } 3247 }
3222} 3248}
3223void CalendarView::showDatePicker( ) 3249void CalendarView::showDatePicker( )
3224{ 3250{
3225 showDatePickerPopup(); 3251 showDatePickerPopup();
3226 mDatePickerMode = 1; 3252 mDatePickerMode = 1;
3227 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3253 mDatePicker->setDate( mNavigator->selectedDates().first() );
3228} 3254}
3229 3255
3230void CalendarView::showEventEditor() 3256void CalendarView::showEventEditor()
3231{ 3257{
3232#ifdef DESKTOP_VERSION 3258#ifdef DESKTOP_VERSION
3233 int x,y,w,h; 3259 int x,y,w,h;
3234 x = mEventEditor->geometry().x(); 3260 x = mEventEditor->geometry().x();
3235 y = mEventEditor->geometry().y(); 3261 y = mEventEditor->geometry().y();
3236 w = mEventEditor->width(); 3262 w = mEventEditor->width();
3237 h = mEventEditor->height(); 3263 h = mEventEditor->height();
3238 mEventEditor->show(); 3264 mEventEditor->show();
3239 mEventEditor->setGeometry(x,y,w,h); 3265 mEventEditor->setGeometry(x,y,w,h);
3240#else 3266#else
3241 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3267 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3242 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3268 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3243 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3269 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3244 qApp->processEvents(); 3270 qApp->processEvents();
3245 delete mEventEditor; 3271 delete mEventEditor;
3246 mEventEditor = mDialogManager->getEventEditor(); 3272 mEventEditor = mDialogManager->getEventEditor();
3247 topLevelWidget()->setCaption( i18n("") ); 3273 topLevelWidget()->setCaption( i18n("") );
3248 } 3274 }
3249 mEventEditor->showMaximized(); 3275 mEventEditor->showMaximized();
3250#endif 3276#endif
3251} 3277}
3252void CalendarView::showTodoEditor() 3278void CalendarView::showTodoEditor()
3253{ 3279{
3254#ifdef DESKTOP_VERSION 3280#ifdef DESKTOP_VERSION
3255 int x,y,w,h; 3281 int x,y,w,h;
3256 x = mTodoEditor->geometry().x(); 3282 x = mTodoEditor->geometry().x();
3257 y = mTodoEditor->geometry().y(); 3283 y = mTodoEditor->geometry().y();
3258 w = mTodoEditor->width(); 3284 w = mTodoEditor->width();
3259 h = mTodoEditor->height(); 3285 h = mTodoEditor->height();
3260 mTodoEditor->show(); 3286 mTodoEditor->show();
3261 mTodoEditor->setGeometry(x,y,w,h); 3287 mTodoEditor->setGeometry(x,y,w,h);
3262#else 3288#else
3263 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3289 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3264 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3290 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3265 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3291 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3266 qApp->processEvents(); 3292 qApp->processEvents();
3267 delete mTodoEditor; 3293 delete mTodoEditor;
3268 mTodoEditor = mDialogManager->getTodoEditor(); 3294 mTodoEditor = mDialogManager->getTodoEditor();
3269 topLevelWidget()->setCaption( i18n("") ); 3295 topLevelWidget()->setCaption( i18n("") );
3270 } 3296 }
3271 mTodoEditor->showMaximized(); 3297 mTodoEditor->showMaximized();
3272#endif 3298#endif
3273} 3299}
3274 3300
3275void CalendarView::cloneIncidence() 3301void CalendarView::cloneIncidence()
3276{ 3302{
3277 Incidence *incidence = currentSelection(); 3303 Incidence *incidence = currentSelection();
3278 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3304 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3279 if ( incidence ) { 3305 if ( incidence ) {
3280 cloneIncidence(incidence); 3306 cloneIncidence(incidence);
3281 } 3307 }
3282} 3308}
3283void CalendarView::moveIncidence() 3309void CalendarView::moveIncidence()
3284{ 3310{
3285 Incidence *incidence = currentSelection(); 3311 Incidence *incidence = currentSelection();
3286 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3312 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3287 if ( incidence ) { 3313 if ( incidence ) {
3288 moveIncidence(incidence); 3314 moveIncidence(incidence);
3289 } 3315 }
3290} 3316}
3291void CalendarView::beamIncidence() 3317void CalendarView::beamIncidence()
3292{ 3318{
3293 Incidence *incidence = currentSelection(); 3319 Incidence *incidence = currentSelection();
3294 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3320 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3295 if ( incidence ) { 3321 if ( incidence ) {
3296 beamIncidence(incidence); 3322 beamIncidence(incidence);
3297 } 3323 }
3298} 3324}
3299void CalendarView::toggleCancelIncidence() 3325void CalendarView::toggleCancelIncidence()
3300{ 3326{
3301 Incidence *incidence = currentSelection(); 3327 Incidence *incidence = currentSelection();
3302 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3328 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3303 if ( incidence ) { 3329 if ( incidence ) {
3304 cancelIncidence(incidence); 3330 cancelIncidence(incidence);
3305 } 3331 }
3306} 3332}
3307 3333
3308 3334
3309void CalendarView::cancelIncidence(Incidence * inc ) 3335void CalendarView::cancelIncidence(Incidence * inc )
3310{ 3336{
3311 inc->setCancelled( ! inc->cancelled() ); 3337 inc->setCancelled( ! inc->cancelled() );
3312 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3338 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3313 updateView(); 3339 updateView();
3314} 3340}
3315void CalendarView::cloneIncidence(Incidence * orgInc ) 3341void CalendarView::cloneIncidence(Incidence * orgInc )
3316{ 3342{
3317 Incidence * newInc = orgInc->clone(); 3343 Incidence * newInc = orgInc->clone();
3318 newInc->recreate(); 3344 newInc->recreate();
3319 3345
3320 if ( newInc->typeID() == todoID ) { 3346 if ( newInc->typeID() == todoID ) {
3321 Todo* t = (Todo*) newInc; 3347 Todo* t = (Todo*) newInc;
3322 bool cloneSub = false; 3348 bool cloneSub = false;
3323 if ( orgInc->relations().count() ) { 3349 if ( orgInc->relations().count() ) {
3324 int result = KMessageBox::warningYesNoCancel(this, 3350 int result = KMessageBox::warningYesNoCancel(this,
3325 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3351 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3326 i18n("Todo has subtodos"), 3352 i18n("Todo has subtodos"),
3327 i18n("Yes"), 3353 i18n("Yes"),
3328 i18n("No")); 3354 i18n("No"));
3329 3355
3330 if ( result == KMessageBox::Cancel ) { 3356 if ( result == KMessageBox::Cancel ) {
3331 delete t; 3357 delete t;
3332 return; 3358 return;
3333 } 3359 }
3334 if (result == KMessageBox::Yes) cloneSub = true; 3360 if (result == KMessageBox::Yes) cloneSub = true;
3335 } 3361 }
3336 showTodoEditor(); 3362 showTodoEditor();
3337 mTodoEditor->editTodo( t ); 3363 mTodoEditor->editTodo( t );
3338 if ( mTodoEditor->exec() ) { 3364 if ( mTodoEditor->exec() ) {
3339 if ( cloneSub ) { 3365 if ( cloneSub ) {
3340 orgInc->cloneRelations( t ); 3366 orgInc->cloneRelations( t );
3341 mCalendar->addIncidenceBranch( t ); 3367 mCalendar->addIncidenceBranch( t );
3342 updateView(); 3368 updateView();
3343 3369
3344 } else { 3370 } else {
3345 mCalendar->addTodo( t ); 3371 mCalendar->addTodo( t );
3346 updateView(); 3372 updateView();
3347 } 3373 }
3348 } else { 3374 } else {
3349 delete t; 3375 delete t;
3350 } 3376 }
3351 } 3377 }
3352 else if ( newInc->typeID() == eventID ) { 3378 else if ( newInc->typeID() == eventID ) {
3353 Event* e = (Event*) newInc; 3379 Event* e = (Event*) newInc;
3354 showEventEditor(); 3380 showEventEditor();
3355 mEventEditor->editEvent( e ); 3381 mEventEditor->editEvent( e );
3356 if ( mEventEditor->exec() ) { 3382 if ( mEventEditor->exec() ) {
3357 mCalendar->addEvent( e ); 3383 mCalendar->addEvent( e );
3358 updateView(); 3384 updateView();
3359 } else { 3385 } else {
3360 delete e; 3386 delete e;
3361 } 3387 }
3362 } if ( newInc->typeID() == journalID ) { 3388 } if ( newInc->typeID() == journalID ) {
3363 mCalendar->addJournal( (Journal*) newInc ); 3389 mCalendar->addJournal( (Journal*) newInc );
3364 editJournal( (Journal*) newInc ); 3390 editJournal( (Journal*) newInc );
3365 } 3391 }
3366 setActiveWindow(); 3392 setActiveWindow();
3367} 3393}
3368 3394
3369void CalendarView::newEvent() 3395void CalendarView::newEvent()
3370{ 3396{
3371 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3397 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3372 KOAgendaView *aView = mViewManager->agendaView(); 3398 KOAgendaView *aView = mViewManager->agendaView();
3373 if (aView) { 3399 if (aView) {
3374 if (aView->selectionStart().isValid()) { 3400 if (aView->selectionStart().isValid()) {
3375 if (aView->selectedIsAllDay()) { 3401 if (aView->selectedIsAllDay()) {
3376 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3402 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3377 } else { 3403 } else {
3378 newEvent(aView->selectionStart(),aView->selectionEnd()); 3404 newEvent(aView->selectionStart(),aView->selectionEnd());
3379 } 3405 }
3380 return; 3406 return;
3381 } 3407 }
3382 } 3408 }
3383 3409
3384 QDate date = mNavigator->selectedDates().first(); 3410 QDate date = mNavigator->selectedDates().first();
3385#if 0 3411#if 0
3386 QDateTime current = QDateTime::currentDateTime(); 3412 QDateTime current = QDateTime::currentDateTime();
3387 if ( date <= current.date() ) { 3413 if ( date <= current.date() ) {
3388 int hour = current.time().hour() +1; 3414 int hour = current.time().hour() +1;
3389 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3415 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3390 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3416 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3391 } else 3417 } else
3392#endif 3418#endif
3393 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3419 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3394 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3420 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3395 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3421 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3396} 3422}
3397 3423
3398void CalendarView::newEvent(QDateTime fh) 3424void CalendarView::newEvent(QDateTime fh)
3399{ 3425{
3400 newEvent(fh, 3426 newEvent(fh,
3401 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3427 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3402} 3428}
3403 3429
3404void CalendarView::newEvent(QDate dt) 3430void CalendarView::newEvent(QDate dt)
3405{ 3431{
3406 newEvent(QDateTime(dt, QTime(0,0,0)), 3432 newEvent(QDateTime(dt, QTime(0,0,0)),
3407 QDateTime(dt, QTime(0,0,0)), true); 3433 QDateTime(dt, QTime(0,0,0)), true);
3408} 3434}
3409void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3435void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3410{ 3436{
3411 newEvent(fromHint, toHint, false); 3437 newEvent(fromHint, toHint, false);
3412} 3438}
3413void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3439void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3414{ 3440{
3415 3441
3416 showEventEditor(); 3442 showEventEditor();
3417 mEventEditor->newEvent(fromHint,toHint,allDay); 3443 mEventEditor->newEvent(fromHint,toHint,allDay);
3418 if ( mFilterView->filtersEnabled() ) { 3444 if ( mFilterView->filtersEnabled() ) {
3419 CalFilter *filter = mFilterView->selectedFilter(); 3445 CalFilter *filter = mFilterView->selectedFilter();
3420 if (filter && filter->showCategories()) { 3446 if (filter && filter->showCategories()) {
3421 mEventEditor->setCategories(filter->categoryList().join(",") ); 3447 mEventEditor->setCategories(filter->categoryList().join(",") );
3422 } 3448 }
3423 if ( filter ) 3449 if ( filter )
3424 mEventEditor->setSecrecy( filter->getSecrecy() ); 3450 mEventEditor->setSecrecy( filter->getSecrecy() );
3425 } 3451 }
3426 mEventEditor->exec(); 3452 mEventEditor->exec();
3427 setActiveWindow(); 3453 setActiveWindow();
3428} 3454}
3429void CalendarView::todoAdded(Todo * t) 3455void CalendarView::todoAdded(Todo * t)
3430{ 3456{
3431 3457
3432 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3458 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3433 updateTodoViews(); 3459 updateTodoViews();
3434} 3460}
3435void CalendarView::todoChanged(Todo * t) 3461void CalendarView::todoChanged(Todo * t)
3436{ 3462{
3437 emit todoModified( t, 4 ); 3463 emit todoModified( t, 4 );
3438 // updateTodoViews(); 3464 // updateTodoViews();
3439} 3465}
3440void CalendarView::todoToBeDeleted(Todo *) 3466void CalendarView::todoToBeDeleted(Todo *)
3441{ 3467{
3442 //qDebug("todoToBeDeleted(Todo *) "); 3468 //qDebug("todoToBeDeleted(Todo *) ");
3443 updateTodoViews(); 3469 updateTodoViews();
3444} 3470}
3445void CalendarView::todoDeleted() 3471void CalendarView::todoDeleted()
3446{ 3472{
3447 //qDebug(" todoDeleted()"); 3473 //qDebug(" todoDeleted()");
3448 updateTodoViews(); 3474 updateTodoViews();
3449} 3475}
3450 3476
3451 3477
3452void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3478void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3453{ 3479{
3454 showTodoEditor(); 3480 showTodoEditor();
3455 mTodoEditor->newTodo(dt,0,allday); 3481 mTodoEditor->newTodo(dt,0,allday);
3456 if ( mFilterView->filtersEnabled() ) { 3482 if ( mFilterView->filtersEnabled() ) {
3457 CalFilter *filter = mFilterView->selectedFilter(); 3483 CalFilter *filter = mFilterView->selectedFilter();
3458 if (filter && filter->showCategories()) { 3484 if (filter && filter->showCategories()) {
3459 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3485 mTodoEditor->setCategories(filter->categoryList().join(",") );
3460 } 3486 }
3461 if ( filter ) 3487 if ( filter )
3462 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3488 mTodoEditor->setSecrecy( filter->getSecrecy() );
3463 } 3489 }
3464 mTodoEditor->exec(); 3490 mTodoEditor->exec();
3465 setActiveWindow(); 3491 setActiveWindow();
3466} 3492}
3467 3493
3468void CalendarView::newTodo() 3494void CalendarView::newTodo()
3469{ 3495{
3470 newTodoDateTime( QDateTime(),true ); 3496 newTodoDateTime( QDateTime(),true );
3471} 3497}
3472 3498
3473void CalendarView::newSubTodo() 3499void CalendarView::newSubTodo()
3474{ 3500{
3475 Todo *todo = selectedTodo(); 3501 Todo *todo = selectedTodo();
3476 if ( todo ) newSubTodo( todo ); 3502 if ( todo ) newSubTodo( todo );
3477} 3503}
3478 3504
3479void CalendarView::newSubTodo(Todo *parentEvent) 3505void CalendarView::newSubTodo(Todo *parentEvent)
3480{ 3506{
3481 3507
3482 showTodoEditor(); 3508 showTodoEditor();
3483 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3509 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3484 mTodoEditor->exec(); 3510 mTodoEditor->exec();
3485 setActiveWindow(); 3511 setActiveWindow();
3486} 3512}
3487 3513
3488void CalendarView::newFloatingEvent() 3514void CalendarView::newFloatingEvent()
3489{ 3515{
3490 DateList tmpList = mNavigator->selectedDates(); 3516 DateList tmpList = mNavigator->selectedDates();
3491 QDate date = tmpList.first(); 3517 QDate date = tmpList.first();
3492 3518
3493 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3519 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3494 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3520 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3495} 3521}
3496 3522
3497 3523
3498void CalendarView::editEvent( Event *event ) 3524void CalendarView::editEvent( Event *event )
3499{ 3525{
3500 3526
3501 if ( !event ) return; 3527 if ( !event ) return;
3502 if ( event->isReadOnly() ) { 3528 if ( event->isReadOnly() ) {
3503 showEvent( event ); 3529 showEvent( event );
3504 return; 3530 return;
3505 } 3531 }
3506 showEventEditor(); 3532 showEventEditor();
3507 mEventEditor->editEvent( event , mFlagEditDescription); 3533 mEventEditor->editEvent( event , mFlagEditDescription);
3508 mEventEditor->exec(); 3534 mEventEditor->exec();
3509 setActiveWindow(); 3535 setActiveWindow();
3510 3536
3511} 3537}
3512void CalendarView::editJournal( Journal *jour ) 3538void CalendarView::editJournal( Journal *jour )
3513{ 3539{
3514 if ( !jour ) return; 3540 if ( !jour ) return;
3515 mDialogManager->hideSearchDialog(); 3541 mDialogManager->hideSearchDialog();
3516 mViewManager->showJournalView(); 3542 mViewManager->showJournalView();
3517 mNavigator->slotDaySelect( jour->dtStart().date() ); 3543 mNavigator->slotDaySelect( jour->dtStart().date() );
3518} 3544}
3519void CalendarView::editTodo( Todo *todo ) 3545void CalendarView::editTodo( Todo *todo )
3520{ 3546{
3521 if ( !todo ) return; 3547 if ( !todo ) return;
3522 3548
3523 if ( todo->isReadOnly() ) { 3549 if ( todo->isReadOnly() ) {
3524 showTodo( todo ); 3550 showTodo( todo );
3525 return; 3551 return;
3526 } 3552 }
3527 showTodoEditor(); 3553 showTodoEditor();
3528 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3554 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3529 mTodoEditor->exec(); 3555 mTodoEditor->exec();
3530 setActiveWindow(); 3556 setActiveWindow();
3531 3557
3532} 3558}
3533 3559
3534KOEventViewerDialog* CalendarView::getEventViewerDialog() 3560KOEventViewerDialog* CalendarView::getEventViewerDialog()
3535{ 3561{
3536 if ( !mEventViewerDialog ) { 3562 if ( !mEventViewerDialog ) {
3537 mEventViewerDialog = new KOEventViewerDialog(0); 3563 mEventViewerDialog = new KOEventViewerDialog(0);
3538 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3564 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3539 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3565 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3540 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3566 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3541 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3567 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3542 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3568 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3543 viewManager(), SLOT( showAgendaView( bool ) ) ); 3569 viewManager(), SLOT( showAgendaView( bool ) ) );
3544 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3570 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3545 this, SLOT( slotViewerClosed() ) ); 3571 this, SLOT( slotViewerClosed() ) );
3546 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3572 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3547 this, SLOT( todoChanged(Todo *) ) ); 3573 this, SLOT( todoChanged(Todo *) ) );
3548 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3574 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3549 mEventViewerDialog->resize( 640, 480 ); 3575 mEventViewerDialog->resize( 640, 480 );
3550 3576
3551 } 3577 }
3552 return mEventViewerDialog; 3578 return mEventViewerDialog;
3553} 3579}
3554void CalendarView::showEvent(Event *event) 3580void CalendarView::showEvent(Event *event)
3555{ 3581{
3556 getEventViewerDialog()->setEvent(event); 3582 getEventViewerDialog()->setEvent(event);
3557 getEventViewerDialog()->showMe(); 3583 getEventViewerDialog()->showMe();
3558} 3584}
3559 3585
3560void CalendarView::showTodo(Todo *event) 3586void CalendarView::showTodo(Todo *event)
3561{ 3587{
3562 getEventViewerDialog()->setTodo(event); 3588 getEventViewerDialog()->setTodo(event);
3563 getEventViewerDialog()->showMe(); 3589 getEventViewerDialog()->showMe();
3564} 3590}
3565void CalendarView::showJournal( Journal *jour ) 3591void CalendarView::showJournal( Journal *jour )
3566{ 3592{
3567 getEventViewerDialog()->setJournal(jour); 3593 getEventViewerDialog()->setJournal(jour);
3568 getEventViewerDialog()->showMe(); 3594 getEventViewerDialog()->showMe();
3569 3595
3570} 3596}
3571// void CalendarView::todoModified (Todo *event, int changed) 3597// void CalendarView::todoModified (Todo *event, int changed)
3572// { 3598// {
3573// // if (mDialogList.find (event) != mDialogList.end ()) { 3599// // if (mDialogList.find (event) != mDialogList.end ()) {
3574// // kdDebug() << "Todo modified and open" << endl; 3600// // kdDebug() << "Todo modified and open" << endl;
3575// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3601// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3576// // temp->modified (changed); 3602// // temp->modified (changed);
3577 3603
3578// // } 3604// // }
3579 3605
3580// mViewManager->updateView(); 3606// mViewManager->updateView();
3581// } 3607// }
3582 3608
3583void CalendarView::appointment_show() 3609void CalendarView::appointment_show()
3584{ 3610{
3585 Event *anEvent = 0; 3611 Event *anEvent = 0;
3586 3612
3587 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3613 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3588 3614
3589 if (mViewManager->currentView()->isEventView()) { 3615 if (mViewManager->currentView()->isEventView()) {
3590 if ( incidence && incidence->typeID() == eventID ) { 3616 if ( incidence && incidence->typeID() == eventID ) {
3591 anEvent = static_cast<Event *>(incidence); 3617 anEvent = static_cast<Event *>(incidence);
3592 } 3618 }
3593 } 3619 }
3594 3620
3595 if (!anEvent) { 3621 if (!anEvent) {
3596 KNotifyClient::beep(); 3622 KNotifyClient::beep();
3597 return; 3623 return;
3598 } 3624 }
3599 3625
3600 showEvent(anEvent); 3626 showEvent(anEvent);
3601} 3627}
3602 3628
3603void CalendarView::appointment_edit() 3629void CalendarView::appointment_edit()
3604{ 3630{
3605 Event *anEvent = 0; 3631 Event *anEvent = 0;
3606 3632
3607 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3633 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3608 3634
3609 if (mViewManager->currentView()->isEventView()) { 3635 if (mViewManager->currentView()->isEventView()) {
3610 if ( incidence && incidence->typeID() == eventID ) { 3636 if ( incidence && incidence->typeID() == eventID ) {
3611 anEvent = static_cast<Event *>(incidence); 3637 anEvent = static_cast<Event *>(incidence);
3612 } 3638 }
3613 } 3639 }
3614 3640
3615 if (!anEvent) { 3641 if (!anEvent) {
3616 KNotifyClient::beep(); 3642 KNotifyClient::beep();
3617 return; 3643 return;
3618 } 3644 }
3619 3645
3620 editEvent(anEvent); 3646 editEvent(anEvent);
3621} 3647}
3622 3648
3623void CalendarView::appointment_delete() 3649void CalendarView::appointment_delete()
3624{ 3650{
3625 Event *anEvent = 0; 3651 Event *anEvent = 0;
3626 3652
3627 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3653 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3628 3654
3629 if (mViewManager->currentView()->isEventView()) { 3655 if (mViewManager->currentView()->isEventView()) {
3630 if ( incidence && incidence->typeID() == eventID ) { 3656 if ( incidence && incidence->typeID() == eventID ) {
3631 anEvent = static_cast<Event *>(incidence); 3657 anEvent = static_cast<Event *>(incidence);
3632 } 3658 }
3633 } 3659 }
3634 3660
3635 if (!anEvent) { 3661 if (!anEvent) {
3636 KNotifyClient::beep(); 3662 KNotifyClient::beep();
3637 return; 3663 return;
3638 } 3664 }
3639 3665
3640 deleteEvent(anEvent); 3666 deleteEvent(anEvent);
3641} 3667}
3642 3668
3643void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3669void CalendarView::todo_resub( Todo * parent, Todo * sub )
3644{ 3670{
3645 if (!sub) return; 3671 if (!sub) return;
3646 if ( sub->relatedTo() == parent ) 3672 if ( sub->relatedTo() == parent )
3647 return; 3673 return;
3648 sub->setRelatedTo(parent); 3674 sub->setRelatedTo(parent);
3649 sub->updated(); 3675 sub->updated();
3650 setModified(true); 3676 setModified(true);
3651 updateView(); 3677 updateView();
3652} 3678}
3653void CalendarView::todo_unsub(Todo *anTodo ) 3679void CalendarView::todo_unsub(Todo *anTodo )
3654{ 3680{
3655 todo_resub( 0, anTodo ); 3681 todo_resub( 0, anTodo );
3656} 3682}
3657 3683
3658void CalendarView::deleteTodo(Todo *todo) 3684void CalendarView::deleteTodo(Todo *todo)
3659{ 3685{
3660 if (!todo) { 3686 if (!todo) {
3661 KNotifyClient::beep(); 3687 KNotifyClient::beep();
3662 return; 3688 return;
3663 } 3689 }
3664 if (KOPrefs::instance()->mConfirm) { 3690 if (KOPrefs::instance()->mConfirm) {
3665 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3691 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3666 if (!todo->relations().isEmpty()) { 3692 if (!todo->relations().isEmpty()) {
3667 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3693 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3668 3694
3669 } 3695 }
3670 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3696 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3671 case KMessageBox::Continue: // OK 3697 case KMessageBox::Continue: // OK
3672 bool deleteT = false; 3698 bool deleteT = false;
3673 if (!todo->relations().isEmpty()) { 3699 if (!todo->relations().isEmpty()) {
3674 deleteT = removeCompletedSubTodos( todo ); 3700 deleteT = removeCompletedSubTodos( todo );
3675 } 3701 }
3676 // deleteT == true: todo already deleted in removeCompletedSubTodos 3702 // deleteT == true: todo already deleted in removeCompletedSubTodos
3677 if ( !deleteT ) { 3703 if ( !deleteT ) {
3678 checkExternalId( todo ); 3704 checkExternalId( todo );
3679 calendar()->deleteTodo(todo); 3705 calendar()->deleteTodo(todo);
3680 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3706 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3681 updateView(); 3707 updateView();
3682 } 3708 }
3683 break; 3709 break;
3684 } // switch 3710 } // switch
3685 } else { 3711 } else {
3686 checkExternalId( todo ); 3712 checkExternalId( todo );
3687 mCalendar->deleteTodo(todo); 3713 mCalendar->deleteTodo(todo);
3688 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3714 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3689 updateView(); 3715 updateView();
3690 } 3716 }
3691 3717
3692 emit updateSearchDialog(); 3718 emit updateSearchDialog();
3693} 3719}
3694void CalendarView::deleteJournal(Journal *jour) 3720void CalendarView::deleteJournal(Journal *jour)
3695{ 3721{
3696 if (!jour) { 3722 if (!jour) {
3697 KNotifyClient::beep(); 3723 KNotifyClient::beep();
3698 return; 3724 return;
3699 } 3725 }
3700 if (KOPrefs::instance()->mConfirm) { 3726 if (KOPrefs::instance()->mConfirm) {
3701 3727
3702 QString des; 3728 QString des;
3703 if ( !jour->summary().isEmpty() ) { 3729 if ( !jour->summary().isEmpty() ) {
3704 des = jour->summary(); 3730 des = jour->summary();
3705 } else { 3731 } else {
3706 des = jour->description().left(30); 3732 des = jour->description().left(30);
3707 des = des.simplifyWhiteSpace (); 3733 des = des.simplifyWhiteSpace ();
3708 des.replace (QRegExp ("\\n"),"" ); 3734 des.replace (QRegExp ("\\n"),"" );
3709 des.replace (QRegExp ("\\r"),"" ); 3735 des.replace (QRegExp ("\\r"),"" );
3710 } 3736 }
3711 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3737 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3712 case KMessageBox::Continue: // OK 3738 case KMessageBox::Continue: // OK
3713 calendar()->deleteJournal(jour); 3739 calendar()->deleteJournal(jour);
3714 updateView(); 3740 updateView();
3715 break; 3741 break;
3716 } // switch 3742 } // switch
3717 } else { 3743 } else {
3718 calendar()->deleteJournal(jour);; 3744 calendar()->deleteJournal(jour);;
3719 updateView(); 3745 updateView();
3720 } 3746 }
3721 emit updateSearchDialog(); 3747 emit updateSearchDialog();
3722} 3748}
3723 3749
3724void CalendarView::deleteEvent(Event *anEvent) 3750void CalendarView::deleteEvent(Event *anEvent)
3725{ 3751{
3726 if (!anEvent) { 3752 if (!anEvent) {
3727 KNotifyClient::beep(); 3753 KNotifyClient::beep();
3728 return; 3754 return;
3729 } 3755 }
3730 3756
3731 if (anEvent->recurrence()->doesRecur()) { 3757 if (anEvent->recurrence()->doesRecur()) {
3732 QDate itemDate = mViewManager->currentSelectionDate(); 3758 QDate itemDate = mViewManager->currentSelectionDate();
3733 int km; 3759 int km;
3734 if (!itemDate.isValid()) { 3760 if (!itemDate.isValid()) {
3735 //kdDebug() << "Date Not Valid" << endl; 3761 //kdDebug() << "Date Not Valid" << endl;
3736 if (KOPrefs::instance()->mConfirm) { 3762 if (KOPrefs::instance()->mConfirm) {
3737 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3763 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3738 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3764 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3739 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3765 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3740 if ( km == KMessageBox::Continue ) 3766 if ( km == KMessageBox::Continue )
3741 km = KMessageBox::No; // No = all below 3767 km = KMessageBox::No; // No = all below
3742 } else 3768 } else
3743 km = KMessageBox::No; 3769 km = KMessageBox::No;
3744 } else { 3770 } else {
3745 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3771 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3746 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3772 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3747 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3773 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3748 i18n("KO/Pi Confirmation"),i18n("Current"), 3774 i18n("KO/Pi Confirmation"),i18n("Current"),
3749 i18n("All")); 3775 i18n("All"));
3750 } 3776 }
3751 switch(km) { 3777 switch(km) {
3752 3778
3753 case KMessageBox::No: // Continue // all 3779 case KMessageBox::No: // Continue // all
3754 //qDebug("KMessageBox::No "); 3780 //qDebug("KMessageBox::No ");
3755 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3781 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3756 schedule(Scheduler::Cancel,anEvent); 3782 schedule(Scheduler::Cancel,anEvent);
3757 3783
3758 checkExternalId( anEvent); 3784 checkExternalId( anEvent);
3759 mCalendar->deleteEvent(anEvent); 3785 mCalendar->deleteEvent(anEvent);
3760 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3786 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3761 break; 3787 break;
3762 3788
3763 // Disabled because it does not work 3789 // Disabled because it does not work
3764 //#if 0 3790 //#if 0
3765 case KMessageBox::Yes: // just this one 3791 case KMessageBox::Yes: // just this one
3766 //QDate qd = mNavigator->selectedDates().first(); 3792 //QDate qd = mNavigator->selectedDates().first();
3767 //if (!qd.isValid()) { 3793 //if (!qd.isValid()) {
3768 // kdDebug() << "no date selected, or invalid date" << endl; 3794 // kdDebug() << "no date selected, or invalid date" << endl;
3769 // KNotifyClient::beep(); 3795 // KNotifyClient::beep();
3770 // return; 3796 // return;
3771 //} 3797 //}
3772 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3798 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3773 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3799 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3774 anEvent->addExDate(itemDate); 3800 anEvent->addExDate(itemDate);
3775 int duration = anEvent->recurrence()->duration(); 3801 int duration = anEvent->recurrence()->duration();
3776 if ( duration > 0 ) { 3802 if ( duration > 0 ) {
3777 anEvent->recurrence()->setDuration( duration - 1 ); 3803 anEvent->recurrence()->setDuration( duration - 1 );
3778 } 3804 }
3779 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3805 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3780 } 3806 }
3781 break; 3807 break;
3782 //#endif 3808 //#endif
3783 } // switch 3809 } // switch
3784 } else { 3810 } else {
3785 if (KOPrefs::instance()->mConfirm) { 3811 if (KOPrefs::instance()->mConfirm) {
3786 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3812 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3787 i18n("\nAre you sure you want\nto delete this event?"), 3813 i18n("\nAre you sure you want\nto delete this event?"),
3788 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3814 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3789 case KMessageBox::Continue: // OK 3815 case KMessageBox::Continue: // OK
3790 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3816 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3791 schedule(Scheduler::Cancel,anEvent); 3817 schedule(Scheduler::Cancel,anEvent);
3792 checkExternalId( anEvent); 3818 checkExternalId( anEvent);
3793 mCalendar->deleteEvent(anEvent); 3819 mCalendar->deleteEvent(anEvent);
3794 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3820 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3795 break; 3821 break;
3796 } // switch 3822 } // switch
3797 } else { 3823 } else {
3798 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3824 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3799 schedule(Scheduler::Cancel,anEvent); 3825 schedule(Scheduler::Cancel,anEvent);
3800 checkExternalId( anEvent); 3826 checkExternalId( anEvent);
3801 mCalendar->deleteEvent(anEvent); 3827 mCalendar->deleteEvent(anEvent);
3802 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3828 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3803 } 3829 }
3804 } // if-else 3830 } // if-else
3805 emit updateSearchDialog(); 3831 emit updateSearchDialog();
3806} 3832}
3807 3833
3808bool CalendarView::deleteEvent(const QString &uid) 3834bool CalendarView::deleteEvent(const QString &uid)
3809{ 3835{
3810 Event *ev = mCalendar->event(uid); 3836 Event *ev = mCalendar->event(uid);
3811 if (ev) { 3837 if (ev) {
3812 deleteEvent(ev); 3838 deleteEvent(ev);
3813 return true; 3839 return true;
3814 } else { 3840 } else {
3815 return false; 3841 return false;
3816 } 3842 }
3817} 3843}
3818 3844
3819/*****************************************************************************/ 3845/*****************************************************************************/
3820 3846
3821void CalendarView::action_mail() 3847void CalendarView::action_mail()
3822{ 3848{
3823#ifndef KORG_NOMAIL 3849#ifndef KORG_NOMAIL
3824 KOMailClient mailClient; 3850 KOMailClient mailClient;
3825 3851
3826 Incidence *incidence = currentSelection(); 3852 Incidence *incidence = currentSelection();
3827 3853
3828 if (!incidence) { 3854 if (!incidence) {
3829 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3855 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3830 return; 3856 return;
3831 } 3857 }
3832 if(incidence->attendeeCount() == 0 ) { 3858 if(incidence->attendeeCount() == 0 ) {
3833 KMessageBox::sorry(this, 3859 KMessageBox::sorry(this,
3834 i18n("Can't generate mail:\nNo attendees defined.\n")); 3860 i18n("Can't generate mail:\nNo attendees defined.\n"));
3835 return; 3861 return;
3836 } 3862 }
3837 3863
3838 CalendarLocal cal_tmp; 3864 CalendarLocal cal_tmp;
3839 Event *event = 0; 3865 Event *event = 0;
3840 Event *ev = 0; 3866 Event *ev = 0;
3841 if ( incidence && incidence->typeID() == eventID ) { 3867 if ( incidence && incidence->typeID() == eventID ) {
3842 event = static_cast<Event *>(incidence); 3868 event = static_cast<Event *>(incidence);
3843 ev = new Event(*event); 3869 ev = new Event(*event);
3844 cal_tmp.addEvent(ev); 3870 cal_tmp.addEvent(ev);
3845 } 3871 }
3846 ICalFormat mForm(); 3872 ICalFormat mForm();
3847 QString attachment = mForm.toString( &cal_tmp ); 3873 QString attachment = mForm.toString( &cal_tmp );
3848 if (ev) delete(ev); 3874 if (ev) delete(ev);
3849 3875
3850 mailClient.mailAttendees(currentSelection(), attachment); 3876 mailClient.mailAttendees(currentSelection(), attachment);
3851 3877
3852#endif 3878#endif
3853 3879
3854#if 0 3880#if 0
3855 Event *anEvent = 0; 3881 Event *anEvent = 0;
3856 if (mViewManager->currentView()->isEventView()) { 3882 if (mViewManager->currentView()->isEventView()) {
3857 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3883 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3858 } 3884 }
3859 3885
3860 if (!anEvent) { 3886 if (!anEvent) {
3861 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3887 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3862 return; 3888 return;
3863 } 3889 }
3864 if(anEvent->attendeeCount() == 0 ) { 3890 if(anEvent->attendeeCount() == 0 ) {
3865 KMessageBox::sorry(this, 3891 KMessageBox::sorry(this,
3866 i18n("Can't generate mail:\nNo attendees defined.\n")); 3892 i18n("Can't generate mail:\nNo attendees defined.\n"));
3867 return; 3893 return;
3868 } 3894 }
3869 3895
3870 mailobject.emailEvent(anEvent); 3896 mailobject.emailEvent(anEvent);
3871#endif 3897#endif
3872} 3898}
3873 3899
3874 3900
3875void CalendarView::schedule_publish(Incidence *incidence) 3901void CalendarView::schedule_publish(Incidence *incidence)
3876{ 3902{
3877 Event *event = 0; 3903 Event *event = 0;
3878 Todo *todo = 0; 3904 Todo *todo = 0;
3879 3905
3880 if (incidence == 0) { 3906 if (incidence == 0) {
3881 incidence = mViewManager->currentView()->selectedIncidences().first(); 3907 incidence = mViewManager->currentView()->selectedIncidences().first();
3882 if (incidence == 0) { 3908 if (incidence == 0) {
3883 incidence = mTodoList->selectedIncidences().first(); 3909 incidence = mTodoList->selectedIncidences().first();
3884 } 3910 }
3885 } 3911 }
3886 if ( incidence && incidence->typeID() == eventID ) { 3912 if ( incidence && incidence->typeID() == eventID ) {
3887 event = static_cast<Event *>(incidence); 3913 event = static_cast<Event *>(incidence);
3888 } else { 3914 } else {
3889 if ( incidence && incidence->typeID() == todoID ) { 3915 if ( incidence && incidence->typeID() == todoID ) {
3890 todo = static_cast<Todo *>(incidence); 3916 todo = static_cast<Todo *>(incidence);
3891 } 3917 }
3892 } 3918 }
3893 3919
3894 if (!event && !todo) { 3920 if (!event && !todo) {
3895 KMessageBox::sorry(this,i18n("No event selected.")); 3921 KMessageBox::sorry(this,i18n("No event selected."));
3896 return; 3922 return;
3897 } 3923 }
3898 3924
3899 PublishDialog *publishdlg = new PublishDialog(); 3925 PublishDialog *publishdlg = new PublishDialog();
3900 if (incidence->attendeeCount()>0) { 3926 if (incidence->attendeeCount()>0) {
3901 QPtrList<Attendee> attendees = incidence->attendees(); 3927 QPtrList<Attendee> attendees = incidence->attendees();
3902 attendees.first(); 3928 attendees.first();
3903 while ( attendees.current()!=0 ) { 3929 while ( attendees.current()!=0 ) {
3904 publishdlg->addAttendee(attendees.current()); 3930 publishdlg->addAttendee(attendees.current());
3905 attendees.next(); 3931 attendees.next();
3906 } 3932 }
3907 } 3933 }
3908 bool send = true; 3934 bool send = true;
3909 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3935 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3910 if ( publishdlg->exec() != QDialog::Accepted ) 3936 if ( publishdlg->exec() != QDialog::Accepted )
3911 send = false; 3937 send = false;
3912 } 3938 }
3913 if ( send ) { 3939 if ( send ) {
3914 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3940 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3915 if ( event ) { 3941 if ( event ) {
3916 Event *ev = new Event(*event); 3942 Event *ev = new Event(*event);
3917 ev->registerObserver(0); 3943 ev->registerObserver(0);
3918 ev->clearAttendees(); 3944 ev->clearAttendees();
3919 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3945 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3920 delete(ev); 3946 delete(ev);
3921 } 3947 }
3922 } else { 3948 } else {
3923 if ( todo ) { 3949 if ( todo ) {
3924 Todo *ev = new Todo(*todo); 3950 Todo *ev = new Todo(*todo);
3925 ev->registerObserver(0); 3951 ev->registerObserver(0);
3926 ev->clearAttendees(); 3952 ev->clearAttendees();
3927 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3953 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3928 delete(ev); 3954 delete(ev);
3929 } 3955 }
3930 } 3956 }
3931 } 3957 }
3932 } 3958 }
3933 delete publishdlg; 3959 delete publishdlg;
3934} 3960}
3935 3961
3936void CalendarView::schedule_request(Incidence *incidence) 3962void CalendarView::schedule_request(Incidence *incidence)
3937{ 3963{
3938 schedule(Scheduler::Request,incidence); 3964 schedule(Scheduler::Request,incidence);
3939} 3965}
3940 3966
3941void CalendarView::schedule_refresh(Incidence *incidence) 3967void CalendarView::schedule_refresh(Incidence *incidence)
3942{ 3968{
3943 schedule(Scheduler::Refresh,incidence); 3969 schedule(Scheduler::Refresh,incidence);
3944} 3970}
3945 3971
3946void CalendarView::schedule_cancel(Incidence *incidence) 3972void CalendarView::schedule_cancel(Incidence *incidence)
3947{ 3973{
3948 schedule(Scheduler::Cancel,incidence); 3974 schedule(Scheduler::Cancel,incidence);
3949} 3975}
3950 3976
3951void CalendarView::schedule_add(Incidence *incidence) 3977void CalendarView::schedule_add(Incidence *incidence)
3952{ 3978{
3953 schedule(Scheduler::Add,incidence); 3979 schedule(Scheduler::Add,incidence);
3954} 3980}
3955 3981
3956void CalendarView::schedule_reply(Incidence *incidence) 3982void CalendarView::schedule_reply(Incidence *incidence)
3957{ 3983{
3958 schedule(Scheduler::Reply,incidence); 3984 schedule(Scheduler::Reply,incidence);
3959} 3985}
3960 3986
3961void CalendarView::schedule_counter(Incidence *incidence) 3987void CalendarView::schedule_counter(Incidence *incidence)
3962{ 3988{
3963 schedule(Scheduler::Counter,incidence); 3989 schedule(Scheduler::Counter,incidence);
3964} 3990}
3965 3991
3966void CalendarView::schedule_declinecounter(Incidence *incidence) 3992void CalendarView::schedule_declinecounter(Incidence *incidence)
3967{ 3993{
3968 schedule(Scheduler::Declinecounter,incidence); 3994 schedule(Scheduler::Declinecounter,incidence);
3969} 3995}
3970 3996
3971void CalendarView::schedule_publish_freebusy(int daysToPublish) 3997void CalendarView::schedule_publish_freebusy(int daysToPublish)
3972{ 3998{
3973 QDateTime start = QDateTime::currentDateTime(); 3999 QDateTime start = QDateTime::currentDateTime();
3974 QDateTime end = start.addDays(daysToPublish); 4000 QDateTime end = start.addDays(daysToPublish);
3975 4001
3976 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 4002 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3977 freebusy->setOrganizer(KOPrefs::instance()->email()); 4003 freebusy->setOrganizer(KOPrefs::instance()->email());
3978 4004
3979 4005
3980 PublishDialog *publishdlg = new PublishDialog(); 4006 PublishDialog *publishdlg = new PublishDialog();
3981 if ( publishdlg->exec() == QDialog::Accepted ) { 4007 if ( publishdlg->exec() == QDialog::Accepted ) {
3982 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4008 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3983 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 4009 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3984 delete(freebusy); 4010 delete(freebusy);
3985 } 4011 }
3986 } 4012 }
3987 delete publishdlg; 4013 delete publishdlg;
3988} 4014}
3989 4015
3990void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 4016void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3991{ 4017{
3992 Event *event = 0; 4018 Event *event = 0;
3993 Todo *todo = 0; 4019 Todo *todo = 0;
3994 4020
3995 if (incidence == 0) { 4021 if (incidence == 0) {
3996 incidence = mViewManager->currentView()->selectedIncidences().first(); 4022 incidence = mViewManager->currentView()->selectedIncidences().first();
3997 if (incidence == 0) { 4023 if (incidence == 0) {
3998 incidence = mTodoList->selectedIncidences().first(); 4024 incidence = mTodoList->selectedIncidences().first();
3999 } 4025 }
4000 } 4026 }
4001 if ( incidence && incidence->typeID() == eventID ) { 4027 if ( incidence && incidence->typeID() == eventID ) {
4002 event = static_cast<Event *>(incidence); 4028 event = static_cast<Event *>(incidence);
4003 } 4029 }
4004 if ( incidence && incidence->typeID() == todoID ) { 4030 if ( incidence && incidence->typeID() == todoID ) {
4005 todo = static_cast<Todo *>(incidence); 4031 todo = static_cast<Todo *>(incidence);
4006 } 4032 }
4007 4033
4008 if (!event && !todo) { 4034 if (!event && !todo) {
4009 KMessageBox::sorry(this,i18n("No event selected.")); 4035 KMessageBox::sorry(this,i18n("No event selected."));
4010 return; 4036 return;
4011 } 4037 }
4012 4038
4013 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4039 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
4014 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4040 KMessageBox::sorry(this,i18n("The event has no attendees."));
4015 return; 4041 return;
4016 } 4042 }
4017 4043
4018 Event *ev = 0; 4044 Event *ev = 0;
4019 if (event) ev = new Event(*event); 4045 if (event) ev = new Event(*event);
4020 Todo *to = 0; 4046 Todo *to = 0;
4021 if (todo) to = new Todo(*todo); 4047 if (todo) to = new Todo(*todo);
4022 4048
4023 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4049 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
4024 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4050 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
4025 if (!me) { 4051 if (!me) {
4026 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4052 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4027 return; 4053 return;
4028 } 4054 }
4029 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4055 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4030 StatusDialog *statdlg = new StatusDialog(this); 4056 StatusDialog *statdlg = new StatusDialog(this);
4031 if (!statdlg->exec()==QDialog::Accepted) return; 4057 if (!statdlg->exec()==QDialog::Accepted) return;
4032 me->setStatus( statdlg->status() ); 4058 me->setStatus( statdlg->status() );
4033 delete(statdlg); 4059 delete(statdlg);
4034 } 4060 }
4035 Attendee *menew = new Attendee(*me); 4061 Attendee *menew = new Attendee(*me);
4036 if (ev) { 4062 if (ev) {
4037 ev->clearAttendees(); 4063 ev->clearAttendees();
4038 ev->addAttendee(menew,false); 4064 ev->addAttendee(menew,false);
4039 } else { 4065 } else {
4040 if (to) { 4066 if (to) {
4041 todo->clearAttendees(); 4067 todo->clearAttendees();
4042 todo->addAttendee(menew,false); 4068 todo->addAttendee(menew,false);
4043 } 4069 }
4044 } 4070 }
4045 } 4071 }
4046 4072
4047 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4073 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4048 if (ev) { 4074 if (ev) {
4049 if ( !dlg->addMessage(ev,method) ) delete(ev); 4075 if ( !dlg->addMessage(ev,method) ) delete(ev);
4050 } else { 4076 } else {
4051 if (to) { 4077 if (to) {
4052 if ( !dlg->addMessage(to,method) ) delete(to); 4078 if ( !dlg->addMessage(to,method) ) delete(to);
4053 } 4079 }
4054 } 4080 }
4055} 4081}
4056 4082
4057void CalendarView::openAddressbook() 4083void CalendarView::openAddressbook()
4058{ 4084{
4059 KRun::runCommand("kaddressbook"); 4085 KRun::runCommand("kaddressbook");
4060} 4086}
4061 4087
4062void CalendarView::setModified(bool modified) 4088void CalendarView::setModified(bool modified)
4063{ 4089{
4064 if ( modified ) 4090 if ( modified )
4065 emit signalmodified(); 4091 emit signalmodified();
4066 if (mModified != modified) { 4092 if (mModified != modified) {
4067 mModified = modified; 4093 mModified = modified;
4068 emit modifiedChanged(mModified); 4094 emit modifiedChanged(mModified);
4069 } 4095 }
4070} 4096}
4071 4097
4072bool CalendarView::isReadOnly() 4098bool CalendarView::isReadOnly()
4073{ 4099{
4074 return mReadOnly; 4100 return mReadOnly;
4075} 4101}
4076 4102
4077void CalendarView::setReadOnly(bool readOnly) 4103void CalendarView::setReadOnly(bool readOnly)
4078{ 4104{
4079 if (mReadOnly != readOnly) { 4105 if (mReadOnly != readOnly) {
4080 mReadOnly = readOnly; 4106 mReadOnly = readOnly;
4081 emit readOnlyChanged(mReadOnly); 4107 emit readOnlyChanged(mReadOnly);
4082 } 4108 }
4083} 4109}
4084 4110
4085bool CalendarView::isModified() 4111bool CalendarView::isModified()
4086{ 4112{
4087 return mModified; 4113 return mModified;
4088} 4114}
4089void CalendarView::slotprintSelInc() 4115void CalendarView::slotprintSelInc()
4090{ 4116{
4091 if ( currentSelection() == 0 ) { 4117 if ( currentSelection() == 0 ) {
4092 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4118 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4093 return; 4119 return;
4094 } 4120 }
4095 showIncidence(); 4121 showIncidence();
4096 getEventViewerDialog()->print(); 4122 getEventViewerDialog()->print();
4097 4123
4098} 4124}
4099void CalendarView::printSetup() 4125void CalendarView::printSetup()
4100{ 4126{
4101#ifndef KORG_NOPRINTER 4127#ifndef KORG_NOPRINTER
4102 createPrinter(); 4128 createPrinter();
4103 4129
4104 mCalPrinter->setupPrinter(); 4130 mCalPrinter->setupPrinter();
4105#endif 4131#endif
4106} 4132}
4107 4133
4108void CalendarView::print() 4134void CalendarView::print()
4109{ 4135{
4110#ifndef KORG_NOPRINTER 4136#ifndef KORG_NOPRINTER
4111 createPrinter(); 4137 createPrinter();
4112 4138
4113 DateList tmpDateList = mNavigator->selectedDates(); 4139 DateList tmpDateList = mNavigator->selectedDates();
4114 mCalPrinter->print(CalPrinter::Month, 4140 mCalPrinter->print(CalPrinter::Month,
4115 tmpDateList.first(), tmpDateList.last()); 4141 tmpDateList.first(), tmpDateList.last());
4116#endif 4142#endif
4117} 4143}
4118 4144
4119void CalendarView::printPreview() 4145void CalendarView::printPreview()
4120{ 4146{
4121#ifndef KORG_NOPRINTER 4147#ifndef KORG_NOPRINTER
4122 kdDebug() << "CalendarView::printPreview()" << endl; 4148 kdDebug() << "CalendarView::printPreview()" << endl;
4123 4149
4124 createPrinter(); 4150 createPrinter();
4125 4151
4126 DateList tmpDateList = mNavigator->selectedDates(); 4152 DateList tmpDateList = mNavigator->selectedDates();
4127 4153
4128 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4154 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4129 tmpDateList.last()); 4155 tmpDateList.last());
4130#endif 4156#endif
4131} 4157}
4132 4158
4133void CalendarView::exportICalendar() 4159void CalendarView::exportICalendar()
4134{ 4160{
4135 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4161 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4136 4162
4137 // Force correct extension 4163 // Force correct extension
4138 if (filename.right(4) != ".ics") filename += ".ics"; 4164 if (filename.right(4) != ".ics") filename += ".ics";
4139 4165
4140 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4166 FileStorage storage( mCalendar, filename, new ICalFormat() );
4141 storage.save(); 4167 storage.save();
4142} 4168}
4143 4169
4144bool CalendarView::exportVCalendar( QString filename ) 4170bool CalendarView::exportVCalendar( QString filename )
4145{ 4171{
4146 if (mCalendar->journals().count() > 0) { 4172 if (mCalendar->journals().count() > 0) {
4147 int result = KMessageBox::warningContinueCancel(this, 4173 int result = KMessageBox::warningContinueCancel(this,
4148 i18n("The journal entries can not be\nexported to a vCalendar file."), 4174 i18n("The journal entries can not be\nexported to a vCalendar file."),
4149 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4175 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4150 true); 4176 true);
4151 if (result != KMessageBox::Continue) return false; 4177 if (result != KMessageBox::Continue) return false;
4152 } 4178 }
4153 4179
4154 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4180 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4155 4181
4156 // Force correct extension 4182 // Force correct extension
4157 if (filename.right(4) != ".vcs") filename += ".vcs"; 4183 if (filename.right(4) != ".vcs") filename += ".vcs";
4158 4184
4159 FileStorage storage( mCalendar, filename, new VCalFormat ); 4185 FileStorage storage( mCalendar, filename, new VCalFormat );
4160 return storage.save(); 4186 return storage.save();
4161 4187
4162} 4188}
4163 4189
4164void CalendarView::eventUpdated(Incidence *) 4190void CalendarView::eventUpdated(Incidence *)
4165{ 4191{
4166 setModified(); 4192 setModified();
4167 // Don't call updateView here. The code, which has caused the update of the 4193 // Don't call updateView here. The code, which has caused the update of the
4168 // event is responsible for updating the view. 4194 // event is responsible for updating the view.
4169 // updateView(); 4195 // updateView();
4170} 4196}
4171 4197
4172void CalendarView::adaptNavigationUnits() 4198void CalendarView::adaptNavigationUnits()
4173{ 4199{
4174 if (mViewManager->currentView()->isEventView()) { 4200 if (mViewManager->currentView()->isEventView()) {
4175 int days = mViewManager->currentView()->currentDateCount(); 4201 int days = mViewManager->currentView()->currentDateCount();
4176 if (days == 1) { 4202 if (days == 1) {
4177 emit changeNavStringPrev(i18n("&Previous Day")); 4203 emit changeNavStringPrev(i18n("&Previous Day"));
4178 emit changeNavStringNext(i18n("&Next Day")); 4204 emit changeNavStringNext(i18n("&Next Day"));
4179 } else { 4205 } else {
4180 emit changeNavStringPrev(i18n("&Previous Week")); 4206 emit changeNavStringPrev(i18n("&Previous Week"));
4181 emit changeNavStringNext(i18n("&Next Week")); 4207 emit changeNavStringNext(i18n("&Next Week"));
4182 } 4208 }
4183 } 4209 }
4184} 4210}
4185 4211
4186void CalendarView::processMainViewSelection( Incidence *incidence ) 4212void CalendarView::processMainViewSelection( Incidence *incidence )
4187{ 4213{
4188 if ( incidence ) mTodoList->clearSelection(); 4214 if ( incidence ) mTodoList->clearSelection();
4189 processIncidenceSelection( incidence ); 4215 processIncidenceSelection( incidence );
4190} 4216}
4191 4217
4192void CalendarView::processTodoListSelection( Incidence *incidence ) 4218void CalendarView::processTodoListSelection( Incidence *incidence )
4193{ 4219{
4194 if ( incidence && mViewManager->currentView() ) { 4220 if ( incidence && mViewManager->currentView() ) {
4195 mViewManager->currentView()->clearSelection(); 4221 mViewManager->currentView()->clearSelection();
4196 } 4222 }
4197 processIncidenceSelection( incidence ); 4223 processIncidenceSelection( incidence );
4198} 4224}
4199 4225
4200void CalendarView::processIncidenceSelection( Incidence *incidence ) 4226void CalendarView::processIncidenceSelection( Incidence *incidence )
4201{ 4227{
4202 emit incidenceSelected( incidence ); 4228 emit incidenceSelected( incidence );
4203 if ( incidence == mSelectedIncidence ) return; 4229 if ( incidence == mSelectedIncidence ) return;
4204 mSelectedIncidence = incidence; 4230 mSelectedIncidence = incidence;
4205 4231
4206 if ( incidence && incidence->typeID() == eventID ) { 4232 if ( incidence && incidence->typeID() == eventID ) {
4207 Event *event = static_cast<Event *>( incidence ); 4233 Event *event = static_cast<Event *>( incidence );
4208 if ( event->organizer() == KOPrefs::instance()->email() ) { 4234 if ( event->organizer() == KOPrefs::instance()->email() ) {
4209 emit organizerEventsSelected( true ); 4235 emit organizerEventsSelected( true );
4210 } else { 4236 } else {
4211 emit organizerEventsSelected(false); 4237 emit organizerEventsSelected(false);
4212 } 4238 }
4213 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4239 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4214 KOPrefs::instance()->email() ) ) { 4240 KOPrefs::instance()->email() ) ) {
4215 emit groupEventsSelected( true ); 4241 emit groupEventsSelected( true );
4216 } else { 4242 } else {
4217 emit groupEventsSelected(false); 4243 emit groupEventsSelected(false);
4218 } 4244 }
4219 return; 4245 return;
4220 } else { 4246 } else {
4221 if ( incidence && incidence->typeID() == todoID ) { 4247 if ( incidence && incidence->typeID() == todoID ) {
4222 emit todoSelected( true ); 4248 emit todoSelected( true );
4223 Todo *event = static_cast<Todo *>( incidence ); 4249 Todo *event = static_cast<Todo *>( incidence );
4224 if ( event->organizer() == KOPrefs::instance()->email() ) { 4250 if ( event->organizer() == KOPrefs::instance()->email() ) {
4225 emit organizerEventsSelected( true ); 4251 emit organizerEventsSelected( true );
4226 } else { 4252 } else {
4227 emit organizerEventsSelected(false); 4253 emit organizerEventsSelected(false);
4228 } 4254 }
4229 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 4255 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
4230 KOPrefs::instance()->email() ) ) { 4256 KOPrefs::instance()->email() ) ) {
4231 emit groupEventsSelected( true ); 4257 emit groupEventsSelected( true );
4232 } else { 4258 } else {
4233 emit groupEventsSelected(false); 4259 emit groupEventsSelected(false);
4234 } 4260 }
4235 return; 4261 return;
4236 } else { 4262 } else {
4237 emit todoSelected( false ); 4263 emit todoSelected( false );
4238 emit organizerEventsSelected(false); 4264 emit organizerEventsSelected(false);
4239 emit groupEventsSelected(false); 4265 emit groupEventsSelected(false);
4240 } 4266 }
4241 return; 4267 return;
4242 } 4268 }
4243 4269
4244 /* if ( incidence && incidence->typeID() == todoID ) { 4270 /* if ( incidence && incidence->typeID() == todoID ) {
4245 emit todoSelected( true ); 4271 emit todoSelected( true );
4246 } else { 4272 } else {
4247 emit todoSelected( false ); 4273 emit todoSelected( false );
4248 }*/ 4274 }*/
4249} 4275}
4250 4276
4251 4277
4252void CalendarView::checkClipboard() 4278void CalendarView::checkClipboard()
4253{ 4279{
4254#ifndef KORG_NODND 4280#ifndef KORG_NODND
4255 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 4281 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
4256 emit pasteEnabled(true); 4282 emit pasteEnabled(true);
4257 } else { 4283 } else {
4258 emit pasteEnabled(false); 4284 emit pasteEnabled(false);
4259 } 4285 }
4260#endif 4286#endif
4261} 4287}
4262 4288
4263void CalendarView::showDates(const DateList &selectedDates) 4289void CalendarView::showDates(const DateList &selectedDates)
4264{ 4290{
4265 // kdDebug() << "CalendarView::selectDates()" << endl; 4291 // kdDebug() << "CalendarView::selectDates()" << endl;
4266 4292
4267 4293
4268 if ( !mBlockShowDates ) { 4294 if ( !mBlockShowDates ) {
4269 if ( mViewManager->currentView() ) { 4295 if ( mViewManager->currentView() ) {
4270 updateView( selectedDates.first(), selectedDates.last() ); 4296 updateView( selectedDates.first(), selectedDates.last() );
4271 } else { 4297 } else {
4272 mViewManager->showAgendaView(); 4298 mViewManager->showAgendaView();
4273 } 4299 }
4274 } 4300 }
4275 4301
4276 QDate date = selectedDates.first(); 4302 QDate date = selectedDates.first();
4277 if ( ! date.isValid() ) { 4303 if ( ! date.isValid() ) {
4278 topLevelWidget()->setCaption(""); 4304 topLevelWidget()->setCaption("");
4279 return; 4305 return;
4280 } 4306 }
4281 4307
4282 QString selDates; 4308 QString selDates;
4283 selDates = KGlobal::locale()->formatDate( date, true); 4309 selDates = KGlobal::locale()->formatDate( date, true);
4284 if (selectedDates.first() < selectedDates.last() ) 4310 if (selectedDates.first() < selectedDates.last() )
4285 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4311 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4286 else { 4312 else {
4287 QString addString; 4313 QString addString;
4288 if ( date == QDateTime::currentDateTime().date() ) 4314 if ( date == QDateTime::currentDateTime().date() )
4289 addString = i18n("Today"); 4315 addString = i18n("Today");
4290 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4316 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4291 addString = i18n("Tomorrow"); 4317 addString = i18n("Tomorrow");
4292 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4318 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4293 addString = i18n("Yesterday"); 4319 addString = i18n("Yesterday");
4294 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4320 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4295 addString = i18n("Day before yesterday"); 4321 addString = i18n("Day before yesterday");
4296 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4322 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4297 addString = i18n("Day after tomorrow"); 4323 addString = i18n("Day after tomorrow");
4298 if ( !addString.isEmpty() ) { 4324 if ( !addString.isEmpty() ) {
4299 topLevelWidget()->setCaption( addString+", " + selDates ); 4325 topLevelWidget()->setCaption( addString+", " + selDates );
4300 return; 4326 return;
4301 } 4327 }
4302 } 4328 }
4303 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4329 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4304 4330
4305} 4331}
4306 4332
4307QPtrList<CalFilter> CalendarView::filters() 4333QPtrList<CalFilter> CalendarView::filters()
4308{ 4334{
4309 return mFilters; 4335 return mFilters;
4310 4336
4311} 4337}
4312void CalendarView::editFilters() 4338void CalendarView::editFilters()
4313{ 4339{
4314 // kdDebug() << "CalendarView::editFilters()" << endl; 4340 // kdDebug() << "CalendarView::editFilters()" << endl;
4315 4341
4316 CalFilter *filter = mFilters.first(); 4342 CalFilter *filter = mFilters.first();
4317 while(filter) { 4343 while(filter) {
4318 filter = mFilters.next(); 4344 filter = mFilters.next();
4319 } 4345 }
4320 4346
4321 mDialogManager->showFilterEditDialog(&mFilters); 4347 mDialogManager->showFilterEditDialog(&mFilters);
4322 updateFilter(); 4348 updateFilter();
4323} 4349}
4324void CalendarView::toggleFilter() 4350void CalendarView::toggleFilter()
4325{ 4351{
4326 if ( mLeftFrame->isHidden() ) { 4352 if ( mLeftFrame->isHidden() ) {
4327 toggleExpand(); 4353 toggleExpand();
4328 showFilter( true ); 4354 showFilter( true );
4329 } else 4355 } else
4330 showFilter(! mCalEditView->isVisible()); 4356 showFilter(! mCalEditView->isVisible());
4331} 4357}
4332 4358
4333KOFilterView *CalendarView::filterView() 4359KOFilterView *CalendarView::filterView()
4334{ 4360{
4335 return mFilterView; 4361 return mFilterView;
4336} 4362}
4337void CalendarView::selectFilter( int fil ) 4363void CalendarView::selectFilter( int fil )
4338{ 4364{
4339 mFilterView->setSelectedFilter( fil ); 4365 mFilterView->setSelectedFilter( fil );
4340 updateUnmanagedViews(); 4366 updateUnmanagedViews();
4341} 4367}
4342void CalendarView::showFilter(bool visible) 4368void CalendarView::showFilter(bool visible)
4343{ 4369{
4344#if 1 4370#if 1
4345 if (visible) { 4371 if (visible) {
4346 mCalEditView->readConfig(); 4372 mCalEditView->readConfig();
4347 mCalEditView->show(); 4373 mCalEditView->show();
4348 QValueList<int> sizes; 4374 QValueList<int> sizes;
4349 sizes = mLeftFrame->sizes(); 4375 sizes = mLeftFrame->sizes();
4350 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4376 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4351 sizes.clear(); 4377 sizes.clear();
4352 sizes << 100; 4378 sizes << 100;
4353 sizes << 0; 4379 sizes << 0;
4354 sizes << 0; 4380 sizes << 0;
4355 sizes << 100; 4381 sizes << 100;
4356 mLeftFrame->setSizes(sizes); 4382 mLeftFrame->setSizes(sizes);
4357 } 4383 }
4358#if 0 4384#if 0
4359 sizes = mLeftFrame->sizes(); 4385 sizes = mLeftFrame->sizes();
4360 int ccc = 0; 4386 int ccc = 0;
4361 while ( ccc < sizes.count()) { 4387 while ( ccc < sizes.count()) {
4362 qDebug("size %d %d ", ccc, sizes[ccc]); 4388 qDebug("size %d %d ", ccc, sizes[ccc]);
4363 ++ccc; 4389 ++ccc;
4364 } 4390 }
4365#endif 4391#endif
4366 4392
4367 } 4393 }
4368 else { 4394 else {
4369 mCalEditView->hide(); 4395 mCalEditView->hide();
4370 } 4396 }
4371#else 4397#else
4372 if (visible) mFilterView->show(); 4398 if (visible) mFilterView->show();
4373 else mFilterView->hide(); 4399 else mFilterView->hide();
4374#endif 4400#endif
4375} 4401}
4376void CalendarView::toggleFilerEnabled( ) 4402void CalendarView::toggleFilerEnabled( )
4377{ 4403{
4378 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4404 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4379 if ( !mFilterView->filtersEnabled() ) 4405 if ( !mFilterView->filtersEnabled() )
4380 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4406 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4381 updateUnmanagedViews(); 4407 updateUnmanagedViews();
4382 4408
4383} 4409}
4384void CalendarView::updateFilter() 4410void CalendarView::updateFilter()
4385{ 4411{
4386 CalFilter *filter = mFilterView->selectedFilter(); 4412 CalFilter *filter = mFilterView->selectedFilter();
4387 if (filter) { 4413 if (filter) {
4388 QString mess; 4414 QString mess;
4389 if (mFilterView->filtersEnabled()) { 4415 if (mFilterView->filtersEnabled()) {
4390 mess = i18n("Filter selected: ")+filter->name(); 4416 mess = i18n("Filter selected: ")+filter->name();
4391 filter->setEnabled(true); 4417 filter->setEnabled(true);
4392 } 4418 }
4393 else filter->setEnabled(false); 4419 else filter->setEnabled(false);
4394 mCalendar->setFilter(filter); 4420 mCalendar->setFilter(filter);
4395 updateView(); 4421 updateView();
4396 if ( !mess.isEmpty() ) 4422 if ( !mess.isEmpty() )
4397 topLevelWidget()->setCaption( mess ); 4423 topLevelWidget()->setCaption( mess );
4398 4424
4399 } 4425 }
4400 emit filtersUpdated(); 4426 emit filtersUpdated();
4401} 4427}
4402 4428
4403void CalendarView::filterEdited() 4429void CalendarView::filterEdited()
4404{ 4430{
4405 mFilterView->updateFilters(); 4431 mFilterView->updateFilters();
4406 updateFilter(); 4432 updateFilter();
4407 writeSettings(); 4433 writeSettings();
4408} 4434}
4409 4435
4410 4436
4411void CalendarView::takeOverEvent() 4437void CalendarView::takeOverEvent()
4412{ 4438{
4413 Incidence *incidence = currentSelection(); 4439 Incidence *incidence = currentSelection();
4414 4440
4415 if (!incidence) return; 4441 if (!incidence) return;
4416 4442
4417 incidence->setOrganizer(KOPrefs::instance()->email()); 4443 incidence->setOrganizer(KOPrefs::instance()->email());
4418 incidence->recreate(); 4444 incidence->recreate();
4419 incidence->setReadOnly(false); 4445 incidence->setReadOnly(false);
4420 4446
4421 updateView(); 4447 updateView();
4422} 4448}
4423 4449
4424void CalendarView::takeOverCalendar() 4450void CalendarView::takeOverCalendar()
4425{ 4451{
4426 // TODO: Create Calendar::allIncidences() function and use it here 4452 // TODO: Create Calendar::allIncidences() function and use it here
4427 4453
4428 clearAllViews(); 4454 clearAllViews();
4429 QPtrList<Event> events = mCalendar->events(); 4455 QPtrList<Event> events = mCalendar->events();
4430 for(uint i=0; i<events.count(); ++i) { 4456 for(uint i=0; i<events.count(); ++i) {
4431 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 4457 events.at(i)->setOrganizer(KOPrefs::instance()->email());
4432 events.at(i)->recreate(); 4458 events.at(i)->recreate();
4433 events.at(i)->setReadOnly(false); 4459 events.at(i)->setReadOnly(false);
4434 } 4460 }
4435 4461
4436 QPtrList<Todo> todos = mCalendar->todos(); 4462 QPtrList<Todo> todos = mCalendar->todos();
4437 for(uint i=0; i<todos.count(); ++i) { 4463 for(uint i=0; i<todos.count(); ++i) {
4438 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 4464 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
4439 todos.at(i)->recreate(); 4465 todos.at(i)->recreate();
4440 todos.at(i)->setReadOnly(false); 4466 todos.at(i)->setReadOnly(false);
4441 } 4467 }
4442 4468
4443 QPtrList<Journal> journals = mCalendar->journals(); 4469 QPtrList<Journal> journals = mCalendar->journals();
4444 for(uint i=0; i<journals.count(); ++i) { 4470 for(uint i=0; i<journals.count(); ++i) {
4445 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 4471 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
4446 journals.at(i)->recreate(); 4472 journals.at(i)->recreate();
4447 journals.at(i)->setReadOnly(false); 4473 journals.at(i)->setReadOnly(false);
4448 } 4474 }
4449 4475
4450 updateView(); 4476 updateView();
4451} 4477}
4452 4478
4453void CalendarView::showIntro() 4479void CalendarView::showIntro()
4454{ 4480{
4455 kdDebug() << "To be implemented." << endl; 4481 kdDebug() << "To be implemented." << endl;
4456} 4482}
4457 4483
4458QWidgetStack *CalendarView::viewStack() 4484QWidgetStack *CalendarView::viewStack()
4459{ 4485{
4460 return mRightFrame; 4486 return mRightFrame;
4461} 4487}
4462 4488
4463QWidget *CalendarView::leftFrame() 4489QWidget *CalendarView::leftFrame()
4464{ 4490{
4465 return ( QWidget *)mLeftFrame; 4491 return ( QWidget *)mLeftFrame;
4466} 4492}
4467 4493
4468DateNavigator *CalendarView::dateNavigator() 4494DateNavigator *CalendarView::dateNavigator()
4469{ 4495{
4470 return mNavigator; 4496 return mNavigator;
4471} 4497}
4472 4498
4473KDateNavigator* CalendarView::dateNavigatorWidget() 4499KDateNavigator* CalendarView::dateNavigatorWidget()
4474{ 4500{
4475 return mDateNavigator->navigatorView(); 4501 return mDateNavigator->navigatorView();
4476} 4502}
4477void CalendarView::toggleDateNavigatorWidget() 4503void CalendarView::toggleDateNavigatorWidget()
4478{ 4504{
4479 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 4505 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
4480 4506
4481 if (!KOPrefs::instance()->mShowDateNavigator ) 4507 if (!KOPrefs::instance()->mShowDateNavigator )
4482 mDateNavigator->hide(); 4508 mDateNavigator->hide();
4483 else 4509 else
4484 mDateNavigator->show(); 4510 mDateNavigator->show();
4485} 4511}
4486void CalendarView::addView(KOrg::BaseView *view) 4512void CalendarView::addView(KOrg::BaseView *view)
4487{ 4513{
4488 mViewManager->addView(view); 4514 mViewManager->addView(view);
4489} 4515}
4490 4516
4491void CalendarView::showView(KOrg::BaseView *view) 4517void CalendarView::showView(KOrg::BaseView *view)
4492{ 4518{
4493 mViewManager->showView(view, mLeftFrame->isVisible()); 4519 mViewManager->showView(view, mLeftFrame->isVisible());
4494} 4520}
4495 4521
4496Incidence *CalendarView::currentSelection() 4522Incidence *CalendarView::currentSelection()
4497{ 4523{
4498 return mViewManager->currentSelection(); 4524 return mViewManager->currentSelection();
4499} 4525}
4500void CalendarView::toggleAllDaySize() 4526void CalendarView::toggleAllDaySize()
4501{ 4527{
4502 /* 4528 /*
4503 if ( KOPrefs::instance()->mAllDaySize > 47 ) 4529 if ( KOPrefs::instance()->mAllDaySize > 47 )
4504 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 4530 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
4505 else 4531 else
4506 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 4532 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
4507 */ 4533 */
4508 viewManager()->agendaView()->toggleAllDay(); 4534 viewManager()->agendaView()->toggleAllDay();
4509} 4535}
4510void CalendarView::toggleExpand() 4536void CalendarView::toggleExpand()
4511{ 4537{
4512 // if ( mLeftFrame->isHidden() ) { 4538 // if ( mLeftFrame->isHidden() ) {
4513 // mLeftFrame->show(); 4539 // mLeftFrame->show();
4514 // emit calendarViewExpanded( false ); 4540 // emit calendarViewExpanded( false );
4515 // } else { 4541 // } else {
4516 // mLeftFrame->hide(); 4542 // mLeftFrame->hide();
4517 // emit calendarViewExpanded( true ); 4543 // emit calendarViewExpanded( true );
4518 // } 4544 // }
4519 //qDebug(" CalendarView::toggleExpand()"); 4545 //qDebug(" CalendarView::toggleExpand()");
4520 globalFlagBlockAgenda = 1; 4546 globalFlagBlockAgenda = 1;
4521 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 4547 emit calendarViewExpanded( !mLeftFrame->isHidden() );
4522 globalFlagBlockAgenda = 5; 4548 globalFlagBlockAgenda = 5;
4523 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 4549 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
4524 //mViewManager->showView( 0, true ); 4550 //mViewManager->showView( 0, true );
4525} 4551}
4526 4552
4527void CalendarView::calendarModified( bool modified, Calendar * ) 4553void CalendarView::calendarModified( bool modified, Calendar * )
4528{ 4554{
4529 setModified( modified ); 4555 setModified( modified );
4530} 4556}
4531 4557
4532Todo *CalendarView::selectedTodo() 4558Todo *CalendarView::selectedTodo()
4533{ 4559{
4534 Incidence *incidence = currentSelection(); 4560 Incidence *incidence = currentSelection();
4535 if ( incidence && incidence->typeID() == todoID ) { 4561 if ( incidence && incidence->typeID() == todoID ) {
4536 return static_cast<Todo *>( incidence ); 4562 return static_cast<Todo *>( incidence );
4537 } 4563 }
4538 4564
4539 incidence = mTodoList->selectedIncidences().first(); 4565 incidence = mTodoList->selectedIncidences().first();
4540 if ( incidence && incidence->typeID() == todoID ) { 4566 if ( incidence && incidence->typeID() == todoID ) {
4541 return static_cast<Todo *>( incidence ); 4567 return static_cast<Todo *>( incidence );
4542 } 4568 }
4543 4569
4544 return 0; 4570 return 0;
4545} 4571}
4546 4572
4547void CalendarView::showIncidence() 4573void CalendarView::showIncidence()
4548{ 4574{
4549 mViewerCallerIsSearchDialog = false; 4575 mViewerCallerIsSearchDialog = false;
4550 Incidence *incidence = currentSelection(); 4576 Incidence *incidence = currentSelection();
4551 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4577 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4552 if ( incidence ) { 4578 if ( incidence ) {
4553 ShowIncidenceVisitor v; 4579 ShowIncidenceVisitor v;
4554 v.act( incidence, this ); 4580 v.act( incidence, this );
4555 } 4581 }
4556} 4582}
4557void CalendarView::editIncidenceDescription() 4583void CalendarView::editIncidenceDescription()
4558{ 4584{
4559 mFlagEditDescription = true; 4585 mFlagEditDescription = true;
4560 editIncidence(); 4586 editIncidence();
4561 mFlagEditDescription = false; 4587 mFlagEditDescription = false;
4562} 4588}
4563void CalendarView::editIncidence() 4589void CalendarView::editIncidence()
4564{ 4590{
4565 // qDebug("editIncidence() "); 4591 // qDebug("editIncidence() ");
4566 Incidence *incidence = currentSelection(); 4592 Incidence *incidence = currentSelection();
4567 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4593 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4568 if ( incidence ) { 4594 if ( incidence ) {
4569 EditIncidenceVisitor v; 4595 EditIncidenceVisitor v;
4570 v.act( incidence, this ); 4596 v.act( incidence, this );
4571 } 4597 }
4572} 4598}
4573 4599
4574void CalendarView::deleteIncidence() 4600void CalendarView::deleteIncidence()
4575{ 4601{
4576 Incidence *incidence = currentSelection(); 4602 Incidence *incidence = currentSelection();
4577 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 4603 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
4578 if ( incidence ) { 4604 if ( incidence ) {
4579 deleteIncidence(incidence); 4605 deleteIncidence(incidence);
4580 } 4606 }
4581} 4607}
4582void CalendarView::showIncidence(QString uid) 4608void CalendarView::showIncidence(QString uid)
4583{ 4609{
4584 Incidence *inc = mCalendar->incidence( uid ); 4610 Incidence *inc = mCalendar->incidence( uid );
4585 if ( inc ) 4611 if ( inc )
4586 showIncidence( inc ); 4612 showIncidence( inc );
4587} 4613}
4588void CalendarView::showIncidence(Incidence *incidence) 4614void CalendarView::showIncidence(Incidence *incidence)
4589{ 4615{
4590 mViewerCallerIsSearchDialog = false; 4616 mViewerCallerIsSearchDialog = false;
4591 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 4617 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
4592 if ( sender() && mDialogManager->getSearchDialog() ) { 4618 if ( sender() && mDialogManager->getSearchDialog() ) {
4593 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 4619 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
4594 mViewerCallerIsSearchDialog = true; 4620 mViewerCallerIsSearchDialog = true;
4595 } 4621 }
4596 } 4622 }
4597 if ( incidence ) { 4623 if ( incidence ) {
4598 ShowIncidenceVisitor v; 4624 ShowIncidenceVisitor v;
4599 v.act( incidence, this ); 4625 v.act( incidence, this );
4600 } 4626 }
4601} 4627}
4602 4628
4603void CalendarView::editIncidence(Incidence *incidence) 4629void CalendarView::editIncidence(Incidence *incidence)
4604{ 4630{
4605 if ( incidence ) { 4631 if ( incidence ) {
4606 4632
4607 EditIncidenceVisitor v; 4633 EditIncidenceVisitor v;
4608 v.act( incidence, this ); 4634 v.act( incidence, this );
4609 4635
4610 } 4636 }
4611} 4637}
4612 4638
4613void CalendarView::deleteIncidence(Incidence *incidence) 4639void CalendarView::deleteIncidence(Incidence *incidence)
4614{ 4640{
4615 //qDebug(" CalendarView::deleteIncidence "); 4641 //qDebug(" CalendarView::deleteIncidence ");
4616 if ( incidence == 0 ) { 4642 if ( incidence == 0 ) {
4617 updateView(); 4643 updateView();
4618 emit updateSearchDialog(); 4644 emit updateSearchDialog();
4619 return; 4645 return;
4620 } 4646 }
4621 if ( incidence ) { 4647 if ( incidence ) {
4622 DeleteIncidenceVisitor v; 4648 DeleteIncidenceVisitor v;
4623 v.act( incidence, this ); 4649 v.act( incidence, this );
4624 } 4650 }
4625} 4651}
4626 4652
4627 4653
4628void CalendarView::lookForOutgoingMessages() 4654void CalendarView::lookForOutgoingMessages()
4629{ 4655{
4630 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 4656 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
4631 ogd->loadMessages(); 4657 ogd->loadMessages();
4632} 4658}
4633 4659
4634void CalendarView::lookForIncomingMessages() 4660void CalendarView::lookForIncomingMessages()
4635{ 4661{
4636 IncomingDialog *icd = mDialogManager->incomingDialog(); 4662 IncomingDialog *icd = mDialogManager->incomingDialog();
4637 icd->retrieve(); 4663 icd->retrieve();
4638} 4664}
4639 4665
4640bool CalendarView::removeCompletedSubTodos( Todo* t ) 4666bool CalendarView::removeCompletedSubTodos( Todo* t )
4641{ 4667{
4642 bool deleteTodo = true; 4668 bool deleteTodo = true;
4643 QPtrList<Incidence> subTodos; 4669 QPtrList<Incidence> subTodos;
4644 Incidence *aTodo; 4670 Incidence *aTodo;
4645 subTodos = t->relations(); 4671 subTodos = t->relations();
4646 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 4672 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
4647 if (! removeCompletedSubTodos( (Todo*) aTodo )) 4673 if (! removeCompletedSubTodos( (Todo*) aTodo ))
4648 deleteTodo = false; 4674 deleteTodo = false;
4649 } 4675 }
4650 if ( deleteTodo ) { 4676 if ( deleteTodo ) {
4651 if ( t->isCompleted() && !t->doesRecur()) { 4677 if ( t->isCompleted() && !t->doesRecur()) {
4652 checkExternalId( t ); 4678 checkExternalId( t );
4653 mCalendar->deleteTodo( t ); 4679 mCalendar->deleteTodo( t );
4654 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 4680 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
4655 } 4681 }
4656 else 4682 else
4657 deleteTodo = false; 4683 deleteTodo = false;
4658 } 4684 }
4659 return deleteTodo; 4685 return deleteTodo;
4660 4686
4661} 4687}
4662void CalendarView::purgeCompleted() 4688void CalendarView::purgeCompleted()
4663{ 4689{
4664 int result = KMessageBox::warningContinueCancel(this, 4690 int result = KMessageBox::warningContinueCancel(this,
4665 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge")); 4691 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
4666 4692
4667 if (result == KMessageBox::Continue) { 4693 if (result == KMessageBox::Continue) {
4668 4694
4669 QPtrList<Todo> todoCal; 4695 QPtrList<Todo> todoCal;
4670 QPtrList<Todo> rootTodos; 4696 QPtrList<Todo> rootTodos;
4671 //QPtrList<Incidence> rel; 4697 //QPtrList<Incidence> rel;
4672 Todo *aTodo; 4698 Todo *aTodo;
4673 todoCal = calendar()->todos(); 4699 todoCal = calendar()->todos();
4674 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4700 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4675 if ( !aTodo->relatedTo() ) 4701 if ( !aTodo->relatedTo() )
4676 rootTodos.append( aTodo ); 4702 rootTodos.append( aTodo );
4677 } 4703 }
4678 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4704 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4679 removeCompletedSubTodos( aTodo ); 4705 removeCompletedSubTodos( aTodo );
4680 } 4706 }
4681 4707
4682 updateView(); 4708 updateView();
4683 } 4709 }
4684} 4710}
4685 4711
4686void CalendarView::slotCalendarChanged() 4712void CalendarView::slotCalendarChanged()
4687{ 4713{
4688 ; 4714 ;
4689} 4715}
4690 4716
4691void CalendarView::keyPressEvent ( QKeyEvent *e) 4717void CalendarView::keyPressEvent ( QKeyEvent *e)
4692{ 4718{
4693 //qDebug("CalendarView::keyPressEvent "); 4719 //qDebug("CalendarView::keyPressEvent ");
4694 e->ignore(); 4720 e->ignore();
4695} 4721}
4696 4722
4697 4723
4698bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4724bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4699{ 4725{
4700 4726
4701 if ( manager != mSyncManager) 4727 if ( manager != mSyncManager)
4702 qDebug("KO: Internal error-1. SyncManager mismatch "); 4728 qDebug("KO: Internal error-1. SyncManager mismatch ");
4703 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4729 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4704 qDebug("KO: SyncKDE request detected!"); 4730 qDebug("KO: SyncKDE request detected!");
4705 } 4731 }
4706 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4732 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4707 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4733 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4708 return syncCalendar( filename, mode ); 4734 return syncCalendar( filename, mode );
4709} 4735}
4710bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4736bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4711{ 4737{
4712 //mSyncManager = manager; 4738 //mSyncManager = manager;
4713 if ( manager != mSyncManager) 4739 if ( manager != mSyncManager)
4714 qDebug("KO: Internal error-2. SyncManager mismatch "); 4740 qDebug("KO: Internal error-2. SyncManager mismatch ");
4715 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4741 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4716 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4742 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4717 if ( resource == "sharp" ) 4743 if ( resource == "sharp" )
4718 syncExternal( 0 ); 4744 syncExternal( 0 );
4719 if ( resource == "phone" ) 4745 if ( resource == "phone" )
4720 syncExternal( 1 ); 4746 syncExternal( 1 );
4721 // pending setmodified 4747 // pending setmodified
4722 return true; 4748 return true;
4723} 4749}
4724void CalendarView::setSyncManager(KSyncManager* manager) 4750void CalendarView::setSyncManager(KSyncManager* manager)
4725{ 4751{
4726 mSyncManager = manager; 4752 mSyncManager = manager;
4727} 4753}
4728 4754
4729void CalendarView::removeSyncInfo( QString syncProfile) 4755void CalendarView::removeSyncInfo( QString syncProfile)
4730{ 4756{
4731 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4757 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4732 mCalendar->removeSyncInfo( syncProfile ); 4758 mCalendar->removeSyncInfo( syncProfile );
4733 4759
4734} 4760}
4735 4761
4736void CalendarView::undo_delete() 4762void CalendarView::undo_delete()
4737{ 4763{
4738 //qDebug("undo_delete() "); 4764 //qDebug("undo_delete() ");
4739 Incidence* undo = mCalendar->undoIncidence(); 4765 Incidence* undo = mCalendar->undoIncidence();
4740 if ( !undo ) { 4766 if ( !undo ) {
4741 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4767 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4742 i18n("KO/Pi")); 4768 i18n("KO/Pi"));
4743 return; 4769 return;
4744 } 4770 }
4745 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) + 4771 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( undo->summary(),0 ) +
4746 i18n("\nAre you sure you want\nto restore this?"), 4772 i18n("\nAre you sure you want\nto restore this?"),
4747 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4773 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4748 mCalendar->undoDeleteIncidence(); 4774 mCalendar->undoDeleteIncidence();
4749 updateView(); 4775 updateView();
4750 } 4776 }
4751} 4777}
4752 4778
4753void CalendarView::slotViewerClosed() 4779void CalendarView::slotViewerClosed()
4754{ 4780{
4755 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4781 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4756} 4782}
4757 4783
4758void CalendarView::resetFocus() 4784void CalendarView::resetFocus()
4759{ 4785{
4760 if ( mViewerCallerIsSearchDialog ) { 4786 if ( mViewerCallerIsSearchDialog ) {
4761 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4787 if ( mDialogManager->getSearchDialog()->isVisible() ){
4762 mDialogManager->getSearchDialog()->raise(); 4788 mDialogManager->getSearchDialog()->raise();
4763 mDialogManager->getSearchDialog()->setActiveWindow(); 4789 mDialogManager->getSearchDialog()->setActiveWindow();
4764 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4790 mDialogManager->getSearchDialog()->listview()->resetFocus();
4765 } else 4791 } else
4766 mViewerCallerIsSearchDialog = false; 4792 mViewerCallerIsSearchDialog = false;
4767 } 4793 }
4768 if ( !mViewerCallerIsSearchDialog ) { 4794 if ( !mViewerCallerIsSearchDialog ) {
4769 //mViewManager->currentView()->setFocus(); 4795 //mViewManager->currentView()->setFocus();
4770 //qDebug("sssssssssssssssset focus "); 4796 //qDebug("sssssssssssssssset focus ");
4771 topLevelWidget()->raise(); 4797 topLevelWidget()->raise();
4772 setActiveWindow(); 4798 setActiveWindow();
4773 //setFocus(); 4799 //setFocus();
4774 } 4800 }
4775 mViewerCallerIsSearchDialog = false; 4801 mViewerCallerIsSearchDialog = false;
4776} 4802}
4777 4803
4778void CalendarView::showNextAlarms() 4804void CalendarView::showNextAlarms()
4779{ 4805{
4780 QString message; 4806 QString message;
4781 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4807 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4782 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4808 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4783 QString sum = mCalendar->nextSummary(); 4809 QString sum = mCalendar->nextSummary();
4784 QDateTime nextA = mNextAlarmDateTime; 4810 QDateTime nextA = mNextAlarmDateTime;
4785 QDateTime cur = QDateTime::currentDateTime(); 4811 QDateTime cur = QDateTime::currentDateTime();
4786 int secs = cur.secsTo( nextA ); 4812 int secs = cur.secsTo( nextA );
4787 int min = secs /60; 4813 int min = secs /60;
4788 int hours = min /60; 4814 int hours = min /60;
4789 min = min % 60; 4815 min = min % 60;
4790 int days = hours /24; 4816 int days = hours /24;
4791 hours = hours % 24; 4817 hours = hours % 24;
4792 4818
4793 //message = i18n("The next alarm is in:\n"); 4819 //message = i18n("The next alarm is in:\n");
4794 if ( days > 1 ) 4820 if ( days > 1 )
4795 message += i18n("%1 days\n").arg( days ); 4821 message += i18n("%1 days\n").arg( days );
4796 else if ( days == 1 ) 4822 else if ( days == 1 )
4797 message += i18n("1 day\n"); 4823 message += i18n("1 day\n");
4798 if ( hours > 1 ) 4824 if ( hours > 1 )
4799 message += i18n("%1 hours\n").arg( hours ); 4825 message += i18n("%1 hours\n").arg( hours );
4800 else if ( hours == 1 ) 4826 else if ( hours == 1 )
4801 message += i18n("1 hour\n"); 4827 message += i18n("1 hour\n");
4802 if ( min > 1 ) 4828 if ( min > 1 )
4803 message += i18n("%1 minutes\n").arg( min ); 4829 message += i18n("%1 minutes\n").arg( min );
4804 else if ( min == 1 ) 4830 else if ( min == 1 )
4805 message += i18n("1 minute\n"); 4831 message += i18n("1 minute\n");
4806 if ( message.isEmpty() ) 4832 if ( message.isEmpty() )
4807 message = i18n("The next alarm is in\nless than one minute!"); 4833 message = i18n("The next alarm is in\nless than one minute!");
4808 else 4834 else
4809 message = i18n("The next alarm is in:\n") + message; 4835 message = i18n("The next alarm is in:\n") + message;
4810 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4836 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4811 } else { 4837 } else {
4812 message = i18n("There is no next alarm."); 4838 message = i18n("There is no next alarm.");
4813 4839
4814 } 4840 }
4815#ifdef DESKTOP_VERSION 4841#ifdef DESKTOP_VERSION
4816 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4842 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4817 message += i18n("\nThe internal alarm notification is disabled!\n"); 4843 message += i18n("\nThe internal alarm notification is disabled!\n");
4818 message += i18n("Enable it in the settings menu, TAB alarm."); 4844 message += i18n("Enable it in the settings menu, TAB alarm.");
4819 } 4845 }
4820 4846
4821#endif 4847#endif
4822 KMessageBox::information( this, message); 4848 KMessageBox::information( this, message);
4823} 4849}
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 5285559..ad66639 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,395 +1,415 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 unsigned int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 return dtStart(); 123 return dtStart();
124} 124}
125 125
126QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
127{ 127{
128 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
129} 129}
130 130
131QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
132{ 132{
133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
134} 134}
135 135
136QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
137{ 137{
138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
139} 139}
140 140
141void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
142{ 142{
143 mHasEndDate = b; 143 mHasEndDate = b;
144} 144}
145 145
146bool Event::hasEndDate() const 146bool Event::hasEndDate() const
147{ 147{
148 return mHasEndDate; 148 return mHasEndDate;
149} 149}
150 150
151bool Event::isMultiDay() const 151bool Event::isMultiDay() const
152{ 152{
153 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
154 return multi; 154 return multi;
155} 155}
156 156
157void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
158{ 158{
159 if (mReadOnly) return; 159 if (mReadOnly) return;
160 mTransparency = transparency; 160 mTransparency = transparency;
161 updated(); 161 updated();
162} 162}
163 163
164Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
165{ 165{
166 return mTransparency; 166 return mTransparency;
167} 167}
168 168
169void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
170{ 170{
171 setHasEndDate(false); 171 setHasEndDate(false);
172 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
173} 173}
174bool Event::matchTime(QDateTime*startDT, QDateTime* endDT)
175{
176 if ( ! doesRecur() ) {
177 if ( doesFloat() ) {
178 if ( mDtEnd.addDays( 1 ) < *startDT)
179 return false;
180 if ( endDT && mDtStart > * endDT)
181 return false;
182 } else {
183 if ( mDtEnd < *startDT )
184 return false;
185 if ( endDT && mDtStart > * endDT)
186 return false;
187 }
188 } else {
189 if ( endDT && mDtStart > * endDT)
190 return false;
191 }
192 return true;
193}
174bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) 194bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT )
175{ 195{
176 if ( testEvent == this ) 196 if ( testEvent == this )
177 return false; 197 return false;
178 if ( ! doesRecur() && !testEvent->doesRecur() ) { 198 if ( ! doesRecur() && !testEvent->doesRecur() ) {
179 QDateTime te; 199 QDateTime te;
180 if ( testEvent->doesFloat() ) 200 if ( testEvent->doesFloat() )
181 te = testEvent->mDtEnd.addDays( 1 ); 201 te = testEvent->mDtEnd.addDays( 1 );
182 else 202 else
183 te = testEvent->mDtEnd; 203 te = testEvent->mDtEnd;
184 QDateTime e; 204 QDateTime e;
185 if ( doesFloat() ) 205 if ( doesFloat() )
186 e = mDtEnd.addDays( 1 ); 206 e = mDtEnd.addDays( 1 );
187 else 207 else
188 e = mDtEnd; 208 e = mDtEnd;
189 if ( mDtStart < te && testEvent->mDtStart < e ) { 209 if ( mDtStart < te && testEvent->mDtStart < e ) {
190 if ( mDtStart < testEvent->mDtStart ) 210 if ( mDtStart < testEvent->mDtStart )
191 *overlapDT = testEvent->mDtStart; 211 *overlapDT = testEvent->mDtStart;
192 else 212 else
193 *overlapDT = mDtStart; 213 *overlapDT = mDtStart;
194 if ( startDT ) 214 if ( startDT )
195 return (*overlapDT >= *startDT ); 215 return (*overlapDT >= *startDT );
196 return true; 216 return true;
197 } 217 }
198 return false; 218 return false;
199 } 219 }
200 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 220 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
201 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { 221 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) {
202 // no need to test. times mismatch 222 // no need to test. times mismatch
203 //fprintf(stderr,"timi "); 223 //fprintf(stderr,"timi ");
204 return false; 224 return false;
205 } 225 }
206 } 226 }
207 Event *nonRecur = 0; 227 Event *nonRecur = 0;
208 Event *recurEvent = 0; 228 Event *recurEvent = 0;
209 if ( ! doesRecur() ) { 229 if ( ! doesRecur() ) {
210 nonRecur = this; 230 nonRecur = this;
211 recurEvent = testEvent; 231 recurEvent = testEvent;
212 } 232 }
213 else if ( !testEvent->doesRecur() ) { 233 else if ( !testEvent->doesRecur() ) {
214 nonRecur = testEvent; 234 nonRecur = testEvent;
215 recurEvent = this; 235 recurEvent = this;
216 } 236 }
217 if ( nonRecur ) { 237 if ( nonRecur ) {
218 QDateTime enr; 238 QDateTime enr;
219 if ( nonRecur->doesFloat() ) 239 if ( nonRecur->doesFloat() )
220 enr = nonRecur->mDtEnd.addDays( 1 ); 240 enr = nonRecur->mDtEnd.addDays( 1 );
221 else 241 else
222 enr = nonRecur->mDtEnd; 242 enr = nonRecur->mDtEnd;
223 if ( enr < recurEvent->mDtStart ) 243 if ( enr < recurEvent->mDtStart )
224 return false; 244 return false;
225 if ( startDT && enr < *startDT ) 245 if ( startDT && enr < *startDT )
226 return false; 246 return false;
227 247
228 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); 248 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
229 if ( recurEvent->doesFloat() ) 249 if ( recurEvent->doesFloat() )
230 recDuration += 86400; 250 recDuration += 86400;
231 bool ok = false; 251 bool ok = false;
232 QDateTime recStart; 252 QDateTime recStart;
233 if ( startDT ) { 253 if ( startDT ) {
234 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 254 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
235 } 255 }
236 if ( recStart.isValid() ) { 256 if ( recStart.isValid() ) {
237 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); 257 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1());
238 recStart = recStart.addSecs( -300); 258 recStart = recStart.addSecs( -300);
239 } 259 }
240 else 260 else
241 recStart = recurEvent->mDtStart.addSecs( -300); 261 recStart = recurEvent->mDtStart.addSecs( -300);
242 ok = true; 262 ok = true;
243 263
244 while ( ok ) { 264 while ( ok ) {
245 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); 265 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
246 if ( ok ) { 266 if ( ok ) {
247 if ( recStart > enr ) 267 if ( recStart > enr )
248 return false; 268 return false;
249 QDateTime recEnd = recStart.addSecs( recDuration ); 269 QDateTime recEnd = recStart.addSecs( recDuration );
250 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { 270 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
251 if ( nonRecur->mDtStart < recStart ) 271 if ( nonRecur->mDtStart < recStart )
252 *overlapDT = recStart; 272 *overlapDT = recStart;
253 else 273 else
254 *overlapDT = nonRecur->mDtStart; 274 *overlapDT = nonRecur->mDtStart;
255 if ( startDT ) { 275 if ( startDT ) {
256 if ( *overlapDT >= *startDT ) 276 if ( *overlapDT >= *startDT )
257 return true; 277 return true;
258 } else 278 } else
259 return true; 279 return true;
260 } 280 }
261 } 281 }
262 } 282 }
263 return false; 283 return false;
264 } 284 }
265 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 285 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
266 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { 286 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) {
267 bool found = false; 287 bool found = false;
268 uint i; 288 uint i;
269 for ( i=0; i< recurrence()->days().size();++i ) { 289 for ( i=0; i< recurrence()->days().size();++i ) {
270 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); 290 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) );
271 } 291 }
272 if ( ! found ) { 292 if ( ! found ) {
273 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); 293 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1());
274 return false; 294 return false;
275 } 295 }
276 296
277 } 297 }
278 } 298 }
279 bool ok = true; 299 bool ok = true;
280 QDateTime incidenceStart;// = mDtStart; 300 QDateTime incidenceStart;// = mDtStart;
281 QDateTime testincidenceStart;// = testEvent->mDtStart; 301 QDateTime testincidenceStart;// = testEvent->mDtStart;
282 if ( startDT ) { 302 if ( startDT ) {
283 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 303 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
284 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 304 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
285 } 305 }
286 if ( !testincidenceStart.isValid() ) 306 if ( !testincidenceStart.isValid() )
287 testincidenceStart = testEvent->mDtStart; 307 testincidenceStart = testEvent->mDtStart;
288 if ( !incidenceStart.isValid() ) 308 if ( !incidenceStart.isValid() )
289 incidenceStart = mDtStart; 309 incidenceStart = mDtStart;
290 int duration = mDtStart.secsTo( mDtEnd ); 310 int duration = mDtStart.secsTo( mDtEnd );
291 if ( doesFloat() ) 311 if ( doesFloat() )
292 duration += 86400; 312 duration += 86400;
293 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); 313 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd );
294 if ( testEvent->doesFloat() ) 314 if ( testEvent->doesFloat() )
295 testduration += 86400; 315 testduration += 86400;
296 bool computeThis = false; 316 bool computeThis = false;
297 if ( incidenceStart < testincidenceStart ) 317 if ( incidenceStart < testincidenceStart )
298 computeThis = true; 318 computeThis = true;
299 if ( computeThis ) 319 if ( computeThis )
300 incidenceStart = incidenceStart.addSecs( -300 ); 320 incidenceStart = incidenceStart.addSecs( -300 );
301 else 321 else
302 testincidenceStart = testincidenceStart.addSecs( -300 ); 322 testincidenceStart = testincidenceStart.addSecs( -300 );
303 int count = 0; 323 int count = 0;
304 ok = true; 324 ok = true;
305 int countbreak = 2000; 325 int countbreak = 2000;
306 QDateTime stopSearch; 326 QDateTime stopSearch;
307 bool testStop = false; 327 bool testStop = false;
308 if ( startDT ) { 328 if ( startDT ) {
309 stopSearch = startDT->addDays( 365*3 ); 329 stopSearch = startDT->addDays( 365*3 );
310 testStop = true; 330 testStop = true;
311 } 331 }
312 while ( ok ) { 332 while ( ok ) {
313 ++count; 333 ++count;
314 if ( count > countbreak ) break; 334 if ( count > countbreak ) break;
315 if ( computeThis ) { 335 if ( computeThis ) {
316 if ( testStop ) 336 if ( testStop )
317 if ( testincidenceStart > stopSearch ) 337 if ( testincidenceStart > stopSearch )
318 break; 338 break;
319 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); 339 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok );
320 } 340 }
321 else { 341 else {
322 if ( testStop ) 342 if ( testStop )
323 if ( incidenceStart > stopSearch ) 343 if ( incidenceStart > stopSearch )
324 break; 344 break;
325 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); 345 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok );
326 } 346 }
327 if ( ok ) { 347 if ( ok ) {
328 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { 348 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) {
329 if ( incidenceStart < testincidenceStart ) 349 if ( incidenceStart < testincidenceStart )
330 *overlapDT = testincidenceStart; 350 *overlapDT = testincidenceStart;
331 else 351 else
332 *overlapDT = incidenceStart; 352 *overlapDT = incidenceStart;
333 if ( startDT ) { 353 if ( startDT ) {
334 if ( *overlapDT >= *startDT ) 354 if ( *overlapDT >= *startDT )
335 return true; 355 return true;
336 } else 356 } else
337 return true; 357 return true;
338 } 358 }
339 computeThis = ( incidenceStart < testincidenceStart ); 359 computeThis = ( incidenceStart < testincidenceStart );
340 } 360 }
341 361
342 } 362 }
343 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); 363 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() );
344 return false; 364 return false;
345} 365}
346QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 366QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
347{ 367{
348 *ok = false; 368 *ok = false;
349 if ( !alarmEnabled() ) 369 if ( !alarmEnabled() )
350 return QDateTime (); 370 return QDateTime ();
351 bool yes; 371 bool yes;
352 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 372 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
353 if ( ! yes || cancelled() ) { 373 if ( ! yes || cancelled() ) {
354 *ok = false; 374 *ok = false;
355 return QDateTime (); 375 return QDateTime ();
356 } 376 }
357 377
358 bool enabled = false; 378 bool enabled = false;
359 Alarm* alarm; 379 Alarm* alarm;
360 int off = 0; 380 int off = 0;
361 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 381 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
362 // if ( QDateTime::currentDateTime() > incidenceStart ){ 382 // if ( QDateTime::currentDateTime() > incidenceStart ){
363// *ok = false; 383// *ok = false;
364// return incidenceStart; 384// return incidenceStart;
365// } 385// }
366 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 386 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
367 if (alarm->enabled()) { 387 if (alarm->enabled()) {
368 if ( alarm->hasTime () ) { 388 if ( alarm->hasTime () ) {
369 if ( alarm->time() < alarmStart ) { 389 if ( alarm->time() < alarmStart ) {
370 alarmStart = alarm->time(); 390 alarmStart = alarm->time();
371 enabled = true; 391 enabled = true;
372 off = alarmStart.secsTo( incidenceStart ); 392 off = alarmStart.secsTo( incidenceStart );
373 } 393 }
374 394
375 } else { 395 } else {
376 int secs = alarm->startOffset().asSeconds(); 396 int secs = alarm->startOffset().asSeconds();
377 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 397 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
378 alarmStart = incidenceStart.addSecs( secs ); 398 alarmStart = incidenceStart.addSecs( secs );
379 enabled = true; 399 enabled = true;
380 off = -secs; 400 off = -secs;
381 } 401 }
382 } 402 }
383 } 403 }
384 } 404 }
385 if ( enabled ) { 405 if ( enabled ) {
386 if ( alarmStart > start_dt ) { 406 if ( alarmStart > start_dt ) {
387 *ok = true; 407 *ok = true;
388 * offset = off; 408 * offset = off;
389 return alarmStart; 409 return alarmStart;
390 } 410 }
391 } 411 }
392 *ok = false; 412 *ok = false;
393 return QDateTime (); 413 return QDateTime ();
394 414
395} 415}
diff --git a/libkcal/event.h b/libkcal/event.h
index e6055a5..2da9770 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,93 +1,94 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef EVENT_H 21#ifndef EVENT_H
22#define EVENT_H 22#define EVENT_H
23// 23//
24// Event component, representing a VEVENT object 24// Event component, representing a VEVENT object
25// 25//
26 26
27#include "incidence.h" 27#include "incidence.h"
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides an Event in the sense of RFC2445. 31 This class provides an Event in the sense of RFC2445.
32*/ 32*/
33class Event : public Incidence 33class Event : public Incidence
34{ 34{
35 public: 35 public:
36 enum Transparency { Opaque, Transparent }; 36 enum Transparency { Opaque, Transparent };
37 typedef ListBase<Event> List; 37 typedef ListBase<Event> List;
38 Event(); 38 Event();
39 Event(const Event &); 39 Event(const Event &);
40 ~Event(); 40 ~Event();
41 bool matchTime(QDateTime*startDT, QDateTime* endDT);
41 42
42 QCString type() const { return "Event"; } 43 QCString type() const { return "Event"; }
43 IncTypeID typeID() const { return eventID; } 44 IncTypeID typeID() const { return eventID; }
44 45
45 Incidence *clone(); 46 Incidence *clone();
46 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; 47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
47 48
48 /** for setting an event's ending date/time with a QDateTime. */ 49 /** for setting an event's ending date/time with a QDateTime. */
49 void setDtEnd(const QDateTime &dtEnd); 50 void setDtEnd(const QDateTime &dtEnd);
50 /** Return the event's ending date/time as a QDateTime. */ 51 /** Return the event's ending date/time as a QDateTime. */
51 virtual QDateTime dtEnd() const; 52 virtual QDateTime dtEnd() const;
52 /** returns an event's end time as a string formatted according to the 53 /** returns an event's end time as a string formatted according to the
53 users locale settings */ 54 users locale settings */
54 QString dtEndTimeStr() const; 55 QString dtEndTimeStr() const;
55 /** returns an event's end date as a string formatted according to the 56 /** returns an event's end date as a string formatted according to the
56 users locale settings */ 57 users locale settings */
57 QString dtEndDateStr(bool shortfmt=true) const; 58 QString dtEndDateStr(bool shortfmt=true) const;
58 /** returns an event's end date and time as a string formatted according 59 /** returns an event's end date and time as a string formatted according
59 to the users locale settings */ 60 to the users locale settings */
60 QString dtEndStr(bool shortfmt=true) const; 61 QString dtEndStr(bool shortfmt=true) const;
61 void setHasEndDate(bool); 62 void setHasEndDate(bool);
62 /** Return whether the event has an end date/time. */ 63 /** Return whether the event has an end date/time. */
63 bool hasEndDate() const; 64 bool hasEndDate() const;
64 65
65 /** Return true if the event spans multiple days, otherwise return false. */ 66 /** Return true if the event spans multiple days, otherwise return false. */
66 bool isMultiDay() const; 67 bool isMultiDay() const;
67 68
68 /** set the event's time transparency level. */ 69 /** set the event's time transparency level. */
69 void setTransparency(Transparency transparency); 70 void setTransparency(Transparency transparency);
70 /** get the event's time transparency level. */ 71 /** get the event's time transparency level. */
71 Transparency transparency() const; 72 Transparency transparency() const;
72 73
73 void setDuration(int seconds); 74 void setDuration(int seconds);
74 75
75 bool contains ( Event*); 76 bool contains ( Event*);
76 77
77 bool isOverlapping ( Event*, QDateTime*, QDateTime* ); 78 bool isOverlapping ( Event*, QDateTime*, QDateTime* );
78 79
79 private: 80 private:
80 bool accept(Visitor &v) { return v.visit(this); } 81 bool accept(Visitor &v) { return v.visit(this); }
81 82
82 QDateTime mDtEnd; 83 QDateTime mDtEnd;
83 bool mHasEndDate; 84 bool mHasEndDate;
84 Transparency mTransparency; 85 Transparency mTransparency;
85}; 86};
86 87
87bool operator==( const Event&, const Event& ); 88bool operator==( const Event&, const Event& );
88 89
89 90
90} 91}
91 92
92 93
93#endif 94#endif