summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-11 09:37:01 (UTC)
committer zautrix <zautrix>2004-10-11 09:37:01 (UTC)
commitff475669e0cb65677168d4a29928a6c1d984aa10 (patch) (unidiff)
tree02dd4b6ff9f9c1e1eb177d149d127ac90b693031
parent5ec2ee22f69f6b3d78b505a4a44b6b0deff29645 (diff)
downloadkdepimpi-ff475669e0cb65677168d4a29928a6c1d984aa10.zip
kdepimpi-ff475669e0cb65677168d4a29928a6c1d984aa10.tar.gz
kdepimpi-ff475669e0cb65677168d4a29928a6c1d984aa10.tar.bz2
fix file transmission with sockets
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index df53235..6baa2ee 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -946,97 +946,97 @@ void KServerSocket::readClient()
946 } 946 }
947 if ( tokens[0] == "STOP" ) { 947 if ( tokens[0] == "STOP" ) {
948 //emit endConnect(); 948 //emit endConnect();
949 end_connect(); 949 end_connect();
950 } 950 }
951 } 951 }
952} 952}
953void KServerSocket::end_connect() 953void KServerSocket::end_connect()
954{ 954{
955 delete mSyncActionDialog; 955 delete mSyncActionDialog;
956 mSyncActionDialog = 0; 956 mSyncActionDialog = 0;
957} 957}
958void KServerSocket::send_file() 958void KServerSocket::send_file()
959{ 959{
960 //qDebug("MainWindow::sendFile(QSocket* s) "); 960 //qDebug("MainWindow::sendFile(QSocket* s) ");
961 if ( mSyncActionDialog ) 961 if ( mSyncActionDialog )
962 delete mSyncActionDialog; 962 delete mSyncActionDialog;
963 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 963 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
964 mSyncActionDialog->setCaption(i18n("Received sync request")); 964 mSyncActionDialog->setCaption(i18n("Received sync request"));
965 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 965 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
966 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 966 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
967 lay->addWidget( label); 967 lay->addWidget( label);
968 lay->setMargin(7); 968 lay->setMargin(7);
969 lay->setSpacing(7); 969 lay->setSpacing(7);
970 mSyncActionDialog->setFixedSize( 230, 120); 970 mSyncActionDialog->setFixedSize( 230, 120);
971 mSyncActionDialog->show(); 971 mSyncActionDialog->show();
972 mSyncActionDialog->raise(); 972 mSyncActionDialog->raise();
973 emit request_file(); 973 emit request_file();
974 qApp->processEvents(); 974 qApp->processEvents();
975 QString fileName = mFileName; 975 QString fileName = mFileName;
976 QFile file( fileName ); 976 QFile file( fileName );
977 if (!file.open( IO_ReadOnly ) ) { 977 if (!file.open( IO_ReadOnly ) ) {
978 delete mSyncActionDialog; 978 delete mSyncActionDialog;
979 mSyncActionDialog = 0; 979 mSyncActionDialog = 0;
980 qDebug("KSS::error open file "); 980 qDebug("KSS::error open file ");
981 mSocket->close(); 981 mSocket->close();
982 if ( mSocket->state() == QSocket::Idle ) 982 if ( mSocket->state() == QSocket::Idle )
983 QTimer::singleShot( 10, this , SLOT ( discardClient())); 983 QTimer::singleShot( 10, this , SLOT ( discardClient()));
984 return ; 984 return ;
985 985
986 } 986 }
987 mSyncActionDialog->setCaption( i18n("Sending file...") ); 987 mSyncActionDialog->setCaption( i18n("Sending file...") );
988 QTextStream ts( &file ); 988 QTextStream ts( &file );
989 ts.setEncoding( QTextStream::Latin1 ); 989 ts.setEncoding( QTextStream::Latin1 );
990 990
991 QTextStream os( mSocket ); 991 QTextStream os( mSocket );
992 os.setEncoding( QTextStream::Latin1 ); 992 os.setEncoding( QTextStream::Latin1 );
993 while ( ! ts.atEnd() ) { 993 while ( ! ts.atEnd() ) {
994 os << ts.readLine() << "\n"; 994 os << ts.readLine() << "\r\n";
995 } 995 }
996 //os << ts.read(); 996 //os << ts.read();
997 file.close(); 997 file.close();
998 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 998 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
999 mSocket->close(); 999 mSocket->close();
1000 if ( mSocket->state() == QSocket::Idle ) 1000 if ( mSocket->state() == QSocket::Idle )
1001 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1001 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1002} 1002}
1003void KServerSocket::get_file() 1003void KServerSocket::get_file()
1004{ 1004{
1005 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1005 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1006 1006
1007 piTime.start(); 1007 piTime.start();
1008 piFileString = ""; 1008 piFileString = "";
1009 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1009 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1010} 1010}
1011 1011
1012 1012
1013void KServerSocket::readBackFileFromSocket() 1013void KServerSocket::readBackFileFromSocket()
1014{ 1014{
1015 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1015 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1016 while ( mSocket->canReadLine () ) { 1016 while ( mSocket->canReadLine () ) {
1017 piTime.restart(); 1017 piTime.restart();
1018 QString line = mSocket->readLine (); 1018 QString line = mSocket->readLine ();
1019 piFileString += line; 1019 piFileString += line;
1020 //qDebug("readline: %s ", line.latin1()); 1020 //qDebug("readline: %s ", line.latin1());
1021 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1021 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1022 1022
1023 } 1023 }
1024 if ( piTime.elapsed () < 3000 ) { 1024 if ( piTime.elapsed () < 3000 ) {
1025 // wait for more 1025 // wait for more
1026 //qDebug("waitformore "); 1026 //qDebug("waitformore ");
1027 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1027 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1028 return; 1028 return;
1029 } 1029 }
1030 QString fileName = mFileName; 1030 QString fileName = mFileName;
1031 QFile file ( fileName ); 1031 QFile file ( fileName );
1032 if (!file.open( IO_WriteOnly ) ) { 1032 if (!file.open( IO_WriteOnly ) ) {
1033 delete mSyncActionDialog; 1033 delete mSyncActionDialog;
1034 mSyncActionDialog = 0; 1034 mSyncActionDialog = 0;
1035 qDebug("KSS:Error open read back file "); 1035 qDebug("KSS:Error open read back file ");
1036 piFileString = ""; 1036 piFileString = "";
1037 emit file_received( false ); 1037 emit file_received( false );
1038 blockRC = false; 1038 blockRC = false;
1039 return ; 1039 return ;
1040 1040
1041 } 1041 }
1042 1042
@@ -1066,97 +1066,97 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host,
1066 1066
1067 mRetVal = quiet; 1067 mRetVal = quiet;
1068 mTimerSocket = new QTimer ( this ); 1068 mTimerSocket = new QTimer ( this );
1069 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1069 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1070} 1070}
1071void KCommandSocket::readFile( QString fn ) 1071void KCommandSocket::readFile( QString fn )
1072{ 1072{
1073 if ( !mSocket ) { 1073 if ( !mSocket ) {
1074 mSocket = new QSocket( this ); 1074 mSocket = new QSocket( this );
1075 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1075 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1076 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1076 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1077 } 1077 }
1078 mFileString = ""; 1078 mFileString = "";
1079 mFileName = fn; 1079 mFileName = fn;
1080 mFirst = true; 1080 mFirst = true;
1081 mSocket->connectToHost( mHost, mPort ); 1081 mSocket->connectToHost( mHost, mPort );
1082 QTextStream os( mSocket ); 1082 QTextStream os( mSocket );
1083 os.setEncoding( QTextStream::Latin1 ); 1083 os.setEncoding( QTextStream::Latin1 );
1084 os << "GET " << mPassWord << "\r\n"; 1084 os << "GET " << mPassWord << "\r\n";
1085 mTimerSocket->start( 10000 ); 1085 mTimerSocket->start( 10000 );
1086} 1086}
1087 1087
1088void KCommandSocket::writeFile( QString fileName ) 1088void KCommandSocket::writeFile( QString fileName )
1089{ 1089{
1090 if ( !mSocket ) { 1090 if ( !mSocket ) {
1091 mSocket = new QSocket( this ); 1091 mSocket = new QSocket( this );
1092 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1092 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1093 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1093 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1094 } 1094 }
1095 mFileName = fileName ; 1095 mFileName = fileName ;
1096 mSocket->connectToHost( mHost, mPort ); 1096 mSocket->connectToHost( mHost, mPort );
1097} 1097}
1098void KCommandSocket::writeFileToSocket() 1098void KCommandSocket::writeFileToSocket()
1099{ 1099{
1100 QFile file2( mFileName ); 1100 QFile file2( mFileName );
1101 if (!file2.open( IO_ReadOnly ) ) { 1101 if (!file2.open( IO_ReadOnly ) ) {
1102 mRetVal= errorW; 1102 mRetVal= errorW;
1103 mSocket->close(); 1103 mSocket->close();
1104 if ( mSocket->state() == QSocket::Idle ) 1104 if ( mSocket->state() == QSocket::Idle )
1105 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1105 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1106 return ; 1106 return ;
1107 } 1107 }
1108 QTextStream ts2( &file2 ); 1108 QTextStream ts2( &file2 );
1109 ts2.setEncoding( QTextStream::Latin1 ); 1109 ts2.setEncoding( QTextStream::Latin1 );
1110 QTextStream os2( mSocket ); 1110 QTextStream os2( mSocket );
1111 os2.setEncoding( QTextStream::Latin1 ); 1111 os2.setEncoding( QTextStream::Latin1 );
1112 os2 << "PUT " << mPassWord << "\r\n";; 1112 os2 << "PUT " << mPassWord << "\r\n";;
1113 while ( ! ts2.atEnd() ) { 1113 while ( ! ts2.atEnd() ) {
1114 os2 << ts2.readLine() << "\n"; 1114 os2 << ts2.readLine() << "\r\n";
1115 } 1115 }
1116 mRetVal= successW; 1116 mRetVal= successW;
1117 file2.close(); 1117 file2.close();
1118 mSocket->close(); 1118 mSocket->close();
1119 if ( mSocket->state() == QSocket::Idle ) 1119 if ( mSocket->state() == QSocket::Idle )
1120 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1120 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1121} 1121}
1122void KCommandSocket::sendStop() 1122void KCommandSocket::sendStop()
1123{ 1123{
1124 if ( !mSocket ) { 1124 if ( !mSocket ) {
1125 mSocket = new QSocket( this ); 1125 mSocket = new QSocket( this );
1126 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1126 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1127 } 1127 }
1128 mSocket->connectToHost( mHost, mPort ); 1128 mSocket->connectToHost( mHost, mPort );
1129 QTextStream os2( mSocket ); 1129 QTextStream os2( mSocket );
1130 os2.setEncoding( QTextStream::Latin1 ); 1130 os2.setEncoding( QTextStream::Latin1 );
1131 os2 << "STOP\r\n"; 1131 os2 << "STOP\r\n";
1132 mSocket->close(); 1132 mSocket->close();
1133 if ( mSocket->state() == QSocket::Idle ) 1133 if ( mSocket->state() == QSocket::Idle )
1134 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1134 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1135} 1135}
1136 1136
1137void KCommandSocket::startReadFileFromSocket() 1137void KCommandSocket::startReadFileFromSocket()
1138{ 1138{
1139 if ( ! mFirst ) 1139 if ( ! mFirst )
1140 return; 1140 return;
1141 mFirst = false; 1141 mFirst = false;
1142 mTimerSocket->stop(); 1142 mTimerSocket->stop();
1143 mFileString = ""; 1143 mFileString = "";
1144 mTime.start(); 1144 mTime.start();
1145 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1145 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1146 1146
1147} 1147}
1148void KCommandSocket::readFileFromSocket() 1148void KCommandSocket::readFileFromSocket()
1149{ 1149{
1150 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1150 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1151 while ( mSocket->canReadLine () ) { 1151 while ( mSocket->canReadLine () ) {
1152 mTime.restart(); 1152 mTime.restart();
1153 QString line = mSocket->readLine (); 1153 QString line = mSocket->readLine ();
1154 mFileString += line; 1154 mFileString += line;
1155 //qDebug("readline: %s ", line.latin1()); 1155 //qDebug("readline: %s ", line.latin1());
1156 } 1156 }
1157 if ( mTime.elapsed () < 3000 ) { 1157 if ( mTime.elapsed () < 3000 ) {
1158 // wait for more 1158 // wait for more
1159 //qDebug("waitformore "); 1159 //qDebug("waitformore ");
1160 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1160 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1161 return; 1161 return;
1162 } 1162 }