summaryrefslogtreecommitdiffabout
path: root/libkdepim
authorzautrix <zautrix>2004-10-07 13:22:40 (UTC)
committer zautrix <zautrix>2004-10-07 13:22:40 (UTC)
commitd14d61ebb2e41329465883a0dfce719d69fc3f3e (patch) (unidiff)
tree39330d3848e530f9ba8deac4086685674acdc839 /libkdepim
parent826dc960353e47a60aba13916189c45ef3392c1e (diff)
downloadkdepimpi-d14d61ebb2e41329465883a0dfce719d69fc3f3e.zip
kdepimpi-d14d61ebb2e41329465883a0dfce719d69fc3f3e.tar.gz
kdepimpi-d14d61ebb2e41329465883a0dfce719d69fc3f3e.tar.bz2
utf8 fixes
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index a663427..28af135 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -553,596 +553,596 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
553 while ( len < preCommand.length() ) { 553 while ( len < preCommand.length() ) {
554 preCommand.insert( len , "\n" ); 554 preCommand.insert( len , "\n" );
555 len += maxlen +2; 555 len += maxlen +2;
556 } 556 }
557 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) ; 557 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) ;
558 QMessageBox::information( mParent, i18n("Sync - ERROR"), 558 QMessageBox::information( mParent, i18n("Sync - ERROR"),
559 question, 559 question,
560 i18n("Okay!")) ; 560 i18n("Okay!")) ;
561 mParent->topLevelWidget()->setCaption (""); 561 mParent->topLevelWidget()->setCaption ("");
562 return; 562 return;
563 } 563 }
564 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 564 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
565 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 565 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
566 566
567 567
568 568
569 if ( syncWithFile( localTempFile, true ) ) { 569 if ( syncWithFile( localTempFile, true ) ) {
570// Event* e = mView->getLastSyncEvent(); 570// Event* e = mView->getLastSyncEvent();
571// e->setReadOnly( false ); 571// e->setReadOnly( false );
572// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 572// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
573// e->setReadOnly( true ); 573// e->setReadOnly( true );
574 if ( mWriteBackFile ) { 574 if ( mWriteBackFile ) {
575 int fi; 575 int fi;
576 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 576 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
577 QString pwd = getPassword(); 577 QString pwd = getPassword();
578 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 578 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
579 579
580 } 580 }
581 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 581 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
582 result = system ( postCommand ); 582 result = system ( postCommand );
583 qDebug("Writing back file result: %d ", result); 583 qDebug("Writing back file result: %d ", result);
584 if ( result != 0 ) { 584 if ( result != 0 ) {
585 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 585 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
586 return; 586 return;
587 } else { 587 } else {
588 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 588 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
589 } 589 }
590 } 590 }
591 } 591 }
592 return; 592 return;
593} 593}
594 594
595void KSyncManager::edit_sync_options() 595void KSyncManager::edit_sync_options()
596{ 596{
597 //mDialogManager->showSyncOptions(); 597 //mDialogManager->showSyncOptions();
598 //mSyncAlgoPrefs 598 //mSyncAlgoPrefs
599 QDialog dia( mParent, "dia", true ); 599 QDialog dia( mParent, "dia", true );
600 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 600 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
601 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 601 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
602 QVBoxLayout lay ( &dia ); 602 QVBoxLayout lay ( &dia );
603 lay.setSpacing( 2 ); 603 lay.setSpacing( 2 );
604 lay.setMargin( 3 ); 604 lay.setMargin( 3 );
605 lay.addWidget(&gr); 605 lay.addWidget(&gr);
606 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 606 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
607 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 607 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
608 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 608 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
609 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 609 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
610 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 610 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
611 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 611 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
612 //QRadioButton both( i18n("Take both on conflict"), &gr ); 612 //QRadioButton both( i18n("Take both on conflict"), &gr );
613 QPushButton pb ( "OK", &dia); 613 QPushButton pb ( "OK", &dia);
614 lay.addWidget( &pb ); 614 lay.addWidget( &pb );
615 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 615 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
616 switch ( mSyncAlgoPrefs ) { 616 switch ( mSyncAlgoPrefs ) {
617 case 0: 617 case 0:
618 loc.setChecked( true); 618 loc.setChecked( true);
619 break; 619 break;
620 case 1: 620 case 1:
621 rem.setChecked( true ); 621 rem.setChecked( true );
622 break; 622 break;
623 case 2: 623 case 2:
624 newest.setChecked( true); 624 newest.setChecked( true);
625 break; 625 break;
626 case 3: 626 case 3:
627 ask.setChecked( true); 627 ask.setChecked( true);
628 break; 628 break;
629 case 4: 629 case 4:
630 f_loc.setChecked( true); 630 f_loc.setChecked( true);
631 break; 631 break;
632 case 5: 632 case 5:
633 f_rem.setChecked( true); 633 f_rem.setChecked( true);
634 break; 634 break;
635 case 6: 635 case 6:
636 // both.setChecked( true); 636 // both.setChecked( true);
637 break; 637 break;
638 default: 638 default:
639 break; 639 break;
640 } 640 }
641 if ( dia.exec() ) { 641 if ( dia.exec() ) {
642 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 642 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
643 } 643 }
644 644
645 645
646} 646}
647QString KSyncManager::getPassword( ) 647QString KSyncManager::getPassword( )
648{ 648{
649 QString retfile = ""; 649 QString retfile = "";
650 QDialog dia ( mParent, "input-dialog", true ); 650 QDialog dia ( mParent, "input-dialog", true );
651 QLineEdit lab ( &dia ); 651 QLineEdit lab ( &dia );
652 lab.setEchoMode( QLineEdit::Password ); 652 lab.setEchoMode( QLineEdit::Password );
653 QVBoxLayout lay( &dia ); 653 QVBoxLayout lay( &dia );
654 lay.setMargin(7); 654 lay.setMargin(7);
655 lay.setSpacing(7); 655 lay.setSpacing(7);
656 lay.addWidget( &lab); 656 lay.addWidget( &lab);
657 dia.setFixedSize( 230,50 ); 657 dia.setFixedSize( 230,50 );
658 dia.setCaption( i18n("Enter password") ); 658 dia.setCaption( i18n("Enter password") );
659 QPushButton pb ( "OK", &dia); 659 QPushButton pb ( "OK", &dia);
660 lay.addWidget( &pb ); 660 lay.addWidget( &pb );
661 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 661 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
662 dia.show(); 662 dia.show();
663 int res = dia.exec(); 663 int res = dia.exec();
664 if ( res ) 664 if ( res )
665 retfile = lab.text(); 665 retfile = lab.text();
666 dia.hide(); 666 dia.hide();
667 qApp->processEvents(); 667 qApp->processEvents();
668 return retfile; 668 return retfile;
669 669
670} 670}
671 671
672 672
673void KSyncManager::confSync() 673void KSyncManager::confSync()
674{ 674{
675 static KSyncPrefsDialog* sp = 0; 675 static KSyncPrefsDialog* sp = 0;
676 if ( ! sp ) { 676 if ( ! sp ) {
677 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 677 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
678 } 678 }
679 sp->usrReadConfig(); 679 sp->usrReadConfig();
680#ifndef DESKTOP_VERSION 680#ifndef DESKTOP_VERSION
681 sp->showMaximized(); 681 sp->showMaximized();
682#else 682#else
683 sp->show(); 683 sp->show();
684#endif 684#endif
685 sp->exec(); 685 sp->exec();
686 mSyncProfileNames = sp->getSyncProfileNames(); 686 mSyncProfileNames = sp->getSyncProfileNames();
687 mLocalMachineName = sp->getLocalMachineName (); 687 mLocalMachineName = sp->getLocalMachineName ();
688 fillSyncMenu(); 688 fillSyncMenu();
689} 689}
690 690
691void KSyncManager::syncSharp() 691void KSyncManager::syncSharp()
692{ 692{
693 if ( ! syncExternalApplication("sharp") ) 693 if ( ! syncExternalApplication("sharp") )
694 qDebug("ERROR sync sharp ");; 694 qDebug("ERROR sync sharp ");;
695} 695}
696 696
697bool KSyncManager::syncExternalApplication(QString resource) 697bool KSyncManager::syncExternalApplication(QString resource)
698{ 698{
699 699
700 emit save(); 700 emit save();
701 701
702 if ( mAskForPreferences ) 702 if ( mAskForPreferences )
703 edit_sync_options(); 703 edit_sync_options();
704 704
705 qDebug("sync %s", resource.latin1()); 705 qDebug("sync %s", resource.latin1());
706 706
707 bool syncOK = mImplementation->syncExternal(this, resource); 707 bool syncOK = mImplementation->syncExternal(this, resource);
708 708
709 return syncOK; 709 return syncOK;
710 710
711} 711}
712 712
713void KSyncManager::syncPhone() 713void KSyncManager::syncPhone()
714{ 714{
715 emit save(); 715 emit save();
716 716
717 qDebug("pending syncPhone(); "); 717 qDebug("pending syncPhone(); ");
718 //mView->syncPhone(); 718 //mView->syncPhone();
719 719
720} 720}
721 721
722void KSyncManager::showProgressBar(int percentage, QString caption, int total) 722void KSyncManager::showProgressBar(int percentage, QString caption, int total)
723{ 723{
724 if (!bar->isVisible()) 724 if (!bar->isVisible())
725 { 725 {
726 bar->setCaption (caption); 726 bar->setCaption (caption);
727 bar->setTotalSteps ( total ) ; 727 bar->setTotalSteps ( total ) ;
728 728
729 bar->show(); 729 bar->show();
730 } 730 }
731 731
732 bar->setProgress( percentage ); 732 bar->setProgress( percentage );
733} 733}
734 734
735void KSyncManager::hideProgressBar() 735void KSyncManager::hideProgressBar()
736{ 736{
737 bar->hide(); 737 bar->hide();
738} 738}
739 739
740bool KSyncManager::isProgressBarCanceled() 740bool KSyncManager::isProgressBarCanceled()
741{ 741{
742 return !bar->isVisible(); 742 return !bar->isVisible();
743} 743}
744 744
745QString KSyncManager::syncFileName() 745QString KSyncManager::syncFileName()
746{ 746{
747 747
748 QString fn = "tempfile"; 748 QString fn = "tempfile";
749 switch(mTargetApp) 749 switch(mTargetApp)
750 { 750 {
751 case (KAPI): 751 case (KAPI):
752 fn = "tempsyncab.vcf"; 752 fn = "tempsyncab.vcf";
753 break; 753 break;
754 case (KOPI): 754 case (KOPI):
755 fn = "tempsynccal.ics"; 755 fn = "tempsynccal.ics";
756 break; 756 break;
757 case (PWMPI): 757 case (PWMPI):
758 fn = "tempsyncpw.pwm"; 758 fn = "tempsyncpw.pwm";
759 break; 759 break;
760 default: 760 default:
761 break; 761 break;
762 } 762 }
763#ifdef _WIN32_ 763#ifdef _WIN32_
764 return locateLocal( "tmp", fn ); 764 return locateLocal( "tmp", fn );
765#else 765#else
766 return (QString( "/tmp/" )+ fn ); 766 return (QString( "/tmp/" )+ fn );
767#endif 767#endif
768} 768}
769 769
770void KSyncManager::syncPi() 770void KSyncManager::syncPi()
771{ 771{
772 qApp->processEvents(); 772 qApp->processEvents();
773 bool ok; 773 bool ok;
774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
775 if ( ! ok ) { 775 if ( ! ok ) {
776 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 776 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
777 return; 777 return;
778 } 778 }
779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
781 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 781 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
782 commandSocket->readFile( syncFileName() ); 782 commandSocket->readFile( syncFileName() );
783} 783}
784 784
785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
786{ 786{
787 qDebug("MainWindow::deleteCommandSocket %d", state); 787 qDebug("MainWindow::deleteCommandSocket %d", state);
788 788
789 //enum { success, errorW, errorR, quiet }; 789 //enum { success, errorW, errorR, quiet };
790 if ( state == KCommandSocket::errorR ) { 790 if ( state == KCommandSocket::errorR ) {
791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
792 delete s; 792 delete s;
793 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 793 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
794 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 794 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
795 commandSocket->sendStop(); 795 commandSocket->sendStop();
796 return; 796 return;
797 797
798 } else if ( state == KCommandSocket::errorW ) { 798 } else if ( state == KCommandSocket::errorW ) {
799 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 799 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
800 800
801 } else if ( state == KCommandSocket::successR ) { 801 } else if ( state == KCommandSocket::successR ) {
802 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 802 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
803 803
804 } else if ( state == KCommandSocket::successW ) { 804 } else if ( state == KCommandSocket::successW ) {
805 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 805 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
806 } 806 }
807 807
808 delete s; 808 delete s;
809} 809}
810 810
811void KSyncManager::readFileFromSocket() 811void KSyncManager::readFileFromSocket()
812{ 812{
813 QString fileName = syncFileName(); 813 QString fileName = syncFileName();
814 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 814 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
815 if ( ! syncWithFile( fileName , true ) ) { 815 if ( ! syncWithFile( fileName , true ) ) {
816 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 816 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
817 qDebug("Syncing failed "); 817 qDebug("Syncing failed ");
818 return; 818 return;
819 } 819 }
820 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 820 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
821 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 821 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
822 if ( mWriteBackFile ) 822 if ( mWriteBackFile )
823 commandSocket->writeFile( fileName ); 823 commandSocket->writeFile( fileName );
824 else { 824 else {
825 commandSocket->sendStop(); 825 commandSocket->sendStop();
826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
827 } 827 }
828} 828}
829 829
830KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 830KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
831{ 831{
832 mPassWord = pw; 832 mPassWord = pw;
833 mSocket = 0; 833 mSocket = 0;
834 mSyncActionDialog = 0; 834 mSyncActionDialog = 0;
835 blockRC = false; 835 blockRC = false;
836}; 836};
837 837
838void KServerSocket::newConnection ( int socket ) 838void KServerSocket::newConnection ( int socket )
839{ 839{
840 // qDebug("KServerSocket:New connection %d ", socket); 840 // qDebug("KServerSocket:New connection %d ", socket);
841 if ( mSocket ) { 841 if ( mSocket ) {
842 qDebug("KServerSocket::newConnection Socket deleted! "); 842 qDebug("KServerSocket::newConnection Socket deleted! ");
843 delete mSocket; 843 delete mSocket;
844 mSocket = 0; 844 mSocket = 0;
845 } 845 }
846 mSocket = new QSocket( this ); 846 mSocket = new QSocket( this );
847 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 847 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
848 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 848 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
849 mSocket->setSocket( socket ); 849 mSocket->setSocket( socket );
850} 850}
851 851
852void KServerSocket::discardClient() 852void KServerSocket::discardClient()
853{ 853{
854 //qDebug(" KServerSocket::discardClient()"); 854 //qDebug(" KServerSocket::discardClient()");
855 if ( mSocket ) { 855 if ( mSocket ) {
856 delete mSocket; 856 delete mSocket;
857 mSocket = 0; 857 mSocket = 0;
858 } 858 }
859 //emit endConnect(); 859 //emit endConnect();
860} 860}
861void KServerSocket::readClient() 861void KServerSocket::readClient()
862{ 862{
863 if ( blockRC ) 863 if ( blockRC )
864 return; 864 return;
865 if ( mSocket == 0 ) { 865 if ( mSocket == 0 ) {
866 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 866 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
867 return; 867 return;
868 } 868 }
869 qDebug("KServerSocket readClient()"); 869 qDebug("KServerSocket readClient()");
870 if ( mSocket->canReadLine() ) { 870 if ( mSocket->canReadLine() ) {
871 QString line = mSocket->readLine(); 871 QString line = mSocket->readLine();
872 qDebug("KServerSocket readline: %s ", line.latin1()); 872 qDebug("KServerSocket readline: %s ", line.latin1());
873 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 873 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
874 if ( tokens[0] == "GET" ) { 874 if ( tokens[0] == "GET" ) {
875 if ( tokens[1] == mPassWord ) 875 if ( tokens[1] == mPassWord )
876 //emit sendFile( mSocket ); 876 //emit sendFile( mSocket );
877 send_file(); 877 send_file();
878 else { 878 else {
879 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 879 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
880 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 880 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
881 } 881 }
882 } 882 }
883 if ( tokens[0] == "PUT" ) { 883 if ( tokens[0] == "PUT" ) {
884 if ( tokens[1] == mPassWord ) { 884 if ( tokens[1] == mPassWord ) {
885 //emit getFile( mSocket ); 885 //emit getFile( mSocket );
886 blockRC = true; 886 blockRC = true;
887 get_file(); 887 get_file();
888 } 888 }
889 else { 889 else {
890 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 890 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
891 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 891 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
892 } 892 }
893 } 893 }
894 if ( tokens[0] == "STOP" ) { 894 if ( tokens[0] == "STOP" ) {
895 //emit endConnect(); 895 //emit endConnect();
896 end_connect(); 896 end_connect();
897 } 897 }
898 } 898 }
899} 899}
900void KServerSocket::end_connect() 900void KServerSocket::end_connect()
901{ 901{
902 delete mSyncActionDialog; 902 delete mSyncActionDialog;
903 mSyncActionDialog = 0; 903 mSyncActionDialog = 0;
904} 904}
905void KServerSocket::send_file() 905void KServerSocket::send_file()
906{ 906{
907 //qDebug("MainWindow::sendFile(QSocket* s) "); 907 //qDebug("MainWindow::sendFile(QSocket* s) ");
908 if ( mSyncActionDialog ) 908 if ( mSyncActionDialog )
909 delete mSyncActionDialog; 909 delete mSyncActionDialog;
910 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 910 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
911 mSyncActionDialog->setCaption(i18n("Received sync request")); 911 mSyncActionDialog->setCaption(i18n("Received sync request"));
912 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 912 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
913 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 913 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
914 lay->addWidget( label); 914 lay->addWidget( label);
915 lay->setMargin(7); 915 lay->setMargin(7);
916 lay->setSpacing(7); 916 lay->setSpacing(7);
917 mSyncActionDialog->setFixedSize( 230, 120); 917 mSyncActionDialog->setFixedSize( 230, 120);
918 mSyncActionDialog->show(); 918 mSyncActionDialog->show();
919 mSyncActionDialog->raise(); 919 mSyncActionDialog->raise();
920 qDebug("KSS::saving ... "); 920 qDebug("KSS::saving ... ");
921 emit request_file(); 921 emit request_file();
922 qApp->processEvents(); 922 qApp->processEvents();
923 QString fileName = mFileName; 923 QString fileName = mFileName;
924 QFile file( fileName ); 924 QFile file( fileName );
925 if (!file.open( IO_ReadOnly ) ) { 925 if (!file.open( IO_ReadOnly ) ) {
926 delete mSyncActionDialog; 926 delete mSyncActionDialog;
927 mSyncActionDialog = 0; 927 mSyncActionDialog = 0;
928 qDebug("KSS::error open file "); 928 qDebug("KSS::error open file ");
929 mSocket->close(); 929 mSocket->close();
930 if ( mSocket->state() == QSocket::Idle ) 930 if ( mSocket->state() == QSocket::Idle )
931 QTimer::singleShot( 10, this , SLOT ( discardClient())); 931 QTimer::singleShot( 10, this , SLOT ( discardClient()));
932 return ; 932 return ;
933 933
934 } 934 }
935 mSyncActionDialog->setCaption( i18n("Sending file...") ); 935 mSyncActionDialog->setCaption( i18n("Sending file...") );
936 QTextStream ts( &file ); 936 QTextStream ts( &file );
937 ts.setCodec( QTextCodec::codecForName("utf8") ); 937 ts.setEncoding( QTextStream::Latin1 );
938
938 QTextStream os( mSocket ); 939 QTextStream os( mSocket );
939 os.setCodec( QTextCodec::codecForName("utf8") ); 940 os.setEncoding( QTextStream::Latin1 );
940 //os.setEncoding( QTextStream::UnicodeUTF8 );
941 while ( ! ts.atEnd() ) { 941 while ( ! ts.atEnd() ) {
942 os << ts.readLine() << "\n"; 942 os << ts.readLine() << "\n";
943 } 943 }
944 //os << ts.read(); 944 //os << ts.read();
945 file.close(); 945 file.close();
946 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 946 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
947 mSocket->close(); 947 mSocket->close();
948 if ( mSocket->state() == QSocket::Idle ) 948 if ( mSocket->state() == QSocket::Idle )
949 QTimer::singleShot( 10, this , SLOT ( discardClient())); 949 QTimer::singleShot( 10, this , SLOT ( discardClient()));
950} 950}
951void KServerSocket::get_file() 951void KServerSocket::get_file()
952{ 952{
953 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 953 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
954 954
955 piTime.start(); 955 piTime.start();
956 piFileString = ""; 956 piFileString = "";
957 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 957 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
958} 958}
959 959
960 960
961void KServerSocket::readBackFileFromSocket() 961void KServerSocket::readBackFileFromSocket()
962{ 962{
963 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 963 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
964 while ( mSocket->canReadLine () ) { 964 while ( mSocket->canReadLine () ) {
965 piTime.restart(); 965 piTime.restart();
966 QString line = mSocket->readLine (); 966 QString line = mSocket->readLine ();
967 piFileString += line; 967 piFileString += line;
968 //qDebug("readline: %s ", line.latin1()); 968 //qDebug("readline: %s ", line.latin1());
969 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 969 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
970 970
971 } 971 }
972 if ( piTime.elapsed () < 3000 ) { 972 if ( piTime.elapsed () < 3000 ) {
973 // wait for more 973 // wait for more
974 //qDebug("waitformore "); 974 //qDebug("waitformore ");
975 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 975 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
976 return; 976 return;
977 } 977 }
978 QString fileName = mFileName; 978 QString fileName = mFileName;
979 QFile file ( fileName ); 979 QFile file ( fileName );
980 if (!file.open( IO_WriteOnly ) ) { 980 if (!file.open( IO_WriteOnly ) ) {
981 delete mSyncActionDialog; 981 delete mSyncActionDialog;
982 mSyncActionDialog = 0; 982 mSyncActionDialog = 0;
983 qDebug("error open cal file "); 983 qDebug("error open cal file ");
984 piFileString = ""; 984 piFileString = "";
985 emit file_received( false ); 985 emit file_received( false );
986 blockRC = false; 986 blockRC = false;
987 return ; 987 return ;
988 988
989 } 989 }
990 990
991 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 991 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
992 QTextStream ts ( &file ); 992 QTextStream ts ( &file );
993 ts.setCodec( QTextCodec::codecForName("utf8") ); 993 ts.setEncoding( QTextStream::Latin1 );
994 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 994 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
995 ts << piFileString; 995 ts << piFileString;
996 mSocket->close(); 996 mSocket->close();
997 if ( mSocket->state() == QSocket::Idle ) 997 if ( mSocket->state() == QSocket::Idle )
998 QTimer::singleShot( 10, this , SLOT ( discardClient())); 998 QTimer::singleShot( 10, this , SLOT ( discardClient()));
999 file.close(); 999 file.close();
1000 delete mSyncActionDialog; 1000 delete mSyncActionDialog;
1001 mSyncActionDialog = 0; 1001 mSyncActionDialog = 0;
1002 piFileString = ""; 1002 piFileString = "";
1003 blockRC = false; 1003 blockRC = false;
1004 emit file_received( true ); 1004 emit file_received( true );
1005 1005
1006} 1006}
1007 1007
1008KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1008KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1009{ 1009{
1010 mPassWord = password; 1010 mPassWord = password;
1011 mSocket = 0; 1011 mSocket = 0;
1012 mPort = port; 1012 mPort = port;
1013 mHost = host; 1013 mHost = host;
1014 1014
1015 mRetVal = quiet; 1015 mRetVal = quiet;
1016 mTimerSocket = new QTimer ( this ); 1016 mTimerSocket = new QTimer ( this );
1017 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1017 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1018} 1018}
1019void KCommandSocket::readFile( QString fn ) 1019void KCommandSocket::readFile( QString fn )
1020{ 1020{
1021 if ( !mSocket ) { 1021 if ( !mSocket ) {
1022 mSocket = new QSocket( this ); 1022 mSocket = new QSocket( this );
1023 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1023 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1024 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1024 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1025 } 1025 }
1026 mFileString = ""; 1026 mFileString = "";
1027 mFileName = fn; 1027 mFileName = fn;
1028 mFirst = true; 1028 mFirst = true;
1029 mSocket->connectToHost( mHost, mPort ); 1029 mSocket->connectToHost( mHost, mPort );
1030 QTextStream os( mSocket ); 1030 QTextStream os( mSocket );
1031 os.setEncoding( QTextStream::UnicodeUTF8 ); 1031 os.setEncoding( QTextStream::Latin1 );
1032 os << "GET " << mPassWord << "\r\n"; 1032 os << "GET " << mPassWord << "\r\n";
1033 mTimerSocket->start( 10000 ); 1033 mTimerSocket->start( 10000 );
1034} 1034}
1035 1035
1036void KCommandSocket::writeFile( QString fileName ) 1036void KCommandSocket::writeFile( QString fileName )
1037{ 1037{
1038 if ( !mSocket ) { 1038 if ( !mSocket ) {
1039 mSocket = new QSocket( this ); 1039 mSocket = new QSocket( this );
1040 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1040 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1041 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1041 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1042 } 1042 }
1043 mFileName = fileName ; 1043 mFileName = fileName ;
1044 mSocket->connectToHost( mHost, mPort ); 1044 mSocket->connectToHost( mHost, mPort );
1045} 1045}
1046void KCommandSocket::writeFileToSocket() 1046void KCommandSocket::writeFileToSocket()
1047{ 1047{
1048 QFile file2( mFileName ); 1048 QFile file2( mFileName );
1049 if (!file2.open( IO_ReadOnly ) ) { 1049 if (!file2.open( IO_ReadOnly ) ) {
1050 mRetVal= errorW; 1050 mRetVal= errorW;
1051 mSocket->close(); 1051 mSocket->close();
1052 if ( mSocket->state() == QSocket::Idle ) 1052 if ( mSocket->state() == QSocket::Idle )
1053 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1053 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1054 return ; 1054 return ;
1055 } 1055 }
1056 QTextStream ts2( &file2 ); 1056 QTextStream ts2( &file2 );
1057 ts2.setCodec( QTextCodec::codecForName("utf8") ); 1057 ts2.setEncoding( QTextStream::Latin1 );
1058 QTextStream os2( mSocket ); 1058 QTextStream os2( mSocket );
1059 os2.setCodec( QTextCodec::codecForName("utf8") ); 1059 os2.setEncoding( QTextStream::Latin1 );
1060 os2 << "PUT " << mPassWord << "\r\n";; 1060 os2 << "PUT " << mPassWord << "\r\n";;
1061 while ( ! ts2.atEnd() ) { 1061 while ( ! ts2.atEnd() ) {
1062 os2 << ts2.readLine() << "\n"; 1062 os2 << ts2.readLine() << "\n";
1063 } 1063 }
1064 mRetVal= successW; 1064 mRetVal= successW;
1065 file2.close(); 1065 file2.close();
1066 mSocket->close(); 1066 mSocket->close();
1067 if ( mSocket->state() == QSocket::Idle ) 1067 if ( mSocket->state() == QSocket::Idle )
1068 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1068 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1069} 1069}
1070void KCommandSocket::sendStop() 1070void KCommandSocket::sendStop()
1071{ 1071{
1072 if ( !mSocket ) { 1072 if ( !mSocket ) {
1073 mSocket = new QSocket( this ); 1073 mSocket = new QSocket( this );
1074 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1074 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1075 } 1075 }
1076 mSocket->connectToHost( mHost, mPort ); 1076 mSocket->connectToHost( mHost, mPort );
1077 QTextStream os2( mSocket ); 1077 QTextStream os2( mSocket );
1078 os2.setCodec( QTextCodec::codecForName("utf8") ); 1078 os2.setEncoding( QTextStream::Latin1 );
1079 os2 << "STOP\r\n"; 1079 os2 << "STOP\r\n";
1080 mSocket->close(); 1080 mSocket->close();
1081 if ( mSocket->state() == QSocket::Idle ) 1081 if ( mSocket->state() == QSocket::Idle )
1082 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1082 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1083} 1083}
1084 1084
1085void KCommandSocket::startReadFileFromSocket() 1085void KCommandSocket::startReadFileFromSocket()
1086{ 1086{
1087 if ( ! mFirst ) 1087 if ( ! mFirst )
1088 return; 1088 return;
1089 mFirst = false; 1089 mFirst = false;
1090 mTimerSocket->stop(); 1090 mTimerSocket->stop();
1091 mFileString = ""; 1091 mFileString = "";
1092 mTime.start(); 1092 mTime.start();
1093 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1093 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1094 1094
1095} 1095}
1096void KCommandSocket::readFileFromSocket() 1096void KCommandSocket::readFileFromSocket()
1097{ 1097{
1098 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1098 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1099 while ( mSocket->canReadLine () ) { 1099 while ( mSocket->canReadLine () ) {
1100 mTime.restart(); 1100 mTime.restart();
1101 QString line = mSocket->readLine (); 1101 QString line = mSocket->readLine ();
1102 mFileString += line; 1102 mFileString += line;
1103 //qDebug("readline: %s ", line.latin1()); 1103 //qDebug("readline: %s ", line.latin1());
1104 } 1104 }
1105 if ( mTime.elapsed () < 3000 ) { 1105 if ( mTime.elapsed () < 3000 ) {
1106 // wait for more 1106 // wait for more
1107 //qDebug("waitformore "); 1107 //qDebug("waitformore ");
1108 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1108 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1109 return; 1109 return;
1110 } 1110 }
1111 QString fileName = mFileName; 1111 QString fileName = mFileName;
1112 QFile file ( fileName ); 1112 QFile file ( fileName );
1113 if (!file.open( IO_WriteOnly ) ) { 1113 if (!file.open( IO_WriteOnly ) ) {
1114 mFileString = ""; 1114 mFileString = "";
1115 mRetVal = errorR; 1115 mRetVal = errorR;
1116 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1116 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1117 deleteSocket(); 1117 deleteSocket();
1118 return ; 1118 return ;
1119 1119
1120 } 1120 }
1121 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1121 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1122 QTextStream ts ( &file ); 1122 QTextStream ts ( &file );
1123 ts.setCodec( QTextCodec::codecForName("utf8") ); 1123 ts.setEncoding( QTextStream::Latin1 );
1124 ts << mFileString; 1124 ts << mFileString;
1125 file.close(); 1125 file.close();
1126 mFileString = ""; 1126 mFileString = "";
1127 mRetVal = successR; 1127 mRetVal = successR;
1128 mSocket->close(); 1128 mSocket->close();
1129 // if state is not idle, deleteSocket(); is called via 1129 // if state is not idle, deleteSocket(); is called via
1130 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1130 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1131 if ( mSocket->state() == QSocket::Idle ) 1131 if ( mSocket->state() == QSocket::Idle )
1132 deleteSocket(); 1132 deleteSocket();
1133} 1133}
1134 1134
1135void KCommandSocket::deleteSocket() 1135void KCommandSocket::deleteSocket()
1136{ 1136{
1137 if ( mTimerSocket->isActive () ) { 1137 if ( mTimerSocket->isActive () ) {
1138 mTimerSocket->stop(); 1138 mTimerSocket->stop();
1139 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1139 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1140 mRetVal = errorR; 1140 mRetVal = errorR;
1141 } 1141 }
1142 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1142 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1143 if ( mSocket) 1143 if ( mSocket)
1144 delete mSocket; 1144 delete mSocket;
1145 mSocket = 0; 1145 mSocket = 0;
1146 emit commandFinished( this, mRetVal ); 1146 emit commandFinished( this, mRetVal );
1147} 1147}
1148 1148