summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-08 20:46:59 (UTC)
committer zautrix <zautrix>2004-08-08 20:46:59 (UTC)
commit3a769cd15cfdb8e19e5fec2088c59aadeed4800a (patch) (unidiff)
tree93b3dee16f7ae02c762f1cfd63864b3676ac65cb
parent957c13e21844ca75e337fc1c864554dd2240fc78 (diff)
downloadkdepimpi-3a769cd15cfdb8e19e5fec2088c59aadeed4800a.zip
kdepimpi-3a769cd15cfdb8e19e5fec2088c59aadeed4800a.tar.gz
kdepimpi-3a769cd15cfdb8e19e5fec2088c59aadeed4800a.tar.bz2
Fixed reading from phone
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 238b0ef..1a9ccbc 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -75,74 +75,77 @@ public:
75 if (todo ) 75 if (todo )
76 todo = (Todo *)todo->clone(); 76 todo = (Todo *)todo->clone();
77 else 77 else
78 todo = new Todo; 78 todo = new Todo;
79 todo->setID( mProfileName,QString::number( id ) ); 79 todo->setID( mProfileName,QString::number( id ) );
80 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 80 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
81 int priority; 81 int priority;
82 switch (ToDo->Priority) { 82 switch (ToDo->Priority) {
83 case GSM_Priority_Low : priority = 1; break; 83 case GSM_Priority_Low : priority = 1; break;
84 case GSM_Priority_Medium : priority = 3; break; 84 case GSM_Priority_Medium : priority = 3; break;
85 case GSM_Priority_High : priority = 5; break; 85 case GSM_Priority_High : priority = 5; break;
86 default :priority = 3 ;break; 86 default :priority = 3 ;break;
87 } 87 }
88 todo->setPriority( priority ); 88 todo->setPriority( priority );
89 GSM_Phone_Functions*Phone; 89 GSM_Phone_Functions*Phone;
90 Phone=s->Phone.Functions; 90 Phone=s->Phone.Functions;
91 int j; 91 int j;
92 GSM_DateTime* dtp; 92 GSM_DateTime* dtp;
93 bool alarm = false; 93 bool alarm = false;
94 QDateTime alarmDt; 94 QDateTime alarmDt;
95 GSM_Category Category; 95 GSM_Category Category;
96 int error; 96 int error;
97 QString completedString = "no"; 97 QString completedString = "no";
98 for (j=0;j<ToDo->EntriesNum;j++) { 98 for (j=0;j<ToDo->EntriesNum;j++) {
99
100 //qDebug(" for todo %d",ToDo->Location );
99 switch (ToDo->Entries[j].EntryType) { 101 switch (ToDo->Entries[j].EntryType) {
100 case TODO_END_DATETIME: 102 case TODO_END_DATETIME:
101 dtp = &ToDo->Entries[j].Date ; 103 dtp = &ToDo->Entries[j].Date ;
102 todo->setDtDue (fromGSM ( dtp )); 104 todo->setDtDue (fromGSM ( dtp ));
103 break; 105 break;
104 case TODO_COMPLETED: 106 case TODO_COMPLETED:
105 if ( ToDo->Entries[j].Number == 1 ) { 107 if ( ToDo->Entries[j].Number == 1 ) {
106 todo->setCompleted( true ); 108 todo->setCompleted( true );
107 completedString = "yes"; 109 completedString = "yes";
108 } 110 }
109 else { 111 else {
110 todo->setCompleted( false ); 112 todo->setCompleted( false );
111 } 113 }
112 break; 114 break;
113 case TODO_ALARM_DATETIME: 115 case TODO_ALARM_DATETIME:
114 dtp = &ToDo->Entries[j].Date ; 116 dtp = &ToDo->Entries[j].Date ;
115 alarm = true; 117 alarm = true;
116 alarmDt = fromGSM ( dtp ); 118 alarmDt = fromGSM ( dtp );
117 break; 119 break;
118 case TODO_SILENT_ALARM_DATETIME: 120 case TODO_SILENT_ALARM_DATETIME:
119 dtp = &ToDo->Entries[j].Date ; 121 dtp = &ToDo->Entries[j].Date ;
120 alarm = true; 122 alarm = true;
121 alarmDt = fromGSM ( dtp ); 123 alarmDt = fromGSM ( dtp );
122 break; 124 break;
123 case TODO_TEXT: 125 case TODO_TEXT:
124 todo->setSummary( QString ( (const char*) ToDo->Entries[j].Text )); 126 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
127 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
125 break; 128 break;
126 case TODO_PRIVATE: 129 case TODO_PRIVATE:
127 if ( ToDo->Entries[j].Number == 1 ) 130 if ( ToDo->Entries[j].Number == 1 )
128 todo->setSecrecy( Incidence::SecrecyPrivate ); 131 todo->setSecrecy( Incidence::SecrecyPrivate );
129 else 132 else
130 todo->setSecrecy( Incidence::SecrecyPublic ); 133 todo->setSecrecy( Incidence::SecrecyPublic );
131 break; 134 break;
132 case TODO_CATEGORY: 135 case TODO_CATEGORY:
133 Category.Location = ToDo->Entries[j].Number; 136 Category.Location = ToDo->Entries[j].Number;
134 Category.Type = Category_ToDo; 137 Category.Type = Category_ToDo;
135 error=Phone->GetCategory(s, &Category); 138 error=Phone->GetCategory(s, &Category);
136 if (error == ERR_NONE) { 139 if (error == ERR_NONE) {
137 QStringList cat = todo->categories(); 140 QStringList cat = todo->categories();
138 QString nCat = QString ( (const char*)Category.Name ); 141 QString nCat = QString ( (const char*)Category.Name );
139 if ( !nCat.isEmpty() ) 142 if ( !nCat.isEmpty() )
140 if ( !cat.contains( nCat )) { 143 if ( !cat.contains( nCat )) {
141 cat << nCat; 144 cat << nCat;
142 todo->setCategories( cat ); 145 todo->setCategories( cat );
143 } 146 }
144 } 147 }
145 break; 148 break;
146 case TODO_CONTACTID: 149 case TODO_CONTACTID:
147#if 0 150#if 0
148 // not supported 151 // not supported
@@ -213,88 +216,89 @@ public:
213 event = (Event*)event->clone(); 216 event = (Event*)event->clone();
214 else 217 else
215 event = new Event; 218 event = new Event;
216 event->setID( mProfileName,QString::number( id ) ); 219 event->setID( mProfileName,QString::number( id ) );
217 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 220 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
218 221
219 222
220 int i = 0; 223 int i = 0;
221 bool repeating = false; 224 bool repeating = false;
222 int repeat_dayofweek = -1; 225 int repeat_dayofweek = -1;
223 int repeat_day = -1; 226 int repeat_day = -1;
224 int repeat_weekofmonth = -1; 227 int repeat_weekofmonth = -1;
225 int repeat_month = -1; 228 int repeat_month = -1;
226 int repeat_frequency = -1; 229 int repeat_frequency = -1;
227 int rec_type = -1; 230 int rec_type = -1;
228 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 231 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
229 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 232 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
230 GSM_DateTime* dtp; 233 GSM_DateTime* dtp;
231 bool alarm = false; 234 bool alarm = false;
232 QDateTime alarmDt; 235 QDateTime alarmDt;
233 repeat_startdate.Day= 0; 236 repeat_startdate.Day= 0;
234 repeat_stopdate.Day = 0; 237 repeat_stopdate.Day = 0;
235 for (i=0;i<Note->EntriesNum;i++) { 238 for (i=0;i<Note->EntriesNum;i++) {
236 239
237 qDebug(" for "); 240 //qDebug(" for ev");
238 switch (Note->Entries[i].EntryType) { 241 switch (Note->Entries[i].EntryType) {
239 case CAL_START_DATETIME: 242 case CAL_START_DATETIME:
240 dtp = &Note->Entries[i].Date ; 243 dtp = &Note->Entries[i].Date ;
241 if ( dtp->Hour > 24 ) { 244 if ( dtp->Hour > 24 ) {
242 event->setFloats( true ); 245 event->setFloats( true );
243 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 246 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
244 } else { 247 } else {
245 event->setDtStart (fromGSM ( dtp )); 248 event->setDtStart (fromGSM ( dtp ));
246 249
247 } 250 }
248 break; 251 break;
249 case CAL_END_DATETIME: 252 case CAL_END_DATETIME:
250 dtp = &Note->Entries[i].Date ; 253 dtp = &Note->Entries[i].Date ;
251 if ( dtp->Hour > 24 ) { 254 if ( dtp->Hour > 24 ) {
252 event->setFloats( true ); 255 event->setFloats( true );
253 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 256 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
254 } else { 257 } else {
255 event->setDtEnd (fromGSM ( dtp )); 258 event->setDtEnd (fromGSM ( dtp ));
256 } 259 }
257 break; 260 break;
258 case CAL_ALARM_DATETIME: 261 case CAL_ALARM_DATETIME:
259 dtp = &Note->Entries[i].Date ; 262 dtp = &Note->Entries[i].Date ;
260 alarm = true; 263 alarm = true;
261 alarmDt = fromGSM ( dtp ); 264 alarmDt = fromGSM ( dtp );
262 break; 265 break;
263 case CAL_SILENT_ALARM_DATETIME: 266 case CAL_SILENT_ALARM_DATETIME:
264 dtp = &Note->Entries[i].Date ; 267 dtp = &Note->Entries[i].Date ;
265 alarm = true; 268 alarm = true;
266 alarmDt = fromGSM ( dtp ); 269 alarmDt = fromGSM ( dtp );
267 break; 270 break;
268 case CAL_RECURRANCE: 271 case CAL_RECURRANCE:
269 rec_type = Note->Entries[i].Number; 272 rec_type = Note->Entries[i].Number;
270 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 273 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
271 break; 274 break;
272 case CAL_TEXT: 275 case CAL_TEXT:
273 event->setSummary( QString ( (const char*) Note->Entries[i].Text )); 276 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
277 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
274 break; 278 break;
275 case CAL_LOCATION: 279 case CAL_LOCATION:
276 event->setLocation(QString ((const char*) Note->Entries[i].Text )); 280 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
277 break; 281 break;
278 case CAL_PHONE: 282 case CAL_PHONE:
279 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 283 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
280 break; 284 break;
281 case CAL_PRIVATE: 285 case CAL_PRIVATE:
282 if ( Note->Entries[i].Number == 1 ) 286 if ( Note->Entries[i].Number == 1 )
283 event->setSecrecy( Incidence::SecrecyPrivate ); 287 event->setSecrecy( Incidence::SecrecyPrivate );
284 else 288 else
285 event->setSecrecy( Incidence::SecrecyPublic ); 289 event->setSecrecy( Incidence::SecrecyPublic );
286 290
287 break; 291 break;
288 case CAL_CONTACTID: 292 case CAL_CONTACTID:
289#if 0 293#if 0
290 entry.Location = Note->Entries[i].Number; 294 entry.Location = Note->Entries[i].Number;
291 entry.MemoryType = MEM_ME; 295 entry.MemoryType = MEM_ME;
292 error=Phone->GetMemory(&s, &entry); 296 error=Phone->GetMemory(&s, &entry);
293 if (error == ERR_NONE) { 297 if (error == ERR_NONE) {
294 name = GSM_PhonebookGetEntryName(&entry); 298 name = GSM_PhonebookGetEntryName(&entry);
295 if (name != NULL) { 299 if (name != NULL) {
296 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 300 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
297 } else { 301 } else {
298 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 302 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
299 } 303 }
300 } else { 304 } else {
@@ -591,110 +595,137 @@ ulong PhoneFormat::getCsum( const QStringList & attList)
591 for ( k = 0; k < j; ++k ) { 595 for ( k = 0; k < j; ++k ) {
592 int mul = k +1; 596 int mul = k +1;
593 add = s[k].unicode (); 597 add = s[k].unicode ();
594 if ( k < 16 ) 598 if ( k < 16 )
595 mul = mul * mul; 599 mul = mul * mul;
596 add = add * mul *i*i*i; 600 add = add * mul *i*i*i;
597 cSum += add; 601 cSum += add;
598 } 602 }
599 } 603 }
600 } 604 }
601 return cSum; 605 return cSum;
602 606
603} 607}
604//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 608//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
605#include <stdlib.h> 609#include <stdlib.h>
606#define DEBUGMODE false 610#define DEBUGMODE false
607bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) 611bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model )
608{ 612{
609 mProfileName = profileName; 613 mProfileName = profileName;
610 GSM_StateMachines; 614 GSM_StateMachines;
611 qDebug(" load "); 615 qDebug(" load ");
612 s.opened = false; 616 s.opened = false;
613 s.msg = NULL; 617 s.msg = NULL;
614 s.ConfigNum = 0; 618 s.ConfigNum = 0;
619#if 0
615 static char*cp; 620 static char*cp;
616 static INI_Section *cfg = NULL; 621 static INI_Section *cfg = NULL;
617 cfg=GSM_FindGammuRC(); 622 cfg=GSM_FindGammuRC();
618 int i; 623 int i;
619 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 624 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
620 if (cfg!=NULL) { 625 if (cfg!=NULL) {
621 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); 626 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
622 if (cp) di.coding = cp; 627 if (cp) di.coding = cp;
623 628
624 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); 629 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
625 if (s.Config[i].Localize) { 630 if (s.Config[i].Localize) {
626 s.msg=INI_ReadFile(s.Config[i].Localize, true); 631 s.msg=INI_ReadFile(s.Config[i].Localize, true);
627 } else { 632 } else {
628#if !defined(WIN32) && defined(LOCALE_PATH) 633#if !defined(WIN32) && defined(LOCALE_PATH)
629 locale = setlocale(LC_MESSAGES, NULL); 634 locale = setlocale(LC_MESSAGES, NULL);
630 if (locale != NULL) { 635 if (locale != NULL) {
631 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 636 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
632 LOCALE_PATH, 637 LOCALE_PATH,
633 tolower(locale[0]), 638 tolower(locale[0]),
634 tolower(locale[1])); 639 tolower(locale[1]));
635 s.msg = INI_ReadFile(locale_file, true); 640 s.msg = INI_ReadFile(locale_file, true);
636 } 641 }
637#endif 642#endif
638 } 643 }
639 } 644 }
640 645
641 /* Wanted user specific configuration? */ 646 /* Wanted user specific configuration? */
642 647
643 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 648 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
644 649
645 s.ConfigNum++; 650 s.ConfigNum++;
646 651
647 /* We want to use only one file descriptor for global and state machine debug output */ 652 /* We want to use only one file descriptor for global and state machine debug output */
648 s.Config[i].UseGlobalDebugFile = true; 653 s.Config[i].UseGlobalDebugFile = true;
649 654
650 655
651 656
652 /* We wanted to read just user specified configuration. */ 657 /* We wanted to read just user specified configuration. */
653 {break;} 658 {break;}
654 } 659 }
655 660
661#endif
662 setlocale(LC_ALL, "");
663 GSM_ReadConfig(NULL, &s.Config[0], 0);
664 s.ConfigNum = 1;
665 GSM_Config *cfg = &s.Config[0];
666 di.coding = "utf8";
667 if ( ! connection.isEmpty() ) {
668 cfg->Connection = strdup(connection.latin1());
669 cfg->DefaultConnection = false;
670 qDebug("Connection set %s ", cfg->Connection );
671
672 }
673 if ( ! device.isEmpty() ) {
674 cfg->Device = strdup(device.latin1());
675 cfg->DefaultDevice = false;
676 qDebug("Device set %s ", cfg->Device);
677
678 }
679 if ( ! model.isEmpty() ) {
680 strcpy(cfg->Model,model.latin1() );
681 cfg->DefaultModel = false;
682 qDebug("Model set %s ",cfg->Model );
683
684
685 }
656 int error=GSM_InitConnection(&s,3); 686 int error=GSM_InitConnection(&s,3);
657 qDebug(" init %d %d", error, ERR_NONE); 687 qDebug(" init %d %d", error, ERR_NONE);
658 if ( error != ERR_NONE ) 688 if ( error != ERR_NONE )
659 return false; 689 return false;
660 // fromString2Cal( calendar, existngCal, &s, "Event" ); 690 // fromString2Cal( calendar, existngCal, &s, "Event" );
661 GSM_Phone_Functions*Phone; 691 GSM_Phone_Functions*Phone;
662 GSM_CalendarEntrynote; 692 GSM_CalendarEntrynote;
663 bool refresh= true; 693 bool start = true;
664 Phone=s.Phone.Functions; 694 Phone=s.Phone.Functions;
665 bool gshutdown = false; 695 bool gshutdown = false;
666 PhoneParser handler( calendar, profileName ); 696 PhoneParser handler( calendar, profileName );
667 int ccc = 0; 697 int ccc = 0;
668 while (!gshutdown && ccc++ < 10 ) { 698 while (!gshutdown && ccc++ < 3) {
669 699
670 qDebug("readEvent %d ", ccc); 700 qDebug("readEvent %d ", ccc);
671 error=Phone->GetNextCalendar(&s,&note,refresh); 701 error=Phone->GetNextCalendar(&s,&note,start);
672 if (error == ERR_EMPTY) break; 702 if (error == ERR_EMPTY) break;
703 start = false;
673 handler.readEvent( existingCal, &note ); 704 handler.readEvent( existingCal, &note );
674 } 705 }
675 706
676 bool start = true; 707 start = true;
677 GSM_ToDoEntry ToDo; 708 GSM_ToDoEntry ToDo;
678 ccc = 0; 709 ccc = 0;
679 while (!gshutdown) { 710 while (!gshutdown) {
680 error = Phone->GetNextToDo(&s, &ToDo, start); 711 error = Phone->GetNextToDo(&s, &ToDo, start);
681 if (error == ERR_EMPTY) break; 712 if (error == ERR_EMPTY) break;
682 start = false; 713 start = false;
683 qDebug("readTodo %d ", ++ccc); 714 qDebug("readTodo %d ", ++ccc);
684 handler.readTodo( existingCal, &ToDo, &s); 715 handler.readTodo( existingCal, &ToDo, &s);
685 716
686 } 717 }
687 718
688 error=GSM_TerminateConnection(&s); 719 error=GSM_TerminateConnection(&s);
689 720
690 return true; 721 return true;
691} 722}
692 723
693bool PhoneFormat::save( Calendar *calendar) 724bool PhoneFormat::save( Calendar *calendar)
694{ 725{
695#if 0 726#if 0
696 QLabel status ( i18n("Processing/adding events ..."), 0 ); 727 QLabel status ( i18n("Processing/adding events ..."), 0 );
697 int w = status.sizeHint().width()+20 ; 728 int w = status.sizeHint().width()+20 ;
698 if ( w < 200 ) w = 200; 729 if ( w < 200 ) w = 200;
699 int h = status.sizeHint().height()+20 ; 730 int h = status.sizeHint().height()+20 ;
700 int dw = QApplication::desktop()->width(); 731 int dw = QApplication::desktop()->width();