-rw-r--r-- | libkcal/phoneformat.cpp | 68 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 2 |
2 files changed, 44 insertions, 26 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 29c1ae6..b2a62b1 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -81,14 +81,25 @@ public: | |||
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
85 | { | 85 | { |
86 | mProfileName = profileName; | 86 | mProfileName = profileName; |
87 | 87 | writeConfig( device, connection, model ); | |
88 | } | ||
89 | |||
90 | PhoneFormat::~PhoneFormat() | ||
91 | { | ||
92 | } | ||
93 | void PhoneFormat::writeConfig( QString device, QString connection, QString model ) | ||
94 | { | ||
95 | #ifdef _WIN32_ | ||
96 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; | ||
97 | #else | ||
88 | QString fileName = QDir::homeDirPath() +"/.gammurc"; | 98 | QString fileName = QDir::homeDirPath() +"/.gammurc"; |
99 | #endif | ||
89 | //qDebug("save %d ", load ); | 100 | //qDebug("save %d ", load ); |
90 | QString content; | 101 | QString content; |
91 | bool write = false; | 102 | bool write = false; |
92 | bool addPort = true, addConnection = true, addModel = true; | 103 | bool addPort = true, addConnection = true, addModel = true; |
93 | QFile file( fileName ); | 104 | QFile file( fileName ); |
94 | if ( QFile::exists( fileName) ) { | 105 | if ( QFile::exists( fileName) ) { |
@@ -173,16 +184,13 @@ PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, | |||
173 | } | 184 | } |
174 | qDebug("Writing file %s ", fileName.latin1() ); | 185 | qDebug("Writing file %s ", fileName.latin1() ); |
175 | QTextStream ts( &file ); | 186 | QTextStream ts( &file ); |
176 | ts << content ; | 187 | ts << content ; |
177 | file.close(); | 188 | file.close(); |
178 | } | 189 | } |
179 | } | ||
180 | 190 | ||
181 | PhoneFormat::~PhoneFormat() | ||
182 | { | ||
183 | } | 191 | } |
184 | #if 0 | 192 | #if 0 |
185 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 193 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
186 | { | 194 | { |
187 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 195 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
188 | s->ConfigNum = 1; | 196 | s->ConfigNum = 1; |
@@ -566,12 +574,41 @@ void PhoneFormat::afterSave( Incidence* inc) | |||
566 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 574 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
567 | inc->setCsum( mProfileName, QString::number( csum )); | 575 | inc->setCsum( mProfileName, QString::number( csum )); |
568 | 576 | ||
569 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 577 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
570 | 578 | ||
571 | } | 579 | } |
580 | |||
581 | bool PhoneFormat::writeToPhone( Calendar * calendar) | ||
582 | { | ||
583 | #ifdef _WIN32_ | ||
584 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | ||
585 | #else | ||
586 | QString fileName = "/tmp/kdepimtemp.vcs"; | ||
587 | #endif | ||
588 | |||
589 | VCalFormat vfsave; | ||
590 | vfsave.setLocalTime ( true ); | ||
591 | if ( ! vfsave.save( calendar, fileName ) ) | ||
592 | return false; | ||
593 | // 4 call kammu | ||
594 | #ifdef DESKTOP_VERSION | ||
595 | QString command ="./kammu --restore " + fileName ; | ||
596 | #else | ||
597 | QString command ="kammu --restore " + fileName ; | ||
598 | #endif | ||
599 | int ret; | ||
600 | while ( (ret = system ( command.latin1())) != 0 ) { | ||
601 | qDebug("Error S::command returned %d. asking users", ret); | ||
602 | int retval = KMessageBox::warningContinueCancel(0, | ||
603 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); | ||
604 | if ( retval != KMessageBox::Continue ) | ||
605 | return false; | ||
606 | } | ||
607 | return true; | ||
608 | } | ||
572 | bool PhoneFormat::save( Calendar *calendar) | 609 | bool PhoneFormat::save( Calendar *calendar) |
573 | { | 610 | { |
574 | QLabel status ( i18n(" Opening device ..."), 0 ); | 611 | QLabel status ( i18n(" Opening device ..."), 0 ); |
575 | int w = status.sizeHint().width()+20 ; | 612 | int w = status.sizeHint().width()+20 ; |
576 | if ( w < 200 ) w = 230; | 613 | if ( w < 200 ) w = 230; |
577 | int h = status.sizeHint().height()+20 ; | 614 | int h = status.sizeHint().height()+20 ; |
@@ -580,17 +617,12 @@ bool PhoneFormat::save( Calendar *calendar) | |||
580 | status.setCaption(i18n("Writing to phone...") ); | 617 | status.setCaption(i18n("Writing to phone...") ); |
581 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 618 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
582 | status.show(); | 619 | status.show(); |
583 | status.raise(); | 620 | status.raise(); |
584 | qApp->processEvents(); | 621 | qApp->processEvents(); |
585 | QString message; | 622 | QString message; |
586 | #ifdef _WIN32_ | ||
587 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | ||
588 | #else | ||
589 | QString fileName = "/tmp/kdepimtemp.vcs"; | ||
590 | #endif | ||
591 | 623 | ||
592 | // 1 remove events which should be deleted | 624 | // 1 remove events which should be deleted |
593 | QPtrList<Event> er = calendar->rawEvents(); | 625 | QPtrList<Event> er = calendar->rawEvents(); |
594 | Event* ev = er.first(); | 626 | Event* ev = er.first(); |
595 | while ( ev ) { | 627 | while ( ev ) { |
596 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 628 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
@@ -611,30 +643,14 @@ bool PhoneFormat::save( Calendar *calendar) | |||
611 | calendar->deleteTodo( to ); | 643 | calendar->deleteTodo( to ); |
612 | } | 644 | } |
613 | } | 645 | } |
614 | to = tl.next(); | 646 | to = tl.next(); |
615 | } | 647 | } |
616 | // 3 save file | 648 | // 3 save file |
617 | VCalFormat vfsave; | 649 | if ( !writeToPhone( calendar ) ) |
618 | vfsave.setLocalTime ( true ); | ||
619 | if ( ! vfsave.save( calendar, fileName ) ) | ||
620 | return false; | 650 | return false; |
621 | // 4 call kammu | ||
622 | #ifdef DESKTOP_VERSION | ||
623 | QString command ="./kammu --restore " + fileName ; | ||
624 | #else | ||
625 | QString command ="kammu --restore " + fileName ; | ||
626 | #endif | ||
627 | int ret; | ||
628 | while ( (ret = system ( command.latin1())) != 0 ) { | ||
629 | qDebug("Error S::command returned %d. asking users", ret); | ||
630 | int retval = KMessageBox::warningContinueCancel(0, | ||
631 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); | ||
632 | if ( retval != KMessageBox::Continue ) | ||
633 | return false; | ||
634 | } | ||
635 | 651 | ||
636 | // 5 reread data | 652 | // 5 reread data |
637 | message = i18n(" Rereading all data ... "); | 653 | message = i18n(" Rereading all data ... "); |
638 | status.setText ( message ); | 654 | status.setText ( message ); |
639 | qApp->processEvents(); | 655 | qApp->processEvents(); |
640 | CalendarLocal* calendarTemp = new CalendarLocal(); | 656 | CalendarLocal* calendarTemp = new CalendarLocal(); |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 2d1ff79..61e8160 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -45,12 +45,14 @@ class PhoneFormat : public QObject { | |||
45 | bool save( Calendar * ); | 45 | bool save( Calendar * ); |
46 | bool fromString( Calendar *, const QString & ); | 46 | bool fromString( Calendar *, const QString & ); |
47 | QString toString( Calendar * ); | 47 | QString toString( Calendar * ); |
48 | static ulong getCsum( const QStringList & ); | 48 | static ulong getCsum( const QStringList & ); |
49 | static ulong getCsumTodo( Todo* to ); | 49 | static ulong getCsumTodo( Todo* to ); |
50 | static ulong getCsumEvent( Event* ev ); | 50 | static ulong getCsumEvent( Event* ev ); |
51 | static void writeConfig( QString device,QString connection, QString model ); | ||
52 | static bool writeToPhone( Calendar * ); | ||
51 | private: | 53 | private: |
52 | void copyEvent( Event* to, Event* from ); | 54 | void copyEvent( Event* to, Event* from ); |
53 | void copyTodo( Todo* to, Todo* from ); | 55 | void copyTodo( Todo* to, Todo* from ); |
54 | //int initDevice(GSM_StateMachine *s); | 56 | //int initDevice(GSM_StateMachine *s); |
55 | QString mProfileName; | 57 | QString mProfileName; |
56 | void afterSave( Incidence* ); | 58 | void afterSave( Incidence* ); |