summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2004-10-07 13:41:15 (UTC)
committer zautrix <zautrix>2004-10-07 13:41:15 (UTC)
commitbb8293c794d82a57bc93af85ccd89b601356d577 (patch) (unidiff)
tree1b5112b9fda89888095bbb9934349c800865043c /libkdepim/ksyncmanager.cpp
parentd14d61ebb2e41329465883a0dfce719d69fc3f3e (diff)
downloadkdepimpi-bb8293c794d82a57bc93af85ccd89b601356d577.zip
kdepimpi-bb8293c794d82a57bc93af85ccd89b601356d577.tar.gz
kdepimpi-bb8293c794d82a57bc93af85ccd89b601356d577.tar.bz2
sync fixes
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 28af135..fad9a76 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -726,134 +726,136 @@ void KSyncManager::showProgressBar(int percentage, QString caption, int total)
726 bar->setCaption (caption); 726 bar->setCaption (caption);
727 bar->setTotalSteps ( total ) ; 727 bar->setTotalSteps ( total ) ;
728 728
729 bar->show(); 729 bar->show();
730 } 730 }
731 731
732 bar->setProgress( percentage ); 732 bar->setProgress( percentage );
733} 733}
734 734
735void KSyncManager::hideProgressBar() 735void KSyncManager::hideProgressBar()
736{ 736{
737 bar->hide(); 737 bar->hide();
738} 738}
739 739
740bool KSyncManager::isProgressBarCanceled() 740bool KSyncManager::isProgressBarCanceled()
741{ 741{
742 return !bar->isVisible(); 742 return !bar->isVisible();
743} 743}
744 744
745QString KSyncManager::syncFileName() 745QString KSyncManager::syncFileName()
746{ 746{
747 747
748 QString fn = "tempfile"; 748 QString fn = "tempfile";
749 switch(mTargetApp) 749 switch(mTargetApp)
750 { 750 {
751 case (KAPI): 751 case (KAPI):
752 fn = "tempsyncab.vcf"; 752 fn = "tempsyncab.vcf";
753 break; 753 break;
754 case (KOPI): 754 case (KOPI):
755 fn = "tempsynccal.ics"; 755 fn = "tempsynccal.ics";
756 break; 756 break;
757 case (PWMPI): 757 case (PWMPI):
758 fn = "tempsyncpw.pwm"; 758 fn = "tempsyncpw.pwm";
759 break; 759 break;
760 default: 760 default:
761 break; 761 break;
762 } 762 }
763#ifdef _WIN32_ 763#ifdef _WIN32_
764 return locateLocal( "tmp", fn ); 764 return locateLocal( "tmp", fn );
765#else 765#else
766 return (QString( "/tmp/" )+ fn ); 766 return (QString( "/tmp/" )+ fn );
767#endif 767#endif
768} 768}
769 769
770void KSyncManager::syncPi() 770void KSyncManager::syncPi()
771{ 771{
772 qApp->processEvents(); 772 qApp->processEvents();
773 bool ok; 773 bool ok;
774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
775 if ( ! ok ) { 775 if ( ! ok ) {
776 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 776 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
777 return; 777 return;
778 } 778 }
779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
781 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 781 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
782 commandSocket->readFile( syncFileName() ); 782 commandSocket->readFile( syncFileName() );
783} 783}
784 784
785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
786{ 786{
787 qDebug("MainWindow::deleteCommandSocket %d", state); 787 qDebug("MainWindow::deleteCommandSocket %d", state);
788 788
789 //enum { success, errorW, errorR, quiet }; 789 //enum { success, errorW, errorR, quiet };
790 if ( state == KCommandSocket::errorR ) { 790 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
792 delete s; 792 delete s;
793 if ( state == KCommandSocket::errorR ) {
793 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 794 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
794 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 795 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
795 commandSocket->sendStop(); 796 commandSocket->sendStop();
797 }
796 return; 798 return;
797 799
798 } else if ( state == KCommandSocket::errorW ) { 800 } else if ( state == KCommandSocket::errorW ) {
799 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 801 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
800 802
801 } else if ( state == KCommandSocket::successR ) { 803 } else if ( state == KCommandSocket::successR ) {
802 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 804 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
803 805
804 } else if ( state == KCommandSocket::successW ) { 806 } else if ( state == KCommandSocket::successW ) {
805 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 807 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
806 } 808 }
807 809
808 delete s; 810 delete s;
809} 811}
810 812
811void KSyncManager::readFileFromSocket() 813void KSyncManager::readFileFromSocket()
812{ 814{
813 QString fileName = syncFileName(); 815 QString fileName = syncFileName();
814 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 816 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
815 if ( ! syncWithFile( fileName , true ) ) { 817 if ( ! syncWithFile( fileName , true ) ) {
816 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 818 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
817 qDebug("Syncing failed "); 819 qDebug("Syncing failed ");
818 return; 820 return;
819 } 821 }
820 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 822 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
821 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 823 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
822 if ( mWriteBackFile ) 824 if ( mWriteBackFile )
823 commandSocket->writeFile( fileName ); 825 commandSocket->writeFile( fileName );
824 else { 826 else {
825 commandSocket->sendStop(); 827 commandSocket->sendStop();
826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 828 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
827 } 829 }
828} 830}
829 831
830KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 832KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
831{ 833{
832 mPassWord = pw; 834 mPassWord = pw;
833 mSocket = 0; 835 mSocket = 0;
834 mSyncActionDialog = 0; 836 mSyncActionDialog = 0;
835 blockRC = false; 837 blockRC = false;
836}; 838};
837 839
838void KServerSocket::newConnection ( int socket ) 840void KServerSocket::newConnection ( int socket )
839{ 841{
840 // qDebug("KServerSocket:New connection %d ", socket); 842 // qDebug("KServerSocket:New connection %d ", socket);
841 if ( mSocket ) { 843 if ( mSocket ) {
842 qDebug("KServerSocket::newConnection Socket deleted! "); 844 qDebug("KServerSocket::newConnection Socket deleted! ");
843 delete mSocket; 845 delete mSocket;
844 mSocket = 0; 846 mSocket = 0;
845 } 847 }
846 mSocket = new QSocket( this ); 848 mSocket = new QSocket( this );
847 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 849 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
848 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 850 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
849 mSocket->setSocket( socket ); 851 mSocket->setSocket( socket );
850} 852}
851 853
852void KServerSocket::discardClient() 854void KServerSocket::discardClient()
853{ 855{
854 //qDebug(" KServerSocket::discardClient()"); 856 //qDebug(" KServerSocket::discardClient()");
855 if ( mSocket ) { 857 if ( mSocket ) {
856 delete mSocket; 858 delete mSocket;
857 mSocket = 0; 859 mSocket = 0;
858 } 860 }
859 //emit endConnect(); 861 //emit endConnect();
@@ -1076,73 +1078,79 @@ void KCommandSocket::sendStop()
1076 mSocket->connectToHost( mHost, mPort ); 1078 mSocket->connectToHost( mHost, mPort );
1077 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1078 os2.setEncoding( QTextStream::Latin1 ); 1080 os2.setEncoding( QTextStream::Latin1 );
1079 os2 << "STOP\r\n"; 1081 os2 << "STOP\r\n";
1080 mSocket->close(); 1082 mSocket->close();
1081 if ( mSocket->state() == QSocket::Idle ) 1083 if ( mSocket->state() == QSocket::Idle )
1082 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1084 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1083} 1085}
1084 1086
1085void KCommandSocket::startReadFileFromSocket() 1087void KCommandSocket::startReadFileFromSocket()
1086{ 1088{
1087 if ( ! mFirst ) 1089 if ( ! mFirst )
1088 return; 1090 return;
1089 mFirst = false; 1091 mFirst = false;
1090 mTimerSocket->stop(); 1092 mTimerSocket->stop();
1091 mFileString = ""; 1093 mFileString = "";
1092 mTime.start(); 1094 mTime.start();
1093 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1095 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1094 1096
1095} 1097}
1096void KCommandSocket::readFileFromSocket() 1098void KCommandSocket::readFileFromSocket()
1097{ 1099{
1098 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1100 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1099 while ( mSocket->canReadLine () ) { 1101 while ( mSocket->canReadLine () ) {
1100 mTime.restart(); 1102 mTime.restart();
1101 QString line = mSocket->readLine (); 1103 QString line = mSocket->readLine ();
1102 mFileString += line; 1104 mFileString += line;
1103 //qDebug("readline: %s ", line.latin1()); 1105 //qDebug("readline: %s ", line.latin1());
1104 } 1106 }
1105 if ( mTime.elapsed () < 3000 ) { 1107 if ( mTime.elapsed () < 3000 ) {
1106 // wait for more 1108 // wait for more
1107 //qDebug("waitformore "); 1109 //qDebug("waitformore ");
1108 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1110 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1109 return; 1111 return;
1110 } 1112 }
1111 QString fileName = mFileName; 1113 QString fileName = mFileName;
1112 QFile file ( fileName ); 1114 QFile file ( fileName );
1113 if (!file.open( IO_WriteOnly ) ) { 1115 if (!file.open( IO_WriteOnly ) ) {
1114 mFileString = ""; 1116 mFileString = "";
1115 mRetVal = errorR; 1117 mRetVal = errorR;
1116 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1118 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1117 deleteSocket(); 1119 deleteSocket();
1118 return ; 1120 return ;
1119 1121
1120 } 1122 }
1121 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1123 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1122 QTextStream ts ( &file ); 1124 QTextStream ts ( &file );
1123 ts.setEncoding( QTextStream::Latin1 ); 1125 ts.setEncoding( QTextStream::Latin1 );
1124 ts << mFileString; 1126 ts << mFileString;
1125 file.close(); 1127 file.close();
1126 mFileString = ""; 1128 mFileString = "";
1127 mRetVal = successR; 1129 mRetVal = successR;
1128 mSocket->close(); 1130 mSocket->close();
1129 // if state is not idle, deleteSocket(); is called via 1131 // if state is not idle, deleteSocket(); is called via
1130 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1132 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1131 if ( mSocket->state() == QSocket::Idle ) 1133 if ( mSocket->state() == QSocket::Idle )
1132 deleteSocket(); 1134 deleteSocket();
1133} 1135}
1134 1136
1135void KCommandSocket::deleteSocket() 1137void KCommandSocket::deleteSocket()
1136{ 1138{
1137 if ( mTimerSocket->isActive () ) { 1139 if ( mTimerSocket->isActive () ) {
1138 mTimerSocket->stop(); 1140 mTimerSocket->stop();
1139 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1141 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1140 mRetVal = errorR; 1142 mRetVal = errorTO;
1143 if ( mSocket ) {
1144 mSocket->close();
1145 if ( mSocket->state() == QSocket::Idle )
1146 deleteSocket();
1147 return;
1148 }
1141 } 1149 }
1142 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1150 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1143 if ( mSocket) 1151 if ( mSocket)
1144 delete mSocket; 1152 delete mSocket;
1145 mSocket = 0; 1153 mSocket = 0;
1146 emit commandFinished( this, mRetVal ); 1154 emit commandFinished( this, mRetVal );
1147} 1155}
1148 1156