-rw-r--r-- | gammu/emb/gammu/gammu.c | 47 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 6 |
2 files changed, 50 insertions, 3 deletions
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index 1d53fb0..5163d81 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c @@ -8121,236 +8121,281 @@ 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; } + 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 + +#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) { 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;} } - +#endif /* 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) { 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 0bc9125..2ad1b5a 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -159,423 +159,425 @@ ulong PhoneFormat::getCsumEvent( Event* event ) } } 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(); 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; int add; for ( i = 1; 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; cSum += add; } } } 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"; + QString command ="./kammu --backup " + fileName + " -yes -C" + + mConnection +" -D" + mDevice +" -M" + mModel; int ret = system ( command.latin1() ); if ( ret != 0 ) return false; VCalFormat vfload; vfload.setLocalTime ( true ); if ( ! vfload.load( calendar, fileName ) ) return false; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); while ( ev ) { 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(); } { 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 ) { 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(); 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(); 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()); } #include <qcstring.h> void PhoneFormat::afterSave( Incidence* inc) { uint csum; inc->removeID( mProfileName ); if ( inc->type() == "Event") csum = PhoneFormat::getCsumEvent( (Event*) inc ); else csum = PhoneFormat::getCsumTodo( (Todo*) inc ); inc->setCsum( mProfileName, QString::number( csum )); 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 ; + QString command ="./kammu --restore " + fileName + " -C" + + mConnection +" -D" + mDevice +" -M" + mModel;; int ret = system ( command.latin1() ); if ( ret != 0 ) 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 "); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString cSum = ev->getCsum(mProfileName); ev1 = er1.first(); while ( ev1 ) { if ( ev1->getCsum( mProfileName ) == cSum ) { er1.remove( ev1 ); afterSave( ev ); ev->setID(mProfileName, ev1->getID(mProfileName) ); 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 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); 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; } |