summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile428
-rw-r--r--korganizer/calendarview.cpp1
-rw-r--r--libkcal/phoneformat.cpp336
-rw-r--r--libkcal/sharpformat.cpp2
-rw-r--r--libkcal/vcalformat.cpp71
-rw-r--r--microkde/kidmanager.cpp14
6 files changed, 489 insertions, 363 deletions
diff --git a/Makefile b/Makefile
index 9b55ecf..95a3a45 100644
--- a/Makefile
+++ b/Makefile
@@ -1,271 +1,159 @@
1export KDEPIMDIR = $(shell pwd) 1#############################################################################
2# Makefile for building: kopi-desktop
3# Generated by qmake (1.07a) (Qt 3.3.3) on: Thu Aug 19 22:23:29 2004
4# Project: kopi-desktop.pro
5# Template: subdirs
6# Command: $(QMAKE) -o Makefile kopi-desktop.pro
7#############################################################################
8
9 MAKEFILE =Makefile
10 QMAKE =qmake
11DEL_FILE = rm -f
12CHK_DIR_EXISTS= test -d
13MKDIR = mkdir -p
14INSTALL_FILE=
15INSTALL_DIR =
16 SUBTARGETS = \
17 sub-gammu-emb-common \
18 sub-libical \
19 sub-libkcal \
20 sub-microkde \
21 sub-libkdepim \
22 sub-kabc \
23 sub-korganizer \
24 sub-kaddressbook \
25 sub-kabc-plugins-file \
26 sub-kabc-plugins-dir
27
28first: all
29
30all: Makefile $(SUBTARGETS)
31
32gammu/emb/common/$(MAKEFILE):
33 @$(CHK_DIR_EXISTS) "gammu/emb/common" || $(MKDIR) "gammu/emb/common"
34 cd gammu/emb/common && $(QMAKE) common.pro -o $(MAKEFILE)
35sub-gammu-emb-common: gammu/emb/common/$(MAKEFILE) FORCE
36 cd gammu/emb/common && $(MAKE) -f $(MAKEFILE)
37
38libical/$(MAKEFILE):
39 @$(CHK_DIR_EXISTS) "libical" || $(MKDIR) "libical"
40 cd libical && $(QMAKE) libical.pro -o $(MAKEFILE)
41sub-libical: libical/$(MAKEFILE) FORCE
42 cd libical && $(MAKE) -f $(MAKEFILE)
43
44libkcal/$(MAKEFILE):
45 @$(CHK_DIR_EXISTS) "libkcal" || $(MKDIR) "libkcal"
46 cd libkcal && $(QMAKE) libkcal.pro -o $(MAKEFILE)
47sub-libkcal: libkcal/$(MAKEFILE) FORCE
48 cd libkcal && $(MAKE) -f $(MAKEFILE)
49
50microkde/$(MAKEFILE):
51 @$(CHK_DIR_EXISTS) "microkde" || $(MKDIR) "microkde"
52 cd microkde && $(QMAKE) microkde.pro -o $(MAKEFILE)
53sub-microkde: microkde/$(MAKEFILE) FORCE
54 cd microkde && $(MAKE) -f $(MAKEFILE)
55
56libkdepim/$(MAKEFILE):
57 @$(CHK_DIR_EXISTS) "libkdepim" || $(MKDIR) "libkdepim"
58 cd libkdepim && $(QMAKE) libkdepim.pro -o $(MAKEFILE)
59sub-libkdepim: libkdepim/$(MAKEFILE) FORCE
60 cd libkdepim && $(MAKE) -f $(MAKEFILE)
61
62kabc/$(MAKEFILE):
63 @$(CHK_DIR_EXISTS) "kabc" || $(MKDIR) "kabc"
64 cd kabc && $(QMAKE) kabc.pro -o $(MAKEFILE)
65sub-kabc: kabc/$(MAKEFILE) FORCE
66 cd kabc && $(MAKE) -f $(MAKEFILE)
67
68korganizer/$(MAKEFILE):
69 @$(CHK_DIR_EXISTS) "korganizer" || $(MKDIR) "korganizer"
70 cd korganizer && $(QMAKE) korganizer.pro -o $(MAKEFILE)
71sub-korganizer: korganizer/$(MAKEFILE) FORCE
72 cd korganizer && $(MAKE) -f $(MAKEFILE)
73
74kaddressbook/$(MAKEFILE):
75 @$(CHK_DIR_EXISTS) "kaddressbook" || $(MKDIR) "kaddressbook"
76 cd kaddressbook && $(QMAKE) kaddressbook.pro -o $(MAKEFILE)
77sub-kaddressbook: kaddressbook/$(MAKEFILE) FORCE
78 cd kaddressbook && $(MAKE) -f $(MAKEFILE)
79
80kabc/plugins/file/$(MAKEFILE):
81 @$(CHK_DIR_EXISTS) "kabc/plugins/file" || $(MKDIR) "kabc/plugins/file"
82 cd kabc/plugins/file && $(QMAKE) file.pro -o $(MAKEFILE)
83sub-kabc-plugins-file: kabc/plugins/file/$(MAKEFILE) FORCE
84 cd kabc/plugins/file && $(MAKE) -f $(MAKEFILE)
85
86kabc/plugins/dir/$(MAKEFILE):
87 @$(CHK_DIR_EXISTS) "kabc/plugins/dir" || $(MKDIR) "kabc/plugins/dir"
88 cd kabc/plugins/dir && $(QMAKE) dir.pro -o $(MAKEFILE)
89sub-kabc-plugins-dir: kabc/plugins/dir/$(MAKEFILE) FORCE
90 cd kabc/plugins/dir && $(MAKE) -f $(MAKEFILE)
91
92Makefile: kopi-desktop.pro /usr/local/qtgcc/mkspecs/default/qmake.conf
93 $(QMAKE) -o Makefile kopi-desktop.pro
94qmake: qmake_all
95 @$(QMAKE) -o Makefile kopi-desktop.pro
96
97all: $(SUBTARGETS)
98qmake_all: gammu/emb/common/$(MAKEFILE) libical/$(MAKEFILE) libkcal/$(MAKEFILE) microkde/$(MAKEFILE) libkdepim/$(MAKEFILE) kabc/$(MAKEFILE) korganizer/$(MAKEFILE) kaddressbook/$(MAKEFILE) kabc/plugins/file/$(MAKEFILE) kabc/plugins/dir/$(MAKEFILE)
99 ( [ -d gammu/emb/common ] && cd gammu/emb/common ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
100 ( [ -d libical ] && cd libical ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
101 ( [ -d libkcal ] && cd libkcal ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
102 ( [ -d microkde ] && cd microkde ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
103 ( [ -d libkdepim ] && cd libkdepim ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
104 ( [ -d kabc ] && cd kabc ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
105 ( [ -d korganizer ] && cd korganizer ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
106 ( [ -d kaddressbook ] && cd kaddressbook ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
107 ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
108 ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; grep "^qmake_all:" $(MAKEFILE) && $(MAKE) -f $(MAKEFILE) qmake_all; ) || true
109clean uicables mocables uiclean mocclean lexclean yaccclean : qmake_all FORCE
110 ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) $@; ) || true
111 ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) $@; ) || true
112 ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) $@; ) || true
113 ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) $@; ) || true
114 ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) $@; ) || true
115 ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) $@; ) || true
116 ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) $@; ) || true
117 ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) $@; ) || true
118 ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; ) || true
119 ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) $@; ) || true
120uninstall_subdirs: qmake_all FORCE
121 ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
122 ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
123 ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
124 ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
125 ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
126 ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
127 ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
128 ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
129 ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
130 ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) uninstall; ) || true
131install_subdirs: qmake_all FORCE
132 ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) install; ) || true
133 ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) install; ) || true
134 ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) install; ) || true
135 ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) install; ) || true
136 ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) install; ) || true
137 ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) install; ) || true
138 ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) install; ) || true
139 ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) install; ) || true
140 ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) install; ) || true
141 ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) install; ) || true
142distclean: qmake_all FORCE
143 ( [ -d gammu/emb/common ] && cd gammu/emb/common ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
144 ( [ -d libical ] && cd libical ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
145 ( [ -d libkcal ] && cd libkcal ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
146 ( [ -d microkde ] && cd microkde ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
147 ( [ -d libkdepim ] && cd libkdepim ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
148 ( [ -d kabc ] && cd kabc ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
149 ( [ -d korganizer ] && cd korganizer ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
150 ( [ -d kaddressbook ] && cd kaddressbook ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
151 ( [ -d kabc/plugins/file ] && cd kabc/plugins/file ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
152 ( [ -d kabc/plugins/dir ] && cd kabc/plugins/dir ; $(MAKE) -f $(MAKEFILE) $@; $(DEL_FILE) $(MAKEFILE); ) || true
153
154install: install_subdirs
155
156uninstall: uninstall_subdirs
157
158FORCE:
2 159
3
4ifeq ($(PLATFORM) , zaurus)
5 BUILD_NO_LDAP_PLUGIN=1
6endif
7
8ifneq ($(PLATFORM) , zaurus)
9 BUILD_NO_SHARP_PLUGIN=1
10endif
11
12SUBDIRS_MICROKDE = \
13 libical/src/libical \
14 libical/src/libicalss \
15 qtcompat \
16 microkde \
17 libkcal \
18 libkdepim \
19 kabc \
20 kabc/formats/binary \
21 kabc/plugins/file \
22 kabc/plugins/dir \
23 korganizer \
24 kalarmd \
25 kaddressbook
26
27SUBDIRS_QTOPIA_PLUGIN = \
28 kabc/plugins/qtopia
29
30SUBDIRS_OPIE_PLUGIN = \
31 kabc/plugins/opie
32
33SUBDIRS_SHARP_PLUGIN = \
34 kabc/plugins/sharpdtm
35
36SUBDIRS_LDAP_PLUGIN = \
37 kabc/plugins/ldap
38
39SUBDIRS_MICROMAIL = \
40 kmicromail/libetpan \
41 kmicromail/libmailwrapper \
42 kmicromail
43
44SUBDIRS = \
45 $(SUBDIRS_MICROKDE) \
46 $(SUBDIRS_QTOPIA_PLUGIN) \
47 $(SUBDIRS_OPIE_PLUGIN) \
48 $(SUBDIRS_SHARP_PLUGIN) \
49 $(SUBDIRS_LDAP_PLUGIN) \
50 $(SUBDIRS_MICROMAIL)
51
52
53all: build_microkde \
54 build_qtopia_plugin \
55 build_opie_plugin \
56 build_sharp_plugin \
57 build_ldap_plugin \
58 build_micromail
59
60
61build_microkde: variable_test tmake
62 for i in $(SUBDIRS_MICROKDE); do pushd $$i; \
63 make -f Makefile$(PLATFORM) || exit 1; popd; \
64 done
65
66build_qtopia_plugin: build_microkde
67 for i in $(SUBDIRS_QTOPIA_PLUGIN); do pushd $$i; \
68 make -f Makefile$(PLATFORM) || exit 1; popd; \
69 done
70
71build_opie_plugin: build_microkde
72 ifdef BUILD_NO_OPIE_PLUGIN
73 @echo ---> opie plugin not build.
74 else
75 for i in $(SUBDIRS_OPIE_PLUGIN); do pushd $$i; \
76 make -f Makefile$(PLATFORM) || exit 1; popd; \
77 done
78 endif
79
80build_sharp_plugin: build_microkde
81 ifdef BUILD_NO_SHARP_PLUGIN
82 @echo ---> ldap plugin not build.
83 else
84 for i in $(SUBDIRS_SHARP_PLUGIN); do pushd $$i; \
85 make -f Makefile$(PLATFORM) || exit 1; popd; \
86 done
87 endif
88
89build_ldap_plugin: build_microkde
90 ifdef BUILD_NO_LDAP_PLUGIN
91 @echo ---> ldap plugin not build.
92 else
93 for i in $(SUBDIRS_LDAP_PLUGIN); do pushd $$i; \
94 make -f Makefile$(PLATFORM) || exit 1; popd; \
95 done
96 endif
97
98
99build_micromail: build_microkde
100 ifdef BUILD_NO_MICROMAIL
101 @echo ---> micromail not build.
102 else
103 for i in $(SUBDIRS_MICROMAIL); do pushd $$i; \
104 make -f Makefile$(PLATFORM) || exit 1; popd; \
105 done
106 endif
107
108
109variable_info:
110 @echo --------------------------------------
111 @echo KDEPIM buildsystem, variableinfo...
112 @echo KDEPIMDIR=$(KDEPIMDIR)
113 @echo QTDIR=$(QTDIR)
114 @echo QPEDIR=$(QPEDIR)
115 @echo OPIEDIR=$(OPIEDIR)
116 @echo PLATFORM=$(PLATFORM)
117 @echo RELEASE_DEBUG=$(RELEASE_DEBUG)
118 @echo BUILD_NO_MICROMAIL=$(BUILD_NO_MICROMAIL)
119 @echo BUILD_NO_LDAP_PLUGIN=$(BUILD_NO_LDAP_PLUGIN)
120 @echo BUILD_NO_OPIE_PLUGIN=$(BUILD_NO_OPIE_PLUGIN)
121 @echo BUILD_NO_SHARP_PLUGIN=$(BUILD_NO_SHARP_PLUGIN)
122 ifndef BUILD_NO_SHARP_PLUGIN
123 @echo SHARPDTMSDK=$(SHARPDTMSDK)
124 endif
125 @echo --------------------------------------
126
127variable_test: variable_info
128 @echo KDEPIM buildsystem, variablecheck...
129 ifndef KDEPIMDIR
130 @echo KDEPIMDIR is not defined.
131 $(error KDEPIMDIR is not defined)
132 endif
133 ifndef PLATFORM
134 @echo PLATFORM is not defined.
135 $(error PLATFORM is not defined)
136 endif
137 ifdef BUILD_NO_LDAP_PLUGIN
138 @echo LDAP PLUGIN will not be build, because BUILD_NO_LDAP_PLUGIN is set to $(BUILD_NO_LDAP_PLUGIN)
139 endif
140 ifdef BUILD_NO_OPIE_PLUGIN
141 @echo OPIE PLUGIN will not be build, because BUILD_NO_OPIE_PLUGIN is set to $(BUILD_NO_OPIE_PLUGIN)
142 endif
143 ifdef BUILD_NO_MICROMAIL
144 @echo MICROMAIL will not be build, because BUILD_NO_MICROMAIL is set to $(BUILD_NO_MICROMAIL)
145 endif
146 ifdef BUILD_NO_SHARP_PLUGIN
147 @echo SHARP PLUGIN will not be build, because BUILD_NO_SHARP_PLUGIN is set to $(BUILD_NO_SHARP_PLUGIN)
148 else
149 ifndef SHARPDTMSDK
150 @echo SHARP PLUGIN can not be build, because SHARPDTMSDK is set to $(SHARPDTMSDK)
151 $(error SHARPDTMSDK is not defined)
152 endif
153 endif
154 @echo --------------------------------------
155
156
157objects:
158 for i in $(SUBDIRS); do mkdir -p $$i/obj/$(PLATFORM); done
159 for i in $(SUBDIRS); do mkdir -p $$i/moc/$(PLATFORM); done
160 mkdir -p libical/lib/$(PLATFORM)
161
162clean:
163 rm -rf libical/lib/$(PLATFORM)/*;
164 for i in $(SUBDIRS); do pushd $$i; make clean; rm -f *~;\
165 rm -f obj/$(PLATFORM)/*; rm -f moc/$(PLATFORM)/*; rm Makefile$(PLATFORM); popd; \
166 done
167install:
168 cd bin/kdepim; make install
169 cp db2file/db2file $(QPEDIR)/bin/db2file
170 cp korganizer/korganizer.desktop $(QPEDIR)/apps/Pim/korganizer.desktop
171 cp kaddressbook/kaddressbook.desktop $(QPEDIR)/apps/Pim/kaddressbook.desktop
172 cp kmicromail/kmicromail.desktop $(QPEDIR)/apps/Pim/kmicromail.desktop
173
174dist:
175 @echo Dont forget to do "make install" before "make dist"
176 rm -f *arm.ipk
177 rm -f *~
178 cd ..; tar czf kdepim.src.tar.gz --exclude=obj --exclude=moc kdepim
179 ./mkipks kmicrokdelibs.control
180 ./mkipks korganizer.control
181 ./mkipks kaddressbook.control
182 ifndef BUILD_NO_MICROMAIL
183 ./mkipks kopiemail.control
184 endif
185 ./mkipks korganizer-alarm.control
186
187tmake: objects \
188 qtcompat/Makefile$(PLATFORM) \
189 microkde/Makefile$(PLATFORM) \
190 libkcal/Makefile$(PLATFORM) \
191 libkdepim/Makefile$(PLATFORM) \
192 korganizer/Makefile$(PLATFORM) \
193 kalarmd/Makefile$(PLATFORM) \
194 libical/src/libical/Makefile$(PLATFORM) \
195 libical/src/libicalss/Makefile$(PLATFORM) \
196 kabc/Makefile$(PLATFORM) \
197 kabc/formats/binary/Makefile$(PLATFORM) \
198 kabc/plugins/file/Makefile$(PLATFORM) \
199 kabc/plugins/dir/Makefile$(PLATFORM) \
200 kabc/plugins/ldap/Makefile$(PLATFORM) \
201 kabc/plugins/opie/Makefile$(PLATFORM) \
202 kabc/plugins/qtopia/Makefile$(PLATFORM) \
203 kabc/plugins/sharpdtm/Makefile$(PLATFORM) \
204 kaddressbook/Makefile$(PLATFORM) \
205 kmicromail/Makefile$(PLATFORM) \
206 kmicromail/libetpan/Makefile$(PLATFORM) \
207 kmicromail/libmailwrapper/Makefile$(PLATFORM)
208
209
210
211
212qtcompat/Makefile$(PLATFORM): qtcompat/qtcompat.pro
213 cd qtcompat; tmake "CONFIG+=$(RELEASE_DEBUG)" qtcompat.pro -o Makefile$(PLATFORM)
214
215microkde/Makefile$(PLATFORM): microkde/microkdeE.pro
216 cd microkde; tmake "CONFIG+=$(RELEASE_DEBUG)" microkdeE.pro -o Makefile$(PLATFORM)
217
218libkcal/Makefile$(PLATFORM): libkcal/libkcalE.pro
219 cd libkcal; tmake "CONFIG+=$(RELEASE_DEBUG)" libkcalE.pro -o Makefile$(PLATFORM)
220
221
222libkdepim/Makefile$(PLATFORM): libkdepim/libkdepimE.pro
223 cd libkdepim; tmake "CONFIG+=$(RELEASE_DEBUG)" libkdepimE.pro -o Makefile$(PLATFORM)
224
225kalarmd/Makefile$(PLATFORM): kalarmd/kalarmdE.pro
226 cd kalarmd; tmake "CONFIG+=$(RELEASE_DEBUG)" kalarmdE.pro -o Makefile$(PLATFORM)
227
228korganizer/Makefile$(PLATFORM): korganizer/korganizerE.pro
229 cd korganizer; tmake "CONFIG+=$(RELEASE_DEBUG)" korganizerE.pro -o Makefile$(PLATFORM)
230
231libical/src/libical/Makefile$(PLATFORM): libical/src/libical/libicalE.pro
232 cd libical/src/libical; tmake "CONFIG+=$(RELEASE_DEBUG)" libicalE.pro -o Makefile$(PLATFORM)
233
234libical/src/libicalss/Makefile$(PLATFORM): libical/src/libicalss/libicalssE.pro
235 cd libical/src/libicalss; tmake "CONFIG+=$(RELEASE_DEBUG)" libicalssE.pro -o Makefile$(PLATFORM)
236
237kabc/Makefile$(PLATFORM): kabc/kabcE.pro
238 cd kabc; tmake "CONFIG+=$(RELEASE_DEBUG)" kabcE.pro -o Makefile$(PLATFORM)
239
240kabc/formats/binary/Makefile$(PLATFORM): kabc/formats/binary/kabcformat_binaryE.pro
241 cd kabc/formats/binary; tmake "CONFIG+=$(RELEASE_DEBUG)" kabcformat_binaryE.pro -o Makefile$(PLATFORM)
242
243kabc/plugins/file/Makefile$(PLATFORM): kabc/plugins/file/fileE.pro
244 cd kabc/plugins/file; tmake "CONFIG+=$(RELEASE_DEBUG)" fileE.pro -o Makefile$(PLATFORM)
245
246kabc/plugins/dir/Makefile$(PLATFORM): kabc/plugins/dir/dirE.pro
247 cd kabc/plugins/dir; tmake "CONFIG+=$(RELEASE_DEBUG)" dirE.pro -o Makefile$(PLATFORM)
248
249kabc/plugins/ldap/Makefile$(PLATFORM): kabc/plugins/ldap/ldapE.pro
250 cd kabc/plugins/ldap; tmake "CONFIG+=$(RELEASE_DEBUG)" ldapE.pro -o Makefile$(PLATFORM)
251
252kabc/plugins/opie/Makefile$(PLATFORM): kabc/plugins/opie/opieE.pro
253 cd kabc/plugins/opie; tmake "CONFIG+=$(RELEASE_DEBUG)" opieE.pro -o Makefile$(PLATFORM)
254
255kabc/plugins/qtopia/Makefile$(PLATFORM): kabc/plugins/qtopia/qtopiaE.pro
256 cd kabc/plugins/qtopia; tmake "CONFIG+=$(RELEASE_DEBUG)" qtopiaE.pro -o Makefile$(PLATFORM)
257
258kabc/plugins/sharpdtm/Makefile$(PLATFORM): kabc/plugins/sharpdtm/sharpdtmE.pro
259 cd kabc/plugins/sharpdtm; tmake "CONFIG+=$(RELEASE_DEBUG)" sharpdtmE.pro -o Makefile$(PLATFORM)
260
261kaddressbook/Makefile$(PLATFORM): kaddressbook/kaddressbookE.pro
262 cd kaddressbook; tmake "CONFIG+=$(RELEASE_DEBUG)" kaddressbookE.pro -o Makefile$(PLATFORM)
263
264kmicromail/Makefile$(PLATFORM): kmicromail/kmicromailE.pro
265 cd kmicromail; tmake "CONFIG+=$(RELEASE_DEBUG)" kmicromailE.pro -o Makefile$(PLATFORM)
266
267kmicromail/libetpan/Makefile$(PLATFORM): kmicromail/libetpan/libetpanE.pro
268 cd kmicromail/libetpan; tmake "CONFIG+=$(RELEASE_DEBUG)" libetpanE.pro -o Makefile$(PLATFORM)
269
270kmicromail/libmailwrapper/Makefile$(PLATFORM): kmicromail/libmailwrapper/libmailwrapperE.pro
271 cd kmicromail/libmailwrapper; tmake "CONFIG+=$(RELEASE_DEBUG)" libmailwrapperE.pro -o Makefile$(PLATFORM)
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 547d02b..7eca69d 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,3541 +1,3542 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preston.brown@yale.edu) 8 Preston Brown (preston.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66 66
67#include <libkcal/vcaldrag.h> 67#include <libkcal/vcaldrag.h>
68#include <libkcal/icaldrag.h> 68#include <libkcal/icaldrag.h>
69#include <libkcal/icalformat.h> 69#include <libkcal/icalformat.h>
70#include <libkcal/vcalformat.h> 70#include <libkcal/vcalformat.h>
71#include <libkcal/scheduler.h> 71#include <libkcal/scheduler.h>
72#include <libkcal/calendarlocal.h> 72#include <libkcal/calendarlocal.h>
73#include <libkcal/journal.h> 73#include <libkcal/journal.h>
74#include <libkcal/calfilter.h> 74#include <libkcal/calfilter.h>
75#include <libkcal/attendee.h> 75#include <libkcal/attendee.h>
76#include <libkcal/dndfactory.h> 76#include <libkcal/dndfactory.h>
77#include <libkcal/freebusy.h> 77#include <libkcal/freebusy.h>
78#include <libkcal/filestorage.h> 78#include <libkcal/filestorage.h>
79#include <libkcal/calendarresources.h> 79#include <libkcal/calendarresources.h>
80#include <libkcal/qtopiaformat.h> 80#include <libkcal/qtopiaformat.h>
81#include "../kalarmd/alarmdialog.h" 81#include "../kalarmd/alarmdialog.h"
82 82
83#ifndef DESKTOP_VERSION 83#ifndef DESKTOP_VERSION
84#include <libkcal/sharpformat.h> 84#include <libkcal/sharpformat.h>
85#endif 85#endif
86#include <libkcal/phoneformat.h> 86#include <libkcal/phoneformat.h>
87#ifndef KORG_NOMAIL 87#ifndef KORG_NOMAIL
88#include "komailclient.h" 88#include "komailclient.h"
89#endif 89#endif
90#ifndef KORG_NOPRINTER 90#ifndef KORG_NOPRINTER
91#include "calprinter.h" 91#include "calprinter.h"
92#endif 92#endif
93#ifndef KORG_NOPLUGINS 93#ifndef KORG_NOPLUGINS
94#include "kocore.h" 94#include "kocore.h"
95#endif 95#endif
96#include "koeventeditor.h" 96#include "koeventeditor.h"
97#include "kotodoeditor.h" 97#include "kotodoeditor.h"
98#include "koprefs.h" 98#include "koprefs.h"
99#include "koeventviewerdialog.h" 99#include "koeventviewerdialog.h"
100#include "publishdialog.h" 100#include "publishdialog.h"
101#include "kofilterview.h" 101#include "kofilterview.h"
102#include "koglobals.h" 102#include "koglobals.h"
103#include "koviewmanager.h" 103#include "koviewmanager.h"
104#include "koagendaview.h" 104#include "koagendaview.h"
105#include "kodialogmanager.h" 105#include "kodialogmanager.h"
106#include "outgoingdialog.h" 106#include "outgoingdialog.h"
107#include "incomingdialog.h" 107#include "incomingdialog.h"
108#include "statusdialog.h" 108#include "statusdialog.h"
109#include "kdatenavigator.h" 109#include "kdatenavigator.h"
110#include "kotodoview.h" 110#include "kotodoview.h"
111#include "datenavigator.h" 111#include "datenavigator.h"
112#include "resourceview.h" 112#include "resourceview.h"
113#include "navigatorbar.h" 113#include "navigatorbar.h"
114#include "searchdialog.h" 114#include "searchdialog.h"
115#include "mainwindow.h" 115#include "mainwindow.h"
116 116
117#include "calendarview.h" 117#include "calendarview.h"
118#ifndef DESKTOP_VERSION 118#ifndef DESKTOP_VERSION
119#include <qtopia/alarmserver.h> 119#include <qtopia/alarmserver.h>
120#endif 120#endif
121#ifndef _WIN32_ 121#ifndef _WIN32_
122#include <stdlib.h> 122#include <stdlib.h>
123#include <stdio.h> 123#include <stdio.h>
124#include <unistd.h> 124#include <unistd.h>
125#else 125#else
126#include <qprocess.h> 126#include <qprocess.h>
127#endif 127#endif
128using namespace KOrg; 128using namespace KOrg;
129using namespace KCal; 129using namespace KCal;
130extern int globalFlagBlockAgenda; 130extern int globalFlagBlockAgenda;
131extern int globalFlagBlockStartup; 131extern int globalFlagBlockStartup;
132 132
133 133
134 134
135class KOBeamPrefs : public QDialog 135class KOBeamPrefs : public QDialog
136{ 136{
137 public: 137 public:
138 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 138 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
139 QDialog( parent, name, true ) 139 QDialog( parent, name, true )
140 { 140 {
141 setCaption( i18n("Beam Options") ); 141 setCaption( i18n("Beam Options") );
142 QVBoxLayout* lay = new QVBoxLayout( this ); 142 QVBoxLayout* lay = new QVBoxLayout( this );
143 lay->setSpacing( 3 ); 143 lay->setSpacing( 3 );
144 lay->setMargin( 3 ); 144 lay->setMargin( 3 );
145 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 145 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
146 lay->addWidget( format ); 146 lay->addWidget( format );
147 format->setExclusive ( true ) ; 147 format->setExclusive ( true ) ;
148 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 148 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
149 lay->addWidget( time ); time->setExclusive ( true ) ; 149 lay->addWidget( time ); time->setExclusive ( true ) ;
150 vcal = new QRadioButton(" vCalendar ", format ); 150 vcal = new QRadioButton(" vCalendar ", format );
151 ical = new QRadioButton(" iCalendar ", format ); 151 ical = new QRadioButton(" iCalendar ", format );
152 vcal->setChecked( true ); 152 vcal->setChecked( true );
153 tz = new QRadioButton(i18n(" With timezone "), time ); 153 tz = new QRadioButton(i18n(" With timezone "), time );
154 local = new QRadioButton(i18n(" Local time "), time ); 154 local = new QRadioButton(i18n(" Local time "), time );
155 tz->setChecked( true ); 155 tz->setChecked( true );
156 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 156 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
157 lay->addWidget( ok ); 157 lay->addWidget( ok );
158 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 158 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
159 lay->addWidget( cancel ); 159 lay->addWidget( cancel );
160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
161 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 161 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
162 resize( 200, 200 ); 162 resize( 200, 200 );
163 } 163 }
164 164
165 bool beamVcal() { return vcal->isChecked(); } 165 bool beamVcal() { return vcal->isChecked(); }
166 bool beamLocal() { return local->isChecked(); } 166 bool beamLocal() { return local->isChecked(); }
167private: 167private:
168 QRadioButton* vcal, *ical, *local, *tz; 168 QRadioButton* vcal, *ical, *local, *tz;
169}; 169};
170class KOCatPrefs : public QDialog 170class KOCatPrefs : public QDialog
171{ 171{
172 public: 172 public:
173 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 173 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
174 QDialog( parent, name, true ) 174 QDialog( parent, name, true )
175 { 175 {
176 setCaption( i18n("Manage new Categories") ); 176 setCaption( i18n("Manage new Categories") );
177 QVBoxLayout* lay = new QVBoxLayout( this ); 177 QVBoxLayout* lay = new QVBoxLayout( this );
178 lay->setSpacing( 3 ); 178 lay->setSpacing( 3 );
179 lay->setMargin( 3 ); 179 lay->setMargin( 3 );
180 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this ); 180 QLabel * lab = new QLabel( i18n("After importing/loading/syncing\nthere may be new categories in\nevents or todos\nwhich are not in the category list.\nPlease choose what to do:\n "), this );
181 lay->addWidget( lab ); 181 lay->addWidget( lab );
182 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 182 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
183 lay->addWidget( format ); 183 lay->addWidget( format );
184 format->setExclusive ( true ) ; 184 format->setExclusive ( true ) ;
185 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 185 addCatBut = new QRadioButton(i18n("Add to category list"), format );
186 new QRadioButton(i18n("Remove from Events/Todos"), format ); 186 new QRadioButton(i18n("Remove from Events/Todos"), format );
187 addCatBut->setChecked( true ); 187 addCatBut->setChecked( true );
188 QPushButton * ok = new QPushButton( i18n("OK"), this ); 188 QPushButton * ok = new QPushButton( i18n("OK"), this );
189 lay->addWidget( ok ); 189 lay->addWidget( ok );
190 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 190 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
191 lay->addWidget( cancel ); 191 lay->addWidget( cancel );
192 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 192 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
193 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 193 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
194 resize( 200, 200 ); 194 resize( 200, 200 );
195 } 195 }
196 196
197 bool addCat() { return addCatBut->isChecked(); } 197 bool addCat() { return addCatBut->isChecked(); }
198private: 198private:
199 QRadioButton* addCatBut; 199 QRadioButton* addCatBut;
200}; 200};
201 201
202 202
203 203
204CalendarView::CalendarView( CalendarResources *calendar, 204CalendarView::CalendarView( CalendarResources *calendar,
205 QWidget *parent, const char *name ) 205 QWidget *parent, const char *name )
206 : CalendarViewBase( parent, name ), 206 : CalendarViewBase( parent, name ),
207 mCalendar( calendar ), 207 mCalendar( calendar ),
208 mResourceManager( calendar->resourceManager() ) 208 mResourceManager( calendar->resourceManager() )
209{ 209{
210 210
211 mEventEditor = 0; 211 mEventEditor = 0;
212 mTodoEditor = 0; 212 mTodoEditor = 0;
213 213
214 init(); 214 init();
215} 215}
216 216
217CalendarView::CalendarView( Calendar *calendar, 217CalendarView::CalendarView( Calendar *calendar,
218 QWidget *parent, const char *name ) 218 QWidget *parent, const char *name )
219 : CalendarViewBase( parent, name ), 219 : CalendarViewBase( parent, name ),
220 mCalendar( calendar ), 220 mCalendar( calendar ),
221 mResourceManager( 0 ) 221 mResourceManager( 0 )
222{ 222{
223 223
224 mEventEditor = 0; 224 mEventEditor = 0;
225 mTodoEditor = 0; 225 mTodoEditor = 0;
226 init();} 226 init();}
227 227
228void CalendarView::init() 228void CalendarView::init()
229{ 229{
230 beamDialog = new KOBeamPrefs(); 230 beamDialog = new KOBeamPrefs();
231 mDatePickerMode = 0; 231 mDatePickerMode = 0;
232 mCurrentSyncDevice = ""; 232 mCurrentSyncDevice = "";
233 writeLocale(); 233 writeLocale();
234 mViewManager = new KOViewManager( this ); 234 mViewManager = new KOViewManager( this );
235 mDialogManager = new KODialogManager( this ); 235 mDialogManager = new KODialogManager( this );
236 mEventViewerDialog = 0; 236 mEventViewerDialog = 0;
237 mModified = false; 237 mModified = false;
238 mReadOnly = false; 238 mReadOnly = false;
239 mSelectedIncidence = 0; 239 mSelectedIncidence = 0;
240 mCalPrinter = 0; 240 mCalPrinter = 0;
241 mFilters.setAutoDelete(true); 241 mFilters.setAutoDelete(true);
242 242
243 mCalendar->registerObserver( this ); 243 mCalendar->registerObserver( this );
244 // TODO: Make sure that view is updated, when calendar is changed. 244 // TODO: Make sure that view is updated, when calendar is changed.
245 245
246 mStorage = new FileStorage( mCalendar ); 246 mStorage = new FileStorage( mCalendar );
247 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 247 mNavigator = new DateNavigator( this, "datevav", mViewManager );
248 248
249 QBoxLayout *topLayout = (QBoxLayout*)layout(); 249 QBoxLayout *topLayout = (QBoxLayout*)layout();
250#ifndef KORG_NOSPLITTER 250#ifndef KORG_NOSPLITTER
251 // create the main layout frames. 251 // create the main layout frames.
252 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 252 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
253 topLayout->addWidget(mPanner); 253 topLayout->addWidget(mPanner);
254 254
255 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 255 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
256 "CalendarView::LeftFrame"); 256 "CalendarView::LeftFrame");
257 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 257 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
258 258
259 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE, 259 mDateNavigator = new KDateNavigator(mLeftSplitter, mCalendar, TRUE,
260 "CalendarView::DateNavigator", QDate::currentDate() ); 260 "CalendarView::DateNavigator", QDate::currentDate() );
261 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 261 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
262 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 262 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
263 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 263 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
264 264
265#ifdef KORG_NORESOURCEVIEW 265#ifdef KORG_NORESOURCEVIEW
266 mResourceView = 0; 266 mResourceView = 0;
267#else 267#else
268 if ( mResourceManager ) { 268 if ( mResourceManager ) {
269 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 269 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
270 mResourceView->updateView(); 270 mResourceView->updateView();
271 connect( mResourceView, SIGNAL( resourcesChanged() ), 271 connect( mResourceView, SIGNAL( resourcesChanged() ),
272 SLOT( updateView() ) ); 272 SLOT( updateView() ) );
273 } else { 273 } else {
274 mResourceView = 0; 274 mResourceView = 0;
275 } 275 }
276#endif 276#endif
277 QWidget *rightBox = new QWidget( mPanner ); 277 QWidget *rightBox = new QWidget( mPanner );
278 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 278 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
279 279
280 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 280 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
281 rightLayout->addWidget( mNavigatorBar ); 281 rightLayout->addWidget( mNavigatorBar );
282 282
283 mRightFrame = new QWidgetStack( rightBox ); 283 mRightFrame = new QWidgetStack( rightBox );
284 rightLayout->addWidget( mRightFrame, 1 ); 284 rightLayout->addWidget( mRightFrame, 1 );
285 285
286 mLeftFrame = mLeftSplitter; 286 mLeftFrame = mLeftSplitter;
287#else 287#else
288 QWidget *mainBox = new QWidget( this ); 288 QWidget *mainBox = new QWidget( this );
289 QWidget *leftFrame = new QWidget( mainBox ); 289 QWidget *leftFrame = new QWidget( mainBox );
290 290
291 QBoxLayout * mainBoxLayout; 291 QBoxLayout * mainBoxLayout;
292 QBoxLayout * leftFrameLayout; 292 QBoxLayout * leftFrameLayout;
293 if ( KOPrefs::instance()->mVerticalScreen ) { 293 if ( KOPrefs::instance()->mVerticalScreen ) {
294 mainBoxLayout = new QVBoxLayout(mainBox); 294 mainBoxLayout = new QVBoxLayout(mainBox);
295 leftFrameLayout = new QHBoxLayout(leftFrame ); 295 leftFrameLayout = new QHBoxLayout(leftFrame );
296 } else { 296 } else {
297 mainBoxLayout = new QHBoxLayout(mainBox); 297 mainBoxLayout = new QHBoxLayout(mainBox);
298 leftFrameLayout = new QVBoxLayout(leftFrame ); 298 leftFrameLayout = new QVBoxLayout(leftFrame );
299 } 299 }
300 topLayout->addWidget( mainBox ); 300 topLayout->addWidget( mainBox );
301 mainBoxLayout->addWidget (leftFrame); 301 mainBoxLayout->addWidget (leftFrame);
302 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE, 302 mDateNavigator = new KDateNavigator(leftFrame, mCalendar, TRUE,
303 "CalendarView::DateNavigator", QDate::currentDate()); 303 "CalendarView::DateNavigator", QDate::currentDate());
304 // mDateNavigator->blockSignals( true ); 304 // mDateNavigator->blockSignals( true );
305 leftFrameLayout->addWidget( mDateNavigator ); 305 leftFrameLayout->addWidget( mDateNavigator );
306 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView"); 306 mFilterView = new KOFilterView(&mFilters,leftFrame,"CalendarView::FilterView");
307 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist"); 307 mTodoList = new KOTodoView(mCalendar, leftFrame, "todolist");
308 308
309 if ( QApplication::desktop()->width() < 480 ) { 309 if ( QApplication::desktop()->width() < 480 ) {
310 leftFrameLayout->addWidget(mFilterView); 310 leftFrameLayout->addWidget(mFilterView);
311 leftFrameLayout->addWidget(mTodoList, 2 ); 311 leftFrameLayout->addWidget(mTodoList, 2 );
312 312
313 } else { 313 } else {
314 leftFrameLayout->addWidget(mTodoList,2 ); 314 leftFrameLayout->addWidget(mTodoList,2 );
315 leftFrameLayout->addWidget(mFilterView ); 315 leftFrameLayout->addWidget(mFilterView );
316 } 316 }
317 mFilterView->hide(); 317 mFilterView->hide();
318 QWidget *rightBox = new QWidget( mainBox ); 318 QWidget *rightBox = new QWidget( mainBox );
319 mainBoxLayout->addWidget ( rightBox, 10 ); 319 mainBoxLayout->addWidget ( rightBox, 10 );
320 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 320 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
321 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" ); 321 mNavigatorBar = new NavigatorBar( QDate::currentDate(), rightBox, "useBigPixmaps" );
322 mRightFrame = new QWidgetStack( rightBox ); 322 mRightFrame = new QWidgetStack( rightBox );
323 rightLayout->addWidget( mNavigatorBar ); 323 rightLayout->addWidget( mNavigatorBar );
324 rightLayout->addWidget( mRightFrame, 10 ); 324 rightLayout->addWidget( mRightFrame, 10 );
325 325
326 mLeftFrame = leftFrame; 326 mLeftFrame = leftFrame;
327 if ( KOPrefs::instance()->mVerticalScreen ) { 327 if ( KOPrefs::instance()->mVerticalScreen ) {
328 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 328 mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
329 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 329 leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
330 } else { 330 } else {
331 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 331 mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
332 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 332 leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
333 } 333 }
334 334
335 //qDebug("Calendarview Size %d %d ", width(), height()); 335 //qDebug("Calendarview Size %d %d ", width(), height());
336#endif 336#endif
337 337
338 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 338 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
339 SLOT( showDates( const KCal::DateList & ) ) ); 339 SLOT( showDates( const KCal::DateList & ) ) );
340 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 340 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
341 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 341 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
342 342
343 connect( mNavigatorBar, SIGNAL( goPrevYear() ), 343 connect( mNavigatorBar, SIGNAL( goPrevYear() ),
344 mNavigator, SLOT( selectPreviousYear() ) ); 344 mNavigator, SLOT( selectPreviousYear() ) );
345 connect( mNavigatorBar, SIGNAL( goNextYear() ), 345 connect( mNavigatorBar, SIGNAL( goNextYear() ),
346 mNavigator, SLOT( selectNextYear() ) ); 346 mNavigator, SLOT( selectNextYear() ) );
347 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), 347 connect( mNavigatorBar, SIGNAL( goPrevMonth() ),
348 mNavigator, SLOT( selectPreviousMonth() ) ); 348 mNavigator, SLOT( selectPreviousMonth() ) );
349 connect( mNavigatorBar, SIGNAL( goNextMonth() ), 349 connect( mNavigatorBar, SIGNAL( goNextMonth() ),
350 mNavigator, SLOT( selectNextMonth() ) ); 350 mNavigator, SLOT( selectNextMonth() ) );
351 351
352 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 352 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
353 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) ); 353 mNavigatorBar, SLOT( selectDates( const KCal::DateList & ) ) );
354 354
355 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 355 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
356 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 356 mNavigator, SLOT( selectWeek( const QDate & ) ) );
357 357
358 connect( mDateNavigator, SIGNAL( goPrevYear() ), 358 connect( mDateNavigator, SIGNAL( goPrevYear() ),
359 mNavigator, SLOT( selectPreviousYear() ) ); 359 mNavigator, SLOT( selectPreviousYear() ) );
360 connect( mDateNavigator, SIGNAL( goNextYear() ), 360 connect( mDateNavigator, SIGNAL( goNextYear() ),
361 mNavigator, SLOT( selectNextYear() ) ); 361 mNavigator, SLOT( selectNextYear() ) );
362 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 362 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
363 mNavigator, SLOT( selectPreviousMonth() ) ); 363 mNavigator, SLOT( selectPreviousMonth() ) );
364 connect( mDateNavigator, SIGNAL( goNextMonth() ), 364 connect( mDateNavigator, SIGNAL( goNextMonth() ),
365 mNavigator, SLOT( selectNextMonth() ) ); 365 mNavigator, SLOT( selectNextMonth() ) );
366 366
367 connect( mDateNavigator, SIGNAL( goPrevious() ), 367 connect( mDateNavigator, SIGNAL( goPrevious() ),
368 mNavigator, SLOT( selectPrevious() ) ); 368 mNavigator, SLOT( selectPrevious() ) );
369 connect( mDateNavigator, SIGNAL( goNext() ), 369 connect( mDateNavigator, SIGNAL( goNext() ),
370 mNavigator, SLOT( selectNext() ) ); 370 mNavigator, SLOT( selectNext() ) );
371 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 371 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
372 mNavigator, SLOT( slotMonthSelect( int ) ) ); 372 mNavigator, SLOT( slotMonthSelect( int ) ) );
373 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ), 373 connect( mNavigatorBar, SIGNAL( monthSelected ( int ) ),
374 mNavigator, SLOT( slotMonthSelect( int ) ) ); 374 mNavigator, SLOT( slotMonthSelect( int ) ) );
375 375
376 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 376 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
377 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 377 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
378 378
379 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ), 379 connect( mDateNavigator, SIGNAL( eventDropped( Event * ) ),
380 SLOT( eventAdded( Event *) ) ); 380 SLOT( eventAdded( Event *) ) );
381 381
382 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 382 connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
383 383
384 connect( this, SIGNAL( configChanged() ), 384 connect( this, SIGNAL( configChanged() ),
385 mDateNavigator, SLOT( updateConfig() ) ); 385 mDateNavigator, SLOT( updateConfig() ) );
386 386
387 connect( mTodoList, SIGNAL( newTodoSignal() ), 387 connect( mTodoList, SIGNAL( newTodoSignal() ),
388 SLOT( newTodo() ) ); 388 SLOT( newTodo() ) );
389 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 389 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
390 SLOT( newSubTodo( Todo * ) ) ); 390 SLOT( newSubTodo( Todo * ) ) );
391 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 391 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
392 SLOT( editTodo( Todo * ) ) ); 392 SLOT( editTodo( Todo * ) ) );
393 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 393 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
394 SLOT( showTodo( Todo *) ) ); 394 SLOT( showTodo( Todo *) ) );
395 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 395 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
396 SLOT( deleteTodo( Todo *) ) ); 396 SLOT( deleteTodo( Todo *) ) );
397 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 397 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
398 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 398 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
399 SLOT( purgeCompleted() ) ); 399 SLOT( purgeCompleted() ) );
400 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 400 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
401 SIGNAL( todoModified( Todo *, int ) ) ); 401 SIGNAL( todoModified( Todo *, int ) ) );
402 402
403 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 403 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
404 this, SLOT ( cloneIncidence( Incidence * ) ) ); 404 this, SLOT ( cloneIncidence( Incidence * ) ) );
405 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 405 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
406 this, SLOT (cancelIncidence( Incidence * ) ) ); 406 this, SLOT (cancelIncidence( Incidence * ) ) );
407 407
408 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 408 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
409 this, SLOT ( moveIncidence( Incidence * ) ) ); 409 this, SLOT ( moveIncidence( Incidence * ) ) );
410 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 410 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
411 this, SLOT ( beamIncidence( Incidence * ) ) ); 411 this, SLOT ( beamIncidence( Incidence * ) ) );
412 412
413 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 413 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
414 this, SLOT ( todo_unsub( Todo * ) ) ); 414 this, SLOT ( todo_unsub( Todo * ) ) );
415 415
416 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 416 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
417 SLOT( updateTodo( Todo *, int ) ) ); 417 SLOT( updateTodo( Todo *, int ) ) );
418 connect( this, SIGNAL( todoModified( Todo *, int )), this, 418 connect( this, SIGNAL( todoModified( Todo *, int )), this,
419 SLOT( changeTodoDisplay( Todo *, int ) ) ); 419 SLOT( changeTodoDisplay( Todo *, int ) ) );
420 420
421 421
422 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 422 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
423 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 423 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
424 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 424 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
425 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 425 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
426 426
427 427
428 428
429 429
430 430
431 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 431 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
432 SLOT(checkClipboard())); 432 SLOT(checkClipboard()));
433 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 433 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
434 SLOT( processTodoListSelection( Incidence * ) ) ); 434 SLOT( processTodoListSelection( Incidence * ) ) );
435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 435 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
436 436
437 // kdDebug() << "CalendarView::CalendarView() done" << endl; 437 // kdDebug() << "CalendarView::CalendarView() done" << endl;
438 438
439 mDateFrame = new QVBox(0,0,WType_Popup); 439 mDateFrame = new QVBox(0,0,WType_Popup);
440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 440 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 441 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
442 mDateFrame->setLineWidth(3); 442 mDateFrame->setLineWidth(3);
443 mDateFrame->hide(); 443 mDateFrame->hide();
444 mDateFrame->setCaption( i18n( "Pick a date to display")); 444 mDateFrame->setCaption( i18n( "Pick a date to display"));
445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 445 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
446 446
447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 447 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
448 448
449 mEventEditor = mDialogManager->getEventEditor(); 449 mEventEditor = mDialogManager->getEventEditor();
450 mTodoEditor = mDialogManager->getTodoEditor(); 450 mTodoEditor = mDialogManager->getTodoEditor();
451 451
452 mFlagEditDescription = false; 452 mFlagEditDescription = false;
453 453
454 mSuspendTimer = new QTimer( this ); 454 mSuspendTimer = new QTimer( this );
455 mAlarmTimer = new QTimer( this ); 455 mAlarmTimer = new QTimer( this );
456 mRecheckAlarmTimer = new QTimer( this ); 456 mRecheckAlarmTimer = new QTimer( this );
457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 457 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 458 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 459 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
460 mAlarmDialog = new AlarmDialog( this ); 460 mAlarmDialog = new AlarmDialog( this );
461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 461 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
462 mAlarmDialog->setServerNotification( false ); 462 mAlarmDialog->setServerNotification( false );
463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 463 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
464} 464}
465 465
466 466
467CalendarView::~CalendarView() 467CalendarView::~CalendarView()
468{ 468{
469 // kdDebug() << "~CalendarView()" << endl; 469 // kdDebug() << "~CalendarView()" << endl;
470 //qDebug("CalendarView::~CalendarView() "); 470 //qDebug("CalendarView::~CalendarView() ");
471 delete mDialogManager; 471 delete mDialogManager;
472 delete mViewManager; 472 delete mViewManager;
473 delete mStorage; 473 delete mStorage;
474 delete mDateFrame ; 474 delete mDateFrame ;
475 delete beamDialog; 475 delete beamDialog;
476 //kdDebug() << "~CalendarView() done" << endl; 476 //kdDebug() << "~CalendarView() done" << endl;
477} 477}
478void CalendarView::timerAlarm() 478void CalendarView::timerAlarm()
479{ 479{
480 //qDebug("CalendarView::timerAlarm() "); 480 //qDebug("CalendarView::timerAlarm() ");
481 computeAlarm(mAlarmNotification ); 481 computeAlarm(mAlarmNotification );
482} 482}
483 483
484void CalendarView::suspendAlarm() 484void CalendarView::suspendAlarm()
485{ 485{
486 //qDebug(" CalendarView::suspendAlarm() "); 486 //qDebug(" CalendarView::suspendAlarm() ");
487 computeAlarm(mSuspendAlarmNotification ); 487 computeAlarm(mSuspendAlarmNotification );
488 488
489} 489}
490 490
491void CalendarView::startAlarm( QString mess , QString filename) 491void CalendarView::startAlarm( QString mess , QString filename)
492{ 492{
493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 493 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) ); 494 QTimer::singleShot( 3000, this, SLOT( checkNextTimerAlarm() ) );
495 495
496} 496}
497 497
498void CalendarView::checkNextTimerAlarm() 498void CalendarView::checkNextTimerAlarm()
499{ 499{
500 mCalendar->checkAlarmForIncidence( 0, true ); 500 mCalendar->checkAlarmForIncidence( 0, true );
501} 501}
502 502
503void CalendarView::computeAlarm( QString msg ) 503void CalendarView::computeAlarm( QString msg )
504{ 504{
505 505
506 QString mess = msg; 506 QString mess = msg;
507 QString mAlarmMessage = mess.mid( 9 ); 507 QString mAlarmMessage = mess.mid( 9 );
508 QString filename = MainWindow::resourcePath(); 508 QString filename = MainWindow::resourcePath();
509 filename += "koalarm.wav"; 509 filename += "koalarm.wav";
510 QString tempfilename; 510 QString tempfilename;
511 if ( mess.left( 13 ) == "suspend_alarm") { 511 if ( mess.left( 13 ) == "suspend_alarm") {
512 bool error = false; 512 bool error = false;
513 int len = mess.mid( 13 ).find("+++"); 513 int len = mess.mid( 13 ).find("+++");
514 if ( len < 2 ) 514 if ( len < 2 )
515 error = true; 515 error = true;
516 else { 516 else {
517 tempfilename = mess.mid( 13, len ); 517 tempfilename = mess.mid( 13, len );
518 if ( !QFile::exists( tempfilename ) ) 518 if ( !QFile::exists( tempfilename ) )
519 error = true; 519 error = true;
520 } 520 }
521 if ( ! error ) { 521 if ( ! error ) {
522 filename = tempfilename; 522 filename = tempfilename;
523 } 523 }
524 mAlarmMessage = mess.mid( 13+len+3 ); 524 mAlarmMessage = mess.mid( 13+len+3 );
525 //qDebug("suspend file %s ",tempfilename.latin1() ); 525 //qDebug("suspend file %s ",tempfilename.latin1() );
526 startAlarm( mAlarmMessage, filename); 526 startAlarm( mAlarmMessage, filename);
527 return; 527 return;
528 } 528 }
529 if ( mess.left( 11 ) == "timer_alarm") { 529 if ( mess.left( 11 ) == "timer_alarm") {
530 //mTimerTime = 0; 530 //mTimerTime = 0;
531 startAlarm( mess.mid( 11 ), filename ); 531 startAlarm( mess.mid( 11 ), filename );
532 return; 532 return;
533 } 533 }
534 if ( mess.left( 10 ) == "proc_alarm") { 534 if ( mess.left( 10 ) == "proc_alarm") {
535 bool error = false; 535 bool error = false;
536 int len = mess.mid( 10 ).find("+++"); 536 int len = mess.mid( 10 ).find("+++");
537 if ( len < 2 ) 537 if ( len < 2 )
538 error = true; 538 error = true;
539 else { 539 else {
540 tempfilename = mess.mid( 10, len ); 540 tempfilename = mess.mid( 10, len );
541 if ( !QFile::exists( tempfilename ) ) 541 if ( !QFile::exists( tempfilename ) )
542 error = true; 542 error = true;
543 } 543 }
544 if ( error ) { 544 if ( error ) {
545 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 545 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
546 mAlarmMessage += mess.mid( 10+len+3+9 ); 546 mAlarmMessage += mess.mid( 10+len+3+9 );
547 } else { 547 } else {
548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 548 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
549 //qDebug("-----system command %s ",tempfilename.latin1() ); 549 //qDebug("-----system command %s ",tempfilename.latin1() );
550#ifndef _WIN32_ 550#ifndef _WIN32_
551 if ( vfork () == 0 ) { 551 if ( vfork () == 0 ) {
552 execl ( tempfilename.latin1(), 0 ); 552 execl ( tempfilename.latin1(), 0 );
553 return; 553 return;
554 } 554 }
555#else 555#else
556 QProcess* p = new QProcess(); 556 QProcess* p = new QProcess();
557 p->addArgument( tempfilename.latin1() ); 557 p->addArgument( tempfilename.latin1() );
558 p->start(); 558 p->start();
559 return; 559 return;
560#endif 560#endif
561 561
562 return; 562 return;
563 } 563 }
564 564
565 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 565 //qDebug("+++++++system command %s ",tempfilename.latin1() );
566 } 566 }
567 if ( mess.left( 11 ) == "audio_alarm") { 567 if ( mess.left( 11 ) == "audio_alarm") {
568 bool error = false; 568 bool error = false;
569 int len = mess.mid( 11 ).find("+++"); 569 int len = mess.mid( 11 ).find("+++");
570 if ( len < 2 ) 570 if ( len < 2 )
571 error = true; 571 error = true;
572 else { 572 else {
573 tempfilename = mess.mid( 11, len ); 573 tempfilename = mess.mid( 11, len );
574 if ( !QFile::exists( tempfilename ) ) 574 if ( !QFile::exists( tempfilename ) )
575 error = true; 575 error = true;
576 } 576 }
577 if ( ! error ) { 577 if ( ! error ) {
578 filename = tempfilename; 578 filename = tempfilename;
579 } 579 }
580 mAlarmMessage = mess.mid( 11+len+3+9 ); 580 mAlarmMessage = mess.mid( 11+len+3+9 );
581 //qDebug("audio file command %s ",tempfilename.latin1() ); 581 //qDebug("audio file command %s ",tempfilename.latin1() );
582 } 582 }
583 if ( mess.left( 9 ) == "cal_alarm") { 583 if ( mess.left( 9 ) == "cal_alarm") {
584 mAlarmMessage = mess.mid( 9 ) ; 584 mAlarmMessage = mess.mid( 9 ) ;
585 } 585 }
586 586
587 startAlarm( mAlarmMessage, filename ); 587 startAlarm( mAlarmMessage, filename );
588 588
589 589
590} 590}
591 591
592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 592void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
593{ 593{
594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 594 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
595 595
596 mSuspendAlarmNotification = noti; 596 mSuspendAlarmNotification = noti;
597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 597 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 598 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
599 mSuspendTimer->start( ms , true ); 599 mSuspendTimer->start( ms , true );
600 600
601} 601}
602 602
603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 603void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
604{ 604{
605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 605 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 606 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
607#ifndef DESKTOP_VERSION 607#ifndef DESKTOP_VERSION
608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() ); 608 AlarmServer::addAlarm ( qdt,"koalarm", noti.latin1() );
609#endif 609#endif
610 return; 610 return;
611 } 611 }
612 int maxSec; 612 int maxSec;
613 //maxSec = 5; //testing only 613 //maxSec = 5; //testing only
614 maxSec = 86400+3600; // one day+1hour 614 maxSec = 86400+3600; // one day+1hour
615 mAlarmNotification = noti; 615 mAlarmNotification = noti;
616 int sec = QDateTime::currentDateTime().secsTo( qdt ); 616 int sec = QDateTime::currentDateTime().secsTo( qdt );
617 if ( sec > maxSec ) { 617 if ( sec > maxSec ) {
618 mRecheckAlarmTimer->start( maxSec * 1000 ); 618 mRecheckAlarmTimer->start( maxSec * 1000 );
619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 619 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
620 return; 620 return;
621 } else { 621 } else {
622 mRecheckAlarmTimer->stop(); 622 mRecheckAlarmTimer->stop();
623 } 623 }
624 //qDebug("Alarm timer started with secs: %d ", sec); 624 //qDebug("Alarm timer started with secs: %d ", sec);
625 mAlarmTimer->start( sec *1000 , true ); 625 mAlarmTimer->start( sec *1000 , true );
626 626
627} 627}
628// called by mRecheckAlarmTimer to get next alarm 628// called by mRecheckAlarmTimer to get next alarm
629// we need this, because a QTimer has only a max range of 25 days 629// we need this, because a QTimer has only a max range of 25 days
630void CalendarView::recheckTimerAlarm() 630void CalendarView::recheckTimerAlarm()
631{ 631{
632 mAlarmTimer->stop(); 632 mAlarmTimer->stop();
633 mRecheckAlarmTimer->stop(); 633 mRecheckAlarmTimer->stop();
634 mCalendar->checkAlarmForIncidence( 0, true ); 634 mCalendar->checkAlarmForIncidence( 0, true );
635} 635}
636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 636void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
637{ 637{
638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 638 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 639 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
640#ifndef DESKTOP_VERSION 640#ifndef DESKTOP_VERSION
641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 641 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
642#endif 642#endif
643 return; 643 return;
644 } 644 }
645 mAlarmTimer->stop(); 645 mAlarmTimer->stop();
646} 646}
647void CalendarView::selectWeekNum ( int num ) 647void CalendarView::selectWeekNum ( int num )
648{ 648{
649 dateNavigator()->selectWeek( num ); 649 dateNavigator()->selectWeek( num );
650 mViewManager->showWeekView(); 650 mViewManager->showWeekView();
651} 651}
652KOViewManager *CalendarView::viewManager() 652KOViewManager *CalendarView::viewManager()
653{ 653{
654 return mViewManager; 654 return mViewManager;
655} 655}
656 656
657KODialogManager *CalendarView::dialogManager() 657KODialogManager *CalendarView::dialogManager()
658{ 658{
659 return mDialogManager; 659 return mDialogManager;
660} 660}
661 661
662QDate CalendarView::startDate() 662QDate CalendarView::startDate()
663{ 663{
664 DateList dates = mNavigator->selectedDates(); 664 DateList dates = mNavigator->selectedDates();
665 665
666 return dates.first(); 666 return dates.first();
667} 667}
668 668
669QDate CalendarView::endDate() 669QDate CalendarView::endDate()
670{ 670{
671 DateList dates = mNavigator->selectedDates(); 671 DateList dates = mNavigator->selectedDates();
672 672
673 return dates.last(); 673 return dates.last();
674} 674}
675 675
676 676
677void CalendarView::createPrinter() 677void CalendarView::createPrinter()
678{ 678{
679#ifndef KORG_NOPRINTER 679#ifndef KORG_NOPRINTER
680 if (!mCalPrinter) { 680 if (!mCalPrinter) {
681 mCalPrinter = new CalPrinter(this, mCalendar); 681 mCalPrinter = new CalPrinter(this, mCalendar);
682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 682 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
683 } 683 }
684#endif 684#endif
685} 685}
686 686
687void CalendarView::confSync() 687void CalendarView::confSync()
688{ 688{
689 static KSyncPrefsDialog* sp = 0; 689 static KSyncPrefsDialog* sp = 0;
690 if ( ! sp ) { 690 if ( ! sp ) {
691 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 691 sp = new KSyncPrefsDialog( this, "syncprefs", true );
692 } 692 }
693 sp->usrReadConfig(); 693 sp->usrReadConfig();
694#ifndef DESKTOP_VERSION 694#ifndef DESKTOP_VERSION
695 sp->showMaximized(); 695 sp->showMaximized();
696#else 696#else
697 sp->show(); 697 sp->show();
698#endif 698#endif
699 sp->exec(); 699 sp->exec();
700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 700 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 701 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
702} 702}
703 703
704 704
705//KOPrefs::instance()->mWriteBackFile 705//KOPrefs::instance()->mWriteBackFile
706//KOPrefs::instance()->mWriteBackExistingOnly 706//KOPrefs::instance()->mWriteBackExistingOnly
707 707
708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 708// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 709// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 710// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 711// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 712// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 713// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
714 714
715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 715int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
716{ 716{
717 717
718 //void setZaurusId(int id); 718 //void setZaurusId(int id);
719 // int zaurusId() const; 719 // int zaurusId() const;
720 // void setZaurusUid(int id); 720 // void setZaurusUid(int id);
721 // int zaurusUid() const; 721 // int zaurusUid() const;
722 // void setZaurusStat(int id); 722 // void setZaurusStat(int id);
723 // int zaurusStat() const; 723 // int zaurusStat() const;
724 // 0 equal 724 // 0 equal
725 // 1 take local 725 // 1 take local
726 // 2 take remote 726 // 2 take remote
727 // 3 cancel 727 // 3 cancel
728 QDateTime lastSync = mLastCalendarSync; 728 QDateTime lastSync = mLastCalendarSync;
729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 729 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
730 bool remCh, locCh; 730 bool remCh, locCh;
731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 731 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
732 locCh = ( local->lastModified() > mLastCalendarSync ); 732 locCh = ( local->lastModified() > mLastCalendarSync );
733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() ); 733 //qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
734 if ( !remCh && ! locCh ) { 734 if ( !remCh && ! locCh ) {
735 //qDebug("both not changed "); 735 //qDebug("both not changed ");
736 lastSync = local->lastModified().addDays(1); 736 lastSync = local->lastModified().addDays(1);
737 } else { 737 } else {
738 if ( locCh ) { 738 if ( locCh ) {
739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() ); 739 //qDebug("loc changed %d %d", local->zaurusStat(), local->revision() );
740 lastSync = local->lastModified().addDays( -1 ); 740 lastSync = local->lastModified().addDays( -1 );
741 if ( !remCh ) 741 if ( !remCh )
742 remote->setLastModified( lastSync.addDays( -1 ) ); 742 remote->setLastModified( lastSync.addDays( -1 ) );
743 } else { 743 } else {
744 //qDebug(" not loc changed "); 744 //qDebug(" not loc changed ");
745 lastSync = local->lastModified().addDays( 1 ); 745 lastSync = local->lastModified().addDays( 1 );
746 if ( remCh ) 746 if ( remCh )
747 remote->setLastModified( lastSync.addDays( 1 ) ); 747 remote->setLastModified( lastSync.addDays( 1 ) );
748 748
749 } 749 }
750 } 750 }
751 full = true; 751 full = true;
752 if ( mode < SYNC_PREF_ASK ) 752 if ( mode < SYNC_PREF_ASK )
753 mode = SYNC_PREF_ASK; 753 mode = SYNC_PREF_ASK;
754 } else { 754 } else {
755 if ( local->lastModified() == remote->lastModified() ) 755 if ( local->lastModified() == remote->lastModified() )
756 if ( local->revision() == remote->revision() ) 756 if ( local->revision() == remote->revision() )
757 return 0; 757 return 0;
758 758
759 } 759 }
760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 760 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
761 761
762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 762 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 763 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
764 //full = true; //debug only 764 //full = true; //debug only
765 if ( full ) { 765 if ( full ) {
766 bool equ = false; 766 bool equ = false;
767 if ( local->type() == "Event" ) { 767 if ( local->type() == "Event" ) {
768 equ = (*((Event*) local) == *((Event*) remote)); 768 equ = (*((Event*) local) == *((Event*) remote));
769 } 769 }
770 else if ( local->type() =="Todo" ) 770 else if ( local->type() =="Todo" )
771 equ = (*((Todo*) local) == (*(Todo*) remote)); 771 equ = (*((Todo*) local) == (*(Todo*) remote));
772 else if ( local->type() =="Journal" ) 772 else if ( local->type() =="Journal" )
773 equ = (*((Journal*) local) == *((Journal*) remote)); 773 equ = (*((Journal*) local) == *((Journal*) remote));
774 if ( equ ) { 774 if ( equ ) {
775 //qDebug("equal "); 775 //qDebug("equal ");
776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 776 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 777 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
778 } 778 }
779 if ( mode < SYNC_PREF_FORCE_LOCAL ) 779 if ( mode < SYNC_PREF_FORCE_LOCAL )
780 return 0; 780 return 0;
781 781
782 }//else //debug only 782 }//else //debug only
783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 783 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
784 } 784 }
785 int result; 785 int result;
786 bool localIsNew; 786 bool localIsNew;
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 > remote->lastModified() ) 792 if ( lastSync > remote->lastModified() )
793 return 1; 793 return 1;
794 if ( lastSync > local->lastModified() ) 794 if ( lastSync > local->lastModified() )
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 > remote->lastModified() ) 799 if ( lastSync > remote->lastModified() )
800 return 1; 800 return 1;
801 if ( lastSync > local->lastModified() ) 801 if ( lastSync > local->lastModified() )
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 ( local->lastModified() > remote->lastModified() ) 806 if ( local->lastModified() > remote->lastModified() )
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(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 812 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
813 if ( lastSync > remote->lastModified() ) 813 if ( lastSync > remote->lastModified() )
814 return 1; 814 return 1;
815 if ( lastSync > local->lastModified() ) 815 if ( lastSync > local->lastModified() )
816 return 2; 816 return 2;
817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); 817 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
818 localIsNew = local->lastModified() > remote->lastModified(); 818 localIsNew = local->lastModified() > remote->lastModified();
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 ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( KOPrefs::instance()->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// probaly useless 872// probaly useless
873void CalendarView::setupExternSyncProfiles() 873void CalendarView::setupExternSyncProfiles()
874{ 874{
875 Event* lse; 875 Event* lse;
876 mExternLastSyncEvent.clear(); 876 mExternLastSyncEvent.clear();
877 int i; 877 int i;
878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { 878 for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) {
879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); 879 lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] );
880 if ( lse ) 880 if ( lse )
881 mExternLastSyncEvent.append( lse ); 881 mExternLastSyncEvent.append( lse );
882 else 882 else
883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); 883 qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1());
884 } 884 }
885 885
886} 886}
887// we check, if the to delete event has a id for a profile 887// we check, if the to delete event has a id for a profile
888// if yes, we set this id in the profile to delete 888// if yes, we set this id in the profile to delete
889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 889void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
890{ 890{
891 if ( lastSync.count() == 0 ) { 891 if ( lastSync.count() == 0 ) {
892 //qDebug(" lastSync.count() == 0"); 892 //qDebug(" lastSync.count() == 0");
893 return; 893 return;
894 } 894 }
895 if ( toDelete->type() == "Journal" ) 895 if ( toDelete->type() == "Journal" )
896 return; 896 return;
897 897
898 Event* eve = lastSync.first(); 898 Event* eve = lastSync.first();
899 899
900 while ( eve ) { 900 while ( eve ) {
901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 901 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
902 if ( !id.isEmpty() ) { 902 if ( !id.isEmpty() ) {
903 QString des = eve->description(); 903 QString des = eve->description();
904 QString pref = "e"; 904 QString pref = "e";
905 if ( toDelete->type() == "Todo" ) 905 if ( toDelete->type() == "Todo" )
906 pref = "t"; 906 pref = "t";
907 des += pref+ id + ","; 907 des += pref+ id + ",";
908 eve->setReadOnly( false ); 908 eve->setReadOnly( false );
909 eve->setDescription( des ); 909 eve->setDescription( des );
910 //qDebug("setdes %s ", des.latin1()); 910 //qDebug("setdes %s ", des.latin1());
911 eve->setReadOnly( true ); 911 eve->setReadOnly( true );
912 } 912 }
913 eve = lastSync.next(); 913 eve = lastSync.next();
914 } 914 }
915 915
916} 916}
917void CalendarView::checkExternalId( Incidence * inc ) 917void CalendarView::checkExternalId( Incidence * inc )
918{ 918{
919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 919 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
920 checkExternSyncEvent( lastSync, inc ); 920 checkExternSyncEvent( lastSync, inc );
921 921
922} 922}
923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 923bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
924{ 924{
925 bool syncOK = true; 925 bool syncOK = true;
926 int addedEvent = 0; 926 int addedEvent = 0;
927 int addedEventR = 0; 927 int addedEventR = 0;
928 int deletedEventR = 0; 928 int deletedEventR = 0;
929 int deletedEventL = 0; 929 int deletedEventL = 0;
930 int changedLocal = 0; 930 int changedLocal = 0;
931 int changedRemote = 0; 931 int changedRemote = 0;
932 //QPtrList<Event> el = local->rawEvents(); 932 //QPtrList<Event> el = local->rawEvents();
933 Event* eventR; 933 Event* eventR;
934 QString uid; 934 QString uid;
935 int take; 935 int take;
936 Event* eventL; 936 Event* eventL;
937 Event* eventRSync; 937 Event* eventRSync;
938 Event* eventLSync; 938 Event* eventLSync;
939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 939 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 940 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
941 bool fullDateRange = false; 941 bool fullDateRange = false;
942 local->resetTempSyncStat();
942 mLastCalendarSync = QDateTime::currentDateTime(); 943 mLastCalendarSync = QDateTime::currentDateTime();
943 QDateTime modifiedCalendar = mLastCalendarSync;; 944 QDateTime modifiedCalendar = mLastCalendarSync;;
944 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 945 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
945 if ( eventR ) { 946 if ( eventR ) {
946 eventRSync = (Event*) eventR->clone(); 947 eventRSync = (Event*) eventR->clone();
947 remote->deleteEvent(eventR ); 948 remote->deleteEvent(eventR );
948 949
949 } else { 950 } else {
950 fullDateRange = true; 951 fullDateRange = true;
951 eventRSync = new Event(); 952 eventRSync = new Event();
952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 953 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 954 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
954 eventRSync->setDtStart( mLastCalendarSync ); 955 eventRSync->setDtStart( mLastCalendarSync );
955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 956 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
956 eventRSync->setCategories( i18n("SyncEvent") ); 957 eventRSync->setCategories( i18n("SyncEvent") );
957 } 958 }
958 eventLSync = getLastSyncEvent(); 959 eventLSync = getLastSyncEvent();
959 if ( eventLSync->dtStart() == mLastCalendarSync ) 960 if ( eventLSync->dtStart() == mLastCalendarSync )
960 fullDateRange = true; 961 fullDateRange = true;
961 962
962 if ( ! fullDateRange ) { 963 if ( ! fullDateRange ) {
963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 964 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
964 965
965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 966 // 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()); 967 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
967 fullDateRange = true; 968 fullDateRange = true;
968 } 969 }
969 } 970 }
970 if ( fullDateRange ) 971 if ( fullDateRange )
971 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 972 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
972 else 973 else
973 mLastCalendarSync = eventLSync->dtStart(); 974 mLastCalendarSync = eventLSync->dtStart();
974 // for resyncing if own file has changed 975 // for resyncing if own file has changed
975 if ( mCurrentSyncDevice == "deleteaftersync" ) { 976 if ( mCurrentSyncDevice == "deleteaftersync" ) {
976 mLastCalendarSync = loadedFileVersion; 977 mLastCalendarSync = loadedFileVersion;
977 qDebug("setting mLastCalendarSync "); 978 qDebug("setting mLastCalendarSync ");
978 } 979 }
979 //qDebug("*************************** "); 980 //qDebug("*************************** ");
980 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 981 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
981 QPtrList<Incidence> er = remote->rawIncidences(); 982 QPtrList<Incidence> er = remote->rawIncidences();
982 Incidence* inR = er.first(); 983 Incidence* inR = er.first();
983 Incidence* inL; 984 Incidence* inL;
984 QProgressBar bar( er.count(),0 ); 985 QProgressBar bar( er.count(),0 );
985 bar.setCaption (i18n("Syncing - close to abort!") ); 986 bar.setCaption (i18n("Syncing - close to abort!") );
986 987
987 int w = 300; 988 int w = 300;
988 if ( QApplication::desktop()->width() < 320 ) 989 if ( QApplication::desktop()->width() < 320 )
989 w = 220; 990 w = 220;
990 int h = bar.sizeHint().height() ; 991 int h = bar.sizeHint().height() ;
991 int dw = QApplication::desktop()->width(); 992 int dw = QApplication::desktop()->width();
992 int dh = QApplication::desktop()->height(); 993 int dh = QApplication::desktop()->height();
993 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 994 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
994 bar.show(); 995 bar.show();
995 int modulo = (er.count()/10)+1; 996 int modulo = (er.count()/10)+1;
996 int incCounter = 0; 997 int incCounter = 0;
997 while ( inR ) { 998 while ( inR ) {
998 if ( ! bar.isVisible() ) 999 if ( ! bar.isVisible() )
999 return false; 1000 return false;
1000 if ( incCounter % modulo == 0 ) 1001 if ( incCounter % modulo == 0 )
1001 bar.setProgress( incCounter ); 1002 bar.setProgress( incCounter );
1002 ++incCounter; 1003 ++incCounter;
1003 uid = inR->uid(); 1004 uid = inR->uid();
1004 bool skipIncidence = false; 1005 bool skipIncidence = false;
1005 if ( uid.left(15) == QString("last-syncEvent-") ) 1006 if ( uid.left(15) == QString("last-syncEvent-") )
1006 skipIncidence = true; 1007 skipIncidence = true;
1007 1008
1008 qApp->processEvents(); 1009 qApp->processEvents();
1009 if ( !skipIncidence ) { 1010 if ( !skipIncidence ) {
1010 inL = local->incidence( uid ); 1011 inL = local->incidence( uid );
1011 if ( inL ) { // maybe conflict - same uid in both calendars 1012 if ( inL ) { // maybe conflict - same uid in both calendars
1012 int maxrev = inL->revision(); 1013 int maxrev = inL->revision();
1013 if ( maxrev < inR->revision() ) 1014 if ( maxrev < inR->revision() )
1014 maxrev = inR->revision(); 1015 maxrev = inR->revision();
1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1016 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1016 //qDebug("take %d %s ", take, inL->summary().latin1()); 1017 //qDebug("take %d %s ", take, inL->summary().latin1());
1017 if ( take == 3 ) 1018 if ( take == 3 )
1018 return false; 1019 return false;
1019 if ( take == 1 ) {// take local 1020 if ( take == 1 ) {// take local
1020 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1021 remote->deleteIncidence( inR ); 1022 remote->deleteIncidence( inR );
1022 if ( inL->revision() < maxrev ) 1023 if ( inL->revision() < maxrev )
1023 inL->setRevision( maxrev ); 1024 inL->setRevision( maxrev );
1024 remote->addIncidence( inL->clone() ); 1025 remote->addIncidence( inL->clone() );
1025 ++changedRemote; 1026 ++changedRemote;
1026 } else { 1027 } else {
1027 if ( inR->revision() < maxrev ) 1028 if ( inR->revision() < maxrev )
1028 inR->setRevision( maxrev ); 1029 inR->setRevision( maxrev );
1029 local->deleteIncidence( inL ); 1030 local->deleteIncidence( inL );
1030 local->addIncidence( inR->clone() ); 1031 local->addIncidence( inR->clone() );
1031 ++changedLocal; 1032 ++changedLocal;
1032 } 1033 }
1033 } 1034 }
1034 } else { // no conflict 1035 } else { // no conflict
1035 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1036 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1036 QString des = eventLSync->description(); 1037 QString des = eventLSync->description();
1037 QString pref = "e"; 1038 QString pref = "e";
1038 if ( inR->type() == "Todo" ) 1039 if ( inR->type() == "Todo" )
1039 pref = "t"; 1040 pref = "t";
1040 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1041 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1041 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1042 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1042 //remote->deleteIncidence( inR ); 1043 //remote->deleteIncidence( inR );
1043 ++deletedEventR; 1044 ++deletedEventR;
1044 } else { 1045 } else {
1045 inR->setLastModified( modifiedCalendar ); 1046 inR->setLastModified( modifiedCalendar );
1046 local->addIncidence( inR->clone() ); 1047 local->addIncidence( inR->clone() );
1047 ++addedEvent; 1048 ++addedEvent;
1048 } 1049 }
1049 } else { 1050 } else {
1050 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1051 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1051 inR->setLastModified( modifiedCalendar ); 1052 inR->setLastModified( modifiedCalendar );
1052 local->addIncidence( inR->clone() ); 1053 local->addIncidence( inR->clone() );
1053 ++addedEvent; 1054 ++addedEvent;
1054 } else { 1055 } else {
1055 checkExternSyncEvent(eventRSyncSharp, inR); 1056 checkExternSyncEvent(eventRSyncSharp, inR);
1056 remote->deleteIncidence( inR ); 1057 remote->deleteIncidence( inR );
1057 ++deletedEventR; 1058 ++deletedEventR;
1058 } 1059 }
1059 } 1060 }
1060 } 1061 }
1061 } 1062 }
1062 inR = er.next(); 1063 inR = er.next();
1063 } 1064 }
1064 QPtrList<Incidence> el = local->rawIncidences(); 1065 QPtrList<Incidence> el = local->rawIncidences();
1065 inL = el.first(); 1066 inL = el.first();
1066 modulo = (el.count()/10)+1; 1067 modulo = (el.count()/10)+1;
1067 bar.setCaption (i18n("Add / remove events") ); 1068 bar.setCaption (i18n("Add / remove events") );
1068 bar.setTotalSteps ( el.count() ) ; 1069 bar.setTotalSteps ( el.count() ) ;
1069 bar.show(); 1070 bar.show();
1070 incCounter = 0; 1071 incCounter = 0;
1071 1072
1072 while ( inL ) { 1073 while ( inL ) {
1073 1074
1074 qApp->processEvents(); 1075 qApp->processEvents();
1075 if ( ! bar.isVisible() ) 1076 if ( ! bar.isVisible() )
1076 return false; 1077 return false;
1077 if ( incCounter % modulo == 0 ) 1078 if ( incCounter % modulo == 0 )
1078 bar.setProgress( incCounter ); 1079 bar.setProgress( incCounter );
1079 ++incCounter; 1080 ++incCounter;
1080 uid = inL->uid(); 1081 uid = inL->uid();
1081 bool skipIncidence = false; 1082 bool skipIncidence = false;
1082 if ( uid.left(15) == QString("last-syncEvent-") ) 1083 if ( uid.left(15) == QString("last-syncEvent-") )
1083 skipIncidence = true; 1084 skipIncidence = true;
1084 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1085 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1085 skipIncidence = true; 1086 skipIncidence = true;
1086 if ( !skipIncidence ) { 1087 if ( !skipIncidence ) {
1087 inR = remote->incidence( uid ); 1088 inR = remote->incidence( uid );
1088 if ( ! inR ) { 1089 if ( ! inR ) {
1089 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1090 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1090 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1091 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1091 local->deleteIncidence( inL ); 1092 local->deleteIncidence( inL );
1092 ++deletedEventL; 1093 ++deletedEventL;
1093 } else { 1094 } else {
1094 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1095 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1095 inL->removeID(mCurrentSyncDevice ); 1096 inL->removeID(mCurrentSyncDevice );
1096 ++addedEventR; 1097 ++addedEventR;
1097 inL->setLastModified( modifiedCalendar ); 1098 inL->setLastModified( modifiedCalendar );
1098 remote->addIncidence( inL->clone() ); 1099 remote->addIncidence( inL->clone() );
1099 } 1100 }
1100 } 1101 }
1101 } else { 1102 } else {
1102 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1103 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1103 checkExternSyncEvent(eventLSyncSharp, inL); 1104 checkExternSyncEvent(eventLSyncSharp, inL);
1104 local->deleteIncidence( inL ); 1105 local->deleteIncidence( inL );
1105 ++deletedEventL; 1106 ++deletedEventL;
1106 } else { 1107 } else {
1107 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1108 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1108 ++addedEventR; 1109 ++addedEventR;
1109 inL->setLastModified( modifiedCalendar ); 1110 inL->setLastModified( modifiedCalendar );
1110 remote->addIncidence( inL->clone() ); 1111 remote->addIncidence( inL->clone() );
1111 } 1112 }
1112 } 1113 }
1113 } 1114 }
1114 } 1115 }
1115 } 1116 }
1116 inL = el.next(); 1117 inL = el.next();
1117 } 1118 }
1118 1119
1119 bar.hide(); 1120 bar.hide();
1120 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1121 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1121 eventLSync->setReadOnly( false ); 1122 eventLSync->setReadOnly( false );
1122 eventLSync->setDtStart( mLastCalendarSync ); 1123 eventLSync->setDtStart( mLastCalendarSync );
1123 eventRSync->setDtStart( mLastCalendarSync ); 1124 eventRSync->setDtStart( mLastCalendarSync );
1124 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1125 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1125 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1126 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1126 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1127 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1127 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1128 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1128 eventLSync->setReadOnly( true ); 1129 eventLSync->setReadOnly( true );
1129 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1130 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1130 remote->addEvent( eventRSync ); 1131 remote->addEvent( eventRSync );
1131 QString mes; 1132 QString mes;
1132 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 ); 1133 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 );
1133 if ( KOPrefs::instance()->mShowSyncSummary ) { 1134 if ( KOPrefs::instance()->mShowSyncSummary ) {
1134 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1135 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1135 } 1136 }
1136 qDebug( mes ); 1137 qDebug( mes );
1137 mCalendar->checkAlarmForIncidence( 0, true ); 1138 mCalendar->checkAlarmForIncidence( 0, true );
1138 return syncOK; 1139 return syncOK;
1139} 1140}
1140 1141
1141void CalendarView::setSyncDevice( QString s ) 1142void CalendarView::setSyncDevice( QString s )
1142{ 1143{
1143 mCurrentSyncDevice= s; 1144 mCurrentSyncDevice= s;
1144} 1145}
1145void CalendarView::setSyncName( QString s ) 1146void CalendarView::setSyncName( QString s )
1146{ 1147{
1147 mCurrentSyncName= s; 1148 mCurrentSyncName= s;
1148} 1149}
1149bool CalendarView::syncCalendar(QString filename, int mode) 1150bool CalendarView::syncCalendar(QString filename, int mode)
1150{ 1151{
1151 mGlobalSyncMode = SYNC_MODE_NORMAL; 1152 mGlobalSyncMode = SYNC_MODE_NORMAL;
1152 CalendarLocal* calendar = new CalendarLocal(); 1153 CalendarLocal* calendar = new CalendarLocal();
1153 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1154 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1154 FileStorage* storage = new FileStorage( calendar ); 1155 FileStorage* storage = new FileStorage( calendar );
1155 bool syncOK = false; 1156 bool syncOK = false;
1156 storage->setFileName( filename ); 1157 storage->setFileName( filename );
1157 // qDebug("loading ... "); 1158 // qDebug("loading ... ");
1158 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1159 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1159 getEventViewerDialog()->setSyncMode( true ); 1160 getEventViewerDialog()->setSyncMode( true );
1160 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1161 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1161 getEventViewerDialog()->setSyncMode( false ); 1162 getEventViewerDialog()->setSyncMode( false );
1162 if ( syncOK ) { 1163 if ( syncOK ) {
1163 if ( KOPrefs::instance()->mWriteBackFile ) 1164 if ( KOPrefs::instance()->mWriteBackFile )
1164 { 1165 {
1165 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1166 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1166 storage->save(); 1167 storage->save();
1167 } 1168 }
1168 } 1169 }
1169 setModified( true ); 1170 setModified( true );
1170 } 1171 }
1171 delete storage; 1172 delete storage;
1172 delete calendar; 1173 delete calendar;
1173 if ( syncOK ) 1174 if ( syncOK )
1174 updateView(); 1175 updateView();
1175 return syncOK; 1176 return syncOK;
1176} 1177}
1177void CalendarView::syncPhone() 1178void CalendarView::syncPhone()
1178{ 1179{
1179 syncExternal( 1 ); 1180 syncExternal( 1 );
1180} 1181}
1181void CalendarView::syncExternal( int mode ) 1182void CalendarView::syncExternal( int mode )
1182{ 1183{
1183 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1184 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1184 //mCurrentSyncDevice = "sharp-DTM"; 1185 //mCurrentSyncDevice = "sharp-DTM";
1185 if ( KOPrefs::instance()->mAskForPreferences ) 1186 if ( KOPrefs::instance()->mAskForPreferences )
1186 edit_sync_options(); 1187 edit_sync_options();
1187 qApp->processEvents(); 1188 qApp->processEvents();
1188 CalendarLocal* calendar = new CalendarLocal(); 1189 CalendarLocal* calendar = new CalendarLocal();
1189 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1190 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1190 bool syncOK = false; 1191 bool syncOK = false;
1191 bool loadSuccess = false; 1192 bool loadSuccess = false;
1192 PhoneFormat* phoneFormat = 0; 1193 PhoneFormat* phoneFormat = 0;
1193#ifndef DESKTOP_VERSION 1194#ifndef DESKTOP_VERSION
1194 SharpFormat* sharpFormat = 0; 1195 SharpFormat* sharpFormat = 0;
1195 if ( mode == 0 ) { // sharp 1196 if ( mode == 0 ) { // sharp
1196 sharpFormat = new SharpFormat () ; 1197 sharpFormat = new SharpFormat () ;
1197 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1198 loadSuccess = sharpFormat->load( calendar, mCalendar );
1198 1199
1199 } else 1200 } else
1200#endif 1201#endif
1201 if ( mode == 1 ) { // phone 1202 if ( mode == 1 ) { // phone
1202 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1203 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1203 KOPrefs::instance()->mPhoneDevice, 1204 KOPrefs::instance()->mPhoneDevice,
1204 KOPrefs::instance()->mPhoneConnection, 1205 KOPrefs::instance()->mPhoneConnection,
1205 KOPrefs::instance()->mPhoneModel); 1206 KOPrefs::instance()->mPhoneModel);
1206 loadSuccess = phoneFormat->load( calendar,mCalendar); 1207 loadSuccess = phoneFormat->load( calendar,mCalendar);
1207 1208
1208 } else 1209 } else
1209 return; 1210 return;
1210 if ( loadSuccess ) { 1211 if ( loadSuccess ) {
1211 getEventViewerDialog()->setSyncMode( true ); 1212 getEventViewerDialog()->setSyncMode( true );
1212 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1213 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1213 getEventViewerDialog()->setSyncMode( false ); 1214 getEventViewerDialog()->setSyncMode( false );
1214 qApp->processEvents(); 1215 qApp->processEvents();
1215 if ( syncOK ) { 1216 if ( syncOK ) {
1216 if ( KOPrefs::instance()->mWriteBackFile ) 1217 if ( KOPrefs::instance()->mWriteBackFile )
1217 { 1218 {
1218 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1219 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1219 Incidence* inc = iL.first(); 1220 Incidence* inc = iL.first();
1220 /* obsolete 1221 /* obsolete
1221 while ( inc ) { 1222 while ( inc ) {
1222 inc->setZaurusStat( inc->revision () ); 1223 inc->setZaurusStat( inc->revision () );
1223 inc = iL.next(); 1224 inc = iL.next();
1224 } 1225 }
1225 */ 1226 */
1226#ifndef DESKTOP_VERSION 1227#ifndef DESKTOP_VERSION
1227 if ( sharpFormat ) 1228 if ( sharpFormat )
1228 sharpFormat->save(calendar); 1229 sharpFormat->save(calendar);
1229#endif 1230#endif
1230 if ( phoneFormat ) 1231 if ( phoneFormat )
1231 phoneFormat->save(calendar); 1232 phoneFormat->save(calendar);
1232 iL = calendar->rawIncidences(); 1233 iL = calendar->rawIncidences();
1233 inc = iL.first(); 1234 inc = iL.first();
1234 Incidence* loc; 1235 Incidence* loc;
1235 while ( inc ) { 1236 while ( inc ) {
1236 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1237 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1237 loc = mCalendar->incidence(inc->uid() ); 1238 loc = mCalendar->incidence(inc->uid() );
1238 if ( loc ) { 1239 if ( loc ) {
1239 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1240 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1240 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1241 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1241 } 1242 }
1242 } 1243 }
1243 inc = iL.next(); 1244 inc = iL.next();
1244 } 1245 }
1245 Incidence* lse = getLastSyncEvent(); 1246 Incidence* lse = getLastSyncEvent();
1246 if ( lse ) { 1247 if ( lse ) {
1247 lse->setReadOnly( false ); 1248 lse->setReadOnly( false );
1248 lse->setDescription( "" ); 1249 lse->setDescription( "" );
1249 lse->setReadOnly( true ); 1250 lse->setReadOnly( true );
1250 } 1251 }
1251 } 1252 }
1252 } 1253 }
1253 setModified( true ); 1254 setModified( true );
1254 } else { 1255 } else {
1255 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1256 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1256 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1257 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1257 question, i18n("Ok")) ; 1258 question, i18n("Ok")) ;
1258 1259
1259 } 1260 }
1260 delete calendar; 1261 delete calendar;
1261 updateView(); 1262 updateView();
1262 return ;//syncOK; 1263 return ;//syncOK;
1263 1264
1264} 1265}
1265void CalendarView::syncSharp() 1266void CalendarView::syncSharp()
1266{ 1267{
1267 syncExternal( 0 ); 1268 syncExternal( 0 );
1268 1269
1269} 1270}
1270 1271
1271 1272
1272#include <kabc/stdaddressbook.h> 1273#include <kabc/stdaddressbook.h>
1273bool CalendarView::importBday() 1274bool CalendarView::importBday()
1274{ 1275{
1275 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1276 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1276 KABC::AddressBook::Iterator it; 1277 KABC::AddressBook::Iterator it;
1277 int count = 0; 1278 int count = 0;
1278 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1279 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1279 ++count; 1280 ++count;
1280 } 1281 }
1281 QProgressBar bar(count,0 ); 1282 QProgressBar bar(count,0 );
1282 int w = 300; 1283 int w = 300;
1283 if ( QApplication::desktop()->width() < 320 ) 1284 if ( QApplication::desktop()->width() < 320 )
1284 w = 220; 1285 w = 220;
1285 int h = bar.sizeHint().height() ; 1286 int h = bar.sizeHint().height() ;
1286 int dw = QApplication::desktop()->width(); 1287 int dw = QApplication::desktop()->width();
1287 int dh = QApplication::desktop()->height(); 1288 int dh = QApplication::desktop()->height();
1288 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1289 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1289 bar.show(); 1290 bar.show();
1290 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1291 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1291 qApp->processEvents(); 1292 qApp->processEvents();
1292 count = 0; 1293 count = 0;
1293 int addCount = 0; 1294 int addCount = 0;
1294 KCal::Attendee* a = 0; 1295 KCal::Attendee* a = 0;
1295 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1296 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1296 if ( ! bar.isVisible() ) 1297 if ( ! bar.isVisible() )
1297 return false; 1298 return false;
1298 bar.setProgress( count++ ); 1299 bar.setProgress( count++ );
1299 qApp->processEvents(); 1300 qApp->processEvents();
1300 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1301 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1301 if ( (*it).birthday().date().isValid() ){ 1302 if ( (*it).birthday().date().isValid() ){
1302 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1303 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1303 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1304 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1304 ++addCount; 1305 ++addCount;
1305 } 1306 }
1306 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1307 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1307 if ( anni.isValid() ){ 1308 if ( anni.isValid() ){
1308 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1309 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1309 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1310 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1310 ++addCount; 1311 ++addCount;
1311 } 1312 }
1312 } 1313 }
1313 updateView(); 1314 updateView();
1314 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1315 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1315 return true; 1316 return true;
1316} 1317}
1317 1318
1318bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1319bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1319{ 1320{
1320 //qDebug("addAnni "); 1321 //qDebug("addAnni ");
1321 Event * ev = new Event(); 1322 Event * ev = new Event();
1322 if ( a ) { 1323 if ( a ) {
1323 ev->addAttendee( a ); 1324 ev->addAttendee( a );
1324 } 1325 }
1325 QString kind; 1326 QString kind;
1326 if ( birthday ) 1327 if ( birthday )
1327 kind = i18n( "Birthday" ); 1328 kind = i18n( "Birthday" );
1328 else 1329 else
1329 kind = i18n( "Anniversary" ); 1330 kind = i18n( "Anniversary" );
1330 ev->setSummary( name + " - " + kind ); 1331 ev->setSummary( name + " - " + kind );
1331 ev->setOrganizer( "nobody@nowhere" ); 1332 ev->setOrganizer( "nobody@nowhere" );
1332 ev->setCategories( kind ); 1333 ev->setCategories( kind );
1333 ev->setDtStart( QDateTime(date) ); 1334 ev->setDtStart( QDateTime(date) );
1334 ev->setDtEnd( QDateTime(date) ); 1335 ev->setDtEnd( QDateTime(date) );
1335 ev->setFloats( true ); 1336 ev->setFloats( true );
1336 Recurrence * rec = ev->recurrence(); 1337 Recurrence * rec = ev->recurrence();
1337 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1338 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1338 rec->addYearlyNum( date.month() ); 1339 rec->addYearlyNum( date.month() );
1339 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1340 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1340 delete ev; 1341 delete ev;
1341 return false; 1342 return false;
1342 } 1343 }
1343 return true; 1344 return true;
1344 1345
1345} 1346}
1346bool CalendarView::importQtopia( const QString &categories, 1347bool CalendarView::importQtopia( const QString &categories,
1347 const QString &datebook, 1348 const QString &datebook,
1348 const QString &todolist ) 1349 const QString &todolist )
1349{ 1350{
1350 1351
1351 QtopiaFormat qtopiaFormat; 1352 QtopiaFormat qtopiaFormat;
1352 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1353 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1353 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1354 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1354 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1355 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1355 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1356 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1356 1357
1357 updateView(); 1358 updateView();
1358 return true; 1359 return true;
1359 1360
1360#if 0 1361#if 0
1361 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1362 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1362 mCurrentSyncDevice = "qtopia-XML"; 1363 mCurrentSyncDevice = "qtopia-XML";
1363 if ( KOPrefs::instance()->mAskForPreferences ) 1364 if ( KOPrefs::instance()->mAskForPreferences )
1364 edit_sync_options(); 1365 edit_sync_options();
1365 qApp->processEvents(); 1366 qApp->processEvents();
1366 CalendarLocal* calendar = new CalendarLocal(); 1367 CalendarLocal* calendar = new CalendarLocal();
1367 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1368 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1368 bool syncOK = false; 1369 bool syncOK = false;
1369 QtopiaFormat qtopiaFormat; 1370 QtopiaFormat qtopiaFormat;
1370 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1371 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1371 bool loadOk = true; 1372 bool loadOk = true;
1372 if ( !categories.isEmpty() ) 1373 if ( !categories.isEmpty() )
1373 loadOk = qtopiaFormat.load( calendar, categories ); 1374 loadOk = qtopiaFormat.load( calendar, categories );
1374 if ( loadOk && !datebook.isEmpty() ) 1375 if ( loadOk && !datebook.isEmpty() )
1375 loadOk = qtopiaFormat.load( calendar, datebook ); 1376 loadOk = qtopiaFormat.load( calendar, datebook );
1376 if ( loadOk && !todolist.isEmpty() ) 1377 if ( loadOk && !todolist.isEmpty() )
1377 loadOk = qtopiaFormat.load( calendar, todolist ); 1378 loadOk = qtopiaFormat.load( calendar, todolist );
1378 1379
1379 if ( loadOk ) { 1380 if ( loadOk ) {
1380 getEventViewerDialog()->setSyncMode( true ); 1381 getEventViewerDialog()->setSyncMode( true );
1381 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1382 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1382 getEventViewerDialog()->setSyncMode( false ); 1383 getEventViewerDialog()->setSyncMode( false );
1383 qApp->processEvents(); 1384 qApp->processEvents();
1384 if ( syncOK ) { 1385 if ( syncOK ) {
1385 if ( KOPrefs::instance()->mWriteBackFile ) 1386 if ( KOPrefs::instance()->mWriteBackFile )
1386 { 1387 {
1387 // write back XML file 1388 // write back XML file
1388 1389
1389 } 1390 }
1390 setModified( true ); 1391 setModified( true );
1391 } 1392 }
1392 } else { 1393 } else {
1393 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1394 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1394 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1395 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1395 question, i18n("Ok")) ; 1396 question, i18n("Ok")) ;
1396 } 1397 }
1397 delete calendar; 1398 delete calendar;
1398 updateView(); 1399 updateView();
1399 return syncOK; 1400 return syncOK;
1400 1401
1401 1402
1402#endif 1403#endif
1403 1404
1404} 1405}
1405 1406
1406void CalendarView::setSyncEventsReadOnly() 1407void CalendarView::setSyncEventsReadOnly()
1407{ 1408{
1408 Event * ev; 1409 Event * ev;
1409 QPtrList<Event> eL = mCalendar->rawEvents(); 1410 QPtrList<Event> eL = mCalendar->rawEvents();
1410 ev = eL.first(); 1411 ev = eL.first();
1411 while ( ev ) { 1412 while ( ev ) {
1412 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1413 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1413 ev->setReadOnly( true ); 1414 ev->setReadOnly( true );
1414 ev = eL.next(); 1415 ev = eL.next();
1415 } 1416 }
1416} 1417}
1417bool CalendarView::openCalendar(QString filename, bool merge) 1418bool CalendarView::openCalendar(QString filename, bool merge)
1418{ 1419{
1419 1420
1420 if (filename.isEmpty()) { 1421 if (filename.isEmpty()) {
1421 return false; 1422 return false;
1422 } 1423 }
1423 1424
1424 if (!QFile::exists(filename)) { 1425 if (!QFile::exists(filename)) {
1425 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1426 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1426 return false; 1427 return false;
1427 } 1428 }
1428 1429
1429 globalFlagBlockAgenda = 1; 1430 globalFlagBlockAgenda = 1;
1430 if (!merge) mCalendar->close(); 1431 if (!merge) mCalendar->close();
1431 1432
1432 mStorage->setFileName( filename ); 1433 mStorage->setFileName( filename );
1433 1434
1434 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) { 1435 if ( mStorage->load(KOPrefs::instance()->mUseQuicksave) ) {
1435 if ( merge ) ;//setModified( true ); 1436 if ( merge ) ;//setModified( true );
1436 else { 1437 else {
1437 //setModified( true ); 1438 //setModified( true );
1438 mViewManager->setDocumentId( filename ); 1439 mViewManager->setDocumentId( filename );
1439 mDialogManager->setDocumentId( filename ); 1440 mDialogManager->setDocumentId( filename );
1440 mTodoList->setDocumentId( filename ); 1441 mTodoList->setDocumentId( filename );
1441 } 1442 }
1442 globalFlagBlockAgenda = 2; 1443 globalFlagBlockAgenda = 2;
1443 // if ( getLastSyncEvent() ) 1444 // if ( getLastSyncEvent() )
1444 // getLastSyncEvent()->setReadOnly( true ); 1445 // getLastSyncEvent()->setReadOnly( true );
1445 mCalendar->reInitAlarmSettings(); 1446 mCalendar->reInitAlarmSettings();
1446 setSyncEventsReadOnly(); 1447 setSyncEventsReadOnly();
1447 updateUnmanagedViews(); 1448 updateUnmanagedViews();
1448 updateView(); 1449 updateView();
1449 if ( filename != MainWindow::defaultFileName() ) 1450 if ( filename != MainWindow::defaultFileName() )
1450 saveCalendar( MainWindow::defaultFileName() ); 1451 saveCalendar( MainWindow::defaultFileName() );
1451 loadedFileVersion = QDateTime::currentDateTime(); 1452 loadedFileVersion = QDateTime::currentDateTime();
1452 return true; 1453 return true;
1453 } else { 1454 } else {
1454 // while failing to load, the calendar object could 1455 // while failing to load, the calendar object could
1455 // have become partially populated. Clear it out. 1456 // have become partially populated. Clear it out.
1456 if ( !merge ) mCalendar->close(); 1457 if ( !merge ) mCalendar->close();
1457 1458
1458 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1459 KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1459 1460
1460 globalFlagBlockAgenda = 2; 1461 globalFlagBlockAgenda = 2;
1461 updateView(); 1462 updateView();
1462 } 1463 }
1463 return false; 1464 return false;
1464} 1465}
1465void CalendarView::setLoadedFileVersion(QDateTime dt) 1466void CalendarView::setLoadedFileVersion(QDateTime dt)
1466{ 1467{
1467 loadedFileVersion = dt; 1468 loadedFileVersion = dt;
1468} 1469}
1469bool CalendarView::checkFileChanged(QString fn) 1470bool CalendarView::checkFileChanged(QString fn)
1470{ 1471{
1471 QFileInfo finf ( fn ); 1472 QFileInfo finf ( fn );
1472 if ( !finf.exists() ) 1473 if ( !finf.exists() )
1473 return true; 1474 return true;
1474 QDateTime dt = finf.lastModified (); 1475 QDateTime dt = finf.lastModified ();
1475 if ( dt <= loadedFileVersion ) 1476 if ( dt <= loadedFileVersion )
1476 return false; 1477 return false;
1477 return true; 1478 return true;
1478 1479
1479} 1480}
1480bool CalendarView::checkFileVersion(QString fn) 1481bool CalendarView::checkFileVersion(QString fn)
1481{ 1482{
1482 QFileInfo finf ( fn ); 1483 QFileInfo finf ( fn );
1483 if ( !finf.exists() ) 1484 if ( !finf.exists() )
1484 return true; 1485 return true;
1485 QDateTime dt = finf.lastModified (); 1486 QDateTime dt = finf.lastModified ();
1486 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1487 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1487 //qDebug("file on disk version %s",dt.toString().latin1()); 1488 //qDebug("file on disk version %s",dt.toString().latin1());
1488 if ( dt <= loadedFileVersion ) 1489 if ( dt <= loadedFileVersion )
1489 return true; 1490 return true;
1490 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) , 1491 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, false)) ,
1491 i18n("KO/Pi Warning"),i18n("Overwrite"), 1492 i18n("KO/Pi Warning"),i18n("Overwrite"),
1492 i18n("Sync+save")); 1493 i18n("Sync+save"));
1493 1494
1494 if ( km == KMessageBox::Cancel ) 1495 if ( km == KMessageBox::Cancel )
1495 return false; 1496 return false;
1496 if ( km == KMessageBox::Yes ) 1497 if ( km == KMessageBox::Yes )
1497 return true; 1498 return true;
1498 1499
1499 setSyncDevice("deleteaftersync" ); 1500 setSyncDevice("deleteaftersync" );
1500 KOPrefs::instance()->mAskForPreferences = true; 1501 KOPrefs::instance()->mAskForPreferences = true;
1501 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1502 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1502 KOPrefs::instance()->mWriteBackFile = false; 1503 KOPrefs::instance()->mWriteBackFile = false;
1503 KOPrefs::instance()->mWriteBackExistingOnly = false; 1504 KOPrefs::instance()->mWriteBackExistingOnly = false;
1504 KOPrefs::instance()->mShowSyncSummary = false; 1505 KOPrefs::instance()->mShowSyncSummary = false;
1505 syncCalendar( fn, 3 ); 1506 syncCalendar( fn, 3 );
1506 Event * e = getLastSyncEvent(); 1507 Event * e = getLastSyncEvent();
1507 mCalendar->deleteEvent ( e ); 1508 mCalendar->deleteEvent ( e );
1508 updateView(); 1509 updateView();
1509 return true; 1510 return true;
1510} 1511}
1511 1512
1512bool CalendarView::saveCalendar( QString filename ) 1513bool CalendarView::saveCalendar( QString filename )
1513{ 1514{
1514 1515
1515 // Store back all unsaved data into calendar object 1516 // Store back all unsaved data into calendar object
1516 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1517 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1517 if ( mViewManager->currentView() ) 1518 if ( mViewManager->currentView() )
1518 mViewManager->currentView()->flushView(); 1519 mViewManager->currentView()->flushView();
1519 1520
1520 //mStorage->setFileName( filename ); 1521 //mStorage->setFileName( filename );
1521 1522
1522 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1523 mStorage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1523 mStorage->setFileName( filename ); 1524 mStorage->setFileName( filename );
1524 bool success; 1525 bool success;
1525 success = mStorage->save(); 1526 success = mStorage->save();
1526 if ( !success ) { 1527 if ( !success ) {
1527 return false; 1528 return false;
1528 } 1529 }
1529 1530
1530 return true; 1531 return true;
1531} 1532}
1532 1533
1533void CalendarView::closeCalendar() 1534void CalendarView::closeCalendar()
1534{ 1535{
1535 1536
1536 // child windows no longer valid 1537 // child windows no longer valid
1537 emit closingDown(); 1538 emit closingDown();
1538 1539
1539 mCalendar->close(); 1540 mCalendar->close();
1540 setModified(false); 1541 setModified(false);
1541 updateView(); 1542 updateView();
1542} 1543}
1543 1544
1544void CalendarView::archiveCalendar() 1545void CalendarView::archiveCalendar()
1545{ 1546{
1546 mDialogManager->showArchiveDialog(); 1547 mDialogManager->showArchiveDialog();
1547} 1548}
1548 1549
1549 1550
1550void CalendarView::readSettings() 1551void CalendarView::readSettings()
1551{ 1552{
1552 1553
1553 1554
1554 // mViewManager->showAgendaView(); 1555 // mViewManager->showAgendaView();
1555 QString str; 1556 QString str;
1556 //qDebug("CalendarView::readSettings() "); 1557 //qDebug("CalendarView::readSettings() ");
1557 // read settings from the KConfig, supplying reasonable 1558 // read settings from the KConfig, supplying reasonable
1558 // defaults where none are to be found 1559 // defaults where none are to be found
1559 KConfig *config = KOGlobals::config(); 1560 KConfig *config = KOGlobals::config();
1560#ifndef KORG_NOSPLITTER 1561#ifndef KORG_NOSPLITTER
1561 config->setGroup("KOrganizer Geometry"); 1562 config->setGroup("KOrganizer Geometry");
1562 1563
1563 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1564 QValueList<int> sizes = config->readIntListEntry("Separator1");
1564 if (sizes.count() != 2) { 1565 if (sizes.count() != 2) {
1565 sizes << mDateNavigator->minimumSizeHint().width(); 1566 sizes << mDateNavigator->minimumSizeHint().width();
1566 sizes << 300; 1567 sizes << 300;
1567 } 1568 }
1568 mPanner->setSizes(sizes); 1569 mPanner->setSizes(sizes);
1569 1570
1570 sizes = config->readIntListEntry("Separator2"); 1571 sizes = config->readIntListEntry("Separator2");
1571 if ( ( mResourceView && sizes.count() == 4 ) || 1572 if ( ( mResourceView && sizes.count() == 4 ) ||
1572 ( !mResourceView && sizes.count() == 3 ) ) { 1573 ( !mResourceView && sizes.count() == 3 ) ) {
1573 mLeftSplitter->setSizes(sizes); 1574 mLeftSplitter->setSizes(sizes);
1574 } 1575 }
1575#endif 1576#endif
1576 globalFlagBlockAgenda = 1; 1577 globalFlagBlockAgenda = 1;
1577 mViewManager->showAgendaView(); 1578 mViewManager->showAgendaView();
1578 //mViewManager->readSettings( config ); 1579 //mViewManager->readSettings( config );
1579 mTodoList->restoreLayout(config,QString("Todo Layout")); 1580 mTodoList->restoreLayout(config,QString("Todo Layout"));
1580 readFilterSettings(config); 1581 readFilterSettings(config);
1581 config->setGroup( "Views" ); 1582 config->setGroup( "Views" );
1582 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1583 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1583 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1584 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1584 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1585 else if ( dateCount == 7 ) mNavigator->selectWeek();
1585 else mNavigator->selectDates( dateCount ); 1586 else mNavigator->selectDates( dateCount );
1586 // mViewManager->readSettings( config ); 1587 // mViewManager->readSettings( config );
1587 updateConfig(); 1588 updateConfig();
1588 globalFlagBlockAgenda = 2; 1589 globalFlagBlockAgenda = 2;
1589 mViewManager->readSettings( config ); 1590 mViewManager->readSettings( config );
1590#ifdef DESKTOP_VERSION 1591#ifdef DESKTOP_VERSION
1591 config->setGroup("WidgetLayout"); 1592 config->setGroup("WidgetLayout");
1592 QStringList list; 1593 QStringList list;
1593 list = config->readListEntry("MainLayout"); 1594 list = config->readListEntry("MainLayout");
1594 int x,y,w,h; 1595 int x,y,w,h;
1595 if ( ! list.isEmpty() ) { 1596 if ( ! list.isEmpty() ) {
1596 x = list[0].toInt(); 1597 x = list[0].toInt();
1597 y = list[1].toInt(); 1598 y = list[1].toInt();
1598 w = list[2].toInt(); 1599 w = list[2].toInt();
1599 h = list[3].toInt(); 1600 h = list[3].toInt();
1600 topLevelWidget()->setGeometry(x,y,w,h); 1601 topLevelWidget()->setGeometry(x,y,w,h);
1601 1602
1602 } else { 1603 } else {
1603 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1604 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1604 } 1605 }
1605 list = config->readListEntry("EditEventLayout"); 1606 list = config->readListEntry("EditEventLayout");
1606 if ( ! list.isEmpty() ) { 1607 if ( ! list.isEmpty() ) {
1607 x = list[0].toInt(); 1608 x = list[0].toInt();
1608 y = list[1].toInt(); 1609 y = list[1].toInt();
1609 w = list[2].toInt(); 1610 w = list[2].toInt();
1610 h = list[3].toInt(); 1611 h = list[3].toInt();
1611 mEventEditor->setGeometry(x,y,w,h); 1612 mEventEditor->setGeometry(x,y,w,h);
1612 1613
1613 } 1614 }
1614 list = config->readListEntry("EditTodoLayout"); 1615 list = config->readListEntry("EditTodoLayout");
1615 if ( ! list.isEmpty() ) { 1616 if ( ! list.isEmpty() ) {
1616 x = list[0].toInt(); 1617 x = list[0].toInt();
1617 y = list[1].toInt(); 1618 y = list[1].toInt();
1618 w = list[2].toInt(); 1619 w = list[2].toInt();
1619 h = list[3].toInt(); 1620 h = list[3].toInt();
1620 mTodoEditor->setGeometry(x,y,w,h); 1621 mTodoEditor->setGeometry(x,y,w,h);
1621 1622
1622 } 1623 }
1623 list = config->readListEntry("ViewerLayout"); 1624 list = config->readListEntry("ViewerLayout");
1624 if ( ! list.isEmpty() ) { 1625 if ( ! list.isEmpty() ) {
1625 x = list[0].toInt(); 1626 x = list[0].toInt();
1626 y = list[1].toInt(); 1627 y = list[1].toInt();
1627 w = list[2].toInt(); 1628 w = list[2].toInt();
1628 h = list[3].toInt(); 1629 h = list[3].toInt();
1629 getEventViewerDialog()->setGeometry(x,y,w,h); 1630 getEventViewerDialog()->setGeometry(x,y,w,h);
1630 } 1631 }
1631#endif 1632#endif
1632 1633
1633} 1634}
1634 1635
1635 1636
1636void CalendarView::writeSettings() 1637void CalendarView::writeSettings()
1637{ 1638{
1638 // kdDebug() << "CalendarView::writeSettings" << endl; 1639 // kdDebug() << "CalendarView::writeSettings" << endl;
1639 1640
1640 KConfig *config = KOGlobals::config(); 1641 KConfig *config = KOGlobals::config();
1641 1642
1642#ifndef KORG_NOSPLITTER 1643#ifndef KORG_NOSPLITTER
1643 config->setGroup("KOrganizer Geometry"); 1644 config->setGroup("KOrganizer Geometry");
1644 1645
1645 QValueList<int> list = mPanner->sizes(); 1646 QValueList<int> list = mPanner->sizes();
1646 config->writeEntry("Separator1",list); 1647 config->writeEntry("Separator1",list);
1647 1648
1648 list = mLeftSplitter->sizes(); 1649 list = mLeftSplitter->sizes();
1649 config->writeEntry("Separator2",list); 1650 config->writeEntry("Separator2",list);
1650#endif 1651#endif
1651 1652
1652 mViewManager->writeSettings( config ); 1653 mViewManager->writeSettings( config );
1653 mTodoList->saveLayout(config,QString("Todo Layout")); 1654 mTodoList->saveLayout(config,QString("Todo Layout"));
1654 mDialogManager->writeSettings( config ); 1655 mDialogManager->writeSettings( config );
1655 //KOPrefs::instance()->usrWriteConfig(); 1656 //KOPrefs::instance()->usrWriteConfig();
1656 KOPrefs::instance()->writeConfig(); 1657 KOPrefs::instance()->writeConfig();
1657 1658
1658 writeFilterSettings(config); 1659 writeFilterSettings(config);
1659 1660
1660 config->setGroup( "Views" ); 1661 config->setGroup( "Views" );
1661 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1662 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1662 1663
1663#ifdef DESKTOP_VERSION 1664#ifdef DESKTOP_VERSION
1664 config->setGroup("WidgetLayout"); 1665 config->setGroup("WidgetLayout");
1665 QStringList list ;//= config->readListEntry("MainLayout"); 1666 QStringList list ;//= config->readListEntry("MainLayout");
1666 int x,y,w,h; 1667 int x,y,w,h;
1667 QWidget* wid; 1668 QWidget* wid;
1668 wid = topLevelWidget(); 1669 wid = topLevelWidget();
1669 x = wid->geometry().x(); 1670 x = wid->geometry().x();
1670 y = wid->geometry().y(); 1671 y = wid->geometry().y();
1671 w = wid->width(); 1672 w = wid->width();
1672 h = wid->height(); 1673 h = wid->height();
1673 list.clear(); 1674 list.clear();
1674 list << QString::number( x ); 1675 list << QString::number( x );
1675 list << QString::number( y ); 1676 list << QString::number( y );
1676 list << QString::number( w ); 1677 list << QString::number( w );
1677 list << QString::number( h ); 1678 list << QString::number( h );
1678 config->writeEntry("MainLayout",list ); 1679 config->writeEntry("MainLayout",list );
1679 1680
1680 wid = mEventEditor; 1681 wid = mEventEditor;
1681 x = wid->geometry().x(); 1682 x = wid->geometry().x();
1682 y = wid->geometry().y(); 1683 y = wid->geometry().y();
1683 w = wid->width(); 1684 w = wid->width();
1684 h = wid->height(); 1685 h = wid->height();
1685 list.clear(); 1686 list.clear();
1686 list << QString::number( x ); 1687 list << QString::number( x );
1687 list << QString::number( y ); 1688 list << QString::number( y );
1688 list << QString::number( w ); 1689 list << QString::number( w );
1689 list << QString::number( h ); 1690 list << QString::number( h );
1690 config->writeEntry("EditEventLayout",list ); 1691 config->writeEntry("EditEventLayout",list );
1691 1692
1692 wid = mTodoEditor; 1693 wid = mTodoEditor;
1693 x = wid->geometry().x(); 1694 x = wid->geometry().x();
1694 y = wid->geometry().y(); 1695 y = wid->geometry().y();
1695 w = wid->width(); 1696 w = wid->width();
1696 h = wid->height(); 1697 h = wid->height();
1697 list.clear(); 1698 list.clear();
1698 list << QString::number( x ); 1699 list << QString::number( x );
1699 list << QString::number( y ); 1700 list << QString::number( y );
1700 list << QString::number( w ); 1701 list << QString::number( w );
1701 list << QString::number( h ); 1702 list << QString::number( h );
1702 config->writeEntry("EditTodoLayout",list ); 1703 config->writeEntry("EditTodoLayout",list );
1703 wid = getEventViewerDialog(); 1704 wid = getEventViewerDialog();
1704 x = wid->geometry().x(); 1705 x = wid->geometry().x();
1705 y = wid->geometry().y(); 1706 y = wid->geometry().y();
1706 w = wid->width(); 1707 w = wid->width();
1707 h = wid->height(); 1708 h = wid->height();
1708 list.clear(); 1709 list.clear();
1709 list << QString::number( x ); 1710 list << QString::number( x );
1710 list << QString::number( y ); 1711 list << QString::number( y );
1711 list << QString::number( w ); 1712 list << QString::number( w );
1712 list << QString::number( h ); 1713 list << QString::number( h );
1713 config->writeEntry("ViewerLayout",list ); 1714 config->writeEntry("ViewerLayout",list );
1714 wid = mDialogManager->getSearchDialog(); 1715 wid = mDialogManager->getSearchDialog();
1715 if ( wid ) { 1716 if ( wid ) {
1716 x = wid->geometry().x(); 1717 x = wid->geometry().x();
1717 y = wid->geometry().y(); 1718 y = wid->geometry().y();
1718 w = wid->width(); 1719 w = wid->width();
1719 h = wid->height(); 1720 h = wid->height();
1720 list.clear(); 1721 list.clear();
1721 list << QString::number( x ); 1722 list << QString::number( x );
1722 list << QString::number( y ); 1723 list << QString::number( y );
1723 list << QString::number( w ); 1724 list << QString::number( w );
1724 list << QString::number( h ); 1725 list << QString::number( h );
1725 config->writeEntry("SearchLayout",list ); 1726 config->writeEntry("SearchLayout",list );
1726 } 1727 }
1727#endif 1728#endif
1728 1729
1729 1730
1730 config->sync(); 1731 config->sync();
1731} 1732}
1732 1733
1733void CalendarView::readFilterSettings(KConfig *config) 1734void CalendarView::readFilterSettings(KConfig *config)
1734{ 1735{
1735 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1736 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1736 1737
1737 mFilters.clear(); 1738 mFilters.clear();
1738 1739
1739 config->setGroup("General"); 1740 config->setGroup("General");
1740 QStringList filterList = config->readListEntry("CalendarFilters"); 1741 QStringList filterList = config->readListEntry("CalendarFilters");
1741 1742
1742 QStringList::ConstIterator it = filterList.begin(); 1743 QStringList::ConstIterator it = filterList.begin();
1743 QStringList::ConstIterator end = filterList.end(); 1744 QStringList::ConstIterator end = filterList.end();
1744 while(it != end) { 1745 while(it != end) {
1745 // kdDebug() << " filter: " << (*it) << endl; 1746 // kdDebug() << " filter: " << (*it) << endl;
1746 1747
1747 CalFilter *filter; 1748 CalFilter *filter;
1748 filter = new CalFilter(*it); 1749 filter = new CalFilter(*it);
1749 config->setGroup("Filter_" + (*it)); 1750 config->setGroup("Filter_" + (*it));
1750 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1751 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1751 filter->setCriteria(config->readNumEntry("Criteria",0)); 1752 filter->setCriteria(config->readNumEntry("Criteria",0));
1752 filter->setCategoryList(config->readListEntry("CategoryList")); 1753 filter->setCategoryList(config->readListEntry("CategoryList"));
1753 mFilters.append(filter); 1754 mFilters.append(filter);
1754 1755
1755 ++it; 1756 ++it;
1756 } 1757 }
1757 1758
1758 if (mFilters.count() == 0) { 1759 if (mFilters.count() == 0) {
1759 CalFilter *filter = new CalFilter(i18n("Default")); 1760 CalFilter *filter = new CalFilter(i18n("Default"));
1760 mFilters.append(filter); 1761 mFilters.append(filter);
1761 } 1762 }
1762 mFilterView->updateFilters(); 1763 mFilterView->updateFilters();
1763 config->setGroup("FilterView"); 1764 config->setGroup("FilterView");
1764 1765
1765 mFilterView->blockSignals(true); 1766 mFilterView->blockSignals(true);
1766 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1767 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1767 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1768 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1768 mFilterView->blockSignals(false); 1769 mFilterView->blockSignals(false);
1769 // We do it manually to avoid it being done twice by the above calls 1770 // We do it manually to avoid it being done twice by the above calls
1770 updateFilter(); 1771 updateFilter();
1771} 1772}
1772 1773
1773void CalendarView::writeFilterSettings(KConfig *config) 1774void CalendarView::writeFilterSettings(KConfig *config)
1774{ 1775{
1775 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1776 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1776 1777
1777 QStringList filterList; 1778 QStringList filterList;
1778 1779
1779 CalFilter *filter = mFilters.first(); 1780 CalFilter *filter = mFilters.first();
1780 while(filter) { 1781 while(filter) {
1781 // kdDebug() << " fn: " << filter->name() << endl; 1782 // kdDebug() << " fn: " << filter->name() << endl;
1782 filterList << filter->name(); 1783 filterList << filter->name();
1783 config->setGroup("Filter_" + filter->name()); 1784 config->setGroup("Filter_" + filter->name());
1784 config->writeEntry("Criteria",filter->criteria()); 1785 config->writeEntry("Criteria",filter->criteria());
1785 config->writeEntry("CategoryList",filter->categoryList()); 1786 config->writeEntry("CategoryList",filter->categoryList());
1786 filter = mFilters.next(); 1787 filter = mFilters.next();
1787 } 1788 }
1788 config->setGroup("General"); 1789 config->setGroup("General");
1789 config->writeEntry("CalendarFilters",filterList); 1790 config->writeEntry("CalendarFilters",filterList);
1790 1791
1791 config->setGroup("FilterView"); 1792 config->setGroup("FilterView");
1792 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1793 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1793 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1794 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1794} 1795}
1795 1796
1796 1797
1797void CalendarView::goToday() 1798void CalendarView::goToday()
1798{ 1799{
1799 mNavigator->selectToday(); 1800 mNavigator->selectToday();
1800} 1801}
1801 1802
1802void CalendarView::goNext() 1803void CalendarView::goNext()
1803{ 1804{
1804 mNavigator->selectNext(); 1805 mNavigator->selectNext();
1805} 1806}
1806 1807
1807void CalendarView::goPrevious() 1808void CalendarView::goPrevious()
1808{ 1809{
1809 mNavigator->selectPrevious(); 1810 mNavigator->selectPrevious();
1810} 1811}
1811void CalendarView::goNextMonth() 1812void CalendarView::goNextMonth()
1812{ 1813{
1813 mNavigator->selectNextMonth(); 1814 mNavigator->selectNextMonth();
1814} 1815}
1815 1816
1816void CalendarView::goPreviousMonth() 1817void CalendarView::goPreviousMonth()
1817{ 1818{
1818 mNavigator->selectPreviousMonth(); 1819 mNavigator->selectPreviousMonth();
1819} 1820}
1820void CalendarView::writeLocale() 1821void CalendarView::writeLocale()
1821{ 1822{
1822 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1823 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1823 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1824 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1824 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1825 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1825 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1826 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1826 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1827 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1827 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1828 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1828 dummy = KOPrefs::instance()->mUserDateFormatShort; 1829 dummy = KOPrefs::instance()->mUserDateFormatShort;
1829 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1830 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1830 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1831 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1831 KOPrefs::instance()->mDaylightsavingStart, 1832 KOPrefs::instance()->mDaylightsavingStart,
1832 KOPrefs::instance()->mDaylightsavingEnd ); 1833 KOPrefs::instance()->mDaylightsavingEnd );
1833 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1834 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1834} 1835}
1835void CalendarView::updateConfig() 1836void CalendarView::updateConfig()
1836{ 1837{
1837 writeLocale(); 1838 writeLocale();
1838 if ( KOPrefs::instance()->mUseAppColors ) 1839 if ( KOPrefs::instance()->mUseAppColors )
1839 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1840 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1840 emit configChanged(); 1841 emit configChanged();
1841 mTodoList->updateConfig(); 1842 mTodoList->updateConfig();
1842 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1843 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1843 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1844 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1844 // To make the "fill window" configurations work 1845 // To make the "fill window" configurations work
1845 //mViewManager->raiseCurrentView(); 1846 //mViewManager->raiseCurrentView();
1846} 1847}
1847 1848
1848 1849
1849void CalendarView::eventChanged(Event *event) 1850void CalendarView::eventChanged(Event *event)
1850{ 1851{
1851 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1852 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1852 //updateUnmanagedViews(); 1853 //updateUnmanagedViews();
1853} 1854}
1854 1855
1855void CalendarView::eventAdded(Event *event) 1856void CalendarView::eventAdded(Event *event)
1856{ 1857{
1857 changeEventDisplay(event,KOGlobals::EVENTADDED); 1858 changeEventDisplay(event,KOGlobals::EVENTADDED);
1858} 1859}
1859 1860
1860void CalendarView::eventToBeDeleted(Event *) 1861void CalendarView::eventToBeDeleted(Event *)
1861{ 1862{
1862 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 1863 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
1863} 1864}
1864 1865
1865void CalendarView::eventDeleted() 1866void CalendarView::eventDeleted()
1866{ 1867{
1867 changeEventDisplay(0,KOGlobals::EVENTDELETED); 1868 changeEventDisplay(0,KOGlobals::EVENTDELETED);
1868} 1869}
1869void CalendarView::changeTodoDisplay(Todo *which, int action) 1870void CalendarView::changeTodoDisplay(Todo *which, int action)
1870{ 1871{
1871 changeIncidenceDisplay((Incidence *)which, action); 1872 changeIncidenceDisplay((Incidence *)which, action);
1872} 1873}
1873 1874
1874void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 1875void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
1875{ 1876{
1876 updateUnmanagedViews(); 1877 updateUnmanagedViews();
1877 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 1878 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
1878 if ( action == KOGlobals::EVENTDELETED ) { //delete 1879 if ( action == KOGlobals::EVENTDELETED ) { //delete
1879 mCalendar->checkAlarmForIncidence( 0, true ); 1880 mCalendar->checkAlarmForIncidence( 0, true );
1880 if ( mEventViewerDialog ) 1881 if ( mEventViewerDialog )
1881 mEventViewerDialog->hide(); 1882 mEventViewerDialog->hide();
1882 } 1883 }
1883 else 1884 else
1884 mCalendar->checkAlarmForIncidence( which , false ); 1885 mCalendar->checkAlarmForIncidence( which , false );
1885} 1886}
1886 1887
1887// most of the changeEventDisplays() right now just call the view's 1888// most of the changeEventDisplays() right now just call the view's
1888// total update mode, but they SHOULD be recoded to be more refresh-efficient. 1889// total update mode, but they SHOULD be recoded to be more refresh-efficient.
1889void CalendarView::changeEventDisplay(Event *which, int action) 1890void CalendarView::changeEventDisplay(Event *which, int action)
1890{ 1891{
1891 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 1892 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
1892 changeIncidenceDisplay((Incidence *)which, action); 1893 changeIncidenceDisplay((Incidence *)which, action);
1893 mDateNavigator->updateView(); 1894 mDateNavigator->updateView();
1894 //mDialogManager->updateSearchDialog(); 1895 //mDialogManager->updateSearchDialog();
1895 1896
1896 if (which) { 1897 if (which) {
1897 // If there is an event view visible update the display 1898 // If there is an event view visible update the display
1898 mViewManager->currentView()->changeEventDisplay(which,action); 1899 mViewManager->currentView()->changeEventDisplay(which,action);
1899 // TODO: check, if update needed 1900 // TODO: check, if update needed
1900 // if (which->getTodoStatus()) { 1901 // if (which->getTodoStatus()) {
1901 mTodoList->updateView(); 1902 mTodoList->updateView();
1902 // } 1903 // }
1903 } else { 1904 } else {
1904 mViewManager->currentView()->updateView(); 1905 mViewManager->currentView()->updateView();
1905 } 1906 }
1906} 1907}
1907 1908
1908 1909
1909void CalendarView::updateTodoViews() 1910void CalendarView::updateTodoViews()
1910{ 1911{
1911 1912
1912 mTodoList->updateView(); 1913 mTodoList->updateView();
1913 mViewManager->currentView()->updateView(); 1914 mViewManager->currentView()->updateView();
1914 1915
1915} 1916}
1916 1917
1917 1918
1918void CalendarView::updateView(const QDate &start, const QDate &end) 1919void CalendarView::updateView(const QDate &start, const QDate &end)
1919{ 1920{
1920 mTodoList->updateView(); 1921 mTodoList->updateView();
1921 mViewManager->updateView(start, end); 1922 mViewManager->updateView(start, end);
1922 //mDateNavigator->updateView(); 1923 //mDateNavigator->updateView();
1923} 1924}
1924 1925
1925void CalendarView::updateView() 1926void CalendarView::updateView()
1926{ 1927{
1927 DateList tmpList = mNavigator->selectedDates(); 1928 DateList tmpList = mNavigator->selectedDates();
1928 1929
1929 // We assume that the navigator only selects consecutive days. 1930 // We assume that the navigator only selects consecutive days.
1930 updateView( tmpList.first(), tmpList.last() ); 1931 updateView( tmpList.first(), tmpList.last() );
1931} 1932}
1932 1933
1933void CalendarView::updateUnmanagedViews() 1934void CalendarView::updateUnmanagedViews()
1934{ 1935{
1935 mDateNavigator->updateDayMatrix(); 1936 mDateNavigator->updateDayMatrix();
1936} 1937}
1937 1938
1938int CalendarView::msgItemDelete() 1939int CalendarView::msgItemDelete()
1939{ 1940{
1940 return KMessageBox::warningContinueCancel(this, 1941 return KMessageBox::warningContinueCancel(this,
1941 i18n("This item will be\npermanently deleted."), 1942 i18n("This item will be\npermanently deleted."),
1942 i18n("KO/Pi Confirmation"),i18n("Delete")); 1943 i18n("KO/Pi Confirmation"),i18n("Delete"));
1943} 1944}
1944 1945
1945 1946
1946void CalendarView::edit_cut() 1947void CalendarView::edit_cut()
1947{ 1948{
1948 Event *anEvent=0; 1949 Event *anEvent=0;
1949 1950
1950 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1951 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1951 1952
1952 if (mViewManager->currentView()->isEventView()) { 1953 if (mViewManager->currentView()->isEventView()) {
1953 if ( incidence && incidence->type() == "Event" ) { 1954 if ( incidence && incidence->type() == "Event" ) {
1954 anEvent = static_cast<Event *>(incidence); 1955 anEvent = static_cast<Event *>(incidence);
1955 } 1956 }
1956 } 1957 }
1957 1958
1958 if (!anEvent) { 1959 if (!anEvent) {
1959 KNotifyClient::beep(); 1960 KNotifyClient::beep();
1960 return; 1961 return;
1961 } 1962 }
1962 DndFactory factory( mCalendar ); 1963 DndFactory factory( mCalendar );
1963 factory.cutEvent(anEvent); 1964 factory.cutEvent(anEvent);
1964 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 1965 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
1965} 1966}
1966 1967
1967void CalendarView::edit_copy() 1968void CalendarView::edit_copy()
1968{ 1969{
1969 Event *anEvent=0; 1970 Event *anEvent=0;
1970 1971
1971 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 1972 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
1972 1973
1973 if (mViewManager->currentView()->isEventView()) { 1974 if (mViewManager->currentView()->isEventView()) {
1974 if ( incidence && incidence->type() == "Event" ) { 1975 if ( incidence && incidence->type() == "Event" ) {
1975 anEvent = static_cast<Event *>(incidence); 1976 anEvent = static_cast<Event *>(incidence);
1976 } 1977 }
1977 } 1978 }
1978 1979
1979 if (!anEvent) { 1980 if (!anEvent) {
1980 KNotifyClient::beep(); 1981 KNotifyClient::beep();
1981 return; 1982 return;
1982 } 1983 }
1983 DndFactory factory( mCalendar ); 1984 DndFactory factory( mCalendar );
1984 factory.copyEvent(anEvent); 1985 factory.copyEvent(anEvent);
1985} 1986}
1986 1987
1987void CalendarView::edit_paste() 1988void CalendarView::edit_paste()
1988{ 1989{
1989 QDate date = mNavigator->selectedDates().first(); 1990 QDate date = mNavigator->selectedDates().first();
1990 1991
1991 DndFactory factory( mCalendar ); 1992 DndFactory factory( mCalendar );
1992 Event *pastedEvent = factory.pasteEvent( date ); 1993 Event *pastedEvent = factory.pasteEvent( date );
1993 1994
1994 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 1995 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
1995} 1996}
1996 1997
1997void CalendarView::edit_options() 1998void CalendarView::edit_options()
1998{ 1999{
1999 mDialogManager->showOptionsDialog(); 2000 mDialogManager->showOptionsDialog();
2000 //writeSettings(); 2001 //writeSettings();
2001} 2002}
2002void CalendarView::edit_sync_options() 2003void CalendarView::edit_sync_options()
2003{ 2004{
2004 //mDialogManager->showSyncOptions(); 2005 //mDialogManager->showSyncOptions();
2005 //KOPrefs::instance()->mSyncAlgoPrefs 2006 //KOPrefs::instance()->mSyncAlgoPrefs
2006 QDialog dia( this, "dia", true ); 2007 QDialog dia( this, "dia", true );
2007 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2008 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2008 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2009 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2009 QVBoxLayout lay ( &dia ); 2010 QVBoxLayout lay ( &dia );
2010 lay.setSpacing( 2 ); 2011 lay.setSpacing( 2 );
2011 lay.setMargin( 3 ); 2012 lay.setMargin( 3 );
2012 lay.addWidget(&gr); 2013 lay.addWidget(&gr);
2013 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2014 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2014 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2015 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2015 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2016 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2016 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2017 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2017 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2018 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2018 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2019 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2019 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2020 //QRadioButton both( i18n("Take both on conflict"), &gr );
2020 QPushButton pb ( "OK", &dia); 2021 QPushButton pb ( "OK", &dia);
2021 lay.addWidget( &pb ); 2022 lay.addWidget( &pb );
2022 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2023 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2023 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) { 2024 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2024 case 0: 2025 case 0:
2025 loc.setChecked( true); 2026 loc.setChecked( true);
2026 break; 2027 break;
2027 case 1: 2028 case 1:
2028 rem.setChecked( true ); 2029 rem.setChecked( true );
2029 break; 2030 break;
2030 case 2: 2031 case 2:
2031 newest.setChecked( true); 2032 newest.setChecked( true);
2032 break; 2033 break;
2033 case 3: 2034 case 3:
2034 ask.setChecked( true); 2035 ask.setChecked( true);
2035 break; 2036 break;
2036 case 4: 2037 case 4:
2037 f_loc.setChecked( true); 2038 f_loc.setChecked( true);
2038 break; 2039 break;
2039 case 5: 2040 case 5:
2040 f_rem.setChecked( true); 2041 f_rem.setChecked( true);
2041 break; 2042 break;
2042 case 6: 2043 case 6:
2043 // both.setChecked( true); 2044 // both.setChecked( true);
2044 break; 2045 break;
2045 default: 2046 default:
2046 break; 2047 break;
2047 } 2048 }
2048 if ( dia.exec() ) { 2049 if ( dia.exec() ) {
2049 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2050 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2050 } 2051 }
2051 2052
2052} 2053}
2053 2054
2054void CalendarView::slotSelectPickerDate( QDate d) 2055void CalendarView::slotSelectPickerDate( QDate d)
2055{ 2056{
2056 mDateFrame->hide(); 2057 mDateFrame->hide();
2057 if ( mDatePickerMode == 1 ) { 2058 if ( mDatePickerMode == 1 ) {
2058 mNavigator->slotDaySelect( d ); 2059 mNavigator->slotDaySelect( d );
2059 } else if ( mDatePickerMode == 2 ) { 2060 } else if ( mDatePickerMode == 2 ) {
2060 if ( mMoveIncidence->type() == "Todo" ) { 2061 if ( mMoveIncidence->type() == "Todo" ) {
2061 Todo * to = (Todo *) mMoveIncidence; 2062 Todo * to = (Todo *) mMoveIncidence;
2062 QTime tim; 2063 QTime tim;
2063 if ( to->hasDueDate() ) 2064 if ( to->hasDueDate() )
2064 tim = to->dtDue().time(); 2065 tim = to->dtDue().time();
2065 else { 2066 else {
2066 tim = QTime ( 0,0,0 ); 2067 tim = QTime ( 0,0,0 );
2067 to->setFloats( true ); 2068 to->setFloats( true );
2068 to->setHasDueDate( true ); 2069 to->setHasDueDate( true );
2069 } 2070 }
2070 QDateTime dt ( d,tim ); 2071 QDateTime dt ( d,tim );
2071 to->setDtDue( dt ); 2072 to->setDtDue( dt );
2072 todoChanged( to ); 2073 todoChanged( to );
2073 } else { 2074 } else {
2074 QTime tim = mMoveIncidence->dtStart().time(); 2075 QTime tim = mMoveIncidence->dtStart().time();
2075 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2076 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2076 QDateTime dt ( d,tim ); 2077 QDateTime dt ( d,tim );
2077 mMoveIncidence->setDtStart( dt ); 2078 mMoveIncidence->setDtStart( dt );
2078 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2079 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2079 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2080 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2080 } 2081 }
2081 2082
2082 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2083 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2083 } 2084 }
2084} 2085}
2085 2086
2086void CalendarView::removeCategories() 2087void CalendarView::removeCategories()
2087{ 2088{
2088 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2089 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2089 QStringList catList = KOPrefs::instance()->mCustomCategories; 2090 QStringList catList = KOPrefs::instance()->mCustomCategories;
2090 QStringList catIncList; 2091 QStringList catIncList;
2091 QStringList newCatList; 2092 QStringList newCatList;
2092 Incidence* inc = incList.first(); 2093 Incidence* inc = incList.first();
2093 int i; 2094 int i;
2094 int count = 0; 2095 int count = 0;
2095 while ( inc ) { 2096 while ( inc ) {
2096 newCatList.clear(); 2097 newCatList.clear();
2097 catIncList = inc->categories() ; 2098 catIncList = inc->categories() ;
2098 for( i = 0; i< catIncList.count(); ++i ) { 2099 for( i = 0; i< catIncList.count(); ++i ) {
2099 if ( catList.contains (catIncList[i])) 2100 if ( catList.contains (catIncList[i]))
2100 newCatList.append( catIncList[i] ); 2101 newCatList.append( catIncList[i] );
2101 } 2102 }
2102 newCatList.sort(); 2103 newCatList.sort();
2103 inc->setCategories( newCatList.join(",") ); 2104 inc->setCategories( newCatList.join(",") );
2104 inc = incList.next(); 2105 inc = incList.next();
2105 } 2106 }
2106} 2107}
2107 2108
2108int CalendarView::addCategories() 2109int CalendarView::addCategories()
2109{ 2110{
2110 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2111 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2111 QStringList catList = KOPrefs::instance()->mCustomCategories; 2112 QStringList catList = KOPrefs::instance()->mCustomCategories;
2112 QStringList catIncList; 2113 QStringList catIncList;
2113 Incidence* inc = incList.first(); 2114 Incidence* inc = incList.first();
2114 int i; 2115 int i;
2115 int count = 0; 2116 int count = 0;
2116 while ( inc ) { 2117 while ( inc ) {
2117 catIncList = inc->categories() ; 2118 catIncList = inc->categories() ;
2118 for( i = 0; i< catIncList.count(); ++i ) { 2119 for( i = 0; i< catIncList.count(); ++i ) {
2119 if ( !catList.contains (catIncList[i])) { 2120 if ( !catList.contains (catIncList[i])) {
2120 catList.append( catIncList[i] ); 2121 catList.append( catIncList[i] );
2121 //qDebug("add cat %s ", catIncList[i].latin1()); 2122 //qDebug("add cat %s ", catIncList[i].latin1());
2122 ++count; 2123 ++count;
2123 } 2124 }
2124 } 2125 }
2125 inc = incList.next(); 2126 inc = incList.next();
2126 } 2127 }
2127 catList.sort(); 2128 catList.sort();
2128 KOPrefs::instance()->mCustomCategories = catList; 2129 KOPrefs::instance()->mCustomCategories = catList;
2129 return count; 2130 return count;
2130} 2131}
2131 2132
2132void CalendarView::manageCategories() 2133void CalendarView::manageCategories()
2133{ 2134{
2134 KOCatPrefs* cp = new KOCatPrefs(); 2135 KOCatPrefs* cp = new KOCatPrefs();
2135 cp->show(); 2136 cp->show();
2136 int w =cp->sizeHint().width() ; 2137 int w =cp->sizeHint().width() ;
2137 int h = cp->sizeHint().height() ; 2138 int h = cp->sizeHint().height() ;
2138 int dw = QApplication::desktop()->width(); 2139 int dw = QApplication::desktop()->width();
2139 int dh = QApplication::desktop()->height(); 2140 int dh = QApplication::desktop()->height();
2140 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2141 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2141 if ( !cp->exec() ) { 2142 if ( !cp->exec() ) {
2142 delete cp; 2143 delete cp;
2143 return; 2144 return;
2144 } 2145 }
2145 int count = 0; 2146 int count = 0;
2146 if ( cp->addCat() ) { 2147 if ( cp->addCat() ) {
2147 count = addCategories(); 2148 count = addCategories();
2148 if ( count ) { 2149 if ( count ) {
2149 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2150 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2150 writeSettings(); 2151 writeSettings();
2151 } 2152 }
2152 } else { 2153 } else {
2153 removeCategories(); 2154 removeCategories();
2154 updateView(); 2155 updateView();
2155 } 2156 }
2156 delete cp; 2157 delete cp;
2157} 2158}
2158 2159
2159void CalendarView::beamIncidence(Incidence * Inc) 2160void CalendarView::beamIncidence(Incidence * Inc)
2160{ 2161{
2161 QPtrList<Incidence> delSel ; 2162 QPtrList<Incidence> delSel ;
2162 delSel.append(Inc); 2163 delSel.append(Inc);
2163 beamIncidenceList( delSel ); 2164 beamIncidenceList( delSel );
2164} 2165}
2165void CalendarView::beamCalendar() 2166void CalendarView::beamCalendar()
2166{ 2167{
2167 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2168 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2168 //qDebug("beamCalendar() "); 2169 //qDebug("beamCalendar() ");
2169 beamIncidenceList( delSel ); 2170 beamIncidenceList( delSel );
2170} 2171}
2171void CalendarView::beamFilteredCalendar() 2172void CalendarView::beamFilteredCalendar()
2172{ 2173{
2173 QPtrList<Incidence> delSel = mCalendar->incidences(); 2174 QPtrList<Incidence> delSel = mCalendar->incidences();
2174 //qDebug("beamFilteredCalendar() "); 2175 //qDebug("beamFilteredCalendar() ");
2175 beamIncidenceList( delSel ); 2176 beamIncidenceList( delSel );
2176} 2177}
2177void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2178void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2178{ 2179{
2179 if ( beamDialog->exec () == QDialog::Rejected ) 2180 if ( beamDialog->exec () == QDialog::Rejected )
2180 return; 2181 return;
2181 2182
2182 QString fn = "/tmp/kopibeamfile"; 2183 QString fn = "/tmp/kopibeamfile";
2183 QString mes; 2184 QString mes;
2184 bool createbup = true; 2185 bool createbup = true;
2185 if ( createbup ) { 2186 if ( createbup ) {
2186 QString description = "\n"; 2187 QString description = "\n";
2187 CalendarLocal* cal = new CalendarLocal(); 2188 CalendarLocal* cal = new CalendarLocal();
2188 if ( beamDialog->beamLocal() ) 2189 if ( beamDialog->beamLocal() )
2189 cal->setLocalTime(); 2190 cal->setLocalTime();
2190 else 2191 else
2191 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 2192 cal->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
2192 Incidence *incidence = delSel.first(); 2193 Incidence *incidence = delSel.first();
2193 bool addText = false; 2194 bool addText = false;
2194 if ( delSel.count() < 10 ) 2195 if ( delSel.count() < 10 )
2195 addText = true; 2196 addText = true;
2196 else { 2197 else {
2197 description.sprintf(i18n(" %d items?"),delSel.count() ); 2198 description.sprintf(i18n(" %d items?"),delSel.count() );
2198 } 2199 }
2199 while ( incidence ) { 2200 while ( incidence ) {
2200 Incidence *in = incidence->clone(); 2201 Incidence *in = incidence->clone();
2201 if ( addText ) 2202 if ( addText )
2202 description += in->summary() + "\n"; 2203 description += in->summary() + "\n";
2203 cal->addIncidence( in ); 2204 cal->addIncidence( in );
2204 incidence = delSel.next(); 2205 incidence = delSel.next();
2205 } 2206 }
2206 if ( beamDialog->beamVcal() ) { 2207 if ( beamDialog->beamVcal() ) {
2207 fn += ".vcs"; 2208 fn += ".vcs";
2208 FileStorage storage( cal, fn, new VCalFormat ); 2209 FileStorage storage( cal, fn, new VCalFormat );
2209 storage.save(); 2210 storage.save();
2210 } else { 2211 } else {
2211 fn += ".ics"; 2212 fn += ".ics";
2212 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2213 FileStorage storage( cal, fn, new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2213 storage.save(); 2214 storage.save();
2214 } 2215 }
2215 delete cal; 2216 delete cal;
2216 mes = i18n("KO/Pi: Ready for beaming"); 2217 mes = i18n("KO/Pi: Ready for beaming");
2217 setCaption(mes); 2218 setCaption(mes);
2218 2219
2219#ifndef DESKTOP_VERSION 2220#ifndef DESKTOP_VERSION
2220 Ir *ir = new Ir( this ); 2221 Ir *ir = new Ir( this );
2221 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2222 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2222 ir->send( fn, description, "text/x-vCalendar" ); 2223 ir->send( fn, description, "text/x-vCalendar" );
2223#endif 2224#endif
2224 } 2225 }
2225} 2226}
2226void CalendarView::beamDone( Ir *ir ) 2227void CalendarView::beamDone( Ir *ir )
2227{ 2228{
2228#ifndef DESKTOP_VERSION 2229#ifndef DESKTOP_VERSION
2229 delete ir; 2230 delete ir;
2230#endif 2231#endif
2231} 2232}
2232 2233
2233void CalendarView::moveIncidence(Incidence * inc ) 2234void CalendarView::moveIncidence(Incidence * inc )
2234{ 2235{
2235 if ( !inc ) return; 2236 if ( !inc ) return;
2236 // qDebug("showDatePickerForIncidence( ) "); 2237 // qDebug("showDatePickerForIncidence( ) ");
2237 if ( mDateFrame->isVisible() ) 2238 if ( mDateFrame->isVisible() )
2238 mDateFrame->hide(); 2239 mDateFrame->hide();
2239 else { 2240 else {
2240 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2241 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2241 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2242 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2242 int dw = QApplication::desktop()->width(); 2243 int dw = QApplication::desktop()->width();
2243 int dh = QApplication::desktop()->height(); 2244 int dh = QApplication::desktop()->height();
2244 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2245 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2245 mDateFrame->show(); 2246 mDateFrame->show();
2246 } 2247 }
2247 mDatePickerMode = 2; 2248 mDatePickerMode = 2;
2248 mMoveIncidence = inc ; 2249 mMoveIncidence = inc ;
2249 QDate da; 2250 QDate da;
2250 if ( mMoveIncidence->type() == "Todo" ) { 2251 if ( mMoveIncidence->type() == "Todo" ) {
2251 Todo * to = (Todo *) mMoveIncidence; 2252 Todo * to = (Todo *) mMoveIncidence;
2252 if ( to->hasDueDate() ) 2253 if ( to->hasDueDate() )
2253 da = to->dtDue().date(); 2254 da = to->dtDue().date();
2254 else 2255 else
2255 da = QDate::currentDate(); 2256 da = QDate::currentDate();
2256 } else { 2257 } else {
2257 da = mMoveIncidence->dtStart().date(); 2258 da = mMoveIncidence->dtStart().date();
2258 } 2259 }
2259 mDatePicker->setDate( da ); 2260 mDatePicker->setDate( da );
2260} 2261}
2261void CalendarView::showDatePicker( ) 2262void CalendarView::showDatePicker( )
2262{ 2263{
2263 //qDebug("CalendarView::showDatePicker( ) "); 2264 //qDebug("CalendarView::showDatePicker( ) ");
2264 if ( mDateFrame->isVisible() ) 2265 if ( mDateFrame->isVisible() )
2265 mDateFrame->hide(); 2266 mDateFrame->hide();
2266 else { 2267 else {
2267 int w =mDatePicker->sizeHint().width() ; 2268 int w =mDatePicker->sizeHint().width() ;
2268 int h = mDatePicker->sizeHint().height() ; 2269 int h = mDatePicker->sizeHint().height() ;
2269 int dw = QApplication::desktop()->width(); 2270 int dw = QApplication::desktop()->width();
2270 int dh = QApplication::desktop()->height(); 2271 int dh = QApplication::desktop()->height();
2271 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2272 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2272 mDateFrame->show(); 2273 mDateFrame->show();
2273 } 2274 }
2274 mDatePickerMode = 1; 2275 mDatePickerMode = 1;
2275 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2276 mDatePicker->setDate( mNavigator->selectedDates().first() );
2276} 2277}
2277 2278
2278void CalendarView::showEventEditor() 2279void CalendarView::showEventEditor()
2279{ 2280{
2280#ifdef DESKTOP_VERSION 2281#ifdef DESKTOP_VERSION
2281 mEventEditor->show(); 2282 mEventEditor->show();
2282#else 2283#else
2283 mEventEditor->showMaximized(); 2284 mEventEditor->showMaximized();
2284#endif 2285#endif
2285} 2286}
2286void CalendarView::showTodoEditor() 2287void CalendarView::showTodoEditor()
2287{ 2288{
2288#ifdef DESKTOP_VERSION 2289#ifdef DESKTOP_VERSION
2289 mTodoEditor->show(); 2290 mTodoEditor->show();
2290#else 2291#else
2291 mTodoEditor->showMaximized(); 2292 mTodoEditor->showMaximized();
2292#endif 2293#endif
2293} 2294}
2294void CalendarView::cancelIncidence(Incidence * inc ) 2295void CalendarView::cancelIncidence(Incidence * inc )
2295{ 2296{
2296 inc->setCancelled( ! inc->cancelled() ); 2297 inc->setCancelled( ! inc->cancelled() );
2297 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2298 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2298 updateView(); 2299 updateView();
2299} 2300}
2300void CalendarView::cloneIncidence(Incidence * orgInc ) 2301void CalendarView::cloneIncidence(Incidence * orgInc )
2301{ 2302{
2302 Incidence * newInc = orgInc->clone(); 2303 Incidence * newInc = orgInc->clone();
2303 newInc->recreate(); 2304 newInc->recreate();
2304 2305
2305 if ( newInc->type() == "Todo" ) { 2306 if ( newInc->type() == "Todo" ) {
2306 Todo* t = (Todo*) newInc; 2307 Todo* t = (Todo*) newInc;
2307 mTodoEditor->editTodo( t ); 2308 mTodoEditor->editTodo( t );
2308 showTodoEditor(); 2309 showTodoEditor();
2309 if ( mTodoEditor->exec() ) { 2310 if ( mTodoEditor->exec() ) {
2310 mCalendar->addTodo( t ); 2311 mCalendar->addTodo( t );
2311 updateView(); 2312 updateView();
2312 } else { 2313 } else {
2313 delete t; 2314 delete t;
2314 } 2315 }
2315 } 2316 }
2316 else { 2317 else {
2317 Event* e = (Event*) newInc; 2318 Event* e = (Event*) newInc;
2318 mEventEditor->editEvent( e ); 2319 mEventEditor->editEvent( e );
2319 showEventEditor(); 2320 showEventEditor();
2320 if ( mEventEditor->exec() ) { 2321 if ( mEventEditor->exec() ) {
2321 mCalendar->addEvent( e ); 2322 mCalendar->addEvent( e );
2322 updateView(); 2323 updateView();
2323 } else { 2324 } else {
2324 delete e; 2325 delete e;
2325 } 2326 }
2326 } 2327 }
2327} 2328}
2328 2329
2329void CalendarView::newEvent() 2330void CalendarView::newEvent()
2330{ 2331{
2331 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2332 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2332 KOAgendaView *aView = mViewManager->agendaView(); 2333 KOAgendaView *aView = mViewManager->agendaView();
2333 if (aView) { 2334 if (aView) {
2334 if (aView->selectionStart().isValid()) { 2335 if (aView->selectionStart().isValid()) {
2335 if (aView->selectedIsAllDay()) { 2336 if (aView->selectedIsAllDay()) {
2336 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2337 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2337 } else { 2338 } else {
2338 newEvent(aView->selectionStart(),aView->selectionEnd()); 2339 newEvent(aView->selectionStart(),aView->selectionEnd());
2339 } 2340 }
2340 return; 2341 return;
2341 } 2342 }
2342 } 2343 }
2343 2344
2344 QDate date = mNavigator->selectedDates().first(); 2345 QDate date = mNavigator->selectedDates().first();
2345 QDateTime current = QDateTime::currentDateTime(); 2346 QDateTime current = QDateTime::currentDateTime();
2346 if ( date <= current.date() ) { 2347 if ( date <= current.date() ) {
2347 int hour = current.time().hour() +1; 2348 int hour = current.time().hour() +1;
2348 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2349 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2349 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2350 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2350 } else 2351 } else
2351 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2352 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2352 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2353 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2353 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2354 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2354} 2355}
2355 2356
2356void CalendarView::newEvent(QDateTime fh) 2357void CalendarView::newEvent(QDateTime fh)
2357{ 2358{
2358 newEvent(fh, 2359 newEvent(fh,
2359 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2360 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2360} 2361}
2361 2362
2362void CalendarView::newEvent(QDate dt) 2363void CalendarView::newEvent(QDate dt)
2363{ 2364{
2364 newEvent(QDateTime(dt, QTime(0,0,0)), 2365 newEvent(QDateTime(dt, QTime(0,0,0)),
2365 QDateTime(dt, QTime(0,0,0)), true); 2366 QDateTime(dt, QTime(0,0,0)), true);
2366} 2367}
2367 2368
2368void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2369void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2369{ 2370{
2370 2371
2371 mEventEditor->newEvent(fromHint,toHint,allDay); 2372 mEventEditor->newEvent(fromHint,toHint,allDay);
2372 if ( mFilterView->filtersEnabled() ) { 2373 if ( mFilterView->filtersEnabled() ) {
2373 CalFilter *filter = mFilterView->selectedFilter(); 2374 CalFilter *filter = mFilterView->selectedFilter();
2374 if (filter && filter->showCategories()) { 2375 if (filter && filter->showCategories()) {
2375 mEventEditor->setCategories(filter->categoryList().join(",") ); 2376 mEventEditor->setCategories(filter->categoryList().join(",") );
2376 } 2377 }
2377 if ( filter ) 2378 if ( filter )
2378 mEventEditor->setSecrecy( filter->getSecrecy() ); 2379 mEventEditor->setSecrecy( filter->getSecrecy() );
2379 } 2380 }
2380 showEventEditor(); 2381 showEventEditor();
2381} 2382}
2382void CalendarView::todoAdded(Todo * t) 2383void CalendarView::todoAdded(Todo * t)
2383{ 2384{
2384 2385
2385 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2386 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2386 updateTodoViews(); 2387 updateTodoViews();
2387} 2388}
2388void CalendarView::todoChanged(Todo * t) 2389void CalendarView::todoChanged(Todo * t)
2389{ 2390{
2390 emit todoModified( t, 4 ); 2391 emit todoModified( t, 4 );
2391 // updateTodoViews(); 2392 // updateTodoViews();
2392} 2393}
2393void CalendarView::todoToBeDeleted(Todo *) 2394void CalendarView::todoToBeDeleted(Todo *)
2394{ 2395{
2395 //qDebug("todoToBeDeleted(Todo *) "); 2396 //qDebug("todoToBeDeleted(Todo *) ");
2396 updateTodoViews(); 2397 updateTodoViews();
2397} 2398}
2398void CalendarView::todoDeleted() 2399void CalendarView::todoDeleted()
2399{ 2400{
2400 //qDebug(" todoDeleted()"); 2401 //qDebug(" todoDeleted()");
2401 updateTodoViews(); 2402 updateTodoViews();
2402} 2403}
2403 2404
2404 2405
2405 2406
2406void CalendarView::newTodo() 2407void CalendarView::newTodo()
2407{ 2408{
2408 2409
2409 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true); 2410 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),0,true);
2410 if ( mFilterView->filtersEnabled() ) { 2411 if ( mFilterView->filtersEnabled() ) {
2411 CalFilter *filter = mFilterView->selectedFilter(); 2412 CalFilter *filter = mFilterView->selectedFilter();
2412 if (filter && filter->showCategories()) { 2413 if (filter && filter->showCategories()) {
2413 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2414 mTodoEditor->setCategories(filter->categoryList().join(",") );
2414 } 2415 }
2415 if ( filter ) 2416 if ( filter )
2416 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2417 mTodoEditor->setSecrecy( filter->getSecrecy() );
2417 } 2418 }
2418 showTodoEditor(); 2419 showTodoEditor();
2419} 2420}
2420 2421
2421void CalendarView::newSubTodo() 2422void CalendarView::newSubTodo()
2422{ 2423{
2423 Todo *todo = selectedTodo(); 2424 Todo *todo = selectedTodo();
2424 if ( todo ) newSubTodo( todo ); 2425 if ( todo ) newSubTodo( todo );
2425} 2426}
2426 2427
2427void CalendarView::newSubTodo(Todo *parentEvent) 2428void CalendarView::newSubTodo(Todo *parentEvent)
2428{ 2429{
2429 2430
2430 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true); 2431 mTodoEditor->newTodo(QDateTime::currentDateTime().addDays(7),parentEvent,true);
2431 showTodoEditor(); 2432 showTodoEditor();
2432} 2433}
2433 2434
2434void CalendarView::newFloatingEvent() 2435void CalendarView::newFloatingEvent()
2435{ 2436{
2436 DateList tmpList = mNavigator->selectedDates(); 2437 DateList tmpList = mNavigator->selectedDates();
2437 QDate date = tmpList.first(); 2438 QDate date = tmpList.first();
2438 2439
2439 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2440 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2440 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2441 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2441} 2442}
2442 2443
2443 2444
2444void CalendarView::editEvent( Event *event ) 2445void CalendarView::editEvent( Event *event )
2445{ 2446{
2446 2447
2447 if ( !event ) return; 2448 if ( !event ) return;
2448 if ( event->isReadOnly() ) { 2449 if ( event->isReadOnly() ) {
2449 showEvent( event ); 2450 showEvent( event );
2450 return; 2451 return;
2451 } 2452 }
2452 mEventEditor->editEvent( event , mFlagEditDescription); 2453 mEventEditor->editEvent( event , mFlagEditDescription);
2453 showEventEditor(); 2454 showEventEditor();
2454} 2455}
2455void CalendarView::editJournal( Journal *jour ) 2456void CalendarView::editJournal( Journal *jour )
2456{ 2457{
2457 if ( !jour ) return; 2458 if ( !jour ) return;
2458 mDialogManager->hideSearchDialog(); 2459 mDialogManager->hideSearchDialog();
2459 mViewManager->showJournalView(); 2460 mViewManager->showJournalView();
2460 mNavigator->slotDaySelect( jour->dtStart().date() ); 2461 mNavigator->slotDaySelect( jour->dtStart().date() );
2461} 2462}
2462void CalendarView::editTodo( Todo *todo ) 2463void CalendarView::editTodo( Todo *todo )
2463{ 2464{
2464 if ( !todo ) return; 2465 if ( !todo ) return;
2465 2466
2466 if ( todo->isReadOnly() ) { 2467 if ( todo->isReadOnly() ) {
2467 showTodo( todo ); 2468 showTodo( todo );
2468 return; 2469 return;
2469 } 2470 }
2470 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2471 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2471 showTodoEditor(); 2472 showTodoEditor();
2472 2473
2473} 2474}
2474 2475
2475KOEventViewerDialog* CalendarView::getEventViewerDialog() 2476KOEventViewerDialog* CalendarView::getEventViewerDialog()
2476{ 2477{
2477 if ( !mEventViewerDialog ) { 2478 if ( !mEventViewerDialog ) {
2478 mEventViewerDialog = new KOEventViewerDialog(this); 2479 mEventViewerDialog = new KOEventViewerDialog(this);
2479 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2480 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2480 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2481 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2481 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2482 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2482 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2483 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2483 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2484 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2484 viewManager(), SLOT( showAgendaView( bool ) ) ); 2485 viewManager(), SLOT( showAgendaView( bool ) ) );
2485 mEventViewerDialog->resize( 640, 480 ); 2486 mEventViewerDialog->resize( 640, 480 );
2486 2487
2487 } 2488 }
2488 return mEventViewerDialog; 2489 return mEventViewerDialog;
2489} 2490}
2490void CalendarView::showEvent(Event *event) 2491void CalendarView::showEvent(Event *event)
2491{ 2492{
2492 getEventViewerDialog()->setEvent(event); 2493 getEventViewerDialog()->setEvent(event);
2493 getEventViewerDialog()->showMe(); 2494 getEventViewerDialog()->showMe();
2494} 2495}
2495 2496
2496void CalendarView::showTodo(Todo *event) 2497void CalendarView::showTodo(Todo *event)
2497{ 2498{
2498 getEventViewerDialog()->setTodo(event); 2499 getEventViewerDialog()->setTodo(event);
2499 getEventViewerDialog()->showMe(); 2500 getEventViewerDialog()->showMe();
2500} 2501}
2501void CalendarView::showJournal( Journal *jour ) 2502void CalendarView::showJournal( Journal *jour )
2502{ 2503{
2503 getEventViewerDialog()->setJournal(jour); 2504 getEventViewerDialog()->setJournal(jour);
2504 getEventViewerDialog()->showMe(); 2505 getEventViewerDialog()->showMe();
2505 2506
2506} 2507}
2507// void CalendarView::todoModified (Todo *event, int changed) 2508// void CalendarView::todoModified (Todo *event, int changed)
2508// { 2509// {
2509// // if (mDialogList.find (event) != mDialogList.end ()) { 2510// // if (mDialogList.find (event) != mDialogList.end ()) {
2510// // kdDebug() << "Todo modified and open" << endl; 2511// // kdDebug() << "Todo modified and open" << endl;
2511// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2512// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2512// // temp->modified (changed); 2513// // temp->modified (changed);
2513 2514
2514// // } 2515// // }
2515 2516
2516// mViewManager->updateView(); 2517// mViewManager->updateView();
2517// } 2518// }
2518 2519
2519void CalendarView::appointment_show() 2520void CalendarView::appointment_show()
2520{ 2521{
2521 Event *anEvent = 0; 2522 Event *anEvent = 0;
2522 2523
2523 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2524 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2524 2525
2525 if (mViewManager->currentView()->isEventView()) { 2526 if (mViewManager->currentView()->isEventView()) {
2526 if ( incidence && incidence->type() == "Event" ) { 2527 if ( incidence && incidence->type() == "Event" ) {
2527 anEvent = static_cast<Event *>(incidence); 2528 anEvent = static_cast<Event *>(incidence);
2528 } 2529 }
2529 } 2530 }
2530 2531
2531 if (!anEvent) { 2532 if (!anEvent) {
2532 KNotifyClient::beep(); 2533 KNotifyClient::beep();
2533 return; 2534 return;
2534 } 2535 }
2535 2536
2536 showEvent(anEvent); 2537 showEvent(anEvent);
2537} 2538}
2538 2539
2539void CalendarView::appointment_edit() 2540void CalendarView::appointment_edit()
2540{ 2541{
2541 Event *anEvent = 0; 2542 Event *anEvent = 0;
2542 2543
2543 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2544 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2544 2545
2545 if (mViewManager->currentView()->isEventView()) { 2546 if (mViewManager->currentView()->isEventView()) {
2546 if ( incidence && incidence->type() == "Event" ) { 2547 if ( incidence && incidence->type() == "Event" ) {
2547 anEvent = static_cast<Event *>(incidence); 2548 anEvent = static_cast<Event *>(incidence);
2548 } 2549 }
2549 } 2550 }
2550 2551
2551 if (!anEvent) { 2552 if (!anEvent) {
2552 KNotifyClient::beep(); 2553 KNotifyClient::beep();
2553 return; 2554 return;
2554 } 2555 }
2555 2556
2556 editEvent(anEvent); 2557 editEvent(anEvent);
2557} 2558}
2558 2559
2559void CalendarView::appointment_delete() 2560void CalendarView::appointment_delete()
2560{ 2561{
2561 Event *anEvent = 0; 2562 Event *anEvent = 0;
2562 2563
2563 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2564 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2564 2565
2565 if (mViewManager->currentView()->isEventView()) { 2566 if (mViewManager->currentView()->isEventView()) {
2566 if ( incidence && incidence->type() == "Event" ) { 2567 if ( incidence && incidence->type() == "Event" ) {
2567 anEvent = static_cast<Event *>(incidence); 2568 anEvent = static_cast<Event *>(incidence);
2568 } 2569 }
2569 } 2570 }
2570 2571
2571 if (!anEvent) { 2572 if (!anEvent) {
2572 KNotifyClient::beep(); 2573 KNotifyClient::beep();
2573 return; 2574 return;
2574 } 2575 }
2575 2576
2576 deleteEvent(anEvent); 2577 deleteEvent(anEvent);
2577} 2578}
2578 2579
2579void CalendarView::todo_unsub(Todo *anTodo ) 2580void CalendarView::todo_unsub(Todo *anTodo )
2580{ 2581{
2581 // Todo *anTodo = selectedTodo(); 2582 // Todo *anTodo = selectedTodo();
2582 if (!anTodo) return; 2583 if (!anTodo) return;
2583 if (!anTodo->relatedTo()) return; 2584 if (!anTodo->relatedTo()) return;
2584 anTodo->relatedTo()->removeRelation(anTodo); 2585 anTodo->relatedTo()->removeRelation(anTodo);
2585 anTodo->setRelatedTo(0); 2586 anTodo->setRelatedTo(0);
2586 anTodo->updated(); 2587 anTodo->updated();
2587 anTodo->setRelatedToUid(""); 2588 anTodo->setRelatedToUid("");
2588 setModified(true); 2589 setModified(true);
2589 updateView(); 2590 updateView();
2590} 2591}
2591 2592
2592void CalendarView::deleteTodo(Todo *todo) 2593void CalendarView::deleteTodo(Todo *todo)
2593{ 2594{
2594 if (!todo) { 2595 if (!todo) {
2595 KNotifyClient::beep(); 2596 KNotifyClient::beep();
2596 return; 2597 return;
2597 } 2598 }
2598 if (KOPrefs::instance()->mConfirm) { 2599 if (KOPrefs::instance()->mConfirm) {
2599 switch (msgItemDelete()) { 2600 switch (msgItemDelete()) {
2600 case KMessageBox::Continue: // OK 2601 case KMessageBox::Continue: // OK
2601 if (!todo->relations().isEmpty()) { 2602 if (!todo->relations().isEmpty()) {
2602 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2603 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2603 i18n("Delete To-Do")); 2604 i18n("Delete To-Do"));
2604 } else { 2605 } else {
2605 checkExternalId( todo ); 2606 checkExternalId( todo );
2606 calendar()->deleteTodo(todo); 2607 calendar()->deleteTodo(todo);
2607 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2608 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2608 updateView(); 2609 updateView();
2609 } 2610 }
2610 break; 2611 break;
2611 } // switch 2612 } // switch
2612 } else { 2613 } else {
2613 if (!todo->relations().isEmpty()) { 2614 if (!todo->relations().isEmpty()) {
2614 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."), 2615 KMessageBox::sorry(this,i18n("Cannot delete To-Do\nwhich has children."),
2615 i18n("Delete To-Do")); 2616 i18n("Delete To-Do"));
2616 } else { 2617 } else {
2617 checkExternalId( todo ); 2618 checkExternalId( todo );
2618 mCalendar->deleteTodo(todo); 2619 mCalendar->deleteTodo(todo);
2619 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2620 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2620 updateView(); 2621 updateView();
2621 } 2622 }
2622 } 2623 }
2623 emit updateSearchDialog(); 2624 emit updateSearchDialog();
2624} 2625}
2625void CalendarView::deleteJournal(Journal *jour) 2626void CalendarView::deleteJournal(Journal *jour)
2626{ 2627{
2627 if (!jour) { 2628 if (!jour) {
2628 KNotifyClient::beep(); 2629 KNotifyClient::beep();
2629 return; 2630 return;
2630 } 2631 }
2631 if (KOPrefs::instance()->mConfirm) { 2632 if (KOPrefs::instance()->mConfirm) {
2632 switch (msgItemDelete()) { 2633 switch (msgItemDelete()) {
2633 case KMessageBox::Continue: // OK 2634 case KMessageBox::Continue: // OK
2634 calendar()->deleteJournal(jour); 2635 calendar()->deleteJournal(jour);
2635 updateView(); 2636 updateView();
2636 break; 2637 break;
2637 } // switch 2638 } // switch
2638 } else { 2639 } else {
2639 calendar()->deleteJournal(jour);; 2640 calendar()->deleteJournal(jour);;
2640 updateView(); 2641 updateView();
2641 } 2642 }
2642 emit updateSearchDialog(); 2643 emit updateSearchDialog();
2643} 2644}
2644 2645
2645void CalendarView::deleteEvent(Event *anEvent) 2646void CalendarView::deleteEvent(Event *anEvent)
2646{ 2647{
2647 if (!anEvent) { 2648 if (!anEvent) {
2648 KNotifyClient::beep(); 2649 KNotifyClient::beep();
2649 return; 2650 return;
2650 } 2651 }
2651 2652
2652 if (anEvent->recurrence()->doesRecur()) { 2653 if (anEvent->recurrence()->doesRecur()) {
2653 QDate itemDate = mViewManager->currentSelectionDate(); 2654 QDate itemDate = mViewManager->currentSelectionDate();
2654 int km; 2655 int km;
2655 if (!itemDate.isValid()) { 2656 if (!itemDate.isValid()) {
2656 //kdDebug() << "Date Not Valid" << endl; 2657 //kdDebug() << "Date Not Valid" << endl;
2657 if (KOPrefs::instance()->mConfirm) { 2658 if (KOPrefs::instance()->mConfirm) {
2658 km = KMessageBox::warningContinueCancel(this,anEvent->summary() + 2659 km = KMessageBox::warningContinueCancel(this,anEvent->summary() +
2659 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2660 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2660 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2661 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2661 if ( km == KMessageBox::Continue ) 2662 if ( km == KMessageBox::Continue )
2662 km = KMessageBox::No; // No = all below 2663 km = KMessageBox::No; // No = all below
2663 } else 2664 } else
2664 km = KMessageBox::No; 2665 km = KMessageBox::No;
2665 } else { 2666 } else {
2666 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() + 2667 km = KMessageBox::warningYesNoCancel(this,anEvent->summary() +
2667 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2668 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2668 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2669 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2669 i18n("KO/Pi Confirmation"),i18n("Current"), 2670 i18n("KO/Pi Confirmation"),i18n("Current"),
2670 i18n("All")); 2671 i18n("All"));
2671 } 2672 }
2672 switch(km) { 2673 switch(km) {
2673 2674
2674 case KMessageBox::No: // Continue // all 2675 case KMessageBox::No: // Continue // all
2675 //qDebug("KMessageBox::No "); 2676 //qDebug("KMessageBox::No ");
2676 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2677 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2677 schedule(Scheduler::Cancel,anEvent); 2678 schedule(Scheduler::Cancel,anEvent);
2678 2679
2679 checkExternalId( anEvent); 2680 checkExternalId( anEvent);
2680 mCalendar->deleteEvent(anEvent); 2681 mCalendar->deleteEvent(anEvent);
2681 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2682 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2682 break; 2683 break;
2683 2684
2684 // Disabled because it does not work 2685 // Disabled because it does not work
2685 //#if 0 2686 //#if 0
2686 case KMessageBox::Yes: // just this one 2687 case KMessageBox::Yes: // just this one
2687 //QDate qd = mNavigator->selectedDates().first(); 2688 //QDate qd = mNavigator->selectedDates().first();
2688 //if (!qd.isValid()) { 2689 //if (!qd.isValid()) {
2689 // kdDebug() << "no date selected, or invalid date" << endl; 2690 // kdDebug() << "no date selected, or invalid date" << endl;
2690 // KNotifyClient::beep(); 2691 // KNotifyClient::beep();
2691 // return; 2692 // return;
2692 //} 2693 //}
2693 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 2694 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
2694 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 2695 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
2695 anEvent->addExDate(itemDate); 2696 anEvent->addExDate(itemDate);
2696 int duration = anEvent->recurrence()->duration(); 2697 int duration = anEvent->recurrence()->duration();
2697 if ( duration > 0 ) { 2698 if ( duration > 0 ) {
2698 anEvent->recurrence()->setDuration( duration - 1 ); 2699 anEvent->recurrence()->setDuration( duration - 1 );
2699 } 2700 }
2700 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 2701 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
2701 } 2702 }
2702 break; 2703 break;
2703 //#endif 2704 //#endif
2704 } // switch 2705 } // switch
2705 } else { 2706 } else {
2706 if (KOPrefs::instance()->mConfirm) { 2707 if (KOPrefs::instance()->mConfirm) {
2707 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() + 2708 switch (KMessageBox::warningContinueCancel(this,anEvent->summary() +
2708 i18n("\nAre you sure you want\nto delete this event?"), 2709 i18n("\nAre you sure you want\nto delete this event?"),
2709 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 2710 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
2710 case KMessageBox::Continue: // OK 2711 case KMessageBox::Continue: // OK
2711 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2712 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2712 schedule(Scheduler::Cancel,anEvent); 2713 schedule(Scheduler::Cancel,anEvent);
2713 checkExternalId( anEvent); 2714 checkExternalId( anEvent);
2714 mCalendar->deleteEvent(anEvent); 2715 mCalendar->deleteEvent(anEvent);
2715 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2716 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2716 break; 2717 break;
2717 } // switch 2718 } // switch
2718 } else { 2719 } else {
2719 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2720 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2720 schedule(Scheduler::Cancel,anEvent); 2721 schedule(Scheduler::Cancel,anEvent);
2721 checkExternalId( anEvent); 2722 checkExternalId( anEvent);
2722 mCalendar->deleteEvent(anEvent); 2723 mCalendar->deleteEvent(anEvent);
2723 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2724 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2724 } 2725 }
2725 } // if-else 2726 } // if-else
2726 emit updateSearchDialog(); 2727 emit updateSearchDialog();
2727} 2728}
2728 2729
2729bool CalendarView::deleteEvent(const QString &uid) 2730bool CalendarView::deleteEvent(const QString &uid)
2730{ 2731{
2731 Event *ev = mCalendar->event(uid); 2732 Event *ev = mCalendar->event(uid);
2732 if (ev) { 2733 if (ev) {
2733 deleteEvent(ev); 2734 deleteEvent(ev);
2734 return true; 2735 return true;
2735 } else { 2736 } else {
2736 return false; 2737 return false;
2737 } 2738 }
2738} 2739}
2739 2740
2740/*****************************************************************************/ 2741/*****************************************************************************/
2741 2742
2742void CalendarView::action_mail() 2743void CalendarView::action_mail()
2743{ 2744{
2744#ifndef KORG_NOMAIL 2745#ifndef KORG_NOMAIL
2745 KOMailClient mailClient; 2746 KOMailClient mailClient;
2746 2747
2747 Incidence *incidence = currentSelection(); 2748 Incidence *incidence = currentSelection();
2748 2749
2749 if (!incidence) { 2750 if (!incidence) {
2750 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2751 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2751 return; 2752 return;
2752 } 2753 }
2753 if(incidence->attendeeCount() == 0 ) { 2754 if(incidence->attendeeCount() == 0 ) {
2754 KMessageBox::sorry(this, 2755 KMessageBox::sorry(this,
2755 i18n("Can't generate mail:\nNo attendees defined.\n")); 2756 i18n("Can't generate mail:\nNo attendees defined.\n"));
2756 return; 2757 return;
2757 } 2758 }
2758 2759
2759 CalendarLocal cal_tmp; 2760 CalendarLocal cal_tmp;
2760 Event *event = 0; 2761 Event *event = 0;
2761 Event *ev = 0; 2762 Event *ev = 0;
2762 if ( incidence && incidence->type() == "Event" ) { 2763 if ( incidence && incidence->type() == "Event" ) {
2763 event = static_cast<Event *>(incidence); 2764 event = static_cast<Event *>(incidence);
2764 ev = new Event(*event); 2765 ev = new Event(*event);
2765 cal_tmp.addEvent(ev); 2766 cal_tmp.addEvent(ev);
2766 } 2767 }
2767 ICalFormat mForm( KOPrefs::instance()->mUseQuicksave); 2768 ICalFormat mForm( KOPrefs::instance()->mUseQuicksave);
2768 QString attachment = mForm.toString( &cal_tmp ); 2769 QString attachment = mForm.toString( &cal_tmp );
2769 if (ev) delete(ev); 2770 if (ev) delete(ev);
2770 2771
2771 mailClient.mailAttendees(currentSelection(), attachment); 2772 mailClient.mailAttendees(currentSelection(), attachment);
2772 2773
2773#endif 2774#endif
2774 2775
2775#if 0 2776#if 0
2776 Event *anEvent = 0; 2777 Event *anEvent = 0;
2777 if (mViewManager->currentView()->isEventView()) { 2778 if (mViewManager->currentView()->isEventView()) {
2778 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 2779 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
2779 } 2780 }
2780 2781
2781 if (!anEvent) { 2782 if (!anEvent) {
2782 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 2783 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
2783 return; 2784 return;
2784 } 2785 }
2785 if(anEvent->attendeeCount() == 0 ) { 2786 if(anEvent->attendeeCount() == 0 ) {
2786 KMessageBox::sorry(this, 2787 KMessageBox::sorry(this,
2787 i18n("Can't generate mail:\nNo attendees defined.\n")); 2788 i18n("Can't generate mail:\nNo attendees defined.\n"));
2788 return; 2789 return;
2789 } 2790 }
2790 2791
2791 mailobject.emailEvent(anEvent); 2792 mailobject.emailEvent(anEvent);
2792#endif 2793#endif
2793} 2794}
2794 2795
2795 2796
2796void CalendarView::schedule_publish(Incidence *incidence) 2797void CalendarView::schedule_publish(Incidence *incidence)
2797{ 2798{
2798 Event *event = 0; 2799 Event *event = 0;
2799 Todo *todo = 0; 2800 Todo *todo = 0;
2800 2801
2801 if (incidence == 0) { 2802 if (incidence == 0) {
2802 incidence = mViewManager->currentView()->selectedIncidences().first(); 2803 incidence = mViewManager->currentView()->selectedIncidences().first();
2803 if (incidence == 0) { 2804 if (incidence == 0) {
2804 incidence = mTodoList->selectedIncidences().first(); 2805 incidence = mTodoList->selectedIncidences().first();
2805 } 2806 }
2806 } 2807 }
2807 if ( incidence && incidence->type() == "Event" ) { 2808 if ( incidence && incidence->type() == "Event" ) {
2808 event = static_cast<Event *>(incidence); 2809 event = static_cast<Event *>(incidence);
2809 } else { 2810 } else {
2810 if ( incidence && incidence->type() == "Todo" ) { 2811 if ( incidence && incidence->type() == "Todo" ) {
2811 todo = static_cast<Todo *>(incidence); 2812 todo = static_cast<Todo *>(incidence);
2812 } 2813 }
2813 } 2814 }
2814 2815
2815 if (!event && !todo) { 2816 if (!event && !todo) {
2816 KMessageBox::sorry(this,i18n("No event selected.")); 2817 KMessageBox::sorry(this,i18n("No event selected."));
2817 return; 2818 return;
2818 } 2819 }
2819 2820
2820 PublishDialog *publishdlg = new PublishDialog(); 2821 PublishDialog *publishdlg = new PublishDialog();
2821 if (incidence->attendeeCount()>0) { 2822 if (incidence->attendeeCount()>0) {
2822 QPtrList<Attendee> attendees = incidence->attendees(); 2823 QPtrList<Attendee> attendees = incidence->attendees();
2823 attendees.first(); 2824 attendees.first();
2824 while ( attendees.current()!=0 ) { 2825 while ( attendees.current()!=0 ) {
2825 publishdlg->addAttendee(attendees.current()); 2826 publishdlg->addAttendee(attendees.current());
2826 attendees.next(); 2827 attendees.next();
2827 } 2828 }
2828 } 2829 }
2829 bool send = true; 2830 bool send = true;
2830 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 2831 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
2831 if ( publishdlg->exec() != QDialog::Accepted ) 2832 if ( publishdlg->exec() != QDialog::Accepted )
2832 send = false; 2833 send = false;
2833 } 2834 }
2834 if ( send ) { 2835 if ( send ) {
2835 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2836 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2836 if ( event ) { 2837 if ( event ) {
2837 Event *ev = new Event(*event); 2838 Event *ev = new Event(*event);
2838 ev->registerObserver(0); 2839 ev->registerObserver(0);
2839 ev->clearAttendees(); 2840 ev->clearAttendees();
2840 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2841 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2841 delete(ev); 2842 delete(ev);
2842 } 2843 }
2843 } else { 2844 } else {
2844 if ( todo ) { 2845 if ( todo ) {
2845 Todo *ev = new Todo(*todo); 2846 Todo *ev = new Todo(*todo);
2846 ev->registerObserver(0); 2847 ev->registerObserver(0);
2847 ev->clearAttendees(); 2848 ev->clearAttendees();
2848 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 2849 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
2849 delete(ev); 2850 delete(ev);
2850 } 2851 }
2851 } 2852 }
2852 } 2853 }
2853 } 2854 }
2854 delete publishdlg; 2855 delete publishdlg;
2855} 2856}
2856 2857
2857void CalendarView::schedule_request(Incidence *incidence) 2858void CalendarView::schedule_request(Incidence *incidence)
2858{ 2859{
2859 schedule(Scheduler::Request,incidence); 2860 schedule(Scheduler::Request,incidence);
2860} 2861}
2861 2862
2862void CalendarView::schedule_refresh(Incidence *incidence) 2863void CalendarView::schedule_refresh(Incidence *incidence)
2863{ 2864{
2864 schedule(Scheduler::Refresh,incidence); 2865 schedule(Scheduler::Refresh,incidence);
2865} 2866}
2866 2867
2867void CalendarView::schedule_cancel(Incidence *incidence) 2868void CalendarView::schedule_cancel(Incidence *incidence)
2868{ 2869{
2869 schedule(Scheduler::Cancel,incidence); 2870 schedule(Scheduler::Cancel,incidence);
2870} 2871}
2871 2872
2872void CalendarView::schedule_add(Incidence *incidence) 2873void CalendarView::schedule_add(Incidence *incidence)
2873{ 2874{
2874 schedule(Scheduler::Add,incidence); 2875 schedule(Scheduler::Add,incidence);
2875} 2876}
2876 2877
2877void CalendarView::schedule_reply(Incidence *incidence) 2878void CalendarView::schedule_reply(Incidence *incidence)
2878{ 2879{
2879 schedule(Scheduler::Reply,incidence); 2880 schedule(Scheduler::Reply,incidence);
2880} 2881}
2881 2882
2882void CalendarView::schedule_counter(Incidence *incidence) 2883void CalendarView::schedule_counter(Incidence *incidence)
2883{ 2884{
2884 schedule(Scheduler::Counter,incidence); 2885 schedule(Scheduler::Counter,incidence);
2885} 2886}
2886 2887
2887void CalendarView::schedule_declinecounter(Incidence *incidence) 2888void CalendarView::schedule_declinecounter(Incidence *incidence)
2888{ 2889{
2889 schedule(Scheduler::Declinecounter,incidence); 2890 schedule(Scheduler::Declinecounter,incidence);
2890} 2891}
2891 2892
2892void CalendarView::schedule_publish_freebusy(int daysToPublish) 2893void CalendarView::schedule_publish_freebusy(int daysToPublish)
2893{ 2894{
2894 QDateTime start = QDateTime::currentDateTime(); 2895 QDateTime start = QDateTime::currentDateTime();
2895 QDateTime end = start.addDays(daysToPublish); 2896 QDateTime end = start.addDays(daysToPublish);
2896 2897
2897 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 2898 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
2898 freebusy->setOrganizer(KOPrefs::instance()->email()); 2899 freebusy->setOrganizer(KOPrefs::instance()->email());
2899 2900
2900 2901
2901 PublishDialog *publishdlg = new PublishDialog(); 2902 PublishDialog *publishdlg = new PublishDialog();
2902 if ( publishdlg->exec() == QDialog::Accepted ) { 2903 if ( publishdlg->exec() == QDialog::Accepted ) {
2903 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2904 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2904 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 2905 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
2905 delete(freebusy); 2906 delete(freebusy);
2906 } 2907 }
2907 } 2908 }
2908 delete publishdlg; 2909 delete publishdlg;
2909} 2910}
2910 2911
2911void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 2912void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
2912{ 2913{
2913 Event *event = 0; 2914 Event *event = 0;
2914 Todo *todo = 0; 2915 Todo *todo = 0;
2915 2916
2916 if (incidence == 0) { 2917 if (incidence == 0) {
2917 incidence = mViewManager->currentView()->selectedIncidences().first(); 2918 incidence = mViewManager->currentView()->selectedIncidences().first();
2918 if (incidence == 0) { 2919 if (incidence == 0) {
2919 incidence = mTodoList->selectedIncidences().first(); 2920 incidence = mTodoList->selectedIncidences().first();
2920 } 2921 }
2921 } 2922 }
2922 if ( incidence && incidence->type() == "Event" ) { 2923 if ( incidence && incidence->type() == "Event" ) {
2923 event = static_cast<Event *>(incidence); 2924 event = static_cast<Event *>(incidence);
2924 } 2925 }
2925 if ( incidence && incidence->type() == "Todo" ) { 2926 if ( incidence && incidence->type() == "Todo" ) {
2926 todo = static_cast<Todo *>(incidence); 2927 todo = static_cast<Todo *>(incidence);
2927 } 2928 }
2928 2929
2929 if (!event && !todo) { 2930 if (!event && !todo) {
2930 KMessageBox::sorry(this,i18n("No event selected.")); 2931 KMessageBox::sorry(this,i18n("No event selected."));
2931 return; 2932 return;
2932 } 2933 }
2933 2934
2934 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 2935 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
2935 KMessageBox::sorry(this,i18n("The event has no attendees.")); 2936 KMessageBox::sorry(this,i18n("The event has no attendees."));
2936 return; 2937 return;
2937 } 2938 }
2938 2939
2939 Event *ev = 0; 2940 Event *ev = 0;
2940 if (event) ev = new Event(*event); 2941 if (event) ev = new Event(*event);
2941 Todo *to = 0; 2942 Todo *to = 0;
2942 if (todo) to = new Todo(*todo); 2943 if (todo) to = new Todo(*todo);
2943 2944
2944 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 2945 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
2945 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 2946 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
2946 if (!me) { 2947 if (!me) {
2947 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 2948 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
2948 return; 2949 return;
2949 } 2950 }
2950 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 2951 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
2951 StatusDialog *statdlg = new StatusDialog(this); 2952 StatusDialog *statdlg = new StatusDialog(this);
2952 if (!statdlg->exec()==QDialog::Accepted) return; 2953 if (!statdlg->exec()==QDialog::Accepted) return;
2953 me->setStatus( statdlg->status() ); 2954 me->setStatus( statdlg->status() );
2954 delete(statdlg); 2955 delete(statdlg);
2955 } 2956 }
2956 Attendee *menew = new Attendee(*me); 2957 Attendee *menew = new Attendee(*me);
2957 if (ev) { 2958 if (ev) {
2958 ev->clearAttendees(); 2959 ev->clearAttendees();
2959 ev->addAttendee(menew,false); 2960 ev->addAttendee(menew,false);
2960 } else { 2961 } else {
2961 if (to) { 2962 if (to) {
2962 todo->clearAttendees(); 2963 todo->clearAttendees();
2963 todo->addAttendee(menew,false); 2964 todo->addAttendee(menew,false);
2964 } 2965 }
2965 } 2966 }
2966 } 2967 }
2967 2968
2968 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 2969 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
2969 if (ev) { 2970 if (ev) {
2970 if ( !dlg->addMessage(ev,method) ) delete(ev); 2971 if ( !dlg->addMessage(ev,method) ) delete(ev);
2971 } else { 2972 } else {
2972 if (to) { 2973 if (to) {
2973 if ( !dlg->addMessage(to,method) ) delete(to); 2974 if ( !dlg->addMessage(to,method) ) delete(to);
2974 } 2975 }
2975 } 2976 }
2976} 2977}
2977 2978
2978void CalendarView::openAddressbook() 2979void CalendarView::openAddressbook()
2979{ 2980{
2980 KRun::runCommand("kaddressbook"); 2981 KRun::runCommand("kaddressbook");
2981} 2982}
2982 2983
2983void CalendarView::setModified(bool modified) 2984void CalendarView::setModified(bool modified)
2984{ 2985{
2985 if ( modified ) 2986 if ( modified )
2986 emit signalmodified(); 2987 emit signalmodified();
2987 if (mModified != modified) { 2988 if (mModified != modified) {
2988 mModified = modified; 2989 mModified = modified;
2989 emit modifiedChanged(mModified); 2990 emit modifiedChanged(mModified);
2990 } 2991 }
2991} 2992}
2992 2993
2993bool CalendarView::isReadOnly() 2994bool CalendarView::isReadOnly()
2994{ 2995{
2995 return mReadOnly; 2996 return mReadOnly;
2996} 2997}
2997 2998
2998void CalendarView::setReadOnly(bool readOnly) 2999void CalendarView::setReadOnly(bool readOnly)
2999{ 3000{
3000 if (mReadOnly != readOnly) { 3001 if (mReadOnly != readOnly) {
3001 mReadOnly = readOnly; 3002 mReadOnly = readOnly;
3002 emit readOnlyChanged(mReadOnly); 3003 emit readOnlyChanged(mReadOnly);
3003 } 3004 }
3004} 3005}
3005 3006
3006bool CalendarView::isModified() 3007bool CalendarView::isModified()
3007{ 3008{
3008 return mModified; 3009 return mModified;
3009} 3010}
3010 3011
3011void CalendarView::printSetup() 3012void CalendarView::printSetup()
3012{ 3013{
3013#ifndef KORG_NOPRINTER 3014#ifndef KORG_NOPRINTER
3014 createPrinter(); 3015 createPrinter();
3015 3016
3016 mCalPrinter->setupPrinter(); 3017 mCalPrinter->setupPrinter();
3017#endif 3018#endif
3018} 3019}
3019 3020
3020void CalendarView::print() 3021void CalendarView::print()
3021{ 3022{
3022#ifndef KORG_NOPRINTER 3023#ifndef KORG_NOPRINTER
3023 createPrinter(); 3024 createPrinter();
3024 3025
3025 DateList tmpDateList = mNavigator->selectedDates(); 3026 DateList tmpDateList = mNavigator->selectedDates();
3026 mCalPrinter->print(CalPrinter::Month, 3027 mCalPrinter->print(CalPrinter::Month,
3027 tmpDateList.first(), tmpDateList.last()); 3028 tmpDateList.first(), tmpDateList.last());
3028#endif 3029#endif
3029} 3030}
3030 3031
3031void CalendarView::printPreview() 3032void CalendarView::printPreview()
3032{ 3033{
3033#ifndef KORG_NOPRINTER 3034#ifndef KORG_NOPRINTER
3034 kdDebug() << "CalendarView::printPreview()" << endl; 3035 kdDebug() << "CalendarView::printPreview()" << endl;
3035 3036
3036 createPrinter(); 3037 createPrinter();
3037 3038
3038 DateList tmpDateList = mNavigator->selectedDates(); 3039 DateList tmpDateList = mNavigator->selectedDates();
3039 3040
3040 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3041 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3041 tmpDateList.last()); 3042 tmpDateList.last());
3042#endif 3043#endif
3043} 3044}
3044 3045
3045void CalendarView::exportICalendar() 3046void CalendarView::exportICalendar()
3046{ 3047{
3047 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3048 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3048 3049
3049 // Force correct extension 3050 // Force correct extension
3050 if (filename.right(4) != ".ics") filename += ".ics"; 3051 if (filename.right(4) != ".ics") filename += ".ics";
3051 3052
3052 FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 3053 FileStorage storage( mCalendar, filename, new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
3053 storage.save(); 3054 storage.save();
3054} 3055}
3055 3056
3056bool CalendarView::exportVCalendar( QString filename ) 3057bool CalendarView::exportVCalendar( QString filename )
3057{ 3058{
3058 if (mCalendar->journals().count() > 0) { 3059 if (mCalendar->journals().count() > 0) {
3059 int result = KMessageBox::warningContinueCancel(this, 3060 int result = KMessageBox::warningContinueCancel(this,
3060 i18n("The journal entries can not be\nexported to a vCalendar file."), 3061 i18n("The journal entries can not be\nexported to a vCalendar file."),
3061 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3062 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3062 true); 3063 true);
3063 if (result != KMessageBox::Continue) return false; 3064 if (result != KMessageBox::Continue) return false;
3064 } 3065 }
3065 3066
3066 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3067 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3067 3068
3068 // Force correct extension 3069 // Force correct extension
3069 if (filename.right(4) != ".vcs") filename += ".vcs"; 3070 if (filename.right(4) != ".vcs") filename += ".vcs";
3070 3071
3071 FileStorage storage( mCalendar, filename, new VCalFormat ); 3072 FileStorage storage( mCalendar, filename, new VCalFormat );
3072 return storage.save(); 3073 return storage.save();
3073 3074
3074} 3075}
3075 3076
3076void CalendarView::eventUpdated(Incidence *) 3077void CalendarView::eventUpdated(Incidence *)
3077{ 3078{
3078 setModified(); 3079 setModified();
3079 // Don't call updateView here. The code, which has caused the update of the 3080 // Don't call updateView here. The code, which has caused the update of the
3080 // event is responsible for updating the view. 3081 // event is responsible for updating the view.
3081 // updateView(); 3082 // updateView();
3082} 3083}
3083 3084
3084void CalendarView::adaptNavigationUnits() 3085void CalendarView::adaptNavigationUnits()
3085{ 3086{
3086 if (mViewManager->currentView()->isEventView()) { 3087 if (mViewManager->currentView()->isEventView()) {
3087 int days = mViewManager->currentView()->currentDateCount(); 3088 int days = mViewManager->currentView()->currentDateCount();
3088 if (days == 1) { 3089 if (days == 1) {
3089 emit changeNavStringPrev(i18n("&Previous Day")); 3090 emit changeNavStringPrev(i18n("&Previous Day"));
3090 emit changeNavStringNext(i18n("&Next Day")); 3091 emit changeNavStringNext(i18n("&Next Day"));
3091 } else { 3092 } else {
3092 emit changeNavStringPrev(i18n("&Previous Week")); 3093 emit changeNavStringPrev(i18n("&Previous Week"));
3093 emit changeNavStringNext(i18n("&Next Week")); 3094 emit changeNavStringNext(i18n("&Next Week"));
3094 } 3095 }
3095 } 3096 }
3096} 3097}
3097 3098
3098void CalendarView::processMainViewSelection( Incidence *incidence ) 3099void CalendarView::processMainViewSelection( Incidence *incidence )
3099{ 3100{
3100 if ( incidence ) mTodoList->clearSelection(); 3101 if ( incidence ) mTodoList->clearSelection();
3101 processIncidenceSelection( incidence ); 3102 processIncidenceSelection( incidence );
3102} 3103}
3103 3104
3104void CalendarView::processTodoListSelection( Incidence *incidence ) 3105void CalendarView::processTodoListSelection( Incidence *incidence )
3105{ 3106{
3106 if ( incidence && mViewManager->currentView() ) { 3107 if ( incidence && mViewManager->currentView() ) {
3107 mViewManager->currentView()->clearSelection(); 3108 mViewManager->currentView()->clearSelection();
3108 } 3109 }
3109 processIncidenceSelection( incidence ); 3110 processIncidenceSelection( incidence );
3110} 3111}
3111 3112
3112void CalendarView::processIncidenceSelection( Incidence *incidence ) 3113void CalendarView::processIncidenceSelection( Incidence *incidence )
3113{ 3114{
3114 if ( incidence == mSelectedIncidence ) return; 3115 if ( incidence == mSelectedIncidence ) return;
3115 3116
3116 mSelectedIncidence = incidence; 3117 mSelectedIncidence = incidence;
3117 3118
3118 emit incidenceSelected( mSelectedIncidence ); 3119 emit incidenceSelected( mSelectedIncidence );
3119 3120
3120 if ( incidence && incidence->type() == "Event" ) { 3121 if ( incidence && incidence->type() == "Event" ) {
3121 Event *event = static_cast<Event *>( incidence ); 3122 Event *event = static_cast<Event *>( incidence );
3122 if ( event->organizer() == KOPrefs::instance()->email() ) { 3123 if ( event->organizer() == KOPrefs::instance()->email() ) {
3123 emit organizerEventsSelected( true ); 3124 emit organizerEventsSelected( true );
3124 } else { 3125 } else {
3125 emit organizerEventsSelected(false); 3126 emit organizerEventsSelected(false);
3126 } 3127 }
3127 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3128 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3128 KOPrefs::instance()->email() ) ) { 3129 KOPrefs::instance()->email() ) ) {
3129 emit groupEventsSelected( true ); 3130 emit groupEventsSelected( true );
3130 } else { 3131 } else {
3131 emit groupEventsSelected(false); 3132 emit groupEventsSelected(false);
3132 } 3133 }
3133 return; 3134 return;
3134 } else { 3135 } else {
3135 if ( incidence && incidence->type() == "Todo" ) { 3136 if ( incidence && incidence->type() == "Todo" ) {
3136 emit todoSelected( true ); 3137 emit todoSelected( true );
3137 Todo *event = static_cast<Todo *>( incidence ); 3138 Todo *event = static_cast<Todo *>( incidence );
3138 if ( event->organizer() == KOPrefs::instance()->email() ) { 3139 if ( event->organizer() == KOPrefs::instance()->email() ) {
3139 emit organizerEventsSelected( true ); 3140 emit organizerEventsSelected( true );
3140 } else { 3141 } else {
3141 emit organizerEventsSelected(false); 3142 emit organizerEventsSelected(false);
3142 } 3143 }
3143 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3144 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3144 KOPrefs::instance()->email() ) ) { 3145 KOPrefs::instance()->email() ) ) {
3145 emit groupEventsSelected( true ); 3146 emit groupEventsSelected( true );
3146 } else { 3147 } else {
3147 emit groupEventsSelected(false); 3148 emit groupEventsSelected(false);
3148 } 3149 }
3149 return; 3150 return;
3150 } else { 3151 } else {
3151 emit todoSelected( false ); 3152 emit todoSelected( false );
3152 emit organizerEventsSelected(false); 3153 emit organizerEventsSelected(false);
3153 emit groupEventsSelected(false); 3154 emit groupEventsSelected(false);
3154 } 3155 }
3155 return; 3156 return;
3156 } 3157 }
3157 3158
3158 /* if ( incidence && incidence->type() == "Todo" ) { 3159 /* if ( incidence && incidence->type() == "Todo" ) {
3159 emit todoSelected( true ); 3160 emit todoSelected( true );
3160 } else { 3161 } else {
3161 emit todoSelected( false ); 3162 emit todoSelected( false );
3162 }*/ 3163 }*/
3163} 3164}
3164 3165
3165 3166
3166void CalendarView::checkClipboard() 3167void CalendarView::checkClipboard()
3167{ 3168{
3168#ifndef KORG_NODND 3169#ifndef KORG_NODND
3169 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3170 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3170 emit pasteEnabled(true); 3171 emit pasteEnabled(true);
3171 } else { 3172 } else {
3172 emit pasteEnabled(false); 3173 emit pasteEnabled(false);
3173 } 3174 }
3174#endif 3175#endif
3175} 3176}
3176 3177
3177void CalendarView::showDates(const DateList &selectedDates) 3178void CalendarView::showDates(const DateList &selectedDates)
3178{ 3179{
3179 // kdDebug() << "CalendarView::selectDates()" << endl; 3180 // kdDebug() << "CalendarView::selectDates()" << endl;
3180 3181
3181 if ( mViewManager->currentView() ) { 3182 if ( mViewManager->currentView() ) {
3182 updateView( selectedDates.first(), selectedDates.last() ); 3183 updateView( selectedDates.first(), selectedDates.last() );
3183 } else { 3184 } else {
3184 mViewManager->showAgendaView(); 3185 mViewManager->showAgendaView();
3185 } 3186 }
3186 3187
3187 QString selDates; 3188 QString selDates;
3188 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true); 3189 selDates = KGlobal::locale()->formatDate( selectedDates.first(), true);
3189 if (selectedDates.first() < selectedDates.last() ) 3190 if (selectedDates.first() < selectedDates.last() )
3190 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3191 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3191 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3192 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3192 3193
3193} 3194}
3194 3195
3195QPtrList<CalFilter> CalendarView::filters() 3196QPtrList<CalFilter> CalendarView::filters()
3196{ 3197{
3197 return mFilters; 3198 return mFilters;
3198 3199
3199} 3200}
3200void CalendarView::editFilters() 3201void CalendarView::editFilters()
3201{ 3202{
3202 // kdDebug() << "CalendarView::editFilters()" << endl; 3203 // kdDebug() << "CalendarView::editFilters()" << endl;
3203 3204
3204 CalFilter *filter = mFilters.first(); 3205 CalFilter *filter = mFilters.first();
3205 while(filter) { 3206 while(filter) {
3206 kdDebug() << " Filter: " << filter->name() << endl; 3207 kdDebug() << " Filter: " << filter->name() << endl;
3207 filter = mFilters.next(); 3208 filter = mFilters.next();
3208 } 3209 }
3209 3210
3210 mDialogManager->showFilterEditDialog(&mFilters); 3211 mDialogManager->showFilterEditDialog(&mFilters);
3211} 3212}
3212void CalendarView::toggleFilter() 3213void CalendarView::toggleFilter()
3213{ 3214{
3214 showFilter(! mFilterView->isVisible()); 3215 showFilter(! mFilterView->isVisible());
3215} 3216}
3216 3217
3217KOFilterView *CalendarView::filterView() 3218KOFilterView *CalendarView::filterView()
3218{ 3219{
3219 return mFilterView; 3220 return mFilterView;
3220} 3221}
3221void CalendarView::selectFilter( int fil ) 3222void CalendarView::selectFilter( int fil )
3222{ 3223{
3223 mFilterView->setSelectedFilter( fil ); 3224 mFilterView->setSelectedFilter( fil );
3224} 3225}
3225void CalendarView::showFilter(bool visible) 3226void CalendarView::showFilter(bool visible)
3226{ 3227{
3227 if (visible) mFilterView->show(); 3228 if (visible) mFilterView->show();
3228 else mFilterView->hide(); 3229 else mFilterView->hide();
3229} 3230}
3230void CalendarView::toggleFilerEnabled( ) 3231void CalendarView::toggleFilerEnabled( )
3231{ 3232{
3232 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3233 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3233 if ( !mFilterView->filtersEnabled() ) 3234 if ( !mFilterView->filtersEnabled() )
3234 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3235 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3235 3236
3236} 3237}
3237void CalendarView::updateFilter() 3238void CalendarView::updateFilter()
3238{ 3239{
3239 CalFilter *filter = mFilterView->selectedFilter(); 3240 CalFilter *filter = mFilterView->selectedFilter();
3240 if (filter) { 3241 if (filter) {
3241 if (mFilterView->filtersEnabled()) { 3242 if (mFilterView->filtersEnabled()) {
3242 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() ); 3243 topLevelWidget()->setCaption( i18n("Filter selected: ")+filter->name() );
3243 filter->setEnabled(true); 3244 filter->setEnabled(true);
3244 } 3245 }
3245 else filter->setEnabled(false); 3246 else filter->setEnabled(false);
3246 mCalendar->setFilter(filter); 3247 mCalendar->setFilter(filter);
3247 updateView(); 3248 updateView();
3248 } 3249 }
3249} 3250}
3250 3251
3251void CalendarView::filterEdited() 3252void CalendarView::filterEdited()
3252{ 3253{
3253 mFilterView->updateFilters(); 3254 mFilterView->updateFilters();
3254 updateFilter(); 3255 updateFilter();
3255 writeSettings(); 3256 writeSettings();
3256} 3257}
3257 3258
3258 3259
3259void CalendarView::takeOverEvent() 3260void CalendarView::takeOverEvent()
3260{ 3261{
3261 Incidence *incidence = currentSelection(); 3262 Incidence *incidence = currentSelection();
3262 3263
3263 if (!incidence) return; 3264 if (!incidence) return;
3264 3265
3265 incidence->setOrganizer(KOPrefs::instance()->email()); 3266 incidence->setOrganizer(KOPrefs::instance()->email());
3266 incidence->recreate(); 3267 incidence->recreate();
3267 incidence->setReadOnly(false); 3268 incidence->setReadOnly(false);
3268 3269
3269 updateView(); 3270 updateView();
3270} 3271}
3271 3272
3272void CalendarView::takeOverCalendar() 3273void CalendarView::takeOverCalendar()
3273{ 3274{
3274 // TODO: Create Calendar::allIncidences() function and use it here 3275 // TODO: Create Calendar::allIncidences() function and use it here
3275 3276
3276 QPtrList<Event> events = mCalendar->events(); 3277 QPtrList<Event> events = mCalendar->events();
3277 for(uint i=0; i<events.count(); ++i) { 3278 for(uint i=0; i<events.count(); ++i) {
3278 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3279 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3279 events.at(i)->recreate(); 3280 events.at(i)->recreate();
3280 events.at(i)->setReadOnly(false); 3281 events.at(i)->setReadOnly(false);
3281 } 3282 }
3282 3283
3283 QPtrList<Todo> todos = mCalendar->todos(); 3284 QPtrList<Todo> todos = mCalendar->todos();
3284 for(uint i=0; i<todos.count(); ++i) { 3285 for(uint i=0; i<todos.count(); ++i) {
3285 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3286 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3286 todos.at(i)->recreate(); 3287 todos.at(i)->recreate();
3287 todos.at(i)->setReadOnly(false); 3288 todos.at(i)->setReadOnly(false);
3288 } 3289 }
3289 3290
3290 QPtrList<Journal> journals = mCalendar->journals(); 3291 QPtrList<Journal> journals = mCalendar->journals();
3291 for(uint i=0; i<journals.count(); ++i) { 3292 for(uint i=0; i<journals.count(); ++i) {
3292 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3293 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3293 journals.at(i)->recreate(); 3294 journals.at(i)->recreate();
3294 journals.at(i)->setReadOnly(false); 3295 journals.at(i)->setReadOnly(false);
3295 } 3296 }
3296 3297
3297 updateView(); 3298 updateView();
3298} 3299}
3299 3300
3300void CalendarView::showIntro() 3301void CalendarView::showIntro()
3301{ 3302{
3302 kdDebug() << "To be implemented." << endl; 3303 kdDebug() << "To be implemented." << endl;
3303} 3304}
3304 3305
3305QWidgetStack *CalendarView::viewStack() 3306QWidgetStack *CalendarView::viewStack()
3306{ 3307{
3307 return mRightFrame; 3308 return mRightFrame;
3308} 3309}
3309 3310
3310QWidget *CalendarView::leftFrame() 3311QWidget *CalendarView::leftFrame()
3311{ 3312{
3312 return mLeftFrame; 3313 return mLeftFrame;
3313} 3314}
3314 3315
3315DateNavigator *CalendarView::dateNavigator() 3316DateNavigator *CalendarView::dateNavigator()
3316{ 3317{
3317 return mNavigator; 3318 return mNavigator;
3318} 3319}
3319 3320
3320KDateNavigator* CalendarView::dateNavigatorWidget() 3321KDateNavigator* CalendarView::dateNavigatorWidget()
3321{ 3322{
3322 return mDateNavigator; 3323 return mDateNavigator;
3323} 3324}
3324void CalendarView::toggleDateNavigatorWidget() 3325void CalendarView::toggleDateNavigatorWidget()
3325{ 3326{
3326 if (mDateNavigator->isVisible()) 3327 if (mDateNavigator->isVisible())
3327 mDateNavigator->hide(); 3328 mDateNavigator->hide();
3328 else 3329 else
3329 mDateNavigator->show(); 3330 mDateNavigator->show();
3330} 3331}
3331void CalendarView::addView(KOrg::BaseView *view) 3332void CalendarView::addView(KOrg::BaseView *view)
3332{ 3333{
3333 mViewManager->addView(view); 3334 mViewManager->addView(view);
3334} 3335}
3335 3336
3336void CalendarView::showView(KOrg::BaseView *view) 3337void CalendarView::showView(KOrg::BaseView *view)
3337{ 3338{
3338 mViewManager->showView(view, mLeftFrame->isVisible()); 3339 mViewManager->showView(view, mLeftFrame->isVisible());
3339} 3340}
3340 3341
3341Incidence *CalendarView::currentSelection() 3342Incidence *CalendarView::currentSelection()
3342{ 3343{
3343 return mViewManager->currentSelection(); 3344 return mViewManager->currentSelection();
3344} 3345}
3345void CalendarView::toggleAllDaySize() 3346void CalendarView::toggleAllDaySize()
3346{ 3347{
3347 /* 3348 /*
3348 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3349 if ( KOPrefs::instance()->mAllDaySize > 47 )
3349 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3350 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3350 else 3351 else
3351 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3352 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3352 */ 3353 */
3353 viewManager()->agendaView()->toggleAllDay(); 3354 viewManager()->agendaView()->toggleAllDay();
3354} 3355}
3355void CalendarView::toggleExpand() 3356void CalendarView::toggleExpand()
3356{ 3357{
3357 // if ( mLeftFrame->isHidden() ) { 3358 // if ( mLeftFrame->isHidden() ) {
3358 // mLeftFrame->show(); 3359 // mLeftFrame->show();
3359 // emit calendarViewExpanded( false ); 3360 // emit calendarViewExpanded( false );
3360 // } else { 3361 // } else {
3361 // mLeftFrame->hide(); 3362 // mLeftFrame->hide();
3362 // emit calendarViewExpanded( true ); 3363 // emit calendarViewExpanded( true );
3363 // } 3364 // }
3364 3365
3365 globalFlagBlockAgenda = 1; 3366 globalFlagBlockAgenda = 1;
3366 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3367 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3367 globalFlagBlockAgenda = 5; 3368 globalFlagBlockAgenda = 5;
3368 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3369 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3369 //mViewManager->showView( 0, true ); 3370 //mViewManager->showView( 0, true );
3370} 3371}
3371 3372
3372void CalendarView::calendarModified( bool modified, Calendar * ) 3373void CalendarView::calendarModified( bool modified, Calendar * )
3373{ 3374{
3374 setModified( modified ); 3375 setModified( modified );
3375} 3376}
3376 3377
3377Todo *CalendarView::selectedTodo() 3378Todo *CalendarView::selectedTodo()
3378{ 3379{
3379 Incidence *incidence = currentSelection(); 3380 Incidence *incidence = currentSelection();
3380 if ( incidence && incidence->type() == "Todo" ) { 3381 if ( incidence && incidence->type() == "Todo" ) {
3381 return static_cast<Todo *>( incidence ); 3382 return static_cast<Todo *>( incidence );
3382 } 3383 }
3383 3384
3384 incidence = mTodoList->selectedIncidences().first(); 3385 incidence = mTodoList->selectedIncidences().first();
3385 if ( incidence && incidence->type() == "Todo" ) { 3386 if ( incidence && incidence->type() == "Todo" ) {
3386 return static_cast<Todo *>( incidence ); 3387 return static_cast<Todo *>( incidence );
3387 } 3388 }
3388 3389
3389 return 0; 3390 return 0;
3390} 3391}
3391 3392
3392void CalendarView::dialogClosing(Incidence *in) 3393void CalendarView::dialogClosing(Incidence *in)
3393{ 3394{
3394 // mDialogList.remove(in); 3395 // mDialogList.remove(in);
3395} 3396}
3396 3397
3397void CalendarView::showIncidence() 3398void CalendarView::showIncidence()
3398{ 3399{
3399 Incidence *incidence = currentSelection(); 3400 Incidence *incidence = currentSelection();
3400 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3401 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3401 if ( incidence ) { 3402 if ( incidence ) {
3402 ShowIncidenceVisitor v; 3403 ShowIncidenceVisitor v;
3403 v.act( incidence, this ); 3404 v.act( incidence, this );
3404 } 3405 }
3405} 3406}
3406void CalendarView::editIncidenceDescription() 3407void CalendarView::editIncidenceDescription()
3407{ 3408{
3408 mFlagEditDescription = true; 3409 mFlagEditDescription = true;
3409 editIncidence(); 3410 editIncidence();
3410 mFlagEditDescription = false; 3411 mFlagEditDescription = false;
3411} 3412}
3412void CalendarView::editIncidence() 3413void CalendarView::editIncidence()
3413{ 3414{
3414 // qDebug("editIncidence() "); 3415 // qDebug("editIncidence() ");
3415 Incidence *incidence = currentSelection(); 3416 Incidence *incidence = currentSelection();
3416 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3417 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3417 if ( incidence ) { 3418 if ( incidence ) {
3418 EditIncidenceVisitor v; 3419 EditIncidenceVisitor v;
3419 v.act( incidence, this ); 3420 v.act( incidence, this );
3420 } 3421 }
3421} 3422}
3422 3423
3423void CalendarView::deleteIncidence() 3424void CalendarView::deleteIncidence()
3424{ 3425{
3425 Incidence *incidence = currentSelection(); 3426 Incidence *incidence = currentSelection();
3426 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3427 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3427 if ( incidence ) { 3428 if ( incidence ) {
3428 deleteIncidence(incidence); 3429 deleteIncidence(incidence);
3429 } 3430 }
3430} 3431}
3431 3432
3432void CalendarView::showIncidence(Incidence *incidence) 3433void CalendarView::showIncidence(Incidence *incidence)
3433{ 3434{
3434 if ( incidence ) { 3435 if ( incidence ) {
3435 ShowIncidenceVisitor v; 3436 ShowIncidenceVisitor v;
3436 v.act( incidence, this ); 3437 v.act( incidence, this );
3437 } 3438 }
3438} 3439}
3439 3440
3440void CalendarView::editIncidence(Incidence *incidence) 3441void CalendarView::editIncidence(Incidence *incidence)
3441{ 3442{
3442 if ( incidence ) { 3443 if ( incidence ) {
3443 3444
3444 EditIncidenceVisitor v; 3445 EditIncidenceVisitor v;
3445 v.act( incidence, this ); 3446 v.act( incidence, this );
3446 3447
3447 } 3448 }
3448} 3449}
3449 3450
3450void CalendarView::deleteIncidence(Incidence *incidence) 3451void CalendarView::deleteIncidence(Incidence *incidence)
3451{ 3452{
3452 //qDebug(" CalendarView::deleteIncidence "); 3453 //qDebug(" CalendarView::deleteIncidence ");
3453 if ( incidence ) { 3454 if ( incidence ) {
3454 DeleteIncidenceVisitor v; 3455 DeleteIncidenceVisitor v;
3455 v.act( incidence, this ); 3456 v.act( incidence, this );
3456 } 3457 }
3457} 3458}
3458 3459
3459 3460
3460void CalendarView::lookForOutgoingMessages() 3461void CalendarView::lookForOutgoingMessages()
3461{ 3462{
3462 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3463 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3463 ogd->loadMessages(); 3464 ogd->loadMessages();
3464} 3465}
3465 3466
3466void CalendarView::lookForIncomingMessages() 3467void CalendarView::lookForIncomingMessages()
3467{ 3468{
3468 IncomingDialog *icd = mDialogManager->incomingDialog(); 3469 IncomingDialog *icd = mDialogManager->incomingDialog();
3469 icd->retrieve(); 3470 icd->retrieve();
3470} 3471}
3471 3472
3472bool CalendarView::removeCompletedSubTodos( Todo* t ) 3473bool CalendarView::removeCompletedSubTodos( Todo* t )
3473{ 3474{
3474 bool deleteTodo = true; 3475 bool deleteTodo = true;
3475 QPtrList<Incidence> subTodos; 3476 QPtrList<Incidence> subTodos;
3476 Incidence *aTodo; 3477 Incidence *aTodo;
3477 subTodos = t->relations(); 3478 subTodos = t->relations();
3478 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3479 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3479 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3480 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3480 deleteTodo = false; 3481 deleteTodo = false;
3481 } 3482 }
3482 if ( deleteTodo ) { 3483 if ( deleteTodo ) {
3483 if ( t->isCompleted() ) { 3484 if ( t->isCompleted() ) {
3484 checkExternalId( t ); 3485 checkExternalId( t );
3485 mCalendar->deleteTodo( t ); 3486 mCalendar->deleteTodo( t );
3486 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3487 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3487 } 3488 }
3488 else 3489 else
3489 deleteTodo = false; 3490 deleteTodo = false;
3490 } 3491 }
3491 return deleteTodo; 3492 return deleteTodo;
3492 3493
3493} 3494}
3494void CalendarView::purgeCompleted() 3495void CalendarView::purgeCompleted()
3495{ 3496{
3496 int result = KMessageBox::warningContinueCancel(this, 3497 int result = KMessageBox::warningContinueCancel(this,
3497 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3498 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge"));
3498 3499
3499 if (result == KMessageBox::Continue) { 3500 if (result == KMessageBox::Continue) {
3500 3501
3501 QPtrList<Todo> todoCal; 3502 QPtrList<Todo> todoCal;
3502 QPtrList<Todo> rootTodos; 3503 QPtrList<Todo> rootTodos;
3503 //QPtrList<Incidence> rel; 3504 //QPtrList<Incidence> rel;
3504 Todo *aTodo;//, *rTodo; 3505 Todo *aTodo;//, *rTodo;
3505 Incidence *rIncidence; 3506 Incidence *rIncidence;
3506 bool childDelete = false; 3507 bool childDelete = false;
3507 bool deletedOne = true; 3508 bool deletedOne = true;
3508 todoCal = calendar()->todos(); 3509 todoCal = calendar()->todos();
3509 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 3510 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
3510 if ( !aTodo->relatedTo() ) 3511 if ( !aTodo->relatedTo() )
3511 rootTodos.append( aTodo ); 3512 rootTodos.append( aTodo );
3512 } 3513 }
3513 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 3514 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
3514 removeCompletedSubTodos( aTodo ); 3515 removeCompletedSubTodos( aTodo );
3515 } 3516 }
3516 3517
3517 updateView(); 3518 updateView();
3518 } 3519 }
3519} 3520}
3520 3521
3521void CalendarView::slotCalendarChanged() 3522void CalendarView::slotCalendarChanged()
3522{ 3523{
3523 ; 3524 ;
3524} 3525}
3525 3526
3526NavigatorBar *CalendarView::navigatorBar() 3527NavigatorBar *CalendarView::navigatorBar()
3527{ 3528{
3528 return mNavigatorBar; 3529 return mNavigatorBar;
3529} 3530}
3530 3531
3531 3532
3532 3533
3533void CalendarView::keyPressEvent ( QKeyEvent *e) 3534void CalendarView::keyPressEvent ( QKeyEvent *e)
3534{ 3535{
3535 //qDebug(" alendarView::keyPressEvent "); 3536 //qDebug(" alendarView::keyPressEvent ");
3536 e->ignore(); 3537 e->ignore();
3537} 3538}
3538 3539
3539//#include "calendarview.moc" 3540//#include "calendarview.moc"
3540 3541
3541//#include "calendarviewbase.moc" 3542//#include "calendarviewbase.moc"
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6bbc0a3..6276498 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,1427 +1,1659 @@
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 "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
53 ; 53 ;
54 } 54 }
55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
56 { 56 {
57 57
58 int id = ToDo->Location; 58 int id = ToDo->Location;
59 Todo *todo; 59 Todo *todo;
60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
61 if (todo ) 61 if (todo )
62 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
63 else 63 else
64 todo = new Todo; 64 todo = new Todo;
65 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
67 int priority; 67 int priority;
68 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
69 case GSM_Priority_Low : priority = 5; break; 69 case GSM_Priority_Low : priority = 5; break;
70 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
71 case GSM_Priority_High : priority = 1; break; 71 case GSM_Priority_High : priority = 1; break;
72 default :priority = 3 ;break; 72 default :priority = 3 ;break;
73 } 73 }
74 todo->setPriority( priority ); 74 todo->setPriority( priority );
75 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
76 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
77 int j; 77 int j;
78 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
79 bool alarm = false; 79 bool alarm = false;
80 QDateTime alarmDt; 80 QDateTime alarmDt;
81 GSM_Category Category; 81 GSM_Category Category;
82 int error; 82 int error;
83 for (j=0;j<ToDo->EntriesNum;j++) { 83 for (j=0;j<ToDo->EntriesNum;j++) {
84 84
85 //qDebug(" for todo %d",ToDo->Location ); 85 //qDebug(" for todo %d",ToDo->Location );
86 switch (ToDo->Entries[j].EntryType) { 86 switch (ToDo->Entries[j].EntryType) {
87 case TODO_END_DATETIME: 87 case TODO_END_DATETIME:
88 dtp = &ToDo->Entries[j].Date ; 88 dtp = &ToDo->Entries[j].Date ;
89 todo->setDtDue (fromGSM ( dtp )); 89 todo->setDtDue (fromGSM ( dtp ));
90 break; 90 break;
91 case TODO_COMPLETED: 91 case TODO_COMPLETED:
92 if ( ToDo->Entries[j].Number == 1 ) { 92 if ( ToDo->Entries[j].Number == 1 ) {
93 todo->setCompleted( true ); 93 todo->setCompleted( true );
94 } 94 }
95 else { 95 else {
96 todo->setCompleted( false ); 96 todo->setCompleted( false );
97 } 97 }
98 break; 98 break;
99 case TODO_ALARM_DATETIME: 99 case TODO_ALARM_DATETIME:
100 dtp = &ToDo->Entries[j].Date ; 100 dtp = &ToDo->Entries[j].Date ;
101 alarm = true; 101 alarm = true;
102 alarmDt = fromGSM ( dtp ); 102 alarmDt = fromGSM ( dtp );
103 break; 103 break;
104 case TODO_SILENT_ALARM_DATETIME: 104 case TODO_SILENT_ALARM_DATETIME:
105 dtp = &ToDo->Entries[j].Date ; 105 dtp = &ToDo->Entries[j].Date ;
106 alarm = true; 106 alarm = true;
107 alarmDt = fromGSM ( dtp ); 107 alarmDt = fromGSM ( dtp );
108 break; 108 break;
109 case TODO_TEXT: 109 case TODO_TEXT:
110 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 110 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
111 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 111 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
112 break; 112 break;
113 case TODO_PRIVATE: 113 case TODO_PRIVATE:
114 if ( ToDo->Entries[j].Number == 1 ) 114 if ( ToDo->Entries[j].Number == 1 )
115 todo->setSecrecy( Incidence::SecrecyPrivate ); 115 todo->setSecrecy( Incidence::SecrecyPrivate );
116 else 116 else
117 todo->setSecrecy( Incidence::SecrecyPublic ); 117 todo->setSecrecy( Incidence::SecrecyPublic );
118 break; 118 break;
119 case TODO_CATEGORY: 119 case TODO_CATEGORY:
120 Category.Location = ToDo->Entries[j].Number; 120 Category.Location = ToDo->Entries[j].Number;
121 Category.Type = Category_ToDo; 121 Category.Type = Category_ToDo;
122 error=Phone->GetCategory(s, &Category); 122 error=Phone->GetCategory(s, &Category);
123 if (error == ERR_NONE) { 123 if (error == ERR_NONE) {
124 QStringList cat = todo->categories(); 124 QStringList cat = todo->categories();
125 QString nCat = QString ( (const char*)Category.Name ); 125 QString nCat = QString ( (const char*)Category.Name );
126 if ( !nCat.isEmpty() ) 126 if ( !nCat.isEmpty() )
127 if ( !cat.contains( nCat )) { 127 if ( !cat.contains( nCat )) {
128 cat << nCat; 128 cat << nCat;
129 todo->setCategories( cat ); 129 todo->setCategories( cat );
130 } 130 }
131 } 131 }
132 break; 132 break;
133 case TODO_CONTACTID: 133 case TODO_CONTACTID:
134#if 0 134#if 0
135 // not supported 135 // not supported
136 entry.Location = ToDo->Entries[j].Number; 136 entry.Location = ToDo->Entries[j].Number;
137 entry.MemoryType = MEM_ME; 137 entry.MemoryType = MEM_ME;
138 error=Phone->GetMemory(s, &entry); 138 error=Phone->GetMemory(s, &entry);
139 if (error == ERR_NONE) { 139 if (error == ERR_NONE) {
140 name = GSM_PhonebookGetEntryName(&entry); 140 name = GSM_PhonebookGetEntryName(&entry);
141 if (name != NULL) { 141 if (name != NULL) {
142 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); 142 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
143 } else { 143 } else {
144 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 144 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
145 } 145 }
146 } else { 146 } else {
147 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 147 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
148 } 148 }
149#endif 149#endif
150 break; 150 break;
151 case TODO_PHONE: 151 case TODO_PHONE:
152#if 0 152#if 0
153 // not supported 153 // not supported
154 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 154 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
155#endif 155#endif
156 break; 156 break;
157 } 157 }
158 } 158 }
159 QString alarmString = "na"; 159 QString alarmString = "na";
160 if ( alarm ) { 160 if ( alarm ) {
161 Alarm *alarm; 161 Alarm *alarm;
162 if ( todo->alarms().count() > 0 ) 162 if ( todo->alarms().count() > 0 )
163 alarm = todo->alarms().first(); 163 alarm = todo->alarms().first();
164 else { 164 else {
165 alarm = new Alarm( todo ); 165 alarm = new Alarm( todo );
166 todo->addAlarm( alarm ); 166 todo->addAlarm( alarm );
167 } 167 }
168 alarm->setType( Alarm::Audio ); 168 alarm->setType( Alarm::Audio );
169 alarm->setEnabled( true ); 169 alarm->setEnabled( true );
170 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 170 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
171 alarm->setStartOffset( -alarmOffset ); 171 alarm->setStartOffset( -alarmOffset );
172 alarmString = QString::number( alarmOffset ); 172 alarmString = QString::number( alarmOffset );
173 } else { 173 } else {
174 Alarm *alarm; 174 Alarm *alarm;
175 if ( todo->alarms().count() > 0 ) { 175 if ( todo->alarms().count() > 0 ) {
176 alarm = todo->alarms().first(); 176 alarm = todo->alarms().first();
177 alarm->setType( Alarm::Audio ); 177 alarm->setType( Alarm::Audio );
178 alarm->setStartOffset( -60*15 ); 178 alarm->setStartOffset( -60*15 );
179 alarm->setEnabled( false ); 179 alarm->setEnabled( false );
180 } 180 }
181 } 181 }
182 // csum ***************************************** 182 // csum *****************************************
183 uint cSum; 183 uint cSum;
184 cSum = PhoneFormat::getCsumTodo( todo ); 184 cSum = PhoneFormat::getCsumTodo( todo );
185 todo->setCsum( mProfileName, QString::number( cSum )); 185 todo->setCsum( mProfileName, QString::number( cSum ));
186 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 186 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
187 mCalendar->addTodo( todo); 187 mCalendar->addTodo( todo);
188 188
189 return true; 189 return true;
190 } 190 }
191 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 191 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
192 { 192 {
193 193
194 int id = Note->Location; 194 int id = Note->Location;
195 Event *event; 195 Event *event;
196 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 196 event = existingCalendar->event( mProfileName ,QString::number( id ) );
197 if ( event ) 197 if ( event )
198 event = (Event*)event->clone(); 198 event = (Event*)event->clone();
199 else 199 else
200 event = new Event; 200 event = new Event;
201 event->setID( mProfileName,QString::number( id ) ); 201 event->setID( mProfileName,QString::number( id ) );
202 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 202 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
203 203
204 204
205 int i = 0; 205 int i = 0;
206 bool repeating = false; 206 bool repeating = false;
207 int repeat_dayofweek = -1; 207 int repeat_dayofweek = -1;
208 int repeat_day = -1; 208 int repeat_day = -1;
209 int repeat_weekofmonth = -1; 209 int repeat_weekofmonth = -1;
210 int repeat_month = -1; 210 int repeat_month = -1;
211 int repeat_frequency = -1; 211 int repeat_frequency = -1;
212 int rec_type = -1; 212 int rec_type = -1;
213 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 213 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
214 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 214 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
215 GSM_DateTime* dtp; 215 GSM_DateTime* dtp;
216 bool alarm = false; 216 bool alarm = false;
217 QDateTime alarmDt; 217 QDateTime alarmDt;
218 repeat_startdate.Day= 0; 218 repeat_startdate.Day= 0;
219 repeat_stopdate.Day = 0; 219 repeat_stopdate.Day = 0;
220 for (i=0;i<Note->EntriesNum;i++) { 220 for (i=0;i<Note->EntriesNum;i++) {
221 221
222 //qDebug(" for ev"); 222 //qDebug(" for ev");
223 switch (Note->Entries[i].EntryType) { 223 switch (Note->Entries[i].EntryType) {
224 case CAL_START_DATETIME: 224 case CAL_START_DATETIME:
225 dtp = &Note->Entries[i].Date ; 225 dtp = &Note->Entries[i].Date ;
226 if ( dtp->Hour > 24 ) { 226 if ( dtp->Hour > 24 ) {
227 event->setFloats( true ); 227 event->setFloats( true );
228 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 228 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
229 } else { 229 } else {
230 event->setDtStart (fromGSM ( dtp )); 230 event->setDtStart (fromGSM ( dtp ));
231 231
232 } 232 }
233 //Note->Entries[i].Date.Hour = 5; 233 //Note->Entries[i].Date.Hour = 5;
234 break; 234 break;
235 case CAL_END_DATETIME: 235 case CAL_END_DATETIME:
236 dtp = &Note->Entries[i].Date ; 236 dtp = &Note->Entries[i].Date ;
237 if ( dtp->Hour > 24 ) { 237 if ( dtp->Hour > 24 ) {
238 event->setFloats( true ); 238 event->setFloats( true );
239 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 239 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
240 } else { 240 } else {
241 event->setDtEnd (fromGSM ( dtp )); 241 event->setDtEnd (fromGSM ( dtp ));
242 } 242 }
243 break; 243 break;
244 case CAL_ALARM_DATETIME: 244 case CAL_ALARM_DATETIME:
245 dtp = &Note->Entries[i].Date ; 245 dtp = &Note->Entries[i].Date ;
246 alarm = true; 246 alarm = true;
247 alarmDt = fromGSM ( dtp ); 247 alarmDt = fromGSM ( dtp );
248 break; 248 break;
249 case CAL_SILENT_ALARM_DATETIME: 249 case CAL_SILENT_ALARM_DATETIME:
250 dtp = &Note->Entries[i].Date ; 250 dtp = &Note->Entries[i].Date ;
251 alarm = true; 251 alarm = true;
252 alarmDt = fromGSM ( dtp ); 252 alarmDt = fromGSM ( dtp );
253 break; 253 break;
254 case CAL_RECURRANCE: 254 case CAL_RECURRANCE:
255 rec_type = Note->Entries[i].Number; 255 rec_type = Note->Entries[i].Number;
256 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 256 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
257 break; 257 break;
258 case CAL_TEXT: 258 case CAL_TEXT:
259 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); 259 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
260 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); 260 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
261 break; 261 break;
262 case CAL_LOCATION: 262 case CAL_LOCATION:
263 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); 263 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
264 break; 264 break;
265 case CAL_PHONE: 265 case CAL_PHONE:
266 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 266 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
267 break; 267 break;
268 case CAL_PRIVATE: 268 case CAL_PRIVATE:
269 if ( Note->Entries[i].Number == 1 ) 269 if ( Note->Entries[i].Number == 1 )
270 event->setSecrecy( Incidence::SecrecyPrivate ); 270 event->setSecrecy( Incidence::SecrecyPrivate );
271 else 271 else
272 event->setSecrecy( Incidence::SecrecyPublic ); 272 event->setSecrecy( Incidence::SecrecyPublic );
273 273
274 break; 274 break;
275 case CAL_CONTACTID: 275 case CAL_CONTACTID:
276#if 0 276#if 0
277 entry.Location = Note->Entries[i].Number; 277 entry.Location = Note->Entries[i].Number;
278 entry.MemoryType = MEM_ME; 278 entry.MemoryType = MEM_ME;
279 error=Phone->GetMemory(&s, &entry); 279 error=Phone->GetMemory(&s, &entry);
280 if (error == ERR_NONE) { 280 if (error == ERR_NONE) {
281 name = GSM_PhonebookGetEntryName(&entry); 281 name = GSM_PhonebookGetEntryName(&entry);
282 if (name != NULL) { 282 if (name != NULL) {
283 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 283 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
284 } else { 284 } else {
285 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 285 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
286 } 286 }
287 } else { 287 } else {
288 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 288 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
289 } 289 }
290#endif 290#endif
291 break; 291 break;
292 case CAL_REPEAT_DAYOFWEEK: 292 case CAL_REPEAT_DAYOFWEEK:
293 repeat_dayofweek = Note->Entries[i].Number; 293 repeat_dayofweek = Note->Entries[i].Number;
294 repeating = true; 294 repeating = true;
295 break; 295 break;
296 case CAL_REPEAT_DAY: 296 case CAL_REPEAT_DAY:
297 repeat_day = Note->Entries[i].Number; 297 repeat_day = Note->Entries[i].Number;
298 repeating = true; 298 repeating = true;
299 break; 299 break;
300 case CAL_REPEAT_WEEKOFMONTH: 300 case CAL_REPEAT_WEEKOFMONTH:
301 repeat_weekofmonth = Note->Entries[i].Number; 301 repeat_weekofmonth = Note->Entries[i].Number;
302 repeating = true; 302 repeating = true;
303 break; 303 break;
304 case CAL_REPEAT_MONTH: 304 case CAL_REPEAT_MONTH:
305 repeat_month = Note->Entries[i].Number; 305 repeat_month = Note->Entries[i].Number;
306 repeating = true; 306 repeating = true;
307 break; 307 break;
308 case CAL_REPEAT_FREQUENCY: 308 case CAL_REPEAT_FREQUENCY:
309 repeat_frequency = Note->Entries[i].Number; 309 repeat_frequency = Note->Entries[i].Number;
310 repeating = true; 310 repeating = true;
311 break; 311 break;
312 case CAL_REPEAT_STARTDATE: 312 case CAL_REPEAT_STARTDATE:
313 repeat_startdate = Note->Entries[i].Date; 313 repeat_startdate = Note->Entries[i].Date;
314 repeating = true; 314 repeating = true;
315 break; 315 break;
316 case CAL_REPEAT_STOPDATE: 316 case CAL_REPEAT_STOPDATE:
317 repeat_stopdate = Note->Entries[i].Date; 317 repeat_stopdate = Note->Entries[i].Date;
318 repeating = true; 318 repeating = true;
319 break; 319 break;
320 } 320 }
321 } 321 }
322#if 0 322#if 0
323 event->setDescription( attList[4] ); 323 event->setDescription( attList[4] );
324 bool repeating = false; 324 bool repeating = false;
325 int repeat_dayofweek = -1; 325 int repeat_dayofweek = -1;
326 int repeat_day = -1; 326 int repeat_day = -1;
327 int repeat_weekofmonth = -1; 327 int repeat_weekofmonth = -1;
328 int repeat_month = -1; 328 int repeat_month = -1;
329 int repeat_frequency = -1; 329 int repeat_frequency = -1;
330 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 330 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
331 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 331 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
332 332
333#endif 333#endif
334 334
335 QString recurString = "no"; 335 QString recurString = "no";
336 if ( repeating && repeat_frequency != -1) { 336 if ( repeating && repeat_frequency != -1) {
337 recurString = "y"; 337 recurString = "y";
338 if ( repeat_dayofweek >= 0 ) 338 if ( repeat_dayofweek >= 0 )
339 recurString += "dow" + QString::number (repeat_dayofweek); 339 recurString += "dow" + QString::number (repeat_dayofweek);
340 if ( repeat_day >= 0 ) 340 if ( repeat_day >= 0 )
341 recurString += "d" + QString::number (repeat_day); 341 recurString += "d" + QString::number (repeat_day);
342 if ( repeat_weekofmonth >= 0 ) 342 if ( repeat_weekofmonth >= 0 )
343 recurString += "w" + QString::number (repeat_weekofmonth); 343 recurString += "w" + QString::number (repeat_weekofmonth);
344 if ( repeat_month >= 0 ) 344 if ( repeat_month >= 0 )
345 recurString += "m" + QString::number ( repeat_month ); 345 recurString += "m" + QString::number ( repeat_month );
346 if ( repeat_frequency >= 0 ) 346 if ( repeat_frequency >= 0 )
347 recurString += "f" + QString::number (repeat_frequency ); 347 recurString += "f" + QString::number (repeat_frequency );
348 348
349 int rtype = 0; 349 int rtype = 0;
350 // qDebug("recurs "); 350 // qDebug("recurs ");
351 QDate startDate, endDate; 351 QDate startDate, endDate;
352 if ( repeat_startdate.Day > 0 ) { 352 if ( repeat_startdate.Day > 0 ) {
353 startDate = datefromGSM ( &repeat_startdate ); 353 startDate = datefromGSM ( &repeat_startdate );
354 event->setDtStart(QDateTime ( startDate, event->dtStart().time())); 354 event->setDtStart(QDateTime ( startDate, event->dtStart().time()));
355 } else { 355 } else {
356 startDate = event->dtStart().date(); 356 startDate = event->dtStart().date();
357 } 357 }
358 int freq = repeat_frequency; 358 int freq = repeat_frequency;
359 bool hasEndDate = false; 359 bool hasEndDate = false;
360 if ( repeat_stopdate.Day > 0 ) { 360 if ( repeat_stopdate.Day > 0 ) {
361 endDate = datefromGSM ( &repeat_stopdate ); 361 endDate = datefromGSM ( &repeat_stopdate );
362 hasEndDate = true; 362 hasEndDate = true;
363 } 363 }
364 364
365 uint weekDaysNum = repeat_dayofweek ; 365 uint weekDaysNum = repeat_dayofweek ;
366 // 1 == monday, 7 == sunday 366 // 1 == monday, 7 == sunday
367 QBitArray weekDays( 7 ); 367 QBitArray weekDays( 7 );
368 int i; 368 int i;
369 int bb = 1; 369 int bb = 1;
370 for( i = 1; i <= 7; ++i ) { 370 for( i = 1; i <= 7; ++i ) {
371 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 371 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
372 bb = 2 << (i-1); 372 bb = 2 << (i-1);
373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
374 } 374 }
375 // qDebug("next "); 375 // qDebug("next ");
376 int pos = 0; 376 int pos = 0;
377 Recurrence *r = event->recurrence(); 377 Recurrence *r = event->recurrence();
378 /* 378 /*
379 0 daily; 379 0 daily;
380 1 weekly;x 380 1 weekly;x
381 2 monthpos;x 381 2 monthpos;x
382 3 monthlyday; 382 3 monthlyday;
383 4 rYearlyMont 383 4 rYearlyMont
384 bool repeating = false; 384 bool repeating = false;
385 int repeat_dayofweek = -1; 385 int repeat_dayofweek = -1;
386 int repeat_day = -1; 386 int repeat_day = -1;
387 int repeat_weekofmonth = -1; 387 int repeat_weekofmonth = -1;
388 int repeat_month = -1; 388 int repeat_month = -1;
389 int repeat_frequency = -1; 389 int repeat_frequency = -1;
390 */ 390 */
391 int dayOfWeek = startDate.dayOfWeek(); 391 int dayOfWeek = startDate.dayOfWeek();
392 if ( repeat_weekofmonth >= 0 ) { 392 if ( repeat_weekofmonth >= 0 ) {
393 rtype = 2; // ************************ 2 MonthlyPos 393 rtype = 2; // ************************ 2 MonthlyPos
394 pos = repeat_weekofmonth; 394 pos = repeat_weekofmonth;
395 if ( repeat_dayofweek >= 0 ) 395 if ( repeat_dayofweek >= 0 )
396 dayOfWeek = repeat_dayofweek; 396 dayOfWeek = repeat_dayofweek;
397 if (repeat_month > 0) { 397 if (repeat_month > 0) {
398 if ( repeat_month != event->dtStart().date().month() ) { 398 if ( repeat_month != event->dtStart().date().month() ) {
399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); 399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() );
400 event->setDtStart(QDateTime ( date , event->dtStart().time()) ); 400 event->setDtStart(QDateTime ( date , event->dtStart().time()) );
401 } 401 }
402 if ( freq == 1 ) 402 if ( freq == 1 )
403 freq = 12; 403 freq = 12;
404 } 404 }
405 } else if ( repeat_dayofweek >= 0 ) { 405 } else if ( repeat_dayofweek >= 0 ) {
406 rtype = 1;// ************************ 1 Weekly 406 rtype = 1;// ************************ 1 Weekly
407 } else if ( repeat_day >= 0 ) { 407 } else if ( repeat_day >= 0 ) {
408 if ( repeat_month > 0) { 408 if ( repeat_month > 0) {
409 rtype = 4; 409 rtype = 4;
410 } else { 410 } else {
411 rtype = 3; 411 rtype = 3;
412 } 412 }
413 } else { 413 } else {
414 rtype = 0 ; 414 rtype = 0 ;
415 } 415 }
416 416
417 if ( rtype == 0 ) { 417 if ( rtype == 0 ) {
418 if ( hasEndDate ) r->setDaily( freq, endDate ); 418 if ( hasEndDate ) r->setDaily( freq, endDate );
419 else r->setDaily( freq, -1 ); 419 else r->setDaily( freq, -1 );
420 } else if ( rtype == 1 ) { 420 } else if ( rtype == 1 ) {
421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
422 else r->setWeekly( freq, weekDays, -1 ); 422 else r->setWeekly( freq, weekDays, -1 );
423 } else if ( rtype == 3 ) { 423 } else if ( rtype == 3 ) {
424 if ( hasEndDate ) 424 if ( hasEndDate )
425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
426 else 426 else
427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
428 r->addMonthlyDay( startDate.day() ); 428 r->addMonthlyDay( startDate.day() );
429 } else if ( rtype == 2 ) { 429 } else if ( rtype == 2 ) {
430 if ( hasEndDate ) 430 if ( hasEndDate )
431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
432 else 432 else
433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
434 QBitArray days( 7 ); 434 QBitArray days( 7 );
435 days.fill( false ); 435 days.fill( false );
436 days.setBit( dayOfWeek - 1 ); 436 days.setBit( dayOfWeek - 1 );
437 r->addMonthlyPos( pos, days ); 437 r->addMonthlyPos( pos, days );
438 } else if ( rtype == 4 ) { 438 } else if ( rtype == 4 ) {
439 if ( hasEndDate ) 439 if ( hasEndDate )
440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
441 else 441 else
442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
443 r->addYearlyNum( startDate.month() ); 443 r->addYearlyNum( startDate.month() );
444 } 444 }
445 } else { 445 } else {
446 event->recurrence()->unsetRecurs(); 446 event->recurrence()->unsetRecurs();
447 } 447 }
448 448
449 QStringList categoryList; 449 QStringList categoryList;
450 categoryList << getCategory( Note ); 450 categoryList << getCategory( Note );
451 event->setCategories( categoryList ); 451 event->setCategories( categoryList );
452 // strange 0 semms to mean: alarm enabled 452 // strange 0 semms to mean: alarm enabled
453 if ( alarm ) { 453 if ( alarm ) {
454 Alarm *alarm; 454 Alarm *alarm;
455 if ( event->alarms().count() > 0 ) 455 if ( event->alarms().count() > 0 )
456 alarm = event->alarms().first(); 456 alarm = event->alarms().first();
457 else { 457 else {
458 alarm = new Alarm( event ); 458 alarm = new Alarm( event );
459 event->addAlarm( alarm ); 459 event->addAlarm( alarm );
460 } 460 }
461 alarm->setType( Alarm::Audio ); 461 alarm->setType( Alarm::Audio );
462 alarm->setEnabled( true ); 462 alarm->setEnabled( true );
463 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 463 int alarmOffset = alarmDt.secsTo( event->dtStart() );
464 alarm->setStartOffset( -alarmOffset ); 464 alarm->setStartOffset( -alarmOffset );
465 } else { 465 } else {
466 Alarm *alarm; 466 Alarm *alarm;
467 if ( event->alarms().count() > 0 ) { 467 if ( event->alarms().count() > 0 ) {
468 alarm = event->alarms().first(); 468 alarm = event->alarms().first();
469 alarm->setType( Alarm::Audio ); 469 alarm->setType( Alarm::Audio );
470 alarm->setStartOffset( -60*15 ); 470 alarm->setStartOffset( -60*15 );
471 alarm->setEnabled( false ); 471 alarm->setEnabled( false );
472 } 472 }
473 } 473 }
474 // csum ***************************************** 474 // csum *****************************************
475 475
476 uint cSum; 476 uint cSum;
477 cSum = PhoneFormat::getCsumEvent( event ); 477 cSum = PhoneFormat::getCsumEvent( event );
478 event->setCsum( mProfileName, QString::number( cSum )); 478 event->setCsum( mProfileName, QString::number( cSum ));
479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
480 mCalendar->addEvent( event); 480 mCalendar->addEvent( event);
481 481
482 return true; 482 return true;
483 } 483 }
484 484
485 485
486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) {
487 QDateTime dt; 487 QDateTime dt;
488 int y,m,t,h,min,sec; 488 int y,m,t,h,min,sec;
489 y = dtp->Year; 489 y = dtp->Year;
490 m = dtp->Month; 490 m = dtp->Month;
491 t = dtp->Day; 491 t = dtp->Day;
492 h = dtp->Hour; 492 h = dtp->Hour;
493 min = dtp->Minute; 493 min = dtp->Minute;
494 sec = dtp->Second; 494 sec = dtp->Second;
495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
496 // dtp->Timezone: offset in hours 496 // dtp->Timezone: offset in hours
497 int offset = KGlobal::locale()->localTimeOffset( dt ); 497 int offset = KGlobal::locale()->localTimeOffset( dt );
498 if ( useTz ) 498 if ( useTz )
499 dt = dt.addSecs ( offset*60); 499 dt = dt.addSecs ( offset*60);
500 return dt; 500 return dt;
501 501
502 } 502 }
503 503
504 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 504 static QString dtToString( const QDateTime& dti, bool useTZ = false )
505 { 505 {
506 QString datestr; 506 QString datestr;
507 QString timestr; 507 QString timestr;
508 int offset = KGlobal::locale()->localTimeOffset( dti ); 508 int offset = KGlobal::locale()->localTimeOffset( dti );
509 QDateTime dt; 509 QDateTime dt;
510 if (useTZ) 510 if (useTZ)
511 dt = dti.addSecs ( -(offset*60)); 511 dt = dti.addSecs ( -(offset*60));
512 else 512 else
513 dt = dti; 513 dt = dti;
514 if(dt.date().isValid()){ 514 if(dt.date().isValid()){
515 const QDate& date = dt.date(); 515 const QDate& date = dt.date();
516 datestr.sprintf("%04d%02d%02d", 516 datestr.sprintf("%04d%02d%02d",
517 date.year(), date.month(), date.day()); 517 date.year(), date.month(), date.day());
518 } 518 }
519 if(dt.time().isValid()){ 519 if(dt.time().isValid()){
520 const QTime& time = dt.time(); 520 const QTime& time = dt.time();
521 timestr.sprintf("T%02d%02d%02d", 521 timestr.sprintf("T%02d%02d%02d",
522 time.hour(), time.minute(), time.second()); 522 time.hour(), time.minute(), time.second());
523 } 523 }
524 return datestr + timestr; 524 return datestr + timestr;
525 } 525 }
526 QDate datefromGSM ( GSM_DateTime*dtp ) { 526 QDate datefromGSM ( GSM_DateTime*dtp ) {
527 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 527 return QDate ( dtp->Year, dtp->Month, dtp->Day );
528 } 528 }
529 QString getCategory( GSM_CalendarEntry*Note) 529 QString getCategory( GSM_CalendarEntry*Note)
530 { 530 {
531 QString CATEGORY; 531 QString CATEGORY;
532 switch (Note->Type) { 532 switch (Note->Type) {
533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
561 default : CATEGORY = QString(""); 561 default : CATEGORY = QString("");
562 } 562 }
563 563
564 return CATEGORY; 564 return CATEGORY;
565 } 565 }
566 566
567protected: 567protected:
568private: 568private:
569 Calendar *mCalendar; 569 Calendar *mCalendar;
570 QString mProfileName ; 570 QString mProfileName ;
571}; 571};
572 572
573 573
574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
575{ 575{
576 mProfileName = profileName; 576 mProfileName = profileName;
577 mDevice = device; 577 mDevice = device;
578 mConnection = connection; 578 mConnection = connection;
579 mModel = model; 579 mModel = model;
580} 580}
581 581
582PhoneFormat::~PhoneFormat() 582PhoneFormat::~PhoneFormat()
583{ 583{
584} 584}
585int PhoneFormat::initDevice(GSM_StateMachine *s) 585int PhoneFormat::initDevice(GSM_StateMachine *s)
586{ 586{
587 GSM_ReadConfig(NULL, &s->Config[0], 0); 587 GSM_ReadConfig(NULL, &s->Config[0], 0);
588 s->ConfigNum = 1; 588 s->ConfigNum = 1;
589 GSM_Config *cfg = &s->Config[0]; 589 GSM_Config *cfg = &s->Config[0];
590 if ( ! mConnection.isEmpty() ) { 590 if ( ! mConnection.isEmpty() ) {
591 cfg->Connection = strdup(mConnection.latin1()); 591 cfg->Connection = strdup(mConnection.latin1());
592 cfg->DefaultConnection = false; 592 cfg->DefaultConnection = false;
593 qDebug("Connection set %s ", cfg->Connection ); 593 qDebug("Connection set %s ", cfg->Connection );
594 594
595 } 595 }
596 if ( ! mDevice.isEmpty() ) { 596 if ( ! mDevice.isEmpty() ) {
597 cfg->Device = strdup(mDevice.latin1()); 597 cfg->Device = strdup(mDevice.latin1());
598 cfg->DefaultDevice = false; 598 cfg->DefaultDevice = false;
599 qDebug("Device set %s ", cfg->Device); 599 qDebug("Device set %s ", cfg->Device);
600 600
601 } 601 }
602 if ( ! mModel.isEmpty() ) { 602 if ( ! mModel.isEmpty() ) {
603 strcpy(cfg->Model,mModel.latin1() ); 603 strcpy(cfg->Model,mModel.latin1() );
604 cfg->DefaultModel = false; 604 cfg->DefaultModel = false;
605 qDebug("Model set %s ",cfg->Model ); 605 qDebug("Model set %s ",cfg->Model );
606 } 606 }
607 int error=GSM_InitConnection(s,3); 607 int error=GSM_InitConnection(s,3);
608 return error; 608 return error;
609} 609}
610ulong PhoneFormat::getCsumTodo( Todo* todo ) 610ulong PhoneFormat::getCsumTodo( Todo* todo )
611{ 611{
612 QStringList attList; 612 QStringList attList;
613 if ( todo->hasDueDate() ) 613 if ( todo->hasDueDate() )
614 attList << PhoneParser::dtToString ( todo->dtDue() ); 614 attList << PhoneParser::dtToString ( todo->dtDue() );
615 attList << todo->summary(); 615 attList << todo->summary();
616 QString completedString = "no"; 616 QString completedString = "no";
617 if ( todo->isCompleted() ) 617 if ( todo->isCompleted() )
618 completedString = "yes"; 618 completedString = "yes";
619 attList << completedString; 619 attList << completedString;
620 attList << QString::number( todo->priority() ); 620 attList << QString::number( todo->priority() );
621 QString alarmString = "na"; 621 QString alarmString = "na";
622 Alarm *alarm; 622 Alarm *alarm;
623 if ( todo->alarms().count() > 0 ) { 623 if ( todo->alarms().count() > 0 ) {
624 alarm = todo->alarms().first(); 624 alarm = todo->alarms().first();
625 if ( alarm->enabled() ) { 625 if ( alarm->enabled() ) {
626 alarmString = QString::number(alarm->startOffset().asSeconds() ); 626 alarmString = QString::number(alarm->startOffset().asSeconds() );
627 } 627 }
628 } 628 }
629 attList << alarmString; 629 attList << alarmString;
630 attList << todo->categoriesStr(); 630 attList << todo->categoriesStr();
631 attList << todo->secrecyStr(); 631 attList << todo->secrecyStr();
632 return PhoneFormat::getCsum(attList ); 632 return PhoneFormat::getCsum(attList );
633 633
634} 634}
635ulong PhoneFormat::getCsumEvent( Event* event ) 635ulong PhoneFormat::getCsumEvent( Event* event )
636{ 636{
637 QStringList attList; 637 QStringList attList;
638 attList << PhoneParser::dtToString ( event->dtStart() ); 638 attList << PhoneParser::dtToString ( event->dtStart() );
639 attList << PhoneParser::dtToString ( event->dtEnd() ); 639 attList << PhoneParser::dtToString ( event->dtEnd() );
640 attList << event->summary(); 640 attList << event->summary();
641 attList << event->location(); 641 attList << event->location();
642 QString alarmString = "na"; 642 QString alarmString = "na";
643 Alarm *alarm; 643 Alarm *alarm;
644 if ( event->alarms().count() > 0 ) { 644 if ( event->alarms().count() > 0 ) {
645 alarm = event->alarms().first(); 645 alarm = event->alarms().first();
646 if ( alarm->enabled() ) { 646 if ( alarm->enabled() ) {
647 alarmString = QString::number( alarm->startOffset().asSeconds() ); 647 alarmString = QString::number( alarm->startOffset().asSeconds() );
648 } 648 }
649 } 649 }
650 attList << alarmString; 650 attList << alarmString;
651 Recurrence* rec = event->recurrence(); 651 Recurrence* rec = event->recurrence();
652 QStringList list; 652 QStringList list;
653 bool writeEndDate = false; 653 bool writeEndDate = false;
654 switch ( rec->doesRecur() ) 654 switch ( rec->doesRecur() )
655 { 655 {
656 case Recurrence::rDaily: // 0 656 case Recurrence::rDaily: // 0
657 list.append( "0" ); 657 list.append( "0" );
658 list.append( QString::number( rec->frequency() ));//12 658 list.append( QString::number( rec->frequency() ));//12
659 list.append( "0" ); 659 list.append( "0" );
660 list.append( "0" ); 660 list.append( "0" );
661 writeEndDate = true; 661 writeEndDate = true;
662 break; 662 break;
663 case Recurrence::rWeekly:// 1 663 case Recurrence::rWeekly:// 1
664 list.append( "1" ); 664 list.append( "1" );
665 list.append( QString::number( rec->frequency()) );//12 665 list.append( QString::number( rec->frequency()) );//12
666 list.append( "0" ); 666 list.append( "0" );
667 { 667 {
668 int days = 0; 668 int days = 0;
669 QBitArray weekDays = rec->days(); 669 QBitArray weekDays = rec->days();
670 int i; 670 int i;
671 for( i = 1; i <= 7; ++i ) { 671 for( i = 1; i <= 7; ++i ) {
672 if ( weekDays[i-1] ) { 672 if ( weekDays[i-1] ) {
673 days += 1 << (i-1); 673 days += 1 << (i-1);
674 } 674 }
675 } 675 }
676 list.append( QString::number( days ) ); 676 list.append( QString::number( days ) );
677 } 677 }
678 //pending weekdays 678 //pending weekdays
679 writeEndDate = true; 679 writeEndDate = true;
680 680
681 break; 681 break;
682 case Recurrence::rMonthlyPos:// 2 682 case Recurrence::rMonthlyPos:// 2
683 list.append( "2" ); 683 list.append( "2" );
684 list.append( QString::number( rec->frequency()) );//12 684 list.append( QString::number( rec->frequency()) );//12
685 685
686 writeEndDate = true; 686 writeEndDate = true;
687 { 687 {
688 int count = 1; 688 int count = 1;
689 QPtrList<Recurrence::rMonthPos> rmp; 689 QPtrList<Recurrence::rMonthPos> rmp;
690 rmp = rec->monthPositions(); 690 rmp = rec->monthPositions();
691 if ( rmp.first()->negative ) 691 if ( rmp.first()->negative )
692 count = 5 - rmp.first()->rPos - 1; 692 count = 5 - rmp.first()->rPos - 1;
693 else 693 else
694 count = rmp.first()->rPos - 1; 694 count = rmp.first()->rPos - 1;
695 list.append( QString::number( count ) ); 695 list.append( QString::number( count ) );
696 696
697 } 697 }
698 698
699 list.append( "0" ); 699 list.append( "0" );
700 break; 700 break;
701 case Recurrence::rMonthlyDay:// 3 701 case Recurrence::rMonthlyDay:// 3
702 list.append( "3" ); 702 list.append( "3" );
703 list.append( QString::number( rec->frequency()) );//12 703 list.append( QString::number( rec->frequency()) );//12
704 list.append( "0" ); 704 list.append( "0" );
705 list.append( "0" ); 705 list.append( "0" );
706 writeEndDate = true; 706 writeEndDate = true;
707 break; 707 break;
708 case Recurrence::rYearlyMonth://4 708 case Recurrence::rYearlyMonth://4
709 list.append( "4" ); 709 list.append( "4" );
710 list.append( QString::number( rec->frequency()) );//12 710 list.append( QString::number( rec->frequency()) );//12
711 list.append( "0" ); 711 list.append( "0" );
712 list.append( "0" ); 712 list.append( "0" );
713 writeEndDate = true; 713 writeEndDate = true;
714 break; 714 break;
715 715
716 default: 716 default:
717 list.append( "255" ); 717 list.append( "255" );
718 list.append( QString() ); 718 list.append( QString() );
719 list.append( "0" ); 719 list.append( "0" );
720 list.append( QString() ); 720 list.append( QString() );
721 list.append( "0" ); 721 list.append( "0" );
722 list.append( "20991231T000000" ); 722 list.append( "20991231T000000" );
723 break; 723 break;
724 } 724 }
725 if ( writeEndDate ) { 725 if ( writeEndDate ) {
726 726
727 if ( rec->endDate().isValid() ) { // 15 + 16 727 if ( rec->endDate().isValid() ) { // 15 + 16
728 list.append( "1" ); 728 list.append( "1" );
729 list.append( PhoneParser::dtToString( rec->endDate()) ); 729 list.append( PhoneParser::dtToString( rec->endDate()) );
730 } else { 730 } else {
731 list.append( "0" ); 731 list.append( "0" );
732 list.append( "20991231T000000" ); 732 list.append( "20991231T000000" );
733 } 733 }
734 734
735 } 735 }
736 attList << list.join(""); 736 attList << list.join("");
737 attList << event->categoriesStr(); 737 attList << event->categoriesStr();
738 attList << event->secrecyStr(); 738 attList << event->secrecyStr();
739 return PhoneFormat::getCsum(attList ); 739 return PhoneFormat::getCsum(attList );
740} 740}
741ulong PhoneFormat::getCsum( const QStringList & attList) 741ulong PhoneFormat::getCsum( const QStringList & attList)
742{ 742{
743 int max = attList.count() -1; 743 int max = attList.count() -1;
744 ulong cSum = 0; 744 ulong cSum = 0;
745 int j,k,i; 745 int j,k,i;
746 int add; 746 int add;
747 for ( i = 1; i < max ; ++i ) { 747 for ( i = 1; i < max ; ++i ) {
748 QString s = attList[i]; 748 QString s = attList[i];
749 if ( ! s.isEmpty() ){ 749 if ( ! s.isEmpty() ){
750 j = s.length(); 750 j = s.length();
751 for ( k = 0; k < j; ++k ) { 751 for ( k = 0; k < j; ++k ) {
752 int mul = k +1; 752 int mul = k +1;
753 add = s[k].unicode (); 753 add = s[k].unicode ();
754 if ( k < 16 ) 754 if ( k < 16 )
755 mul = mul * mul; 755 mul = mul * mul;
756 add = add * mul *i*i*i; 756 add = add * mul *i*i*i;
757 cSum += add; 757 cSum += add;
758 } 758 }
759 } 759 }
760 } 760 }
761 return cSum; 761 return cSum;
762 762
763} 763}
764//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 764//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
765#include <stdlib.h> 765#include <stdlib.h>
766#define DEBUGMODE false 766#define DEBUGMODE false
767bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 767bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
768{ 768{
769 GSM_StateMachines; 769 GSM_StateMachines;
770 qDebug(" load "); 770 qDebug(" load ");
771 s.opened = false; 771 s.opened = false;
772 s.msg = NULL; 772 s.msg = NULL;
773 s.ConfigNum = 0; 773 s.ConfigNum = 0;
774 QLabel status ( i18n("Opening device ..."), 0 ); 774 QLabel status ( i18n("Opening device ..."), 0 );
775 int w = status.sizeHint().width()+20 ; 775 int w = status.sizeHint().width()+20 ;
776 if ( w < 200 ) w = 230; 776 if ( w < 200 ) w = 230;
777 int h = status.sizeHint().height()+20 ; 777 int h = status.sizeHint().height()+20 ;
778 int dw = QApplication::desktop()->width(); 778 int dw = QApplication::desktop()->width();
779 int dh = QApplication::desktop()->height(); 779 int dh = QApplication::desktop()->height();
780 status.setCaption(i18n("Reading phone...") ); 780 status.setCaption(i18n("Reading phone...") );
781 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 781 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
782 status.show(); 782 status.show();
783 status.raise(); 783 status.raise();
784 qApp->processEvents(); 784 qApp->processEvents();
785#if 0
786 static char*cp;
787 static INI_Section *cfg = NULL;
788 cfg=GSM_FindGammuRC();
789 int i;
790 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
791 if (cfg!=NULL) {
792 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
793 if (cp) di.coding = cp;
794
795 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
796 if (s.Config[i].Localize) {
797 s.msg=INI_ReadFile(s.Config[i].Localize, true);
798 } else {
799#if !defined(WIN32) && defined(LOCALE_PATH)
800 locale = setlocale(LC_MESSAGES, NULL);
801 if (locale != NULL) {
802 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
803 LOCALE_PATH,
804 tolower(locale[0]),
805 tolower(locale[1]));
806 s.msg = INI_ReadFile(locale_file, true);
807 }
808#endif
809 }
810 }
811
812 /* Wanted user specific configuration? */
813
814 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
815
816 s.ConfigNum++;
817
818 /* We want to use only one file descriptor for global and state machine debug output */
819 s.Config[i].UseGlobalDebugFile = true;
820
821
822 785
823 /* We wanted to read just user specified configuration. */
824 {break;}
825 }
826
827#endif
828 int error=initDevice(&s); 786 int error=initDevice(&s);
829 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 787 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
830 if ( error != ERR_NONE ) 788 if ( error != ERR_NONE )
831 return false; 789 return false;
832 GSM_Phone_Functions*Phone; 790 GSM_Phone_Functions*Phone;
833 GSM_CalendarEntrynote; 791 GSM_CalendarEntrynote;
834 bool start = true; 792 bool start = true;
835 Phone=s.Phone.Functions; 793 Phone=s.Phone.Functions;
836 bool gshutdown = false; 794 bool gshutdown = false;
837 PhoneParser handler( calendar, mProfileName ); 795 PhoneParser handler( calendar, mProfileName );
838 int ccc = 0; 796 int ccc = 0;
839 QString message = i18n(" Reading event # "); 797 QString message = i18n(" Reading event # ");
840 int procCount = 0; 798 int procCount = 0;
841 qDebug("Debug: only 10 calender items are downloaded "); 799 qDebug("Debug: only 10 calender items are downloaded ");
842 while (!gshutdown && ccc++ < 10) { 800 while (!gshutdown && ccc++ < 10) {
843 status.setText ( message + QString::number ( ++procCount ) ); 801 status.setText ( message + QString::number ( ++procCount ) );
844 qApp->processEvents(); 802 qApp->processEvents();
845 qDebug("readEvent %d ", ccc); 803 qDebug("readEvent %d ", ccc);
846 error=Phone->GetNextCalendar(&s,&note,start); 804 error=Phone->GetNextCalendar(&s,&note,start);
847 if (error == ERR_EMPTY) break; 805 if (error == ERR_EMPTY) break;
848 start = false; 806 start = false;
849 handler.readEvent( existingCal, &note ); 807 handler.readEvent( existingCal, &note );
850 qDebug("Org loc %d ",note.Location); 808 qDebug("Org loc %d ",note.Location);
851 //note.Location = 0; 809 //note.Location = 0;
852 error=Phone->SetCalendar(&s,&note); 810 error=Phone->SetCalendar(&s,&note);
853 qDebug("new loc %d ",note.Location); 811 qDebug("new loc %d ",note.Location);
854 } 812 }
855 813
856 start = true; 814 start = true;
857 GSM_ToDoEntry ToDo; 815 GSM_ToDoEntry ToDo;
858 ccc = 0; 816 ccc = 0;
859 message = i18n(" Reading todo # "); 817 message = i18n(" Reading todo # ");
860 procCount = 0; 818 procCount = 0;
861 while (!gshutdown && ccc++ < 10) { 819 while (!gshutdown && ccc++ < 10) {
862 status.setText ( message + QString::number ( ++procCount ) ); 820 status.setText ( message + QString::number ( ++procCount ) );
863 qApp->processEvents(); 821 qApp->processEvents();
864 error = Phone->GetNextToDo(&s, &ToDo, start); 822 error = Phone->GetNextToDo(&s, &ToDo, start);
865 if (error == ERR_EMPTY) break; 823 if (error == ERR_EMPTY) break;
866 start = false; 824 start = false;
867 qDebug("ReadTodo %d ", ccc); 825 qDebug("ReadTodo %d ", ccc);
868 handler.readTodo( existingCal, &ToDo, &s); 826 handler.readTodo( existingCal, &ToDo, &s);
869 827
870 } 828 }
871 829
872 error=GSM_TerminateConnection(&s); 830 error=GSM_TerminateConnection(&s);
873 831
874 return true; 832 return true;
875} 833}
876#include <qcstring.h> 834#include <qcstring.h>
877void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) 835void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note )
878{ 836{
879 QString eText = vfconverter.eventToString( ev, cal ); 837 QString eText = vfconverter.eventToString( ev, cal );
880 int pos = 0; 838 int pos = 0;
881 GSM_ToDoEntry dummy; 839 GSM_ToDoEntry dummy;
882 qDebug( "Convert event"); 840 qDebug( "Convert event");
883 QByteArray ba; 841 QByteArray ba;
884 QDataStream s ( ba, IO_WriteOnly ); 842 QDataStream s ( ba, IO_WriteOnly );
885 s << eText.utf8(); 843 s << eText.utf8();
886 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); 844 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
887 qDebug( "Convert event done"); 845 qDebug( "Convert event done");
888 Note->Location = 0; 846 Note->Location = 0;
889 QString loc = ev->getID(mProfileName); 847 QString loc = ev->getID(mProfileName);
890 if ( !loc.isEmpty() ){ 848 if ( !loc.isEmpty() ){
891 Note->Location = loc.toInt(); 849 Note->Location = loc.toInt();
892 } 850 }
893 851
894} 852}
895void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) 853void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo )
896{ 854{
897 qDebug( "Convert todo1"); 855 qDebug( "Convert todo1");
898 QString tText = vfconverter.todoToString( todo, cal ); 856 QString tText = vfconverter.todoToString( todo, cal );
899 int pos = 0; 857 int pos = 0;
900 GSM_CalendarEntry dummy; 858 GSM_CalendarEntry dummy;
901 QByteArray ba; 859 QByteArray ba;
902 QDataStream s ( ba, IO_WriteOnly ); 860 QDataStream s ( ba, IO_WriteOnly );
903 s << tText.utf8(); 861 s << tText.utf8();
904 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); 862 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
905 qDebug( "Convert todo done "); 863 qDebug( "Convert todo done ");
906 gsmTodo->Location = 0; 864 gsmTodo->Location = 0;
907 QString loc = todo->getID(mProfileName); 865 QString loc = todo->getID(mProfileName);
908 if ( !loc.isEmpty() ){ 866 if ( !loc.isEmpty() ){
909 gsmTodo->Location = loc.toInt(); 867 gsmTodo->Location = loc.toInt();
910 } 868 }
911 869
912} 870}
913void PhoneFormat::afterSave( Incidence* inc) 871void PhoneFormat::afterSave( Incidence* inc)
914{ 872{
915 uint csum; 873 uint csum;
874 inc->removeID( mProfileName );
916 if ( inc->type() == "Event") 875 if ( inc->type() == "Event")
917 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 876 csum = PhoneFormat::getCsumEvent( (Event*) inc );
918 else 877 else
919 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 878 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
920 inc->setCsum( mProfileName, QString::number( csum )); 879 inc->setCsum( mProfileName, QString::number( csum ));
921 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 880 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
922 881
923} 882}
924bool PhoneFormat::save( Calendar *calendar) 883bool PhoneFormat::save( Calendar *calendar)
925{ 884{
926 return true; 885
927 GSM_StateMachines; 886 GSM_StateMachines;
928 qDebug(" save "); 887 qDebug(" save ");
929 s.opened = false; 888 s.opened = false;
930 s.msg = NULL; 889 s.msg = NULL;
931 s.ConfigNum = 0; 890 s.ConfigNum = 0;
932 QLabel status ( i18n(" Opening device ..."), 0 ); 891 QLabel status ( i18n(" Opening device ..."), 0 );
933 int w = status.sizeHint().width()+20 ; 892 int w = status.sizeHint().width()+20 ;
934 if ( w < 200 ) w = 230; 893 if ( w < 200 ) w = 230;
935 int h = status.sizeHint().height()+20 ; 894 int h = status.sizeHint().height()+20 ;
936 int dw = QApplication::desktop()->width(); 895 int dw = QApplication::desktop()->width();
937 int dh = QApplication::desktop()->height(); 896 int dh = QApplication::desktop()->height();
938 status.setCaption(i18n("Writing to phone...") ); 897 status.setCaption(i18n("Writing to phone...") );
939 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 898 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
940 status.show(); 899 status.show();
941 status.raise(); 900 status.raise();
942 qApp->processEvents(); 901 qApp->processEvents();
943 902
944 int error=initDevice(&s); 903 int error=initDevice(&s);
945 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 904 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
946 if ( error != ERR_NONE ) 905 if ( error != ERR_NONE )
947 return false; 906 return false;
948 GSM_Phone_Functions*Phone; 907 GSM_Phone_Functions*Phone;
949 GSM_CalendarEntryNote; 908 GSM_CalendarEntryNote;
950 bool start = true; 909 bool start = true;
951 Phone=s.Phone.Functions; 910 Phone=s.Phone.Functions;
952 bool gshutdown = false; 911 bool gshutdown = false;
953 QPtrList<Event> er = calendar->rawEvents(); 912 QPtrList<Event> er = calendar->rawEvents();
954 Event* ev = er.first(); 913 Event* ev = er.first();
955 QString message = i18n(" Processing event # "); 914 QString message = i18n(" Deleting event # ");
956 int procCount = 0; 915 int procCount = 0;
957 bool planB = true;// false; 916 int diffProc = 0;
917 bool setPossible = true;
918#ifdef _WIN32_
919 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
920#else
921 QString fileName = "/tmp/kdepimtemp.vcs";
922#endif
923 //algo 1 delete event
924 while ( ev ) {
925 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
926
927 status.setText ( message + QString::number ( ++procCount ) );
928 qApp->processEvents();
929 qDebug("del event1 %d ", procCount);
930 //event2GSM( calendar, ev, &Note );
931 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
932
933 QString loc = ev->getID(mProfileName);
934 if ( !loc.isEmpty() ){
935 Note.Location = loc.toInt();
936 } else {
937 qDebug("error: loc is empty ");
938 }
939 error = Phone->DeleteCalendar(&s, &Note);
940 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
941 qDebug(" e error delete1 planB %d ", error);
942 break;
943 }
944 }
945 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
946 // we have to do this later after deleting
947
948 }
949 else { // change existing
950
951 QString loc = ev->getID(mProfileName);
952 if ( !loc.isEmpty() ){
953 Note.Location = loc.toInt();
954 } else {
955 qDebug("error3: loc is empty ");
956 }
957 error = Phone->DeleteCalendar(&s, &Note);
958 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
959 qDebug(" e error delete2 planB %d ", error);
960 break;
961 }
962 ev->removeID( mProfileName );
963 }
964 }
965 ev = er.next();
966 }
967 //algo 1 delete todo
968 GSM_ToDoEntry ToDoEntry;
969 QPtrList<Todo> tl = calendar->rawTodos();
970 Todo* to = tl.first();
971 message = i18n(" Deleting todo # ");
972 procCount = 0;
973 while ( to ) {
974 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
975 qDebug("todo3 %d ", procCount);
976 status.setText ( message + QString::number ( ++procCount ) );
977 qApp->processEvents();
978 qDebug("todo5 %d ", procCount);
979 // todo2GSM( calendar, to, &ToDoEntry );
980 QString loc = to->getID(mProfileName);
981 if ( !loc.isEmpty() ){
982 ToDoEntry.Location = loc.toInt();
983 } else {
984 qDebug("error2: loc is empty ");
985 }
986 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
987 error=Phone->DeleteToDo(&s,&ToDoEntry);
988 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
989 qDebug("delete planB %d ", error);
990 }
991 }
992 else if ( to->getID(mProfileName).isEmpty() ) { // add new
993 ;
994 }
995 else { // change existing
996 error=Phone->DeleteToDo(&s,&ToDoEntry);
997 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
998 qDebug("set planB %d ", error);
999 }
1000 to->removeID( mProfileName );
1001 }
1002 }
1003 to = tl.next();
1004 }
1005 //algo 2 add event
1006 ev = er.first();
1007 QString filec;
1008 message = i18n(" Preparing event # ");
1009 procCount = 0;
1010 while ( ev ) {
1011 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1012 if ( ev->getID(mProfileName).isEmpty() ) {
1013 status.setText ( message + QString::number ( ++procCount ) );
1014 qApp->processEvents();
1015 filec += vfconverter.eventToString( ev, calendar )+ "\n";
1016 afterSave ( ev );
1017
1018 }
1019 }
1020 ev = er.next();
1021 }
1022 //algo 2 add todo
1023 to = tl.first();
1024 procCount = 0;
1025 message = i18n(" Preparing todo # ");
1026 while ( to ) {
1027 qDebug("todo2 %d ", procCount);
1028 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1029 qDebug("todo4 %d ", procCount);
1030 if ( to->getID(mProfileName).isEmpty() ) {
1031 status.setText ( message + QString::number ( ++procCount ) );
1032 qApp->processEvents();
1033 filec += vfconverter.todoToString( to, calendar )+ "\n";
1034 afterSave ( to );
1035 }
1036 }
1037 to = tl.next();
1038 }
1039 if ( filec.isEmpty() ) {
1040 qDebug("Nothing to write back.Finished. ");
1041 error=GSM_TerminateConnection(&s);
1042 return true;
1043 }
1044 //algo 3 saving file
1045 message = i18n(" Saving temp file ... ");
1046 status.setText ( message );
1047 qApp->processEvents();
1048 QFile file( fileName );
1049 if (!file.open( IO_WriteOnly ) ) {
1050 qDebug("error open file ");
1051 error=GSM_TerminateConnection(&s);
1052 return false;
1053 }
1054 QTextStream ts( &file );
1055 ts.setCodec( QTextCodec::codecForName("utf8") );
1056 ts << filec ;
1057 file.close();
1058
1059
1060 message = i18n(" Parsing temp file ... ");
1061 status.setText ( message );
1062 qApp->processEvents();
1063 GSM_Backup Backup;
1064 error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup);
1065 qDebug("Read file result %d ",error );
1066 //algo 4 writing event
1067 int max, i;
1068 procCount = 0;
1069 message = i18n(" Writing event # ");
1070 if (Backup.Calendar[0] != NULL) {
1071 max = 0;
1072 while (Backup.Calendar[max]!=NULL) max++;
1073 for (i=0;i<max;i++) {
1074 status.setText ( message + QString::number ( ++procCount ) );
1075 qApp->processEvents();
1076 Note = *Backup.Calendar[i];
1077 Note.Location = 0;
1078 error=Phone->AddCalendar(&s,&Note);
1079 qDebug("add event %d %d", error, Note.Location );
1080 }
1081 }
1082 //algo 4 writing todo
1083 procCount = 0;
1084 message = i18n(" Writing todo # ");
1085 if (Backup.ToDo[0] != NULL) {
1086 max = 0;
1087 while (Backup.ToDo[max]!=NULL) max++;
1088 for (i=0;i<max;i++) {
1089 status.setText ( message + QString::number ( ++procCount ) );
1090 qApp->processEvents();
1091 ToDoEntry = *Backup.ToDo[i];
1092 error = Phone->AddToDo(&s,&ToDoEntry);
1093 qDebug("add todo %d ", error);
1094 }
1095 }
1096 //algo 5 reread
1097 message = i18n(" Rereading all data ... ");
1098 status.setText ( message );
1099 qApp->processEvents();
1100 error=GSM_TerminateConnection(&s);
1101 CalendarLocal* calendarTemp = new CalendarLocal();
1102 calendarTemp->setTimeZoneId( calendar->timeZoneId());
1103 if ( ! load( calendarTemp,calendar) ){
1104 qDebug("error reloading calendar ");
1105 delete calendarTemp;
1106 return false;
1107 }
1108
1109
1110 //algo 6 compare event
1111 ev = er.first();
1112 message = i18n(" Comparing event # ");
1113 QPtrList<Event> er1 = calendarTemp->rawEvents();
1114 Event* ev1;
1115 procCount = 0;
1116 while ( ev ) {
1117 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1118 qDebug("event new ID ");
1119 status.setText ( message + QString::number ( ++procCount ) );
1120 qApp->processEvents();
1121 QString cSum = ev->getCsum(mProfileName);
1122 ev1 = er1.first();
1123 while ( ev1 ) {
1124 if ( ev1->getCsum( mProfileName ) == cSum ) {
1125 er1.remove( ev1 );
1126 ev->setID(mProfileName, ev1->getID(mProfileName) );
1127 break;
1128 }
1129 ev1 = er1.next();
1130 }
1131 if ( ! ev1 ) {
1132 ev->removeID(mProfileName);
1133 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
1134 qDebug("Probably writing back of events not supported ");
1135 }
1136
1137 }
1138 ev = er.next();
1139 }
1140 //algo 6 compare todo
1141 to = tl.first();
1142 procCount = 0;
1143 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
1144 Todo* to1 ;
1145 message = i18n(" Comparing todo # ");
1146 while ( to ) {
1147 qDebug("todo2 %d ", procCount);
1148 if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) {
1149 status.setText ( message + QString::number ( ++procCount ) );
1150 qApp->processEvents();
1151 QString cSum = to->getCsum(mProfileName);
1152 Todo* to1 = tl1.first();
1153 while ( to1 ) {
1154 if ( to1->getCsum( mProfileName ) == cSum ) {
1155 tl1.remove( to1 );
1156 to->setID(mProfileName, to1->getID(mProfileName) );
1157 break;
1158 }
1159 to1 = tl1.next();
1160 }
1161 if ( ! to1 ) {
1162 to->removeID(mProfileName);
1163 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
1164 qDebug("Probably writing back of todos not supported ");
1165 }
1166 }
1167 to = tl.next();
1168 }
1169 delete calendarTemp;
1170 return true;
1171 // *******************************************************************
1172 // *******************************************************************
1173 // *******************************************************************
1174#if 0
958 while ( ev && ! planB) { 1175 while ( ev && ! planB) {
959 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one 1176 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
960 1177
961 status.setText ( message + QString::number ( ++procCount ) ); 1178 status.setText ( message + QString::number ( ++procCount ) );
962 qApp->processEvents(); 1179 qApp->processEvents();
963 qDebug("event1 %d ", procCount); 1180 qDebug("event1 %d ", procCount);
964 event2GSM( calendar, ev, &Note ); 1181 event2GSM( calendar, ev, &Note );
965 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1182 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
966 error = Phone->DeleteCalendar(&s, &Note); 1183 error = Phone->DeleteCalendar(&s, &Note);
967 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1184 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
968 planB = true; 1185 planB = true;
969 qDebug(" e delete planB %d ", error); 1186 qDebug(" e delete1 planB %d ", error);
970 break; 1187 break;
971 } 1188 }
972 } 1189 }
973 else if ( ev->getID(mProfileName).isEmpty() ) { // add new 1190 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
974 // we have to do this later after deleting 1191 // we have to do this later after deleting
975 1192
976 } 1193 }
977 else { // change existing 1194 else { // change existing
978 error = Phone->SetCalendar(&s, &Note); 1195 if ( setPossible ) {
979 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1196 error = Phone->SetCalendar(&s, &Note);
980 planB = true; 1197 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
981 qDebug(" e change planB %d ", error); 1198 setPossible = false;
982 break; 1199 ++diffProc;
1200 qDebug("Set cal not supported %d ", error);
1201 break;
1202 }
1203 }
1204 if ( ! setPossible) {
1205 ++diffProc;
1206 error = Phone->DeleteCalendar(&s, &Note);
1207 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1208 planB = true;
1209 qDebug(" e delete2 planB %d ", error);
1210 break;
1211 }
1212 ev->removeID( mProfileName );
983 } 1213 }
984 qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); 1214 qDebug("Change Calendar. Location %d status: %d",Note.Location, error );
985 } 1215 }
986 } 1216 }
987 ev = er.next(); 1217 ev = er.next();
988 } 1218 }
989 ev = er.first(); 1219 ev = er.first();
990 // pending get empty slots 1220 // pending get empty slots
991 int loc = 0; 1221 int loc = 0;
1222 procCount -= diffProc;
992 while ( ev && ! planB) { 1223 while ( ev && ! planB) {
993 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1224 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
994 qDebug("event2 %d ", procCount); 1225 qDebug("event2 %d ", procCount);
995 if ( ev->getID(mProfileName).isEmpty() ) { 1226 if ( ev->getID(mProfileName).isEmpty() ) {
996 status.setText ( message + QString::number ( ++procCount ) ); 1227 status.setText ( message + QString::number ( ++procCount ) );
997 qApp->processEvents(); 1228 qApp->processEvents();
998 //int newID ;//= pending 1229 //int newID ;//= pending
999 //ev->setID(mProfileName, QString::number( newID )); 1230 //ev->setID(mProfileName, QString::number( newID ));
1000 event2GSM( calendar, ev, &Note ); 1231 event2GSM( calendar, ev, &Note );
1001 ++loc; 1232 ++loc;
1002 Note.Location = loc; 1233 Note.Location = loc;
1003 error = Phone->AddCalendar(&s, &Note); 1234 error = Phone->AddCalendar(&s, &Note);
1004 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1235 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1005 planB = true; 1236 planB = true;
1006 qDebug(" e add planB %d ", error); 1237 qDebug(" e add planB %d ", error);
1007 break; 1238 break;
1008 } 1239 }
1009 ev->setID( mProfileName, QString::number( Note.Location ) ); 1240 ev->setID( mProfileName, QString::number( Note.Location ) );
1010 qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); 1241 qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN);
1011 afterSave( ev ); 1242 afterSave( ev );
1012 } else { 1243 } else {
1013 afterSave( ev ); // setting temp sync stat for changed items 1244 afterSave( ev ); // setting temp sync stat for changed items
1014 } 1245 }
1015 } 1246 }
1016 ev = er.next(); 1247 ev = er.next();
1017 } 1248 }
1018 1249
1019 1250
1020 if ( planB ) { 1251 if ( planB ) {
1021 qDebug("delete all calendar..."); 1252 qDebug("delete all calendar...");
1022 status.setText ( i18n("Deleting all calendar...")); 1253 status.setText ( i18n("Deleting all calendar..."));
1023 qApp->processEvents(); 1254 qApp->processEvents();
1024 error=Phone->DeleteAllCalendar(&s); 1255 error=Phone->DeleteAllCalendar(&s);
1025 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1256 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1026 message = i18n(" Deleting event # "); 1257 message = i18n(" Deleting event # ");
1027 procCount = 0; 1258 procCount = 0;
1028 while (1) { 1259 while (1) {
1029 status.setText ( message + QString::number ( ++procCount ) ); 1260 status.setText ( message + QString::number ( ++procCount ) );
1030 qApp->processEvents(); 1261 qApp->processEvents();
1031 qDebug("deleting event ... %d", procCount); 1262 qDebug("deleting event ... %d", procCount);
1032 error = Phone->GetNextCalendar(&s,&Note,true); 1263 error = Phone->GetNextCalendar(&s,&Note,true);
1033 if (error != ERR_NONE) break; 1264 if (error != ERR_NONE) break;
1034 error = Phone->DeleteCalendar(&s,&Note); 1265 error = Phone->DeleteCalendar(&s,&Note);
1035 } 1266 }
1036 qDebug("deleting calendar ... finished"); 1267 qDebug("deleting calendar ... finished");
1037 } else { 1268 } else {
1038 status.setText ( i18n("All calendar deleted!")); 1269 status.setText ( i18n("All calendar deleted!"));
1039 qDebug("all cal deleted"); 1270 qDebug("all cal deleted");
1040 } 1271 }
1041 bool planC = false; 1272 bool planC = false;
1042 ev = er.first(); 1273 ev = er.first();
1043 procCount = 0; 1274 procCount = 0;
1044 message = i18n(" Writing event # "); 1275 message = i18n(" Writing event # ");
1045 while ( ev && ! planC) { 1276 while ( ev && ! planC) {
1046 status.setText ( message + QString::number ( ++procCount ) ); 1277 status.setText ( message + QString::number ( ++procCount ) );
1047 qApp->processEvents(); 1278 qApp->processEvents();
1048 event2GSM( calendar, ev, &Note ); 1279 event2GSM( calendar, ev, &Note );
1049 Note.Location = procCount; 1280 Note.Location = procCount;
1050 error=Phone->AddCalendar(&s,&Note); 1281 error=Phone->AddCalendar(&s,&Note);
1051 if (error != ERR_NONE ) { 1282 if (error != ERR_NONE ) {
1052 // we have currently no planC :-( 1283 // we have currently no planC :-(
1053 // planC = true; 1284 // planC = true;
1054 //qDebug("add planC %d ", error); 1285 //qDebug("add planC %d ", error);
1055 //break; 1286 //break;
1056 // we remove the ID such that this todo is not deleted after next sync 1287 // we remove the ID such that this todo is not deleted after next sync
1057 ev->removeID(mProfileName); 1288 ev->removeID(mProfileName);
1058 ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 1289 ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1059 qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); 1290 qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error);
1060 } else { 1291 } else {
1061 qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); 1292 qDebug("cal adding loc %d planB stat %d ", Note.Location ,error);
1062 ev->setID(mProfileName, QString::number( Note.Location )); 1293 ev->setID(mProfileName, QString::number( Note.Location ));
1063 afterSave( ev ); 1294 afterSave( ev );
1064 } 1295 }
1065 ev = er.next(); 1296 ev = er.next();
1066 } 1297 }
1067 if ( planC ) { 1298 if ( planC ) {
1068 qDebug("writing cal went wrong..."); 1299 qDebug("writing cal went wrong...");
1069 1300
1070 // we have currently no planC :-( 1301 // we have currently no planC :-(
1071 } 1302 }
1072 } 1303 }
1073 GSM_ToDoEntry ToDoEntry; 1304 GSM_ToDoEntry ToDoEntry;
1074 QPtrList<Todo> tl = calendar->rawTodos(); 1305 QPtrList<Todo> tl = calendar->rawTodos();
1075 Todo* to = tl.first(); 1306 Todo* to = tl.first();
1076 1307
1077 message = i18n(" Processing todo # "); 1308 message = i18n(" Processing todo # ");
1078 procCount = 0; 1309 procCount = 0;
1079 planB = false; 1310 planB = false;
1080 while ( to && ! planB ) { 1311 while ( to && ! planB ) {
1081 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 1312 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
1082 qDebug("todo3 %d ", procCount); 1313 qDebug("todo3 %d ", procCount);
1083 status.setText ( message + QString::number ( ++procCount ) ); 1314 status.setText ( message + QString::number ( ++procCount ) );
1084 qApp->processEvents(); 1315 qApp->processEvents();
1085 qDebug("todo5 %d ", procCount); 1316 qDebug("todo5 %d ", procCount);
1086 todo2GSM( calendar, to, &ToDoEntry ); 1317 todo2GSM( calendar, to, &ToDoEntry );
1087 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1318 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
1088 error=Phone->DeleteToDo(&s,&ToDoEntry); 1319 error=Phone->DeleteToDo(&s,&ToDoEntry);
1089 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1320 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1090 planB = true; 1321 planB = true;
1091 qDebug("delete planB %d ", error); 1322 qDebug("delete planB %d ", error);
1092 } 1323 }
1093 } 1324 }
1094 else if ( to->getID(mProfileName).isEmpty() ) { // add new 1325 else if ( to->getID(mProfileName).isEmpty() ) { // add new
1095 ; 1326 ;
1096 } 1327 }
1097 else { // change existing 1328 else { // change existing
1098 error=Phone->SetToDo(&s,&ToDoEntry); 1329 error=Phone->SetToDo(&s,&ToDoEntry);
1099 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1330 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1100 planB = true; 1331 planB = true;
1101 qDebug("set planB %d ", error); 1332 qDebug("set planB %d ", error);
1102 } 1333 }
1103 qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); 1334 qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error );
1104 } 1335 }
1105 } 1336 }
1106 to = tl.next(); 1337 to = tl.next();
1107 } 1338 }
1108 1339
1109 // pending get empty slots 1340 // pending get empty slots
1110 to = tl.first(); 1341 to = tl.first();
1111 while ( to && ! planB ) { 1342 while ( to && ! planB ) {
1112 qDebug("todo2 %d ", procCount); 1343 qDebug("todo2 %d ", procCount);
1113 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1344 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1114 qDebug("todo4 %d ", procCount); 1345 qDebug("todo4 %d ", procCount);
1115 if ( to->getID(mProfileName).isEmpty() ) { 1346 if ( to->getID(mProfileName).isEmpty() ) {
1116 status.setText ( message + QString::number ( ++procCount ) ); 1347 status.setText ( message + QString::number ( ++procCount ) );
1117 qApp->processEvents(); 1348 qApp->processEvents();
1118 //int newID ;//= pending 1349 //int newID ;//= pending
1119 //to->setID(mProfileName, QString::number( newID )); 1350 //to->setID(mProfileName, QString::number( newID ));
1120 todo2GSM( calendar,to, &ToDoEntry ); 1351 todo2GSM( calendar,to, &ToDoEntry );
1121 ToDoEntry.Location = 0; 1352 ToDoEntry.Location = 0;
1122 error=Phone->AddToDo(&s,&ToDoEntry); 1353 error=Phone->AddToDo(&s,&ToDoEntry);
1123 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1354 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1124 planB = true; 1355 planB = true;
1125 qDebug("new planB %d ", error); 1356 qDebug("new planB %d ", error);
1126 } 1357 }
1127 to->setID(mProfileName, QString::number( ToDoEntry.Location )); 1358 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1128 afterSave( to ); 1359 afterSave( to );
1129 qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); 1360 qDebug("New Todo. Location %d %d",ToDoEntry.Location, error );
1130 } else { 1361 } else {
1131 afterSave( to ); 1362 afterSave( to );
1132 } 1363 }
1133 } 1364 }
1134 to = tl.next(); 1365 to = tl.next();
1135 } 1366 }
1136 if ( planB ) { 1367 if ( planB ) {
1137 qDebug("delete all ..."); 1368 qDebug("delete all ...");
1138 error=Phone->DeleteAllToDo(&s); 1369 error=Phone->DeleteAllToDo(&s);
1139 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1370 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1140 while (1) { 1371 while (1) {
1141 qDebug("deleting todo ..."); 1372 qDebug("deleting todo ...");
1142 error = Phone->GetNextToDo(&s,&ToDoEntry,true); 1373 error = Phone->GetNextToDo(&s,&ToDoEntry,true);
1143 if (error != ERR_NONE) break; 1374 if (error != ERR_NONE) break;
1144 error = Phone->DeleteToDo(&s,&ToDoEntry); 1375 error = Phone->DeleteToDo(&s,&ToDoEntry);
1145 } 1376 }
1146 qDebug("deleting todo ... finished"); 1377 qDebug("deleting todo ... finished");
1147 } else { 1378 } else {
1148 qDebug("all todo deleted"); 1379 qDebug("all todo deleted");
1149 } 1380 }
1150 bool planC = false; 1381 bool planC = false;
1151 to = tl.first(); 1382 to = tl.first();
1152 while ( to && ! planC ) { 1383 while ( to && ! planC ) {
1153 todo2GSM( calendar,to, &ToDoEntry ); 1384 todo2GSM( calendar,to, &ToDoEntry );
1154 ToDoEntry.Location = 0; 1385 ToDoEntry.Location = 0;
1155 error=Phone->AddToDo(&s,&ToDoEntry); 1386 error=Phone->AddToDo(&s,&ToDoEntry);
1156 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 1387 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1157 // we have currently no planC :-( 1388 // we have currently no planC :-(
1158 // planC = true; 1389 // planC = true;
1159 //qDebug("add planC %d ", error); 1390 //qDebug("add planC %d ", error);
1160 //break; 1391 //break;
1161 // we remove the ID such that this todo is not deleted after next sync 1392 // we remove the ID such that this todo is not deleted after next sync
1162 to->removeID(mProfileName); 1393 to->removeID(mProfileName);
1163 to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 1394 to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1164 } else { 1395 } else {
1165 qDebug("adding %d planB %d ", ToDoEntry.Location ,error); 1396 qDebug("adding %d planB %d ", ToDoEntry.Location ,error);
1166 to->setID(mProfileName, QString::number( ToDoEntry.Location )); 1397 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1167 afterSave( to ); 1398 afterSave( to );
1168 } 1399 }
1169 to = tl.next(); 1400 to = tl.next();
1170 } 1401 }
1171 if ( planC ) { 1402 if ( planC ) {
1172 // we have currently no planC :-( 1403 // we have currently no planC :-(
1173 } 1404 }
1174 } 1405 }
1175 return true; 1406 return true;
1407#endif
1176} 1408}
1177QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 1409QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
1178{ 1410{
1179 QString datestr; 1411 QString datestr;
1180 QString timestr; 1412 QString timestr;
1181 int offset = KGlobal::locale()->localTimeOffset( dti ); 1413 int offset = KGlobal::locale()->localTimeOffset( dti );
1182 QDateTime dt; 1414 QDateTime dt;
1183 if (useTZ) 1415 if (useTZ)
1184 dt = dti.addSecs ( -(offset*60)); 1416 dt = dti.addSecs ( -(offset*60));
1185 else 1417 else
1186 dt = dti; 1418 dt = dti;
1187 if(dt.date().isValid()){ 1419 if(dt.date().isValid()){
1188 const QDate& date = dt.date(); 1420 const QDate& date = dt.date();
1189 datestr.sprintf("%04d%02d%02d", 1421 datestr.sprintf("%04d%02d%02d",
1190 date.year(), date.month(), date.day()); 1422 date.year(), date.month(), date.day());
1191 } 1423 }
1192 if(dt.time().isValid()){ 1424 if(dt.time().isValid()){
1193 const QTime& time = dt.time(); 1425 const QTime& time = dt.time();
1194 timestr.sprintf("T%02d%02d%02d", 1426 timestr.sprintf("T%02d%02d%02d",
1195 time.hour(), time.minute(), time.second()); 1427 time.hour(), time.minute(), time.second());
1196 } 1428 }
1197 return datestr + timestr; 1429 return datestr + timestr;
1198} 1430}
1199QString PhoneFormat::getEventString( Event* event ) 1431QString PhoneFormat::getEventString( Event* event )
1200{ 1432{
1201#if 0 1433#if 0
1202 QStringList list; 1434 QStringList list;
1203 list.append( QString::number(event->zaurusId() ) ); 1435 list.append( QString::number(event->zaurusId() ) );
1204 list.append( event->categories().join(",") ); 1436 list.append( event->categories().join(",") );
1205 if ( !event->summary().isEmpty() ) 1437 if ( !event->summary().isEmpty() )
1206 list.append( event->summary() ); 1438 list.append( event->summary() );
1207 else 1439 else
1208 list.append("" ); 1440 list.append("" );
1209 if ( !event->location().isEmpty() ) 1441 if ( !event->location().isEmpty() )
1210 list.append( event->location() ); 1442 list.append( event->location() );
1211 else 1443 else
1212 list.append("" ); 1444 list.append("" );
1213 if ( !event->description().isEmpty() ) 1445 if ( !event->description().isEmpty() )
1214 list.append( event->description() ); 1446 list.append( event->description() );
1215 else 1447 else
1216 list.append( "" ); 1448 list.append( "" );
1217 if ( event->doesFloat () ) { 1449 if ( event->doesFloat () ) {
1218 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 1450 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
1219 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 1451 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
1220 list.append( "1" ); 1452 list.append( "1" );
1221 1453
1222 } 1454 }
1223 else { 1455 else {
1224 list.append( dtToString( event->dtStart()) ); 1456 list.append( dtToString( event->dtStart()) );
1225 list.append( dtToString( event->dtEnd()) ); //6 1457 list.append( dtToString( event->dtEnd()) ); //6
1226 list.append( "0" ); 1458 list.append( "0" );
1227 } 1459 }
1228 bool noAlarm = true; 1460 bool noAlarm = true;
1229 if ( event->alarms().count() > 0 ) { 1461 if ( event->alarms().count() > 0 ) {
1230 Alarm * al = event->alarms().first(); 1462 Alarm * al = event->alarms().first();
1231 if ( al->enabled() ) { 1463 if ( al->enabled() ) {
1232 noAlarm = false; 1464 noAlarm = false;
1233 list.append( "0" ); // yes, 0 == alarm 1465 list.append( "0" ); // yes, 0 == alarm
1234 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 1466 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
1235 if ( al->type() == Alarm::Audio ) 1467 if ( al->type() == Alarm::Audio )
1236 list.append( "1" ); // type audio 1468 list.append( "1" ); // type audio
1237 else 1469 else
1238 list.append( "0" ); // type silent 1470 list.append( "0" ); // type silent
1239 } 1471 }
1240 } 1472 }
1241 if ( noAlarm ) { 1473 if ( noAlarm ) {
1242 list.append( "1" ); // yes, 1 == no alarm 1474 list.append( "1" ); // yes, 1 == no alarm
1243 list.append( "0" ); // no alarm offset 1475 list.append( "0" ); // no alarm offset
1244 list.append( "1" ); // type 1476 list.append( "1" ); // type
1245 } 1477 }
1246 // next is: 11 1478 // next is: 11
1247 // next is: 11-16 are recurrence 1479 // next is: 11-16 are recurrence
1248 Recurrence* rec = event->recurrence(); 1480 Recurrence* rec = event->recurrence();
1249 1481
1250 bool writeEndDate = false; 1482 bool writeEndDate = false;
1251 switch ( rec->doesRecur() ) 1483 switch ( rec->doesRecur() )
1252 { 1484 {
1253 case Recurrence::rDaily: // 0 1485 case Recurrence::rDaily: // 0
1254 list.append( "0" ); 1486 list.append( "0" );
1255 list.append( QString::number( rec->frequency() ));//12 1487 list.append( QString::number( rec->frequency() ));//12
1256 list.append( "0" ); 1488 list.append( "0" );
1257 list.append( "0" ); 1489 list.append( "0" );
1258 writeEndDate = true; 1490 writeEndDate = true;
1259 break; 1491 break;
1260 case Recurrence::rWeekly:// 1 1492 case Recurrence::rWeekly:// 1
1261 list.append( "1" ); 1493 list.append( "1" );
1262 list.append( QString::number( rec->frequency()) );//12 1494 list.append( QString::number( rec->frequency()) );//12
1263 list.append( "0" ); 1495 list.append( "0" );
1264 { 1496 {
1265 int days = 0; 1497 int days = 0;
1266 QBitArray weekDays = rec->days(); 1498 QBitArray weekDays = rec->days();
1267 int i; 1499 int i;
1268 for( i = 1; i <= 7; ++i ) { 1500 for( i = 1; i <= 7; ++i ) {
1269 if ( weekDays[i-1] ) { 1501 if ( weekDays[i-1] ) {
1270 days += 1 << (i-1); 1502 days += 1 << (i-1);
1271 } 1503 }
1272 } 1504 }
1273 list.append( QString::number( days ) ); 1505 list.append( QString::number( days ) );
1274 } 1506 }
1275 //pending weekdays 1507 //pending weekdays
1276 writeEndDate = true; 1508 writeEndDate = true;
1277 1509
1278 break; 1510 break;
1279 case Recurrence::rMonthlyPos:// 2 1511 case Recurrence::rMonthlyPos:// 2
1280 list.append( "2" ); 1512 list.append( "2" );
1281 list.append( QString::number( rec->frequency()) );//12 1513 list.append( QString::number( rec->frequency()) );//12
1282 1514
1283 writeEndDate = true; 1515 writeEndDate = true;
1284 { 1516 {
1285 int count = 1; 1517 int count = 1;
1286 QPtrList<Recurrence::rMonthPos> rmp; 1518 QPtrList<Recurrence::rMonthPos> rmp;
1287 rmp = rec->monthPositions(); 1519 rmp = rec->monthPositions();
1288 if ( rmp.first()->negative ) 1520 if ( rmp.first()->negative )
1289 count = 5 - rmp.first()->rPos - 1; 1521 count = 5 - rmp.first()->rPos - 1;
1290 else 1522 else
1291 count = rmp.first()->rPos - 1; 1523 count = rmp.first()->rPos - 1;
1292 list.append( QString::number( count ) ); 1524 list.append( QString::number( count ) );
1293 1525
1294 } 1526 }
1295 1527
1296 list.append( "0" ); 1528 list.append( "0" );
1297 break; 1529 break;
1298 case Recurrence::rMonthlyDay:// 3 1530 case Recurrence::rMonthlyDay:// 3
1299 list.append( "3" ); 1531 list.append( "3" );
1300 list.append( QString::number( rec->frequency()) );//12 1532 list.append( QString::number( rec->frequency()) );//12
1301 list.append( "0" ); 1533 list.append( "0" );
1302 list.append( "0" ); 1534 list.append( "0" );
1303 writeEndDate = true; 1535 writeEndDate = true;
1304 break; 1536 break;
1305 case Recurrence::rYearlyMonth://4 1537 case Recurrence::rYearlyMonth://4
1306 list.append( "4" ); 1538 list.append( "4" );
1307 list.append( QString::number( rec->frequency()) );//12 1539 list.append( QString::number( rec->frequency()) );//12
1308 list.append( "0" ); 1540 list.append( "0" );
1309 list.append( "0" ); 1541 list.append( "0" );
1310 writeEndDate = true; 1542 writeEndDate = true;
1311 break; 1543 break;
1312 1544
1313 default: 1545 default:
1314 list.append( "255" ); 1546 list.append( "255" );
1315 list.append( QString() ); 1547 list.append( QString() );
1316 list.append( "0" ); 1548 list.append( "0" );
1317 list.append( QString() ); 1549 list.append( QString() );
1318 list.append( "0" ); 1550 list.append( "0" );
1319 list.append( "20991231T000000" ); 1551 list.append( "20991231T000000" );
1320 break; 1552 break;
1321 } 1553 }
1322 if ( writeEndDate ) { 1554 if ( writeEndDate ) {
1323 1555
1324 if ( rec->endDate().isValid() ) { // 15 + 16 1556 if ( rec->endDate().isValid() ) { // 15 + 16
1325 list.append( "1" ); 1557 list.append( "1" );
1326 list.append( dtToString( rec->endDate()) ); 1558 list.append( dtToString( rec->endDate()) );
1327 } else { 1559 } else {
1328 list.append( "0" ); 1560 list.append( "0" );
1329 list.append( "20991231T000000" ); 1561 list.append( "20991231T000000" );
1330 } 1562 }
1331 1563
1332 } 1564 }
1333 if ( event->doesFloat () ) { 1565 if ( event->doesFloat () ) {
1334 list.append( dtToString( event->dtStart(), false ).left( 8 )); 1566 list.append( dtToString( event->dtStart(), false ).left( 8 ));
1335 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 1567 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
1336 1568
1337 } 1569 }
1338 else { 1570 else {
1339 list.append( QString() ); 1571 list.append( QString() );
1340 list.append( QString() ); 1572 list.append( QString() );
1341 1573
1342 } 1574 }
1343 if (event->dtStart().date() == event->dtEnd().date() ) 1575 if (event->dtStart().date() == event->dtEnd().date() )
1344 list.append( "0" ); 1576 list.append( "0" );
1345 else 1577 else
1346 list.append( "1" ); 1578 list.append( "1" );
1347 1579
1348 1580
1349 for(QStringList::Iterator it=list.begin(); 1581 for(QStringList::Iterator it=list.begin();
1350 it!=list.end(); ++it){ 1582 it!=list.end(); ++it){
1351 QString& s = (*it); 1583 QString& s = (*it);
1352 s.replace(QRegExp("\""), "\"\""); 1584 s.replace(QRegExp("\""), "\"\"");
1353 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1585 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1354 s.prepend('\"'); 1586 s.prepend('\"');
1355 s.append('\"'); 1587 s.append('\"');
1356 } else if(s.isEmpty() && !s.isNull()){ 1588 } else if(s.isEmpty() && !s.isNull()){
1357 s = "\"\""; 1589 s = "\"\"";
1358 } 1590 }
1359 } 1591 }
1360 return list.join(","); 1592 return list.join(",");
1361#endif 1593#endif
1362 return QString(); 1594 return QString();
1363 1595
1364} 1596}
1365QString PhoneFormat::getTodoString( Todo* todo ) 1597QString PhoneFormat::getTodoString( Todo* todo )
1366{ 1598{
1367#if 0 1599#if 0
1368 QStringList list; 1600 QStringList list;
1369 list.append( QString::number( todo->zaurusId() ) ); 1601 list.append( QString::number( todo->zaurusId() ) );
1370 list.append( todo->categories().join(",") ); 1602 list.append( todo->categories().join(",") );
1371 1603
1372 if ( todo->hasStartDate() ) { 1604 if ( todo->hasStartDate() ) {
1373 list.append( dtToString( todo->dtStart()) ); 1605 list.append( dtToString( todo->dtStart()) );
1374 } else 1606 } else
1375 list.append( QString() ); 1607 list.append( QString() );
1376 1608
1377 if ( todo->hasDueDate() ) { 1609 if ( todo->hasDueDate() ) {
1378 QTime tim; 1610 QTime tim;
1379 if ( todo->doesFloat()) { 1611 if ( todo->doesFloat()) {
1380 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 1612 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
1381 } else { 1613 } else {
1382 list.append( dtToString(todo->dtDue() ) ); 1614 list.append( dtToString(todo->dtDue() ) );
1383 } 1615 }
1384 } else 1616 } else
1385 list.append( QString() ); 1617 list.append( QString() );
1386 1618
1387 if ( todo->isCompleted() ) { 1619 if ( todo->isCompleted() ) {
1388 list.append( dtToString( todo->completed()) ); 1620 list.append( dtToString( todo->completed()) );
1389 list.append( "0" ); // yes 0 == completed 1621 list.append( "0" ); // yes 0 == completed
1390 } else { 1622 } else {
1391 list.append( dtToString( todo->completed()) ); 1623 list.append( dtToString( todo->completed()) );
1392 list.append( "1" ); 1624 list.append( "1" );
1393 } 1625 }
1394 list.append( QString::number( todo->priority() )); 1626 list.append( QString::number( todo->priority() ));
1395 if( ! todo->summary().isEmpty() ) 1627 if( ! todo->summary().isEmpty() )
1396 list.append( todo->summary() ); 1628 list.append( todo->summary() );
1397 else 1629 else
1398 list.append( "" ); 1630 list.append( "" );
1399 if (! todo->description().isEmpty() ) 1631 if (! todo->description().isEmpty() )
1400 list.append( todo->description() ); 1632 list.append( todo->description() );
1401 else 1633 else
1402 list.append( "" ); 1634 list.append( "" );
1403 for(QStringList::Iterator it=list.begin(); 1635 for(QStringList::Iterator it=list.begin();
1404 it!=list.end(); ++it){ 1636 it!=list.end(); ++it){
1405 QString& s = (*it); 1637 QString& s = (*it);
1406 s.replace(QRegExp("\""), "\"\""); 1638 s.replace(QRegExp("\""), "\"\"");
1407 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1639 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1408 s.prepend('\"'); 1640 s.prepend('\"');
1409 s.append('\"'); 1641 s.append('\"');
1410 } else if(s.isEmpty() && !s.isNull()){ 1642 } else if(s.isEmpty() && !s.isNull()){
1411 s = "\"\""; 1643 s = "\"\"";
1412 } 1644 }
1413 } 1645 }
1414 return list.join(","); 1646 return list.join(",");
1415#endif 1647#endif
1416 return QString(); 1648 return QString();
1417} 1649}
1418 1650
1419 1651
1420QString PhoneFormat::toString( Calendar * ) 1652QString PhoneFormat::toString( Calendar * )
1421{ 1653{
1422 return QString::null; 1654 return QString::null;
1423} 1655}
1424bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 1656bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
1425{ 1657{
1426 return false; 1658 return false;
1427} 1659}
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index defdb09..820d068 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,1018 +1,1018 @@
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 oldCategories = 0; 67 oldCategories = 0;
68 } 68 }
69 69
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 71 {
72 int i = 1; 72 int i = 1;
73 bool skip = true; 73 bool skip = true;
74 int max = attList.count() -2; 74 int max = attList.count() -2;
75 while ( i < max ) { 75 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 76 if ( !attList[i].isEmpty() ) {
77 skip = false; 77 skip = false;
78 break; 78 break;
79 } 79 }
80 ++i ; 80 ++i ;
81 } 81 }
82 if ( skip ) 82 if ( skip )
83 return false; 83 return false;
84 ulong cSum = SharpFormat::getCsum(attList ); 84 ulong cSum = SharpFormat::getCsum(attList );
85 85
86 if ( qName == "Event" ) { 86 if ( qName == "Event" ) {
87 Event *event; 87 Event *event;
88 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 88 event = existingCalendar->event( "Sharp_DTM",attList[0] );
89 if ( event ) 89 if ( event )
90 event = (Event*)event->clone(); 90 event = (Event*)event->clone();
91 else 91 else
92 event = new Event; 92 event = new Event;
93 event->setID("Sharp_DTM", attList[0] ); 93 event->setID("Sharp_DTM", attList[0] );
94 event->setCsum( "Sharp_DTM", QString::number( cSum )); 94 event->setCsum( "Sharp_DTM", QString::number( cSum ));
95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
96 96
97 event->setSummary( attList[2] ); 97 event->setSummary( attList[2] );
98 event->setLocation( attList[3] ); 98 event->setLocation( attList[3] );
99 event->setDescription( attList[4] ); 99 event->setDescription( attList[4] );
100 if ( attList[7] == "1" ) { 100 if ( attList[7] == "1" ) {
101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
103 event->setFloats( true ); 103 event->setFloats( true );
104 } else { 104 } else {
105 event->setFloats( false ); 105 event->setFloats( false );
106 event->setDtStart( fromString( attList[5] ) ); 106 event->setDtStart( fromString( attList[5] ) );
107 event->setDtEnd( fromString( attList[6] )); 107 event->setDtEnd( fromString( attList[6] ));
108 } 108 }
109 109
110 QString rtype = attList[11]; 110 QString rtype = attList[11];
111 if ( rtype != "255" ) { 111 if ( rtype != "255" ) {
112 // qDebug("recurs "); 112 // qDebug("recurs ");
113 QDate startDate = event->dtStart().date(); 113 QDate startDate = event->dtStart().date();
114 114
115 QString freqStr = attList[12]; 115 QString freqStr = attList[12];
116 int freq = freqStr.toInt(); 116 int freq = freqStr.toInt();
117 117
118 QString hasEndDateStr = attList[15] ; 118 QString hasEndDateStr = attList[15] ;
119 bool hasEndDate = hasEndDateStr == "1"; 119 bool hasEndDate = hasEndDateStr == "1";
120 120
121 QString endDateStr = attList[16]; 121 QString endDateStr = attList[16];
122 QDate endDate = fromString( endDateStr ).date(); 122 QDate endDate = fromString( endDateStr ).date();
123 123
124 QString weekDaysStr = attList[14]; 124 QString weekDaysStr = attList[14];
125 uint weekDaysNum = weekDaysStr.toInt(); 125 uint weekDaysNum = weekDaysStr.toInt();
126 126
127 QBitArray weekDays( 7 ); 127 QBitArray weekDays( 7 );
128 int i; 128 int i;
129 int bb = 1; 129 int bb = 1;
130 for( i = 1; i <= 7; ++i ) { 130 for( i = 1; i <= 7; ++i ) {
131 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 131 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
132 bb = 2 << (i-1); 132 bb = 2 << (i-1);
133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
134 } 134 }
135 // qDebug("next "); 135 // qDebug("next ");
136 QString posStr = attList[13]; 136 QString posStr = attList[13];
137 int pos = posStr.toInt(); 137 int pos = posStr.toInt();
138 Recurrence *r = event->recurrence(); 138 Recurrence *r = event->recurrence();
139 139
140 if ( rtype == "0" ) { 140 if ( rtype == "0" ) {
141 if ( hasEndDate ) r->setDaily( freq, endDate ); 141 if ( hasEndDate ) r->setDaily( freq, endDate );
142 else r->setDaily( freq, -1 ); 142 else r->setDaily( freq, -1 );
143 } else if ( rtype == "1" ) { 143 } else if ( rtype == "1" ) {
144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
145 else r->setWeekly( freq, weekDays, -1 ); 145 else r->setWeekly( freq, weekDays, -1 );
146 } else if ( rtype == "3" ) { 146 } else if ( rtype == "3" ) {
147 if ( hasEndDate ) 147 if ( hasEndDate )
148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
149 else 149 else
150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
151 r->addMonthlyDay( startDate.day() ); 151 r->addMonthlyDay( startDate.day() );
152 } else if ( rtype == "2" ) { 152 } else if ( rtype == "2" ) {
153 if ( hasEndDate ) 153 if ( hasEndDate )
154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
155 else 155 else
156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
157 QBitArray days( 7 ); 157 QBitArray days( 7 );
158 days.fill( false ); 158 days.fill( false );
159 days.setBit( startDate.dayOfWeek() - 1 ); 159 days.setBit( startDate.dayOfWeek() - 1 );
160 r->addMonthlyPos( pos, days ); 160 r->addMonthlyPos( pos, days );
161 } else if ( rtype == "4" ) { 161 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 162 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 164 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 166 r->addYearlyNum( startDate.month() );
167 } 167 }
168 } else { 168 } else {
169 event->recurrence()->unsetRecurs(); 169 event->recurrence()->unsetRecurs();
170 } 170 }
171 171
172 QString categoryList = attList[1] ; 172 QString categoryList = attList[1] ;
173 event->setCategories( lookupCategories( categoryList ) ); 173 event->setCategories( lookupCategories( categoryList ) );
174 174
175 // strange 0 semms to mean: alarm enabled 175 // strange 0 semms to mean: alarm enabled
176 if ( attList[8] == "0" ) { 176 if ( attList[8] == "0" ) {
177 Alarm *alarm; 177 Alarm *alarm;
178 if ( event->alarms().count() > 0 ) 178 if ( event->alarms().count() > 0 )
179 alarm = event->alarms().first(); 179 alarm = event->alarms().first();
180 else { 180 else {
181 alarm = new Alarm( event ); 181 alarm = new Alarm( event );
182 event->addAlarm( alarm ); 182 event->addAlarm( alarm );
183 } 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( lookupCategories( categoryList ) ); 226 todo->setCategories( lookupCategories( 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 todo->setCompleted( false );
259 mCalendar->addTodo( todo ); 259 mCalendar->addTodo( todo );
260 260
261 } else if ( qName == "Category" ) { 261 } else if ( qName == "Category" ) {
262 /* 262 /*
263 QString id = attributes.value( "id" ); 263 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 264 QString name = attributes.value( "name" );
265 setCategory( id, name ); 265 setCategory( id, name );
266 */ 266 */
267 } 267 }
268 //qDebug("end "); 268 //qDebug("end ");
269 return true; 269 return true;
270 } 270 }
271 271
272 272
273 void setCategoriesList ( QStringList * c ) 273 void setCategoriesList ( QStringList * c )
274 { 274 {
275 oldCategories = c; 275 oldCategories = c;
276 } 276 }
277 277
278 QDateTime fromString ( QString s, bool useTz = true ) { 278 QDateTime fromString ( QString s, bool useTz = true ) {
279 QDateTime dt; 279 QDateTime dt;
280 int y,m,t,h,min,sec; 280 int y,m,t,h,min,sec;
281 y = s.mid(0,4).toInt(); 281 y = s.mid(0,4).toInt();
282 m = s.mid(4,2).toInt(); 282 m = s.mid(4,2).toInt();
283 t = s.mid(6,2).toInt(); 283 t = s.mid(6,2).toInt();
284 h = s.mid(9,2).toInt(); 284 h = s.mid(9,2).toInt();
285 min = s.mid(11,2).toInt(); 285 min = s.mid(11,2).toInt();
286 sec = s.mid(13,2).toInt(); 286 sec = s.mid(13,2).toInt();
287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
288 int offset = KGlobal::locale()->localTimeOffset( dt ); 288 int offset = KGlobal::locale()->localTimeOffset( dt );
289 if ( useTz ) 289 if ( useTz )
290 dt = dt.addSecs ( offset*60); 290 dt = dt.addSecs ( offset*60);
291 return dt; 291 return dt;
292 292
293 } 293 }
294 protected: 294 protected:
295 QDateTime toDateTime( const QString &value ) 295 QDateTime toDateTime( const QString &value )
296 { 296 {
297 QDateTime dt; 297 QDateTime dt;
298 dt.setTime_t( value.toUInt() ); 298 dt.setTime_t( value.toUInt() );
299 299
300 return dt; 300 return dt;
301 } 301 }
302 302
303 QStringList lookupCategories( const QString &categoryList ) 303 QStringList lookupCategories( const QString &categoryList )
304 { 304 {
305 QStringList categoryIds = QStringList::split( ";", categoryList ); 305 QStringList categoryIds = QStringList::split( ";", categoryList );
306 QStringList categories; 306 QStringList categories;
307 QStringList::ConstIterator it; 307 QStringList::ConstIterator it;
308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
309 QString cate = category( *it ); 309 QString cate = category( *it );
310 if ( oldCategories ) { 310 if ( oldCategories ) {
311 if ( ! oldCategories->contains( cate ) ) 311 if ( ! oldCategories->contains( cate ) )
312 oldCategories->append( cate ); 312 oldCategories->append( cate );
313 } 313 }
314 categories.append(cate ); 314 categories.append(cate );
315 } 315 }
316 return categories; 316 return categories;
317 } 317 }
318 318
319 private: 319 private:
320 Calendar *mCalendar; 320 Calendar *mCalendar;
321 QStringList * oldCategories; 321 QStringList * oldCategories;
322 static QString category( const QString &id ) 322 static QString category( const QString &id )
323 { 323 {
324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
325 if ( it == mCategoriesMap.end() ) return id; 325 if ( it == mCategoriesMap.end() ) return id;
326 else return *it; 326 else return *it;
327 } 327 }
328 328
329 static void setCategory( const QString &id, const QString &name ) 329 static void setCategory( const QString &id, const QString &name )
330 { 330 {
331 mCategoriesMap.insert( id, name ); 331 mCategoriesMap.insert( id, name );
332 } 332 }
333 333
334 static QMap<QString,QString> mCategoriesMap; 334 static QMap<QString,QString> mCategoriesMap;
335}; 335};
336 336
337QMap<QString,QString> SharpParser::mCategoriesMap; 337QMap<QString,QString> SharpParser::mCategoriesMap;
338 338
339SharpFormat::SharpFormat() 339SharpFormat::SharpFormat()
340{ 340{
341 mCategories = 0; 341 mCategories = 0;
342} 342}
343 343
344SharpFormat::~SharpFormat() 344SharpFormat::~SharpFormat()
345{ 345{
346} 346}
347ulong SharpFormat::getCsum( const QStringList & attList) 347ulong SharpFormat::getCsum( const QStringList & attList)
348{ 348{
349 int max = attList.count() -1; 349 int max = attList.count() -1;
350 ulong cSum = 0; 350 ulong cSum = 0;
351 int j,k,i; 351 int j,k,i;
352 int add; 352 int add;
353 for ( i = 1; i < max ; ++i ) { 353 for ( i = 1; i < max ; ++i ) {
354 QString s = attList[i]; 354 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
356 j = s.length(); 356 j = s.length();
357 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 358 int mul = k +1;
359 add = s[k].unicode (); 359 add = s[k].unicode ();
360 if ( k < 16 ) 360 if ( k < 16 )
361 mul = mul * mul; 361 mul = mul * mul;
362 add = add * mul *i*i*i; 362 add = add * mul *i*i*i;
363 cSum += add; 363 cSum += add;
364 } 364 }
365 } 365 }
366 } 366 }
367 return cSum; 367 return cSum;
368 368
369} 369}
370#include <stdlib.h> 370#include <stdlib.h>
371#define DEBUGMODE false 371#define DEBUGMODE false
372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
373{ 373{
374 374
375 375
376 bool debug = DEBUGMODE; 376 bool debug = DEBUGMODE;
377 //debug = true; 377 //debug = true;
378 QString text; 378 QString text;
379 QString codec = "utf8"; 379 QString codec = "utf8";
380 QLabel status ( i18n("Reading events ..."), 0 ); 380 QLabel status ( i18n("Reading events ..."), 0 );
381 381
382 int w = status.sizeHint().width()+20 ; 382 int w = status.sizeHint().width()+20 ;
383 if ( w < 200 ) w = 200; 383 if ( w < 200 ) w = 200;
384 int h = status.sizeHint().height()+20 ; 384 int h = status.sizeHint().height()+20 ;
385 int dw = QApplication::desktop()->width(); 385 int dw = QApplication::desktop()->width();
386 int dh = QApplication::desktop()->height(); 386 int dh = QApplication::desktop()->height();
387 status.setCaption(i18n("Reading DTM Data") ); 387 status.setCaption(i18n("Reading DTM Data") );
388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
389 status.show(); 389 status.show();
390 status.raise(); 390 status.raise();
391 qApp->processEvents(); 391 qApp->processEvents();
392 QString fileName; 392 QString fileName;
393 if ( ! debug ) { 393 if ( ! debug ) {
394 fileName = "/tmp/kopitempout"; 394 fileName = "/tmp/kopitempout";
395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
396 system ( command.latin1() ); 396 system ( command.latin1() );
397 } else { 397 } else {
398 fileName = "/tmp/events.txt"; 398 fileName = "/tmp/events.txt";
399 399
400 } 400 }
401 QFile file( fileName ); 401 QFile file( fileName );
402 if (!file.open( IO_ReadOnly ) ) { 402 if (!file.open( IO_ReadOnly ) ) {
403 return false; 403 return false;
404 404
405 } 405 }
406 QTextStream ts( &file ); 406 QTextStream ts( &file );
407 ts.setCodec( QTextCodec::codecForName("utf8") ); 407 ts.setCodec( QTextCodec::codecForName("utf8") );
408 text = ts.read(); 408 text = ts.read();
409 file.close(); 409 file.close();
410 status.setText( i18n("Processing events ...") ); 410 status.setText( i18n("Processing events ...") );
411 status.raise(); 411 status.raise();
412 qApp->processEvents(); 412 qApp->processEvents();
413 fromString2Cal( calendar, existngCal, text, "Event" ); 413 fromString2Cal( calendar, existngCal, text, "Event" );
414 status.setText( i18n("Reading todos ...") ); 414 status.setText( i18n("Reading todos ...") );
415 qApp->processEvents(); 415 qApp->processEvents();
416 if ( ! debug ) { 416 if ( ! debug ) {
417 fileName = "/tmp/kopitempout"; 417 fileName = "/tmp/kopitempout";
418 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 418 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
419 system ( command.latin1() ); 419 system ( command.latin1() );
420 } else { 420 } else {
421 fileName = "/tmp/todo.txt"; 421 fileName = "/tmp/todo.txt";
422 } 422 }
423 file.setName( fileName ); 423 file.setName( fileName );
424 if (!file.open( IO_ReadOnly ) ) { 424 if (!file.open( IO_ReadOnly ) ) {
425 return false; 425 return false;
426 426
427 } 427 }
428 ts.setDevice( &file ); 428 ts.setDevice( &file );
429 text = ts.read(); 429 text = ts.read();
430 file.close(); 430 file.close();
431 431
432 status.setText( i18n("Processing todos ...") ); 432 status.setText( i18n("Processing todos ...") );
433 status.raise(); 433 status.raise();
434 qApp->processEvents(); 434 qApp->processEvents();
435 fromString2Cal( calendar, existngCal, text, "Todo" ); 435 fromString2Cal( calendar, existngCal, text, "Todo" );
436 return true; 436 return true;
437} 437}
438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
439{ 439{
440 int retval = -1; 440 int retval = -1;
441 QStringList templist; 441 QStringList templist;
442 QString tempString; 442 QString tempString;
443 int start = 0; 443 int start = 0;
444 int len = answer.length(); 444 int len = answer.length();
445 int end = answer.find ("\n",start)+1; 445 int end = answer.find ("\n",start)+1;
446 bool ok = true; 446 bool ok = true;
447 start = end; 447 start = end;
448 int ccc = 0; 448 int ccc = 0;
449 while ( start > 0 ) { 449 while ( start > 0 ) {
450 templist.clear(); 450 templist.clear();
451 ok = true; 451 ok = true;
452 int loopCount = 0; 452 int loopCount = 0;
453 while ( ok ) { 453 while ( ok ) {
454 ++loopCount; 454 ++loopCount;
455 if ( loopCount > 25 ) { 455 if ( loopCount > 25 ) {
456 qDebug("KO: Error in while loop"); 456 qDebug("KO: Error in while loop");
457 ok = false; 457 ok = false;
458 start = 0; 458 start = 0;
459 break; 459 break;
460 } 460 }
461 if ( ok ) 461 if ( ok )
462 tempString = getPart( answer, ok, start ); 462 tempString = getPart( answer, ok, start );
463 if ( start >= len || start == 0 ) { 463 if ( start >= len || start == 0 ) {
464 start = 0; 464 start = 0;
465 ok = false; 465 ok = false;
466 } 466 }
467 if ( tempString.right(1) =="\n" ) 467 if ( tempString.right(1) =="\n" )
468 tempString = tempString.left( tempString.length()-1); 468 tempString = tempString.left( tempString.length()-1);
469 469
470 templist.append( tempString ); 470 templist.append( tempString );
471 } 471 }
472 ++ccc; 472 ++ccc;
473 if ( ccc == 2 && loopCount < 25 ) { 473 if ( ccc == 2 && loopCount < 25 ) {
474 start = 0; 474 start = 0;
475 bool ok; 475 bool ok;
476 int newnum = templist[0].toInt( &ok ); 476 int newnum = templist[0].toInt( &ok );
477 if ( ok && newnum > 0) { 477 if ( ok && newnum > 0) {
478 retval = newnum; 478 retval = newnum;
479 inc->setID( "Sharp_DTM",templist[0] ); 479 inc->setID( "Sharp_DTM",templist[0] );
480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
482 } 482 }
483 } 483 }
484 } 484 }
485 //qDebug("getNumFromRecord returning : %d ", retval); 485 //qDebug("getNumFromRecord returning : %d ", retval);
486 return retval; 486 return retval;
487} 487}
488bool SharpFormat::save( Calendar *calendar) 488bool SharpFormat::save( Calendar *calendar)
489{ 489{
490 490
491 QLabel status ( i18n("Processing/adding events ..."), 0 ); 491 QLabel status ( i18n("Processing/adding events ..."), 0 );
492 int w = status.sizeHint().width()+20 ; 492 int w = status.sizeHint().width()+20 ;
493 if ( w < 200 ) w = 200; 493 if ( w < 200 ) w = 200;
494 int h = status.sizeHint().height()+20 ; 494 int h = status.sizeHint().height()+20 ;
495 int dw = QApplication::desktop()->width(); 495 int dw = QApplication::desktop()->width();
496 int dh = QApplication::desktop()->height(); 496 int dh = QApplication::desktop()->height();
497 status.setCaption(i18n("Writing DTM Data") ); 497 status.setCaption(i18n("Writing DTM Data") );
498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
499 status.show(); 499 status.show();
500 status.raise(); 500 status.raise();
501 qApp->processEvents(); 501 qApp->processEvents();
502 bool debug = DEBUGMODE; 502 bool debug = DEBUGMODE;
503 QString codec = "utf8"; 503 QString codec = "utf8";
504 QString answer; 504 QString answer;
505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
507 QString command; 507 QString command;
508 QPtrList<Event> er = calendar->rawEvents(); 508 QPtrList<Event> er = calendar->rawEvents();
509 Event* ev = er.first(); 509 Event* ev = er.first();
510 QString fileName = "/tmp/kopitempout"; 510 QString fileName = "/tmp/kdepimtempfile";
511 int i = 0; 511 int i = 0;
512 QString changeString = ePrefix; 512 QString changeString = ePrefix;
513 QString deleteString = ePrefix; 513 QString deleteString = ePrefix;
514 bool deleteEnt = false; 514 bool deleteEnt = false;
515 bool changeEnt = false; 515 bool changeEnt = false;
516 QString message = i18n("Processing event # "); 516 QString message = i18n("Processing event # ");
517 int procCount = 0; 517 int procCount = 0;
518 while ( ev ) { 518 while ( ev ) {
519 //qDebug("i %d ", ++i); 519 //qDebug("i %d ", ++i);
520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
521 status.setText ( message + QString::number ( ++procCount ) ); 521 status.setText ( message + QString::number ( ++procCount ) );
522 qApp->processEvents(); 522 qApp->processEvents();
523 QString eString = getEventString( ev ); 523 QString eString = getEventString( ev );
524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
525 // deleting empty strings does not work. 525 // deleting empty strings does not work.
526 // we write first and x and then delete the record with the x 526 // we write first and x and then delete the record with the x
527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
528 changeString += eString + "\n"; 528 changeString += eString + "\n";
529 deleteString += eString + "\n"; 529 deleteString += eString + "\n";
530 deleteEnt = true; 530 deleteEnt = true;
531 changeEnt = true; 531 changeEnt = true;
532 } 532 }
533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
535 system ( command.utf8() ); 535 system ( command.utf8() );
536 QFile file( fileName ); 536 QFile file( fileName );
537 if (!file.open( IO_ReadOnly ) ) { 537 if (!file.open( IO_ReadOnly ) ) {
538 return false; 538 return false;
539 539
540 } 540 }
541 QTextStream ts( &file ); 541 QTextStream ts( &file );
542 ts.setCodec( QTextCodec::codecForName("utf8") ); 542 ts.setCodec( QTextCodec::codecForName("utf8") );
543 answer = ts.read(); 543 answer = ts.read();
544 file.close(); 544 file.close();
545 //qDebug("answer \n%s ", answer.latin1()); 545 //qDebug("answer \n%s ", answer.latin1());
546 getNumFromRecord( answer, ev ) ; 546 getNumFromRecord( answer, ev ) ;
547 547
548 } 548 }
549 else { // change existing 549 else { // change existing
550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
552 changeString += eString + "\n"; 552 changeString += eString + "\n";
553 changeEnt = true; 553 changeEnt = true;
554 554
555 } 555 }
556 } 556 }
557 ev = er.next(); 557 ev = er.next();
558 } 558 }
559 status.setText ( i18n("Changing events ...") ); 559 status.setText ( i18n("Changing events ...") );
560 qApp->processEvents(); 560 qApp->processEvents();
561 //qDebug("changing... "); 561 //qDebug("changing... ");
562 if ( changeEnt ) { 562 if ( changeEnt ) {
563 QFile file( fileName ); 563 QFile file( fileName );
564 if (!file.open( IO_WriteOnly ) ) { 564 if (!file.open( IO_WriteOnly ) ) {
565 return false; 565 return false;
566 566
567 } 567 }
568 QTextStream ts( &file ); 568 QTextStream ts( &file );
569 ts.setCodec( QTextCodec::codecForName("utf8") ); 569 ts.setCodec( QTextCodec::codecForName("utf8") );
570 ts << changeString ; 570 ts << changeString ;
571 file.close(); 571 file.close();
572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
573 system ( command.latin1() ); 573 system ( command.latin1() );
574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
575 575
576 } 576 }
577 status.setText ( i18n("Deleting events ...") ); 577 status.setText ( i18n("Deleting events ...") );
578 qApp->processEvents(); 578 qApp->processEvents();
579 //qDebug("deleting... "); 579 //qDebug("deleting... ");
580 if ( deleteEnt ) { 580 if ( deleteEnt ) {
581 QFile file( fileName ); 581 QFile file( fileName );
582 if (!file.open( IO_WriteOnly ) ) { 582 if (!file.open( IO_WriteOnly ) ) {
583 return false; 583 return false;
584 584
585 } 585 }
586 QTextStream ts( &file ); 586 QTextStream ts( &file );
587 ts.setCodec( QTextCodec::codecForName("utf8") ); 587 ts.setCodec( QTextCodec::codecForName("utf8") );
588 ts << deleteString; 588 ts << deleteString;
589 file.close(); 589 file.close();
590 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 590 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
591 system ( command.latin1() ); 591 system ( command.latin1() );
592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
593 } 593 }
594 594
595 595
596 changeString = tPrefix; 596 changeString = tPrefix;
597 deleteString = tPrefix; 597 deleteString = tPrefix;
598 status.setText ( i18n("Processing todos ...") ); 598 status.setText ( i18n("Processing todos ...") );
599 qApp->processEvents(); 599 qApp->processEvents();
600 QPtrList<Todo> tl = calendar->rawTodos(); 600 QPtrList<Todo> tl = calendar->rawTodos();
601 Todo* to = tl.first(); 601 Todo* to = tl.first();
602 i = 0; 602 i = 0;
603 message = i18n("Processing todo # "); 603 message = i18n("Processing todo # ");
604 procCount = 0; 604 procCount = 0;
605 while ( to ) { 605 while ( to ) {
606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
607 status.setText ( message + QString::number ( ++procCount ) ); 607 status.setText ( message + QString::number ( ++procCount ) );
608 qApp->processEvents(); 608 qApp->processEvents();
609 QString eString = getTodoString( to ); 609 QString eString = getTodoString( to );
610 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 610 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
611 // deleting empty strings does not work. 611 // deleting empty strings does not work.
612 // we write first and x and then delete the record with the x 612 // we write first and x and then delete the record with the x
613 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 613 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
614 changeString += eString + "\n"; 614 changeString += eString + "\n";
615 deleteString += eString + "\n"; 615 deleteString += eString + "\n";
616 deleteEnt = true; 616 deleteEnt = true;
617 changeEnt = true; 617 changeEnt = true;
618 } 618 }
619 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 619 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
620 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 620 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
621 system ( command.utf8() ); 621 system ( command.utf8() );
622 QFile file( fileName ); 622 QFile file( fileName );
623 if (!file.open( IO_ReadOnly ) ) { 623 if (!file.open( IO_ReadOnly ) ) {
624 return false; 624 return false;
625 625
626 } 626 }
627 QTextStream ts( &file ); 627 QTextStream ts( &file );
628 ts.setCodec( QTextCodec::codecForName("utf8") ); 628 ts.setCodec( QTextCodec::codecForName("utf8") );
629 answer = ts.read(); 629 answer = ts.read();
630 file.close(); 630 file.close();
631 //qDebug("answer \n%s ", answer.latin1()); 631 //qDebug("answer \n%s ", answer.latin1());
632 getNumFromRecord( answer, to ) ; 632 getNumFromRecord( answer, to ) ;
633 633
634 } 634 }
635 else { // change existing 635 else { // change existing
636 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 636 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
637 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 637 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
638 changeString += eString + "\n"; 638 changeString += eString + "\n";
639 changeEnt = true; 639 changeEnt = true;
640 640
641 } 641 }
642 } 642 }
643 643
644 to = tl.next(); 644 to = tl.next();
645 } 645 }
646 status.setText ( i18n("Changing todos ...") ); 646 status.setText ( i18n("Changing todos ...") );
647 qApp->processEvents(); 647 qApp->processEvents();
648 //qDebug("changing... "); 648 //qDebug("changing... ");
649 if ( changeEnt ) { 649 if ( changeEnt ) {
650 QFile file( fileName ); 650 QFile file( fileName );
651 if (!file.open( IO_WriteOnly ) ) { 651 if (!file.open( IO_WriteOnly ) ) {
652 return false; 652 return false;
653 653
654 } 654 }
655 QTextStream ts( &file ); 655 QTextStream ts( &file );
656 ts.setCodec( QTextCodec::codecForName("utf8") ); 656 ts.setCodec( QTextCodec::codecForName("utf8") );
657 ts << changeString ; 657 ts << changeString ;
658 file.close(); 658 file.close();
659 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 659 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
660 system ( command.latin1() ); 660 system ( command.latin1() );
661 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 661 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
662 662
663 } 663 }
664 status.setText ( i18n("Deleting todos ...") ); 664 status.setText ( i18n("Deleting todos ...") );
665 qApp->processEvents(); 665 qApp->processEvents();
666 //qDebug("deleting... "); 666 //qDebug("deleting... ");
667 if ( deleteEnt ) { 667 if ( deleteEnt ) {
668 QFile file( fileName ); 668 QFile file( fileName );
669 if (!file.open( IO_WriteOnly ) ) { 669 if (!file.open( IO_WriteOnly ) ) {
670 return false; 670 return false;
671 671
672 } 672 }
673 QTextStream ts( &file ); 673 QTextStream ts( &file );
674 ts.setCodec( QTextCodec::codecForName("utf8") ); 674 ts.setCodec( QTextCodec::codecForName("utf8") );
675 ts << deleteString; 675 ts << deleteString;
676 file.close(); 676 file.close();
677 command = "db2file todo -d -c " + codec+ " < "+ fileName; 677 command = "db2file todo -d -c " + codec+ " < "+ fileName;
678 system ( command.latin1() ); 678 system ( command.latin1() );
679 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 679 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
680 } 680 }
681 681
682 return true; 682 return true;
683} 683}
684QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 684QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
685{ 685{
686 QString datestr; 686 QString datestr;
687 QString timestr; 687 QString timestr;
688 int offset = KGlobal::locale()->localTimeOffset( dti ); 688 int offset = KGlobal::locale()->localTimeOffset( dti );
689 QDateTime dt; 689 QDateTime dt;
690 if (useTZ) 690 if (useTZ)
691 dt = dti.addSecs ( -(offset*60)); 691 dt = dti.addSecs ( -(offset*60));
692 else 692 else
693 dt = dti; 693 dt = dti;
694 if(dt.date().isValid()){ 694 if(dt.date().isValid()){
695 const QDate& date = dt.date(); 695 const QDate& date = dt.date();
696 datestr.sprintf("%04d%02d%02d", 696 datestr.sprintf("%04d%02d%02d",
697 date.year(), date.month(), date.day()); 697 date.year(), date.month(), date.day());
698 } 698 }
699 if(dt.time().isValid()){ 699 if(dt.time().isValid()){
700 const QTime& time = dt.time(); 700 const QTime& time = dt.time();
701 timestr.sprintf("T%02d%02d%02d", 701 timestr.sprintf("T%02d%02d%02d",
702 time.hour(), time.minute(), time.second()); 702 time.hour(), time.minute(), time.second());
703 } 703 }
704 return datestr + timestr; 704 return datestr + timestr;
705} 705}
706QString SharpFormat::getEventString( Event* event ) 706QString SharpFormat::getEventString( Event* event )
707{ 707{
708 QStringList list; 708 QStringList list;
709 list.append( event->getID("Sharp_DTM") ); 709 list.append( event->getID("Sharp_DTM") );
710 list.append( event->categories().join(",") ); 710 list.append( event->categories().join(",") );
711 if ( !event->summary().isEmpty() ) 711 if ( !event->summary().isEmpty() )
712 list.append( event->summary() ); 712 list.append( event->summary() );
713 else 713 else
714 list.append("" ); 714 list.append("" );
715 if ( !event->location().isEmpty() ) 715 if ( !event->location().isEmpty() )
716 list.append( event->location() ); 716 list.append( event->location() );
717 else 717 else
718 list.append("" ); 718 list.append("" );
719 if ( !event->description().isEmpty() ) 719 if ( !event->description().isEmpty() )
720 list.append( event->description() ); 720 list.append( event->description() );
721 else 721 else
722 list.append( "" ); 722 list.append( "" );
723 if ( event->doesFloat () ) { 723 if ( event->doesFloat () ) {
724 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 724 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
725 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 725 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
726 list.append( "1" ); 726 list.append( "1" );
727 727
728 } 728 }
729 else { 729 else {
730 list.append( dtToString( event->dtStart()) ); 730 list.append( dtToString( event->dtStart()) );
731 list.append( dtToString( event->dtEnd()) ); //6 731 list.append( dtToString( event->dtEnd()) ); //6
732 list.append( "0" ); 732 list.append( "0" );
733 } 733 }
734 bool noAlarm = true; 734 bool noAlarm = true;
735 if ( event->alarms().count() > 0 ) { 735 if ( event->alarms().count() > 0 ) {
736 Alarm * al = event->alarms().first(); 736 Alarm * al = event->alarms().first();
737 if ( al->enabled() ) { 737 if ( al->enabled() ) {
738 noAlarm = false; 738 noAlarm = false;
739 list.append( "0" ); // yes, 0 == alarm 739 list.append( "0" ); // yes, 0 == alarm
740 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 740 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
741 if ( al->type() == Alarm::Audio ) 741 if ( al->type() == Alarm::Audio )
742 list.append( "1" ); // type audio 742 list.append( "1" ); // type audio
743 else 743 else
744 list.append( "0" ); // type silent 744 list.append( "0" ); // type silent
745 } 745 }
746 } 746 }
747 if ( noAlarm ) { 747 if ( noAlarm ) {
748 list.append( "1" ); // yes, 1 == no alarm 748 list.append( "1" ); // yes, 1 == no alarm
749 list.append( "0" ); // no alarm offset 749 list.append( "0" ); // no alarm offset
750 list.append( "1" ); // type 750 list.append( "1" ); // type
751 } 751 }
752 // next is: 11 752 // next is: 11
753 // next is: 11-16 are recurrence 753 // next is: 11-16 are recurrence
754 Recurrence* rec = event->recurrence(); 754 Recurrence* rec = event->recurrence();
755 755
756 bool writeEndDate = false; 756 bool writeEndDate = false;
757 switch ( rec->doesRecur() ) 757 switch ( rec->doesRecur() )
758 { 758 {
759 case Recurrence::rDaily: // 0 759 case Recurrence::rDaily: // 0
760 list.append( "0" ); 760 list.append( "0" );
761 list.append( QString::number( rec->frequency() ));//12 761 list.append( QString::number( rec->frequency() ));//12
762 list.append( "0" ); 762 list.append( "0" );
763 list.append( "0" ); 763 list.append( "0" );
764 writeEndDate = true; 764 writeEndDate = true;
765 break; 765 break;
766 case Recurrence::rWeekly:// 1 766 case Recurrence::rWeekly:// 1
767 list.append( "1" ); 767 list.append( "1" );
768 list.append( QString::number( rec->frequency()) );//12 768 list.append( QString::number( rec->frequency()) );//12
769 list.append( "0" ); 769 list.append( "0" );
770 { 770 {
771 int days = 0; 771 int days = 0;
772 QBitArray weekDays = rec->days(); 772 QBitArray weekDays = rec->days();
773 int i; 773 int i;
774 for( i = 1; i <= 7; ++i ) { 774 for( i = 1; i <= 7; ++i ) {
775 if ( weekDays[i-1] ) { 775 if ( weekDays[i-1] ) {
776 days += 1 << (i-1); 776 days += 1 << (i-1);
777 } 777 }
778 } 778 }
779 list.append( QString::number( days ) ); 779 list.append( QString::number( days ) );
780 } 780 }
781 //pending weekdays 781 //pending weekdays
782 writeEndDate = true; 782 writeEndDate = true;
783 783
784 break; 784 break;
785 case Recurrence::rMonthlyPos:// 2 785 case Recurrence::rMonthlyPos:// 2
786 list.append( "2" ); 786 list.append( "2" );
787 list.append( QString::number( rec->frequency()) );//12 787 list.append( QString::number( rec->frequency()) );//12
788 788
789 writeEndDate = true; 789 writeEndDate = true;
790 { 790 {
791 int count = 1; 791 int count = 1;
792 QPtrList<Recurrence::rMonthPos> rmp; 792 QPtrList<Recurrence::rMonthPos> rmp;
793 rmp = rec->monthPositions(); 793 rmp = rec->monthPositions();
794 if ( rmp.first()->negative ) 794 if ( rmp.first()->negative )
795 count = 5 - rmp.first()->rPos - 1; 795 count = 5 - rmp.first()->rPos - 1;
796 else 796 else
797 count = rmp.first()->rPos - 1; 797 count = rmp.first()->rPos - 1;
798 list.append( QString::number( count ) ); 798 list.append( QString::number( count ) );
799 799
800 } 800 }
801 801
802 list.append( "0" ); 802 list.append( "0" );
803 break; 803 break;
804 case Recurrence::rMonthlyDay:// 3 804 case Recurrence::rMonthlyDay:// 3
805 list.append( "3" ); 805 list.append( "3" );
806 list.append( QString::number( rec->frequency()) );//12 806 list.append( QString::number( rec->frequency()) );//12
807 list.append( "0" ); 807 list.append( "0" );
808 list.append( "0" ); 808 list.append( "0" );
809 writeEndDate = true; 809 writeEndDate = true;
810 break; 810 break;
811 case Recurrence::rYearlyMonth://4 811 case Recurrence::rYearlyMonth://4
812 list.append( "4" ); 812 list.append( "4" );
813 list.append( QString::number( rec->frequency()) );//12 813 list.append( QString::number( rec->frequency()) );//12
814 list.append( "0" ); 814 list.append( "0" );
815 list.append( "0" ); 815 list.append( "0" );
816 writeEndDate = true; 816 writeEndDate = true;
817 break; 817 break;
818 818
819 default: 819 default:
820 list.append( "255" ); 820 list.append( "255" );
821 list.append( QString() ); 821 list.append( QString() );
822 list.append( "0" ); 822 list.append( "0" );
823 list.append( QString() ); 823 list.append( QString() );
824 list.append( "0" ); 824 list.append( "0" );
825 list.append( "20991231T000000" ); 825 list.append( "20991231T000000" );
826 break; 826 break;
827 } 827 }
828 if ( writeEndDate ) { 828 if ( writeEndDate ) {
829 829
830 if ( rec->endDate().isValid() ) { // 15 + 16 830 if ( rec->endDate().isValid() ) { // 15 + 16
831 list.append( "1" ); 831 list.append( "1" );
832 list.append( dtToString( rec->endDate()) ); 832 list.append( dtToString( rec->endDate()) );
833 } else { 833 } else {
834 list.append( "0" ); 834 list.append( "0" );
835 list.append( "20991231T000000" ); 835 list.append( "20991231T000000" );
836 } 836 }
837 837
838 } 838 }
839 if ( event->doesFloat () ) { 839 if ( event->doesFloat () ) {
840 list.append( dtToString( event->dtStart(), false ).left( 8 )); 840 list.append( dtToString( event->dtStart(), false ).left( 8 ));
841 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 841 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
842 842
843 } 843 }
844 else { 844 else {
845 list.append( QString() ); 845 list.append( QString() );
846 list.append( QString() ); 846 list.append( QString() );
847 847
848 } 848 }
849 if (event->dtStart().date() == event->dtEnd().date() ) 849 if (event->dtStart().date() == event->dtEnd().date() )
850 list.append( "0" ); 850 list.append( "0" );
851 else 851 else
852 list.append( "1" ); 852 list.append( "1" );
853 853
854 854
855 for(QStringList::Iterator it=list.begin(); 855 for(QStringList::Iterator it=list.begin();
856 it!=list.end(); ++it){ 856 it!=list.end(); ++it){
857 QString& s = (*it); 857 QString& s = (*it);
858 s.replace(QRegExp("\""), "\"\""); 858 s.replace(QRegExp("\""), "\"\"");
859 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 859 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
860 s.prepend('\"'); 860 s.prepend('\"');
861 s.append('\"'); 861 s.append('\"');
862 } else if(s.isEmpty() && !s.isNull()){ 862 } else if(s.isEmpty() && !s.isNull()){
863 s = "\"\""; 863 s = "\"\"";
864 } 864 }
865 } 865 }
866 return list.join(","); 866 return list.join(",");
867 867
868 868
869} 869}
870QString SharpFormat::getTodoString( Todo* todo ) 870QString SharpFormat::getTodoString( Todo* todo )
871{ 871{
872 QStringList list; 872 QStringList list;
873 list.append( todo->getID("Sharp_DTM") ); 873 list.append( todo->getID("Sharp_DTM") );
874 list.append( todo->categories().join(",") ); 874 list.append( todo->categories().join(",") );
875 875
876 if ( todo->hasStartDate() ) { 876 if ( todo->hasStartDate() ) {
877 list.append( dtToString( todo->dtStart()) ); 877 list.append( dtToString( todo->dtStart()) );
878 } else 878 } else
879 list.append( QString() ); 879 list.append( QString() );
880 880
881 if ( todo->hasDueDate() ) { 881 if ( todo->hasDueDate() ) {
882 QTime tim; 882 QTime tim;
883 if ( todo->doesFloat()) { 883 if ( todo->doesFloat()) {
884 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 884 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
885 } else { 885 } else {
886 list.append( dtToString(todo->dtDue() ) ); 886 list.append( dtToString(todo->dtDue() ) );
887 } 887 }
888 } else 888 } else
889 list.append( QString() ); 889 list.append( QString() );
890 890
891 if ( todo->isCompleted() ) { 891 if ( todo->isCompleted() ) {
892 list.append( dtToString( todo->completed()) ); 892 list.append( dtToString( todo->completed()) );
893 list.append( "0" ); // yes 0 == completed 893 list.append( "0" ); // yes 0 == completed
894 } else { 894 } else {
895 list.append( dtToString( todo->completed()) ); 895 list.append( dtToString( todo->completed()) );
896 list.append( "1" ); 896 list.append( "1" );
897 } 897 }
898 list.append( QString::number( todo->priority() )); 898 list.append( QString::number( todo->priority() ));
899 if( ! todo->summary().isEmpty() ) 899 if( ! todo->summary().isEmpty() )
900 list.append( todo->summary() ); 900 list.append( todo->summary() );
901 else 901 else
902 list.append( "" ); 902 list.append( "" );
903 if (! todo->description().isEmpty() ) 903 if (! todo->description().isEmpty() )
904 list.append( todo->description() ); 904 list.append( todo->description() );
905 else 905 else
906 list.append( "" ); 906 list.append( "" );
907 for(QStringList::Iterator it=list.begin(); 907 for(QStringList::Iterator it=list.begin();
908 it!=list.end(); ++it){ 908 it!=list.end(); ++it){
909 QString& s = (*it); 909 QString& s = (*it);
910 s.replace(QRegExp("\""), "\"\""); 910 s.replace(QRegExp("\""), "\"\"");
911 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 911 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
912 s.prepend('\"'); 912 s.prepend('\"');
913 s.append('\"'); 913 s.append('\"');
914 } else if(s.isEmpty() && !s.isNull()){ 914 } else if(s.isEmpty() && !s.isNull()){
915 s = "\"\""; 915 s = "\"\"";
916 } 916 }
917 } 917 }
918 return list.join(","); 918 return list.join(",");
919} 919}
920QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) 920QString SharpFormat::getPart( const QString & text, bool &ok, int &start )
921{ 921{
922 //qDebug("start %d ", start); 922 //qDebug("start %d ", start);
923 923
924 QString retval =""; 924 QString retval ="";
925 if ( text.at(start) == '"' ) { 925 if ( text.at(start) == '"' ) {
926 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { 926 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
927 start = start +2; 927 start = start +2;
928 if ( text.mid( start,1) == "," ) { 928 if ( text.mid( start,1) == "," ) {
929 start += 1; 929 start += 1;
930 } 930 }
931 retval = ""; 931 retval = "";
932 if ( text.mid( start,1) == "\n" ) { 932 if ( text.mid( start,1) == "\n" ) {
933 start += 1; 933 start += 1;
934 ok = false; 934 ok = false;
935 } 935 }
936 return retval; 936 return retval;
937 } 937 }
938 int hk = start+1; 938 int hk = start+1;
939 hk = text.find ('"',hk); 939 hk = text.find ('"',hk);
940 while ( text.at(hk+1) == '"' ) 940 while ( text.at(hk+1) == '"' )
941 hk = text.find ('"',hk+2); 941 hk = text.find ('"',hk+2);
942 retval = text.mid( start+1, hk-start-1); 942 retval = text.mid( start+1, hk-start-1);
943 start = hk+1; 943 start = hk+1;
944 retval.replace( QRegExp("\"\""), "\""); 944 retval.replace( QRegExp("\"\""), "\"");
945 if ( text.mid( start,1) == "," ) { 945 if ( text.mid( start,1) == "," ) {
946 start += 1; 946 start += 1;
947 } 947 }
948 if ( text.mid( start,1) == "\n" ) { 948 if ( text.mid( start,1) == "\n" ) {
949 start += 1; 949 start += 1;
950 ok = false; 950 ok = false;
951 } 951 }
952 //qDebug("retval***%s*** ",retval.latin1() ); 952 //qDebug("retval***%s*** ",retval.latin1() );
953 return retval; 953 return retval;
954 954
955 } else { 955 } else {
956 int nl = text.find ("\n",start); 956 int nl = text.find ("\n",start);
957 int kom = text.find (',',start); 957 int kom = text.find (',',start);
958 if ( kom < nl ) { 958 if ( kom < nl ) {
959 // qDebug("kom < nl %d ", kom); 959 // qDebug("kom < nl %d ", kom);
960 retval = text.mid(start, kom-start); 960 retval = text.mid(start, kom-start);
961 start = kom+1; 961 start = kom+1;
962 return retval; 962 return retval;
963 } else { 963 } else {
964 if ( nl == kom ) { 964 if ( nl == kom ) {
965 // qDebug(" nl == kom "); 965 // qDebug(" nl == kom ");
966 start = 0; 966 start = 0;
967 ok = false; 967 ok = false;
968 return "0"; 968 return "0";
969 } 969 }
970 // qDebug(" nl < kom ", nl); 970 // qDebug(" nl < kom ", nl);
971 retval = text.mid( start, nl-start); 971 retval = text.mid( start, nl-start);
972 ok = false; 972 ok = false;
973 start = nl+1; 973 start = nl+1;
974 return retval; 974 return retval;
975 } 975 }
976 } 976 }
977} 977}
978bool SharpFormat::fromString( Calendar *calendar, const QString & text) 978bool SharpFormat::fromString( Calendar *calendar, const QString & text)
979{ 979{
980 return false; 980 return false;
981} 981}
982bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 982bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
983{ 983{
984 // qDebug("test %s ", text.latin1()); 984 // qDebug("test %s ", text.latin1());
985 QStringList templist; 985 QStringList templist;
986 QString tempString; 986 QString tempString;
987 int start = 0; 987 int start = 0;
988 int len = text.length(); 988 int len = text.length();
989 int end = text.find ("\n",start)+1; 989 int end = text.find ("\n",start)+1;
990 bool ok = true; 990 bool ok = true;
991 start = end; 991 start = end;
992 SharpParser handler( calendar ); 992 SharpParser handler( calendar );
993 handler.setCategoriesList( mCategories ); 993 handler.setCategoriesList( mCategories );
994 while ( start > 0 ) { 994 while ( start > 0 ) {
995 templist.clear(); 995 templist.clear();
996 ok = true; 996 ok = true;
997 while ( ok ) { 997 while ( ok ) {
998 tempString = getPart( text, ok, start ); 998 tempString = getPart( text, ok, start );
999 if ( start >= len || start == 0 ) { 999 if ( start >= len || start == 0 ) {
1000 start = 0; 1000 start = 0;
1001 ok = false; 1001 ok = false;
1002 } 1002 }
1003 if ( tempString.right(1) =="\n" ) 1003 if ( tempString.right(1) =="\n" )
1004 tempString = tempString.left( tempString.length()-1); 1004 tempString = tempString.left( tempString.length()-1);
1005 //if ( ok ) 1005 //if ( ok )
1006 templist.append( tempString ); 1006 templist.append( tempString );
1007 //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); 1007 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
1008 } 1008 }
1009 handler.startElement( existingCalendar, templist, type ); 1009 handler.startElement( existingCalendar, templist, type );
1010 } 1010 }
1011 1011
1012 return false; 1012 return false;
1013} 1013}
1014 1014
1015QString SharpFormat::toString( Calendar * ) 1015QString SharpFormat::toString( Calendar * )
1016{ 1016{
1017 return QString::null; 1017 return QString::null;
1018} 1018}
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 076cd3f..9307f12 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,1700 +1,1705 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brwon 3 Copyright (c) 1998 Preston Brwon
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kmessagebox.h> 32#include <kmessagebox.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <klocale.h> 34#include <klocale.h>
35 35
36#include "vcc.h" 36#include "vcc.h"
37#include "vobject.h" 37#include "vobject.h"
38 38
39#include "vcaldrag.h" 39#include "vcaldrag.h"
40#include "calendar.h" 40#include "calendar.h"
41 41
42#include "vcalformat.h" 42#include "vcalformat.h"
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46VCalFormat::VCalFormat() 46VCalFormat::VCalFormat()
47{ 47{
48 mCalendar = 0; 48 mCalendar = 0;
49} 49}
50 50
51VCalFormat::~VCalFormat() 51VCalFormat::~VCalFormat()
52{ 52{
53} 53}
54 54
55bool VCalFormat::load(Calendar *calendar, const QString &fileName) 55bool VCalFormat::load(Calendar *calendar, const QString &fileName)
56{ 56{
57 mCalendar = calendar; 57 mCalendar = calendar;
58 58
59 clearException(); 59 clearException();
60 60
61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
62 62
63 VObject *vcal = 0; 63 VObject *vcal = 0;
64 64
65 // this is not necessarily only 1 vcal. Could be many vcals, or include 65 // this is not necessarily only 1 vcal. Could be many vcals, or include
66 // a vcard... 66 // a vcard...
67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
68 68
69 if (!vcal) { 69 if (!vcal) {
70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
71 return FALSE; 71 return FALSE;
72 } 72 }
73 73
74 // any other top-level calendar stuff should be added/initialized here 74 // any other top-level calendar stuff should be added/initialized here
75 75
76 // put all vobjects into their proper places 76 // put all vobjects into their proper places
77 populate(vcal); 77 populate(vcal);
78 78
79 // clean up from vcal API stuff 79 // clean up from vcal API stuff
80 cleanVObjects(vcal); 80 cleanVObjects(vcal);
81 cleanStrTbl(); 81 cleanStrTbl();
82 82
83 return true; 83 return true;
84} 84}
85 85
86 86
87bool VCalFormat::save(Calendar *calendar, const QString &fileName) 87bool VCalFormat::save(Calendar *calendar, const QString &fileName)
88{ 88{
89 mCalendar = calendar; 89 mCalendar = calendar;
90 90
91 QString tmpStr; 91 QString tmpStr;
92 VObject *vcal, *vo; 92 VObject *vcal, *vo;
93 93
94 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; 94 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
95 95
96 vcal = newVObject(VCCalProp); 96 vcal = newVObject(VCCalProp);
97 97
98 // addPropValue(vcal,VCLocationProp, "0.0"); 98 // addPropValue(vcal,VCLocationProp, "0.0");
99 addPropValue(vcal,VCProdIdProp, productId()); 99 addPropValue(vcal,VCProdIdProp, productId());
100 tmpStr = mCalendar->getTimeZoneStr(); 100 tmpStr = mCalendar->getTimeZoneStr();
101 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 101 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
102 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 102 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
103 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 103 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
104 104
105 // TODO STUFF 105 // TODO STUFF
106 QPtrList<Todo> todoList = mCalendar->rawTodos(); 106 QPtrList<Todo> todoList = mCalendar->rawTodos();
107 QPtrListIterator<Todo> qlt(todoList); 107 QPtrListIterator<Todo> qlt(todoList);
108 for (; qlt.current(); ++qlt) { 108 for (; qlt.current(); ++qlt) {
109 vo = eventToVTodo(qlt.current()); 109 vo = eventToVTodo(qlt.current());
110 addVObjectProp(vcal, vo); 110 addVObjectProp(vcal, vo);
111 } 111 }
112 112
113 // EVENT STUFF 113 // EVENT STUFF
114 QPtrList<Event> events = mCalendar->rawEvents(); 114 QPtrList<Event> events = mCalendar->rawEvents();
115 Event *ev; 115 Event *ev;
116 for(ev=events.first();ev;ev=events.next()) { 116 for(ev=events.first();ev;ev=events.next()) {
117 vo = eventToVEvent(ev); 117 vo = eventToVEvent(ev);
118 addVObjectProp(vcal, vo); 118 addVObjectProp(vcal, vo);
119 } 119 }
120 120
121 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 121 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
122 cleanVObjects(vcal); 122 cleanVObjects(vcal);
123 cleanStrTbl(); 123 cleanStrTbl();
124 124
125 if (QFile::exists(fileName)) { 125 if (QFile::exists(fileName)) {
126 kdDebug(5800) << "No error" << endl; 126 kdDebug(5800) << "No error" << endl;
127 return true; 127 return true;
128 } else { 128 } else {
129 kdDebug(5800) << "Error" << endl; 129 kdDebug(5800) << "Error" << endl;
130 return false; // error 130 return false; // error
131 } 131 }
132} 132}
133 133
134bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 134bool VCalFormat::fromString( Calendar *calendar, const QString &text )
135{ 135{
136 // TODO: Factor out VCalFormat::fromString() 136 // TODO: Factor out VCalFormat::fromString()
137 137
138 QCString data = text.utf8(); 138 QCString data = text.utf8();
139 139
140 if ( !data.size() ) return false; 140 if ( !data.size() ) return false;
141 141
142 VObject *vcal = Parse_MIME( data.data(), data.size()); 142 VObject *vcal = Parse_MIME( data.data(), data.size());
143 if ( !vcal ) return false; 143 if ( !vcal ) return false;
144 144
145 VObjectIterator i; 145 VObjectIterator i;
146 VObject *curvo; 146 VObject *curvo;
147 initPropIterator( &i, vcal ); 147 initPropIterator( &i, vcal );
148 148
149 // we only take the first object. TODO: parse all incidences. 149 // we only take the first object. TODO: parse all incidences.
150 do { 150 do {
151 curvo = nextVObject( &i ); 151 curvo = nextVObject( &i );
152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
153 strcmp( vObjectName( curvo ), VCTodoProp ) ); 153 strcmp( vObjectName( curvo ), VCTodoProp ) );
154 154
155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
156 Event *event = VEventToEvent( curvo ); 156 Event *event = VEventToEvent( curvo );
157 calendar->addEvent( event ); 157 calendar->addEvent( event );
158 } else { 158 } else {
159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
160 deleteVObject( vcal ); 160 deleteVObject( vcal );
161 return false; 161 return false;
162 } 162 }
163 163
164 deleteVObject( vcal ); 164 deleteVObject( vcal );
165 165
166 return true; 166 return true;
167} 167}
168 168
169QString VCalFormat::eventToString( Event * event, Calendar *calendar) 169QString VCalFormat::eventToString( Event * event, Calendar *calendar)
170{ 170{
171 if ( !event ) return QString::null; 171 if ( !event ) return QString::null;
172 mCalendar = calendar; 172 mCalendar = calendar;
173 VObject *vevent = eventToVEvent( event ); 173 VObject *vevent = eventToVEvent( event );
174 char *buf = writeMemVObject( 0, 0, vevent ); 174 char *buf = writeMemVObject( 0, 0, vevent );
175 QString result( buf ); 175 QString result( buf );
176 cleanVObject( vevent ); 176 cleanVObject( vevent );
177 return result; 177 return result;
178} 178}
179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar ) 179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar )
180{ 180{
181 if ( !todo ) return QString::null; 181 if ( !todo ) return QString::null;
182 mCalendar = calendar; 182 mCalendar = calendar;
183 VObject *vevent = eventToVTodo( todo ); 183 VObject *vevent = eventToVTodo( todo );
184 char *buf = writeMemVObject( 0, 0, vevent ); 184 char *buf = writeMemVObject( 0, 0, vevent );
185 QString result( buf ); 185 QString result( buf );
186 cleanVObject( vevent ); 186 cleanVObject( vevent );
187 return result; 187 return result;
188} 188}
189 189
190QString VCalFormat::toString( Calendar *calendar ) 190QString VCalFormat::toString( Calendar *calendar )
191{ 191{
192 // TODO: Factor out VCalFormat::asString() 192 // TODO: Factor out VCalFormat::asString()
193 193
194 VObject *vcal = newVObject(VCCalProp); 194 VObject *vcal = newVObject(VCCalProp);
195 195
196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
197 QString tmpStr = mCalendar->getTimeZoneStr(); 197 QString tmpStr = mCalendar->getTimeZoneStr();
198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
200 200
201 // TODO: Use all data. 201 // TODO: Use all data.
202 QPtrList<Event> events = calendar->events(); 202 QPtrList<Event> events = calendar->events();
203 Event *event = events.first(); 203 Event *event = events.first();
204 if ( !event ) return QString::null; 204 if ( !event ) return QString::null;
205 205
206 VObject *vevent = eventToVEvent( event ); 206 VObject *vevent = eventToVEvent( event );
207 207
208 addVObjectProp( vcal, vevent ); 208 addVObjectProp( vcal, vevent );
209 209
210 char *buf = writeMemVObject( 0, 0, vcal ); 210 char *buf = writeMemVObject( 0, 0, vcal );
211 211
212 QString result( buf ); 212 QString result( buf );
213 213
214 cleanVObject( vcal ); 214 cleanVObject( vcal );
215 215
216 return result; 216 return result;
217} 217}
218 218
219VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 219VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
220{ 220{
221 VObject *vtodo; 221 VObject *vtodo;
222 QString tmpStr; 222 QString tmpStr;
223 QStringList tmpStrList; 223 QStringList tmpStrList;
224 224
225 vtodo = newVObject(VCTodoProp); 225 vtodo = newVObject(VCTodoProp);
226 226
227 // due date 227 // due date
228 if (anEvent->hasDueDate()) { 228 if (anEvent->hasDueDate()) {
229 tmpStr = qDateTimeToISO(anEvent->dtDue(), 229 tmpStr = qDateTimeToISO(anEvent->dtDue(),
230 !anEvent->doesFloat()); 230 !anEvent->doesFloat());
231 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 231 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
232 } 232 }
233 233
234 // start date 234 // start date
235 if (anEvent->hasStartDate()) { 235 if (anEvent->hasStartDate()) {
236 tmpStr = qDateTimeToISO(anEvent->dtStart(), 236 tmpStr = qDateTimeToISO(anEvent->dtStart(),
237 !anEvent->doesFloat()); 237 !anEvent->doesFloat());
238 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 238 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
239 } 239 }
240 240
241 // creation date 241 // creation date
242 tmpStr = qDateTimeToISO(anEvent->created()); 242 tmpStr = qDateTimeToISO(anEvent->created());
243 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 243 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
244 244
245 // unique id 245 // unique id
246 addPropValue(vtodo, VCUniqueStringProp, 246 addPropValue(vtodo, VCUniqueStringProp,
247 anEvent->uid().local8Bit()); 247 anEvent->uid().local8Bit());
248 248
249 // revision 249 // revision
250 tmpStr.sprintf("%i", anEvent->revision()); 250 tmpStr.sprintf("%i", anEvent->revision());
251 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 251 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
252 252
253 // last modification date 253 // last modification date
254 tmpStr = qDateTimeToISO(anEvent->lastModified()); 254 tmpStr = qDateTimeToISO(anEvent->lastModified());
255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
256 256
257 // organizer stuff 257 // organizer stuff
258 tmpStr = "MAILTO:" + anEvent->organizer(); 258 tmpStr = "MAILTO:" + anEvent->organizer();
259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
260 260
261 // attendees 261 // attendees
262 if (anEvent->attendeeCount() != 0) { 262 if (anEvent->attendeeCount() != 0) {
263 QPtrList<Attendee> al = anEvent->attendees(); 263 QPtrList<Attendee> al = anEvent->attendees();
264 QPtrListIterator<Attendee> ai(al); 264 QPtrListIterator<Attendee> ai(al);
265 Attendee *curAttendee; 265 Attendee *curAttendee;
266 266
267 for (; ai.current(); ++ai) { 267 for (; ai.current(); ++ai) {
268 curAttendee = ai.current(); 268 curAttendee = ai.current();
269 if (!curAttendee->email().isEmpty() && 269 if (!curAttendee->email().isEmpty() &&
270 !curAttendee->name().isEmpty()) 270 !curAttendee->name().isEmpty())
271 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 271 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
272 curAttendee->email() + ">"; 272 curAttendee->email() + ">";
273 else if (curAttendee->name().isEmpty()) 273 else if (curAttendee->name().isEmpty())
274 tmpStr = "MAILTO: " + curAttendee->email(); 274 tmpStr = "MAILTO: " + curAttendee->email();
275 else if (curAttendee->email().isEmpty()) 275 else if (curAttendee->email().isEmpty())
276 tmpStr = "MAILTO: " + curAttendee->name(); 276 tmpStr = "MAILTO: " + curAttendee->name();
277 else if (curAttendee->name().isEmpty() && 277 else if (curAttendee->name().isEmpty() &&
278 curAttendee->email().isEmpty()) 278 curAttendee->email().isEmpty())
279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
283 } 283 }
284 } 284 }
285 285
286 // description BL: 286 // description BL:
287 if (!anEvent->description().isEmpty()) { 287 if (!anEvent->description().isEmpty()) {
288 VObject *d = addPropValue(vtodo, VCDescriptionProp, 288 VObject *d = addPropValue(vtodo, VCDescriptionProp,
289 anEvent->description().local8Bit()); 289 anEvent->description().local8Bit());
290 if (anEvent->description().find('\n') != -1) 290 if (anEvent->description().find('\n') != -1)
291 addProp(d, VCQuotedPrintableProp); 291 addProp(d, VCQuotedPrintableProp);
292 } 292 }
293 293
294 // summary 294 // summary
295 if (!anEvent->summary().isEmpty()) 295 if (!anEvent->summary().isEmpty())
296 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 296 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
297 297
298 if (!anEvent->location().isEmpty()) 298 if (!anEvent->location().isEmpty())
299 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 299 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
300 300
301 // completed 301 // completed
302 // status 302 // status
303 // backward compatibility, KOrganizer used to interpret only these two values 303 // backward compatibility, KOrganizer used to interpret only these two values
304 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 304 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
305 "NEEDS_ACTION"); 305 "NEEDS_ACTION");
306 // completion date 306 // completion date
307 if (anEvent->hasCompletedDate()) { 307 if (anEvent->hasCompletedDate()) {
308 tmpStr = qDateTimeToISO(anEvent->completed()); 308 tmpStr = qDateTimeToISO(anEvent->completed());
309 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 309 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
310 } 310 }
311 311
312 // priority 312 // priority
313 tmpStr.sprintf("%i",anEvent->priority()); 313 tmpStr.sprintf("%i",anEvent->priority());
314 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 314 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
315 315
316 // related event 316 // related event
317 if (anEvent->relatedTo()) { 317 if (anEvent->relatedTo()) {
318 addPropValue(vtodo, VCRelatedToProp, 318 addPropValue(vtodo, VCRelatedToProp,
319 anEvent->relatedTo()->uid().local8Bit()); 319 anEvent->relatedTo()->uid().local8Bit());
320 } 320 }
321 321
322 // categories 322 // categories
323 tmpStrList = anEvent->categories(); 323 tmpStrList = anEvent->categories();
324 tmpStr = ""; 324 tmpStr = "";
325 QString catStr; 325 QString catStr;
326 for ( QStringList::Iterator it = tmpStrList.begin(); 326 for ( QStringList::Iterator it = tmpStrList.begin();
327 it != tmpStrList.end(); 327 it != tmpStrList.end();
328 ++it ) { 328 ++it ) {
329 catStr = *it; 329 catStr = *it;
330 if (catStr[0] == ' ') 330 if (catStr[0] == ' ')
331 tmpStr += catStr.mid(1); 331 tmpStr += catStr.mid(1);
332 else 332 else
333 tmpStr += catStr; 333 tmpStr += catStr;
334 // this must be a ';' character as the vCalendar specification requires! 334 // this must be a ';' character as the vCalendar specification requires!
335 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 335 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
336 // read in. 336 // read in.
337 tmpStr += ";"; 337 tmpStr += ";";
338 } 338 }
339 if (!tmpStr.isEmpty()) { 339 if (!tmpStr.isEmpty()) {
340 tmpStr.truncate(tmpStr.length()-1); 340 tmpStr.truncate(tmpStr.length()-1);
341 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 341 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
342 } 342 }
343 343
344 // alarm stuff 344 // alarm stuff
345 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 345 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
346 QPtrList<Alarm> alarms = anEvent->alarms(); 346 QPtrList<Alarm> alarms = anEvent->alarms();
347 Alarm* alarm; 347 Alarm* alarm;
348 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 348 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
349 if (alarm->enabled()) { 349 if (alarm->enabled()) {
350 VObject *a = addProp(vtodo, VCDAlarmProp); 350 VObject *a;
351 tmpStr = qDateTimeToISO(alarm->time()); 351 tmpStr = qDateTimeToISO(alarm->time());
352 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 352 if (alarm->type() == Alarm::Audio) {
353 addPropValue(a, VCRepeatCountProp, "1"); 353 a = addProp(vtodo, VCAAlarmProp);
354 addPropValue(a, VCDisplayStringProp, "beep!"); 354 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
355 if (alarm->type() == Alarm::Audio) { 355 addPropValue(a, VCRepeatCountProp, "1");
356 a = addProp(vtodo, VCAAlarmProp); 356 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
357 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 357 }
358 addPropValue(a, VCRepeatCountProp, "1"); 358 else if (alarm->type() == Alarm::Procedure) {
359 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 359 a = addProp(vtodo, VCPAlarmProp);
360 } 360 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
361 else if (alarm->type() == Alarm::Procedure) { 361 addPropValue(a, VCRepeatCountProp, "1");
362 a = addProp(vtodo, VCPAlarmProp); 362 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
363 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 363 } else {
364 addPropValue(a, VCRepeatCountProp, "1"); 364 a = addProp(vtodo, VCDAlarmProp);
365 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 365 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
366 addPropValue(a, VCRepeatCountProp, "1");
367 addPropValue(a, VCDisplayStringProp, "beep!");
366 } 368 }
367 } 369 }
368 } 370 }
369 371
370 if (anEvent->pilotId()) { 372 if (anEvent->pilotId()) {
371 // pilot sync stuff 373 // pilot sync stuff
372 tmpStr.sprintf("%i",anEvent->pilotId()); 374 tmpStr.sprintf("%i",anEvent->pilotId());
373 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 375 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
374 tmpStr.sprintf("%i",anEvent->syncStatus()); 376 tmpStr.sprintf("%i",anEvent->syncStatus());
375 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 377 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
376 } 378 }
377 379
378 return vtodo; 380 return vtodo;
379} 381}
380 382
381VObject* VCalFormat::eventToVEvent(const Event *anEvent) 383VObject* VCalFormat::eventToVEvent(const Event *anEvent)
382{ 384{
383 VObject *vevent; 385 VObject *vevent;
384 QString tmpStr; 386 QString tmpStr;
385 QStringList tmpStrList; 387 QStringList tmpStrList;
386 388
387 vevent = newVObject(VCEventProp); 389 vevent = newVObject(VCEventProp);
388 390
389 // start and end time 391 // start and end time
390 tmpStr = qDateTimeToISO(anEvent->dtStart(), 392 tmpStr = qDateTimeToISO(anEvent->dtStart(),
391 !anEvent->doesFloat()); 393 !anEvent->doesFloat());
392 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 394 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
393 395
394 // events that have time associated but take up no time should 396 // events that have time associated but take up no time should
395 // not have both DTSTART and DTEND. 397 // not have both DTSTART and DTEND.
396 if (anEvent->dtStart() != anEvent->dtEnd()) { 398 if (anEvent->dtStart() != anEvent->dtEnd()) {
397 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 399 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
398 !anEvent->doesFloat()); 400 !anEvent->doesFloat());
399 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 401 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
400 } 402 }
401 403
402 // creation date 404 // creation date
403 tmpStr = qDateTimeToISO(anEvent->created()); 405 tmpStr = qDateTimeToISO(anEvent->created());
404 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 406 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
405 407
406 // unique id 408 // unique id
407 addPropValue(vevent, VCUniqueStringProp, 409 addPropValue(vevent, VCUniqueStringProp,
408 anEvent->uid().local8Bit()); 410 anEvent->uid().local8Bit());
409 411
410 // revision 412 // revision
411 tmpStr.sprintf("%i", anEvent->revision()); 413 tmpStr.sprintf("%i", anEvent->revision());
412 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 414 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
413 415
414 // last modification date 416 // last modification date
415 tmpStr = qDateTimeToISO(anEvent->lastModified()); 417 tmpStr = qDateTimeToISO(anEvent->lastModified());
416 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 418 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
417 419
418 // attendee and organizer stuff 420 // attendee and organizer stuff
419 tmpStr = "MAILTO:" + anEvent->organizer(); 421 tmpStr = "MAILTO:" + anEvent->organizer();
420 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 422 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
421 423
422 if (anEvent->attendeeCount() != 0) { 424 if (anEvent->attendeeCount() != 0) {
423 QPtrList<Attendee> al = anEvent->attendees(); 425 QPtrList<Attendee> al = anEvent->attendees();
424 QPtrListIterator<Attendee> ai(al); 426 QPtrListIterator<Attendee> ai(al);
425 Attendee *curAttendee; 427 Attendee *curAttendee;
426 428
427 // TODO: Put this functionality into Attendee class 429 // TODO: Put this functionality into Attendee class
428 for (; ai.current(); ++ai) { 430 for (; ai.current(); ++ai) {
429 curAttendee = ai.current(); 431 curAttendee = ai.current();
430 if (!curAttendee->email().isEmpty() && 432 if (!curAttendee->email().isEmpty() &&
431 !curAttendee->name().isEmpty()) 433 !curAttendee->name().isEmpty())
432 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 434 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
433 curAttendee->email() + ">"; 435 curAttendee->email() + ">";
434 else if (curAttendee->name().isEmpty()) 436 else if (curAttendee->name().isEmpty())
435 tmpStr = "MAILTO: " + curAttendee->email(); 437 tmpStr = "MAILTO: " + curAttendee->email();
436 else if (curAttendee->email().isEmpty()) 438 else if (curAttendee->email().isEmpty())
437 tmpStr = "MAILTO: " + curAttendee->name(); 439 tmpStr = "MAILTO: " + curAttendee->name();
438 else if (curAttendee->name().isEmpty() && 440 else if (curAttendee->name().isEmpty() &&
439 curAttendee->email().isEmpty()) 441 curAttendee->email().isEmpty())
440 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 442 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
441 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 443 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
442 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; 444 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
443 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 445 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
444 } 446 }
445 } 447 }
446 448
447 // recurrence rule stuff 449 // recurrence rule stuff
448 if (anEvent->recurrence()->doesRecur()) { 450 if (anEvent->recurrence()->doesRecur()) {
449 // some more variables 451 // some more variables
450 QPtrList<Recurrence::rMonthPos> tmpPositions; 452 QPtrList<Recurrence::rMonthPos> tmpPositions;
451 QPtrList<int> tmpDays; 453 QPtrList<int> tmpDays;
452 int *tmpDay; 454 int *tmpDay;
453 Recurrence::rMonthPos *tmpPos; 455 Recurrence::rMonthPos *tmpPos;
454 QString tmpStr2; 456 QString tmpStr2;
455 int i; 457 int i;
456 458
457 switch(anEvent->recurrence()->doesRecur()) { 459 switch(anEvent->recurrence()->doesRecur()) {
458 case Recurrence::rDaily: 460 case Recurrence::rDaily:
459 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 461 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
460// if (anEvent->rDuration > 0) 462// if (anEvent->rDuration > 0)
461 //tmpStr += "#"; 463 //tmpStr += "#";
462 break; 464 break;
463 case Recurrence::rWeekly: 465 case Recurrence::rWeekly:
464 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); 466 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency());
465 for (i = 0; i < 7; i++) { 467 for (i = 0; i < 7; i++) {
466 if (anEvent->recurrence()->days().testBit(i)) 468 if (anEvent->recurrence()->days().testBit(i))
467 tmpStr += dayFromNum(i); 469 tmpStr += dayFromNum(i);
468 } 470 }
469 break; 471 break;
470 case Recurrence::rMonthlyPos: 472 case Recurrence::rMonthlyPos:
471 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); 473 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency());
472 // write out all rMonthPos's 474 // write out all rMonthPos's
473 tmpPositions = anEvent->recurrence()->monthPositions(); 475 tmpPositions = anEvent->recurrence()->monthPositions();
474 for (tmpPos = tmpPositions.first(); 476 for (tmpPos = tmpPositions.first();
475 tmpPos; 477 tmpPos;
476 tmpPos = tmpPositions.next()) { 478 tmpPos = tmpPositions.next()) {
477 479
478 tmpStr2.sprintf("%i", tmpPos->rPos); 480 tmpStr2.sprintf("%i", tmpPos->rPos);
479 if (tmpPos->negative) 481 if (tmpPos->negative)
480 tmpStr2 += "- "; 482 tmpStr2 += "- ";
481 else 483 else
482 tmpStr2 += "+ "; 484 tmpStr2 += "+ ";
483 tmpStr += tmpStr2; 485 tmpStr += tmpStr2;
484 for (i = 0; i < 7; i++) { 486 for (i = 0; i < 7; i++) {
485 if (tmpPos->rDays.testBit(i)) 487 if (tmpPos->rDays.testBit(i))
486 tmpStr += dayFromNum(i); 488 tmpStr += dayFromNum(i);
487 } 489 }
488 } // loop for all rMonthPos's 490 } // loop for all rMonthPos's
489 break; 491 break;
490 case Recurrence::rMonthlyDay: 492 case Recurrence::rMonthlyDay:
491 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); 493 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency());
492 // write out all rMonthDays; 494 // write out all rMonthDays;
493 tmpDays = anEvent->recurrence()->monthDays(); 495 tmpDays = anEvent->recurrence()->monthDays();
494 for (tmpDay = tmpDays.first(); 496 for (tmpDay = tmpDays.first();
495 tmpDay; 497 tmpDay;
496 tmpDay = tmpDays.next()) { 498 tmpDay = tmpDays.next()) {
497 tmpStr2.sprintf("%i ", *tmpDay); 499 tmpStr2.sprintf("%i ", *tmpDay);
498 tmpStr += tmpStr2; 500 tmpStr += tmpStr2;
499 } 501 }
500 break; 502 break;
501 case Recurrence::rYearlyMonth: 503 case Recurrence::rYearlyMonth:
502 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); 504 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency());
503 // write out all the rYearNums; 505 // write out all the rYearNums;
504 tmpDays = anEvent->recurrence()->yearNums(); 506 tmpDays = anEvent->recurrence()->yearNums();
505 for (tmpDay = tmpDays.first(); 507 for (tmpDay = tmpDays.first();
506 tmpDay; 508 tmpDay;
507 tmpDay = tmpDays.next()) { 509 tmpDay = tmpDays.next()) {
508 tmpStr2.sprintf("%i ", *tmpDay); 510 tmpStr2.sprintf("%i ", *tmpDay);
509 tmpStr += tmpStr2; 511 tmpStr += tmpStr2;
510 } 512 }
511 break; 513 break;
512 case Recurrence::rYearlyDay: 514 case Recurrence::rYearlyDay:
513 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); 515 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency());
514 // write out all the rYearNums; 516 // write out all the rYearNums;
515 tmpDays = anEvent->recurrence()->yearNums(); 517 tmpDays = anEvent->recurrence()->yearNums();
516 for (tmpDay = tmpDays.first(); 518 for (tmpDay = tmpDays.first();
517 tmpDay; 519 tmpDay;
518 tmpDay = tmpDays.next()) { 520 tmpDay = tmpDays.next()) {
519 tmpStr2.sprintf("%i ", *tmpDay); 521 tmpStr2.sprintf("%i ", *tmpDay);
520 tmpStr += tmpStr2; 522 tmpStr += tmpStr2;
521 } 523 }
522 break; 524 break;
523 default: 525 default:
524 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; 526 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl;
525 break; 527 break;
526 } // switch 528 } // switch
527 529
528 if (anEvent->recurrence()->duration() > 0) { 530 if (anEvent->recurrence()->duration() > 0) {
529 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); 531 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration());
530 tmpStr += tmpStr2; 532 tmpStr += tmpStr2;
531 } else if (anEvent->recurrence()->duration() == -1) { 533 } else if (anEvent->recurrence()->duration() == -1) {
532 tmpStr += "#0"; // defined as repeat forever 534 tmpStr += "#0"; // defined as repeat forever
533 } else { 535 } else {
534 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); 536 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE);
535 } 537 }
536 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); 538 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
537 539
538 } // event repeats 540 } // event repeats
539 541
540 // exceptions to recurrence 542 // exceptions to recurrence
541 DateList dateList = anEvent->exDates(); 543 DateList dateList = anEvent->exDates();
542 DateList::ConstIterator it; 544 DateList::ConstIterator it;
543 QString tmpStr2; 545 QString tmpStr2;
544 546
545 for (it = dateList.begin(); it != dateList.end(); ++it) { 547 for (it = dateList.begin(); it != dateList.end(); ++it) {
546 tmpStr = qDateToISO(*it) + ";"; 548 tmpStr = qDateToISO(*it) + ";";
547 tmpStr2 += tmpStr; 549 tmpStr2 += tmpStr;
548 } 550 }
549 if (!tmpStr2.isEmpty()) { 551 if (!tmpStr2.isEmpty()) {
550 tmpStr2.truncate(tmpStr2.length()-1); 552 tmpStr2.truncate(tmpStr2.length()-1);
551 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); 553 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
552 } 554 }
553 555
554 // description 556 // description
555 if (!anEvent->description().isEmpty()) { 557 if (!anEvent->description().isEmpty()) {
556 VObject *d = addPropValue(vevent, VCDescriptionProp, 558 VObject *d = addPropValue(vevent, VCDescriptionProp,
557 anEvent->description().local8Bit()); 559 anEvent->description().local8Bit());
558 if (anEvent->description().find('\n') != -1) 560 if (anEvent->description().find('\n') != -1)
559 addProp(d, VCQuotedPrintableProp); 561 addProp(d, VCQuotedPrintableProp);
560 } 562 }
561 563
562 // summary 564 // summary
563 if (!anEvent->summary().isEmpty()) 565 if (!anEvent->summary().isEmpty())
564 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); 566 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
565 567
566 if (!anEvent->location().isEmpty()) 568 if (!anEvent->location().isEmpty())
567 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); 569 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
568 570
569 // status 571 // status
570// TODO: define Event status 572// TODO: define Event status
571// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); 573// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
572 574
573 // secrecy 575 // secrecy
574 const char *text = 0; 576 const char *text = 0;
575 switch (anEvent->secrecy()) { 577 switch (anEvent->secrecy()) {
576 case Incidence::SecrecyPublic: 578 case Incidence::SecrecyPublic:
577 text = "PUBLIC"; 579 text = "PUBLIC";
578 break; 580 break;
579 case Incidence::SecrecyPrivate: 581 case Incidence::SecrecyPrivate:
580 text = "PRIVATE"; 582 text = "PRIVATE";
581 break; 583 break;
582 case Incidence::SecrecyConfidential: 584 case Incidence::SecrecyConfidential:
583 text = "CONFIDENTIAL"; 585 text = "CONFIDENTIAL";
584 break; 586 break;
585 } 587 }
586 if (text) { 588 if (text) {
587 addPropValue(vevent, VCClassProp, text); 589 addPropValue(vevent, VCClassProp, text);
588 } 590 }
589 591
590 // categories 592 // categories
591 tmpStrList = anEvent->categories(); 593 tmpStrList = anEvent->categories();
592 tmpStr = ""; 594 tmpStr = "";
593 QString catStr; 595 QString catStr;
594 for ( QStringList::Iterator it = tmpStrList.begin(); 596 for ( QStringList::Iterator it = tmpStrList.begin();
595 it != tmpStrList.end(); 597 it != tmpStrList.end();
596 ++it ) { 598 ++it ) {
597 catStr = *it; 599 catStr = *it;
598 if (catStr[0] == ' ') 600 if (catStr[0] == ' ')
599 tmpStr += catStr.mid(1); 601 tmpStr += catStr.mid(1);
600 else 602 else
601 tmpStr += catStr; 603 tmpStr += catStr;
602 // this must be a ';' character as the vCalendar specification requires! 604 // this must be a ';' character as the vCalendar specification requires!
603 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 605 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
604 // read in. 606 // read in.
605 tmpStr += ";"; 607 tmpStr += ";";
606 } 608 }
607 if (!tmpStr.isEmpty()) { 609 if (!tmpStr.isEmpty()) {
608 tmpStr.truncate(tmpStr.length()-1); 610 tmpStr.truncate(tmpStr.length()-1);
609 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); 611 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
610 } 612 }
611 613
612 // attachments 614 // attachments
613 // TODO: handle binary attachments! 615 // TODO: handle binary attachments!
614 QPtrList<Attachment> attachments = anEvent->attachments(); 616 QPtrList<Attachment> attachments = anEvent->attachments();
615 for ( Attachment *at = attachments.first(); at; at = attachments.next() ) 617 for ( Attachment *at = attachments.first(); at; at = attachments.next() )
616 addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); 618 addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
617 619
618 // resources 620 // resources
619 tmpStrList = anEvent->resources(); 621 tmpStrList = anEvent->resources();
620 tmpStr = tmpStrList.join(";"); 622 tmpStr = tmpStrList.join(";");
621 if (!tmpStr.isEmpty()) 623 if (!tmpStr.isEmpty())
622 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); 624 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
623 625
624 // alarm stuff 626 // alarm stuff
625 QPtrList<Alarm> alarms = anEvent->alarms(); 627 QPtrList<Alarm> alarms = anEvent->alarms();
626 Alarm* alarm; 628 Alarm* alarm;
627 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 629 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
628 if (alarm->enabled()) { 630 if (alarm->enabled()) {
629 VObject *a = addProp(vevent, VCDAlarmProp); 631 VObject *a ;
630 tmpStr = qDateTimeToISO(alarm->time()); 632 tmpStr = qDateTimeToISO(alarm->time());
631 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 633 if (alarm->type() == Alarm::Audio) {
632 addPropValue(a, VCRepeatCountProp, "1"); 634 a = addProp(vevent, VCAAlarmProp);
633 addPropValue(a, VCDisplayStringProp, "beep!"); 635 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
634 if (alarm->type() == Alarm::Audio) { 636 addPropValue(a, VCRepeatCountProp, "1");
635 a = addProp(vevent, VCAAlarmProp); 637 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
636 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 638 }
637 addPropValue(a, VCRepeatCountProp, "1"); 639 if (alarm->type() == Alarm::Procedure) {
638 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 640 a = addProp(vevent, VCPAlarmProp);
639 } 641 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
640 if (alarm->type() == Alarm::Procedure) { 642 addPropValue(a, VCRepeatCountProp, "1");
641 a = addProp(vevent, VCPAlarmProp); 643 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
642 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 644 } else {
643 addPropValue(a, VCRepeatCountProp, "1"); 645 a = addProp(vevent, VCDAlarmProp);
644 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 646 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
647 addPropValue(a, VCRepeatCountProp, "1");
648 addPropValue(a, VCDisplayStringProp, "beep!");
649
645 } 650 }
646 } 651 }
647 } 652 }
648 653
649 // priority 654 // priority
650 tmpStr.sprintf("%i",anEvent->priority()); 655 tmpStr.sprintf("%i",anEvent->priority());
651 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); 656 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
652 657
653 // transparency 658 // transparency
654 tmpStr.sprintf("%i",anEvent->transparency()); 659 tmpStr.sprintf("%i",anEvent->transparency());
655 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); 660 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
656 661
657 // related event 662 // related event
658 if (anEvent->relatedTo()) { 663 if (anEvent->relatedTo()) {
659 addPropValue(vevent, VCRelatedToProp, 664 addPropValue(vevent, VCRelatedToProp,
660 anEvent->relatedTo()->uid().local8Bit()); 665 anEvent->relatedTo()->uid().local8Bit());
661 } 666 }
662 667
663 if (anEvent->pilotId()) { 668 if (anEvent->pilotId()) {
664 // pilot sync stuff 669 // pilot sync stuff
665 tmpStr.sprintf("%i",anEvent->pilotId()); 670 tmpStr.sprintf("%i",anEvent->pilotId());
666 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); 671 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
667 tmpStr.sprintf("%i",anEvent->syncStatus()); 672 tmpStr.sprintf("%i",anEvent->syncStatus());
668 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); 673 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
669 } 674 }
670 675
671 return vevent; 676 return vevent;
672} 677}
673 678
674Todo *VCalFormat::VTodoToEvent(VObject *vtodo) 679Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
675{ 680{
676 VObject *vo; 681 VObject *vo;
677 VObjectIterator voi; 682 VObjectIterator voi;
678 char *s; 683 char *s;
679 684
680 Todo *anEvent = new Todo; 685 Todo *anEvent = new Todo;
681 686
682 // creation date 687 // creation date
683 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { 688 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
684 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 689 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
685 deleteStr(s); 690 deleteStr(s);
686 } 691 }
687 692
688 // unique id 693 // unique id
689 vo = isAPropertyOf(vtodo, VCUniqueStringProp); 694 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
690 // while the UID property is preferred, it is not required. We'll use the 695 // while the UID property is preferred, it is not required. We'll use the
691 // default Event UID if none is given. 696 // default Event UID if none is given.
692 if (vo) { 697 if (vo) {
693 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 698 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
694 deleteStr(s); 699 deleteStr(s);
695 } 700 }
696 701
697 // last modification date 702 // last modification date
698 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { 703 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
699 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 704 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
700 deleteStr(s); 705 deleteStr(s);
701 } 706 }
702 else 707 else
703 anEvent->setLastModified(QDateTime(QDate::currentDate(), 708 anEvent->setLastModified(QDateTime(QDate::currentDate(),
704 QTime::currentTime())); 709 QTime::currentTime()));
705 710
706 // organizer 711 // organizer
707 // if our extension property for the event's ORGANIZER exists, add it. 712 // if our extension property for the event's ORGANIZER exists, add it.
708 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { 713 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
709 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 714 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
710 deleteStr(s); 715 deleteStr(s);
711 } else { 716 } else {
712 anEvent->setOrganizer(mCalendar->getEmail()); 717 anEvent->setOrganizer(mCalendar->getEmail());
713 } 718 }
714 719
715 // attendees. 720 // attendees.
716 initPropIterator(&voi, vtodo); 721 initPropIterator(&voi, vtodo);
717 while (moreIteration(&voi)) { 722 while (moreIteration(&voi)) {
718 vo = nextVObject(&voi); 723 vo = nextVObject(&voi);
719 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 724 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
720 Attendee *a; 725 Attendee *a;
721 VObject *vp; 726 VObject *vp;
722 s = fakeCString(vObjectUStringZValue(vo)); 727 s = fakeCString(vObjectUStringZValue(vo));
723 QString tmpStr = QString::fromLocal8Bit(s); 728 QString tmpStr = QString::fromLocal8Bit(s);
724 deleteStr(s); 729 deleteStr(s);
725 tmpStr = tmpStr.simplifyWhiteSpace(); 730 tmpStr = tmpStr.simplifyWhiteSpace();
726 int emailPos1, emailPos2; 731 int emailPos1, emailPos2;
727 if ((emailPos1 = tmpStr.find('<')) > 0) { 732 if ((emailPos1 = tmpStr.find('<')) > 0) {
728 // both email address and name 733 // both email address and name
729 emailPos2 = tmpStr.findRev('>'); 734 emailPos2 = tmpStr.findRev('>');
730 a = new Attendee(tmpStr.left(emailPos1 - 1), 735 a = new Attendee(tmpStr.left(emailPos1 - 1),
731 tmpStr.mid(emailPos1 + 1, 736 tmpStr.mid(emailPos1 + 1,
732 emailPos2 - (emailPos1 + 1))); 737 emailPos2 - (emailPos1 + 1)));
733 } else if (tmpStr.find('@') > 0) { 738 } else if (tmpStr.find('@') > 0) {
734 // just an email address 739 // just an email address
735 a = new Attendee(0, tmpStr); 740 a = new Attendee(0, tmpStr);
736 } else { 741 } else {
737 // just a name 742 // just a name
738 QString email = tmpStr.replace( QRegExp(" "), "." ); 743 QString email = tmpStr.replace( QRegExp(" "), "." );
739 a = new Attendee(tmpStr,email); 744 a = new Attendee(tmpStr,email);
740 } 745 }
741 746
742 // is there an RSVP property? 747 // is there an RSVP property?
743 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 748 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
744 a->setRSVP(vObjectStringZValue(vp)); 749 a->setRSVP(vObjectStringZValue(vp));
745 // is there a status property? 750 // is there a status property?
746 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 751 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
747 a->setStatus(readStatus(vObjectStringZValue(vp))); 752 a->setStatus(readStatus(vObjectStringZValue(vp)));
748 // add the attendee 753 // add the attendee
749 anEvent->addAttendee(a); 754 anEvent->addAttendee(a);
750 } 755 }
751 } 756 }
752 757
753 // description for todo 758 // description for todo
754 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { 759 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) {
755 s = fakeCString(vObjectUStringZValue(vo)); 760 s = fakeCString(vObjectUStringZValue(vo));
756 anEvent->setDescription(QString::fromLocal8Bit(s)); 761 anEvent->setDescription(QString::fromLocal8Bit(s));
757 deleteStr(s); 762 deleteStr(s);
758 } 763 }
759 764
760 // summary 765 // summary
761 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { 766 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) {
762 s = fakeCString(vObjectUStringZValue(vo)); 767 s = fakeCString(vObjectUStringZValue(vo));
763 anEvent->setSummary(QString::fromLocal8Bit(s)); 768 anEvent->setSummary(QString::fromLocal8Bit(s));
764 deleteStr(s); 769 deleteStr(s);
765 } 770 }
766 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { 771 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) {
767 s = fakeCString(vObjectUStringZValue(vo)); 772 s = fakeCString(vObjectUStringZValue(vo));
768 anEvent->setLocation(QString::fromLocal8Bit(s)); 773 anEvent->setLocation(QString::fromLocal8Bit(s));
769 deleteStr(s); 774 deleteStr(s);
770 } 775 }
771 776
772 777
773 // completed 778 // completed
774 // was: status 779 // was: status
775 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { 780 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) {
776 s = fakeCString(vObjectUStringZValue(vo)); 781 s = fakeCString(vObjectUStringZValue(vo));
777 if (strcmp(s,"COMPLETED") == 0) { 782 if (strcmp(s,"COMPLETED") == 0) {
778 anEvent->setCompleted(true); 783 anEvent->setCompleted(true);
779 } else { 784 } else {
780 anEvent->setCompleted(false); 785 anEvent->setCompleted(false);
781 } 786 }
782 deleteStr(s); 787 deleteStr(s);
783 } 788 }
784 else 789 else
785 anEvent->setCompleted(false); 790 anEvent->setCompleted(false);
786 791
787 // completion date 792 // completion date
788 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { 793 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) {
789 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 794 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
790 deleteStr(s); 795 deleteStr(s);
791 } 796 }
792 797
793 // priority 798 // priority
794 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { 799 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) {
795 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 800 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
796 deleteStr(s); 801 deleteStr(s);
797 } 802 }
798 803
799 // due date 804 // due date
800 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { 805 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) {
801 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 806 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
802 deleteStr(s); 807 deleteStr(s);
803 anEvent->setHasDueDate(true); 808 anEvent->setHasDueDate(true);
804 } else { 809 } else {
805 anEvent->setHasDueDate(false); 810 anEvent->setHasDueDate(false);
806 } 811 }
807 812
808 // start time 813 // start time
809 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { 814 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) {
810 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 815 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
811 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 816 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
812 deleteStr(s); 817 deleteStr(s);
813 anEvent->setHasStartDate(true); 818 anEvent->setHasStartDate(true);
814 } else { 819 } else {
815 anEvent->setHasStartDate(false); 820 anEvent->setHasStartDate(false);
816 } 821 }
817 822
818 /* alarm stuff */ 823 /* alarm stuff */
819 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; 824 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl;
820 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { 825 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) {
821 Alarm* alarm = anEvent->newAlarm(); 826 Alarm* alarm = anEvent->newAlarm();
822 VObject *a; 827 VObject *a;
823 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 828 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
824 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 829 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
825 deleteStr(s); 830 deleteStr(s);
826 } 831 }
827 alarm->setEnabled(true); 832 alarm->setEnabled(true);
828 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { 833 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) {
829 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 834 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
830 s = fakeCString(vObjectUStringZValue(a)); 835 s = fakeCString(vObjectUStringZValue(a));
831 alarm->setProcedureAlarm(QFile::decodeName(s)); 836 alarm->setProcedureAlarm(QFile::decodeName(s));
832 deleteStr(s); 837 deleteStr(s);
833 } 838 }
834 } 839 }
835 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { 840 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) {
836 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 841 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
837 s = fakeCString(vObjectUStringZValue(a)); 842 s = fakeCString(vObjectUStringZValue(a));
838 alarm->setAudioAlarm(QFile::decodeName(s)); 843 alarm->setAudioAlarm(QFile::decodeName(s));
839 deleteStr(s); 844 deleteStr(s);
840 } 845 }
841 } 846 }
842 } 847 }
843 848
844 // related todo 849 // related todo
845 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { 850 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) {
846 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 851 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
847 deleteStr(s); 852 deleteStr(s);
848 mTodosRelate.append(anEvent); 853 mTodosRelate.append(anEvent);
849 } 854 }
850 855
851 // categories 856 // categories
852 QStringList tmpStrList; 857 QStringList tmpStrList;
853 int index1 = 0; 858 int index1 = 0;
854 int index2 = 0; 859 int index2 = 0;
855 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { 860 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) {
856 s = fakeCString(vObjectUStringZValue(vo)); 861 s = fakeCString(vObjectUStringZValue(vo));
857 QString categories = QString::fromLocal8Bit(s); 862 QString categories = QString::fromLocal8Bit(s);
858 deleteStr(s); 863 deleteStr(s);
859 //const char* category; 864 //const char* category;
860 QString category; 865 QString category;
861 while ((index2 = categories.find(',', index1)) != -1) { 866 while ((index2 = categories.find(',', index1)) != -1) {
862 //category = (const char *) categories.mid(index1, (index2 - index1)); 867 //category = (const char *) categories.mid(index1, (index2 - index1));
863 category = categories.mid(index1, (index2 - index1)); 868 category = categories.mid(index1, (index2 - index1));
864 tmpStrList.append(category); 869 tmpStrList.append(category);
865 index1 = index2+1; 870 index1 = index2+1;
866 } 871 }
867 // get last category 872 // get last category
868 category = categories.mid(index1, (categories.length()-index1)); 873 category = categories.mid(index1, (categories.length()-index1));
869 tmpStrList.append(category); 874 tmpStrList.append(category);
870 anEvent->setCategories(tmpStrList); 875 anEvent->setCategories(tmpStrList);
871 } 876 }
872 877
873 /* PILOT SYNC STUFF */ 878 /* PILOT SYNC STUFF */
874 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { 879 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) {
875 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 880 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
876 deleteStr(s); 881 deleteStr(s);
877 } 882 }
878 else 883 else
879 anEvent->setPilotId(0); 884 anEvent->setPilotId(0);
880 885
881 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { 886 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) {
882 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 887 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
883 deleteStr(s); 888 deleteStr(s);
884 } 889 }
885 else 890 else
886 anEvent->setSyncStatus(Event::SYNCMOD); 891 anEvent->setSyncStatus(Event::SYNCMOD);
887 892
888 return anEvent; 893 return anEvent;
889} 894}
890 895
891Event* VCalFormat::VEventToEvent(VObject *vevent) 896Event* VCalFormat::VEventToEvent(VObject *vevent)
892{ 897{
893 VObject *vo; 898 VObject *vo;
894 VObjectIterator voi; 899 VObjectIterator voi;
895 char *s; 900 char *s;
896 901
897 Event *anEvent = new Event; 902 Event *anEvent = new Event;
898 903
899 // creation date 904 // creation date
900 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { 905 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) {
901 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 906 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
902 deleteStr(s); 907 deleteStr(s);
903 } 908 }
904 909
905 // unique id 910 // unique id
906 vo = isAPropertyOf(vevent, VCUniqueStringProp); 911 vo = isAPropertyOf(vevent, VCUniqueStringProp);
907 // while the UID property is preferred, it is not required. We'll use the 912 // while the UID property is preferred, it is not required. We'll use the
908 // default Event UID if none is given. 913 // default Event UID if none is given.
909 if (vo) { 914 if (vo) {
910 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 915 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
911 deleteStr(s); 916 deleteStr(s);
912 } 917 }
913 918
914 // revision 919 // revision
915 // again NSCAL doesn't give us much to work with, so we improvise... 920 // again NSCAL doesn't give us much to work with, so we improvise...
916 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { 921 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) {
917 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 922 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo))));
918 deleteStr(s); 923 deleteStr(s);
919 } 924 }
920 else 925 else
921 anEvent->setRevision(0); 926 anEvent->setRevision(0);
922 927
923 // last modification date 928 // last modification date
924 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { 929 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) {
925 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 930 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
926 deleteStr(s); 931 deleteStr(s);
927 } 932 }
928 else 933 else
929 anEvent->setLastModified(QDateTime(QDate::currentDate(), 934 anEvent->setLastModified(QDateTime(QDate::currentDate(),
930 QTime::currentTime())); 935 QTime::currentTime()));
931 936
932 // organizer 937 // organizer
933 // if our extension property for the event's ORGANIZER exists, add it. 938 // if our extension property for the event's ORGANIZER exists, add it.
934 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { 939 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) {
935 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 940 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
936 deleteStr(s); 941 deleteStr(s);
937 } else { 942 } else {
938 anEvent->setOrganizer(mCalendar->getEmail()); 943 anEvent->setOrganizer(mCalendar->getEmail());
939 } 944 }
940 945
941 // deal with attendees. 946 // deal with attendees.
942 initPropIterator(&voi, vevent); 947 initPropIterator(&voi, vevent);
943 while (moreIteration(&voi)) { 948 while (moreIteration(&voi)) {
944 vo = nextVObject(&voi); 949 vo = nextVObject(&voi);
945 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 950 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
946 Attendee *a; 951 Attendee *a;
947 VObject *vp; 952 VObject *vp;
948 s = fakeCString(vObjectUStringZValue(vo)); 953 s = fakeCString(vObjectUStringZValue(vo));
949 QString tmpStr = QString::fromLocal8Bit(s); 954 QString tmpStr = QString::fromLocal8Bit(s);
950 deleteStr(s); 955 deleteStr(s);
951 tmpStr = tmpStr.simplifyWhiteSpace(); 956 tmpStr = tmpStr.simplifyWhiteSpace();
952 int emailPos1, emailPos2; 957 int emailPos1, emailPos2;
953 if ((emailPos1 = tmpStr.find('<')) > 0) { 958 if ((emailPos1 = tmpStr.find('<')) > 0) {
954 // both email address and name 959 // both email address and name
955 emailPos2 = tmpStr.findRev('>'); 960 emailPos2 = tmpStr.findRev('>');
956 a = new Attendee(tmpStr.left(emailPos1 - 1), 961 a = new Attendee(tmpStr.left(emailPos1 - 1),
957 tmpStr.mid(emailPos1 + 1, 962 tmpStr.mid(emailPos1 + 1,
958 emailPos2 - (emailPos1 + 1))); 963 emailPos2 - (emailPos1 + 1)));
959 } else if (tmpStr.find('@') > 0) { 964 } else if (tmpStr.find('@') > 0) {
960 // just an email address 965 // just an email address
961 a = new Attendee(0, tmpStr); 966 a = new Attendee(0, tmpStr);
962 } else { 967 } else {
963 // just a name 968 // just a name
964 QString email = tmpStr.replace( QRegExp(" "), "." ); 969 QString email = tmpStr.replace( QRegExp(" "), "." );
965 a = new Attendee(tmpStr,email); 970 a = new Attendee(tmpStr,email);
966 } 971 }
967 972
968 // is there an RSVP property? 973 // is there an RSVP property?
969 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 974 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
970 a->setRSVP(vObjectStringZValue(vp)); 975 a->setRSVP(vObjectStringZValue(vp));
971 // is there a status property? 976 // is there a status property?
972 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 977 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
973 a->setStatus(readStatus(vObjectStringZValue(vp))); 978 a->setStatus(readStatus(vObjectStringZValue(vp)));
974 // add the attendee 979 // add the attendee
975 anEvent->addAttendee(a); 980 anEvent->addAttendee(a);
976 } 981 }
977 } 982 }
978 983
979 // This isn't strictly true. An event that doesn't have a start time 984 // This isn't strictly true. An event that doesn't have a start time
980 // or an end time doesn't "float", it has an anchor in time but it doesn't 985 // or an end time doesn't "float", it has an anchor in time but it doesn't
981 // "take up" any time. 986 // "take up" any time.
982 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || 987 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) ||
983 (isAPropertyOf(vevent, VCDTendProp) == 0)) { 988 (isAPropertyOf(vevent, VCDTendProp) == 0)) {
984 anEvent->setFloats(TRUE); 989 anEvent->setFloats(TRUE);
985 } else { 990 } else {
986 }*/ 991 }*/
987 992
988 anEvent->setFloats(FALSE); 993 anEvent->setFloats(FALSE);
989 994
990 // start time 995 // start time
991 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { 996 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) {
992 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 997 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
993 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 998 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
994 deleteStr(s); 999 deleteStr(s);
995 if (anEvent->dtStart().time().isNull()) 1000 if (anEvent->dtStart().time().isNull())
996 anEvent->setFloats(TRUE); 1001 anEvent->setFloats(TRUE);
997 } 1002 }
998 1003
999 // stop time 1004 // stop time
1000 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { 1005 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) {
1001 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 1006 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
1002 deleteStr(s); 1007 deleteStr(s);
1003 if (anEvent->dtEnd().time().isNull()) 1008 if (anEvent->dtEnd().time().isNull())
1004 anEvent->setFloats(TRUE); 1009 anEvent->setFloats(TRUE);
1005 } 1010 }
1006 1011
1007 // at this point, there should be at least a start or end time. 1012 // at this point, there should be at least a start or end time.
1008 // fix up for events that take up no time but have a time associated 1013 // fix up for events that take up no time but have a time associated
1009 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 1014 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
1010 anEvent->setDtStart(anEvent->dtEnd()); 1015 anEvent->setDtStart(anEvent->dtEnd());
1011 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 1016 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
1012 anEvent->setDtEnd(anEvent->dtStart()); 1017 anEvent->setDtEnd(anEvent->dtStart());
1013 1018
1014 /////////////////////////////////////////////////////////////////////////// 1019 ///////////////////////////////////////////////////////////////////////////
1015 1020
1016 // repeat stuff 1021 // repeat stuff
1017 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { 1022 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) {
1018 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); 1023 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo)));
1019 deleteStr(s); 1024 deleteStr(s);
1020 tmpStr.simplifyWhiteSpace(); 1025 tmpStr.simplifyWhiteSpace();
1021 tmpStr = tmpStr.upper(); 1026 tmpStr = tmpStr.upper();
1022 1027
1023 /********************************* DAILY ******************************/ 1028 /********************************* DAILY ******************************/
1024 if (tmpStr.left(1) == "D") { 1029 if (tmpStr.left(1) == "D") {
1025 int index = tmpStr.find(' '); 1030 int index = tmpStr.find(' ');
1026 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1031 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1027 index = tmpStr.findRev(' ') + 1; // advance to last field 1032 index = tmpStr.findRev(' ') + 1; // advance to last field
1028 if (tmpStr.mid(index,1) == "#") index++; 1033 if (tmpStr.mid(index,1) == "#") index++;
1029 if (tmpStr.find('T', index) != -1) { 1034 if (tmpStr.find('T', index) != -1) {
1030 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1035 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1031 anEvent->recurrence()->setDaily(rFreq, rEndDate); 1036 anEvent->recurrence()->setDaily(rFreq, rEndDate);
1032 } else { 1037 } else {
1033 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1038 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1034 if (rDuration == 0) // VEvents set this to 0 forever, we use -1 1039 if (rDuration == 0) // VEvents set this to 0 forever, we use -1
1035 anEvent->recurrence()->setDaily(rFreq, -1); 1040 anEvent->recurrence()->setDaily(rFreq, -1);
1036 else 1041 else
1037 anEvent->recurrence()->setDaily(rFreq, rDuration); 1042 anEvent->recurrence()->setDaily(rFreq, rDuration);
1038 } 1043 }
1039 } 1044 }
1040 /********************************* WEEKLY ******************************/ 1045 /********************************* WEEKLY ******************************/
1041 else if (tmpStr.left(1) == "W") { 1046 else if (tmpStr.left(1) == "W") {
1042 int index = tmpStr.find(' '); 1047 int index = tmpStr.find(' ');
1043 int last = tmpStr.findRev(' ') + 1; 1048 int last = tmpStr.findRev(' ') + 1;
1044 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1049 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1045 index += 1; // advance to beginning of stuff after freq 1050 index += 1; // advance to beginning of stuff after freq
1046 QBitArray qba(7); 1051 QBitArray qba(7);
1047 QString dayStr; 1052 QString dayStr;
1048 if( index == last ) { 1053 if( index == last ) {
1049 // e.g. W1 #0 1054 // e.g. W1 #0
1050 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1055 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1051 } 1056 }
1052 else { 1057 else {
1053 // e.g. W1 SU #0 1058 // e.g. W1 SU #0
1054 while (index < last) { 1059 while (index < last) {
1055 dayStr = tmpStr.mid(index, 3); 1060 dayStr = tmpStr.mid(index, 3);
1056 int dayNum = numFromDay(dayStr); 1061 int dayNum = numFromDay(dayStr);
1057 qba.setBit(dayNum); 1062 qba.setBit(dayNum);
1058 index += 3; // advance to next day, or possibly "#" 1063 index += 3; // advance to next day, or possibly "#"
1059 } 1064 }
1060 } 1065 }
1061 index = last; if (tmpStr.mid(index,1) == "#") index++; 1066 index = last; if (tmpStr.mid(index,1) == "#") index++;
1062 if (tmpStr.find('T', index) != -1) { 1067 if (tmpStr.find('T', index) != -1) {
1063 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1068 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1064 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); 1069 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate);
1065 } else { 1070 } else {
1066 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1071 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1067 if (rDuration == 0) 1072 if (rDuration == 0)
1068 anEvent->recurrence()->setWeekly(rFreq, qba, -1); 1073 anEvent->recurrence()->setWeekly(rFreq, qba, -1);
1069 else 1074 else
1070 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); 1075 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration);
1071 } 1076 }
1072 } 1077 }
1073 /**************************** MONTHLY-BY-POS ***************************/ 1078 /**************************** MONTHLY-BY-POS ***************************/
1074 else if (tmpStr.left(2) == "MP") { 1079 else if (tmpStr.left(2) == "MP") {
1075 int index = tmpStr.find(' '); 1080 int index = tmpStr.find(' ');
1076 int last = tmpStr.findRev(' ') + 1; 1081 int last = tmpStr.findRev(' ') + 1;
1077 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1082 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1078 index += 1; // advance to beginning of stuff after freq 1083 index += 1; // advance to beginning of stuff after freq
1079 QBitArray qba(7); 1084 QBitArray qba(7);
1080 short tmpPos; 1085 short tmpPos;
1081 if( index == last ) { 1086 if( index == last ) {
1082 // e.g. MP1 #0 1087 // e.g. MP1 #0
1083 tmpPos = anEvent->dtStart().date().day()/7 + 1; 1088 tmpPos = anEvent->dtStart().date().day()/7 + 1;
1084 if( tmpPos == 5 ) 1089 if( tmpPos == 5 )
1085 tmpPos = -1; 1090 tmpPos = -1;
1086 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1091 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1087 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1092 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1088 } 1093 }
1089 else { 1094 else {
1090 // e.g. MP1 1+ SU #0 1095 // e.g. MP1 1+ SU #0
1091 while (index < last) { 1096 while (index < last) {
1092 tmpPos = tmpStr.mid(index,1).toShort(); 1097 tmpPos = tmpStr.mid(index,1).toShort();
1093 index += 1; 1098 index += 1;
1094 if (tmpStr.mid(index,1) == "-") 1099 if (tmpStr.mid(index,1) == "-")
1095 // convert tmpPos to negative 1100 // convert tmpPos to negative
1096 tmpPos = 0 - tmpPos; 1101 tmpPos = 0 - tmpPos;
1097 index += 2; // advance to day(s) 1102 index += 2; // advance to day(s)
1098 while (numFromDay(tmpStr.mid(index,3)) >= 0) { 1103 while (numFromDay(tmpStr.mid(index,3)) >= 0) {
1099 int dayNum = numFromDay(tmpStr.mid(index,3)); 1104 int dayNum = numFromDay(tmpStr.mid(index,3));
1100 qba.setBit(dayNum); 1105 qba.setBit(dayNum);
1101 index += 3; // advance to next day, or possibly pos or "#" 1106 index += 3; // advance to next day, or possibly pos or "#"
1102 } 1107 }
1103 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1108 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1104 qba.detach(); 1109 qba.detach();
1105 qba.fill(FALSE); // clear out 1110 qba.fill(FALSE); // clear out
1106 } // while != "#" 1111 } // while != "#"
1107 } 1112 }
1108 index = last; if (tmpStr.mid(index,1) == "#") index++; 1113 index = last; if (tmpStr.mid(index,1) == "#") index++;
1109 if (tmpStr.find('T', index) != -1) { 1114 if (tmpStr.find('T', index) != -1) {
1110 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - 1115 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() -
1111 index))).date(); 1116 index))).date();
1112 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); 1117 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate);
1113 } else { 1118 } else {
1114 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1119 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1115 if (rDuration == 0) 1120 if (rDuration == 0)
1116 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); 1121 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1);
1117 else 1122 else
1118 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); 1123 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration);
1119 } 1124 }
1120 } 1125 }
1121 1126
1122 /**************************** MONTHLY-BY-DAY ***************************/ 1127 /**************************** MONTHLY-BY-DAY ***************************/
1123 else if (tmpStr.left(2) == "MD") { 1128 else if (tmpStr.left(2) == "MD") {
1124 int index = tmpStr.find(' '); 1129 int index = tmpStr.find(' ');
1125 int last = tmpStr.findRev(' ') + 1; 1130 int last = tmpStr.findRev(' ') + 1;
1126 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1131 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1127 index += 1; 1132 index += 1;
1128 short tmpDay; 1133 short tmpDay;
1129 if( index == last ) { 1134 if( index == last ) {
1130 // e.g. MD1 #0 1135 // e.g. MD1 #0
1131 tmpDay = anEvent->dtStart().date().day(); 1136 tmpDay = anEvent->dtStart().date().day();
1132 anEvent->recurrence()->addMonthlyDay(tmpDay); 1137 anEvent->recurrence()->addMonthlyDay(tmpDay);
1133 } 1138 }
1134 else { 1139 else {
1135 // e.g. MD1 3 #0 1140 // e.g. MD1 3 #0
1136 while (index < last) { 1141 while (index < last) {
1137 int index2 = tmpStr.find(' ', index); 1142 int index2 = tmpStr.find(' ', index);
1138 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1143 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1139 index = index2-1; 1144 index = index2-1;
1140 if (tmpStr.mid(index, 1) == "-") 1145 if (tmpStr.mid(index, 1) == "-")
1141 tmpDay = 0 - tmpDay; 1146 tmpDay = 0 - tmpDay;
1142 index += 2; // advance the index; 1147 index += 2; // advance the index;
1143 anEvent->recurrence()->addMonthlyDay(tmpDay); 1148 anEvent->recurrence()->addMonthlyDay(tmpDay);
1144 } // while != # 1149 } // while != #
1145 } 1150 }
1146 index = last; if (tmpStr.mid(index,1) == "#") index++; 1151 index = last; if (tmpStr.mid(index,1) == "#") index++;
1147 if (tmpStr.find('T', index) != -1) { 1152 if (tmpStr.find('T', index) != -1) {
1148 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1153 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1149 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); 1154 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate);
1150 } else { 1155 } else {
1151 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1156 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1152 if (rDuration == 0) 1157 if (rDuration == 0)
1153 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); 1158 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1);
1154 else 1159 else
1155 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); 1160 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration);
1156 } 1161 }
1157 } 1162 }
1158 1163
1159 /*********************** YEARLY-BY-MONTH *******************************/ 1164 /*********************** YEARLY-BY-MONTH *******************************/
1160 else if (tmpStr.left(2) == "YM") { 1165 else if (tmpStr.left(2) == "YM") {
1161 int index = tmpStr.find(' '); 1166 int index = tmpStr.find(' ');
1162 int last = tmpStr.findRev(' ') + 1; 1167 int last = tmpStr.findRev(' ') + 1;
1163 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1168 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1164 index += 1; 1169 index += 1;
1165 short tmpMonth; 1170 short tmpMonth;
1166 if( index == last ) { 1171 if( index == last ) {
1167 // e.g. YM1 #0 1172 // e.g. YM1 #0
1168 tmpMonth = anEvent->dtStart().date().month(); 1173 tmpMonth = anEvent->dtStart().date().month();
1169 anEvent->recurrence()->addYearlyNum(tmpMonth); 1174 anEvent->recurrence()->addYearlyNum(tmpMonth);
1170 } 1175 }
1171 else { 1176 else {
1172 // e.g. YM1 3 #0 1177 // e.g. YM1 3 #0
1173 while (index < last) { 1178 while (index < last) {
1174 int index2 = tmpStr.find(' ', index); 1179 int index2 = tmpStr.find(' ', index);
1175 tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); 1180 tmpMonth = tmpStr.mid(index, (index2-index)).toShort();
1176 index = index2+1; 1181 index = index2+1;
1177 anEvent->recurrence()->addYearlyNum(tmpMonth); 1182 anEvent->recurrence()->addYearlyNum(tmpMonth);
1178 } // while != # 1183 } // while != #
1179 } 1184 }
1180 index = last; if (tmpStr.mid(index,1) == "#") index++; 1185 index = last; if (tmpStr.mid(index,1) == "#") index++;
1181 if (tmpStr.find('T', index) != -1) { 1186 if (tmpStr.find('T', index) != -1) {
1182 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1187 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1183 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); 1188 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate);
1184 } else { 1189 } else {
1185 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1190 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1186 if (rDuration == 0) 1191 if (rDuration == 0)
1187 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); 1192 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1);
1188 else 1193 else
1189 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); 1194 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration);
1190 } 1195 }
1191 } 1196 }
1192 1197
1193 /*********************** YEARLY-BY-DAY *********************************/ 1198 /*********************** YEARLY-BY-DAY *********************************/
1194 else if (tmpStr.left(2) == "YD") { 1199 else if (tmpStr.left(2) == "YD") {
1195 int index = tmpStr.find(' '); 1200 int index = tmpStr.find(' ');
1196 int last = tmpStr.findRev(' ') + 1; 1201 int last = tmpStr.findRev(' ') + 1;
1197 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1202 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1198 index += 1; 1203 index += 1;
1199 short tmpDay; 1204 short tmpDay;
1200 if( index == last ) { 1205 if( index == last ) {
1201 // e.g. YD1 #0 1206 // e.g. YD1 #0
1202 tmpDay = anEvent->dtStart().date().dayOfYear(); 1207 tmpDay = anEvent->dtStart().date().dayOfYear();
1203 anEvent->recurrence()->addYearlyNum(tmpDay); 1208 anEvent->recurrence()->addYearlyNum(tmpDay);
1204 } 1209 }
1205 else { 1210 else {
1206 // e.g. YD1 123 #0 1211 // e.g. YD1 123 #0
1207 while (index < last) { 1212 while (index < last) {
1208 int index2 = tmpStr.find(' ', index); 1213 int index2 = tmpStr.find(' ', index);
1209 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1214 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1210 index = index2+1; 1215 index = index2+1;
1211 anEvent->recurrence()->addYearlyNum(tmpDay); 1216 anEvent->recurrence()->addYearlyNum(tmpDay);
1212 } // while != # 1217 } // while != #
1213 } 1218 }
1214 index = last; if (tmpStr.mid(index,1) == "#") index++; 1219 index = last; if (tmpStr.mid(index,1) == "#") index++;
1215 if (tmpStr.find('T', index) != -1) { 1220 if (tmpStr.find('T', index) != -1) {
1216 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1221 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1217 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); 1222 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate);
1218 } else { 1223 } else {
1219 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1224 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1220 if (rDuration == 0) 1225 if (rDuration == 0)
1221 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); 1226 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1);
1222 else 1227 else
1223 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); 1228 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration);
1224 } 1229 }
1225 } else { 1230 } else {
1226 kdDebug(5800) << "we don't understand this type of recurrence!" << endl; 1231 kdDebug(5800) << "we don't understand this type of recurrence!" << endl;
1227 } // if 1232 } // if
1228 } // repeats 1233 } // repeats
1229 1234
1230 1235
1231 // recurrence exceptions 1236 // recurrence exceptions
1232 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { 1237 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) {
1233 s = fakeCString(vObjectUStringZValue(vo)); 1238 s = fakeCString(vObjectUStringZValue(vo));
1234 QStringList exDates = QStringList::split(",",s); 1239 QStringList exDates = QStringList::split(",",s);
1235 QStringList::ConstIterator it; 1240 QStringList::ConstIterator it;
1236 for(it = exDates.begin(); it != exDates.end(); ++it ) { 1241 for(it = exDates.begin(); it != exDates.end(); ++it ) {
1237 anEvent->addExDate(ISOToQDate(*it)); 1242 anEvent->addExDate(ISOToQDate(*it));
1238 } 1243 }
1239 deleteStr(s); 1244 deleteStr(s);
1240 } 1245 }
1241 1246
1242 // summary 1247 // summary
1243 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { 1248 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) {
1244 s = fakeCString(vObjectUStringZValue(vo)); 1249 s = fakeCString(vObjectUStringZValue(vo));
1245 anEvent->setSummary(QString::fromLocal8Bit(s)); 1250 anEvent->setSummary(QString::fromLocal8Bit(s));
1246 deleteStr(s); 1251 deleteStr(s);
1247 } 1252 }
1248 if ((vo = isAPropertyOf(vevent, VCLocationProp))) { 1253 if ((vo = isAPropertyOf(vevent, VCLocationProp))) {
1249 s = fakeCString(vObjectUStringZValue(vo)); 1254 s = fakeCString(vObjectUStringZValue(vo));
1250 anEvent->setLocation(QString::fromLocal8Bit(s)); 1255 anEvent->setLocation(QString::fromLocal8Bit(s));
1251 deleteStr(s); 1256 deleteStr(s);
1252 } 1257 }
1253 1258
1254 // description 1259 // description
1255 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { 1260 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) {
1256 s = fakeCString(vObjectUStringZValue(vo)); 1261 s = fakeCString(vObjectUStringZValue(vo));
1257 if (!anEvent->description().isEmpty()) { 1262 if (!anEvent->description().isEmpty()) {
1258 anEvent->setDescription(anEvent->description() + "\n" + 1263 anEvent->setDescription(anEvent->description() + "\n" +
1259 QString::fromLocal8Bit(s)); 1264 QString::fromLocal8Bit(s));
1260 } else { 1265 } else {
1261 anEvent->setDescription(QString::fromLocal8Bit(s)); 1266 anEvent->setDescription(QString::fromLocal8Bit(s));
1262 } 1267 }
1263 deleteStr(s); 1268 deleteStr(s);
1264 } 1269 }
1265 1270
1266 // some stupid vCal exporters ignore the standard and use Description 1271 // some stupid vCal exporters ignore the standard and use Description
1267 // instead of Summary for the default field. Correct for this. 1272 // instead of Summary for the default field. Correct for this.
1268 if (anEvent->summary().isEmpty() && 1273 if (anEvent->summary().isEmpty() &&
1269 !(anEvent->description().isEmpty())) { 1274 !(anEvent->description().isEmpty())) {
1270 QString tmpStr = anEvent->description().simplifyWhiteSpace(); 1275 QString tmpStr = anEvent->description().simplifyWhiteSpace();
1271 anEvent->setDescription(""); 1276 anEvent->setDescription("");
1272 anEvent->setSummary(tmpStr); 1277 anEvent->setSummary(tmpStr);
1273 } 1278 }
1274 1279
1275#if 0 1280#if 0
1276 // status 1281 // status
1277 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { 1282 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) {
1278 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); 1283 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo)));
1279 deleteStr(s); 1284 deleteStr(s);
1280// TODO: Define Event status 1285// TODO: Define Event status
1281// anEvent->setStatus(tmpStr); 1286// anEvent->setStatus(tmpStr);
1282 } 1287 }
1283 else 1288 else
1284// anEvent->setStatus("NEEDS ACTION"); 1289// anEvent->setStatus("NEEDS ACTION");
1285#endif 1290#endif
1286 1291
1287 // secrecy 1292 // secrecy
1288 int secrecy = Incidence::SecrecyPublic; 1293 int secrecy = Incidence::SecrecyPublic;
1289 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 1294 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
1290 s = fakeCString(vObjectUStringZValue(vo)); 1295 s = fakeCString(vObjectUStringZValue(vo));
1291 if (strcmp(s,"PRIVATE") == 0) { 1296 if (strcmp(s,"PRIVATE") == 0) {
1292 secrecy = Incidence::SecrecyPrivate; 1297 secrecy = Incidence::SecrecyPrivate;
1293 } else if (strcmp(s,"CONFIDENTIAL") == 0) { 1298 } else if (strcmp(s,"CONFIDENTIAL") == 0) {
1294 secrecy = Incidence::SecrecyConfidential; 1299 secrecy = Incidence::SecrecyConfidential;
1295 } 1300 }
1296 deleteStr(s); 1301 deleteStr(s);
1297 } 1302 }
1298 anEvent->setSecrecy(secrecy); 1303 anEvent->setSecrecy(secrecy);
1299 1304
1300 // categories 1305 // categories
1301 QStringList tmpStrList; 1306 QStringList tmpStrList;
1302 int index1 = 0; 1307 int index1 = 0;
1303 int index2 = 0; 1308 int index2 = 0;
1304 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { 1309 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1305 s = fakeCString(vObjectUStringZValue(vo)); 1310 s = fakeCString(vObjectUStringZValue(vo));
1306 QString categories = QString::fromLocal8Bit(s); 1311 QString categories = QString::fromLocal8Bit(s);
1307 deleteStr(s); 1312 deleteStr(s);
1308 //const char* category; 1313 //const char* category;
1309 QString category; 1314 QString category;
1310 while ((index2 = categories.find(',', index1)) != -1) { 1315 while ((index2 = categories.find(',', index1)) != -1) {
1311 //category = (const char *) categories.mid(index1, (index2 - index1)); 1316 //category = (const char *) categories.mid(index1, (index2 - index1));
1312 category = categories.mid(index1, (index2 - index1)); 1317 category = categories.mid(index1, (index2 - index1));
1313 tmpStrList.append(category); 1318 tmpStrList.append(category);
1314 index1 = index2+1; 1319 index1 = index2+1;
1315 } 1320 }
1316 // get last category 1321 // get last category
1317 category = categories.mid(index1, (categories.length()-index1)); 1322 category = categories.mid(index1, (categories.length()-index1));
1318 tmpStrList.append(category); 1323 tmpStrList.append(category);
1319 anEvent->setCategories(tmpStrList); 1324 anEvent->setCategories(tmpStrList);
1320 } 1325 }
1321 1326
1322 // attachments 1327 // attachments
1323 tmpStrList.clear(); 1328 tmpStrList.clear();
1324 initPropIterator(&voi, vevent); 1329 initPropIterator(&voi, vevent);
1325 while (moreIteration(&voi)) { 1330 while (moreIteration(&voi)) {
1326 vo = nextVObject(&voi); 1331 vo = nextVObject(&voi);
1327 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 1332 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1328 s = fakeCString(vObjectUStringZValue(vo)); 1333 s = fakeCString(vObjectUStringZValue(vo));
1329 anEvent->addAttachment(new Attachment(QString(s))); 1334 anEvent->addAttachment(new Attachment(QString(s)));
1330 deleteStr(s); 1335 deleteStr(s);
1331 } 1336 }
1332 } 1337 }
1333 1338
1334 // resources 1339 // resources
1335 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 1340 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1336 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1341 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1337 deleteStr(s); 1342 deleteStr(s);
1338 tmpStrList.clear(); 1343 tmpStrList.clear();
1339 index1 = 0; 1344 index1 = 0;
1340 index2 = 0; 1345 index2 = 0;
1341 QString resource; 1346 QString resource;
1342 while ((index2 = resources.find(';', index1)) != -1) { 1347 while ((index2 = resources.find(';', index1)) != -1) {
1343 resource = resources.mid(index1, (index2 - index1)); 1348 resource = resources.mid(index1, (index2 - index1));
1344 tmpStrList.append(resource); 1349 tmpStrList.append(resource);
1345 index1 = index2; 1350 index1 = index2;
1346 } 1351 }
1347 anEvent->setResources(tmpStrList); 1352 anEvent->setResources(tmpStrList);
1348 } 1353 }
1349 1354
1350 /* alarm stuff */ 1355 /* alarm stuff */
1351 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1356 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1352 Alarm* alarm = anEvent->newAlarm(); 1357 Alarm* alarm = anEvent->newAlarm();
1353 VObject *a; 1358 VObject *a;
1354 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1359 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1355 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1360 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1356 deleteStr(s); 1361 deleteStr(s);
1357 } 1362 }
1358 alarm->setEnabled(true); 1363 alarm->setEnabled(true);
1359 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1364 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1360 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1365 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1361 s = fakeCString(vObjectUStringZValue(a)); 1366 s = fakeCString(vObjectUStringZValue(a));
1362 alarm->setProcedureAlarm(QFile::decodeName(s)); 1367 alarm->setProcedureAlarm(QFile::decodeName(s));
1363 deleteStr(s); 1368 deleteStr(s);
1364 } 1369 }
1365 } 1370 }
1366 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1371 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1367 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1372 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1368 s = fakeCString(vObjectUStringZValue(a)); 1373 s = fakeCString(vObjectUStringZValue(a));
1369 alarm->setAudioAlarm(QFile::decodeName(s)); 1374 alarm->setAudioAlarm(QFile::decodeName(s));
1370 deleteStr(s); 1375 deleteStr(s);
1371 } 1376 }
1372 } 1377 }
1373 } 1378 }
1374 1379
1375 // priority 1380 // priority
1376 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1381 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1377 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1382 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1378 deleteStr(s); 1383 deleteStr(s);
1379 } 1384 }
1380 1385
1381 // transparency 1386 // transparency
1382 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1387 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1383 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1388 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1384 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1389 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1385 deleteStr(s); 1390 deleteStr(s);
1386 } 1391 }
1387 1392
1388 // related event 1393 // related event
1389 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1394 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1390 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1395 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1391 deleteStr(s); 1396 deleteStr(s);
1392 mEventsRelate.append(anEvent); 1397 mEventsRelate.append(anEvent);
1393 } 1398 }
1394 1399
1395 /* PILOT SYNC STUFF */ 1400 /* PILOT SYNC STUFF */
1396 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1401 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1397 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1402 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1398 deleteStr(s); 1403 deleteStr(s);
1399 } 1404 }
1400 else 1405 else
1401 anEvent->setPilotId(0); 1406 anEvent->setPilotId(0);
1402 1407
1403 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1408 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1404 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1409 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1405 deleteStr(s); 1410 deleteStr(s);
1406 } 1411 }
1407 else 1412 else
1408 anEvent->setSyncStatus(Event::SYNCMOD); 1413 anEvent->setSyncStatus(Event::SYNCMOD);
1409 1414
1410 return anEvent; 1415 return anEvent;
1411} 1416}
1412 1417
1413 1418
1414QString VCalFormat::qDateToISO(const QDate &qd) 1419QString VCalFormat::qDateToISO(const QDate &qd)
1415{ 1420{
1416 QString tmpStr; 1421 QString tmpStr;
1417 1422
1418 ASSERT(qd.isValid()); 1423 ASSERT(qd.isValid());
1419 1424
1420 tmpStr.sprintf("%.2d%.2d%.2d", 1425 tmpStr.sprintf("%.2d%.2d%.2d",
1421 qd.year(), qd.month(), qd.day()); 1426 qd.year(), qd.month(), qd.day());
1422 return tmpStr; 1427 return tmpStr;
1423 1428
1424} 1429}
1425 1430
1426QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1431QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1427{ 1432{
1428 QString tmpStr; 1433 QString tmpStr;
1429 1434
1430 ASSERT(qdt.date().isValid()); 1435 ASSERT(qdt.date().isValid());
1431 ASSERT(qdt.time().isValid()); 1436 ASSERT(qdt.time().isValid());
1432 if (zulu) { 1437 if (zulu) {
1433 QDateTime tmpDT(qdt); 1438 QDateTime tmpDT(qdt);
1434 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT. 1439 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT.
1435 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1440 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1436 tmpDT.date().year(), tmpDT.date().month(), 1441 tmpDT.date().year(), tmpDT.date().month(),
1437 tmpDT.date().day(), tmpDT.time().hour(), 1442 tmpDT.date().day(), tmpDT.time().hour(),
1438 tmpDT.time().minute(), tmpDT.time().second()); 1443 tmpDT.time().minute(), tmpDT.time().second());
1439 } else { 1444 } else {
1440 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1445 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1441 qdt.date().year(), qdt.date().month(), 1446 qdt.date().year(), qdt.date().month(),
1442 qdt.date().day(), qdt.time().hour(), 1447 qdt.date().day(), qdt.time().hour(),
1443 qdt.time().minute(), qdt.time().second()); 1448 qdt.time().minute(), qdt.time().second());
1444 } 1449 }
1445 return tmpStr; 1450 return tmpStr;
1446} 1451}
1447 1452
1448QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1453QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1449{ 1454{
1450 QDate tmpDate; 1455 QDate tmpDate;
1451 QTime tmpTime; 1456 QTime tmpTime;
1452 QString tmpStr; 1457 QString tmpStr;
1453 int year, month, day, hour, minute, second; 1458 int year, month, day, hour, minute, second;
1454 1459
1455 tmpStr = dtStr; 1460 tmpStr = dtStr;
1456 year = tmpStr.left(4).toInt(); 1461 year = tmpStr.left(4).toInt();
1457 month = tmpStr.mid(4,2).toInt(); 1462 month = tmpStr.mid(4,2).toInt();
1458 day = tmpStr.mid(6,2).toInt(); 1463 day = tmpStr.mid(6,2).toInt();
1459 hour = tmpStr.mid(9,2).toInt(); 1464 hour = tmpStr.mid(9,2).toInt();
1460 minute = tmpStr.mid(11,2).toInt(); 1465 minute = tmpStr.mid(11,2).toInt();
1461 second = tmpStr.mid(13,2).toInt(); 1466 second = tmpStr.mid(13,2).toInt();
1462 tmpDate.setYMD(year, month, day); 1467 tmpDate.setYMD(year, month, day);
1463 tmpTime.setHMS(hour, minute, second); 1468 tmpTime.setHMS(hour, minute, second);
1464 1469
1465 ASSERT(tmpDate.isValid()); 1470 ASSERT(tmpDate.isValid());
1466 ASSERT(tmpTime.isValid()); 1471 ASSERT(tmpTime.isValid());
1467 QDateTime tmpDT(tmpDate, tmpTime); 1472 QDateTime tmpDT(tmpDate, tmpTime);
1468 // correct for GMT if string is in Zulu format 1473 // correct for GMT if string is in Zulu format
1469 if (dtStr.at(dtStr.length()-1) == 'Z') 1474 if (dtStr.at(dtStr.length()-1) == 'Z')
1470 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); 1475 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone());
1471 return tmpDT; 1476 return tmpDT;
1472} 1477}
1473 1478
1474QDate VCalFormat::ISOToQDate(const QString &dateStr) 1479QDate VCalFormat::ISOToQDate(const QString &dateStr)
1475{ 1480{
1476 int year, month, day; 1481 int year, month, day;
1477 1482
1478 year = dateStr.left(4).toInt(); 1483 year = dateStr.left(4).toInt();
1479 month = dateStr.mid(4,2).toInt(); 1484 month = dateStr.mid(4,2).toInt();
1480 day = dateStr.mid(6,2).toInt(); 1485 day = dateStr.mid(6,2).toInt();
1481 1486
1482 return(QDate(year, month, day)); 1487 return(QDate(year, month, day));
1483} 1488}
1484 1489
1485// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1490// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1486// and break it down from it's tree-like format into the dictionary format 1491// and break it down from it's tree-like format into the dictionary format
1487// that is used internally in the VCalFormat. 1492// that is used internally in the VCalFormat.
1488void VCalFormat::populate(VObject *vcal) 1493void VCalFormat::populate(VObject *vcal)
1489{ 1494{
1490 // this function will populate the caldict dictionary and other event 1495 // this function will populate the caldict dictionary and other event
1491 // lists. It turns vevents into Events and then inserts them. 1496 // lists. It turns vevents into Events and then inserts them.
1492 1497
1493 VObjectIterator i; 1498 VObjectIterator i;
1494 VObject *curVO, *curVOProp; 1499 VObject *curVO, *curVOProp;
1495 Event *anEvent; 1500 Event *anEvent;
1496 1501
1497 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1502 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1498 char *methodType = 0; 1503 char *methodType = 0;
1499 methodType = fakeCString(vObjectUStringZValue(curVO)); 1504 methodType = fakeCString(vObjectUStringZValue(curVO));
1500 kdDebug() << "This calendar is an iTIP transaction of type '" 1505 kdDebug() << "This calendar is an iTIP transaction of type '"
1501 << methodType << "'" << endl; 1506 << methodType << "'" << endl;
1502 delete methodType; 1507 delete methodType;
1503 } 1508 }
1504 1509
1505 // warn the user that we might have trouble reading non-known calendar. 1510 // warn the user that we might have trouble reading non-known calendar.
1506 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1511 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1507 char *s = fakeCString(vObjectUStringZValue(curVO)); 1512 char *s = fakeCString(vObjectUStringZValue(curVO));
1508 if (strcmp(productId().local8Bit(), s) != 0) 1513 if (strcmp(productId().local8Bit(), s) != 0)
1509 kdDebug() << "This vCalendar file was not created by KOrganizer " 1514 kdDebug() << "This vCalendar file was not created by KOrganizer "
1510 "or any other product we support. Loading anyway..." << endl; 1515 "or any other product we support. Loading anyway..." << endl;
1511 mLoadedProductId = s; 1516 mLoadedProductId = s;
1512 deleteStr(s); 1517 deleteStr(s);
1513 } 1518 }
1514 1519
1515 // warn the user we might have trouble reading this unknown version. 1520 // warn the user we might have trouble reading this unknown version.
1516 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1521 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1517 char *s = fakeCString(vObjectUStringZValue(curVO)); 1522 char *s = fakeCString(vObjectUStringZValue(curVO));
1518 if (strcmp(_VCAL_VERSION, s) != 0) 1523 if (strcmp(_VCAL_VERSION, s) != 0)
1519 kdDebug() << "This vCalendar file has version " << s 1524 kdDebug() << "This vCalendar file has version " << s
1520 << "We only support " << _VCAL_VERSION << endl; 1525 << "We only support " << _VCAL_VERSION << endl;
1521 deleteStr(s); 1526 deleteStr(s);
1522 } 1527 }
1523 1528
1524 // set the time zone 1529 // set the time zone
1525 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1530 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1526 char *s = fakeCString(vObjectUStringZValue(curVO)); 1531 char *s = fakeCString(vObjectUStringZValue(curVO));
1527 mCalendar->setTimeZone(s); 1532 mCalendar->setTimeZone(s);
1528 deleteStr(s); 1533 deleteStr(s);
1529 } 1534 }
1530 1535
1531 1536
1532 // Store all events with a relatedTo property in a list for post-processing 1537 // Store all events with a relatedTo property in a list for post-processing
1533 mEventsRelate.clear(); 1538 mEventsRelate.clear();
1534 mTodosRelate.clear(); 1539 mTodosRelate.clear();
1535 1540
1536 initPropIterator(&i, vcal); 1541 initPropIterator(&i, vcal);
1537 1542
1538 // go through all the vobjects in the vcal 1543 // go through all the vobjects in the vcal
1539 while (moreIteration(&i)) { 1544 while (moreIteration(&i)) {
1540 curVO = nextVObject(&i); 1545 curVO = nextVObject(&i);
1541 1546
1542 /************************************************************************/ 1547 /************************************************************************/
1543 1548
1544 // now, check to see that the object is an event or todo. 1549 // now, check to see that the object is an event or todo.
1545 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1550 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1546 1551
1547 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { 1552 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) {
1548 char *s; 1553 char *s;
1549 s = fakeCString(vObjectUStringZValue(curVOProp)); 1554 s = fakeCString(vObjectUStringZValue(curVOProp));
1550 // check to see if event was deleted by the kpilot conduit 1555 // check to see if event was deleted by the kpilot conduit
1551 if (atoi(s) == Event::SYNCDEL) { 1556 if (atoi(s) == Event::SYNCDEL) {
1552 deleteStr(s); 1557 deleteStr(s);
1553 kdDebug(5800) << "skipping pilot-deleted event" << endl; 1558 kdDebug(5800) << "skipping pilot-deleted event" << endl;
1554 goto SKIP; 1559 goto SKIP;
1555 } 1560 }
1556 deleteStr(s); 1561 deleteStr(s);
1557 } 1562 }
1558 1563
1559 // this code checks to see if we are trying to read in an event 1564 // this code checks to see if we are trying to read in an event
1560 // that we already find to be in the calendar. If we find this 1565 // that we already find to be in the calendar. If we find this
1561 // to be the case, we skip the event. 1566 // to be the case, we skip the event.
1562 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1567 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1563 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1568 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1564 QString tmpStr(s); 1569 QString tmpStr(s);
1565 deleteStr(s); 1570 deleteStr(s);
1566 1571
1567 if (mCalendar->event(tmpStr)) { 1572 if (mCalendar->event(tmpStr)) {
1568 goto SKIP; 1573 goto SKIP;
1569 } 1574 }
1570 if (mCalendar->todo(tmpStr)) { 1575 if (mCalendar->todo(tmpStr)) {
1571 goto SKIP; 1576 goto SKIP;
1572 } 1577 }
1573 } 1578 }
1574 1579
1575 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1580 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1576 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 1581 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1577 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 1582 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1578 goto SKIP; 1583 goto SKIP;
1579 } 1584 }
1580 1585
1581 anEvent = VEventToEvent(curVO); 1586 anEvent = VEventToEvent(curVO);
1582 // we now use addEvent instead of insertEvent so that the 1587 // we now use addEvent instead of insertEvent so that the
1583 // signal/slot get connected. 1588 // signal/slot get connected.
1584 if (anEvent) { 1589 if (anEvent) {
1585 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { 1590 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) {
1586 kdDebug() << "VCalFormat::populate(): Event has invalid dates." 1591 kdDebug() << "VCalFormat::populate(): Event has invalid dates."
1587 << endl; 1592 << endl;
1588 } else { 1593 } else {
1589 mCalendar->addEvent(anEvent); 1594 mCalendar->addEvent(anEvent);
1590 } 1595 }
1591 } else { 1596 } else {
1592 // some sort of error must have occurred while in translation. 1597 // some sort of error must have occurred while in translation.
1593 goto SKIP; 1598 goto SKIP;
1594 } 1599 }
1595 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 1600 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1596 Todo *aTodo = VTodoToEvent(curVO); 1601 Todo *aTodo = VTodoToEvent(curVO);
1597 mCalendar->addTodo(aTodo); 1602 mCalendar->addTodo(aTodo);
1598 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 1603 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1599 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 1604 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1600 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 1605 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1601 // do nothing, we know these properties and we want to skip them. 1606 // do nothing, we know these properties and we want to skip them.
1602 // we have either already processed them or are ignoring them. 1607 // we have either already processed them or are ignoring them.
1603 ; 1608 ;
1604 } else { 1609 } else {
1605 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; 1610 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl;
1606 } 1611 }
1607 SKIP: 1612 SKIP:
1608 ; 1613 ;
1609 } // while 1614 } // while
1610 1615
1611 // Post-Process list of events with relations, put Event objects in relation 1616 // Post-Process list of events with relations, put Event objects in relation
1612 Event *ev; 1617 Event *ev;
1613 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 1618 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
1614 ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); 1619 ev->setRelatedTo(mCalendar->event(ev->relatedToUid()));
1615 } 1620 }
1616 Todo *todo; 1621 Todo *todo;
1617 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 1622 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
1618 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); 1623 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid()));
1619 } 1624 }
1620} 1625}
1621 1626
1622const char *VCalFormat::dayFromNum(int day) 1627const char *VCalFormat::dayFromNum(int day)
1623{ 1628{
1624 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; 1629 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " };
1625 1630
1626 return days[day]; 1631 return days[day];
1627} 1632}
1628 1633
1629int VCalFormat::numFromDay(const QString &day) 1634int VCalFormat::numFromDay(const QString &day)
1630{ 1635{
1631 if (day == "MO ") return 0; 1636 if (day == "MO ") return 0;
1632 if (day == "TU ") return 1; 1637 if (day == "TU ") return 1;
1633 if (day == "WE ") return 2; 1638 if (day == "WE ") return 2;
1634 if (day == "TH ") return 3; 1639 if (day == "TH ") return 3;
1635 if (day == "FR ") return 4; 1640 if (day == "FR ") return 4;
1636 if (day == "SA ") return 5; 1641 if (day == "SA ") return 5;
1637 if (day == "SU ") return 6; 1642 if (day == "SU ") return 6;
1638 1643
1639 return -1; // something bad happened. :) 1644 return -1; // something bad happened. :)
1640} 1645}
1641 1646
1642Attendee::PartStat VCalFormat::readStatus(const char *s) const 1647Attendee::PartStat VCalFormat::readStatus(const char *s) const
1643{ 1648{
1644 QString statStr = s; 1649 QString statStr = s;
1645 statStr = statStr.upper(); 1650 statStr = statStr.upper();
1646 Attendee::PartStat status; 1651 Attendee::PartStat status;
1647 1652
1648 if (statStr == "X-ACTION") 1653 if (statStr == "X-ACTION")
1649 status = Attendee::NeedsAction; 1654 status = Attendee::NeedsAction;
1650 else if (statStr == "NEEDS ACTION") 1655 else if (statStr == "NEEDS ACTION")
1651 status = Attendee::NeedsAction; 1656 status = Attendee::NeedsAction;
1652 else if (statStr== "ACCEPTED") 1657 else if (statStr== "ACCEPTED")
1653 status = Attendee::Accepted; 1658 status = Attendee::Accepted;
1654 else if (statStr== "SENT") 1659 else if (statStr== "SENT")
1655 status = Attendee::NeedsAction; 1660 status = Attendee::NeedsAction;
1656 else if (statStr== "TENTATIVE") 1661 else if (statStr== "TENTATIVE")
1657 status = Attendee::Tentative; 1662 status = Attendee::Tentative;
1658 else if (statStr== "CONFIRMED") 1663 else if (statStr== "CONFIRMED")
1659 status = Attendee::Accepted; 1664 status = Attendee::Accepted;
1660 else if (statStr== "DECLINED") 1665 else if (statStr== "DECLINED")
1661 status = Attendee::Declined; 1666 status = Attendee::Declined;
1662 else if (statStr== "COMPLETED") 1667 else if (statStr== "COMPLETED")
1663 status = Attendee::Completed; 1668 status = Attendee::Completed;
1664 else if (statStr== "DELEGATED") 1669 else if (statStr== "DELEGATED")
1665 status = Attendee::Delegated; 1670 status = Attendee::Delegated;
1666 else { 1671 else {
1667 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; 1672 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl;
1668 status = Attendee::NeedsAction; 1673 status = Attendee::NeedsAction;
1669 } 1674 }
1670 1675
1671 return status; 1676 return status;
1672} 1677}
1673 1678
1674QCString VCalFormat::writeStatus(Attendee::PartStat status) const 1679QCString VCalFormat::writeStatus(Attendee::PartStat status) const
1675{ 1680{
1676 switch(status) { 1681 switch(status) {
1677 default: 1682 default:
1678 case Attendee::NeedsAction: 1683 case Attendee::NeedsAction:
1679 return "NEEDS ACTION"; 1684 return "NEEDS ACTION";
1680 break; 1685 break;
1681 case Attendee::Accepted: 1686 case Attendee::Accepted:
1682 return "ACCEPTED"; 1687 return "ACCEPTED";
1683 break; 1688 break;
1684 case Attendee::Declined: 1689 case Attendee::Declined:
1685 return "DECLINED"; 1690 return "DECLINED";
1686 break; 1691 break;
1687 case Attendee::Tentative: 1692 case Attendee::Tentative:
1688 return "TENTATIVE"; 1693 return "TENTATIVE";
1689 break; 1694 break;
1690 case Attendee::Delegated: 1695 case Attendee::Delegated:
1691 return "DELEGATED"; 1696 return "DELEGATED";
1692 break; 1697 break;
1693 case Attendee::Completed: 1698 case Attendee::Completed:
1694 return "COMPLETED"; 1699 return "COMPLETED";
1695 break; 1700 break;
1696 case Attendee::InProcess: 1701 case Attendee::InProcess:
1697 return "NEEDS ACTION"; 1702 return "NEEDS ACTION";
1698 break; 1703 break;
1699 } 1704 }
1700} 1705}
diff --git a/microkde/kidmanager.cpp b/microkde/kidmanager.cpp
index d24a41f..8cf486a 100644
--- a/microkde/kidmanager.cpp
+++ b/microkde/kidmanager.cpp
@@ -1,136 +1,136 @@
1#include "kidmanager.h" 1#include "kidmanager.h"
2 2
3KIdManager::KIdManager() 3KIdManager::KIdManager()
4{ 4{
5 5
6} 6}
7// :profilename;12;id_withLen12;123456: 7// :profilename;12;id_withLen12;123456:
8// 123456 is the csum 8// 123456 is the csum
9QString KIdManager::setId (const QString& idString,const QString& prof,const QString& idvalue ) 9QString KIdManager::setId (const QString& idString,const QString& prof,const QString& idvalue )
10{ 10{
11 int startProf; 11 int startProf;
12 int startIDnum; 12 int startIDnum;
13 int startIDnumlen; 13 int startIDnumlen;
14 int startID; 14 int startID;
15 int lenID; 15 int lenID;
16 int startCsum; 16 int startCsum;
17 int lenCsum; 17 int lenCsum;
18 int endall; 18 int endall;
19 QString newIDString; 19 QString newIDString;
20 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) { 20 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
21 newIDString = idString.left(startIDnum ) + QString::number( idvalue.length() ) +";"+idvalue+ ";"+idString.mid( startCsum ); 21 newIDString = idString.left(startIDnum ) + QString::number( idvalue.length() ) +";"+idvalue+ ";"+idString.mid( startCsum );
22 } else { 22 } else {
23 newIDString = idString + prof+";"+ QString::number( idvalue.length() ) +";"+idvalue +";0:"; 23 newIDString = idString + prof+";"+ QString::number( idvalue.length() ) +";"+idvalue +";0:";
24 } 24 }
25 qDebug("setID:profile:%s*retval:%s*idvalue:%s* ", prof.latin1(), newIDString.latin1() ,idvalue.latin1() ); 25 //qDebug("setID:profile:%s*retval:%s*idvalue:%s* ", prof.latin1(), newIDString.latin1() ,idvalue.latin1() );
26 return newIDString; 26 return newIDString;
27} 27}
28QString KIdManager::getId (const QString& idString,const QString& prof ) 28QString KIdManager::getId (const QString& idString,const QString& prof )
29{ 29{
30 int startProf; 30 int startProf;
31 int startIDnum; 31 int startIDnum;
32 int startIDnumlen; 32 int startIDnumlen;
33 int startID; 33 int startID;
34 int lenID; 34 int lenID;
35 int startCsum; 35 int startCsum;
36 int lenCsum; 36 int lenCsum;
37 int endall; 37 int endall;
38 QString idval = ""; 38 QString idval = "";
39 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) 39 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) )
40 idval = idString.mid( startID, lenID ); 40 idval = idString.mid( startID, lenID );
41 41
42 qDebug("getID:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() ); 42 //qDebug("getID:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() );
43 return idval; 43 return idval;
44 44
45} 45}
46 46
47QString KIdManager::removeId (const QString& idString,const QString& prof ) 47QString KIdManager::removeId (const QString& idString,const QString& prof )
48{ 48{
49 int startProf; 49 int startProf;
50 int startIDnum; 50 int startIDnum;
51 int startIDnumlen; 51 int startIDnumlen;
52 int startID; 52 int startID;
53 int lenID; 53 int lenID;
54 int startCsum; 54 int startCsum;
55 int lenCsum; 55 int lenCsum;
56 int endall; 56 int endall;
57 QString newIDString; 57 QString newIDString;
58 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) { 58 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
59 newIDString = idString.left(startProf) + idString.mid( endall ); 59 newIDString = idString.left(startProf) + idString.mid( endall+1 );
60 } else { 60 } else {
61 newIDString = idString; 61 newIDString = idString;
62 } 62 }
63 qDebug("removeID:profile:%s*retval:%s*oldidstring:%s* ", prof.latin1(), newIDString.latin1() ,idString.latin1() ); 63 //qDebug("removeID:profile:%s*retval:%s*oldidstring:%s* ", prof.latin1(), newIDString.latin1() ,idString.latin1() );
64 return newIDString; 64 return newIDString;
65} 65}
66 66
67QString KIdManager::setCsum (const QString& idString,const QString& prof,const QString& idCsum ) 67QString KIdManager::setCsum (const QString& idString,const QString& prof,const QString& idCsum )
68{ 68{
69 int startProf; 69 int startProf;
70 int startIDnum; 70 int startIDnum;
71 int startIDnumlen; 71 int startIDnumlen;
72 int startID; 72 int startID;
73 int lenID; 73 int lenID;
74 int startCsum; 74 int startCsum;
75 int lenCsum; 75 int lenCsum;
76 int endall; 76 int endall;
77 QString newIDString; 77 QString newIDString;
78 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) { 78 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
79 newIDString = idString.left(startCsum) + idCsum+ idString.mid( endall +1); 79 newIDString = idString.left(startCsum) + idCsum+ idString.mid( endall +1);
80 } else { 80 } else {
81 newIDString = idString + prof + ";3;_u_;"+ idCsum + ":"; 81 newIDString = idString + prof + ";3;_u_;"+ idCsum + ":";
82 } 82 }
83 qDebug("setCsum:profile:%s*retval:%s*idCsum:%s* ", prof.latin1(), newIDString.latin1() ,idCsum.latin1() ); 83 //qDebug("setCsum:profile:%s*retval:%s*idCsum:%s* ", prof.latin1(), newIDString.latin1() ,idCsum.latin1() );
84 return newIDString; 84 return newIDString;
85} 85}
86QString KIdManager::getCsum (const QString& idString,const QString& prof ) 86QString KIdManager::getCsum (const QString& idString,const QString& prof )
87{ 87{
88 int startProf; 88 int startProf;
89 int startIDnum; 89 int startIDnum;
90 int startIDnumlen; 90 int startIDnumlen;
91 int startID; 91 int startID;
92 int lenID; 92 int lenID;
93 int startCsum; 93 int startCsum;
94 int lenCsum; 94 int lenCsum;
95 int endall; 95 int endall;
96 QString idval = ""; 96 QString idval = "";
97 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) 97 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) )
98 idval = idString.mid( startCsum, lenCsum ); 98 idval = idString.mid( startCsum, lenCsum );
99 99
100 qDebug("getCsum:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() ); 100 //qDebug("getCsum:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() );
101 return idval; 101 return idval;
102} 102}
103// :profilename;12;id_withLen12;123456: 103// :profilename;12;id_withLen12;123456:
104bool KIdManager::getNumbers (const QString& idString,const QString& prof, int &startProf, int &startIDnum, int &startIDnumlen,int &startID, int& lenID, int &startCsum, int &lenCsum, int & endall) 104bool KIdManager::getNumbers (const QString& idString,const QString& prof, int &startProf, int &startIDnum, int &startIDnumlen,int &startID, int& lenID, int &startCsum, int &lenCsum, int & endall)
105{ 105{
106 startProf = idString.find( ":"+prof+";" ); 106 startProf = idString.find( ":"+prof+";" );
107 if ( startProf >= 0 ) { 107 if ( startProf >= 0 ) {
108 startIDnum = prof.length()+2+startProf; 108 startIDnum = prof.length()+2+startProf;
109 startID = idString.find( ";", startIDnum ) +1; 109 startID = idString.find( ";", startIDnum ) +1;
110 startIDnumlen = startID - startIDnum - 1; 110 startIDnumlen = startID - startIDnum - 1;
111 if ( startIDnum > 0 ) { 111 if ( startIDnum > 0 ) {
112 bool ok; 112 bool ok;
113 lenID = idString.mid ( startIDnum,startIDnumlen).toInt( &ok ); 113 lenID = idString.mid ( startIDnum,startIDnumlen).toInt( &ok );
114 if (ok) { 114 if (ok) {
115 startCsum = startID+lenID+1; 115 startCsum = startID+lenID+1;
116 endall = idString.find( ":", startCsum )-1; 116 endall = idString.find( ":", startCsum )-1;
117 if ( endall < 0 ) { 117 if ( endall < 0 ) {
118 qDebug("Error getNumbers: andall not found "); 118 qDebug("Error getNumbers: andall not found ");
119 return false; 119 return false;
120 } 120 }
121 lenCsum = endall-startCsum+1; 121 lenCsum = endall-startCsum+1;
122 } 122 }
123 else { 123 else {
124 qDebug("Error getNumbers:length is no number:*%s* ", idString.mid ( startIDnum,startIDnumlen).toInt( &ok )); 124 qDebug("Error getNumbers:length is no number:*%s* ", idString.mid ( startIDnum,startIDnumlen).toInt( &ok ));
125 return false; 125 return false;
126 } 126 }
127 } else { 127 } else {
128 qDebug("Error in KIdManager::getNumbers.startIDnum <= 0"); 128 qDebug("Error in KIdManager::getNumbers.startIDnum <= 0");
129 return false; 129 return false;
130 } 130 }
131 } else { 131 } else {
132 qDebug("getnumbers: profile not found *%s* ",prof.latin1() ); 132 //qDebug("getnumbers: profile not found *%s* ",prof.latin1() );
133 return false; 133 return false;
134 } 134 }
135 return true; 135 return true;
136} 136}