summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp113
-rw-r--r--korganizer/mainwindow.h10
2 files changed, 48 insertions, 75 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index b7176a1..5aa75f5 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1280,12 +1280,20 @@ void MainWindow::aboutKnownBugs()
1280} 1280}
1281 1281
1282QString MainWindow::defaultFileName() 1282QString MainWindow::defaultFileName()
1283{ 1283{
1284 return locateLocal( "data", "korganizer/mycalendar.ics" ); 1284 return locateLocal( "data", "korganizer/mycalendar.ics" );
1285} 1285}
1286QString MainWindow::syncFileName()
1287{
1288#ifdef _WIN32_
1289 return locateLocal( "tmp", "synccalendar.ics" );
1290#else
1291 return QString( "/tmp/kopitempfile.ics" );
1292#endif
1293}
1286 1294
1287void MainWindow::processIncidenceSelection( Incidence *incidence ) 1295void MainWindow::processIncidenceSelection( Incidence *incidence )
1288{ 1296{
1289 if ( !incidence ) { 1297 if ( !incidence ) {
1290 enableIncidenceActions( false ); 1298 enableIncidenceActions( false );
1291 1299
@@ -1921,26 +1929,24 @@ void MainWindow::enableQuick()
1921 bool ok; 1929 bool ok;
1922 Q_UINT16 port = retfile.toUInt(&ok); 1930 Q_UINT16 port = retfile.toUInt(&ok);
1923 if ( ! ok ) { 1931 if ( ! ok ) {
1924 KMessageBox::information( this, i18n("No valid port")); 1932 KMessageBox::information( this, i18n("No valid port"));
1925 return; 1933 return;
1926 } 1934 }
1927 qDebug("port %d ", port); 1935 //qDebug("port %d ", port);
1928 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); 1936 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
1929 mServerSocket->setFileName( defaultFileName() ); 1937 mServerSocket->setFileName( defaultFileName() );
1930 qDebug("connected "); 1938 //qDebug("connected ");
1931 if ( !mServerSocket->ok() ) { 1939 if ( !mServerSocket->ok() ) {
1932 qWarning("Failed to bind to port %d", port); 1940 qWarning("Failed to bind to port %d", port);
1933 delete mServerSocket; 1941 delete mServerSocket;
1934 mServerSocket = 0; 1942 mServerSocket = 0;
1935 return; 1943 return;
1936 } 1944 }
1937 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); 1945 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
1938 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); 1946 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
1939 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1940 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1941} 1947}
1942 1948
1943void MainWindow::getFile( bool success ) 1949void MainWindow::getFile( bool success )
1944{ 1950{
1945 if ( ! success ) { 1951 if ( ! success ) {
1946 setCaption( i18n("Error receiving file. Nothing changed!") ); 1952 setCaption( i18n("Error receiving file. Nothing changed!") );
@@ -1959,98 +1965,66 @@ void MainWindow::syncPi()
1959 qApp->processEvents(); 1965 qApp->processEvents();
1960 performQuickQuick(); 1966 performQuickQuick();
1961} 1967}
1962 1968
1963void MainWindow::performQuickQuick() 1969void MainWindow::performQuickQuick()
1964{ 1970{
1965 // setCaption( i18n("") );
1966
1967 bool ok; 1971 bool ok;
1968 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 1972 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
1969 if ( ! ok ) { 1973 if ( ! ok ) {
1970 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1974 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1971 return; 1975 return;
1972 } 1976 }
1973 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); 1977 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
1974 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) ); 1978 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1975 setCaption( i18n("Sending request for remote file ...") ); 1979 setCaption( i18n("Sending request for remote file ...") );
1976 QString fileName; 1980 commandSocket->readFile( syncFileName() );
1977#ifdef _WIN32_
1978 fileName = defaultFileName() +"sync";
1979#else
1980 fileName = "/tmp/kopitempfile.ics";
1981#endif
1982 commandSocket->readFile( fileName );
1983} 1981}
1984void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success) 1982void MainWindow::deleteCommandSocket(KCommandSocket*s, int state)
1985{ 1983{
1986 if ( ! success ) { 1984 qDebug("MainWindow::deleteCommandSocket %d", state);
1987 setCaption( i18n("ERROR:Receiving remote file failed.") ); 1985
1986 //enum { success, errorW, errorR, quiet };
1987 if ( state == KCommandSocket::errorR ) {
1988 setCaption( i18n("ERROR: Receiving remote file failed.") );
1988 delete s; 1989 delete s;
1989 // pending : send stop 1990 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
1991 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1992 commandSocket->sendStop();
1990 return; 1993 return;
1991 1994
1992 } 1995 } else if ( state == KCommandSocket::errorW ) {
1993 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1994 qDebug("MainWindow::deleteCommandSocket ");
1995 delete s;
1996}
1997void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success )
1998{
1999 if ( ! success ) {
2000 setCaption( i18n("ERROR:Writing back file failed.") ); 1996 setCaption( i18n("ERROR:Writing back file failed.") );
2001 } else { 1997
2002 qDebug("Syncing succesful! "); 1998 } else if ( state == KCommandSocket::successR ) {
1999 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2000
2001 } else if ( state == KCommandSocket::successW ) {
2003 setCaption( i18n("Pi-Sync succesful!") ); 2002 setCaption( i18n("Pi-Sync succesful!") );
2004 } 2003 }
2005 qDebug("MainWindow::deleteCommandSocketFinish "); 2004
2006 delete s; 2005 delete s;
2007} 2006}
2007
2008void MainWindow::readFileFromSocket() 2008void MainWindow::readFileFromSocket()
2009{ 2009{
2010 // mTimerCommandSocket->stop(); 2010 QString fileName = syncFileName();
2011 setCaption( i18n("Receiving remote file ...") );
2012 qDebug("MainWindow::readFileFromSocket() ");
2013 QString fileName;
2014#ifdef _WIN32_
2015 fileName = defaultFileName() +"sync";
2016#else
2017 fileName = "/tmp/kopitempfile.ics";
2018#endif
2019
2020 setCaption( i18n("Remote file saved to temp file.") );
2021 //mCommandSocket = 0;
2022 mCurrentSyncProfile = 2 ; // last file
2023 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2024 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2025 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2026 KSyncProfile* temp = new KSyncProfile ();
2027 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2028 temp->readConfig(&config);
2029 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2030 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2031 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2032 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2033 KOPrefs::instance()->mWriteBackInFuture = 0;
2034 if ( temp->getWriteBackFuture() )
2035 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2036 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2037 delete temp;
2038 setCaption( i18n("Remote file saved to temp file.") ); 2011 setCaption( i18n("Remote file saved to temp file.") );
2039 if ( ! syncWithFile( fileName , true ) ) { 2012 if ( ! syncWithFile( fileName , true ) ) {
2040 setCaption( i18n("Syncing failed.") ); 2013 setCaption( i18n("Syncing failed.") );
2041 qDebug("Syncing failed "); 2014 qDebug("Syncing failed ");
2042 return; 2015 return;
2043 } 2016 }
2044
2045 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this ); 2017 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
2046 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) ); 2018 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
2047 if ( KOPrefs::instance()->mWriteBackFile ) 2019 if ( KOPrefs::instance()->mWriteBackFile )
2048 commandSocket->writeFile( fileName ); 2020 commandSocket->writeFile( fileName );
2049 else 2021 else {
2050 commandSocket->sendStop(); 2022 commandSocket->sendStop();
2023 setCaption( i18n("Pi-Sync succesful!") );
2024 }
2051} 2025}
2052 2026
2053void MainWindow::syncLocalFile() 2027void MainWindow::syncLocalFile()
2054{ 2028{
2055 2029
2056 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2030 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
@@ -2500,13 +2474,13 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host,
2500{ 2474{
2501 mPassWord = password; 2475 mPassWord = password;
2502 mSocket = 0; 2476 mSocket = 0;
2503 mPort = port; 2477 mPort = port;
2504 mHost = host; 2478 mHost = host;
2505 2479
2506 mRetVal = false; 2480 mRetVal = quiet;
2507 mTimerSocket = new QTimer ( this ); 2481 mTimerSocket = new QTimer ( this );
2508 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 2482 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
2509} 2483}
2510void KCommandSocket::readFile( QString fn ) 2484void KCommandSocket::readFile( QString fn )
2511{ 2485{
2512 if ( !mSocket ) { 2486 if ( !mSocket ) {
@@ -2535,13 +2509,13 @@ void KCommandSocket::writeFile( QString fileName )
2535 mSocket->connectToHost( mHost, mPort ); 2509 mSocket->connectToHost( mHost, mPort );
2536} 2510}
2537void KCommandSocket::writeFileToSocket() 2511void KCommandSocket::writeFileToSocket()
2538{ 2512{
2539 QFile file2( mFileName ); 2513 QFile file2( mFileName );
2540 if (!file2.open( IO_ReadOnly ) ) { 2514 if (!file2.open( IO_ReadOnly ) ) {
2541 mRetVal= false; 2515 mRetVal= errorW;
2542 mSocket->close(); 2516 mSocket->close();
2543 if ( mSocket->state() == QSocket::Idle ) 2517 if ( mSocket->state() == QSocket::Idle )
2544 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 2518 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2545 return ; 2519 return ;
2546 } 2520 }
2547 QTextStream ts2( &file2 ); 2521 QTextStream ts2( &file2 );
@@ -2549,13 +2523,13 @@ void KCommandSocket::writeFileToSocket()
2549 QTextStream os2( mSocket ); 2523 QTextStream os2( mSocket );
2550 os2.setCodec( QTextCodec::codecForName("utf8") ); 2524 os2.setCodec( QTextCodec::codecForName("utf8") );
2551 os2 << "PUT " << mPassWord << "\r\n";; 2525 os2 << "PUT " << mPassWord << "\r\n";;
2552 while ( ! ts2.atEnd() ) { 2526 while ( ! ts2.atEnd() ) {
2553 os2 << ts2.readLine() << "\n"; 2527 os2 << ts2.readLine() << "\n";
2554 } 2528 }
2555 mRetVal= true; 2529 mRetVal= successW;
2556 file2.close(); 2530 file2.close();
2557 mSocket->close(); 2531 mSocket->close();
2558 if ( mSocket->state() == QSocket::Idle ) 2532 if ( mSocket->state() == QSocket::Idle )
2559 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 2533 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2560} 2534}
2561void KCommandSocket::sendStop() 2535void KCommandSocket::sendStop()
@@ -2565,13 +2539,12 @@ void KCommandSocket::sendStop()
2565 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2539 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2566 } 2540 }
2567 mSocket->connectToHost( mHost, mPort ); 2541 mSocket->connectToHost( mHost, mPort );
2568 QTextStream os2( mSocket ); 2542 QTextStream os2( mSocket );
2569 os2.setCodec( QTextCodec::codecForName("utf8") ); 2543 os2.setCodec( QTextCodec::codecForName("utf8") );
2570 os2 << "STOP\r\n"; 2544 os2 << "STOP\r\n";
2571 mRetVal= true;
2572 mSocket->close(); 2545 mSocket->close();
2573 if ( mSocket->state() == QSocket::Idle ) 2546 if ( mSocket->state() == QSocket::Idle )
2574 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 2547 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2575} 2548}
2576 2549
2577void KCommandSocket::startReadFileFromSocket() 2550void KCommandSocket::startReadFileFromSocket()
@@ -2601,38 +2574,38 @@ void KCommandSocket::readFileFromSocket()
2601 return; 2574 return;
2602 } 2575 }
2603 QString fileName = mFileName; 2576 QString fileName = mFileName;
2604 QFile file ( fileName ); 2577 QFile file ( fileName );
2605 if (!file.open( IO_WriteOnly ) ) { 2578 if (!file.open( IO_WriteOnly ) ) {
2606 mFileString = ""; 2579 mFileString = "";
2607 mRetVal = false; 2580 mRetVal = errorR;
2608 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 2581 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2609 deleteSocket(); 2582 deleteSocket();
2610 return ; 2583 return ;
2611 2584
2612 } 2585 }
2613 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 2586 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2614 QTextStream ts ( &file ); 2587 QTextStream ts ( &file );
2615 ts.setCodec( QTextCodec::codecForName("utf8") ); 2588 ts.setCodec( QTextCodec::codecForName("utf8") );
2616 ts << mFileString; 2589 ts << mFileString;
2617 file.close(); 2590 file.close();
2618 mFileString = ""; 2591 mFileString = "";
2619 mRetVal = true; 2592 mRetVal = successR;
2620 mSocket->close(); 2593 mSocket->close();
2621 // if state is not idle, deleteSocket(); is called via 2594 // if state is not idle, deleteSocket(); is called via
2622 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2595 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2623 if ( mSocket->state() == QSocket::Idle ) 2596 if ( mSocket->state() == QSocket::Idle )
2624 deleteSocket(); 2597 deleteSocket();
2625} 2598}
2626 2599
2627void KCommandSocket::deleteSocket() 2600void KCommandSocket::deleteSocket()
2628{ 2601{
2629 if ( mTimerSocket->isActive () ) { 2602 if ( mTimerSocket->isActive () ) {
2630 mTimerSocket->stop(); 2603 mTimerSocket->stop();
2631 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 2604 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
2632 mRetVal = false; 2605 mRetVal = errorR;
2633 } 2606 }
2634 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 2607 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
2635 if ( mSocket) 2608 if ( mSocket)
2636 delete mSocket; 2609 delete mSocket;
2637 mSocket = 0; 2610 mSocket = 0;
2638 emit commandFinished( this, mRetVal ); 2611 emit commandFinished( this, mRetVal );
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 90b3a88..4da371e 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -58,35 +58,35 @@ private slots:
58 QString piFileString; 58 QString piFileString;
59}; 59};
60 60
61class KCommandSocket : public QObject 61class KCommandSocket : public QObject
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64
65public: 64public:
65 enum state { successR, errorR, successW, errorW, quiet };
66 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 66 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
67 void readFile( QString ); 67 void readFile( QString );
68 void writeFile( QString ); 68 void writeFile( QString );
69 void sendStop(); 69 void sendStop();
70 70
71 71
72signals: 72signals:
73 void commandFinished( KCommandSocket*, bool ); 73 void commandFinished( KCommandSocket*, int );
74private slots: 74private slots:
75 void startReadFileFromSocket(); 75 void startReadFileFromSocket();
76 void readFileFromSocket(); 76 void readFileFromSocket();
77 void deleteSocket(); 77 void deleteSocket();
78 void writeFileToSocket(); 78 void writeFileToSocket();
79 private : 79 private :
80 QSocket* mSocket; 80 QSocket* mSocket;
81 QString mPassWord; 81 QString mPassWord;
82 Q_UINT16 mPort; 82 Q_UINT16 mPort;
83 QString mHost; 83 QString mHost;
84 QString mFileName; 84 QString mFileName;
85 QTimer* mTimerSocket; 85 QTimer* mTimerSocket;
86 bool mRetVal; 86 int mRetVal;
87 QTime mTime; 87 QTime mTime;
88 QString mFileString; 88 QString mFileString;
89 bool mFirst; 89 bool mFirst;
90}; 90};
91 91
92namespace KCal { 92namespace KCal {
@@ -103,12 +103,13 @@ class MainWindow : public QMainWindow
103 ~MainWindow(); 103 ~MainWindow();
104 public slots: 104 public slots:
105 virtual void showMaximized (); 105 virtual void showMaximized ();
106 void configureAgenda( int ); 106 void configureAgenda( int );
107 void recieve( const QCString& msg, const QByteArray& data ); 107 void recieve( const QCString& msg, const QByteArray& data );
108 static QString defaultFileName(); 108 static QString defaultFileName();
109 static QString syncFileName();
109 static QString resourcePath(); 110 static QString resourcePath();
110 protected slots: 111 protected slots:
111 void setCaptionToDates(); 112 void setCaptionToDates();
112 int ringSync(); 113 int ringSync();
113 void multiSync( bool askforPrefs = false ); 114 void multiSync( bool askforPrefs = false );
114 void about(); 115 void about();
@@ -161,14 +162,13 @@ class MainWindow : public QMainWindow
161 void enableIncidenceActions( bool ); 162 void enableIncidenceActions( bool );
162 163
163 private slots: 164 private slots:
164 QSocket* piSocket; 165 QSocket* piSocket;
165 QString piFileString; 166 QString piFileString;
166 QTime piTime; 167 QTime piTime;
167 void deleteCommandSocket(KCommandSocket* s, bool success); 168 void deleteCommandSocket(KCommandSocket* s, int state );
168 void deleteCommandSocketFinish(KCommandSocket* s, bool success);
169 void fillSyncMenu(); 169 void fillSyncMenu();
170 void getFile( bool ); 170 void getFile( bool );
171 void readFileFromSocket(); 171 void readFileFromSocket();
172 private: 172 private:
173 //QTimer* mTimerCommandSocket; 173 //QTimer* mTimerCommandSocket;
174 QString mPassWordPiSync; 174 QString mPassWordPiSync;