summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp12
-rw-r--r--libkdepim/ksyncmanager.h4
2 files changed, 12 insertions, 4 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 28af135..fad9a76 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -694,198 +694,200 @@ void KSyncManager::syncSharp()
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 ||state == KCommandSocket::errorTO ) {
791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
792 delete s; 792 delete s;
793 if ( state == KCommandSocket::errorR ) {
793 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 794 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
794 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 795 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
795 commandSocket->sendStop(); 796 commandSocket->sendStop();
797 }
796 return; 798 return;
797 799
798 } else if ( state == KCommandSocket::errorW ) { 800 } else if ( state == KCommandSocket::errorW ) {
799 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 801 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
800 802
801 } else if ( state == KCommandSocket::successR ) { 803 } else if ( state == KCommandSocket::successR ) {
802 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 804 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
803 805
804 } else if ( state == KCommandSocket::successW ) { 806 } else if ( state == KCommandSocket::successW ) {
805 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 807 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
806 } 808 }
807 809
808 delete s; 810 delete s;
809} 811}
810 812
811void KSyncManager::readFileFromSocket() 813void KSyncManager::readFileFromSocket()
812{ 814{
813 QString fileName = syncFileName(); 815 QString fileName = syncFileName();
814 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 816 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
815 if ( ! syncWithFile( fileName , true ) ) { 817 if ( ! syncWithFile( fileName , true ) ) {
816 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 818 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
817 qDebug("Syncing failed "); 819 qDebug("Syncing failed ");
818 return; 820 return;
819 } 821 }
820 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 822 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
821 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 823 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
822 if ( mWriteBackFile ) 824 if ( mWriteBackFile )
823 commandSocket->writeFile( fileName ); 825 commandSocket->writeFile( fileName );
824 else { 826 else {
825 commandSocket->sendStop(); 827 commandSocket->sendStop();
826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 828 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
827 } 829 }
828} 830}
829 831
830KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 832KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
831{ 833{
832 mPassWord = pw; 834 mPassWord = pw;
833 mSocket = 0; 835 mSocket = 0;
834 mSyncActionDialog = 0; 836 mSyncActionDialog = 0;
835 blockRC = false; 837 blockRC = false;
836}; 838};
837 839
838void KServerSocket::newConnection ( int socket ) 840void KServerSocket::newConnection ( int socket )
839{ 841{
840 // qDebug("KServerSocket:New connection %d ", socket); 842 // qDebug("KServerSocket:New connection %d ", socket);
841 if ( mSocket ) { 843 if ( mSocket ) {
842 qDebug("KServerSocket::newConnection Socket deleted! "); 844 qDebug("KServerSocket::newConnection Socket deleted! ");
843 delete mSocket; 845 delete mSocket;
844 mSocket = 0; 846 mSocket = 0;
845 } 847 }
846 mSocket = new QSocket( this ); 848 mSocket = new QSocket( this );
847 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 849 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
848 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 850 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
849 mSocket->setSocket( socket ); 851 mSocket->setSocket( socket );
850} 852}
851 853
852void KServerSocket::discardClient() 854void KServerSocket::discardClient()
853{ 855{
854 //qDebug(" KServerSocket::discardClient()"); 856 //qDebug(" KServerSocket::discardClient()");
855 if ( mSocket ) { 857 if ( mSocket ) {
856 delete mSocket; 858 delete mSocket;
857 mSocket = 0; 859 mSocket = 0;
858 } 860 }
859 //emit endConnect(); 861 //emit endConnect();
860} 862}
861void KServerSocket::readClient() 863void KServerSocket::readClient()
862{ 864{
863 if ( blockRC ) 865 if ( blockRC )
864 return; 866 return;
865 if ( mSocket == 0 ) { 867 if ( mSocket == 0 ) {
866 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 868 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
867 return; 869 return;
868 } 870 }
869 qDebug("KServerSocket readClient()"); 871 qDebug("KServerSocket readClient()");
870 if ( mSocket->canReadLine() ) { 872 if ( mSocket->canReadLine() ) {
871 QString line = mSocket->readLine(); 873 QString line = mSocket->readLine();
872 qDebug("KServerSocket readline: %s ", line.latin1()); 874 qDebug("KServerSocket readline: %s ", line.latin1());
873 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 875 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
874 if ( tokens[0] == "GET" ) { 876 if ( tokens[0] == "GET" ) {
875 if ( tokens[1] == mPassWord ) 877 if ( tokens[1] == mPassWord )
876 //emit sendFile( mSocket ); 878 //emit sendFile( mSocket );
877 send_file(); 879 send_file();
878 else { 880 else {
879 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 881 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
880 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 882 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
881 } 883 }
882 } 884 }
883 if ( tokens[0] == "PUT" ) { 885 if ( tokens[0] == "PUT" ) {
884 if ( tokens[1] == mPassWord ) { 886 if ( tokens[1] == mPassWord ) {
885 //emit getFile( mSocket ); 887 //emit getFile( mSocket );
886 blockRC = true; 888 blockRC = true;
887 get_file(); 889 get_file();
888 } 890 }
889 else { 891 else {
890 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 892 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
891 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 893 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
@@ -1044,105 +1046,111 @@ void KCommandSocket::writeFile( QString fileName )
1044 mSocket->connectToHost( mHost, mPort ); 1046 mSocket->connectToHost( mHost, mPort );
1045} 1047}
1046void KCommandSocket::writeFileToSocket() 1048void KCommandSocket::writeFileToSocket()
1047{ 1049{
1048 QFile file2( mFileName ); 1050 QFile file2( mFileName );
1049 if (!file2.open( IO_ReadOnly ) ) { 1051 if (!file2.open( IO_ReadOnly ) ) {
1050 mRetVal= errorW; 1052 mRetVal= errorW;
1051 mSocket->close(); 1053 mSocket->close();
1052 if ( mSocket->state() == QSocket::Idle ) 1054 if ( mSocket->state() == QSocket::Idle )
1053 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1055 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1054 return ; 1056 return ;
1055 } 1057 }
1056 QTextStream ts2( &file2 ); 1058 QTextStream ts2( &file2 );
1057 ts2.setEncoding( QTextStream::Latin1 ); 1059 ts2.setEncoding( QTextStream::Latin1 );
1058 QTextStream os2( mSocket ); 1060 QTextStream os2( mSocket );
1059 os2.setEncoding( QTextStream::Latin1 ); 1061 os2.setEncoding( QTextStream::Latin1 );
1060 os2 << "PUT " << mPassWord << "\r\n";; 1062 os2 << "PUT " << mPassWord << "\r\n";;
1061 while ( ! ts2.atEnd() ) { 1063 while ( ! ts2.atEnd() ) {
1062 os2 << ts2.readLine() << "\n"; 1064 os2 << ts2.readLine() << "\n";
1063 } 1065 }
1064 mRetVal= successW; 1066 mRetVal= successW;
1065 file2.close(); 1067 file2.close();
1066 mSocket->close(); 1068 mSocket->close();
1067 if ( mSocket->state() == QSocket::Idle ) 1069 if ( mSocket->state() == QSocket::Idle )
1068 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1070 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1069} 1071}
1070void KCommandSocket::sendStop() 1072void KCommandSocket::sendStop()
1071{ 1073{
1072 if ( !mSocket ) { 1074 if ( !mSocket ) {
1073 mSocket = new QSocket( this ); 1075 mSocket = new QSocket( this );
1074 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1076 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1075 } 1077 }
1076 mSocket->connectToHost( mHost, mPort ); 1078 mSocket->connectToHost( mHost, mPort );
1077 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1078 os2.setEncoding( QTextStream::Latin1 ); 1080 os2.setEncoding( QTextStream::Latin1 );
1079 os2 << "STOP\r\n"; 1081 os2 << "STOP\r\n";
1080 mSocket->close(); 1082 mSocket->close();
1081 if ( mSocket->state() == QSocket::Idle ) 1083 if ( mSocket->state() == QSocket::Idle )
1082 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1084 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1083} 1085}
1084 1086
1085void KCommandSocket::startReadFileFromSocket() 1087void KCommandSocket::startReadFileFromSocket()
1086{ 1088{
1087 if ( ! mFirst ) 1089 if ( ! mFirst )
1088 return; 1090 return;
1089 mFirst = false; 1091 mFirst = false;
1090 mTimerSocket->stop(); 1092 mTimerSocket->stop();
1091 mFileString = ""; 1093 mFileString = "";
1092 mTime.start(); 1094 mTime.start();
1093 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1095 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1094 1096
1095} 1097}
1096void KCommandSocket::readFileFromSocket() 1098void KCommandSocket::readFileFromSocket()
1097{ 1099{
1098 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1100 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1099 while ( mSocket->canReadLine () ) { 1101 while ( mSocket->canReadLine () ) {
1100 mTime.restart(); 1102 mTime.restart();
1101 QString line = mSocket->readLine (); 1103 QString line = mSocket->readLine ();
1102 mFileString += line; 1104 mFileString += line;
1103 //qDebug("readline: %s ", line.latin1()); 1105 //qDebug("readline: %s ", line.latin1());
1104 } 1106 }
1105 if ( mTime.elapsed () < 3000 ) { 1107 if ( mTime.elapsed () < 3000 ) {
1106 // wait for more 1108 // wait for more
1107 //qDebug("waitformore "); 1109 //qDebug("waitformore ");
1108 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1110 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1109 return; 1111 return;
1110 } 1112 }
1111 QString fileName = mFileName; 1113 QString fileName = mFileName;
1112 QFile file ( fileName ); 1114 QFile file ( fileName );
1113 if (!file.open( IO_WriteOnly ) ) { 1115 if (!file.open( IO_WriteOnly ) ) {
1114 mFileString = ""; 1116 mFileString = "";
1115 mRetVal = errorR; 1117 mRetVal = errorR;
1116 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1118 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1117 deleteSocket(); 1119 deleteSocket();
1118 return ; 1120 return ;
1119 1121
1120 } 1122 }
1121 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1123 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1122 QTextStream ts ( &file ); 1124 QTextStream ts ( &file );
1123 ts.setEncoding( QTextStream::Latin1 ); 1125 ts.setEncoding( QTextStream::Latin1 );
1124 ts << mFileString; 1126 ts << mFileString;
1125 file.close(); 1127 file.close();
1126 mFileString = ""; 1128 mFileString = "";
1127 mRetVal = successR; 1129 mRetVal = successR;
1128 mSocket->close(); 1130 mSocket->close();
1129 // if state is not idle, deleteSocket(); is called via 1131 // if state is not idle, deleteSocket(); is called via
1130 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1132 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1131 if ( mSocket->state() == QSocket::Idle ) 1133 if ( mSocket->state() == QSocket::Idle )
1132 deleteSocket(); 1134 deleteSocket();
1133} 1135}
1134 1136
1135void KCommandSocket::deleteSocket() 1137void KCommandSocket::deleteSocket()
1136{ 1138{
1137 if ( mTimerSocket->isActive () ) { 1139 if ( mTimerSocket->isActive () ) {
1138 mTimerSocket->stop(); 1140 mTimerSocket->stop();
1139 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1141 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1140 mRetVal = errorR; 1142 mRetVal = errorTO;
1143 if ( mSocket ) {
1144 mSocket->close();
1145 if ( mSocket->state() == QSocket::Idle )
1146 deleteSocket();
1147 return;
1148 }
1141 } 1149 }
1142 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1150 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1143 if ( mSocket) 1151 if ( mSocket)
1144 delete mSocket; 1152 delete mSocket;
1145 mSocket = 0; 1153 mSocket = 0;
1146 emit commandFinished( this, mRetVal ); 1154 emit commandFinished( this, mRetVal );
1147} 1155}
1148 1156
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 32400af..25892d8 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -1,227 +1,227 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 19
20$Id$ 20$Id$
21*/ 21*/
22#ifndef _KSYNCMANAGER_H 22#ifndef _KSYNCMANAGER_H
23#define _KSYNCMANAGER_H 23#define _KSYNCMANAGER_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46public: 46public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 51
52signals: 52signals:
53 void file_received( bool ); 53 void file_received( bool );
54 void request_file(); 54 void request_file();
55 void saveFile(); 55 void saveFile();
56 void endConnect(); 56 void endConnect();
57private slots: 57private slots:
58 void discardClient(); 58 void discardClient();
59 void readClient(); 59 void readClient();
60 void readBackFileFromSocket(); 60 void readBackFileFromSocket();
61 private : 61 private :
62 bool blockRC; 62 bool blockRC;
63 void send_file(); 63 void send_file();
64 void get_file(); 64 void get_file();
65 void end_connect(); 65 void end_connect();
66 QDialog* mSyncActionDialog; 66 QDialog* mSyncActionDialog;
67 QSocket* mSocket; 67 QSocket* mSocket;
68 QString mPassWord; 68 QString mPassWord;
69 QString mFileName; 69 QString mFileName;
70 QTime piTime; 70 QTime piTime;
71 QString piFileString; 71 QString piFileString;
72}; 72};
73 73
74class KCommandSocket : public QObject 74class KCommandSocket : public QObject
75{ 75{
76 Q_OBJECT 76 Q_OBJECT
77public: 77public:
78 enum state { successR, errorR, successW, errorW, quiet }; 78 enum state { successR, errorR, successW, errorW, errorTO, quiet };
79 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 79 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
80 void readFile( QString ); 80 void readFile( QString );
81 void writeFile( QString ); 81 void writeFile( QString );
82 void sendStop(); 82 void sendStop();
83 83
84 84
85signals: 85signals:
86 void commandFinished( KCommandSocket*, int ); 86 void commandFinished( KCommandSocket*, int );
87private slots: 87private slots:
88 void startReadFileFromSocket(); 88 void startReadFileFromSocket();
89 void readFileFromSocket(); 89 void readFileFromSocket();
90 void deleteSocket(); 90 void deleteSocket();
91 void writeFileToSocket(); 91 void writeFileToSocket();
92 private : 92 private :
93 QSocket* mSocket; 93 QSocket* mSocket;
94 QString mPassWord; 94 QString mPassWord;
95 Q_UINT16 mPort; 95 Q_UINT16 mPort;
96 QString mHost; 96 QString mHost;
97 QString mFileName; 97 QString mFileName;
98 QTimer* mTimerSocket; 98 QTimer* mTimerSocket;
99 int mRetVal; 99 int mRetVal;
100 QTime mTime; 100 QTime mTime;
101 QString mFileString; 101 QString mFileString;
102 bool mFirst; 102 bool mFirst;
103}; 103};
104 104
105 105
106class KSyncManager : public QObject 106class KSyncManager : public QObject
107{ 107{
108 Q_OBJECT 108 Q_OBJECT
109 109
110 public: 110 public:
111 enum TargetApp { 111 enum TargetApp {
112 KOPI = 0, 112 KOPI = 0,
113 KAPI = 1, 113 KAPI = 1,
114 PWMPI = 2 }; 114 PWMPI = 2 };
115 115
116 116
117 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 117 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
118 ~KSyncManager() ; 118 ~KSyncManager() ;
119 119
120 bool blockSave() { return mBlockSaveFlag; } 120 bool blockSave() { return mBlockSaveFlag; }
121 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 121 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
122 void setDefaultFileName( QString s) { mDefFileName = s ;} 122 void setDefaultFileName( QString s) { mDefFileName = s ;}
123 QString defaultFileName() { return mDefFileName ;} 123 QString defaultFileName() { return mDefFileName ;}
124 QString syncFileName(); 124 QString syncFileName();
125 void fillSyncMenu();
125 126
126 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 127 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
127 QString getCurrentSyncName() { return mCurrentSyncName; } 128 QString getCurrentSyncName() { return mCurrentSyncName; }
128 129
129 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 130 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
130 void hideProgressBar(); 131 void hideProgressBar();
131 bool isProgressBarCanceled(); 132 bool isProgressBarCanceled();
132 133
133 // sync stuff 134 // sync stuff
134 QString mLocalMachineName; 135 QString mLocalMachineName;
135 QStringList mExternSyncProfiles; 136 QStringList mExternSyncProfiles;
136 QStringList mSyncProfileNames; 137 QStringList mSyncProfileNames;
137 bool mAskForPreferences; 138 bool mAskForPreferences;
138 bool mShowSyncSummary; 139 bool mShowSyncSummary;
139 bool mShowSyncEvents; 140 bool mShowSyncEvents;
140 bool mShowTodoInAgenda; 141 bool mShowTodoInAgenda;
141 bool mWriteBackExistingOnly; 142 bool mWriteBackExistingOnly;
142 int mSyncAlgoPrefs; 143 int mSyncAlgoPrefs;
143 int mRingSyncAlgoPrefs; 144 int mRingSyncAlgoPrefs;
144 bool mWriteBackFile; 145 bool mWriteBackFile;
145 int mWriteBackInFuture; 146 int mWriteBackInFuture;
146 QString mPhoneDevice; 147 QString mPhoneDevice;
147 QString mPhoneConnection; 148 QString mPhoneConnection;
148 QString mPhoneModel; 149 QString mPhoneModel;
149 QString mLastSyncedLocalFile; // save! 150 QString mLastSyncedLocalFile; // save!
150 QString mPassWordPiSync; 151 QString mPassWordPiSync;
151 QString mActiveSyncPort; 152 QString mActiveSyncPort;
152 QString mActiveSyncIP ; 153 QString mActiveSyncIP ;
153 154
154 signals: 155 signals:
155 void save(); 156 void save();
156 void request_file(); 157 void request_file();
157 void getFile( bool ); 158 void getFile( bool );
158 159
159 public slots: 160 public slots:
160 void fillSyncMenu();
161 void slotSyncMenu( int ); 161 void slotSyncMenu( int );
162 void deleteCommandSocket(KCommandSocket*s, int state); 162 void deleteCommandSocket(KCommandSocket*s, int state);
163 void readFileFromSocket(); 163 void readFileFromSocket();
164 164
165 private: 165 private:
166 // LR ******************************* 166 // LR *******************************
167 // sync stuff! 167 // sync stuff!
168 void syncPi(); 168 void syncPi();
169 KServerSocket * mServerSocket; 169 KServerSocket * mServerSocket;
170 void enableQuick(); 170 void enableQuick();
171 KPimPrefs* mPrefs; 171 KPimPrefs* mPrefs;
172 QString mDefFileName; 172 QString mDefFileName;
173 QString mCurrentSyncDevice; 173 QString mCurrentSyncDevice;
174 QString mCurrentSyncName; 174 QString mCurrentSyncName;
175 void quickSyncLocalFile(); 175 void quickSyncLocalFile();
176 bool syncWithFile( QString fn , bool quick ); 176 bool syncWithFile( QString fn , bool quick );
177 void syncLocalFile(); 177 void syncLocalFile();
178 void syncPhone(); 178 void syncPhone();
179 void syncSharp(); 179 void syncSharp();
180 bool syncExternalApplication(QString); 180 bool syncExternalApplication(QString);
181 void multiSync( bool askforPrefs ); 181 void multiSync( bool askforPrefs );
182 int mCurrentSyncProfile ; 182 int mCurrentSyncProfile ;
183 void syncRemote( KSyncProfile* prof, bool ask = true); 183 void syncRemote( KSyncProfile* prof, bool ask = true);
184 void edit_sync_options(); 184 void edit_sync_options();
185 int ringSync(); 185 int ringSync();
186 QString getPassword( ); 186 QString getPassword( );
187 187
188 private slots: 188 private slots:
189 void confSync(); 189 void confSync();
190 // ********************* 190 // *********************
191 191
192 private: 192 private:
193 bool mBlockSaveFlag; 193 bool mBlockSaveFlag;
194 194
195 195
196 QWidget* mParent; 196 QWidget* mParent;
197 KSyncInterface* mImplementation; 197 KSyncInterface* mImplementation;
198 TargetApp mTargetApp; 198 TargetApp mTargetApp;
199 QPopupMenu* mSyncMenu; 199 QPopupMenu* mSyncMenu;
200 200
201 QProgressBar* bar; 201 QProgressBar* bar;
202 202
203 203
204 204
205 205
206 206
207}; 207};
208 208
209 209
210class KSyncInterface 210class KSyncInterface
211{ 211{
212 212
213 213
214 public : 214 public :
215 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 215 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
216 216
217 virtual bool syncExternal(KSyncManager* manager, QString resource) 217 virtual bool syncExternal(KSyncManager* manager, QString resource)
218 { 218 {
219 // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. 219 // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager.
220 return false; 220 return false;
221 } 221 }
222 222
223 223
224}; 224};
225 225
226 226
227#endif 227#endif