summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2005-11-25 21:00:35 (UTC)
committer zautrix <zautrix>2005-11-25 21:00:35 (UTC)
commit81d012860ea3d5d17d0e9cf16ec992baa83efbbf (patch) (unidiff)
tree2e5ce0b81f1700f9c6dc60a8411029cd194e45a1 /libkdepim/ksyncmanager.cpp
parent2468bddcb380d8621d5bb49b69b3492d90562d93 (diff)
downloadkdepimpi-81d012860ea3d5d17d0e9cf16ec992baa83efbbf.zip
kdepimpi-81d012860ea3d5d17d0e9cf16ec992baa83efbbf.tar.gz
kdepimpi-81d012860ea3d5d17d0e9cf16ec992baa83efbbf.tar.bz2
sync
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index d2cb71b..e1b15d2 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1584,195 +1584,195 @@ void KCommandSocket::updateConnectDialog()
1584 --mConnectCount; 1584 --mConnectCount;
1585 if ( mConnectCount > 0 ) 1585 if ( mConnectCount > 0 )
1586 mTimerSocket->start( 1000, true ); 1586 mTimerSocket->start( 1000, true );
1587 else 1587 else
1588 deleteSocket(); 1588 deleteSocket();
1589 1589
1590} 1590}
1591void KCommandSocket::writeFile( QString fileName ) 1591void KCommandSocket::writeFile( QString fileName )
1592{ 1592{
1593 if ( !mSocket ) { 1593 if ( !mSocket ) {
1594 mSocket = new QSocket( this ); 1594 mSocket = new QSocket( this );
1595 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1595 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1596 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1596 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1597 } 1597 }
1598 mFileName = fileName ; 1598 mFileName = fileName ;
1599 mConnectCount = 30;mConnectMax = 30; 1599 mConnectCount = 30;mConnectMax = 30;
1600 mTimerSocket->start( 1000, true ); 1600 mTimerSocket->start( 1000, true );
1601 mSocket->connectToHost( mHost, mPort ); 1601 mSocket->connectToHost( mHost, mPort );
1602} 1602}
1603void KCommandSocket::writeFileToSocket() 1603void KCommandSocket::writeFileToSocket()
1604{ 1604{
1605 mTimerSocket->stop(); 1605 mTimerSocket->stop();
1606 QFile file2( mFileName ); 1606 QFile file2( mFileName );
1607 if (!file2.open( IO_ReadOnly ) ) { 1607 if (!file2.open( IO_ReadOnly ) ) {
1608 mConnectProgress.hide(); 1608 mConnectProgress.hide();
1609 mConnectCount = -1; 1609 mConnectCount = -1;
1610 mRetVal= errorW; 1610 mRetVal= errorW;
1611 mSocket->close(); 1611 mSocket->close();
1612 if ( mSocket->state() == QSocket::Idle ) 1612 if ( mSocket->state() == QSocket::Idle )
1613 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1613 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1614 return ; 1614 return ;
1615 } 1615 }
1616 mConnectProgress.setTotalSteps ( file2.size() ); 1616 mConnectProgress.setTotalSteps ( file2.size() );
1617 mConnectProgress.show(); 1617 mConnectProgress.show();
1618 int count = 0; 1618 int count = 0;
1619 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1619 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1620 mConnectProgress.setProgress( count ); 1620 mConnectProgress.setProgress( count );
1621 mConnectProgress.blockSignals( true ); 1621 mConnectProgress.blockSignals( true );
1622 QTextStream ts2( &file2 ); 1622 QTextStream ts2( &file2 );
1623 ts2.setEncoding( QTextStream::Latin1 ); 1623 ts2.setEncoding( QTextStream::Latin1 );
1624 QTextStream os2( mSocket ); 1624 QTextStream os2( mSocket );
1625 os2.setEncoding( QTextStream::Latin1 ); 1625 os2.setEncoding( QTextStream::Latin1 );
1626 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; 1626 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
1627 int byteCount = 0; 1627 int byteCount = 0;
1628 int byteMax = file2.size()/53; 1628 int byteMax = file2.size()/53;
1629 while ( ! ts2.atEnd() ) { 1629 while ( ! ts2.atEnd() ) {
1630 qApp->processEvents(); 1630 qApp->processEvents();
1631 if ( byteCount > byteMax ) { 1631 if ( byteCount > byteMax ) {
1632 byteCount = 0; 1632 byteCount = 0;
1633 mConnectProgress.setProgress( count ); 1633 mConnectProgress.setProgress( count );
1634 } 1634 }
1635 QString temp = ts2.readLine(); 1635 QString temp = ts2.readLine();
1636 count += temp.length(); 1636 count += temp.length();
1637 byteCount += temp.length(); 1637 byteCount += temp.length();
1638 os2 << temp << "\r\n"; 1638 os2 << temp << "\r\n";
1639 } 1639 }
1640 file2.close(); 1640 file2.close();
1641 mConnectProgress.hide(); 1641 mConnectProgress.hide();
1642 mConnectCount = -1; 1642 mConnectCount = -1;
1643 os2 << "\r\n"; 1643 os2 << "\r\n";
1644 mRetVal= successW; 1644 mRetVal= successW;
1645 mSocket->close(); 1645 mSocket->close();
1646 if ( mSocket->state() == QSocket::Idle ) 1646 if ( mSocket->state() == QSocket::Idle )
1647 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1647 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1648 mConnectProgress.blockSignals( false ); 1648 mConnectProgress.blockSignals( false );
1649} 1649}
1650void KCommandSocket::sendStop() 1650void KCommandSocket::sendStop()
1651{ 1651{
1652 if ( !mSocket ) { 1652 if ( !mSocket ) {
1653 mSocket = new QSocket( this ); 1653 mSocket = new QSocket( this );
1654 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1654 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1655 } 1655 }
1656 mSocket->connectToHost( mHost, mPort ); 1656 mSocket->connectToHost( mHost, mPort );
1657 QTextStream os2( mSocket ); 1657 QTextStream os2( mSocket );
1658 os2.setEncoding( QTextStream::Latin1 ); 1658 os2.setEncoding( QTextStream::Latin1 );
1659 os2 << "STOP\r\n\r\n"; 1659 os2 << "STOP\r\n\r\n";
1660 mSocket->close(); 1660 mSocket->close();
1661 if ( mSocket->state() == QSocket::Idle ) 1661 if ( mSocket->state() == QSocket::Idle )
1662 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1662 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1663} 1663}
1664 1664
1665void KCommandSocket::startReadFileFromSocket() 1665void KCommandSocket::startReadFileFromSocket()
1666{ 1666{
1667 if ( ! mFirst ) 1667 if ( ! mFirst )
1668 return; 1668 return;
1669 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1669 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1670 mFirst = false; 1670 mFirst = false;
1671 mFileString = ""; 1671 mFileString = "";
1672 mTime.start(); 1672 mTime.start();
1673 mFirstLine = true; 1673 mFirstLine = true;
1674 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1674 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1675 1675
1676} 1676}
1677void KCommandSocket::readFileFromSocket() 1677void KCommandSocket::readFileFromSocket()
1678{ 1678{
1679 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1679 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1680 while ( mSocket->canReadLine () ) { 1680 while ( mSocket->canReadLine () ) {
1681 mTime.restart(); 1681 mTime.restart();
1682 QString line = mSocket->readLine (); 1682 QString line = mSocket->readLine ();
1683 if ( mFirstLine ) { 1683 if ( mFirstLine ) {
1684 mFirstLine = false; 1684 mFirstLine = false;
1685 if ( line.left( 6 ) == "ERROR_" ) { 1685 if ( line.left( 6 ) == "ERROR_" ) {
1686 mTimerSocket->stop(); 1686 mTimerSocket->stop();
1687 mConnectCount = -1; 1687 mConnectCount = -1;
1688 if ( line.left( 8 ) == "ERROR_PW" ) { 1688 if ( line.left( 8 ) == "ERROR_PW" ) {
1689 mRetVal = errorPW; 1689 mRetVal = errorPW;
1690 deleteSocket(); 1690 deleteSocket();
1691 return ; 1691 return ;
1692 } 1692 }
1693 if ( line.left( 8 ) == "ERROR_CA" ) { 1693 if ( line.left( 8 ) == "ERROR_CA" ) {
1694 mRetVal = errorCA; 1694 mRetVal = errorCA;
1695 deleteSocket(); 1695 deleteSocket();
1696 return ; 1696 return ;
1697 } 1697 }
1698 if ( line.left( 8 ) == "ERROR_FI" ) { 1698 if ( line.left( 8 ) == "ERROR_FI" ) {
1699 mRetVal = errorFI; 1699 mRetVal = errorFI;
1700 deleteSocket(); 1700 deleteSocket();
1701 return ; 1701 return ;
1702 } 1702 }
1703 if ( line.left( 8 ) == "ERROR_ED" ) { 1703 if ( line.left( 8 ) == "ERROR_ED" ) {
1704 mRetVal = errorED; 1704 mRetVal = errorED;
1705 deleteSocket(); 1705 deleteSocket();
1706 return ; 1706 return ;
1707 } 1707 }
1708 mRetVal = errorUN; 1708 mRetVal = errorUN;
1709 deleteSocket(); 1709 deleteSocket();
1710 return ; 1710 return ;
1711 } 1711 }
1712 } 1712 }
1713 mFileString += line; 1713 mFileString += line;
1714 //qDebug("readline: %s ", line.latin1()); 1714 //qDebug("readline: %s ", line.latin1());
1715 } 1715 }
1716 if ( mTime.elapsed () < 3000 ) { 1716 if ( mTime.elapsed () < 3000 ) {
1717 // wait for more 1717 // wait for more
1718 //qDebug("waitformore "); 1718 //qDebug("waitformore ");
1719 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1719 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1720 return; 1720 return;
1721 } 1721 }
1722 mTimerSocket->stop(); 1722 mTimerSocket->stop();
1723 mConnectCount = -1; 1723 mConnectCount = -1;
1724 mConnectProgress.hide(); 1724 mConnectProgress.hide();
1725 QString fileName = mFileName; 1725 QString fileName = mFileName;
1726 QFile file ( fileName ); 1726 QFile file ( fileName );
1727 if (!file.open( IO_WriteOnly ) ) { 1727 if (!file.open( IO_WriteOnly ) ) {
1728 mFileString = ""; 1728 mFileString = "";
1729 mRetVal = errorR; 1729 mRetVal = errorR;
1730 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1730 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1731 deleteSocket(); 1731 deleteSocket();
1732 return ; 1732 return ;
1733 1733
1734 } 1734 }
1735 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1735 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1736 QTextStream ts ( &file ); 1736 QTextStream ts ( &file );
1737 ts.setEncoding( QTextStream::Latin1 ); 1737 ts.setEncoding( QTextStream::Latin1 );
1738 ts << mFileString; 1738 ts << mFileString;
1739 file.close(); 1739 file.close();
1740 mFileString = ""; 1740 mFileString = "";
1741 mRetVal = successR; 1741 mRetVal = successR;
1742 mSocket->close(); 1742 mSocket->close();
1743 // if state is not idle, deleteSocket(); is called via 1743 // if state is not idle, deleteSocket(); is called via
1744 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1744 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1745 if ( mSocket->state() == QSocket::Idle ) 1745 if ( mSocket->state() == QSocket::Idle )
1746 deleteSocket(); 1746 deleteSocket();
1747} 1747}
1748 1748
1749void KCommandSocket::deleteSocket() 1749void KCommandSocket::deleteSocket()
1750{ 1750{
1751 //qDebug("KCommandSocket::deleteSocket() "); 1751 //qDebug("KCommandSocket::deleteSocket() ");
1752 mConnectProgress.hide(); 1752 mConnectProgress.hide();
1753 1753
1754 if ( mConnectCount >= 0 ) { 1754 if ( mConnectCount >= 0 ) {
1755 mTimerSocket->stop(); 1755 mTimerSocket->stop();
1756 mRetVal = errorTO; 1756 mRetVal = errorTO;
1757 qDebug("KCS::Connection to remote host timed out"); 1757 qDebug("KCS::Connection to remote host timed out");
1758 if ( mSocket ) { 1758 if ( mSocket ) {
1759 mSocket->close(); 1759 mSocket->close();
1760 //if ( mSocket->state() == QSocket::Idle ) 1760 //if ( mSocket->state() == QSocket::Idle )
1761 // deleteSocket(); 1761 // deleteSocket();
1762 delete mSocket; 1762 delete mSocket;
1763 mSocket = 0; 1763 mSocket = 0;
1764 } 1764 }
1765 if ( mConnectCount == 0 ) 1765 if ( mConnectCount == 0 )
1766 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1766 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1767 else if ( tlw ) 1767 else if ( tlw )
1768 tlw->setCaption( i18n("Connection to remote host cancelled!") ); 1768 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1769 emit commandFinished( this, mRetVal ); 1769 emit commandFinished( this, mRetVal );
1770 return; 1770 return;
1771 } 1771 }
1772 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1772 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1773 if ( mSocket) 1773 if ( mSocket)
1774 delete mSocket; 1774 delete mSocket;
1775 mSocket = 0; 1775 mSocket = 0;
1776 qDebug("commandFinished "); 1776 //qDebug("commandFinished ");
1777 emit commandFinished( this, mRetVal ); 1777 emit commandFinished( this, mRetVal );
1778} 1778}