summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp97
-rw-r--r--libkcal/phoneformat.h2
2 files changed, 94 insertions, 5 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 178a63e..99d6a06 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,281 +1,370 @@
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 <qxml.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 39
40#include "calendar.h" 40#include "calendar.h"
41#include "alarm.h" 41#include "alarm.h"
42#include "recurrence.h" 42#include "recurrence.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44 44
45#include "phoneformat.h" 45#include "phoneformat.h"
46#include "syncdefines.h" 46#include "syncdefines.h"
47 47
48using namespace KCal; 48using namespace KCal;
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( ) { 52 PhoneParser( ) {
53 ; 53 ;
54 } 54 }
55 55
56 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 56 static QString dtToString( const QDateTime& dti, bool useTZ = false )
57 { 57 {
58 QString datestr; 58 QString datestr;
59 QString timestr; 59 QString timestr;
60 int offset = KGlobal::locale()->localTimeOffset( dti ); 60 int offset = KGlobal::locale()->localTimeOffset( dti );
61 QDateTime dt; 61 QDateTime dt;
62 if (useTZ) 62 if (useTZ)
63 dt = dti.addSecs ( -(offset*60)); 63 dt = dti.addSecs ( -(offset*60));
64 else 64 else
65 dt = dti; 65 dt = dti;
66 if(dt.date().isValid()){ 66 if(dt.date().isValid()){
67 const QDate& date = dt.date(); 67 const QDate& date = dt.date();
68 datestr.sprintf("%04d%02d%02d", 68 datestr.sprintf("%04d%02d%02d",
69 date.year(), date.month(), date.day()); 69 date.year(), date.month(), date.day());
70 } 70 }
71 if(dt.time().isValid()){ 71 if(dt.time().isValid()){
72 const QTime& time = dt.time(); 72 const QTime& time = dt.time();
73 timestr.sprintf("T%02d%02d%02d", 73 timestr.sprintf("T%02d%02d%02d",
74 time.hour(), time.minute(), time.second()); 74 time.hour(), time.minute(), time.second());
75 } 75 }
76 return datestr + timestr; 76 return datestr + timestr;
77 } 77 }
78 78
79 79
80}; 80};
81 81
82 82
83 83
84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
85{ 85{
86 mProfileName = profileName; 86 mProfileName = profileName;
87 mDevice = device; 87
88 mConnection = connection; 88 QString fileName = QDir::homeDirPath() +"/.gammurc";
89 mModel = model; 89 //qDebug("save %d ", load );
90 QString content;
91 bool write = false;
92 bool addPort = true, addConnection = true, addModel = true;
93 QFile file( fileName );
94 if ( QFile::exists( fileName) ) {
95 if (!file.open( IO_ReadOnly ) ) {
96 qDebug("Error: cannot open %s ", fileName.latin1() );
97 return;
98 }
99 QString line;
100 while ( file.readLine( line, 1024 ) > 0 ) {
101 //qDebug("*%s* ", line.latin1() );
102 if ( line.left(7 ) == "[gammu]" ) {
103 ;
104 } else
105 if ( line.left(4 ) == "port" ) {
106 if ( line == "port = " + device+"\n" ) {
107 content += line ;
108 addPort = false;
109 //qDebug("port found" );
110 }
111
112 } else if ( line.left(5 ) == "model" ) {
113 if ( line == "model = " + model +"\n") {
114 content += line ;
115 addModel = false;
116 //qDebug("model found" );
117 }
118
119 } else if ( line.left( 10 ) == "connection" ) {
120 if ( line == "connection = " + connection +"\n") {
121 addConnection = false;
122 content += line ;
123 //qDebug("con found" );
124 }
125
126 } else {
127 content += line ;
128 }
129 }
130 file.close();
131 } else {
132 if ( ! connection.isEmpty() ) {
133 addConnection = true;
134 }
135 if ( ! device.isEmpty() ) {
136 addPort = true;
137
138 }
139 if ( ! model.isEmpty() ) {
140 addModel = true;
141 }
142 }
143
144 if ( addConnection ) {
145 if ( ! write )
146 content += "[gammu]\n";
147 write = true;
148 content += "connection = ";
149 content += connection;
150 content += "\n";
151 }
152 if ( addPort ) {
153 if ( ! write )
154 content += "[gammu]\n";
155 write = true;
156 content += "port = ";
157 content += device;
158 content += "\n";
159
160 }
161 if ( addModel ) {
162 if ( ! write )
163 content += "[gammu]\n";
164 write = true;
165 content += "model = ";
166 content += model;
167 content += "\n";
168 }
169 if ( write ) {
170 if (!file.open( IO_WriteOnly ) ) {
171 qDebug("Error: cannot write file %s ", fileName.latin1() );
172 return;
173 }
174 qDebug("Writing file %s ", fileName.latin1() );
175 QTextStream ts( &file );
176 ts << content ;
177 file.close();
178 }
90} 179}
91 180
92PhoneFormat::~PhoneFormat() 181PhoneFormat::~PhoneFormat()
93{ 182{
94} 183}
95#if 0 184#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 185int PhoneFormat::initDevice(GSM_StateMachine *s)
97{ 186{
98 GSM_ReadConfig(NULL, &s->Config[0], 0); 187 GSM_ReadConfig(NULL, &s->Config[0], 0);
99 s->ConfigNum = 1; 188 s->ConfigNum = 1;
100 GSM_Config *cfg = &s->Config[0]; 189 GSM_Config *cfg = &s->Config[0];
101 if ( ! mConnection.isEmpty() ) { 190 if ( ! mConnection.isEmpty() ) {
102 cfg->Connection = strdup(mConnection.latin1()); 191 cfg->Connection = strdup(mConnection.latin1());
103 cfg->DefaultConnection = false; 192 cfg->DefaultConnection = false;
104 qDebug("Connection set %s ", cfg->Connection ); 193 qDebug("Connection set %s ", cfg->Connection );
105 194
106 } 195 }
107 if ( ! mDevice.isEmpty() ) { 196 if ( ! mDevice.isEmpty() ) {
108 cfg->Device = strdup(mDevice.latin1()); 197 cfg->Device = strdup(mDevice.latin1());
109 cfg->DefaultDevice = false; 198 cfg->DefaultDevice = false;
110 qDebug("Device set %s ", cfg->Device); 199 qDebug("Device set %s ", cfg->Device);
111 200
112 } 201 }
113 if ( ! mModel.isEmpty() ) { 202 if ( ! mModel.isEmpty() ) {
114 strcpy(cfg->Model,mModel.latin1() ); 203 strcpy(cfg->Model,mModel.latin1() );
115 cfg->DefaultModel = false; 204 cfg->DefaultModel = false;
116 qDebug("Model set %s ",cfg->Model ); 205 qDebug("Model set %s ",cfg->Model );
117 } 206 }
118 int error=GSM_InitConnection(s,3); 207 int error=GSM_InitConnection(s,3);
119 return error; 208 return error;
120} 209}
121#endif 210#endif
122ulong PhoneFormat::getCsumTodo( Todo* todo ) 211ulong PhoneFormat::getCsumTodo( Todo* todo )
123{ 212{
124 QStringList attList; 213 QStringList attList;
125 if ( todo->hasDueDate() ) 214 if ( todo->hasDueDate() )
126 attList << PhoneParser::dtToString ( todo->dtDue() ); 215 attList << PhoneParser::dtToString ( todo->dtDue() );
127 attList << todo->summary(); 216 attList << todo->summary();
128 QString completedString = "no"; 217 QString completedString = "no";
129 if ( todo->isCompleted() ) 218 if ( todo->isCompleted() )
130 completedString = "yes"; 219 completedString = "yes";
131 attList << completedString; 220 attList << completedString;
132 int prio = todo->priority(); 221 int prio = todo->priority();
133 if( prio == 2 ) prio = 1; 222 if( prio == 2 ) prio = 1;
134 if (prio == 4 ) prio = 5 ; 223 if (prio == 4 ) prio = 5 ;
135 attList << QString::number( prio ); 224 attList << QString::number( prio );
136 QString alarmString = "na"; 225 QString alarmString = "na";
137 Alarm *alarm; 226 Alarm *alarm;
138 if ( todo->alarms().count() > 0 ) { 227 if ( todo->alarms().count() > 0 ) {
139 alarm = todo->alarms().first(); 228 alarm = todo->alarms().first();
140 if ( alarm->enabled() ) { 229 if ( alarm->enabled() ) {
141 alarmString = QString::number(alarm->offset() ); 230 alarmString = QString::number(alarm->offset() );
142 } 231 }
143 } 232 }
144 attList << alarmString; 233 attList << alarmString;
145 attList << todo->categoriesStr(); 234 attList << todo->categoriesStr();
146 attList << todo->secrecyStr(); 235 attList << todo->secrecyStr();
147 return PhoneFormat::getCsum(attList ); 236 return PhoneFormat::getCsum(attList );
148 237
149} 238}
150ulong PhoneFormat::getCsumEvent( Event* event ) 239ulong PhoneFormat::getCsumEvent( Event* event )
151{ 240{
152 QStringList attList; 241 QStringList attList;
153 attList << PhoneParser::dtToString ( event->dtStart() ); 242 attList << PhoneParser::dtToString ( event->dtStart() );
154 attList << PhoneParser::dtToString ( event->dtEnd() ); 243 attList << PhoneParser::dtToString ( event->dtEnd() );
155 attList << event->summary(); 244 attList << event->summary();
156 attList << event->location(); 245 attList << event->location();
157 QString alarmString = "na"; 246 QString alarmString = "na";
158 Alarm *alarm; 247 Alarm *alarm;
159 if ( event->alarms().count() > 0 ) { 248 if ( event->alarms().count() > 0 ) {
160 alarm = event->alarms().first(); 249 alarm = event->alarms().first();
161 if ( alarm->enabled() ) { 250 if ( alarm->enabled() ) {
162 alarmString = QString::number( alarm->offset() ); 251 alarmString = QString::number( alarm->offset() );
163 } 252 }
164 } 253 }
165 attList << alarmString; 254 attList << alarmString;
166 Recurrence* rec = event->recurrence(); 255 Recurrence* rec = event->recurrence();
167 QStringList list; 256 QStringList list;
168 bool writeEndDate = false; 257 bool writeEndDate = false;
169 switch ( rec->doesRecur() ) 258 switch ( rec->doesRecur() )
170 { 259 {
171 case Recurrence::rDaily: // 0 260 case Recurrence::rDaily: // 0
172 list.append( "0" ); 261 list.append( "0" );
173 list.append( QString::number( rec->frequency() ));//12 262 list.append( QString::number( rec->frequency() ));//12
174 list.append( "0" ); 263 list.append( "0" );
175 list.append( "0" ); 264 list.append( "0" );
176 writeEndDate = true; 265 writeEndDate = true;
177 break; 266 break;
178 case Recurrence::rWeekly:// 1 267 case Recurrence::rWeekly:// 1
179 list.append( "1" ); 268 list.append( "1" );
180 list.append( QString::number( rec->frequency()) );//12 269 list.append( QString::number( rec->frequency()) );//12
181 list.append( "0" ); 270 list.append( "0" );
182 { 271 {
183 int days = 0; 272 int days = 0;
184 QBitArray weekDays = rec->days(); 273 QBitArray weekDays = rec->days();
185 int i; 274 int i;
186 for( i = 1; i <= 7; ++i ) { 275 for( i = 1; i <= 7; ++i ) {
187 if ( weekDays[i-1] ) { 276 if ( weekDays[i-1] ) {
188 days += 1 << (i-1); 277 days += 1 << (i-1);
189 } 278 }
190 } 279 }
191 list.append( QString::number( days ) ); 280 list.append( QString::number( days ) );
192 } 281 }
193 //pending weekdays 282 //pending weekdays
194 writeEndDate = true; 283 writeEndDate = true;
195 284
196 break; 285 break;
197 case Recurrence::rMonthlyPos:// 2 286 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 287 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 288 list.append( QString::number( rec->frequency()) );//12
200 289
201 writeEndDate = true; 290 writeEndDate = true;
202 { 291 {
203 int count = 1; 292 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 293 QPtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 294 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 295 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 296 count = 5 - rmp.first()->rPos - 1;
208 else 297 else
209 count = rmp.first()->rPos - 1; 298 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 299 list.append( QString::number( count ) );
211 300
212 } 301 }
213 302
214 list.append( "0" ); 303 list.append( "0" );
215 break; 304 break;
216 case Recurrence::rMonthlyDay:// 3 305 case Recurrence::rMonthlyDay:// 3
217 list.append( "3" ); 306 list.append( "3" );
218 list.append( QString::number( rec->frequency()) );//12 307 list.append( QString::number( rec->frequency()) );//12
219 list.append( "0" ); 308 list.append( "0" );
220 list.append( "0" ); 309 list.append( "0" );
221 writeEndDate = true; 310 writeEndDate = true;
222 break; 311 break;
223 case Recurrence::rYearlyMonth://4 312 case Recurrence::rYearlyMonth://4
224 list.append( "4" ); 313 list.append( "4" );
225 list.append( QString::number( rec->frequency()) );//12 314 list.append( QString::number( rec->frequency()) );//12
226 list.append( "0" ); 315 list.append( "0" );
227 list.append( "0" ); 316 list.append( "0" );
228 writeEndDate = true; 317 writeEndDate = true;
229 break; 318 break;
230 319
231 default: 320 default:
232 list.append( "255" ); 321 list.append( "255" );
233 list.append( QString() ); 322 list.append( QString() );
234 list.append( "0" ); 323 list.append( "0" );
235 list.append( QString() ); 324 list.append( QString() );
236 list.append( "0" ); 325 list.append( "0" );
237 list.append( "20991231T000000" ); 326 list.append( "20991231T000000" );
238 break; 327 break;
239 } 328 }
240 if ( writeEndDate ) { 329 if ( writeEndDate ) {
241 330
242 if ( rec->endDate().isValid() ) { // 15 + 16 331 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 332 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 333 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 334 } else {
246 list.append( "0" ); 335 list.append( "0" );
247 list.append( "20991231T000000" ); 336 list.append( "20991231T000000" );
248 } 337 }
249 338
250 } 339 }
251 attList << list.join(""); 340 attList << list.join("");
252 attList << event->categoriesStr(); 341 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 342 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 343
255 attList << event->secrecyStr(); 344 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 345 return PhoneFormat::getCsum(attList );
257} 346}
258ulong PhoneFormat::getCsum( const QStringList & attList) 347ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 348{
260 int max = attList.count(); 349 int max = attList.count();
261 ulong cSum = 0; 350 ulong cSum = 0;
262 int j,k,i; 351 int j,k,i;
263 int add; 352 int add;
264 for ( i = 0; i < max ; ++i ) { 353 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 354 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
267 j = s.length(); 356 j = s.length();
268 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 358 int mul = k +1;
270 add = s[k].unicode (); 359 add = s[k].unicode ();
271 if ( k < 16 ) 360 if ( k < 16 )
272 mul = mul * mul; 361 mul = mul * mul;
273 int ii = i+1; 362 int ii = i+1;
274 add = add * mul *ii*ii*ii; 363 add = add * mul *ii*ii*ii;
275 cSum += add; 364 cSum += add;
276 } 365 }
277 } 366 }
278 367
279 } 368 }
280 //QString dump = attList.join(","); 369 //QString dump = attList.join(",");
281 //qDebug("csum: %d %s", cSum,dump.latin1()); 370 //qDebug("csum: %d %s", cSum,dump.latin1());
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 8286098..2d1ff79 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -1,61 +1,61 @@
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
31namespace KCal { 31namespace 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;
38class PhoneFormat : public QObject { 38class 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 private: 51 private:
52 void copyEvent( Event* to, Event* from ); 52 void copyEvent( Event* to, Event* from );
53 void copyTodo( Todo* to, Todo* from ); 53 void copyTodo( Todo* to, Todo* from );
54 //int initDevice(GSM_StateMachine *s); 54 //int initDevice(GSM_StateMachine *s);
55 QString mProfileName, mDevice, mConnection, mModel; 55 QString mProfileName;
56 void afterSave( Incidence* ); 56 void afterSave( Incidence* );
57}; 57};
58 58
59} 59}
60 60
61#endif 61#endif