summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmcal.c4
-rw-r--r--gammu/emb/gammu/gammu.c6
-rw-r--r--libkcal/phoneformat.cpp42
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
@@ -453,54 +453,54 @@ GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_Calenda
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);
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
@@ -4606,48 +4606,49 @@ static void Restore(int argc, char *argv[])
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);
@@ -4657,58 +4658,62 @@ static void Restore(int argc, char *argv[])
} 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);
@@ -8353,49 +8358,48 @@ int main(int argc, char *argv[])
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 {
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6df639f..ef69bce 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -108,49 +108,52 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
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 ) {
@@ -233,86 +236,89 @@ ulong PhoneFormat::getCsumEvent( Event* event )
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 ) {
@@ -323,161 +329,172 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
}
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
@@ -485,50 +502,49 @@ bool PhoneFormat::save( Calendar *calendar)
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