author | zautrix <zautrix> | 2005-02-09 12:21:39 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-09 12:21:39 (UTC) |
commit | 940cdd0fd1349e7f8e53adff0595c1d946322ef1 (patch) (unidiff) | |
tree | 1a78f2c862afbc0d3c019c0905775782c906df64 /libkdepim/ksyncmanager.cpp | |
parent | 968099947455adc0e8681aedf8c161327e311f38 (diff) | |
download | kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.zip kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.tar.gz kdepimpi-940cdd0fd1349e7f8e53adff0595c1d946322ef1.tar.bz2 |
pisync fixes
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index df5a0d9..1f5f4c7 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -863,622 +863,633 @@ QString KSyncManager::getPassword( ) | |||
863 | dia.setCaption( i18n("Enter password") ); | 863 | dia.setCaption( i18n("Enter password") ); |
864 | QPushButton pb ( "OK", &dia); | 864 | QPushButton pb ( "OK", &dia); |
865 | lay.addWidget( &pb ); | 865 | lay.addWidget( &pb ); |
866 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 866 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
867 | dia.show(); | 867 | dia.show(); |
868 | int res = dia.exec(); | 868 | int res = dia.exec(); |
869 | if ( res ) | 869 | if ( res ) |
870 | retfile = lab.text(); | 870 | retfile = lab.text(); |
871 | dia.hide(); | 871 | dia.hide(); |
872 | qApp->processEvents(); | 872 | qApp->processEvents(); |
873 | return retfile; | 873 | return retfile; |
874 | 874 | ||
875 | } | 875 | } |
876 | 876 | ||
877 | 877 | ||
878 | void KSyncManager::confSync() | 878 | void KSyncManager::confSync() |
879 | { | 879 | { |
880 | static KSyncPrefsDialog* sp = 0; | 880 | static KSyncPrefsDialog* sp = 0; |
881 | if ( ! sp ) { | 881 | if ( ! sp ) { |
882 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 882 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
883 | } | 883 | } |
884 | sp->usrReadConfig(); | 884 | sp->usrReadConfig(); |
885 | #ifndef DESKTOP_VERSION | 885 | #ifndef DESKTOP_VERSION |
886 | sp->showMaximized(); | 886 | sp->showMaximized(); |
887 | #else | 887 | #else |
888 | sp->show(); | 888 | sp->show(); |
889 | #endif | 889 | #endif |
890 | sp->exec(); | 890 | sp->exec(); |
891 | QStringList oldSyncProfileNames = mSyncProfileNames; | 891 | QStringList oldSyncProfileNames = mSyncProfileNames; |
892 | mSyncProfileNames = sp->getSyncProfileNames(); | 892 | mSyncProfileNames = sp->getSyncProfileNames(); |
893 | mLocalMachineName = sp->getLocalMachineName (); | 893 | mLocalMachineName = sp->getLocalMachineName (); |
894 | int ii; | 894 | int ii; |
895 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 895 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
896 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 896 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
897 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 897 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
898 | } | 898 | } |
899 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 899 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
900 | } | 900 | } |
901 | void KSyncManager::syncKDE() | 901 | void KSyncManager::syncKDE() |
902 | { | 902 | { |
903 | mSyncWithDesktop = true; | 903 | mSyncWithDesktop = true; |
904 | emit save(); | 904 | emit save(); |
905 | switch(mTargetApp) | 905 | switch(mTargetApp) |
906 | { | 906 | { |
907 | case (KAPI): | 907 | case (KAPI): |
908 | { | 908 | { |
909 | #ifdef DESKTOP_VERSION | 909 | #ifdef DESKTOP_VERSION |
910 | QString command = qApp->applicationDirPath () + "/kdeabdump"; | 910 | QString command = qApp->applicationDirPath () + "/kdeabdump"; |
911 | #else | 911 | #else |
912 | QString command = "kdeabdump"; | 912 | QString command = "kdeabdump"; |
913 | #endif | 913 | #endif |
914 | if ( ! QFile::exists ( command ) ) | 914 | if ( ! QFile::exists ( command ) ) |
915 | command = "kdeabdump"; | 915 | command = "kdeabdump"; |
916 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 916 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
917 | system ( command.latin1()); | 917 | system ( command.latin1()); |
918 | if ( syncWithFile( fileName,true ) ) { | 918 | if ( syncWithFile( fileName,true ) ) { |
919 | if ( mWriteBackFile ) { | 919 | if ( mWriteBackFile ) { |
920 | command += " --read"; | 920 | command += " --read"; |
921 | system ( command.latin1()); | 921 | system ( command.latin1()); |
922 | } | 922 | } |
923 | } | 923 | } |
924 | 924 | ||
925 | } | 925 | } |
926 | break; | 926 | break; |
927 | case (KOPI): | 927 | case (KOPI): |
928 | { | 928 | { |
929 | #ifdef DESKTOP_VERSION | 929 | #ifdef DESKTOP_VERSION |
930 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 930 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
931 | #else | 931 | #else |
932 | QString command = "kdecaldump"; | 932 | QString command = "kdecaldump"; |
933 | #endif | 933 | #endif |
934 | if ( ! QFile::exists ( command ) ) | 934 | if ( ! QFile::exists ( command ) ) |
935 | command = "kdecaldump"; | 935 | command = "kdecaldump"; |
936 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 936 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
937 | system ( command.latin1()); | 937 | system ( command.latin1()); |
938 | if ( syncWithFile( fileName,true ) ) { | 938 | if ( syncWithFile( fileName,true ) ) { |
939 | if ( mWriteBackFile ) { | 939 | if ( mWriteBackFile ) { |
940 | command += " --read"; | 940 | command += " --read"; |
941 | system ( command.latin1()); | 941 | system ( command.latin1()); |
942 | } | 942 | } |
943 | } | 943 | } |
944 | 944 | ||
945 | } | 945 | } |
946 | break; | 946 | break; |
947 | case (PWMPI): | 947 | case (PWMPI): |
948 | 948 | ||
949 | break; | 949 | break; |
950 | default: | 950 | default: |
951 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); | 951 | qDebug("KSM::slotSyncMenu: invalid apptype selected"); |
952 | break; | 952 | break; |
953 | 953 | ||
954 | } | 954 | } |
955 | } | 955 | } |
956 | 956 | ||
957 | void KSyncManager::syncSharp() | 957 | void KSyncManager::syncSharp() |
958 | { | 958 | { |
959 | 959 | ||
960 | if ( ! syncExternalApplication("sharp") ) | 960 | if ( ! syncExternalApplication("sharp") ) |
961 | qDebug("KSM::ERROR sync sharp "); | 961 | qDebug("KSM::ERROR sync sharp "); |
962 | } | 962 | } |
963 | 963 | ||
964 | bool KSyncManager::syncExternalApplication(QString resource) | 964 | bool KSyncManager::syncExternalApplication(QString resource) |
965 | { | 965 | { |
966 | 966 | ||
967 | emit save(); | 967 | emit save(); |
968 | 968 | ||
969 | if ( mAskForPreferences ) | 969 | if ( mAskForPreferences ) |
970 | if ( !edit_sync_options()) { | 970 | if ( !edit_sync_options()) { |
971 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 971 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
972 | return false; | 972 | return false; |
973 | } | 973 | } |
974 | 974 | ||
975 | qDebug("KSM::Sync extern %s", resource.latin1()); | 975 | qDebug("KSM::Sync extern %s", resource.latin1()); |
976 | 976 | ||
977 | bool syncOK = mImplementation->syncExternal(this, resource); | 977 | bool syncOK = mImplementation->syncExternal(this, resource); |
978 | 978 | ||
979 | return syncOK; | 979 | return syncOK; |
980 | 980 | ||
981 | } | 981 | } |
982 | 982 | ||
983 | void KSyncManager::syncPhone() | 983 | void KSyncManager::syncPhone() |
984 | { | 984 | { |
985 | 985 | ||
986 | syncExternalApplication("phone"); | 986 | syncExternalApplication("phone"); |
987 | 987 | ||
988 | } | 988 | } |
989 | 989 | ||
990 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 990 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
991 | { | 991 | { |
992 | if (!bar->isVisible()) | 992 | if (!bar->isVisible()) |
993 | { | 993 | { |
994 | bar->setCaption (caption); | 994 | bar->setCaption (caption); |
995 | bar->setTotalSteps ( total ) ; | 995 | bar->setTotalSteps ( total ) ; |
996 | bar->show(); | 996 | bar->show(); |
997 | } | 997 | } |
998 | bar->raise(); | 998 | bar->raise(); |
999 | bar->setProgress( percentage ); | 999 | bar->setProgress( percentage ); |
1000 | qApp->processEvents(); | 1000 | qApp->processEvents(); |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | void KSyncManager::hideProgressBar() | 1003 | void KSyncManager::hideProgressBar() |
1004 | { | 1004 | { |
1005 | bar->hide(); | 1005 | bar->hide(); |
1006 | qApp->processEvents(); | 1006 | qApp->processEvents(); |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | bool KSyncManager::isProgressBarCanceled() | 1009 | bool KSyncManager::isProgressBarCanceled() |
1010 | { | 1010 | { |
1011 | return !bar->isVisible(); | 1011 | return !bar->isVisible(); |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | QString KSyncManager::syncFileName() | 1014 | QString KSyncManager::syncFileName() |
1015 | { | 1015 | { |
1016 | 1016 | ||
1017 | QString fn = "tempfile"; | 1017 | QString fn = "tempfile"; |
1018 | switch(mTargetApp) | 1018 | switch(mTargetApp) |
1019 | { | 1019 | { |
1020 | case (KAPI): | 1020 | case (KAPI): |
1021 | fn = "tempsyncab.vcf"; | 1021 | fn = "tempsyncab.vcf"; |
1022 | break; | 1022 | break; |
1023 | case (KOPI): | 1023 | case (KOPI): |
1024 | fn = "tempsynccal.ics"; | 1024 | fn = "tempsynccal.ics"; |
1025 | break; | 1025 | break; |
1026 | case (PWMPI): | 1026 | case (PWMPI): |
1027 | fn = "tempsyncpw.pwm"; | 1027 | fn = "tempsyncpw.pwm"; |
1028 | break; | 1028 | break; |
1029 | default: | 1029 | default: |
1030 | break; | 1030 | break; |
1031 | } | 1031 | } |
1032 | #ifdef _WIN32_ | 1032 | #ifdef _WIN32_ |
1033 | return locateLocal( "tmp", fn ); | 1033 | return locateLocal( "tmp", fn ); |
1034 | #else | 1034 | #else |
1035 | return (QString( "/tmp/" )+ fn ); | 1035 | return (QString( "/tmp/" )+ fn ); |
1036 | #endif | 1036 | #endif |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | void KSyncManager::syncPi() | 1039 | void KSyncManager::syncPi() |
1040 | { | 1040 | { |
1041 | mIsKapiFile = true; | 1041 | mIsKapiFile = true; |
1042 | mPisyncFinished = false; | 1042 | mPisyncFinished = false; |
1043 | qApp->processEvents(); | 1043 | qApp->processEvents(); |
1044 | if ( mAskForPreferences ) | 1044 | if ( mAskForPreferences ) |
1045 | if ( !edit_pisync_options()) { | 1045 | if ( !edit_pisync_options()) { |
1046 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1046 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1047 | return; | 1047 | return; |
1048 | } | 1048 | } |
1049 | bool ok; | 1049 | bool ok; |
1050 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1050 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1051 | if ( ! ok ) { | 1051 | if ( ! ok ) { |
1052 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1052 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1053 | return; | 1053 | return; |
1054 | } | 1054 | } |
1055 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1055 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1056 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1056 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1057 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | ||
1058 | commandSocket->readFile( syncFileName() ); | 1057 | commandSocket->readFile( syncFileName() ); |
1059 | } | 1058 | } |
1060 | 1059 | ||
1061 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1060 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1062 | { | 1061 | { |
1063 | //enum { success, errorW, errorR, quiet }; | 1062 | //enum { success, errorW, errorR, quiet }; |
1064 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1063 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1065 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1066 | delete s; | 1065 | delete s; |
1067 | if ( state == KCommandSocket::errorR ) { | 1066 | if ( state == KCommandSocket::errorR ) { |
1068 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1067 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1069 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1068 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1070 | commandSocket->sendStop(); | 1069 | commandSocket->sendStop(); |
1071 | } | 1070 | } |
1072 | mPisyncFinished = true; | 1071 | mPisyncFinished = true; |
1073 | return; | 1072 | return; |
1074 | 1073 | ||
1075 | } else if ( state == KCommandSocket::errorW ) { | 1074 | } else if ( state == KCommandSocket::errorW ) { |
1076 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1075 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1077 | mPisyncFinished = true; | 1076 | mPisyncFinished = true; |
1078 | 1077 | ||
1079 | } else if ( state == KCommandSocket::successR ) { | 1078 | } else if ( state == KCommandSocket::successR ) { |
1080 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1079 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1081 | 1080 | ||
1082 | } else if ( state == KCommandSocket::successW ) { | 1081 | } else if ( state == KCommandSocket::successW ) { |
1083 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1082 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1084 | mPisyncFinished = true; | 1083 | mPisyncFinished = true; |
1085 | } | 1084 | } |
1086 | 1085 | ||
1087 | delete s; | 1086 | delete s; |
1088 | } | 1087 | } |
1089 | 1088 | ||
1090 | void KSyncManager::readFileFromSocket() | 1089 | void KSyncManager::readFileFromSocket() |
1091 | { | 1090 | { |
1092 | QString fileName = syncFileName(); | 1091 | QString fileName = syncFileName(); |
1093 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1092 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1094 | if ( ! syncWithFile( fileName , true ) ) { | 1093 | if ( ! syncWithFile( fileName , true ) ) { |
1095 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1094 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1096 | mPisyncFinished = true; | 1095 | mPisyncFinished = true; |
1097 | return; | 1096 | return; |
1098 | } | 1097 | } |
1099 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1098 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1100 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1099 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1101 | if ( mWriteBackFile ) | 1100 | if ( mWriteBackFile ) |
1102 | commandSocket->writeFile( fileName ); | 1101 | commandSocket->writeFile( fileName ); |
1103 | else { | 1102 | else { |
1104 | commandSocket->sendStop(); | 1103 | commandSocket->sendStop(); |
1105 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1104 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1106 | mPisyncFinished = true; | 1105 | mPisyncFinished = true; |
1107 | } | 1106 | } |
1108 | } | 1107 | } |
1109 | 1108 | ||
1110 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1109 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1111 | { | 1110 | { |
1112 | mPassWord = pw; | 1111 | mPassWord = pw; |
1113 | mSocket = 0; | 1112 | mSocket = 0; |
1114 | mSyncActionDialog = 0; | 1113 | mSyncActionDialog = 0; |
1115 | blockRC = false; | 1114 | blockRC = false; |
1116 | }; | 1115 | }; |
1117 | 1116 | ||
1118 | void KServerSocket::newConnection ( int socket ) | 1117 | void KServerSocket::newConnection ( int socket ) |
1119 | { | 1118 | { |
1120 | // qDebug("KServerSocket:New connection %d ", socket); | 1119 | // qDebug("KServerSocket:New connection %d ", socket); |
1121 | if ( mSocket ) { | 1120 | if ( mSocket ) { |
1122 | qDebug("KSS::newConnection Socket deleted! "); | 1121 | qDebug("KSS::newConnection Socket deleted! "); |
1123 | delete mSocket; | 1122 | delete mSocket; |
1124 | mSocket = 0; | 1123 | mSocket = 0; |
1125 | } | 1124 | } |
1126 | mSocket = new QSocket( this ); | 1125 | mSocket = new QSocket( this ); |
1127 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1126 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1128 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1127 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1129 | mSocket->setSocket( socket ); | 1128 | mSocket->setSocket( socket ); |
1130 | } | 1129 | } |
1131 | 1130 | ||
1132 | void KServerSocket::discardClient() | 1131 | void KServerSocket::discardClient() |
1133 | { | 1132 | { |
1134 | //qDebug(" KServerSocket::discardClient()"); | 1133 | //qDebug(" KServerSocket::discardClient()"); |
1135 | if ( mSocket ) { | 1134 | if ( mSocket ) { |
1136 | delete mSocket; | 1135 | delete mSocket; |
1137 | mSocket = 0; | 1136 | mSocket = 0; |
1138 | } | 1137 | } |
1139 | //emit endConnect(); | 1138 | //emit endConnect(); |
1140 | } | 1139 | } |
1141 | void KServerSocket::readClient() | 1140 | void KServerSocket::readClient() |
1142 | { | 1141 | { |
1143 | if ( blockRC ) | 1142 | if ( blockRC ) |
1144 | return; | 1143 | return; |
1145 | if ( mSocket == 0 ) { | 1144 | if ( mSocket == 0 ) { |
1146 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1145 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1147 | return; | 1146 | return; |
1148 | } | 1147 | } |
1149 | //qDebug("KServerSocket::readClient()"); | 1148 | //qDebug("KServerSocket::readClient()"); |
1150 | if ( mSocket->canReadLine() ) { | 1149 | if ( mSocket->canReadLine() ) { |
1151 | QString line = mSocket->readLine(); | 1150 | QString line = mSocket->readLine(); |
1152 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1151 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1153 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1152 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1154 | if ( tokens[0] == "GET" ) { | 1153 | if ( tokens[0] == "GET" ) { |
1155 | if ( tokens[1] == mPassWord ) { | 1154 | if ( tokens[1] == mPassWord ) { |
1156 | //emit sendFile( mSocket ); | 1155 | //emit sendFile( mSocket ); |
1157 | bool ok = false; | 1156 | bool ok = false; |
1158 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1157 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1159 | if ( ok ) { | 1158 | if ( ok ) { |
1160 | KSyncManager::mRequestedSyncEvent = dt; | 1159 | KSyncManager::mRequestedSyncEvent = dt; |
1161 | } | 1160 | } |
1162 | else | 1161 | else |
1163 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1162 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1164 | send_file(); | 1163 | send_file(); |
1165 | } | 1164 | } |
1166 | else { | 1165 | else { |
1167 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1166 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1168 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1169 | } | 1168 | } |
1170 | } | 1169 | } |
1171 | if ( tokens[0] == "PUT" ) { | 1170 | if ( tokens[0] == "PUT" ) { |
1172 | if ( tokens[1] == mPassWord ) { | 1171 | if ( tokens[1] == mPassWord ) { |
1173 | //emit getFile( mSocket ); | 1172 | //emit getFile( mSocket ); |
1174 | blockRC = true; | 1173 | blockRC = true; |
1175 | get_file(); | 1174 | get_file(); |
1176 | } | 1175 | } |
1177 | else { | 1176 | else { |
1178 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1177 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1179 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1178 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1180 | } | 1179 | } |
1181 | } | 1180 | } |
1182 | if ( tokens[0] == "STOP" ) { | 1181 | if ( tokens[0] == "STOP" ) { |
1183 | //emit endConnect(); | 1182 | //emit endConnect(); |
1184 | end_connect(); | 1183 | end_connect(); |
1185 | } | 1184 | } |
1186 | } | 1185 | } |
1187 | } | 1186 | } |
1188 | void KServerSocket::end_connect() | 1187 | void KServerSocket::end_connect() |
1189 | { | 1188 | { |
1190 | delete mSyncActionDialog; | 1189 | delete mSyncActionDialog; |
1191 | mSyncActionDialog = 0; | 1190 | mSyncActionDialog = 0; |
1192 | } | 1191 | } |
1193 | void KServerSocket::send_file() | 1192 | void KServerSocket::send_file() |
1194 | { | 1193 | { |
1195 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1194 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1196 | if ( mSyncActionDialog ) | 1195 | if ( mSyncActionDialog ) |
1197 | delete mSyncActionDialog; | 1196 | delete mSyncActionDialog; |
1198 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1197 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1199 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1198 | 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 ); | 1199 | 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 ); | 1200 | label->setAlignment ( Qt::AlignHCenter ); |
1202 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1201 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1203 | lay->addWidget( label); | 1202 | lay->addWidget( label); |
1204 | lay->setMargin(7); | 1203 | lay->setMargin(7); |
1205 | lay->setSpacing(7); | 1204 | lay->setSpacing(7); |
1206 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1205 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1207 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1206 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1208 | if ( secs < 0 ) | 1207 | if ( secs < 0 ) |
1209 | secs = secs * (-1); | 1208 | secs = secs * (-1); |
1210 | if ( secs > 30 ) | 1209 | if ( secs > 30 ) |
1211 | //if ( true ) | 1210 | //if ( true ) |
1212 | { | 1211 | { |
1213 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1212 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1214 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1213 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1215 | label->setAlignment ( Qt::AlignHCenter ); | 1214 | label->setAlignment ( Qt::AlignHCenter ); |
1216 | lay->addWidget( label); | 1215 | lay->addWidget( label); |
1217 | if ( secs > 180 ) | 1216 | if ( secs > 180 ) |
1218 | { | 1217 | { |
1219 | if ( secs > 300 ) { | 1218 | 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!"))) { | 1219 | 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("KSS::Sync cancelled ,cs"); | 1220 | qDebug("KSS::Sync cancelled ,cs"); |
1222 | return ; | 1221 | return ; |
1223 | } | 1222 | } |
1224 | } | 1223 | } |
1225 | QFont f = label->font(); | 1224 | QFont f = label->font(); |
1226 | f.setPointSize ( f.pointSize() *2 ); | 1225 | f.setPointSize ( f.pointSize() *2 ); |
1227 | f. setBold (true ); | 1226 | f. setBold (true ); |
1228 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1227 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1229 | label->setFont( f ); | 1228 | label->setFont( f ); |
1230 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1229 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1231 | label->setText( warning ); | 1230 | label->setText( warning ); |
1232 | label->setAlignment ( Qt::AlignHCenter ); | 1231 | label->setAlignment ( Qt::AlignHCenter ); |
1233 | lay->addWidget( label); | 1232 | lay->addWidget( label); |
1234 | mSyncActionDialog->setFixedSize( 230, 300); | 1233 | mSyncActionDialog->setFixedSize( 230, 300); |
1235 | } else { | 1234 | } else { |
1236 | mSyncActionDialog->setFixedSize( 230, 200); | 1235 | mSyncActionDialog->setFixedSize( 230, 200); |
1237 | } | 1236 | } |
1238 | } else { | 1237 | } else { |
1239 | mSyncActionDialog->setFixedSize( 230, 120); | 1238 | mSyncActionDialog->setFixedSize( 230, 120); |
1240 | } | 1239 | } |
1241 | } else | 1240 | } else |
1242 | mSyncActionDialog->setFixedSize( 230, 120); | 1241 | mSyncActionDialog->setFixedSize( 230, 120); |
1243 | mSyncActionDialog->show(); | 1242 | mSyncActionDialog->show(); |
1244 | mSyncActionDialog->raise(); | 1243 | mSyncActionDialog->raise(); |
1245 | emit request_file(); | 1244 | emit request_file(); |
1246 | qApp->processEvents(); | 1245 | qApp->processEvents(); |
1247 | QString fileName = mFileName; | 1246 | QString fileName = mFileName; |
1248 | QFile file( fileName ); | 1247 | QFile file( fileName ); |
1249 | if (!file.open( IO_ReadOnly ) ) { | 1248 | if (!file.open( IO_ReadOnly ) ) { |
1250 | delete mSyncActionDialog; | 1249 | delete mSyncActionDialog; |
1251 | mSyncActionDialog = 0; | 1250 | mSyncActionDialog = 0; |
1252 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); | 1251 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); |
1253 | mSocket->close(); | 1252 | mSocket->close(); |
1254 | if ( mSocket->state() == QSocket::Idle ) | 1253 | if ( mSocket->state() == QSocket::Idle ) |
1255 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1254 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1256 | return ; | 1255 | return ; |
1257 | 1256 | ||
1258 | } | 1257 | } |
1259 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1260 | QTextStream ts( &file ); | 1259 | QTextStream ts( &file ); |
1261 | ts.setEncoding( QTextStream::Latin1 ); | 1260 | ts.setEncoding( QTextStream::Latin1 ); |
1262 | 1261 | ||
1263 | QTextStream os( mSocket ); | 1262 | QTextStream os( mSocket ); |
1264 | os.setEncoding( QTextStream::Latin1 ); | 1263 | os.setEncoding( QTextStream::Latin1 ); |
1265 | while ( ! ts.atEnd() ) { | 1264 | while ( ! ts.atEnd() ) { |
1266 | os << ts.readLine() << "\r\n"; | 1265 | os << ts.readLine() << "\r\n\r\n"; |
1267 | } | 1266 | } |
1268 | //os << ts.read(); | 1267 | //os << ts.read(); |
1269 | file.close(); | 1268 | file.close(); |
1270 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1269 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1271 | mSocket->close(); | 1270 | mSocket->close(); |
1272 | if ( mSocket->state() == QSocket::Idle ) | 1271 | if ( mSocket->state() == QSocket::Idle ) |
1273 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1272 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1274 | } | 1273 | } |
1275 | void KServerSocket::get_file() | 1274 | void KServerSocket::get_file() |
1276 | { | 1275 | { |
1277 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1276 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1278 | 1277 | ||
1279 | piTime.start(); | 1278 | piTime.start(); |
1280 | piFileString = ""; | 1279 | piFileString = ""; |
1281 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1280 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1282 | } | 1281 | } |
1283 | 1282 | ||
1284 | 1283 | ||
1285 | void KServerSocket::readBackFileFromSocket() | 1284 | void KServerSocket::readBackFileFromSocket() |
1286 | { | 1285 | { |
1287 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1286 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1288 | while ( mSocket->canReadLine () ) { | 1287 | while ( mSocket->canReadLine () ) { |
1289 | piTime.restart(); | 1288 | piTime.restart(); |
1290 | QString line = mSocket->readLine (); | 1289 | QString line = mSocket->readLine (); |
1291 | piFileString += line; | 1290 | piFileString += line; |
1292 | //qDebug("readline: %s ", line.latin1()); | 1291 | //qDebug("readline: %s ", line.latin1()); |
1293 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1292 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1294 | 1293 | ||
1295 | } | 1294 | } |
1296 | if ( piTime.elapsed () < 3000 ) { | 1295 | if ( piTime.elapsed () < 3000 ) { |
1297 | // wait for more | 1296 | // wait for more |
1298 | //qDebug("waitformore "); | 1297 | //qDebug("waitformore "); |
1299 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1298 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1300 | return; | 1299 | return; |
1301 | } | 1300 | } |
1302 | QString fileName = mFileName; | 1301 | QString fileName = mFileName; |
1303 | QFile file ( fileName ); | 1302 | QFile file ( fileName ); |
1304 | if (!file.open( IO_WriteOnly ) ) { | 1303 | if (!file.open( IO_WriteOnly ) ) { |
1305 | delete mSyncActionDialog; | 1304 | delete mSyncActionDialog; |
1306 | mSyncActionDialog = 0; | 1305 | mSyncActionDialog = 0; |
1307 | qDebug("KSS:Error open read back file "); | 1306 | qDebug("KSS:Error open read back file "); |
1308 | piFileString = ""; | 1307 | piFileString = ""; |
1309 | emit file_received( false ); | 1308 | emit file_received( false ); |
1310 | blockRC = false; | 1309 | blockRC = false; |
1311 | return ; | 1310 | return ; |
1312 | 1311 | ||
1313 | } | 1312 | } |
1314 | 1313 | ||
1315 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1314 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1316 | QTextStream ts ( &file ); | 1315 | QTextStream ts ( &file ); |
1317 | ts.setEncoding( QTextStream::Latin1 ); | 1316 | ts.setEncoding( QTextStream::Latin1 ); |
1318 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1317 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1319 | ts << piFileString; | 1318 | ts << piFileString; |
1320 | mSocket->close(); | 1319 | mSocket->close(); |
1321 | if ( mSocket->state() == QSocket::Idle ) | 1320 | if ( mSocket->state() == QSocket::Idle ) |
1322 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1321 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1323 | file.close(); | 1322 | file.close(); |
1324 | piFileString = ""; | 1323 | piFileString = ""; |
1325 | emit file_received( true ); | 1324 | emit file_received( true ); |
1326 | delete mSyncActionDialog; | 1325 | delete mSyncActionDialog; |
1327 | mSyncActionDialog = 0; | 1326 | mSyncActionDialog = 0; |
1328 | blockRC = false; | 1327 | blockRC = false; |
1329 | 1328 | ||
1330 | } | 1329 | } |
1331 | 1330 | ||
1332 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1331 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1333 | { | 1332 | { |
1334 | mPassWord = password; | 1333 | mPassWord = password; |
1335 | mSocket = 0; | 1334 | mSocket = 0; |
1335 | mFirst = false; | ||
1336 | mPort = port; | 1336 | mPort = port; |
1337 | mHost = host; | 1337 | mHost = host; |
1338 | 1338 | tlw = cap; | |
1339 | mRetVal = quiet; | 1339 | mRetVal = quiet; |
1340 | mTimerSocket = new QTimer ( this ); | 1340 | mTimerSocket = new QTimer ( this ); |
1341 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1341 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1342 | } | 1342 | } |
1343 | void KCommandSocket::sendFileRequest() | ||
1344 | { | ||
1345 | if ( tlw ) | ||
1346 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | ||
1347 | mTimerSocket->start( 300000 ); | ||
1348 | QTextStream os( mSocket ); | ||
1349 | os.setEncoding( QTextStream::Latin1 ); | ||
1350 | |||
1351 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1352 | os << "GET " << mPassWord << curDt <<"\r\n\r\n"; | ||
1353 | } | ||
1354 | |||
1343 | void KCommandSocket::readFile( QString fn ) | 1355 | void KCommandSocket::readFile( QString fn ) |
1344 | { | 1356 | { |
1345 | if ( !mSocket ) { | 1357 | if ( !mSocket ) { |
1346 | mSocket = new QSocket( this ); | 1358 | mSocket = new QSocket( this ); |
1347 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1359 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1348 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1360 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1361 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | ||
1349 | } | 1362 | } |
1350 | mFileString = ""; | 1363 | mFileString = ""; |
1351 | mFileName = fn; | 1364 | mFileName = fn; |
1352 | mFirst = true; | 1365 | mFirst = true; |
1366 | if ( tlw ) | ||
1367 | tlw->setCaption( i18n("Trying to connect to remote...") ); | ||
1353 | mSocket->connectToHost( mHost, mPort ); | 1368 | mSocket->connectToHost( mHost, mPort ); |
1354 | QTextStream os( mSocket ); | 1369 | qDebug("KSS: Waiting for connection"); |
1355 | os.setEncoding( QTextStream::Latin1 ); | 1370 | mTimerSocket->start( 20000 ); |
1356 | |||
1357 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1358 | os << "GET " << mPassWord << curDt <<"\r\n"; | ||
1359 | mTimerSocket->start( 300000 ); | ||
1360 | } | 1371 | } |
1361 | 1372 | ||
1362 | void KCommandSocket::writeFile( QString fileName ) | 1373 | void KCommandSocket::writeFile( QString fileName ) |
1363 | { | 1374 | { |
1364 | if ( !mSocket ) { | 1375 | if ( !mSocket ) { |
1365 | mSocket = new QSocket( this ); | 1376 | mSocket = new QSocket( this ); |
1366 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1377 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1367 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1378 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1368 | } | 1379 | } |
1369 | mFileName = fileName ; | 1380 | mFileName = fileName ; |
1370 | mSocket->connectToHost( mHost, mPort ); | 1381 | mSocket->connectToHost( mHost, mPort ); |
1371 | } | 1382 | } |
1372 | void KCommandSocket::writeFileToSocket() | 1383 | void KCommandSocket::writeFileToSocket() |
1373 | { | 1384 | { |
1374 | QFile file2( mFileName ); | 1385 | QFile file2( mFileName ); |
1375 | if (!file2.open( IO_ReadOnly ) ) { | 1386 | if (!file2.open( IO_ReadOnly ) ) { |
1376 | mRetVal= errorW; | 1387 | mRetVal= errorW; |
1377 | mSocket->close(); | 1388 | mSocket->close(); |
1378 | if ( mSocket->state() == QSocket::Idle ) | 1389 | if ( mSocket->state() == QSocket::Idle ) |
1379 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1390 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1380 | return ; | 1391 | return ; |
1381 | } | 1392 | } |
1382 | QTextStream ts2( &file2 ); | 1393 | QTextStream ts2( &file2 ); |
1383 | ts2.setEncoding( QTextStream::Latin1 ); | 1394 | ts2.setEncoding( QTextStream::Latin1 ); |
1384 | QTextStream os2( mSocket ); | 1395 | QTextStream os2( mSocket ); |
1385 | os2.setEncoding( QTextStream::Latin1 ); | 1396 | os2.setEncoding( QTextStream::Latin1 ); |
1386 | os2 << "PUT " << mPassWord << "\r\n";; | 1397 | os2 << "PUT " << mPassWord << "\r\n\r\n";; |
1387 | while ( ! ts2.atEnd() ) { | 1398 | while ( ! ts2.atEnd() ) { |
1388 | os2 << ts2.readLine() << "\r\n"; | 1399 | os2 << ts2.readLine() << "\r\n\r\n"; |
1389 | } | 1400 | } |
1390 | mRetVal= successW; | 1401 | mRetVal= successW; |
1391 | file2.close(); | 1402 | file2.close(); |
1392 | mSocket->close(); | 1403 | mSocket->close(); |
1393 | if ( mSocket->state() == QSocket::Idle ) | 1404 | if ( mSocket->state() == QSocket::Idle ) |
1394 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1405 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1395 | } | 1406 | } |
1396 | void KCommandSocket::sendStop() | 1407 | void KCommandSocket::sendStop() |
1397 | { | 1408 | { |
1398 | if ( !mSocket ) { | 1409 | if ( !mSocket ) { |
1399 | mSocket = new QSocket( this ); | 1410 | mSocket = new QSocket( this ); |
1400 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1411 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1401 | } | 1412 | } |
1402 | mSocket->connectToHost( mHost, mPort ); | 1413 | mSocket->connectToHost( mHost, mPort ); |
1403 | QTextStream os2( mSocket ); | 1414 | QTextStream os2( mSocket ); |
1404 | os2.setEncoding( QTextStream::Latin1 ); | 1415 | os2.setEncoding( QTextStream::Latin1 ); |
1405 | os2 << "STOP\r\n"; | 1416 | os2 << "STOP\r\n\r\n"; |
1406 | mSocket->close(); | 1417 | mSocket->close(); |
1407 | if ( mSocket->state() == QSocket::Idle ) | 1418 | if ( mSocket->state() == QSocket::Idle ) |
1408 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1419 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1409 | } | 1420 | } |
1410 | 1421 | ||
1411 | void KCommandSocket::startReadFileFromSocket() | 1422 | void KCommandSocket::startReadFileFromSocket() |
1412 | { | 1423 | { |
1413 | if ( ! mFirst ) | 1424 | if ( ! mFirst ) |
1414 | return; | 1425 | return; |
1415 | mFirst = false; | 1426 | mFirst = false; |
1416 | mTimerSocket->stop(); | 1427 | mTimerSocket->stop(); |
1417 | mFileString = ""; | 1428 | mFileString = ""; |
1418 | mTime.start(); | 1429 | mTime.start(); |
1419 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1430 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1420 | 1431 | ||
1421 | } | 1432 | } |
1422 | void KCommandSocket::readFileFromSocket() | 1433 | void KCommandSocket::readFileFromSocket() |
1423 | { | 1434 | { |
1424 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1435 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1425 | while ( mSocket->canReadLine () ) { | 1436 | while ( mSocket->canReadLine () ) { |
1426 | mTime.restart(); | 1437 | mTime.restart(); |
1427 | QString line = mSocket->readLine (); | 1438 | QString line = mSocket->readLine (); |
1428 | mFileString += line; | 1439 | mFileString += line; |
1429 | //qDebug("readline: %s ", line.latin1()); | 1440 | //qDebug("readline: %s ", line.latin1()); |
1430 | } | 1441 | } |
1431 | if ( mTime.elapsed () < 3000 ) { | 1442 | if ( mTime.elapsed () < 3000 ) { |
1432 | // wait for more | 1443 | // wait for more |
1433 | //qDebug("waitformore "); | 1444 | //qDebug("waitformore "); |
1434 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1445 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1435 | return; | 1446 | return; |
1436 | } | 1447 | } |
1437 | QString fileName = mFileName; | 1448 | QString fileName = mFileName; |
1438 | QFile file ( fileName ); | 1449 | QFile file ( fileName ); |
1439 | if (!file.open( IO_WriteOnly ) ) { | 1450 | if (!file.open( IO_WriteOnly ) ) { |
1440 | mFileString = ""; | 1451 | mFileString = ""; |
1441 | mRetVal = errorR; | 1452 | mRetVal = errorR; |
1442 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1453 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1443 | deleteSocket(); | 1454 | deleteSocket(); |
1444 | return ; | 1455 | return ; |
1445 | 1456 | ||
1446 | } | 1457 | } |
1447 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1458 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1448 | QTextStream ts ( &file ); | 1459 | QTextStream ts ( &file ); |
1449 | ts.setEncoding( QTextStream::Latin1 ); | 1460 | ts.setEncoding( QTextStream::Latin1 ); |
1450 | ts << mFileString; | 1461 | ts << mFileString; |
1451 | file.close(); | 1462 | file.close(); |
1452 | mFileString = ""; | 1463 | mFileString = ""; |
1453 | mRetVal = successR; | 1464 | mRetVal = successR; |
1454 | mSocket->close(); | 1465 | mSocket->close(); |
1455 | // if state is not idle, deleteSocket(); is called via | 1466 | // if state is not idle, deleteSocket(); is called via |
1456 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1467 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1457 | if ( mSocket->state() == QSocket::Idle ) | 1468 | if ( mSocket->state() == QSocket::Idle ) |
1458 | deleteSocket(); | 1469 | deleteSocket(); |
1459 | } | 1470 | } |
1460 | 1471 | ||
1461 | void KCommandSocket::deleteSocket() | 1472 | void KCommandSocket::deleteSocket() |
1462 | { | 1473 | { |
1463 | //qDebug("KCommandSocket::deleteSocket() "); | 1474 | //qDebug("KCommandSocket::deleteSocket() "); |
1464 | if ( mTimerSocket->isActive () ) { | 1475 | if ( mTimerSocket->isActive () ) { |
1465 | mTimerSocket->stop(); | 1476 | mTimerSocket->stop(); |
1466 | mRetVal = errorTO; | 1477 | mRetVal = errorTO; |
1467 | qDebug("KCS::Connection to remote host timed out"); | 1478 | qDebug("KCS::Connection to remote host timed out"); |
1468 | if ( mSocket ) { | 1479 | if ( mSocket ) { |
1469 | mSocket->close(); | 1480 | mSocket->close(); |
1470 | //if ( mSocket->state() == QSocket::Idle ) | 1481 | //if ( mSocket->state() == QSocket::Idle ) |
1471 | // deleteSocket(); | 1482 | // deleteSocket(); |
1472 | delete mSocket; | 1483 | delete mSocket; |
1473 | mSocket = 0; | 1484 | mSocket = 0; |
1474 | } | 1485 | } |
1475 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1486 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); |
1476 | emit commandFinished( this, mRetVal ); | 1487 | emit commandFinished( this, mRetVal ); |
1477 | return; | 1488 | return; |
1478 | } | 1489 | } |
1479 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1490 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1480 | if ( mSocket) | 1491 | if ( mSocket) |
1481 | delete mSocket; | 1492 | delete mSocket; |
1482 | mSocket = 0; | 1493 | mSocket = 0; |
1483 | emit commandFinished( this, mRetVal ); | 1494 | emit commandFinished( this, mRetVal ); |
1484 | } | 1495 | } |