summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 01309d5..b3e266a 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -968,207 +968,209 @@ void KServerSocket::send_file()
968 mSocket->close(); 968 mSocket->close();
969 if ( mSocket->state() == QSocket::Idle ) 969 if ( mSocket->state() == QSocket::Idle )
970 QTimer::singleShot( 10, this , SLOT ( discardClient())); 970 QTimer::singleShot( 10, this , SLOT ( discardClient()));
971} 971}
972void KServerSocket::get_file() 972void KServerSocket::get_file()
973{ 973{
974 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 974 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
975 975
976 piTime.start(); 976 piTime.start();
977 piFileString = ""; 977 piFileString = "";
978 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 978 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
979} 979}
980 980
981 981
982void KServerSocket::readBackFileFromSocket() 982void KServerSocket::readBackFileFromSocket()
983{ 983{
984 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 984 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
985 while ( mSocket->canReadLine () ) { 985 while ( mSocket->canReadLine () ) {
986 piTime.restart(); 986 piTime.restart();
987 QString line = mSocket->readLine (); 987 QString line = mSocket->readLine ();
988 piFileString += line; 988 piFileString += line;
989 //qDebug("readline: %s ", line.latin1()); 989 //qDebug("readline: %s ", line.latin1());
990 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 990 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
991 991
992 } 992 }
993 if ( piTime.elapsed () < 3000 ) { 993 if ( piTime.elapsed () < 3000 ) {
994 // wait for more 994 // wait for more
995 //qDebug("waitformore "); 995 //qDebug("waitformore ");
996 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 996 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
997 return; 997 return;
998 } 998 }
999 QString fileName = mFileName; 999 QString fileName = mFileName;
1000 QFile file ( fileName ); 1000 QFile file ( fileName );
1001 if (!file.open( IO_WriteOnly ) ) { 1001 if (!file.open( IO_WriteOnly ) ) {
1002 delete mSyncActionDialog; 1002 delete mSyncActionDialog;
1003 mSyncActionDialog = 0; 1003 mSyncActionDialog = 0;
1004 qDebug("error open cal file "); 1004 qDebug("error open cal file ");
1005 piFileString = ""; 1005 piFileString = "";
1006 emit file_received( false ); 1006 emit file_received( false );
1007 blockRC = false; 1007 blockRC = false;
1008 return ; 1008 return ;
1009 1009
1010 } 1010 }
1011 1011
1012 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1012 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1013 QTextStream ts ( &file ); 1013 QTextStream ts ( &file );
1014 ts.setEncoding( QTextStream::Latin1 ); 1014 ts.setEncoding( QTextStream::Latin1 );
1015 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1015 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1016 ts << piFileString; 1016 ts << piFileString;
1017 mSocket->close(); 1017 mSocket->close();
1018 if ( mSocket->state() == QSocket::Idle ) 1018 if ( mSocket->state() == QSocket::Idle )
1019 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1019 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1020 file.close(); 1020 file.close();
1021 delete mSyncActionDialog; 1021 delete mSyncActionDialog;
1022 mSyncActionDialog = 0; 1022 mSyncActionDialog = 0;
1023 piFileString = ""; 1023 piFileString = "";
1024 blockRC = false; 1024 blockRC = false;
1025 emit file_received( true ); 1025 emit file_received( true );
1026 1026
1027} 1027}
1028 1028
1029KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1029KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1030{ 1030{
1031 mPassWord = password; 1031 mPassWord = password;
1032 mSocket = 0; 1032 mSocket = 0;
1033 mPort = port; 1033 mPort = port;
1034 mHost = host; 1034 mHost = host;
1035 1035
1036 mRetVal = quiet; 1036 mRetVal = quiet;
1037 mTimerSocket = new QTimer ( this ); 1037 mTimerSocket = new QTimer ( this );
1038 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1038 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1039} 1039}
1040void KCommandSocket::readFile( QString fn ) 1040void KCommandSocket::readFile( QString fn )
1041{ 1041{
1042 if ( !mSocket ) { 1042 if ( !mSocket ) {
1043 mSocket = new QSocket( this ); 1043 mSocket = new QSocket( this );
1044 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1044 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1045 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1045 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1046 } 1046 }
1047 mFileString = ""; 1047 mFileString = "";
1048 mFileName = fn; 1048 mFileName = fn;
1049 mFirst = true; 1049 mFirst = true;
1050 mSocket->connectToHost( mHost, mPort ); 1050 mSocket->connectToHost( mHost, mPort );
1051 QTextStream os( mSocket ); 1051 QTextStream os( mSocket );
1052 os.setEncoding( QTextStream::Latin1 ); 1052 os.setEncoding( QTextStream::Latin1 );
1053 os << "GET " << mPassWord << "\r\n"; 1053 os << "GET " << mPassWord << "\r\n";
1054 mTimerSocket->start( 10000 ); 1054 mTimerSocket->start( 10000 );
1055} 1055}
1056 1056
1057void KCommandSocket::writeFile( QString fileName ) 1057void KCommandSocket::writeFile( QString fileName )
1058{ 1058{
1059 if ( !mSocket ) { 1059 if ( !mSocket ) {
1060 mSocket = new QSocket( this ); 1060 mSocket = new QSocket( this );
1061 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1061 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1062 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1062 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1063 } 1063 }
1064 mFileName = fileName ; 1064 mFileName = fileName ;
1065 mSocket->connectToHost( mHost, mPort ); 1065 mSocket->connectToHost( mHost, mPort );
1066} 1066}
1067void KCommandSocket::writeFileToSocket() 1067void KCommandSocket::writeFileToSocket()
1068{ 1068{
1069 QFile file2( mFileName ); 1069 QFile file2( mFileName );
1070 if (!file2.open( IO_ReadOnly ) ) { 1070 if (!file2.open( IO_ReadOnly ) ) {
1071 mRetVal= errorW; 1071 mRetVal= errorW;
1072 mSocket->close(); 1072 mSocket->close();
1073 if ( mSocket->state() == QSocket::Idle ) 1073 if ( mSocket->state() == QSocket::Idle )
1074 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1074 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1075 return ; 1075 return ;
1076 } 1076 }
1077 QTextStream ts2( &file2 ); 1077 QTextStream ts2( &file2 );
1078 ts2.setEncoding( QTextStream::Latin1 ); 1078 ts2.setEncoding( QTextStream::Latin1 );
1079 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1080 os2.setEncoding( QTextStream::Latin1 ); 1080 os2.setEncoding( QTextStream::Latin1 );
1081 os2 << "PUT " << mPassWord << "\r\n";; 1081 os2 << "PUT " << mPassWord << "\r\n";;
1082 while ( ! ts2.atEnd() ) { 1082 while ( ! ts2.atEnd() ) {
1083 os2 << ts2.readLine() << "\n"; 1083 os2 << ts2.readLine() << "\n";
1084 } 1084 }
1085 mRetVal= successW; 1085 mRetVal= successW;
1086 file2.close(); 1086 file2.close();
1087 mSocket->close(); 1087 mSocket->close();
1088 if ( mSocket->state() == QSocket::Idle ) 1088 if ( mSocket->state() == QSocket::Idle )
1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1090} 1090}
1091void KCommandSocket::sendStop() 1091void KCommandSocket::sendStop()
1092{ 1092{
1093 if ( !mSocket ) { 1093 if ( !mSocket ) {
1094 mSocket = new QSocket( this ); 1094 mSocket = new QSocket( this );
1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1096 } 1096 }
1097 mSocket->connectToHost( mHost, mPort ); 1097 mSocket->connectToHost( mHost, mPort );
1098 QTextStream os2( mSocket ); 1098 QTextStream os2( mSocket );
1099 os2.setEncoding( QTextStream::Latin1 ); 1099 os2.setEncoding( QTextStream::Latin1 );
1100 os2 << "STOP\r\n"; 1100 os2 << "STOP\r\n";
1101 mSocket->close(); 1101 mSocket->close();
1102 if ( mSocket->state() == QSocket::Idle ) 1102 if ( mSocket->state() == QSocket::Idle )
1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1104} 1104}
1105 1105
1106void KCommandSocket::startReadFileFromSocket() 1106void KCommandSocket::startReadFileFromSocket()
1107{ 1107{
1108 if ( ! mFirst ) 1108 if ( ! mFirst )
1109 return; 1109 return;
1110 mFirst = false; 1110 mFirst = false;
1111 mTimerSocket->stop(); 1111 mTimerSocket->stop();
1112 mFileString = ""; 1112 mFileString = "";
1113 mTime.start(); 1113 mTime.start();
1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1115 1115
1116} 1116}
1117void KCommandSocket::readFileFromSocket() 1117void KCommandSocket::readFileFromSocket()
1118{ 1118{
1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1120 while ( mSocket->canReadLine () ) { 1120 while ( mSocket->canReadLine () ) {
1121 mTime.restart(); 1121 mTime.restart();
1122 QString line = mSocket->readLine (); 1122 QString line = mSocket->readLine ();
1123 mFileString += line; 1123 mFileString += line;
1124 //qDebug("readline: %s ", line.latin1()); 1124 //qDebug("readline: %s ", line.latin1());
1125 } 1125 }
1126 if ( mTime.elapsed () < 3000 ) { 1126 if ( mTime.elapsed () < 3000 ) {
1127 // wait for more 1127 // wait for more
1128 //qDebug("waitformore "); 1128 //qDebug("waitformore ");
1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1130 return; 1130 return;
1131 } 1131 }
1132 QString fileName = mFileName; 1132 QString fileName = mFileName;
1133 QFile file ( fileName ); 1133 QFile file ( fileName );
1134 if (!file.open( IO_WriteOnly ) ) { 1134 if (!file.open( IO_WriteOnly ) ) {
1135 mFileString = ""; 1135 mFileString = "";
1136 mRetVal = errorR; 1136 mRetVal = errorR;
1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1138 deleteSocket(); 1138 deleteSocket();
1139 return ; 1139 return ;
1140 1140
1141 } 1141 }
1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1143 QTextStream ts ( &file ); 1143 QTextStream ts ( &file );
1144 ts.setEncoding( QTextStream::Latin1 ); 1144 ts.setEncoding( QTextStream::Latin1 );
1145 ts << mFileString; 1145 ts << mFileString;
1146 file.close(); 1146 file.close();
1147 mFileString = ""; 1147 mFileString = "";
1148 mRetVal = successR; 1148 mRetVal = successR;
1149 mSocket->close(); 1149 mSocket->close();
1150 // if state is not idle, deleteSocket(); is called via 1150 // if state is not idle, deleteSocket(); is called via
1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1152 if ( mSocket->state() == QSocket::Idle ) 1152 if ( mSocket->state() == QSocket::Idle )
1153 deleteSocket(); 1153 deleteSocket();
1154} 1154}
1155 1155
1156void KCommandSocket::deleteSocket() 1156void KCommandSocket::deleteSocket()
1157{ 1157{
1158 if ( mTimerSocket->isActive () ) { 1158 if ( mTimerSocket->isActive () ) {
1159 mTimerSocket->stop(); 1159 mTimerSocket->stop();
1160 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1161 mRetVal = errorTO; 1160 mRetVal = errorTO;
1162 if ( mSocket ) { 1161 if ( mSocket ) {
1163 mSocket->close(); 1162 mSocket->close();
1164 if ( mSocket->state() == QSocket::Idle ) 1163 if ( mSocket->state() == QSocket::Idle )
1165 deleteSocket(); 1164 deleteSocket();
1166 return; 1165 return;
1167 } 1166 }
1168 } 1167 }
1169 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1168 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1170 if ( mSocket) 1169 if ( mSocket)
1171 delete mSocket; 1170 delete mSocket;
1172 mSocket = 0; 1171 mSocket = 0;
1172 if ( mRetVal == errorTO)
1173 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1174
1173 emit commandFinished( this, mRetVal ); 1175 emit commandFinished( this, mRetVal );
1174} 1176}