summaryrefslogtreecommitdiffabout
Unidiff
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
@@ -610,601 +610,601 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
610 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 610 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
611 } 611 }
612 } 612 }
613 } 613 }
614 return; 614 return;
615} 615}
616void KSyncManager::edit_pisync_options() 616void KSyncManager::edit_pisync_options()
617{ 617{
618 QDialog dia( mParent, "dia", true ); 618 QDialog dia( mParent, "dia", true );
619 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 619 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
620 QVBoxLayout lay ( &dia ); 620 QVBoxLayout lay ( &dia );
621 lay.setSpacing( 5 ); 621 lay.setSpacing( 5 );
622 lay.setMargin( 3 ); 622 lay.setMargin( 3 );
623 QLabel lab1 ( i18n("Password for remote access:"), &dia); 623 QLabel lab1 ( i18n("Password for remote access:"), &dia);
624 lay.addWidget( &lab1 ); 624 lay.addWidget( &lab1 );
625 QLineEdit le1 (&dia ); 625 QLineEdit le1 (&dia );
626 lay.addWidget( &le1 ); 626 lay.addWidget( &le1 );
627 QLabel lab2 ( i18n("Remote IP address:"), &dia); 627 QLabel lab2 ( i18n("Remote IP address:"), &dia);
628 lay.addWidget( &lab2 ); 628 lay.addWidget( &lab2 );
629 QLineEdit le2 (&dia ); 629 QLineEdit le2 (&dia );
630 lay.addWidget( &le2 ); 630 lay.addWidget( &le2 );
631 QLabel lab3 ( i18n("Remote port number:"), &dia); 631 QLabel lab3 ( i18n("Remote port number:"), &dia);
632 lay.addWidget( &lab3 ); 632 lay.addWidget( &lab3 );
633 QLineEdit le3 (&dia ); 633 QLineEdit le3 (&dia );
634 lay.addWidget( &le3 ); 634 lay.addWidget( &le3 );
635 QPushButton pb ( "OK", &dia); 635 QPushButton pb ( "OK", &dia);
636 lay.addWidget( &pb ); 636 lay.addWidget( &pb );
637 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 637 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
638 le1.setText( mPassWordPiSync ); 638 le1.setText( mPassWordPiSync );
639 le2.setText( mActiveSyncIP ); 639 le2.setText( mActiveSyncIP );
640 le3.setText( mActiveSyncPort ); 640 le3.setText( mActiveSyncPort );
641 if ( dia.exec() ) { 641 if ( dia.exec() ) {
642 mPassWordPiSync = le1.text(); 642 mPassWordPiSync = le1.text();
643 mActiveSyncPort = le3.text(); 643 mActiveSyncPort = le3.text();
644 mActiveSyncIP = le2.text(); 644 mActiveSyncIP = le2.text();
645 } 645 }
646 646
647} 647}
648void KSyncManager::edit_sync_options() 648void KSyncManager::edit_sync_options()
649{ 649{
650 650
651 QDialog dia( mParent, "dia", true ); 651 QDialog dia( mParent, "dia", true );
652 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 652 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
653 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 653 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
654 QVBoxLayout lay ( &dia ); 654 QVBoxLayout lay ( &dia );
655 lay.setSpacing( 2 ); 655 lay.setSpacing( 2 );
656 lay.setMargin( 3 ); 656 lay.setMargin( 3 );
657 lay.addWidget(&gr); 657 lay.addWidget(&gr);
658 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 658 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
659 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 659 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
660 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 660 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
661 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 661 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
662 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 662 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
663 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 663 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
664 //QRadioButton both( i18n("Take both on conflict"), &gr ); 664 //QRadioButton both( i18n("Take both on conflict"), &gr );
665 QPushButton pb ( "OK", &dia); 665 QPushButton pb ( "OK", &dia);
666 lay.addWidget( &pb ); 666 lay.addWidget( &pb );
667 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 667 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
668 switch ( mSyncAlgoPrefs ) { 668 switch ( mSyncAlgoPrefs ) {
669 case 0: 669 case 0:
670 loc.setChecked( true); 670 loc.setChecked( true);
671 break; 671 break;
672 case 1: 672 case 1:
673 rem.setChecked( true ); 673 rem.setChecked( true );
674 break; 674 break;
675 case 2: 675 case 2:
676 newest.setChecked( true); 676 newest.setChecked( true);
677 break; 677 break;
678 case 3: 678 case 3:
679 ask.setChecked( true); 679 ask.setChecked( true);
680 break; 680 break;
681 case 4: 681 case 4:
682 f_loc.setChecked( true); 682 f_loc.setChecked( true);
683 break; 683 break;
684 case 5: 684 case 5:
685 f_rem.setChecked( true); 685 f_rem.setChecked( true);
686 break; 686 break;
687 case 6: 687 case 6:
688 // both.setChecked( true); 688 // both.setChecked( true);
689 break; 689 break;
690 default: 690 default:
691 break; 691 break;
692 } 692 }
693 if ( dia.exec() ) { 693 if ( dia.exec() ) {
694 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 694 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
695 } 695 }
696 696
697 697
698} 698}
699 699
700QString KSyncManager::getPassword( ) 700QString KSyncManager::getPassword( )
701{ 701{
702 QString retfile = ""; 702 QString retfile = "";
703 QDialog dia ( mParent, "input-dialog", true ); 703 QDialog dia ( mParent, "input-dialog", true );
704 QLineEdit lab ( &dia ); 704 QLineEdit lab ( &dia );
705 lab.setEchoMode( QLineEdit::Password ); 705 lab.setEchoMode( QLineEdit::Password );
706 QVBoxLayout lay( &dia ); 706 QVBoxLayout lay( &dia );
707 lay.setMargin(7); 707 lay.setMargin(7);
708 lay.setSpacing(7); 708 lay.setSpacing(7);
709 lay.addWidget( &lab); 709 lay.addWidget( &lab);
710 dia.setFixedSize( 230,50 ); 710 dia.setFixedSize( 230,50 );
711 dia.setCaption( i18n("Enter password") ); 711 dia.setCaption( i18n("Enter password") );
712 QPushButton pb ( "OK", &dia); 712 QPushButton pb ( "OK", &dia);
713 lay.addWidget( &pb ); 713 lay.addWidget( &pb );
714 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 714 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
715 dia.show(); 715 dia.show();
716 int res = dia.exec(); 716 int res = dia.exec();
717 if ( res ) 717 if ( res )
718 retfile = lab.text(); 718 retfile = lab.text();
719 dia.hide(); 719 dia.hide();
720 qApp->processEvents(); 720 qApp->processEvents();
721 return retfile; 721 return retfile;
722 722
723} 723}
724 724
725 725
726void KSyncManager::confSync() 726void KSyncManager::confSync()
727{ 727{
728 static KSyncPrefsDialog* sp = 0; 728 static KSyncPrefsDialog* sp = 0;
729 if ( ! sp ) { 729 if ( ! sp ) {
730 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 730 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
731 } 731 }
732 sp->usrReadConfig(); 732 sp->usrReadConfig();
733#ifndef DESKTOP_VERSION 733#ifndef DESKTOP_VERSION
734 sp->showMaximized(); 734 sp->showMaximized();
735#else 735#else
736 sp->show(); 736 sp->show();
737#endif 737#endif
738 sp->exec(); 738 sp->exec();
739 mSyncProfileNames = sp->getSyncProfileNames(); 739 mSyncProfileNames = sp->getSyncProfileNames();
740 mLocalMachineName = sp->getLocalMachineName (); 740 mLocalMachineName = sp->getLocalMachineName ();
741 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 741 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
742} 742}
743 743
744void KSyncManager::syncSharp() 744void KSyncManager::syncSharp()
745{ 745{
746 746
747 if ( ! syncExternalApplication("sharp") ) 747 if ( ! syncExternalApplication("sharp") )
748 qDebug("ERROR sync sharp "); 748 qDebug("ERROR sync sharp ");
749} 749}
750 750
751bool KSyncManager::syncExternalApplication(QString resource) 751bool KSyncManager::syncExternalApplication(QString resource)
752{ 752{
753 753
754 emit save(); 754 emit save();
755 755
756 if ( mAskForPreferences ) 756 if ( mAskForPreferences )
757 edit_sync_options(); 757 edit_sync_options();
758 758
759 qDebug("Sync extern %s", resource.latin1()); 759 qDebug("Sync extern %s", resource.latin1());
760 760
761 bool syncOK = mImplementation->syncExternal(this, resource); 761 bool syncOK = mImplementation->syncExternal(this, resource);
762 762
763 return syncOK; 763 return syncOK;
764 764
765} 765}
766 766
767void KSyncManager::syncPhone() 767void KSyncManager::syncPhone()
768{ 768{
769 769
770 syncExternalApplication("phone"); 770 syncExternalApplication("phone");
771 771
772} 772}
773 773
774void KSyncManager::showProgressBar(int percentage, QString caption, int total) 774void KSyncManager::showProgressBar(int percentage, QString caption, int total)
775{ 775{
776 if (!bar->isVisible()) 776 if (!bar->isVisible())
777 { 777 {
778 bar->setCaption (caption); 778 bar->setCaption (caption);
779 bar->setTotalSteps ( total ) ; 779 bar->setTotalSteps ( total ) ;
780 780
781 bar->show(); 781 bar->show();
782 } 782 }
783 783
784 bar->setProgress( percentage ); 784 bar->setProgress( percentage );
785} 785}
786 786
787void KSyncManager::hideProgressBar() 787void KSyncManager::hideProgressBar()
788{ 788{
789 bar->hide(); 789 bar->hide();
790} 790}
791 791
792bool KSyncManager::isProgressBarCanceled() 792bool KSyncManager::isProgressBarCanceled()
793{ 793{
794 return !bar->isVisible(); 794 return !bar->isVisible();
795} 795}
796 796
797QString KSyncManager::syncFileName() 797QString KSyncManager::syncFileName()
798{ 798{
799 799
800 QString fn = "tempfile"; 800 QString fn = "tempfile";
801 switch(mTargetApp) 801 switch(mTargetApp)
802 { 802 {
803 case (KAPI): 803 case (KAPI):
804 fn = "tempsyncab.vcf"; 804 fn = "tempsyncab.vcf";
805 break; 805 break;
806 case (KOPI): 806 case (KOPI):
807 fn = "tempsynccal.ics"; 807 fn = "tempsynccal.ics";
808 break; 808 break;
809 case (PWMPI): 809 case (PWMPI):
810 fn = "tempsyncpw.pwm"; 810 fn = "tempsyncpw.pwm";
811 break; 811 break;
812 default: 812 default:
813 break; 813 break;
814 } 814 }
815#ifdef _WIN32_ 815#ifdef _WIN32_
816 return locateLocal( "tmp", fn ); 816 return locateLocal( "tmp", fn );
817#else 817#else
818 return (QString( "/tmp/" )+ fn ); 818 return (QString( "/tmp/" )+ fn );
819#endif 819#endif
820} 820}
821 821
822void KSyncManager::syncPi() 822void KSyncManager::syncPi()
823{ 823{
824 qApp->processEvents(); 824 qApp->processEvents();
825 if ( mAskForPreferences ) 825 if ( mAskForPreferences )
826 edit_pisync_options(); 826 edit_pisync_options();
827 bool ok; 827 bool ok;
828 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 828 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
829 if ( ! ok ) { 829 if ( ! ok ) {
830 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 830 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
831 return; 831 return;
832 } 832 }
833 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 833 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
834 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 834 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
835 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 835 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
836 commandSocket->readFile( syncFileName() ); 836 commandSocket->readFile( syncFileName() );
837} 837}
838 838
839void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 839void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
840{ 840{
841 //enum { success, errorW, errorR, quiet }; 841 //enum { success, errorW, errorR, quiet };
842 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 842 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
843 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 843 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
844 delete s; 844 delete s;
845 if ( state == KCommandSocket::errorR ) { 845 if ( state == KCommandSocket::errorR ) {
846 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 846 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
847 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 847 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
848 commandSocket->sendStop(); 848 commandSocket->sendStop();
849 } 849 }
850 return; 850 return;
851 851
852 } else if ( state == KCommandSocket::errorW ) { 852 } else if ( state == KCommandSocket::errorW ) {
853 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 853 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
854 854
855 } else if ( state == KCommandSocket::successR ) { 855 } else if ( state == KCommandSocket::successR ) {
856 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 856 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
857 857
858 } else if ( state == KCommandSocket::successW ) { 858 } else if ( state == KCommandSocket::successW ) {
859 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 859 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
860 } 860 }
861 861
862 delete s; 862 delete s;
863} 863}
864 864
865void KSyncManager::readFileFromSocket() 865void KSyncManager::readFileFromSocket()
866{ 866{
867 QString fileName = syncFileName(); 867 QString fileName = syncFileName();
868 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 868 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
869 if ( ! syncWithFile( fileName , true ) ) { 869 if ( ! syncWithFile( fileName , true ) ) {
870 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 870 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
871 return; 871 return;
872 } 872 }
873 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 873 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
874 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 874 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
875 if ( mWriteBackFile ) 875 if ( mWriteBackFile )
876 commandSocket->writeFile( fileName ); 876 commandSocket->writeFile( fileName );
877 else { 877 else {
878 commandSocket->sendStop(); 878 commandSocket->sendStop();
879 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 879 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
880 } 880 }
881} 881}
882 882
883KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 883KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
884{ 884{
885 mPassWord = pw; 885 mPassWord = pw;
886 mSocket = 0; 886 mSocket = 0;
887 mSyncActionDialog = 0; 887 mSyncActionDialog = 0;
888 blockRC = false; 888 blockRC = false;
889}; 889};
890 890
891void KServerSocket::newConnection ( int socket ) 891void KServerSocket::newConnection ( int socket )
892{ 892{
893 // qDebug("KServerSocket:New connection %d ", socket); 893 // qDebug("KServerSocket:New connection %d ", socket);
894 if ( mSocket ) { 894 if ( mSocket ) {
895 qDebug("KServerSocket::newConnection Socket deleted! "); 895 qDebug("KServerSocket::newConnection Socket deleted! ");
896 delete mSocket; 896 delete mSocket;
897 mSocket = 0; 897 mSocket = 0;
898 } 898 }
899 mSocket = new QSocket( this ); 899 mSocket = new QSocket( this );
900 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 900 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
901 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 901 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
902 mSocket->setSocket( socket ); 902 mSocket->setSocket( socket );
903} 903}
904 904
905void KServerSocket::discardClient() 905void KServerSocket::discardClient()
906{ 906{
907 //qDebug(" KServerSocket::discardClient()"); 907 //qDebug(" KServerSocket::discardClient()");
908 if ( mSocket ) { 908 if ( mSocket ) {
909 delete mSocket; 909 delete mSocket;
910 mSocket = 0; 910 mSocket = 0;
911 } 911 }
912 //emit endConnect(); 912 //emit endConnect();
913} 913}
914void KServerSocket::readClient() 914void KServerSocket::readClient()
915{ 915{
916 if ( blockRC ) 916 if ( blockRC )
917 return; 917 return;
918 if ( mSocket == 0 ) { 918 if ( mSocket == 0 ) {
919 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 919 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
920 return; 920 return;
921 } 921 }
922 //qDebug("KServerSocket::readClient()"); 922 //qDebug("KServerSocket::readClient()");
923 if ( mSocket->canReadLine() ) { 923 if ( mSocket->canReadLine() ) {
924 QString line = mSocket->readLine(); 924 QString line = mSocket->readLine();
925 //qDebug("KServerSocket readline: %s ", line.latin1()); 925 //qDebug("KServerSocket readline: %s ", line.latin1());
926 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 926 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
927 if ( tokens[0] == "GET" ) { 927 if ( tokens[0] == "GET" ) {
928 if ( tokens[1] == mPassWord ) 928 if ( tokens[1] == mPassWord )
929 //emit sendFile( mSocket ); 929 //emit sendFile( mSocket );
930 send_file(); 930 send_file();
931 else { 931 else {
932 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 932 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
933 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 933 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
934 } 934 }
935 } 935 }
936 if ( tokens[0] == "PUT" ) { 936 if ( tokens[0] == "PUT" ) {
937 if ( tokens[1] == mPassWord ) { 937 if ( tokens[1] == mPassWord ) {
938 //emit getFile( mSocket ); 938 //emit getFile( mSocket );
939 blockRC = true; 939 blockRC = true;
940 get_file(); 940 get_file();
941 } 941 }
942 else { 942 else {
943 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 943 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
944 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 944 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
945 } 945 }
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
1043 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1043 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1044 QTextStream ts ( &file ); 1044 QTextStream ts ( &file );
1045 ts.setEncoding( QTextStream::Latin1 ); 1045 ts.setEncoding( QTextStream::Latin1 );
1046 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1046 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1047 ts << piFileString; 1047 ts << piFileString;
1048 mSocket->close(); 1048 mSocket->close();
1049 if ( mSocket->state() == QSocket::Idle ) 1049 if ( mSocket->state() == QSocket::Idle )
1050 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1050 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1051 file.close(); 1051 file.close();
1052 delete mSyncActionDialog; 1052 delete mSyncActionDialog;
1053 mSyncActionDialog = 0; 1053 mSyncActionDialog = 0;
1054 piFileString = ""; 1054 piFileString = "";
1055 blockRC = false; 1055 blockRC = false;
1056 emit file_received( true ); 1056 emit file_received( true );
1057 1057
1058} 1058}
1059 1059
1060KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1060KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1061{ 1061{
1062 mPassWord = password; 1062 mPassWord = password;
1063 mSocket = 0; 1063 mSocket = 0;
1064 mPort = port; 1064 mPort = port;
1065 mHost = host; 1065 mHost = 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 }
1163 QString fileName = mFileName; 1163 QString fileName = mFileName;
1164 QFile file ( fileName ); 1164 QFile file ( fileName );
1165 if (!file.open( IO_WriteOnly ) ) { 1165 if (!file.open( IO_WriteOnly ) ) {
1166 mFileString = ""; 1166 mFileString = "";
1167 mRetVal = errorR; 1167 mRetVal = errorR;
1168 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1168 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1169 deleteSocket(); 1169 deleteSocket();
1170 return ; 1170 return ;
1171 1171
1172 } 1172 }
1173 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1173 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1174 QTextStream ts ( &file ); 1174 QTextStream ts ( &file );
1175 ts.setEncoding( QTextStream::Latin1 ); 1175 ts.setEncoding( QTextStream::Latin1 );
1176 ts << mFileString; 1176 ts << mFileString;
1177 file.close(); 1177 file.close();
1178 mFileString = ""; 1178 mFileString = "";
1179 mRetVal = successR; 1179 mRetVal = successR;
1180 mSocket->close(); 1180 mSocket->close();
1181 // if state is not idle, deleteSocket(); is called via 1181 // if state is not idle, deleteSocket(); is called via
1182 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1182 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1183 if ( mSocket->state() == QSocket::Idle ) 1183 if ( mSocket->state() == QSocket::Idle )
1184 deleteSocket(); 1184 deleteSocket();
1185} 1185}
1186 1186
1187void KCommandSocket::deleteSocket() 1187void KCommandSocket::deleteSocket()
1188{ 1188{
1189 //qDebug("KCommandSocket::deleteSocket() "); 1189 //qDebug("KCommandSocket::deleteSocket() ");
1190 if ( mTimerSocket->isActive () ) { 1190 if ( mTimerSocket->isActive () ) {
1191 mTimerSocket->stop(); 1191 mTimerSocket->stop();
1192 mRetVal = errorTO; 1192 mRetVal = errorTO;
1193 qDebug("Connection to remote host timed out"); 1193 qDebug("Connection to remote host timed out");
1194 if ( mSocket ) { 1194 if ( mSocket ) {
1195 mSocket->close(); 1195 mSocket->close();
1196 //if ( mSocket->state() == QSocket::Idle ) 1196 //if ( mSocket->state() == QSocket::Idle )
1197 // deleteSocket(); 1197 // deleteSocket();
1198 delete mSocket; 1198 delete mSocket;
1199 mSocket = 0; 1199 mSocket = 0;
1200 } 1200 }
1201 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1201 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1202 emit commandFinished( this, mRetVal ); 1202 emit commandFinished( this, mRetVal );
1203 return; 1203 return;
1204 } 1204 }
1205 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1205 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1206 if ( mSocket) 1206 if ( mSocket)
1207 delete mSocket; 1207 delete mSocket;
1208 mSocket = 0; 1208 mSocket = 0;
1209 emit commandFinished( this, mRetVal ); 1209 emit commandFinished( this, mRetVal );
1210} 1210}