summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-09 18:02:44 (UTC)
committer zautrix <zautrix>2004-08-09 18:02:44 (UTC)
commit4f05a9fcbb9e54184aef93883886aaf865104463 (patch) (unidiff)
treef5e94f7694b74dca3b11e1e74a94058a4526dafe /libkcal
parente1909ade2188e53feee65089d5f2882563876c58 (diff)
downloadkdepimpi-4f05a9fcbb9e54184aef93883886aaf865104463.zip
kdepimpi-4f05a9fcbb9e54184aef93883886aaf865104463.tar.gz
kdepimpi-4f05a9fcbb9e54184aef93883886aaf865104463.tar.bz2
more syncing
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp60
-rw-r--r--libkcal/phoneformat.h2
-rw-r--r--libkcal/vcalformat.cpp19
-rw-r--r--libkcal/vcalformat.h2
4 files changed, 32 insertions, 51 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 11c68c5..e6d4879 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -849,101 +849,59 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
849 } 849 }
850 850
851 start = true; 851 start = true;
852 GSM_ToDoEntry ToDo; 852 GSM_ToDoEntry ToDo;
853 ccc = 0; 853 ccc = 0;
854 message = i18n("Processing todo # "); 854 message = i18n("Processing todo # ");
855 procCount = 0; 855 procCount = 0;
856 while (!gshutdown) { 856 while (!gshutdown) {
857 status.setText ( message + QString::number ( ++procCount ) ); 857 status.setText ( message + QString::number ( ++procCount ) );
858 qApp->processEvents(); 858 qApp->processEvents();
859 error = Phone->GetNextToDo(&s, &ToDo, start); 859 error = Phone->GetNextToDo(&s, &ToDo, start);
860 if (error == ERR_EMPTY) break; 860 if (error == ERR_EMPTY) break;
861 start = false; 861 start = false;
862 qDebug("ReadTodo %d ", ++ccc); 862 qDebug("ReadTodo %d ", ++ccc);
863 handler.readTodo( existingCal, &ToDo, &s); 863 handler.readTodo( existingCal, &ToDo, &s);
864 864
865 } 865 }
866 866
867 error=GSM_TerminateConnection(&s); 867 error=GSM_TerminateConnection(&s);
868 868
869 return true; 869 return true;
870} 870}
871void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note ) 871void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note )
872{ 872{
873 873 QString eText = vfconverter.eventToString( ev );
874 int pos = 0;
875 GSM_ToDoEntry dummy;
876 GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
874} 877}
875void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm ) 878void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo )
876{ 879{
877#if 0 880 QString tText = vfconverter.todoToString( todo );
878 QStringList list; 881 int pos = 0;
879 list.append( QString::number( todo->zaurusId() ) ); 882 GSM_CalendarEntry dummy;
880 list.append( todo->categories().join(",") ); 883 GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
881
882 if ( todo->hasStartDate() ) {
883 list.append( dtToString( todo->dtStart()) );
884 } else
885 list.append( QString() );
886
887 if ( todo->hasDueDate() ) {
888 QTime tim;
889 if ( todo->doesFloat()) {
890 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
891 } else {
892 list.append( dtToString(todo->dtDue() ) );
893 }
894 } else
895 list.append( QString() );
896
897 if ( todo->isCompleted() ) {
898 list.append( dtToString( todo->completed()) );
899 list.append( "0" ); // yes 0 == completed
900 } else {
901 list.append( dtToString( todo->completed()) );
902 list.append( "1" );
903 }
904 list.append( QString::number( todo->priority() ));
905 if( ! todo->summary().isEmpty() )
906 list.append( todo->summary() );
907 else
908 list.append( "" );
909 if (! todo->description().isEmpty() )
910 list.append( todo->description() );
911 else
912 list.append( "" );
913 for(QStringList::Iterator it=list.begin();
914 it!=list.end(); ++it){
915 QString& s = (*it);
916 s.replace(QRegExp("\""), "\"\"");
917 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
918 s.prepend('\"');
919 s.append('\"');
920 } else if(s.isEmpty() && !s.isNull()){
921 s = "\"\"";
922 }
923 }
924 return list.join(",");
925#endif
926} 884}
927void PhoneFormat::afterSave( Incidence* inc) 885void PhoneFormat::afterSave( Incidence* inc)
928{ 886{
929 uint csum; 887 uint csum;
930 if ( inc->type() == "Event") 888 if ( inc->type() == "Event")
931 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 889 csum = PhoneFormat::getCsumEvent( (Event*) inc );
932 else 890 else
933 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 891 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
934 inc->setCsum( mProfileName, QString::number( csum )); 892 inc->setCsum( mProfileName, QString::number( csum ));
935 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 893 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
936 894
937} 895}
938bool PhoneFormat::save( Calendar *calendar) 896bool PhoneFormat::save( Calendar *calendar)
939{ 897{
940 GSM_StateMachines; 898 GSM_StateMachines;
941 qDebug(" save "); 899 qDebug(" save ");
942 s.opened = false; 900 s.opened = false;
943 s.msg = NULL; 901 s.msg = NULL;
944 s.ConfigNum = 0; 902 s.ConfigNum = 0;
945 QLabel status ( i18n("Writing data. Opening device ..."), 0 ); 903 QLabel status ( i18n("Writing data. Opening device ..."), 0 );
946 int w = status.sizeHint().width()+20 ; 904 int w = status.sizeHint().width()+20 ;
947 if ( w < 200 ) w = 200; 905 if ( w < 200 ) w = 200;
948 int h = status.sizeHint().height()+20 ; 906 int h = status.sizeHint().height()+20 ;
949 int dw = QApplication::desktop()->width(); 907 int dw = QApplication::desktop()->width();
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 7b7dd04..33b2091 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -4,62 +4,64 @@
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 "calformat.h" 29#include "calformat.h"
29extern "C" { 30extern "C" {
30#include "../gammu/emb/common/gammu.h" 31#include "../gammu/emb/common/gammu.h"
31} 32}
32namespace KCal { 33namespace KCal {
33 34
34/** 35/**
35 This class implements the calendar format used by Phone. 36 This class implements the calendar format used by Phone.
36*/ 37*/
37 class Event; 38 class Event;
38 class Todo; 39 class Todo;
39class PhoneFormat : public QObject { 40class PhoneFormat : public QObject {
40 public: 41 public:
41 /** Create new iCalendar format. */ 42 /** Create new iCalendar format. */
42 PhoneFormat(QString profileName, QString device,QString connection, QString model); 43 PhoneFormat(QString profileName, QString device,QString connection, QString model);
43 virtual ~PhoneFormat(); 44 virtual ~PhoneFormat();
44 45
45 bool load( Calendar * ,Calendar * ); 46 bool load( Calendar * ,Calendar * );
46 bool save( Calendar * ); 47 bool save( Calendar * );
47 bool fromString( Calendar *, const QString & ); 48 bool fromString( Calendar *, const QString & );
48 QString toString( Calendar * ); 49 QString toString( Calendar * );
49 static ulong getCsum( const QStringList & ); 50 static ulong getCsum( const QStringList & );
50 static ulong getCsumTodo( Todo* to ); 51 static ulong getCsumTodo( Todo* to );
51 static ulong getCsumEvent( Event* ev ); 52 static ulong getCsumEvent( Event* ev );
52 private: 53 private:
54 VCalFormat vfconverter;
53 void event2GSM( Event* ev, GSM_CalendarEntry*Note ); 55 void event2GSM( Event* ev, GSM_CalendarEntry*Note );
54 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo ); 56 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
55 int initDevice(GSM_StateMachine *s); 57 int initDevice(GSM_StateMachine *s);
56 QString getEventString( Event* ); 58 QString getEventString( Event* );
57 QString getTodoString( Todo* ); 59 QString getTodoString( Todo* );
58 QString dtToGSM( const QDateTime& dt, bool useTZ = true ); 60 QString dtToGSM( const QDateTime& dt, bool useTZ = true );
59 QString mProfileName, mDevice, mConnection, mModel; 61 QString mProfileName, mDevice, mConnection, mModel;
60 void afterSave( Incidence* ); 62 void afterSave( Incidence* );
61}; 63};
62 64
63} 65}
64 66
65#endif 67#endif
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 72a781a..1167e58 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -144,48 +144,67 @@ bool VCalFormat::fromString( Calendar *calendar, const QString &text )
144 VObjectIterator i; 144 VObjectIterator i;
145 VObject *curvo; 145 VObject *curvo;
146 initPropIterator( &i, vcal ); 146 initPropIterator( &i, vcal );
147 147
148 // we only take the first object. TODO: parse all incidences. 148 // we only take the first object. TODO: parse all incidences.
149 do { 149 do {
150 curvo = nextVObject( &i ); 150 curvo = nextVObject( &i );
151 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 151 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
152 strcmp( vObjectName( curvo ), VCTodoProp ) ); 152 strcmp( vObjectName( curvo ), VCTodoProp ) );
153 153
154 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 154 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
155 Event *event = VEventToEvent( curvo ); 155 Event *event = VEventToEvent( curvo );
156 calendar->addEvent( event ); 156 calendar->addEvent( event );
157 } else { 157 } else {
158 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 158 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
159 deleteVObject( vcal ); 159 deleteVObject( vcal );
160 return false; 160 return false;
161 } 161 }
162 162
163 deleteVObject( vcal ); 163 deleteVObject( vcal );
164 164
165 return true; 165 return true;
166} 166}
167 167
168QString VCalFormat::eventToString( Event * event)
169{
170 if ( !event ) return QString::null;
171 VObject *vevent = eventToVEvent( event );
172 char *buf = writeMemVObject( 0, 0, vevent );
173 QString result( buf );
174 cleanVObject( vevent );
175 return result;
176}
177QString VCalFormat::todoToString( Todo * todo )
178{
179 if ( !todo ) return QString::null;
180 VObject *vevent = eventToVTodo( todo );
181 char *buf = writeMemVObject( 0, 0, vevent );
182 QString result( buf );
183 cleanVObject( vevent );
184 return result;
185}
186
168QString VCalFormat::toString( Calendar *calendar ) 187QString VCalFormat::toString( Calendar *calendar )
169{ 188{
170 // TODO: Factor out VCalFormat::asString() 189 // TODO: Factor out VCalFormat::asString()
171 190
172 VObject *vcal = newVObject(VCCalProp); 191 VObject *vcal = newVObject(VCCalProp);
173 192
174 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 193 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
175 QString tmpStr = mCalendar->getTimeZoneStr(); 194 QString tmpStr = mCalendar->getTimeZoneStr();
176 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 195 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
177 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 196 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
178 197
179 // TODO: Use all data. 198 // TODO: Use all data.
180 QPtrList<Event> events = calendar->events(); 199 QPtrList<Event> events = calendar->events();
181 Event *event = events.first(); 200 Event *event = events.first();
182 if ( !event ) return QString::null; 201 if ( !event ) return QString::null;
183 202
184 VObject *vevent = eventToVEvent( event ); 203 VObject *vevent = eventToVEvent( event );
185 204
186 addVObjectProp( vcal, vevent ); 205 addVObjectProp( vcal, vevent );
187 206
188 char *buf = writeMemVObject( 0, 0, vcal ); 207 char *buf = writeMemVObject( 0, 0, vcal );
189 208
190 QString result( buf ); 209 QString result( buf );
191 210
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h
index d4cecbc..8490125 100644
--- a/libkcal/vcalformat.h
+++ b/libkcal/vcalformat.h
@@ -41,48 +41,50 @@ class VCalFormat : public CalFormat {
41 public: 41 public:
42 VCalFormat(); 42 VCalFormat();
43 virtual ~VCalFormat(); 43 virtual ~VCalFormat();
44 44
45 /** loads a calendar on disk in vCalendar format into the current calendar. 45 /** loads a calendar on disk in vCalendar format into the current calendar.
46 * any information already present is lost. Returns TRUE if successful, 46 * any information already present is lost. Returns TRUE if successful,
47 * else returns FALSE. 47 * else returns FALSE.
48 * @param fileName the name of the calendar on disk. 48 * @param fileName the name of the calendar on disk.
49 */ 49 */
50 bool load(Calendar *,const QString &fileName); 50 bool load(Calendar *,const QString &fileName);
51 /** writes out the calendar to disk in vCalendar format. Returns true if 51 /** writes out the calendar to disk in vCalendar format. Returns true if
52 * successful and false on error. 52 * successful and false on error.
53 * @param fileName the name of the file 53 * @param fileName the name of the file
54 */ 54 */
55 bool save(Calendar *,const QString &fileName); 55 bool save(Calendar *,const QString &fileName);
56 56
57 /** 57 /**
58 Parse string and populate calendar with that information. 58 Parse string and populate calendar with that information.
59 */ 59 */
60 bool fromString( Calendar *, const QString & ); 60 bool fromString( Calendar *, const QString & );
61 /** 61 /**
62 Return calendar information as string. 62 Return calendar information as string.
63 */ 63 */
64 QString toString( Calendar * ); 64 QString toString( Calendar * );
65 QString eventToString( Event * );
66 QString todoToString( Todo * );
65 67
66 protected: 68 protected:
67 /** translates a VObject of the TODO type into a Event */ 69 /** translates a VObject of the TODO type into a Event */
68 Todo *VTodoToEvent(VObject *vtodo); 70 Todo *VTodoToEvent(VObject *vtodo);
69 /** translates a VObject into a Event and returns a pointer to it. */ 71 /** translates a VObject into a Event and returns a pointer to it. */
70 Event *VEventToEvent(VObject *vevent); 72 Event *VEventToEvent(VObject *vevent);
71 /** translate a Event into a VTodo-type VObject and return pointer */ 73 /** translate a Event into a VTodo-type VObject and return pointer */
72 VObject *eventToVTodo(const Todo *anEvent); 74 VObject *eventToVTodo(const Todo *anEvent);
73 /** translate a Event into a VObject and returns a pointer to it. */ 75 /** translate a Event into a VObject and returns a pointer to it. */
74 VObject* eventToVEvent(const Event *anEvent); 76 VObject* eventToVEvent(const Event *anEvent);
75 77
76 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ 78 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */
77 QString qDateToISO(const QDate &); 79 QString qDateToISO(const QDate &);
78 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ 80 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */
79 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); 81 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE);
80 /** takes a string in the format YYYYMMDDTHHMMSS and returns a 82 /** takes a string in the format YYYYMMDDTHHMMSS and returns a
81 * valid QDateTime. */ 83 * valid QDateTime. */
82 QDateTime ISOToQDateTime(const QString & dtStr); 84 QDateTime ISOToQDateTime(const QString & dtStr);
83 /** takes a string in the format YYYYMMDD and returns a 85 /** takes a string in the format YYYYMMDD and returns a
84 * valid QDate. */ 86 * valid QDate. */
85 QDate ISOToQDate(const QString & dtStr); 87 QDate ISOToQDate(const QString & dtStr);
86 /** takes a vCalendar tree of VObjects, and puts all of them that have 88 /** takes a vCalendar tree of VObjects, and puts all of them that have
87 * the "event" property into the dictionary, todos in the todo-list, etc. */ 89 * the "event" property into the dictionary, todos in the todo-list, etc. */
88 void populate(VObject *vcal); 90 void populate(VObject *vcal);