summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-12-04 04:53:22 (UTC)
committer zautrix <zautrix>2004-12-04 04:53:22 (UTC)
commit7828f46413766ee5db72dc9bd457eac0868f0646 (patch) (unidiff)
treed3da09120bdef2b498f836c5b1b97a5b2aa2da99
parent967f7c879d06961dd7a25d019380c521f7a84792 (diff)
downloadkdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.zip
kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.gz
kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.bz2
fixed some bugs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--bin/kdepim/WhatsNew.txt22
-rw-r--r--kmicromail/libetpan/maildir/maildir.c25
-rw-r--r--kmicromail/libetpan/mh/mailmh.c12
-rw-r--r--korganizer/calendarview.cpp4
-rw-r--r--korganizer/kotodoview.cpp1
-rw-r--r--korganizer/kotodoviewitem.cpp2
-rw-r--r--libkcal/sharpformat.cpp7
-rw-r--r--version2
8 files changed, 60 insertions, 15 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt
index 4905631..eb7cf13 100644
--- a/bin/kdepim/WhatsNew.txt
+++ b/bin/kdepim/WhatsNew.txt
@@ -1,589 +1,611 @@
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 1.9.14 ************
4
5Fixed some problems with the dialog sizes when switching
6portrait/landscape mode on 640x480 PDA display.
7
8Fixed some other small bugs.
9
10Fixed an ugly bug in KOpieMail:
11KOpieMail was not able to write files (mails) to MSDOS file system,
12like on an usual preformatted SD card. That should work now.
13To save your mail data on the Sd card do the following:
14Create a dir on the SD card:
15mkdir /mnt/card/localmail
16Go to your home dir:
17cd
18Go to kopiemail data storage dir:
19cd kdepim/apps/kopiemail
20Create a symlink to the SD card:
21ls -s /mnt/card/localmail
22Now KOpieMail will store all mails on the SD card.
23
24
3********** VERSION 1.9.13 ************ 25********** VERSION 1.9.13 ************
4 26
5Fixed nasty PwM/Pi file reading bug, when 27Fixed nasty PwM/Pi file reading bug, when
6the used hash algo of file is different then the global 28the used hash algo of file is different then the global
7hash algo. 29hash algo.
8 30
9Added KA/Pi support for opie mailit mailapplication. 31Added KA/Pi support for opie mailit mailapplication.
10 32
11Fixed some bugs in OM/Pi. 33Fixed some bugs in OM/Pi.
12Now character conversion tables are available for the Zaurus 34Now character conversion tables are available for the Zaurus
13to make OM/Pi working properly. 35to make OM/Pi working properly.
14To get the character conversion in OM/Pi working, please download 36To get the character conversion in OM/Pi working, please download
15at the sourceforge project site the package 37at the sourceforge project site the package
16sr-character-conversion_SharpROM_arm.ipk.zip 38sr-character-conversion_SharpROM_arm.ipk.zip
17(or oz-character-conversion_OZ-gcc3xx_arm.ipk.zip for OZ roms) 39(or oz-character-conversion_OZ-gcc3xx_arm.ipk.zip for OZ roms)
18from the section "general files for KDE/Pim" 40from the section "general files for KDE/Pim"
19Instructions how to install this package are in a ReadMe in this file. 41Instructions how to install this package are in a ReadMe in this file.
20 42
21 43
22Fixed the orientation change problem in KA/Pi when switching 44Fixed the orientation change problem in KA/Pi when switching
23portrait/landscape mode. 45portrait/landscape mode.
24 46
25French translation available for KA/Pi and OM/Pi. 47French translation available for KA/Pi and OM/Pi.
26 48
27Fixed some problems with categories in KO/Pi in DTM sync. 49Fixed some problems with categories in KO/Pi in DTM sync.
28 50
29Added selection dialog for export to phone in KA/Pi. 51Added selection dialog for export to phone in KA/Pi.
30 52
31If in KO/Pi is an attendee selected to add to a meeting and this 53If in KO/Pi is an attendee selected to add to a meeting and this
32attendee is already in the list of attendees, this person is not added 54attendee is already in the list of attendees, this person is not added
33again. 55again.
34 56
35Some menu cleanup in KA/Pi. 57Some menu cleanup in KA/Pi.
36 58
37********** VERSION 1.9.12 ************ 59********** VERSION 1.9.12 ************
38 60
39Fix for the bug in KO/Pi What's Next view of version 1.9.11. 61Fix for the bug in KO/Pi What's Next view of version 1.9.11.
40 62
41Bugfix: Licence file is now shown again. 63Bugfix: Licence file is now shown again.
42 64
43OM/Pi now supports Unicode (utf8 charset). 65OM/Pi now supports Unicode (utf8 charset).
44Fixed some bugs in OM/Pi. 66Fixed some bugs in OM/Pi.
45 67
46KA/Pi has more German translation. 68KA/Pi has more German translation.
47 69
48 70
49********** VERSION 1.9.11 ************ 71********** VERSION 1.9.11 ************
50 72
51Fixed several problems in PWM/Pi, like 73Fixed several problems in PWM/Pi, like
52asking the user, if unsaved changed are pending 74asking the user, if unsaved changed are pending
53when closing the app. 75when closing the app.
54And PwM/Pi handles now different texts for the 76And PwM/Pi handles now different texts for the
55fields Description, Username, Password, configurable per category. 77fields Description, Username, Password, configurable per category.
56 78
57Fixed a crash in KO/Pi , when importing/loading vcs files 79Fixed a crash in KO/Pi , when importing/loading vcs files
58which have an entry with an attendee with state: 80which have an entry with an attendee with state:
59NEEDS ACTION 81NEEDS ACTION
60 82
61Fixed some problems in the German translation of OM/Pi, 83Fixed some problems in the German translation of OM/Pi,
62which makes some dialogs not fitting on the screen 84which makes some dialogs not fitting on the screen
63of the Z 5500. 85of the Z 5500.
64 86
65Fixed Qtopia crash, when disabling/deinstalling 87Fixed Qtopia crash, when disabling/deinstalling
66KO/Pi alarm applet. 88KO/Pi alarm applet.
67 89
68Implemented direct KDE<->KA/Pi sync for KA/Pi running 90Implemented direct KDE<->KA/Pi sync for KA/Pi running
69on Linux desktop. 91on Linux desktop.
70 92
71Added feature "remove sync info" to sync menu. 93Added feature "remove sync info" to sync menu.
72 94
73Tweaked the KO/Pi What's next view a bit, added 95Tweaked the KO/Pi What's next view a bit, added
74setting to hide events that are done. 96setting to hide events that are done.
75 97
76Disabled "beam receive enabled" on startup to 98Disabled "beam receive enabled" on startup to
77avoid problems if Fastload is enabled. 99avoid problems if Fastload is enabled.
78Please set "beam receive enabled", 100Please set "beam receive enabled",
79if you want to receive data via IR. 101if you want to receive data via IR.
80 102
81Fixed bug in direct KDE<->KO/Pi sync for KO/Pi running 103Fixed bug in direct KDE<->KO/Pi sync for KO/Pi running
82on Linux desktop. 104on Linux desktop.
83 105
84Made in KA/Pi scrolling possible, if details view is selected. 106Made in KA/Pi scrolling possible, if details view is selected.
85(The keyboard focus is set automatically to the search line) 107(The keyboard focus is set automatically to the search line)
86 108
87Fixed a bug in DMT sync, that a new entry in DTM was added 109Fixed a bug in DMT sync, that a new entry in DTM was added
88on every sync to Kx/Pi. 110on every sync to Kx/Pi.
89 111
90Fixed missing writing of KA/Pi categories to DMT entries when syncing. 112Fixed missing writing of KA/Pi categories to DMT entries when syncing.
91 113
92Fixed a bug in DMT sync with todos created in KO/Pi containing 114Fixed a bug in DMT sync with todos created in KO/Pi containing
93non-latin1 characters. 115non-latin1 characters.
94 116
95Rearranged package contents of Sharp-ipks and made all 117Rearranged package contents of Sharp-ipks and made all
96packages installable on SD again. 118packages installable on SD again.
97 119
98Fixed the writing of addressbook data in DTM sync. 120Fixed the writing of addressbook data in DTM sync.
99Empty fields in KA/Pi were not removed. 121Empty fields in KA/Pi were not removed.
100 122
101Added better category handling in KA/Pi: 123Added better category handling in KA/Pi:
102Added item 124Added item
103Edit Categories and 125Edit Categories and
104Manage new categories 126Manage new categories
105to the settings menu. 127to the settings menu.
106Possible to configure a view to display categories. 128Possible to configure a view to display categories.
107 129
108Added detailed "KDE Sync Howto" and "Multi Sync Howto" to Help menu. 130Added detailed "KDE Sync Howto" and "Multi Sync Howto" to Help menu.
109 131
110Fixed displaying of "free" days and time in KO Monthview and Agendaview. 132Fixed displaying of "free" days and time in KO Monthview and Agendaview.
111 133
112... and many other bugfixes. 134... and many other bugfixes.
113 135
114********** VERSION 1.9.10 ************ 136********** VERSION 1.9.10 ************
115 137
116Many internal small bugfixes. 138Many internal small bugfixes.
117And fix of the "big" bug in KO/Pi, 139And fix of the "big" bug in KO/Pi,
118that after Syncing the appointments had an offset by several hours. 140that after Syncing the appointments had an offset by several hours.
119That was a problem with the internal timezone setting, 141That was a problem with the internal timezone setting,
120introduced by the changed timezone configuration settings. 142introduced by the changed timezone configuration settings.
121 143
122German translation for OM/Pi is now available. 144German translation for OM/Pi is now available.
123 145
124 146
125********** VERSION 1.9.9 ************ 147********** VERSION 1.9.9 ************
126 148
127KDE-Pim/Pi has a new Member! 149KDE-Pim/Pi has a new Member!
128It is called PWM/Pi (Passwordmanager/platform-independent) 150It is called PWM/Pi (Passwordmanager/platform-independent)
129and it is available for the Zaurus. 151and it is available for the Zaurus.
130It is planned, that it will be available later for Windows. 152It is planned, that it will be available later for Windows.
131(And for Linux, of course). 153(And for Linux, of course).
132It is a port of the Passwordmanager of KDE. 154It is a port of the Passwordmanager of KDE.
133It will need the MicroKDElibs to run. 155It will need the MicroKDElibs to run.
134 156
135Made loading of addressbooks in KA/Pi up to 7 times faster! 157Made loading of addressbooks in KA/Pi up to 7 times faster!
136The bigger your addressbook file, the more starting speed 158The bigger your addressbook file, the more starting speed
137will you gain. (relatively) 159will you gain. (relatively)
138 160
139The Qtopia addressbook connector is now platform independend 161The Qtopia addressbook connector is now platform independend
140as well and should work on any platform for importing/exporting 162as well and should work on any platform for importing/exporting
141Qtopia and Opie XML files. 163Qtopia and Opie XML files.
142 164
143Added a +30min feature to the timezone settings to make 165Added a +30min feature to the timezone settings to make
144KDE-Pim/Pi useable in Australia and other parts on the 166KDE-Pim/Pi useable in Australia and other parts on the
145world with strange timezones ;-) 167world with strange timezones ;-)
146 168
147German "Umlaute" should now be sorted correctly on the Z in KA/Pi. 169German "Umlaute" should now be sorted correctly on the Z in KA/Pi.
148 170
149It is now possible to disable the 171It is now possible to disable the
150"receive data via infrared" feature, such that syncing with 172"receive data via infrared" feature, such that syncing with
151Outlook is now possible again with Kx/Pi runing. 173Outlook is now possible again with Kx/Pi runing.
152Please disable it, before syncing Sharp DTM with Outlook. 174Please disable it, before syncing Sharp DTM with Outlook.
153For your convenience, the "receive data via infrared" feature 175For your convenience, the "receive data via infrared" feature
154is disabled automatically, if you sync Kx/Pi with DTM. 176is disabled automatically, if you sync Kx/Pi with DTM.
155You have to enable it again manually after syncing. 177You have to enable it again manually after syncing.
156Enabling this feature makes it impossible to start the 178Enabling this feature makes it impossible to start the
157Sharp DTM apps. If this feature is enabled, you will only get the 179Sharp DTM apps. If this feature is enabled, you will only get the
158alarm notification from KO/Pi and not from the Sharp calendar. 180alarm notification from KO/Pi and not from the Sharp calendar.
159This is very useful if you sync KO/Pi with Sharp DTM, 181This is very useful if you sync KO/Pi with Sharp DTM,
160because after syncing you usually would get notified about 182because after syncing you usually would get notified about
161an alarm by KO/Pi and the Sharp Calendar. 183an alarm by KO/Pi and the Sharp Calendar.
162 184
163Together with the Linux desktop version of KO/Pi 185Together with the Linux desktop version of KO/Pi
164it is now possible to sync KO/Pi on the Zaurus 186it is now possible to sync KO/Pi on the Zaurus
165with the complete KDE-desktop (3.3 or later) 187with the complete KDE-desktop (3.3 or later)
166calendar data easily. 188calendar data easily.
167That makes it possible to sync the Z with one 189That makes it possible to sync the Z with one
168click of a mouse with the KDE-Desktop. 190click of a mouse with the KDE-Desktop.
169This feature it available for all Zaurus platforms KO/Pi 191This feature it available for all Zaurus platforms KO/Pi
170is running on. 192is running on.
171The only thing needed is a running KO/Pi on Linux and 193The only thing needed is a running KO/Pi on Linux and
172a compiled version of the small 194a compiled version of the small
173KDE-Pim/Pi<->KDE-Desktop access command line program, 195KDE-Pim/Pi<->KDE-Desktop access command line program,
174which is in the KDE-Pim/Pi sources available. 196which is in the KDE-Pim/Pi sources available.
175 197
176The "KDE-desktop" syncing feature for KA/Pi will follow 198The "KDE-desktop" syncing feature for KA/Pi will follow
177in the next releases. 199in the next releases.
178 200
179Fixed the vcard export bug, which had the version 1.9.8. 201Fixed the vcard export bug, which had the version 1.9.8.
180 202
181Added missing GERMAN translation to KO/Pi. 203Added missing GERMAN translation to KO/Pi.
182Hi PsionX, could you add the missing french translation?Thx! 204Hi PsionX, could you add the missing french translation?Thx!
183 205
184Translation files for KA/Pi are available as well. 206Translation files for KA/Pi are available as well.
185GERMAN translation will be available in the next release. 207GERMAN translation will be available in the next release.
186PsionX ( yres, you again ;-) ), could you start translating 208PsionX ( yres, you again ;-) ), could you start translating
187KA/Pi? Thx! 209KA/Pi? Thx!
188 210
189You can download the version 1.9.9 at 211You can download the version 1.9.9 at
190 212
191http://sourceforge.net/project/showfiles.php?group_id=104103&package_id=112604 213http://sourceforge.net/project/showfiles.php?group_id=104103&package_id=112604
192 214
193Note: 215Note:
194To run the mail program OM/Pi you need libopenssl. 216To run the mail program OM/Pi you need libopenssl.
195A link to a download loaction is available at 217A link to a download loaction is available at
196ZSI at www.killefiz.de 218ZSI at www.killefiz.de
197 219
198 220
199********** VERSION 1.9.8 ************ 221********** VERSION 1.9.8 ************
200 222
201Fixed character decoding in OM/Pi. 223Fixed character decoding in OM/Pi.
202(e.g. German "Umlaute" were not displayed properly.) 224(e.g. German "Umlaute" were not displayed properly.)
203 225
204Made is possible to reparent todos in KO/Pi. 226Made is possible to reparent todos in KO/Pi.
205Use contextmenu or keys (look at Help-Keys + Colors) for that. 227Use contextmenu or keys (look at Help-Keys + Colors) for that.
206 228
207Added the missing Sync-Howto and WhatsNew to the packages. 229Added the missing Sync-Howto and WhatsNew to the packages.
208 230
209KO/Pi on Linux desktop can now sync with KDE desktop. 231KO/Pi on Linux desktop can now sync with KDE desktop.
210That means: When using KO/Pi on Linux desktop for syncing with 232That means: When using KO/Pi on Linux desktop for syncing with
211KDE desktop and the Zaurus, the Zaurus can be synced now 233KDE desktop and the Zaurus, the Zaurus can be synced now
212with all KDE-Calendar resources, not only with one local file. 234with all KDE-Calendar resources, not only with one local file.
213(That makes it possible to sync the Zaurus with the 235(That makes it possible to sync the Zaurus with the
214calendar data on a Kolab server) 236calendar data on a Kolab server)
215 237
216KA/Pi syncing with KDE desktop will be available in the next version. 238KA/Pi syncing with KDE desktop will be available in the next version.
217 239
218 240
219********** VERSION 1.9.7 ************ 241********** VERSION 1.9.7 ************
220 242
221KO/Pi - KA/Pi on Windows: 243KO/Pi - KA/Pi on Windows:
222Now a directory can be defined by the user, where the 244Now a directory can be defined by the user, where the
223application/config data should be saved. 245application/config data should be saved.
224 Define your desired path in the evironment variable 246 Define your desired path in the evironment variable
225 MICROKDEHOME 247 MICROKDEHOME
226 before starting KO/Pi or KA/Pi. 248 before starting KO/Pi or KA/Pi.
227 249
228An easy Kx/Pi to Kx/Pi syncing is now possible 250An easy Kx/Pi to Kx/Pi syncing is now possible
229(it is called Pi-Sync) via network. 251(it is called Pi-Sync) via network.
230Please look at the Sync Howto. 252Please look at the Sync Howto.
231 253
232Exporting of calendar data and contacts to mobile phones is now possible. 254Exporting of calendar data and contacts to mobile phones is now possible.
233The SyncHowto is updated with information howto 255The SyncHowto is updated with information howto
234access/sync mobile phones. 256access/sync mobile phones.
235Please look at the Sync Howto. 257Please look at the Sync Howto.
236 258
237Now KO/Pi and KA/Pi on the Zaurus can receive data via infrared directly. 259Now KO/Pi and KA/Pi on the Zaurus can receive data via infrared directly.
238Please disable Fastload for the original contact/calendar applications 260Please disable Fastload for the original contact/calendar applications
239and close them. 261and close them.
240KO/Pi and KA/Pi must be running in order to receive the data. 262KO/Pi and KA/Pi must be running in order to receive the data.
241(KO/Pi and KA/Pi are always running if Fastload for them is enabled!) 263(KO/Pi and KA/Pi are always running if Fastload for them is enabled!)
242 264
243In the KA/Pi details view are now the preferred tel. numbers displayed on top 265In the KA/Pi details view are now the preferred tel. numbers displayed on top
244of the other data ( emails/tel.numbers/addresses) 266of the other data ( emails/tel.numbers/addresses)
245 267
246Fixed some syncing problems in KA/Pi. 268Fixed some syncing problems in KA/Pi.
247 269
248Added font settings for the KA/Pi details view. 270Added font settings for the KA/Pi details view.
249Added fields "children's name" and "gender" to KA/Pi. 271Added fields "children's name" and "gender" to KA/Pi.
250 272
251Made searching in KA/Pi better: 273Made searching in KA/Pi better:
252Now the first item in a view is selected after a search automatically and 274Now the first item in a view is selected after a search automatically and
253the views can be scrolled up/down when the search input field has the keyboard focus. 275the views can be scrolled up/down when the search input field has the keyboard focus.
254 276
255And, of course, fixed a bunch of reported bugs in KO/Pi and KA/Pi. 277And, of course, fixed a bunch of reported bugs in KO/Pi and KA/Pi.
256 278
257 279
258********** VERSION 1.9.6 ************ 280********** VERSION 1.9.6 ************
259 281
260Changes in the external application communication on the Zaurus 282Changes in the external application communication on the Zaurus
261in order to use less RAM when the apps are running. 283in order to use less RAM when the apps are running.
262First syncing of addressbooks (KA/Pi) is possible. 284First syncing of addressbooks (KA/Pi) is possible.
263 285
264 286
265********** VERSION 1.9.5a ************ 287********** VERSION 1.9.5a ************
266 288
267Fixed a bug in KO/Pi in the SharpDTM sync of version 1.9.5. 289Fixed a bug in KO/Pi in the SharpDTM sync of version 1.9.5.
268Fixed some small bugs. 290Fixed some small bugs.
269KA/Pi shows now the birthday in summary view. 291KA/Pi shows now the birthday in summary view.
270Now OM/Pi and KA/Pi are using the date format defined in KO/Pi 292Now OM/Pi and KA/Pi are using the date format defined in KO/Pi
271for displaying dates. 293for displaying dates.
272 294
273 295
274********** VERSION 1.9.5 ************ 296********** VERSION 1.9.5 ************
275 297
276There is still no Addressbook syncing! 298There is still no Addressbook syncing!
277 299
278New in 1.9.5: 300New in 1.9.5:
279 301
280Many bugfixes. 302Many bugfixes.
281Better searching in KA/Pi. 303Better searching in KA/Pi.
282You can configure in KA/Pi if you want to search only after 304You can configure in KA/Pi if you want to search only after
283<return> key pressed. 305<return> key pressed.
284 306
285Better mail downloading in OM/Pi. 307Better mail downloading in OM/Pi.
286 308
287First experimental alpha version of sync of KO/Pi with mobile phones. 309First experimental alpha version of sync of KO/Pi with mobile phones.
288See gammu documentation for supported phones. 310See gammu documentation for supported phones.
289You need to install the package kammu_1.9.5_arm.ipk for sync of KO/Pi with mobile phones. kammu_1.9.5_arm.ipk needs libbluetooth and libsdp. 311You need to install the package kammu_1.9.5_arm.ipk for sync of KO/Pi with mobile phones. kammu_1.9.5_arm.ipk needs libbluetooth and libsdp.
290Quick hint how to use: 312Quick hint how to use:
291NOTE: MOBILE PHONE SYNC IS EXPERIMENTAL! 313NOTE: MOBILE PHONE SYNC IS EXPERIMENTAL!
292Install kammu_1.9.5_arm.ipk , libbluetooth and libsdp. 314Install kammu_1.9.5_arm.ipk , libbluetooth and libsdp.
293Create syncprofile - mobile device 315Create syncprofile - mobile device
294Remove entry for model. (Leave empty ). 316Remove entry for model. (Leave empty ).
295Enable infrared on Zaurus and your Phone. 317Enable infrared on Zaurus and your Phone.
296Sync. 318Sync.
297To get a more detailed log, start kopi from konsole. 319To get a more detailed log, start kopi from konsole.
298 320
299********** VERSION 1.9.4 ************ 321********** VERSION 1.9.4 ************
300 322
301This is the version 1.9.4 of KDE-Pim/Pi for the Zaurus. 323This is the version 1.9.4 of KDE-Pim/Pi for the Zaurus.
302 324
303WARNING: 325WARNING:
304PLEASE BACKUP ALL YOUR DATA! 326PLEASE BACKUP ALL YOUR DATA!
305We have changed a lot and maybe there are some unknown problems. 327We have changed a lot and maybe there are some unknown problems.
306 328
307SYNC HANDLING HAS CHANGED! 329SYNC HANDLING HAS CHANGED!
308Such that, if you sync now with an already synded device, you will duplicated entries after the first sync. 330Such that, if you sync now with an already synded device, you will duplicated entries after the first sync.
309(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks). 331(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks).
310 332
311You need the kmicrokdelibs_1.9.4_arm.ipk as a base for the other programs. 333You need the kmicrokdelibs_1.9.4_arm.ipk as a base for the other programs.
312If you get the error: "Install only possible in main memory", just try it again to install it on SD card. That worked for me. And it was reported that rebooting Qtopia did help in this case as well. 334If you get the error: "Install only possible in main memory", just try it again to install it on SD card. That worked for me. And it was reported that rebooting Qtopia did help in this case as well.
313 335
314As programs are available: 336As programs are available:
315KO/Pi (korganizer ipk) - a calendar program. 337KO/Pi (korganizer ipk) - a calendar program.
316KA/Pi (kaddressbook ipk ) - an addressbook 338KA/Pi (kaddressbook ipk ) - an addressbook
317OM/Pi (kopiemail ipk ) an email program with pop/smtp and IMAP support. 339OM/Pi (kopiemail ipk ) an email program with pop/smtp and IMAP support.
318 340
319An alarm notification program ( korganizer-alarm ipk ) for KO/Pi that notifies you about alarms, even if the Zaurus is in suspend mode. 341An alarm notification program ( korganizer-alarm ipk ) for KO/Pi that notifies you about alarms, even if the Zaurus is in suspend mode.
320(If you do not see an icon in the taskbar after installing korganizer-alarm, please restart Qtopia) 342(If you do not see an icon in the taskbar after installing korganizer-alarm, please restart Qtopia)
321 343
322All the applications are installed in a "Pim" TAB. 344All the applications are installed in a "Pim" TAB.
323If this TAB is new on your system, you can get an icon in this TAB by installing pim_TAB_icon_1.9.4_arm.ipk 345If this TAB is new on your system, you can get an icon in this TAB by installing pim_TAB_icon_1.9.4_arm.ipk
324 346
325All the application are integrated. 347All the application are integrated.
326Such that you can choose in KO/Pi the attendees of a meeting from the addresses in KA/Pi. When you click in KA/Pi on the email address, OM/Pi is started to write the mail. 348Such that you can choose in KO/Pi the attendees of a meeting from the addresses in KA/Pi. When you click in KA/Pi on the email address, OM/Pi is started to write the mail.
327 349
328HINT: 350HINT:
329If you install KPhone/Pi 0.9.7, it will be called, if you click in KA/Pi on a phone number. 351If you install KPhone/Pi 0.9.7, it will be called, if you click in KA/Pi on a phone number.
330 352
331What's new? 353What's new?
332 354
333SYNC HANDLING HAS CHANGED! 355SYNC HANDLING HAS CHANGED!
334Such that, if you sync now with an already synded device, you will duplicated entries after the first sync. 356Such that, if you sync now with an already synded device, you will duplicated entries after the first sync.
335(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks). 357(This change was introduced to make it possible to sync with mobile phones, which will be available later (maybe in 4 weeks).
336 358
337New in OM/Pi: 359New in OM/Pi:
338When copying(i.e. downloading mails) , you can specify, that only mails of a given size should be downloaded. Added mail copy possibility for selected mails. 360When copying(i.e. downloading mails) , you can specify, that only mails of a given size should be downloaded. Added mail copy possibility for selected mails.
339 361
340New in KO/Pi: 362New in KO/Pi:
341French is now available for KO/Pi. 363French is now available for KO/Pi.
342Choose menu:Actions - Configure:TAB locale 364Choose menu:Actions - Configure:TAB locale
343Syncing has changed. 365Syncing has changed.
344Phone sync available soon. 366Phone sync available soon.
345Not much changes, I cannot remember them ... 367Not much changes, I cannot remember them ...
346 368
347New in KA/Pi: 369New in KA/Pi:
348Beaming possible. 370Beaming possible.
349Sharp DTM readonly access possible( create a new DTM resource ); 371Sharp DTM readonly access possible( create a new DTM resource );
350Better searching possible. 372Better searching possible.
351Search is performed only after pressing the return key. 373Search is performed only after pressing the return key.
352Use wildcard * to specify parts of a name. 374Use wildcard * to specify parts of a name.
353 375
354Better name/email selection dialog (called from KO/Pi or OM/Pi). In this dialog, now searching is possible. Like in KA/Pi, use return key and wildcard * . 376Better name/email selection dialog (called from KO/Pi or OM/Pi). In this dialog, now searching is possible. Like in KA/Pi, use return key and wildcard * .
355 377
356A big improvement is the new management of the contact access. 378A big improvement is the new management of the contact access.
357In version 1.9.3, every application was using their own addressbook access data. 379In version 1.9.3, every application was using their own addressbook access data.
358That means, the addressbook was loaded up to three times in the memory, when accessed by KA/Pi, KO/Pi and OM/Pi. 380That means, the addressbook was loaded up to three times in the memory, when accessed by KA/Pi, KO/Pi and OM/Pi.
359That was wasting of memory, if you had several hundreds of contacts. 381That was wasting of memory, if you had several hundreds of contacts.
360 382
361Now only KA/Pi accesses the addressbook. 383Now only KA/Pi accesses the addressbook.
362If KO/Pi or OM/Pi want to get some name/email data, they request KA/Pi to open the name/email selection dialog and send it back to them. 384If KO/Pi or OM/Pi want to get some name/email data, they request KA/Pi to open the name/email selection dialog and send it back to them.
363If you click on an attendee in a meeting, its contact data is displayed in KA/Pi directly. 385If you click on an attendee in a meeting, its contact data is displayed in KA/Pi directly.
364That means, if KO/Pi or OM/Pi want to access contact data, KA/Pi is started first. 386That means, if KO/Pi or OM/Pi want to access contact data, KA/Pi is started first.
365 387
366New in the KO/Pi alarm applet: 388New in the KO/Pi alarm applet:
367Configure your own timer popup menu! 389Configure your own timer popup menu!
368(Text and minutes for timer countdown) 390(Text and minutes for timer countdown)
369Just edit the file 391Just edit the file
370(yourhomedir)/.kopialarmtimerrc 392(yourhomedir)/.kopialarmtimerrc
371and start/stop a timer to get a new menu with the data of this file. 393and start/stop a timer to get a new menu with the data of this file.
372 394
373********** VERSION 1.9.3 ************ 395********** VERSION 1.9.3 ************
3741) 3961)
375Now KO/Pi on Windows imports directly the calendar data of 397Now KO/Pi on Windows imports directly the calendar data of
376an installed Outlook. Should work with OL version >= 2000. 398an installed Outlook. Should work with OL version >= 2000.
377 399
378********** VERSION 1.9.2 ************ 400********** VERSION 1.9.2 ************
3791) 4011)
380KDE-Pim/Pi has got a new member: 402KDE-Pim/Pi has got a new member:
381KmicroMail (KM/Pi) is a mail program, 403KmicroMail (KM/Pi) is a mail program,
382which can handle IMAP and POP mail access. 404which can handle IMAP and POP mail access.
383It is based on Opie-Mail v3. 405It is based on Opie-Mail v3.
384All dependencies to the Opie libraries ar removed, 406All dependencies to the Opie libraries ar removed,
385such that no additional Opie lib is needed. 407such that no additional Opie lib is needed.
386It is already integrated in KO/Pi and KA/Pi. 408It is already integrated in KO/Pi and KA/Pi.
387It it now available for the Zaurus,probably it 409It it now available for the Zaurus,probably it
388will be available for other platforms later. 410will be available for other platforms later.
389Hint: 411Hint:
390Create your own contact (name + email) 412Create your own contact (name + email)
391in KA/Pi, select this contact and choose menu: 413in KA/Pi, select this contact and choose menu:
392Settings - Set Who Am I. 414Settings - Set Who Am I.
393Now the settings of this contact are used as 415Now the settings of this contact are used as
394the sender data in KM/Pi. 416the sender data in KM/Pi.
3952) 4172)
396KDE-Pim/Pi is split up in five different 418KDE-Pim/Pi is split up in five different
397packages now precompiled for Sharp Zaurus: 419packages now precompiled for Sharp Zaurus:
398--kmicrokdelibs_1.9.2_arm.ipk 420--kmicrokdelibs_1.9.2_arm.ipk
399The libs are needed for any 421The libs are needed for any
400of the following programs: 422of the following programs:
401--kaddressbook_1.9.2_arm.ipk 423--kaddressbook_1.9.2_arm.ipk
402--kmicromail_1.9.2_arm.ipk 424--kmicromail_1.9.2_arm.ipk
403--korganizer_1.9.2_arm.ipk 425--korganizer_1.9.2_arm.ipk
404Independ from that, there is the alarm applet 426Independ from that, there is the alarm applet
405available for KO/Pi, which also offers 427available for KO/Pi, which also offers
406quick access for a new mail or 428quick access for a new mail or
407showing the addressbook.: 429showing the addressbook.:
408--korganizer-alarm_1.9.2_arm.ipk 430--korganizer-alarm_1.9.2_arm.ipk
409Independend means, that the alarm applet 431Independend means, that the alarm applet
410does not need any of the libs or programs above to run. 432does not need any of the libs or programs above to run.
411But it would be quite useless without these programs. 433But it would be quite useless without these programs.
412NOTE: 434NOTE:
413If you get a 435If you get a
414"This application depends on other programs" 436"This application depends on other programs"
415during installation of 437during installation of
416--kmicrokdelibs_1.9.2_arm.ipk 438--kmicrokdelibs_1.9.2_arm.ipk
417you probably do not have to care about that. 439you probably do not have to care about that.
418kmicrokdelibs_1.9.2 will come with some 440kmicrokdelibs_1.9.2 will come with some
419resource plugins, which needs additional libraries. 441resource plugins, which needs additional libraries.
420(E.g. libopie1, if you want to use the 442(E.g. libopie1, if you want to use the
421opie resource connector in KA/Pi). 443opie resource connector in KA/Pi).
422If you do not have this libraries installed, 444If you do not have this libraries installed,
423you simply cannot use the resource. 445you simply cannot use the resource.
424To make it clear: 446To make it clear:
425If the libraries are missing, the applications 447If the libraries are missing, the applications
426using kmicrokdelibs will start, 448using kmicrokdelibs will start,
427because the resources are plugins. 449because the resources are plugins.
4283) 4503)
429KO/Pi and friends are now installable on SD-Card! 451KO/Pi and friends are now installable on SD-Card!
430It is recommended to install all libs and apps 452It is recommended to install all libs and apps
431on the SD card or all in the internal storage. 453on the SD card or all in the internal storage.
432There may be problems, if this is mixed. 454There may be problems, if this is mixed.
4334) 4554)
434Fixed two bugs in the alarm notification on Windows. 456Fixed two bugs in the alarm notification on Windows.
4355) 4575)
436Great improvement! 458Great improvement!
437KO/Pi uses now the latest version of libical. 459KO/Pi uses now the latest version of libical.
438Libical is the library which actually reads 460Libical is the library which actually reads
439the calendar files and extract the data from it. 461the calendar files and extract the data from it.
440With the old version, there were problems 462With the old version, there were problems
441(crashes or program hangs) when licical did read 463(crashes or program hangs) when licical did read
442files, which were not stored from KO/Pi. 464files, which were not stored from KO/Pi.
443I do not know, if the new libical works perfect, 465I do not know, if the new libical works perfect,
444but actually it works much better than 466but actually it works much better than
445the old version. 467the old version.
446There are no problems with compatibility with 468There are no problems with compatibility with
447old calendar files of KO/Pi, of course! 469old calendar files of KO/Pi, of course!
4486) 4706)
449New in KA/Pi: 471New in KA/Pi:
450Opie addressbook resource connector available! 472Opie addressbook resource connector available!
451You will need libopie1 and the opie addressbook, 473You will need libopie1 and the opie addressbook,
452of course. 474of course.
453With the Opie addressbook resource connector, 475With the Opie addressbook resource connector,
454you can access the Opie addressbook readonly in KA/Pi. 476you can access the Opie addressbook readonly in KA/Pi.
455If you want to edit or import the data into KA/Pi, 477If you want to edit or import the data into KA/Pi,
456do this: 478do this:
457a) Create an Opie resource. 479a) Create an Opie resource.
458 (Menu: Settings-Configure Resources). 480 (Menu: Settings-Configure Resources).
459After configuration and restarting KA/Pi you should see 481After configuration and restarting KA/Pi you should see
460the Opie contacts in KA/Pi. 482the Opie contacts in KA/Pi.
461b) Select some or all Opie contacts. 483b) Select some or all Opie contacts.
462(NOTE: +++++ 484(NOTE: +++++
463To know exactly, what contacts are Opie contacts, 485To know exactly, what contacts are Opie contacts,
464do this: Choose menu: 486do this: Choose menu:
465View-Modify View - TAB Fields. 487View-Modify View - TAB Fields.
466Select in the above list "Resource" and click 488Select in the above list "Resource" and click
467down arrow to add it to the "Selected fields". 489down arrow to add it to the "Selected fields".
468Click OK. 490Click OK.
469Now you have a new column "Resource" in your list, 491Now you have a new column "Resource" in your list,
470where you can see, what an Opie resource is. 492where you can see, what an Opie resource is.
471++++ NOTE end.) 493++++ NOTE end.)
472Ok, we do have now some Opie contacts seleted. 494Ok, we do have now some Opie contacts seleted.
473(Use SHIFT or CTRL key in order to multiple select). 495(Use SHIFT or CTRL key in order to multiple select).
474c) Choose menu: Edit-Copy. 496c) Choose menu: Edit-Copy.
475d) Choose menu: Edit-Paste. 497d) Choose menu: Edit-Paste.
476e) Select the resource, you want to add the contacts to. 498e) Select the resource, you want to add the contacts to.
477Congrats! Now you have read/write access to the copied 499Congrats! Now you have read/write access to the copied
478opie contacts as "real" KA/Pi contacts. 500opie contacts as "real" KA/Pi contacts.
479 501
480 502
481********** VERSION 1.9.1 ************ 503********** VERSION 1.9.1 ************
4821) 5041)
483 +++ IMPORTANT 1 +++ 505 +++ IMPORTANT 1 +++
484 506
485The storing place of the default calendar 507The storing place of the default calendar
486file has changed! 508file has changed!
487The default calendar file was 509The default calendar file was
488Applications/korganizer/mycalendar.ics 510Applications/korganizer/mycalendar.ics
489on Zaurus and 511on Zaurus and
490(yourHomeDir)/korganizer/mycalendar.ics 512(yourHomeDir)/korganizer/mycalendar.ics
491on Windows/Linux desktop. Now it is 513on Windows/Linux desktop. Now it is
492(yourHomeDir)/kdepim/korganizer/mycalendar.ics 514(yourHomeDir)/kdepim/korganizer/mycalendar.ics
493on Zaurus, Windows and Linux. 515on Zaurus, Windows and Linux.
494To load the old file, choose menu 516To load the old file, choose menu
495File-Load calendar backup. 517File-Load calendar backup.
496(It should be loaded automatically 518(It should be loaded automatically
497at startup with a warning message displayed). 519at startup with a warning message displayed).
498The place of the configuration file has changed too. 520The place of the configuration file has changed too.
499If you want to use your old KO/Pi config, 521If you want to use your old KO/Pi config,
500copy it to 522copy it to
501(yourHomeDir)/kdepim/config/korganizerrc 523(yourHomeDir)/kdepim/config/korganizerrc
502Please read VERSION 1.9.0 - topic 3) as well! 524Please read VERSION 1.9.0 - topic 3) as well!
503 525
504 +++ IMPORTANT 2 +++ 526 +++ IMPORTANT 2 +++
505 527
506Because of the new paths, you will need 528Because of the new paths, you will need
507a new version of the KO/Pi alarm applet 529a new version of the KO/Pi alarm applet
508for Zaurus. 530for Zaurus.
509Use version >= 1.9.1 531Use version >= 1.9.1
510 532
5112) 5332)
512Now the QWhat'sThis Icon works for items 534Now the QWhat'sThis Icon works for items
513in the month view as well. 535in the month view as well.
514(See VERSION 1.7.8 Topic 1) ). 536(See VERSION 1.7.8 Topic 1) ).
5153) 5373)
516You can import birtsdays/anniversaries 538You can import birtsdays/anniversaries
517from KA/Pi into KO/Pi. 539from KA/Pi into KO/Pi.
518Choose menu File-Import birthdays. 540Choose menu File-Import birthdays.
519If you import twice, already imported items 541If you import twice, already imported items
520will not be imported again, if they 542will not be imported again, if they
521have not been changed in KO/Pi. 543have not been changed in KO/Pi.
5224) 5444)
523When syncing with sharp DTM, now a progress 545When syncing with sharp DTM, now a progress
524is shown, when the data is written back. 546is shown, when the data is written back.
525If there is much data in KO/Pi and no data 547If there is much data in KO/Pi and no data
526in DTM, that can take a long time. 548in DTM, that can take a long time.
527(But only for the first time ). 549(But only for the first time ).
5285) 5505)
529In the search dialog, you can search 551In the search dialog, you can search
530now for the name/email of an attendee 552now for the name/email of an attendee
531of an event/todo. 553of an event/todo.
532To get more space for displaying 554To get more space for displaying
533search results, the buttons 555search results, the buttons
534for "search" and "close" on the 556for "search" and "close" on the
535bottom are removed in the PDA version. 557bottom are removed in the PDA version.
536You have to click OK in the top right 558You have to click OK in the top right
537corner to do a search. 559corner to do a search.
5386) 5606)
539Now it is possible to disable the displaying 561Now it is possible to disable the displaying
540of todo items in the Allday part of the Agenda. 562of todo items in the Allday part of the Agenda.
541Choose Menu Action-Configure, 563Choose Menu Action-Configure,
542TAB Todo View, checkbox 564TAB Todo View, checkbox
543"Allday Agenda view shows todos" 565"Allday Agenda view shows todos"
5447) 5667)
545If FastLoad is enabled, now the settings and the 567If FastLoad is enabled, now the settings and the
546calendar data are saved, when KO/Pi is closed. 568calendar data are saved, when KO/Pi is closed.
547(If no Fastload is enabled, KO/Pi saves 569(If no Fastload is enabled, KO/Pi saves
548the data as well, of course) 570the data as well, of course)
5498) 5718)
550The Agenda View has a minimize-splitter now, 572The Agenda View has a minimize-splitter now,
551such that the height of the allday part can be 573such that the height of the allday part can be
552changed quickly. 574changed quickly.
553 575
554********** VERSION 1.9.0 ************ 576********** VERSION 1.9.0 ************
5551) 5771)
556KO/Pi is now merged with the new microKDE from KA/Pi. 578KO/Pi is now merged with the new microKDE from KA/Pi.
557KO/Pi accesses now KA/Pi as the addressbook. 579KO/Pi accesses now KA/Pi as the addressbook.
558The other ddressbook-plugins are not working any longer. 580The other ddressbook-plugins are not working any longer.
559(It is planned, that later KA/Pi itself uses these plugins) 581(It is planned, that later KA/Pi itself uses these plugins)
560New versions of KO/Pi are only available 582New versions of KO/Pi are only available
561together with KA/Pi as the KDE-Pim/Pi package. 583together with KA/Pi as the KDE-Pim/Pi package.
5622) 5842)
563If you click on an attendee of a meeting in the 585If you click on an attendee of a meeting in the
564event viewer, a detailed summary of the 586event viewer, a detailed summary of the
565attendee is shown. 587attendee is shown.
5663) 5883)
567The place of the configuration file has changed. 589The place of the configuration file has changed.
568If you want to use your old KO/Pi config, copy 590If you want to use your old KO/Pi config, copy
569Applications/korganizer/config_korganizerrc 591Applications/korganizer/config_korganizerrc
570to 592to
571Applications/korganizer/config/korganizerrc 593Applications/korganizer/config/korganizerrc
572 594
573********** VERSION 1.7.8 ************ 595********** VERSION 1.7.8 ************
5741) 5961)
575Now the QWhat'sThis ist working. 597Now the QWhat'sThis ist working.
576Enable the QWhat'sThis icon in the toolbar. 598Enable the QWhat'sThis icon in the toolbar.
577(You have to restart to reload the changed toolbar config). 599(You have to restart to reload the changed toolbar config).
578Now click on the QWhat'sThis Icon 600Now click on the QWhat'sThis Icon
579in the top right corner of KO/Pi. 601in the top right corner of KO/Pi.
580Then click on an item in the Agenda View: 602Then click on an item in the Agenda View:
581You will get a detailed display of the items content. 603You will get a detailed display of the items content.
5822) 6042)
583Some other very minor changes. 605Some other very minor changes.
584But I have forgotten the details ... 606But I have forgotten the details ...
585For that reason I start this log here: 607For that reason I start this log here:
586To document my changes, when I am doing it. 608To document my changes, when I am doing it.
587 609
588********** VERSION 1.7.7 ************ 610********** VERSION 1.7.7 ************
589Stable Version of KO/Pi 611Stable Version of KO/Pi
diff --git a/kmicromail/libetpan/maildir/maildir.c b/kmicromail/libetpan/maildir/maildir.c
index 0e038b1..1ef0b7a 100644
--- a/kmicromail/libetpan/maildir/maildir.c
+++ b/kmicromail/libetpan/maildir/maildir.c
@@ -1,729 +1,740 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa 4 * Copyright (C) 2001 - 2003 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36#include "maildir.h" 36#include "maildir.h"
37 37
38#include <string.h> 38#include <string.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <dirent.h> 43#include <dirent.h>
44#include <time.h> 44#include <time.h>
45#include <sys/stat.h> 45#include <sys/stat.h>
46#include <sys/mman.h> 46#include <sys/mman.h>
47 47
48#ifdef LIBETPAN_SYSTEM_BASENAME 48#ifdef LIBETPAN_SYSTEM_BASENAME
49#include <libgen.h> 49#include <libgen.h>
50#endif 50#endif
51 51
52/* 52/*
53 We suppose the maildir mailbox remains on one unique filesystem. 53 We suppose the maildir mailbox remains on one unique filesystem.
54*/ 54*/
55 55
56struct maildir * maildir_new(const char * path) 56struct maildir * maildir_new(const char * path)
57{ 57{
58 struct maildir * md; 58 struct maildir * md;
59 59
60 md = malloc(sizeof(* md)); 60 md = malloc(sizeof(* md));
61 if (md == NULL) 61 if (md == NULL)
62 goto err; 62 goto err;
63 63
64 md->mdir_counter = 0; 64 md->mdir_counter = 0;
65 md->mdir_mtime_new = (time_t) -1; 65 md->mdir_mtime_new = (time_t) -1;
66 md->mdir_mtime_cur = (time_t) -1; 66 md->mdir_mtime_cur = (time_t) -1;
67 67
68 md->mdir_pid = getpid(); 68 md->mdir_pid = getpid();
69 gethostname(md->mdir_hostname, sizeof(md->mdir_hostname)); 69 gethostname(md->mdir_hostname, sizeof(md->mdir_hostname));
70 strncpy(md->mdir_path, path, sizeof(md->mdir_path)); 70 strncpy(md->mdir_path, path, sizeof(md->mdir_path));
71 md->mdir_path[PATH_MAX - 1] = '\0'; 71 md->mdir_path[PATH_MAX - 1] = '\0';
72 72
73 md->mdir_msg_list = carray_new(128); 73 md->mdir_msg_list = carray_new(128);
74 if (md->mdir_msg_list == NULL) 74 if (md->mdir_msg_list == NULL)
75 goto free; 75 goto free;
76 76
77 md->mdir_msg_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYNONE); 77 md->mdir_msg_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYNONE);
78 if (md->mdir_msg_hash == NULL) 78 if (md->mdir_msg_hash == NULL)
79 goto free_msg_list; 79 goto free_msg_list;
80 80
81 return md; 81 return md;
82 82
83 free_msg_list: 83 free_msg_list:
84 carray_free(md->mdir_msg_list); 84 carray_free(md->mdir_msg_list);
85 free: 85 free:
86 free(md); 86 free(md);
87 err: 87 err:
88 return NULL; 88 return NULL;
89} 89}
90 90
91static void maildir_flush(struct maildir * md, int msg_new); 91static void maildir_flush(struct maildir * md, int msg_new);
92 92
93void maildir_free(struct maildir * md) 93void maildir_free(struct maildir * md)
94{ 94{
95 maildir_flush(md, 0); 95 maildir_flush(md, 0);
96 maildir_flush(md, 1); 96 maildir_flush(md, 1);
97 chash_free(md->mdir_msg_hash); 97 chash_free(md->mdir_msg_hash);
98 carray_free(md->mdir_msg_list); 98 carray_free(md->mdir_msg_list);
99 free(md); 99 free(md);
100} 100}
101 101
102#define MAX_TRY_ALLOC 32 102#define MAX_TRY_ALLOC 32
103 103
104static char * maildir_get_new_message_filename(struct maildir * md, 104static char * maildir_get_new_message_filename(struct maildir * md,
105 char * tmpfile) 105 char * tmpfile)
106{ 106{
107 char filename[PATH_MAX]; 107 char filename[PATH_MAX];
108 char basename[PATH_MAX]; 108 char basename[PATH_MAX];
109 int k; 109 int k;
110 time_t now; 110 time_t now;
111 111 struct stat f_stat;
112 now = time(NULL); 112 now = time(NULL);
113 k = 0; 113 k = 0;
114
115 fprintf(stderr,"maildir_get_new_message_filename: %s \n", tmpfile);
114 while (k < MAX_TRY_ALLOC) { 116 while (k < MAX_TRY_ALLOC) {
115 snprintf(basename, sizeof(basename), "%lu.%u_%u.%s", 117 snprintf(basename, sizeof(basename), "%lu.%u_%u.%s",
116 (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname); 118 (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname);
117 snprintf(filename, sizeof(filename), "%s/tmp/%s", 119 snprintf(filename, sizeof(filename), "%s/tmp/%s",
118 md->mdir_path, basename); 120 md->mdir_path, basename);
119 121 fprintf(stderr,"filename %s \n", filename);
120 if (link(tmpfile, filename) == 0) { 122 // LR changed following lines
123 if ( stat( filename, &f_stat ) == -1 ) {
124 //if (link(tmpfile, filename) == 0) {
121 char * dup_filename; 125 char * dup_filename;
122 126
123 dup_filename = strdup(filename); 127 dup_filename = strdup(filename);
124 if (dup_filename == NULL) { 128 if (dup_filename == NULL) {
125 unlink(filename); 129 //unlink(filename);
126 return NULL; 130 return NULL;
127 } 131 }
128 132 fprintf(stderr,"filename %s %s \n", tmpfile,dup_filename);
129 unlink(tmpfile); 133 //unlink(tmpfile);
134 rename (tmpfile,dup_filename );
130 md->mdir_counter ++; 135 md->mdir_counter ++;
131 136
132 return dup_filename; 137 return dup_filename;
133 } 138 }
134 139
135 md->mdir_counter ++; 140 md->mdir_counter ++;
136 k ++; 141 k ++;
137 } 142 }
138 143
139 return NULL; 144 return NULL;
140} 145}
141 146
142 147
143static void msg_free(struct maildir_msg * msg) 148static void msg_free(struct maildir_msg * msg)
144{ 149{
145 free(msg->msg_uid); 150 free(msg->msg_uid);
146 free(msg->msg_filename); 151 free(msg->msg_filename);
147 free(msg); 152 free(msg);
148} 153}
149 154
150/* 155/*
151 msg_new() 156 msg_new()
152 157
153 filename is given without path 158 filename is given without path
154*/ 159*/
155 160
156static struct maildir_msg * msg_new(char * filename, int new_msg) 161static struct maildir_msg * msg_new(char * filename, int new_msg)
157{ 162{
158 struct maildir_msg * msg; 163 struct maildir_msg * msg;
159 char * p; 164 char * p;
160 int flags; 165 int flags;
161 size_t uid_len; 166 size_t uid_len;
162 char * begin_uid; 167 char * begin_uid;
163 168
164 /* name of file : xxx-xxx_xxx-xxx:2,SRFT */ 169 /* name of file : xxx-xxx_xxx-xxx:2,SRFT */
165 170
166 msg = malloc(sizeof(* msg)); 171 msg = malloc(sizeof(* msg));
167 if (msg == NULL) 172 if (msg == NULL)
168 goto err; 173 goto err;
169 174
170 msg->msg_filename = strdup(filename); 175 msg->msg_filename = strdup(filename);
171 if (msg->msg_filename == NULL) 176 if (msg->msg_filename == NULL)
172 goto free; 177 goto free;
173 178
174 begin_uid = filename; 179 begin_uid = filename;
175 180
176 uid_len = strlen(begin_uid); 181 uid_len = strlen(begin_uid);
177 182
178 flags = 0; 183 flags = 0;
179 p = strstr(filename, ":2,"); 184 p = strstr(filename, ":2,");
180 if (p != NULL) { 185 if (p != NULL) {
181 uid_len = p - begin_uid; 186 uid_len = p - begin_uid;
182 187
183 p += 3; 188 p += 3;
184 189
185 /* parse flags */ 190 /* parse flags */
186 while (* p != '\0') { 191 while (* p != '\0') {
187 switch (* p) { 192 switch (* p) {
188 case 'S': 193 case 'S':
189 flags |= MAILDIR_FLAG_SEEN; 194 flags |= MAILDIR_FLAG_SEEN;
190 break; 195 break;
191 case 'R': 196 case 'R':
192 flags |= MAILDIR_FLAG_REPLIED; 197 flags |= MAILDIR_FLAG_REPLIED;
193 break; 198 break;
194 case 'F': 199 case 'F':
195 flags |= MAILDIR_FLAG_FLAGGED; 200 flags |= MAILDIR_FLAG_FLAGGED;
196 break; 201 break;
197 case 'T': 202 case 'T':
198 flags |= MAILDIR_FLAG_TRASHED; 203 flags |= MAILDIR_FLAG_TRASHED;
199 break; 204 break;
200 } 205 }
201 p ++; 206 p ++;
202 } 207 }
203 } 208 }
204 209
205 if (new_msg) 210 if (new_msg)
206 flags |= MAILDIR_FLAG_NEW; 211 flags |= MAILDIR_FLAG_NEW;
207 212
208 msg->msg_flags = flags; 213 msg->msg_flags = flags;
209 214
210 msg->msg_uid = malloc(uid_len + 1); 215 msg->msg_uid = malloc(uid_len + 1);
211 if (msg->msg_uid == NULL) 216 if (msg->msg_uid == NULL)
212 goto free_filename; 217 goto free_filename;
213 218
214 strncpy(msg->msg_uid, begin_uid, uid_len); 219 strncpy(msg->msg_uid, begin_uid, uid_len);
215 msg->msg_uid[uid_len] = '\0'; 220 msg->msg_uid[uid_len] = '\0';
216 221
217 return msg; 222 return msg;
218 223
219 free_filename: 224 free_filename:
220 free(msg->msg_filename); 225 free(msg->msg_filename);
221 free: 226 free:
222 free(msg); 227 free(msg);
223 err: 228 err:
224 return NULL; 229 return NULL;
225} 230}
226 231
227static void maildir_flush(struct maildir * md, int msg_new) 232static void maildir_flush(struct maildir * md, int msg_new)
228{ 233{
229 unsigned int i; 234 unsigned int i;
230 235
231 i = 0; 236 i = 0;
232 while (i < carray_count(md->mdir_msg_list)) { 237 while (i < carray_count(md->mdir_msg_list)) {
233 struct maildir_msg * msg; 238 struct maildir_msg * msg;
234 int delete; 239 int delete;
235 240
236 msg = carray_get(md->mdir_msg_list, i); 241 msg = carray_get(md->mdir_msg_list, i);
237 242
238 if (msg_new) { 243 if (msg_new) {
239 delete = 0; 244 delete = 0;
240 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 245 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
241 delete = 1; 246 delete = 1;
242 } 247 }
243 else { 248 else {
244 delete = 1; 249 delete = 1;
245 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 250 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
246 delete = 0; 251 delete = 0;
247 } 252 }
248 253
249 if (delete) { 254 if (delete) {
250 chashdatum key; 255 chashdatum key;
251 256
252 key.data = msg->msg_uid; 257 key.data = msg->msg_uid;
253 key.len = strlen(msg->msg_uid); 258 key.len = strlen(msg->msg_uid);
254 chash_delete(md->mdir_msg_hash, &key, NULL); 259 chash_delete(md->mdir_msg_hash, &key, NULL);
255 260
256 carray_delete(md->mdir_msg_list, i); 261 carray_delete(md->mdir_msg_list, i);
257 msg_free(msg); 262 msg_free(msg);
258 } 263 }
259 else { 264 else {
260 i ++; 265 i ++;
261 } 266 }
262 } 267 }
263} 268}
264 269
265static int add_message(struct maildir * md, 270static int add_message(struct maildir * md,
266 char * filename, int is_new) 271 char * filename, int is_new)
267{ 272{
268 struct maildir_msg * msg; 273 struct maildir_msg * msg;
269 chashdatum key; 274 chashdatum key;
270 chashdatum value; 275 chashdatum value;
271 unsigned int i; 276 unsigned int i;
272 int res; 277 int res;
273 int r; 278 int r;
274 279
280 fprintf(stderr,"add_message filename: %s \n", filename);
275 msg = msg_new(filename, is_new); 281 msg = msg_new(filename, is_new);
276 if (msg == NULL) { 282 if (msg == NULL) {
277 res = MAILDIR_ERROR_MEMORY; 283 res = MAILDIR_ERROR_MEMORY;
278 goto err; 284 goto err;
279 } 285 }
280 286
281 r = carray_add(md->mdir_msg_list, msg, &i); 287 r = carray_add(md->mdir_msg_list, msg, &i);
282 if (r < 0) { 288 if (r < 0) {
283 res = MAILDIR_ERROR_MEMORY; 289 res = MAILDIR_ERROR_MEMORY;
284 goto free_msg; 290 goto free_msg;
285 } 291 }
286 292
287 key.data = msg->msg_uid; 293 key.data = msg->msg_uid;
288 key.len = strlen(msg->msg_uid); 294 key.len = strlen(msg->msg_uid);
289 value.data = msg; 295 value.data = msg;
290 value.len = 0; 296 value.len = 0;
291 297
292 r = chash_set(md->mdir_msg_hash, &key, &value, NULL); 298 r = chash_set(md->mdir_msg_hash, &key, &value, NULL);
293 if (r < 0) { 299 if (r < 0) {
294 res = MAILDIR_ERROR_MEMORY; 300 res = MAILDIR_ERROR_MEMORY;
295 goto delete; 301 goto delete;
296 } 302 }
297 303
298 return MAILDIR_NO_ERROR; 304 return MAILDIR_NO_ERROR;
299 305
300 delete: 306 delete:
301 carray_delete(md->mdir_msg_list, i); 307 carray_delete(md->mdir_msg_list, i);
302 free_msg: 308 free_msg:
303 msg_free(msg); 309 msg_free(msg);
304 err: 310 err:
305 return res; 311 return res;
306} 312}
307 313
308static int add_directory(struct maildir * md, char * path, int is_new) 314static int add_directory(struct maildir * md, char * path, int is_new)
309{ 315{
310 DIR * d; 316 DIR * d;
311 struct dirent * entry; 317 struct dirent * entry;
312 int res; 318 int res;
313 int r; 319 int r;
314 char filename[PATH_MAX]; 320 char filename[PATH_MAX];
315 321
316 d = opendir(path); 322 d = opendir(path);
317 if (d == NULL) { 323 if (d == NULL) {
318 res = MAILDIR_ERROR_DIRECTORY; 324 res = MAILDIR_ERROR_DIRECTORY;
319 goto err; 325 goto err;
320 } 326 }
321 327
322 while ((entry = readdir(d)) != NULL) { 328 while ((entry = readdir(d)) != NULL) {
323 struct stat stat_info; 329 struct stat stat_info;
324 330
325 snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name); 331 snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name);
326 r = stat(filename, &stat_info); 332 r = stat(filename, &stat_info);
327 if (r < 0) 333 if (r < 0)
328 continue; 334 continue;
329 335
330 if (S_ISDIR(stat_info.st_mode)) 336 if (S_ISDIR(stat_info.st_mode))
331 continue; 337 continue;
332 338
333 r = add_message(md, entry->d_name, is_new); 339 r = add_message(md, entry->d_name, is_new);
334 if (r != MAILDIR_NO_ERROR) { 340 if (r != MAILDIR_NO_ERROR) {
335 /* ignore errors */ 341 /* ignore errors */
336 } 342 }
337 } 343 }
338 344
339 closedir(d); 345 closedir(d);
340 346
341 return MAILDIR_NO_ERROR; 347 return MAILDIR_NO_ERROR;
342 348
343 err: 349 err:
344 return res; 350 return res;
345} 351}
346 352
347int maildir_update(struct maildir * md) 353int maildir_update(struct maildir * md)
348{ 354{
349 struct stat stat_info; 355 struct stat stat_info;
350 char path_new[PATH_MAX]; 356 char path_new[PATH_MAX];
351 char path_cur[PATH_MAX]; 357 char path_cur[PATH_MAX];
352 int r; 358 int r;
353 int res; 359 int res;
354 360
355 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); 361 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path);
356 snprintf(path_cur, sizeof(path_cur), "%s/cur", md->mdir_path); 362 snprintf(path_cur, sizeof(path_cur), "%s/cur", md->mdir_path);
357 363
358 /* did new/ changed ? */ 364 /* did new/ changed ? */
359 365
360 r = stat(path_new, &stat_info); 366 r = stat(path_new, &stat_info);
361 if (r < 0) { 367 if (r < 0) {
362 res = MAILDIR_ERROR_DIRECTORY; 368 res = MAILDIR_ERROR_DIRECTORY;
363 goto free; 369 goto free;
364 } 370 }
365 371
366 if (md->mdir_mtime_new != stat_info.st_mtime) { 372 if (md->mdir_mtime_new != stat_info.st_mtime) {
367 md->mdir_mtime_new = stat_info.st_mtime; 373 md->mdir_mtime_new = stat_info.st_mtime;
368 374
369 maildir_flush(md, 1); 375 maildir_flush(md, 1);
370 376
371 /* messages in new */ 377 /* messages in new */
372 r = add_directory(md, path_new, 1); 378 r = add_directory(md, path_new, 1);
373 if (r != MAILDIR_NO_ERROR) { 379 if (r != MAILDIR_NO_ERROR) {
374 res = r; 380 res = r;
375 goto free; 381 goto free;
376 } 382 }
377 } 383 }
378 384
379 /* did cur/ changed ? */ 385 /* did cur/ changed ? */
380 386
381 r = stat(path_cur, &stat_info); 387 r = stat(path_cur, &stat_info);
382 if (r < 0) { 388 if (r < 0) {
383 res = MAILDIR_ERROR_DIRECTORY; 389 res = MAILDIR_ERROR_DIRECTORY;
384 goto free; 390 goto free;
385 } 391 }
386 392
387 if (md->mdir_mtime_cur != stat_info.st_mtime) { 393 if (md->mdir_mtime_cur != stat_info.st_mtime) {
388 md->mdir_mtime_cur = stat_info.st_mtime; 394 md->mdir_mtime_cur = stat_info.st_mtime;
389 395
390 maildir_flush(md, 0); 396 maildir_flush(md, 0);
391 397
392 /* messages in cur */ 398 /* messages in cur */
393 r = add_directory(md, path_cur, 0); 399 r = add_directory(md, path_cur, 0);
394 if (r != MAILDIR_NO_ERROR) { 400 if (r != MAILDIR_NO_ERROR) {
395 res = r; 401 res = r;
396 goto free; 402 goto free;
397 } 403 }
398 } 404 }
399 405
400 return MAILDIR_NO_ERROR; 406 return MAILDIR_NO_ERROR;
401 407
402 free: 408 free:
403 maildir_flush(md, 0); 409 maildir_flush(md, 0);
404 maildir_flush(md, 1); 410 maildir_flush(md, 1);
405 md->mdir_mtime_cur = (time_t) -1; 411 md->mdir_mtime_cur = (time_t) -1;
406 md->mdir_mtime_new = (time_t) -1; 412 md->mdir_mtime_new = (time_t) -1;
407 return res; 413 return res;
408} 414}
409 415
410#ifndef LIBETPAN_SYSTEM_BASENAME 416#ifndef LIBETPAN_SYSTEM_BASENAME
411static char * libetpan_basename(char * filename) 417static char * libetpan_basename(char * filename)
412{ 418{
413 char * next; 419 char * next;
414 char * p; 420 char * p;
415 421
416 p = filename; 422 p = filename;
417 next = strchr(p, '/'); 423 next = strchr(p, '/');
418 424
419 while (next != NULL) { 425 while (next != NULL) {
420 p = next; 426 p = next;
421 next = strchr(p + 1, '/'); 427 next = strchr(p + 1, '/');
422 } 428 }
423 429
424 if (p == filename) 430 if (p == filename)
425 return filename; 431 return filename;
426 else 432 else
427 return p + 1; 433 return p + 1;
428} 434}
429#else 435#else
430#define libetpan_basename(a) basename(a) 436#define libetpan_basename(a) basename(a)
431#endif 437#endif
432 438
433int maildir_message_add_uid(struct maildir * md, 439int maildir_message_add_uid(struct maildir * md,
434 const char * message, size_t size, 440 const char * message, size_t size,
435 char * uid, size_t max_uid_len) 441 char * uid, size_t max_uid_len)
436{ 442{
437 char path_new[PATH_MAX]; 443 char path_new[PATH_MAX];
438 char tmpname[PATH_MAX]; 444 char tmpname[PATH_MAX];
439 int fd; 445 int fd;
440 int r; 446 int r;
441 char * mapping; 447 char * mapping;
442 char * delivery_tmp_name; 448 char * delivery_tmp_name;
443 char * delivery_tmp_basename; 449 char * delivery_tmp_basename;
444 char delivery_new_name[PATH_MAX]; 450 char delivery_new_name[PATH_MAX];
445 char * delivery_new_basename; 451 char * delivery_new_basename;
446 int res; 452 int res;
447 struct stat stat_info; 453 struct stat stat_info;
448 454
455 fprintf(stderr,"maildir_message_add_uid for uid: %s \n", uid);
449 r = maildir_update(md); 456 r = maildir_update(md);
450 if (r != MAILDIR_NO_ERROR) { 457 if (r != MAILDIR_NO_ERROR) {
451 res = r; 458 res = r;
452 goto err; 459 goto err;
453 } 460 }
454 461
455 /* write to tmp/ with a classic temporary file */ 462 /* write to tmp/ with a classic temporary file */
456 463
457 snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", 464 snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX",
458 md->mdir_path); 465 md->mdir_path);
459 fd = mkstemp(tmpname); 466 fd = mkstemp(tmpname);
460 if (fd < 0) { 467 if (fd < 0) {
461 res = MAILDIR_ERROR_FILE; 468 res = MAILDIR_ERROR_FILE;
462 goto err; 469 goto err;
463 } 470 }
464 471
465 r = ftruncate(fd, size); 472 r = ftruncate(fd, size);
466 if (r < 0) { 473 if (r < 0) {
467 res = MAILDIR_ERROR_FILE; 474 res = MAILDIR_ERROR_FILE;
468 goto close; 475 goto close;
469 } 476 }
470 477
471 mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 478 mapping = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
472 if (mapping == MAP_FAILED) { 479 if (mapping == MAP_FAILED) {
473 res = MAILDIR_ERROR_FILE; 480 res = MAILDIR_ERROR_FILE;
474 goto close; 481 goto close;
475 } 482 }
476 483
477 memcpy(mapping, message, size); 484 memcpy(mapping, message, size);
478 485
479 msync(mapping, size, MS_SYNC); 486 msync(mapping, size, MS_SYNC);
480 munmap(mapping, size); 487 munmap(mapping, size);
481 488
482 close(fd); 489 close(fd);
483 490
484 /* write to tmp/ with maildir standard name */ 491 /* write to tmp/ with maildir standard name */
485 492
486 delivery_tmp_name = maildir_get_new_message_filename(md, tmpname); 493 delivery_tmp_name = maildir_get_new_message_filename(md, tmpname);
487 if (delivery_tmp_name == NULL) { 494 if (delivery_tmp_name == NULL) {
488 res = MAILDIR_ERROR_FILE; 495 res = MAILDIR_ERROR_FILE;
489 goto unlink; 496 goto unlink;
490 } 497 }
491 498
492 /* write to new/ with maildir standard name */ 499 /* write to new/ with maildir standard name */
493 500
494 strncpy(tmpname, delivery_tmp_name, sizeof(tmpname)); 501 strncpy(tmpname, delivery_tmp_name, sizeof(tmpname));
495 tmpname[sizeof(tmpname) - 1] = '\0'; 502 tmpname[sizeof(tmpname) - 1] = '\0';
496 503
497 delivery_tmp_basename = libetpan_basename(tmpname); 504 delivery_tmp_basename = libetpan_basename(tmpname);
498 505
499 snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s", 506 snprintf(delivery_new_name, sizeof(delivery_new_name), "%s/new/%s",
500 md->mdir_path, delivery_tmp_basename); 507 md->mdir_path, delivery_tmp_basename);
501 508
502 r = link(delivery_tmp_name, delivery_new_name); 509 r = link(delivery_tmp_name, delivery_new_name);
503 if (r < 0) { 510 if (r < 0) {
504 res = MAILDIR_ERROR_FILE; 511 res = MAILDIR_ERROR_FILE;
505 goto unlink_tmp; 512 goto unlink_tmp;
506 } 513 }
507 514
508 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path); 515 snprintf(path_new, sizeof(path_new), "%s/new", md->mdir_path);
509 r = stat(path_new, &stat_info); 516 r = stat(path_new, &stat_info);
510 if (r < 0) { 517 if (r < 0) {
511 unlink(delivery_new_name); 518 unlink(delivery_new_name);
512 res = MAILDIR_ERROR_FILE; 519 res = MAILDIR_ERROR_FILE;
513 goto unlink_tmp; 520 goto unlink_tmp;
514 } 521 }
515 522
516 md->mdir_mtime_new = stat_info.st_mtime; 523 md->mdir_mtime_new = stat_info.st_mtime;
517 524
518 delivery_new_basename = libetpan_basename(delivery_new_name); 525 delivery_new_basename = libetpan_basename(delivery_new_name);
519 526
520 r = add_message(md, delivery_new_basename, 1); 527 r = add_message(md, delivery_new_basename, 1);
521 if (r != MAILDIR_NO_ERROR) { 528 if (r != MAILDIR_NO_ERROR) {
522 unlink(delivery_new_name); 529 unlink(delivery_new_name);
523 res = MAILDIR_ERROR_FILE; 530 res = MAILDIR_ERROR_FILE;
524 goto unlink_tmp; 531 goto unlink_tmp;
525 } 532 }
526 533
527 if (uid != NULL) 534 if (uid != NULL)
528 strncpy(uid, delivery_new_basename, max_uid_len); 535 strncpy(uid, delivery_new_basename, max_uid_len);
529 536
530 unlink(delivery_tmp_name); 537 unlink(delivery_tmp_name);
531 free(delivery_tmp_name); 538 free(delivery_tmp_name);
532 539
533 return MAILDIR_NO_ERROR; 540 return MAILDIR_NO_ERROR;
534 541
535 unlink_tmp: 542 unlink_tmp:
536 unlink(delivery_tmp_name); 543 unlink(delivery_tmp_name);
537 free(delivery_tmp_name); 544 free(delivery_tmp_name);
538 goto err; 545 goto err;
539 close: 546 close:
540 close(fd); 547 close(fd);
541 unlink: 548 unlink:
542 unlink(tmpname); 549 unlink(tmpname);
543 err: 550 err:
544 return res; 551 return res;
545} 552}
546 553
547int maildir_message_add(struct maildir * md, 554int maildir_message_add(struct maildir * md,
548 const char * message, size_t size) 555 const char * message, size_t size)
549{ 556{
550 return maildir_message_add_uid(md, message, size, 557 return maildir_message_add_uid(md, message, size,
551 NULL, 0); 558 NULL, 0);
552} 559}
553 560
554int maildir_message_add_file_uid(struct maildir * md, int fd, 561int maildir_message_add_file_uid(struct maildir * md, int fd,
555 char * uid, size_t max_uid_len) 562 char * uid, size_t max_uid_len)
556{ 563{
557 char * message; 564 char * message;
558 struct stat buf; 565 struct stat buf;
559 int r; 566 int r;
560 567
568 fprintf(stderr,"maildir_message_add_file_uid: %s \n", uid);
561 if (fstat(fd, &buf) == -1) 569 if (fstat(fd, &buf) == -1)
562 return MAILDIR_ERROR_FILE; 570 return MAILDIR_ERROR_FILE;
563 571
564 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 572 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
565 if (message == MAP_FAILED) 573 if (message == MAP_FAILED)
566 return MAILDIR_ERROR_FILE; 574 return MAILDIR_ERROR_FILE;
567 575
568 r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len); 576 r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len);
569 577
570 munmap(message, buf.st_size); 578 munmap(message, buf.st_size);
571 579
572 return r; 580 return r;
573} 581}
574 582
575int maildir_message_add_file(struct maildir * md, int fd) 583int maildir_message_add_file(struct maildir * md, int fd)
576{ 584{
585 fprintf(stderr,"maildir_message_add_file \n");
577 return maildir_message_add_file_uid(md, fd, 586 return maildir_message_add_file_uid(md, fd,
578 NULL, 0); 587 NULL, 0);
579} 588}
580 589
581char * maildir_message_get(struct maildir * md, const char * uid) 590char * maildir_message_get(struct maildir * md, const char * uid)
582{ 591{
583 chashdatum key; 592 chashdatum key;
584 chashdatum value; 593 chashdatum value;
585 char filename[PATH_MAX]; 594 char filename[PATH_MAX];
586 char * dup_filename; 595 char * dup_filename;
587 struct maildir_msg * msg; 596 struct maildir_msg * msg;
588 char * dir; 597 char * dir;
589 int r; 598 int r;
590 599
600 fprintf(stderr,"maildir_message_get for uid: %s \n", uid);
591 key.data = (void *) uid; 601 key.data = (void *) uid;
592 key.len = strlen(uid); 602 key.len = strlen(uid);
593 r = chash_get(md->mdir_msg_hash, &key, &value); 603 r = chash_get(md->mdir_msg_hash, &key, &value);
594 if (r < 0) 604 if (r < 0)
595 return NULL; 605 return NULL;
596 606
597 msg = value.data; 607 msg = value.data;
598 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 608 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
599 dir = "new"; 609 dir = "new";
600 else 610 else
601 dir = "cur"; 611 dir = "cur";
602 612
603 snprintf(filename, sizeof(filename), "%s/%s/%s", 613 snprintf(filename, sizeof(filename), "%s/%s/%s",
604 md->mdir_path, dir, msg->msg_filename); 614 md->mdir_path, dir, msg->msg_filename);
605 615
606 dup_filename = strdup(filename); 616 dup_filename = strdup(filename);
607 if (dup_filename == NULL) 617 if (dup_filename == NULL)
608 return NULL; 618 return NULL;
609 619
610 return dup_filename; 620 return dup_filename;
611} 621}
612 622
613int maildir_message_remove(struct maildir * md, const char * uid) 623int maildir_message_remove(struct maildir * md, const char * uid)
614{ 624{
615 chashdatum key; 625 chashdatum key;
616 chashdatum value; 626 chashdatum value;
617 char filename[PATH_MAX]; 627 char filename[PATH_MAX];
618 struct maildir_msg * msg; 628 struct maildir_msg * msg;
619 char * dir; 629 char * dir;
620 int r; 630 int r;
621 int res; 631 int res;
622 632
633 fprintf(stderr,"maildir_message_remove for uid: %s \n", uid);
623 key.data = (void *) uid; 634 key.data = (void *) uid;
624 key.len = strlen(uid); 635 key.len = strlen(uid);
625 r = chash_get(md->mdir_msg_hash, &key, &value); 636 r = chash_get(md->mdir_msg_hash, &key, &value);
626 if (r < 0) { 637 if (r < 0) {
627 res = MAILDIR_ERROR_NOT_FOUND; 638 res = MAILDIR_ERROR_NOT_FOUND;
628 goto err; 639 goto err;
629 } 640 }
630 641
631 msg = value.data; 642 msg = value.data;
632 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 643 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
633 dir = "new"; 644 dir = "new";
634 else 645 else
635 dir = "cur"; 646 dir = "cur";
636 647
637 snprintf(filename, sizeof(filename), "%s/%s/%s", 648 snprintf(filename, sizeof(filename), "%s/%s/%s",
638 md->mdir_path, dir, msg->msg_filename); 649 md->mdir_path, dir, msg->msg_filename);
639 650
640 r = unlink(filename); 651 r = unlink(filename);
641 if (r < 0) { 652 if (r < 0) {
642 res = MAILDIR_ERROR_FILE; 653 res = MAILDIR_ERROR_FILE;
643 goto err; 654 goto err;
644 } 655 }
645 656
646 return MAILDIR_NO_ERROR; 657 return MAILDIR_NO_ERROR;
647 658
648 err: 659 err:
649 return res; 660 return res;
650} 661}
651 662
652int maildir_message_change_flags(struct maildir * md, 663int maildir_message_change_flags(struct maildir * md,
653 const char * uid, int new_flags) 664 const char * uid, int new_flags)
654{ 665{
655 chashdatum key; 666 chashdatum key;
656 chashdatum value; 667 chashdatum value;
657 char filename[PATH_MAX]; 668 char filename[PATH_MAX];
658 struct maildir_msg * msg; 669 struct maildir_msg * msg;
659 char * dir; 670 char * dir;
660 int r; 671 int r;
661 char new_filename[PATH_MAX]; 672 char new_filename[PATH_MAX];
662 char flag_str[5]; 673 char flag_str[5];
663 size_t i; 674 size_t i;
664 int res; 675 int res;
665 676 fprintf(stderr,"maildir_message_change_flags for uid: %s \n", uid);
666 key.data = (void *) uid; 677 key.data = (void *) uid;
667 key.len = strlen(uid); 678 key.len = strlen(uid);
668 r = chash_get(md->mdir_msg_hash, &key, &value); 679 r = chash_get(md->mdir_msg_hash, &key, &value);
669 if (r < 0) { 680 if (r < 0) {
670 res = MAILDIR_ERROR_NOT_FOUND; 681 res = MAILDIR_ERROR_NOT_FOUND;
671 goto err; 682 goto err;
672 } 683 }
673 684
674 msg = value.data; 685 msg = value.data;
675 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) 686 if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0)
676 dir = "new"; 687 dir = "new";
677 else 688 else
678 dir = "cur"; 689 dir = "cur";
679 690
680 snprintf(filename, sizeof(filename), "%s/%s/%s", 691 snprintf(filename, sizeof(filename), "%s/%s/%s",
681 md->mdir_path, dir, msg->msg_filename); 692 md->mdir_path, dir, msg->msg_filename);
682 693
683 if ((new_flags & MAILDIR_FLAG_NEW) != 0) 694 if ((new_flags & MAILDIR_FLAG_NEW) != 0)
684 dir = "new"; 695 dir = "new";
685 else 696 else
686 dir = "cur"; 697 dir = "cur";
687 698
688 i = 0; 699 i = 0;
689 if ((new_flags & MAILDIR_FLAG_SEEN) != 0) { 700 if ((new_flags & MAILDIR_FLAG_SEEN) != 0) {
690 flag_str[i] = 'S'; 701 flag_str[i] = 'S';
691 i ++; 702 i ++;
692 } 703 }
693 if ((new_flags & MAILDIR_FLAG_REPLIED) != 0) { 704 if ((new_flags & MAILDIR_FLAG_REPLIED) != 0) {
694 flag_str[i] = 'R'; 705 flag_str[i] = 'R';
695 i ++; 706 i ++;
696 } 707 }
697 if ((new_flags & MAILDIR_FLAG_FLAGGED) != 0) { 708 if ((new_flags & MAILDIR_FLAG_FLAGGED) != 0) {
698 flag_str[i] = 'F'; 709 flag_str[i] = 'F';
699 i ++; 710 i ++;
700 } 711 }
701 if ((new_flags & MAILDIR_FLAG_TRASHED) != 0) { 712 if ((new_flags & MAILDIR_FLAG_TRASHED) != 0) {
702 flag_str[i] = 'T'; 713 flag_str[i] = 'T';
703 i ++; 714 i ++;
704 } 715 }
705 flag_str[i] = 0; 716 flag_str[i] = 0;
706 717
707 if (flag_str[0] == '\0') 718 if (flag_str[0] == '\0')
708 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s", 719 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s",
709 md->mdir_path, dir, msg->msg_uid); 720 md->mdir_path, dir, msg->msg_uid);
710 else 721 else
711 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s:2,%s", 722 snprintf(new_filename, sizeof(new_filename), "%s/%s/%s:2,%s",
712 md->mdir_path, dir, msg->msg_uid, flag_str); 723 md->mdir_path, dir, msg->msg_uid, flag_str);
713 724
714 if (strcmp(filename, new_filename) == 0) 725 if (strcmp(filename, new_filename) == 0)
715 return MAILDIR_NO_ERROR; 726 return MAILDIR_NO_ERROR;
716 727
717 r = link(filename, new_filename); 728 r = link(filename, new_filename);
718 if (r < 0) { 729 if (r < 0) {
719 res = MAILDIR_ERROR_FILE; 730 res = MAILDIR_ERROR_FILE;
720 goto err; 731 goto err;
721 } 732 }
722 733
723 unlink(filename); 734 unlink(filename);
724 735
725 return MAILDIR_NO_ERROR; 736 return MAILDIR_NO_ERROR;
726 737
727 err: 738 err:
728 return res; 739 return res;
729} 740}
diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c
index 119f217..5e2b4cc 100644
--- a/kmicromail/libetpan/mh/mailmh.c
+++ b/kmicromail/libetpan/mh/mailmh.c
@@ -1,981 +1,985 @@
1/* 1/*
2 * libEtPan! -- a mail stuff library 2 * libEtPan! -- a mail stuff library
3 * 3 *
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa 4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36#include "mailmh.h" 36#include "mailmh.h"
37 37
38/* 38/*
39perfs : 39perfs :
40 40
41/net/home/dinh/Mail/inbox/sylpheed 686 41/net/home/dinh/Mail/inbox/sylpheed 686
42 42
432724 /net/home/dinh/Mail/inbox/sylpheed 432724 /net/home/dinh/Mail/inbox/sylpheed
44 44
45bart:~/LibEtPan/libetpan/tests> time ./mhtest >/dev/null 45bart:~/LibEtPan/libetpan/tests> time ./mhtest >/dev/null
46 46
47real 0m0.385s 47real 0m0.385s
48user 0m0.270s 48user 0m0.270s
49sys 0m0.110s 49sys 0m0.110s
50 50
51*/ 51*/
52 52
53#include <dirent.h> 53#include <dirent.h>
54#include <sys/stat.h> 54#include <sys/stat.h>
55#include <errno.h> 55#include <errno.h>
56#include <unistd.h> 56#include <unistd.h>
57#include <sys/mman.h> 57#include <sys/mman.h>
58#include <fcntl.h> 58#include <fcntl.h>
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62 62
63#include "libetpan-config.h" 63#include "libetpan-config.h"
64 64
65struct mailmh * mailmh_new(const char * foldername) 65struct mailmh * mailmh_new(const char * foldername)
66{ 66{
67 struct mailmh * f; 67 struct mailmh * f;
68 68
69 f = malloc(sizeof(*f)); 69 f = malloc(sizeof(*f));
70 if (f == NULL) 70 if (f == NULL)
71 return NULL; 71 return NULL;
72 72
73 f->mh_main = mailmh_folder_new(NULL, foldername); 73 f->mh_main = mailmh_folder_new(NULL, foldername);
74 if (f->mh_main == NULL) { 74 if (f->mh_main == NULL) {
75 free(f); 75 free(f);
76 return NULL; 76 return NULL;
77 } 77 }
78 78
79 return f; 79 return f;
80} 80}
81 81
82void mailmh_free(struct mailmh * f) 82void mailmh_free(struct mailmh * f)
83{ 83{
84 mailmh_folder_free(f->mh_main); 84 mailmh_folder_free(f->mh_main);
85 free(f); 85 free(f);
86} 86}
87 87
88 88
89 89
90struct mailmh_msg_info * mailmh_msg_info_new(uint32_t index, size_t size, 90struct mailmh_msg_info * mailmh_msg_info_new(uint32_t index, size_t size,
91 time_t mtime) 91 time_t mtime)
92{ 92{
93 struct mailmh_msg_info * msg_info; 93 struct mailmh_msg_info * msg_info;
94 94
95 msg_info = malloc(sizeof(* msg_info)); 95 msg_info = malloc(sizeof(* msg_info));
96 if (msg_info == NULL) 96 if (msg_info == NULL)
97 return NULL; 97 return NULL;
98 msg_info->msg_index = index; 98 msg_info->msg_index = index;
99 msg_info->msg_size = size; 99 msg_info->msg_size = size;
100 msg_info->msg_mtime = mtime; 100 msg_info->msg_mtime = mtime;
101 101
102 msg_info->msg_array_index = 0; 102 msg_info->msg_array_index = 0;
103 103
104 return msg_info; 104 return msg_info;
105} 105}
106 106
107void mailmh_msg_info_free(struct mailmh_msg_info * msg_info) 107void mailmh_msg_info_free(struct mailmh_msg_info * msg_info)
108{ 108{
109 free(msg_info); 109 free(msg_info);
110} 110}
111 111
112struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent, 112struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent,
113 const char * name) 113 const char * name)
114{ 114{
115 char * filename; 115 char * filename;
116 char * parent_filename; 116 char * parent_filename;
117 117
118 struct mailmh_folder * folder; 118 struct mailmh_folder * folder;
119 119
120 folder = malloc(sizeof(* folder)); 120 folder = malloc(sizeof(* folder));
121 if (folder == NULL) 121 if (folder == NULL)
122 goto err; 122 goto err;
123 123
124 if (parent == NULL) { 124 if (parent == NULL) {
125 filename = strdup(name); 125 filename = strdup(name);
126 if (filename == NULL) 126 if (filename == NULL)
127 goto free_folder; 127 goto free_folder;
128 } 128 }
129 else { 129 else {
130 parent_filename = parent->fl_filename; 130 parent_filename = parent->fl_filename;
131 filename = malloc(strlen(parent_filename) + strlen(name) + 2); 131 filename = malloc(strlen(parent_filename) + strlen(name) + 2);
132 if (filename == NULL) 132 if (filename == NULL)
133 goto free_folder; 133 goto free_folder;
134 134
135 strcpy(filename, parent_filename); 135 strcpy(filename, parent_filename);
136 strcat(filename, MAIL_DIR_SEPARATOR_S); 136 strcat(filename, MAIL_DIR_SEPARATOR_S);
137 strcat(filename, name); 137 strcat(filename, name);
138 } 138 }
139 139
140 folder->fl_filename = filename; 140 folder->fl_filename = filename;
141 141
142 folder->fl_name = strdup(name); 142 folder->fl_name = strdup(name);
143 if (folder->fl_name == NULL) 143 if (folder->fl_name == NULL)
144 goto free_filename; 144 goto free_filename;
145 145
146 folder->fl_msgs_tab = carray_new(128); 146 folder->fl_msgs_tab = carray_new(128);
147 if (folder->fl_msgs_tab == NULL) 147 if (folder->fl_msgs_tab == NULL)
148 goto free_name; 148 goto free_name;
149 149
150#if 0 150#if 0
151 folder->fl_msgs_hash = cinthash_new(128); 151 folder->fl_msgs_hash = cinthash_new(128);
152 if (folder->fl_msgs_hash == NULL) 152 if (folder->fl_msgs_hash == NULL)
153 goto free_msgs_tab; 153 goto free_msgs_tab;
154#endif 154#endif
155 folder->fl_msgs_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY); 155 folder->fl_msgs_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY);
156 if (folder->fl_msgs_hash == NULL) 156 if (folder->fl_msgs_hash == NULL)
157 goto free_msgs_tab; 157 goto free_msgs_tab;
158 158
159 folder->fl_subfolders_tab = carray_new(128); 159 folder->fl_subfolders_tab = carray_new(128);
160 if (folder->fl_subfolders_tab == NULL) 160 if (folder->fl_subfolders_tab == NULL)
161 goto free_msgs_hash; 161 goto free_msgs_hash;
162 162
163 folder->fl_subfolders_hash = chash_new(128, CHASH_COPYNONE); 163 folder->fl_subfolders_hash = chash_new(128, CHASH_COPYNONE);
164 if (folder->fl_subfolders_hash == NULL) 164 if (folder->fl_subfolders_hash == NULL)
165 goto free_subfolders_tab; 165 goto free_subfolders_tab;
166 166
167 folder->fl_mtime = 0; 167 folder->fl_mtime = 0;
168 folder->fl_parent = parent; 168 folder->fl_parent = parent;
169 folder->fl_max_index = 0; 169 folder->fl_max_index = 0;
170 170
171 return folder; 171 return folder;
172 172
173 free_subfolders_tab: 173 free_subfolders_tab:
174 carray_free(folder->fl_subfolders_tab); 174 carray_free(folder->fl_subfolders_tab);
175 free_msgs_hash: 175 free_msgs_hash:
176#if 0 176#if 0
177 cinthash_free(folder->fl_msgs_hash); 177 cinthash_free(folder->fl_msgs_hash);
178#endif 178#endif
179 chash_free(folder->fl_msgs_hash); 179 chash_free(folder->fl_msgs_hash);
180 free_msgs_tab: 180 free_msgs_tab:
181 carray_free(folder->fl_msgs_tab); 181 carray_free(folder->fl_msgs_tab);
182 free_name: 182 free_name:
183 free(folder->fl_name); 183 free(folder->fl_name);
184 free_filename: 184 free_filename:
185 free(folder->fl_filename); 185 free(folder->fl_filename);
186 free_folder: 186 free_folder:
187 free(folder); 187 free(folder);
188 err: 188 err:
189 return NULL; 189 return NULL;
190} 190}
191 191
192void mailmh_folder_free(struct mailmh_folder * folder) 192void mailmh_folder_free(struct mailmh_folder * folder)
193{ 193{
194 unsigned int i; 194 unsigned int i;
195 195
196 for(i = 0 ; i < carray_count(folder->fl_subfolders_tab) ; i++) { 196 for(i = 0 ; i < carray_count(folder->fl_subfolders_tab) ; i++) {
197 struct mailmh_folder * subfolder; 197 struct mailmh_folder * subfolder;
198 198
199 subfolder = carray_get(folder->fl_subfolders_tab, i); 199 subfolder = carray_get(folder->fl_subfolders_tab, i);
200 if (subfolder != NULL) 200 if (subfolder != NULL)
201 mailmh_folder_free(subfolder); 201 mailmh_folder_free(subfolder);
202 } 202 }
203 carray_free(folder->fl_subfolders_tab); 203 carray_free(folder->fl_subfolders_tab);
204 chash_free(folder->fl_subfolders_hash); 204 chash_free(folder->fl_subfolders_hash);
205 205
206 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) { 206 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i++) {
207 struct mailmh_msg_info * msg_info; 207 struct mailmh_msg_info * msg_info;
208 208
209 msg_info = carray_get(folder->fl_msgs_tab, i); 209 msg_info = carray_get(folder->fl_msgs_tab, i);
210 if (msg_info != NULL) 210 if (msg_info != NULL)
211 mailmh_msg_info_free(msg_info); 211 mailmh_msg_info_free(msg_info);
212 } 212 }
213 carray_free(folder->fl_msgs_tab); 213 carray_free(folder->fl_msgs_tab);
214 chash_free(folder->fl_msgs_hash); 214 chash_free(folder->fl_msgs_hash);
215#if 0 215#if 0
216 cinthash_free(folder->fl_msgs_hash); 216 cinthash_free(folder->fl_msgs_hash);
217#endif 217#endif
218 218
219 free(folder->fl_filename); 219 free(folder->fl_filename);
220 free(folder->fl_name); 220 free(folder->fl_name);
221 221
222 free(folder); 222 free(folder);
223} 223}
224 224
225struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root, 225struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
226 const char * filename) 226 const char * filename)
227{ 227{
228 int r; 228 int r;
229 char pathname[PATH_MAX]; 229 char pathname[PATH_MAX];
230 char * p; 230 char * p;
231 chashdatum key; 231 chashdatum key;
232 chashdatum data; 232 chashdatum data;
233 struct mailmh_folder * folder; 233 struct mailmh_folder * folder;
234 char * start; 234 char * start;
235 235
236 if (strcmp(root->fl_filename, filename) == 0) 236 if (strcmp(root->fl_filename, filename) == 0)
237 return root; 237 return root;
238 238
239#if 0 239#if 0
240 r = mailmh_folder_update(root); 240 r = mailmh_folder_update(root);
241 if (r != MAILMH_NO_ERROR) 241 if (r != MAILMH_NO_ERROR)
242 return NULL; 242 return NULL;
243#endif 243#endif
244 244
245#if 0 245#if 0
246 for(i = 0 ; i < root->fl_subfolders_tab->len ; i++) { 246 for(i = 0 ; i < root->fl_subfolders_tab->len ; i++) {
247 struct mailmh_folder * subfolder; 247 struct mailmh_folder * subfolder;
248 248
249 subfolder = carray_get(root->fl_subfolders_tab, i); 249 subfolder = carray_get(root->fl_subfolders_tab, i);
250 if (subfolder != NULL) 250 if (subfolder != NULL)
251 if (strncmp(subfolder->fl_filename, filename, 251 if (strncmp(subfolder->fl_filename, filename,
252 strlen(subfolder->fl_filename)) == 0) 252 strlen(subfolder->fl_filename)) == 0)
253 return mailmh_folder_find(subfolder, filename); 253 return mailmh_folder_find(subfolder, filename);
254 } 254 }
255#endif 255#endif
256 strncpy(pathname, filename, PATH_MAX); 256 strncpy(pathname, filename, PATH_MAX);
257 pathname[PATH_MAX - 1] = 0; 257 pathname[PATH_MAX - 1] = 0;
258 start = pathname + strlen(root->fl_filename) + 1; 258 start = pathname + strlen(root->fl_filename) + 1;
259 259
260 p = strchr(start, MAIL_DIR_SEPARATOR); 260 p = strchr(start, MAIL_DIR_SEPARATOR);
261 if (p != NULL) { 261 if (p != NULL) {
262 * p = 0; 262 * p = 0;
263 263
264 root = mailmh_folder_find(root, pathname); 264 root = mailmh_folder_find(root, pathname);
265 if (root != NULL) { 265 if (root != NULL) {
266 folder = mailmh_folder_find(root, filename); 266 folder = mailmh_folder_find(root, filename);
267 if (folder == NULL) 267 if (folder == NULL)
268 return NULL; 268 return NULL;
269 return folder; 269 return folder;
270 } 270 }
271 271
272 return NULL; 272 return NULL;
273 } 273 }
274 else { 274 else {
275 key.data = pathname; 275 key.data = pathname;
276 key.len = strlen(pathname); 276 key.len = strlen(pathname);
277 r = chash_get(root->fl_subfolders_hash, &key, &data); 277 r = chash_get(root->fl_subfolders_hash, &key, &data);
278 if (r < 0) 278 if (r < 0)
279 return NULL; 279 return NULL;
280 280
281 return data.data; 281 return data.data;
282 } 282 }
283} 283}
284 284
285int mailmh_folder_update(struct mailmh_folder * folder) 285int mailmh_folder_update(struct mailmh_folder * folder)
286{ 286{
287 DIR * d; 287 DIR * d;
288 struct dirent * ent; 288 struct dirent * ent;
289 struct stat buf; 289 struct stat buf;
290 char * mh_seq; 290 char * mh_seq;
291 char filename[PATH_MAX]; 291 char filename[PATH_MAX];
292 int res; 292 int res;
293 int r; 293 int r;
294 uint32_t max_index; 294 uint32_t max_index;
295#if 0 295#if 0
296 int add_folder; 296 int add_folder;
297#endif 297#endif
298 unsigned int i; 298 unsigned int i;
299 299
300 if (stat(folder->fl_filename, &buf) == -1) { 300 if (stat(folder->fl_filename, &buf) == -1) {
301 res = MAILMH_ERROR_FOLDER; 301 res = MAILMH_ERROR_FOLDER;
302 goto err; 302 goto err;
303 } 303 }
304 304
305 if (folder->fl_mtime == buf.st_mtime) { 305 if (folder->fl_mtime == buf.st_mtime) {
306 res = MAILMH_NO_ERROR; 306 res = MAILMH_NO_ERROR;
307 goto err; 307 goto err;
308 } 308 }
309 309
310 folder->fl_mtime = buf.st_mtime; 310 folder->fl_mtime = buf.st_mtime;
311 311
312 d = opendir(folder->fl_filename); 312 d = opendir(folder->fl_filename);
313 if (d == NULL) { 313 if (d == NULL) {
314 res = MAILMH_ERROR_FOLDER; 314 res = MAILMH_ERROR_FOLDER;
315 goto err; 315 goto err;
316 } 316 }
317 317
318 max_index = 0; 318 max_index = 0;
319 319
320#if 0 320#if 0
321 if (folder->fl_subfolders_tab->len == 0) 321 if (folder->fl_subfolders_tab->len == 0)
322 add_folder = 1; 322 add_folder = 1;
323 else 323 else
324 add_folder = 0; 324 add_folder = 0;
325#endif 325#endif
326 326
327 /* clear the message list */ 327 /* clear the message list */
328 328
329 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) { 329 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) {
330 struct mailmh_msg_info * msg_info; 330 struct mailmh_msg_info * msg_info;
331 chashdatum key; 331 chashdatum key;
332 332
333 msg_info = carray_get(folder->fl_msgs_tab, i); 333 msg_info = carray_get(folder->fl_msgs_tab, i);
334 if (msg_info == NULL) 334 if (msg_info == NULL)
335 continue; 335 continue;
336 336
337#if 0 337#if 0
338 cinthash_remove(folder->fl_msgs_hash, msg_info->msg_index); 338 cinthash_remove(folder->fl_msgs_hash, msg_info->msg_index);
339#endif 339#endif
340 key.data = &msg_info->msg_index; 340 key.data = &msg_info->msg_index;
341 key.len = sizeof(msg_info->msg_index); 341 key.len = sizeof(msg_info->msg_index);
342 chash_delete(folder->fl_msgs_hash, &key, NULL); 342 chash_delete(folder->fl_msgs_hash, &key, NULL);
343 343
344 mailmh_msg_info_free(msg_info); 344 mailmh_msg_info_free(msg_info);
345 } 345 }
346 346
347 carray_set_size(folder->fl_msgs_tab, 0); 347 carray_set_size(folder->fl_msgs_tab, 0);
348 348
349 do { 349 do {
350 uint32_t index; 350 uint32_t index;
351 351
352 ent = readdir(d); 352 ent = readdir(d);
353 353
354 if (ent != NULL) { 354 if (ent != NULL) {
355 355
356 snprintf(filename, PATH_MAX, 356 snprintf(filename, PATH_MAX,
357 "%s%c%s", folder->fl_filename, MAIL_DIR_SEPARATOR, ent->d_name); 357 "%s%c%s", folder->fl_filename, MAIL_DIR_SEPARATOR, ent->d_name);
358 358
359 if (stat(filename, &buf) == -1) 359 if (stat(filename, &buf) == -1)
360 continue; 360 continue;
361 361
362 if (S_ISREG(buf.st_mode)) { 362 if (S_ISREG(buf.st_mode)) {
363 index = strtoul(ent->d_name, NULL, 10); 363 index = strtoul(ent->d_name, NULL, 10);
364 if (index != 0) { 364 if (index != 0) {
365 struct mailmh_msg_info * msg_info; 365 struct mailmh_msg_info * msg_info;
366 unsigned int array_index; 366 unsigned int array_index;
367 chashdatum key; 367 chashdatum key;
368 chashdatum data; 368 chashdatum data;
369 369
370 msg_info = mailmh_msg_info_new(index, buf.st_size, buf.st_mtime); 370 msg_info = mailmh_msg_info_new(index, buf.st_size, buf.st_mtime);
371 if (msg_info == NULL) { 371 if (msg_info == NULL) {
372 res = MAILMH_ERROR_MEMORY; 372 res = MAILMH_ERROR_MEMORY;
373 goto closedir; 373 goto closedir;
374 } 374 }
375 375
376 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); 376 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index);
377 if (r < 0) { 377 if (r < 0) {
378 mailmh_msg_info_free(msg_info); 378 mailmh_msg_info_free(msg_info);
379 res = MAILMH_ERROR_MEMORY; 379 res = MAILMH_ERROR_MEMORY;
380 goto closedir; 380 goto closedir;
381 } 381 }
382 msg_info->msg_array_index = array_index; 382 msg_info->msg_array_index = array_index;
383 383
384 if (index > max_index) 384 if (index > max_index)
385 max_index = index; 385 max_index = index;
386 386
387#if 0 387#if 0
388 r = cinthash_add(folder->fl_msgs_hash, msg_info->msg_index, msg_info); 388 r = cinthash_add(folder->fl_msgs_hash, msg_info->msg_index, msg_info);
389#endif 389#endif
390 key.data = &msg_info->msg_index; 390 key.data = &msg_info->msg_index;
391 key.len = sizeof(msg_info->msg_index); 391 key.len = sizeof(msg_info->msg_index);
392 data.data = msg_info; 392 data.data = msg_info;
393 data.len = 0; 393 data.len = 0;
394 394
395 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); 395 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL);
396 if (r < 0) { 396 if (r < 0) {
397 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); 397 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
398 mailmh_msg_info_free(msg_info); 398 mailmh_msg_info_free(msg_info);
399 res = MAILMH_ERROR_MEMORY; 399 res = MAILMH_ERROR_MEMORY;
400 goto closedir; 400 goto closedir;
401 } 401 }
402 } 402 }
403 } 403 }
404 else if (S_ISDIR(buf.st_mode)) { 404 else if (S_ISDIR(buf.st_mode)) {
405 struct mailmh_folder * subfolder; 405 struct mailmh_folder * subfolder;
406 unsigned int array_index; 406 unsigned int array_index;
407 chashdatum key; 407 chashdatum key;
408 chashdatum data; 408 chashdatum data;
409 409
410 if (ent->d_name[0] == '.') { 410 if (ent->d_name[0] == '.') {
411 if (ent->d_name[1] == 0) 411 if (ent->d_name[1] == 0)
412 continue; 412 continue;
413 if ((ent->d_name[1] == '.') && (ent->d_name[2] == 0)) 413 if ((ent->d_name[1] == '.') && (ent->d_name[2] == 0))
414 continue; 414 continue;
415 } 415 }
416 416
417 key.data = ent->d_name; 417 key.data = ent->d_name;
418 key.len = strlen(ent->d_name); 418 key.len = strlen(ent->d_name);
419 r = chash_get(folder->fl_subfolders_hash, &key, &data); 419 r = chash_get(folder->fl_subfolders_hash, &key, &data);
420 if (r < 0) { 420 if (r < 0) {
421 subfolder = mailmh_folder_new(folder, ent->d_name); 421 subfolder = mailmh_folder_new(folder, ent->d_name);
422 if (subfolder == NULL) { 422 if (subfolder == NULL) {
423 res = MAILMH_ERROR_MEMORY; 423 res = MAILMH_ERROR_MEMORY;
424 goto closedir; 424 goto closedir;
425 } 425 }
426 426
427 r = carray_add(folder->fl_subfolders_tab, subfolder, &array_index); 427 r = carray_add(folder->fl_subfolders_tab, subfolder, &array_index);
428 if (r < 0) { 428 if (r < 0) {
429 mailmh_folder_free(subfolder); 429 mailmh_folder_free(subfolder);
430 res = MAILMH_ERROR_MEMORY; 430 res = MAILMH_ERROR_MEMORY;
431 goto closedir; 431 goto closedir;
432 } 432 }
433 subfolder->fl_array_index = array_index; 433 subfolder->fl_array_index = array_index;
434 434
435 key.data = subfolder->fl_filename; 435 key.data = subfolder->fl_filename;
436 key.len = strlen(subfolder->fl_filename); 436 key.len = strlen(subfolder->fl_filename);
437 data.data = subfolder; 437 data.data = subfolder;
438 data.len = 0; 438 data.len = 0;
439 r = chash_set(folder->fl_subfolders_hash, &key, &data, NULL); 439 r = chash_set(folder->fl_subfolders_hash, &key, &data, NULL);
440 if (r < 0) { 440 if (r < 0) {
441 carray_delete_fast(folder->fl_subfolders_tab, subfolder->fl_array_index); 441 carray_delete_fast(folder->fl_subfolders_tab, subfolder->fl_array_index);
442 mailmh_folder_free(subfolder); 442 mailmh_folder_free(subfolder);
443 res = MAILMH_ERROR_MEMORY; 443 res = MAILMH_ERROR_MEMORY;
444 goto closedir; 444 goto closedir;
445 } 445 }
446 } 446 }
447 } 447 }
448 } 448 }
449 } 449 }
450 while (ent != NULL); 450 while (ent != NULL);
451 451
452 folder->fl_max_index = max_index; 452 folder->fl_max_index = max_index;
453 453
454 mh_seq = malloc(strlen(folder->fl_filename) + 2 + sizeof(".mh_sequences")); 454 mh_seq = malloc(strlen(folder->fl_filename) + 2 + sizeof(".mh_sequences"));
455 if (mh_seq == NULL) { 455 if (mh_seq == NULL) {
456 res = MAILMH_ERROR_MEMORY; 456 res = MAILMH_ERROR_MEMORY;
457 goto closedir; 457 goto closedir;
458 } 458 }
459 strcpy(mh_seq, folder->fl_filename); 459 strcpy(mh_seq, folder->fl_filename);
460 strcat(mh_seq, MAIL_DIR_SEPARATOR_S); 460 strcat(mh_seq, MAIL_DIR_SEPARATOR_S);
461 strcat(mh_seq, ".mh_sequences"); 461 strcat(mh_seq, ".mh_sequences");
462 462
463 if (stat(mh_seq, &buf) == -1) { 463 if (stat(mh_seq, &buf) == -1) {
464 int fd; 464 int fd;
465 465
466 fd = creat(mh_seq, S_IRUSR | S_IWUSR); 466 fd = creat(mh_seq, S_IRUSR | S_IWUSR);
467 if (fd != -1) 467 if (fd != -1)
468 close(fd); 468 close(fd);
469 } 469 }
470 free(mh_seq); 470 free(mh_seq);
471 471
472 closedir(d); 472 closedir(d);
473 473
474 return MAILMH_NO_ERROR; 474 return MAILMH_NO_ERROR;
475 475
476 closedir: 476 closedir:
477 closedir(d); 477 closedir(d);
478 err: 478 err:
479 return res; 479 return res;
480} 480}
481 481
482int mailmh_folder_add_subfolder(struct mailmh_folder * parent, 482int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
483 const char * name) 483 const char * name)
484{ 484{
485 char * foldername; 485 char * foldername;
486 int r; 486 int r;
487 struct mailmh_folder * folder; 487 struct mailmh_folder * folder;
488 unsigned int array_index; 488 unsigned int array_index;
489 chashdatum key; 489 chashdatum key;
490 chashdatum data; 490 chashdatum data;
491 491
492 foldername = malloc(strlen(parent->fl_filename) + strlen(name) + 2); 492 foldername = malloc(strlen(parent->fl_filename) + strlen(name) + 2);
493 if (foldername == NULL) 493 if (foldername == NULL)
494 return MAILMH_ERROR_MEMORY; 494 return MAILMH_ERROR_MEMORY;
495 strcpy(foldername, parent->fl_filename); 495 strcpy(foldername, parent->fl_filename);
496 strcat(foldername, MAIL_DIR_SEPARATOR_S); 496 strcat(foldername, MAIL_DIR_SEPARATOR_S);
497 strcat(foldername, name); 497 strcat(foldername, name);
498 498
499 r = mkdir(foldername, 0700); 499 r = mkdir(foldername, 0700);
500 free(foldername); 500 free(foldername);
501 501
502 if (r < 0) 502 if (r < 0)
503 return MAILMH_ERROR_FOLDER; 503 return MAILMH_ERROR_FOLDER;
504 504
505 folder = mailmh_folder_new(parent, name); 505 folder = mailmh_folder_new(parent, name);
506 if (folder == NULL) 506 if (folder == NULL)
507 return MAILMH_ERROR_MEMORY; 507 return MAILMH_ERROR_MEMORY;
508 508
509 r = carray_add(parent->fl_subfolders_tab, folder, &array_index); 509 r = carray_add(parent->fl_subfolders_tab, folder, &array_index);
510 if (r < 0) { 510 if (r < 0) {
511 mailmh_folder_free(folder); 511 mailmh_folder_free(folder);
512 return MAILMH_ERROR_MEMORY; 512 return MAILMH_ERROR_MEMORY;
513 } 513 }
514 folder->fl_array_index = array_index; 514 folder->fl_array_index = array_index;
515 515
516 key.data = folder->fl_filename; 516 key.data = folder->fl_filename;
517 key.len = strlen(folder->fl_filename); 517 key.len = strlen(folder->fl_filename);
518 data.data = folder; 518 data.data = folder;
519 data.len = 0; 519 data.len = 0;
520 520
521 r = chash_set(parent->fl_subfolders_hash, &key, &data, NULL); 521 r = chash_set(parent->fl_subfolders_hash, &key, &data, NULL);
522 if (r < 0) { 522 if (r < 0) {
523 carray_delete_fast(folder->fl_subfolders_tab, folder->fl_array_index); 523 carray_delete_fast(folder->fl_subfolders_tab, folder->fl_array_index);
524 mailmh_folder_free(folder); 524 mailmh_folder_free(folder);
525 return MAILMH_ERROR_MEMORY; 525 return MAILMH_ERROR_MEMORY;
526 } 526 }
527 527
528 return MAILMH_NO_ERROR; 528 return MAILMH_NO_ERROR;
529} 529}
530 530
531int mailmh_folder_remove_subfolder(struct mailmh_folder * folder) 531int mailmh_folder_remove_subfolder(struct mailmh_folder * folder)
532{ 532{
533 struct mailmh_folder * parent; 533 struct mailmh_folder * parent;
534 chashdatum key; 534 chashdatum key;
535 chashdatum data; 535 chashdatum data;
536 int r; 536 int r;
537 537
538 parent = folder->fl_parent; 538 parent = folder->fl_parent;
539 539
540 key.data = folder->fl_filename; 540 key.data = folder->fl_filename;
541 key.len = strlen(folder->fl_filename); 541 key.len = strlen(folder->fl_filename);
542 542
543 r = chash_get(parent->fl_subfolders_hash, &key, &data); 543 r = chash_get(parent->fl_subfolders_hash, &key, &data);
544 if (r < 0) 544 if (r < 0)
545 return MAILMH_ERROR_FOLDER; 545 return MAILMH_ERROR_FOLDER;
546 546
547 chash_delete(parent->fl_subfolders_hash, &key, NULL); 547 chash_delete(parent->fl_subfolders_hash, &key, NULL);
548 carray_delete_fast(parent->fl_subfolders_tab, folder->fl_array_index); 548 carray_delete_fast(parent->fl_subfolders_tab, folder->fl_array_index);
549 549
550 mailmh_folder_free(folder); 550 mailmh_folder_free(folder);
551 551
552 return MAILMH_NO_ERROR; 552 return MAILMH_NO_ERROR;
553 553
554} 554}
555 555
556int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, 556int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
557 struct mailmh_folder * dst_folder, 557 struct mailmh_folder * dst_folder,
558 const char * new_name) 558 const char * new_name)
559{ 559{
560 int r; 560 int r;
561 struct mailmh_folder * folder; 561 struct mailmh_folder * folder;
562 struct mailmh_folder * parent; 562 struct mailmh_folder * parent;
563 char * new_foldername; 563 char * new_foldername;
564 564
565 parent = src_folder->fl_parent; 565 parent = src_folder->fl_parent;
566 if (parent == NULL) 566 if (parent == NULL)
567 return MAILMH_ERROR_RENAME; 567 return MAILMH_ERROR_RENAME;
568 568
569 new_foldername = malloc(strlen(dst_folder->fl_filename) + 2 + strlen(new_name)); 569 new_foldername = malloc(strlen(dst_folder->fl_filename) + 2 + strlen(new_name));
570 if (new_foldername == NULL) 570 if (new_foldername == NULL)
571 return MAILMH_ERROR_MEMORY; 571 return MAILMH_ERROR_MEMORY;
572 572
573 strcpy(new_foldername, dst_folder->fl_filename); 573 strcpy(new_foldername, dst_folder->fl_filename);
574 strcat(new_foldername, MAIL_DIR_SEPARATOR_S); 574 strcat(new_foldername, MAIL_DIR_SEPARATOR_S);
575 strcat(new_foldername, new_name); 575 strcat(new_foldername, new_name);
576 576
577 r = rename(src_folder->fl_filename, new_foldername); 577 r = rename(src_folder->fl_filename, new_foldername);
578 free(new_foldername); 578 free(new_foldername);
579 if (r < 0) 579 if (r < 0)
580 return MAILMH_ERROR_RENAME; 580 return MAILMH_ERROR_RENAME;
581 581
582 r = mailmh_folder_remove_subfolder(src_folder); 582 r = mailmh_folder_remove_subfolder(src_folder);
583 if (r != MAILMH_NO_ERROR) 583 if (r != MAILMH_NO_ERROR)
584 return r; 584 return r;
585 585
586 folder = mailmh_folder_new(dst_folder, new_name); 586 folder = mailmh_folder_new(dst_folder, new_name);
587 if (folder == NULL) 587 if (folder == NULL)
588 return MAILMH_ERROR_MEMORY; 588 return MAILMH_ERROR_MEMORY;
589 589
590 r = carray_add(parent->fl_subfolders_tab, folder, NULL); 590 r = carray_add(parent->fl_subfolders_tab, folder, NULL);
591 if (r < 0) { 591 if (r < 0) {
592 mailmh_folder_free(folder); 592 mailmh_folder_free(folder);
593 return MAILMH_ERROR_MEMORY; 593 return MAILMH_ERROR_MEMORY;
594 } 594 }
595 595
596 return MAILMH_NO_ERROR; 596 return MAILMH_NO_ERROR;
597} 597}
598 598
599#define MAX_TRY_ALLOC 32 599#define MAX_TRY_ALLOC 32
600 600
601/* initial file MUST be in the same directory */ 601/* initial file MUST be in the same directory */
602 602
603static int mailmh_folder_alloc_msg(struct mailmh_folder * folder, 603static int mailmh_folder_alloc_msg(struct mailmh_folder * folder,
604 char * filename, uint32_t * result) 604 char * filename, uint32_t * result)
605{ 605{
606 uint32_t max; 606 uint32_t max;
607 uint32_t k; 607 uint32_t k;
608 char * new_filename; 608 char * new_filename;
609 size_t len; 609 size_t len;
610 struct stat f_stat;
610 611
611 len = strlen(folder->fl_filename) + 20; 612 len = strlen(folder->fl_filename) + 20;
612 new_filename = malloc(len); 613 new_filename = malloc(len);
613 if (new_filename == NULL) 614 if (new_filename == NULL)
614 return MAILMH_ERROR_MEMORY; 615 return MAILMH_ERROR_MEMORY;
615 616
616 max = folder->fl_max_index + 1; 617 max = folder->fl_max_index + 1;
617 618
619 //fprintf(stderr,"mailmh_folder_alloc_msg filename: %s \n", filename);
618 k = 0; 620 k = 0;
619 while (k < MAX_TRY_ALLOC) { 621 while (k < MAX_TRY_ALLOC) {
620 snprintf(new_filename, len, "%s%c%lu", folder->fl_filename, 622 snprintf(new_filename, len, "%s%c%lu", folder->fl_filename,
621 MAIL_DIR_SEPARATOR, (unsigned long) (max + k)); 623 MAIL_DIR_SEPARATOR, (unsigned long) (max + k));
622 624 //fprintf(stderr,"mailmh_folder_alloc_msg new_filename: %s \n", new_filename);
623 if (link(filename, new_filename) == 0) { 625 if ( stat( new_filename, &f_stat ) == -1 ) {
626 // if (link(filename, new_filename) == 0) {
624 int r; 627 int r;
625 628 //fprintf(stderr,"filename found \n");
629 //unlink(filename);
630 rename (filename,new_filename );
626 free(new_filename); 631 free(new_filename);
627 unlink(filename);
628 632
629 if (k > MAX_TRY_ALLOC / 2) { 633 if (k > MAX_TRY_ALLOC / 2) {
630 r = mailmh_folder_update(folder); 634 r = mailmh_folder_update(folder);
631 /* ignore errors */ 635 /* ignore errors */
632 } 636 }
633 637
634 * result = max + k; 638 * result = max + k;
635 639
636 folder->fl_max_index = max + k; 640 folder->fl_max_index = max + k;
637 641
638 return MAILMH_NO_ERROR; 642 return MAILMH_NO_ERROR;
639 } 643 }
640 else if (errno == EXDEV) { 644 else if (errno == EXDEV) {
641 free(filename); 645 free(filename);
642 return MAILMH_ERROR_FOLDER; 646 return MAILMH_ERROR_FOLDER;
643 } 647 }
644 k ++; 648 k ++;
645 } 649 }
646 650
647 free(new_filename); 651 free(new_filename);
648 652
649 return MAILMH_ERROR_FOLDER; 653 return MAILMH_ERROR_FOLDER;
650} 654}
651 655
652int mailmh_folder_get_message_filename(struct mailmh_folder * folder, 656int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
653 uint32_t index, char ** result) 657 uint32_t index, char ** result)
654{ 658{
655 char * filename; 659 char * filename;
656 int len; 660 int len;
657 661
658#if 0 662#if 0
659 r = mailmh_folder_update(folder); 663 r = mailmh_folder_update(folder);
660 if (r != MAILMH_NO_ERROR) 664 if (r != MAILMH_NO_ERROR)
661 return r; 665 return r;
662#endif 666#endif
663 667
664 len = strlen(folder->fl_filename) + 20; 668 len = strlen(folder->fl_filename) + 20;
665 filename = malloc(len); 669 filename = malloc(len);
666 if (filename == NULL) 670 if (filename == NULL)
667 return MAILMH_ERROR_MEMORY; 671 return MAILMH_ERROR_MEMORY;
668 672
669 snprintf(filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR, 673 snprintf(filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR,
670 (unsigned long) index); 674 (unsigned long) index);
671 675
672 * result = filename; 676 * result = filename;
673 677
674 return MAILMH_NO_ERROR;; 678 return MAILMH_NO_ERROR;;
675} 679}
676 680
677 681
678int mailmh_folder_get_message_fd(struct mailmh_folder * folder, 682int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
679 uint32_t index, int flags, int * result) 683 uint32_t index, int flags, int * result)
680{ 684{
681 char * filename; 685 char * filename;
682 int fd; 686 int fd;
683 int r; 687 int r;
684 688
685#if 0 689#if 0
686 r = mailmh_folder_update(folder); 690 r = mailmh_folder_update(folder);
687 if (r != MAILMH_NO_ERROR) 691 if (r != MAILMH_NO_ERROR)
688 return r; 692 return r;
689#endif 693#endif
690 694
691 r = mailmh_folder_get_message_filename(folder, index, &filename); 695 r = mailmh_folder_get_message_filename(folder, index, &filename);
692 if (r != MAILMH_NO_ERROR) 696 if (r != MAILMH_NO_ERROR)
693 return r; 697 return r;
694 698
695 fd = open(filename, flags); 699 fd = open(filename, flags);
696 free(filename); 700 free(filename);
697 if (fd == -1) 701 if (fd == -1)
698 return MAILMH_ERROR_MSG_NOT_FOUND; 702 return MAILMH_ERROR_MSG_NOT_FOUND;
699 703
700 * result = fd; 704 * result = fd;
701 705
702 return MAILMH_NO_ERROR; 706 return MAILMH_NO_ERROR;
703} 707}
704 708
705int mailmh_folder_get_message_size(struct mailmh_folder * folder, 709int mailmh_folder_get_message_size(struct mailmh_folder * folder,
706 uint32_t index, size_t * result) 710 uint32_t index, size_t * result)
707{ 711{
708 int r; 712 int r;
709 char * filename; 713 char * filename;
710 struct stat buf; 714 struct stat buf;
711 715
712 r = mailmh_folder_get_message_filename(folder, index, &filename); 716 r = mailmh_folder_get_message_filename(folder, index, &filename);
713 if (r != MAILMH_NO_ERROR) 717 if (r != MAILMH_NO_ERROR)
714 return r; 718 return r;
715 719
716 r = stat(filename, &buf); 720 r = stat(filename, &buf);
717 free(filename); 721 free(filename);
718 if (r < 0) 722 if (r < 0)
719 return MAILMH_ERROR_FILE; 723 return MAILMH_ERROR_FILE;
720 724
721 * result = buf.st_size; 725 * result = buf.st_size;
722 726
723 return MAILMH_NO_ERROR; 727 return MAILMH_NO_ERROR;
724} 728}
725 729
726int mailmh_folder_add_message_uid(struct mailmh_folder * folder, 730int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
727 const char * message, size_t size, 731 const char * message, size_t size,
728 uint32_t * pindex) 732 uint32_t * pindex)
729{ 733{
730 char * tmpname; 734 char * tmpname;
731 int fd; 735 int fd;
732 size_t namesize; 736 size_t namesize;
733 size_t left; 737 size_t left;
734 ssize_t res; 738 ssize_t res;
735 struct mailmh_msg_info * msg_info; 739 struct mailmh_msg_info * msg_info;
736 uint32_t index; 740 uint32_t index;
737 int error; 741 int error;
738 int r; 742 int r;
739 unsigned int array_index; 743 unsigned int array_index;
740 struct stat buf; 744 struct stat buf;
741 chashdatum key; 745 chashdatum key;
742 chashdatum data; 746 chashdatum data;
743 747
744#if 0 748#if 0
745 r = mailmh_folder_update(folder); 749 r = mailmh_folder_update(folder);
746 if (r != MAILMH_NO_ERROR) { 750 if (r != MAILMH_NO_ERROR) {
747 error = r; 751 error = r;
748 goto err; 752 goto err;
749 } 753 }
750#endif 754#endif
751 755
752 namesize = strlen(folder->fl_filename) + 20; 756 namesize = strlen(folder->fl_filename) + 20;
753 tmpname = malloc(namesize); 757 tmpname = malloc(namesize);
754 snprintf(tmpname, namesize, "%s%ctmpXXXXXX", 758 snprintf(tmpname, namesize, "%s%ctmpXXXXXX",
755 folder->fl_filename, MAIL_DIR_SEPARATOR); 759 folder->fl_filename, MAIL_DIR_SEPARATOR);
756 fd = mkstemp(tmpname); 760 fd = mkstemp(tmpname);
757 if (fd < 0) { 761 if (fd < 0) {
758 error = MAILMH_ERROR_FILE; 762 error = MAILMH_ERROR_FILE;
759 goto free; 763 goto free;
760 } 764 }
761 765
762 left = size; 766 left = size;
763 while (left > 0) { 767 while (left > 0) {
764 res = write(fd, message, left); 768 res = write(fd, message, left);
765 if (res == -1) { 769 if (res == -1) {
766 close(fd); 770 close(fd);
767 error = MAILMH_ERROR_FILE; 771 error = MAILMH_ERROR_FILE;
768 goto free; 772 goto free;
769 } 773 }
770 774
771 left -= res; 775 left -= res;
772 } 776 }
773 close(fd); 777 close(fd);
774 778
775 r = stat(tmpname, &buf); 779 r = stat(tmpname, &buf);
776 if (r < 0) { 780 if (r < 0) {
777 error = MAILMH_ERROR_FILE; 781 error = MAILMH_ERROR_FILE;
778 goto free; 782 goto free;
779 } 783 }
780 784
781 r = mailmh_folder_alloc_msg(folder, tmpname, &index); 785 r = mailmh_folder_alloc_msg(folder, tmpname, &index);
782 if (r != MAILMH_NO_ERROR) { 786 if (r != MAILMH_NO_ERROR) {
783 unlink(tmpname); 787 unlink(tmpname);
784 error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG; 788 error = MAILMH_ERROR_COULD_NOT_ALLOC_MSG;
785 goto free; 789 goto free;
786 } 790 }
787 free(tmpname); 791 free(tmpname);
788 792
789 msg_info = mailmh_msg_info_new(index, size, buf.st_mtime); 793 msg_info = mailmh_msg_info_new(index, size, buf.st_mtime);
790 if (msg_info == NULL) { 794 if (msg_info == NULL) {
791 mailmh_folder_remove_message(folder, index); 795 mailmh_folder_remove_message(folder, index);
792 error = MAILMH_ERROR_MEMORY; 796 error = MAILMH_ERROR_MEMORY;
793 goto err; 797 goto err;
794 } 798 }
795 799
796 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index); 800 r = carray_add(folder->fl_msgs_tab, msg_info, &array_index);
797 if (r < 0) { 801 if (r < 0) {
798 mailmh_folder_remove_message(folder, index); 802 mailmh_folder_remove_message(folder, index);
799 mailmh_msg_info_free(msg_info); 803 mailmh_msg_info_free(msg_info);
800 error = MAILMH_ERROR_MEMORY; 804 error = MAILMH_ERROR_MEMORY;
801 goto err; 805 goto err;
802 } 806 }
803 msg_info->msg_array_index = array_index; 807 msg_info->msg_array_index = array_index;
804 808
805#if 0 809#if 0
806 r = cinthash_add(folder->fl_msgs_hash, index, msg_info); 810 r = cinthash_add(folder->fl_msgs_hash, index, msg_info);
807#endif 811#endif
808 key.data = &index; 812 key.data = &index;
809 key.len = sizeof(index); 813 key.len = sizeof(index);
810 data.data = msg_info; 814 data.data = msg_info;
811 data.len = 0; 815 data.len = 0;
812 816
813 if (pindex != NULL) 817 if (pindex != NULL)
814 * pindex = index; 818 * pindex = index;
815 819
816 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL); 820 r = chash_set(folder->fl_msgs_hash, &key, &data, NULL);
817 if (r < 0) { 821 if (r < 0) {
818 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); 822 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
819 mailmh_msg_info_free(msg_info); 823 mailmh_msg_info_free(msg_info);
820 error = MAILMH_ERROR_MEMORY; 824 error = MAILMH_ERROR_MEMORY;
821 goto err; 825 goto err;
822 } 826 }
823 827
824 return MAILMH_NO_ERROR; 828 return MAILMH_NO_ERROR;
825 829
826 free: 830 free:
827 free(tmpname); 831 free(tmpname);
828 err: 832 err:
829 return error; 833 return error;
830} 834}
831 835
832int mailmh_folder_add_message(struct mailmh_folder * folder, 836int mailmh_folder_add_message(struct mailmh_folder * folder,
833 const char * message, size_t size) 837 const char * message, size_t size)
834{ 838{
835 return mailmh_folder_add_message_uid(folder, message, size, NULL); 839 return mailmh_folder_add_message_uid(folder, message, size, NULL);
836} 840}
837 841
838int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder, 842int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
839 int fd, uint32_t * pindex) 843 int fd, uint32_t * pindex)
840{ 844{
841 char * message; 845 char * message;
842 struct stat buf; 846 struct stat buf;
843 int r; 847 int r;
844 848
845#if 0 849#if 0
846 r = mailmh_folder_update(folder); 850 r = mailmh_folder_update(folder);
847 if (r != MAILMH_NO_ERROR) 851 if (r != MAILMH_NO_ERROR)
848 return r; 852 return r;
849#endif 853#endif
850 854
851 if (fstat(fd, &buf) == -1) 855 if (fstat(fd, &buf) == -1)
852 return MAILMH_ERROR_FILE; 856 return MAILMH_ERROR_FILE;
853 857
854 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); 858 message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
855 if (message == MAP_FAILED) 859 if (message == MAP_FAILED)
856 return MAILMH_ERROR_FILE; 860 return MAILMH_ERROR_FILE;
857 861
858 r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex); 862 r = mailmh_folder_add_message_uid(folder, message, buf.st_size, pindex);
859 863
860 munmap(message, buf.st_size); 864 munmap(message, buf.st_size);
861 865
862 return r; 866 return r;
863} 867}
864 868
865int mailmh_folder_add_message_file(struct mailmh_folder * folder, 869int mailmh_folder_add_message_file(struct mailmh_folder * folder,
866 int fd) 870 int fd)
867{ 871{
868 return mailmh_folder_add_message_file_uid(folder, fd, NULL); 872 return mailmh_folder_add_message_file_uid(folder, fd, NULL);
869} 873}
870 874
871int mailmh_folder_remove_message(struct mailmh_folder * folder, 875int mailmh_folder_remove_message(struct mailmh_folder * folder,
872 uint32_t index) 876 uint32_t index)
873{ 877{
874 char * filename; 878 char * filename;
875 struct mailmh_msg_info * msg_info; 879 struct mailmh_msg_info * msg_info;
876 int res; 880 int res;
877 int r; 881 int r;
878 chashdatum key; 882 chashdatum key;
879 chashdatum data; 883 chashdatum data;
880 884
881#if 0 885#if 0
882 r = mailmh_folder_update(folder); 886 r = mailmh_folder_update(folder);
883 if (r != MAILMH_NO_ERROR) { 887 if (r != MAILMH_NO_ERROR) {
884 res = r; 888 res = r;
885 goto err; 889 goto err;
886 } 890 }
887#endif 891#endif
888 892
889 r = mailmh_folder_get_message_filename(folder, index, &filename); 893 r = mailmh_folder_get_message_filename(folder, index, &filename);
890 if (filename == NULL) { 894 if (filename == NULL) {
891 res = r; 895 res = r;
892 goto err; 896 goto err;
893 } 897 }
894 898
895 if (unlink(filename) == -1) { 899 if (unlink(filename) == -1) {
896 res = MAILMH_ERROR_FILE; 900 res = MAILMH_ERROR_FILE;
897 goto free; 901 goto free;
898 } 902 }
899 903
900 key.data = &index; 904 key.data = &index;
901 key.len = sizeof(index); 905 key.len = sizeof(index);
902 r = chash_get(folder->fl_msgs_hash, &key, &data); 906 r = chash_get(folder->fl_msgs_hash, &key, &data);
903#if 0 907#if 0
904 msg_info = cinthash_find(folder->fl_msgs_hash, index); 908 msg_info = cinthash_find(folder->fl_msgs_hash, index);
905#endif 909#endif
906 if (r == 0) { 910 if (r == 0) {
907 msg_info = data.data; 911 msg_info = data.data;
908 912
909 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index); 913 carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
910#if 0 914#if 0
911 cinthash_remove(folder->fl_msgs_hash, index); 915 cinthash_remove(folder->fl_msgs_hash, index);
912#endif 916#endif
913 chash_delete(folder->fl_msgs_hash, &key, NULL); 917 chash_delete(folder->fl_msgs_hash, &key, NULL);
914 } 918 }
915 919
916 return MAILMH_NO_ERROR; 920 return MAILMH_NO_ERROR;
917 921
918 free: 922 free:
919 free(filename); 923 free(filename);
920 err: 924 err:
921 return res; 925 return res;
922} 926}
923 927
924 928
925int mailmh_folder_move_message(struct mailmh_folder * dest_folder, 929int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
926 struct mailmh_folder * src_folder, 930 struct mailmh_folder * src_folder,
927 uint32_t index) 931 uint32_t index)
928{ 932{
929 int fd; 933 int fd;
930 char * filename; 934 char * filename;
931 int r; 935 int r;
932 936
933#if 0 937#if 0
934 r = mailmh_folder_update(dest_folder); 938 r = mailmh_folder_update(dest_folder);
935 if (r != MAILMH_NO_ERROR) 939 if (r != MAILMH_NO_ERROR)
936 return r; 940 return r;
937 r = mailmh_folder_update(src_folder); 941 r = mailmh_folder_update(src_folder);
938 if (r != MAILMH_NO_ERROR) 942 if (r != MAILMH_NO_ERROR)
939 return r; 943 return r;
940#endif 944#endif
941 945
942 /* move on the same filesystem */ 946 /* move on the same filesystem */
943 r = mailmh_folder_get_message_filename(src_folder, index, &filename); 947 r = mailmh_folder_get_message_filename(src_folder, index, &filename);
944 if (r != MAILMH_NO_ERROR) 948 if (r != MAILMH_NO_ERROR)
945 return r; 949 return r;
946 950
947 r = mailmh_folder_alloc_msg(dest_folder, filename, &index); 951 r = mailmh_folder_alloc_msg(dest_folder, filename, &index);
948 free(filename); 952 free(filename);
949 if (r == MAILMH_NO_ERROR) 953 if (r == MAILMH_NO_ERROR)
950 return MAILMH_NO_ERROR; 954 return MAILMH_NO_ERROR;
951 955
952 /* move on the different filesystems */ 956 /* move on the different filesystems */
953 r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd); 957 r = mailmh_folder_get_message_fd(src_folder, index, O_RDONLY, &fd);
954 if (r != MAILMH_NO_ERROR) 958 if (r != MAILMH_NO_ERROR)
955 return r; 959 return r;
956 960
957 r = mailmh_folder_add_message_file(dest_folder, fd); 961 r = mailmh_folder_add_message_file(dest_folder, fd);
958 if (r != MAILMH_NO_ERROR) { 962 if (r != MAILMH_NO_ERROR) {
959 close(fd); 963 close(fd);
960 return r; 964 return r;
961 } 965 }
962 966
963 close(fd); 967 close(fd);
964 968
965 r = mailmh_folder_remove_message(src_folder, index); 969 r = mailmh_folder_remove_message(src_folder, index);
966 970
967 return MAILMH_NO_ERROR; 971 return MAILMH_NO_ERROR;
968} 972}
969 973
970unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder) 974unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder)
971{ 975{
972 unsigned int i; 976 unsigned int i;
973 unsigned int count; 977 unsigned int count;
974 978
975 count = 0; 979 count = 0;
976 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) 980 for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++)
977 if (carray_get(folder->fl_msgs_tab, i) != NULL) 981 if (carray_get(folder->fl_msgs_tab, i) != NULL)
978 count ++; 982 count ++;
979 983
980 return count; 984 return count;
981} 985}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 2321087..3908dbb 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3788 +1,3792 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#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 "kodialogmanager.h" 107#include "kodialogmanager.h"
108#include "outgoingdialog.h" 108#include "outgoingdialog.h"
109#include "incomingdialog.h" 109#include "incomingdialog.h"
110#include "statusdialog.h" 110#include "statusdialog.h"
111#include "kdatenavigator.h" 111#include "kdatenavigator.h"
112#include "kotodoview.h" 112#include "kotodoview.h"
113#include "datenavigator.h" 113#include "datenavigator.h"
114#include "resourceview.h" 114#include "resourceview.h"
115#include "navigatorbar.h" 115#include "navigatorbar.h"
116#include "searchdialog.h" 116#include "searchdialog.h"
117#include "mainwindow.h" 117#include "mainwindow.h"
118 118
119#include "calendarview.h" 119#include "calendarview.h"
120#ifndef DESKTOP_VERSION 120#ifndef DESKTOP_VERSION
121#include <qtopia/alarmserver.h> 121#include <qtopia/alarmserver.h>
122#endif 122#endif
123#ifndef _WIN32_ 123#ifndef _WIN32_
124#include <stdlib.h> 124#include <stdlib.h>
125#include <stdio.h> 125#include <stdio.h>
126#include <unistd.h> 126#include <unistd.h>
127#else 127#else
128#include <qprocess.h> 128#include <qprocess.h>
129#endif 129#endif
130 130
131#ifdef DESKTOP_VERSION 131#ifdef DESKTOP_VERSION
132#include <kabc/stdaddressbook.h> 132#include <kabc/stdaddressbook.h>
133#endif 133#endif
134using namespace KOrg; 134using namespace KOrg;
135using namespace KCal; 135using namespace KCal;
136extern int globalFlagBlockAgenda; 136extern int globalFlagBlockAgenda;
137extern int globalFlagBlockStartup; 137extern int globalFlagBlockStartup;
138 138
139 139
140 140
141class KOBeamPrefs : public QDialog 141class KOBeamPrefs : public QDialog
142{ 142{
143 public: 143 public:
144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 144 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
145 QDialog( parent, name, true ) 145 QDialog( parent, name, true )
146 { 146 {
147 setCaption( i18n("Beam Options") ); 147 setCaption( i18n("Beam Options") );
148 QVBoxLayout* lay = new QVBoxLayout( this ); 148 QVBoxLayout* lay = new QVBoxLayout( this );
149 lay->setSpacing( 3 ); 149 lay->setSpacing( 3 );
150 lay->setMargin( 3 ); 150 lay->setMargin( 3 );
151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 151 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
152 lay->addWidget( format ); 152 lay->addWidget( format );
153 format->setExclusive ( true ) ; 153 format->setExclusive ( true ) ;
154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 154 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
155 lay->addWidget( time ); time->setExclusive ( true ) ; 155 lay->addWidget( time ); time->setExclusive ( true ) ;
156 vcal = new QRadioButton(" vCalendar ", format ); 156 vcal = new QRadioButton(" vCalendar ", format );
157 ical = new QRadioButton(" iCalendar ", format ); 157 ical = new QRadioButton(" iCalendar ", format );
158 vcal->setChecked( true ); 158 vcal->setChecked( true );
159 tz = new QRadioButton(i18n(" With timezone "), time ); 159 tz = new QRadioButton(i18n(" With timezone "), time );
160 local = new QRadioButton(i18n(" Local time "), time ); 160 local = new QRadioButton(i18n(" Local time "), time );
161 tz->setChecked( true ); 161 tz->setChecked( true );
162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 162 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
163 lay->addWidget( ok ); 163 lay->addWidget( ok );
164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 164 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
165 lay->addWidget( cancel ); 165 lay->addWidget( cancel );
166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 166 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 167 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
168 resize( 200, 200 ); 168 resize( 200, 200 );
169 } 169 }
170 170
171 bool beamVcal() { return vcal->isChecked(); } 171 bool beamVcal() { return vcal->isChecked(); }
172 bool beamLocal() { return local->isChecked(); } 172 bool beamLocal() { return local->isChecked(); }
173private: 173private:
174 QRadioButton* vcal, *ical, *local, *tz; 174 QRadioButton* vcal, *ical, *local, *tz;
175}; 175};
176class KOCatPrefs : public QDialog 176class KOCatPrefs : public QDialog
177{ 177{
178 public: 178 public:
179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 179 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
180 QDialog( parent, name, true ) 180 QDialog( parent, name, true )
181 { 181 {
182 setCaption( i18n("Manage new Categories") ); 182 setCaption( i18n("Manage new Categories") );
183 QVBoxLayout* lay = new QVBoxLayout( this ); 183 QVBoxLayout* lay = new QVBoxLayout( this );
184 lay->setSpacing( 3 ); 184 lay->setSpacing( 3 );
185 lay->setMargin( 3 ); 185 lay->setMargin( 3 );
186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 186 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
187 lay->addWidget( lab ); 187 lay->addWidget( lab );
188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 188 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
189 lay->addWidget( format ); 189 lay->addWidget( format );
190 format->setExclusive ( true ) ; 190 format->setExclusive ( true ) ;
191 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 191 addCatBut = new QRadioButton(i18n("Add to category list"), format );
192 new QRadioButton(i18n("Remove from Events/Todos"), format ); 192 new QRadioButton(i18n("Remove from Events/Todos"), format );
193 addCatBut->setChecked( true ); 193 addCatBut->setChecked( true );
194 QPushButton * ok = new QPushButton( i18n("OK"), this ); 194 QPushButton * ok = new QPushButton( i18n("OK"), this );
195 lay->addWidget( ok ); 195 lay->addWidget( ok );
196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 196 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
197 lay->addWidget( cancel ); 197 lay->addWidget( cancel );
198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 198 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 199 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
200 resize( 200, 200 ); 200 resize( 200, 200 );
201 } 201 }
202 202
203 bool addCat() { return addCatBut->isChecked(); } 203 bool addCat() { return addCatBut->isChecked(); }
204private: 204private:
205 QRadioButton* addCatBut; 205 QRadioButton* addCatBut;
206}; 206};
207 207
208 208
209 209
210CalendarView::CalendarView( CalendarResources *calendar, 210CalendarView::CalendarView( CalendarResources *calendar,
211 QWidget *parent, const char *name ) 211 QWidget *parent, const char *name )
212 : CalendarViewBase( parent, name ), 212 : CalendarViewBase( parent, name ),
213 mCalendar( calendar ), 213 mCalendar( calendar ),
214 mResourceManager( calendar->resourceManager() ) 214 mResourceManager( calendar->resourceManager() )
215{ 215{
216 216
217 mEventEditor = 0; 217 mEventEditor = 0;
218 mTodoEditor = 0; 218 mTodoEditor = 0;
219 219
220 init(); 220 init();
221} 221}
222 222
223CalendarView::CalendarView( Calendar *calendar, 223CalendarView::CalendarView( Calendar *calendar,
224 QWidget *parent, const char *name ) 224 QWidget *parent, const char *name )
225 : CalendarViewBase( parent, name ), 225 : CalendarViewBase( parent, name ),
226 mCalendar( calendar ), 226 mCalendar( calendar ),
227 mResourceManager( 0 ) 227 mResourceManager( 0 )
228{ 228{
229 229
230 mEventEditor = 0; 230 mEventEditor = 0;
231 mTodoEditor = 0; 231 mTodoEditor = 0;
232 init();} 232 init();}
233 233
234void CalendarView::init() 234void CalendarView::init()
235{ 235{
236 beamDialog = new KOBeamPrefs(); 236 beamDialog = new KOBeamPrefs();
237 mDatePickerMode = 0; 237 mDatePickerMode = 0;
238 mCurrentSyncDevice = ""; 238 mCurrentSyncDevice = "";
239 writeLocale(); 239 writeLocale();
240 mViewManager = new KOViewManager( this ); 240 mViewManager = new KOViewManager( this );
241 mDialogManager = new KODialogManager( this ); 241 mDialogManager = new KODialogManager( this );
242 mEventViewerDialog = 0; 242 mEventViewerDialog = 0;
243 mModified = false; 243 mModified = false;
244 mReadOnly = false; 244 mReadOnly = false;
245 mSelectedIncidence = 0; 245 mSelectedIncidence = 0;
246 mCalPrinter = 0; 246 mCalPrinter = 0;
247 mFilters.setAutoDelete(true); 247 mFilters.setAutoDelete(true);
248 248
249 mCalendar->registerObserver( this ); 249 mCalendar->registerObserver( this );
250 // TODO: Make sure that view is updated, when calendar is changed. 250 // TODO: Make sure that view is updated, when calendar is changed.
251 251
252 mStorage = new FileStorage( mCalendar ); 252 mStorage = new FileStorage( mCalendar );
253 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 253 mNavigator = new DateNavigator( this, "datevav", mViewManager );
254 254
255 QBoxLayout *topLayout = (QBoxLayout*)layout(); 255 QBoxLayout *topLayout = (QBoxLayout*)layout();
256#ifndef KORG_NOSPLITTER 256#ifndef KORG_NOSPLITTER
257 // create the main layout frames. 257 // create the main layout frames.
258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 258 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
259 topLayout->addWidget(mPanner); 259 topLayout->addWidget(mPanner);
260 260
261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 261 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
262 "CalendarView::LeftFrame"); 262 "CalendarView::LeftFrame");
263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 263 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
264 264
265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 265 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
266 "CalendarView::DateNavigator", QDate::currentDate() ); 266 "CalendarView::DateNavigator", QDate::currentDate() );
267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 267 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 268 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 269 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
270 270
271#ifdef KORG_NORESOURCEVIEW 271#ifdef KORG_NORESOURCEVIEW
272 mResourceView = 0; 272 mResourceView = 0;
273#else 273#else
274 if ( mResourceManager ) { 274 if ( mResourceManager ) {
275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 275 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
276 mResourceView->updateView(); 276 mResourceView->updateView();
277 connect( mResourceView, SIGNAL( resourcesChanged() ), 277 connect( mResourceView, SIGNAL( resourcesChanged() ),
278 SLOT( updateView() ) ); 278 SLOT( updateView() ) );
279 } else { 279 } else {
280 mResourceView = 0; 280 mResourceView = 0;
281 } 281 }
282#endif 282#endif
283 QWidget *rightBox = new QWidget( mPanner ); 283 QWidget *rightBox = new QWidget( mPanner );
284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 284 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
285 285
286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 286 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
287 rightLayout->addWidget( mNavigatorBar ); 287 rightLayout->addWidget( mNavigatorBar );
288 288
289 mRightFrame = new QWidgetStack( rightBox ); 289 mRightFrame = new QWidgetStack( rightBox );
290 rightLayout->addWidget( mRightFrame, 1 ); 290 rightLayout->addWidget( mRightFrame, 1 );
291 291
292 mLeftFrame = mLeftSplitter; 292 mLeftFrame = mLeftSplitter;
293#else 293#else
294 QWidget *mainBox = new QWidget( this ); 294 QWidget *mainBox = new QWidget( this );
295 QWidget *leftFrame = new QWidget( mainBox ); 295 QWidget *leftFrame = new QWidget( mainBox );
296 296
297 QBoxLayout * mainBoxLayout; 297 QBoxLayout * mainBoxLayout;
298 QBoxLayout * leftFrameLayout; 298 QBoxLayout * leftFrameLayout;
299 if ( KOPrefs::instance()->mVerticalScreen ) { 299 if ( KOPrefs::instance()->mVerticalScreen ) {
300 mainBoxLayout = new QVBoxLayout(mainBox); 300 mainBoxLayout = new QVBoxLayout(mainBox);
301 leftFrameLayout = new QHBoxLayout(leftFrame ); 301 leftFrameLayout = new QHBoxLayout(leftFrame );
302 } else { 302 } else {
303 mainBoxLayout = new QHBoxLayout(mainBox); 303 mainBoxLayout = new QHBoxLayout(mainBox);
304 leftFrameLayout = new QVBoxLayout(leftFrame ); 304 leftFrameLayout = new QVBoxLayout(leftFrame );
305 } 305 }
306 topLayout->addWidget( mainBox ); 306 topLayout->addWidget( mainBox );
307 mainBoxLayout->addWidget (leftFrame); 307 mainBoxLayout->addWidget (leftFrame);
308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 308 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
309 "CalendarView::DateNavigator", QDate::currentDate()); 309 "CalendarView::DateNavigator", QDate::currentDate());
310 // mDateNavigator->blockSignals( true ); 310 // mDateNavigator->blockSignals( true );
311 leftFrameLayout->addWidget( mDateNavigator ); 311 leftFrameLayout->addWidget( mDateNavigator );
312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 312 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall"); 313 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolistsmall");
314 314
315 if ( QApplication::desktop()->width() < 480 ) { 315 if ( QApplication::desktop()->width() < 480 ) {
316 leftFrameLayout->addWidget(mFilterView); 316 leftFrameLayout->addWidget(mFilterView);
317 leftFrameLayout->addWidget(mTodoList, 2 ); 317 leftFrameLayout->addWidget(mTodoList, 2 );
318 318
319 } else { 319 } else {
320 leftFrameLayout->addWidget(mTodoList,2 ); 320 leftFrameLayout->addWidget(mTodoList,2 );
321 leftFrameLayout->addWidget(mFilterView ); 321 leftFrameLayout->addWidget(mFilterView );
322 } 322 }
323 mFilterView->hide(); 323 mFilterView->hide();
324 QWidget *rightBox = new QWidget( mainBox ); 324 QWidget *rightBox = new QWidget( mainBox );
325 mainBoxLayout->addWidget ( rightBox, 10 ); 325 mainBoxLayout->addWidget ( rightBox, 10 );
326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 326 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 327 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
328 mRightFrame = new QWidgetStack( rightBox ); 328 mRightFrame = new QWidgetStack( rightBox );
329 rightLayout->addWidget( mNavigatorBar ); 329 rightLayout->addWidget( mNavigatorBar );
330 rightLayout->addWidget( mRightFrame, 10 ); 330 rightLayout->addWidget( mRightFrame, 10 );
331 331
332 mLeftFrame = leftFrame; 332 mLeftFrame = leftFrame;
333 if ( KOPrefs::instance()->mVerticalScreen ) { 333 if ( KOPrefs::instance()->mVerticalScreen ) {
334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 334 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 335 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
336 } else { 336 } else {
337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 337 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 338 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
339 } 339 }
340 340
341 //qDebug("Calendarview Size %d %d ", width(), height()); 341 //qDebug("Calendarview Size %d %d ", width(), height());
342#endif 342#endif
343 343
344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 344 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
345 SLOT( showDates( const KCal::DateList & ) ) ); 345 SLOT( showDates( const KCal::DateList & ) ) );
346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 346 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 347 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
348 348
349 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 349 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
350 mNavigator, SLOT( selectPreviousYear() ) ); 350 mNavigator, SLOT( selectPreviousYear() ) );
351 connect( mNavigatorBar, SIGNAL( goNextYear() ), 351 connect( mNavigatorBar, SIGNAL( goNextYear() ),
352 mNavigator, SLOT( selectNextYear() ) ); 352 mNavigator, SLOT( selectNextYear() ) );
353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 353 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
354 mNavigator, SLOT( selectPreviousMonth() ) ); 354 mNavigator, SLOT( selectPreviousMonth() ) );
355 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 355 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
356 mNavigator, SLOT( selectNextMonth() ) ); 356 mNavigator, SLOT( selectNextMonth() ) );
357 357
358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 358 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 359 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
360 360
361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 361 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
362 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 362 mNavigator, SLOT( selectWeek( const QDate & ) ) );
363 363
364 connect( mDateNavigator, SIGNAL( goPrevYear() ), 364 connect( mDateNavigator, SIGNAL( goPrevYear() ),
365 mNavigator, SLOT( selectPreviousYear() ) ); 365 mNavigator, SLOT( selectPreviousYear() ) );
366 connect( mDateNavigator, SIGNAL( goNextYear() ), 366 connect( mDateNavigator, SIGNAL( goNextYear() ),
367 mNavigator, SLOT( selectNextYear() ) ); 367 mNavigator, SLOT( selectNextYear() ) );
368 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 368 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
369 mNavigator, SLOT( selectPreviousMonth() ) ); 369 mNavigator, SLOT( selectPreviousMonth() ) );
370 connect( mDateNavigator, SIGNAL( goNextMonth() ), 370 connect( mDateNavigator, SIGNAL( goNextMonth() ),
371 mNavigator, SLOT( selectNextMonth() ) ); 371 mNavigator, SLOT( selectNextMonth() ) );
372 372
373 connect( mDateNavigator, SIGNAL( goPrevious() ), 373 connect( mDateNavigator, SIGNAL( goPrevious() ),
374 mNavigator, SLOT( selectPrevious() ) ); 374 mNavigator, SLOT( selectPrevious() ) );
375 connect( mDateNavigator, SIGNAL( goNext() ), 375 connect( mDateNavigator, SIGNAL( goNext() ),
376 mNavigator, SLOT( selectNext() ) ); 376 mNavigator, SLOT( selectNext() ) );
377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 377 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
378 mNavigator, SLOT( slotMonthSelect( int ) ) ); 378 mNavigator, SLOT( slotMonthSelect( int ) ) );
379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 379 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
380 mNavigator, SLOT( slotMonthSelect( int ) ) ); 380 mNavigator, SLOT( slotMonthSelect( int ) ) );
381 381
382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 382 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 383 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
384 384
385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 385 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
386 SLOT( eventAdded( Event *) ) ); 386 SLOT( eventAdded( Event *) ) );
387 387
388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 388 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
389 389
390 connect( this, SIGNAL( configChanged() ), 390 connect( this, SIGNAL( configChanged() ),
391 mDateNavigator, SLOT( updateConfig() ) ); 391 mDateNavigator, SLOT( updateConfig() ) );
392 392
393 connect( mTodoList, SIGNAL( newTodoSignal() ), 393 connect( mTodoList, SIGNAL( newTodoSignal() ),
394 SLOT( newTodo() ) ); 394 SLOT( newTodo() ) );
395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
396 SLOT( newSubTodo( Todo * ) ) ); 396 SLOT( newSubTodo( Todo * ) ) );
397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 397 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
398 SLOT( editTodo( Todo * ) ) ); 398 SLOT( editTodo( Todo * ) ) );
399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 399 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
400 SLOT( showTodo( Todo *) ) ); 400 SLOT( showTodo( Todo *) ) );
401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 401 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
402 SLOT( deleteTodo( Todo *) ) ); 402 SLOT( deleteTodo( Todo *) ) );
403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 403 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 404 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
405 SLOT( purgeCompleted() ) ); 405 SLOT( purgeCompleted() ) );
406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 406 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
407 SIGNAL( todoModified( Todo *, int ) ) ); 407 SIGNAL( todoModified( Todo *, int ) ) );
408 408
409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 409 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
410 this, SLOT ( cloneIncidence( Incidence * ) ) ); 410 this, SLOT ( cloneIncidence( Incidence * ) ) );
411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 411 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
412 this, SLOT (cancelIncidence( Incidence * ) ) ); 412 this, SLOT (cancelIncidence( Incidence * ) ) );
413 413
414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 414 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
415 this, SLOT ( moveIncidence( Incidence * ) ) ); 415 this, SLOT ( moveIncidence( Incidence * ) ) );
416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 416 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
417 this, SLOT ( beamIncidence( Incidence * ) ) ); 417 this, SLOT ( beamIncidence( Incidence * ) ) );
418 418
419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 419 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
420 this, SLOT ( todo_unsub( Todo * ) ) ); 420 this, SLOT ( todo_unsub( Todo * ) ) );
421 421
422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 422 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
423 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 423 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 424 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
425 SLOT( updateTodo( Todo *, int ) ) ); 425 SLOT( updateTodo( Todo *, int ) ) );
426 connect( this, SIGNAL( todoModified( Todo *, int )), this, 426 connect( this, SIGNAL( todoModified( Todo *, int )), this,
427 SLOT( changeTodoDisplay( Todo *, int ) ) ); 427 SLOT( changeTodoDisplay( Todo *, int ) ) );
428 428
429 429
430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 430 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 431 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 432 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 433 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
434 434
435 435
436 436
437 437
438 438
439 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 439 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
440 SLOT(checkClipboard())); 440 SLOT(checkClipboard()));
441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 441 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
442 SLOT( processTodoListSelection( Incidence * ) ) ); 442 SLOT( processTodoListSelection( Incidence * ) ) );
443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 443 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
444 444
445 // kdDebug() << "CalendarView::CalendarView() done" << endl; 445 // kdDebug() << "CalendarView::CalendarView() done" << endl;
446 446
447 mDateFrame = new QVBox(0,0,WType_Popup); 447 mDateFrame = new QVBox(0,0,WType_Popup);
448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 448 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 449 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
450 mDateFrame->setLineWidth(3); 450 mDateFrame->setLineWidth(3);
451 mDateFrame->hide(); 451 mDateFrame->hide();
452 mDateFrame->setCaption( i18n( "Pick a date to display")); 452 mDateFrame->setCaption( i18n( "Pick a date to display"));
453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 453 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
454 454
455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 455 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
456 456
457 mEventEditor = mDialogManager->getEventEditor(); 457 mEventEditor = mDialogManager->getEventEditor();
458 mTodoEditor = mDialogManager->getTodoEditor(); 458 mTodoEditor = mDialogManager->getTodoEditor();
459 459
460 mFlagEditDescription = false; 460 mFlagEditDescription = false;
461 461
462 mSuspendTimer = new QTimer( this ); 462 mSuspendTimer = new QTimer( this );
463 mAlarmTimer = new QTimer( this ); 463 mAlarmTimer = new QTimer( this );
464 mRecheckAlarmTimer = new QTimer( this ); 464 mRecheckAlarmTimer = new QTimer( this );
465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 465 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 466 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 467 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
468 mAlarmDialog = new AlarmDialog( this ); 468 mAlarmDialog = new AlarmDialog( this );
469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 469 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
470 mAlarmDialog->setServerNotification( false ); 470 mAlarmDialog->setServerNotification( false );
471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 471 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
472 472
473 473
474#ifndef DESKTOP_VERSION 474#ifndef DESKTOP_VERSION
475//US listen for arriving address resultsets 475//US listen for arriving address resultsets
476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 476 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 477 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
478#endif 478#endif
479 479
480} 480}
481 481
482 482
483CalendarView::~CalendarView() 483CalendarView::~CalendarView()
484{ 484{
485 // kdDebug() << "~CalendarView()" << endl; 485 // kdDebug() << "~CalendarView()" << endl;
486 //qDebug("CalendarView::~CalendarView() "); 486 //qDebug("CalendarView::~CalendarView() ");
487 delete mDialogManager; 487 delete mDialogManager;
488 delete mViewManager; 488 delete mViewManager;
489 delete mStorage; 489 delete mStorage;
490 delete mDateFrame ; 490 delete mDateFrame ;
491 delete beamDialog; 491 delete beamDialog;
492 //kdDebug() << "~CalendarView() done" << endl; 492 //kdDebug() << "~CalendarView() done" << endl;
493} 493}
494void CalendarView::timerAlarm() 494void CalendarView::timerAlarm()
495{ 495{
496 //qDebug("CalendarView::timerAlarm() "); 496 //qDebug("CalendarView::timerAlarm() ");
497 computeAlarm(mAlarmNotification ); 497 computeAlarm(mAlarmNotification );
498} 498}
499 499
500void CalendarView::suspendAlarm() 500void CalendarView::suspendAlarm()
501{ 501{
502 //qDebug(" CalendarView::suspendAlarm() "); 502 //qDebug(" CalendarView::suspendAlarm() ");
503 computeAlarm(mSuspendAlarmNotification ); 503 computeAlarm(mSuspendAlarmNotification );
504 504
505} 505}
506 506
507void CalendarView::startAlarm( QString mess , QString filename) 507void CalendarView::startAlarm( QString mess , QString filename)
508{ 508{
509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 509 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 510 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
511 511
512} 512}
513 513
514void CalendarView::checkNextTimerAlarm() 514void CalendarView::checkNextTimerAlarm()
515{ 515{
516 mCalendar->checkAlarmForIncidence( 0, true ); 516 mCalendar->checkAlarmForIncidence( 0, true );
517} 517}
518 518
519void CalendarView::computeAlarm( QString msg ) 519void CalendarView::computeAlarm( QString msg )
520{ 520{
521 521
522 QString mess = msg; 522 QString mess = msg;
523 QString mAlarmMessage = mess.mid( 9 ); 523 QString mAlarmMessage = mess.mid( 9 );
524 QString filename = MainWindow::resourcePath(); 524 QString filename = MainWindow::resourcePath();
525 filename += "koalarm.wav"; 525 filename += "koalarm.wav";
526 QString tempfilename; 526 QString tempfilename;
527 if ( mess.left( 13 ) == "suspend_alarm") { 527 if ( mess.left( 13 ) == "suspend_alarm") {
528 bool error = false; 528 bool error = false;
529 int len = mess.mid( 13 ).find("+++"); 529 int len = mess.mid( 13 ).find("+++");
530 if ( len < 2 ) 530 if ( len < 2 )
531 error = true; 531 error = true;
532 else { 532 else {
533 tempfilename = mess.mid( 13, len ); 533 tempfilename = mess.mid( 13, len );
534 if ( !QFile::exists( tempfilename ) ) 534 if ( !QFile::exists( tempfilename ) )
535 error = true; 535 error = true;
536 } 536 }
537 if ( ! error ) { 537 if ( ! error ) {
538 filename = tempfilename; 538 filename = tempfilename;
539 } 539 }
540 mAlarmMessage = mess.mid( 13+len+3 ); 540 mAlarmMessage = mess.mid( 13+len+3 );
541 //qDebug("suspend file %s ",tempfilename.latin1() ); 541 //qDebug("suspend file %s ",tempfilename.latin1() );
542 startAlarm( mAlarmMessage, filename); 542 startAlarm( mAlarmMessage, filename);
543 return; 543 return;
544 } 544 }
545 if ( mess.left( 11 ) == "timer_alarm") { 545 if ( mess.left( 11 ) == "timer_alarm") {
546 //mTimerTime = 0; 546 //mTimerTime = 0;
547 startAlarm( mess.mid( 11 ), filename ); 547 startAlarm( mess.mid( 11 ), filename );
548 return; 548 return;
549 } 549 }
550 if ( mess.left( 10 ) == "proc_alarm") { 550 if ( mess.left( 10 ) == "proc_alarm") {
551 bool error = false; 551 bool error = false;
552 int len = mess.mid( 10 ).find("+++"); 552 int len = mess.mid( 10 ).find("+++");
553 if ( len < 2 ) 553 if ( len < 2 )
554 error = true; 554 error = true;
555 else { 555 else {
556 tempfilename = mess.mid( 10, len ); 556 tempfilename = mess.mid( 10, len );
557 if ( !QFile::exists( tempfilename ) ) 557 if ( !QFile::exists( tempfilename ) )
558 error = true; 558 error = true;
559 } 559 }
560 if ( error ) { 560 if ( error ) {
561 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 561 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
562 mAlarmMessage += mess.mid( 10+len+3+9 ); 562 mAlarmMessage += mess.mid( 10+len+3+9 );
563 } else { 563 } else {
564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 564 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
565 //qDebug("-----system command %s ",tempfilename.latin1() ); 565 //qDebug("-----system command %s ",tempfilename.latin1() );
566#ifndef _WIN32_ 566#ifndef _WIN32_
567 if ( vfork () == 0 ) { 567 if ( vfork () == 0 ) {
568 execl ( tempfilename.latin1(), 0 ); 568 execl ( tempfilename.latin1(), 0 );
569 return; 569 return;
570 } 570 }
571#else 571#else
572 QProcess* p = new QProcess(); 572 QProcess* p = new QProcess();
573 p->addArgument( tempfilename.latin1() ); 573 p->addArgument( tempfilename.latin1() );
574 p->start(); 574 p->start();
575 return; 575 return;
576#endif 576#endif
577 577
578 return; 578 return;
579 } 579 }
580 580
581 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 581 //qDebug("+++++++system command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 11 ) == "audio_alarm") { 583 if ( mess.left( 11 ) == "audio_alarm") {
584 bool error = false; 584 bool error = false;
585 int len = mess.mid( 11 ).find("+++"); 585 int len = mess.mid( 11 ).find("+++");
586 if ( len < 2 ) 586 if ( len < 2 )
587 error = true; 587 error = true;
588 else { 588 else {
589 tempfilename = mess.mid( 11, len ); 589 tempfilename = mess.mid( 11, len );
590 if ( !QFile::exists( tempfilename ) ) 590 if ( !QFile::exists( tempfilename ) )
591 error = true; 591 error = true;
592 } 592 }
593 if ( ! error ) { 593 if ( ! error ) {
594 filename = tempfilename; 594 filename = tempfilename;
595 } 595 }
596 mAlarmMessage = mess.mid( 11+len+3+9 ); 596 mAlarmMessage = mess.mid( 11+len+3+9 );
597 //qDebug("audio file command %s ",tempfilename.latin1() ); 597 //qDebug("audio file command %s ",tempfilename.latin1() );
598 } 598 }
599 if ( mess.left( 9 ) == "cal_alarm") { 599 if ( mess.left( 9 ) == "cal_alarm") {
600 mAlarmMessage = mess.mid( 9 ) ; 600 mAlarmMessage = mess.mid( 9 ) ;
601 } 601 }
602 602
603 startAlarm( mAlarmMessage, filename ); 603 startAlarm( mAlarmMessage, filename );
604 604
605 605
606} 606}
607 607
608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 608void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
609{ 609{
610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 610 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
611 611
612 mSuspendAlarmNotification = noti; 612 mSuspendAlarmNotification = noti;
613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 613 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 614 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
615 mSuspendTimer->start( ms , true ); 615 mSuspendTimer->start( ms , true );
616 616
617} 617}
618 618
619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 619void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
620{ 620{
621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 621 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 622 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
623#ifndef DESKTOP_VERSION 623#ifndef DESKTOP_VERSION
624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 624 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
625#endif 625#endif
626 return; 626 return;
627 } 627 }
628 int maxSec; 628 int maxSec;
629 //maxSec = 5; //testing only 629 //maxSec = 5; //testing only
630 maxSec = 86400+3600; // one day+1hour 630 maxSec = 86400+3600; // one day+1hour
631 mAlarmNotification = noti; 631 mAlarmNotification = noti;
632 int sec = QDateTime::currentDateTime().secsTo( qdt ); 632 int sec = QDateTime::currentDateTime().secsTo( qdt );
633 if ( sec > maxSec ) { 633 if ( sec > maxSec ) {
634 mRecheckAlarmTimer->start( maxSec * 1000 ); 634 mRecheckAlarmTimer->start( maxSec * 1000 );
635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 635 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
636 return; 636 return;
637 } else { 637 } else {
638 mRecheckAlarmTimer->stop(); 638 mRecheckAlarmTimer->stop();
639 } 639 }
640 //qDebug("Alarm timer started with secs: %d ", sec); 640 //qDebug("Alarm timer started with secs: %d ", sec);
641 mAlarmTimer->start( sec *1000 , true ); 641 mAlarmTimer->start( sec *1000 , true );
642 642
643} 643}
644// called by mRecheckAlarmTimer to get next alarm 644// called by mRecheckAlarmTimer to get next alarm
645// we need this, because a QTimer has only a max range of 25 days 645// we need this, because a QTimer has only a max range of 25 days
646void CalendarView::recheckTimerAlarm() 646void CalendarView::recheckTimerAlarm()
647{ 647{
648 mAlarmTimer->stop(); 648 mAlarmTimer->stop();
649 mRecheckAlarmTimer->stop(); 649 mRecheckAlarmTimer->stop();
650 mCalendar->checkAlarmForIncidence( 0, true ); 650 mCalendar->checkAlarmForIncidence( 0, true );
651} 651}
652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 652void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
653{ 653{
654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 654 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 655 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
656#ifndef DESKTOP_VERSION 656#ifndef DESKTOP_VERSION
657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 657 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
658#endif 658#endif
659 return; 659 return;
660 } 660 }
661 mAlarmTimer->stop(); 661 mAlarmTimer->stop();
662} 662}
663void CalendarView::selectWeekNum ( int num ) 663void CalendarView::selectWeekNum ( int num )
664{ 664{
665 dateNavigator()->selectWeek( num ); 665 dateNavigator()->selectWeek( num );
666 mViewManager->showWeekView(); 666 mViewManager->showWeekView();
667} 667}
668KOViewManager *CalendarView::viewManager() 668KOViewManager *CalendarView::viewManager()
669{ 669{
670 return mViewManager; 670 return mViewManager;
671} 671}
672 672
673KODialogManager *CalendarView::dialogManager() 673KODialogManager *CalendarView::dialogManager()
674{ 674{
675 return mDialogManager; 675 return mDialogManager;
676} 676}
677 677
678QDate CalendarView::startDate() 678QDate CalendarView::startDate()
679{ 679{
680 DateList dates = mNavigator->selectedDates(); 680 DateList dates = mNavigator->selectedDates();
681 681
682 return dates.first(); 682 return dates.first();
683} 683}
684 684
685QDate CalendarView::endDate() 685QDate CalendarView::endDate()
686{ 686{
687 DateList dates = mNavigator->selectedDates(); 687 DateList dates = mNavigator->selectedDates();
688 688
689 return dates.last(); 689 return dates.last();
690} 690}
691 691
692 692
693void CalendarView::createPrinter() 693void CalendarView::createPrinter()
694{ 694{
695#ifndef KORG_NOPRINTER 695#ifndef KORG_NOPRINTER
696 if (!mCalPrinter) { 696 if (!mCalPrinter) {
697 mCalPrinter = new CalPrinter(this, mCalendar); 697 mCalPrinter = new CalPrinter(this, mCalendar);
698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 698 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
699 } 699 }
700#endif 700#endif
701} 701}
702 702
703 703
704//KOPrefs::instance()->mWriteBackFile 704//KOPrefs::instance()->mWriteBackFile
705//KOPrefs::instance()->mWriteBackExistingOnly 705//KOPrefs::instance()->mWriteBackExistingOnly
706 706
707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 707// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 708// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 709// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 710// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 711// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 712// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
713 713
714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 714int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
715{ 715{
716 716
717 // 0 equal 717 // 0 equal
718 // 1 take local 718 // 1 take local
719 // 2 take remote 719 // 2 take remote
720 // 3 cancel 720 // 3 cancel
721 QDateTime lastSync = mLastCalendarSync; 721 QDateTime lastSync = mLastCalendarSync;
722 QDateTime localMod = local->lastModified(); 722 QDateTime localMod = local->lastModified();
723 QDateTime remoteMod = remote->lastModified(); 723 QDateTime remoteMod = remote->lastModified();
724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 724 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
725 bool remCh, locCh; 725 bool remCh, locCh;
726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 726 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
727 //if ( remCh ) 727 //if ( remCh )
728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 728 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
729 locCh = ( localMod > mLastCalendarSync ); 729 locCh = ( localMod > mLastCalendarSync );
730 if ( !remCh && ! locCh ) { 730 if ( !remCh && ! locCh ) {
731 //qDebug("both not changed "); 731 //qDebug("both not changed ");
732 lastSync = localMod.addDays(1); 732 lastSync = localMod.addDays(1);
733 if ( mode <= SYNC_PREF_ASK ) 733 if ( mode <= SYNC_PREF_ASK )
734 return 0; 734 return 0;
735 } else { 735 } else {
736 if ( locCh ) { 736 if ( locCh ) {
737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 737 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
738 lastSync = localMod.addDays( -1 ); 738 lastSync = localMod.addDays( -1 );
739 if ( !remCh ) 739 if ( !remCh )
740 remoteMod = ( lastSync.addDays( -1 ) ); 740 remoteMod = ( lastSync.addDays( -1 ) );
741 } else { 741 } else {
742 //qDebug(" not loc changed "); 742 //qDebug(" not loc changed ");
743 lastSync = localMod.addDays( 1 ); 743 lastSync = localMod.addDays( 1 );
744 if ( remCh ) 744 if ( remCh )
745 remoteMod =( lastSync.addDays( 1 ) ); 745 remoteMod =( lastSync.addDays( 1 ) );
746 746
747 } 747 }
748 } 748 }
749 full = true; 749 full = true;
750 if ( mode < SYNC_PREF_ASK ) 750 if ( mode < SYNC_PREF_ASK )
751 mode = SYNC_PREF_ASK; 751 mode = SYNC_PREF_ASK;
752 } else { 752 } else {
753 if ( localMod == remoteMod ) 753 if ( localMod == remoteMod )
754 // if ( local->revision() == remote->revision() ) 754 // if ( local->revision() == remote->revision() )
755 return 0; 755 return 0;
756 756
757 } 757 }
758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 758 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
759 759
760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 760 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 761 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
762 //full = true; //debug only 762 //full = true; //debug only
763 if ( full ) { 763 if ( full ) {
764 bool equ = false; 764 bool equ = false;
765 if ( local->type() == "Event" ) { 765 if ( local->type() == "Event" ) {
766 equ = (*((Event*) local) == *((Event*) remote)); 766 equ = (*((Event*) local) == *((Event*) remote));
767 } 767 }
768 else if ( local->type() =="Todo" ) 768 else if ( local->type() =="Todo" )
769 equ = (*((Todo*) local) == (*(Todo*) remote)); 769 equ = (*((Todo*) local) == (*(Todo*) remote));
770 else if ( local->type() =="Journal" ) 770 else if ( local->type() =="Journal" )
771 equ = (*((Journal*) local) == *((Journal*) remote)); 771 equ = (*((Journal*) local) == *((Journal*) remote));
772 if ( equ ) { 772 if ( equ ) {
773 //qDebug("equal "); 773 //qDebug("equal ");
774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 774 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 775 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
776 } 776 }
777 if ( mode < SYNC_PREF_FORCE_LOCAL ) 777 if ( mode < SYNC_PREF_FORCE_LOCAL )
778 return 0; 778 return 0;
779 779
780 }//else //debug only 780 }//else //debug only
781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 781 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
782 } 782 }
783 int result; 783 int result;
784 bool localIsNew; 784 bool localIsNew;
785 //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() ); 785 //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() );
786 786
787 if ( full && mode < SYNC_PREF_NEWEST ) 787 if ( full && mode < SYNC_PREF_NEWEST )
788 mode = SYNC_PREF_ASK; 788 mode = SYNC_PREF_ASK;
789 789
790 switch( mode ) { 790 switch( mode ) {
791 case SYNC_PREF_LOCAL: 791 case SYNC_PREF_LOCAL:
792 if ( lastSync > remoteMod ) 792 if ( lastSync > remoteMod )
793 return 1; 793 return 1;
794 if ( lastSync > localMod ) 794 if ( lastSync > localMod )
795 return 2; 795 return 2;
796 return 1; 796 return 1;
797 break; 797 break;
798 case SYNC_PREF_REMOTE: 798 case SYNC_PREF_REMOTE:
799 if ( lastSync > remoteMod ) 799 if ( lastSync > remoteMod )
800 return 1; 800 return 1;
801 if ( lastSync > localMod ) 801 if ( lastSync > localMod )
802 return 2; 802 return 2;
803 return 2; 803 return 2;
804 break; 804 break;
805 case SYNC_PREF_NEWEST: 805 case SYNC_PREF_NEWEST:
806 if ( localMod > remoteMod ) 806 if ( localMod > remoteMod )
807 return 1; 807 return 1;
808 else 808 else
809 return 2; 809 return 2;
810 break; 810 break;
811 case SYNC_PREF_ASK: 811 case SYNC_PREF_ASK:
812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
813 if ( lastSync > remoteMod ) 813 if ( lastSync > remoteMod )
814 return 1; 814 return 1;
815 if ( lastSync > localMod ) 815 if ( lastSync > localMod )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
818 localIsNew = localMod >= remoteMod; 818 localIsNew = localMod >= remoteMod;
819 if ( localIsNew ) 819 if ( localIsNew )
820 getEventViewerDialog()->setColorMode( 1 ); 820 getEventViewerDialog()->setColorMode( 1 );
821 else 821 else
822 getEventViewerDialog()->setColorMode( 2 ); 822 getEventViewerDialog()->setColorMode( 2 );
823 getEventViewerDialog()->setIncidence(local); 823 getEventViewerDialog()->setIncidence(local);
824 if ( localIsNew ) 824 if ( localIsNew )
825 getEventViewerDialog()->setColorMode( 2 ); 825 getEventViewerDialog()->setColorMode( 2 );
826 else 826 else
827 getEventViewerDialog()->setColorMode( 1 ); 827 getEventViewerDialog()->setColorMode( 1 );
828 getEventViewerDialog()->addIncidence(remote); 828 getEventViewerDialog()->addIncidence(remote);
829 getEventViewerDialog()->setColorMode( 0 ); 829 getEventViewerDialog()->setColorMode( 0 );
830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 830 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 831 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
832 getEventViewerDialog()->showMe(); 832 getEventViewerDialog()->showMe();
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 mLastCalendarSync = QDateTime::currentDateTime(); 929 mLastCalendarSync = QDateTime::currentDateTime();
930 if ( mSyncManager->syncWithDesktop() ) { 930 if ( mSyncManager->syncWithDesktop() ) {
931 remote->resetPilotStat(1); 931 remote->resetPilotStat(1);
932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
935 } else { 935 } else {
936 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 936 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
937 } 937 }
938 } 938 }
939 QDateTime modifiedCalendar = mLastCalendarSync; 939 QDateTime modifiedCalendar = mLastCalendarSync;
940 eventLSync = getLastSyncEvent(); 940 eventLSync = getLastSyncEvent();
941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
942 if ( eventR ) { 942 if ( eventR ) {
943 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
944 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
945 945
946 } else { 946 } else {
947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
948 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
949 } else { 949 } else {
950 fullDateRange = true; 950 fullDateRange = true;
951 eventRSync = new Event(); 951 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
957 } 957 }
958 } 958 }
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 960 fullDateRange = true;
961 961
962 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 964
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 967 fullDateRange = true;
968 } 968 }
969 } 969 }
970 if ( mSyncManager->syncWithDesktop() ) { 970 if ( mSyncManager->syncWithDesktop() ) {
971 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
972 } 972 }
973 if ( fullDateRange ) 973 if ( fullDateRange )
974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
975 else 975 else
976 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
977 // for resyncing if own file has changed 977 // for resyncing if own file has changed
978 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
979 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
980 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
981 } 981 }
982 //qDebug("*************************** "); 982 //qDebug("*************************** ");
983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
984 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
985 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
986 Incidence* inL; 986 Incidence* inL;
987 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
988 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
989 989
990 int w = 300; 990 int w = 300;
991 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
992 w = 220; 992 w = 220;
993 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
994 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
995 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
997 bar.show(); 997 bar.show();
998 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
999 int incCounter = 0; 999 int incCounter = 0;
1000 while ( inR ) { 1000 while ( inR ) {
1001 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
1002 return false; 1002 return false;
1003 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
1004 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
1005 ++incCounter; 1005 ++incCounter;
1006 uid = inR->uid(); 1006 uid = inR->uid();
1007 bool skipIncidence = false; 1007 bool skipIncidence = false;
1008 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1009 skipIncidence = true; 1009 skipIncidence = true;
1010 QString idS; 1010 QString idS;
1011 qApp->processEvents(); 1011 qApp->processEvents();
1012 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1013 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1014 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1017 if ( take == 3 )
1018 return false; 1018 return false;
1019 if ( take == 1 ) {// take local ********************** 1019 if ( take == 1 ) {// take local **********************
1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1022 else 1022 else
1023 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1024 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1025 inR = inL->clone(); 1025 inR = inL->clone();
1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1028 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1029 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1030 if ( mSyncManager->syncWithDesktop() ) 1030 if ( mSyncManager->syncWithDesktop() )
1031 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1032 ++changedRemote; 1032 ++changedRemote;
1033 } else {// take remote ********************** 1033 } else {// take remote **********************
1034 idS = inL->IDStr(); 1034 idS = inL->IDStr();
1035 int pid = inL->pilotId(); 1035 int pid = inL->pilotId();
1036 local->deleteIncidence( inL ); 1036 local->deleteIncidence( inL );
1037 inL = inR->clone(); 1037 inL = inR->clone();
1038 if ( mSyncManager->syncWithDesktop() ) 1038 if ( mSyncManager->syncWithDesktop() )
1039 inL->setPilotId( pid ); 1039 inL->setPilotId( pid );
1040 inL->setIDStr( idS ); 1040 inL->setIDStr( idS );
1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1041 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1042 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1043 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1044 } 1044 }
1045 local->addIncidence( inL ); 1045 local->addIncidence( inL );
1046 ++changedLocal; 1046 ++changedLocal;
1047 } 1047 }
1048 } 1048 }
1049 } else { // no conflict ********** add or delete remote 1049 } else { // no conflict ********** add or delete remote
1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1050 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1051 QString des = eventLSync->description(); 1051 QString des = eventLSync->description();
1052 QString pref = "e"; 1052 QString pref = "e";
1053 if ( inR->type() == "Todo" ) 1053 if ( inR->type() == "Todo" )
1054 pref = "t"; 1054 pref = "t";
1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1055 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1056 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1057 //remote->deleteIncidence( inR ); 1057 //remote->deleteIncidence( inR );
1058 ++deletedEventR; 1058 ++deletedEventR;
1059 } else { 1059 } else {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 inL = inR->clone(); 1061 inL = inR->clone();
1062 inL->setIDStr( ":" ); 1062 inL->setIDStr( ":" );
1063 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1063 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1064 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1064 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1065 local->addIncidence( inL ); 1065 local->addIncidence( inL );
1066 ++addedEvent; 1066 ++addedEvent;
1067 } 1067 }
1068 } else { 1068 } else {
1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1069 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1070 inR->setLastModified( modifiedCalendar ); 1070 inR->setLastModified( modifiedCalendar );
1071 inL = inR->clone(); 1071 inL = inR->clone();
1072 inL->setIDStr( ":" ); 1072 inL->setIDStr( ":" );
1073 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1074 ++addedEvent; 1074 ++addedEvent;
1075 } else { 1075 } else {
1076 checkExternSyncEvent(eventRSyncSharp, inR); 1076 checkExternSyncEvent(eventRSyncSharp, inR);
1077 remote->deleteIncidence( inR ); 1077 remote->deleteIncidence( inR );
1078 ++deletedEventR; 1078 ++deletedEventR;
1079 } 1079 }
1080 } 1080 }
1081 } 1081 }
1082 } 1082 }
1083 inR = er.next(); 1083 inR = er.next();
1084 } 1084 }
1085 QPtrList<Incidence> el = local->rawIncidences(); 1085 QPtrList<Incidence> el = local->rawIncidences();
1086 inL = el.first(); 1086 inL = el.first();
1087 modulo = (el.count()/10)+1; 1087 modulo = (el.count()/10)+1;
1088 bar.setCaption (i18n("Add / remove events") ); 1088 bar.setCaption (i18n("Add / remove events") );
1089 bar.setTotalSteps ( el.count() ) ; 1089 bar.setTotalSteps ( el.count() ) ;
1090 bar.show(); 1090 bar.show();
1091 incCounter = 0; 1091 incCounter = 0;
1092 1092
1093 while ( inL ) { 1093 while ( inL ) {
1094 1094
1095 qApp->processEvents(); 1095 qApp->processEvents();
1096 if ( ! bar.isVisible() ) 1096 if ( ! bar.isVisible() )
1097 return false; 1097 return false;
1098 if ( incCounter % modulo == 0 ) 1098 if ( incCounter % modulo == 0 )
1099 bar.setProgress( incCounter ); 1099 bar.setProgress( incCounter );
1100 ++incCounter; 1100 ++incCounter;
1101 uid = inL->uid(); 1101 uid = inL->uid();
1102 bool skipIncidence = false; 1102 bool skipIncidence = false;
1103 if ( uid.left(15) == QString("last-syncEvent-") ) 1103 if ( uid.left(15) == QString("last-syncEvent-") )
1104 skipIncidence = true; 1104 skipIncidence = true;
1105 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1105 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1106 skipIncidence = true; 1106 skipIncidence = true;
1107 if ( !skipIncidence ) { 1107 if ( !skipIncidence ) {
1108 inR = remote->incidence( uid ); 1108 inR = remote->incidence( uid );
1109 if ( ! inR ) { // no conflict ********** add or delete local 1109 if ( ! inR ) { // no conflict ********** add or delete local
1110 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1110 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1111 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1111 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1114 ++deletedEventL; 1114 ++deletedEventL;
1115 } else { 1115 } else {
1116 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1116 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1117 inL->removeID(mCurrentSyncDevice ); 1117 inL->removeID(mCurrentSyncDevice );
1118 ++addedEventR; 1118 ++addedEventR;
1119 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1119 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1120 inL->setLastModified( modifiedCalendar ); 1120 inL->setLastModified( modifiedCalendar );
1121 inR = inL->clone(); 1121 inR = inL->clone();
1122 inR->setIDStr( ":" ); 1122 inR->setIDStr( ":" );
1123 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1123 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1124 remote->addIncidence( inR ); 1124 remote->addIncidence( inR );
1125 } 1125 }
1126 } 1126 }
1127 } else { 1127 } else {
1128 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1128 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1129 checkExternSyncEvent(eventLSyncSharp, inL); 1129 checkExternSyncEvent(eventLSyncSharp, inL);
1130 local->deleteIncidence( inL ); 1130 local->deleteIncidence( inL );
1131 ++deletedEventL; 1131 ++deletedEventL;
1132 } else { 1132 } else {
1133 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1133 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1134 ++addedEventR; 1134 ++addedEventR;
1135 inL->setLastModified( modifiedCalendar ); 1135 inL->setLastModified( modifiedCalendar );
1136 inR = inL->clone(); 1136 inR = inL->clone();
1137 inR->setIDStr( ":" ); 1137 inR->setIDStr( ":" );
1138 remote->addIncidence( inR ); 1138 remote->addIncidence( inR );
1139 } 1139 }
1140 } 1140 }
1141 } 1141 }
1142 } 1142 }
1143 } 1143 }
1144 inL = el.next(); 1144 inL = el.next();
1145 } 1145 }
1146 int delFut = 0; 1146 int delFut = 0;
1147 int remRem = 0; 1147 int remRem = 0;
1148 if ( mSyncManager->mWriteBackInFuture ) { 1148 if ( mSyncManager->mWriteBackInFuture ) {
1149 er = remote->rawIncidences(); 1149 er = remote->rawIncidences();
1150 remRem = er.count(); 1150 remRem = er.count();
1151 inR = er.first(); 1151 inR = er.first();
1152 QDateTime dt; 1152 QDateTime dt;
1153 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1153 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1154 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1154 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1155 while ( inR ) { 1155 while ( inR ) {
1156 if ( inR->type() == "Todo" ) { 1156 if ( inR->type() == "Todo" ) {
1157 Todo * t = (Todo*)inR; 1157 Todo * t = (Todo*)inR;
1158 if ( t->hasDueDate() ) 1158 if ( t->hasDueDate() )
1159 dt = t->dtDue(); 1159 dt = t->dtDue();
1160 else 1160 else
1161 dt = cur.addSecs( 62 ); 1161 dt = cur.addSecs( 62 );
1162 } 1162 }
1163 else if (inR->type() == "Event" ) { 1163 else if (inR->type() == "Event" ) {
1164 bool ok; 1164 bool ok;
1165 dt = inR->getNextOccurence( cur, &ok ); 1165 dt = inR->getNextOccurence( cur, &ok );
1166 if ( !ok ) 1166 if ( !ok )
1167 dt = cur.addSecs( -62 ); 1167 dt = cur.addSecs( -62 );
1168 } 1168 }
1169 else 1169 else
1170 dt = inR->dtStart(); 1170 dt = inR->dtStart();
1171 if ( dt < cur || dt > end ) { 1171 if ( dt < cur || dt > end ) {
1172 remote->deleteIncidence( inR ); 1172 remote->deleteIncidence( inR );
1173 ++delFut; 1173 ++delFut;
1174 } 1174 }
1175 inR = er.next(); 1175 inR = er.next();
1176 } 1176 }
1177 } 1177 }
1178 bar.hide(); 1178 bar.hide();
1179 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1179 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1180 eventLSync->setReadOnly( false ); 1180 eventLSync->setReadOnly( false );
1181 eventLSync->setDtStart( mLastCalendarSync ); 1181 eventLSync->setDtStart( mLastCalendarSync );
1182 eventRSync->setDtStart( mLastCalendarSync ); 1182 eventRSync->setDtStart( mLastCalendarSync );
1183 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1183 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1184 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1184 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1185 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1185 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1186 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1186 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1187 eventLSync->setReadOnly( true ); 1187 eventLSync->setReadOnly( true );
1188 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1188 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1189 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1189 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1190 remote->addEvent( eventRSync ); 1190 remote->addEvent( eventRSync );
1191 else 1191 else
1192 delete eventRSync; 1192 delete eventRSync;
1193 QString mes; 1193 QString mes;
1194 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1194 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1195 QString delmess; 1195 QString delmess;
1196 if ( delFut ) { 1196 if ( delFut ) {
1197 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1197 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut);
1198 mes += delmess; 1198 mes += delmess;
1199 } 1199 }
1200 mes = i18n("Local calendar changed!\n") +mes; 1200 mes = i18n("Local calendar changed!\n") +mes;
1201 mCalendar->checkAlarmForIncidence( 0, true ); 1201 mCalendar->checkAlarmForIncidence( 0, true );
1202 qDebug( mes ); 1202 qDebug( mes );
1203 if ( mSyncManager->mShowSyncSummary ) { 1203 if ( mSyncManager->mShowSyncSummary ) {
1204 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1204 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1205 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1205 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1206 qDebug("cancelled "); 1206 qDebug("cancelled ");
1207 return false; 1207 return false;
1208 } 1208 }
1209 } 1209 }
1210 return syncOK; 1210 return syncOK;
1211} 1211}
1212 1212
1213void CalendarView::setSyncDevice( QString s ) 1213void CalendarView::setSyncDevice( QString s )
1214{ 1214{
1215 mCurrentSyncDevice= s; 1215 mCurrentSyncDevice= s;
1216} 1216}
1217void CalendarView::setSyncName( QString s ) 1217void CalendarView::setSyncName( QString s )
1218{ 1218{
1219 mCurrentSyncName= s; 1219 mCurrentSyncName= s;
1220} 1220}
1221bool CalendarView::syncCalendar(QString filename, int mode) 1221bool CalendarView::syncCalendar(QString filename, int mode)
1222{ 1222{
1223 //qDebug("syncCalendar %s ", filename.latin1()); 1223 //qDebug("syncCalendar %s ", filename.latin1());
1224 mGlobalSyncMode = SYNC_MODE_NORMAL; 1224 mGlobalSyncMode = SYNC_MODE_NORMAL;
1225 CalendarLocal* calendar = new CalendarLocal(); 1225 CalendarLocal* calendar = new CalendarLocal();
1226 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1226 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1227 FileStorage* storage = new FileStorage( calendar ); 1227 FileStorage* storage = new FileStorage( calendar );
1228 bool syncOK = false; 1228 bool syncOK = false;
1229 storage->setFileName( filename ); 1229 storage->setFileName( filename );
1230 // qDebug("loading ... "); 1230 // qDebug("loading ... ");
1231 if ( storage->load() ) { 1231 if ( storage->load() ) {
1232 getEventViewerDialog()->setSyncMode( true ); 1232 getEventViewerDialog()->setSyncMode( true );
1233 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1233 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1234 getEventViewerDialog()->setSyncMode( false ); 1234 getEventViewerDialog()->setSyncMode( false );
1235 if ( syncOK ) { 1235 if ( syncOK ) {
1236 if ( mSyncManager->mWriteBackFile ) 1236 if ( mSyncManager->mWriteBackFile )
1237 { 1237 {
1238 storage->setSaveFormat( new ICalFormat() ); 1238 storage->setSaveFormat( new ICalFormat() );
1239 storage->save(); 1239 storage->save();
1240 } 1240 }
1241 } 1241 }
1242 setModified( true ); 1242 setModified( true );
1243 } 1243 }
1244 delete storage; 1244 delete storage;
1245 delete calendar; 1245 delete calendar;
1246 if ( syncOK ) 1246 if ( syncOK )
1247 updateView(); 1247 updateView();
1248 return syncOK; 1248 return syncOK;
1249} 1249}
1250 1250
1251void CalendarView::syncExternal( int mode ) 1251void CalendarView::syncExternal( int mode )
1252{ 1252{
1253 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1253 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1254 1254
1255 qApp->processEvents(); 1255 qApp->processEvents();
1256 CalendarLocal* calendar = new CalendarLocal(); 1256 CalendarLocal* calendar = new CalendarLocal();
1257 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1257 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1258 bool syncOK = false; 1258 bool syncOK = false;
1259 bool loadSuccess = false; 1259 bool loadSuccess = false;
1260 PhoneFormat* phoneFormat = 0; 1260 PhoneFormat* phoneFormat = 0;
1261 emit tempDisableBR(true); 1261 emit tempDisableBR(true);
1262#ifndef DESKTOP_VERSION 1262#ifndef DESKTOP_VERSION
1263 SharpFormat* sharpFormat = 0; 1263 SharpFormat* sharpFormat = 0;
1264 if ( mode == 0 ) { // sharp 1264 if ( mode == 0 ) { // sharp
1265 sharpFormat = new SharpFormat () ; 1265 sharpFormat = new SharpFormat () ;
1266 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1266 loadSuccess = sharpFormat->load( calendar, mCalendar );
1267 1267
1268 } else 1268 } else
1269#endif 1269#endif
1270 if ( mode == 1 ) { // phone 1270 if ( mode == 1 ) { // phone
1271 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1271 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1272 mSyncManager->mPhoneDevice, 1272 mSyncManager->mPhoneDevice,
1273 mSyncManager->mPhoneConnection, 1273 mSyncManager->mPhoneConnection,
1274 mSyncManager->mPhoneModel); 1274 mSyncManager->mPhoneModel);
1275 loadSuccess = phoneFormat->load( calendar,mCalendar); 1275 loadSuccess = phoneFormat->load( calendar,mCalendar);
1276 1276
1277 } else { 1277 } else {
1278 emit tempDisableBR(false); 1278 emit tempDisableBR(false);
1279 return; 1279 return;
1280 } 1280 }
1281 if ( loadSuccess ) { 1281 if ( loadSuccess ) {
1282 getEventViewerDialog()->setSyncMode( true ); 1282 getEventViewerDialog()->setSyncMode( true );
1283 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1283 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1284 getEventViewerDialog()->setSyncMode( false ); 1284 getEventViewerDialog()->setSyncMode( false );
1285 qApp->processEvents(); 1285 qApp->processEvents();
1286 if ( syncOK ) { 1286 if ( syncOK ) {
1287 if ( mSyncManager->mWriteBackFile ) 1287 if ( mSyncManager->mWriteBackFile )
1288 { 1288 {
1289 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1289 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1290 Incidence* inc = iL.first(); 1290 Incidence* inc = iL.first();
1291 if ( phoneFormat ) { 1291 if ( phoneFormat ) {
1292 while ( inc ) { 1292 while ( inc ) {
1293 inc->removeID(mCurrentSyncDevice); 1293 inc->removeID(mCurrentSyncDevice);
1294 inc = iL.next(); 1294 inc = iL.next();
1295 } 1295 }
1296 } 1296 }
1297#ifndef DESKTOP_VERSION 1297#ifndef DESKTOP_VERSION
1298 if ( sharpFormat ) 1298 if ( sharpFormat )
1299 sharpFormat->save(calendar); 1299 sharpFormat->save(calendar);
1300#endif 1300#endif
1301 if ( phoneFormat ) 1301 if ( phoneFormat )
1302 phoneFormat->save(calendar); 1302 phoneFormat->save(calendar);
1303 iL = calendar->rawIncidences(); 1303 iL = calendar->rawIncidences();
1304 inc = iL.first(); 1304 inc = iL.first();
1305 Incidence* loc; 1305 Incidence* loc;
1306 while ( inc ) { 1306 while ( inc ) {
1307 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1307 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1308 loc = mCalendar->incidence(inc->uid() ); 1308 loc = mCalendar->incidence(inc->uid() );
1309 if ( loc ) { 1309 if ( loc ) {
1310 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1310 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1311 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1311 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1312 } 1312 }
1313 } 1313 }
1314 inc = iL.next(); 1314 inc = iL.next();
1315 } 1315 }
1316 Incidence* lse = getLastSyncEvent(); 1316 Incidence* lse = getLastSyncEvent();
1317 if ( lse ) { 1317 if ( lse ) {
1318 lse->setReadOnly( false ); 1318 lse->setReadOnly( false );
1319 lse->setDescription( "" ); 1319 lse->setDescription( "" );
1320 lse->setReadOnly( true ); 1320 lse->setReadOnly( true );
1321 } 1321 }
1322 } 1322 }
1323 } else { 1323 } else {
1324 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1324 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1325 } 1325 }
1326 setModified( true ); 1326 setModified( true );
1327 } else { 1327 } else {
1328 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1328 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1329 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1329 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1330 question, i18n("Ok")) ; 1330 question, i18n("Ok")) ;
1331 1331
1332 } 1332 }
1333 delete calendar; 1333 delete calendar;
1334 updateView(); 1334 updateView();
1335 emit tempDisableBR(false); 1335 emit tempDisableBR(false);
1336 return ;//syncOK; 1336 return ;//syncOK;
1337 1337
1338} 1338}
1339 1339
1340bool CalendarView::importBday() 1340bool CalendarView::importBday()
1341{ 1341{
1342#ifndef KORG_NOKABC 1342#ifndef KORG_NOKABC
1343 1343
1344#ifdef DESKTOP_VERSION 1344#ifdef DESKTOP_VERSION
1345 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1345 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1346 KABC::AddressBook::Iterator it; 1346 KABC::AddressBook::Iterator it;
1347 int count = 0; 1347 int count = 0;
1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1348 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1349 ++count; 1349 ++count;
1350 } 1350 }
1351 QProgressBar bar(count,0 ); 1351 QProgressBar bar(count,0 );
1352 int w = 300; 1352 int w = 300;
1353 if ( QApplication::desktop()->width() < 320 ) 1353 if ( QApplication::desktop()->width() < 320 )
1354 w = 220; 1354 w = 220;
1355 int h = bar.sizeHint().height() ; 1355 int h = bar.sizeHint().height() ;
1356 int dw = QApplication::desktop()->width(); 1356 int dw = QApplication::desktop()->width();
1357 int dh = QApplication::desktop()->height(); 1357 int dh = QApplication::desktop()->height();
1358 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1358 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1359 bar.show(); 1359 bar.show();
1360 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1360 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1361 qApp->processEvents(); 1361 qApp->processEvents();
1362 count = 0; 1362 count = 0;
1363 int addCount = 0; 1363 int addCount = 0;
1364 KCal::Attendee* a = 0; 1364 KCal::Attendee* a = 0;
1365 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1365 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1366 if ( ! bar.isVisible() ) 1366 if ( ! bar.isVisible() )
1367 return false; 1367 return false;
1368 bar.setProgress( count++ ); 1368 bar.setProgress( count++ );
1369 qApp->processEvents(); 1369 qApp->processEvents();
1370 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1370 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1371 if ( (*it).birthday().date().isValid() ){ 1371 if ( (*it).birthday().date().isValid() ){
1372 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1372 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1373 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1373 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1374 ++addCount; 1374 ++addCount;
1375 } 1375 }
1376 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1376 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1377 if ( anni.isValid() ){ 1377 if ( anni.isValid() ){
1378 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1378 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1379 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1379 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1380 ++addCount; 1380 ++addCount;
1381 } 1381 }
1382 } 1382 }
1383 updateView(); 1383 updateView();
1384 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1384 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1385#else //DESKTOP_VERSION 1385#else //DESKTOP_VERSION
1386 1386
1387 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1387 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1388 // the result should now arrive through method insertBirthdays 1388 // the result should now arrive through method insertBirthdays
1389 1389
1390#endif //DESKTOP_VERSION 1390#endif //DESKTOP_VERSION
1391 1391
1392#endif //KORG_NOKABC 1392#endif //KORG_NOKABC
1393 1393
1394 1394
1395 return true; 1395 return true;
1396} 1396}
1397 1397
1398// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1398// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1399void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1399void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1400 const QStringList& anniversaryList, const QStringList& realNameList, 1400 const QStringList& anniversaryList, const QStringList& realNameList,
1401 const QStringList& emailList, const QStringList& assembledNameList, 1401 const QStringList& emailList, const QStringList& assembledNameList,
1402 const QStringList& uidList) 1402 const QStringList& uidList)
1403{ 1403{
1404 qDebug("CalendarView::insertBirthdays"); 1404 qDebug("CalendarView::insertBirthdays");
1405 if (uid == this->name()) 1405 if (uid == this->name())
1406 { 1406 {
1407 int count = birthdayList.count(); 1407 int count = birthdayList.count();
1408 int addCount = 0; 1408 int addCount = 0;
1409 KCal::Attendee* a = 0; 1409 KCal::Attendee* a = 0;
1410 1410
1411 qDebug("CalView 1 %i", count); 1411 qDebug("CalView 1 %i", count);
1412 1412
1413 QProgressBar bar(count,0 ); 1413 QProgressBar bar(count,0 );
1414 int w = 300; 1414 int w = 300;
1415 if ( QApplication::desktop()->width() < 320 ) 1415 if ( QApplication::desktop()->width() < 320 )
1416 w = 220; 1416 w = 220;
1417 int h = bar.sizeHint().height() ; 1417 int h = bar.sizeHint().height() ;
1418 int dw = QApplication::desktop()->width(); 1418 int dw = QApplication::desktop()->width();
1419 int dh = QApplication::desktop()->height(); 1419 int dh = QApplication::desktop()->height();
1420 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1420 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1421 bar.show(); 1421 bar.show();
1422 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1422 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1423 qApp->processEvents(); 1423 qApp->processEvents();
1424 1424
1425 QDate birthday; 1425 QDate birthday;
1426 QDate anniversary; 1426 QDate anniversary;
1427 QString realName; 1427 QString realName;
1428 QString email; 1428 QString email;
1429 QString assembledName; 1429 QString assembledName;
1430 QString uid; 1430 QString uid;
1431 bool ok = true; 1431 bool ok = true;
1432 for ( int i = 0; i < count; i++) 1432 for ( int i = 0; i < count; i++)
1433 { 1433 {
1434 if ( ! bar.isVisible() ) 1434 if ( ! bar.isVisible() )
1435 return; 1435 return;
1436 bar.setProgress( i ); 1436 bar.setProgress( i );
1437 qApp->processEvents(); 1437 qApp->processEvents();
1438 1438
1439 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1439 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1440 if (!ok) { 1440 if (!ok) {
1441 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1441 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1442 } 1442 }
1443 1443
1444 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1444 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1445 if (!ok) { 1445 if (!ok) {
1446 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1446 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1447 } 1447 }
1448 realName = realNameList[i]; 1448 realName = realNameList[i];
1449 email = emailList[i]; 1449 email = emailList[i];
1450 assembledName = assembledNameList[i]; 1450 assembledName = assembledNameList[i];
1451 uid = uidList[i]; 1451 uid = uidList[i];
1452 //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() ); 1452 //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() );
1453 1453
1454 if ( birthday.isValid() ){ 1454 if ( birthday.isValid() ){
1455 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1455 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1456 KCal::Attendee::ReqParticipant,uid) ; 1456 KCal::Attendee::ReqParticipant,uid) ;
1457 if ( addAnniversary( birthday, assembledName, a, true ) ) 1457 if ( addAnniversary( birthday, assembledName, a, true ) )
1458 ++addCount; 1458 ++addCount;
1459 } 1459 }
1460 1460
1461 if ( anniversary.isValid() ){ 1461 if ( anniversary.isValid() ){
1462 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1462 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1463 KCal::Attendee::ReqParticipant,uid) ; 1463 KCal::Attendee::ReqParticipant,uid) ;
1464 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1464 if ( addAnniversary( anniversary, assembledName, a, false ) )
1465 ++addCount; 1465 ++addCount;
1466 } 1466 }
1467 } 1467 }
1468 1468
1469 updateView(); 1469 updateView();
1470 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1470 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1471 1471
1472 } 1472 }
1473 1473
1474} 1474}
1475 1475
1476 1476
1477 1477
1478bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1478bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1479{ 1479{
1480 //qDebug("addAnni "); 1480 //qDebug("addAnni ");
1481 Event * ev = new Event(); 1481 Event * ev = new Event();
1482 if ( a ) { 1482 if ( a ) {
1483 ev->addAttendee( a ); 1483 ev->addAttendee( a );
1484 } 1484 }
1485 QString kind; 1485 QString kind;
1486 if ( birthday ) 1486 if ( birthday )
1487 kind = i18n( "Birthday" ); 1487 kind = i18n( "Birthday" );
1488 else 1488 else
1489 kind = i18n( "Anniversary" ); 1489 kind = i18n( "Anniversary" );
1490 ev->setSummary( name + " - " + kind ); 1490 ev->setSummary( name + " - " + kind );
1491 ev->setOrganizer(a->email()); 1491 ev->setOrganizer(a->email());
1492 ev->setCategories( kind ); 1492 ev->setCategories( kind );
1493 ev->setDtStart( QDateTime(date) ); 1493 ev->setDtStart( QDateTime(date) );
1494 ev->setDtEnd( QDateTime(date) ); 1494 ev->setDtEnd( QDateTime(date) );
1495 ev->setFloats( true ); 1495 ev->setFloats( true );
1496 Recurrence * rec = ev->recurrence(); 1496 Recurrence * rec = ev->recurrence();
1497 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1497 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1498 rec->addYearlyNum( date.month() ); 1498 rec->addYearlyNum( date.month() );
1499 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1499 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1500 delete ev; 1500 delete ev;
1501 return false; 1501 return false;
1502 } 1502 }
1503 return true; 1503 return true;
1504 1504
1505} 1505}
1506bool CalendarView::importQtopia( const QString &categories, 1506bool CalendarView::importQtopia( const QString &categories,
1507 const QString &datebook, 1507 const QString &datebook,
1508 const QString &todolist ) 1508 const QString &todolist )
1509{ 1509{
1510 1510
1511 QtopiaFormat qtopiaFormat; 1511 QtopiaFormat qtopiaFormat;
1512 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1512 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1513 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1513 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1514 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1514 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1515 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1515 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1516 1516
1517 updateView(); 1517 updateView();
1518 return true; 1518 return true;
1519 1519
1520#if 0 1520#if 0
1521 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1521 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1522 mCurrentSyncDevice = "qtopia-XML"; 1522 mCurrentSyncDevice = "qtopia-XML";
1523 if ( mSyncManager->mAskForPreferences ) 1523 if ( mSyncManager->mAskForPreferences )
1524 edit_sync_options(); 1524 edit_sync_options();
1525 qApp->processEvents(); 1525 qApp->processEvents();
1526 CalendarLocal* calendar = new CalendarLocal(); 1526 CalendarLocal* calendar = new CalendarLocal();
1527 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1527 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1528 bool syncOK = false; 1528 bool syncOK = false;
1529 QtopiaFormat qtopiaFormat; 1529 QtopiaFormat qtopiaFormat;
1530 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1530 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1531 bool loadOk = true; 1531 bool loadOk = true;
1532 if ( !categories.isEmpty() ) 1532 if ( !categories.isEmpty() )
1533 loadOk = qtopiaFormat.load( calendar, categories ); 1533 loadOk = qtopiaFormat.load( calendar, categories );
1534 if ( loadOk && !datebook.isEmpty() ) 1534 if ( loadOk && !datebook.isEmpty() )
1535 loadOk = qtopiaFormat.load( calendar, datebook ); 1535 loadOk = qtopiaFormat.load( calendar, datebook );
1536 if ( loadOk && !todolist.isEmpty() ) 1536 if ( loadOk && !todolist.isEmpty() )
1537 loadOk = qtopiaFormat.load( calendar, todolist ); 1537 loadOk = qtopiaFormat.load( calendar, todolist );
1538 1538
1539 if ( loadOk ) { 1539 if ( loadOk ) {
1540 getEventViewerDialog()->setSyncMode( true ); 1540 getEventViewerDialog()->setSyncMode( true );
1541 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1541 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1542 getEventViewerDialog()->setSyncMode( false ); 1542 getEventViewerDialog()->setSyncMode( false );
1543 qApp->processEvents(); 1543 qApp->processEvents();
1544 if ( syncOK ) { 1544 if ( syncOK ) {
1545 if ( mSyncManager->mWriteBackFile ) 1545 if ( mSyncManager->mWriteBackFile )
1546 { 1546 {
1547 // write back XML file 1547 // write back XML file
1548 1548
1549 } 1549 }
1550 setModified( true ); 1550 setModified( true );
1551 } 1551 }
1552 } else { 1552 } else {
1553 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1553 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1554 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1554 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1555 question, i18n("Ok")) ; 1555 question, i18n("Ok")) ;
1556 } 1556 }
1557 delete calendar; 1557 delete calendar;
1558 updateView(); 1558 updateView();
1559 return syncOK; 1559 return syncOK;
1560 1560
1561 1561
1562#endif 1562#endif
1563 1563
1564} 1564}
1565 1565
1566void CalendarView::setSyncEventsReadOnly() 1566void CalendarView::setSyncEventsReadOnly()
1567{ 1567{
1568 Event * ev; 1568 Event * ev;
1569 QPtrList<Event> eL = mCalendar->rawEvents(); 1569 QPtrList<Event> eL = mCalendar->rawEvents();
1570 ev = eL.first(); 1570 ev = eL.first();
1571 while ( ev ) { 1571 while ( ev ) {
1572 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1572 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1573 ev->setReadOnly( true ); 1573 ev->setReadOnly( true );
1574 ev = eL.next(); 1574 ev = eL.next();
1575 } 1575 }
1576} 1576}
1577bool CalendarView::openCalendar(QString filename, bool merge) 1577bool CalendarView::openCalendar(QString filename, bool merge)
1578{ 1578{
1579 1579
1580 if (filename.isEmpty()) { 1580 if (filename.isEmpty()) {
1581 return false; 1581 return false;
1582 } 1582 }
1583 1583
1584 if (!QFile::exists(filename)) { 1584 if (!QFile::exists(filename)) {
1585 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1585 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1586 return false; 1586 return false;
1587 } 1587 }
1588 1588
1589 globalFlagBlockAgenda = 1; 1589 globalFlagBlockAgenda = 1;
1590 if (!merge) mCalendar->close(); 1590 if (!merge) mCalendar->close();
1591 1591
1592 mStorage->setFileName( filename ); 1592 mStorage->setFileName( filename );
1593 1593
1594 if ( mStorage->load() ) { 1594 if ( mStorage->load() ) {
1595 if ( merge ) ;//setModified( true ); 1595 if ( merge ) ;//setModified( true );
1596 else { 1596 else {
1597 //setModified( true ); 1597 //setModified( true );
1598 mViewManager->setDocumentId( filename ); 1598 mViewManager->setDocumentId( filename );
1599 mDialogManager->setDocumentId( filename ); 1599 mDialogManager->setDocumentId( filename );
1600 mTodoList->setDocumentId( filename ); 1600 mTodoList->setDocumentId( filename );
1601 } 1601 }
1602 globalFlagBlockAgenda = 2; 1602 globalFlagBlockAgenda = 2;
1603 // if ( getLastSyncEvent() ) 1603 // if ( getLastSyncEvent() )
1604 // getLastSyncEvent()->setReadOnly( true ); 1604 // getLastSyncEvent()->setReadOnly( true );
1605 mCalendar->reInitAlarmSettings(); 1605 mCalendar->reInitAlarmSettings();
1606 setSyncEventsReadOnly(); 1606 setSyncEventsReadOnly();
1607 updateUnmanagedViews(); 1607 updateUnmanagedViews();
1608 updateView(); 1608 updateView();
1609 if ( filename != MainWindow::defaultFileName() ) { 1609 if ( filename != MainWindow::defaultFileName() ) {
1610 saveCalendar( MainWindow::defaultFileName() ); 1610 saveCalendar( MainWindow::defaultFileName() );
1611 } else { 1611 } else {
1612 QFileInfo finf ( MainWindow::defaultFileName()); 1612 QFileInfo finf ( MainWindow::defaultFileName());
1613 if ( finf.exists() ) { 1613 if ( finf.exists() ) {
1614 setLoadedFileVersion( finf.lastModified () ); 1614 setLoadedFileVersion( finf.lastModified () );
1615 } 1615 }
1616 } 1616 }
1617 return true; 1617 return true;
1618 } else { 1618 } else {
1619 // while failing to load, the calendar object could 1619 // while failing to load, the calendar object could
1620 // have become partially populated. Clear it out. 1620 // have become partially populated. Clear it out.
1621 if ( !merge ) { 1621 if ( !merge ) {
1622 mCalendar->close(); 1622 mCalendar->close();
1623 mViewManager->setDocumentId( filename ); 1623 mViewManager->setDocumentId( filename );
1624 mDialogManager->setDocumentId( filename ); 1624 mDialogManager->setDocumentId( filename );
1625 mTodoList->setDocumentId( filename ); 1625 mTodoList->setDocumentId( filename );
1626 } 1626 }
1627 1627
1628 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1628 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1629 1629
1630 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1630 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1631 globalFlagBlockAgenda = 2; 1631 globalFlagBlockAgenda = 2;
1632 mCalendar->reInitAlarmSettings(); 1632 mCalendar->reInitAlarmSettings();
1633 setSyncEventsReadOnly(); 1633 setSyncEventsReadOnly();
1634 updateUnmanagedViews(); 1634 updateUnmanagedViews();
1635 updateView(); 1635 updateView();
1636 } 1636 }
1637 return false; 1637 return false;
1638} 1638}
1639void CalendarView::showOpenError() 1639void CalendarView::showOpenError()
1640{ 1640{
1641 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1641 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1642} 1642}
1643void CalendarView::setLoadedFileVersion(QDateTime dt) 1643void CalendarView::setLoadedFileVersion(QDateTime dt)
1644{ 1644{
1645 loadedFileVersion = dt; 1645 loadedFileVersion = dt;
1646} 1646}
1647bool CalendarView::checkFileChanged(QString fn) 1647bool CalendarView::checkFileChanged(QString fn)
1648{ 1648{
1649 QFileInfo finf ( fn ); 1649 QFileInfo finf ( fn );
1650 if ( !finf.exists() ) 1650 if ( !finf.exists() )
1651 return true; 1651 return true;
1652 QDateTime dt = finf.lastModified (); 1652 QDateTime dt = finf.lastModified ();
1653 if ( dt <= loadedFileVersion ) 1653 if ( dt <= loadedFileVersion )
1654 return false; 1654 return false;
1655 return true; 1655 return true;
1656 1656
1657} 1657}
1658void CalendarView::watchSavedFile() 1658void CalendarView::watchSavedFile()
1659{ 1659{
1660 QFileInfo finf ( MainWindow::defaultFileName()); 1660 QFileInfo finf ( MainWindow::defaultFileName());
1661 if ( !finf.exists() ) 1661 if ( !finf.exists() )
1662 return; 1662 return;
1663 QDateTime dt = finf.lastModified (); 1663 QDateTime dt = finf.lastModified ();
1664 if ( dt < loadedFileVersion ) { 1664 if ( dt < loadedFileVersion ) {
1665 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1665 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1666 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1666 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1667 return; 1667 return;
1668 } 1668 }
1669 loadedFileVersion = dt; 1669 loadedFileVersion = dt;
1670} 1670}
1671 1671
1672bool CalendarView::checkFileVersion(QString fn) 1672bool CalendarView::checkFileVersion(QString fn)
1673{ 1673{
1674 QFileInfo finf ( fn ); 1674 QFileInfo finf ( fn );
1675 if ( !finf.exists() ) 1675 if ( !finf.exists() )
1676 return true; 1676 return true;
1677 QDateTime dt = finf.lastModified (); 1677 QDateTime dt = finf.lastModified ();
1678 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1678 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1679 //qDebug("file on disk version %s",dt.toString().latin1()); 1679 //qDebug("file on disk version %s",dt.toString().latin1());
1680 if ( dt <= loadedFileVersion ) 1680 if ( dt <= loadedFileVersion )
1681 return true; 1681 return true;
1682 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1682 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1683 i18n("KO/Pi Warning"),i18n("Overwrite"), 1683 i18n("KO/Pi Warning"),i18n("Overwrite"),
1684 i18n("Sync+save")); 1684 i18n("Sync+save"));
1685 1685
1686 if ( km == KMessageBox::Cancel ) 1686 if ( km == KMessageBox::Cancel )
1687 return false; 1687 return false;
1688 if ( km == KMessageBox::Yes ) 1688 if ( km == KMessageBox::Yes )
1689 return true; 1689 return true;
1690 1690
1691 setSyncDevice("deleteaftersync" ); 1691 setSyncDevice("deleteaftersync" );
1692 mSyncManager->mAskForPreferences = true; 1692 mSyncManager->mAskForPreferences = true;
1693 mSyncManager->mSyncAlgoPrefs = 3; 1693 mSyncManager->mSyncAlgoPrefs = 3;
1694 mSyncManager->mWriteBackFile = false; 1694 mSyncManager->mWriteBackFile = false;
1695 mSyncManager->mWriteBackExistingOnly = false; 1695 mSyncManager->mWriteBackExistingOnly = false;
1696 mSyncManager->mShowSyncSummary = false; 1696 mSyncManager->mShowSyncSummary = false;
1697 syncCalendar( fn, 3 ); 1697 syncCalendar( fn, 3 );
1698 Event * e = getLastSyncEvent(); 1698 Event * e = getLastSyncEvent();
1699 mCalendar->deleteEvent ( e ); 1699 mCalendar->deleteEvent ( e );
1700 updateView(); 1700 updateView();
1701 return true; 1701 return true;
1702} 1702}
1703 1703
1704bool CalendarView::saveCalendar( QString filename ) 1704bool CalendarView::saveCalendar( QString filename )
1705{ 1705{
1706 1706
1707 // Store back all unsaved data into calendar object 1707 // Store back all unsaved data into calendar object
1708 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1708 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1709 if ( mViewManager->currentView() ) 1709 if ( mViewManager->currentView() )
1710 mViewManager->currentView()->flushView(); 1710 mViewManager->currentView()->flushView();
1711 1711
1712 1712
1713 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1713 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1714 mStorage->setSaveFormat( new ICalFormat() ); 1714 mStorage->setSaveFormat( new ICalFormat() );
1715 mStorage->setFileName( filename ); 1715 mStorage->setFileName( filename );
1716 bool success; 1716 bool success;
1717 success = mStorage->save(); 1717 success = mStorage->save();
1718 if ( !success ) { 1718 if ( !success ) {
1719 return false; 1719 return false;
1720 } 1720 }
1721 if ( filename == MainWindow::defaultFileName() ) { 1721 if ( filename == MainWindow::defaultFileName() ) {
1722 setLoadedFileVersion( lfv ); 1722 setLoadedFileVersion( lfv );
1723 watchSavedFile(); 1723 watchSavedFile();
1724 } 1724 }
1725 return true; 1725 return true;
1726} 1726}
1727 1727
1728void CalendarView::closeCalendar() 1728void CalendarView::closeCalendar()
1729{ 1729{
1730 1730
1731 // child windows no longer valid 1731 // child windows no longer valid
1732 emit closingDown(); 1732 emit closingDown();
1733 1733
1734 mCalendar->close(); 1734 mCalendar->close();
1735 setModified(false); 1735 setModified(false);
1736 updateView(); 1736 updateView();
1737} 1737}
1738 1738
1739void CalendarView::archiveCalendar() 1739void CalendarView::archiveCalendar()
1740{ 1740{
1741 mDialogManager->showArchiveDialog(); 1741 mDialogManager->showArchiveDialog();
1742} 1742}
1743 1743
1744 1744
1745void CalendarView::readSettings() 1745void CalendarView::readSettings()
1746{ 1746{
1747 1747
1748 1748
1749 // mViewManager->showAgendaView(); 1749 // mViewManager->showAgendaView();
1750 QString str; 1750 QString str;
1751 //qDebug("CalendarView::readSettings() "); 1751 //qDebug("CalendarView::readSettings() ");
1752 // read settings from the KConfig, supplying reasonable 1752 // read settings from the KConfig, supplying reasonable
1753 // defaults where none are to be found 1753 // defaults where none are to be found
1754 KConfig *config = KOGlobals::config(); 1754 KConfig *config = KOGlobals::config();
1755#ifndef KORG_NOSPLITTER 1755#ifndef KORG_NOSPLITTER
1756 config->setGroup("KOrganizer Geometry"); 1756 config->setGroup("KOrganizer Geometry");
1757 1757
1758 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1758 QValueList<int> sizes = config->readIntListEntry("Separator1");
1759 if (sizes.count() != 2) { 1759 if (sizes.count() != 2) {
1760 sizes << mDateNavigator->minimumSizeHint().width(); 1760 sizes << mDateNavigator->minimumSizeHint().width();
1761 sizes << 300; 1761 sizes << 300;
1762 } 1762 }
1763 mPanner->setSizes(sizes); 1763 mPanner->setSizes(sizes);
1764 1764
1765 sizes = config->readIntListEntry("Separator2"); 1765 sizes = config->readIntListEntry("Separator2");
1766 if ( ( mResourceView && sizes.count() == 4 ) || 1766 if ( ( mResourceView && sizes.count() == 4 ) ||
1767 ( !mResourceView && sizes.count() == 3 ) ) { 1767 ( !mResourceView && sizes.count() == 3 ) ) {
1768 mLeftSplitter->setSizes(sizes); 1768 mLeftSplitter->setSizes(sizes);
1769 } 1769 }
1770#endif 1770#endif
1771 globalFlagBlockAgenda = 1; 1771 globalFlagBlockAgenda = 1;
1772 mViewManager->showAgendaView(); 1772 mViewManager->showAgendaView();
1773 //mViewManager->readSettings( config ); 1773 //mViewManager->readSettings( config );
1774 mTodoList->restoreLayout(config,QString("Todo Layout")); 1774 mTodoList->restoreLayout(config,QString("Todo Layout"));
1775 readFilterSettings(config); 1775 readFilterSettings(config);
1776 config->setGroup( "Views" ); 1776 config->setGroup( "Views" );
1777 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1777 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1778 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1778 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1779 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1779 else if ( dateCount == 7 ) mNavigator->selectWeek();
1780 else mNavigator->selectDates( dateCount ); 1780 else mNavigator->selectDates( dateCount );
1781 // mViewManager->readSettings( config ); 1781 // mViewManager->readSettings( config );
1782 updateConfig(); 1782 updateConfig();
1783 globalFlagBlockAgenda = 2; 1783 globalFlagBlockAgenda = 2;
1784 mViewManager->readSettings( config ); 1784 mViewManager->readSettings( config );
1785#ifdef DESKTOP_VERSION 1785#ifdef DESKTOP_VERSION
1786 config->setGroup("WidgetLayout"); 1786 config->setGroup("WidgetLayout");
1787 QStringList list; 1787 QStringList list;
1788 list = config->readListEntry("MainLayout"); 1788 list = config->readListEntry("MainLayout");
1789 int x,y,w,h; 1789 int x,y,w,h;
1790 if ( ! list.isEmpty() ) { 1790 if ( ! list.isEmpty() ) {
1791 x = list[0].toInt(); 1791 x = list[0].toInt();
1792 y = list[1].toInt(); 1792 y = list[1].toInt();
1793 w = list[2].toInt(); 1793 w = list[2].toInt();
1794 h = list[3].toInt(); 1794 h = list[3].toInt();
1795 topLevelWidget()->setGeometry(x,y,w,h); 1795 topLevelWidget()->setGeometry(x,y,w,h);
1796 1796
1797 } else { 1797 } else {
1798 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1798 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1799 } 1799 }
1800 list = config->readListEntry("EditEventLayout"); 1800 list = config->readListEntry("EditEventLayout");
1801 if ( ! list.isEmpty() ) { 1801 if ( ! list.isEmpty() ) {
1802 x = list[0].toInt(); 1802 x = list[0].toInt();
1803 y = list[1].toInt(); 1803 y = list[1].toInt();
1804 w = list[2].toInt(); 1804 w = list[2].toInt();
1805 h = list[3].toInt(); 1805 h = list[3].toInt();
1806 mEventEditor->setGeometry(x,y,w,h); 1806 mEventEditor->setGeometry(x,y,w,h);
1807 1807
1808 } 1808 }
1809 list = config->readListEntry("EditTodoLayout"); 1809 list = config->readListEntry("EditTodoLayout");
1810 if ( ! list.isEmpty() ) { 1810 if ( ! list.isEmpty() ) {
1811 x = list[0].toInt(); 1811 x = list[0].toInt();
1812 y = list[1].toInt(); 1812 y = list[1].toInt();
1813 w = list[2].toInt(); 1813 w = list[2].toInt();
1814 h = list[3].toInt(); 1814 h = list[3].toInt();
1815 mTodoEditor->setGeometry(x,y,w,h); 1815 mTodoEditor->setGeometry(x,y,w,h);
1816 1816
1817 } 1817 }
1818 list = config->readListEntry("ViewerLayout"); 1818 list = config->readListEntry("ViewerLayout");
1819 if ( ! list.isEmpty() ) { 1819 if ( ! list.isEmpty() ) {
1820 x = list[0].toInt(); 1820 x = list[0].toInt();
1821 y = list[1].toInt(); 1821 y = list[1].toInt();
1822 w = list[2].toInt(); 1822 w = list[2].toInt();
1823 h = list[3].toInt(); 1823 h = list[3].toInt();
1824 getEventViewerDialog()->setGeometry(x,y,w,h); 1824 getEventViewerDialog()->setGeometry(x,y,w,h);
1825 } 1825 }
1826#endif 1826#endif
1827 1827
1828} 1828}
1829 1829
1830 1830
1831void CalendarView::writeSettings() 1831void CalendarView::writeSettings()
1832{ 1832{
1833 // kdDebug() << "CalendarView::writeSettings" << endl; 1833 // kdDebug() << "CalendarView::writeSettings" << endl;
1834 1834
1835 KConfig *config = KOGlobals::config(); 1835 KConfig *config = KOGlobals::config();
1836 1836
1837#ifndef KORG_NOSPLITTER 1837#ifndef KORG_NOSPLITTER
1838 config->setGroup("KOrganizer Geometry"); 1838 config->setGroup("KOrganizer Geometry");
1839 1839
1840 QValueList<int> list = mPanner->sizes(); 1840 QValueList<int> list = mPanner->sizes();
1841 config->writeEntry("Separator1",list); 1841 config->writeEntry("Separator1",list);
1842 1842
1843 list = mLeftSplitter->sizes(); 1843 list = mLeftSplitter->sizes();
1844 config->writeEntry("Separator2",list); 1844 config->writeEntry("Separator2",list);
1845#endif 1845#endif
1846 1846
1847 mViewManager->writeSettings( config ); 1847 mViewManager->writeSettings( config );
1848 mTodoList->saveLayout(config,QString("Todo Layout")); 1848 mTodoList->saveLayout(config,QString("Todo Layout"));
1849 mDialogManager->writeSettings( config ); 1849 mDialogManager->writeSettings( config );
1850 //KOPrefs::instance()->usrWriteConfig(); 1850 //KOPrefs::instance()->usrWriteConfig();
1851 KOPrefs::instance()->writeConfig(); 1851 KOPrefs::instance()->writeConfig();
1852 1852
1853 writeFilterSettings(config); 1853 writeFilterSettings(config);
1854 1854
1855 config->setGroup( "Views" ); 1855 config->setGroup( "Views" );
1856 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1856 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1857 1857
1858#ifdef DESKTOP_VERSION 1858#ifdef DESKTOP_VERSION
1859 config->setGroup("WidgetLayout"); 1859 config->setGroup("WidgetLayout");
1860 QStringList list ;//= config->readListEntry("MainLayout"); 1860 QStringList list ;//= config->readListEntry("MainLayout");
1861 int x,y,w,h; 1861 int x,y,w,h;
1862 QWidget* wid; 1862 QWidget* wid;
1863 wid = topLevelWidget(); 1863 wid = topLevelWidget();
1864 x = wid->geometry().x(); 1864 x = wid->geometry().x();
1865 y = wid->geometry().y(); 1865 y = wid->geometry().y();
1866 w = wid->width(); 1866 w = wid->width();
1867 h = wid->height(); 1867 h = wid->height();
1868 list.clear(); 1868 list.clear();
1869 list << QString::number( x ); 1869 list << QString::number( x );
1870 list << QString::number( y ); 1870 list << QString::number( y );
1871 list << QString::number( w ); 1871 list << QString::number( w );
1872 list << QString::number( h ); 1872 list << QString::number( h );
1873 config->writeEntry("MainLayout",list ); 1873 config->writeEntry("MainLayout",list );
1874 1874
1875 wid = mEventEditor; 1875 wid = mEventEditor;
1876 x = wid->geometry().x(); 1876 x = wid->geometry().x();
1877 y = wid->geometry().y(); 1877 y = wid->geometry().y();
1878 w = wid->width(); 1878 w = wid->width();
1879 h = wid->height(); 1879 h = wid->height();
1880 list.clear(); 1880 list.clear();
1881 list << QString::number( x ); 1881 list << QString::number( x );
1882 list << QString::number( y ); 1882 list << QString::number( y );
1883 list << QString::number( w ); 1883 list << QString::number( w );
1884 list << QString::number( h ); 1884 list << QString::number( h );
1885 config->writeEntry("EditEventLayout",list ); 1885 config->writeEntry("EditEventLayout",list );
1886 1886
1887 wid = mTodoEditor; 1887 wid = mTodoEditor;
1888 x = wid->geometry().x(); 1888 x = wid->geometry().x();
1889 y = wid->geometry().y(); 1889 y = wid->geometry().y();
1890 w = wid->width(); 1890 w = wid->width();
1891 h = wid->height(); 1891 h = wid->height();
1892 list.clear(); 1892 list.clear();
1893 list << QString::number( x ); 1893 list << QString::number( x );
1894 list << QString::number( y ); 1894 list << QString::number( y );
1895 list << QString::number( w ); 1895 list << QString::number( w );
1896 list << QString::number( h ); 1896 list << QString::number( h );
1897 config->writeEntry("EditTodoLayout",list ); 1897 config->writeEntry("EditTodoLayout",list );
1898 wid = getEventViewerDialog(); 1898 wid = getEventViewerDialog();
1899 x = wid->geometry().x(); 1899 x = wid->geometry().x();
1900 y = wid->geometry().y(); 1900 y = wid->geometry().y();
1901 w = wid->width(); 1901 w = wid->width();
1902 h = wid->height(); 1902 h = wid->height();
1903 list.clear(); 1903 list.clear();
1904 list << QString::number( x ); 1904 list << QString::number( x );
1905 list << QString::number( y ); 1905 list << QString::number( y );
1906 list << QString::number( w ); 1906 list << QString::number( w );
1907 list << QString::number( h ); 1907 list << QString::number( h );
1908 config->writeEntry("ViewerLayout",list ); 1908 config->writeEntry("ViewerLayout",list );
1909 wid = mDialogManager->getSearchDialog(); 1909 wid = mDialogManager->getSearchDialog();
1910 if ( wid ) { 1910 if ( wid ) {
1911 x = wid->geometry().x(); 1911 x = wid->geometry().x();
1912 y = wid->geometry().y(); 1912 y = wid->geometry().y();
1913 w = wid->width(); 1913 w = wid->width();
1914 h = wid->height(); 1914 h = wid->height();
1915 list.clear(); 1915 list.clear();
1916 list << QString::number( x ); 1916 list << QString::number( x );
1917 list << QString::number( y ); 1917 list << QString::number( y );
1918 list << QString::number( w ); 1918 list << QString::number( w );
1919 list << QString::number( h ); 1919 list << QString::number( h );
1920 config->writeEntry("SearchLayout",list ); 1920 config->writeEntry("SearchLayout",list );
1921 } 1921 }
1922#endif 1922#endif
1923 1923
1924 1924
1925 config->sync(); 1925 config->sync();
1926} 1926}
1927 1927
1928void CalendarView::readFilterSettings(KConfig *config) 1928void CalendarView::readFilterSettings(KConfig *config)
1929{ 1929{
1930 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1930 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1931 1931
1932 mFilters.clear(); 1932 mFilters.clear();
1933 1933
1934 config->setGroup("General"); 1934 config->setGroup("General");
1935 QStringList filterList = config->readListEntry("CalendarFilters"); 1935 QStringList filterList = config->readListEntry("CalendarFilters");
1936 1936
1937 QStringList::ConstIterator it = filterList.begin(); 1937 QStringList::ConstIterator it = filterList.begin();
1938 QStringList::ConstIterator end = filterList.end(); 1938 QStringList::ConstIterator end = filterList.end();
1939 while(it != end) { 1939 while(it != end) {
1940 // kdDebug() << " filter: " << (*it) << endl; 1940 // kdDebug() << " filter: " << (*it) << endl;
1941 1941
1942 CalFilter *filter; 1942 CalFilter *filter;
1943 filter = new CalFilter(*it); 1943 filter = new CalFilter(*it);
1944 config->setGroup("Filter_" + (*it)); 1944 config->setGroup("Filter_" + (*it));
1945 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1945 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1946 filter->setCriteria(config->readNumEntry("Criteria",0)); 1946 filter->setCriteria(config->readNumEntry("Criteria",0));
1947 filter->setCategoryList(config->readListEntry("CategoryList")); 1947 filter->setCategoryList(config->readListEntry("CategoryList"));
1948 mFilters.append(filter); 1948 mFilters.append(filter);
1949 1949
1950 ++it; 1950 ++it;
1951 } 1951 }
1952 1952
1953 if (mFilters.count() == 0) { 1953 if (mFilters.count() == 0) {
1954 CalFilter *filter = new CalFilter(i18n("Default")); 1954 CalFilter *filter = new CalFilter(i18n("Default"));
1955 mFilters.append(filter); 1955 mFilters.append(filter);
1956 } 1956 }
1957 mFilterView->updateFilters(); 1957 mFilterView->updateFilters();
1958 config->setGroup("FilterView"); 1958 config->setGroup("FilterView");
1959 1959
1960 mFilterView->blockSignals(true); 1960 mFilterView->blockSignals(true);
1961 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1961 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1962 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1962 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1963 mFilterView->blockSignals(false); 1963 mFilterView->blockSignals(false);
1964 // We do it manually to avoid it being done twice by the above calls 1964 // We do it manually to avoid it being done twice by the above calls
1965 updateFilter(); 1965 updateFilter();
1966} 1966}
1967 1967
1968void CalendarView::writeFilterSettings(KConfig *config) 1968void CalendarView::writeFilterSettings(KConfig *config)
1969{ 1969{
1970 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1970 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1971 1971
1972 QStringList filterList; 1972 QStringList filterList;
1973 1973
1974 CalFilter *filter = mFilters.first(); 1974 CalFilter *filter = mFilters.first();
1975 while(filter) { 1975 while(filter) {
1976 // kdDebug() << " fn: " << filter->name() << endl; 1976 // kdDebug() << " fn: " << filter->name() << endl;
1977 filterList << filter->name(); 1977 filterList << filter->name();
1978 config->setGroup("Filter_" + filter->name()); 1978 config->setGroup("Filter_" + filter->name());
1979 config->writeEntry("Criteria",filter->criteria()); 1979 config->writeEntry("Criteria",filter->criteria());
1980 config->writeEntry("CategoryList",filter->categoryList()); 1980 config->writeEntry("CategoryList",filter->categoryList());
1981 filter = mFilters.next(); 1981 filter = mFilters.next();
1982 } 1982 }
1983 config->setGroup("General"); 1983 config->setGroup("General");
1984 config->writeEntry("CalendarFilters",filterList); 1984 config->writeEntry("CalendarFilters",filterList);
1985 1985
1986 config->setGroup("FilterView"); 1986 config->setGroup("FilterView");
1987 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1987 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1988 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1988 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1989} 1989}
1990 1990
1991 1991
1992void CalendarView::goToday() 1992void CalendarView::goToday()
1993{ 1993{
1994 mNavigator->selectToday(); 1994 mNavigator->selectToday();
1995} 1995}
1996 1996
1997void CalendarView::goNext() 1997void CalendarView::goNext()
1998{ 1998{
1999 mNavigator->selectNext(); 1999 mNavigator->selectNext();
2000} 2000}
2001 2001
2002void CalendarView::goPrevious() 2002void CalendarView::goPrevious()
2003{ 2003{
2004 mNavigator->selectPrevious(); 2004 mNavigator->selectPrevious();
2005} 2005}
2006void CalendarView::goNextMonth() 2006void CalendarView::goNextMonth()
2007{ 2007{
2008 mNavigator->selectNextMonth(); 2008 mNavigator->selectNextMonth();
2009} 2009}
2010 2010
2011void CalendarView::goPreviousMonth() 2011void CalendarView::goPreviousMonth()
2012{ 2012{
2013 mNavigator->selectPreviousMonth(); 2013 mNavigator->selectPreviousMonth();
2014} 2014}
2015void CalendarView::writeLocale() 2015void CalendarView::writeLocale()
2016{ 2016{
2017 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2017 //KPimGlobalPrefs::instance()->setGlobalConfig();
2018#if 0 2018#if 0
2019 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2019 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2020 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2020 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2021 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2021 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2022 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2022 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2023 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2023 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2024 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2024 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2025 dummy = KOPrefs::instance()->mUserDateFormatShort; 2025 dummy = KOPrefs::instance()->mUserDateFormatShort;
2026 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2026 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2027 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2027 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2028 KOPrefs::instance()->mDaylightsavingStart, 2028 KOPrefs::instance()->mDaylightsavingStart,
2029 KOPrefs::instance()->mDaylightsavingEnd ); 2029 KOPrefs::instance()->mDaylightsavingEnd );
2030 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2030 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2031#endif 2031#endif
2032} 2032}
2033void CalendarView::updateConfig() 2033void CalendarView::updateConfig()
2034{ 2034{
2035 writeLocale(); 2035 writeLocale();
2036 if ( KOPrefs::instance()->mUseAppColors ) 2036 if ( KOPrefs::instance()->mUseAppColors )
2037 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2037 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2038 emit configChanged(); 2038 emit configChanged();
2039 mTodoList->updateConfig(); 2039 mTodoList->updateConfig();
2040 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2040 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2041 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2041 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2042 // To make the "fill window" configurations work 2042 // To make the "fill window" configurations work
2043 //mViewManager->raiseCurrentView(); 2043 //mViewManager->raiseCurrentView();
2044} 2044}
2045 2045
2046 2046
2047void CalendarView::eventChanged(Event *event) 2047void CalendarView::eventChanged(Event *event)
2048{ 2048{
2049 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2049 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2050 //updateUnmanagedViews(); 2050 //updateUnmanagedViews();
2051} 2051}
2052 2052
2053void CalendarView::eventAdded(Event *event) 2053void CalendarView::eventAdded(Event *event)
2054{ 2054{
2055 changeEventDisplay(event,KOGlobals::EVENTADDED); 2055 changeEventDisplay(event,KOGlobals::EVENTADDED);
2056} 2056}
2057 2057
2058void CalendarView::eventToBeDeleted(Event *) 2058void CalendarView::eventToBeDeleted(Event *)
2059{ 2059{
2060 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2060 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2061} 2061}
2062 2062
2063void CalendarView::eventDeleted() 2063void CalendarView::eventDeleted()
2064{ 2064{
2065 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2065 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2066} 2066}
2067void CalendarView::changeTodoDisplay(Todo *which, int action) 2067void CalendarView::changeTodoDisplay(Todo *which, int action)
2068{ 2068{
2069 changeIncidenceDisplay((Incidence *)which, action); 2069 changeIncidenceDisplay((Incidence *)which, action);
2070 mDateNavigator->updateView(); //LR 2070 mDateNavigator->updateView(); //LR
2071 //mDialogManager->updateSearchDialog(); 2071 //mDialogManager->updateSearchDialog();
2072 2072
2073 if (which) { 2073 if (which) {
2074 mViewManager->updateWNview(); 2074 mViewManager->updateWNview();
2075 //mTodoList->updateView(); 2075 //mTodoList->updateView();
2076 } 2076 }
2077 2077
2078} 2078}
2079 2079
2080void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2080void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2081{ 2081{
2082 updateUnmanagedViews(); 2082 updateUnmanagedViews();
2083 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2083 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2084 if ( action == KOGlobals::EVENTDELETED ) { //delete 2084 if ( action == KOGlobals::EVENTDELETED ) { //delete
2085 mCalendar->checkAlarmForIncidence( 0, true ); 2085 mCalendar->checkAlarmForIncidence( 0, true );
2086 if ( mEventViewerDialog ) 2086 if ( mEventViewerDialog )
2087 mEventViewerDialog->hide(); 2087 mEventViewerDialog->hide();
2088 } 2088 }
2089 else 2089 else
2090 mCalendar->checkAlarmForIncidence( which , false ); 2090 mCalendar->checkAlarmForIncidence( which , false );
2091} 2091}
2092 2092
2093// most of the changeEventDisplays() right now just call the view's 2093// most of the changeEventDisplays() right now just call the view's
2094// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2094// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2095void CalendarView::changeEventDisplay(Event *which, int action) 2095void CalendarView::changeEventDisplay(Event *which, int action)
2096{ 2096{
2097 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2097 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2098 changeIncidenceDisplay((Incidence *)which, action); 2098 changeIncidenceDisplay((Incidence *)which, action);
2099 mDateNavigator->updateView(); 2099 mDateNavigator->updateView();
2100 //mDialogManager->updateSearchDialog(); 2100 //mDialogManager->updateSearchDialog();
2101 2101
2102 if (which) { 2102 if (which) {
2103 // If there is an event view visible update the display 2103 // If there is an event view visible update the display
2104 mViewManager->currentView()->changeEventDisplay(which,action); 2104 mViewManager->currentView()->changeEventDisplay(which,action);
2105 // TODO: check, if update needed 2105 // TODO: check, if update needed
2106 // if (which->getTodoStatus()) { 2106 // if (which->getTodoStatus()) {
2107 mTodoList->updateView(); 2107 mTodoList->updateView();
2108 // } 2108 // }
2109 } else { 2109 } else {
2110 mViewManager->currentView()->updateView(); 2110 mViewManager->currentView()->updateView();
2111 } 2111 }
2112} 2112}
2113 2113
2114 2114
2115void CalendarView::updateTodoViews() 2115void CalendarView::updateTodoViews()
2116{ 2116{
2117 2117
2118 mTodoList->updateView(); 2118 mTodoList->updateView();
2119 mViewManager->currentView()->updateView(); 2119 mViewManager->currentView()->updateView();
2120 2120
2121} 2121}
2122 2122
2123 2123
2124void CalendarView::updateView(const QDate &start, const QDate &end) 2124void CalendarView::updateView(const QDate &start, const QDate &end)
2125{ 2125{
2126 mTodoList->updateView(); 2126 mTodoList->updateView();
2127 mViewManager->updateView(start, end); 2127 mViewManager->updateView(start, end);
2128 //mDateNavigator->updateView(); 2128 //mDateNavigator->updateView();
2129} 2129}
2130 2130
2131void CalendarView::updateView() 2131void CalendarView::updateView()
2132{ 2132{
2133 DateList tmpList = mNavigator->selectedDates(); 2133 DateList tmpList = mNavigator->selectedDates();
2134 2134
2135 // We assume that the navigator only selects consecutive days. 2135 // We assume that the navigator only selects consecutive days.
2136 updateView( tmpList.first(), tmpList.last() ); 2136 updateView( tmpList.first(), tmpList.last() );
2137} 2137}
2138 2138
2139void CalendarView::updateUnmanagedViews() 2139void CalendarView::updateUnmanagedViews()
2140{ 2140{
2141 mDateNavigator->updateDayMatrix(); 2141 mDateNavigator->updateDayMatrix();
2142} 2142}
2143 2143
2144int CalendarView::msgItemDelete() 2144int CalendarView::msgItemDelete()
2145{ 2145{
2146 return KMessageBox::warningContinueCancel(this, 2146 return KMessageBox::warningContinueCancel(this,
2147 i18n("This item will be\npermanently deleted."), 2147 i18n("This item will be\npermanently deleted."),
2148 i18n("KO/Pi Confirmation"),i18n("Delete")); 2148 i18n("KO/Pi Confirmation"),i18n("Delete"));
2149} 2149}
2150 2150
2151 2151
2152void CalendarView::edit_cut() 2152void CalendarView::edit_cut()
2153{ 2153{
2154 Event *anEvent=0; 2154 Event *anEvent=0;
2155 2155
2156 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2156 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2157 2157
2158 if (mViewManager->currentView()->isEventView()) { 2158 if (mViewManager->currentView()->isEventView()) {
2159 if ( incidence && incidence->type() == "Event" ) { 2159 if ( incidence && incidence->type() == "Event" ) {
2160 anEvent = static_cast<Event *>(incidence); 2160 anEvent = static_cast<Event *>(incidence);
2161 } 2161 }
2162 } 2162 }
2163 2163
2164 if (!anEvent) { 2164 if (!anEvent) {
2165 KNotifyClient::beep(); 2165 KNotifyClient::beep();
2166 return; 2166 return;
2167 } 2167 }
2168 DndFactory factory( mCalendar ); 2168 DndFactory factory( mCalendar );
2169 factory.cutEvent(anEvent); 2169 factory.cutEvent(anEvent);
2170 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2170 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2171} 2171}
2172 2172
2173void CalendarView::edit_copy() 2173void CalendarView::edit_copy()
2174{ 2174{
2175 Event *anEvent=0; 2175 Event *anEvent=0;
2176 2176
2177 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2177 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2178 2178
2179 if (mViewManager->currentView()->isEventView()) { 2179 if (mViewManager->currentView()->isEventView()) {
2180 if ( incidence && incidence->type() == "Event" ) { 2180 if ( incidence && incidence->type() == "Event" ) {
2181 anEvent = static_cast<Event *>(incidence); 2181 anEvent = static_cast<Event *>(incidence);
2182 } 2182 }
2183 } 2183 }
2184 2184
2185 if (!anEvent) { 2185 if (!anEvent) {
2186 KNotifyClient::beep(); 2186 KNotifyClient::beep();
2187 return; 2187 return;
2188 } 2188 }
2189 DndFactory factory( mCalendar ); 2189 DndFactory factory( mCalendar );
2190 factory.copyEvent(anEvent); 2190 factory.copyEvent(anEvent);
2191} 2191}
2192 2192
2193void CalendarView::edit_paste() 2193void CalendarView::edit_paste()
2194{ 2194{
2195 QDate date = mNavigator->selectedDates().first(); 2195 QDate date = mNavigator->selectedDates().first();
2196 2196
2197 DndFactory factory( mCalendar ); 2197 DndFactory factory( mCalendar );
2198 Event *pastedEvent = factory.pasteEvent( date ); 2198 Event *pastedEvent = factory.pasteEvent( date );
2199 2199
2200 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2200 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2201} 2201}
2202 2202
2203void CalendarView::edit_options() 2203void CalendarView::edit_options()
2204{ 2204{
2205 mDialogManager->showOptionsDialog(); 2205 mDialogManager->showOptionsDialog();
2206 //writeSettings(); 2206 //writeSettings();
2207} 2207}
2208 2208
2209void CalendarView::slotSelectPickerDate( QDate d) 2209void CalendarView::slotSelectPickerDate( QDate d)
2210{ 2210{
2211 mDateFrame->hide(); 2211 mDateFrame->hide();
2212 if ( mDatePickerMode == 1 ) { 2212 if ( mDatePickerMode == 1 ) {
2213 mNavigator->slotDaySelect( d ); 2213 mNavigator->slotDaySelect( d );
2214 } else if ( mDatePickerMode == 2 ) { 2214 } else if ( mDatePickerMode == 2 ) {
2215 if ( mMoveIncidence->type() == "Todo" ) { 2215 if ( mMoveIncidence->type() == "Todo" ) {
2216 Todo * to = (Todo *) mMoveIncidence; 2216 Todo * to = (Todo *) mMoveIncidence;
2217 QTime tim; 2217 QTime tim;
2218 if ( to->hasDueDate() ) 2218 if ( to->hasDueDate() )
2219 tim = to->dtDue().time(); 2219 tim = to->dtDue().time();
2220 else { 2220 else {
2221 tim = QTime ( 0,0,0 ); 2221 tim = QTime ( 0,0,0 );
2222 to->setFloats( true ); 2222 to->setFloats( true );
2223 to->setHasDueDate( true ); 2223 to->setHasDueDate( true );
2224 } 2224 }
2225 QDateTime dt ( d,tim ); 2225 QDateTime dt ( d,tim );
2226 to->setDtDue( dt ); 2226 to->setDtDue( dt );
2227 todoChanged( to ); 2227 todoChanged( to );
2228 } else { 2228 } else {
2229 QTime tim = mMoveIncidence->dtStart().time(); 2229 QTime tim = mMoveIncidence->dtStart().time();
2230 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2230 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2231 QDateTime dt ( d,tim ); 2231 QDateTime dt ( d,tim );
2232 mMoveIncidence->setDtStart( dt ); 2232 mMoveIncidence->setDtStart( dt );
2233 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2233 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2234 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2234 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2235 } 2235 }
2236 2236
2237 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2237 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2238 } 2238 }
2239} 2239}
2240 2240
2241void CalendarView::removeCategories() 2241void CalendarView::removeCategories()
2242{ 2242{
2243 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2243 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2244 QStringList catList = KOPrefs::instance()->mCustomCategories; 2244 QStringList catList = KOPrefs::instance()->mCustomCategories;
2245 QStringList catIncList; 2245 QStringList catIncList;
2246 QStringList newCatList; 2246 QStringList newCatList;
2247 Incidence* inc = incList.first(); 2247 Incidence* inc = incList.first();
2248 int i; 2248 int i;
2249 int count = 0; 2249 int count = 0;
2250 while ( inc ) { 2250 while ( inc ) {
2251 newCatList.clear(); 2251 newCatList.clear();
2252 catIncList = inc->categories() ; 2252 catIncList = inc->categories() ;
2253 for( i = 0; i< catIncList.count(); ++i ) { 2253 for( i = 0; i< catIncList.count(); ++i ) {
2254 if ( catList.contains (catIncList[i])) 2254 if ( catList.contains (catIncList[i]))
2255 newCatList.append( catIncList[i] ); 2255 newCatList.append( catIncList[i] );
2256 } 2256 }
2257 newCatList.sort(); 2257 newCatList.sort();
2258 inc->setCategories( newCatList.join(",") ); 2258 inc->setCategories( newCatList.join(",") );
2259 inc = incList.next(); 2259 inc = incList.next();
2260 } 2260 }
2261} 2261}
2262 2262
2263int CalendarView::addCategories() 2263int CalendarView::addCategories()
2264{ 2264{
2265 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2265 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2266 QStringList catList = KOPrefs::instance()->mCustomCategories; 2266 QStringList catList = KOPrefs::instance()->mCustomCategories;
2267 QStringList catIncList; 2267 QStringList catIncList;
2268 Incidence* inc = incList.first(); 2268 Incidence* inc = incList.first();
2269 int i; 2269 int i;
2270 int count = 0; 2270 int count = 0;
2271 while ( inc ) { 2271 while ( inc ) {
2272 catIncList = inc->categories() ; 2272 catIncList = inc->categories() ;
2273 for( i = 0; i< catIncList.count(); ++i ) { 2273 for( i = 0; i< catIncList.count(); ++i ) {
2274 if ( !catList.contains (catIncList[i])) { 2274 if ( !catList.contains (catIncList[i])) {
2275 catList.append( catIncList[i] ); 2275 catList.append( catIncList[i] );
2276 //qDebug("add cat %s ", catIncList[i].latin1()); 2276 //qDebug("add cat %s ", catIncList[i].latin1());
2277 ++count; 2277 ++count;
2278 } 2278 }
2279 } 2279 }
2280 inc = incList.next(); 2280 inc = incList.next();
2281 } 2281 }
2282 catList.sort(); 2282 catList.sort();
2283 KOPrefs::instance()->mCustomCategories = catList; 2283 KOPrefs::instance()->mCustomCategories = catList;
2284 return count; 2284 return count;
2285} 2285}
2286 2286
2287void CalendarView::manageCategories() 2287void CalendarView::manageCategories()
2288{ 2288{
2289 KOCatPrefs* cp = new KOCatPrefs(); 2289 KOCatPrefs* cp = new KOCatPrefs();
2290 cp->show(); 2290 cp->show();
2291 int w =cp->sizeHint().width() ; 2291 int w =cp->sizeHint().width() ;
2292 int h = cp->sizeHint().height() ; 2292 int h = cp->sizeHint().height() ;
2293 int dw = QApplication::desktop()->width(); 2293 int dw = QApplication::desktop()->width();
2294 int dh = QApplication::desktop()->height(); 2294 int dh = QApplication::desktop()->height();
2295 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2295 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2296 if ( !cp->exec() ) { 2296 if ( !cp->exec() ) {
2297 delete cp; 2297 delete cp;
2298 return; 2298 return;
2299 } 2299 }
2300 int count = 0; 2300 int count = 0;
2301 if ( cp->addCat() ) { 2301 if ( cp->addCat() ) {
2302 count = addCategories(); 2302 count = addCategories();
2303 if ( count ) { 2303 if ( count ) {
2304 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2304 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2305 writeSettings(); 2305 writeSettings();
2306 } else 2306 } else
2307 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2307 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2308 } else { 2308 } else {
2309 removeCategories(); 2309 removeCategories();
2310 updateView(); 2310 updateView();
2311 } 2311 }
2312 delete cp; 2312 delete cp;
2313} 2313}
2314 2314
2315void CalendarView::beamIncidence(Incidence * Inc) 2315void CalendarView::beamIncidence(Incidence * Inc)
2316{ 2316{
2317 QPtrList<Incidence> delSel ; 2317 QPtrList<Incidence> delSel ;
2318 delSel.append(Inc); 2318 delSel.append(Inc);
2319 beamIncidenceList( delSel ); 2319 beamIncidenceList( delSel );
2320} 2320}
2321void CalendarView::beamCalendar() 2321void CalendarView::beamCalendar()
2322{ 2322{
2323 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2323 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2324 //qDebug("beamCalendar() "); 2324 //qDebug("beamCalendar() ");
2325 beamIncidenceList( delSel ); 2325 beamIncidenceList( delSel );
2326} 2326}
2327void CalendarView::beamFilteredCalendar() 2327void CalendarView::beamFilteredCalendar()
2328{ 2328{
2329 QPtrList<Incidence> delSel = mCalendar->incidences(); 2329 QPtrList<Incidence> delSel = mCalendar->incidences();
2330 //qDebug("beamFilteredCalendar() "); 2330 //qDebug("beamFilteredCalendar() ");
2331 beamIncidenceList( delSel ); 2331 beamIncidenceList( delSel );
2332} 2332}
2333void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2333void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2334{ 2334{
2335 if ( beamDialog->exec () == QDialog::Rejected ) 2335 if ( beamDialog->exec () == QDialog::Rejected )
2336 return; 2336 return;
2337#ifdef DESKTOP_VERSION 2337#ifdef DESKTOP_VERSION
2338 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2338 QString fn = locateLocal( "tmp", "kopibeamfile" );
2339#else 2339#else
2340 QString fn = "/tmp/kopibeamfile"; 2340 QString fn = "/tmp/kopibeamfile";
2341#endif 2341#endif
2342 QString mes; 2342 QString mes;
2343 bool createbup = true; 2343 bool createbup = true;
2344 if ( createbup ) { 2344 if ( createbup ) {
2345 QString description = "\n"; 2345 QString description = "\n";
2346 CalendarLocal* cal = new CalendarLocal(); 2346 CalendarLocal* cal = new CalendarLocal();
2347 if ( beamDialog->beamLocal() ) 2347 if ( beamDialog->beamLocal() )
2348 cal->setLocalTime(); 2348 cal->setLocalTime();
2349 else 2349 else
2350 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2350 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2351 Incidence *incidence = delSel.first(); 2351 Incidence *incidence = delSel.first();
2352 bool addText = false; 2352 bool addText = false;
2353 if ( delSel.count() < 10 ) 2353 if ( delSel.count() < 10 )
2354 addText = true; 2354 addText = true;
2355 else { 2355 else {
2356 description.sprintf(i18n(" %d items?"),delSel.count() ); 2356 description.sprintf(i18n(" %d items?"),delSel.count() );
2357 } 2357 }
2358 while ( incidence ) { 2358 while ( incidence ) {
2359 Incidence *in = incidence->clone(); 2359 Incidence *in = incidence->clone();
2360 if ( ! in->summary().isEmpty() ) { 2360 if ( ! in->summary().isEmpty() ) {
2361 in->setDescription(""); 2361 in->setDescription("");
2362 } else { 2362 } else {
2363 in->setSummary( in->description().left(20)); 2363 in->setSummary( in->description().left(20));
2364 in->setDescription(""); 2364 in->setDescription("");
2365 } 2365 }
2366 if ( addText ) 2366 if ( addText )
2367 description += in->summary() + "\n"; 2367 description += in->summary() + "\n";
2368 cal->addIncidence( in ); 2368 cal->addIncidence( in );
2369 incidence = delSel.next(); 2369 incidence = delSel.next();
2370 } 2370 }
2371 if ( beamDialog->beamVcal() ) { 2371 if ( beamDialog->beamVcal() ) {
2372 fn += ".vcs"; 2372 fn += ".vcs";
2373 FileStorage storage( cal, fn, new VCalFormat ); 2373 FileStorage storage( cal, fn, new VCalFormat );
2374 storage.save(); 2374 storage.save();
2375 } else { 2375 } else {
2376 fn += ".ics"; 2376 fn += ".ics";
2377 FileStorage storage( cal, fn, new ICalFormat( ) ); 2377 FileStorage storage( cal, fn, new ICalFormat( ) );
2378 storage.save(); 2378 storage.save();
2379 } 2379 }
2380 delete cal; 2380 delete cal;
2381 mes = i18n("KO/Pi: Ready for beaming"); 2381 mes = i18n("KO/Pi: Ready for beaming");
2382 topLevelWidget()->setCaption(mes); 2382 topLevelWidget()->setCaption(mes);
2383 KApplication::convert2latin1( fn ); 2383 KApplication::convert2latin1( fn );
2384#ifndef DESKTOP_VERSION 2384#ifndef DESKTOP_VERSION
2385 Ir *ir = new Ir( this ); 2385 Ir *ir = new Ir( this );
2386 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2386 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2387 ir->send( fn, description, "text/x-vCalendar" ); 2387 ir->send( fn, description, "text/x-vCalendar" );
2388#endif 2388#endif
2389 } 2389 }
2390} 2390}
2391void CalendarView::beamDone( Ir *ir ) 2391void CalendarView::beamDone( Ir *ir )
2392{ 2392{
2393#ifndef DESKTOP_VERSION 2393#ifndef DESKTOP_VERSION
2394 delete ir; 2394 delete ir;
2395#endif 2395#endif
2396 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2396 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2397 topLevelWidget()->raise(); 2397 topLevelWidget()->raise();
2398} 2398}
2399 2399
2400void CalendarView::moveIncidence(Incidence * inc ) 2400void CalendarView::moveIncidence(Incidence * inc )
2401{ 2401{
2402 if ( !inc ) return; 2402 if ( !inc ) return;
2403 // qDebug("showDatePickerForIncidence( ) "); 2403 // qDebug("showDatePickerForIncidence( ) ");
2404 if ( mDateFrame->isVisible() ) 2404 if ( mDateFrame->isVisible() )
2405 mDateFrame->hide(); 2405 mDateFrame->hide();
2406 else { 2406 else {
2407 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2407 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2408 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2408 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2409 int dw = QApplication::desktop()->width(); 2409 int dw = QApplication::desktop()->width();
2410 int dh = QApplication::desktop()->height(); 2410 int dh = QApplication::desktop()->height();
2411 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2411 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2412 mDateFrame->show(); 2412 mDateFrame->show();
2413 } 2413 }
2414 mDatePickerMode = 2; 2414 mDatePickerMode = 2;
2415 mMoveIncidence = inc ; 2415 mMoveIncidence = inc ;
2416 QDate da; 2416 QDate da;
2417 if ( mMoveIncidence->type() == "Todo" ) { 2417 if ( mMoveIncidence->type() == "Todo" ) {
2418 Todo * to = (Todo *) mMoveIncidence; 2418 Todo * to = (Todo *) mMoveIncidence;
2419 if ( to->hasDueDate() ) 2419 if ( to->hasDueDate() )
2420 da = to->dtDue().date(); 2420 da = to->dtDue().date();
2421 else 2421 else
2422 da = QDate::currentDate(); 2422 da = QDate::currentDate();
2423 } else { 2423 } else {
2424 da = mMoveIncidence->dtStart().date(); 2424 da = mMoveIncidence->dtStart().date();
2425 } 2425 }
2426 mDatePicker->setDate( da ); 2426 mDatePicker->setDate( da );
2427} 2427}
2428void CalendarView::showDatePicker( ) 2428void CalendarView::showDatePicker( )
2429{ 2429{
2430 //qDebug("CalendarView::showDatePicker( ) "); 2430 //qDebug("CalendarView::showDatePicker( ) ");
2431 if ( mDateFrame->isVisible() ) 2431 if ( mDateFrame->isVisible() )
2432 mDateFrame->hide(); 2432 mDateFrame->hide();
2433 else { 2433 else {
2434 int w =mDatePicker->sizeHint().width() ; 2434 int w =mDatePicker->sizeHint().width() ;
2435 int h = mDatePicker->sizeHint().height() ; 2435 int h = mDatePicker->sizeHint().height() ;
2436 int dw = QApplication::desktop()->width(); 2436 int dw = QApplication::desktop()->width();
2437 int dh = QApplication::desktop()->height(); 2437 int dh = QApplication::desktop()->height();
2438 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2438 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2439 mDateFrame->show(); 2439 mDateFrame->show();
2440 } 2440 }
2441 mDatePickerMode = 1; 2441 mDatePickerMode = 1;
2442 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2442 mDatePicker->setDate( mNavigator->selectedDates().first() );
2443} 2443}
2444 2444
2445void CalendarView::showEventEditor() 2445void CalendarView::showEventEditor()
2446{ 2446{
2447#ifdef DESKTOP_VERSION 2447#ifdef DESKTOP_VERSION
2448 mEventEditor->show(); 2448 mEventEditor->show();
2449#else 2449#else
2450 if ( mEventEditor->width() != QApplication::desktop()->width() )
2451 mEventEditor->hide();
2450 mEventEditor->showMaximized(); 2452 mEventEditor->showMaximized();
2451#endif 2453#endif
2452} 2454}
2453void CalendarView::showTodoEditor() 2455void CalendarView::showTodoEditor()
2454{ 2456{
2455#ifdef DESKTOP_VERSION 2457#ifdef DESKTOP_VERSION
2456 mTodoEditor->show(); 2458 mTodoEditor->show();
2457#else 2459#else
2460 if ( mTodoEditor->width() != QApplication::desktop()->width() )
2461 mTodoEditor->hide();
2458 mTodoEditor->showMaximized(); 2462 mTodoEditor->showMaximized();
2459#endif 2463#endif
2460} 2464}
2461 2465
2462void CalendarView::cloneIncidence() 2466void CalendarView::cloneIncidence()
2463{ 2467{
2464 Incidence *incidence = currentSelection(); 2468 Incidence *incidence = currentSelection();
2465 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2469 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2466 if ( incidence ) { 2470 if ( incidence ) {
2467 cloneIncidence(incidence); 2471 cloneIncidence(incidence);
2468 } 2472 }
2469} 2473}
2470void CalendarView::moveIncidence() 2474void CalendarView::moveIncidence()
2471{ 2475{
2472 Incidence *incidence = currentSelection(); 2476 Incidence *incidence = currentSelection();
2473 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2477 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2474 if ( incidence ) { 2478 if ( incidence ) {
2475 moveIncidence(incidence); 2479 moveIncidence(incidence);
2476 } 2480 }
2477} 2481}
2478void CalendarView::beamIncidence() 2482void CalendarView::beamIncidence()
2479{ 2483{
2480 Incidence *incidence = currentSelection(); 2484 Incidence *incidence = currentSelection();
2481 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2485 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2482 if ( incidence ) { 2486 if ( incidence ) {
2483 beamIncidence(incidence); 2487 beamIncidence(incidence);
2484 } 2488 }
2485} 2489}
2486void CalendarView::toggleCancelIncidence() 2490void CalendarView::toggleCancelIncidence()
2487{ 2491{
2488 Incidence *incidence = currentSelection(); 2492 Incidence *incidence = currentSelection();
2489 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2493 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2490 if ( incidence ) { 2494 if ( incidence ) {
2491 cancelIncidence(incidence); 2495 cancelIncidence(incidence);
2492 } 2496 }
2493} 2497}
2494 2498
2495 2499
2496void CalendarView::cancelIncidence(Incidence * inc ) 2500void CalendarView::cancelIncidence(Incidence * inc )
2497{ 2501{
2498 inc->setCancelled( ! inc->cancelled() ); 2502 inc->setCancelled( ! inc->cancelled() );
2499 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2503 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2500 updateView(); 2504 updateView();
2501} 2505}
2502void CalendarView::cloneIncidence(Incidence * orgInc ) 2506void CalendarView::cloneIncidence(Incidence * orgInc )
2503{ 2507{
2504 Incidence * newInc = orgInc->clone(); 2508 Incidence * newInc = orgInc->clone();
2505 newInc->recreate(); 2509 newInc->recreate();
2506 2510
2507 if ( newInc->type() == "Todo" ) { 2511 if ( newInc->type() == "Todo" ) {
2508 Todo* t = (Todo*) newInc; 2512 Todo* t = (Todo*) newInc;
2509 mTodoEditor->editTodo( t ); 2513 mTodoEditor->editTodo( t );
2510 showTodoEditor(); 2514 showTodoEditor();
2511 if ( mTodoEditor->exec() ) { 2515 if ( mTodoEditor->exec() ) {
2512 mCalendar->addTodo( t ); 2516 mCalendar->addTodo( t );
2513 updateView(); 2517 updateView();
2514 } else { 2518 } else {
2515 delete t; 2519 delete t;
2516 } 2520 }
2517 } 2521 }
2518 else { 2522 else {
2519 Event* e = (Event*) newInc; 2523 Event* e = (Event*) newInc;
2520 mEventEditor->editEvent( e ); 2524 mEventEditor->editEvent( e );
2521 showEventEditor(); 2525 showEventEditor();
2522 if ( mEventEditor->exec() ) { 2526 if ( mEventEditor->exec() ) {
2523 mCalendar->addEvent( e ); 2527 mCalendar->addEvent( e );
2524 updateView(); 2528 updateView();
2525 } else { 2529 } else {
2526 delete e; 2530 delete e;
2527 } 2531 }
2528 } 2532 }
2529} 2533}
2530 2534
2531void CalendarView::newEvent() 2535void CalendarView::newEvent()
2532{ 2536{
2533 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2537 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2534 KOAgendaView *aView = mViewManager->agendaView(); 2538 KOAgendaView *aView = mViewManager->agendaView();
2535 if (aView) { 2539 if (aView) {
2536 if (aView->selectionStart().isValid()) { 2540 if (aView->selectionStart().isValid()) {
2537 if (aView->selectedIsAllDay()) { 2541 if (aView->selectedIsAllDay()) {
2538 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2542 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2539 } else { 2543 } else {
2540 newEvent(aView->selectionStart(),aView->selectionEnd()); 2544 newEvent(aView->selectionStart(),aView->selectionEnd());
2541 } 2545 }
2542 return; 2546 return;
2543 } 2547 }
2544 } 2548 }
2545 2549
2546 QDate date = mNavigator->selectedDates().first(); 2550 QDate date = mNavigator->selectedDates().first();
2547 QDateTime current = QDateTime::currentDateTime(); 2551 QDateTime current = QDateTime::currentDateTime();
2548 if ( date <= current.date() ) { 2552 if ( date <= current.date() ) {
2549 int hour = current.time().hour() +1; 2553 int hour = current.time().hour() +1;
2550 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2554 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2551 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2555 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2552 } else 2556 } else
2553 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2557 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2554 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2558 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2555 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2559 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2556} 2560}
2557 2561
2558void CalendarView::newEvent(QDateTime fh) 2562void CalendarView::newEvent(QDateTime fh)
2559{ 2563{
2560 newEvent(fh, 2564 newEvent(fh,
2561 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2565 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2562} 2566}
2563 2567
2564void CalendarView::newEvent(QDate dt) 2568void CalendarView::newEvent(QDate dt)
2565{ 2569{
2566 newEvent(QDateTime(dt, QTime(0,0,0)), 2570 newEvent(QDateTime(dt, QTime(0,0,0)),
2567 QDateTime(dt, QTime(0,0,0)), true); 2571 QDateTime(dt, QTime(0,0,0)), true);
2568} 2572}
2569 2573
2570void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2574void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2571{ 2575{
2572 2576
2573 mEventEditor->newEvent(fromHint,toHint,allDay); 2577 mEventEditor->newEvent(fromHint,toHint,allDay);
2574 if ( mFilterView->filtersEnabled() ) { 2578 if ( mFilterView->filtersEnabled() ) {
2575 CalFilter *filter = mFilterView->selectedFilter(); 2579 CalFilter *filter = mFilterView->selectedFilter();
2576 if (filter && filter->showCategories()) { 2580 if (filter && filter->showCategories()) {
2577 mEventEditor->setCategories(filter->categoryList().join(",") ); 2581 mEventEditor->setCategories(filter->categoryList().join(",") );
2578 } 2582 }
2579 if ( filter ) 2583 if ( filter )
2580 mEventEditor->setSecrecy( filter->getSecrecy() ); 2584 mEventEditor->setSecrecy( filter->getSecrecy() );
2581 } 2585 }
2582 showEventEditor(); 2586 showEventEditor();
2583} 2587}
2584void CalendarView::todoAdded(Todo * t) 2588void CalendarView::todoAdded(Todo * t)
2585{ 2589{
2586 2590
2587 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2591 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2588 updateTodoViews(); 2592 updateTodoViews();
2589} 2593}
2590void CalendarView::todoChanged(Todo * t) 2594void CalendarView::todoChanged(Todo * t)
2591{ 2595{
2592 emit todoModified( t, 4 ); 2596 emit todoModified( t, 4 );
2593 // updateTodoViews(); 2597 // updateTodoViews();
2594} 2598}
2595void CalendarView::todoToBeDeleted(Todo *) 2599void CalendarView::todoToBeDeleted(Todo *)
2596{ 2600{
2597 //qDebug("todoToBeDeleted(Todo *) "); 2601 //qDebug("todoToBeDeleted(Todo *) ");
2598 updateTodoViews(); 2602 updateTodoViews();
2599} 2603}
2600void CalendarView::todoDeleted() 2604void CalendarView::todoDeleted()
2601{ 2605{
2602 //qDebug(" todoDeleted()"); 2606 //qDebug(" todoDeleted()");
2603 updateTodoViews(); 2607 updateTodoViews();
2604} 2608}
2605 2609
2606 2610
2607 2611
2608void CalendarView::newTodo() 2612void CalendarView::newTodo()
2609{ 2613{
2610 2614
2611 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2615 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2612 if ( mFilterView->filtersEnabled() ) { 2616 if ( mFilterView->filtersEnabled() ) {
2613 CalFilter *filter = mFilterView->selectedFilter(); 2617 CalFilter *filter = mFilterView->selectedFilter();
2614 if (filter && filter->showCategories()) { 2618 if (filter && filter->showCategories()) {
2615 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2619 mTodoEditor->setCategories(filter->categoryList().join(",") );
2616 } 2620 }
2617 if ( filter ) 2621 if ( filter )
2618 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2622 mTodoEditor->setSecrecy( filter->getSecrecy() );
2619 } 2623 }
2620 showTodoEditor(); 2624 showTodoEditor();
2621} 2625}
2622 2626
2623void CalendarView::newSubTodo() 2627void CalendarView::newSubTodo()
2624{ 2628{
2625 Todo *todo = selectedTodo(); 2629 Todo *todo = selectedTodo();
2626 if ( todo ) newSubTodo( todo ); 2630 if ( todo ) newSubTodo( todo );
2627} 2631}
2628 2632
2629void CalendarView::newSubTodo(Todo *parentEvent) 2633void CalendarView::newSubTodo(Todo *parentEvent)
2630{ 2634{
2631 2635
2632 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2636 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2633 showTodoEditor(); 2637 showTodoEditor();
2634} 2638}
2635 2639
2636void CalendarView::newFloatingEvent() 2640void CalendarView::newFloatingEvent()
2637{ 2641{
2638 DateList tmpList = mNavigator->selectedDates(); 2642 DateList tmpList = mNavigator->selectedDates();
2639 QDate date = tmpList.first(); 2643 QDate date = tmpList.first();
2640 2644
2641 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2645 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2642 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2646 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2643} 2647}
2644 2648
2645 2649
2646void CalendarView::editEvent( Event *event ) 2650void CalendarView::editEvent( Event *event )
2647{ 2651{
2648 2652
2649 if ( !event ) return; 2653 if ( !event ) return;
2650 if ( event->isReadOnly() ) { 2654 if ( event->isReadOnly() ) {
2651 showEvent( event ); 2655 showEvent( event );
2652 return; 2656 return;
2653 } 2657 }
2654 mEventEditor->editEvent( event , mFlagEditDescription); 2658 mEventEditor->editEvent( event , mFlagEditDescription);
2655 showEventEditor(); 2659 showEventEditor();
2656} 2660}
2657void CalendarView::editJournal( Journal *jour ) 2661void CalendarView::editJournal( Journal *jour )
2658{ 2662{
2659 if ( !jour ) return; 2663 if ( !jour ) return;
2660 mDialogManager->hideSearchDialog(); 2664 mDialogManager->hideSearchDialog();
2661 mViewManager->showJournalView(); 2665 mViewManager->showJournalView();
2662 mNavigator->slotDaySelect( jour->dtStart().date() ); 2666 mNavigator->slotDaySelect( jour->dtStart().date() );
2663} 2667}
2664void CalendarView::editTodo( Todo *todo ) 2668void CalendarView::editTodo( Todo *todo )
2665{ 2669{
2666 if ( !todo ) return; 2670 if ( !todo ) return;
2667 2671
2668 if ( todo->isReadOnly() ) { 2672 if ( todo->isReadOnly() ) {
2669 showTodo( todo ); 2673 showTodo( todo );
2670 return; 2674 return;
2671 } 2675 }
2672 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2676 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2673 showTodoEditor(); 2677 showTodoEditor();
2674 2678
2675} 2679}
2676 2680
2677KOEventViewerDialog* CalendarView::getEventViewerDialog() 2681KOEventViewerDialog* CalendarView::getEventViewerDialog()
2678{ 2682{
2679 if ( !mEventViewerDialog ) { 2683 if ( !mEventViewerDialog ) {
2680 mEventViewerDialog = new KOEventViewerDialog(this); 2684 mEventViewerDialog = new KOEventViewerDialog(this);
2681 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2685 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2682 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2686 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2683 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2687 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2684 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2688 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2685 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2689 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2686 viewManager(), SLOT( showAgendaView( bool ) ) ); 2690 viewManager(), SLOT( showAgendaView( bool ) ) );
2687 mEventViewerDialog->resize( 640, 480 ); 2691 mEventViewerDialog->resize( 640, 480 );
2688 2692
2689 } 2693 }
2690 return mEventViewerDialog; 2694 return mEventViewerDialog;
2691} 2695}
2692void CalendarView::showEvent(Event *event) 2696void CalendarView::showEvent(Event *event)
2693{ 2697{
2694 getEventViewerDialog()->setEvent(event); 2698 getEventViewerDialog()->setEvent(event);
2695 getEventViewerDialog()->showMe(); 2699 getEventViewerDialog()->showMe();
2696} 2700}
2697 2701
2698void CalendarView::showTodo(Todo *event) 2702void CalendarView::showTodo(Todo *event)
2699{ 2703{
2700 getEventViewerDialog()->setTodo(event); 2704 getEventViewerDialog()->setTodo(event);
2701 getEventViewerDialog()->showMe(); 2705 getEventViewerDialog()->showMe();
2702} 2706}
2703void CalendarView::showJournal( Journal *jour ) 2707void CalendarView::showJournal( Journal *jour )
2704{ 2708{
2705 getEventViewerDialog()->setJournal(jour); 2709 getEventViewerDialog()->setJournal(jour);
2706 getEventViewerDialog()->showMe(); 2710 getEventViewerDialog()->showMe();
2707 2711
2708} 2712}
2709// void CalendarView::todoModified (Todo *event, int changed) 2713// void CalendarView::todoModified (Todo *event, int changed)
2710// { 2714// {
2711// // if (mDialogList.find (event) != mDialogList.end ()) { 2715// // if (mDialogList.find (event) != mDialogList.end ()) {
2712// // kdDebug() << "Todo modified and open" << endl; 2716// // kdDebug() << "Todo modified and open" << endl;
2713// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2717// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2714// // temp->modified (changed); 2718// // temp->modified (changed);
2715 2719
2716// // } 2720// // }
2717 2721
2718// mViewManager->updateView(); 2722// mViewManager->updateView();
2719// } 2723// }
2720 2724
2721void CalendarView::appointment_show() 2725void CalendarView::appointment_show()
2722{ 2726{
2723 Event *anEvent = 0; 2727 Event *anEvent = 0;
2724 2728
2725 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2729 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2726 2730
2727 if (mViewManager->currentView()->isEventView()) { 2731 if (mViewManager->currentView()->isEventView()) {
2728 if ( incidence && incidence->type() == "Event" ) { 2732 if ( incidence && incidence->type() == "Event" ) {
2729 anEvent = static_cast<Event *>(incidence); 2733 anEvent = static_cast<Event *>(incidence);
2730 } 2734 }
2731 } 2735 }
2732 2736
2733 if (!anEvent) { 2737 if (!anEvent) {
2734 KNotifyClient::beep(); 2738 KNotifyClient::beep();
2735 return; 2739 return;
2736 } 2740 }
2737 2741
2738 showEvent(anEvent); 2742 showEvent(anEvent);
2739} 2743}
2740 2744
2741void CalendarView::appointment_edit() 2745void CalendarView::appointment_edit()
2742{ 2746{
2743 Event *anEvent = 0; 2747 Event *anEvent = 0;
2744 2748
2745 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2749 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2746 2750
2747 if (mViewManager->currentView()->isEventView()) { 2751 if (mViewManager->currentView()->isEventView()) {
2748 if ( incidence && incidence->type() == "Event" ) { 2752 if ( incidence && incidence->type() == "Event" ) {
2749 anEvent = static_cast<Event *>(incidence); 2753 anEvent = static_cast<Event *>(incidence);
2750 } 2754 }
2751 } 2755 }
2752 2756
2753 if (!anEvent) { 2757 if (!anEvent) {
2754 KNotifyClient::beep(); 2758 KNotifyClient::beep();
2755 return; 2759 return;
2756 } 2760 }
2757 2761
2758 editEvent(anEvent); 2762 editEvent(anEvent);
2759} 2763}
2760 2764
2761void CalendarView::appointment_delete() 2765void CalendarView::appointment_delete()
2762{ 2766{
2763 Event *anEvent = 0; 2767 Event *anEvent = 0;
2764 2768
2765 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2769 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2766 2770
2767 if (mViewManager->currentView()->isEventView()) { 2771 if (mViewManager->currentView()->isEventView()) {
2768 if ( incidence && incidence->type() == "Event" ) { 2772 if ( incidence && incidence->type() == "Event" ) {
2769 anEvent = static_cast<Event *>(incidence); 2773 anEvent = static_cast<Event *>(incidence);
2770 } 2774 }
2771 } 2775 }
2772 2776
2773 if (!anEvent) { 2777 if (!anEvent) {
2774 KNotifyClient::beep(); 2778 KNotifyClient::beep();
2775 return; 2779 return;
2776 } 2780 }
2777 2781
2778 deleteEvent(anEvent); 2782 deleteEvent(anEvent);
2779} 2783}
2780 2784
2781void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2785void CalendarView::todo_resub( Todo * parent, Todo * sub )
2782{ 2786{
2783 if (!sub) return; 2787 if (!sub) return;
2784 if (!parent) return; 2788 if (!parent) return;
2785 if ( sub->relatedTo() ) 2789 if ( sub->relatedTo() )
2786 sub->relatedTo()->removeRelation(sub); 2790 sub->relatedTo()->removeRelation(sub);
2787 sub->setRelatedTo(parent); 2791 sub->setRelatedTo(parent);
2788 sub->setRelatedToUid(parent->uid()); 2792 sub->setRelatedToUid(parent->uid());
2789 parent->addRelation(sub); 2793 parent->addRelation(sub);
2790 sub->updated(); 2794 sub->updated();
2791 parent->updated(); 2795 parent->updated();
2792 setModified(true); 2796 setModified(true);
2793 updateView(); 2797 updateView();
2794} 2798}
2795void CalendarView::todo_unsub(Todo *anTodo ) 2799void CalendarView::todo_unsub(Todo *anTodo )
2796{ 2800{
2797 // Todo *anTodo = selectedTodo(); 2801 // Todo *anTodo = selectedTodo();
2798 if (!anTodo) return; 2802 if (!anTodo) return;
2799 if (!anTodo->relatedTo()) return; 2803 if (!anTodo->relatedTo()) return;
2800 anTodo->relatedTo()->removeRelation(anTodo); 2804 anTodo->relatedTo()->removeRelation(anTodo);
2801 anTodo->setRelatedTo(0); 2805 anTodo->setRelatedTo(0);
2802 anTodo->updated(); 2806 anTodo->updated();
2803 anTodo->setRelatedToUid(""); 2807 anTodo->setRelatedToUid("");
2804 setModified(true); 2808 setModified(true);
2805 updateView(); 2809 updateView();
2806} 2810}
2807 2811
2808void CalendarView::deleteTodo(Todo *todo) 2812void CalendarView::deleteTodo(Todo *todo)
2809{ 2813{
2810 if (!todo) { 2814 if (!todo) {
2811 KNotifyClient::beep(); 2815 KNotifyClient::beep();
2812 return; 2816 return;
2813 } 2817 }
2814 if (KOPrefs::instance()->mConfirm) { 2818 if (KOPrefs::instance()->mConfirm) {
2815 switch (msgItemDelete()) { 2819 switch (msgItemDelete()) {
2816 case KMessageBox::Continue: // OK 2820 case KMessageBox::Continue: // OK
2817 if (!todo->relations().isEmpty()) { 2821 if (!todo->relations().isEmpty()) {
2818 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2822 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2819 i18n("Delete To-Do")); 2823 i18n("Delete To-Do"));
2820 } else { 2824 } else {
2821 checkExternalId( todo ); 2825 checkExternalId( todo );
2822 calendar()->deleteTodo(todo); 2826 calendar()->deleteTodo(todo);
2823 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2827 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2824 updateView(); 2828 updateView();
2825 } 2829 }
2826 break; 2830 break;
2827 } // switch 2831 } // switch
2828 } else { 2832 } else {
2829 if (!todo->relations().isEmpty()) { 2833 if (!todo->relations().isEmpty()) {
2830 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2834 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2831 i18n("Delete To-Do")); 2835 i18n("Delete To-Do"));
2832 } else { 2836 } else {
2833 checkExternalId( todo ); 2837 checkExternalId( todo );
2834 mCalendar->deleteTodo(todo); 2838 mCalendar->deleteTodo(todo);
2835 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2839 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2836 updateView(); 2840 updateView();
2837 } 2841 }
2838 } 2842 }
2839 emit updateSearchDialog(); 2843 emit updateSearchDialog();
2840} 2844}
2841void CalendarView::deleteJournal(Journal *jour) 2845void CalendarView::deleteJournal(Journal *jour)
2842{ 2846{
2843 if (!jour) { 2847 if (!jour) {
2844 KNotifyClient::beep(); 2848 KNotifyClient::beep();
2845 return; 2849 return;
2846 } 2850 }
2847 if (KOPrefs::instance()->mConfirm) { 2851 if (KOPrefs::instance()->mConfirm) {
2848 switch (msgItemDelete()) { 2852 switch (msgItemDelete()) {
2849 case KMessageBox::Continue: // OK 2853 case KMessageBox::Continue: // OK
2850 calendar()->deleteJournal(jour); 2854 calendar()->deleteJournal(jour);
2851 updateView(); 2855 updateView();
2852 break; 2856 break;
2853 } // switch 2857 } // switch
2854 } else { 2858 } else {
2855 calendar()->deleteJournal(jour);; 2859 calendar()->deleteJournal(jour);;
2856 updateView(); 2860 updateView();
2857 } 2861 }
2858 emit updateSearchDialog(); 2862 emit updateSearchDialog();
2859} 2863}
2860 2864
2861void CalendarView::deleteEvent(Event *anEvent) 2865void CalendarView::deleteEvent(Event *anEvent)
2862{ 2866{
2863 if (!anEvent) { 2867 if (!anEvent) {
2864 KNotifyClient::beep(); 2868 KNotifyClient::beep();
2865 return; 2869 return;
2866 } 2870 }
2867 2871
2868 if (anEvent->recurrence()->doesRecur()) { 2872 if (anEvent->recurrence()->doesRecur()) {
2869 QDate itemDate = mViewManager->currentSelectionDate(); 2873 QDate itemDate = mViewManager->currentSelectionDate();
2870 int km; 2874 int km;
2871 if (!itemDate.isValid()) { 2875 if (!itemDate.isValid()) {
2872 //kdDebug() << "Date Not Valid" << endl; 2876 //kdDebug() << "Date Not Valid" << endl;
2873 if (KOPrefs::instance()->mConfirm) { 2877 if (KOPrefs::instance()->mConfirm) {
2874 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2878 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2875 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2879 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2876 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2880 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2877 if ( km == KMessageBox::Continue ) 2881 if ( km == KMessageBox::Continue )
2878 km = KMessageBox::No; // No = all below 2882 km = KMessageBox::No; // No = all below
2879 } else 2883 } else
2880 km = KMessageBox::No; 2884 km = KMessageBox::No;
2881 } else { 2885 } else {
2882 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2886 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2883 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2887 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2884 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2888 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2885 i18n("KO/Pi Confirmation"),i18n("Current"), 2889 i18n("KO/Pi Confirmation"),i18n("Current"),
2886 i18n("All")); 2890 i18n("All"));
2887 } 2891 }
2888 switch(km) { 2892 switch(km) {
2889 2893
2890 case KMessageBox::No: // Continue // all 2894 case KMessageBox::No: // Continue // all
2891 //qDebug("KMessageBox::No "); 2895 //qDebug("KMessageBox::No ");
2892 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2896 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2893 schedule(Scheduler::Cancel,anEvent); 2897 schedule(Scheduler::Cancel,anEvent);
2894 2898
2895 checkExternalId( anEvent); 2899 checkExternalId( anEvent);
2896 mCalendar->deleteEvent(anEvent); 2900 mCalendar->deleteEvent(anEvent);
2897 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2901 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2898 break; 2902 break;
2899 2903
2900 // Disabled because it does not work 2904 // Disabled because it does not work
2901 //#if 0 2905 //#if 0
2902 case KMessageBox::Yes: // just this one 2906 case KMessageBox::Yes: // just this one
2903 //QDate qd = mNavigator->selectedDates().first(); 2907 //QDate qd = mNavigator->selectedDates().first();
2904 //if (!qd.isValid()) { 2908 //if (!qd.isValid()) {
2905 // kdDebug() << "no date selected, or invalid date" << endl; 2909 // kdDebug() << "no date selected, or invalid date" << endl;
2906 // KNotifyClient::beep(); 2910 // KNotifyClient::beep();
2907 // return; 2911 // return;
2908 //} 2912 //}
2909 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2913 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2910 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2914 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2911 anEvent->addExDate(itemDate); 2915 anEvent->addExDate(itemDate);
2912 int duration = anEvent->recurrence()->duration(); 2916 int duration = anEvent->recurrence()->duration();
2913 if ( duration > 0 ) { 2917 if ( duration > 0 ) {
2914 anEvent->recurrence()->setDuration( duration - 1 ); 2918 anEvent->recurrence()->setDuration( duration - 1 );
2915 } 2919 }
2916 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2920 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2917 } 2921 }
2918 break; 2922 break;
2919 //#endif 2923 //#endif
2920 } // switch 2924 } // switch
2921 } else { 2925 } else {
2922 if (KOPrefs::instance()->mConfirm) { 2926 if (KOPrefs::instance()->mConfirm) {
2923 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2927 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2924 i18n("\nAre you sure you want\nto delete this event?"), 2928 i18n("\nAre you sure you want\nto delete this event?"),
2925 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2929 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2926 case KMessageBox::Continue: // OK 2930 case KMessageBox::Continue: // OK
2927 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2931 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2928 schedule(Scheduler::Cancel,anEvent); 2932 schedule(Scheduler::Cancel,anEvent);
2929 checkExternalId( anEvent); 2933 checkExternalId( anEvent);
2930 mCalendar->deleteEvent(anEvent); 2934 mCalendar->deleteEvent(anEvent);
2931 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2935 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2932 break; 2936 break;
2933 } // switch 2937 } // switch
2934 } else { 2938 } else {
2935 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2939 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2936 schedule(Scheduler::Cancel,anEvent); 2940 schedule(Scheduler::Cancel,anEvent);
2937 checkExternalId( anEvent); 2941 checkExternalId( anEvent);
2938 mCalendar->deleteEvent(anEvent); 2942 mCalendar->deleteEvent(anEvent);
2939 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2943 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2940 } 2944 }
2941 } // if-else 2945 } // if-else
2942 emit updateSearchDialog(); 2946 emit updateSearchDialog();
2943} 2947}
2944 2948
2945bool CalendarView::deleteEvent(const QString &uid) 2949bool CalendarView::deleteEvent(const QString &uid)
2946{ 2950{
2947 Event *ev = mCalendar->event(uid); 2951 Event *ev = mCalendar->event(uid);
2948 if (ev) { 2952 if (ev) {
2949 deleteEvent(ev); 2953 deleteEvent(ev);
2950 return true; 2954 return true;
2951 } else { 2955 } else {
2952 return false; 2956 return false;
2953 } 2957 }
2954} 2958}
2955 2959
2956/*****************************************************************************/ 2960/*****************************************************************************/
2957 2961
2958void CalendarView::action_mail() 2962void CalendarView::action_mail()
2959{ 2963{
2960#ifndef KORG_NOMAIL 2964#ifndef KORG_NOMAIL
2961 KOMailClient mailClient; 2965 KOMailClient mailClient;
2962 2966
2963 Incidence *incidence = currentSelection(); 2967 Incidence *incidence = currentSelection();
2964 2968
2965 if (!incidence) { 2969 if (!incidence) {
2966 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2970 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2967 return; 2971 return;
2968 } 2972 }
2969 if(incidence->attendeeCount() == 0 ) { 2973 if(incidence->attendeeCount() == 0 ) {
2970 KMessageBox::sorry(this, 2974 KMessageBox::sorry(this,
2971 i18n("Can't generate mail:\nNo attendees defined.\n")); 2975 i18n("Can't generate mail:\nNo attendees defined.\n"));
2972 return; 2976 return;
2973 } 2977 }
2974 2978
2975 CalendarLocal cal_tmp; 2979 CalendarLocal cal_tmp;
2976 Event *event = 0; 2980 Event *event = 0;
2977 Event *ev = 0; 2981 Event *ev = 0;
2978 if ( incidence && incidence->type() == "Event" ) { 2982 if ( incidence && incidence->type() == "Event" ) {
2979 event = static_cast<Event *>(incidence); 2983 event = static_cast<Event *>(incidence);
2980 ev = new Event(*event); 2984 ev = new Event(*event);
2981 cal_tmp.addEvent(ev); 2985 cal_tmp.addEvent(ev);
2982 } 2986 }
2983 ICalFormat mForm(); 2987 ICalFormat mForm();
2984 QString attachment = mForm.toString( &cal_tmp ); 2988 QString attachment = mForm.toString( &cal_tmp );
2985 if (ev) delete(ev); 2989 if (ev) delete(ev);
2986 2990
2987 mailClient.mailAttendees(currentSelection(), attachment); 2991 mailClient.mailAttendees(currentSelection(), attachment);
2988 2992
2989#endif 2993#endif
2990 2994
2991#if 0 2995#if 0
2992 Event *anEvent = 0; 2996 Event *anEvent = 0;
2993 if (mViewManager->currentView()->isEventView()) { 2997 if (mViewManager->currentView()->isEventView()) {
2994 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2998 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2995 } 2999 }
2996 3000
2997 if (!anEvent) { 3001 if (!anEvent) {
2998 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3002 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2999 return; 3003 return;
3000 } 3004 }
3001 if(anEvent->attendeeCount() == 0 ) { 3005 if(anEvent->attendeeCount() == 0 ) {
3002 KMessageBox::sorry(this, 3006 KMessageBox::sorry(this,
3003 i18n("Can't generate mail:\nNo attendees defined.\n")); 3007 i18n("Can't generate mail:\nNo attendees defined.\n"));
3004 return; 3008 return;
3005 } 3009 }
3006 3010
3007 mailobject.emailEvent(anEvent); 3011 mailobject.emailEvent(anEvent);
3008#endif 3012#endif
3009} 3013}
3010 3014
3011 3015
3012void CalendarView::schedule_publish(Incidence *incidence) 3016void CalendarView::schedule_publish(Incidence *incidence)
3013{ 3017{
3014 Event *event = 0; 3018 Event *event = 0;
3015 Todo *todo = 0; 3019 Todo *todo = 0;
3016 3020
3017 if (incidence == 0) { 3021 if (incidence == 0) {
3018 incidence = mViewManager->currentView()->selectedIncidences().first(); 3022 incidence = mViewManager->currentView()->selectedIncidences().first();
3019 if (incidence == 0) { 3023 if (incidence == 0) {
3020 incidence = mTodoList->selectedIncidences().first(); 3024 incidence = mTodoList->selectedIncidences().first();
3021 } 3025 }
3022 } 3026 }
3023 if ( incidence && incidence->type() == "Event" ) { 3027 if ( incidence && incidence->type() == "Event" ) {
3024 event = static_cast<Event *>(incidence); 3028 event = static_cast<Event *>(incidence);
3025 } else { 3029 } else {
3026 if ( incidence && incidence->type() == "Todo" ) { 3030 if ( incidence && incidence->type() == "Todo" ) {
3027 todo = static_cast<Todo *>(incidence); 3031 todo = static_cast<Todo *>(incidence);
3028 } 3032 }
3029 } 3033 }
3030 3034
3031 if (!event && !todo) { 3035 if (!event && !todo) {
3032 KMessageBox::sorry(this,i18n("No event selected.")); 3036 KMessageBox::sorry(this,i18n("No event selected."));
3033 return; 3037 return;
3034 } 3038 }
3035 3039
3036 PublishDialog *publishdlg = new PublishDialog(); 3040 PublishDialog *publishdlg = new PublishDialog();
3037 if (incidence->attendeeCount()>0) { 3041 if (incidence->attendeeCount()>0) {
3038 QPtrList<Attendee> attendees = incidence->attendees(); 3042 QPtrList<Attendee> attendees = incidence->attendees();
3039 attendees.first(); 3043 attendees.first();
3040 while ( attendees.current()!=0 ) { 3044 while ( attendees.current()!=0 ) {
3041 publishdlg->addAttendee(attendees.current()); 3045 publishdlg->addAttendee(attendees.current());
3042 attendees.next(); 3046 attendees.next();
3043 } 3047 }
3044 } 3048 }
3045 bool send = true; 3049 bool send = true;
3046 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3050 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3047 if ( publishdlg->exec() != QDialog::Accepted ) 3051 if ( publishdlg->exec() != QDialog::Accepted )
3048 send = false; 3052 send = false;
3049 } 3053 }
3050 if ( send ) { 3054 if ( send ) {
3051 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3055 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3052 if ( event ) { 3056 if ( event ) {
3053 Event *ev = new Event(*event); 3057 Event *ev = new Event(*event);
3054 ev->registerObserver(0); 3058 ev->registerObserver(0);
3055 ev->clearAttendees(); 3059 ev->clearAttendees();
3056 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3060 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3057 delete(ev); 3061 delete(ev);
3058 } 3062 }
3059 } else { 3063 } else {
3060 if ( todo ) { 3064 if ( todo ) {
3061 Todo *ev = new Todo(*todo); 3065 Todo *ev = new Todo(*todo);
3062 ev->registerObserver(0); 3066 ev->registerObserver(0);
3063 ev->clearAttendees(); 3067 ev->clearAttendees();
3064 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3068 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3065 delete(ev); 3069 delete(ev);
3066 } 3070 }
3067 } 3071 }
3068 } 3072 }
3069 } 3073 }
3070 delete publishdlg; 3074 delete publishdlg;
3071} 3075}
3072 3076
3073void CalendarView::schedule_request(Incidence *incidence) 3077void CalendarView::schedule_request(Incidence *incidence)
3074{ 3078{
3075 schedule(Scheduler::Request,incidence); 3079 schedule(Scheduler::Request,incidence);
3076} 3080}
3077 3081
3078void CalendarView::schedule_refresh(Incidence *incidence) 3082void CalendarView::schedule_refresh(Incidence *incidence)
3079{ 3083{
3080 schedule(Scheduler::Refresh,incidence); 3084 schedule(Scheduler::Refresh,incidence);
3081} 3085}
3082 3086
3083void CalendarView::schedule_cancel(Incidence *incidence) 3087void CalendarView::schedule_cancel(Incidence *incidence)
3084{ 3088{
3085 schedule(Scheduler::Cancel,incidence); 3089 schedule(Scheduler::Cancel,incidence);
3086} 3090}
3087 3091
3088void CalendarView::schedule_add(Incidence *incidence) 3092void CalendarView::schedule_add(Incidence *incidence)
3089{ 3093{
3090 schedule(Scheduler::Add,incidence); 3094 schedule(Scheduler::Add,incidence);
3091} 3095}
3092 3096
3093void CalendarView::schedule_reply(Incidence *incidence) 3097void CalendarView::schedule_reply(Incidence *incidence)
3094{ 3098{
3095 schedule(Scheduler::Reply,incidence); 3099 schedule(Scheduler::Reply,incidence);
3096} 3100}
3097 3101
3098void CalendarView::schedule_counter(Incidence *incidence) 3102void CalendarView::schedule_counter(Incidence *incidence)
3099{ 3103{
3100 schedule(Scheduler::Counter,incidence); 3104 schedule(Scheduler::Counter,incidence);
3101} 3105}
3102 3106
3103void CalendarView::schedule_declinecounter(Incidence *incidence) 3107void CalendarView::schedule_declinecounter(Incidence *incidence)
3104{ 3108{
3105 schedule(Scheduler::Declinecounter,incidence); 3109 schedule(Scheduler::Declinecounter,incidence);
3106} 3110}
3107 3111
3108void CalendarView::schedule_publish_freebusy(int daysToPublish) 3112void CalendarView::schedule_publish_freebusy(int daysToPublish)
3109{ 3113{
3110 QDateTime start = QDateTime::currentDateTime(); 3114 QDateTime start = QDateTime::currentDateTime();
3111 QDateTime end = start.addDays(daysToPublish); 3115 QDateTime end = start.addDays(daysToPublish);
3112 3116
3113 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3117 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3114 freebusy->setOrganizer(KOPrefs::instance()->email()); 3118 freebusy->setOrganizer(KOPrefs::instance()->email());
3115 3119
3116 3120
3117 PublishDialog *publishdlg = new PublishDialog(); 3121 PublishDialog *publishdlg = new PublishDialog();
3118 if ( publishdlg->exec() == QDialog::Accepted ) { 3122 if ( publishdlg->exec() == QDialog::Accepted ) {
3119 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3123 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3120 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3124 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3121 delete(freebusy); 3125 delete(freebusy);
3122 } 3126 }
3123 } 3127 }
3124 delete publishdlg; 3128 delete publishdlg;
3125} 3129}
3126 3130
3127void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3131void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3128{ 3132{
3129 Event *event = 0; 3133 Event *event = 0;
3130 Todo *todo = 0; 3134 Todo *todo = 0;
3131 3135
3132 if (incidence == 0) { 3136 if (incidence == 0) {
3133 incidence = mViewManager->currentView()->selectedIncidences().first(); 3137 incidence = mViewManager->currentView()->selectedIncidences().first();
3134 if (incidence == 0) { 3138 if (incidence == 0) {
3135 incidence = mTodoList->selectedIncidences().first(); 3139 incidence = mTodoList->selectedIncidences().first();
3136 } 3140 }
3137 } 3141 }
3138 if ( incidence && incidence->type() == "Event" ) { 3142 if ( incidence && incidence->type() == "Event" ) {
3139 event = static_cast<Event *>(incidence); 3143 event = static_cast<Event *>(incidence);
3140 } 3144 }
3141 if ( incidence && incidence->type() == "Todo" ) { 3145 if ( incidence && incidence->type() == "Todo" ) {
3142 todo = static_cast<Todo *>(incidence); 3146 todo = static_cast<Todo *>(incidence);
3143 } 3147 }
3144 3148
3145 if (!event && !todo) { 3149 if (!event && !todo) {
3146 KMessageBox::sorry(this,i18n("No event selected.")); 3150 KMessageBox::sorry(this,i18n("No event selected."));
3147 return; 3151 return;
3148 } 3152 }
3149 3153
3150 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3154 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3151 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3155 KMessageBox::sorry(this,i18n("The event has no attendees."));
3152 return; 3156 return;
3153 } 3157 }
3154 3158
3155 Event *ev = 0; 3159 Event *ev = 0;
3156 if (event) ev = new Event(*event); 3160 if (event) ev = new Event(*event);
3157 Todo *to = 0; 3161 Todo *to = 0;
3158 if (todo) to = new Todo(*todo); 3162 if (todo) to = new Todo(*todo);
3159 3163
3160 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3164 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3161 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3165 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3162 if (!me) { 3166 if (!me) {
3163 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3167 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3164 return; 3168 return;
3165 } 3169 }
3166 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3170 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3167 StatusDialog *statdlg = new StatusDialog(this); 3171 StatusDialog *statdlg = new StatusDialog(this);
3168 if (!statdlg->exec()==QDialog::Accepted) return; 3172 if (!statdlg->exec()==QDialog::Accepted) return;
3169 me->setStatus( statdlg->status() ); 3173 me->setStatus( statdlg->status() );
3170 delete(statdlg); 3174 delete(statdlg);
3171 } 3175 }
3172 Attendee *menew = new Attendee(*me); 3176 Attendee *menew = new Attendee(*me);
3173 if (ev) { 3177 if (ev) {
3174 ev->clearAttendees(); 3178 ev->clearAttendees();
3175 ev->addAttendee(menew,false); 3179 ev->addAttendee(menew,false);
3176 } else { 3180 } else {
3177 if (to) { 3181 if (to) {
3178 todo->clearAttendees(); 3182 todo->clearAttendees();
3179 todo->addAttendee(menew,false); 3183 todo->addAttendee(menew,false);
3180 } 3184 }
3181 } 3185 }
3182 } 3186 }
3183 3187
3184 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3188 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3185 if (ev) { 3189 if (ev) {
3186 if ( !dlg->addMessage(ev,method) ) delete(ev); 3190 if ( !dlg->addMessage(ev,method) ) delete(ev);
3187 } else { 3191 } else {
3188 if (to) { 3192 if (to) {
3189 if ( !dlg->addMessage(to,method) ) delete(to); 3193 if ( !dlg->addMessage(to,method) ) delete(to);
3190 } 3194 }
3191 } 3195 }
3192} 3196}
3193 3197
3194void CalendarView::openAddressbook() 3198void CalendarView::openAddressbook()
3195{ 3199{
3196 KRun::runCommand("kaddressbook"); 3200 KRun::runCommand("kaddressbook");
3197} 3201}
3198 3202
3199void CalendarView::setModified(bool modified) 3203void CalendarView::setModified(bool modified)
3200{ 3204{
3201 if ( modified ) 3205 if ( modified )
3202 emit signalmodified(); 3206 emit signalmodified();
3203 if (mModified != modified) { 3207 if (mModified != modified) {
3204 mModified = modified; 3208 mModified = modified;
3205 emit modifiedChanged(mModified); 3209 emit modifiedChanged(mModified);
3206 } 3210 }
3207} 3211}
3208 3212
3209bool CalendarView::isReadOnly() 3213bool CalendarView::isReadOnly()
3210{ 3214{
3211 return mReadOnly; 3215 return mReadOnly;
3212} 3216}
3213 3217
3214void CalendarView::setReadOnly(bool readOnly) 3218void CalendarView::setReadOnly(bool readOnly)
3215{ 3219{
3216 if (mReadOnly != readOnly) { 3220 if (mReadOnly != readOnly) {
3217 mReadOnly = readOnly; 3221 mReadOnly = readOnly;
3218 emit readOnlyChanged(mReadOnly); 3222 emit readOnlyChanged(mReadOnly);
3219 } 3223 }
3220} 3224}
3221 3225
3222bool CalendarView::isModified() 3226bool CalendarView::isModified()
3223{ 3227{
3224 return mModified; 3228 return mModified;
3225} 3229}
3226 3230
3227void CalendarView::printSetup() 3231void CalendarView::printSetup()
3228{ 3232{
3229#ifndef KORG_NOPRINTER 3233#ifndef KORG_NOPRINTER
3230 createPrinter(); 3234 createPrinter();
3231 3235
3232 mCalPrinter->setupPrinter(); 3236 mCalPrinter->setupPrinter();
3233#endif 3237#endif
3234} 3238}
3235 3239
3236void CalendarView::print() 3240void CalendarView::print()
3237{ 3241{
3238#ifndef KORG_NOPRINTER 3242#ifndef KORG_NOPRINTER
3239 createPrinter(); 3243 createPrinter();
3240 3244
3241 DateList tmpDateList = mNavigator->selectedDates(); 3245 DateList tmpDateList = mNavigator->selectedDates();
3242 mCalPrinter->print(CalPrinter::Month, 3246 mCalPrinter->print(CalPrinter::Month,
3243 tmpDateList.first(), tmpDateList.last()); 3247 tmpDateList.first(), tmpDateList.last());
3244#endif 3248#endif
3245} 3249}
3246 3250
3247void CalendarView::printPreview() 3251void CalendarView::printPreview()
3248{ 3252{
3249#ifndef KORG_NOPRINTER 3253#ifndef KORG_NOPRINTER
3250 kdDebug() << "CalendarView::printPreview()" << endl; 3254 kdDebug() << "CalendarView::printPreview()" << endl;
3251 3255
3252 createPrinter(); 3256 createPrinter();
3253 3257
3254 DateList tmpDateList = mNavigator->selectedDates(); 3258 DateList tmpDateList = mNavigator->selectedDates();
3255 3259
3256 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3260 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3257 tmpDateList.last()); 3261 tmpDateList.last());
3258#endif 3262#endif
3259} 3263}
3260 3264
3261void CalendarView::exportICalendar() 3265void CalendarView::exportICalendar()
3262{ 3266{
3263 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3267 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3264 3268
3265 // Force correct extension 3269 // Force correct extension
3266 if (filename.right(4) != ".ics") filename += ".ics"; 3270 if (filename.right(4) != ".ics") filename += ".ics";
3267 3271
3268 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3272 FileStorage storage( mCalendar, filename, new ICalFormat() );
3269 storage.save(); 3273 storage.save();
3270} 3274}
3271 3275
3272bool CalendarView::exportVCalendar( QString filename ) 3276bool CalendarView::exportVCalendar( QString filename )
3273{ 3277{
3274 if (mCalendar->journals().count() > 0) { 3278 if (mCalendar->journals().count() > 0) {
3275 int result = KMessageBox::warningContinueCancel(this, 3279 int result = KMessageBox::warningContinueCancel(this,
3276 i18n("The journal entries can not be\nexported to a vCalendar file."), 3280 i18n("The journal entries can not be\nexported to a vCalendar file."),
3277 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3281 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3278 true); 3282 true);
3279 if (result != KMessageBox::Continue) return false; 3283 if (result != KMessageBox::Continue) return false;
3280 } 3284 }
3281 3285
3282 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3286 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3283 3287
3284 // Force correct extension 3288 // Force correct extension
3285 if (filename.right(4) != ".vcs") filename += ".vcs"; 3289 if (filename.right(4) != ".vcs") filename += ".vcs";
3286 3290
3287 FileStorage storage( mCalendar, filename, new VCalFormat ); 3291 FileStorage storage( mCalendar, filename, new VCalFormat );
3288 return storage.save(); 3292 return storage.save();
3289 3293
3290} 3294}
3291 3295
3292void CalendarView::eventUpdated(Incidence *) 3296void CalendarView::eventUpdated(Incidence *)
3293{ 3297{
3294 setModified(); 3298 setModified();
3295 // Don't call updateView here. The code, which has caused the update of the 3299 // Don't call updateView here. The code, which has caused the update of the
3296 // event is responsible for updating the view. 3300 // event is responsible for updating the view.
3297 // updateView(); 3301 // updateView();
3298} 3302}
3299 3303
3300void CalendarView::adaptNavigationUnits() 3304void CalendarView::adaptNavigationUnits()
3301{ 3305{
3302 if (mViewManager->currentView()->isEventView()) { 3306 if (mViewManager->currentView()->isEventView()) {
3303 int days = mViewManager->currentView()->currentDateCount(); 3307 int days = mViewManager->currentView()->currentDateCount();
3304 if (days == 1) { 3308 if (days == 1) {
3305 emit changeNavStringPrev(i18n("&Previous Day")); 3309 emit changeNavStringPrev(i18n("&Previous Day"));
3306 emit changeNavStringNext(i18n("&Next Day")); 3310 emit changeNavStringNext(i18n("&Next Day"));
3307 } else { 3311 } else {
3308 emit changeNavStringPrev(i18n("&Previous Week")); 3312 emit changeNavStringPrev(i18n("&Previous Week"));
3309 emit changeNavStringNext(i18n("&Next Week")); 3313 emit changeNavStringNext(i18n("&Next Week"));
3310 } 3314 }
3311 } 3315 }
3312} 3316}
3313 3317
3314void CalendarView::processMainViewSelection( Incidence *incidence ) 3318void CalendarView::processMainViewSelection( Incidence *incidence )
3315{ 3319{
3316 if ( incidence ) mTodoList->clearSelection(); 3320 if ( incidence ) mTodoList->clearSelection();
3317 processIncidenceSelection( incidence ); 3321 processIncidenceSelection( incidence );
3318} 3322}
3319 3323
3320void CalendarView::processTodoListSelection( Incidence *incidence ) 3324void CalendarView::processTodoListSelection( Incidence *incidence )
3321{ 3325{
3322 if ( incidence && mViewManager->currentView() ) { 3326 if ( incidence && mViewManager->currentView() ) {
3323 mViewManager->currentView()->clearSelection(); 3327 mViewManager->currentView()->clearSelection();
3324 } 3328 }
3325 processIncidenceSelection( incidence ); 3329 processIncidenceSelection( incidence );
3326} 3330}
3327 3331
3328void CalendarView::processIncidenceSelection( Incidence *incidence ) 3332void CalendarView::processIncidenceSelection( Incidence *incidence )
3329{ 3333{
3330 if ( incidence == mSelectedIncidence ) return; 3334 if ( incidence == mSelectedIncidence ) return;
3331 3335
3332 mSelectedIncidence = incidence; 3336 mSelectedIncidence = incidence;
3333 3337
3334 emit incidenceSelected( mSelectedIncidence ); 3338 emit incidenceSelected( mSelectedIncidence );
3335 3339
3336 if ( incidence && incidence->type() == "Event" ) { 3340 if ( incidence && incidence->type() == "Event" ) {
3337 Event *event = static_cast<Event *>( incidence ); 3341 Event *event = static_cast<Event *>( incidence );
3338 if ( event->organizer() == KOPrefs::instance()->email() ) { 3342 if ( event->organizer() == KOPrefs::instance()->email() ) {
3339 emit organizerEventsSelected( true ); 3343 emit organizerEventsSelected( true );
3340 } else { 3344 } else {
3341 emit organizerEventsSelected(false); 3345 emit organizerEventsSelected(false);
3342 } 3346 }
3343 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3347 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3344 KOPrefs::instance()->email() ) ) { 3348 KOPrefs::instance()->email() ) ) {
3345 emit groupEventsSelected( true ); 3349 emit groupEventsSelected( true );
3346 } else { 3350 } else {
3347 emit groupEventsSelected(false); 3351 emit groupEventsSelected(false);
3348 } 3352 }
3349 return; 3353 return;
3350 } else { 3354 } else {
3351 if ( incidence && incidence->type() == "Todo" ) { 3355 if ( incidence && incidence->type() == "Todo" ) {
3352 emit todoSelected( true ); 3356 emit todoSelected( true );
3353 Todo *event = static_cast<Todo *>( incidence ); 3357 Todo *event = static_cast<Todo *>( incidence );
3354 if ( event->organizer() == KOPrefs::instance()->email() ) { 3358 if ( event->organizer() == KOPrefs::instance()->email() ) {
3355 emit organizerEventsSelected( true ); 3359 emit organizerEventsSelected( true );
3356 } else { 3360 } else {
3357 emit organizerEventsSelected(false); 3361 emit organizerEventsSelected(false);
3358 } 3362 }
3359 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3363 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3360 KOPrefs::instance()->email() ) ) { 3364 KOPrefs::instance()->email() ) ) {
3361 emit groupEventsSelected( true ); 3365 emit groupEventsSelected( true );
3362 } else { 3366 } else {
3363 emit groupEventsSelected(false); 3367 emit groupEventsSelected(false);
3364 } 3368 }
3365 return; 3369 return;
3366 } else { 3370 } else {
3367 emit todoSelected( false ); 3371 emit todoSelected( false );
3368 emit organizerEventsSelected(false); 3372 emit organizerEventsSelected(false);
3369 emit groupEventsSelected(false); 3373 emit groupEventsSelected(false);
3370 } 3374 }
3371 return; 3375 return;
3372 } 3376 }
3373 3377
3374 /* if ( incidence && incidence->type() == "Todo" ) { 3378 /* if ( incidence && incidence->type() == "Todo" ) {
3375 emit todoSelected( true ); 3379 emit todoSelected( true );
3376 } else { 3380 } else {
3377 emit todoSelected( false ); 3381 emit todoSelected( false );
3378 }*/ 3382 }*/
3379} 3383}
3380 3384
3381 3385
3382void CalendarView::checkClipboard() 3386void CalendarView::checkClipboard()
3383{ 3387{
3384#ifndef KORG_NODND 3388#ifndef KORG_NODND
3385 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3389 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3386 emit pasteEnabled(true); 3390 emit pasteEnabled(true);
3387 } else { 3391 } else {
3388 emit pasteEnabled(false); 3392 emit pasteEnabled(false);
3389 } 3393 }
3390#endif 3394#endif
3391} 3395}
3392 3396
3393void CalendarView::showDates(const DateList &selectedDates) 3397void CalendarView::showDates(const DateList &selectedDates)
3394{ 3398{
3395 // kdDebug() << "CalendarView::selectDates()" << endl; 3399 // kdDebug() << "CalendarView::selectDates()" << endl;
3396 3400
3397 if ( mViewManager->currentView() ) { 3401 if ( mViewManager->currentView() ) {
3398 updateView( selectedDates.first(), selectedDates.last() ); 3402 updateView( selectedDates.first(), selectedDates.last() );
3399 } else { 3403 } else {
3400 mViewManager->showAgendaView(); 3404 mViewManager->showAgendaView();
3401 } 3405 }
3402 3406
3403 QString selDates; 3407 QString selDates;
3404 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3408 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3405 if (selectedDates.first() < selectedDates.last() ) 3409 if (selectedDates.first() < selectedDates.last() )
3406 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3410 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3407 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3411 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3408 3412
3409} 3413}
3410 3414
3411QPtrList<CalFilter> CalendarView::filters() 3415QPtrList<CalFilter> CalendarView::filters()
3412{ 3416{
3413 return mFilters; 3417 return mFilters;
3414 3418
3415} 3419}
3416void CalendarView::editFilters() 3420void CalendarView::editFilters()
3417{ 3421{
3418 // kdDebug() << "CalendarView::editFilters()" << endl; 3422 // kdDebug() << "CalendarView::editFilters()" << endl;
3419 3423
3420 CalFilter *filter = mFilters.first(); 3424 CalFilter *filter = mFilters.first();
3421 while(filter) { 3425 while(filter) {
3422 kdDebug() << " Filter: " << filter->name() << endl; 3426 kdDebug() << " Filter: " << filter->name() << endl;
3423 filter = mFilters.next(); 3427 filter = mFilters.next();
3424 } 3428 }
3425 3429
3426 mDialogManager->showFilterEditDialog(&mFilters); 3430 mDialogManager->showFilterEditDialog(&mFilters);
3427} 3431}
3428void CalendarView::toggleFilter() 3432void CalendarView::toggleFilter()
3429{ 3433{
3430 showFilter(! mFilterView->isVisible()); 3434 showFilter(! mFilterView->isVisible());
3431} 3435}
3432 3436
3433KOFilterView *CalendarView::filterView() 3437KOFilterView *CalendarView::filterView()
3434{ 3438{
3435 return mFilterView; 3439 return mFilterView;
3436} 3440}
3437void CalendarView::selectFilter( int fil ) 3441void CalendarView::selectFilter( int fil )
3438{ 3442{
3439 mFilterView->setSelectedFilter( fil ); 3443 mFilterView->setSelectedFilter( fil );
3440} 3444}
3441void CalendarView::showFilter(bool visible) 3445void CalendarView::showFilter(bool visible)
3442{ 3446{
3443 if (visible) mFilterView->show(); 3447 if (visible) mFilterView->show();
3444 else mFilterView->hide(); 3448 else mFilterView->hide();
3445} 3449}
3446void CalendarView::toggleFilerEnabled( ) 3450void CalendarView::toggleFilerEnabled( )
3447{ 3451{
3448 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3452 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3449 if ( !mFilterView->filtersEnabled() ) 3453 if ( !mFilterView->filtersEnabled() )
3450 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3454 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3451 3455
3452} 3456}
3453void CalendarView::updateFilter() 3457void CalendarView::updateFilter()
3454{ 3458{
3455 CalFilter *filter = mFilterView->selectedFilter(); 3459 CalFilter *filter = mFilterView->selectedFilter();
3456 if (filter) { 3460 if (filter) {
3457 if (mFilterView->filtersEnabled()) { 3461 if (mFilterView->filtersEnabled()) {
3458 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3462 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3459 filter->setEnabled(true); 3463 filter->setEnabled(true);
3460 } 3464 }
3461 else filter->setEnabled(false); 3465 else filter->setEnabled(false);
3462 mCalendar->setFilter(filter); 3466 mCalendar->setFilter(filter);
3463 updateView(); 3467 updateView();
3464 } 3468 }
3465} 3469}
3466 3470
3467void CalendarView::filterEdited() 3471void CalendarView::filterEdited()
3468{ 3472{
3469 mFilterView->updateFilters(); 3473 mFilterView->updateFilters();
3470 updateFilter(); 3474 updateFilter();
3471 writeSettings(); 3475 writeSettings();
3472} 3476}
3473 3477
3474 3478
3475void CalendarView::takeOverEvent() 3479void CalendarView::takeOverEvent()
3476{ 3480{
3477 Incidence *incidence = currentSelection(); 3481 Incidence *incidence = currentSelection();
3478 3482
3479 if (!incidence) return; 3483 if (!incidence) return;
3480 3484
3481 incidence->setOrganizer(KOPrefs::instance()->email()); 3485 incidence->setOrganizer(KOPrefs::instance()->email());
3482 incidence->recreate(); 3486 incidence->recreate();
3483 incidence->setReadOnly(false); 3487 incidence->setReadOnly(false);
3484 3488
3485 updateView(); 3489 updateView();
3486} 3490}
3487 3491
3488void CalendarView::takeOverCalendar() 3492void CalendarView::takeOverCalendar()
3489{ 3493{
3490 // TODO: Create Calendar::allIncidences() function and use it here 3494 // TODO: Create Calendar::allIncidences() function and use it here
3491 3495
3492 QPtrList<Event> events = mCalendar->events(); 3496 QPtrList<Event> events = mCalendar->events();
3493 for(uint i=0; i<events.count(); ++i) { 3497 for(uint i=0; i<events.count(); ++i) {
3494 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3498 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3495 events.at(i)->recreate(); 3499 events.at(i)->recreate();
3496 events.at(i)->setReadOnly(false); 3500 events.at(i)->setReadOnly(false);
3497 } 3501 }
3498 3502
3499 QPtrList<Todo> todos = mCalendar->todos(); 3503 QPtrList<Todo> todos = mCalendar->todos();
3500 for(uint i=0; i<todos.count(); ++i) { 3504 for(uint i=0; i<todos.count(); ++i) {
3501 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3505 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3502 todos.at(i)->recreate(); 3506 todos.at(i)->recreate();
3503 todos.at(i)->setReadOnly(false); 3507 todos.at(i)->setReadOnly(false);
3504 } 3508 }
3505 3509
3506 QPtrList<Journal> journals = mCalendar->journals(); 3510 QPtrList<Journal> journals = mCalendar->journals();
3507 for(uint i=0; i<journals.count(); ++i) { 3511 for(uint i=0; i<journals.count(); ++i) {
3508 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3512 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3509 journals.at(i)->recreate(); 3513 journals.at(i)->recreate();
3510 journals.at(i)->setReadOnly(false); 3514 journals.at(i)->setReadOnly(false);
3511 } 3515 }
3512 3516
3513 updateView(); 3517 updateView();
3514} 3518}
3515 3519
3516void CalendarView::showIntro() 3520void CalendarView::showIntro()
3517{ 3521{
3518 kdDebug() << "To be implemented." << endl; 3522 kdDebug() << "To be implemented." << endl;
3519} 3523}
3520 3524
3521QWidgetStack *CalendarView::viewStack() 3525QWidgetStack *CalendarView::viewStack()
3522{ 3526{
3523 return mRightFrame; 3527 return mRightFrame;
3524} 3528}
3525 3529
3526QWidget *CalendarView::leftFrame() 3530QWidget *CalendarView::leftFrame()
3527{ 3531{
3528 return mLeftFrame; 3532 return mLeftFrame;
3529} 3533}
3530 3534
3531DateNavigator *CalendarView::dateNavigator() 3535DateNavigator *CalendarView::dateNavigator()
3532{ 3536{
3533 return mNavigator; 3537 return mNavigator;
3534} 3538}
3535 3539
3536KDateNavigator* CalendarView::dateNavigatorWidget() 3540KDateNavigator* CalendarView::dateNavigatorWidget()
3537{ 3541{
3538 return mDateNavigator; 3542 return mDateNavigator;
3539} 3543}
3540void CalendarView::toggleDateNavigatorWidget() 3544void CalendarView::toggleDateNavigatorWidget()
3541{ 3545{
3542 if (mDateNavigator->isVisible()) 3546 if (mDateNavigator->isVisible())
3543 mDateNavigator->hide(); 3547 mDateNavigator->hide();
3544 else 3548 else
3545 mDateNavigator->show(); 3549 mDateNavigator->show();
3546} 3550}
3547void CalendarView::addView(KOrg::BaseView *view) 3551void CalendarView::addView(KOrg::BaseView *view)
3548{ 3552{
3549 mViewManager->addView(view); 3553 mViewManager->addView(view);
3550} 3554}
3551 3555
3552void CalendarView::showView(KOrg::BaseView *view) 3556void CalendarView::showView(KOrg::BaseView *view)
3553{ 3557{
3554 mViewManager->showView(view, mLeftFrame->isVisible()); 3558 mViewManager->showView(view, mLeftFrame->isVisible());
3555} 3559}
3556 3560
3557Incidence *CalendarView::currentSelection() 3561Incidence *CalendarView::currentSelection()
3558{ 3562{
3559 return mViewManager->currentSelection(); 3563 return mViewManager->currentSelection();
3560} 3564}
3561void CalendarView::toggleAllDaySize() 3565void CalendarView::toggleAllDaySize()
3562{ 3566{
3563 /* 3567 /*
3564 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3568 if ( KOPrefs::instance()->mAllDaySize > 47 )
3565 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3569 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3566 else 3570 else
3567 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3571 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3568 */ 3572 */
3569 viewManager()->agendaView()->toggleAllDay(); 3573 viewManager()->agendaView()->toggleAllDay();
3570} 3574}
3571void CalendarView::toggleExpand() 3575void CalendarView::toggleExpand()
3572{ 3576{
3573 // if ( mLeftFrame->isHidden() ) { 3577 // if ( mLeftFrame->isHidden() ) {
3574 // mLeftFrame->show(); 3578 // mLeftFrame->show();
3575 // emit calendarViewExpanded( false ); 3579 // emit calendarViewExpanded( false );
3576 // } else { 3580 // } else {
3577 // mLeftFrame->hide(); 3581 // mLeftFrame->hide();
3578 // emit calendarViewExpanded( true ); 3582 // emit calendarViewExpanded( true );
3579 // } 3583 // }
3580 3584
3581 globalFlagBlockAgenda = 1; 3585 globalFlagBlockAgenda = 1;
3582 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3586 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3583 globalFlagBlockAgenda = 5; 3587 globalFlagBlockAgenda = 5;
3584 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3588 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3585 //mViewManager->showView( 0, true ); 3589 //mViewManager->showView( 0, true );
3586} 3590}
3587 3591
3588void CalendarView::calendarModified( bool modified, Calendar * ) 3592void CalendarView::calendarModified( bool modified, Calendar * )
3589{ 3593{
3590 setModified( modified ); 3594 setModified( modified );
3591} 3595}
3592 3596
3593Todo *CalendarView::selectedTodo() 3597Todo *CalendarView::selectedTodo()
3594{ 3598{
3595 Incidence *incidence = currentSelection(); 3599 Incidence *incidence = currentSelection();
3596 if ( incidence && incidence->type() == "Todo" ) { 3600 if ( incidence && incidence->type() == "Todo" ) {
3597 return static_cast<Todo *>( incidence ); 3601 return static_cast<Todo *>( incidence );
3598 } 3602 }
3599 3603
3600 incidence = mTodoList->selectedIncidences().first(); 3604 incidence = mTodoList->selectedIncidences().first();
3601 if ( incidence && incidence->type() == "Todo" ) { 3605 if ( incidence && incidence->type() == "Todo" ) {
3602 return static_cast<Todo *>( incidence ); 3606 return static_cast<Todo *>( incidence );
3603 } 3607 }
3604 3608
3605 return 0; 3609 return 0;
3606} 3610}
3607 3611
3608void CalendarView::dialogClosing(Incidence *in) 3612void CalendarView::dialogClosing(Incidence *in)
3609{ 3613{
3610 // mDialogList.remove(in); 3614 // mDialogList.remove(in);
3611} 3615}
3612 3616
3613void CalendarView::showIncidence() 3617void CalendarView::showIncidence()
3614{ 3618{
3615 Incidence *incidence = currentSelection(); 3619 Incidence *incidence = currentSelection();
3616 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3620 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3617 if ( incidence ) { 3621 if ( incidence ) {
3618 ShowIncidenceVisitor v; 3622 ShowIncidenceVisitor v;
3619 v.act( incidence, this ); 3623 v.act( incidence, this );
3620 } 3624 }
3621} 3625}
3622void CalendarView::editIncidenceDescription() 3626void CalendarView::editIncidenceDescription()
3623{ 3627{
3624 mFlagEditDescription = true; 3628 mFlagEditDescription = true;
3625 editIncidence(); 3629 editIncidence();
3626 mFlagEditDescription = false; 3630 mFlagEditDescription = false;
3627} 3631}
3628void CalendarView::editIncidence() 3632void CalendarView::editIncidence()
3629{ 3633{
3630 // qDebug("editIncidence() "); 3634 // qDebug("editIncidence() ");
3631 Incidence *incidence = currentSelection(); 3635 Incidence *incidence = currentSelection();
3632 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3636 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3633 if ( incidence ) { 3637 if ( incidence ) {
3634 EditIncidenceVisitor v; 3638 EditIncidenceVisitor v;
3635 v.act( incidence, this ); 3639 v.act( incidence, this );
3636 } 3640 }
3637} 3641}
3638 3642
3639void CalendarView::deleteIncidence() 3643void CalendarView::deleteIncidence()
3640{ 3644{
3641 Incidence *incidence = currentSelection(); 3645 Incidence *incidence = currentSelection();
3642 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3646 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3643 if ( incidence ) { 3647 if ( incidence ) {
3644 deleteIncidence(incidence); 3648 deleteIncidence(incidence);
3645 } 3649 }
3646} 3650}
3647 3651
3648void CalendarView::showIncidence(Incidence *incidence) 3652void CalendarView::showIncidence(Incidence *incidence)
3649{ 3653{
3650 if ( incidence ) { 3654 if ( incidence ) {
3651 ShowIncidenceVisitor v; 3655 ShowIncidenceVisitor v;
3652 v.act( incidence, this ); 3656 v.act( incidence, this );
3653 } 3657 }
3654} 3658}
3655 3659
3656void CalendarView::editIncidence(Incidence *incidence) 3660void CalendarView::editIncidence(Incidence *incidence)
3657{ 3661{
3658 if ( incidence ) { 3662 if ( incidence ) {
3659 3663
3660 EditIncidenceVisitor v; 3664 EditIncidenceVisitor v;
3661 v.act( incidence, this ); 3665 v.act( incidence, this );
3662 3666
3663 } 3667 }
3664} 3668}
3665 3669
3666void CalendarView::deleteIncidence(Incidence *incidence) 3670void CalendarView::deleteIncidence(Incidence *incidence)
3667{ 3671{
3668 //qDebug(" CalendarView::deleteIncidence "); 3672 //qDebug(" CalendarView::deleteIncidence ");
3669 if ( incidence ) { 3673 if ( incidence ) {
3670 DeleteIncidenceVisitor v; 3674 DeleteIncidenceVisitor v;
3671 v.act( incidence, this ); 3675 v.act( incidence, this );
3672 } 3676 }
3673} 3677}
3674 3678
3675 3679
3676void CalendarView::lookForOutgoingMessages() 3680void CalendarView::lookForOutgoingMessages()
3677{ 3681{
3678 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3682 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3679 ogd->loadMessages(); 3683 ogd->loadMessages();
3680} 3684}
3681 3685
3682void CalendarView::lookForIncomingMessages() 3686void CalendarView::lookForIncomingMessages()
3683{ 3687{
3684 IncomingDialog *icd = mDialogManager->incomingDialog(); 3688 IncomingDialog *icd = mDialogManager->incomingDialog();
3685 icd->retrieve(); 3689 icd->retrieve();
3686} 3690}
3687 3691
3688bool CalendarView::removeCompletedSubTodos( Todo* t ) 3692bool CalendarView::removeCompletedSubTodos( Todo* t )
3689{ 3693{
3690 bool deleteTodo = true; 3694 bool deleteTodo = true;
3691 QPtrList<Incidence> subTodos; 3695 QPtrList<Incidence> subTodos;
3692 Incidence *aTodo; 3696 Incidence *aTodo;
3693 subTodos = t->relations(); 3697 subTodos = t->relations();
3694 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3698 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3695 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3699 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3696 deleteTodo = false; 3700 deleteTodo = false;
3697 } 3701 }
3698 if ( deleteTodo ) { 3702 if ( deleteTodo ) {
3699 if ( t->isCompleted() ) { 3703 if ( t->isCompleted() ) {
3700 checkExternalId( t ); 3704 checkExternalId( t );
3701 mCalendar->deleteTodo( t ); 3705 mCalendar->deleteTodo( t );
3702 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3706 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3703 } 3707 }
3704 else 3708 else
3705 deleteTodo = false; 3709 deleteTodo = false;
3706 } 3710 }
3707 return deleteTodo; 3711 return deleteTodo;
3708 3712
3709} 3713}
3710void CalendarView::purgeCompleted() 3714void CalendarView::purgeCompleted()
3711{ 3715{
3712 int result = KMessageBox::warningContinueCancel(this, 3716 int result = KMessageBox::warningContinueCancel(this,
3713 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3717 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3714 3718
3715 if (result == KMessageBox::Continue) { 3719 if (result == KMessageBox::Continue) {
3716 3720
3717 QPtrList<Todo> todoCal; 3721 QPtrList<Todo> todoCal;
3718 QPtrList<Todo> rootTodos; 3722 QPtrList<Todo> rootTodos;
3719 //QPtrList<Incidence> rel; 3723 //QPtrList<Incidence> rel;
3720 Todo *aTodo;//, *rTodo; 3724 Todo *aTodo;//, *rTodo;
3721 Incidence *rIncidence; 3725 Incidence *rIncidence;
3722 bool childDelete = false; 3726 bool childDelete = false;
3723 bool deletedOne = true; 3727 bool deletedOne = true;
3724 todoCal = calendar()->todos(); 3728 todoCal = calendar()->todos();
3725 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3729 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3726 if ( !aTodo->relatedTo() ) 3730 if ( !aTodo->relatedTo() )
3727 rootTodos.append( aTodo ); 3731 rootTodos.append( aTodo );
3728 } 3732 }
3729 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3733 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3730 removeCompletedSubTodos( aTodo ); 3734 removeCompletedSubTodos( aTodo );
3731 } 3735 }
3732 3736
3733 updateView(); 3737 updateView();
3734 } 3738 }
3735} 3739}
3736 3740
3737void CalendarView::slotCalendarChanged() 3741void CalendarView::slotCalendarChanged()
3738{ 3742{
3739 ; 3743 ;
3740} 3744}
3741 3745
3742NavigatorBar *CalendarView::navigatorBar() 3746NavigatorBar *CalendarView::navigatorBar()
3743{ 3747{
3744 return mNavigatorBar; 3748 return mNavigatorBar;
3745} 3749}
3746 3750
3747 3751
3748 3752
3749void CalendarView::keyPressEvent ( QKeyEvent *e) 3753void CalendarView::keyPressEvent ( QKeyEvent *e)
3750{ 3754{
3751 //qDebug(" alendarView::keyPressEvent "); 3755 //qDebug(" alendarView::keyPressEvent ");
3752 e->ignore(); 3756 e->ignore();
3753} 3757}
3754 3758
3755 3759
3756bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 3760bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3757{ 3761{
3758 // mSyncManager = manager; 3762 // mSyncManager = manager;
3759 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 3763 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
3760 qDebug("SyncKDE request detected!"); 3764 qDebug("SyncKDE request detected!");
3761 } 3765 }
3762 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3766 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3763 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3767 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3764 return syncCalendar( filename, mode ); 3768 return syncCalendar( filename, mode );
3765} 3769}
3766bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 3770bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3767{ 3771{
3768 //mSyncManager = manager; 3772 //mSyncManager = manager;
3769 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 3773 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3770 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 3774 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3771 if ( resource == "sharp" ) 3775 if ( resource == "sharp" )
3772 syncExternal( 0 ); 3776 syncExternal( 0 );
3773 if ( resource == "phone" ) 3777 if ( resource == "phone" )
3774 syncExternal( 1 ); 3778 syncExternal( 1 );
3775 // pending setmodified 3779 // pending setmodified
3776 return true; 3780 return true;
3777} 3781}
3778void CalendarView::setSyncManager(KSyncManager* manager) 3782void CalendarView::setSyncManager(KSyncManager* manager)
3779{ 3783{
3780 mSyncManager = manager; 3784 mSyncManager = manager;
3781} 3785}
3782 3786
3783void CalendarView::removeSyncInfo( QString syncProfile) 3787void CalendarView::removeSyncInfo( QString syncProfile)
3784{ 3788{
3785 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1()); 3789 qDebug("removeSyncInfo for profile %s ", syncProfile.latin1());
3786 mCalendar->removeSyncInfo( syncProfile ); 3790 mCalendar->removeSyncInfo( syncProfile );
3787 3791
3788} 3792}
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index a12acd1..9cafc60 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1118 +1,1119 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27 27
28#include <qvbox.h> 28#include <qvbox.h>
29#include <kdebug.h> 29#include <kdebug.h>
30#include "koprefs.h" 30#include "koprefs.h"
31#include <klocale.h> 31#include <klocale.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/vcaldrag.h> 37#include <libkcal/vcaldrag.h>
38#include <libkcal/calfilter.h> 38#include <libkcal/calfilter.h>
39#include <libkcal/dndfactory.h> 39#include <libkcal/dndfactory.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42#include <kresources/resourceselectdialog.h> 42#include <kresources/resourceselectdialog.h>
43#ifndef DESKTOP_VERSION 43#ifndef DESKTOP_VERSION
44#include <qpe/qpeapplication.h> 44#include <qpe/qpeapplication.h>
45#else 45#else
46#include <qapplication.h> 46#include <qapplication.h>
47#endif 47#endif
48#ifndef KORG_NOPRINTER 48#ifndef KORG_NOPRINTER
49#include "calprinter.h" 49#include "calprinter.h"
50#endif 50#endif
51#include "docprefs.h" 51#include "docprefs.h"
52 52
53#include "kotodoview.h" 53#include "kotodoview.h"
54using namespace KOrg; 54using namespace KOrg;
55 55
56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
57 const char *name) : 57 const char *name) :
58 KListView(parent,name) 58 KListView(parent,name)
59{ 59{
60 mName = QString ( name ); 60 mName = QString ( name );
61 mCalendar = calendar; 61 mCalendar = calendar;
62#ifndef DESKTOP_VERSION 62#ifndef DESKTOP_VERSION
63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
64#endif 64#endif
65 mOldCurrent = 0; 65 mOldCurrent = 0;
66 mMousePressed = false; 66 mMousePressed = false;
67 67
68 setAcceptDrops(true); 68 setAcceptDrops(true);
69 viewport()->setAcceptDrops(true); 69 viewport()->setAcceptDrops(true);
70 int size = 16; 70 int size = 16;
71 if (qApp->desktop()->width() < 300 ) 71 if (qApp->desktop()->width() < 300 )
72 size = 12; 72 size = 12;
73 setTreeStepSize( size + 6 ); 73 setTreeStepSize( size + 6 );
74 74
75} 75}
76 76
77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
78{ 78{
79#ifndef KORG_NODND 79#ifndef KORG_NODND
80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
82 !QTextDrag::canDecode( e ) ) { 82 !QTextDrag::canDecode( e ) ) {
83 e->ignore(); 83 e->ignore();
84 return; 84 return;
85 } 85 }
86 86
87 mOldCurrent = currentItem(); 87 mOldCurrent = currentItem();
88#endif 88#endif
89} 89}
90 90
91 91
92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
93{ 93{
94#ifndef KORG_NODND 94#ifndef KORG_NODND
95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
96 96
97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
98 !QTextDrag::canDecode( e ) ) { 98 !QTextDrag::canDecode( e ) ) {
99 e->ignore(); 99 e->ignore();
100 return; 100 return;
101 } 101 }
102 102
103 e->accept(); 103 e->accept();
104#endif 104#endif
105} 105}
106 106
107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
108{ 108{
109#ifndef KORG_NODND 109#ifndef KORG_NODND
110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
111 111
112 setCurrentItem(mOldCurrent); 112 setCurrentItem(mOldCurrent);
113 setSelected(mOldCurrent,true); 113 setSelected(mOldCurrent,true);
114#endif 114#endif
115} 115}
116 116
117void KOTodoListView::contentsDropEvent(QDropEvent *e) 117void KOTodoListView::contentsDropEvent(QDropEvent *e)
118{ 118{
119#ifndef KORG_NODND 119#ifndef KORG_NODND
120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
121 121
122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
123 !QTextDrag::canDecode( e ) ) { 123 !QTextDrag::canDecode( e ) ) {
124 e->ignore(); 124 e->ignore();
125 return; 125 return;
126 } 126 }
127 127
128 DndFactory factory( mCalendar ); 128 DndFactory factory( mCalendar );
129 Todo *todo = factory.createDropTodo(e); 129 Todo *todo = factory.createDropTodo(e);
130 130
131 if (todo) { 131 if (todo) {
132 e->acceptAction(); 132 e->acceptAction();
133 133
134 KOTodoViewItem *destination = 134 KOTodoViewItem *destination =
135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
136 Todo *destinationEvent = 0; 136 Todo *destinationEvent = 0;
137 if (destination) destinationEvent = destination->todo(); 137 if (destination) destinationEvent = destination->todo();
138 138
139 Todo *existingTodo = mCalendar->todo(todo->uid()); 139 Todo *existingTodo = mCalendar->todo(todo->uid());
140 140
141 if(existingTodo) { 141 if(existingTodo) {
142// kdDebug() << "Drop existing Todo" << endl; 142// kdDebug() << "Drop existing Todo" << endl;
143 Incidence *to = destinationEvent; 143 Incidence *to = destinationEvent;
144 while(to) { 144 while(to) {
145 if (to->uid() == todo->uid()) { 145 if (to->uid() == todo->uid()) {
146 KMessageBox::sorry(this, 146 KMessageBox::sorry(this,
147 i18n("Cannot move To-Do to itself or a child of itself"), 147 i18n("Cannot move To-Do to itself or a child of itself"),
148 i18n("Drop To-Do")); 148 i18n("Drop To-Do"));
149 delete todo; 149 delete todo;
150 return; 150 return;
151 } 151 }
152 to = to->relatedTo(); 152 to = to->relatedTo();
153 } 153 }
154 existingTodo->setRelatedTo(destinationEvent); 154 existingTodo->setRelatedTo(destinationEvent);
155 emit todoDropped(todo); 155 emit todoDropped(todo);
156 delete todo; 156 delete todo;
157 } else { 157 } else {
158// kdDebug() << "Drop new Todo" << endl; 158// kdDebug() << "Drop new Todo" << endl;
159 todo->setRelatedTo(destinationEvent); 159 todo->setRelatedTo(destinationEvent);
160 mCalendar->addTodo(todo); 160 mCalendar->addTodo(todo);
161 161
162 emit todoDropped(todo); 162 emit todoDropped(todo);
163 } 163 }
164 } 164 }
165 else { 165 else {
166 QString text; 166 QString text;
167 if (QTextDrag::decode(e,text)) { 167 if (QTextDrag::decode(e,text)) {
168 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 168 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
169 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 169 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
170 kdDebug() << "Dropped : " << text << endl; 170 kdDebug() << "Dropped : " << text << endl;
171 QStringList emails = QStringList::split(",",text); 171 QStringList emails = QStringList::split(",",text);
172 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 172 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
173 kdDebug() << " Email: " << (*it) << endl; 173 kdDebug() << " Email: " << (*it) << endl;
174 int pos = (*it).find("<"); 174 int pos = (*it).find("<");
175 QString name = (*it).left(pos); 175 QString name = (*it).left(pos);
176 QString email = (*it).mid(pos); 176 QString email = (*it).mid(pos);
177 if (!email.isEmpty() && todoi) { 177 if (!email.isEmpty() && todoi) {
178 todoi->todo()->addAttendee(new Attendee(name,email)); 178 todoi->todo()->addAttendee(new Attendee(name,email));
179 } 179 }
180 } 180 }
181 } 181 }
182 else { 182 else {
183 kdDebug() << "KOTodoListView::contentsDropEvent(): Todo from drop not decodable" << endl; 183 kdDebug() << "KOTodoListView::contentsDropEvent(): Todo from drop not decodable" << endl;
184 e->ignore(); 184 e->ignore();
185 } 185 }
186 } 186 }
187#endif 187#endif
188} 188}
189 189
190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
191{ 191{
192 QListView::contentsMousePressEvent(e); 192 QListView::contentsMousePressEvent(e);
193#ifndef KORG_NODND 193#ifndef KORG_NODND
194 QPoint p(contentsToViewport(e->pos())); 194 QPoint p(contentsToViewport(e->pos()));
195 QListViewItem *i = itemAt(p); 195 QListViewItem *i = itemAt(p);
196 if (i) { 196 if (i) {
197 // if the user clicked into the root decoration of the item, don't 197 // if the user clicked into the root decoration of the item, don't
198 // try to start a drag! 198 // try to start a drag!
199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
201 itemMargin() || 201 itemMargin() ||
202 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 202 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
203 if (e->button()==Qt::LeftButton) { 203 if (e->button()==Qt::LeftButton) {
204 mPressPos = e->pos(); 204 mPressPos = e->pos();
205 mMousePressed = true; 205 mMousePressed = true;
206 } 206 }
207 } 207 }
208 } 208 }
209#endif 209#endif
210} 210}
211 211
212void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 212void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
213{ 213{
214 214
215#ifndef KORG_NODND 215#ifndef KORG_NODND
216// kdDebug() << "KOTodoListView::contentsMouseMoveEvent()" << endl; 216// kdDebug() << "KOTodoListView::contentsMouseMoveEvent()" << endl;
217 QListView::contentsMouseMoveEvent(e); 217 QListView::contentsMouseMoveEvent(e);
218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
219 QApplication::startDragDistance()) { 219 QApplication::startDragDistance()) {
220 mMousePressed = false; 220 mMousePressed = false;
221 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 221 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
222 if (item) { 222 if (item) {
223// kdDebug() << "Start Drag for item " << item->text(0) << endl; 223// kdDebug() << "Start Drag for item " << item->text(0) << endl;
224 DndFactory factory( mCalendar ); 224 DndFactory factory( mCalendar );
225 ICalDrag *vd = factory.createDragTodo( 225 ICalDrag *vd = factory.createDragTodo(
226 ((KOTodoViewItem *)item)->todo(),viewport()); 226 ((KOTodoViewItem *)item)->todo(),viewport());
227 if (vd->drag()) { 227 if (vd->drag()) {
228 kdDebug() << "KOTodoListView::contentsMouseMoveEvent(): Delete drag source" << endl; 228 kdDebug() << "KOTodoListView::contentsMouseMoveEvent(): Delete drag source" << endl;
229 } 229 }
230/* 230/*
231 QString source = fullPath(item); 231 QString source = fullPath(item);
232 if ( QFile::exists(source) ) { 232 if ( QFile::exists(source) ) {
233 QUriDrag* ud = new QUriDrag(viewport()); 233 QUriDrag* ud = new QUriDrag(viewport());
234 ud->setFilenames( source ); 234 ud->setFilenames( source );
235 if ( ud->drag() ) 235 if ( ud->drag() )
236 QMessageBox::information( this, "Drag source", 236 QMessageBox::information( this, "Drag source",
237 QString("Delete ")+source, "Not implemented" ); 237 QString("Delete ")+source, "Not implemented" );
238*/ 238*/
239 } 239 }
240 } 240 }
241#endif 241#endif
242} 242}
243void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 243void KOTodoListView::keyPressEvent ( QKeyEvent * e )
244{ 244{
245 245
246 QListViewItem* cn; 246 QListViewItem* cn;
247 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 247 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
248 cn = currentItem(); 248 cn = currentItem();
249 if ( cn ) { 249 if ( cn ) {
250 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 250 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
251 if ( ci ){ 251 if ( ci ){
252 if ( e->state() == ShiftButton ) 252 if ( e->state() == ShiftButton )
253 ci->setOn( false ); 253 ci->setOn( false );
254 else 254 else
255 ci->setOn( true ); 255 ci->setOn( true );
256 cn = cn->nextSibling(); 256 cn = cn->nextSibling();
257 if ( cn ) { 257 if ( cn ) {
258 setCurrentItem ( cn ); 258 setCurrentItem ( cn );
259 ensureItemVisible ( cn ); 259 ensureItemVisible ( cn );
260 } 260 }
261 261
262 } 262 }
263 } 263 }
264 264
265 return; 265 return;
266 } 266 }
267 267
268 // qDebug("KOTodoListView::keyPressEvent "); 268 // qDebug("KOTodoListView::keyPressEvent ");
269 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 269 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
270 switch ( e->key() ) { 270 switch ( e->key() ) {
271 case Qt::Key_Down: 271 case Qt::Key_Down:
272 case Qt::Key_Up: 272 case Qt::Key_Up:
273 QListView::keyPressEvent ( e ); 273 QListView::keyPressEvent ( e );
274 break; 274 break;
275 case Qt::Key_Left: 275 case Qt::Key_Left:
276 case Qt::Key_Right: 276 case Qt::Key_Right:
277 QListView::keyPressEvent ( e ); 277 QListView::keyPressEvent ( e );
278 e->accept(); 278 e->accept();
279 return; 279 return;
280 break; 280 break;
281 default: 281 default:
282 e->ignore(); 282 e->ignore();
283 break; 283 break;
284 } 284 }
285 return; 285 return;
286 } 286 }
287 e->ignore(); 287 e->ignore();
288} 288}
289void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 289void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
290{ 290{
291 QListView::contentsMouseReleaseEvent(e); 291 QListView::contentsMouseReleaseEvent(e);
292 mMousePressed = false; 292 mMousePressed = false;
293} 293}
294 294
295void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 295void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
296{ 296{
297 if (!e) return; 297 if (!e) return;
298 298
299 QPoint vp = contentsToViewport(e->pos()); 299 QPoint vp = contentsToViewport(e->pos());
300 300
301 QListViewItem *item = itemAt(vp); 301 QListViewItem *item = itemAt(vp);
302 302
303 emit double_Clicked(item); 303 emit double_Clicked(item);
304 if (!item) return; 304 if (!item) return;
305 305
306 emit doubleClicked(item,vp,0); 306 emit doubleClicked(item,vp,0);
307} 307}
308 308
309///////////////////////////////////////////////////////////////////////////// 309/////////////////////////////////////////////////////////////////////////////
310 310
311KOQuickTodo::KOQuickTodo(QWidget *parent) : 311KOQuickTodo::KOQuickTodo(QWidget *parent) :
312 QLineEdit(parent) 312 QLineEdit(parent)
313{ 313{
314 setText(i18n("Click to add a new Todo")); 314 setText(i18n("Click to add a new Todo"));
315} 315}
316 316
317void KOQuickTodo::focusInEvent(QFocusEvent *ev) 317void KOQuickTodo::focusInEvent(QFocusEvent *ev)
318{ 318{
319 if ( text()==i18n("Click to add a new Todo") ) 319 if ( text()==i18n("Click to add a new Todo") )
320 setText(""); 320 setText("");
321 QLineEdit::focusInEvent(ev); 321 QLineEdit::focusInEvent(ev);
322} 322}
323 323
324void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 324void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
325{ 325{
326 setText(i18n("Click to add a new Todo")); 326 setText(i18n("Click to add a new Todo"));
327 QLineEdit::focusOutEvent(ev); 327 QLineEdit::focusOutEvent(ev);
328} 328}
329 329
330///////////////////////////////////////////////////////////////////////////// 330/////////////////////////////////////////////////////////////////////////////
331 331
332KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 332KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
333 KOrg::BaseView(calendar,parent,name) 333 KOrg::BaseView(calendar,parent,name)
334{ 334{
335 QBoxLayout *topLayout = new QVBoxLayout(this); 335 QBoxLayout *topLayout = new QVBoxLayout(this);
336 mName = QString ( name ); 336 mName = QString ( name );
337 mBlockUpdate = false; 337 mBlockUpdate = false;
338 mQuickAdd = new KOQuickTodo(this); 338 mQuickAdd = new KOQuickTodo(this);
339 topLayout->addWidget(mQuickAdd); 339 topLayout->addWidget(mQuickAdd);
340 340
341 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 341 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
342 342
343 mTodoListView = new KOTodoListView(calendar,this, name ); 343 mTodoListView = new KOTodoListView(calendar,this, name );
344 topLayout->addWidget(mTodoListView); 344 topLayout->addWidget(mTodoListView);
345 //mTodoListView->header()->setMaximumHeight(30); 345 //mTodoListView->header()->setMaximumHeight(30);
346 mTodoListView->setRootIsDecorated(true); 346 mTodoListView->setRootIsDecorated(true);
347 mTodoListView->setAllColumnsShowFocus(true); 347 mTodoListView->setAllColumnsShowFocus(true);
348 348
349 mTodoListView->setShowSortIndicator(true); 349 mTodoListView->setShowSortIndicator(true);
350 350
351 mTodoListView->addColumn(i18n("Todo")); 351 mTodoListView->addColumn(i18n("Todo"));
352 mTodoListView->addColumn(i18n("Prio")); 352 mTodoListView->addColumn(i18n("Prio"));
353 mTodoListView->setColumnAlignment(1,AlignHCenter); 353 mTodoListView->setColumnAlignment(1,AlignHCenter);
354 mTodoListView->addColumn(i18n("Complete")); 354 mTodoListView->addColumn(i18n("Complete"));
355 mTodoListView->setColumnAlignment(2,AlignHCenter); 355 mTodoListView->setColumnAlignment(2,AlignHCenter);
356 mTodoListView->addColumn(i18n("Due Date")); 356 mTodoListView->addColumn(i18n("Due Date"));
357 mTodoListView->setColumnAlignment(3,AlignLeft); 357 mTodoListView->setColumnAlignment(3,AlignLeft);
358 mTodoListView->addColumn(i18n("Due Time")); 358 mTodoListView->addColumn(i18n("Due Time"));
359 mTodoListView->setColumnAlignment(4,AlignHCenter); 359 mTodoListView->setColumnAlignment(4,AlignHCenter);
360 mTodoListView->addColumn(i18n("Cancelled")); 360 mTodoListView->addColumn(i18n("Cancelled"));
361 mTodoListView->addColumn(i18n("Categories")); 361 mTodoListView->addColumn(i18n("Categories"));
362#if 0 362#if 0
363 mTodoListView->addColumn(i18n("Sort Id")); 363 mTodoListView->addColumn(i18n("Sort Id"));
364 mTodoListView->setColumnAlignment(4,AlignHCenter); 364 mTodoListView->setColumnAlignment(4,AlignHCenter);
365#endif 365#endif
366 366
367 mTodoListView->setMinimumHeight( 60 ); 367 mTodoListView->setMinimumHeight( 60 );
368 mTodoListView->setItemsRenameable( true ); 368 mTodoListView->setItemsRenameable( true );
369 mTodoListView->setRenameable( 0 ); 369 mTodoListView->setRenameable( 0 );
370 mTodoListView->setColumnWidth( 0, 120 ); 370 mTodoListView->setColumnWidth( 0, 120 );
371 mTodoListView->setColumnWidthMode(0, QListView::Manual); 371 mTodoListView->setColumnWidthMode(0, QListView::Manual);
372 mTodoListView->setColumnWidthMode(1, QListView::Manual); 372 mTodoListView->setColumnWidthMode(1, QListView::Manual);
373 mTodoListView->setColumnWidthMode(2, QListView::Manual); 373 mTodoListView->setColumnWidthMode(2, QListView::Manual);
374 mTodoListView->setColumnWidthMode(3, QListView::Manual); 374 mTodoListView->setColumnWidthMode(3, QListView::Manual);
375 mTodoListView->setColumnWidthMode(4, QListView::Manual); 375 mTodoListView->setColumnWidthMode(4, QListView::Manual);
376 mTodoListView->setColumnWidthMode(5, QListView::Manual); 376 mTodoListView->setColumnWidthMode(5, QListView::Manual);
377 mTodoListView->setColumnWidthMode(6, QListView::Manual);
377 mTodoListView->setColumnAlignment( 2, AlignCenter ); 378 mTodoListView->setColumnAlignment( 2, AlignCenter );
378#if 0 379#if 0
379 mTodoListView->setColumnWidthMode(6, QListView::Manual); 380 mTodoListView->setColumnWidthMode(6, QListView::Manual);
380#endif 381#endif
381 382
382 mPriorityPopupMenu = new QPopupMenu(this); 383 mPriorityPopupMenu = new QPopupMenu(this);
383 for (int i = 1; i <= 5; i++) { 384 for (int i = 1; i <= 5; i++) {
384 QString label = QString ("%1").arg (i); 385 QString label = QString ("%1").arg (i);
385 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 386 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
386 } 387 }
387 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 388 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
388 389
389 mPercentageCompletedPopupMenu = new QPopupMenu(this); 390 mPercentageCompletedPopupMenu = new QPopupMenu(this);
390 for (int i = 0; i <= 100; i+=20) { 391 for (int i = 0; i <= 100; i+=20) {
391 QString label = QString ("%1 %").arg (i); 392 QString label = QString ("%1 %").arg (i);
392 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 393 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
393 } 394 }
394 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 395 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
395 396
396 397
397 398
398 mItemPopupMenu = new QPopupMenu(this); 399 mItemPopupMenu = new QPopupMenu(this);
399 mItemPopupMenu->insertItem(i18n("Show..."), this, 400 mItemPopupMenu->insertItem(i18n("Show..."), this,
400 SLOT (showTodo())); 401 SLOT (showTodo()));
401 mItemPopupMenu->insertItem(i18n("Edit..."), this, 402 mItemPopupMenu->insertItem(i18n("Edit..."), this,
402 SLOT (editTodo())); 403 SLOT (editTodo()));
403 mItemPopupMenu->insertItem( i18n("Delete"), this, 404 mItemPopupMenu->insertItem( i18n("Delete"), this,
404 SLOT (deleteTodo())); 405 SLOT (deleteTodo()));
405 mItemPopupMenu->insertItem( i18n("Clone..."), this, 406 mItemPopupMenu->insertItem( i18n("Clone..."), this,
406 SLOT (cloneTodo())); 407 SLOT (cloneTodo()));
407 mItemPopupMenu->insertItem( i18n("Move..."), this, 408 mItemPopupMenu->insertItem( i18n("Move..."), this,
408 SLOT (moveTodo())); 409 SLOT (moveTodo()));
409 mItemPopupMenu->insertItem( i18n("Beam..."), this, 410 mItemPopupMenu->insertItem( i18n("Beam..."), this,
410 SLOT (beamTodo())); 411 SLOT (beamTodo()));
411 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 412 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
412 SLOT (cancelTodo())); 413 SLOT (cancelTodo()));
413 mItemPopupMenu->insertSeparator(); 414 mItemPopupMenu->insertSeparator();
414 415
415 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 416 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
416 SLOT (newTodo())); 417 SLOT (newTodo()));
417 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 418 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
418 SLOT (newSubTodo())); 419 SLOT (newSubTodo()));
419 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 420 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
420 SLOT (unparentTodo()),0,21); 421 SLOT (unparentTodo()),0,21);
421 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 422 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
422 SLOT (reparentTodo()),0,22); 423 SLOT (reparentTodo()),0,22);
423 mItemPopupMenu->insertSeparator(); 424 mItemPopupMenu->insertSeparator();
424 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 425 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
425 this, SLOT( purgeCompleted() ) ); 426 this, SLOT( purgeCompleted() ) );
426 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 427 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
427 this, SLOT( toggleCompleted() ),0, 33 ); 428 this, SLOT( toggleCompleted() ),0, 33 );
428 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 429 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
429 this, SLOT( toggleQuickTodo() ),0, 34 ); 430 this, SLOT( toggleQuickTodo() ),0, 34 );
430 431
431 mPopupMenu = new QPopupMenu(this); 432 mPopupMenu = new QPopupMenu(this);
432 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 433 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
433 SLOT (newTodo()),0,1); 434 SLOT (newTodo()),0,1);
434 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 435 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
435 this, SLOT(purgeCompleted()),0,2); 436 this, SLOT(purgeCompleted()),0,2);
436 mPopupMenu->insertItem(i18n("Show Completed"), 437 mPopupMenu->insertItem(i18n("Show Completed"),
437 this, SLOT( toggleCompleted() ),0,3 ); 438 this, SLOT( toggleCompleted() ),0,3 );
438 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 439 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
439 this, SLOT( toggleQuickTodo() ),0,4 ); 440 this, SLOT( toggleQuickTodo() ),0,4 );
440 mDocPrefs = new DocPrefs( name ); 441 mDocPrefs = new DocPrefs( name );
441 442
442 mPopupMenu->setCheckable( true ); 443 mPopupMenu->setCheckable( true );
443 mItemPopupMenu->setCheckable( true ); 444 mItemPopupMenu->setCheckable( true );
444 // Double clicking conflicts with opening/closing the subtree 445 // Double clicking conflicts with opening/closing the subtree
445 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 446 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
446 SLOT( editItem( QListViewItem *) ) ); 447 SLOT( editItem( QListViewItem *) ) );
447 /* 448 /*
448 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 449 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
449 const QPoint &,int ) ), 450 const QPoint &,int ) ),
450 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 451 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
451 */ 452 */
452 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 453 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
453 const QPoint &,int ) ), 454 const QPoint &,int ) ),
454 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 455 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
455 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 456 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
456 SLOT( itemClicked( QListViewItem * ) ) ); 457 SLOT( itemClicked( QListViewItem * ) ) );
457 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 458 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
458 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 459 SLOT( itemDoubleClicked( QListViewItem * ) ) );
459 connect( mTodoListView, SIGNAL( todoDropped( Todo * ) ), 460 connect( mTodoListView, SIGNAL( todoDropped( Todo * ) ),
460 SLOT( updateView() ) ); 461 SLOT( updateView() ) );
461 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 462 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
462 SLOT( itemStateChanged( QListViewItem * ) ) ); 463 SLOT( itemStateChanged( QListViewItem * ) ) );
463 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 464 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
464 SLOT( itemStateChanged( QListViewItem * ) ) ); 465 SLOT( itemStateChanged( QListViewItem * ) ) );
465 466
466#if 0 467#if 0
467 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 468 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
468 SLOT(selectionChanged(QListViewItem *))); 469 SLOT(selectionChanged(QListViewItem *)));
469 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 470 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
470 SLOT(selectionChanged(QListViewItem *))); 471 SLOT(selectionChanged(QListViewItem *)));
471 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 472 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
472 SLOT(selectionChanged(QListViewItem *))); 473 SLOT(selectionChanged(QListViewItem *)));
473#endif 474#endif
474 connect( mTodoListView, SIGNAL(selectionChanged() ), 475 connect( mTodoListView, SIGNAL(selectionChanged() ),
475 SLOT( processSelectionChange() ) ); 476 SLOT( processSelectionChange() ) );
476 connect( mQuickAdd, SIGNAL( returnPressed () ), 477 connect( mQuickAdd, SIGNAL( returnPressed () ),
477 SLOT( addQuickTodo() ) ); 478 SLOT( addQuickTodo() ) );
478// if ( QApplication::desktop()->width() < 480 ) { 479// if ( QApplication::desktop()->width() < 480 ) {
479// setNarrow(); 480// setNarrow();
480 // mTodoListView->setColumnWidth( 0, 100 ); 481 // mTodoListView->setColumnWidth( 0, 100 );
481 482
482 // } 483 // }
483 484
484} 485}
485 486
486KOTodoView::~KOTodoView() 487KOTodoView::~KOTodoView()
487{ 488{
488 delete mDocPrefs; 489 delete mDocPrefs;
489} 490}
490 491
491void KOTodoView::jumpToDate () 492void KOTodoView::jumpToDate ()
492{ 493{
493 // if (mActiveItem) { 494 // if (mActiveItem) {
494// mActiveItem->todo()); 495// mActiveItem->todo());
495// if ( mActiveItem->todo()->hasDueDate() ) 496// if ( mActiveItem->todo()->hasDueDate() )
496// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 497// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
497} 498}
498 499
499void KOTodoView::setNarrow() 500void KOTodoView::setNarrow()
500{ 501{
501 //mTodoListView->setColumnWidth( 0, 120 ); 502 //mTodoListView->setColumnWidth( 0, 120 );
502 mTodoListView->setColumnWidth( 1, 35 ); 503 mTodoListView->setColumnWidth( 1, 35 );
503 mTodoListView->setColumnWidth( 2, 40 ); 504 mTodoListView->setColumnWidth( 2, 40 );
504 mTodoListView->setColumnWidth( 3, 80 ); 505 mTodoListView->setColumnWidth( 3, 80 );
505 mTodoListView->setColumnWidth( 4, 40 ); 506 mTodoListView->setColumnWidth( 4, 40 );
506 mTodoListView->setColumnWidth( 5, 90 ); 507 mTodoListView->setColumnWidth( 5, 90 );
507 508
508} 509}
509void KOTodoView::updateView() 510void KOTodoView::updateView()
510{ 511{
511 pendingSubtodo = 0; 512 pendingSubtodo = 0;
512 if ( mBlockUpdate ) { 513 if ( mBlockUpdate ) {
513 //qDebug("blocked "); 514 //qDebug("blocked ");
514 return; 515 return;
515 } 516 }
516 //qDebug("update "); 517 //qDebug("update ");
517// kdDebug() << "KOTodoView::updateView()" << endl; 518// kdDebug() << "KOTodoView::updateView()" << endl;
518 QFont fo = KOPrefs::instance()->mTodoViewFont; 519 QFont fo = KOPrefs::instance()->mTodoViewFont;
519 mTodoListView->clear(); 520 mTodoListView->clear();
520 if ( mName == "todolistsmall" ) { 521 if ( mName == "todolistsmall" ) {
521 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 522 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
522 int ps = fo.pointSize() -2; 523 int ps = fo.pointSize() -2;
523 if ( ps > 12 ) 524 if ( ps > 12 )
524 ps -= 2; 525 ps -= 2;
525 fo.setPointSize( ps ); 526 fo.setPointSize( ps );
526 } 527 }
527 } 528 }
528 529
529 mTodoListView->setFont( fo ); 530 mTodoListView->setFont( fo );
530 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 531 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
531 //mTodoListView->header()->setMaximumHeight(fm.height()); 532 //mTodoListView->header()->setMaximumHeight(fm.height());
532 QPtrList<Todo> todoList = calendar()->todos(); 533 QPtrList<Todo> todoList = calendar()->todos();
533 534
534/* 535/*
535 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 536 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
536 Event *t; 537 Event *t;
537 for(t = todoList.first(); t; t = todoList.next()) { 538 for(t = todoList.first(); t; t = todoList.next()) {
538 kdDebug() << " " << t->getSummary() << endl; 539 kdDebug() << " " << t->getSummary() << endl;
539 540
540 if (t->getRelatedTo()) { 541 if (t->getRelatedTo()) {
541 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 542 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
542 } 543 }
543 544
544 QPtrList<Event> l = t->getRelations(); 545 QPtrList<Event> l = t->getRelations();
545 Event *c; 546 Event *c;
546 for(c=l.first();c;c=l.next()) { 547 for(c=l.first();c;c=l.next()) {
547 kdDebug() << " - relation: " << c->getSummary() << endl; 548 kdDebug() << " - relation: " << c->getSummary() << endl;
548 } 549 }
549 } 550 }
550*/ 551*/
551 552
552 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 553 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
553 // specific order of events. That means that we have to generate parent items 554 // specific order of events. That means that we have to generate parent items
554 // recursively for proper hierarchical display of Todos. 555 // recursively for proper hierarchical display of Todos.
555 mTodoMap.clear(); 556 mTodoMap.clear();
556 Todo *todo; 557 Todo *todo;
557 todo = todoList.first();// todo; todo = todoList.next()) { 558 todo = todoList.first();// todo; todo = todoList.next()) {
558 while ( todo ) { 559 while ( todo ) {
559 bool next = true; 560 bool next = true;
560 // qDebug("todo %s ", todo->summary().latin1()); 561 // qDebug("todo %s ", todo->summary().latin1());
561 Incidence *incidence = todo->relatedTo(); 562 Incidence *incidence = todo->relatedTo();
562 while ( incidence ) { 563 while ( incidence ) {
563 if ( incidence->type() == "Todo") { 564 if ( incidence->type() == "Todo") {
564 //qDebug("related %s ",incidence->summary().latin1() ); 565 //qDebug("related %s ",incidence->summary().latin1() );
565 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 566 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
566 //qDebug("related not found "); 567 //qDebug("related not found ");
567 todoList.remove( ); 568 todoList.remove( );
568 todo = todoList.current(); 569 todo = todoList.current();
569 next = false; 570 next = false;
570 incidence = 0; 571 incidence = 0;
571 572
572 } else { 573 } else {
573 //qDebug("related found "); 574 //qDebug("related found ");
574 incidence = incidence->relatedTo(); 575 incidence = incidence->relatedTo();
575 } 576 }
576 } else 577 } else
577 incidence = 0; 578 incidence = 0;
578 } 579 }
579 if ( next ) 580 if ( next )
580 todo = todoList.next(); 581 todo = todoList.next();
581 } 582 }
582// qDebug("again .... "); 583// qDebug("again .... ");
583// for(todo = todoList.first(); todo; todo = todoList.next()) { 584// for(todo = todoList.first(); todo; todo = todoList.next()) {
584 585
585// qDebug("yytodo %s ", todo->summary().latin1()); 586// qDebug("yytodo %s ", todo->summary().latin1());
586// } 587// }
587 //qDebug("for "); 588 //qDebug("for ");
588 for(todo = todoList.first(); todo; todo = todoList.next()) { 589 for(todo = todoList.first(); todo; todo = todoList.next()) {
589 if (!mTodoMap.contains(todo) && ( KOPrefs::instance()->mShowCompletedTodo || !todo->isCompleted() ) ) 590 if (!mTodoMap.contains(todo) && ( KOPrefs::instance()->mShowCompletedTodo || !todo->isCompleted() ) )
590 { 591 {
591 insertTodoItem(todo); 592 insertTodoItem(todo);
592 } 593 }
593 } 594 }
594 //qDebug("for end "); 595 //qDebug("for end ");
595 // Restore opened/closed state 596 // Restore opened/closed state
596 mTodoListView->blockSignals( true ); 597 mTodoListView->blockSignals( true );
597 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 598 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
598 mTodoListView->blockSignals( false ); 599 mTodoListView->blockSignals( false );
599 mTodoListView->setFocus(); 600 mTodoListView->setFocus();
600 processSelectionChange(); 601 processSelectionChange();
601} 602}
602 603
603void KOTodoView::restoreItemState( QListViewItem *item ) 604void KOTodoView::restoreItemState( QListViewItem *item )
604{ 605{
605 pendingSubtodo = 0; 606 pendingSubtodo = 0;
606 while( item ) { 607 while( item ) {
607 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 608 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
608 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 609 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
609 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 610 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
610 item = item->nextSibling(); 611 item = item->nextSibling();
611 } 612 }
612} 613}
613 614
614 615
615QMap<Todo *,KOTodoViewItem *>::ConstIterator 616QMap<Todo *,KOTodoViewItem *>::ConstIterator
616 KOTodoView::insertTodoItem(Todo *todo) 617 KOTodoView::insertTodoItem(Todo *todo)
617{ 618{
618// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 619// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
619 // TODO: Check, if dynmaic cast is necessary 620 // TODO: Check, if dynmaic cast is necessary
620 621
621 pendingSubtodo = 0; 622 pendingSubtodo = 0;
622 Incidence *incidence = todo->relatedTo(); 623 Incidence *incidence = todo->relatedTo();
623 if (incidence && incidence->type() == "Todo") { 624 if (incidence && incidence->type() == "Todo") {
624 Todo *relatedTodo = static_cast<Todo *>(incidence); 625 Todo *relatedTodo = static_cast<Todo *>(incidence);
625 626
626// kdDebug() << " has Related" << endl; 627// kdDebug() << " has Related" << endl;
627 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 628 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
628 itemIterator = mTodoMap.find(relatedTodo); 629 itemIterator = mTodoMap.find(relatedTodo);
629 if (itemIterator == mTodoMap.end()) { 630 if (itemIterator == mTodoMap.end()) {
630// kdDebug() << " related not yet in list" << endl; 631// kdDebug() << " related not yet in list" << endl;
631 itemIterator = insertTodoItem (relatedTodo); 632 itemIterator = insertTodoItem (relatedTodo);
632 } 633 }
633 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 634 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
634 // and one into the map. Sure finding is more easy but why? -zecke 635 // and one into the map. Sure finding is more easy but why? -zecke
635 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 636 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
636 return mTodoMap.insert(todo,todoItem); 637 return mTodoMap.insert(todo,todoItem);
637 } else { 638 } else {
638// kdDebug() << " no Related" << endl; 639// kdDebug() << " no Related" << endl;
639 // see above -zecke 640 // see above -zecke
640 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 641 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
641 return mTodoMap.insert(todo,todoItem); 642 return mTodoMap.insert(todo,todoItem);
642 } 643 }
643} 644}
644 645
645 646
646void KOTodoView::updateConfig() 647void KOTodoView::updateConfig()
647{ 648{
648 updateView(); 649 updateView();
649 mTodoListView->repaintContents(); 650 mTodoListView->repaintContents();
650} 651}
651 652
652QPtrList<Incidence> KOTodoView::selectedIncidences() 653QPtrList<Incidence> KOTodoView::selectedIncidences()
653{ 654{
654 QPtrList<Incidence> selected; 655 QPtrList<Incidence> selected;
655 656
656 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 657 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
657// if (!item) item = mActiveItem; 658// if (!item) item = mActiveItem;
658 if (item) selected.append(item->todo()); 659 if (item) selected.append(item->todo());
659 660
660 return selected; 661 return selected;
661} 662}
662 663
663QPtrList<Todo> KOTodoView::selectedTodos() 664QPtrList<Todo> KOTodoView::selectedTodos()
664{ 665{
665 QPtrList<Todo> selected; 666 QPtrList<Todo> selected;
666 667
667 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 668 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
668// if (!item) item = mActiveItem; 669// if (!item) item = mActiveItem;
669 if (item) selected.append(item->todo()); 670 if (item) selected.append(item->todo());
670 671
671 return selected; 672 return selected;
672} 673}
673 674
674void KOTodoView::changeEventDisplay(Event *, int) 675void KOTodoView::changeEventDisplay(Event *, int)
675{ 676{
676 updateView(); 677 updateView();
677} 678}
678 679
679void KOTodoView::showDates(const QDate &, const QDate &) 680void KOTodoView::showDates(const QDate &, const QDate &)
680{ 681{
681} 682}
682 683
683void KOTodoView::showEvents(QPtrList<Event>) 684void KOTodoView::showEvents(QPtrList<Event>)
684{ 685{
685 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 686 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
686} 687}
687 688
688void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 689void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
689 const QDate &td) 690 const QDate &td)
690{ 691{
691#ifndef KORG_NOPRINTER 692#ifndef KORG_NOPRINTER
692 calPrinter->preview(CalPrinter::Todolist, fd, td); 693 calPrinter->preview(CalPrinter::Todolist, fd, td);
693#endif 694#endif
694} 695}
695 696
696void KOTodoView::editItem(QListViewItem *item ) 697void KOTodoView::editItem(QListViewItem *item )
697{ 698{
698 // qDebug("editItem(QListViewItem *item ) "); 699 // qDebug("editItem(QListViewItem *item ) ");
699 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 700 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
700} 701}
701 702
702void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 703void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
703{ 704{
704 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 705 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
705} 706}
706 707
707void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column) 708void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column)
708{ 709{
709 pendingSubtodo = 0; 710 pendingSubtodo = 0;
710 mActiveItem = (KOTodoViewItem *)item; 711 mActiveItem = (KOTodoViewItem *)item;
711 if (item) { 712 if (item) {
712 switch (column){ 713 switch (column){
713 case 1: 714 case 1:
714 mPriorityPopupMenu->popup(QCursor::pos ()); break; 715 mPriorityPopupMenu->popup(QCursor::pos ()); break;
715 case 2: 716 case 2:
716 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 717 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
717 case 3: 718 case 3:
718 moveTodo(); 719 moveTodo();
719 break; 720 break;
720 case 6: 721 case 6:
721 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 722 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
722 default: 723 default:
723 mItemPopupMenu->popup(QCursor::pos()); 724 mItemPopupMenu->popup(QCursor::pos());
724 } 725 }
725 } else mPopupMenu->popup(QCursor::pos()); 726 } else mPopupMenu->popup(QCursor::pos());
726} 727}
727void KOTodoView::newTodo() 728void KOTodoView::newTodo()
728{ 729{
729 emit newTodoSignal(); 730 emit newTodoSignal();
730} 731}
731 732
732void KOTodoView::newSubTodo() 733void KOTodoView::newSubTodo()
733{ 734{
734 if (mActiveItem) { 735 if (mActiveItem) {
735 emit newSubTodoSignal(mActiveItem->todo()); 736 emit newSubTodoSignal(mActiveItem->todo());
736 } 737 }
737} 738}
738void KOTodoView::unparentTodo() 739void KOTodoView::unparentTodo()
739{ 740{
740 if (mActiveItem) { 741 if (mActiveItem) {
741 emit unparentTodoSignal(mActiveItem->todo()); 742 emit unparentTodoSignal(mActiveItem->todo());
742 } 743 }
743} 744}
744 745
745void KOTodoView::reparentTodo() 746void KOTodoView::reparentTodo()
746{ 747{
747 if (mActiveItem) { 748 if (mActiveItem) {
748 qDebug("KOTodoView::reparentTodo() "); 749 qDebug("KOTodoView::reparentTodo() ");
749 topLevelWidget()->setCaption(i18n("Click on new parent item")); 750 topLevelWidget()->setCaption(i18n("Click on new parent item"));
750 pendingSubtodo = mActiveItem; 751 pendingSubtodo = mActiveItem;
751 } 752 }
752} 753}
753void KOTodoView::editTodo() 754void KOTodoView::editTodo()
754{ 755{
755 if (mActiveItem) { 756 if (mActiveItem) {
756 emit editTodoSignal(mActiveItem->todo()); 757 emit editTodoSignal(mActiveItem->todo());
757 } 758 }
758} 759}
759void KOTodoView::cloneTodo() 760void KOTodoView::cloneTodo()
760{ 761{
761 if (mActiveItem) { 762 if (mActiveItem) {
762 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 763 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
763 } 764 }
764} 765}
765void KOTodoView::cancelTodo() 766void KOTodoView::cancelTodo()
766{ 767{
767 if (mActiveItem) { 768 if (mActiveItem) {
768 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 769 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
769 } 770 }
770} 771}
771void KOTodoView::moveTodo() 772void KOTodoView::moveTodo()
772{ 773{
773 if (mActiveItem) { 774 if (mActiveItem) {
774 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 775 emit moveTodoSignal((Incidence*)mActiveItem->todo());
775 } 776 }
776} 777}
777void KOTodoView::beamTodo() 778void KOTodoView::beamTodo()
778{ 779{
779 if (mActiveItem) { 780 if (mActiveItem) {
780 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 781 emit beamTodoSignal((Incidence*)mActiveItem->todo());
781 } 782 }
782} 783}
783 784
784 785
785void KOTodoView::showTodo() 786void KOTodoView::showTodo()
786{ 787{
787 if (mActiveItem) { 788 if (mActiveItem) {
788 emit showTodoSignal(mActiveItem->todo()); 789 emit showTodoSignal(mActiveItem->todo());
789 } 790 }
790} 791}
791 792
792void KOTodoView::deleteTodo() 793void KOTodoView::deleteTodo()
793{ 794{
794 if (mActiveItem) { 795 if (mActiveItem) {
795 if (mActiveItem->childCount()) { 796 if (mActiveItem->childCount()) {
796 KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."), 797 KMessageBox::sorry(this,i18n("Cannot delete To-Do which has children."),
797 i18n("Delete To-Do")); 798 i18n("Delete To-Do"));
798 } else { 799 } else {
799 emit deleteTodoSignal(mActiveItem->todo()); 800 emit deleteTodoSignal(mActiveItem->todo());
800 } 801 }
801 } 802 }
802} 803}
803 804
804void KOTodoView::setNewPriority(int index) 805void KOTodoView::setNewPriority(int index)
805{ 806{
806 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 807 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
807 mActiveItem->todo()->setPriority(mPriority[index]); 808 mActiveItem->todo()->setPriority(mPriority[index]);
808 mActiveItem->construct(); 809 mActiveItem->construct();
809 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 810 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
810 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 811 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
811 } 812 }
812} 813}
813 814
814void KOTodoView::setNewPercentage(int index) 815void KOTodoView::setNewPercentage(int index)
815{ 816{
816 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 817 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
817 if (mPercentage[index] == 100) { 818 if (mPercentage[index] == 100) {
818 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 819 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
819 } else { 820 } else {
820 mActiveItem->todo()->setCompleted(false); 821 mActiveItem->todo()->setCompleted(false);
821 } 822 }
822 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 823 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
823 mActiveItem->construct(); 824 mActiveItem->construct();
824 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 825 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
825 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 826 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
826 } 827 }
827} 828}
828 829
829 830
830QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 831QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
831{ 832{
832 QPopupMenu* tempMenu = new QPopupMenu (this); 833 QPopupMenu* tempMenu = new QPopupMenu (this);
833 QStringList checkedCategories = todoItem->todo()->categories (); 834 QStringList checkedCategories = todoItem->todo()->categories ();
834 835
835 tempMenu->setCheckable (true); 836 tempMenu->setCheckable (true);
836 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 837 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
837 it != KOPrefs::instance()->mCustomCategories.end (); 838 it != KOPrefs::instance()->mCustomCategories.end ();
838 ++it) { 839 ++it) {
839 int index = tempMenu->insertItem (*it); 840 int index = tempMenu->insertItem (*it);
840 mCategory[index] = *it; 841 mCategory[index] = *it;
841 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 842 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
842 } 843 }
843 844
844 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 845 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
845 return tempMenu; 846 return tempMenu;
846 847
847 848
848} 849}
849void KOTodoView::changedCategories(int index) 850void KOTodoView::changedCategories(int index)
850{ 851{
851 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 852 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
852 QStringList categories = mActiveItem->todo()->categories (); 853 QStringList categories = mActiveItem->todo()->categories ();
853 if (categories.find (mCategory[index]) != categories.end ()) 854 if (categories.find (mCategory[index]) != categories.end ())
854 categories.remove (mCategory[index]); 855 categories.remove (mCategory[index]);
855 else 856 else
856 categories.insert (categories.end(), mCategory[index]); 857 categories.insert (categories.end(), mCategory[index]);
857 categories.sort (); 858 categories.sort ();
858 mActiveItem->todo()->setCategories (categories); 859 mActiveItem->todo()->setCategories (categories);
859 mActiveItem->construct(); 860 mActiveItem->construct();
860 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 861 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
861 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 862 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
862 } 863 }
863} 864}
864void KOTodoView::itemDoubleClicked(QListViewItem *item) 865void KOTodoView::itemDoubleClicked(QListViewItem *item)
865{ 866{
866 if ( pendingSubtodo != 0 ) { 867 if ( pendingSubtodo != 0 ) {
867 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 868 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
868 } 869 }
869 pendingSubtodo = 0; 870 pendingSubtodo = 0;
870 if (!item) { 871 if (!item) {
871 newTodo(); 872 newTodo();
872 return; 873 return;
873 } 874 }
874 if ( KOPrefs::instance()->mEditOnDoubleClick ) 875 if ( KOPrefs::instance()->mEditOnDoubleClick )
875 editItem( item ); 876 editItem( item );
876 else 877 else
877 showItem( item , QPoint(), 0 ); 878 showItem( item , QPoint(), 0 );
878} 879}
879void KOTodoView::itemClicked(QListViewItem *item) 880void KOTodoView::itemClicked(QListViewItem *item)
880{ 881{
881 882
882 if (!item) { 883 if (!item) {
883 if ( pendingSubtodo != 0 ) { 884 if ( pendingSubtodo != 0 ) {
884 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 885 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
885 } 886 }
886 pendingSubtodo = 0; 887 pendingSubtodo = 0;
887 return; 888 return;
888 } 889 }
889 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 890 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
890 if ( pendingSubtodo != 0 ) { 891 if ( pendingSubtodo != 0 ) {
891 bool allowReparent = true; 892 bool allowReparent = true;
892 QListViewItem *par = item; 893 QListViewItem *par = item;
893 while ( par ) { 894 while ( par ) {
894 if ( par == pendingSubtodo ) { 895 if ( par == pendingSubtodo ) {
895 allowReparent = false; 896 allowReparent = false;
896 break; 897 break;
897 } 898 }
898 par = par->parent(); 899 par = par->parent();
899 } 900 }
900 if ( !allowReparent ) { 901 if ( !allowReparent ) {
901 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 902 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
902 qDebug("Recursive reparenting not possible "); 903 qDebug("Recursive reparenting not possible ");
903 pendingSubtodo = 0; 904 pendingSubtodo = 0;
904 } else { 905 } else {
905 Todo* newParent = todoItem->todo(); 906 Todo* newParent = todoItem->todo();
906 Todo* newSub = pendingSubtodo->todo(); 907 Todo* newSub = pendingSubtodo->todo();
907 pendingSubtodo = 0; 908 pendingSubtodo = 0;
908 emit reparentTodoSignal( newParent,newSub ); 909 emit reparentTodoSignal( newParent,newSub );
909 return; 910 return;
910 } 911 }
911 } 912 }
912 int completed = todoItem->todo()->isCompleted(); // Completed or not? 913 int completed = todoItem->todo()->isCompleted(); // Completed or not?
913 914
914 if (todoItem->isOn()) { 915 if (todoItem->isOn()) {
915 if (!completed) { 916 if (!completed) {
916 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 917 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
917 } 918 }
918 } else { 919 } else {
919 if (completed) { 920 if (completed) {
920 todoItem->todo()->setCompleted(false); 921 todoItem->todo()->setCompleted(false);
921 } 922 }
922 } 923 }
923} 924}
924 925
925void KOTodoView::setDocumentId( const QString &id ) 926void KOTodoView::setDocumentId( const QString &id )
926{ 927{
927 kdDebug() << "KOTodoView::setDocumentId()" << endl; 928 kdDebug() << "KOTodoView::setDocumentId()" << endl;
928 929
929 mDocPrefs->setDoc( id ); 930 mDocPrefs->setDoc( id );
930} 931}
931 932
932void KOTodoView::itemStateChanged( QListViewItem *item ) 933void KOTodoView::itemStateChanged( QListViewItem *item )
933{ 934{
934 if (!item) return; 935 if (!item) return;
935 936
936 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 937 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
937 938
938// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 939// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
939 940
940 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 941 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
941} 942}
942 943
943void KOTodoView::saveLayout(KConfig *config, const QString &group) const 944void KOTodoView::saveLayout(KConfig *config, const QString &group) const
944{ 945{
945 mTodoListView->saveLayout(config,group); 946 mTodoListView->saveLayout(config,group);
946} 947}
947 948
948void KOTodoView::restoreLayout(KConfig *config, const QString &group) 949void KOTodoView::restoreLayout(KConfig *config, const QString &group)
949{ 950{
950 mTodoListView->restoreLayout(config,group); 951 mTodoListView->restoreLayout(config,group);
951} 952}
952 953
953void KOTodoView::processSelectionChange() 954void KOTodoView::processSelectionChange()
954{ 955{
955// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 956// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
956 957
957 KOTodoViewItem *item = 958 KOTodoViewItem *item =
958 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 959 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
959 960
960 if ( !item ) { 961 if ( !item ) {
961 emit incidenceSelected( 0 ); 962 emit incidenceSelected( 0 );
962 } else { 963 } else {
963 emit incidenceSelected( item->todo() ); 964 emit incidenceSelected( item->todo() );
964 } 965 }
965} 966}
966 967
967void KOTodoView::modified(bool b) 968void KOTodoView::modified(bool b)
968{ 969{
969 emit isModified(b); 970 emit isModified(b);
970} 971}
971void KOTodoView::setTodoModified( Todo* todo ) 972void KOTodoView::setTodoModified( Todo* todo )
972{ 973{
973 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 974 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
974} 975}
975void KOTodoView::clearSelection() 976void KOTodoView::clearSelection()
976{ 977{
977 mTodoListView->selectAll( false ); 978 mTodoListView->selectAll( false );
978} 979}
979 980
980void KOTodoView::purgeCompleted() 981void KOTodoView::purgeCompleted()
981{ 982{
982 emit purgeCompletedSignal(); 983 emit purgeCompletedSignal();
983} 984}
984void KOTodoView::toggleQuickTodo() 985void KOTodoView::toggleQuickTodo()
985{ 986{
986 if ( mQuickAdd->isVisible() ) { 987 if ( mQuickAdd->isVisible() ) {
987 mQuickAdd->hide(); 988 mQuickAdd->hide();
988 KOPrefs::instance()->mEnableQuickTodo = false; 989 KOPrefs::instance()->mEnableQuickTodo = false;
989 } 990 }
990 else { 991 else {
991 mQuickAdd->show(); 992 mQuickAdd->show();
992 KOPrefs::instance()->mEnableQuickTodo = true; 993 KOPrefs::instance()->mEnableQuickTodo = true;
993 } 994 }
994 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 995 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
995 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 996 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
996} 997}
997void KOTodoView::toggleCompleted() 998void KOTodoView::toggleCompleted()
998{ 999{
999 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1000 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1000 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1001 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1001 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1002 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1002 updateView(); 1003 updateView();
1003} 1004}
1004 1005
1005void KOTodoView::addQuickTodo() 1006void KOTodoView::addQuickTodo()
1006{ 1007{
1007 Todo *todo = new Todo(); 1008 Todo *todo = new Todo();
1008 todo->setSummary(mQuickAdd->text()); 1009 todo->setSummary(mQuickAdd->text());
1009 todo->setOrganizer(KOPrefs::instance()->email()); 1010 todo->setOrganizer(KOPrefs::instance()->email());
1010 CalFilter * cf = mCalendar->filter(); 1011 CalFilter * cf = mCalendar->filter();
1011 if ( cf ) { 1012 if ( cf ) {
1012 if ( cf->isEnabled()&& cf->showCategories()) { 1013 if ( cf->isEnabled()&& cf->showCategories()) {
1013 todo->setCategories(cf->categoryList()); 1014 todo->setCategories(cf->categoryList());
1014 } 1015 }
1015 if ( cf->isEnabled() ) 1016 if ( cf->isEnabled() )
1016 todo->setSecrecy( cf->getSecrecy()); 1017 todo->setSecrecy( cf->getSecrecy());
1017 } 1018 }
1018 mCalendar->addTodo(todo); 1019 mCalendar->addTodo(todo);
1019 mQuickAdd->setText(""); 1020 mQuickAdd->setText("");
1020 todoModified (todo, KOGlobals::EVENTADDED ); 1021 todoModified (todo, KOGlobals::EVENTADDED );
1021 updateView(); 1022 updateView();
1022} 1023}
1023void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1024void KOTodoView::keyPressEvent ( QKeyEvent * e )
1024{ 1025{
1025 // e->ignore(); 1026 // e->ignore();
1026 //return; 1027 //return;
1027 //qDebug("KOTodoView::keyPressEvent "); 1028 //qDebug("KOTodoView::keyPressEvent ");
1028 switch ( e->key() ) { 1029 switch ( e->key() ) {
1029 case Qt::Key_Down: 1030 case Qt::Key_Down:
1030 case Qt::Key_Up: 1031 case Qt::Key_Up:
1031 QWidget::keyPressEvent ( e ); 1032 QWidget::keyPressEvent ( e );
1032 break; 1033 break;
1033 1034
1034 case Qt::Key_Q: 1035 case Qt::Key_Q:
1035 toggleQuickTodo(); 1036 toggleQuickTodo();
1036 break; 1037 break;
1037 case Qt::Key_U: 1038 case Qt::Key_U:
1038 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1039 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1039 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1040 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1040 unparentTodo(); 1041 unparentTodo();
1041 e->accept(); 1042 e->accept();
1042 } else 1043 } else
1043 e->ignore(); 1044 e->ignore();
1044 break; 1045 break;
1045 case Qt::Key_S: 1046 case Qt::Key_S:
1046 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1047 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1047 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1048 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1048 reparentTodo(); 1049 reparentTodo();
1049 e->accept(); 1050 e->accept();
1050 } else 1051 } else
1051 e->ignore(); 1052 e->ignore();
1052 break; 1053 break;
1053 case Qt::Key_P: 1054 case Qt::Key_P:
1054 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1055 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1055 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1056 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1056 if ( pendingSubtodo ) 1057 if ( pendingSubtodo )
1057 itemClicked(mActiveItem); 1058 itemClicked(mActiveItem);
1058 e->accept(); 1059 e->accept();
1059 } else 1060 } else
1060 e->ignore(); 1061 e->ignore();
1061 break; 1062 break;
1062 case Qt::Key_Escape: 1063 case Qt::Key_Escape:
1063 if ( pendingSubtodo ) { 1064 if ( pendingSubtodo ) {
1064 itemClicked(0); 1065 itemClicked(0);
1065 e->accept(); 1066 e->accept();
1066 } else 1067 } else
1067 e->ignore(); 1068 e->ignore();
1068 break; 1069 break;
1069 default: 1070 default:
1070 e->ignore(); 1071 e->ignore();
1071 } 1072 }
1072 1073
1073 if ( true ) { 1074 if ( true ) {
1074 if ( e->key() == Qt::Key_I ) { 1075 if ( e->key() == Qt::Key_I ) {
1075 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1076 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1076 if ( cn ) { 1077 if ( cn ) {
1077 mActiveItem = cn; 1078 mActiveItem = cn;
1078 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1079 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1079 if ( ci ){ 1080 if ( ci ){
1080 showTodo(); 1081 showTodo();
1081 cn = (KOTodoViewItem*)cn->itemBelow(); 1082 cn = (KOTodoViewItem*)cn->itemBelow();
1082 if ( cn ) { 1083 if ( cn ) {
1083 mTodoListView->setCurrentItem ( cn ); 1084 mTodoListView->setCurrentItem ( cn );
1084 mTodoListView->ensureItemVisible ( cn ); 1085 mTodoListView->ensureItemVisible ( cn );
1085 } 1086 }
1086 1087
1087 } 1088 }
1088 } 1089 }
1089 e->accept(); 1090 e->accept();
1090 1091
1091 } 1092 }
1092 1093
1093 } 1094 }
1094 1095
1095} 1096}
1096void KOTodoView::updateTodo( Todo * t, int type ) 1097void KOTodoView::updateTodo( Todo * t, int type )
1097{ 1098{
1098 if ( mBlockUpdate) 1099 if ( mBlockUpdate)
1099 return; 1100 return;
1100 1101
1101 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1102 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1102 itemIterator = mTodoMap.find(t); 1103 itemIterator = mTodoMap.find(t);
1103 if (itemIterator != mTodoMap.end()) { 1104 if (itemIterator != mTodoMap.end()) {
1104 (*itemIterator)->construct(); 1105 (*itemIterator)->construct();
1105 } else { 1106 } else {
1106 if ( type == KOGlobals::EVENTADDED ) { 1107 if ( type == KOGlobals::EVENTADDED ) {
1107 insertTodoItem( t ); 1108 insertTodoItem( t );
1108 } 1109 }
1109 } 1110 }
1110 1111
1111} 1112}
1112 1113
1113void KOTodoView::todoModified(Todo * t , int p ) 1114void KOTodoView::todoModified(Todo * t , int p )
1114{ 1115{
1115 mBlockUpdate = true; 1116 mBlockUpdate = true;
1116 emit todoModifiedSignal ( t, p ); 1117 emit todoModifiedSignal ( t, p );
1117 mBlockUpdate = false; 1118 mBlockUpdate = false;
1118} 1119}
diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp
index 85647b1..ae0b334 100644
--- a/korganizer/kotodoviewitem.cpp
+++ b/korganizer/kotodoviewitem.cpp
@@ -1,432 +1,432 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qapp.h> 22#include <qapp.h>
23 23
24#include <kiconloader.h> 24#include <kiconloader.h>
25#include "kotodoviewitem.h" 25#include "kotodoviewitem.h"
26#include "kotodoview.h" 26#include "kotodoview.h"
27#include "koprefs.h" 27#include "koprefs.h"
28 28
29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo) 29KOTodoViewItem::KOTodoViewItem( QListView *parent, Todo *todo, KOTodoView *kotodo)
30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 30 : QCheckListItem( parent , "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
31{ 31{
32 construct(); 32 construct();
33} 33}
34 34
35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo ) 35KOTodoViewItem::KOTodoViewItem( KOTodoViewItem *parent, Todo *todo, KOTodoView *kotodo )
36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo ) 36 : QCheckListItem( parent, "", CheckBox ), mTodo( todo ), mTodoView( kotodo )
37{ 37{
38 construct(); 38 construct();
39} 39}
40 40
41QString KOTodoViewItem::key(int column,bool) const 41QString KOTodoViewItem::key(int column,bool) const
42{ 42{
43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 43 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
44 if (it == mKeyMap.end()) { 44 if (it == mKeyMap.end()) {
45 return text(column); 45 return text(column).lower();
46 } else { 46 } else {
47 return *it; 47 return *it;
48 } 48 }
49} 49}
50 50
51void KOTodoViewItem:: setup() 51void KOTodoViewItem:: setup()
52{ 52{
53 53
54 int h = 20; 54 int h = 20;
55 if ( listView () ) { 55 if ( listView () ) {
56 QFontMetrics fm ( listView ()->font () ); 56 QFontMetrics fm ( listView ()->font () );
57 h = fm.height(); 57 h = fm.height();
58 } 58 }
59 setHeight( h ); 59 setHeight( h );
60 60
61} 61}
62void KOTodoViewItem::setSortKey(int column,const QString &key) 62void KOTodoViewItem::setSortKey(int column,const QString &key)
63{ 63{
64 mKeyMap.insert(column,key); 64 mKeyMap.insert(column,key);
65} 65}
66 66
67#if QT_VERSION >= 300 67#if QT_VERSION >= 300
68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w, 68void KOTodoViewItem::paintBranches(QPainter *p,const QColorGroup & cg,int w,
69 int y,int h) 69 int y,int h)
70{ 70{
71 QListViewItem::paintBranches(p,cg,w,y,h); 71 QListViewItem::paintBranches(p,cg,w,y,h);
72} 72}
73#else 73#else
74#endif 74#endif
75 75
76void KOTodoViewItem::construct() 76void KOTodoViewItem::construct()
77{ 77{
78 // qDebug("KOTodoViewItem::construct() "); 78 // qDebug("KOTodoViewItem::construct() ");
79 m_init = true; 79 m_init = true;
80 QString keyd = "=="; 80 QString keyd = "==";
81 QString keyt = "=="; 81 QString keyt = "==";
82 82
83 setOn(mTodo->isCompleted()); 83 setOn(mTodo->isCompleted());
84 setText(0,mTodo->summary()); 84 setText(0,mTodo->summary());
85 setText(1,QString::number(mTodo->priority())); 85 setText(1,QString::number(mTodo->priority()));
86 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 86 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
87 if (mTodo->percentComplete()<100) { 87 if (mTodo->percentComplete()<100) {
88 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 88 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
89 else setSortKey(2,QString::number(mTodo->percentComplete())); 89 else setSortKey(2,QString::number(mTodo->percentComplete()));
90 } 90 }
91 else { 91 else {
92 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 92 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
93 else setSortKey(2,QString::number(99)); 93 else setSortKey(2,QString::number(99));
94 } 94 }
95 if (mTodo->hasDueDate()) { 95 if (mTodo->hasDueDate()) {
96 setText(3, mTodo->dtDueDateStr()); 96 setText(3, mTodo->dtDueDateStr());
97 QDate d = mTodo->dtDue().date(); 97 QDate d = mTodo->dtDue().date();
98 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 98 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
99 setSortKey(3,keyd); 99 setSortKey(3,keyd);
100 if (mTodo->doesFloat()) { 100 if (mTodo->doesFloat()) {
101 setText(4,""); 101 setText(4,"");
102 } 102 }
103 else { 103 else {
104 setText(4,mTodo->dtDueTimeStr()); 104 setText(4,mTodo->dtDueTimeStr());
105 QTime t = mTodo->dtDue().time(); 105 QTime t = mTodo->dtDue().time();
106 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 106 keyt.sprintf("%02d%02d",t.hour(),t.minute());
107 setSortKey(4,keyt); 107 setSortKey(4,keyt);
108 } 108 }
109 } else { 109 } else {
110 setText(3,""); 110 setText(3,"");
111 setText(4,""); 111 setText(4,"");
112 } 112 }
113 setSortKey(3,keyd); 113 setSortKey(3,keyd);
114 setSortKey(4,keyt); 114 setSortKey(4,keyt);
115 115
116 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt); 116 if (mTodo->isCompleted()) setSortKey(1,"6" + QString::number(mTodo->priority())+keyd+keyt);
117 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 117 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
118 118
119 setText(5,mTodo->cancelled() ? i18n("Yes") : i18n("No")); 119 setText(5,mTodo->cancelled() ? i18n("Yes") : i18n("No"));
120 setText(6,mTodo->categoriesStr()); 120 setText(6,mTodo->categoriesStr());
121 121
122#if 0 122#if 0
123 // Find sort id in description. It's the text behind the last '#' character 123 // Find sort id in description. It's the text behind the last '#' character
124 // found in the description. White spaces are removed from beginning and end 124 // found in the description. White spaces are removed from beginning and end
125 // of sort id. 125 // of sort id.
126 int pos = mTodo->description().findRev('#'); 126 int pos = mTodo->description().findRev('#');
127 if (pos < 0) { 127 if (pos < 0) {
128 setText(6,""); 128 setText(6,"");
129 } else { 129 } else {
130 QString str = mTodo->description().mid(pos+1); 130 QString str = mTodo->description().mid(pos+1);
131 str.stripWhiteSpace(); 131 str.stripWhiteSpace();
132 setText(6,str); 132 setText(6,str);
133 } 133 }
134#endif 134#endif
135 135
136 m_known = false; 136 m_known = false;
137 m_init = false; 137 m_init = false;
138 138
139 setMyPixmap(); 139 setMyPixmap();
140 140
141} 141}
142void KOTodoViewItem::setMyPixmap() 142void KOTodoViewItem::setMyPixmap()
143{ 143{
144 int size = 5; 144 int size = 5;
145 QPixmap pixi = QPixmap( 1, 1 ); 145 QPixmap pixi = QPixmap( 1, 1 );
146 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) { 146 // if ( !mTodo->isCompleted() && mTodo->hasDueDate() && mTodo->dtDue() < QDateTime::currentDateTime() ) {
147// pixi = SmallIcon("redcross16"); 147// pixi = SmallIcon("redcross16");
148// } else { 148// } else {
149 QPainter p; 149 QPainter p;
150 150
151 int pixSize = 0; 151 int pixSize = 0;
152 QPixmap pPix = QPixmap( size, size ); 152 QPixmap pPix = QPixmap( size, size );
153 if ( mTodo->description().length() > 0 ) { 153 if ( mTodo->description().length() > 0 ) {
154 pixi.resize(size, pixSize+size); 154 pixi.resize(size, pixSize+size);
155 pPix.fill( Qt::darkGreen ); 155 pPix.fill( Qt::darkGreen );
156 p.begin( &pixi ); 156 p.begin( &pixi );
157 p. drawPixmap ( 0, pixSize, pPix); 157 p. drawPixmap ( 0, pixSize, pPix);
158 p.end(); 158 p.end();
159 pixSize += size; 159 pixSize += size;
160 } 160 }
161 if ( mTodo->isAlarmEnabled() ) { 161 if ( mTodo->isAlarmEnabled() ) {
162 pixi.resize(size, pixSize+size); 162 pixi.resize(size, pixSize+size);
163 pPix.fill( Qt::red ); 163 pPix.fill( Qt::red );
164 p.begin( &pixi ); 164 p.begin( &pixi );
165 p. drawPixmap ( 0, pixSize, pPix); 165 p. drawPixmap ( 0, pixSize, pPix);
166 p.end(); 166 p.end();
167 pixSize += size; 167 pixSize += size;
168 } 168 }
169 // } 169 // }
170 if ( pixi.width() > 1 ) { 170 if ( pixi.width() > 1 ) {
171 setPixmap ( 0,pixi ) ; 171 setPixmap ( 0,pixi ) ;
172 } 172 }
173 173
174 174
175} 175}
176void KOTodoViewItem::stateChange(bool state) 176void KOTodoViewItem::stateChange(bool state)
177{ 177{
178 // qDebug("KOTodoViewItem::stateChange "); 178 // qDebug("KOTodoViewItem::stateChange ");
179 // do not change setting on startup 179 // do not change setting on startup
180 if ( m_init ) return; 180 if ( m_init ) return;
181 181
182 kdDebug() << "State changed, modified " << state << endl; 182 kdDebug() << "State changed, modified " << state << endl;
183 QString keyd = "=="; 183 QString keyd = "==";
184 QString keyt = "=="; 184 QString keyt = "==";
185 185
186 if (state) mTodo->setCompleted(state); 186 if (state) mTodo->setCompleted(state);
187 else mTodo->setPercentComplete(0); 187 else mTodo->setPercentComplete(0);
188 if (isOn()!=state) { 188 if (isOn()!=state) {
189 setOn(state); 189 setOn(state);
190 } 190 }
191 191
192 if (mTodo->hasDueDate()) { 192 if (mTodo->hasDueDate()) {
193 setText(3, mTodo->dtDueDateStr()); 193 setText(3, mTodo->dtDueDateStr());
194 QDate d = mTodo->dtDue().date(); 194 QDate d = mTodo->dtDue().date();
195 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); 195 keyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day());
196 setSortKey(3,keyd); 196 setSortKey(3,keyd);
197 if (mTodo->doesFloat()) { 197 if (mTodo->doesFloat()) {
198 setText(4,""); 198 setText(4,"");
199 } 199 }
200 else { 200 else {
201 setText(4,mTodo->dtDueTimeStr()); 201 setText(4,mTodo->dtDueTimeStr());
202 QTime t = mTodo->dtDue().time(); 202 QTime t = mTodo->dtDue().time();
203 keyt.sprintf("%02d%02d",t.hour(),t.minute()); 203 keyt.sprintf("%02d%02d",t.hour(),t.minute());
204 setSortKey(4,keyt); 204 setSortKey(4,keyt);
205 } 205 }
206 } 206 }
207 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt); 207 if (mTodo->isCompleted()) setSortKey(1,QString::number(9)+keyd+keyt);
208 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt); 208 else setSortKey(1,QString::number(mTodo->priority())+keyd+keyt);
209 209
210 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete()))); 210 setText(2,i18n("%1 %").arg(QString::number(mTodo->percentComplete())));
211 if (mTodo->percentComplete()<100) { 211 if (mTodo->percentComplete()<100) {
212 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 212 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
213 else setSortKey(2,QString::number(mTodo->percentComplete())); 213 else setSortKey(2,QString::number(mTodo->percentComplete()));
214 } 214 }
215 else { 215 else {
216 if (mTodo->isCompleted()) setSortKey(2,QString::number(999)); 216 if (mTodo->isCompleted()) setSortKey(2,QString::number(999));
217 else setSortKey(2,QString::number(99)); 217 else setSortKey(2,QString::number(99));
218 } 218 }
219 QListViewItem * myChild = firstChild(); 219 QListViewItem * myChild = firstChild();
220 KOTodoViewItem *item; 220 KOTodoViewItem *item;
221 while( myChild ) { 221 while( myChild ) {
222 item = static_cast<KOTodoViewItem*>(myChild); 222 item = static_cast<KOTodoViewItem*>(myChild);
223 item->stateChange(state); 223 item->stateChange(state);
224 myChild = myChild->nextSibling(); 224 myChild = myChild->nextSibling();
225 } 225 }
226 mTodoView->modified(true); 226 mTodoView->modified(true);
227 mTodoView->setTodoModified( mTodo ); 227 mTodoView->setTodoModified( mTodo );
228 setMyPixmap(); 228 setMyPixmap();
229} 229}
230 230
231bool KOTodoViewItem::isAlternate() 231bool KOTodoViewItem::isAlternate()
232{ 232{
233#ifndef KORG_NOLVALTERNATION 233#ifndef KORG_NOLVALTERNATION
234 KOTodoListView *lv = static_cast<KOTodoListView *>(listView()); 234 KOTodoListView *lv = static_cast<KOTodoListView *>(listView());
235 if (lv && lv->alternateBackground().isValid()) 235 if (lv && lv->alternateBackground().isValid())
236 { 236 {
237 KOTodoViewItem *above = 0; 237 KOTodoViewItem *above = 0;
238 above = dynamic_cast<KOTodoViewItem *>(itemAbove()); 238 above = dynamic_cast<KOTodoViewItem *>(itemAbove());
239 m_known = above ? above->m_known : true; 239 m_known = above ? above->m_known : true;
240 if (m_known) 240 if (m_known)
241 { 241 {
242 m_odd = above ? !above->m_odd : false; 242 m_odd = above ? !above->m_odd : false;
243 } 243 }
244 else 244 else
245 { 245 {
246 KOTodoViewItem *item; 246 KOTodoViewItem *item;
247 bool previous = true; 247 bool previous = true;
248 if (QListViewItem::parent()) 248 if (QListViewItem::parent())
249 { 249 {
250 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()); 250 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent());
251 if (item) 251 if (item)
252 previous = item->m_odd; 252 previous = item->m_odd;
253 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild()); 253 item = dynamic_cast<KOTodoViewItem *>(QListViewItem::parent()->firstChild());
254 } 254 }
255 else 255 else
256 { 256 {
257 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild()); 257 item = dynamic_cast<KOTodoViewItem *>(lv->firstChild());
258 } 258 }
259 259
260 while(item) 260 while(item)
261 { 261 {
262 item->m_odd = previous = !previous; 262 item->m_odd = previous = !previous;
263 item->m_known = true; 263 item->m_known = true;
264 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling()); 264 item = dynamic_cast<KOTodoViewItem *>(item->nextSibling());
265 } 265 }
266 } 266 }
267 return m_odd; 267 return m_odd;
268 } 268 }
269 return false; 269 return false;
270#else 270#else
271 return false; 271 return false;
272#endif 272#endif
273} 273}
274 274
275void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 275void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
276{ 276{
277 QColorGroup _cg = cg; 277 QColorGroup _cg = cg;
278 QColorGroup::ColorRole role; 278 QColorGroup::ColorRole role;
279 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor ) 279 if ( KOPrefs::instance()->mTodoViewUsesForegroundColor )
280 role = QColorGroup::Text; 280 role = QColorGroup::Text;
281 else 281 else
282 role = QColorGroup::Base; 282 role = QColorGroup::Base;
283 //#ifndef KORG_NOLVALTERNATION 283 //#ifndef KORG_NOLVALTERNATION
284 // if (isAlternate()) 284 // if (isAlternate())
285 // _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground()); 285 // _cg.setColor(QColorGroup::Base, static_cast< KOTodoListView* >(listView())->alternateBackground());
286 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors; 286 bool setColor = KOPrefs::instance()->mTodoViewUsesCatColors;
287 QColor colorToSet; 287 QColor colorToSet;
288 if ( setColor ) { 288 if ( setColor ) {
289 QStringList categories = mTodo->categories(); 289 QStringList categories = mTodo->categories();
290 QString cat = categories.first(); 290 QString cat = categories.first();
291 if ( !cat.isEmpty()) { 291 if ( !cat.isEmpty()) {
292 colorToSet = *(KOPrefs::instance()->categoryColor(cat) ); 292 colorToSet = *(KOPrefs::instance()->categoryColor(cat) );
293 } else 293 } else
294 setColor = false; 294 setColor = false;
295 } 295 }
296 if (mTodo->hasDueDate()) { 296 if (mTodo->hasDueDate()) {
297 if (mTodo->dtDue().date()==QDate::currentDate() && 297 if (mTodo->dtDue().date()==QDate::currentDate() &&
298 !mTodo->isCompleted()) { 298 !mTodo->isCompleted()) {
299 //_cg.setColor( role , KOPrefs::instance()->mTodoDueTodayColor); 299 //_cg.setColor( role , KOPrefs::instance()->mTodoDueTodayColor);
300 colorToSet = KOPrefs::instance()->mTodoDueTodayColor; 300 colorToSet = KOPrefs::instance()->mTodoDueTodayColor;
301 setColor = true; 301 setColor = true;
302 } 302 }
303 if (mTodo->dtDue().date() < QDate::currentDate() && 303 if (mTodo->dtDue().date() < QDate::currentDate() &&
304 !mTodo->isCompleted()) { 304 !mTodo->isCompleted()) {
305 //_cg.setColor( role, KOPrefs::instance()->mTodoOverdueColor); 305 //_cg.setColor( role, KOPrefs::instance()->mTodoOverdueColor);
306 colorToSet = KOPrefs::instance()->mTodoOverdueColor; 306 colorToSet = KOPrefs::instance()->mTodoOverdueColor;
307 setColor = true; 307 setColor = true;
308 } 308 }
309 } 309 }
310 310
311 if ( setColor ) { 311 if ( setColor ) {
312 _cg.setColor(role,colorToSet ); 312 _cg.setColor(role,colorToSet );
313 if ( role == QColorGroup::Base) { 313 if ( role == QColorGroup::Base) {
314 int rgb = colorToSet.red(); 314 int rgb = colorToSet.red();
315 rgb += colorToSet.blue()/2; 315 rgb += colorToSet.blue()/2;
316 rgb += colorToSet.green(); 316 rgb += colorToSet.green();
317 if ( rgb < 200 ) 317 if ( rgb < 200 )
318 _cg.setColor(QColorGroup::Text,Qt::white ); 318 _cg.setColor(QColorGroup::Text,Qt::white );
319 } 319 }
320 } 320 }
321 //#endif 321 //#endif
322 if ( column > 0 ){ 322 if ( column > 0 ){
323 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) { 323 if ( column == 2 && !KOPrefs::instance()->mTodoViewShowsPercentage ) {
324 p->save(); 324 p->save();
325 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5); 325 int progress = (int)(( (width-6)*mTodo->percentComplete())/100.0 + 0.5);
326 326
327 p->fillRect( 0, 0, width, height(), _cg.base() ); // background 327 p->fillRect( 0, 0, width, height(), _cg.base() ); // background
328 // p->setPen(Qt::black ); //border 328 // p->setPen(Qt::black ); //border
329 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling 329 // p->setBrush( KOPrefs::instance()->mHighlightColorKGlobalSettings::baseColor() ); //filling
330 QColor fc = KOPrefs::instance()->mHighlightColor; 330 QColor fc = KOPrefs::instance()->mHighlightColor;
331 if ( mTodo->percentComplete() == 100 ) 331 if ( mTodo->percentComplete() == 100 )
332 fc = darkGreen; 332 fc = darkGreen;
333 p->drawRect( 2, 2, width-4, height()-4); 333 p->drawRect( 2, 2, width-4, height()-4);
334 p->fillRect( 3, 3, progress, height()-6, 334 p->fillRect( 3, 3, progress, height()-6,
335 fc ); 335 fc );
336 p->restore(); 336 p->restore();
337 } else { 337 } else {
338 QCheckListItem::paintCell(p, _cg, column, width, alignment); 338 QCheckListItem::paintCell(p, _cg, column, width, alignment);
339 } 339 }
340 return; 340 return;
341 } 341 }
342 342
343 int align = alignment; 343 int align = alignment;
344 344
345 if ( !p ) 345 if ( !p )
346 return; 346 return;
347 347
348 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) ); 348 p->fillRect( 0, 0, width, height(), _cg.brush( QColorGroup::Base ) );
349 349
350 QListView *lv = listView(); 350 QListView *lv = listView();
351 if ( !lv ) 351 if ( !lv )
352 return; 352 return;
353 int marg = 2;//lv->itemMargin(); 353 int marg = 2;//lv->itemMargin();
354 int r = 0; 354 int r = 0;
355 QCheckListItem::Type myType = QCheckListItem::CheckBox; 355 QCheckListItem::Type myType = QCheckListItem::CheckBox;
356 int BoxSize = 20; 356 int BoxSize = 20;
357 int boxOffset = 2; 357 int boxOffset = 2;
358 int xOffset = 2; 358 int xOffset = 2;
359 if (qApp->desktop()->width() < 300 ) { 359 if (qApp->desktop()->width() < 300 ) {
360 BoxSize = 14; 360 BoxSize = 14;
361 boxOffset = -1; 361 boxOffset = -1;
362 xOffset = 1; 362 xOffset = 1;
363 // marg = 0; 363 // marg = 0;
364 } 364 }
365 if ( height() < BoxSize ) { 365 if ( height() < BoxSize ) {
366 boxOffset = boxOffset - ((BoxSize - height())/2) ; 366 boxOffset = boxOffset - ((BoxSize - height())/2) ;
367 // qDebug("boxOffset %d height %d", boxOffset, height() ); 367 // qDebug("boxOffset %d height %d", boxOffset, height() );
368 BoxSize = height(); 368 BoxSize = height();
369 369
370 } 370 }
371 //bool winStyle = lv->style() == WindowsStyle; 371 //bool winStyle = lv->style() == WindowsStyle;
372 372
373 int lineStart = 5; 373 int lineStart = 5;
374 if ( myType == Controller ) { 374 if ( myType == Controller ) {
375 if ( !pixmap( 0 ) ) 375 if ( !pixmap( 0 ) )
376 r += BoxSize + 4; 376 r += BoxSize + 4;
377 } else { 377 } else {
378 ASSERT( lv ); //### 378 ASSERT( lv ); //###
379 //QFontMetrics fm( lv->font() ); 379 //QFontMetrics fm( lv->font() );
380 //int d = fm.height(); 380 //int d = fm.height();
381 int x = 0; 381 int x = 0;
382 int y = (height() - BoxSize) / 2; 382 int y = (height() - BoxSize) / 2;
383 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) ); 383 //p->setPen( QPen( _cg.text(), winStyle ? 2 : 1 ) );
384 if ( myType == CheckBox ) { 384 if ( myType == CheckBox ) {
385 if ( isEnabled() ) 385 if ( isEnabled() )
386 p->setPen( QPen( _cg.text(), 1 ) ); 386 p->setPen( QPen( _cg.text(), 1 ) );
387 else 387 else
388 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) ); 388 p->setPen( QPen( listView()->palette().color( QPalette::Disabled, QColorGroup::Text ), 1 ) );
389 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); 389 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
390 lineStart = x+marg; 390 lineStart = x+marg;
391 ///////////////////// 391 /////////////////////
392 x++; 392 x++;
393 y++; 393 y++;
394 if ( isOn() ) { 394 if ( isOn() ) {
395 QPointArray a( 7*2 ); 395 QPointArray a( 7*2 );
396 int i, xx, yy; 396 int i, xx, yy;
397 xx = x+xOffset+marg+(boxOffset/2); 397 xx = x+xOffset+marg+(boxOffset/2);
398 yy = y+5+boxOffset; 398 yy = y+5+boxOffset;
399 for ( i=0; i<3; i++ ) { 399 for ( i=0; i<3; i++ ) {
400 a.setPoint( 2*i, xx, yy ); 400 a.setPoint( 2*i, xx, yy );
401 a.setPoint( 2*i+1, xx, yy+2 ); 401 a.setPoint( 2*i+1, xx, yy+2 );
402 // qDebug(" "); 402 // qDebug(" ");
403 xx++; yy++; 403 xx++; yy++;
404 } 404 }
405 yy -= 2; 405 yy -= 2;
406 for ( i=3; i<7; i++ ) { 406 for ( i=3; i<7; i++ ) {
407 a.setPoint( 2*i, xx, yy ); 407 a.setPoint( 2*i, xx, yy );
408 a.setPoint( 2*i+1, xx, yy+2 ); 408 a.setPoint( 2*i+1, xx, yy+2 );
409 xx++; yy--; 409 xx++; yy--;
410 } 410 }
411 p->setPen( darkGreen ); 411 p->setPen( darkGreen );
412 p->drawLineSegments( a ); 412 p->drawLineSegments( a );
413 } 413 }
414 //////////////////////// 414 ////////////////////////
415 } 415 }
416 r += BoxSize + 4; 416 r += BoxSize + 4;
417 } 417 }
418 418
419 p->translate( r, 0 ); 419 p->translate( r, 0 );
420 p->setPen( QPen( _cg.text() ) ); 420 p->setPen( QPen( _cg.text() ) );
421 QListViewItem::paintCell( p, _cg, column, width - r, align ); 421 QListViewItem::paintCell( p, _cg, column, width - r, align );
422 if ( mTodo->cancelled () ) { 422 if ( mTodo->cancelled () ) {
423 p->setPen( black ); 423 p->setPen( black );
424 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() ); 424 QRect br = p->boundingRect( 1,1,1,1,0,mTodo->summary() );
425 int wid = br.width() +lineStart; 425 int wid = br.width() +lineStart;
426 if ( wid > width-3 ) 426 if ( wid > width-3 )
427 wid = width-3; 427 wid = width-3;
428 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 ); 428 p->drawLine( lineStart, height()/2+1, wid, height()/2+1 );
429 429
430 } 430 }
431 431
432} 432}
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 24b8349..c2ee2c9 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,1009 +1,1012 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "sharpformat.h" 44#include "sharpformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY 49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
51 51
52//ARSD silentalarm = 0 52//ARSD silentalarm = 0
53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly 53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
54// 12 RFRQ 54// 12 RFRQ
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 } 67 }
68 68
69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
70 { 70 {
71 int i = 1; 71 int i = 1;
72 bool skip = true; 72 bool skip = true;
73 int max = attList.count() -2; 73 int max = attList.count() -2;
74 while ( i < max ) { 74 while ( i < max ) {
75 if ( !attList[i].isEmpty() ) { 75 if ( !attList[i].isEmpty() ) {
76 skip = false; 76 skip = false;
77 break; 77 break;
78 } 78 }
79 ++i ; 79 ++i ;
80 } 80 }
81 if ( skip ) 81 if ( skip )
82 return false; 82 return false;
83 ulong cSum = SharpFormat::getCsum(attList ); 83 ulong cSum = SharpFormat::getCsum(attList );
84 84
85 if ( qName == "Event" ) { 85 if ( qName == "Event" ) {
86 Event *event; 86 Event *event;
87 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 87 event = existingCalendar->event( "Sharp_DTM",attList[0] );
88 if ( event ) 88 if ( event )
89 event = (Event*)event->clone(); 89 event = (Event*)event->clone();
90 else 90 else
91 event = new Event; 91 event = new Event;
92 event->setID("Sharp_DTM", attList[0] ); 92 event->setID("Sharp_DTM", attList[0] );
93 event->setCsum( "Sharp_DTM", QString::number( cSum )); 93 event->setCsum( "Sharp_DTM", QString::number( cSum ));
94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
95 95
96 event->setSummary( attList[2] ); 96 event->setSummary( attList[2] );
97 event->setLocation( attList[3] ); 97 event->setLocation( attList[3] );
98 event->setDescription( attList[4] ); 98 event->setDescription( attList[4] );
99 if ( attList[7] == "1" ) { 99 if ( attList[7] == "1" ) {
100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
102 event->setFloats( true ); 102 event->setFloats( true );
103 } else { 103 } else {
104 event->setFloats( false ); 104 event->setFloats( false );
105 event->setDtStart( fromString( attList[5] ) ); 105 event->setDtStart( fromString( attList[5] ) );
106 event->setDtEnd( fromString( attList[6] )); 106 event->setDtEnd( fromString( attList[6] ));
107 } 107 }
108 108
109 QString rtype = attList[11]; 109 QString rtype = attList[11];
110 if ( rtype != "255" ) { 110 if ( rtype != "255" ) {
111 // qDebug("recurs "); 111 // qDebug("recurs ");
112 QDate startDate = event->dtStart().date(); 112 QDate startDate = event->dtStart().date();
113 113
114 QString freqStr = attList[12]; 114 QString freqStr = attList[12];
115 int freq = freqStr.toInt(); 115 int freq = freqStr.toInt();
116 116
117 QString hasEndDateStr = attList[15] ; 117 QString hasEndDateStr = attList[15] ;
118 bool hasEndDate = hasEndDateStr == "1"; 118 bool hasEndDate = hasEndDateStr == "1";
119 119
120 QString endDateStr = attList[16]; 120 QString endDateStr = attList[16];
121 QDate endDate = fromString( endDateStr ).date(); 121 QDate endDate = fromString( endDateStr ).date();
122 122
123 QString weekDaysStr = attList[14]; 123 QString weekDaysStr = attList[14];
124 uint weekDaysNum = weekDaysStr.toInt(); 124 uint weekDaysNum = weekDaysStr.toInt();
125 125
126 QBitArray weekDays( 7 ); 126 QBitArray weekDays( 7 );
127 int i; 127 int i;
128 int bb = 1; 128 int bb = 1;
129 for( i = 1; i <= 7; ++i ) { 129 for( i = 1; i <= 7; ++i ) {
130 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 130 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
131 bb = 2 << (i-1); 131 bb = 2 << (i-1);
132 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 132 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
133 } 133 }
134 // qDebug("next "); 134 // qDebug("next ");
135 QString posStr = attList[13]; 135 QString posStr = attList[13];
136 int pos = posStr.toInt(); 136 int pos = posStr.toInt();
137 Recurrence *r = event->recurrence(); 137 Recurrence *r = event->recurrence();
138 138
139 if ( rtype == "0" ) { 139 if ( rtype == "0" ) {
140 if ( hasEndDate ) r->setDaily( freq, endDate ); 140 if ( hasEndDate ) r->setDaily( freq, endDate );
141 else r->setDaily( freq, -1 ); 141 else r->setDaily( freq, -1 );
142 } else if ( rtype == "1" ) { 142 } else if ( rtype == "1" ) {
143 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 143 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
144 else r->setWeekly( freq, weekDays, -1 ); 144 else r->setWeekly( freq, weekDays, -1 );
145 } else if ( rtype == "3" ) { 145 } else if ( rtype == "3" ) {
146 if ( hasEndDate ) 146 if ( hasEndDate )
147 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 147 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
148 else 148 else
149 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 149 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
150 r->addMonthlyDay( startDate.day() ); 150 r->addMonthlyDay( startDate.day() );
151 } else if ( rtype == "2" ) { 151 } else if ( rtype == "2" ) {
152 if ( hasEndDate ) 152 if ( hasEndDate )
153 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 153 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
154 else 154 else
155 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 155 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
156 QBitArray days( 7 ); 156 QBitArray days( 7 );
157 days.fill( false ); 157 days.fill( false );
158 days.setBit( startDate.dayOfWeek() - 1 ); 158 days.setBit( startDate.dayOfWeek() - 1 );
159 r->addMonthlyPos( pos, days ); 159 r->addMonthlyPos( pos, days );
160 } else if ( rtype == "4" ) { 160 } else if ( rtype == "4" ) {
161 if ( hasEndDate ) 161 if ( hasEndDate )
162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
163 else 163 else
164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
165 r->addYearlyNum( startDate.month() ); 165 r->addYearlyNum( startDate.month() );
166 } 166 }
167 } else { 167 } else {
168 event->recurrence()->unsetRecurs(); 168 event->recurrence()->unsetRecurs();
169 } 169 }
170 170
171 QString categoryList = attList[1] ; 171 QString categoryList = attList[1] ;
172 event->setCategories( categoryList ); 172 event->setCategories( categoryList );
173 173
174 // strange 0 semms to mean: alarm enabled 174 // strange 0 semms to mean: alarm enabled
175 if ( attList[8] == "0" ) { 175 if ( attList[8] == "0" ) {
176 Alarm *alarm; 176 Alarm *alarm;
177 if ( event->alarms().count() > 0 ) 177 if ( event->alarms().count() > 0 )
178 alarm = event->alarms().first(); 178 alarm = event->alarms().first();
179 else { 179 else {
180 alarm = new Alarm( event ); 180 alarm = new Alarm( event );
181 event->addAlarm( alarm ); 181 event->addAlarm( alarm );
182 alarm->setType( Alarm::Audio ); 182 alarm->setType( Alarm::Audio );
183 } 183 }
184 //alarm->setType( Alarm::Audio ); 184 //alarm->setType( Alarm::Audio );
185 alarm->setEnabled( true ); 185 alarm->setEnabled( true );
186 int alarmOffset = attList[9].toInt(); 186 int alarmOffset = attList[9].toInt();
187 alarm->setStartOffset( alarmOffset * -60 ); 187 alarm->setStartOffset( alarmOffset * -60 );
188 } else { 188 } else {
189 Alarm *alarm; 189 Alarm *alarm;
190 if ( event->alarms().count() > 0 ) { 190 if ( event->alarms().count() > 0 ) {
191 alarm = event->alarms().first(); 191 alarm = event->alarms().first();
192 alarm->setType( Alarm::Audio ); 192 alarm->setType( Alarm::Audio );
193 alarm->setStartOffset( -60*15 ); 193 alarm->setStartOffset( -60*15 );
194 alarm->setEnabled( false ); 194 alarm->setEnabled( false );
195 } 195 }
196 } 196 }
197 197
198 mCalendar->addEvent( event); 198 mCalendar->addEvent( event);
199 } else if ( qName == "Todo" ) { 199 } else if ( qName == "Todo" ) {
200 Todo *todo; 200 Todo *todo;
201 201
202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
203 if (todo ) 203 if (todo )
204 todo = (Todo*)todo->clone(); 204 todo = (Todo*)todo->clone();
205 else 205 else
206 todo = new Todo; 206 todo = new Todo;
207 207
208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
209// 0 1 2 3 4 5 6 7 8 209// 0 1 2 3 4 5 6 7 8
210//1,,,,,1,4,Loch zumachen,"" 210//1,,,,,1,4,Loch zumachen,""
211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
213 213
214 todo->setID( "Sharp_DTM", attList[0]); 214 todo->setID( "Sharp_DTM", attList[0]);
215 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 215 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
217 217
218 todo->setSummary( attList[7] ); 218 todo->setSummary( attList[7] );
219 todo->setDescription( attList[8]); 219 todo->setDescription( attList[8]);
220 220
221 int priority = attList[6].toInt(); 221 int priority = attList[6].toInt();
222 if ( priority == 0 ) priority = 3; 222 if ( priority == 0 ) priority = 3;
223 todo->setPriority( priority ); 223 todo->setPriority( priority );
224 224
225 QString categoryList = attList[1]; 225 QString categoryList = attList[1];
226 todo->setCategories( categoryList ); 226 todo->setCategories( categoryList );
227 227
228 228
229 229
230 QString hasDateStr = attList[3]; // due 230 QString hasDateStr = attList[3]; // due
231 if ( !hasDateStr.isEmpty() ) { 231 if ( !hasDateStr.isEmpty() ) {
232 if ( hasDateStr.right(6) == "000000" ) { 232 if ( hasDateStr.right(6) == "000000" ) {
233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
234 todo->setFloats( true ); 234 todo->setFloats( true );
235 } 235 }
236 else { 236 else {
237 todo->setDtDue( fromString( hasDateStr ) ); 237 todo->setDtDue( fromString( hasDateStr ) );
238 todo->setFloats( false ); 238 todo->setFloats( false );
239 } 239 }
240 240
241 todo->setHasDueDate( true ); 241 todo->setHasDueDate( true );
242 } 242 }
243 hasDateStr = attList[2];//start 243 hasDateStr = attList[2];//start
244 if ( !hasDateStr.isEmpty() ) { 244 if ( !hasDateStr.isEmpty() ) {
245 245
246 todo->setDtStart( fromString( hasDateStr ) ); 246 todo->setDtStart( fromString( hasDateStr ) );
247 todo->setHasStartDate( true); 247 todo->setHasStartDate( true);
248 } else 248 } else
249 todo->setHasStartDate( false ); 249 todo->setHasStartDate( false );
250 hasDateStr = attList[4];//completed 250 hasDateStr = attList[4];//completed
251 if ( !hasDateStr.isEmpty() ) { 251 if ( !hasDateStr.isEmpty() ) {
252 todo->setCompleted(fromString( hasDateStr ) ); 252 todo->setCompleted(fromString( hasDateStr ) );
253 } 253 }
254 QString completedStr = attList[5]; 254 QString completedStr = attList[5];
255 if ( completedStr == "0" ) 255 if ( completedStr == "0" )
256 todo->setCompleted( true ); 256 todo->setCompleted( true );
257 else 257 else {
258 todo->setCompleted( false ); 258 // do not change percent complete
259 if ( todo->isCompleted() )
260 todo->setCompleted( false );
261 }
259 mCalendar->addTodo( todo ); 262 mCalendar->addTodo( todo );
260 263
261 } else if ( qName == "Category" ) { 264 } else if ( qName == "Category" ) {
262 /* 265 /*
263 QString id = attributes.value( "id" ); 266 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 267 QString name = attributes.value( "name" );
265 setCategory( id, name ); 268 setCategory( id, name );
266 */ 269 */
267 } 270 }
268 //qDebug("end "); 271 //qDebug("end ");
269 return true; 272 return true;
270 } 273 }
271 274
272 275
273 QDateTime fromString ( QString s, bool useTz = true ) { 276 QDateTime fromString ( QString s, bool useTz = true ) {
274 QDateTime dt; 277 QDateTime dt;
275 int y,m,t,h,min,sec; 278 int y,m,t,h,min,sec;
276 y = s.mid(0,4).toInt(); 279 y = s.mid(0,4).toInt();
277 m = s.mid(4,2).toInt(); 280 m = s.mid(4,2).toInt();
278 t = s.mid(6,2).toInt(); 281 t = s.mid(6,2).toInt();
279 h = s.mid(9,2).toInt(); 282 h = s.mid(9,2).toInt();
280 min = s.mid(11,2).toInt(); 283 min = s.mid(11,2).toInt();
281 sec = s.mid(13,2).toInt(); 284 sec = s.mid(13,2).toInt();
282 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 285 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
283 int offset = KGlobal::locale()->localTimeOffset( dt ); 286 int offset = KGlobal::locale()->localTimeOffset( dt );
284 if ( useTz ) 287 if ( useTz )
285 dt = dt.addSecs ( offset*60); 288 dt = dt.addSecs ( offset*60);
286 return dt; 289 return dt;
287 290
288 } 291 }
289 protected: 292 protected:
290 QDateTime toDateTime( const QString &value ) 293 QDateTime toDateTime( const QString &value )
291 { 294 {
292 QDateTime dt; 295 QDateTime dt;
293 dt.setTime_t( value.toUInt() ); 296 dt.setTime_t( value.toUInt() );
294 297
295 return dt; 298 return dt;
296 } 299 }
297 300
298 private: 301 private:
299 Calendar *mCalendar; 302 Calendar *mCalendar;
300}; 303};
301 304
302 305
303SharpFormat::SharpFormat() 306SharpFormat::SharpFormat()
304{ 307{
305 308
306} 309}
307 310
308SharpFormat::~SharpFormat() 311SharpFormat::~SharpFormat()
309{ 312{
310} 313}
311ulong SharpFormat::getCsum( const QStringList & attList) 314ulong SharpFormat::getCsum( const QStringList & attList)
312{ 315{
313 int max = attList.count() -1; 316 int max = attList.count() -1;
314 ulong cSum = 0; 317 ulong cSum = 0;
315 int j,k,i; 318 int j,k,i;
316 int add; 319 int add;
317 for ( i = 1; i < max ; ++i ) { 320 for ( i = 1; i < max ; ++i ) {
318 QString s = attList[i]; 321 QString s = attList[i];
319 if ( ! s.isEmpty() ){ 322 if ( ! s.isEmpty() ){
320 j = s.length(); 323 j = s.length();
321 for ( k = 0; k < j; ++k ) { 324 for ( k = 0; k < j; ++k ) {
322 int mul = k +1; 325 int mul = k +1;
323 add = s[k].unicode (); 326 add = s[k].unicode ();
324 if ( k < 16 ) 327 if ( k < 16 )
325 mul = mul * mul; 328 mul = mul * mul;
326 add = add * mul *i*i*i; 329 add = add * mul *i*i*i;
327 cSum += add; 330 cSum += add;
328 } 331 }
329 } 332 }
330 } 333 }
331 return cSum; 334 return cSum;
332 335
333} 336}
334#include <stdlib.h> 337#include <stdlib.h>
335#define DEBUGMODE false 338#define DEBUGMODE false
336//#define DEBUGMODE true 339//#define DEBUGMODE true
337bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 340bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
338{ 341{
339 342
340 343
341 bool debug = DEBUGMODE; 344 bool debug = DEBUGMODE;
342 QString text; 345 QString text;
343 QString codec = "utf8"; 346 QString codec = "utf8";
344 QLabel status ( i18n("Reading events ..."), 0 ); 347 QLabel status ( i18n("Reading events ..."), 0 );
345 348
346 int w = status.sizeHint().width()+20 ; 349 int w = status.sizeHint().width()+20 ;
347 if ( w < 200 ) w = 200; 350 if ( w < 200 ) w = 200;
348 int h = status.sizeHint().height()+20 ; 351 int h = status.sizeHint().height()+20 ;
349 int dw = QApplication::desktop()->width(); 352 int dw = QApplication::desktop()->width();
350 int dh = QApplication::desktop()->height(); 353 int dh = QApplication::desktop()->height();
351 status.setCaption(i18n("Reading DTM Data") ); 354 status.setCaption(i18n("Reading DTM Data") );
352 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 355 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
353 status.show(); 356 status.show();
354 status.raise(); 357 status.raise();
355 qApp->processEvents(); 358 qApp->processEvents();
356 QString fileName; 359 QString fileName;
357 if ( ! debug ) { 360 if ( ! debug ) {
358 fileName = "/tmp/kopitempout"; 361 fileName = "/tmp/kopitempout";
359 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 362 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
360 system ( command.latin1() ); 363 system ( command.latin1() );
361 } else { 364 } else {
362 fileName = "/tmp/events.txt"; 365 fileName = "/tmp/events.txt";
363 366
364 } 367 }
365 QFile file( fileName ); 368 QFile file( fileName );
366 if (!file.open( IO_ReadOnly ) ) { 369 if (!file.open( IO_ReadOnly ) ) {
367 return false; 370 return false;
368 371
369 } 372 }
370 QTextStream ts( &file ); 373 QTextStream ts( &file );
371 ts.setCodec( QTextCodec::codecForName("utf8") ); 374 ts.setCodec( QTextCodec::codecForName("utf8") );
372 text = ts.read(); 375 text = ts.read();
373 file.close(); 376 file.close();
374 status.setText( i18n("Processing events ...") ); 377 status.setText( i18n("Processing events ...") );
375 status.raise(); 378 status.raise();
376 qApp->processEvents(); 379 qApp->processEvents();
377 fromString2Cal( calendar, existngCal, text, "Event" ); 380 fromString2Cal( calendar, existngCal, text, "Event" );
378 status.setText( i18n("Reading todos ...") ); 381 status.setText( i18n("Reading todos ...") );
379 qApp->processEvents(); 382 qApp->processEvents();
380 if ( ! debug ) { 383 if ( ! debug ) {
381 fileName = "/tmp/kopitempout"; 384 fileName = "/tmp/kopitempout";
382 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 385 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
383 system ( command.latin1() ); 386 system ( command.latin1() );
384 } else { 387 } else {
385 fileName = "/tmp/todo.txt"; 388 fileName = "/tmp/todo.txt";
386 } 389 }
387 file.setName( fileName ); 390 file.setName( fileName );
388 if (!file.open( IO_ReadOnly ) ) { 391 if (!file.open( IO_ReadOnly ) ) {
389 return false; 392 return false;
390 393
391 } 394 }
392 ts.setDevice( &file ); 395 ts.setDevice( &file );
393 text = ts.read(); 396 text = ts.read();
394 file.close(); 397 file.close();
395 398
396 status.setText( i18n("Processing todos ...") ); 399 status.setText( i18n("Processing todos ...") );
397 status.raise(); 400 status.raise();
398 qApp->processEvents(); 401 qApp->processEvents();
399 fromString2Cal( calendar, existngCal, text, "Todo" ); 402 fromString2Cal( calendar, existngCal, text, "Todo" );
400 return true; 403 return true;
401} 404}
402int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 405int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
403{ 406{
404 int retval = -1; 407 int retval = -1;
405 QStringList templist; 408 QStringList templist;
406 QString tempString; 409 QString tempString;
407 int start = 0; 410 int start = 0;
408 int len = answer.length(); 411 int len = answer.length();
409 int end = answer.find ("\n",start)+1; 412 int end = answer.find ("\n",start)+1;
410 bool ok = true; 413 bool ok = true;
411 start = end; 414 start = end;
412 int ccc = 0; 415 int ccc = 0;
413 while ( start > 0 ) { 416 while ( start > 0 ) {
414 templist.clear(); 417 templist.clear();
415 ok = true; 418 ok = true;
416 int loopCount = 0; 419 int loopCount = 0;
417 while ( ok ) { 420 while ( ok ) {
418 ++loopCount; 421 ++loopCount;
419 if ( loopCount > 25 ) { 422 if ( loopCount > 25 ) {
420 qDebug("KO: Error in while loop"); 423 qDebug("KO: Error in while loop");
421 ok = false; 424 ok = false;
422 start = 0; 425 start = 0;
423 break; 426 break;
424 } 427 }
425 if ( ok ) 428 if ( ok )
426 tempString = getPart( answer, ok, start ); 429 tempString = getPart( answer, ok, start );
427 if ( start >= len || start == 0 ) { 430 if ( start >= len || start == 0 ) {
428 start = 0; 431 start = 0;
429 ok = false; 432 ok = false;
430 } 433 }
431 if ( tempString.right(1) =="\n" ) 434 if ( tempString.right(1) =="\n" )
432 tempString = tempString.left( tempString.length()-1); 435 tempString = tempString.left( tempString.length()-1);
433 436
434 templist.append( tempString ); 437 templist.append( tempString );
435 } 438 }
436 ++ccc; 439 ++ccc;
437 if ( ccc == 2 && loopCount < 25 ) { 440 if ( ccc == 2 && loopCount < 25 ) {
438 start = 0; 441 start = 0;
439 bool ok; 442 bool ok;
440 int newnum = templist[0].toInt( &ok ); 443 int newnum = templist[0].toInt( &ok );
441 if ( ok && newnum > 0) { 444 if ( ok && newnum > 0) {
442 retval = newnum; 445 retval = newnum;
443 inc->setID( "Sharp_DTM",templist[0] ); 446 inc->setID( "Sharp_DTM",templist[0] );
444 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 447 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
445 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 448 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
446 } 449 }
447 if ( ok && newnum == -1 ) { 450 if ( ok && newnum == -1 ) {
448 qDebug("Error writing back %s ", inc->summary().latin1()); 451 qDebug("Error writing back %s ", inc->summary().latin1());
449 } 452 }
450 } 453 }
451 } 454 }
452 //qDebug("getNumFromRecord returning : %d ", retval); 455 //qDebug("getNumFromRecord returning : %d ", retval);
453 return retval; 456 return retval;
454} 457}
455bool SharpFormat::save( Calendar *calendar) 458bool SharpFormat::save( Calendar *calendar)
456{ 459{
457 460
458 QLabel status ( i18n("Processing/adding events ..."), 0 ); 461 QLabel status ( i18n("Processing/adding events ..."), 0 );
459 int w = status.sizeHint().width()+20 ; 462 int w = status.sizeHint().width()+20 ;
460 if ( w < 200 ) w = 200; 463 if ( w < 200 ) w = 200;
461 int h = status.sizeHint().height()+20 ; 464 int h = status.sizeHint().height()+20 ;
462 int dw = QApplication::desktop()->width(); 465 int dw = QApplication::desktop()->width();
463 int dh = QApplication::desktop()->height(); 466 int dh = QApplication::desktop()->height();
464 status.setCaption(i18n("Writing DTM Data") ); 467 status.setCaption(i18n("Writing DTM Data") );
465 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 468 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
466 status.show(); 469 status.show();
467 status.raise(); 470 status.raise();
468 qApp->processEvents(); 471 qApp->processEvents();
469 bool debug = DEBUGMODE; 472 bool debug = DEBUGMODE;
470 QString codec = "utf8"; 473 QString codec = "utf8";
471 QString answer; 474 QString answer;
472 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 475 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
473 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 476 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
474 QString command; 477 QString command;
475 QPtrList<Event> er = calendar->rawEvents(); 478 QPtrList<Event> er = calendar->rawEvents();
476 Event* ev = er.first(); 479 Event* ev = er.first();
477 QString fileName = "/tmp/kopitempout"; 480 QString fileName = "/tmp/kopitempout";
478 int i = 0; 481 int i = 0;
479 QString changeString = ePrefix; 482 QString changeString = ePrefix;
480 QString deleteString = ePrefix; 483 QString deleteString = ePrefix;
481 bool deleteEnt = false; 484 bool deleteEnt = false;
482 bool changeEnt = false; 485 bool changeEnt = false;
483 QString message = i18n("Processing event # "); 486 QString message = i18n("Processing event # ");
484 int procCount = 0; 487 int procCount = 0;
485 while ( ev ) { 488 while ( ev ) {
486 //qDebug("i %d ", ++i); 489 //qDebug("i %d ", ++i);
487 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 490 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
488 status.setText ( message + QString::number ( ++procCount ) ); 491 status.setText ( message + QString::number ( ++procCount ) );
489 qApp->processEvents(); 492 qApp->processEvents();
490 QString eString = getEventString( ev ); 493 QString eString = getEventString( ev );
491 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 494 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
492 // deleting empty strings does not work. 495 // deleting empty strings does not work.
493 // we write first and x and then delete the record with the x 496 // we write first and x and then delete the record with the x
494 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 497 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
495 changeString += eString + "\n"; 498 changeString += eString + "\n";
496 deleteString += eString + "\n"; 499 deleteString += eString + "\n";
497 deleteEnt = true; 500 deleteEnt = true;
498 changeEnt = true; 501 changeEnt = true;
499 } 502 }
500 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 503 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
501 QString fileNameIn = "/tmp/kopitempin"; 504 QString fileNameIn = "/tmp/kopitempin";
502 QFile fileIn( fileNameIn ); 505 QFile fileIn( fileNameIn );
503 if (!fileIn.open( IO_WriteOnly ) ) { 506 if (!fileIn.open( IO_WriteOnly ) ) {
504 return false; 507 return false;
505 } 508 }
506 QTextStream tsIn( &fileIn ); 509 QTextStream tsIn( &fileIn );
507 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 510 tsIn.setCodec( QTextCodec::codecForName("utf8") );
508 tsIn << ePrefix << eString ; 511 tsIn << ePrefix << eString ;
509 fileIn.close(); 512 fileIn.close();
510 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 513 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
511 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; 514 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
512 //qDebug("command ++++++++ "); 515 //qDebug("command ++++++++ ");
513 //qDebug("%s ",command.latin1()); 516 //qDebug("%s ",command.latin1());
514 //qDebug("command -------- "); 517 //qDebug("command -------- ");
515 system ( command.utf8() ); 518 system ( command.utf8() );
516 QFile file( fileName ); 519 QFile file( fileName );
517 if (!file.open( IO_ReadOnly ) ) { 520 if (!file.open( IO_ReadOnly ) ) {
518 return false; 521 return false;
519 522
520 } 523 }
521 QTextStream ts( &file ); 524 QTextStream ts( &file );
522 ts.setCodec( QTextCodec::codecForName("utf8") ); 525 ts.setCodec( QTextCodec::codecForName("utf8") );
523 answer = ts.read(); 526 answer = ts.read();
524 file.close(); 527 file.close();
525 //qDebug("answer \n%s ", answer.latin1()); 528 //qDebug("answer \n%s ", answer.latin1());
526 getNumFromRecord( answer, ev ) ; 529 getNumFromRecord( answer, ev ) ;
527 530
528 } 531 }
529 else { // change existing 532 else { // change existing
530 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 533 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
531 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 534 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
532 changeString += eString + "\n"; 535 changeString += eString + "\n";
533 changeEnt = true; 536 changeEnt = true;
534 537
535 } 538 }
536 } 539 }
537 ev = er.next(); 540 ev = er.next();
538 } 541 }
539 status.setText ( i18n("Changing events ...") ); 542 status.setText ( i18n("Changing events ...") );
540 qApp->processEvents(); 543 qApp->processEvents();
541 //qDebug("changing... "); 544 //qDebug("changing... ");
542 if ( changeEnt ) { 545 if ( changeEnt ) {
543 QFile file( fileName ); 546 QFile file( fileName );
544 if (!file.open( IO_WriteOnly ) ) { 547 if (!file.open( IO_WriteOnly ) ) {
545 return false; 548 return false;
546 549
547 } 550 }
548 QTextStream ts( &file ); 551 QTextStream ts( &file );
549 ts.setCodec( QTextCodec::codecForName("utf8") ); 552 ts.setCodec( QTextCodec::codecForName("utf8") );
550 ts << changeString ; 553 ts << changeString ;
551 file.close(); 554 file.close();
552 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 555 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
553 system ( command.latin1() ); 556 system ( command.latin1() );
554 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 557 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
555 558
556 } 559 }
557 status.setText ( i18n("Deleting events ...") ); 560 status.setText ( i18n("Deleting events ...") );
558 qApp->processEvents(); 561 qApp->processEvents();
559 //qDebug("deleting... "); 562 //qDebug("deleting... ");
560 if ( deleteEnt ) { 563 if ( deleteEnt ) {
561 QFile file( fileName ); 564 QFile file( fileName );
562 if (!file.open( IO_WriteOnly ) ) { 565 if (!file.open( IO_WriteOnly ) ) {
563 return false; 566 return false;
564 567
565 } 568 }
566 QTextStream ts( &file ); 569 QTextStream ts( &file );
567 ts.setCodec( QTextCodec::codecForName("utf8") ); 570 ts.setCodec( QTextCodec::codecForName("utf8") );
568 ts << deleteString; 571 ts << deleteString;
569 file.close(); 572 file.close();
570 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 573 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
571 system ( command.latin1() ); 574 system ( command.latin1() );
572 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 575 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
573 } 576 }
574 577
575 578
576 changeString = tPrefix; 579 changeString = tPrefix;
577 deleteString = tPrefix; 580 deleteString = tPrefix;
578 status.setText ( i18n("Processing todos ...") ); 581 status.setText ( i18n("Processing todos ...") );
579 qApp->processEvents(); 582 qApp->processEvents();
580 QPtrList<Todo> tl = calendar->rawTodos(); 583 QPtrList<Todo> tl = calendar->rawTodos();
581 Todo* to = tl.first(); 584 Todo* to = tl.first();
582 i = 0; 585 i = 0;
583 message = i18n("Processing todo # "); 586 message = i18n("Processing todo # ");
584 procCount = 0; 587 procCount = 0;
585 while ( to ) { 588 while ( to ) {
586 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 589 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
587 status.setText ( message + QString::number ( ++procCount ) ); 590 status.setText ( message + QString::number ( ++procCount ) );
588 qApp->processEvents(); 591 qApp->processEvents();
589 QString eString = getTodoString( to ); 592 QString eString = getTodoString( to );
590 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 593 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
591 // deleting empty strings does not work. 594 // deleting empty strings does not work.
592 // we write first and x and then delete the record with the x 595 // we write first and x and then delete the record with the x
593 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 596 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
594 changeString += eString + "\n"; 597 changeString += eString + "\n";
595 deleteString += eString + "\n"; 598 deleteString += eString + "\n";
596 deleteEnt = true; 599 deleteEnt = true;
597 changeEnt = true; 600 changeEnt = true;
598 } 601 }
599 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 602 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
600 603
601 604
602 605
603 QString fileNameIn = "/tmp/kopitempin"; 606 QString fileNameIn = "/tmp/kopitempin";
604 QFile fileIn( fileNameIn ); 607 QFile fileIn( fileNameIn );
605 if (!fileIn.open( IO_WriteOnly ) ) { 608 if (!fileIn.open( IO_WriteOnly ) ) {
606 return false; 609 return false;
607 } 610 }
608 QTextStream tsIn( &fileIn ); 611 QTextStream tsIn( &fileIn );
609 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 612 tsIn.setCodec( QTextCodec::codecForName("utf8") );
610 tsIn << tPrefix << eString ; 613 tsIn << tPrefix << eString ;
611 fileIn.close(); 614 fileIn.close();
612 command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; 615 command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName;
613 system ( command.utf8() ); 616 system ( command.utf8() );
614 QFile file( fileName ); 617 QFile file( fileName );
615 if (!file.open( IO_ReadOnly ) ) { 618 if (!file.open( IO_ReadOnly ) ) {
616 return false; 619 return false;
617 } 620 }
618 QTextStream ts( &file ); 621 QTextStream ts( &file );
619 ts.setCodec( QTextCodec::codecForName("utf8") ); 622 ts.setCodec( QTextCodec::codecForName("utf8") );
620 answer = ts.read(); 623 answer = ts.read();
621 file.close(); 624 file.close();
622 //qDebug("answer \n%s ", answer.latin1()); 625 //qDebug("answer \n%s ", answer.latin1());
623 getNumFromRecord( answer, to ) ; 626 getNumFromRecord( answer, to ) ;
624 627
625 } 628 }
626 else { // change existing 629 else { // change existing
627 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 630 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
628 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 631 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
629 changeString += eString + "\n"; 632 changeString += eString + "\n";
630 changeEnt = true; 633 changeEnt = true;
631 634
632 } 635 }
633 } 636 }
634 637
635 to = tl.next(); 638 to = tl.next();
636 } 639 }
637 status.setText ( i18n("Changing todos ...") ); 640 status.setText ( i18n("Changing todos ...") );
638 qApp->processEvents(); 641 qApp->processEvents();
639 //qDebug("changing... "); 642 //qDebug("changing... ");
640 if ( changeEnt ) { 643 if ( changeEnt ) {
641 QFile file( fileName ); 644 QFile file( fileName );
642 if (!file.open( IO_WriteOnly ) ) { 645 if (!file.open( IO_WriteOnly ) ) {
643 return false; 646 return false;
644 647
645 } 648 }
646 QTextStream ts( &file ); 649 QTextStream ts( &file );
647 ts.setCodec( QTextCodec::codecForName("utf8") ); 650 ts.setCodec( QTextCodec::codecForName("utf8") );
648 ts << changeString ; 651 ts << changeString ;
649 file.close(); 652 file.close();
650 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 653 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
651 system ( command.latin1() ); 654 system ( command.latin1() );
652 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 655 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
653 656
654 } 657 }
655 status.setText ( i18n("Deleting todos ...") ); 658 status.setText ( i18n("Deleting todos ...") );
656 qApp->processEvents(); 659 qApp->processEvents();
657 //qDebug("deleting... "); 660 //qDebug("deleting... ");
658 if ( deleteEnt ) { 661 if ( deleteEnt ) {
659 QFile file( fileName ); 662 QFile file( fileName );
660 if (!file.open( IO_WriteOnly ) ) { 663 if (!file.open( IO_WriteOnly ) ) {
661 return false; 664 return false;
662 665
663 } 666 }
664 QTextStream ts( &file ); 667 QTextStream ts( &file );
665 ts.setCodec( QTextCodec::codecForName("utf8") ); 668 ts.setCodec( QTextCodec::codecForName("utf8") );
666 ts << deleteString; 669 ts << deleteString;
667 file.close(); 670 file.close();
668 command = "db2file todo -d -c " + codec+ " < "+ fileName; 671 command = "db2file todo -d -c " + codec+ " < "+ fileName;
669 system ( command.latin1() ); 672 system ( command.latin1() );
670 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 673 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
671 } 674 }
672 675
673 return true; 676 return true;
674} 677}
675QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 678QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
676{ 679{
677 QString datestr; 680 QString datestr;
678 QString timestr; 681 QString timestr;
679 int offset = KGlobal::locale()->localTimeOffset( dti ); 682 int offset = KGlobal::locale()->localTimeOffset( dti );
680 QDateTime dt; 683 QDateTime dt;
681 if (useTZ) 684 if (useTZ)
682 dt = dti.addSecs ( -(offset*60)); 685 dt = dti.addSecs ( -(offset*60));
683 else 686 else
684 dt = dti; 687 dt = dti;
685 if(dt.date().isValid()){ 688 if(dt.date().isValid()){
686 const QDate& date = dt.date(); 689 const QDate& date = dt.date();
687 datestr.sprintf("%04d%02d%02d", 690 datestr.sprintf("%04d%02d%02d",
688 date.year(), date.month(), date.day()); 691 date.year(), date.month(), date.day());
689 } 692 }
690 if(dt.time().isValid()){ 693 if(dt.time().isValid()){
691 const QTime& time = dt.time(); 694 const QTime& time = dt.time();
692 timestr.sprintf("T%02d%02d%02d", 695 timestr.sprintf("T%02d%02d%02d",
693 time.hour(), time.minute(), time.second()); 696 time.hour(), time.minute(), time.second());
694 } 697 }
695 return datestr + timestr; 698 return datestr + timestr;
696} 699}
697QString SharpFormat::getEventString( Event* event ) 700QString SharpFormat::getEventString( Event* event )
698{ 701{
699 QStringList list; 702 QStringList list;
700 list.append( event->getID("Sharp_DTM") ); 703 list.append( event->getID("Sharp_DTM") );
701 list.append( event->categories().join(",") ); 704 list.append( event->categories().join(",") );
702 if ( !event->summary().isEmpty() ) 705 if ( !event->summary().isEmpty() )
703 list.append( event->summary() ); 706 list.append( event->summary() );
704 else 707 else
705 list.append("" ); 708 list.append("" );
706 if ( !event->location().isEmpty() ) 709 if ( !event->location().isEmpty() )
707 list.append( event->location() ); 710 list.append( event->location() );
708 else 711 else
709 list.append("" ); 712 list.append("" );
710 if ( !event->description().isEmpty() ) 713 if ( !event->description().isEmpty() )
711 list.append( event->description() ); 714 list.append( event->description() );
712 else 715 else
713 list.append( "" ); 716 list.append( "" );
714 if ( event->doesFloat () ) { 717 if ( event->doesFloat () ) {
715 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 718 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
716 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 719 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
717 list.append( "1" ); 720 list.append( "1" );
718 721
719 } 722 }
720 else { 723 else {
721 list.append( dtToString( event->dtStart()) ); 724 list.append( dtToString( event->dtStart()) );
722 list.append( dtToString( event->dtEnd()) ); //6 725 list.append( dtToString( event->dtEnd()) ); //6
723 list.append( "0" ); 726 list.append( "0" );
724 } 727 }
725 bool noAlarm = true; 728 bool noAlarm = true;
726 if ( event->alarms().count() > 0 ) { 729 if ( event->alarms().count() > 0 ) {
727 Alarm * al = event->alarms().first(); 730 Alarm * al = event->alarms().first();
728 if ( al->enabled() ) { 731 if ( al->enabled() ) {
729 noAlarm = false; 732 noAlarm = false;
730 list.append( "0" ); // yes, 0 == alarm 733 list.append( "0" ); // yes, 0 == alarm
731 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 734 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
732 if ( al->type() == Alarm::Audio ) 735 if ( al->type() == Alarm::Audio )
733 list.append( "1" ); // type audio 736 list.append( "1" ); // type audio
734 else 737 else
735 list.append( "0" ); // type silent 738 list.append( "0" ); // type silent
736 } 739 }
737 } 740 }
738 if ( noAlarm ) { 741 if ( noAlarm ) {
739 list.append( "1" ); // yes, 1 == no alarm 742 list.append( "1" ); // yes, 1 == no alarm
740 list.append( "0" ); // no alarm offset 743 list.append( "0" ); // no alarm offset
741 list.append( "1" ); // type 744 list.append( "1" ); // type
742 } 745 }
743 // next is: 11 746 // next is: 11
744 // next is: 11-16 are recurrence 747 // next is: 11-16 are recurrence
745 Recurrence* rec = event->recurrence(); 748 Recurrence* rec = event->recurrence();
746 749
747 bool writeEndDate = false; 750 bool writeEndDate = false;
748 switch ( rec->doesRecur() ) 751 switch ( rec->doesRecur() )
749 { 752 {
750 case Recurrence::rDaily: // 0 753 case Recurrence::rDaily: // 0
751 list.append( "0" ); 754 list.append( "0" );
752 list.append( QString::number( rec->frequency() ));//12 755 list.append( QString::number( rec->frequency() ));//12
753 list.append( "0" ); 756 list.append( "0" );
754 list.append( "0" ); 757 list.append( "0" );
755 writeEndDate = true; 758 writeEndDate = true;
756 break; 759 break;
757 case Recurrence::rWeekly:// 1 760 case Recurrence::rWeekly:// 1
758 list.append( "1" ); 761 list.append( "1" );
759 list.append( QString::number( rec->frequency()) );//12 762 list.append( QString::number( rec->frequency()) );//12
760 list.append( "0" ); 763 list.append( "0" );
761 { 764 {
762 int days = 0; 765 int days = 0;
763 QBitArray weekDays = rec->days(); 766 QBitArray weekDays = rec->days();
764 int i; 767 int i;
765 for( i = 1; i <= 7; ++i ) { 768 for( i = 1; i <= 7; ++i ) {
766 if ( weekDays[i-1] ) { 769 if ( weekDays[i-1] ) {
767 days += 1 << (i-1); 770 days += 1 << (i-1);
768 } 771 }
769 } 772 }
770 list.append( QString::number( days ) ); 773 list.append( QString::number( days ) );
771 } 774 }
772 //pending weekdays 775 //pending weekdays
773 writeEndDate = true; 776 writeEndDate = true;
774 777
775 break; 778 break;
776 case Recurrence::rMonthlyPos:// 2 779 case Recurrence::rMonthlyPos:// 2
777 list.append( "2" ); 780 list.append( "2" );
778 list.append( QString::number( rec->frequency()) );//12 781 list.append( QString::number( rec->frequency()) );//12
779 782
780 writeEndDate = true; 783 writeEndDate = true;
781 { 784 {
782 int count = 1; 785 int count = 1;
783 QPtrList<Recurrence::rMonthPos> rmp; 786 QPtrList<Recurrence::rMonthPos> rmp;
784 rmp = rec->monthPositions(); 787 rmp = rec->monthPositions();
785 if ( rmp.first()->negative ) 788 if ( rmp.first()->negative )
786 count = 5 - rmp.first()->rPos - 1; 789 count = 5 - rmp.first()->rPos - 1;
787 else 790 else
788 count = rmp.first()->rPos - 1; 791 count = rmp.first()->rPos - 1;
789 list.append( QString::number( count ) ); 792 list.append( QString::number( count ) );
790 793
791 } 794 }
792 795
793 list.append( "0" ); 796 list.append( "0" );
794 break; 797 break;
795 case Recurrence::rMonthlyDay:// 3 798 case Recurrence::rMonthlyDay:// 3
796 list.append( "3" ); 799 list.append( "3" );
797 list.append( QString::number( rec->frequency()) );//12 800 list.append( QString::number( rec->frequency()) );//12
798 list.append( "0" ); 801 list.append( "0" );
799 list.append( "0" ); 802 list.append( "0" );
800 writeEndDate = true; 803 writeEndDate = true;
801 break; 804 break;
802 case Recurrence::rYearlyMonth://4 805 case Recurrence::rYearlyMonth://4
803 list.append( "4" ); 806 list.append( "4" );
804 list.append( QString::number( rec->frequency()) );//12 807 list.append( QString::number( rec->frequency()) );//12
805 list.append( "0" ); 808 list.append( "0" );
806 list.append( "0" ); 809 list.append( "0" );
807 writeEndDate = true; 810 writeEndDate = true;
808 break; 811 break;
809 812
810 default: 813 default:
811 list.append( "255" ); 814 list.append( "255" );
812 list.append( QString() ); 815 list.append( QString() );
813 list.append( "0" ); 816 list.append( "0" );
814 list.append( QString() ); 817 list.append( QString() );
815 list.append( "0" ); 818 list.append( "0" );
816 list.append( "20991231T000000" ); 819 list.append( "20991231T000000" );
817 break; 820 break;
818 } 821 }
819 if ( writeEndDate ) { 822 if ( writeEndDate ) {
820 823
821 if ( rec->endDate().isValid() ) { // 15 + 16 824 if ( rec->endDate().isValid() ) { // 15 + 16
822 list.append( "1" ); 825 list.append( "1" );
823 list.append( dtToString( rec->endDate()) ); 826 list.append( dtToString( rec->endDate()) );
824 } else { 827 } else {
825 list.append( "0" ); 828 list.append( "0" );
826 list.append( "20991231T000000" ); 829 list.append( "20991231T000000" );
827 } 830 }
828 831
829 } 832 }
830 if ( event->doesFloat () ) { 833 if ( event->doesFloat () ) {
831 list.append( dtToString( event->dtStart(), false ).left( 8 )); 834 list.append( dtToString( event->dtStart(), false ).left( 8 ));
832 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 835 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
833 836
834 } 837 }
835 else { 838 else {
836 list.append( QString() ); 839 list.append( QString() );
837 list.append( QString() ); 840 list.append( QString() );
838 841
839 } 842 }
840 if (event->dtStart().date() == event->dtEnd().date() ) 843 if (event->dtStart().date() == event->dtEnd().date() )
841 list.append( "0" ); 844 list.append( "0" );
842 else 845 else
843 list.append( "1" ); 846 list.append( "1" );
844 847
845 848
846 for(QStringList::Iterator it=list.begin(); 849 for(QStringList::Iterator it=list.begin();
847 it!=list.end(); ++it){ 850 it!=list.end(); ++it){
848 QString& s = (*it); 851 QString& s = (*it);
849 s.replace(QRegExp("\""), "\"\""); 852 s.replace(QRegExp("\""), "\"\"");
850 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 853 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
851 s.prepend('\"'); 854 s.prepend('\"');
852 s.append('\"'); 855 s.append('\"');
853 } else if(s.isEmpty() && !s.isNull()){ 856 } else if(s.isEmpty() && !s.isNull()){
854 s = "\"\""; 857 s = "\"\"";
855 } 858 }
856 } 859 }
857 return list.join(","); 860 return list.join(",");
858 861
859 862
860} 863}
861QString SharpFormat::getTodoString( Todo* todo ) 864QString SharpFormat::getTodoString( Todo* todo )
862{ 865{
863 QStringList list; 866 QStringList list;
864 list.append( todo->getID("Sharp_DTM") ); 867 list.append( todo->getID("Sharp_DTM") );
865 list.append( todo->categories().join(",") ); 868 list.append( todo->categories().join(",") );
866 869
867 if ( todo->hasStartDate() ) { 870 if ( todo->hasStartDate() ) {
868 list.append( dtToString( todo->dtStart()) ); 871 list.append( dtToString( todo->dtStart()) );
869 } else 872 } else
870 list.append( QString() ); 873 list.append( QString() );
871 874
872 if ( todo->hasDueDate() ) { 875 if ( todo->hasDueDate() ) {
873 QTime tim; 876 QTime tim;
874 if ( todo->doesFloat()) { 877 if ( todo->doesFloat()) {
875 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 878 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
876 } else { 879 } else {
877 list.append( dtToString(todo->dtDue() ) ); 880 list.append( dtToString(todo->dtDue() ) );
878 } 881 }
879 } else 882 } else
880 list.append( QString() ); 883 list.append( QString() );
881 884
882 if ( todo->isCompleted() ) { 885 if ( todo->isCompleted() ) {
883 list.append( dtToString( todo->completed()) ); 886 list.append( dtToString( todo->completed()) );
884 list.append( "0" ); // yes 0 == completed 887 list.append( "0" ); // yes 0 == completed
885 } else { 888 } else {
886 list.append( dtToString( todo->completed()) ); 889 list.append( dtToString( todo->completed()) );
887 list.append( "1" ); 890 list.append( "1" );
888 } 891 }
889 list.append( QString::number( todo->priority() )); 892 list.append( QString::number( todo->priority() ));
890 if( ! todo->summary().isEmpty() ) 893 if( ! todo->summary().isEmpty() )
891 list.append( todo->summary() ); 894 list.append( todo->summary() );
892 else 895 else
893 list.append( "" ); 896 list.append( "" );
894 if (! todo->description().isEmpty() ) 897 if (! todo->description().isEmpty() )
895 list.append( todo->description() ); 898 list.append( todo->description() );
896 else 899 else
897 list.append( "" ); 900 list.append( "" );
898 for(QStringList::Iterator it=list.begin(); 901 for(QStringList::Iterator it=list.begin();
899 it!=list.end(); ++it){ 902 it!=list.end(); ++it){
900 QString& s = (*it); 903 QString& s = (*it);
901 s.replace(QRegExp("\""), "\"\""); 904 s.replace(QRegExp("\""), "\"\"");
902 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 905 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
903 s.prepend('\"'); 906 s.prepend('\"');
904 s.append('\"'); 907 s.append('\"');
905 } else if(s.isEmpty() && !s.isNull()){ 908 } else if(s.isEmpty() && !s.isNull()){
906 s = "\"\""; 909 s = "\"\"";
907 } 910 }
908 } 911 }
909 return list.join(","); 912 return list.join(",");
910} 913}
911QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) 914QString SharpFormat::getPart( const QString & text, bool &ok, int &start )
912{ 915{
913 //qDebug("start %d ", start); 916 //qDebug("start %d ", start);
914 917
915 QString retval =""; 918 QString retval ="";
916 if ( text.at(start) == '"' ) { 919 if ( text.at(start) == '"' ) {
917 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { 920 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
918 start = start +2; 921 start = start +2;
919 if ( text.mid( start,1) == "," ) { 922 if ( text.mid( start,1) == "," ) {
920 start += 1; 923 start += 1;
921 } 924 }
922 retval = ""; 925 retval = "";
923 if ( text.mid( start,1) == "\n" ) { 926 if ( text.mid( start,1) == "\n" ) {
924 start += 1; 927 start += 1;
925 ok = false; 928 ok = false;
926 } 929 }
927 return retval; 930 return retval;
928 } 931 }
929 int hk = start+1; 932 int hk = start+1;
930 hk = text.find ('"',hk); 933 hk = text.find ('"',hk);
931 while ( text.at(hk+1) == '"' ) 934 while ( text.at(hk+1) == '"' )
932 hk = text.find ('"',hk+2); 935 hk = text.find ('"',hk+2);
933 retval = text.mid( start+1, hk-start-1); 936 retval = text.mid( start+1, hk-start-1);
934 start = hk+1; 937 start = hk+1;
935 retval.replace( QRegExp("\"\""), "\""); 938 retval.replace( QRegExp("\"\""), "\"");
936 if ( text.mid( start,1) == "," ) { 939 if ( text.mid( start,1) == "," ) {
937 start += 1; 940 start += 1;
938 } 941 }
939 if ( text.mid( start,1) == "\n" ) { 942 if ( text.mid( start,1) == "\n" ) {
940 start += 1; 943 start += 1;
941 ok = false; 944 ok = false;
942 } 945 }
943 //qDebug("retval***%s*** ",retval.latin1() ); 946 //qDebug("retval***%s*** ",retval.latin1() );
944 return retval; 947 return retval;
945 948
946 } else { 949 } else {
947 int nl = text.find ("\n",start); 950 int nl = text.find ("\n",start);
948 int kom = text.find (',',start); 951 int kom = text.find (',',start);
949 if ( kom < nl ) { 952 if ( kom < nl ) {
950 // qDebug("kom < nl %d ", kom); 953 // qDebug("kom < nl %d ", kom);
951 retval = text.mid(start, kom-start); 954 retval = text.mid(start, kom-start);
952 start = kom+1; 955 start = kom+1;
953 return retval; 956 return retval;
954 } else { 957 } else {
955 if ( nl == kom ) { 958 if ( nl == kom ) {
956 // qDebug(" nl == kom "); 959 // qDebug(" nl == kom ");
957 start = 0; 960 start = 0;
958 ok = false; 961 ok = false;
959 return "0"; 962 return "0";
960 } 963 }
961 // qDebug(" nl < kom ", nl); 964 // qDebug(" nl < kom ", nl);
962 retval = text.mid( start, nl-start); 965 retval = text.mid( start, nl-start);
963 ok = false; 966 ok = false;
964 start = nl+1; 967 start = nl+1;
965 return retval; 968 return retval;
966 } 969 }
967 } 970 }
968} 971}
969bool SharpFormat::fromString( Calendar *calendar, const QString & text) 972bool SharpFormat::fromString( Calendar *calendar, const QString & text)
970{ 973{
971 return false; 974 return false;
972} 975}
973bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 976bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
974{ 977{
975 // qDebug("test %s ", text.latin1()); 978 // qDebug("test %s ", text.latin1());
976 QStringList templist; 979 QStringList templist;
977 QString tempString; 980 QString tempString;
978 int start = 0; 981 int start = 0;
979 int len = text.length(); 982 int len = text.length();
980 int end = text.find ("\n",start)+1; 983 int end = text.find ("\n",start)+1;
981 bool ok = true; 984 bool ok = true;
982 start = end; 985 start = end;
983 SharpParser handler( calendar ); 986 SharpParser handler( calendar );
984 // handler.setCategoriesList( mCategories ); 987 // handler.setCategoriesList( mCategories );
985 while ( start > 0 ) { 988 while ( start > 0 ) {
986 templist.clear(); 989 templist.clear();
987 ok = true; 990 ok = true;
988 while ( ok ) { 991 while ( ok ) {
989 tempString = getPart( text, ok, start ); 992 tempString = getPart( text, ok, start );
990 if ( start >= len || start == 0 ) { 993 if ( start >= len || start == 0 ) {
991 start = 0; 994 start = 0;
992 ok = false; 995 ok = false;
993 } 996 }
994 if ( tempString.right(1) =="\n" ) 997 if ( tempString.right(1) =="\n" )
995 tempString = tempString.left( tempString.length()-1); 998 tempString = tempString.left( tempString.length()-1);
996 //if ( ok ) 999 //if ( ok )
997 templist.append( tempString ); 1000 templist.append( tempString );
998 //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); 1001 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
999 } 1002 }
1000 handler.startElement( existingCalendar, templist, type ); 1003 handler.startElement( existingCalendar, templist, type );
1001 } 1004 }
1002 1005
1003 return false; 1006 return false;
1004} 1007}
1005 1008
1006QString SharpFormat::toString( Calendar * ) 1009QString SharpFormat::toString( Calendar * )
1007{ 1010{
1008 return QString::null; 1011 return QString::null;
1009} 1012}
diff --git a/version b/version
index c4fe6e2..0343cbb 100644
--- a/version
+++ b/version
@@ -1 +1 @@
version = "1.9.13"; version = "1.9.14";