-rw-r--r-- | libkcal/libkcal.pro | 2 | ||||
-rw-r--r-- | libkcal/libkcalE.pro | 2 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 117 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 1 |
4 files changed, 5 insertions, 117 deletions
diff --git a/libkcal/libkcal.pro b/libkcal/libkcal.pro index 7a0bd22..171c726 100644 --- a/libkcal/libkcal.pro +++ b/libkcal/libkcal.pro | |||
@@ -1,106 +1,106 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkcal | 3 | TARGET = microkcal |
4 | 4 | ||
5 | include( ../variables.pri ) | 5 | include( ../variables.pri ) |
6 | 6 | ||
7 | INCLUDEPATH += ../microkde versit ../microkde/kdecore | 7 | INCLUDEPATH += ../libkdepim ../microkde versit ../microkde/kdecore |
8 | #../qtcompat | 8 | #../qtcompat |
9 | INCLUDEPATH += ../libical/src/libical | 9 | INCLUDEPATH += ../libical/src/libical |
10 | INCLUDEPATH += ../libical/src/libicalss | 10 | INCLUDEPATH += ../libical/src/libicalss |
11 | DESTDIR = ../bin | 11 | DESTDIR = ../bin |
12 | DEFINES += DESKTOP_VERSION | 12 | DEFINES += DESKTOP_VERSION |
13 | unix: { | 13 | unix: { |
14 | LIBS += ../libical/lib/libical.a | 14 | LIBS += ../libical/lib/libical.a |
15 | LIBS += ../libical/lib/libicalss.a | 15 | LIBS += ../libical/lib/libicalss.a |
16 | OBJECTS_DIR = obj/unix | 16 | OBJECTS_DIR = obj/unix |
17 | MOC_DIR = moc/unix | 17 | MOC_DIR = moc/unix |
18 | } | 18 | } |
19 | win32: { | 19 | win32: { |
20 | DEFINES += _WIN32_ | 20 | DEFINES += _WIN32_ |
21 | 21 | ||
22 | LIBS += ../libical/lib/ical.lib | 22 | LIBS += ../libical/lib/ical.lib |
23 | LIBS += ../libical/lib/icalss.lib | 23 | LIBS += ../libical/lib/icalss.lib |
24 | OBJECTS_DIR = obj/win | 24 | OBJECTS_DIR = obj/win |
25 | MOC_DIR = moc/win | 25 | MOC_DIR = moc/win |
26 | 26 | ||
27 | } | 27 | } |
28 | 28 | ||
29 | INTERFACES = \ | 29 | INTERFACES = \ |
30 | 30 | ||
31 | HEADERS = \ | 31 | HEADERS = \ |
32 | alarm.h \ | 32 | alarm.h \ |
33 | attachment.h \ | 33 | attachment.h \ |
34 | attendee.h \ | 34 | attendee.h \ |
35 | calendar.h \ | 35 | calendar.h \ |
36 | calendarlocal.h \ | 36 | calendarlocal.h \ |
37 | calfilter.h \ | 37 | calfilter.h \ |
38 | calformat.h \ | 38 | calformat.h \ |
39 | calstorage.h \ | 39 | calstorage.h \ |
40 | compat.h \ | 40 | compat.h \ |
41 | customproperties.h \ | 41 | customproperties.h \ |
42 | dummyscheduler.h \ | 42 | dummyscheduler.h \ |
43 | kincidenceformatter.h \ | 43 | kincidenceformatter.h \ |
44 | duration.h \ | 44 | duration.h \ |
45 | event.h \ | 45 | event.h \ |
46 | exceptions.h \ | 46 | exceptions.h \ |
47 | filestorage.h \ | 47 | filestorage.h \ |
48 | freebusy.h \ | 48 | freebusy.h \ |
49 | icaldrag.h \ | 49 | icaldrag.h \ |
50 | icalformat.h \ | 50 | icalformat.h \ |
51 | icalformatimpl.h \ | 51 | icalformatimpl.h \ |
52 | imipscheduler.h \ | 52 | imipscheduler.h \ |
53 | incidence.h \ | 53 | incidence.h \ |
54 | incidencebase.h \ | 54 | incidencebase.h \ |
55 | journal.h \ | 55 | journal.h \ |
56 | period.h \ | 56 | period.h \ |
57 | person.h \ | 57 | person.h \ |
58 | qtopiaformat.h \ | 58 | qtopiaformat.h \ |
59 | recurrence.h \ | 59 | recurrence.h \ |
60 | scheduler.h \ | 60 | scheduler.h \ |
61 | todo.h \ | 61 | todo.h \ |
62 | vcaldrag.h \ | 62 | vcaldrag.h \ |
63 | vcalformat.h \ | 63 | vcalformat.h \ |
64 | versit/port.h \ | 64 | versit/port.h \ |
65 | versit/vcc.h \ | 65 | versit/vcc.h \ |
66 | versit/vobject.h \ | 66 | versit/vobject.h \ |
67 | phoneformat.h \ | 67 | phoneformat.h \ |
68 | 68 | ||
69 | 69 | ||
70 | 70 | ||
71 | SOURCES = \ | 71 | SOURCES = \ |
72 | alarm.cpp \ | 72 | alarm.cpp \ |
73 | attachment.cpp \ | 73 | attachment.cpp \ |
74 | attendee.cpp \ | 74 | attendee.cpp \ |
75 | calendar.cpp \ | 75 | calendar.cpp \ |
76 | calendarlocal.cpp \ | 76 | calendarlocal.cpp \ |
77 | calfilter.cpp \ | 77 | calfilter.cpp \ |
78 | calformat.cpp \ | 78 | calformat.cpp \ |
79 | compat.cpp \ | 79 | compat.cpp \ |
80 | customproperties.cpp \ | 80 | customproperties.cpp \ |
81 | dummyscheduler.cpp \ | 81 | dummyscheduler.cpp \ |
82 | kincidenceformatter.cpp \ | 82 | kincidenceformatter.cpp \ |
83 | duration.cpp \ | 83 | duration.cpp \ |
84 | event.cpp \ | 84 | event.cpp \ |
85 | exceptions.cpp \ | 85 | exceptions.cpp \ |
86 | filestorage.cpp \ | 86 | filestorage.cpp \ |
87 | freebusy.cpp \ | 87 | freebusy.cpp \ |
88 | icaldrag.cpp \ | 88 | icaldrag.cpp \ |
89 | icalformat.cpp \ | 89 | icalformat.cpp \ |
90 | icalformatimpl.cpp \ | 90 | icalformatimpl.cpp \ |
91 | imipscheduler.cpp \ | 91 | imipscheduler.cpp \ |
92 | incidence.cpp \ | 92 | incidence.cpp \ |
93 | incidencebase.cpp \ | 93 | incidencebase.cpp \ |
94 | journal.cpp \ | 94 | journal.cpp \ |
95 | period.cpp \ | 95 | period.cpp \ |
96 | person.cpp \ | 96 | person.cpp \ |
97 | qtopiaformat.cpp \ | 97 | qtopiaformat.cpp \ |
98 | recurrence.cpp \ | 98 | recurrence.cpp \ |
99 | scheduler.cpp \ | 99 | scheduler.cpp \ |
100 | todo.cpp \ | 100 | todo.cpp \ |
101 | vcaldrag.cpp \ | 101 | vcaldrag.cpp \ |
102 | vcalformat.cpp \ | 102 | vcalformat.cpp \ |
103 | versit/vcc.c \ | 103 | versit/vcc.c \ |
104 | versit/vobject.c \ | 104 | versit/vobject.c \ |
105 | phoneformat.cpp \ | 105 | phoneformat.cpp \ |
106 | 106 | ||
diff --git a/libkcal/libkcalE.pro b/libkcal/libkcalE.pro index e379b95..e42dc9c 100644 --- a/libkcal/libkcalE.pro +++ b/libkcal/libkcalE.pro | |||
@@ -1,91 +1,91 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = komicrokcal | 3 | TARGET = komicrokcal |
4 | 4 | ||
5 | INCLUDEPATH += ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include | 5 | INCLUDEPATH += ../libkdepim ../microkde ../qtcompat versit ../microkde/kdecore $(QPEDIR)/include |
6 | INCLUDEPATH += ../libical/src/libical | 6 | INCLUDEPATH += ../libical/src/libical |
7 | INCLUDEPATH += ../libical/src/libicalss | 7 | INCLUDEPATH += ../libical/src/libicalss |
8 | OBJECTS_DIR = obj/$(PLATFORM) | 8 | OBJECTS_DIR = obj/$(PLATFORM) |
9 | MOC_DIR = moc/$(PLATFORM) | 9 | MOC_DIR = moc/$(PLATFORM) |
10 | DESTDIR = $(QPEDIR)/lib | 10 | DESTDIR = $(QPEDIR)/lib |
11 | LIBS += ../libical/lib/$(PLATFORM)/libical.a | 11 | LIBS += ../libical/lib/$(PLATFORM)/libical.a |
12 | LIBS += ../libical/lib/$(PLATFORM)/libicalss.a | 12 | LIBS += ../libical/lib/$(PLATFORM)/libicalss.a |
13 | 13 | ||
14 | INTERFACES = \ | 14 | INTERFACES = \ |
15 | 15 | ||
16 | HEADERS = \ | 16 | HEADERS = \ |
17 | alarm.h \ | 17 | alarm.h \ |
18 | attachment.h \ | 18 | attachment.h \ |
19 | attendee.h \ | 19 | attendee.h \ |
20 | calendar.h \ | 20 | calendar.h \ |
21 | calendarlocal.h \ | 21 | calendarlocal.h \ |
22 | calfilter.h \ | 22 | calfilter.h \ |
23 | calformat.h \ | 23 | calformat.h \ |
24 | calstorage.h \ | 24 | calstorage.h \ |
25 | compat.h \ | 25 | compat.h \ |
26 | customproperties.h \ | 26 | customproperties.h \ |
27 | dummyscheduler.h \ | 27 | dummyscheduler.h \ |
28 | duration.h \ | 28 | duration.h \ |
29 | event.h \ | 29 | event.h \ |
30 | exceptions.h \ | 30 | exceptions.h \ |
31 | filestorage.h \ | 31 | filestorage.h \ |
32 | freebusy.h \ | 32 | freebusy.h \ |
33 | icaldrag.h \ | 33 | icaldrag.h \ |
34 | icalformat.h \ | 34 | icalformat.h \ |
35 | icalformatimpl.h \ | 35 | icalformatimpl.h \ |
36 | imipscheduler.h \ | 36 | imipscheduler.h \ |
37 | incidence.h \ | 37 | incidence.h \ |
38 | incidencebase.h \ | 38 | incidencebase.h \ |
39 | kincidenceformatter.h \ | 39 | kincidenceformatter.h \ |
40 | journal.h \ | 40 | journal.h \ |
41 | period.h \ | 41 | period.h \ |
42 | person.h \ | 42 | person.h \ |
43 | qtopiaformat.h \ | 43 | qtopiaformat.h \ |
44 | sharpformat.h \ | 44 | sharpformat.h \ |
45 | phoneformat.h \ | 45 | phoneformat.h \ |
46 | recurrence.h \ | 46 | recurrence.h \ |
47 | scheduler.h \ | 47 | scheduler.h \ |
48 | todo.h \ | 48 | todo.h \ |
49 | vcaldrag.h \ | 49 | vcaldrag.h \ |
50 | vcalformat.h \ | 50 | vcalformat.h \ |
51 | versit/port.h \ | 51 | versit/port.h \ |
52 | versit/vcc.h \ | 52 | versit/vcc.h \ |
53 | versit/vobject.h \ | 53 | versit/vobject.h \ |
54 | 54 | ||
55 | SOURCES = \ | 55 | SOURCES = \ |
56 | alarm.cpp \ | 56 | alarm.cpp \ |
57 | attachment.cpp \ | 57 | attachment.cpp \ |
58 | attendee.cpp \ | 58 | attendee.cpp \ |
59 | calendar.cpp \ | 59 | calendar.cpp \ |
60 | calendarlocal.cpp \ | 60 | calendarlocal.cpp \ |
61 | calfilter.cpp \ | 61 | calfilter.cpp \ |
62 | calformat.cpp \ | 62 | calformat.cpp \ |
63 | compat.cpp \ | 63 | compat.cpp \ |
64 | customproperties.cpp \ | 64 | customproperties.cpp \ |
65 | dummyscheduler.cpp \ | 65 | dummyscheduler.cpp \ |
66 | duration.cpp \ | 66 | duration.cpp \ |
67 | event.cpp \ | 67 | event.cpp \ |
68 | exceptions.cpp \ | 68 | exceptions.cpp \ |
69 | filestorage.cpp \ | 69 | filestorage.cpp \ |
70 | freebusy.cpp \ | 70 | freebusy.cpp \ |
71 | icaldrag.cpp \ | 71 | icaldrag.cpp \ |
72 | icalformat.cpp \ | 72 | icalformat.cpp \ |
73 | icalformatimpl.cpp \ | 73 | icalformatimpl.cpp \ |
74 | imipscheduler.cpp \ | 74 | imipscheduler.cpp \ |
75 | incidence.cpp \ | 75 | incidence.cpp \ |
76 | incidencebase.cpp \ | 76 | incidencebase.cpp \ |
77 | kincidenceformatter.cpp \ | 77 | kincidenceformatter.cpp \ |
78 | journal.cpp \ | 78 | journal.cpp \ |
79 | period.cpp \ | 79 | period.cpp \ |
80 | person.cpp \ | 80 | person.cpp \ |
81 | qtopiaformat.cpp \ | 81 | qtopiaformat.cpp \ |
82 | sharpformat.cpp \ | 82 | sharpformat.cpp \ |
83 | phoneformat.cpp \ | 83 | phoneformat.cpp \ |
84 | recurrence.cpp \ | 84 | recurrence.cpp \ |
85 | scheduler.cpp \ | 85 | scheduler.cpp \ |
86 | todo.cpp \ | 86 | todo.cpp \ |
87 | vcaldrag.cpp \ | 87 | vcaldrag.cpp \ |
88 | vcalformat.cpp \ | 88 | vcalformat.cpp \ |
89 | versit/vcc.c \ | 89 | versit/vcc.c \ |
90 | versit/vobject.c \ | 90 | versit/vobject.c \ |
91 | 91 | ||
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index b2a62b1..c39413e 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,748 +1,637 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@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 <qdir.h> | 32 | #include <qdir.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 | #include <kmessagebox.h> | 38 | #include <kmessagebox.h> |
39 | #include <phoneaccess.h> | ||
39 | 40 | ||
40 | #include "calendar.h" | 41 | #include "calendar.h" |
41 | #include "alarm.h" | 42 | #include "alarm.h" |
42 | #include "recurrence.h" | 43 | #include "recurrence.h" |
43 | #include "calendarlocal.h" | 44 | #include "calendarlocal.h" |
44 | 45 | ||
45 | #include "phoneformat.h" | 46 | #include "phoneformat.h" |
46 | #include "syncdefines.h" | 47 | #include "syncdefines.h" |
47 | 48 | ||
48 | using namespace KCal; | 49 | using namespace KCal; |
49 | class PhoneParser : public QObject | 50 | class PhoneParser : public QObject |
50 | { | 51 | { |
51 | public: | 52 | public: |
52 | PhoneParser( ) { | 53 | PhoneParser( ) { |
53 | ; | 54 | ; |
54 | } | 55 | } |
55 | 56 | ||
56 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 57 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
57 | { | 58 | { |
58 | QString datestr; | 59 | QString datestr; |
59 | QString timestr; | 60 | QString timestr; |
60 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 61 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
61 | QDateTime dt; | 62 | QDateTime dt; |
62 | if (useTZ) | 63 | if (useTZ) |
63 | dt = dti.addSecs ( -(offset*60)); | 64 | dt = dti.addSecs ( -(offset*60)); |
64 | else | 65 | else |
65 | dt = dti; | 66 | dt = dti; |
66 | if(dt.date().isValid()){ | 67 | if(dt.date().isValid()){ |
67 | const QDate& date = dt.date(); | 68 | const QDate& date = dt.date(); |
68 | datestr.sprintf("%04d%02d%02d", | 69 | datestr.sprintf("%04d%02d%02d", |
69 | date.year(), date.month(), date.day()); | 70 | date.year(), date.month(), date.day()); |
70 | } | 71 | } |
71 | if(dt.time().isValid()){ | 72 | if(dt.time().isValid()){ |
72 | const QTime& time = dt.time(); | 73 | const QTime& time = dt.time(); |
73 | timestr.sprintf("T%02d%02d%02d", | 74 | timestr.sprintf("T%02d%02d%02d", |
74 | time.hour(), time.minute(), time.second()); | 75 | time.hour(), time.minute(), time.second()); |
75 | } | 76 | } |
76 | return datestr + timestr; | 77 | return datestr + timestr; |
77 | } | 78 | } |
78 | 79 | ||
79 | 80 | ||
80 | }; | 81 | }; |
81 | 82 | ||
82 | 83 | ||
83 | 84 | ||
84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 85 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
85 | { | 86 | { |
86 | mProfileName = profileName; | 87 | mProfileName = profileName; |
87 | writeConfig( device, connection, model ); | 88 | PhoneAccess::writeConfig( device, connection, model ); |
88 | } | 89 | } |
89 | 90 | ||
90 | PhoneFormat::~PhoneFormat() | 91 | PhoneFormat::~PhoneFormat() |
91 | { | 92 | { |
92 | } | 93 | } |
93 | void PhoneFormat::writeConfig( QString device, QString connection, QString model ) | ||
94 | { | ||
95 | #ifdef _WIN32_ | ||
96 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; | ||
97 | #else | ||
98 | QString fileName = QDir::homeDirPath() +"/.gammurc"; | ||
99 | #endif | ||
100 | //qDebug("save %d ", load ); | ||
101 | QString content; | ||
102 | bool write = false; | ||
103 | bool addPort = true, addConnection = true, addModel = true; | ||
104 | QFile file( fileName ); | ||
105 | if ( QFile::exists( fileName) ) { | ||
106 | if (!file.open( IO_ReadOnly ) ) { | ||
107 | qDebug("Error: cannot open %s ", fileName.latin1() ); | ||
108 | return; | ||
109 | } | ||
110 | QString line; | ||
111 | while ( file.readLine( line, 1024 ) > 0 ) { | ||
112 | //qDebug("*%s* ", line.latin1() ); | ||
113 | if ( line.left(7 ) == "[gammu]" ) { | ||
114 | ; | ||
115 | } else | ||
116 | if ( line.left(4 ) == "port" ) { | ||
117 | if ( line == "port = " + device+"\n" ) { | ||
118 | content += line ; | ||
119 | addPort = false; | ||
120 | //qDebug("port found" ); | ||
121 | } | ||
122 | |||
123 | } else if ( line.left(5 ) == "model" ) { | ||
124 | if ( line == "model = " + model +"\n") { | ||
125 | content += line ; | ||
126 | addModel = false; | ||
127 | //qDebug("model found" ); | ||
128 | } | ||
129 | |||
130 | } else if ( line.left( 10 ) == "connection" ) { | ||
131 | if ( line == "connection = " + connection +"\n") { | ||
132 | addConnection = false; | ||
133 | content += line ; | ||
134 | //qDebug("con found" ); | ||
135 | } | ||
136 | |||
137 | } else { | ||
138 | content += line ; | ||
139 | } | ||
140 | } | ||
141 | file.close(); | ||
142 | } else { | ||
143 | if ( ! connection.isEmpty() ) { | ||
144 | addConnection = true; | ||
145 | } | ||
146 | if ( ! device.isEmpty() ) { | ||
147 | addPort = true; | ||
148 | 94 | ||
149 | } | ||
150 | if ( ! model.isEmpty() ) { | ||
151 | addModel = true; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | if ( addConnection ) { | ||
156 | if ( ! write ) | ||
157 | content += "[gammu]\n"; | ||
158 | write = true; | ||
159 | content += "connection = "; | ||
160 | content += connection; | ||
161 | content += "\n"; | ||
162 | } | ||
163 | if ( addPort ) { | ||
164 | if ( ! write ) | ||
165 | content += "[gammu]\n"; | ||
166 | write = true; | ||
167 | content += "port = "; | ||
168 | content += device; | ||
169 | content += "\n"; | ||
170 | |||
171 | } | ||
172 | if ( addModel ) { | ||
173 | if ( ! write ) | ||
174 | content += "[gammu]\n"; | ||
175 | write = true; | ||
176 | content += "model = "; | ||
177 | content += model; | ||
178 | content += "\n"; | ||
179 | } | ||
180 | if ( write ) { | ||
181 | if (!file.open( IO_WriteOnly ) ) { | ||
182 | qDebug("Error: cannot write file %s ", fileName.latin1() ); | ||
183 | return; | ||
184 | } | ||
185 | qDebug("Writing file %s ", fileName.latin1() ); | ||
186 | QTextStream ts( &file ); | ||
187 | ts << content ; | ||
188 | file.close(); | ||
189 | } | ||
190 | |||
191 | } | ||
192 | #if 0 | 95 | #if 0 |
193 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 96 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
194 | { | 97 | { |
195 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 98 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
196 | s->ConfigNum = 1; | 99 | s->ConfigNum = 1; |
197 | GSM_Config *cfg = &s->Config[0]; | 100 | GSM_Config *cfg = &s->Config[0]; |
198 | if ( ! mConnection.isEmpty() ) { | 101 | if ( ! mConnection.isEmpty() ) { |
199 | cfg->Connection = strdup(mConnection.latin1()); | 102 | cfg->Connection = strdup(mConnection.latin1()); |
200 | cfg->DefaultConnection = false; | 103 | cfg->DefaultConnection = false; |
201 | qDebug("Connection set %s ", cfg->Connection ); | 104 | qDebug("Connection set %s ", cfg->Connection ); |
202 | 105 | ||
203 | } | 106 | } |
204 | if ( ! mDevice.isEmpty() ) { | 107 | if ( ! mDevice.isEmpty() ) { |
205 | cfg->Device = strdup(mDevice.latin1()); | 108 | cfg->Device = strdup(mDevice.latin1()); |
206 | cfg->DefaultDevice = false; | 109 | cfg->DefaultDevice = false; |
207 | qDebug("Device set %s ", cfg->Device); | 110 | qDebug("Device set %s ", cfg->Device); |
208 | 111 | ||
209 | } | 112 | } |
210 | if ( ! mModel.isEmpty() ) { | 113 | if ( ! mModel.isEmpty() ) { |
211 | strcpy(cfg->Model,mModel.latin1() ); | 114 | strcpy(cfg->Model,mModel.latin1() ); |
212 | cfg->DefaultModel = false; | 115 | cfg->DefaultModel = false; |
213 | qDebug("Model set %s ",cfg->Model ); | 116 | qDebug("Model set %s ",cfg->Model ); |
214 | } | 117 | } |
215 | int error=GSM_InitConnection(s,3); | 118 | int error=GSM_InitConnection(s,3); |
216 | return error; | 119 | return error; |
217 | } | 120 | } |
218 | #endif | 121 | #endif |
219 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
220 | { | 123 | { |
221 | QStringList attList; | 124 | QStringList attList; |
222 | if ( todo->hasDueDate() ) | 125 | if ( todo->hasDueDate() ) |
223 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 126 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
224 | attList << todo->summary(); | 127 | attList << todo->summary(); |
225 | QString completedString = "no"; | 128 | QString completedString = "no"; |
226 | if ( todo->isCompleted() ) | 129 | if ( todo->isCompleted() ) |
227 | completedString = "yes"; | 130 | completedString = "yes"; |
228 | attList << completedString; | 131 | attList << completedString; |
229 | int prio = todo->priority(); | 132 | int prio = todo->priority(); |
230 | if( prio == 2 ) prio = 1; | 133 | if( prio == 2 ) prio = 1; |
231 | if (prio == 4 ) prio = 5 ; | 134 | if (prio == 4 ) prio = 5 ; |
232 | attList << QString::number( prio ); | 135 | attList << QString::number( prio ); |
233 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
234 | Alarm *alarm; | 137 | Alarm *alarm; |
235 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
236 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
237 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
238 | alarmString = QString::number(alarm->offset() ); | 141 | alarmString = QString::number(alarm->offset() ); |
239 | } | 142 | } |
240 | } | 143 | } |
241 | attList << alarmString; | 144 | attList << alarmString; |
242 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
243 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
244 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
245 | 148 | ||
246 | } | 149 | } |
247 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
248 | { | 151 | { |
249 | QStringList attList; | 152 | QStringList attList; |
250 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
251 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
252 | attList << event->summary(); | 155 | attList << event->summary(); |
253 | attList << event->location(); | 156 | attList << event->location(); |
254 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
255 | Alarm *alarm; | 158 | Alarm *alarm; |
256 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
257 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
258 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
259 | alarmString = QString::number( alarm->offset() ); | 162 | alarmString = QString::number( alarm->offset() ); |
260 | } | 163 | } |
261 | } | 164 | } |
262 | attList << alarmString; | 165 | attList << alarmString; |
263 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
264 | QStringList list; | 167 | QStringList list; |
265 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
266 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
267 | { | 170 | { |
268 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
269 | list.append( "0" ); | 172 | list.append( "0" ); |
270 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
271 | list.append( "0" ); | 174 | list.append( "0" ); |
272 | list.append( "0" ); | 175 | list.append( "0" ); |
273 | writeEndDate = true; | 176 | writeEndDate = true; |
274 | break; | 177 | break; |
275 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
276 | list.append( "1" ); | 179 | list.append( "1" ); |
277 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
278 | list.append( "0" ); | 181 | list.append( "0" ); |
279 | { | 182 | { |
280 | int days = 0; | 183 | int days = 0; |
281 | QBitArray weekDays = rec->days(); | 184 | QBitArray weekDays = rec->days(); |
282 | int i; | 185 | int i; |
283 | for( i = 1; i <= 7; ++i ) { | 186 | for( i = 1; i <= 7; ++i ) { |
284 | if ( weekDays[i-1] ) { | 187 | if ( weekDays[i-1] ) { |
285 | days += 1 << (i-1); | 188 | days += 1 << (i-1); |
286 | } | 189 | } |
287 | } | 190 | } |
288 | list.append( QString::number( days ) ); | 191 | list.append( QString::number( days ) ); |
289 | } | 192 | } |
290 | //pending weekdays | 193 | //pending weekdays |
291 | writeEndDate = true; | 194 | writeEndDate = true; |
292 | 195 | ||
293 | break; | 196 | break; |
294 | case Recurrence::rMonthlyPos:// 2 | 197 | case Recurrence::rMonthlyPos:// 2 |
295 | list.append( "2" ); | 198 | list.append( "2" ); |
296 | list.append( QString::number( rec->frequency()) );//12 | 199 | list.append( QString::number( rec->frequency()) );//12 |
297 | 200 | ||
298 | writeEndDate = true; | 201 | writeEndDate = true; |
299 | { | 202 | { |
300 | int count = 1; | 203 | int count = 1; |
301 | QPtrList<Recurrence::rMonthPos> rmp; | 204 | QPtrList<Recurrence::rMonthPos> rmp; |
302 | rmp = rec->monthPositions(); | 205 | rmp = rec->monthPositions(); |
303 | if ( rmp.first()->negative ) | 206 | if ( rmp.first()->negative ) |
304 | count = 5 - rmp.first()->rPos - 1; | 207 | count = 5 - rmp.first()->rPos - 1; |
305 | else | 208 | else |
306 | count = rmp.first()->rPos - 1; | 209 | count = rmp.first()->rPos - 1; |
307 | list.append( QString::number( count ) ); | 210 | list.append( QString::number( count ) ); |
308 | 211 | ||
309 | } | 212 | } |
310 | 213 | ||
311 | list.append( "0" ); | 214 | list.append( "0" ); |
312 | break; | 215 | break; |
313 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
314 | list.append( "3" ); | 217 | list.append( "3" ); |
315 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
316 | list.append( "0" ); | 219 | list.append( "0" ); |
317 | list.append( "0" ); | 220 | list.append( "0" ); |
318 | writeEndDate = true; | 221 | writeEndDate = true; |
319 | break; | 222 | break; |
320 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
321 | list.append( "4" ); | 224 | list.append( "4" ); |
322 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
323 | list.append( "0" ); | 226 | list.append( "0" ); |
324 | list.append( "0" ); | 227 | list.append( "0" ); |
325 | writeEndDate = true; | 228 | writeEndDate = true; |
326 | break; | 229 | break; |
327 | 230 | ||
328 | default: | 231 | default: |
329 | list.append( "255" ); | 232 | list.append( "255" ); |
330 | list.append( QString() ); | 233 | list.append( QString() ); |
331 | list.append( "0" ); | 234 | list.append( "0" ); |
332 | list.append( QString() ); | 235 | list.append( QString() ); |
333 | list.append( "0" ); | 236 | list.append( "0" ); |
334 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
335 | break; | 238 | break; |
336 | } | 239 | } |
337 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
338 | 241 | ||
339 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
340 | list.append( "1" ); | 243 | list.append( "1" ); |
341 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
342 | } else { | 245 | } else { |
343 | list.append( "0" ); | 246 | list.append( "0" ); |
344 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
345 | } | 248 | } |
346 | 249 | ||
347 | } | 250 | } |
348 | attList << list.join(""); | 251 | attList << list.join(""); |
349 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
350 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
351 | 254 | ||
352 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
353 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
354 | } | 257 | } |
355 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
356 | { | 259 | { |
357 | int max = attList.count(); | 260 | int max = attList.count(); |
358 | ulong cSum = 0; | 261 | ulong cSum = 0; |
359 | int j,k,i; | 262 | int j,k,i; |
360 | int add; | 263 | int add; |
361 | for ( i = 0; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
362 | QString s = attList[i]; | 265 | QString s = attList[i]; |
363 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
364 | j = s.length(); | 267 | j = s.length(); |
365 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
366 | int mul = k +1; | 269 | int mul = k +1; |
367 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
368 | if ( k < 16 ) | 271 | if ( k < 16 ) |
369 | mul = mul * mul; | 272 | mul = mul * mul; |
370 | int ii = i+1; | 273 | int ii = i+1; |
371 | add = add * mul *ii*ii*ii; | 274 | add = add * mul *ii*ii*ii; |
372 | cSum += add; | 275 | cSum += add; |
373 | } | 276 | } |
374 | } | 277 | } |
375 | 278 | ||
376 | } | 279 | } |
377 | //QString dump = attList.join(","); | 280 | //QString dump = attList.join(","); |
378 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 281 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
379 | 282 | ||
380 | return cSum; | 283 | return cSum; |
381 | 284 | ||
382 | } | 285 | } |
383 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
384 | #include <stdlib.h> | 287 | #include <stdlib.h> |
385 | #define DEBUGMODE false | 288 | #define DEBUGMODE false |
386 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
387 | { | 290 | { |
388 | 291 | ||
389 | QString fileName; | 292 | QString fileName; |
390 | #ifdef _WIN32_ | 293 | #ifdef _WIN32_ |
391 | fileName = locateLocal("tmp", "tempfile.vcs"); | 294 | fileName = locateLocal("tmp", "tempfile.vcs"); |
392 | #else | 295 | #else |
393 | fileName = "/tmp/kdepimtemp.vcs"; | 296 | fileName = "/tmp/kdepimtemp.vcs"; |
394 | #endif | 297 | #endif |
395 | #ifdef DESKTOP_VERSION | 298 | #ifdef DESKTOP_VERSION |
396 | QString command ="./kammu --backup " + fileName + " -yes" ; | 299 | QString command ="./kammu --backup " + fileName + " -yes" ; |
397 | #else | 300 | #else |
398 | QString command ="kammu --backup " + fileName + " -yes" ; | 301 | QString command ="kammu --backup " + fileName + " -yes" ; |
399 | #endif | 302 | #endif |
400 | int ret = system ( command.latin1() ); | 303 | int ret = system ( command.latin1() ); |
401 | if ( ret != 0 ) { | 304 | if ( ret != 0 ) { |
402 | qDebug("Error::command returned %d", ret); | 305 | qDebug("Error::command returned %d", ret); |
403 | return false; | 306 | return false; |
404 | } | 307 | } |
405 | VCalFormat vfload; | 308 | VCalFormat vfload; |
406 | vfload.setLocalTime ( true ); | 309 | vfload.setLocalTime ( true ); |
407 | qDebug("loading file ..."); | 310 | qDebug("loading file ..."); |
408 | 311 | ||
409 | if ( ! vfload.load( calendar, fileName ) ) | 312 | if ( ! vfload.load( calendar, fileName ) ) |
410 | return false; | 313 | return false; |
411 | QPtrList<Event> er = calendar->rawEvents(); | 314 | QPtrList<Event> er = calendar->rawEvents(); |
412 | Event* ev = er.first(); | 315 | Event* ev = er.first(); |
413 | qDebug("reading events... "); | 316 | qDebug("reading events... "); |
414 | while ( ev ) { | 317 | while ( ev ) { |
415 | QStringList cat = ev->categories(); | 318 | QStringList cat = ev->categories(); |
416 | if ( cat.contains( "MeetingDEF" )) { | 319 | if ( cat.contains( "MeetingDEF" )) { |
417 | ev->setCategories( QStringList() ); | 320 | ev->setCategories( QStringList() ); |
418 | } | 321 | } |
419 | int id = ev->pilotId(); | 322 | int id = ev->pilotId(); |
420 | Event *event; | 323 | Event *event; |
421 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 324 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
422 | if ( event ) { | 325 | if ( event ) { |
423 | event = (Event*)event->clone(); | 326 | event = (Event*)event->clone(); |
424 | copyEvent( event, ev ); | 327 | copyEvent( event, ev ); |
425 | calendar->deleteEvent( ev ); | 328 | calendar->deleteEvent( ev ); |
426 | calendar->addEvent( event); | 329 | calendar->addEvent( event); |
427 | } | 330 | } |
428 | else | 331 | else |
429 | event = ev; | 332 | event = ev; |
430 | uint cSum; | 333 | uint cSum; |
431 | cSum = PhoneFormat::getCsumEvent( event ); | 334 | cSum = PhoneFormat::getCsumEvent( event ); |
432 | event->setCsum( mProfileName, QString::number( cSum )); | 335 | event->setCsum( mProfileName, QString::number( cSum )); |
433 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 336 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
434 | event->setID( mProfileName,QString::number( id ) ); | 337 | event->setID( mProfileName,QString::number( id ) ); |
435 | ev = er.next(); | 338 | ev = er.next(); |
436 | } | 339 | } |
437 | { | 340 | { |
438 | qDebug("reading todos... "); | 341 | qDebug("reading todos... "); |
439 | QPtrList<Todo> tr = calendar->rawTodos(); | 342 | QPtrList<Todo> tr = calendar->rawTodos(); |
440 | Todo* ev = tr.first(); | 343 | Todo* ev = tr.first(); |
441 | while ( ev ) { | 344 | while ( ev ) { |
442 | 345 | ||
443 | QStringList cat = ev->categories(); | 346 | QStringList cat = ev->categories(); |
444 | if ( cat.contains( "MeetingDEF" )) { | 347 | if ( cat.contains( "MeetingDEF" )) { |
445 | ev->setCategories( QStringList() ); | 348 | ev->setCategories( QStringList() ); |
446 | } | 349 | } |
447 | int id = ev->pilotId(); | 350 | int id = ev->pilotId(); |
448 | Todo *event; | 351 | Todo *event; |
449 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 352 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
450 | if ( event ) { | 353 | if ( event ) { |
451 | //qDebug("copy todo %s ", event->summary().latin1()); | 354 | //qDebug("copy todo %s ", event->summary().latin1()); |
452 | 355 | ||
453 | event = (Todo*)event->clone(); | 356 | event = (Todo*)event->clone(); |
454 | copyTodo( event, ev ); | 357 | copyTodo( event, ev ); |
455 | calendar->deleteTodo( ev ); | 358 | calendar->deleteTodo( ev ); |
456 | calendar->addTodo( event); | 359 | calendar->addTodo( event); |
457 | } | 360 | } |
458 | else | 361 | else |
459 | event = ev; | 362 | event = ev; |
460 | uint cSum; | 363 | uint cSum; |
461 | cSum = PhoneFormat::getCsumTodo( event ); | 364 | cSum = PhoneFormat::getCsumTodo( event ); |
462 | event->setCsum( mProfileName, QString::number( cSum )); | 365 | event->setCsum( mProfileName, QString::number( cSum )); |
463 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 366 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
464 | event->setID( mProfileName,QString::number( id ) ); | 367 | event->setID( mProfileName,QString::number( id ) ); |
465 | ev = tr.next(); | 368 | ev = tr.next(); |
466 | } | 369 | } |
467 | } | 370 | } |
468 | return true; | 371 | return true; |
469 | } | 372 | } |
470 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 373 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
471 | { | 374 | { |
472 | if ( from->dtStart().isValid() ) | 375 | if ( from->dtStart().isValid() ) |
473 | to->setDtStart( from->dtStart() ); | 376 | to->setDtStart( from->dtStart() ); |
474 | if ( from->dtEnd().isValid() ) | 377 | if ( from->dtEnd().isValid() ) |
475 | to->setDtEnd( from->dtEnd() ); | 378 | to->setDtEnd( from->dtEnd() ); |
476 | if ( !from->location().isEmpty() ) | 379 | if ( !from->location().isEmpty() ) |
477 | to->setLocation( from->location() ); | 380 | to->setLocation( from->location() ); |
478 | if ( !from->description().isEmpty() ) | 381 | if ( !from->description().isEmpty() ) |
479 | to->setDescription( from->description() ); | 382 | to->setDescription( from->description() ); |
480 | if ( !from->summary().isEmpty() ) | 383 | if ( !from->summary().isEmpty() ) |
481 | to->setSummary( from->summary() ); | 384 | to->setSummary( from->summary() ); |
482 | 385 | ||
483 | if ( from->alarms().count() ) { | 386 | if ( from->alarms().count() ) { |
484 | to->clearAlarms(); | 387 | to->clearAlarms(); |
485 | Alarm *a = from->alarms().first(); | 388 | Alarm *a = from->alarms().first(); |
486 | Alarm *b = to->newAlarm( ); | 389 | Alarm *b = to->newAlarm( ); |
487 | b->setEnabled( a->enabled() ); | 390 | b->setEnabled( a->enabled() ); |
488 | if ( a->hasStartOffset() ) { | 391 | if ( a->hasStartOffset() ) { |
489 | b->setStartOffset( a->startOffset() ); | 392 | b->setStartOffset( a->startOffset() ); |
490 | } | 393 | } |
491 | if ( a->hasTime() ) | 394 | if ( a->hasTime() ) |
492 | b->setTime( a->time() ); | 395 | b->setTime( a->time() ); |
493 | 396 | ||
494 | } | 397 | } |
495 | QStringList cat = to->categories(); | 398 | QStringList cat = to->categories(); |
496 | QStringList catFrom = from->categories(); | 399 | QStringList catFrom = from->categories(); |
497 | QString nCat; | 400 | QString nCat; |
498 | int iii; | 401 | int iii; |
499 | for ( iii = 0; iii < catFrom.count();++iii ) { | 402 | for ( iii = 0; iii < catFrom.count();++iii ) { |
500 | nCat = catFrom[iii]; | 403 | nCat = catFrom[iii]; |
501 | if ( !nCat.isEmpty() ) | 404 | if ( !nCat.isEmpty() ) |
502 | if ( !cat.contains( nCat )) { | 405 | if ( !cat.contains( nCat )) { |
503 | cat << nCat; | 406 | cat << nCat; |
504 | } | 407 | } |
505 | } | 408 | } |
506 | to->setCategories( cat ); | 409 | to->setCategories( cat ); |
507 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 410 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
508 | to->setRecurrence( r ) ; | 411 | to->setRecurrence( r ) ; |
509 | 412 | ||
510 | 413 | ||
511 | } | 414 | } |
512 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 415 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
513 | { | 416 | { |
514 | if ( from->dtStart().isValid() ) | 417 | if ( from->dtStart().isValid() ) |
515 | to->setDtStart( from->dtStart() ); | 418 | to->setDtStart( from->dtStart() ); |
516 | if ( from->dtDue().isValid() ) | 419 | if ( from->dtDue().isValid() ) |
517 | to->setDtDue( from->dtDue() ); | 420 | to->setDtDue( from->dtDue() ); |
518 | if ( !from->location().isEmpty() ) | 421 | if ( !from->location().isEmpty() ) |
519 | to->setLocation( from->location() ); | 422 | to->setLocation( from->location() ); |
520 | if ( !from->description().isEmpty() ) | 423 | if ( !from->description().isEmpty() ) |
521 | to->setDescription( from->description() ); | 424 | to->setDescription( from->description() ); |
522 | if ( !from->summary().isEmpty() ) | 425 | if ( !from->summary().isEmpty() ) |
523 | to->setSummary( from->summary() ); | 426 | to->setSummary( from->summary() ); |
524 | 427 | ||
525 | if ( from->alarms().count() ) { | 428 | if ( from->alarms().count() ) { |
526 | to->clearAlarms(); | 429 | to->clearAlarms(); |
527 | Alarm *a = from->alarms().first(); | 430 | Alarm *a = from->alarms().first(); |
528 | Alarm *b = to->newAlarm( ); | 431 | Alarm *b = to->newAlarm( ); |
529 | b->setEnabled( a->enabled() ); | 432 | b->setEnabled( a->enabled() ); |
530 | if ( a->hasStartOffset() ) | 433 | if ( a->hasStartOffset() ) |
531 | b->setStartOffset( a->startOffset() ); | 434 | b->setStartOffset( a->startOffset() ); |
532 | if ( a->hasTime() ) | 435 | if ( a->hasTime() ) |
533 | b->setTime( a->time() ); | 436 | b->setTime( a->time() ); |
534 | } | 437 | } |
535 | 438 | ||
536 | QStringList cat = to->categories(); | 439 | QStringList cat = to->categories(); |
537 | QStringList catFrom = from->categories(); | 440 | QStringList catFrom = from->categories(); |
538 | QString nCat; | 441 | QString nCat; |
539 | int iii; | 442 | int iii; |
540 | for ( iii = 0; iii < catFrom.count();++iii ) { | 443 | for ( iii = 0; iii < catFrom.count();++iii ) { |
541 | nCat = catFrom[iii]; | 444 | nCat = catFrom[iii]; |
542 | if ( !nCat.isEmpty() ) | 445 | if ( !nCat.isEmpty() ) |
543 | if ( !cat.contains( nCat )) { | 446 | if ( !cat.contains( nCat )) { |
544 | cat << nCat; | 447 | cat << nCat; |
545 | } | 448 | } |
546 | } | 449 | } |
547 | to->setCategories( cat ); | 450 | to->setCategories( cat ); |
548 | if ( from->isCompleted() ) { | 451 | if ( from->isCompleted() ) { |
549 | to->setCompleted( true ); | 452 | to->setCompleted( true ); |
550 | if( from->completed().isValid() ) | 453 | if( from->completed().isValid() ) |
551 | to->setCompleted( from->completed() ); | 454 | to->setCompleted( from->completed() ); |
552 | } else { | 455 | } else { |
553 | // set percentcomplete only, if to->isCompleted() | 456 | // set percentcomplete only, if to->isCompleted() |
554 | if ( to->isCompleted() ) | 457 | if ( to->isCompleted() ) |
555 | to->setPercentComplete(from->percentComplete()); | 458 | to->setPercentComplete(from->percentComplete()); |
556 | } | 459 | } |
557 | if( to->priority() == 2 && from->priority() == 1 ) | 460 | if( to->priority() == 2 && from->priority() == 1 ) |
558 | ; //skip | 461 | ; //skip |
559 | else if (to->priority() == 4 && from->priority() == 5 ) | 462 | else if (to->priority() == 4 && from->priority() == 5 ) |
560 | ; | 463 | ; |
561 | else | 464 | else |
562 | to->setPriority(from->priority()); | 465 | to->setPriority(from->priority()); |
563 | 466 | ||
564 | } | 467 | } |
565 | #include <qcstring.h> | 468 | #include <qcstring.h> |
566 | 469 | ||
567 | void PhoneFormat::afterSave( Incidence* inc) | 470 | void PhoneFormat::afterSave( Incidence* inc) |
568 | { | 471 | { |
569 | uint csum; | 472 | uint csum; |
570 | inc->removeID( mProfileName ); | 473 | inc->removeID( mProfileName ); |
571 | if ( inc->type() == "Event") | 474 | if ( inc->type() == "Event") |
572 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 475 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
573 | else | 476 | else |
574 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 477 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
575 | inc->setCsum( mProfileName, QString::number( csum )); | 478 | inc->setCsum( mProfileName, QString::number( csum )); |
576 | 479 | ||
577 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 480 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
578 | 481 | ||
579 | } | 482 | } |
580 | 483 | ||
581 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 484 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
582 | { | 485 | { |
583 | #ifdef _WIN32_ | 486 | #ifdef _WIN32_ |
584 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | 487 | QString fileName = locateLocal("tmp", "tempfile.vcs"); |
585 | #else | 488 | #else |
586 | QString fileName = "/tmp/kdepimtemp.vcs"; | 489 | QString fileName = "/tmp/kdepimtemp.vcs"; |
587 | #endif | 490 | #endif |
588 | 491 | ||
589 | VCalFormat vfsave; | 492 | VCalFormat vfsave; |
590 | vfsave.setLocalTime ( true ); | 493 | vfsave.setLocalTime ( true ); |
591 | if ( ! vfsave.save( calendar, fileName ) ) | 494 | if ( ! vfsave.save( calendar, fileName ) ) |
592 | return false; | 495 | return false; |
593 | // 4 call kammu | 496 | return PhoneAccess::writeToPhone( fileName ); |
594 | #ifdef DESKTOP_VERSION | ||
595 | QString command ="./kammu --restore " + fileName ; | ||
596 | #else | ||
597 | QString command ="kammu --restore " + fileName ; | ||
598 | #endif | ||
599 | int ret; | ||
600 | while ( (ret = system ( command.latin1())) != 0 ) { | ||
601 | qDebug("Error S::command returned %d. asking users", ret); | ||
602 | int retval = KMessageBox::warningContinueCancel(0, | ||
603 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); | ||
604 | if ( retval != KMessageBox::Continue ) | ||
605 | return false; | ||
606 | } | ||
607 | return true; | ||
608 | } | 497 | } |
609 | bool PhoneFormat::save( Calendar *calendar) | 498 | bool PhoneFormat::save( Calendar *calendar) |
610 | { | 499 | { |
611 | QLabel status ( i18n(" Opening device ..."), 0 ); | 500 | QLabel status ( i18n(" Opening device ..."), 0 ); |
612 | int w = status.sizeHint().width()+20 ; | 501 | int w = status.sizeHint().width()+20 ; |
613 | if ( w < 200 ) w = 230; | 502 | if ( w < 200 ) w = 230; |
614 | int h = status.sizeHint().height()+20 ; | 503 | int h = status.sizeHint().height()+20 ; |
615 | int dw = QApplication::desktop()->width(); | 504 | int dw = QApplication::desktop()->width(); |
616 | int dh = QApplication::desktop()->height(); | 505 | int dh = QApplication::desktop()->height(); |
617 | status.setCaption(i18n("Writing to phone...") ); | 506 | status.setCaption(i18n("Writing to phone...") ); |
618 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 507 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
619 | status.show(); | 508 | status.show(); |
620 | status.raise(); | 509 | status.raise(); |
621 | qApp->processEvents(); | 510 | qApp->processEvents(); |
622 | QString message; | 511 | QString message; |
623 | 512 | ||
624 | // 1 remove events which should be deleted | 513 | // 1 remove events which should be deleted |
625 | QPtrList<Event> er = calendar->rawEvents(); | 514 | QPtrList<Event> er = calendar->rawEvents(); |
626 | Event* ev = er.first(); | 515 | Event* ev = er.first(); |
627 | while ( ev ) { | 516 | while ( ev ) { |
628 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 517 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
629 | calendar->deleteEvent( ev ); | 518 | calendar->deleteEvent( ev ); |
630 | } else { | 519 | } else { |
631 | 520 | ||
632 | } | 521 | } |
633 | ev = er.next(); | 522 | ev = er.next(); |
634 | } | 523 | } |
635 | // 2 remove todos which should be deleted | 524 | // 2 remove todos which should be deleted |
636 | QPtrList<Todo> tl = calendar->rawTodos(); | 525 | QPtrList<Todo> tl = calendar->rawTodos(); |
637 | Todo* to = tl.first(); | 526 | Todo* to = tl.first(); |
638 | while ( to ) { | 527 | while ( to ) { |
639 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 528 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
640 | calendar->deleteTodo( to ); | 529 | calendar->deleteTodo( to ); |
641 | } else { | 530 | } else { |
642 | if ( to->isCompleted()) { | 531 | if ( to->isCompleted()) { |
643 | calendar->deleteTodo( to ); | 532 | calendar->deleteTodo( to ); |
644 | } | 533 | } |
645 | } | 534 | } |
646 | to = tl.next(); | 535 | to = tl.next(); |
647 | } | 536 | } |
648 | // 3 save file | 537 | // 3 save file |
649 | if ( !writeToPhone( calendar ) ) | 538 | if ( !writeToPhone( calendar ) ) |
650 | return false; | 539 | return false; |
651 | 540 | ||
652 | // 5 reread data | 541 | // 5 reread data |
653 | message = i18n(" Rereading all data ... "); | 542 | message = i18n(" Rereading all data ... "); |
654 | status.setText ( message ); | 543 | status.setText ( message ); |
655 | qApp->processEvents(); | 544 | qApp->processEvents(); |
656 | CalendarLocal* calendarTemp = new CalendarLocal(); | 545 | CalendarLocal* calendarTemp = new CalendarLocal(); |
657 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 546 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
658 | if ( ! load( calendarTemp,calendar) ){ | 547 | if ( ! load( calendarTemp,calendar) ){ |
659 | qDebug("error reloading calendar "); | 548 | qDebug("error reloading calendar "); |
660 | delete calendarTemp; | 549 | delete calendarTemp; |
661 | return false; | 550 | return false; |
662 | } | 551 | } |
663 | // 6 compare data | 552 | // 6 compare data |
664 | 553 | ||
665 | //algo 6 compare event | 554 | //algo 6 compare event |
666 | er = calendar->rawEvents(); | 555 | er = calendar->rawEvents(); |
667 | ev = er.first(); | 556 | ev = er.first(); |
668 | message = i18n(" Comparing event # "); | 557 | message = i18n(" Comparing event # "); |
669 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 558 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
670 | Event* ev1; | 559 | Event* ev1; |
671 | int procCount = 0; | 560 | int procCount = 0; |
672 | while ( ev ) { | 561 | while ( ev ) { |
673 | //qDebug("event new ID %s",ev->summary().latin1()); | 562 | //qDebug("event new ID %s",ev->summary().latin1()); |
674 | status.setText ( message + QString::number ( ++procCount ) ); | 563 | status.setText ( message + QString::number ( ++procCount ) ); |
675 | qApp->processEvents(); | 564 | qApp->processEvents(); |
676 | uint csum; | 565 | uint csum; |
677 | csum = PhoneFormat::getCsumEvent( ev ); | 566 | csum = PhoneFormat::getCsumEvent( ev ); |
678 | QString cSum = QString::number( csum ); | 567 | QString cSum = QString::number( csum ); |
679 | //ev->setCsum( mProfileName, cSum ); | 568 | //ev->setCsum( mProfileName, cSum ); |
680 | //qDebug("Event cSum %s ", cSum.latin1()); | 569 | //qDebug("Event cSum %s ", cSum.latin1()); |
681 | ev1 = er1.first(); | 570 | ev1 = er1.first(); |
682 | while ( ev1 ) { | 571 | while ( ev1 ) { |
683 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 572 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
684 | er1.remove( ev1 ); | 573 | er1.remove( ev1 ); |
685 | afterSave( ev ); | 574 | afterSave( ev ); |
686 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 575 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
687 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 576 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |
688 | 577 | ||
689 | break; | 578 | break; |
690 | } | 579 | } |
691 | ev1 = er1.next(); | 580 | ev1 = er1.next(); |
692 | } | 581 | } |
693 | if ( ! ev1 ) { | 582 | if ( ! ev1 ) { |
694 | // ev->removeID(mProfileName); | 583 | // ev->removeID(mProfileName); |
695 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 584 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
696 | } | 585 | } |
697 | 586 | ||
698 | 587 | ||
699 | ev = er.next(); | 588 | ev = er.next(); |
700 | } | 589 | } |
701 | //algo 6 compare todo | 590 | //algo 6 compare todo |
702 | tl = calendar->rawTodos(); | 591 | tl = calendar->rawTodos(); |
703 | to = tl.first(); | 592 | to = tl.first(); |
704 | procCount = 0; | 593 | procCount = 0; |
705 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 594 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
706 | Todo* to1 ; | 595 | Todo* to1 ; |
707 | message = i18n(" Comparing todo # "); | 596 | message = i18n(" Comparing todo # "); |
708 | while ( to ) { | 597 | while ( to ) { |
709 | status.setText ( message + QString::number ( ++procCount ) ); | 598 | status.setText ( message + QString::number ( ++procCount ) ); |
710 | qApp->processEvents(); | 599 | qApp->processEvents(); |
711 | uint csum; | 600 | uint csum; |
712 | csum = PhoneFormat::getCsumTodo( to ); | 601 | csum = PhoneFormat::getCsumTodo( to ); |
713 | QString cSum = QString::number( csum ); | 602 | QString cSum = QString::number( csum ); |
714 | //to->setCsum( mProfileName, cSum ); | 603 | //to->setCsum( mProfileName, cSum ); |
715 | //qDebug("Todo cSum %s ", cSum.latin1()); | 604 | //qDebug("Todo cSum %s ", cSum.latin1()); |
716 | Todo* to1 = tl1.first(); | 605 | Todo* to1 = tl1.first(); |
717 | while ( to1 ) { | 606 | while ( to1 ) { |
718 | if ( to1->getCsum( mProfileName ) == cSum ) { | 607 | if ( to1->getCsum( mProfileName ) == cSum ) { |
719 | tl1.remove( to1 ); | 608 | tl1.remove( to1 ); |
720 | afterSave( to ); | 609 | afterSave( to ); |
721 | to->setID(mProfileName, to1->getID(mProfileName) ); | 610 | to->setID(mProfileName, to1->getID(mProfileName) ); |
722 | break; | 611 | break; |
723 | } | 612 | } |
724 | to1 = tl1.next(); | 613 | to1 = tl1.next(); |
725 | } | 614 | } |
726 | if ( ! to1 ) { | 615 | if ( ! to1 ) { |
727 | //to->removeID(mProfileName); | 616 | //to->removeID(mProfileName); |
728 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 617 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
729 | } | 618 | } |
730 | 619 | ||
731 | to = tl.next(); | 620 | to = tl.next(); |
732 | } | 621 | } |
733 | delete calendarTemp; | 622 | delete calendarTemp; |
734 | return true; | 623 | return true; |
735 | 624 | ||
736 | 625 | ||
737 | 626 | ||
738 | } | 627 | } |
739 | 628 | ||
740 | 629 | ||
741 | QString PhoneFormat::toString( Calendar * ) | 630 | QString PhoneFormat::toString( Calendar * ) |
742 | { | 631 | { |
743 | return QString::null; | 632 | return QString::null; |
744 | } | 633 | } |
745 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 634 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
746 | { | 635 | { |
747 | return false; | 636 | return false; |
748 | } | 637 | } |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 61e8160..001fd81 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -1,63 +1,62 @@ | |||
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 | #ifndef PHONEFORMAT_H | 21 | #ifndef PHONEFORMAT_H |
22 | #define PHONEFORMAT_H | 22 | #define PHONEFORMAT_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | #include "scheduler.h" | 26 | #include "scheduler.h" |
27 | 27 | ||
28 | #include "vcalformat.h" | 28 | #include "vcalformat.h" |
29 | #include "calformat.h" | 29 | #include "calformat.h" |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | This class implements the calendar format used by Phone. | 34 | This class implements the calendar format used by Phone. |
35 | */ | 35 | */ |
36 | class Event; | 36 | class Event; |
37 | class Todo; | 37 | class Todo; |
38 | class PhoneFormat : public QObject { | 38 | class PhoneFormat : public QObject { |
39 | public: | 39 | public: |
40 | /** Create new iCalendar format. */ | 40 | /** Create new iCalendar format. */ |
41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); | 41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); |
42 | virtual ~PhoneFormat(); | 42 | virtual ~PhoneFormat(); |
43 | 43 | ||
44 | bool load( Calendar * ,Calendar * ); | 44 | bool load( Calendar * ,Calendar * ); |
45 | bool save( Calendar * ); | 45 | bool save( Calendar * ); |
46 | bool fromString( Calendar *, const QString & ); | 46 | bool fromString( Calendar *, const QString & ); |
47 | QString toString( Calendar * ); | 47 | QString toString( Calendar * ); |
48 | static ulong getCsum( const QStringList & ); | 48 | static ulong getCsum( const QStringList & ); |
49 | static ulong getCsumTodo( Todo* to ); | 49 | static ulong getCsumTodo( Todo* to ); |
50 | static ulong getCsumEvent( Event* ev ); | 50 | static ulong getCsumEvent( Event* ev ); |
51 | static void writeConfig( QString device,QString connection, QString model ); | ||
52 | static bool writeToPhone( Calendar * ); | 51 | static bool writeToPhone( Calendar * ); |
53 | private: | 52 | private: |
54 | void copyEvent( Event* to, Event* from ); | 53 | void copyEvent( Event* to, Event* from ); |
55 | void copyTodo( Todo* to, Todo* from ); | 54 | void copyTodo( Todo* to, Todo* from ); |
56 | //int initDevice(GSM_StateMachine *s); | 55 | //int initDevice(GSM_StateMachine *s); |
57 | QString mProfileName; | 56 | QString mProfileName; |
58 | void afterSave( Incidence* ); | 57 | void afterSave( Incidence* ); |
59 | }; | 58 | }; |
60 | 59 | ||
61 | } | 60 | } |
62 | 61 | ||
63 | #endif | 62 | #endif |