summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp8
-rw-r--r--libkcal/phoneformat.cpp341
-rw-r--r--libkcal/phoneformat.h13
3 files changed, 168 insertions, 194 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index d6ead37..547d02b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1201,9 +1201,7 @@ void CalendarView::syncExternal( int mode )
1201 if ( mode == 1 ) { // phone 1201 if ( mode == 1 ) { // phone
1202 phoneFormat = new PhoneFormat (); 1202 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1203 loadSuccess = phoneFormat->load( calendar,
1204 mCalendar,
1205 mCurrentSyncDevice,
1206 KOPrefs::instance()->mPhoneDevice, 1203 KOPrefs::instance()->mPhoneDevice,
1207 KOPrefs::instance()->mPhoneConnection, 1204 KOPrefs::instance()->mPhoneConnection,
1208 KOPrefs::instance()->mPhoneModel); 1205 KOPrefs::instance()->mPhoneModel);
1206 loadSuccess = phoneFormat->load( calendar,mCalendar);
1209 1207
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 596148e..b8fed47 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -197,2 +197,3 @@ public:
197 todo->setCsum( mProfileName, QString::number( cSum )); 197 todo->setCsum( mProfileName, QString::number( cSum ));
198 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
198 mCalendar->addTodo( todo); 199 mCalendar->addTodo( todo);
@@ -499,2 +500,3 @@ public:
499 event->setCsum( mProfileName, QString::number( cSum )); 500 event->setCsum( mProfileName, QString::number( cSum ));
501 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
500 mCalendar->addEvent( event); 502 mCalendar->addEvent( event);
@@ -593,5 +595,8 @@ private:
593 595
594PhoneFormat::PhoneFormat() 596PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
595{ 597{
596 ; 598 mProfileName = profileName;
599 mDevice = device;
600 mConnection = connection;
601 mModel = model;
597} 602}
@@ -601,2 +606,27 @@ PhoneFormat::~PhoneFormat()
601} 606}
607int PhoneFormat::initDevice(GSM_StateMachine *s)
608{
609 GSM_ReadConfig(NULL, &s->Config[0], 0);
610 s->ConfigNum = 1;
611 GSM_Config *cfg = &s->Config[0];
612 if ( ! mConnection.isEmpty() ) {
613 cfg->Connection = strdup(mConnection.latin1());
614 cfg->DefaultConnection = false;
615 qDebug("Connection set %s ", cfg->Connection );
616
617 }
618 if ( ! mDevice.isEmpty() ) {
619 cfg->Device = strdup(mDevice.latin1());
620 cfg->DefaultDevice = false;
621 qDebug("Device set %s ", cfg->Device);
622
623 }
624 if ( ! mModel.isEmpty() ) {
625 strcpy(cfg->Model,mModel.latin1() );
626 cfg->DefaultModel = false;
627 qDebug("Model set %s ",cfg->Model );
628 }
629 int error=GSM_InitConnection(s,3);
630 return error;
631}
602ulong PhoneFormat::getCsum( const QStringList & attList) 632ulong PhoneFormat::getCsum( const QStringList & attList)
@@ -627,5 +657,4 @@ ulong PhoneFormat::getCsum( const QStringList & attList)
627#define DEBUGMODE false 657#define DEBUGMODE false
628bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) 658bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
629{ 659{
630 mProfileName = profileName;
631 GSM_StateMachines; 660 GSM_StateMachines;
@@ -678,26 +707,3 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profi
678#endif 707#endif
679 setlocale(LC_ALL, ""); 708 int error=initDevice(&s);
680 GSM_ReadConfig(NULL, &s.Config[0], 0);
681 s.ConfigNum = 1;
682 GSM_Config *cfg = &s.Config[0];
683 if ( ! connection.isEmpty() ) {
684 cfg->Connection = strdup(connection.latin1());
685 cfg->DefaultConnection = false;
686 qDebug("Connection set %s ", cfg->Connection );
687
688 }
689 if ( ! device.isEmpty() ) {
690 cfg->Device = strdup(device.latin1());
691 cfg->DefaultDevice = false;
692 qDebug("Device set %s ", cfg->Device);
693
694 }
695 if ( ! model.isEmpty() ) {
696 strcpy(cfg->Model,model.latin1() );
697 cfg->DefaultModel = false;
698 qDebug("Model set %s ",cfg->Model );
699
700
701 }
702 int error=GSM_InitConnection(&s,3);
703 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 709 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
@@ -710,3 +716,3 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profi
710 bool gshutdown = false; 716 bool gshutdown = false;
711 PhoneParser handler( calendar, profileName ); 717 PhoneParser handler( calendar, mProfileName );
712 int ccc = 0; 718 int ccc = 0;
@@ -738,7 +744,66 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profi
738} 744}
745void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note )
746{
739 747
740bool PhoneFormat::save( Calendar *calendar) 748}
749void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
741{ 750{
742#if 0 751#if 0
743 QLabel status ( i18n("Processing/adding events ..."), 0 ); 752 QStringList list;
753 list.append( QString::number( todo->zaurusId() ) );
754 list.append( todo->categories().join(",") );
755
756 if ( todo->hasStartDate() ) {
757 list.append( dtToString( todo->dtStart()) );
758 } else
759 list.append( QString() );
760
761 if ( todo->hasDueDate() ) {
762 QTime tim;
763 if ( todo->doesFloat()) {
764 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
765 } else {
766 list.append( dtToString(todo->dtDue() ) );
767 }
768 } else
769 list.append( QString() );
770
771 if ( todo->isCompleted() ) {
772 list.append( dtToString( todo->completed()) );
773 list.append( "0" ); // yes 0 == completed
774 } else {
775 list.append( dtToString( todo->completed()) );
776 list.append( "1" );
777 }
778 list.append( QString::number( todo->priority() ));
779 if( ! todo->summary().isEmpty() )
780 list.append( todo->summary() );
781 else
782 list.append( "" );
783 if (! todo->description().isEmpty() )
784 list.append( todo->description() );
785 else
786 list.append( "" );
787 for(QStringList::Iterator it=list.begin();
788 it!=list.end(); ++it){
789 QString& s = (*it);
790 s.replace(QRegExp("\""), "\"\"");
791 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
792 s.prepend('\"');
793 s.append('\"');
794 } else if(s.isEmpty() && !s.isNull()){
795 s = "\"\"";
796 }
797 }
798 return list.join(",");
799#endif
800}
801bool PhoneFormat::save( Calendar *calendar)
802{
803 GSM_StateMachines;
804 qDebug(" save ");
805 s.opened = false;
806 s.msg = NULL;
807 s.ConfigNum = 0;
808 QLabel status ( i18n("Writing data. Opening device ..."), 0 );
744 int w = status.sizeHint().width()+20 ; 809 int w = status.sizeHint().width()+20 ;
@@ -753,16 +818,14 @@ bool PhoneFormat::save( Calendar *calendar)
753 qApp->processEvents(); 818 qApp->processEvents();
754 bool debug = DEBUGMODE; 819
755 QString codec = "utf8"; 820 int error=initDevice(&s);
756 QString answer; 821 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
757 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 822 if ( error != ERR_NONE )
758 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 823 return false;
759 QString command; 824 GSM_Phone_Functions*Phone;
760 QPtrList<Event> er = calendar->rawEvents(); 825 GSM_CalendarEntryNote;
761 Event* ev = er.first(); 826 bool start = true;
762 QString fileName = "/tmp/kopitempout"; 827 Phone=s.Phone.Functions;
763 int i = 0; 828 bool gshutdown = false;
764 QString changeString = ePrefix; 829 QPtrList<Event> er = calendar->rawEvents();
765 QString deleteString = ePrefix; 830 Event* ev = er.first();
766 bool deleteEnt = false;
767 bool changeEnt = false;
768 QString message = i18n("Processing event # "); 831 QString message = i18n("Processing event # ");
@@ -771,37 +834,16 @@ bool PhoneFormat::save( Calendar *calendar)
771 //qDebug("i %d ", ++i); 834 //qDebug("i %d ", ++i);
772 if ( true /*ev->zaurusStat() != -2*/ ) { 835 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
836
773 status.setText ( message + QString::number ( ++procCount ) ); 837 status.setText ( message + QString::number ( ++procCount ) );
774 qApp->processEvents(); 838 qApp->processEvents();
775 QString eString = getEventString( ev ); 839 event2GSM( ev, &Note );
776 if (/* ev->zaurusStat() == -3 */ true) { // delete 840 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
777 // deleting empty strings does not work. 841 error = Phone->DeleteCalendar(&s, &Note);
778 // we write first and x and then delete the record with the x
779 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
780 changeString += eString + "\n";
781 deleteString += eString + "\n";
782 deleteEnt = true;
783 changeEnt = true;
784 } 842 }
785 else if ( /*ev->zaurusId() == -1*/true ) { // add new 843 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
786 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 844 // we have to do this later after deleting
787 system ( command.utf8() ); 845
788 QFile file( fileName );
789 if (!file.open( IO_ReadOnly ) ) {
790 return false;
791
792 }
793 QTextStream ts( &file );
794 ts.setCodec( QTextCodec::codecForName("utf8") );
795 answer = ts.read();
796 file.close();
797 //qDebug("answer \n%s ", answer.latin1());
798 getNumFromRecord( answer, ev ) ;
799
800 } 846 }
801 else { // change existing 847 else { // change existing
802 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 848 error = Phone->AddCalendar(&s, &Note);
803 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
804 changeString += eString + "\n";
805 changeEnt = true;
806
807 } 849 }
@@ -810,46 +852,21 @@ bool PhoneFormat::save( Calendar *calendar)
810 } 852 }
811 status.setText ( i18n("Changing events ...") ); 853 ev = er.first();
812 qApp->processEvents(); 854 // pending get empty slots
813 //qDebug("changing... "); 855 while ( ev ) {
814 if ( changeEnt ) { 856 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
815 QFile file( fileName ); 857 if ( ev->getID(mProfileName).isEmpty() ) {
816 if (!file.open( IO_WriteOnly ) ) { 858 status.setText ( message + QString::number ( ++procCount ) );
817 return false; 859 qApp->processEvents();
818 860 int newID ;//= pending
819 } 861 ev->setID(mProfileName, QString::number( newID ));
820 QTextStream ts( &file ); 862 event2GSM( ev, &Note );
821 ts.setCodec( QTextCodec::codecForName("utf8") ); 863 error = Phone->AddCalendar(&s, &Note);
822 ts << changeString ; 864 }
823 file.close(); 865 }
824 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 866 ev = er.next();
825 system ( command.latin1() );
826 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
827
828 }
829 status.setText ( i18n("Deleting events ...") );
830 qApp->processEvents();
831 //qDebug("deleting... ");
832 if ( deleteEnt ) {
833 QFile file( fileName );
834 if (!file.open( IO_WriteOnly ) ) {
835 return false;
836
837 }
838 QTextStream ts( &file );
839 ts.setCodec( QTextCodec::codecForName("utf8") );
840 ts << deleteString;
841 file.close();
842 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
843 system ( command.latin1() );
844 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
845 } 867 }
846 868 GSM_ToDoEntry ToDoEntry;
847
848 changeString = tPrefix;
849 deleteString = tPrefix;
850 status.setText ( i18n("Processing todos ...") );
851 qApp->processEvents();
852 QPtrList<Todo> tl = calendar->rawTodos(); 869 QPtrList<Todo> tl = calendar->rawTodos();
853 Todo* to = tl.first(); 870 Todo* to = tl.first();
854 i = 0; 871
855 message = i18n("Processing todo # "); 872 message = i18n("Processing todo # ");
@@ -857,78 +874,34 @@ bool PhoneFormat::save( Calendar *calendar)
857 while ( to ) { 874 while ( to ) {
858 if ( true /*to->zaurusStat() != -2 */) { 875 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
859 status.setText ( message + QString::number ( ++procCount ) ); 876 status.setText ( message + QString::number ( ++procCount ) );
860 qApp->processEvents(); 877 qApp->processEvents();
861 QString eString = getTodoString( to ); 878 todo2GSM( to, &ToDoEntry );
862 if ( /*to->zaurusStat() == -3*/true ) { // delete 879 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
863 // deleting empty strings does not work. 880 error=Phone->DeleteToDo(&s,&ToDoEntry);
864 // we write first and x and then delete the record with the x
865 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
866 changeString += eString + "\n";
867 deleteString += eString + "\n";
868 deleteEnt = true;
869 changeEnt = true;
870 } 881 }
871 else if ( true /*to->zaurusId() == -1*/ ) { // add new 882 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
872 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 883 ;
873 system ( command.utf8() );
874 QFile file( fileName );
875 if (!file.open( IO_ReadOnly ) ) {
876 return false;
877
878 }
879 QTextStream ts( &file );
880 ts.setCodec( QTextCodec::codecForName("utf8") );
881 answer = ts.read();
882 file.close();
883 //qDebug("answer \n%s ", answer.latin1());
884 getNumFromRecord( answer, to ) ;
885
886 } 884 }
887 else { // change existing 885 else { // change existing
888 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 886 error=Phone->AddToDo(&s,&ToDoEntry);
889 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
890 changeString += eString + "\n";
891 changeEnt = true;
892
893 } 887 }
894 } 888 }
895
896 to = tl.next(); 889 to = tl.next();
897 } 890 }
898 status.setText ( i18n("Changing todos ...") ); 891
899 qApp->processEvents(); 892 // pending get empty slots
900 //qDebug("changing... "); 893 to = tl.first();
901 if ( changeEnt ) { 894 while ( to ) {
902 QFile file( fileName ); 895 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
903 if (!file.open( IO_WriteOnly ) ) { 896 if ( to->getID(mProfileName).isEmpty() ) {
904 return false; 897 status.setText ( message + QString::number ( ++procCount ) );
905 898 qApp->processEvents();
906 } 899 int newID ;//= pending
907 QTextStream ts( &file ); 900 to->setID(mProfileName, QString::number( newID ));
908 ts.setCodec( QTextCodec::codecForName("utf8") ); 901 todo2GSM( to, &ToDoEntry );
909 ts << changeString ; 902 error=Phone->AddToDo(&s,&ToDoEntry);
910 file.close(); 903 }
911 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 904 }
912 system ( command.latin1() ); 905 to = tl.next();
913 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
914
915 }
916 status.setText ( i18n("Deleting todos ...") );
917 qApp->processEvents();
918 //qDebug("deleting... ");
919 if ( deleteEnt ) {
920 QFile file( fileName );
921 if (!file.open( IO_WriteOnly ) ) {
922 return false;
923
924 }
925 QTextStream ts( &file );
926 ts.setCodec( QTextCodec::codecForName("utf8") );
927 ts << deleteString;
928 file.close();
929 command = "db2file todo -d -c " + codec+ " < "+ fileName;
930 system ( command.latin1() );
931 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
932 } 906 }
933#endif
934 return true; 907 return true;
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 8d4e200..1472880 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -31,3 +31,2 @@ extern "C" {
31} 31}
32
33namespace KCal { 32namespace KCal {
@@ -37,3 +36,4 @@ namespace KCal {
37*/ 36*/
38 37 class Event;
38 class Todo;
39class PhoneFormat : public QObject { 39class PhoneFormat : public QObject {
@@ -41,6 +41,6 @@ class PhoneFormat : public QObject {
41 /** Create new iCalendar format. */ 41 /** Create new iCalendar format. */
42 PhoneFormat(); 42 PhoneFormat(QString profileName, QString device,QString connection, QString model);
43 virtual ~PhoneFormat(); 43 virtual ~PhoneFormat();
44 44
45 bool load( Calendar * ,Calendar *, QString profileName, QString device,QString connection, QString model ); 45 bool load( Calendar * ,Calendar * );
46 bool save( Calendar * ); 46 bool save( Calendar * );
@@ -51,2 +51,5 @@ class PhoneFormat : public QObject {
51 private: 51 private:
52 void event2GSM( Event* ev, GSM_CalendarEntry*Note );
53 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
54 int initDevice(GSM_StateMachine *s);
52 QString getEventString( Event* ); 55 QString getEventString( Event* );
@@ -54,3 +57,3 @@ class PhoneFormat : public QObject {
54 QString dtToGSM( const QDateTime& dt, bool useTZ = true ); 57 QString dtToGSM( const QDateTime& dt, bool useTZ = true );
55 QString mProfileName; 58 QString mProfileName, mDevice, mConnection, mModel;
56}; 59};