-rw-r--r-- | gammu/emb/common/service/gsmcal.c | 2 | ||||
-rw-r--r-- | gammu/emb/gammu/gammu.c | 41 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 51 |
3 files changed, 79 insertions, 15 deletions
diff --git a/gammu/emb/common/service/gsmcal.c b/gammu/emb/common/service/gsmcal.c index 598292c..ddf9790 100644 --- a/gammu/emb/common/service/gsmcal.c +++ b/gammu/emb/common/service/gsmcal.c @@ -137,17 +137,17 @@ GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note if (EndTime != -1) { SaveVCALDateTime(Buffer, Length, ¬e->Entries[EndTime].Date, "DTEND"); } 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"); + SaveVCALDateTime(Buffer, Length, ¬e->Entries[Alarm].Date, "DALARM"); } } /* Birthday is known to be recurranced */ if (Recurrance != -1 && note->Type != GSM_CAL_BIRTHDAY) { switch(note->Entries[Recurrance].Number/24) { case 1 : *Length+=sprintf(Buffer+(*Length), "RRULE:D1 #0%c%c",13,10); break; case 7 : *Length+=sprintf(Buffer+(*Length), "RRULE:W1 #0%c%c",13,10); break; diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index 5163d81..a3b93a8 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c @@ -8236,21 +8236,22 @@ int main(int argc, char *argv[]) /* 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; - } - + //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); @@ -8264,17 +8265,17 @@ int main(int argc, char *argv[]) } 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 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()); @@ -8285,17 +8286,17 @@ int main(int argc, char *argv[]) if ( ! mModel.isEmpty() ) { strcpy(cfg->Model,mModel.latin1() ); cfg->DefaultModel = false; qDebug("Model set %s ",cfg->Model ); } #endif -#if 0 + 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) { @@ -8310,16 +8311,17 @@ int main(int argc, char *argv[]) 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++; @@ -8345,17 +8347,41 @@ int main(int argc, char *argv[]) /* 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 */ @@ -8364,16 +8390,17 @@ int main(int argc, char *argv[]) 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++; } diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 2ad1b5a..6df639f 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -30,16 +30,17 @@ #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" @@ -241,16 +242,18 @@ ulong PhoneFormat::getCsumEvent( Event* event ) } 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; ulong cSum = 0; int j,k,i; @@ -264,16 +267,19 @@ ulong PhoneFormat::getCsum( const QStringList & attList) add = s[k].unicode (); if ( k < 16 ) mul = mul * mul; add = add * mul *i*i*i; cSum += add; } } } + //QString dump = attList.join(","); + //qDebug("csum: %s", 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) { @@ -282,25 +288,35 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) #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; int ret = system ( command.latin1() ); - if ( ret != 0 ) + 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); @@ -310,16 +326,17 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 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() ); } @@ -485,20 +502,29 @@ bool PhoneFormat::save( Calendar *calendar) } // 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;; - int ret = system ( command.latin1() ); - if ( ret != 0 ) + mConnection +" -D" + mDevice +" -M" + mModel; + 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 "); @@ -510,49 +536,60 @@ bool PhoneFormat::save( Calendar *calendar) //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 "); + //qDebug("event new ID %s",ev->summary().latin1()); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); - QString cSum = ev->getCsum(mProfileName); + 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(); - QString cSum = to->getCsum(mProfileName); + 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; } |