summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 9177f63..c8d0e0d 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -51,58 +51,62 @@
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent; 58QDateTime KSyncManager::mRequestedSyncEvent;
59 59
60 60
61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
62 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) 62 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
63{ 63{
64 mServerSocket = 0; 64 mServerSocket = 0;
65 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
66 bar->setCaption (""); 66 bar->setCaption ("");
67 mWriteBackInPast = 2; 67 mWriteBackInPast = 2;
68 int w = 300; 68 int w = 300;
69 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
70 w = 220; 70 w = 220;
71 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
72 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
73 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
75 if ( mPrefs->mPassiveSyncAutoStart )
76 enableQuick( false );
77 75
78} 76}
79 77
80KSyncManager::~KSyncManager() 78KSyncManager::~KSyncManager()
81{ 79{
82 delete bar; 80 delete bar;
83} 81}
84 82
83void KSyncManager::setDefaultFileName( QString s)
84{
85 mDefFileName = s ;
86 if ( mPrefs->mPassiveSyncAutoStart )
87 enableQuick( false );
88}
85 89
86void KSyncManager::fillSyncMenu() 90void KSyncManager::fillSyncMenu()
87{ 91{
88 if ( mSyncMenu->count() ) 92 if ( mSyncMenu->count() )
89 mSyncMenu->clear(); 93 mSyncMenu->clear();
90 94
91 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 95 mSyncMenu->insertItem( i18n("Configure..."), 0 );
92 mSyncMenu->insertSeparator(); 96 mSyncMenu->insertSeparator();
93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 97 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 98 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
95 clearMenu->insertItem( i18n("For all profiles"), 1 ); 99 clearMenu->insertItem( i18n("For all profiles"), 1 );
96 clearMenu->insertSeparator(); 100 clearMenu->insertSeparator();
97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 101 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
98 mSyncMenu->insertSeparator(); 102 mSyncMenu->insertSeparator();
99 if ( mServerSocket == 0 ) { 103 if ( mServerSocket == 0 ) {
100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 104 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
101 } else { 105 } else {
102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 106 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
103 } 107 }
104 mSyncMenu->insertSeparator(); 108 mSyncMenu->insertSeparator();
105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 109 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
106 mSyncMenu->insertSeparator(); 110 mSyncMenu->insertSeparator();
107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 111 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
108 config.setGroup("General"); 112 config.setGroup("General");
@@ -391,49 +395,48 @@ void KSyncManager::enableQuick( bool ask )
391 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 395 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
392 mPrefs->mPassiveSyncPort = lab.text(); 396 mPrefs->mPassiveSyncPort = lab.text();
393 changed = true; 397 changed = true;
394 } 398 }
395 autoStart = autostart.isChecked(); 399 autoStart = autostart.isChecked();
396 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 400 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
397 changed = true; 401 changed = true;
398 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 402 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
399 } 403 }
400 } 404 }
401 else 405 else
402 autoStart = mPrefs->mPassiveSyncAutoStart; 406 autoStart = mPrefs->mPassiveSyncAutoStart;
403 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 407 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
404 changed = true; 408 changed = true;
405 bool ok; 409 bool ok;
406 mPrefs->mPassiveSyncAutoStart = false; 410 mPrefs->mPassiveSyncAutoStart = false;
407 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 411 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
408 if ( ! ok ) { 412 if ( ! ok ) {
409 KMessageBox::information( 0, i18n("No valid port")); 413 KMessageBox::information( 0, i18n("No valid port"));
410 return; 414 return;
411 } 415 }
412 //qDebug("port %d ", port); 416 //qDebug("port %d ", port);
413 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 417 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
414 mServerSocket->setFileName( defaultFileName() );//bbb 418 mServerSocket->setFileName( defaultFileName() );//bbb
415 //qDebug("connected ");
416 if ( !mServerSocket->ok() ) { 419 if ( !mServerSocket->ok() ) {
417 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 420 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
418 delete mServerSocket; 421 delete mServerSocket;
419 mServerSocket = 0; 422 mServerSocket = 0;
420 return; 423 return;
421 } 424 }
422 mPrefs->mPassiveSyncAutoStart = autoStart; 425 mPrefs->mPassiveSyncAutoStart = autoStart;
423 if ( changed ) { 426 if ( changed ) {
424 mPrefs->writeConfig(); 427 mPrefs->writeConfig();
425 } 428 }
426 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 429 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
427 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 430 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
428} 431}
429 432
430void KSyncManager::syncLocalFile() 433void KSyncManager::syncLocalFile()
431{ 434{
432 435
433 QString fn =mPrefs->mLastSyncedLocalFile; 436 QString fn =mPrefs->mLastSyncedLocalFile;
434 QString ext; 437 QString ext;
435 438
436 switch(mTargetApp) 439 switch(mTargetApp)
437 { 440 {
438 case (KAPI): 441 case (KAPI):
439 ext = "(*.vcf)"; 442 ext = "(*.vcf)";
@@ -1096,49 +1099,49 @@ void KSyncManager::readFileFromSocket()
1096 QString fileName = syncFileName(); 1099 QString fileName = syncFileName();
1097 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1100 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1098 if ( ! syncWithFile( fileName , true ) ) { 1101 if ( ! syncWithFile( fileName , true ) ) {
1099 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1102 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1100 mPisyncFinished = true; 1103 mPisyncFinished = true;
1101 return; 1104 return;
1102 } 1105 }
1103 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1106 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1104 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1107 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1105 if ( mWriteBackFile ) 1108 if ( mWriteBackFile )
1106 commandSocket->writeFile( fileName ); 1109 commandSocket->writeFile( fileName );
1107 else { 1110 else {
1108 commandSocket->sendStop(); 1111 commandSocket->sendStop();
1109 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1112 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1110 mPisyncFinished = true; 1113 mPisyncFinished = true;
1111 } 1114 }
1112} 1115}
1113 1116
1114KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1117KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1115{ 1118{
1116 mPassWord = pw; 1119 mPassWord = pw;
1117 mSocket = 0; 1120 mSocket = 0;
1118 mSyncActionDialog = 0; 1121 mSyncActionDialog = 0;
1119 blockRC = false; 1122 blockRC = false;
1120}; 1123}
1121 1124
1122void KServerSocket::newConnection ( int socket ) 1125void KServerSocket::newConnection ( int socket )
1123{ 1126{
1124 // qDebug("KServerSocket:New connection %d ", socket); 1127 // qDebug("KServerSocket:New connection %d ", socket);
1125 if ( mSocket ) { 1128 if ( mSocket ) {
1126 qDebug("KSS::newConnection Socket deleted! "); 1129 qDebug("KSS::newConnection Socket deleted! ");
1127 delete mSocket; 1130 delete mSocket;
1128 mSocket = 0; 1131 mSocket = 0;
1129 } 1132 }
1130 mSocket = new QSocket( this ); 1133 mSocket = new QSocket( this );
1131 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1134 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1132 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1135 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1133 mSocket->setSocket( socket ); 1136 mSocket->setSocket( socket );
1134} 1137}
1135 1138
1136void KServerSocket::discardClient() 1139void KServerSocket::discardClient()
1137{ 1140{
1138 //qDebug(" KServerSocket::discardClient()"); 1141 //qDebug(" KServerSocket::discardClient()");
1139 if ( mSocket ) { 1142 if ( mSocket ) {
1140 delete mSocket; 1143 delete mSocket;
1141 mSocket = 0; 1144 mSocket = 0;
1142 } 1145 }
1143 //emit endConnect(); 1146 //emit endConnect();
1144} 1147}