-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 6c1f444..f488a07 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -741,522 +741,523 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | |||
741 | return; | 741 | return; |
742 | } | 742 | } |
743 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 743 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
744 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 744 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
745 | 745 | ||
746 | if ( syncWithFile( localTempFile, true ) ) { | 746 | if ( syncWithFile( localTempFile, true ) ) { |
747 | 747 | ||
748 | if ( mWriteBackFile ) { | 748 | if ( mWriteBackFile ) { |
749 | int fi; | 749 | int fi; |
750 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 750 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
751 | QString pwd = getPassword(); | 751 | QString pwd = getPassword(); |
752 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 752 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
753 | 753 | ||
754 | } | 754 | } |
755 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 755 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
756 | result = system ( postCommand ); | 756 | result = system ( postCommand ); |
757 | qDebug("Sync:Writing back file result: %d ", result); | 757 | qDebug("Sync:Writing back file result: %d ", result); |
758 | if ( result != 0 ) { | 758 | if ( result != 0 ) { |
759 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 759 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
760 | return; | 760 | return; |
761 | } else { | 761 | } else { |
762 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 762 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
763 | } | 763 | } |
764 | } | 764 | } |
765 | } | 765 | } |
766 | return; | 766 | return; |
767 | } | 767 | } |
768 | bool KSyncManager::edit_pisync_options() | 768 | bool KSyncManager::edit_pisync_options() |
769 | { | 769 | { |
770 | QDialog dia( mParent, "dia", true ); | 770 | QDialog dia( mParent, "dia", true ); |
771 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 771 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
772 | QVBoxLayout lay ( &dia ); | 772 | QVBoxLayout lay ( &dia ); |
773 | lay.setSpacing( 5 ); | 773 | lay.setSpacing( 5 ); |
774 | lay.setMargin( 3 ); | 774 | lay.setMargin( 3 ); |
775 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 775 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
776 | lay.addWidget( &lab1 ); | 776 | lay.addWidget( &lab1 ); |
777 | QLineEdit le1 (&dia ); | 777 | QLineEdit le1 (&dia ); |
778 | lay.addWidget( &le1 ); | 778 | lay.addWidget( &le1 ); |
779 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 779 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
780 | lay.addWidget( &lab2 ); | 780 | lay.addWidget( &lab2 ); |
781 | QLineEdit le2 (&dia ); | 781 | QLineEdit le2 (&dia ); |
782 | lay.addWidget( &le2 ); | 782 | lay.addWidget( &le2 ); |
783 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 783 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
784 | lay.addWidget( &lab3 ); | 784 | lay.addWidget( &lab3 ); |
785 | QLineEdit le3 (&dia ); | 785 | QLineEdit le3 (&dia ); |
786 | lay.addWidget( &le3 ); | 786 | lay.addWidget( &le3 ); |
787 | QPushButton pb ( "OK", &dia); | 787 | QPushButton pb ( "OK", &dia); |
788 | lay.addWidget( &pb ); | 788 | lay.addWidget( &pb ); |
789 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 789 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
790 | le1.setText( mPassWordPiSync ); | 790 | le1.setText( mPassWordPiSync ); |
791 | le2.setText( mActiveSyncIP ); | 791 | le2.setText( mActiveSyncIP ); |
792 | le3.setText( mActiveSyncPort ); | 792 | le3.setText( mActiveSyncPort ); |
793 | if ( dia.exec() ) { | 793 | if ( dia.exec() ) { |
794 | mPassWordPiSync = le1.text(); | 794 | mPassWordPiSync = le1.text(); |
795 | mActiveSyncPort = le3.text(); | 795 | mActiveSyncPort = le3.text(); |
796 | mActiveSyncIP = le2.text(); | 796 | mActiveSyncIP = le2.text(); |
797 | return true; | 797 | return true; |
798 | } | 798 | } |
799 | return false; | 799 | return false; |
800 | } | 800 | } |
801 | bool KSyncManager::edit_sync_options() | 801 | bool KSyncManager::edit_sync_options() |
802 | { | 802 | { |
803 | 803 | ||
804 | QDialog dia( mParent, "dia", true ); | 804 | QDialog dia( mParent, "dia", true ); |
805 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 805 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
806 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 806 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
807 | QVBoxLayout lay ( &dia ); | 807 | QVBoxLayout lay ( &dia ); |
808 | lay.setSpacing( 2 ); | 808 | lay.setSpacing( 2 ); |
809 | lay.setMargin( 3 ); | 809 | lay.setMargin( 3 ); |
810 | lay.addWidget(&gr); | 810 | lay.addWidget(&gr); |
811 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 811 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
812 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 812 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
813 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 813 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
814 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 814 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
815 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 815 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
816 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 816 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
817 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 817 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
818 | QPushButton pb ( "OK", &dia); | 818 | QPushButton pb ( "OK", &dia); |
819 | lay.addWidget( &pb ); | 819 | lay.addWidget( &pb ); |
820 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 820 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
821 | switch ( mSyncAlgoPrefs ) { | 821 | switch ( mSyncAlgoPrefs ) { |
822 | case 0: | 822 | case 0: |
823 | loc.setChecked( true); | 823 | loc.setChecked( true); |
824 | break; | 824 | break; |
825 | case 1: | 825 | case 1: |
826 | rem.setChecked( true ); | 826 | rem.setChecked( true ); |
827 | break; | 827 | break; |
828 | case 2: | 828 | case 2: |
829 | newest.setChecked( true); | 829 | newest.setChecked( true); |
830 | break; | 830 | break; |
831 | case 3: | 831 | case 3: |
832 | ask.setChecked( true); | 832 | ask.setChecked( true); |
833 | break; | 833 | break; |
834 | case 4: | 834 | case 4: |
835 | f_loc.setChecked( true); | 835 | f_loc.setChecked( true); |
836 | break; | 836 | break; |
837 | case 5: | 837 | case 5: |
838 | f_rem.setChecked( true); | 838 | f_rem.setChecked( true); |
839 | break; | 839 | break; |
840 | case 6: | 840 | case 6: |
841 | // both.setChecked( true); | 841 | // both.setChecked( true); |
842 | break; | 842 | break; |
843 | default: | 843 | default: |
844 | break; | 844 | break; |
845 | } | 845 | } |
846 | if ( dia.exec() ) { | 846 | if ( dia.exec() ) { |
847 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 847 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
848 | return true; | 848 | return true; |
849 | } | 849 | } |
850 | return false; | 850 | return false; |
851 | } | 851 | } |
852 | 852 | ||
853 | QString KSyncManager::getPassword( ) | 853 | QString KSyncManager::getPassword( ) |
854 | { | 854 | { |
855 | QString retfile = ""; | 855 | QString retfile = ""; |
856 | QDialog dia ( mParent, "input-dialog", true ); | 856 | QDialog dia ( mParent, "input-dialog", true ); |
857 | QLineEdit lab ( &dia ); | 857 | QLineEdit lab ( &dia ); |
858 | lab.setEchoMode( QLineEdit::Password ); | 858 | lab.setEchoMode( QLineEdit::Password ); |
859 | QVBoxLayout lay( &dia ); | 859 | QVBoxLayout lay( &dia ); |
860 | lay.setMargin(7); | 860 | lay.setMargin(7); |
861 | lay.setSpacing(7); | 861 | lay.setSpacing(7); |
862 | lay.addWidget( &lab); | 862 | lay.addWidget( &lab); |
863 | dia.setFixedSize( 230,50 ); | 863 | dia.setFixedSize( 230,50 ); |
864 | dia.setCaption( i18n("Enter password") ); | 864 | dia.setCaption( i18n("Enter password") ); |
865 | QPushButton pb ( "OK", &dia); | 865 | QPushButton pb ( "OK", &dia); |
866 | lay.addWidget( &pb ); | 866 | lay.addWidget( &pb ); |
867 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 867 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
868 | dia.show(); | 868 | dia.show(); |
869 | int res = dia.exec(); | 869 | int res = dia.exec(); |
870 | if ( res ) | 870 | if ( res ) |
871 | retfile = lab.text(); | 871 | retfile = lab.text(); |
872 | dia.hide(); | 872 | dia.hide(); |
873 | qApp->processEvents(); | 873 | qApp->processEvents(); |
874 | return retfile; | 874 | return retfile; |
875 | 875 | ||
876 | } | 876 | } |
877 | 877 | ||
878 | 878 | ||
879 | void KSyncManager::confSync() | 879 | void KSyncManager::confSync() |
880 | { | 880 | { |
881 | static KSyncPrefsDialog* sp = 0; | 881 | static KSyncPrefsDialog* sp = 0; |
882 | if ( ! sp ) { | 882 | if ( ! sp ) { |
883 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 883 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
884 | } | 884 | } |
885 | sp->usrReadConfig(); | 885 | sp->usrReadConfig(); |
886 | #ifndef DESKTOP_VERSION | 886 | #ifndef DESKTOP_VERSION |
887 | sp->showMaximized(); | 887 | sp->showMaximized(); |
888 | #else | 888 | #else |
889 | sp->show(); | 889 | sp->show(); |
890 | #endif | 890 | #endif |
891 | sp->exec(); | 891 | sp->exec(); |
892 | QStringList oldSyncProfileNames = mSyncProfileNames; | 892 | QStringList oldSyncProfileNames = mSyncProfileNames; |
893 | mSyncProfileNames = sp->getSyncProfileNames(); | 893 | mSyncProfileNames = sp->getSyncProfileNames(); |
894 | mLocalMachineName = sp->getLocalMachineName (); | 894 | mLocalMachineName = sp->getLocalMachineName (); |
895 | int ii; | 895 | int ii; |
896 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 896 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
897 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 897 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
898 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 898 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
899 | } | 899 | } |
900 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 900 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
901 | } | 901 | } |
902 | void KSyncManager::syncKDE() | 902 | void KSyncManager::syncKDE() |
903 | { | 903 | { |
904 | mSyncWithDesktop = true; | 904 | mSyncWithDesktop = true; |
905 | emit save(); | 905 | emit save(); |
906 | switch(mTargetApp) | 906 | switch(mTargetApp) |
907 | { | 907 | { |
908 | case (KAPI): | 908 | case (KAPI): |
909 | { | 909 | { |
910 | #ifdef DESKTOP_VERSION | 910 | #ifdef DESKTOP_VERSION |
911 | QString command = qApp->applicationDirPath () + "/kdeabdump"; | 911 | QString command = qApp->applicationDirPath () + "/kdeabdump"; |
912 | #else | 912 | #else |
913 | QString command = "kdeabdump"; | 913 | QString command = "kdeabdump"; |
914 | #endif | 914 | #endif |
915 | if ( ! QFile::exists ( command ) ) | 915 | if ( ! QFile::exists ( command ) ) |
916 | command = "kdeabdump"; | 916 | command = "kdeabdump"; |
917 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 917 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
918 | system ( command.latin1()); | 918 | system ( command.latin1()); |
919 | if ( syncWithFile( fileName,true ) ) { | 919 | if ( syncWithFile( fileName,true ) ) { |
920 | if ( mWriteBackFile ) { | 920 | if ( mWriteBackFile ) { |
921 | command += " --read"; | 921 | command += " --read"; |
922 | system ( command.latin1()); | 922 | system ( command.latin1()); |
923 | } | 923 | } |
924 | } | 924 | } |
925 | 925 | ||
926 | } | 926 | } |
927 | break; | 927 | break; |
928 | case (KOPI): | 928 | case (KOPI): |
929 | { | 929 | { |
930 | #ifdef DESKTOP_VERSION | 930 | #ifdef DESKTOP_VERSION |
931 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 931 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
932 | #else | 932 | #else |
933 | QString command = "kdecaldump"; | 933 | QString command = "kdecaldump"; |
934 | #endif | 934 | #endif |
935 | if ( ! QFile::exists ( command ) ) | 935 | if ( ! QFile::exists ( command ) ) |
936 | command = "kdecaldump"; | 936 | command = "kdecaldump"; |
937 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 937 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
938 | system ( command.latin1()); | 938 | system ( command.latin1()); |
939 | if ( syncWithFile( fileName,true ) ) { | 939 | if ( syncWithFile( fileName,true ) ) { |
940 | if ( mWriteBackFile ) { | 940 | if ( mWriteBackFile ) { |
941 | command += " --read"; | 941 | command += " --read"; |
942 | system ( command.latin1()); | 942 | system ( command.latin1()); |
943 | } | 943 | } |
944 | } | 944 | } |
945 | 945 | ||
946 | } | 946 | } |
947 | break; | 947 | break; |
948 | case (PWMPI): | 948 | case (PWMPI): |
949 | 949 | ||
950 | break; | 950 | break; |
951 | default: | 951 | default: |
952 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 952 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
953 | break; | 953 | break; |
954 | 954 | ||
955 | } | 955 | } |
956 | } | 956 | } |
957 | 957 | ||
958 | void KSyncManager::syncSharp() | 958 | void KSyncManager::syncSharp() |
959 | { | 959 | { |
960 | 960 | ||
961 | if ( ! syncExternalApplication("sharp") ) | 961 | if ( ! syncExternalApplication("sharp") ) |
962 | qDebug("ERROR sync sharp "); | 962 | qDebug("ERROR sync sharp "); |
963 | } | 963 | } |
964 | 964 | ||
965 | bool KSyncManager::syncExternalApplication(QString resource) | 965 | bool KSyncManager::syncExternalApplication(QString resource) |
966 | { | 966 | { |
967 | 967 | ||
968 | emit save(); | 968 | emit save(); |
969 | 969 | ||
970 | if ( mAskForPreferences ) | 970 | if ( mAskForPreferences ) |
971 | if ( !edit_sync_options()) { | 971 | if ( !edit_sync_options()) { |
972 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 972 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
973 | return false; | 973 | return false; |
974 | } | 974 | } |
975 | 975 | ||
976 | qDebug("Sync extern %s", resource.latin1()); | 976 | qDebug("Sync extern %s", resource.latin1()); |
977 | 977 | ||
978 | bool syncOK = mImplementation->syncExternal(this, resource); | 978 | bool syncOK = mImplementation->syncExternal(this, resource); |
979 | 979 | ||
980 | return syncOK; | 980 | return syncOK; |
981 | 981 | ||
982 | } | 982 | } |
983 | 983 | ||
984 | void KSyncManager::syncPhone() | 984 | void KSyncManager::syncPhone() |
985 | { | 985 | { |
986 | 986 | ||
987 | syncExternalApplication("phone"); | 987 | syncExternalApplication("phone"); |
988 | 988 | ||
989 | } | 989 | } |
990 | 990 | ||
991 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 991 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
992 | { | 992 | { |
993 | if (!bar->isVisible()) | 993 | if (!bar->isVisible()) |
994 | { | 994 | { |
995 | bar->setCaption (caption); | 995 | bar->setCaption (caption); |
996 | bar->setTotalSteps ( total ) ; | 996 | bar->setTotalSteps ( total ) ; |
997 | |||
998 | bar->show(); | 997 | bar->show(); |
999 | } | 998 | } |
1000 | 999 | bar->raise(); | |
1001 | bar->setProgress( percentage ); | 1000 | bar->setProgress( percentage ); |
1001 | qApp->processEvents(); | ||
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | void KSyncManager::hideProgressBar() | 1004 | void KSyncManager::hideProgressBar() |
1005 | { | 1005 | { |
1006 | bar->hide(); | 1006 | bar->hide(); |
1007 | qApp->processEvents(); | ||
1007 | } | 1008 | } |
1008 | 1009 | ||
1009 | bool KSyncManager::isProgressBarCanceled() | 1010 | bool KSyncManager::isProgressBarCanceled() |
1010 | { | 1011 | { |
1011 | return !bar->isVisible(); | 1012 | return !bar->isVisible(); |
1012 | } | 1013 | } |
1013 | 1014 | ||
1014 | QString KSyncManager::syncFileName() | 1015 | QString KSyncManager::syncFileName() |
1015 | { | 1016 | { |
1016 | 1017 | ||
1017 | QString fn = "tempfile"; | 1018 | QString fn = "tempfile"; |
1018 | switch(mTargetApp) | 1019 | switch(mTargetApp) |
1019 | { | 1020 | { |
1020 | case (KAPI): | 1021 | case (KAPI): |
1021 | fn = "tempsyncab.vcf"; | 1022 | fn = "tempsyncab.vcf"; |
1022 | break; | 1023 | break; |
1023 | case (KOPI): | 1024 | case (KOPI): |
1024 | fn = "tempsynccal.ics"; | 1025 | fn = "tempsynccal.ics"; |
1025 | break; | 1026 | break; |
1026 | case (PWMPI): | 1027 | case (PWMPI): |
1027 | fn = "tempsyncpw.pwm"; | 1028 | fn = "tempsyncpw.pwm"; |
1028 | break; | 1029 | break; |
1029 | default: | 1030 | default: |
1030 | break; | 1031 | break; |
1031 | } | 1032 | } |
1032 | #ifdef _WIN32_ | 1033 | #ifdef _WIN32_ |
1033 | return locateLocal( "tmp", fn ); | 1034 | return locateLocal( "tmp", fn ); |
1034 | #else | 1035 | #else |
1035 | return (QString( "/tmp/" )+ fn ); | 1036 | return (QString( "/tmp/" )+ fn ); |
1036 | #endif | 1037 | #endif |
1037 | } | 1038 | } |
1038 | 1039 | ||
1039 | void KSyncManager::syncPi() | 1040 | void KSyncManager::syncPi() |
1040 | { | 1041 | { |
1041 | mIsKapiFile = true; | 1042 | mIsKapiFile = true; |
1042 | mPisyncFinished = false; | 1043 | mPisyncFinished = false; |
1043 | qApp->processEvents(); | 1044 | qApp->processEvents(); |
1044 | if ( mAskForPreferences ) | 1045 | if ( mAskForPreferences ) |
1045 | if ( !edit_pisync_options()) { | 1046 | if ( !edit_pisync_options()) { |
1046 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1047 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1047 | return; | 1048 | return; |
1048 | } | 1049 | } |
1049 | bool ok; | 1050 | bool ok; |
1050 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1051 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1051 | if ( ! ok ) { | 1052 | if ( ! ok ) { |
1052 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1053 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1053 | return; | 1054 | return; |
1054 | } | 1055 | } |
1055 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1056 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
1056 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1057 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1057 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 1058 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
1058 | commandSocket->readFile( syncFileName() ); | 1059 | commandSocket->readFile( syncFileName() ); |
1059 | } | 1060 | } |
1060 | 1061 | ||
1061 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1062 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1062 | { | 1063 | { |
1063 | //enum { success, errorW, errorR, quiet }; | 1064 | //enum { success, errorW, errorR, quiet }; |
1064 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1065 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1065 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1066 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1066 | delete s; | 1067 | delete s; |
1067 | if ( state == KCommandSocket::errorR ) { | 1068 | if ( state == KCommandSocket::errorR ) { |
1068 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1069 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1069 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1070 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1070 | commandSocket->sendStop(); | 1071 | commandSocket->sendStop(); |
1071 | } | 1072 | } |
1072 | mPisyncFinished = true; | 1073 | mPisyncFinished = true; |
1073 | return; | 1074 | return; |
1074 | 1075 | ||
1075 | } else if ( state == KCommandSocket::errorW ) { | 1076 | } else if ( state == KCommandSocket::errorW ) { |
1076 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1077 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1077 | mPisyncFinished = true; | 1078 | mPisyncFinished = true; |
1078 | 1079 | ||
1079 | } else if ( state == KCommandSocket::successR ) { | 1080 | } else if ( state == KCommandSocket::successR ) { |
1080 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1081 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1081 | 1082 | ||
1082 | } else if ( state == KCommandSocket::successW ) { | 1083 | } else if ( state == KCommandSocket::successW ) { |
1083 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1084 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1084 | mPisyncFinished = true; | 1085 | mPisyncFinished = true; |
1085 | } | 1086 | } |
1086 | 1087 | ||
1087 | delete s; | 1088 | delete s; |
1088 | } | 1089 | } |
1089 | 1090 | ||
1090 | void KSyncManager::readFileFromSocket() | 1091 | void KSyncManager::readFileFromSocket() |
1091 | { | 1092 | { |
1092 | QString fileName = syncFileName(); | 1093 | QString fileName = syncFileName(); |
1093 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1094 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1094 | if ( ! syncWithFile( fileName , true ) ) { | 1095 | if ( ! syncWithFile( fileName , true ) ) { |
1095 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1096 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1096 | mPisyncFinished = true; | 1097 | mPisyncFinished = true; |
1097 | return; | 1098 | return; |
1098 | } | 1099 | } |
1099 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1100 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1100 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1101 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1101 | if ( mWriteBackFile ) | 1102 | if ( mWriteBackFile ) |
1102 | commandSocket->writeFile( fileName ); | 1103 | commandSocket->writeFile( fileName ); |
1103 | else { | 1104 | else { |
1104 | commandSocket->sendStop(); | 1105 | commandSocket->sendStop(); |
1105 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1106 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1106 | mPisyncFinished = true; | 1107 | mPisyncFinished = true; |
1107 | } | 1108 | } |
1108 | } | 1109 | } |
1109 | 1110 | ||
1110 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1111 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1111 | { | 1112 | { |
1112 | mPassWord = pw; | 1113 | mPassWord = pw; |
1113 | mSocket = 0; | 1114 | mSocket = 0; |
1114 | mSyncActionDialog = 0; | 1115 | mSyncActionDialog = 0; |
1115 | blockRC = false; | 1116 | blockRC = false; |
1116 | }; | 1117 | }; |
1117 | 1118 | ||
1118 | void KServerSocket::newConnection ( int socket ) | 1119 | void KServerSocket::newConnection ( int socket ) |
1119 | { | 1120 | { |
1120 | // qDebug("KServerSocket:New connection %d ", socket); | 1121 | // qDebug("KServerSocket:New connection %d ", socket); |
1121 | if ( mSocket ) { | 1122 | if ( mSocket ) { |
1122 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1123 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1123 | delete mSocket; | 1124 | delete mSocket; |
1124 | mSocket = 0; | 1125 | mSocket = 0; |
1125 | } | 1126 | } |
1126 | mSocket = new QSocket( this ); | 1127 | mSocket = new QSocket( this ); |
1127 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1128 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1128 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1129 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1129 | mSocket->setSocket( socket ); | 1130 | mSocket->setSocket( socket ); |
1130 | } | 1131 | } |
1131 | 1132 | ||
1132 | void KServerSocket::discardClient() | 1133 | void KServerSocket::discardClient() |
1133 | { | 1134 | { |
1134 | //qDebug(" KServerSocket::discardClient()"); | 1135 | //qDebug(" KServerSocket::discardClient()"); |
1135 | if ( mSocket ) { | 1136 | if ( mSocket ) { |
1136 | delete mSocket; | 1137 | delete mSocket; |
1137 | mSocket = 0; | 1138 | mSocket = 0; |
1138 | } | 1139 | } |
1139 | //emit endConnect(); | 1140 | //emit endConnect(); |
1140 | } | 1141 | } |
1141 | void KServerSocket::readClient() | 1142 | void KServerSocket::readClient() |
1142 | { | 1143 | { |
1143 | if ( blockRC ) | 1144 | if ( blockRC ) |
1144 | return; | 1145 | return; |
1145 | if ( mSocket == 0 ) { | 1146 | if ( mSocket == 0 ) { |
1146 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1147 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1147 | return; | 1148 | return; |
1148 | } | 1149 | } |
1149 | //qDebug("KServerSocket::readClient()"); | 1150 | //qDebug("KServerSocket::readClient()"); |
1150 | if ( mSocket->canReadLine() ) { | 1151 | if ( mSocket->canReadLine() ) { |
1151 | QString line = mSocket->readLine(); | 1152 | QString line = mSocket->readLine(); |
1152 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1153 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1153 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1154 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1154 | if ( tokens[0] == "GET" ) { | 1155 | if ( tokens[0] == "GET" ) { |
1155 | if ( tokens[1] == mPassWord ) { | 1156 | if ( tokens[1] == mPassWord ) { |
1156 | //emit sendFile( mSocket ); | 1157 | //emit sendFile( mSocket ); |
1157 | bool ok = false; | 1158 | bool ok = false; |
1158 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1159 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1159 | if ( ok ) { | 1160 | if ( ok ) { |
1160 | KSyncManager::mRequestedSyncEvent = dt; | 1161 | KSyncManager::mRequestedSyncEvent = dt; |
1161 | } | 1162 | } |
1162 | else | 1163 | else |
1163 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1164 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1164 | send_file(); | 1165 | send_file(); |
1165 | } | 1166 | } |
1166 | else { | 1167 | else { |
1167 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1168 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1168 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1169 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1169 | } | 1170 | } |
1170 | } | 1171 | } |
1171 | if ( tokens[0] == "PUT" ) { | 1172 | if ( tokens[0] == "PUT" ) { |
1172 | if ( tokens[1] == mPassWord ) { | 1173 | if ( tokens[1] == mPassWord ) { |
1173 | //emit getFile( mSocket ); | 1174 | //emit getFile( mSocket ); |
1174 | blockRC = true; | 1175 | blockRC = true; |
1175 | get_file(); | 1176 | get_file(); |
1176 | } | 1177 | } |
1177 | else { | 1178 | else { |
1178 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1179 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1179 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1180 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1180 | } | 1181 | } |
1181 | } | 1182 | } |
1182 | if ( tokens[0] == "STOP" ) { | 1183 | if ( tokens[0] == "STOP" ) { |
1183 | //emit endConnect(); | 1184 | //emit endConnect(); |
1184 | end_connect(); | 1185 | end_connect(); |
1185 | } | 1186 | } |
1186 | } | 1187 | } |
1187 | } | 1188 | } |
1188 | void KServerSocket::end_connect() | 1189 | void KServerSocket::end_connect() |
1189 | { | 1190 | { |
1190 | delete mSyncActionDialog; | 1191 | delete mSyncActionDialog; |
1191 | mSyncActionDialog = 0; | 1192 | mSyncActionDialog = 0; |
1192 | } | 1193 | } |
1193 | void KServerSocket::send_file() | 1194 | void KServerSocket::send_file() |
1194 | { | 1195 | { |
1195 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1196 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1196 | if ( mSyncActionDialog ) | 1197 | if ( mSyncActionDialog ) |
1197 | delete mSyncActionDialog; | 1198 | delete mSyncActionDialog; |
1198 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1199 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1199 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1200 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1200 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1201 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1201 | label->setAlignment ( Qt::AlignHCenter ); | 1202 | label->setAlignment ( Qt::AlignHCenter ); |
1202 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1203 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1203 | lay->addWidget( label); | 1204 | lay->addWidget( label); |
1204 | lay->setMargin(7); | 1205 | lay->setMargin(7); |
1205 | lay->setSpacing(7); | 1206 | lay->setSpacing(7); |
1206 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1207 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1207 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1208 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1208 | if ( secs < 0 ) | 1209 | if ( secs < 0 ) |
1209 | secs = secs * (-1); | 1210 | secs = secs * (-1); |
1210 | if ( secs > 30 ) | 1211 | if ( secs > 30 ) |
1211 | //if ( true ) | 1212 | //if ( true ) |
1212 | { | 1213 | { |
1213 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1214 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1214 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1215 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1215 | label->setAlignment ( Qt::AlignHCenter ); | 1216 | label->setAlignment ( Qt::AlignHCenter ); |
1216 | lay->addWidget( label); | 1217 | lay->addWidget( label); |
1217 | if ( secs > 180 ) | 1218 | if ( secs > 180 ) |
1218 | { | 1219 | { |
1219 | if ( secs > 300 ) { | 1220 | if ( secs > 300 ) { |
1220 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1221 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1221 | qDebug("cancelled "); | 1222 | qDebug("cancelled "); |
1222 | return ; | 1223 | return ; |
1223 | } | 1224 | } |
1224 | } | 1225 | } |
1225 | QFont f = label->font(); | 1226 | QFont f = label->font(); |
1226 | f.setPointSize ( f.pointSize() *2 ); | 1227 | f.setPointSize ( f.pointSize() *2 ); |
1227 | f. setBold (true ); | 1228 | f. setBold (true ); |
1228 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1229 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1229 | label->setFont( f ); | 1230 | label->setFont( f ); |
1230 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1231 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1231 | label->setText( warning ); | 1232 | label->setText( warning ); |
1232 | label->setAlignment ( Qt::AlignHCenter ); | 1233 | label->setAlignment ( Qt::AlignHCenter ); |
1233 | lay->addWidget( label); | 1234 | lay->addWidget( label); |
1234 | mSyncActionDialog->setFixedSize( 230, 300); | 1235 | mSyncActionDialog->setFixedSize( 230, 300); |
1235 | } else { | 1236 | } else { |
1236 | mSyncActionDialog->setFixedSize( 230, 200); | 1237 | mSyncActionDialog->setFixedSize( 230, 200); |
1237 | } | 1238 | } |
1238 | } else { | 1239 | } else { |
1239 | mSyncActionDialog->setFixedSize( 230, 120); | 1240 | mSyncActionDialog->setFixedSize( 230, 120); |
1240 | } | 1241 | } |
1241 | } else | 1242 | } else |
1242 | mSyncActionDialog->setFixedSize( 230, 120); | 1243 | mSyncActionDialog->setFixedSize( 230, 120); |
1243 | mSyncActionDialog->show(); | 1244 | mSyncActionDialog->show(); |
1244 | mSyncActionDialog->raise(); | 1245 | mSyncActionDialog->raise(); |
1245 | emit request_file(); | 1246 | emit request_file(); |
1246 | qApp->processEvents(); | 1247 | qApp->processEvents(); |
1247 | QString fileName = mFileName; | 1248 | QString fileName = mFileName; |
1248 | QFile file( fileName ); | 1249 | QFile file( fileName ); |
1249 | if (!file.open( IO_ReadOnly ) ) { | 1250 | if (!file.open( IO_ReadOnly ) ) { |
1250 | delete mSyncActionDialog; | 1251 | delete mSyncActionDialog; |
1251 | mSyncActionDialog = 0; | 1252 | mSyncActionDialog = 0; |
1252 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); | 1253 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); |
1253 | mSocket->close(); | 1254 | mSocket->close(); |
1254 | if ( mSocket->state() == QSocket::Idle ) | 1255 | if ( mSocket->state() == QSocket::Idle ) |
1255 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1256 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1256 | return ; | 1257 | return ; |
1257 | 1258 | ||
1258 | } | 1259 | } |
1259 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1260 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1260 | QTextStream ts( &file ); | 1261 | QTextStream ts( &file ); |
1261 | ts.setEncoding( QTextStream::Latin1 ); | 1262 | ts.setEncoding( QTextStream::Latin1 ); |
1262 | 1263 | ||