summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkdepim/ksyncmanager.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp97
1 files changed, 50 insertions, 47 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5708dfc..c844627 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -14,103 +14,106 @@
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 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <q3progressbar.h>
39#include <qpopupmenu.h> 39#include <q3popupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <q3buttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52#include <qapplication.h> 52#include <qapplication.h>
53#include <QDesktopWidget>
54//Added by qt3to4:
55#include <Q3VBoxLayout>
53 56
54#include <klocale.h> 57#include <klocale.h>
55#include <kglobal.h> 58#include <kglobal.h>
56#include <kconfig.h> 59#include <kconfig.h>
57#include <kfiledialog.h> 60#include <kfiledialog.h>
58 61
59QDateTime KSyncManager::mRequestedSyncEvent; 62QDateTime KSyncManager::mRequestedSyncEvent;
60 63
61 64
62KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 65KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, Q3PopupMenu* syncmenu)
63 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) 66 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
64{ 67{
65 mServerSocket = 0; 68 mServerSocket = 0;
66 bar = new QProgressBar ( 1, 0 ); 69 bar = new Q3ProgressBar ( 1, 0 );
67 bar->setCaption (""); 70 bar->setCaption ("");
68 mWriteBackInPast = 2; 71 mWriteBackInPast = 2;
69 72
70 73
71} 74}
72 75
73KSyncManager::~KSyncManager() 76KSyncManager::~KSyncManager()
74{ 77{
75 delete bar; 78 delete bar;
76} 79}
77 80
78void KSyncManager::setDefaultFileName( QString s) 81void KSyncManager::setDefaultFileName( QString s)
79{ 82{
80 mDefFileName = s ; 83 mDefFileName = s ;
81 if ( mPrefs->mPassiveSyncAutoStart ) 84 if ( mPrefs->mPassiveSyncAutoStart )
82 enableQuick( false ); 85 enableQuick( false );
83} 86}
84 87
85void KSyncManager::fillSyncMenu() 88void KSyncManager::fillSyncMenu()
86{ 89{
87 if ( mSyncMenu->count() ) 90 if ( mSyncMenu->count() )
88 mSyncMenu->clear(); 91 mSyncMenu->clear();
89 92
90 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 93 mSyncMenu->insertItem( i18n("Configure..."), 0 );
91 mSyncMenu->insertSeparator(); 94 mSyncMenu->insertSeparator();
92 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 95 Q3PopupMenu *clearMenu = new Q3PopupMenu ( mSyncMenu );
93 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 96 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
94 clearMenu->insertItem( i18n("For all profiles"), 1 ); 97 clearMenu->insertItem( i18n("For all profiles"), 1 );
95 clearMenu->insertSeparator(); 98 clearMenu->insertSeparator();
96 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 99 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
97 mSyncMenu->insertSeparator(); 100 mSyncMenu->insertSeparator();
98 if ( mServerSocket == 0 ) { 101 if ( mServerSocket == 0 ) {
99 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 102 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
100 } else { 103 } else {
101 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 104 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
102 } 105 }
103 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
104 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 107 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
105 mSyncMenu->insertSeparator(); 108 mSyncMenu->insertSeparator();
106 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 109 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
107 config.setGroup("General"); 110 config.setGroup("General");
108 QStringList prof = config.readListEntry("SyncProfileNames"); 111 QStringList prof = config.readListEntry("SyncProfileNames");
109 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 112 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
110 if ( prof.count() < 2 ) { 113 if ( prof.count() < 2 ) {
111 prof.clear(); 114 prof.clear();
112 QString externalName; 115 QString externalName;
113#ifdef DESKTOP_VERSION 116#ifdef DESKTOP_VERSION
114#ifdef _WIN32_ 117#ifdef _WIN32_
115 externalName = "OutLook"; 118 externalName = "OutLook";
116#else 119#else
@@ -334,49 +337,49 @@ void KSyncManager::slotSyncMenu( int action )
334 mActiveSyncPort = temp->getRemotePortPWM(); 337 mActiveSyncPort = temp->getRemotePortPWM();
335 mActiveSyncIP = temp->getRemoteIPPWM(); 338 mActiveSyncIP = temp->getRemoteIPPWM();
336 } 339 }
337 syncPi(); 340 syncPi();
338 while ( !mPisyncFinished ) { 341 while ( !mPisyncFinished ) {
339 //qDebug("waiting "); 342 //qDebug("waiting ");
340 qApp->processEvents(); 343 qApp->processEvents();
341 } 344 }
342 } else 345 } else
343 syncRemote( temp ); 346 syncRemote( temp );
344 347
345 } 348 }
346 } 349 }
347 delete temp; 350 delete temp;
348 setBlockSave(false); 351 setBlockSave(false);
349} 352}
350 353
351void KSyncManager::enableQuick( bool ask ) 354void KSyncManager::enableQuick( bool ask )
352{ 355{
353 bool autoStart; 356 bool autoStart;
354 bool changed = false; 357 bool changed = false;
355 if ( ask ) { 358 if ( ask ) {
356 QDialog dia ( 0, "input-dialog", true ); 359 QDialog dia ( 0, "input-dialog", true );
357 QLineEdit lab ( &dia ); 360 QLineEdit lab ( &dia );
358 QVBoxLayout lay( &dia ); 361 Q3VBoxLayout lay( &dia );
359 lab.setText( mPrefs->mPassiveSyncPort ); 362 lab.setText( mPrefs->mPassiveSyncPort );
360 lay.setMargin(7); 363 lay.setMargin(7);
361 lay.setSpacing(7); 364 lay.setSpacing(7);
362 int po = 9197+mTargetApp; 365 int po = 9197+mTargetApp;
363 QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia ); 366 QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia );
364 lay.addWidget( &label); 367 lay.addWidget( &label);
365 lay.addWidget( &lab); 368 lay.addWidget( &lab);
366 369
367 QLineEdit lepw ( &dia ); 370 QLineEdit lepw ( &dia );
368 lepw.setText( mPrefs->mPassiveSyncPw ); 371 lepw.setText( mPrefs->mPassiveSyncPw );
369 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 372 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
370 lay.addWidget( &label2); 373 lay.addWidget( &label2);
371 lay.addWidget( &lepw); 374 lay.addWidget( &lepw);
372 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 375 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
373 lay.addWidget( &autostart); 376 lay.addWidget( &autostart);
374 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 377 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
375#ifdef DESKTOP_VERSION 378#ifdef DESKTOP_VERSION
376#ifdef _WIN32_ 379#ifdef _WIN32_
377 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 380 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
378 syncdesktop.hide();// not implemented! 381 syncdesktop.hide();// not implemented!
379#else 382#else
380 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 383 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
381#endif 384#endif
382 lay.addWidget( &syncdesktop); 385 lay.addWidget( &syncdesktop);
@@ -783,84 +786,84 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
783 if ( mWriteBackFile ) { 786 if ( mWriteBackFile ) {
784 int fi; 787 int fi;
785 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 788 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
786 QString pwd = getPassword(); 789 QString pwd = getPassword();
787 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 790 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
788 791
789 } 792 }
790 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 793 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
791 result = system ( postCommand ); 794 result = system ( postCommand );
792 qDebug("KSM::Sync:Writing back file result: %d ", result); 795 qDebug("KSM::Sync:Writing back file result: %d ", result);
793 if ( result != 0 ) { 796 if ( result != 0 ) {
794 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 797 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
795 return; 798 return;
796 } else { 799 } else {
797 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 800 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
798 } 801 }
799 } 802 }
800 } 803 }
801 return; 804 return;
802} 805}
803bool KSyncManager::edit_pisync_options() 806bool KSyncManager::edit_pisync_options()
804{ 807{
805 QDialog dia( mParent, "dia", true ); 808 QDialog dia( mParent, "dia", true );
806 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); 809 dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
807 QVBoxLayout lay ( &dia ); 810 Q3VBoxLayout lay ( &dia );
808 lay.setSpacing( 5 ); 811 lay.setSpacing( 5 );
809 lay.setMargin( 3 ); 812 lay.setMargin( 3 );
810 QLabel lab1 ( i18n("Password for remote access:"), &dia); 813 QLabel lab1 ( i18n("Password for remote access:"), &dia);
811 lay.addWidget( &lab1 ); 814 lay.addWidget( &lab1 );
812 QLineEdit le1 (&dia ); 815 QLineEdit le1 (&dia );
813 lay.addWidget( &le1 ); 816 lay.addWidget( &le1 );
814 QLabel lab2 ( i18n("Remote IP address:"), &dia); 817 QLabel lab2 ( i18n("Remote IP address:"), &dia);
815 lay.addWidget( &lab2 ); 818 lay.addWidget( &lab2 );
816 QLineEdit le2 (&dia ); 819 QLineEdit le2 (&dia );
817 lay.addWidget( &le2 ); 820 lay.addWidget( &le2 );
818 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); 821 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia);
819 lay.addWidget( &lab3 ); 822 lay.addWidget( &lab3 );
820 QLineEdit le3 (&dia ); 823 QLineEdit le3 (&dia );
821 lay.addWidget( &le3 ); 824 lay.addWidget( &le3 );
822 QPushButton pb ( "OK", &dia); 825 QPushButton pb ( "OK", &dia);
823 lay.addWidget( &pb ); 826 lay.addWidget( &pb );
824 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 827 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
825 le1.setText( mPassWordPiSync ); 828 le1.setText( mPassWordPiSync );
826 le2.setText( mActiveSyncIP ); 829 le2.setText( mActiveSyncIP );
827 le3.setText( mActiveSyncPort ); 830 le3.setText( mActiveSyncPort );
828 if ( dia.exec() ) { 831 if ( dia.exec() ) {
829 mPassWordPiSync = le1.text(); 832 mPassWordPiSync = le1.text();
830 mActiveSyncPort = le3.text(); 833 mActiveSyncPort = le3.text();
831 mActiveSyncIP = le2.text(); 834 mActiveSyncIP = le2.text();
832 return true; 835 return true;
833 } 836 }
834 return false; 837 return false;
835} 838}
836bool KSyncManager::edit_sync_options() 839bool KSyncManager::edit_sync_options()
837{ 840{
838 841
839 QDialog dia( mParent, "dia", true ); 842 QDialog dia( mParent, "dia", true );
840 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 843 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
841 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 844 Q3ButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
842 QVBoxLayout lay ( &dia ); 845 Q3VBoxLayout lay ( &dia );
843 lay.setSpacing( 2 ); 846 lay.setSpacing( 2 );
844 lay.setMargin( 3 ); 847 lay.setMargin( 3 );
845 lay.addWidget(&gr); 848 lay.addWidget(&gr);
846 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 849 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
847 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 850 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
848 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 851 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
849 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 852 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
850 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 853 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
851 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 854 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
852 //QRadioButton both( i18n("Take both on conflict"), &gr ); 855 //QRadioButton both( i18n("Take both on conflict"), &gr );
853 QPushButton pb ( "OK", &dia); 856 QPushButton pb ( "OK", &dia);
854 lay.addWidget( &pb ); 857 lay.addWidget( &pb );
855 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 858 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
856 switch ( mSyncAlgoPrefs ) { 859 switch ( mSyncAlgoPrefs ) {
857 case 0: 860 case 0:
858 loc.setChecked( true); 861 loc.setChecked( true);
859 break; 862 break;
860 case 1: 863 case 1:
861 rem.setChecked( true ); 864 rem.setChecked( true );
862 break; 865 break;
863 case 2: 866 case 2:
864 newest.setChecked( true); 867 newest.setChecked( true);
865 break; 868 break;
866 case 3: 869 case 3:
@@ -870,49 +873,49 @@ bool KSyncManager::edit_sync_options()
870 f_loc.setChecked( true); 873 f_loc.setChecked( true);
871 break; 874 break;
872 case 5: 875 case 5:
873 f_rem.setChecked( true); 876 f_rem.setChecked( true);
874 break; 877 break;
875 case 6: 878 case 6:
876 // both.setChecked( true); 879 // both.setChecked( true);
877 break; 880 break;
878 default: 881 default:
879 break; 882 break;
880 } 883 }
881 if ( dia.exec() ) { 884 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 ; 885 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
883 return true; 886 return true;
884 } 887 }
885 return false; 888 return false;
886} 889}
887 890
888QString KSyncManager::getPassword( ) 891QString KSyncManager::getPassword( )
889{ 892{
890 QString retfile = ""; 893 QString retfile = "";
891 QDialog dia ( mParent, "input-dialog", true ); 894 QDialog dia ( mParent, "input-dialog", true );
892 QLineEdit lab ( &dia ); 895 QLineEdit lab ( &dia );
893 lab.setEchoMode( QLineEdit::Password ); 896 lab.setEchoMode( QLineEdit::Password );
894 QVBoxLayout lay( &dia ); 897 Q3VBoxLayout lay( &dia );
895 lay.setMargin(7); 898 lay.setMargin(7);
896 lay.setSpacing(7); 899 lay.setSpacing(7);
897 lay.addWidget( &lab); 900 lay.addWidget( &lab);
898 dia.setFixedSize( 230,50 ); 901 dia.setFixedSize( 230,50 );
899 dia.setCaption( i18n("Enter password") ); 902 dia.setCaption( i18n("Enter password") );
900 QPushButton pb ( "OK", &dia); 903 QPushButton pb ( "OK", &dia);
901 lay.addWidget( &pb ); 904 lay.addWidget( &pb );
902 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 905 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
903 dia.show(); 906 dia.show();
904 int res = dia.exec(); 907 int res = dia.exec();
905 if ( res ) 908 if ( res )
906 retfile = lab.text(); 909 retfile = lab.text();
907 dia.hide(); 910 dia.hide();
908 qApp->processEvents(); 911 qApp->processEvents();
909 return retfile; 912 return retfile;
910 913
911} 914}
912 915
913 916
914void KSyncManager::confSync() 917void KSyncManager::confSync()
915{ 918{
916 static KSyncPrefsDialog* sp = 0; 919 static KSyncPrefsDialog* sp = 0;
917 if ( ! sp ) { 920 if ( ! sp ) {
918 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 921 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
@@ -1313,87 +1316,87 @@ void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1313 1316
1314void KSyncManager::readFileFromSocket() 1317void KSyncManager::readFileFromSocket()
1315{ 1318{
1316 QString fileName = syncFileName(); 1319 QString fileName = syncFileName();
1317 bool syncOK = true; 1320 bool syncOK = true;
1318 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1321 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1319 if ( ! syncWithFile( fileName , true ) ) { 1322 if ( ! syncWithFile( fileName , true ) ) {
1320 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1323 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1321 syncOK = false; 1324 syncOK = false;
1322 } 1325 }
1323 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1326 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1324 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1327 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1325 if ( mWriteBackFile && syncOK ) { 1328 if ( mWriteBackFile && syncOK ) {
1326 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1329 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1327 commandSocket->writeFile( fileName ); 1330 commandSocket->writeFile( fileName );
1328 } 1331 }
1329 else { 1332 else {
1330 commandSocket->sendStop(); 1333 commandSocket->sendStop();
1331 if ( syncOK ) 1334 if ( syncOK )
1332 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1335 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1333 mPisyncFinished = true; 1336 mPisyncFinished = true;
1334 } 1337 }
1335} 1338}
1336 1339
1337KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1340KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : Q3ServerSocket( port, backlog, parent, name )
1338{ 1341{
1339 mPendingConnect = 0; 1342 mPendingConnect = 0;
1340 mPassWord = pw; 1343 mPassWord = pw;
1341 mSocket = 0; 1344 mSocket = 0;
1342 mSyncActionDialog = 0; 1345 mSyncActionDialog = 0;
1343 blockRC = false; 1346 blockRC = false;
1344 mErrorMessage = 0; 1347 mErrorMessage = 0;
1345} 1348}
1346void KServerSocket::waitForSocketFinish() 1349void KServerSocket::waitForSocketFinish()
1347{ 1350{
1348 if ( mSocket ) { 1351 if ( mSocket ) {
1349 //qDebug("KSS:: waiting for finish operation"); 1352 //qDebug("KSS:: waiting for finish operation");
1350 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1353 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1351 return; 1354 return;
1352 } 1355 }
1353 mSocket = new QSocket( this ); 1356 mSocket = new Q3Socket( this );
1354 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1357 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1355 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1358 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1356 mSocket->setSocket( mPendingConnect ); 1359 mSocket->setSocket( mPendingConnect );
1357 mPendingConnect = 0; 1360 mPendingConnect = 0;
1358} 1361}
1359void KServerSocket::newConnection ( int socket ) 1362void KServerSocket::newConnection ( int socket )
1360{ 1363{
1361 // qDebug("KServerSocket:New connection %d ", socket); 1364 // qDebug("KServerSocket:New connection %d ", socket);
1362 if ( mPendingConnect ) { 1365 if ( mPendingConnect ) {
1363 qDebug("KSS::Error : new Connection"); 1366 qDebug("KSS::Error : new Connection");
1364 return; 1367 return;
1365 } 1368 }
1366 if ( mSocket ) { 1369 if ( mSocket ) {
1367 mPendingConnect = socket; 1370 mPendingConnect = socket;
1368 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); 1371 QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
1369 return; 1372 return;
1370 qDebug("KSS::newConnection Socket deleted! "); 1373 qDebug("KSS::newConnection Socket deleted! ");
1371 delete mSocket; 1374 delete mSocket;
1372 mSocket = 0; 1375 mSocket = 0;
1373 } 1376 }
1374 mPendingConnect = 0; 1377 mPendingConnect = 0;
1375 mSocket = new QSocket( this ); 1378 mSocket = new Q3Socket( this );
1376 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1379 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1377 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1380 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1378 mSocket->setSocket( socket ); 1381 mSocket->setSocket( socket );
1379} 1382}
1380 1383
1381void KServerSocket::discardClient() 1384void KServerSocket::discardClient()
1382{ 1385{
1383 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1386 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1384} 1387}
1385void KServerSocket::deleteSocket() 1388void KServerSocket::deleteSocket()
1386{ 1389{
1387 //qDebug("KSS::deleteSocket"); 1390 //qDebug("KSS::deleteSocket");
1388 if ( mSocket ) { 1391 if ( mSocket ) {
1389 delete mSocket; 1392 delete mSocket;
1390 mSocket = 0; 1393 mSocket = 0;
1391 } 1394 }
1392 if ( mErrorMessage ) 1395 if ( mErrorMessage )
1393 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1396 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1394} 1397}
1395void KServerSocket::readClient() 1398void KServerSocket::readClient()
1396{ 1399{
1397 if ( blockRC ) 1400 if ( blockRC )
1398 return; 1401 return;
1399 if ( mSocket == 0 ) { 1402 if ( mSocket == 0 ) {
@@ -1441,71 +1444,71 @@ void KServerSocket::readClient()
1441 mErrorMessage = 2; 1444 mErrorMessage = 2;
1442 error_connect("ERROR_PW\r\n\r\n"); 1445 error_connect("ERROR_PW\r\n\r\n");
1443 end_connect(); 1446 end_connect();
1444 } 1447 }
1445 } 1448 }
1446 if ( tokens[0] == "STOP" ) { 1449 if ( tokens[0] == "STOP" ) {
1447 //emit endConnect(); 1450 //emit endConnect();
1448 end_connect(); 1451 end_connect();
1449 } 1452 }
1450 } 1453 }
1451} 1454}
1452void KServerSocket::displayErrorMessage() 1455void KServerSocket::displayErrorMessage()
1453{ 1456{
1454 if ( mErrorMessage == 1 ) { 1457 if ( mErrorMessage == 1 ) {
1455 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1458 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1456 mErrorMessage = 0; 1459 mErrorMessage = 0;
1457 } 1460 }
1458 else if ( mErrorMessage == 2 ) { 1461 else if ( mErrorMessage == 2 ) {
1459 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1462 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1460 mErrorMessage = 0; 1463 mErrorMessage = 0;
1461 } 1464 }
1462} 1465}
1463void KServerSocket::error_connect( QString errmess ) 1466void KServerSocket::error_connect( QString errmess )
1464{ 1467{
1465 QTextStream os( mSocket ); 1468 Q3TextStream os( mSocket );
1466 os.setEncoding( QTextStream::Latin1 ); 1469 os.setEncoding( Q3TextStream::Latin1 );
1467 os << errmess ; 1470 os << errmess ;
1468 mSocket->close(); 1471 mSocket->close();
1469 if ( mSocket->state() == QSocket::Idle ) { 1472 if ( mSocket->state() == Q3Socket::Idle ) {
1470 QTimer::singleShot( 0, this , SLOT ( discardClient())); 1473 QTimer::singleShot( 0, this , SLOT ( discardClient()));
1471 } 1474 }
1472} 1475}
1473void KServerSocket::end_connect() 1476void KServerSocket::end_connect()
1474{ 1477{
1475 delete mSyncActionDialog; 1478 delete mSyncActionDialog;
1476 mSyncActionDialog = 0; 1479 mSyncActionDialog = 0;
1477} 1480}
1478void KServerSocket::send_file() 1481void KServerSocket::send_file()
1479{ 1482{
1480 //qDebug("MainWindow::sendFile(QSocket* s) "); 1483 //qDebug("MainWindow::sendFile(QSocket* s) ");
1481 if ( mSyncActionDialog ) 1484 if ( mSyncActionDialog )
1482 delete mSyncActionDialog; 1485 delete mSyncActionDialog;
1483 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1486 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1484 mSyncActionDialog->setCaption(i18n("Received sync request")); 1487 mSyncActionDialog->setCaption(i18n("Received sync request"));
1485 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1488 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1486 label->setAlignment ( Qt::AlignHCenter ); 1489 label->setAlignment ( Qt::AlignHCenter );
1487 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1490 Q3VBoxLayout* lay = new Q3VBoxLayout( mSyncActionDialog );
1488 lay->addWidget( label); 1491 lay->addWidget( label);
1489 lay->setMargin(7); 1492 lay->setMargin(7);
1490 lay->setSpacing(7); 1493 lay->setSpacing(7);
1491 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1494 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1492 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1495 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1493 //secs = 333; 1496 //secs = 333;
1494 if ( secs < 0 ) 1497 if ( secs < 0 )
1495 secs = secs * (-1); 1498 secs = secs * (-1);
1496 if ( secs > 30 ) 1499 if ( secs > 30 )
1497 //if ( true ) 1500 //if ( true )
1498 { 1501 {
1499 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1502 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1500 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1503 QLabel* label = new QLabel( warning, mSyncActionDialog );
1501 label->setAlignment ( Qt::AlignHCenter ); 1504 label->setAlignment ( Qt::AlignHCenter );
1502 lay->addWidget( label); 1505 lay->addWidget( label);
1503 if ( secs > 180 ) 1506 if ( secs > 180 )
1504 { 1507 {
1505 if ( secs > 300 ) { 1508 if ( secs > 300 ) {
1506 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!"))) { 1509 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!"))) {
1507 qDebug("KSS::Sync cancelled ,cs"); 1510 qDebug("KSS::Sync cancelled ,cs");
1508 mErrorMessage = 0; 1511 mErrorMessage = 0;
1509 end_connect(); 1512 end_connect();
1510 error_connect("ERROR_CA\r\n\r\n"); 1513 error_connect("ERROR_CA\r\n\r\n");
1511 return ; 1514 return ;
@@ -1515,276 +1518,276 @@ void KServerSocket::send_file()
1515 f.setPointSize ( f.pointSize() *2 ); 1518 f.setPointSize ( f.pointSize() *2 );
1516 f. setBold (true ); 1519 f. setBold (true );
1517 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1520 QLabel* label = new QLabel( warning, mSyncActionDialog );
1518 label->setFont( f ); 1521 label->setFont( f );
1519 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1522 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1520 label->setText( warning ); 1523 label->setText( warning );
1521 label->setAlignment ( Qt::AlignHCenter ); 1524 label->setAlignment ( Qt::AlignHCenter );
1522 lay->addWidget( label); 1525 lay->addWidget( label);
1523 mSyncActionDialog->setFixedSize( 230, 300); 1526 mSyncActionDialog->setFixedSize( 230, 300);
1524 } else { 1527 } else {
1525 mSyncActionDialog->setFixedSize( 230, 200); 1528 mSyncActionDialog->setFixedSize( 230, 200);
1526 } 1529 }
1527 } else { 1530 } else {
1528 mSyncActionDialog->setFixedSize( 230, 120); 1531 mSyncActionDialog->setFixedSize( 230, 120);
1529 } 1532 }
1530 } else 1533 } else
1531 mSyncActionDialog->setFixedSize( 230, 120); 1534 mSyncActionDialog->setFixedSize( 230, 120);
1532 mSyncActionDialog->show(); 1535 mSyncActionDialog->show();
1533 mSyncActionDialog->raise(); 1536 mSyncActionDialog->raise();
1534 emit request_file(mResource); 1537 emit request_file(mResource);
1535 //emit request_file(); 1538 //emit request_file();
1536 qApp->processEvents(); 1539 qApp->processEvents();
1537 QString fileName = mFileName; 1540 QString fileName = mFileName;
1538 QFile file( fileName ); 1541 QFile file( fileName );
1539 if (!file.open( IO_ReadOnly ) ) { 1542 if (!file.open( QIODevice::ReadOnly ) ) {
1540 mErrorMessage = 0; 1543 mErrorMessage = 0;
1541 end_connect(); 1544 end_connect();
1542 error_connect("ERROR_FI\r\n\r\n"); 1545 error_connect("ERROR_FI\r\n\r\n");
1543 return ; 1546 return ;
1544 } 1547 }
1545 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1548 mSyncActionDialog->setCaption( i18n("Sending file...") );
1546 QTextStream ts( &file ); 1549 Q3TextStream ts( &file );
1547 ts.setEncoding( QTextStream::Latin1 ); 1550 ts.setEncoding( Q3TextStream::Latin1 );
1548 1551
1549 QTextStream os( mSocket ); 1552 Q3TextStream os( mSocket );
1550 os.setEncoding( QTextStream::Latin1 ); 1553 os.setEncoding( Q3TextStream::Latin1 );
1551 while ( ! ts.atEnd() ) { 1554 while ( ! ts.atEnd() ) {
1552 os << ts.readLine() << "\r\n"; 1555 os << ts.readLine() << "\r\n";
1553 } 1556 }
1554 os << "\r\n"; 1557 os << "\r\n";
1555 //os << ts.read(); 1558 //os << ts.read();
1556 file.close(); 1559 file.close();
1557 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1560 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1558 mSocket->close(); 1561 mSocket->close();
1559 if ( mSocket->state() == QSocket::Idle ) 1562 if ( mSocket->state() == Q3Socket::Idle )
1560 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1563 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1561} 1564}
1562void KServerSocket::get_file() 1565void KServerSocket::get_file()
1563{ 1566{
1564 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1567 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1565 1568
1566 piTime.start(); 1569 piTime.start();
1567 piFileString = ""; 1570 piFileString = "";
1568 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1571 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1569} 1572}
1570 1573
1571 1574
1572void KServerSocket::readBackFileFromSocket() 1575void KServerSocket::readBackFileFromSocket()
1573{ 1576{
1574 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1577 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1575 while ( mSocket->canReadLine () ) { 1578 while ( mSocket->canReadLine () ) {
1576 piTime.restart(); 1579 piTime.restart();
1577 QString line = mSocket->readLine (); 1580 QString line = mSocket->readLine ();
1578 piFileString += line; 1581 piFileString += line;
1579 //qDebug("readline: %s ", line.latin1()); 1582 //qDebug("readline: %s ", line.latin1());
1580 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1583 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1581 1584
1582 } 1585 }
1583 if ( piTime.elapsed () < 3000 ) { 1586 if ( piTime.elapsed () < 3000 ) {
1584 // wait for more 1587 // wait for more
1585 //qDebug("waitformore "); 1588 //qDebug("waitformore ");
1586 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1589 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1587 return; 1590 return;
1588 } 1591 }
1589 QString fileName = mFileName; 1592 QString fileName = mFileName;
1590 QFile file ( fileName ); 1593 QFile file ( fileName );
1591 if (!file.open( IO_WriteOnly ) ) { 1594 if (!file.open( QIODevice::WriteOnly ) ) {
1592 delete mSyncActionDialog; 1595 delete mSyncActionDialog;
1593 mSyncActionDialog = 0; 1596 mSyncActionDialog = 0;
1594 qDebug("KSS:Error open read back file "); 1597 qDebug("KSS:Error open read back file ");
1595 piFileString = ""; 1598 piFileString = "";
1596 emit file_received( false, mResource); 1599 emit file_received( false, mResource);
1597 emit file_received( false); 1600 emit file_received( false);
1598 blockRC = false; 1601 blockRC = false;
1599 return ; 1602 return ;
1600 1603
1601 } 1604 }
1602 1605
1603 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1606 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1604 QTextStream ts ( &file ); 1607 Q3TextStream ts ( &file );
1605 ts.setEncoding( QTextStream::Latin1 ); 1608 ts.setEncoding( Q3TextStream::Latin1 );
1606 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1609 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1607 ts << piFileString; 1610 ts << piFileString;
1608 mSocket->close(); 1611 mSocket->close();
1609 if ( mSocket->state() == QSocket::Idle ) 1612 if ( mSocket->state() == Q3Socket::Idle )
1610 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1613 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1611 file.close(); 1614 file.close();
1612 piFileString = ""; 1615 piFileString = "";
1613 emit file_received( true, mResource ); 1616 emit file_received( true, mResource );
1614 emit file_received( true); 1617 emit file_received( true);
1615 delete mSyncActionDialog; 1618 delete mSyncActionDialog;
1616 mSyncActionDialog = 0; 1619 mSyncActionDialog = 0;
1617 blockRC = false; 1620 blockRC = false;
1618 1621
1619} 1622}
1620 1623
1621KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1624KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1622{ 1625{
1623 mRemoteResource = remres; 1626 mRemoteResource = remres;
1624 if ( mRemoteResource.isEmpty() ) 1627 if ( mRemoteResource.isEmpty() )
1625 mRemoteResource = "ALL"; 1628 mRemoteResource = "ALL";
1626 else 1629 else
1627 mRemoteResource.replace (QRegExp (" "),"_" ); 1630 mRemoteResource.replace (QRegExp (" "),"_" );
1628 mPassWord = password; 1631 mPassWord = password;
1629 mSocket = 0; 1632 mSocket = 0;
1630 mFirst = false; 1633 mFirst = false;
1631 mFirstLine = true; 1634 mFirstLine = true;
1632 mPort = port; 1635 mPort = port;
1633 mHost = host; 1636 mHost = host;
1634 tlw = cap; 1637 tlw = cap;
1635 mRetVal = quiet; 1638 mRetVal = quiet;
1636 mTimerSocket = new QTimer ( this ); 1639 mTimerSocket = new QTimer ( this );
1637 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1640 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1638 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1641 mConnectProgress.setCaption( i18n("Pi-Sync") );
1639 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1642 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1640 mConnectCount = -1; 1643 mConnectCount = -1;
1641} 1644}
1642void KCommandSocket::sendFileRequest() 1645void KCommandSocket::sendFileRequest()
1643{ 1646{
1644 if ( tlw ) 1647 if ( tlw )
1645 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1648 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1646 mConnectProgress.hide(); 1649 mConnectProgress.hide();
1647 mConnectCount = 300;mConnectMax = 300; 1650 mConnectCount = 300;mConnectMax = 300;
1648 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1651 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1649 mConnectProgress.setLabelText( i18n("Waiting for remote file...") ); 1652 mConnectProgress.setLabelText( i18n("Waiting for remote file...") );
1650 mTimerSocket->start( 100, true ); 1653 mTimerSocket->start( 100, true );
1651 QTextStream os( mSocket ); 1654 Q3TextStream os( mSocket );
1652 os.setEncoding( QTextStream::Latin1 ); 1655 os.setEncoding( Q3TextStream::Latin1 );
1653 1656
1654 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1657 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1655 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; 1658 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n";
1656} 1659}
1657 1660
1658void KCommandSocket::readFile( QString fn ) 1661void KCommandSocket::readFile( QString fn )
1659{ 1662{
1660 if ( !mSocket ) { 1663 if ( !mSocket ) {
1661 mSocket = new QSocket( this ); 1664 mSocket = new Q3Socket( this );
1662 //qDebug("KCS: read file - new socket"); 1665 //qDebug("KCS: read file - new socket");
1663 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1666 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1664 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1667 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1665 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1668 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1666 } 1669 }
1667 mFileString = ""; 1670 mFileString = "";
1668 mFileName = fn; 1671 mFileName = fn;
1669 mFirst = true; 1672 mFirst = true;
1670 if ( tlw ) 1673 if ( tlw )
1671 tlw->setCaption( i18n("Trying to connect to remote...") ); 1674 tlw->setCaption( i18n("Trying to connect to remote...") );
1672 mConnectCount = 30;mConnectMax = 30; 1675 mConnectCount = 30;mConnectMax = 30;
1673 mTimerSocket->start( 1000, true ); 1676 mTimerSocket->start( 1000, true );
1674 mSocket->connectToHost( mHost, mPort ); 1677 mSocket->connectToHost( mHost, mPort );
1675 //qDebug("KCS: Waiting for connection"); 1678 //qDebug("KCS: Waiting for connection");
1676} 1679}
1677void KCommandSocket::updateConnectDialog() 1680void KCommandSocket::updateConnectDialog()
1678{ 1681{
1679 1682
1680 if ( mConnectCount == mConnectMax ) { 1683 if ( mConnectCount == mConnectMax ) {
1681 //qDebug("MAXX %d", mConnectMax); 1684 //qDebug("MAXX %d", mConnectMax);
1682 mConnectProgress.setTotalSteps ( 30 ); 1685 mConnectProgress.setTotalSteps ( 30 );
1683 mConnectProgress.show(); 1686 mConnectProgress.show();
1684 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1687 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1685 } 1688 }
1686 //qDebug("updateConnectDialog() %d", mConnectCount); 1689 //qDebug("updateConnectDialog() %d", mConnectCount);
1687 mConnectProgress.raise(); 1690 mConnectProgress.raise();
1688 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1691 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1689 --mConnectCount; 1692 --mConnectCount;
1690 if ( mConnectCount > 0 ) 1693 if ( mConnectCount > 0 )
1691 mTimerSocket->start( 1000, true ); 1694 mTimerSocket->start( 1000, true );
1692 else 1695 else
1693 deleteSocket(); 1696 deleteSocket();
1694 1697
1695} 1698}
1696void KCommandSocket::writeFile( QString fileName ) 1699void KCommandSocket::writeFile( QString fileName )
1697{ 1700{
1698 if ( !mSocket ) { 1701 if ( !mSocket ) {
1699 mSocket = new QSocket( this ); 1702 mSocket = new Q3Socket( this );
1700 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1703 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1701 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1704 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1702 } 1705 }
1703 mFileName = fileName ; 1706 mFileName = fileName ;
1704 mConnectCount = 30;mConnectMax = 30; 1707 mConnectCount = 30;mConnectMax = 30;
1705 mTimerSocket->start( 1000, true ); 1708 mTimerSocket->start( 1000, true );
1706 mSocket->connectToHost( mHost, mPort ); 1709 mSocket->connectToHost( mHost, mPort );
1707} 1710}
1708void KCommandSocket::writeFileToSocket() 1711void KCommandSocket::writeFileToSocket()
1709{ 1712{
1710 mTimerSocket->stop(); 1713 mTimerSocket->stop();
1711 QFile file2( mFileName ); 1714 QFile file2( mFileName );
1712 if (!file2.open( IO_ReadOnly ) ) { 1715 if (!file2.open( QIODevice::ReadOnly ) ) {
1713 mConnectProgress.hide(); 1716 mConnectProgress.hide();
1714 mConnectCount = -1; 1717 mConnectCount = -1;
1715 mRetVal= errorW; 1718 mRetVal= errorW;
1716 mSocket->close(); 1719 mSocket->close();
1717 if ( mSocket->state() == QSocket::Idle ) 1720 if ( mSocket->state() == Q3Socket::Idle )
1718 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1721 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1719 return ; 1722 return ;
1720 } 1723 }
1721 mConnectProgress.setTotalSteps ( file2.size() ); 1724 mConnectProgress.setTotalSteps ( file2.size() );
1722 mConnectProgress.show(); 1725 mConnectProgress.show();
1723 int count = 0; 1726 int count = 0;
1724 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1727 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1725 mConnectProgress.setProgress( count ); 1728 mConnectProgress.setProgress( count );
1726 mConnectProgress.blockSignals( true ); 1729 mConnectProgress.blockSignals( true );
1727 QTextStream ts2( &file2 ); 1730 Q3TextStream ts2( &file2 );
1728 ts2.setEncoding( QTextStream::Latin1 ); 1731 ts2.setEncoding( Q3TextStream::Latin1 );
1729 QTextStream os2( mSocket ); 1732 Q3TextStream os2( mSocket );
1730 os2.setEncoding( QTextStream::Latin1 ); 1733 os2.setEncoding( Q3TextStream::Latin1 );
1731 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; 1734 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
1732 int byteCount = 0; 1735 int byteCount = 0;
1733 int byteMax = file2.size()/53; 1736 int byteMax = file2.size()/53;
1734 while ( ! ts2.atEnd() ) { 1737 while ( ! ts2.atEnd() ) {
1735 qApp->processEvents(); 1738 qApp->processEvents();
1736 if ( byteCount > byteMax ) { 1739 if ( byteCount > byteMax ) {
1737 byteCount = 0; 1740 byteCount = 0;
1738 mConnectProgress.setProgress( count ); 1741 mConnectProgress.setProgress( count );
1739 } 1742 }
1740 QString temp = ts2.readLine(); 1743 QString temp = ts2.readLine();
1741 count += temp.length(); 1744 count += temp.length();
1742 byteCount += temp.length(); 1745 byteCount += temp.length();
1743 os2 << temp << "\r\n"; 1746 os2 << temp << "\r\n";
1744 } 1747 }
1745 file2.close(); 1748 file2.close();
1746 mConnectProgress.hide(); 1749 mConnectProgress.hide();
1747 mConnectCount = -1; 1750 mConnectCount = -1;
1748 os2 << "\r\n"; 1751 os2 << "\r\n";
1749 mRetVal= successW; 1752 mRetVal= successW;
1750 mSocket->close(); 1753 mSocket->close();
1751 if ( mSocket->state() == QSocket::Idle ) 1754 if ( mSocket->state() == Q3Socket::Idle )
1752 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1755 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1753 mConnectProgress.blockSignals( false ); 1756 mConnectProgress.blockSignals( false );
1754} 1757}
1755void KCommandSocket::sendStop() 1758void KCommandSocket::sendStop()
1756{ 1759{
1757 if ( !mSocket ) { 1760 if ( !mSocket ) {
1758 mSocket = new QSocket( this ); 1761 mSocket = new Q3Socket( this );
1759 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1762 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1760 } 1763 }
1761 mSocket->connectToHost( mHost, mPort ); 1764 mSocket->connectToHost( mHost, mPort );
1762 QTextStream os2( mSocket ); 1765 Q3TextStream os2( mSocket );
1763 os2.setEncoding( QTextStream::Latin1 ); 1766 os2.setEncoding( Q3TextStream::Latin1 );
1764 os2 << "STOP\r\n\r\n"; 1767 os2 << "STOP\r\n\r\n";
1765 mSocket->close(); 1768 mSocket->close();
1766 if ( mSocket->state() == QSocket::Idle ) 1769 if ( mSocket->state() == Q3Socket::Idle )
1767 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1770 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1768} 1771}
1769 1772
1770void KCommandSocket::startReadFileFromSocket() 1773void KCommandSocket::startReadFileFromSocket()
1771{ 1774{
1772 if ( ! mFirst ) 1775 if ( ! mFirst )
1773 return; 1776 return;
1774 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1777 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1775 mFirst = false; 1778 mFirst = false;
1776 mFileString = ""; 1779 mFileString = "";
1777 mTime.start(); 1780 mTime.start();
1778 mFirstLine = true; 1781 mFirstLine = true;
1779 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1782 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1780 1783
1781} 1784}
1782void KCommandSocket::readFileFromSocket() 1785void KCommandSocket::readFileFromSocket()
1783{ 1786{
1784 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1787 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1785 while ( mSocket->canReadLine () ) { 1788 while ( mSocket->canReadLine () ) {
1786 mTime.restart(); 1789 mTime.restart();
1787 QString line = mSocket->readLine (); 1790 QString line = mSocket->readLine ();
1788 if ( mFirstLine ) { 1791 if ( mFirstLine ) {
1789 mFirstLine = false; 1792 mFirstLine = false;
1790 if ( line.left( 6 ) == "ERROR_" ) { 1793 if ( line.left( 6 ) == "ERROR_" ) {
@@ -1808,67 +1811,67 @@ void KCommandSocket::readFileFromSocket()
1808 if ( line.left( 8 ) == "ERROR_ED" ) { 1811 if ( line.left( 8 ) == "ERROR_ED" ) {
1809 mRetVal = errorED; 1812 mRetVal = errorED;
1810 deleteSocket(); 1813 deleteSocket();
1811 return ; 1814 return ;
1812 } 1815 }
1813 mRetVal = errorUN; 1816 mRetVal = errorUN;
1814 deleteSocket(); 1817 deleteSocket();
1815 return ; 1818 return ;
1816 } 1819 }
1817 } 1820 }
1818 mFileString += line; 1821 mFileString += line;
1819 //qDebug("readline: %s ", line.latin1()); 1822 //qDebug("readline: %s ", line.latin1());
1820 } 1823 }
1821 if ( mTime.elapsed () < 3000 ) { 1824 if ( mTime.elapsed () < 3000 ) {
1822 // wait for more 1825 // wait for more
1823 //qDebug("waitformore "); 1826 //qDebug("waitformore ");
1824 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1827 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1825 return; 1828 return;
1826 } 1829 }
1827 mTimerSocket->stop(); 1830 mTimerSocket->stop();
1828 mConnectCount = -1; 1831 mConnectCount = -1;
1829 mConnectProgress.hide(); 1832 mConnectProgress.hide();
1830 QString fileName = mFileName; 1833 QString fileName = mFileName;
1831 QFile file ( fileName ); 1834 QFile file ( fileName );
1832 if (!file.open( IO_WriteOnly ) ) { 1835 if (!file.open( QIODevice::WriteOnly ) ) {
1833 mFileString = ""; 1836 mFileString = "";
1834 mRetVal = errorR; 1837 mRetVal = errorR;
1835 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1838 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1836 deleteSocket(); 1839 deleteSocket();
1837 return ; 1840 return ;
1838 1841
1839 } 1842 }
1840 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1843 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1841 QTextStream ts ( &file ); 1844 Q3TextStream ts ( &file );
1842 ts.setEncoding( QTextStream::Latin1 ); 1845 ts.setEncoding( Q3TextStream::Latin1 );
1843 ts << mFileString; 1846 ts << mFileString;
1844 file.close(); 1847 file.close();
1845 mFileString = ""; 1848 mFileString = "";
1846 mRetVal = successR; 1849 mRetVal = successR;
1847 mSocket->close(); 1850 mSocket->close();
1848 // if state is not idle, deleteSocket(); is called via 1851 // if state is not idle, deleteSocket(); is called via
1849 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1852 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1850 if ( mSocket->state() == QSocket::Idle ) 1853 if ( mSocket->state() == Q3Socket::Idle )
1851 deleteSocket(); 1854 deleteSocket();
1852} 1855}
1853 1856
1854void KCommandSocket::deleteSocket() 1857void KCommandSocket::deleteSocket()
1855{ 1858{
1856 //qDebug("KCommandSocket::deleteSocket() "); 1859 //qDebug("KCommandSocket::deleteSocket() ");
1857 mConnectProgress.hide(); 1860 mConnectProgress.hide();
1858 1861
1859 if ( mConnectCount >= 0 ) { 1862 if ( mConnectCount >= 0 ) {
1860 mTimerSocket->stop(); 1863 mTimerSocket->stop();
1861 mRetVal = errorTO; 1864 mRetVal = errorTO;
1862 qDebug("KCS::Connection to remote host timed out"); 1865 qDebug("KCS::Connection to remote host timed out");
1863 if ( mSocket ) { 1866 if ( mSocket ) {
1864 mSocket->close(); 1867 mSocket->close();
1865 //if ( mSocket->state() == QSocket::Idle ) 1868 //if ( mSocket->state() == QSocket::Idle )
1866 // deleteSocket(); 1869 // deleteSocket();
1867 delete mSocket; 1870 delete mSocket;
1868 mSocket = 0; 1871 mSocket = 0;
1869 } 1872 }
1870 if ( mConnectCount == 0 ) 1873 if ( mConnectCount == 0 )
1871 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1874 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1872 else if ( tlw ) 1875 else if ( tlw )
1873 tlw->setCaption( i18n("Connection to remote host cancelled!") ); 1876 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1874 emit commandFinished( this, mRetVal ); 1877 emit commandFinished( this, mRetVal );