author | zautrix <zautrix> | 2004-09-12 15:24:11 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 15:24:11 (UTC) |
commit | a222c2f7369eeefd19454c973c0cc48300f72bec (patch) (side-by-side diff) | |
tree | 6f01a5922ea622add6960f3fad703e8e8f099caa | |
parent | b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26 (diff) | |
download | kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.zip kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.tar.gz kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.tar.bz2 |
many phone sync fixes
-rw-r--r-- | gammu/emb/common/service/gsmcal.c | 4 | ||||
-rw-r--r-- | gammu/emb/gammu/gammu.c | 6 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 42 |
3 files changed, 36 insertions, 16 deletions
diff --git a/gammu/emb/common/service/gsmcal.c b/gammu/emb/common/service/gsmcal.c index ddf9790..0ea8e06 100644 --- a/gammu/emb/common/service/gsmcal.c +++ b/gammu/emb/common/service/gsmcal.c @@ -221,292 +221,292 @@ GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note break; case GSM_CAL_MEMO: default: *Length+=sprintf(Buffer+(*Length), "Miscellaneous%c%c",13,10); break; } if (Time == -1) return ERR_UNKNOWN; SaveVCALDateTime(Buffer, Length, ¬e->Entries[Time].Date, "DTSTART"); if (EndTime != -1) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[EndTime].Date, "DTEND"); } if (Alarm != -1) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[Alarm].Date, "AALARM"); } SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); if (Location != -1) { SaveVCALText(Buffer, Length, note->Entries[Location].Text, "LOCATION"); } } *Length+=sprintf(Buffer+(*Length), "X-PILOTID:%d%c%c",note->Location,13,10); *Length+=sprintf(Buffer+(*Length), "END:VEVENT%c%c",13,10); if (header) *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10); return ERR_NONE; } void GSM_ToDoFindDefaultTextTimeAlarmCompleted(GSM_ToDoEntry *entry, int *Text, int *Alarm, int *Completed, int *EndTime, int *Phone) { int i; *Text = -1; *EndTime = -1; *Alarm = -1; *Completed = -1; *Phone = -1; for (i = 0; i < entry->EntriesNum; i++) { switch (entry->Entries[i].EntryType) { case TODO_END_DATETIME : if (*EndTime == -1) *EndTime = i; break; case TODO_ALARM_DATETIME : case TODO_SILENT_ALARM_DATETIME: if (*Alarm == -1) *Alarm = i; break; case TODO_TEXT: if (*Text == -1) *Text = i; break; case TODO_COMPLETED: if (*Completed == -1) *Completed = i; break; case TODO_PHONE: if (*Phone == -1) *Phone = i; break; default: break; } } } GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool header, GSM_VToDoVersion Version) { int Text, Alarm, Completed, EndTime, Phone; GSM_ToDoFindDefaultTextTimeAlarmCompleted(note, &Text, &Alarm, &Completed, &EndTime, &Phone); if (header) { *Length+=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10); *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10); } *Length+=sprintf(Buffer+(*Length), "BEGIN:VTODO%c%c",13,10); if (Version == Nokia_VToDo) { if (Text == -1) return ERR_UNKNOWN; SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); if (Completed == -1) { *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10); } else { *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10); } switch (note->Priority) { case GSM_Priority_Low : *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break; case GSM_Priority_Medium: *Length+=sprintf(Buffer+(*Length), "PRIORITY:3%c%c",13,10); break; case GSM_Priority_High : *Length+=sprintf(Buffer+(*Length), "PRIORITY:1%c%c",13,10); break; } if (EndTime != -1) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[EndTime].Date, "DUE"); } if (Alarm != -1) { if (note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[Alarm].Date, "DALARM"); } else { SaveVCALDateTime(Buffer, Length, ¬e->Entries[Alarm].Date, "AALARM"); } } } else if (Version == SonyEricsson_VToDo) { if (Text == -1) return ERR_UNKNOWN; SaveVCALText(Buffer, Length, note->Entries[Text].Text, "SUMMARY"); if (Completed == -1) { *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:0%c%c",13,10); } else { *Length+=sprintf(Buffer+(*Length), "PERCENT-COMPLETE:100%c%c",13,10); } switch (note->Priority) { case GSM_Priority_Low : *Length+=sprintf(Buffer+(*Length), "PRIORITY:5%c%c",13,10); break; case GSM_Priority_Medium: *Length+=sprintf(Buffer+(*Length), "PRIORITY:3%c%c",13,10); break; case GSM_Priority_High : *Length+=sprintf(Buffer+(*Length), "PRIORITY:1%c%c",13,10); break; } if (Alarm != -1) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[Alarm].Date, "AALARM"); } } *Length+=sprintf(Buffer+(*Length), "X-PILOTID:%d%c%c",note->Location,13,10); *Length+=sprintf(Buffer+(*Length), "END:VTODO%c%c",13,10); if (header) { *Length+=sprintf(Buffer+(*Length), "END:VCALENDAR%c%c",13,10); } return ERR_NONE; } GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_CalendarEntry *Calendar, GSM_ToDoEntry *ToDo, GSM_VCalendarVersion CalVer, GSM_VToDoVersion ToDoVer) { unsigned char Line[2000],Buff[2000]; int Level = 0; Calendar->EntriesNum = 0; ToDo->EntriesNum = 0; while (1) { MyGetLine(Buffer, Pos, Line, strlen(Buffer)); if (strlen(Line) == 0) break; switch (Level) { case 0: if (strstr(Line,"BEGIN:VEVENT")) { Calendar->Type = GSM_CAL_MEMO; Level = 1; } if (strstr(Line,"BEGIN:VTODO")) { ToDo->Priority = GSM_Priority_Medium; Level = 2; } break; case 1: /* Calendar note */ if (strstr(Line,"END:VEVENT")) { if (Calendar->EntriesNum == 0) return ERR_EMPTY; return ERR_NONE; } Calendar->Type = GSM_CAL_MEETING; if (strstr(Line,"CATEGORIES:Reminder")) Calendar->Type = GSM_CAL_REMINDER; if (strstr(Line,"CATEGORIES:Date")) Calendar->Type = GSM_CAL_REMINDER;//SE if (strstr(Line,"CATEGORIES:Travel")) Calendar->Type = GSM_CAL_TRAVEL; //SE if (strstr(Line,"CATEGORIES:Vacation")) Calendar->Type = GSM_CAL_VACATION;//SE if (strstr(Line,"CATEGORIES:Miscellaneous")) Calendar->Type = GSM_CAL_MEMO; if (strstr(Line,"CATEGORIES:Phone Call")) Calendar->Type = GSM_CAL_CALL; if (strstr(Line,"CATEGORIES:Special Occasion")) Calendar->Type = GSM_CAL_BIRTHDAY; if (strstr(Line,"CATEGORIES:Anniversary")) Calendar->Type = GSM_CAL_BIRTHDAY; if (strstr(Line,"CATEGORIES:Meeting")) Calendar->Type = GSM_CAL_MEETING; if (strstr(Line,"CATEGORIES:Appointment")) Calendar->Type = GSM_CAL_MEETING; if (strstr(Line,"RRULE:D1")) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; Calendar->Entries[Calendar->EntriesNum].Number = 1*24; Calendar->EntriesNum++; } if ((strstr(Line,"RRULE:W1")) || (strstr(Line,"RRULE:D7"))) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; Calendar->Entries[Calendar->EntriesNum].Number = 7*24; Calendar->EntriesNum++; } if (strstr(Line,"RRULE:W2")) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; Calendar->Entries[Calendar->EntriesNum].Number = 14*24; Calendar->EntriesNum++; } if (strstr(Line,"RRULE:MD1")) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; Calendar->Entries[Calendar->EntriesNum].Number = 30*24; Calendar->EntriesNum++; } if (strstr(Line,"RRULE:YD1")) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_RECURRANCE; Calendar->Entries[Calendar->EntriesNum].Number = 365*24; Calendar->EntriesNum++; } if ((ReadVCALText(Line, "SUMMARY", Buff)) || (ReadVCALText(Line, "DESCRIPTION", Buff))) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_TEXT; CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); Calendar->EntriesNum++; } if (ReadVCALText(Line, "LOCATION", Buff)) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_LOCATION; CopyUnicodeString(Calendar->Entries[Calendar->EntriesNum].Text,Buff); Calendar->EntriesNum++; } if (ReadVCALText(Line, "DTSTART", Buff)) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_START_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); Calendar->EntriesNum++; } if (ReadVCALText(Line, "DTEND", Buff)) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_END_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); Calendar->EntriesNum++; } if (ReadVCALText(Line, "DALARM", Buff)) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); Calendar->EntriesNum++; } if (ReadVCALText(Line, "AALARM", Buff)) { Calendar->Entries[Calendar->EntriesNum].EntryType = CAL_ALARM_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &Calendar->Entries[Calendar->EntriesNum].Date); Calendar->EntriesNum++; } break; case 2: /* ToDo note */ if (strstr(Line,"END:VTODO")) { if (ToDo->EntriesNum == 0) return ERR_EMPTY; return ERR_NONE; } if (ReadVCALText(Line, "DUE", Buff)) { ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_END_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); ToDo->EntriesNum++; } if (ReadVCALText(Line, "DALARM", Buff)) { ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); ToDo->EntriesNum++; } if (ReadVCALText(Line, "AALARM", Buff)) { ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_ALARM_DATETIME; ReadVCALDateTime(DecodeUnicodeString(Buff), &ToDo->Entries[ToDo->EntriesNum].Date); ToDo->EntriesNum++; } if (ReadVCALText(Line, "SUMMARY", Buff)) { ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_TEXT; CopyUnicodeString(ToDo->Entries[ToDo->EntriesNum].Text,Buff); ToDo->EntriesNum++; } if (ReadVCALText(Line, "PRIORITY", Buff)) { if (ToDoVer == SonyEricsson_VToDo) { - ToDo->Priority = GSM_Priority_Low; + ToDo->Priority = GSM_Priority_Medium; if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; dbgprintf("atoi is %i %s\n",atoi(DecodeUnicodeString(Buff)),DecodeUnicodeString(Buff)); } else if (ToDoVer == Nokia_VToDo) { - ToDo->Priority = GSM_Priority_Low; + ToDo->Priority = GSM_Priority_Medium; if (atoi(DecodeUnicodeString(Buff))>3) ToDo->Priority = GSM_Priority_Low; if (atoi(DecodeUnicodeString(Buff))<3) ToDo->Priority = GSM_Priority_High; } } if (strstr(Line,"PERCENT-COMPLETE:100")) { ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_COMPLETED; ToDo->Entries[ToDo->EntriesNum].Number = 1; ToDo->EntriesNum++; } break; } } if (Calendar->EntriesNum == 0 && ToDo->EntriesNum == 0) return ERR_EMPTY; return ERR_NONE; } GSM_Error GSM_EncodeVNTFile(unsigned char *Buffer, int *Length, GSM_NoteEntry *Note) { *Length+=sprintf(Buffer+(*Length), "BEGIN:VNOTE%c%c",13,10); *Length+=sprintf(Buffer+(*Length), "VERSION:1.1%c%c",13,10); SaveVCALText(Buffer, Length, Note->Text, "BODY"); *Length+=sprintf(Buffer+(*Length), "END:VNOTE%c%c",13,10); return ERR_NONE; } /* How should editor hadle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index a3b93a8..997485a 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c @@ -4374,573 +4374,578 @@ static void Backup(int argc, char *argv[]) } } printmsgerr("\n"); } DoBackup = false; if (Info.Profiles) { printmsg("Checking phone profiles\n"); Profile.Location = 1; error = Phone->GetProfile(&s,&Profile); if (error == ERR_NONE) { if (answer_yes(" Backup phone profiles")) DoBackup = true; } } if (DoBackup) { used = 0; printmsgerr(" Reading: "); while (true) { Profile.Location = used + 1; error = Phone->GetProfile(&s,&Profile); if (error != ERR_NONE) break; if (used < GSM_BACKUP_MAX_PROFILES) { Backup.Profiles[used] = malloc(sizeof(GSM_Profile)); if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.Profiles[used + 1] = NULL; } else { printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES"); GSM_Terminate(); exit(-1); } *Backup.Profiles[used]=Profile; used++; printmsgerr("*"); } printmsgerr("\n"); } DoBackup = false; if (Info.FMStation) { printmsg("Checking FM stations\n"); FMStation.Location = 1; error = Phone->GetFMStation(&s,&FMStation); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes(" Backup phone FM stations")) DoBackup=true; } } if (DoBackup) { used = 0; i = 1; printmsgerr(" Reading: "); while (error == ERR_NONE || error == ERR_EMPTY) { error = Phone->GetFMStation(&s,&FMStation); if (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_FMSTATIONS) { Backup.FMStation[used] = malloc(sizeof(GSM_FMStation)); if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.FMStation[used + 1] = NULL; } else { printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS"); GSM_Terminate(); exit(-1); } *Backup.FMStation[used]=FMStation; used++; } i++; FMStation.Location = i; printmsgerr("*"); } printmsgerr("\n"); } DoBackup = false; if (Info.GPRSPoint) { printmsg("Checking GPRS access points\n"); GPRSPoint.Location = 1; error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes(" Backup GPRS access points")) DoBackup = true; } } if (DoBackup) { used = 0; i = 1; printmsgerr(" Reading: "); while (error == ERR_NONE || error == ERR_EMPTY) { error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); if (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_GPRSPOINT) { Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint)); if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.GPRSPoint[used + 1] = NULL; } else { printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT"); GSM_Terminate(); exit(-1); } *Backup.GPRSPoint[used]=GPRSPoint; used++; } i++; GPRSPoint.Location = i; printmsgerr("*"); } printmsgerr("\n"); } GSM_Terminate(); GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode); GSM_FreeBackup(&Backup); } static void Restore(int argc, char *argv[]) { GSM_Backup Backup; GSM_FMStation FMStation; GSM_DateTime date_time; GSM_CalendarEntry Calendar; GSM_Bitmap Bitmap; GSM_Ringtone Ringtone; GSM_MemoryEntry Pbk; GSM_MemoryStatus MemStatus; GSM_ToDoEntry ToDo; GSM_ToDoStatus ToDoStatus; GSM_Profile Profile; GSM_MultiWAPSettings Settings; GSM_GPRSAccessPoint GPRSPoint; GSM_WAPBookmark Bookmark; int i, used, max = 0; bool Past = true; bool Found, DoRestore; error=GSM_ReadBackupFile(argv[2],&Backup); Print_Error(error); signal(SIGINT, interrupt); printmsgerr("Press Ctrl+C to break...\n"); if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); if (Backup.MD5Calculated[0]!=0) { dbgprintf("\"%s\"\n",Backup.MD5Original); dbgprintf("\"%s\"\n",Backup.MD5Calculated); if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { if (!answer_yes("Checksum in backup file do not match. Continue")) return; } } GSM_Init(true); DoRestore = false; if (Backup.PhonePhonebook[0] != NULL) { MemStatus.MemoryType = MEM_ME; error=Phone->GetMemoryStatus(&s, &MemStatus); if (error==ERR_NONE) { max = 0; while (Backup.PhonePhonebook[max]!=NULL) max++; printmsgerr("%i entries in backup file\n",max); if (answer_yes("Restore phone phonebook")) DoRestore = true; } } if (DoRestore) { used = 0; for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { Pbk.MemoryType = MEM_ME; Pbk.Location = i + 1; Pbk.EntriesNum = 0; if (used<max) { if (Backup.PhonePhonebook[used]->Location == Pbk.Location) { Pbk = *Backup.PhonePhonebook[used]; used++; dbgprintf("Location %i\n",Pbk.Location); if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); } } if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.SIMPhonebook[0] != NULL) { MemStatus.MemoryType = MEM_SM; error=Phone->GetMemoryStatus(&s, &MemStatus); if (error==ERR_NONE) { max = 0; while (Backup.SIMPhonebook[max]!=NULL) max++; printmsgerr("%i entries in backup file\n",max); if (answer_yes("Restore SIM phonebook")) DoRestore = true; } } if (DoRestore) { used = 0; for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { Pbk.MemoryType = MEM_SM; Pbk.Location = i + 1; Pbk.EntriesNum = 0; if (used<max) { if (Backup.SIMPhonebook[used]->Location == Pbk.Location) { Pbk = *Backup.SIMPhonebook[used]; used++; dbgprintf("Location %i\n",Pbk.Location); if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); } } if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.CallerLogos[0] != NULL) { Bitmap.Type = GSM_CallerGroupLogo; Bitmap.Location = 1; error=Phone->GetBitmap(&s,&Bitmap); if (error == ERR_NONE) { if (answer_yes("Restore caller groups and logos")) DoRestore = true; } } if (DoRestore) { max = 0; while (Backup.CallerLogos[max]!=NULL) max++; for (i=0;i<max;i++) { error=Phone->SetBitmap(&s,Backup.CallerLogos[i]); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { if (/*answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/ true ) { GSM_GetCurrentDateTime(&date_time); error=Phone->SetDateTime(&s, &date_time); Print_Error(error); } } DoRestore = false; if (Backup.Calendar[0] != NULL) { + DoRestore = true; /* N6110 doesn't support getting calendar status */ error = Phone->GetNextCalendar(&s,&Calendar,true); if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { max = 0; while (Backup.Calendar[max] != NULL) max++; printmsgerr("%i entries in backup file\n",max); DoRestore = true; /* if (answer_yes("Restore calendar notes")) { Past = answer_yes("Restore notes from the past"); DoRestore = true; } */ } } if (DoRestore) { printmsgerr("Deleting old notes: "); error = Phone->DeleteAllCalendar(&s); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { while (1) { error = Phone->GetNextCalendar(&s,&Calendar,true); if (error != ERR_NONE) break; error = Phone->DeleteCalendar(&s,&Calendar); Print_Error(error); printmsgerr("*"); } printmsgerr("\n"); } else { printmsgerr("Done\n"); Print_Error(error); } for (i=0;i<max;i++) { if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; Calendar = *Backup.Calendar[i]; error=Phone->AddCalendar(&s,&Calendar); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.ToDo[0] != NULL) { error = Phone->GetToDoStatus(&s,&ToDoStatus); if (error == ERR_NONE) { + error == ERR_NOTSUPPORTED; + DoRestore = true; max = 0; while (Backup.ToDo[max]!=NULL) max++; printmsgerr("%i entries in backup file\n",max); /*if (answer_yes("Restore ToDo")) */DoRestore = true; } } if (DoRestore) { + if ( max > 0 ) { ToDo = *Backup.ToDo[0]; error = Phone->SetToDo(&s,&ToDo); + } } if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { printmsgerr("Deleting old ToDo: "); error=Phone->DeleteAllToDo(&s); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { while (1) { error = Phone->GetNextToDo(&s,&ToDo,true); if (error != ERR_NONE) break; error = Phone->DeleteToDo(&s,&ToDo); Print_Error(error); printmsgerr("*"); } printmsgerr("\n"); } else { printmsgerr("Done\n"); Print_Error(error); } for (i=0;i<max;i++) { ToDo = *Backup.ToDo[i]; ToDo.Location = 0; error=Phone->AddToDo(&s,&ToDo); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } else if (DoRestore) { /* At first delete entries, that were deleted */ used = 0; error = Phone->GetNextToDo(&s,&ToDo,true); while (error == ERR_NONE) { used++; Found = false; for (i=0;i<max;i++) { if (Backup.ToDo[i]->Location == ToDo.Location) { Found = true; break; } } if (!Found) { error=Phone->DeleteToDo(&s,&ToDo); Print_Error(error); } error = Phone->GetNextToDo(&s,&ToDo,false); printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); /* Now write modified/new entries */ for (i=0;i<max;i++) { ToDo = *Backup.ToDo[i]; error = Phone->SetToDo(&s,&ToDo); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) { max = 0; while (Backup.SMSC[max]!=NULL) max++; for (i=0;i<max;i++) { error=Phone->SetSMSC(&s,Backup.SMSC[i]); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) { error=Phone->SetBitmap(&s,Backup.StartupLogo); Print_Error(error); } if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) { error=Phone->SetBitmap(&s,Backup.OperatorLogo); Print_Error(error); } DoRestore = false; if (Backup.WAPBookmark[0] != NULL) { Bookmark.Location = 1; error = Phone->GetWAPBookmark(&s,&Bookmark); if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { if (answer_yes("Restore WAP bookmarks")) DoRestore = true; } } if (DoRestore) { printmsgerr("Deleting old bookmarks: "); /* One thing to explain: DCT4 phones seems to have bug here. * When delete for example first bookmark, phone change * numeration for getting frame, not for deleting. So, we try to * get 1'st bookmark. Inside frame is "correct" location. We use * it later */ while (error==ERR_NONE) { error = Phone->DeleteWAPBookmark(&s,&Bookmark); Bookmark.Location = 1; error = Phone->GetWAPBookmark(&s,&Bookmark); printmsgerr("*"); } printmsgerr("\n"); max = 0; while (Backup.WAPBookmark[max]!=NULL) max++; for (i=0;i<max;i++) { Bookmark = *Backup.WAPBookmark[i]; Bookmark.Location = 0; error=Phone->SetWAPBookmark(&s,&Bookmark); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.WAPSettings[0] != NULL) { Settings.Location = 1; error = Phone->GetWAPSettings(&s,&Settings); if (error == ERR_NONE) { if (answer_yes("Restore WAP settings")) DoRestore = true; } } if (DoRestore) { max = 0; while (Backup.WAPSettings[max]!=NULL) max++; for (i=0;i<max;i++) { error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.MMSSettings[0] != NULL) { Settings.Location = 1; error = Phone->GetMMSSettings(&s,&Settings); if (error == ERR_NONE) { if (answer_yes("Restore MMS settings")) DoRestore = true; } } if (DoRestore) { max = 0; while (Backup.MMSSettings[max]!=NULL) max++; for (i=0;i<max;i++) { error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.Ringtone[0] != NULL) { Ringtone.Location = 1; Ringtone.Format = 0; error = Phone->GetRingtone(&s,&Ringtone,false); if (error == ERR_NONE || error ==ERR_EMPTY) { if (Phone->DeleteUserRingtones != NOTSUPPORTED) { if (answer_yes("Delete all user ringtones")) DoRestore = true; } } } if (DoRestore) { printmsgerr("Deleting: "); error=Phone->DeleteUserRingtones(&s); Print_Error(error); printmsgerr("Done\n"); DoRestore = false; if (answer_yes("Restore user ringtones")) DoRestore = true; } if (DoRestore) { max = 0; while (Backup.Ringtone[max]!=NULL) max++; for (i=0;i<max;i++) { error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format); Print_Error(error); error=Phone->SetRingtone(&s,&Ringtone,&i); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.Profiles[0] != NULL) { Profile.Location = 1; error = Phone->GetProfile(&s,&Profile); if (error == ERR_NONE) { if (answer_yes("Restore profiles")) DoRestore = true; } } if (DoRestore) { Profile.Location= 0; max = 0; while (Backup.Profiles[max]!=NULL) max++; for (i=0;i<max;i++) { Profile = *Backup.Profiles[i]; error=Phone->SetProfile(&s,&Profile); Print_Error(error); if (gshutdown) { GSM_Terminate(); exit(0); } } printmsgerr("\n"); } DoRestore = false; if (Backup.FMStation[0] != NULL) { FMStation.Location = 1; error = Phone->GetFMStation(&s,&FMStation); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes("Restore FM stations")) DoRestore = true; } } if (DoRestore) { printmsgerr("Deleting old FM stations: "); error=Phone->ClearFMStations(&s); Print_Error(error); printmsgerr("Done\n"); max = 0; while (Backup.FMStation[max]!=NULL) max++; for (i=0;i<max;i++) { FMStation = *Backup.FMStation[i]; error=Phone->SetFMStation(&s,&FMStation); Print_Error(error); printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); if (gshutdown) { GSM_Terminate(); exit(0); } @@ -8121,308 +8126,307 @@ static void Help(int argc, char *argv[]) /* Just --help */ if (argc == 2) { HelpGeneral(); return; } if (!strcmp(argv[2],"all")) { HelpHeader(); } else { while (HelpDescriptions[i].category != 0) { if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; i++; } if (HelpDescriptions[i].category == 0) { HelpGeneral(); printmsg("Unknown help topic specified!\n"); return; } HelpHeader(); printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); } #if defined(WIN32) || defined(DJGPP) cols = 80; #else cols = 0; /* If stdout is a tty, we will wrap to columns it has */ if (isatty(1)) { #ifdef TIOCGWINSZ if (ioctl(2, TIOCGWINSZ, &w) == 0) { if (w.ws_col > 0) cols = w.ws_col; } #endif if (cols == 0) { columns = getenv("COLUMNS"); if (columns != NULL) { cols = atoi(columns); if (cols <= 0) cols = 0; } } if (cols == 0) { /* Fallback */ cols = 80; } } #endif while (Parameters[j].Function != NULL) { k = 0; disp = false; if (!strcmp(argv[2],"all")) { if (j==0) disp = true; if (j!=0) { if (strcmp(Parameters[j].help,Parameters[j-1].help)) { disp = true; } else { if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { disp = true; } } } } else { while (Parameters[j].help_cat[k] != 0) { if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { disp = true; break; } k++; } } if (disp) { printf("%s", Parameters[j].parameter); if (Parameters[j].help[0] == 0) { printf("\n"); } else { HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); } } j++; } } #if 0 #endif // 0 int main(int argc, char *argv[]) { //fprintf(stderr,"HIIIIIIIIIIIII \n"); //#if 0 static int z ,start,i; static int only_config ; #if !defined(WIN32) && defined(LOCALE_PATH) static char *locale, locale_file[201]; #endif static char *cp; static bool count_failed; z = 0; start=0;only_config = -1;count_failed = false; s.opened = false; s.msg = NULL; s.ConfigNum = 0; setlocale(LC_ALL, ""); #ifdef DEBUG di.dl = DL_TEXTALL; di.df = stdout; #endif //#if 0 /* Any parameters? */ if (argc == 1) { HelpGeneral(); printmsg("Too few parameters!\n"); exit(1); } /* Help? */ if (strncmp(argv[1 + start], "--help", 6) == 0) { Help(argc - start, argv + start); exit(1); } /* Is first parameter numeric? If so treat it as config that should be loaded. */ //if (isdigit(argv[1][0])) { //only_config = atoi(argv[1]); //if (only_config >= 0) start++; else only_config = -1; //} only_config = 0;; #if 0 GSM_ReadConfig(NULL, &s.Config[0], 0); s.ConfigNum = 1; GSM_Config *con = &s.Config[0]; char* tempC; tempC = argv[argc-1]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using model %s \n",tempC); strcpy(con->Model,tempC ); } tempC = argv[argc-2]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using device %s \n",tempC); con->Device = strdup(tempC); con->DefaultDevice = false; } tempC = argv[argc-3]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using connection %s \n",tempC); con->Connection = strdup(tempC); con->DefaultConnection = false; } argc = argc-3; //#if 0 if ( ! mConnection.isEmpty() ) { cfg->Connection = strdup(mConnection.latin1()); cfg->DefaultConnection = false; qDebug("Connection set %s ", cfg->Connection ); } if ( ! mDevice.isEmpty() ) { cfg->Device = strdup(mDevice.latin1()); cfg->DefaultDevice = false; qDebug("Device set %s ", cfg->Device); } if ( ! mModel.isEmpty() ) { strcpy(cfg->Model,mModel.latin1() ); cfg->DefaultModel = false; qDebug("Model set %s ",cfg->Model ); } #endif cfg=GSM_FindGammuRC(); for (i = 0; i <= MAX_CONFIG_NUM; i++) { if (cfg!=NULL) { cp = INI_GetValue(cfg, "gammu", "gammucoding", false); if (cp) di.coding = cp; s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); if (s.Config[i].Localize) { s.msg=INI_ReadFile(s.Config[i].Localize, true); } else { #if !defined(WIN32) && defined(LOCALE_PATH) locale = setlocale(LC_MESSAGES, NULL); if (locale != NULL) { snprintf(locale_file, 200, "%s/gammu_%c%c.txt", LOCALE_PATH, tolower(locale[0]), tolower(locale[1])); s.msg = INI_ReadFile(locale_file, true); } #endif } } /* Wanted user specific configuration? */ if (only_config != -1) { /* Here we get only in first for loop */ if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; } else { if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; } s.ConfigNum++; /* We want to use only one file descriptor for global and state machine debug output */ s.Config[i].UseGlobalDebugFile = true; /* It makes no sense to open several debug logs... */ if (i != 0) { strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); free(s.Config[i].DebugFile); s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); } else { /* Just for first config */ /* When user gave debug level on command line */ if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { /* Debug level from command line will be used with phone too */ strcpy(s.Config[i].DebugLevel,argv[1 + start]); start++; } else { /* Try to set debug level from config file */ GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); } /* If user gave debug file in gammurc, we will use it */ error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); Print_Error(error); } /* We wanted to read just user specified configuration. */ if (only_config != -1) {break;} } #if 0 GSM_Config *con = &s.Config[0]; char* tempC; tempC = argv[argc-1]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using model %s \n",tempC); strcpy(con->Model,tempC ); } tempC = argv[argc-2]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using device %s \n",tempC); con->Device = strdup(tempC); con->DefaultDevice = false; } tempC = argv[argc-3]+2; if ( *tempC != 0 ) { fprintf(stderr,"Using connection %s \n",tempC); con->Connection = strdup(tempC); con->DefaultConnection = false; } #endif - argc = argc-3; /* Do we have enough parameters? */ if (argc == 1 + start) { HelpGeneral(); printmsg("Too few parameters!\n"); exit(-2); } /* Check used version vs. compiled */ if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", GetGammuVersion(),VERSION); exit(-1); } /* Check parameters */ while (Parameters[z].Function != NULL) { if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { fprintf(stderr,"Executing \n"); Parameters[z].Function(argc - start, argv + start); break; } else { count_failed = true; } } z++; } /* Tell user when we did nothing */ if (Parameters[z].Function == NULL) { HelpGeneral(); if (count_failed) { printmsg("Bad parameter count!\n"); } else { printmsg("Bad option!\n"); } } /* Close debug output if opened */ if (di.df!=stdout) fclose(di.df); //#endif // 0 fprintf(stderr,"kammu: Success. End. \n"); exit(0); } /* How should editor hadle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6df639f..ef69bce 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -1,620 +1,636 @@ /* This file is part of libkcal. Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qdatetime.h> #include <qstring.h> #include <qapplication.h> #include <qptrlist.h> #include <qregexp.h> #include <qmessagebox.h> #include <qclipboard.h> #include <qfile.h> #include <qtextstream.h> #include <qtextcodec.h> #include <qxml.h> #include <qlabel.h> #include <kdebug.h> #include <klocale.h> #include <kglobal.h> #include <kmessagebox.h> #include "calendar.h" #include "alarm.h" #include "recurrence.h" #include "calendarlocal.h" #include "phoneformat.h" #include "syncdefines.h" using namespace KCal; class PhoneParser : public QObject { public: PhoneParser( ) { ; } static QString dtToString( const QDateTime& dti, bool useTZ = false ) { QString datestr; QString timestr; int offset = KGlobal::locale()->localTimeOffset( dti ); QDateTime dt; if (useTZ) dt = dti.addSecs ( -(offset*60)); else dt = dti; if(dt.date().isValid()){ const QDate& date = dt.date(); datestr.sprintf("%04d%02d%02d", date.year(), date.month(), date.day()); } if(dt.time().isValid()){ const QTime& time = dt.time(); timestr.sprintf("T%02d%02d%02d", time.hour(), time.minute(), time.second()); } return datestr + timestr; } }; PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) { mProfileName = profileName; mDevice = device; mConnection = connection; mModel = model; } PhoneFormat::~PhoneFormat() { } #if 0 int PhoneFormat::initDevice(GSM_StateMachine *s) { GSM_ReadConfig(NULL, &s->Config[0], 0); s->ConfigNum = 1; GSM_Config *cfg = &s->Config[0]; if ( ! mConnection.isEmpty() ) { cfg->Connection = strdup(mConnection.latin1()); cfg->DefaultConnection = false; qDebug("Connection set %s ", cfg->Connection ); } if ( ! mDevice.isEmpty() ) { cfg->Device = strdup(mDevice.latin1()); cfg->DefaultDevice = false; qDebug("Device set %s ", cfg->Device); } if ( ! mModel.isEmpty() ) { strcpy(cfg->Model,mModel.latin1() ); cfg->DefaultModel = false; qDebug("Model set %s ",cfg->Model ); } int error=GSM_InitConnection(s,3); return error; } #endif ulong PhoneFormat::getCsumTodo( Todo* todo ) { QStringList attList; if ( todo->hasDueDate() ) attList << PhoneParser::dtToString ( todo->dtDue() ); attList << todo->summary(); QString completedString = "no"; if ( todo->isCompleted() ) completedString = "yes"; attList << completedString; - attList << QString::number( todo->priority() ); + int prio = todo->priority(); + if( prio == 2 ) prio = 1; + if (prio == 4 ) prio = 5 ; + attList << QString::number( prio ); QString alarmString = "na"; Alarm *alarm; if ( todo->alarms().count() > 0 ) { alarm = todo->alarms().first(); if ( alarm->enabled() ) { alarmString = QString::number(alarm->startOffset().asSeconds() ); } } attList << alarmString; attList << todo->categoriesStr(); attList << todo->secrecyStr(); return PhoneFormat::getCsum(attList ); } ulong PhoneFormat::getCsumEvent( Event* event ) { QStringList attList; attList << PhoneParser::dtToString ( event->dtStart() ); attList << PhoneParser::dtToString ( event->dtEnd() ); attList << event->summary(); attList << event->location(); QString alarmString = "na"; Alarm *alarm; if ( event->alarms().count() > 0 ) { alarm = event->alarms().first(); if ( alarm->enabled() ) { alarmString = QString::number( alarm->startOffset().asSeconds() ); } } attList << alarmString; Recurrence* rec = event->recurrence(); QStringList list; bool writeEndDate = false; switch ( rec->doesRecur() ) { case Recurrence::rDaily: // 0 list.append( "0" ); list.append( QString::number( rec->frequency() ));//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; case Recurrence::rWeekly:// 1 list.append( "1" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); { int days = 0; QBitArray weekDays = rec->days(); int i; for( i = 1; i <= 7; ++i ) { if ( weekDays[i-1] ) { days += 1 << (i-1); } } list.append( QString::number( days ) ); } //pending weekdays writeEndDate = true; break; case Recurrence::rMonthlyPos:// 2 list.append( "2" ); list.append( QString::number( rec->frequency()) );//12 writeEndDate = true; { int count = 1; QPtrList<Recurrence::rMonthPos> rmp; rmp = rec->monthPositions(); if ( rmp.first()->negative ) count = 5 - rmp.first()->rPos - 1; else count = rmp.first()->rPos - 1; list.append( QString::number( count ) ); } list.append( "0" ); break; case Recurrence::rMonthlyDay:// 3 list.append( "3" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; case Recurrence::rYearlyMonth://4 list.append( "4" ); list.append( QString::number( rec->frequency()) );//12 list.append( "0" ); list.append( "0" ); writeEndDate = true; break; default: list.append( "255" ); list.append( QString() ); list.append( "0" ); list.append( QString() ); list.append( "0" ); list.append( "20991231T000000" ); break; } if ( writeEndDate ) { if ( rec->endDate().isValid() ) { // 15 + 16 list.append( "1" ); list.append( PhoneParser::dtToString( rec->endDate()) ); } else { list.append( "0" ); list.append( "20991231T000000" ); } } attList << list.join(""); attList << event->categoriesStr(); //qDebug("csum cat %s", event->categoriesStr().latin1()); attList << event->secrecyStr(); return PhoneFormat::getCsum(attList ); } ulong PhoneFormat::getCsum( const QStringList & attList) { - int max = attList.count() -1; + int max = attList.count(); ulong cSum = 0; int j,k,i; int add; - for ( i = 1; i < max ; ++i ) { + for ( i = 0; i < max ; ++i ) { QString s = attList[i]; if ( ! s.isEmpty() ){ j = s.length(); for ( k = 0; k < j; ++k ) { int mul = k +1; add = s[k].unicode (); if ( k < 16 ) mul = mul * mul; - add = add * mul *i*i*i; + int ii = i+1; + add = add * mul *ii*ii*ii; cSum += add; } } + if ( i == 0 ) + qDebug("csum: i == 0 %d ", cSum); + } - //QString dump = attList.join(","); - //qDebug("csum: %s", dump.latin1()); + QString dump = attList.join(","); + qDebug("csum: %d %s", cSum,dump.latin1()); return cSum; } //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); #include <stdlib.h> #define DEBUGMODE false bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) { QString fileName; #ifdef _WIN32_ fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; #else fileName = "/tmp/kdepimtemp.vcs"; #endif - QString command ="./kammu --backup " + fileName + " -yes -C" + - mConnection +" -D" + mDevice +" -M" + mModel; + QString command ="./kammu --backup " + fileName + " -yes" ; int ret = system ( command.latin1() ); if ( ret != 0 ) { qDebug("Error::command returned %d", ret); return false; } qDebug("Command returned %d", ret); VCalFormat vfload; vfload.setLocalTime ( true ); qDebug("loading file ..."); if ( ! vfload.load( calendar, fileName ) ) return false; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); qDebug("reading events... "); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); } int id = ev->pilotId(); Event *event; event = existingCal->event( mProfileName ,QString::number( id ) ); if ( event ) { event = (Event*)event->clone(); copyEvent( event, ev ); calendar->deleteEvent( ev ); calendar->addEvent( event); } else event = ev; uint cSum; cSum = PhoneFormat::getCsumEvent( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setID( mProfileName,QString::number( id ) ); ev = er.next(); } { qDebug("reading todos... "); QPtrList<Todo> tr = calendar->rawTodos(); Todo* ev = tr.first(); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); } int id = ev->pilotId(); Todo *event; event = existingCal->todo( mProfileName ,QString::number( id ) ); if ( event ) { + qDebug("copy todo %s ", event->summary().latin1()); + event = (Todo*)event->clone(); copyTodo( event, ev ); calendar->deleteTodo( ev ); calendar->addTodo( event); } else event = ev; uint cSum; cSum = PhoneFormat::getCsumTodo( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setID( mProfileName,QString::number( id ) ); ev = tr.next(); } } return true; } void PhoneFormat::copyEvent( Event* to, Event* from ) { if ( from->dtStart().isValid() ) to->setDtStart( from->dtStart() ); if ( from->dtEnd().isValid() ) to->setDtEnd( from->dtEnd() ); if ( !from->location().isEmpty() ) to->setLocation( from->location() ); if ( !from->description().isEmpty() ) to->setDescription( from->description() ); if ( !from->summary().isEmpty() ) to->setSummary( from->summary() ); QPtrListIterator<Alarm> it( from->alarms() ); - to->clearAlarms(); + if ( it.current() ) + to->clearAlarms(); const Alarm *a; while( (a = it.current()) ) { Alarm *b = new Alarm( *a ); b->setParent( to ); to->addAlarm( b ); ++it; } QStringList cat = to->categories(); QStringList catFrom = from->categories(); QString nCat; int iii; for ( iii = 0; iii < catFrom.count();++iii ) { nCat = catFrom[iii]; if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { cat << nCat; } } to->setCategories( cat ); Recurrence * r = new Recurrence( *from->recurrence(),to); to->setRecurrence( r ) ; } void PhoneFormat::copyTodo( Todo* to, Todo* from ) { if ( from->dtStart().isValid() ) to->setDtStart( from->dtStart() ); if ( from->dtDue().isValid() ) to->setDtDue( from->dtDue() ); if ( !from->location().isEmpty() ) to->setLocation( from->location() ); if ( !from->description().isEmpty() ) to->setDescription( from->description() ); if ( !from->summary().isEmpty() ) to->setSummary( from->summary() ); QPtrListIterator<Alarm> it( from->alarms() ); - to->clearAlarms(); + if ( it.current() ) + to->clearAlarms(); const Alarm *a; while( (a = it.current()) ) { Alarm *b = new Alarm( *a ); b->setParent( to ); to->addAlarm( b ); ++it; } QStringList cat = to->categories(); QStringList catFrom = from->categories(); QString nCat; int iii; for ( iii = 0; iii < catFrom.count();++iii ) { nCat = catFrom[iii]; if ( !nCat.isEmpty() ) if ( !cat.contains( nCat )) { cat << nCat; } } to->setCategories( cat ); if ( from->isCompleted() ) { to->setCompleted( true ); if( from->completed().isValid() ) to->setCompleted( from->completed() ); } else { // set percentcomplete only, if to->isCompleted() if ( to->isCompleted() ) to->setPercentComplete(from->percentComplete()); } - to->setPriority(from->priority()); + if( to->priority() == 2 && from->priority() == 1 ) + ; //skip + else if (to->priority() == 4 && from->priority() == 5 ) + ; + else + to->setPriority(from->priority()); } #include <qcstring.h> void PhoneFormat::afterSave( Incidence* inc) { uint csum; inc->removeID( mProfileName ); +#if 0 if ( inc->type() == "Event") csum = PhoneFormat::getCsumEvent( (Event*) inc ); else csum = PhoneFormat::getCsumTodo( (Todo*) inc ); inc->setCsum( mProfileName, QString::number( csum )); +#endif inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); } bool PhoneFormat::save( Calendar *calendar) { QLabel status ( i18n(" Opening device ..."), 0 ); int w = status.sizeHint().width()+20 ; if ( w < 200 ) w = 230; int h = status.sizeHint().height()+20 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); status.setCaption(i18n("Writing to phone...") ); status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); status.show(); status.raise(); qApp->processEvents(); QString message; #ifdef _WIN32_ QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; #else QString fileName = "/tmp/kdepimtemp.vcs"; #endif // 1 remove events which should be deleted QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); while ( ev ) { if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { calendar->deleteEvent( ev ); } else { } ev = er.next(); } // 2 remove todos which should be deleted QPtrList<Todo> tl = calendar->rawTodos(); Todo* to = tl.first(); while ( to ) { if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { calendar->deleteTodo( to ); } to = tl.next(); } // 3 save file VCalFormat vfsave; vfsave.setLocalTime ( true ); if ( ! vfsave.save( calendar, fileName ) ) return false; // 4 call kammu - QString command ="./kammu --restore " + fileName + " -C" + - mConnection +" -D" + mDevice +" -M" + mModel; + QString command ="./kammu --restore " + fileName ; int ret; while ( (ret = system ( command.latin1())) != 0 ) { qDebug("Error S::command returned %d. asking users", ret); int retval = KMessageBox::warningContinueCancel(0, i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); if ( retval != KMessageBox::Continue ) return false; } if ( ret != 0 ) { qDebug("Error S::command returned %d", ret); return false; } // 5 reread data message = i18n(" Rereading all data ... "); status.setText ( message ); qApp->processEvents(); CalendarLocal* calendarTemp = new CalendarLocal(); calendarTemp->setTimeZoneId( calendar->timeZoneId()); if ( ! load( calendarTemp,calendar) ){ qDebug("error reloading calendar "); delete calendarTemp; return false; } // 6 compare data //algo 6 compare event er = calendar->rawEvents(); ev = er.first(); message = i18n(" Comparing event # "); QPtrList<Event> er1 = calendarTemp->rawEvents(); Event* ev1; int procCount = 0; while ( ev ) { //qDebug("event new ID %s",ev->summary().latin1()); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); uint csum; csum = PhoneFormat::getCsumEvent( ev ); QString cSum = QString::number( csum ); ev->setCsum( mProfileName, cSum ); //qDebug("Event cSum %s ", cSum.latin1()); ev1 = er1.first(); while ( ev1 ) { if ( ev1->getCsum( mProfileName ) == cSum ) { er1.remove( ev1 ); afterSave( ev ); ev->setID(mProfileName, ev1->getID(mProfileName) ); //qDebug("Event found on phone for %s ", ev->summary().latin1()); break; } ev1 = er1.next(); } if ( ! ev1 ) { ev->removeID(mProfileName); qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); } ev = er.next(); } //algo 6 compare todo tl = calendar->rawTodos(); to = tl.first(); procCount = 0; QPtrList<Todo> tl1 = calendarTemp->rawTodos(); Todo* to1 ; message = i18n(" Comparing todo # "); while ( to ) { qDebug("todo2 %d ", procCount); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); uint csum; csum = PhoneFormat::getCsumTodo( to ); QString cSum = QString::number( csum ); to->setCsum( mProfileName, cSum ); qDebug("Todo cSum %s ", cSum.latin1()); Todo* to1 = tl1.first(); while ( to1 ) { if ( to1->getCsum( mProfileName ) == cSum ) { tl1.remove( to1 ); afterSave( to ); to->setID(mProfileName, to1->getID(mProfileName) ); break; } to1 = tl1.next(); } if ( ! to1 ) { to->removeID(mProfileName); qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); } to = tl.next(); } delete calendarTemp; return true; } QString PhoneFormat::toString( Calendar * ) { return QString::null; } bool PhoneFormat::fromString( Calendar *calendar, const QString & text) { return false; } |