summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp97
1 files changed, 78 insertions, 19 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index fc0ac6b..f2ee0ab 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -354,5 +354,5 @@ void KSyncManager::enableQuick( bool ask )
354 lay.setSpacing(7); 354 lay.setSpacing(7);
355 int po = 9197+mTargetApp; 355 int po = 9197+mTargetApp;
356 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 356 QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia );
357 lay.addWidget( &label); 357 lay.addWidget( &label);
358 lay.addWidget( &lab); 358 lay.addWidget( &lab);
@@ -416,14 +416,16 @@ void KSyncManager::enableQuick( bool ask )
416 bool ok; 416 bool ok;
417 mPrefs->mPassiveSyncAutoStart = false; 417 mPrefs->mPassiveSyncAutoStart = false;
418 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 418 Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok);
419 if ( ! ok ) { 419 qDebug("%d ", port_t);
420 KMessageBox::information( 0, i18n("No valid port")); 420 if ( ! ok || port_t > 65535 ) {
421 KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error"));
421 return; 422 return;
422 } 423 }
424 Q_UINT16 port = port_t;
423 //qDebug("port %d ", port); 425 //qDebug("port %d ", port);
424 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 426 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
425 mServerSocket->setFileName( defaultFileName() );//bbb 427 mServerSocket->setFileName( defaultFileName() );//bbb
426 if ( !mServerSocket->ok() ) { 428 if ( !mServerSocket->ok() ) {
427 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 429 QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) );
428 delete mServerSocket; 430 delete mServerSocket;
429 mServerSocket = 0; 431 mServerSocket = 0;
@@ -437,5 +439,8 @@ void KSyncManager::enableQuick( bool ask )
437 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 439 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
438} 440}
439 441void KSyncManager::displayErrorPort()
442{
443 KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error"));
444}
440void KSyncManager::syncLocalFile() 445void KSyncManager::syncLocalFile()
441{ 446{
@@ -797,5 +802,5 @@ bool KSyncManager::edit_pisync_options()
797 QLineEdit le2 (&dia ); 802 QLineEdit le2 (&dia );
798 lay.addWidget( &le2 ); 803 lay.addWidget( &le2 );
799 QLabel lab3 ( i18n("Remote port number:"), &dia); 804 QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia);
800 lay.addWidget( &lab3 ); 805 lay.addWidget( &lab3 );
801 QLineEdit le3 (&dia ); 806 QLineEdit le3 (&dia );
@@ -1189,6 +1194,8 @@ void KSyncManager::readFileFromSocket()
1189 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1194 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1190 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1195 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1191 if ( mWriteBackFile && syncOK ) 1196 if ( mWriteBackFile && syncOK ) {
1197 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1192 commandSocket->writeFile( fileName ); 1198 commandSocket->writeFile( fileName );
1199 }
1193 else { 1200 else {
1194 commandSocket->sendStop(); 1201 commandSocket->sendStop();
@@ -1293,9 +1300,9 @@ void KServerSocket::displayErrorMessage()
1293{ 1300{
1294 if ( mErrorMessage == 1 ) { 1301 if ( mErrorMessage == 1 ) {
1295 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1302 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1296 mErrorMessage = 0; 1303 mErrorMessage = 0;
1297 } 1304 }
1298 else if ( mErrorMessage == 2 ) { 1305 else if ( mErrorMessage == 2 ) {
1299 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1306 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1300 mErrorMessage = 0; 1307 mErrorMessage = 0;
1301 } 1308 }
@@ -1467,5 +1474,8 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host,
1467 mRetVal = quiet; 1474 mRetVal = quiet;
1468 mTimerSocket = new QTimer ( this ); 1475 mTimerSocket = new QTimer ( this );
1469 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1476 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1477 mConnectProgress.setCaption( i18n("Pi-Sync") );
1478 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1479 mConnectCount = -1;
1470} 1480}
1471void KCommandSocket::sendFileRequest() 1481void KCommandSocket::sendFileRequest()
@@ -1473,5 +1483,8 @@ void KCommandSocket::sendFileRequest()
1473 if ( tlw ) 1483 if ( tlw )
1474 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1484 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1475 mTimerSocket->start( 300000 ); 1485 mConnectProgress.hide();
1486 mConnectCount = 300;mConnectMax = 300;
1487 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1488 mTimerSocket->start( 100, true );
1476 QTextStream os( mSocket ); 1489 QTextStream os( mSocket );
1477 os.setEncoding( QTextStream::Latin1 ); 1490 os.setEncoding( QTextStream::Latin1 );
@@ -1494,9 +1507,28 @@ void KCommandSocket::readFile( QString fn )
1494 if ( tlw ) 1507 if ( tlw )
1495 tlw->setCaption( i18n("Trying to connect to remote...") ); 1508 tlw->setCaption( i18n("Trying to connect to remote...") );
1496 mTimerSocket->start( 20000 ); 1509 mConnectCount = 30;mConnectMax = 30;
1510 mTimerSocket->start( 1000, true );
1497 mSocket->connectToHost( mHost, mPort ); 1511 mSocket->connectToHost( mHost, mPort );
1498 qDebug("KSS: Waiting for connection"); 1512 qDebug("KSS: Waiting for connection");
1499} 1513}
1500 1514void KCommandSocket::updateConnectDialog()
1515{
1516
1517 if ( mConnectCount == mConnectMax ) {
1518 //qDebug("MAXX %d", mConnectMax);
1519 mConnectProgress.setTotalSteps ( 30 );
1520 mConnectProgress.show();
1521 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1522 }
1523 //qDebug("updateConnectDialog() %d", mConnectCount);
1524 mConnectProgress.raise();
1525 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1526 --mConnectCount;
1527 if ( mConnectCount > 0 )
1528 mTimerSocket->start( 1000, true );
1529 else
1530 deleteSocket();
1531
1532}
1501void KCommandSocket::writeFile( QString fileName ) 1533void KCommandSocket::writeFile( QString fileName )
1502{ 1534{
@@ -1507,5 +1539,6 @@ void KCommandSocket::writeFile( QString fileName )
1507 } 1539 }
1508 mFileName = fileName ; 1540 mFileName = fileName ;
1509 mTimerSocket->start( 20000 ); 1541 mConnectCount = 30;mConnectMax = 30;
1542 mTimerSocket->start( 1000, true );
1510 mSocket->connectToHost( mHost, mPort ); 1543 mSocket->connectToHost( mHost, mPort );
1511} 1544}
@@ -1515,4 +1548,6 @@ void KCommandSocket::writeFileToSocket()
1515 QFile file2( mFileName ); 1548 QFile file2( mFileName );
1516 if (!file2.open( IO_ReadOnly ) ) { 1549 if (!file2.open( IO_ReadOnly ) ) {
1550 mConnectProgress.hide();
1551 mConnectCount = -1;
1517 mRetVal= errorW; 1552 mRetVal= errorW;
1518 mSocket->close(); 1553 mSocket->close();
@@ -1521,4 +1556,10 @@ void KCommandSocket::writeFileToSocket()
1521 return ; 1556 return ;
1522 } 1557 }
1558 mConnectProgress.setTotalSteps ( file2.size() );
1559 mConnectProgress.show();
1560 int count = 0;
1561 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1562 mConnectProgress.setProgress( count );
1563 mConnectProgress.blockSignals( true );
1523 QTextStream ts2( &file2 ); 1564 QTextStream ts2( &file2 );
1524 ts2.setEncoding( QTextStream::Latin1 ); 1565 ts2.setEncoding( QTextStream::Latin1 );
@@ -1527,12 +1568,19 @@ void KCommandSocket::writeFileToSocket()
1527 os2 << "PUT " << mPassWord << "\r\n\r\n";; 1568 os2 << "PUT " << mPassWord << "\r\n\r\n";;
1528 while ( ! ts2.atEnd() ) { 1569 while ( ! ts2.atEnd() ) {
1529 os2 << ts2.readLine() << "\r\n"; 1570 qApp->processEvents();
1571 mConnectProgress.setProgress( count );
1572 QString temp = ts2.readLine();
1573 count += temp.length();
1574 os2 << temp << "\r\n";
1530 } 1575 }
1576 file2.close();
1577 mConnectProgress.hide();
1578 mConnectCount = -1;
1531 os2 << "\r\n"; 1579 os2 << "\r\n";
1532 mRetVal= successW; 1580 mRetVal= successW;
1533 file2.close();
1534 mSocket->close(); 1581 mSocket->close();
1535 if ( mSocket->state() == QSocket::Idle ) 1582 if ( mSocket->state() == QSocket::Idle )
1536 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1583 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1584 mConnectProgress.blockSignals( false );
1537} 1585}
1538void KCommandSocket::sendStop() 1586void KCommandSocket::sendStop()
@@ -1555,6 +1603,6 @@ void KCommandSocket::startReadFileFromSocket()
1555 if ( ! mFirst ) 1603 if ( ! mFirst )
1556 return; 1604 return;
1605 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1557 mFirst = false; 1606 mFirst = false;
1558 mTimerSocket->stop();
1559 mFileString = ""; 1607 mFileString = "";
1560 mTime.start(); 1608 mTime.start();
@@ -1572,4 +1620,6 @@ void KCommandSocket::readFileFromSocket()
1572 mFirstLine = false; 1620 mFirstLine = false;
1573 if ( line.left( 6 ) == "ERROR_" ) { 1621 if ( line.left( 6 ) == "ERROR_" ) {
1622 mTimerSocket->stop();
1623 mConnectCount = -1;
1574 if ( line.left( 8 ) == "ERROR_PW" ) { 1624 if ( line.left( 8 ) == "ERROR_PW" ) {
1575 mRetVal = errorPW; 1625 mRetVal = errorPW;
@@ -1606,4 +1656,7 @@ void KCommandSocket::readFileFromSocket()
1606 return; 1656 return;
1607 } 1657 }
1658 mTimerSocket->stop();
1659 mConnectCount = -1;
1660 mConnectProgress.hide();
1608 QString fileName = mFileName; 1661 QString fileName = mFileName;
1609 QFile file ( fileName ); 1662 QFile file ( fileName );
@@ -1633,5 +1686,7 @@ void KCommandSocket::deleteSocket()
1633{ 1686{
1634 //qDebug("KCommandSocket::deleteSocket() "); 1687 //qDebug("KCommandSocket::deleteSocket() ");
1635 if ( mTimerSocket->isActive () ) { 1688 mConnectProgress.hide();
1689
1690 if ( mConnectCount >= 0 ) {
1636 mTimerSocket->stop(); 1691 mTimerSocket->stop();
1637 mRetVal = errorTO; 1692 mRetVal = errorTO;
@@ -1644,5 +1699,8 @@ void KCommandSocket::deleteSocket()
1644 mSocket = 0; 1699 mSocket = 0;
1645 } 1700 }
1701 if ( mConnectCount == 0 )
1646 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1702 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1703 else if ( tlw )
1704 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1647 emit commandFinished( this, mRetVal ); 1705 emit commandFinished( this, mRetVal );
1648 return; 1706 return;
@@ -1652,4 +1710,5 @@ void KCommandSocket::deleteSocket()
1652 delete mSocket; 1710 delete mSocket;
1653 mSocket = 0; 1711 mSocket = 0;
1712 qDebug("commandFinished ");
1654 emit commandFinished( this, mRetVal ); 1713 emit commandFinished( this, mRetVal );
1655} 1714}