summaryrefslogtreecommitdiffabout
path: root/libkdepim
Unidiff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 7197b30..b7929ec 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -677,1024 +677,1025 @@ int KSyncManager::ringSync()
677 mPassWordPiSync = temp->getRemotePwPWM(); 677 mPassWordPiSync = temp->getRemotePwPWM();
678 mActiveSyncPort = temp->getRemotePortPWM(); 678 mActiveSyncPort = temp->getRemotePortPWM();
679 mActiveSyncIP = temp->getRemoteIPPWM(); 679 mActiveSyncIP = temp->getRemoteIPPWM();
680 } 680 }
681 syncPi(); 681 syncPi();
682 while ( !mPisyncFinished ) { 682 while ( !mPisyncFinished ) {
683 //qDebug("waiting "); 683 //qDebug("waiting ");
684 qApp->processEvents(); 684 qApp->processEvents();
685 } 685 }
686 timer.start(); 686 timer.start();
687 while ( timer.elapsed () < 2000 ) { 687 while ( timer.elapsed () < 2000 ) {
688 qApp->processEvents(); 688 qApp->processEvents();
689 } 689 }
690 } else 690 } else
691 syncRemote( temp, false ); 691 syncRemote( temp, false );
692 692
693 } 693 }
694 } 694 }
695 timer.start(); 695 timer.start();
696 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 696 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
697 while ( timer.elapsed () < 2000 ) { 697 while ( timer.elapsed () < 2000 ) {
698 qApp->processEvents(); 698 qApp->processEvents();
699#ifndef _WIN32_ 699#ifndef _WIN32_
700 sleep (1); 700 sleep (1);
701#endif 701#endif
702 } 702 }
703 703
704 } 704 }
705 705
706 } 706 }
707 delete temp; 707 delete temp;
708 return syncedProfiles; 708 return syncedProfiles;
709} 709}
710 710
711void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 711void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
712{ 712{
713 QString question; 713 QString question;
714 if ( ask ) { 714 if ( ask ) {
715 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 715 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
716 if ( QMessageBox::information( mParent, i18n("Sync"), 716 if ( QMessageBox::information( mParent, i18n("Sync"),
717 question, 717 question,
718 i18n("Yes"), i18n("No"), 718 i18n("Yes"), i18n("No"),
719 0, 0 ) != 0 ) 719 0, 0 ) != 0 )
720 return; 720 return;
721 } 721 }
722 722
723 QString preCommand; 723 QString preCommand;
724 QString localTempFile; 724 QString localTempFile;
725 QString postCommand; 725 QString postCommand;
726 726
727 switch(mTargetApp) 727 switch(mTargetApp)
728 { 728 {
729 case (KAPI): 729 case (KAPI):
730 preCommand = prof->getPreSyncCommandAB(); 730 preCommand = prof->getPreSyncCommandAB();
731 postCommand = prof->getPostSyncCommandAB(); 731 postCommand = prof->getPostSyncCommandAB();
732 localTempFile = prof->getLocalTempFileAB(); 732 localTempFile = prof->getLocalTempFileAB();
733 break; 733 break;
734 case (KOPI): 734 case (KOPI):
735 preCommand = prof->getPreSyncCommand(); 735 preCommand = prof->getPreSyncCommand();
736 postCommand = prof->getPostSyncCommand(); 736 postCommand = prof->getPostSyncCommand();
737 localTempFile = prof->getLocalTempFile(); 737 localTempFile = prof->getLocalTempFile();
738 break; 738 break;
739 case (PWMPI): 739 case (PWMPI):
740 preCommand = prof->getPreSyncCommandPWM(); 740 preCommand = prof->getPreSyncCommandPWM();
741 postCommand = prof->getPostSyncCommandPWM(); 741 postCommand = prof->getPostSyncCommandPWM();
742 localTempFile = prof->getLocalTempFilePWM(); 742 localTempFile = prof->getLocalTempFilePWM();
743 break; 743 break;
744 default: 744 default:
745 qDebug("KSM::syncRemote: invalid apptype selected"); 745 qDebug("KSM::syncRemote: invalid apptype selected");
746 break; 746 break;
747 } 747 }
748 748
749 749
750 int fi; 750 int fi;
751 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 751 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
752 QString pwd = getPassword(); 752 QString pwd = getPassword();
753 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 753 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
754 754
755 } 755 }
756 int maxlen = 30; 756 int maxlen = 30;
757 if ( QApplication::desktop()->width() > 320 ) 757 if ( QApplication::desktop()->width() > 320 )
758 maxlen += 25; 758 maxlen += 25;
759 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 759 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
760 int result = system ( preCommand ); 760 int result = system ( preCommand );
761 // 0 : okay 761 // 0 : okay
762 // 256: no such file or dir 762 // 256: no such file or dir
763 // 763 //
764 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); 764 qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result );
765 if ( result != 0 ) { 765 if ( result != 0 ) {
766 unsigned int len = maxlen; 766 unsigned int len = maxlen;
767 while ( len < preCommand.length() ) { 767 while ( len < preCommand.length() ) {
768 preCommand.insert( len , "\n" ); 768 preCommand.insert( len , "\n" );
769 len += maxlen +2; 769 len += maxlen +2;
770 } 770 }
771 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; 771 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ;
772 QMessageBox::information( mParent, i18n("Sync - ERROR"), 772 QMessageBox::information( mParent, i18n("Sync - ERROR"),
773 question, 773 question,
774 i18n("Okay!")) ; 774 i18n("Okay!")) ;
775 mParent->topLevelWidget()->setCaption ("KDE-Pim"); 775 mParent->topLevelWidget()->setCaption ("KDE-Pim");
776 return; 776 return;
777 } 777 }
778 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 778 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
779 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 779 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
780 780
781 if ( syncWithFile( localTempFile, true ) ) { 781 if ( syncWithFile( localTempFile, true ) ) {
782 782
783 if ( mWriteBackFile ) { 783 if ( mWriteBackFile ) {
784 int fi; 784 int fi;
785 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 785 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
786 QString pwd = getPassword(); 786 QString pwd = getPassword();
787 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 787 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
788 788
789 } 789 }
790 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 790 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
791 result = system ( postCommand ); 791 result = system ( postCommand );
792 qDebug("KSM::Sync:Writing back file result: %d ", result); 792 qDebug("KSM::Sync:Writing back file result: %d ", result);
793 if ( result != 0 ) { 793 if ( result != 0 ) {
794 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 794 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
795 return; 795 return;
796 } else { 796 } else {
797 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 797 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
798 } 798 }
799 } 799 }
800 } 800 }
801 return; 801 return;
802} 802}
803bool KSyncManager::edit_pisync_options() 803bool KSyncManager::edit_pisync_options()
804{ 804{
805 QDialog dia( mParent, "dia", true ); 805 QDialog dia( mParent, "dia", true );
806 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 806 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
807 QVBoxLayout lay ( &dia ); 807 QVBoxLayout lay ( &dia );
808 lay.setSpacing( 5 ); 808 lay.setSpacing( 5 );
809 lay.setMargin( 3 ); 809 lay.setMargin( 3 );
810 QLabel lab1 ( i18n("Password for remote access:"), &dia); 810 QLabel lab1 ( i18n("Password for remote access:"), &dia);
811 lay.addWidget( &lab1 ); 811 lay.addWidget( &lab1 );
812 QLineEdit le1 (&dia ); 812 QLineEdit le1 (&dia );
813 lay.addWidget( &le1 ); 813 lay.addWidget( &le1 );
814 QLabel lab2 ( i18n("Remote IP address:"), &dia); 814 QLabel lab2 ( i18n("Remote IP address:"), &dia);
815 lay.addWidget( &lab2 ); 815 lay.addWidget( &lab2 );
816 QLineEdit le2 (&dia ); 816 QLineEdit le2 (&dia );
817 lay.addWidget( &le2 ); 817 lay.addWidget( &le2 );
818 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); 818 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia);
819 lay.addWidget( &lab3 ); 819 lay.addWidget( &lab3 );
820 QLineEdit le3 (&dia ); 820 QLineEdit le3 (&dia );
821 lay.addWidget( &le3 ); 821 lay.addWidget( &le3 );
822 QPushButton pb ( "OK", &dia); 822 QPushButton pb ( "OK", &dia);
823 lay.addWidget( &pb ); 823 lay.addWidget( &pb );
824 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 824 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
825 le1.setText( mPassWordPiSync ); 825 le1.setText( mPassWordPiSync );
826 le2.setText( mActiveSyncIP ); 826 le2.setText( mActiveSyncIP );
827 le3.setText( mActiveSyncPort ); 827 le3.setText( mActiveSyncPort );
828 if ( dia.exec() ) { 828 if ( dia.exec() ) {
829 mPassWordPiSync = le1.text(); 829 mPassWordPiSync = le1.text();
830 mActiveSyncPort = le3.text(); 830 mActiveSyncPort = le3.text();
831 mActiveSyncIP = le2.text(); 831 mActiveSyncIP = le2.text();
832 return true; 832 return true;
833 } 833 }
834 return false; 834 return false;
835} 835}
836bool KSyncManager::edit_sync_options() 836bool KSyncManager::edit_sync_options()
837{ 837{
838 838
839 QDialog dia( mParent, "dia", true ); 839 QDialog dia( mParent, "dia", true );
840 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 840 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
841 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 841 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
842 QVBoxLayout lay ( &dia ); 842 QVBoxLayout lay ( &dia );
843 lay.setSpacing( 2 ); 843 lay.setSpacing( 2 );
844 lay.setMargin( 3 ); 844 lay.setMargin( 3 );
845 lay.addWidget(&gr); 845 lay.addWidget(&gr);
846 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 846 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
847 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 847 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
848 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 848 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
849 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 849 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
850 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 850 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
851 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 851 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
852 //QRadioButton both( i18n("Take both on conflict"), &gr ); 852 //QRadioButton both( i18n("Take both on conflict"), &gr );
853 QPushButton pb ( "OK", &dia); 853 QPushButton pb ( "OK", &dia);
854 lay.addWidget( &pb ); 854 lay.addWidget( &pb );
855 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 855 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
856 switch ( mSyncAlgoPrefs ) { 856 switch ( mSyncAlgoPrefs ) {
857 case 0: 857 case 0:
858 loc.setChecked( true); 858 loc.setChecked( true);
859 break; 859 break;
860 case 1: 860 case 1:
861 rem.setChecked( true ); 861 rem.setChecked( true );
862 break; 862 break;
863 case 2: 863 case 2:
864 newest.setChecked( true); 864 newest.setChecked( true);
865 break; 865 break;
866 case 3: 866 case 3:
867 ask.setChecked( true); 867 ask.setChecked( true);
868 break; 868 break;
869 case 4: 869 case 4:
870 f_loc.setChecked( true); 870 f_loc.setChecked( true);
871 break; 871 break;
872 case 5: 872 case 5:
873 f_rem.setChecked( true); 873 f_rem.setChecked( true);
874 break; 874 break;
875 case 6: 875 case 6:
876 // both.setChecked( true); 876 // both.setChecked( true);
877 break; 877 break;
878 default: 878 default:
879 break; 879 break;
880 } 880 }
881 if ( dia.exec() ) { 881 if ( dia.exec() ) {
882 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 882 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
883 return true; 883 return true;
884 } 884 }
885 return false; 885 return false;
886} 886}
887 887
888QString KSyncManager::getPassword( ) 888QString KSyncManager::getPassword( )
889{ 889{
890 QString retfile = ""; 890 QString retfile = "";
891 QDialog dia ( mParent, "input-dialog", true ); 891 QDialog dia ( mParent, "input-dialog", true );
892 QLineEdit lab ( &dia ); 892 QLineEdit lab ( &dia );
893 lab.setEchoMode( QLineEdit::Password ); 893 lab.setEchoMode( QLineEdit::Password );
894 QVBoxLayout lay( &dia ); 894 QVBoxLayout lay( &dia );
895 lay.setMargin(7); 895 lay.setMargin(7);
896 lay.setSpacing(7); 896 lay.setSpacing(7);
897 lay.addWidget( &lab); 897 lay.addWidget( &lab);
898 dia.setFixedSize( 230,50 ); 898 dia.setFixedSize( 230,50 );
899 dia.setCaption( i18n("Enter password") ); 899 dia.setCaption( i18n("Enter password") );
900 QPushButton pb ( "OK", &dia); 900 QPushButton pb ( "OK", &dia);
901 lay.addWidget( &pb ); 901 lay.addWidget( &pb );
902 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 902 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
903 dia.show(); 903 dia.show();
904 int res = dia.exec(); 904 int res = dia.exec();
905 if ( res ) 905 if ( res )
906 retfile = lab.text(); 906 retfile = lab.text();
907 dia.hide(); 907 dia.hide();
908 qApp->processEvents(); 908 qApp->processEvents();
909 return retfile; 909 return retfile;
910 910
911} 911}
912 912
913 913
914void KSyncManager::confSync() 914void KSyncManager::confSync()
915{ 915{
916 static KSyncPrefsDialog* sp = 0; 916 static KSyncPrefsDialog* sp = 0;
917 if ( ! sp ) { 917 if ( ! sp ) {
918 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 918 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
919 } 919 }
920 sp->usrReadConfig(); 920 sp->usrReadConfig();
921#ifndef DESKTOP_VERSION 921#ifndef DESKTOP_VERSION
922 sp->showMaximized(); 922 sp->showMaximized();
923#else 923#else
924 sp->show(); 924 sp->show();
925#endif 925#endif
926 sp->exec(); 926 sp->exec();
927 QStringList oldSyncProfileNames = mSyncProfileNames; 927 QStringList oldSyncProfileNames = mSyncProfileNames;
928 mSyncProfileNames = sp->getSyncProfileNames(); 928 mSyncProfileNames = sp->getSyncProfileNames();
929 mLocalMachineName = sp->getLocalMachineName (); 929 mLocalMachineName = sp->getLocalMachineName ();
930 uint ii; 930 uint ii;
931 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { 931 for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) {
932 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) 932 if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) )
933 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); 933 mImplementation->removeSyncInfo( oldSyncProfileNames[ii] );
934 } 934 }
935 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 935 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
936} 936}
937void KSyncManager::syncKDE() 937void KSyncManager::syncKDE()
938{ 938{
939 mSyncWithDesktop = true; 939 mSyncWithDesktop = true;
940 emit save(); 940 emit save();
941 switch(mTargetApp) 941 switch(mTargetApp)
942 { 942 {
943 case (KAPI): 943 case (KAPI):
944 { 944 {
945#ifdef DESKTOP_VERSION 945#ifdef DESKTOP_VERSION
946 QString command = "kdeabdump33"; 946 QString command = "kdeabdump33";
947 QString commandfile = "kdeabdump33"; 947 QString commandfile = "kdeabdump33";
948 QString commandpath = qApp->applicationDirPath () + "/"; 948 QString commandpath = qApp->applicationDirPath () + "/";
949#else 949#else
950 QString command = "kdeabdump33"; 950 QString command = "kdeabdump33";
951 QString commandfile = "kdeabdump33"; 951 QString commandfile = "kdeabdump33";
952 QString commandpath = QDir::homeDirPath ()+"/"; 952 QString commandpath = QDir::homeDirPath ()+"/";
953#endif 953#endif
954 if ( ! QFile::exists ( commandpath+commandfile ) ) 954 if ( ! QFile::exists ( commandpath+commandfile ) )
955 command = commandfile; 955 command = commandfile;
956 else 956 else
957 command = commandpath+commandfile; 957 command = commandpath+commandfile;
958 958
959 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; 959 QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf";
960 int result = system ( command.latin1()); 960 int result = system ( command.latin1());
961 qDebug("AB dump 33 command call result: %d ", result); 961 qDebug("AB dump 33 command call result: %d ", result);
962 if ( result != 0 ) { 962 if ( result != 0 ) {
963 qDebug("Calling AB dump version 33 failed. Trying 34... "); 963 qDebug("Calling AB dump version 33 failed. Trying 34... ");
964 commandfile = "kdeabdump34"; 964 commandfile = "kdeabdump34";
965 if ( ! QFile::exists ( commandpath+commandfile ) ) 965 if ( ! QFile::exists ( commandpath+commandfile ) )
966 command = commandfile; 966 command = commandfile;
967 else 967 else
968 command = commandpath+commandfile; 968 command = commandpath+commandfile;
969 result = system ( command.latin1()); 969 result = system ( command.latin1());
970 qDebug("AB dump 34 command call result: %d ", result); 970 qDebug("AB dump 34 command call result: %d ", result);
971 if ( result != 0 ) { 971 if ( result != 0 ) {
972 KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); 972 KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath ));
973 return; 973 return;
974 } 974 }
975 } 975 }
976 if ( syncWithFile( fileName,true ) ) { 976 if ( syncWithFile( fileName,true ) ) {
977 if ( mWriteBackFile ) { 977 if ( mWriteBackFile ) {
978 command += " --read"; 978 command += " --read";
979 system ( command.latin1()); 979 system ( command.latin1());
980 } 980 }
981 } 981 }
982 982
983 } 983 }
984 break; 984 break;
985 case (KOPI): 985 case (KOPI):
986 { 986 {
987#ifdef DESKTOP_VERSION 987#ifdef DESKTOP_VERSION
988 QString command = "kdecaldump33"; 988 QString command = "kdecaldump33";
989 QString commandfile = "kdecaldump33"; 989 QString commandfile = "kdecaldump33";
990 QString commandpath = qApp->applicationDirPath () + "/"; 990 QString commandpath = qApp->applicationDirPath () + "/";
991#else 991#else
992 QString command = "kdecaldump33"; 992 QString command = "kdecaldump33";
993 QString commandfile = "kdecaldump33"; 993 QString commandfile = "kdecaldump33";
994 QString commandpath = QDir::homeDirPath ()+"/"; 994 QString commandpath = QDir::homeDirPath ()+"/";
995#endif 995#endif
996 if ( ! QFile::exists ( commandpath+commandfile ) ) 996 if ( ! QFile::exists ( commandpath+commandfile ) )
997 command = commandfile; 997 command = commandfile;
998 else 998 else
999 command = commandpath+commandfile; 999 command = commandpath+commandfile;
1000 1000
1001 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 1001 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
1002 int result = system ( command.latin1()); 1002 int result = system ( command.latin1());
1003 qDebug("Cal dump 33 command call result result: %d ", result); 1003 qDebug("Cal dump 33 command call result result: %d ", result);
1004 if ( result != 0 ) { 1004 if ( result != 0 ) {
1005 qDebug("Calling CAL dump version 33 failed. Trying 34... "); 1005 qDebug("Calling CAL dump version 33 failed. Trying 34... ");
1006 commandfile = "kdecaldump34"; 1006 commandfile = "kdecaldump34";
1007 if ( ! QFile::exists ( commandpath+commandfile ) ) 1007 if ( ! QFile::exists ( commandpath+commandfile ) )
1008 command = commandfile; 1008 command = commandfile;
1009 else 1009 else
1010 command = commandpath+commandfile; 1010 command = commandpath+commandfile;
1011 result = system ( command.latin1()); 1011 result = system ( command.latin1());
1012 qDebug("Cal dump 34 command call result result: %d ", result); 1012 qDebug("Cal dump 34 command call result result: %d ", result);
1013 if ( result != 0 ) { 1013 if ( result != 0 ) {
1014 KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); 1014 KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath ));
1015 return; 1015 return;
1016 } 1016 }
1017 } 1017 }
1018 if ( syncWithFile( fileName,true ) ) { 1018 if ( syncWithFile( fileName,true ) ) {
1019 if ( mWriteBackFile ) { 1019 if ( mWriteBackFile ) {
1020 command += " --read"; 1020 command += " --read";
1021 system ( command.latin1()); 1021 system ( command.latin1());
1022 } 1022 }
1023 } 1023 }
1024 1024
1025 } 1025 }
1026 break; 1026 break;
1027 case (PWMPI): 1027 case (PWMPI):
1028 1028
1029 break; 1029 break;
1030 default: 1030 default:
1031 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 1031 qDebug("KSM::slotSyncMenu: invalid apptype selected");
1032 break; 1032 break;
1033 1033
1034 } 1034 }
1035} 1035}
1036 1036
1037void KSyncManager::syncSharp() 1037void KSyncManager::syncSharp()
1038{ 1038{
1039 1039
1040 if ( ! syncExternalApplication("sharp") ) 1040 if ( ! syncExternalApplication("sharp") )
1041 qDebug("KSM::ERROR sync sharp "); 1041 qDebug("KSM::ERROR sync sharp ");
1042} 1042}
1043 1043
1044bool KSyncManager::syncExternalApplication(QString resource) 1044bool KSyncManager::syncExternalApplication(QString resource)
1045{ 1045{
1046 1046
1047 emit save(); 1047 emit save();
1048 1048
1049 if ( mAskForPreferences ) 1049 if ( mAskForPreferences )
1050 if ( !edit_sync_options()) { 1050 if ( !edit_sync_options()) {
1051 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1051 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1052 return false; 1052 return false;
1053 } 1053 }
1054 1054
1055 qDebug("KSM::Sync extern %s", resource.latin1()); 1055 qDebug("KSM::Sync extern %s", resource.latin1());
1056 1056
1057 bool syncOK = mImplementation->syncExternal(this, resource); 1057 bool syncOK = mImplementation->syncExternal(this, resource);
1058 1058
1059 return syncOK; 1059 return syncOK;
1060 1060
1061} 1061}
1062 1062
1063void KSyncManager::syncPhone() 1063void KSyncManager::syncPhone()
1064{ 1064{
1065 1065
1066 syncExternalApplication("phone"); 1066 syncExternalApplication("phone");
1067 1067
1068} 1068}
1069 1069
1070void KSyncManager::showProgressBar(int percentage, QString caption, int total) 1070void KSyncManager::showProgressBar(int percentage, QString caption, int total)
1071{ 1071{
1072 if (!bar->isVisible()) 1072 if (!bar->isVisible())
1073 { 1073 {
1074 int w = 300; 1074 int w = 300;
1075 if ( QApplication::desktop()->width() < 320 ) 1075 if ( QApplication::desktop()->width() < 320 )
1076 w = 220; 1076 w = 220;
1077 int h = bar->sizeHint().height() ; 1077 int h = bar->sizeHint().height() ;
1078 int dw = QApplication::desktop()->width(); 1078 int dw = QApplication::desktop()->width();
1079 int dh = QApplication::desktop()->height(); 1079 int dh = QApplication::desktop()->height();
1080 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1080 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1081 bar->setCaption (caption); 1081 bar->setCaption (caption);
1082 bar->setTotalSteps ( total ) ; 1082 bar->setTotalSteps ( total ) ;
1083 bar->show(); 1083 bar->show();
1084 } 1084 }
1085 bar->raise(); 1085 bar->raise();
1086 bar->setProgress( percentage ); 1086 bar->setProgress( percentage );
1087 qApp->processEvents(); 1087 qApp->processEvents();
1088} 1088}
1089 1089
1090void KSyncManager::hideProgressBar() 1090void KSyncManager::hideProgressBar()
1091{ 1091{
1092 bar->hide(); 1092 bar->hide();
1093 qApp->processEvents(); 1093 qApp->processEvents();
1094} 1094}
1095 1095
1096bool KSyncManager::isProgressBarCanceled() 1096bool KSyncManager::isProgressBarCanceled()
1097{ 1097{
1098 return !bar->isVisible(); 1098 return !bar->isVisible();
1099} 1099}
1100 1100
1101QString KSyncManager::syncFileName() 1101QString KSyncManager::syncFileName()
1102{ 1102{
1103 1103
1104 QString fn = "tempfile"; 1104 QString fn = "tempfile";
1105 switch(mTargetApp) 1105 switch(mTargetApp)
1106 { 1106 {
1107 case (KAPI): 1107 case (KAPI):
1108 fn = "tempsyncab.vcf"; 1108 fn = "tempsyncab.vcf";
1109 break; 1109 break;
1110 case (KOPI): 1110 case (KOPI):
1111 fn = "tempsynccal.ics"; 1111 fn = "tempsynccal.ics";
1112 break; 1112 break;
1113 case (PWMPI): 1113 case (PWMPI):
1114 fn = "tempsyncpw.pwm"; 1114 fn = "tempsyncpw.pwm";
1115 break; 1115 break;
1116 default: 1116 default:
1117 break; 1117 break;
1118 } 1118 }
1119#ifdef DESKTOP_VERSION 1119#ifdef DESKTOP_VERSION
1120 return locateLocal( "tmp", fn ); 1120 return locateLocal( "tmp", fn );
1121#else 1121#else
1122 return (QString( "/tmp/" )+ fn ); 1122 return (QString( "/tmp/" )+ fn );
1123#endif 1123#endif
1124} 1124}
1125 1125
1126void KSyncManager::syncPi() 1126void KSyncManager::syncPi()
1127{ 1127{
1128 mIsKapiFile = true; 1128 mIsKapiFile = true;
1129 mPisyncFinished = false; 1129 mPisyncFinished = false;
1130 qApp->processEvents(); 1130 qApp->processEvents();
1131 if ( mAskForPreferences ) 1131 if ( mAskForPreferences )
1132 if ( !edit_pisync_options()) { 1132 if ( !edit_pisync_options()) {
1133 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1133 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1134 mPisyncFinished = true; 1134 mPisyncFinished = true;
1135 return; 1135 return;
1136 } 1136 }
1137 bool ok; 1137 bool ok;
1138 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1138 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1139 if ( ! ok ) { 1139 if ( ! ok ) {
1140 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1140 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1141 mPisyncFinished = true; 1141 mPisyncFinished = true;
1142 return; 1142 return;
1143 } 1143 }
1144 mCurrentResourceLocal = ""; 1144 mCurrentResourceLocal = "";
1145 mCurrentResourceRemote = ""; 1145 mCurrentResourceRemote = "";
1146 if ( mSpecificResources.count() ) { 1146 if ( mSpecificResources.count() ) {
1147 uint lastSyncRes = mSpecificResources.count()/2; 1147 uint lastSyncRes = mSpecificResources.count()/2;
1148 int ccc = mSpecificResources.count()-1; 1148 int ccc = mSpecificResources.count()-1;
1149 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { 1149 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) {
1150 --ccc; 1150 --ccc;
1151 --lastSyncRes; 1151 --lastSyncRes;
1152 //qDebug ( "KSM: sync pi %d",ccc ); 1152 //qDebug ( "KSM: sync pi %d",ccc );
1153 } 1153 }
1154 uint startLocal = 0; 1154 uint startLocal = 0;
1155 uint startRemote = mSpecificResources.count()/2; 1155 uint startRemote = mSpecificResources.count()/2;
1156 emit multiResourceSyncStart( true ); 1156 emit multiResourceSyncStart( true );
1157 while ( startLocal < mSpecificResources.count()/2 ) { 1157 while ( startLocal < mSpecificResources.count()/2 ) {
1158 if ( startLocal+1 >= lastSyncRes ) 1158 if ( startLocal+1 >= lastSyncRes )
1159 emit multiResourceSyncStart( false ); 1159 emit multiResourceSyncStart( false );
1160 mPisyncFinished = false; 1160 mPisyncFinished = false;
1161 mCurrentResourceLocal = mSpecificResources[ startLocal ]; 1161 mCurrentResourceLocal = mSpecificResources[ startLocal ];
1162 mCurrentResourceRemote = mSpecificResources[ startRemote ]; 1162 mCurrentResourceRemote = mSpecificResources[ startRemote ];
1163 //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); 1163 //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1164 if ( !mCurrentResourceRemote.isEmpty() ) { 1164 if ( !mCurrentResourceRemote.isEmpty() ) {
1165 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); 1165 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1166 1166
1167 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1167 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1168 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1168 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1169 commandSocket->readFile( syncFileName() ); 1169 commandSocket->readFile( syncFileName() );
1170 mParent->topLevelWidget()->setCaption( i18n("Syncing %1 <-> %2").arg( mCurrentResourceLocal ).arg( mCurrentResourceRemote ) ); 1170 mParent->topLevelWidget()->setCaption( i18n("Syncing %1 <-> %2").arg( mCurrentResourceLocal ).arg( mCurrentResourceRemote ) );
1171 while ( !mPisyncFinished ) { 1171 while ( !mPisyncFinished ) {
1172 //qDebug("waiting "); 1172 //qDebug("waiting ");
1173 qApp->processEvents(); 1173 qApp->processEvents();
1174 } 1174 }
1175 if ( startLocal+1 < mSpecificResources.count()/2 ) { 1175 if ( startLocal+1 < mSpecificResources.count()/2 ) {
1176 mParent->topLevelWidget()->setCaption( i18n("Waiting a second before syncing next resource...") ); 1176 mParent->topLevelWidget()->setCaption( i18n("Waiting a second before syncing next resource...") );
1177 QTime timer; 1177 QTime timer;
1178 timer.start(); 1178 timer.start();
1179 while ( timer.elapsed () < 1000 ) { 1179 while ( timer.elapsed () < 1000 ) {
1180 qApp->processEvents(); 1180 qApp->processEvents();
1181 } 1181 }
1182 } 1182 }
1183 } 1183 }
1184 ++startRemote; 1184 ++startRemote;
1185 ++startLocal; 1185 ++startLocal;
1186 mAskForPreferences = false; 1186 mAskForPreferences = false;
1187 } 1187 }
1188 mPisyncFinished = true; 1188 mPisyncFinished = true;
1189 mParent->topLevelWidget()->setCaption( i18n("Multi-resource Pi-sync finished") );
1189 } else { 1190 } else {
1190 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1191 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1191 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1192 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1192 commandSocket->readFile( syncFileName() ); 1193 commandSocket->readFile( syncFileName() );
1193 } 1194 }
1194} 1195}
1195 1196
1196void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1197void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1197{ 1198{
1198 //enum { success, errorW, errorR, quiet }; 1199 //enum { success, errorW, errorR, quiet };
1199 1200
1200 1201
1201 1202
1202 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || 1203 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
1203 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { 1204 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
1204 if ( state == KCommandSocket::errorPW ) 1205 if ( state == KCommandSocket::errorPW )
1205 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); 1206 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
1206 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) 1207 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
1207 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1208 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1208 else if ( state == KCommandSocket::errorCA ) 1209 else if ( state == KCommandSocket::errorCA )
1209 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); 1210 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
1210 else if ( state == KCommandSocket::errorFI ) 1211 else if ( state == KCommandSocket::errorFI )
1211 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); 1212 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
1212 else if ( state == KCommandSocket::errorED ) 1213 else if ( state == KCommandSocket::errorED )
1213 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); 1214 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
1214 else if ( state == KCommandSocket::errorUN ) 1215 else if ( state == KCommandSocket::errorUN )
1215 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); 1216 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
1216 delete s; 1217 delete s;
1217 if ( state == KCommandSocket::errorR ) { 1218 if ( state == KCommandSocket::errorR ) {
1218 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1219 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1219 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1220 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1220 commandSocket->sendStop(); 1221 commandSocket->sendStop();
1221 } 1222 }
1222 mPisyncFinished = true; 1223 mPisyncFinished = true;
1223 return; 1224 return;
1224 1225
1225 } else if ( state == KCommandSocket::errorW ) { 1226 } else if ( state == KCommandSocket::errorW ) {
1226 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1227 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1227 mPisyncFinished = true; 1228 mPisyncFinished = true;
1228 1229
1229 } else if ( state == KCommandSocket::successR ) { 1230 } else if ( state == KCommandSocket::successR ) {
1230 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1231 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1231 1232
1232 } else if ( state == KCommandSocket::successW ) { 1233 } else if ( state == KCommandSocket::successW ) {
1233 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1234 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1234 mPisyncFinished = true; 1235 mPisyncFinished = true;
1235 } else if ( state == KCommandSocket::quiet ){ 1236 } else if ( state == KCommandSocket::quiet ){
1236 qDebug("KSS: quiet "); 1237 qDebug("KSS: quiet ");
1237 mPisyncFinished = true; 1238 mPisyncFinished = true;
1238 } else { 1239 } else {
1239 qDebug("KSS: Error: unknown state: %d ", state); 1240 qDebug("KSS: Error: unknown state: %d ", state);
1240 mPisyncFinished = true; 1241 mPisyncFinished = true;
1241 } 1242 }
1242 1243
1243 delete s; 1244 delete s;
1244} 1245}
1245 1246
1246void KSyncManager::readFileFromSocket() 1247void KSyncManager::readFileFromSocket()
1247{ 1248{
1248 QString fileName = syncFileName(); 1249 QString fileName = syncFileName();
1249 bool syncOK = true; 1250 bool syncOK = true;
1250 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1251 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1251 if ( ! syncWithFile( fileName , true ) ) { 1252 if ( ! syncWithFile( fileName , true ) ) {
1252 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1253 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1253 syncOK = false; 1254 syncOK = false;
1254 } 1255 }
1255 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1256 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1256 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1257 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1257 if ( mWriteBackFile && syncOK ) { 1258 if ( mWriteBackFile && syncOK ) {
1258 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1259 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1259 commandSocket->writeFile( fileName ); 1260 commandSocket->writeFile( fileName );
1260 } 1261 }
1261 else { 1262 else {
1262 commandSocket->sendStop(); 1263 commandSocket->sendStop();
1263 if ( syncOK ) 1264 if ( syncOK )
1264 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1265 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1265 mPisyncFinished = true; 1266 mPisyncFinished = true;
1266 } 1267 }
1267} 1268}
1268 1269
1269KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1270KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1270{ 1271{
1271 mPendingConnect = 0; 1272 mPendingConnect = 0;
1272 mPassWord = pw; 1273 mPassWord = pw;
1273 mSocket = 0; 1274 mSocket = 0;
1274 mSyncActionDialog = 0; 1275 mSyncActionDialog = 0;
1275 blockRC = false; 1276 blockRC = false;
1276 mErrorMessage = 0; 1277 mErrorMessage = 0;
1277} 1278}
1278void KServerSocket::waitForSocketFinish() 1279void KServerSocket::waitForSocketFinish()
1279{ 1280{
1280 if ( mSocket ) { 1281 if ( mSocket ) {
1281 //qDebug("KSS:: waiting for finish operation"); 1282 //qDebug("KSS:: waiting for finish operation");
1282 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1283 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1283 return; 1284 return;
1284 } 1285 }
1285 mSocket = new QSocket( this ); 1286 mSocket = new QSocket( this );
1286 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1287 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1287 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1288 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1288 mSocket->setSocket( mPendingConnect ); 1289 mSocket->setSocket( mPendingConnect );
1289 mPendingConnect = 0; 1290 mPendingConnect = 0;
1290} 1291}
1291void KServerSocket::newConnection ( int socket ) 1292void KServerSocket::newConnection ( int socket )
1292{ 1293{
1293 // qDebug("KServerSocket:New connection %d ", socket); 1294 // qDebug("KServerSocket:New connection %d ", socket);
1294 if ( mPendingConnect ) { 1295 if ( mPendingConnect ) {
1295 qDebug("KSS::Error : new Connection"); 1296 qDebug("KSS::Error : new Connection");
1296 return; 1297 return;
1297 } 1298 }
1298 if ( mSocket ) { 1299 if ( mSocket ) {
1299 mPendingConnect = socket; 1300 mPendingConnect = socket;
1300 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1301 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1301 return; 1302 return;
1302 qDebug("KSS::newConnection Socket deleted! "); 1303 qDebug("KSS::newConnection Socket deleted! ");
1303 delete mSocket; 1304 delete mSocket;
1304 mSocket = 0; 1305 mSocket = 0;
1305 } 1306 }
1306 mPendingConnect = 0; 1307 mPendingConnect = 0;
1307 mSocket = new QSocket( this ); 1308 mSocket = new QSocket( this );
1308 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1309 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1309 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1310 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1310 mSocket->setSocket( socket ); 1311 mSocket->setSocket( socket );
1311} 1312}
1312 1313
1313void KServerSocket::discardClient() 1314void KServerSocket::discardClient()
1314{ 1315{
1315 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1316 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1316} 1317}
1317void KServerSocket::deleteSocket() 1318void KServerSocket::deleteSocket()
1318{ 1319{
1319 //qDebug("KSS::deleteSocket"); 1320 //qDebug("KSS::deleteSocket");
1320 if ( mSocket ) { 1321 if ( mSocket ) {
1321 delete mSocket; 1322 delete mSocket;
1322 mSocket = 0; 1323 mSocket = 0;
1323 } 1324 }
1324 if ( mErrorMessage ) 1325 if ( mErrorMessage )
1325 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1326 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1326} 1327}
1327void KServerSocket::readClient() 1328void KServerSocket::readClient()
1328{ 1329{
1329 if ( blockRC ) 1330 if ( blockRC )
1330 return; 1331 return;
1331 if ( mSocket == 0 ) { 1332 if ( mSocket == 0 ) {
1332 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1333 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1333 return; 1334 return;
1334 } 1335 }
1335 if ( mErrorMessage ) { 1336 if ( mErrorMessage ) {
1336 mErrorMessage = 999; 1337 mErrorMessage = 999;
1337 error_connect("ERROR_ED\r\n\r\n"); 1338 error_connect("ERROR_ED\r\n\r\n");
1338 return; 1339 return;
1339 } 1340 }
1340 mResource = ""; 1341 mResource = "";
1341 mErrorMessage = 0; 1342 mErrorMessage = 0;
1342 //qDebug("KServerSocket::readClient()"); 1343 //qDebug("KServerSocket::readClient()");
1343 if ( mSocket->canReadLine() ) { 1344 if ( mSocket->canReadLine() ) {
1344 QString line = mSocket->readLine(); 1345 QString line = mSocket->readLine();
1345 //qDebug("KServerSocket readline: %s ", line.latin1()); 1346 //qDebug("KServerSocket readline: %s ", line.latin1());
1346 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1347 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1347 if ( tokens[0] == "GET" ) { 1348 if ( tokens[0] == "GET" ) {
1348 if ( tokens[1] == mPassWord ) { 1349 if ( tokens[1] == mPassWord ) {
1349 //emit sendFile( mSocket ); 1350 //emit sendFile( mSocket );
1350 bool ok = false; 1351 bool ok = false;
1351 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1352 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1352 if ( ok ) { 1353 if ( ok ) {
1353 KSyncManager::mRequestedSyncEvent = dt; 1354 KSyncManager::mRequestedSyncEvent = dt;
1354 } 1355 }
1355 else 1356 else
1356 KSyncManager::mRequestedSyncEvent = QDateTime(); 1357 KSyncManager::mRequestedSyncEvent = QDateTime();
1357 mResource =tokens[3]; 1358 mResource =tokens[3];
1358 send_file(); 1359 send_file();
1359 } 1360 }
1360 else { 1361 else {
1361 mErrorMessage = 1; 1362 mErrorMessage = 1;
1362 error_connect("ERROR_PW\r\n\r\n"); 1363 error_connect("ERROR_PW\r\n\r\n");
1363 } 1364 }
1364 } 1365 }
1365 if ( tokens[0] == "PUT" ) { 1366 if ( tokens[0] == "PUT" ) {
1366 if ( tokens[1] == mPassWord ) { 1367 if ( tokens[1] == mPassWord ) {
1367 //emit getFile( mSocket ); 1368 //emit getFile( mSocket );
1368 blockRC = true; 1369 blockRC = true;
1369 mResource =tokens[2]; 1370 mResource =tokens[2];
1370 get_file(); 1371 get_file();
1371 } 1372 }
1372 else { 1373 else {
1373 mErrorMessage = 2; 1374 mErrorMessage = 2;
1374 error_connect("ERROR_PW\r\n\r\n"); 1375 error_connect("ERROR_PW\r\n\r\n");
1375 end_connect(); 1376 end_connect();
1376 } 1377 }
1377 } 1378 }
1378 if ( tokens[0] == "STOP" ) { 1379 if ( tokens[0] == "STOP" ) {
1379 //emit endConnect(); 1380 //emit endConnect();
1380 end_connect(); 1381 end_connect();
1381 } 1382 }
1382 } 1383 }
1383} 1384}
1384void KServerSocket::displayErrorMessage() 1385void KServerSocket::displayErrorMessage()
1385{ 1386{
1386 if ( mErrorMessage == 1 ) { 1387 if ( mErrorMessage == 1 ) {
1387 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1388 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1388 mErrorMessage = 0; 1389 mErrorMessage = 0;
1389 } 1390 }
1390 else if ( mErrorMessage == 2 ) { 1391 else if ( mErrorMessage == 2 ) {
1391 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1392 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1392 mErrorMessage = 0; 1393 mErrorMessage = 0;
1393 } 1394 }
1394} 1395}
1395void KServerSocket::error_connect( QString errmess ) 1396void KServerSocket::error_connect( QString errmess )
1396{ 1397{
1397 QTextStream os( mSocket ); 1398 QTextStream os( mSocket );
1398 os.setEncoding( QTextStream::Latin1 ); 1399 os.setEncoding( QTextStream::Latin1 );
1399 os << errmess ; 1400 os << errmess ;
1400 mSocket->close(); 1401 mSocket->close();
1401 if ( mSocket->state() == QSocket::Idle ) { 1402 if ( mSocket->state() == QSocket::Idle ) {
1402 QTimer::singleShot( 0, this , SLOT ( discardClient())); 1403 QTimer::singleShot( 0, this , SLOT ( discardClient()));
1403 } 1404 }
1404} 1405}
1405void KServerSocket::end_connect() 1406void KServerSocket::end_connect()
1406{ 1407{
1407 delete mSyncActionDialog; 1408 delete mSyncActionDialog;
1408 mSyncActionDialog = 0; 1409 mSyncActionDialog = 0;
1409} 1410}
1410void KServerSocket::send_file() 1411void KServerSocket::send_file()
1411{ 1412{
1412 //qDebug("MainWindow::sendFile(QSocket* s) "); 1413 //qDebug("MainWindow::sendFile(QSocket* s) ");
1413 if ( mSyncActionDialog ) 1414 if ( mSyncActionDialog )
1414 delete mSyncActionDialog; 1415 delete mSyncActionDialog;
1415 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1416 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1416 mSyncActionDialog->setCaption(i18n("Received sync request")); 1417 mSyncActionDialog->setCaption(i18n("Received sync request"));
1417 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1418 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1418 label->setAlignment ( Qt::AlignHCenter ); 1419 label->setAlignment ( Qt::AlignHCenter );
1419 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1420 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1420 lay->addWidget( label); 1421 lay->addWidget( label);
1421 lay->setMargin(7); 1422 lay->setMargin(7);
1422 lay->setSpacing(7); 1423 lay->setSpacing(7);
1423 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1424 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1424 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1425 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1425 //secs = 333; 1426 //secs = 333;
1426 if ( secs < 0 ) 1427 if ( secs < 0 )
1427 secs = secs * (-1); 1428 secs = secs * (-1);
1428 if ( secs > 30 ) 1429 if ( secs > 30 )
1429 //if ( true ) 1430 //if ( true )
1430 { 1431 {
1431 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1432 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1432 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1433 QLabel* label = new QLabel( warning, mSyncActionDialog );
1433 label->setAlignment ( Qt::AlignHCenter ); 1434 label->setAlignment ( Qt::AlignHCenter );
1434 lay->addWidget( label); 1435 lay->addWidget( label);
1435 if ( secs > 180 ) 1436 if ( secs > 180 )
1436 { 1437 {
1437 if ( secs > 300 ) { 1438 if ( secs > 300 ) {
1438 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1439 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1439 qDebug("KSS::Sync cancelled ,cs"); 1440 qDebug("KSS::Sync cancelled ,cs");
1440 mErrorMessage = 0; 1441 mErrorMessage = 0;
1441 end_connect(); 1442 end_connect();
1442 error_connect("ERROR_CA\r\n\r\n"); 1443 error_connect("ERROR_CA\r\n\r\n");
1443 return ; 1444 return ;
1444 } 1445 }
1445 } 1446 }
1446 QFont f = label->font(); 1447 QFont f = label->font();
1447 f.setPointSize ( f.pointSize() *2 ); 1448 f.setPointSize ( f.pointSize() *2 );
1448 f. setBold (true ); 1449 f. setBold (true );
1449 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1450 QLabel* label = new QLabel( warning, mSyncActionDialog );
1450 label->setFont( f ); 1451 label->setFont( f );
1451 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1452 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1452 label->setText( warning ); 1453 label->setText( warning );
1453 label->setAlignment ( Qt::AlignHCenter ); 1454 label->setAlignment ( Qt::AlignHCenter );
1454 lay->addWidget( label); 1455 lay->addWidget( label);
1455 mSyncActionDialog->setFixedSize( 230, 300); 1456 mSyncActionDialog->setFixedSize( 230, 300);
1456 } else { 1457 } else {
1457 mSyncActionDialog->setFixedSize( 230, 200); 1458 mSyncActionDialog->setFixedSize( 230, 200);
1458 } 1459 }
1459 } else { 1460 } else {
1460 mSyncActionDialog->setFixedSize( 230, 120); 1461 mSyncActionDialog->setFixedSize( 230, 120);
1461 } 1462 }
1462 } else 1463 } else
1463 mSyncActionDialog->setFixedSize( 230, 120); 1464 mSyncActionDialog->setFixedSize( 230, 120);
1464 mSyncActionDialog->show(); 1465 mSyncActionDialog->show();
1465 mSyncActionDialog->raise(); 1466 mSyncActionDialog->raise();
1466 emit request_file(mResource); 1467 emit request_file(mResource);
1467 //emit request_file(); 1468 //emit request_file();
1468 qApp->processEvents(); 1469 qApp->processEvents();
1469 QString fileName = mFileName; 1470 QString fileName = mFileName;
1470 QFile file( fileName ); 1471 QFile file( fileName );
1471 if (!file.open( IO_ReadOnly ) ) { 1472 if (!file.open( IO_ReadOnly ) ) {
1472 mErrorMessage = 0; 1473 mErrorMessage = 0;
1473 end_connect(); 1474 end_connect();
1474 error_connect("ERROR_FI\r\n\r\n"); 1475 error_connect("ERROR_FI\r\n\r\n");
1475 return ; 1476 return ;
1476 } 1477 }
1477 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1478 mSyncActionDialog->setCaption( i18n("Sending file...") );
1478 QTextStream ts( &file ); 1479 QTextStream ts( &file );
1479 ts.setEncoding( QTextStream::Latin1 ); 1480 ts.setEncoding( QTextStream::Latin1 );
1480 1481
1481 QTextStream os( mSocket ); 1482 QTextStream os( mSocket );
1482 os.setEncoding( QTextStream::Latin1 ); 1483 os.setEncoding( QTextStream::Latin1 );
1483 while ( ! ts.atEnd() ) { 1484 while ( ! ts.atEnd() ) {
1484 os << ts.readLine() << "\r\n"; 1485 os << ts.readLine() << "\r\n";
1485 } 1486 }
1486 os << "\r\n"; 1487 os << "\r\n";
1487 //os << ts.read(); 1488 //os << ts.read();
1488 file.close(); 1489 file.close();
1489 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1490 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1490 mSocket->close(); 1491 mSocket->close();
1491 if ( mSocket->state() == QSocket::Idle ) 1492 if ( mSocket->state() == QSocket::Idle )
1492 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1493 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1493} 1494}
1494void KServerSocket::get_file() 1495void KServerSocket::get_file()
1495{ 1496{
1496 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1497 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1497 1498
1498 piTime.start(); 1499 piTime.start();
1499 piFileString = ""; 1500 piFileString = "";
1500 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1501 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1501} 1502}
1502 1503
1503 1504
1504void KServerSocket::readBackFileFromSocket() 1505void KServerSocket::readBackFileFromSocket()
1505{ 1506{
1506 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1507 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1507 while ( mSocket->canReadLine () ) { 1508 while ( mSocket->canReadLine () ) {
1508 piTime.restart(); 1509 piTime.restart();
1509 QString line = mSocket->readLine (); 1510 QString line = mSocket->readLine ();
1510 piFileString += line; 1511 piFileString += line;
1511 //qDebug("readline: %s ", line.latin1()); 1512 //qDebug("readline: %s ", line.latin1());
1512 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1513 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1513 1514
1514 } 1515 }
1515 if ( piTime.elapsed () < 3000 ) { 1516 if ( piTime.elapsed () < 3000 ) {
1516 // wait for more 1517 // wait for more
1517 //qDebug("waitformore "); 1518 //qDebug("waitformore ");
1518 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1519 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1519 return; 1520 return;
1520 } 1521 }
1521 QString fileName = mFileName; 1522 QString fileName = mFileName;
1522 QFile file ( fileName ); 1523 QFile file ( fileName );
1523 if (!file.open( IO_WriteOnly ) ) { 1524 if (!file.open( IO_WriteOnly ) ) {
1524 delete mSyncActionDialog; 1525 delete mSyncActionDialog;
1525 mSyncActionDialog = 0; 1526 mSyncActionDialog = 0;
1526 qDebug("KSS:Error open read back file "); 1527 qDebug("KSS:Error open read back file ");
1527 piFileString = ""; 1528 piFileString = "";
1528 emit file_received( false, mResource); 1529 emit file_received( false, mResource);
1529 emit file_received( false); 1530 emit file_received( false);
1530 blockRC = false; 1531 blockRC = false;
1531 return ; 1532 return ;
1532 1533
1533 } 1534 }
1534 1535
1535 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1536 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1536 QTextStream ts ( &file ); 1537 QTextStream ts ( &file );
1537 ts.setEncoding( QTextStream::Latin1 ); 1538 ts.setEncoding( QTextStream::Latin1 );
1538 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1539 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1539 ts << piFileString; 1540 ts << piFileString;
1540 mSocket->close(); 1541 mSocket->close();
1541 if ( mSocket->state() == QSocket::Idle ) 1542 if ( mSocket->state() == QSocket::Idle )
1542 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1543 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1543 file.close(); 1544 file.close();
1544 piFileString = ""; 1545 piFileString = "";
1545 emit file_received( true, mResource ); 1546 emit file_received( true, mResource );
1546 emit file_received( true); 1547 emit file_received( true);
1547 delete mSyncActionDialog; 1548 delete mSyncActionDialog;
1548 mSyncActionDialog = 0; 1549 mSyncActionDialog = 0;
1549 blockRC = false; 1550 blockRC = false;
1550 1551
1551} 1552}
1552 1553
1553KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1554KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1554{ 1555{
1555 mRemoteResource = remres; 1556 mRemoteResource = remres;
1556 if ( mRemoteResource.isEmpty() ) 1557 if ( mRemoteResource.isEmpty() )
1557 mRemoteResource = "ALL"; 1558 mRemoteResource = "ALL";
1558 else 1559 else
1559 mRemoteResource.replace (QRegExp (" "),"_" ); 1560 mRemoteResource.replace (QRegExp (" "),"_" );
1560 mPassWord = password; 1561 mPassWord = password;
1561 mSocket = 0; 1562 mSocket = 0;
1562 mFirst = false; 1563 mFirst = false;
1563 mFirstLine = true; 1564 mFirstLine = true;
1564 mPort = port; 1565 mPort = port;
1565 mHost = host; 1566 mHost = host;
1566 tlw = cap; 1567 tlw = cap;
1567 mRetVal = quiet; 1568 mRetVal = quiet;
1568 mTimerSocket = new QTimer ( this ); 1569 mTimerSocket = new QTimer ( this );
1569 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1570 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1570 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1571 mConnectProgress.setCaption( i18n("Pi-Sync") );
1571 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1572 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1572 mConnectCount = -1; 1573 mConnectCount = -1;
1573} 1574}
1574void KCommandSocket::sendFileRequest() 1575void KCommandSocket::sendFileRequest()
1575{ 1576{
1576 if ( tlw ) 1577 if ( tlw )
1577 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1578 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1578 mConnectProgress.hide(); 1579 mConnectProgress.hide();
1579 mConnectCount = 300;mConnectMax = 300; 1580 mConnectCount = 300;mConnectMax = 300;
1580 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1581 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1581 mConnectProgress.setLabelText( i18n("Waiting for remote file...") ); 1582 mConnectProgress.setLabelText( i18n("Waiting for remote file...") );
1582 mTimerSocket->start( 100, true ); 1583 mTimerSocket->start( 100, true );
1583 QTextStream os( mSocket ); 1584 QTextStream os( mSocket );
1584 os.setEncoding( QTextStream::Latin1 ); 1585 os.setEncoding( QTextStream::Latin1 );
1585 1586
1586 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1587 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1587 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; 1588 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n";
1588} 1589}
1589 1590
1590void KCommandSocket::readFile( QString fn ) 1591void KCommandSocket::readFile( QString fn )
1591{ 1592{
1592 if ( !mSocket ) { 1593 if ( !mSocket ) {
1593 mSocket = new QSocket( this ); 1594 mSocket = new QSocket( this );
1594 //qDebug("KCS: read file - new socket"); 1595 //qDebug("KCS: read file - new socket");
1595 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1596 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1596 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1597 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1597 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1598 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1598 } 1599 }
1599 mFileString = ""; 1600 mFileString = "";
1600 mFileName = fn; 1601 mFileName = fn;
1601 mFirst = true; 1602 mFirst = true;
1602 if ( tlw ) 1603 if ( tlw )
1603 tlw->setCaption( i18n("Trying to connect to remote...") ); 1604 tlw->setCaption( i18n("Trying to connect to remote...") );
1604 mConnectCount = 30;mConnectMax = 30; 1605 mConnectCount = 30;mConnectMax = 30;
1605 mTimerSocket->start( 1000, true ); 1606 mTimerSocket->start( 1000, true );
1606 mSocket->connectToHost( mHost, mPort ); 1607 mSocket->connectToHost( mHost, mPort );
1607 //qDebug("KCS: Waiting for connection"); 1608 //qDebug("KCS: Waiting for connection");
1608} 1609}
1609void KCommandSocket::updateConnectDialog() 1610void KCommandSocket::updateConnectDialog()
1610{ 1611{
1611 1612
1612 if ( mConnectCount == mConnectMax ) { 1613 if ( mConnectCount == mConnectMax ) {
1613 //qDebug("MAXX %d", mConnectMax); 1614 //qDebug("MAXX %d", mConnectMax);
1614 mConnectProgress.setTotalSteps ( 30 ); 1615 mConnectProgress.setTotalSteps ( 30 );
1615 mConnectProgress.show(); 1616 mConnectProgress.show();
1616 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1617 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1617 } 1618 }
1618 //qDebug("updateConnectDialog() %d", mConnectCount); 1619 //qDebug("updateConnectDialog() %d", mConnectCount);
1619 mConnectProgress.raise(); 1620 mConnectProgress.raise();
1620 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1621 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1621 --mConnectCount; 1622 --mConnectCount;
1622 if ( mConnectCount > 0 ) 1623 if ( mConnectCount > 0 )
1623 mTimerSocket->start( 1000, true ); 1624 mTimerSocket->start( 1000, true );
1624 else 1625 else
1625 deleteSocket(); 1626 deleteSocket();
1626 1627
1627} 1628}
1628void KCommandSocket::writeFile( QString fileName ) 1629void KCommandSocket::writeFile( QString fileName )
1629{ 1630{
1630 if ( !mSocket ) { 1631 if ( !mSocket ) {
1631 mSocket = new QSocket( this ); 1632 mSocket = new QSocket( this );
1632 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1633 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1633 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1634 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1634 } 1635 }
1635 mFileName = fileName ; 1636 mFileName = fileName ;
1636 mConnectCount = 30;mConnectMax = 30; 1637 mConnectCount = 30;mConnectMax = 30;
1637 mTimerSocket->start( 1000, true ); 1638 mTimerSocket->start( 1000, true );
1638 mSocket->connectToHost( mHost, mPort ); 1639 mSocket->connectToHost( mHost, mPort );
1639} 1640}
1640void KCommandSocket::writeFileToSocket() 1641void KCommandSocket::writeFileToSocket()
1641{ 1642{
1642 mTimerSocket->stop(); 1643 mTimerSocket->stop();
1643 QFile file2( mFileName ); 1644 QFile file2( mFileName );
1644 if (!file2.open( IO_ReadOnly ) ) { 1645 if (!file2.open( IO_ReadOnly ) ) {
1645 mConnectProgress.hide(); 1646 mConnectProgress.hide();
1646 mConnectCount = -1; 1647 mConnectCount = -1;
1647 mRetVal= errorW; 1648 mRetVal= errorW;
1648 mSocket->close(); 1649 mSocket->close();
1649 if ( mSocket->state() == QSocket::Idle ) 1650 if ( mSocket->state() == QSocket::Idle )
1650 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1651 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1651 return ; 1652 return ;
1652 } 1653 }
1653 mConnectProgress.setTotalSteps ( file2.size() ); 1654 mConnectProgress.setTotalSteps ( file2.size() );
1654 mConnectProgress.show(); 1655 mConnectProgress.show();
1655 int count = 0; 1656 int count = 0;
1656 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1657 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1657 mConnectProgress.setProgress( count ); 1658 mConnectProgress.setProgress( count );
1658 mConnectProgress.blockSignals( true ); 1659 mConnectProgress.blockSignals( true );
1659 QTextStream ts2( &file2 ); 1660 QTextStream ts2( &file2 );
1660 ts2.setEncoding( QTextStream::Latin1 ); 1661 ts2.setEncoding( QTextStream::Latin1 );
1661 QTextStream os2( mSocket ); 1662 QTextStream os2( mSocket );
1662 os2.setEncoding( QTextStream::Latin1 ); 1663 os2.setEncoding( QTextStream::Latin1 );
1663 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; 1664 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
1664 int byteCount = 0; 1665 int byteCount = 0;
1665 int byteMax = file2.size()/53; 1666 int byteMax = file2.size()/53;
1666 while ( ! ts2.atEnd() ) { 1667 while ( ! ts2.atEnd() ) {
1667 qApp->processEvents(); 1668 qApp->processEvents();
1668 if ( byteCount > byteMax ) { 1669 if ( byteCount > byteMax ) {
1669 byteCount = 0; 1670 byteCount = 0;
1670 mConnectProgress.setProgress( count ); 1671 mConnectProgress.setProgress( count );
1671 } 1672 }
1672 QString temp = ts2.readLine(); 1673 QString temp = ts2.readLine();
1673 count += temp.length(); 1674 count += temp.length();
1674 byteCount += temp.length(); 1675 byteCount += temp.length();
1675 os2 << temp << "\r\n"; 1676 os2 << temp << "\r\n";
1676 } 1677 }
1677 file2.close(); 1678 file2.close();
1678 mConnectProgress.hide(); 1679 mConnectProgress.hide();
1679 mConnectCount = -1; 1680 mConnectCount = -1;
1680 os2 << "\r\n"; 1681 os2 << "\r\n";
1681 mRetVal= successW; 1682 mRetVal= successW;
1682 mSocket->close(); 1683 mSocket->close();
1683 if ( mSocket->state() == QSocket::Idle ) 1684 if ( mSocket->state() == QSocket::Idle )
1684 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1685 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1685 mConnectProgress.blockSignals( false ); 1686 mConnectProgress.blockSignals( false );
1686} 1687}
1687void KCommandSocket::sendStop() 1688void KCommandSocket::sendStop()
1688{ 1689{
1689 if ( !mSocket ) { 1690 if ( !mSocket ) {
1690 mSocket = new QSocket( this ); 1691 mSocket = new QSocket( this );
1691 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1692 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1692 } 1693 }
1693 mSocket->connectToHost( mHost, mPort ); 1694 mSocket->connectToHost( mHost, mPort );
1694 QTextStream os2( mSocket ); 1695 QTextStream os2( mSocket );
1695 os2.setEncoding( QTextStream::Latin1 ); 1696 os2.setEncoding( QTextStream::Latin1 );
1696 os2 << "STOP\r\n\r\n"; 1697 os2 << "STOP\r\n\r\n";
1697 mSocket->close(); 1698 mSocket->close();
1698 if ( mSocket->state() == QSocket::Idle ) 1699 if ( mSocket->state() == QSocket::Idle )
1699 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1700 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1700} 1701}