-rw-r--r-- | korganizer/mainwindow.cpp | 105 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 10 |
2 files changed, 44 insertions, 71 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index b7176a1..5aa75f5 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -1262,48 +1262,56 @@ void MainWindow::aboutAutoSaving() } void MainWindow::aboutKnownBugs() { QMessageBox* msg; msg = new QMessageBox( i18n("Known Problems in KOrganizer/Pi"), i18n("1) Importing *.vcs or *.ics files from\nother applications may not work properly,\nif there are events with properties\nKO/Pi does not support.\n")+ i18n("2) Audio alarm daemon\nfor Zaurus is available!\nas an additional small application\n")+ i18n("\nPlease report unexpected behaviour to\nlutz@pi-sync.net\n") + i18n("\nor report them in the bugtracker on\n") + i18n("\nhttp://sourceforge.net/projects/kdepimpi\n"), QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); msg->exec(); delete msg; } QString MainWindow::defaultFileName() { return locateLocal( "data", "korganizer/mycalendar.ics" ); } +QString MainWindow::syncFileName() +{ +#ifdef _WIN32_ + return locateLocal( "tmp", "synccalendar.ics" ); +#else + return QString( "/tmp/kopitempfile.ics" ); +#endif +} void MainWindow::processIncidenceSelection( Incidence *incidence ) { if ( !incidence ) { enableIncidenceActions( false ); mNewSubTodoAction->setEnabled( false ); setCaptionToDates(); return; } //KGlobal::locale()->formatDateTime(nextA, true); QString startString = ""; if ( incidence->type() != "Todo" ) { if ( incidence->dtStart().date() < incidence->dtEnd().date() ) { if ( incidence->doesFloat() ) { startString += ": "+incidence->dtStartDateStr( true ); startString += " --- "+((Event*)incidence)->dtEndDateStr( true ); } else { startString = ": "+incidence->dtStartStr(true); startString += " --- "+((Event*)incidence)->dtEndStr(true); @@ -1903,172 +1911,138 @@ void MainWindow::enableQuick() QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); lay.addWidget( &label2); lay.addWidget( &lepw); dia.setFixedSize( 230,80 ); dia.setCaption( i18n("Enter port for Pi-Sync") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); int res = dia.exec(); if ( res ) retfile = lab.text(); else return; dia.hide(); passWordPiSync = lepw.text(); qApp->processEvents(); KOPrefs::instance()->mPassiveSyncPort = retfile; bool ok; Q_UINT16 port = retfile.toUInt(&ok); if ( ! ok ) { KMessageBox::information( this, i18n("No valid port")); return; } - qDebug("port %d ", port); + //qDebug("port %d ", port); mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); mServerSocket->setFileName( defaultFileName() ); - qDebug("connected "); + //qDebug("connected "); if ( !mServerSocket->ok() ) { qWarning("Failed to bind to port %d", port); delete mServerSocket; mServerSocket = 0; return; } connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); - // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); - //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); } void MainWindow::getFile( bool success ) { if ( ! success ) { setCaption( i18n("Error receiving file. Nothing changed!") ); return; } // pending adjust time for watchSavedFile() //mView->watchSavedFile(); mView->openCalendar( defaultFileName() ); setCaption( i18n("Pi-Sync successful!") ); } void MainWindow::syncPi() { qApp->processEvents(); performQuickQuick(); } void MainWindow::performQuickQuick() { - // setCaption( i18n("") ); - bool ok; Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); if ( ! ok ) { setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); return; } KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); - connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); setCaption( i18n("Sending request for remote file ...") ); - QString fileName; -#ifdef _WIN32_ - fileName = defaultFileName() +"sync"; -#else - fileName = "/tmp/kopitempfile.ics"; -#endif - commandSocket->readFile( fileName ); + commandSocket->readFile( syncFileName() ); } -void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success) +void MainWindow::deleteCommandSocket(KCommandSocket*s, int state) { - if ( ! success ) { + qDebug("MainWindow::deleteCommandSocket %d", state); + + //enum { success, errorW, errorR, quiet }; + if ( state == KCommandSocket::errorR ) { setCaption( i18n("ERROR:Receiving remote file failed.") ); delete s; - // pending : send stop + KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); + commandSocket->sendStop(); return; - } - QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); - qDebug("MainWindow::deleteCommandSocket "); - delete s; -} -void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success ) -{ - if ( ! success ) { + } else if ( state == KCommandSocket::errorW ) { setCaption( i18n("ERROR:Writing back file failed.") ); - } else { - qDebug("Syncing succesful! "); + + } else if ( state == KCommandSocket::successR ) { + QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); + + } else if ( state == KCommandSocket::successW ) { setCaption( i18n("Pi-Sync succesful!") ); } - qDebug("MainWindow::deleteCommandSocketFinish "); + delete s; } + void MainWindow::readFileFromSocket() { - // mTimerCommandSocket->stop(); - setCaption( i18n("Receiving remote file ...") ); - qDebug("MainWindow::readFileFromSocket() "); - QString fileName; -#ifdef _WIN32_ - fileName = defaultFileName() +"sync"; -#else - fileName = "/tmp/kopitempfile.ics"; -#endif - - setCaption( i18n("Remote file saved to temp file.") ); - //mCommandSocket = 0; - mCurrentSyncProfile = 2 ; // last file - mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); - mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - KSyncProfile* temp = new KSyncProfile (); - temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); - temp->readConfig(&config); - KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); - KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); - KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); - KOPrefs::instance()->mWriteBackInFuture = 0; - if ( temp->getWriteBackFuture() ) - KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); - delete temp; + QString fileName = syncFileName(); setCaption( i18n("Remote file saved to temp file.") ); if ( ! syncWithFile( fileName , true ) ) { setCaption( i18n("Syncing failed.") ); qDebug("Syncing failed "); return; } - KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this ); - connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); if ( KOPrefs::instance()->mWriteBackFile ) commandSocket->writeFile( fileName ); - else + else { commandSocket->sendStop(); + setCaption( i18n("Pi-Sync succesful!") ); + } } void MainWindow::syncLocalFile() { QString fn =KOPrefs::instance()->mLastSyncedLocalFile; fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); if ( fn == "" ) return; //mView->setSyncDevice("local-file" ); if ( syncWithFile( fn, false ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); // e->setReadOnly( true ); } } bool MainWindow::syncWithFile( QString fn , bool quick ) { bool ret = false; QFileInfo info; @@ -2482,159 +2456,158 @@ void KServerSocket::readBackFileFromSocket() // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); ts << piFileString; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); file.close(); delete mSyncActionDialog; mSyncActionDialog = 0; piFileString = ""; emit file_received( true ); } KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) { mPassWord = password; mSocket = 0; mPort = port; mHost = host; - mRetVal = false; + mRetVal = quiet; mTimerSocket = new QTimer ( this ); connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); } void KCommandSocket::readFile( QString fn ) { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); } mFileString = ""; mFileName = fn; mFirst = true; mSocket->connectToHost( mHost, mPort ); QTextStream os( mSocket ); os.setEncoding( QTextStream::UnicodeUTF8 ); os << "GET " << mPassWord << "\r\n"; mTimerSocket->start( 10000 ); } void KCommandSocket::writeFile( QString fileName ) { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); } mFileName = fileName ; mSocket->connectToHost( mHost, mPort ); } void KCommandSocket::writeFileToSocket() { QFile file2( mFileName ); if (!file2.open( IO_ReadOnly ) ) { - mRetVal= false; + mRetVal= errorW; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); return ; } QTextStream ts2( &file2 ); ts2.setCodec( QTextCodec::codecForName("utf8") ); QTextStream os2( mSocket ); os2.setCodec( QTextCodec::codecForName("utf8") ); os2 << "PUT " << mPassWord << "\r\n";; while ( ! ts2.atEnd() ) { os2 << ts2.readLine() << "\n"; } - mRetVal= true; + mRetVal= successW; file2.close(); mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KCommandSocket::sendStop() { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); } mSocket->connectToHost( mHost, mPort ); QTextStream os2( mSocket ); os2.setCodec( QTextCodec::codecForName("utf8") ); os2 << "STOP\r\n"; - mRetVal= true; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KCommandSocket::startReadFileFromSocket() { if ( ! mFirst ) return; mFirst = false; mTimerSocket->stop(); mFileString = ""; mTime.start(); QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); } void KCommandSocket::readFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); while ( mSocket->canReadLine () ) { mTime.restart(); QString line = mSocket->readLine (); mFileString += line; //qDebug("readline: %s ", line.latin1()); } if ( mTime.elapsed () < 3000 ) { // wait for more //qDebug("waitformore "); QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); return; } QString fileName = mFileName; QFile file ( fileName ); if (!file.open( IO_WriteOnly ) ) { mFileString = ""; - mRetVal = false; + mRetVal = errorR; qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); deleteSocket(); return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); ts << mFileString; file.close(); mFileString = ""; - mRetVal = true; + mRetVal = successR; mSocket->close(); // if state is not idle, deleteSocket(); is called via // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); if ( mSocket->state() == QSocket::Idle ) deleteSocket(); } void KCommandSocket::deleteSocket() { if ( mTimerSocket->isActive () ) { mTimerSocket->stop(); KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); - mRetVal = false; + mRetVal = errorR; } //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); if ( mSocket) delete mSocket; mSocket = 0; 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 @@ -40,93 +40,94 @@ signals: //void getFile(QSocket*); void file_received( bool ); //void file_sent(); void saveFile(); void endConnect(); private slots: void discardClient(); void readClient(); void readBackFileFromSocket(); private : void send_file(); void get_file(); void end_connect(); QDialog* mSyncActionDialog; QSocket* mSocket; QString mPassWord; QString mFileName; QTime piTime; QString piFileString; }; class KCommandSocket : public QObject { Q_OBJECT - public: + enum state { successR, errorR, successW, errorW, quiet }; KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); void readFile( QString ); void writeFile( QString ); void sendStop(); signals: - void commandFinished( KCommandSocket*, bool ); + void commandFinished( KCommandSocket*, int ); private slots: void startReadFileFromSocket(); void readFileFromSocket(); void deleteSocket(); void writeFileToSocket(); private : QSocket* mSocket; QString mPassWord; Q_UINT16 mPort; QString mHost; QString mFileName; QTimer* mTimerSocket; - bool mRetVal; + int mRetVal; QTime mTime; QString mFileString; bool mFirst; }; namespace KCal { class CalendarLocal; } using namespace KCal; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow( QWidget *parent = 0, const char *name = 0, QString command = ""); ~MainWindow(); public slots: virtual void showMaximized (); void configureAgenda( int ); void recieve( const QCString& msg, const QByteArray& data ); static QString defaultFileName(); + static QString syncFileName(); static QString resourcePath(); protected slots: void setCaptionToDates(); int ringSync(); void multiSync( bool askforPrefs = false ); void about(); void licence(); void faq(); void usertrans(); void features(); void synchowto(); void whatsNew(); void keyBindings(); void aboutAutoSaving();; void aboutKnownBugs(); void processIncidenceSelection( Incidence * ); void importQtopia(); void importBday(); void importOL(); void importIcal(); void importFile( QString, bool ); void quickImportIcal(); @@ -143,50 +144,49 @@ class MainWindow : public QMainWindow void fillFilterMenu(); void selectFilter( int ); void slotSyncMenu( int ); void syncSSH(); void confSync(); void syncSharp(); void syncPhone(); void syncPi(); void syncLocalFile(); bool syncWithFile( QString, bool ); void quickSyncLocalFile(); protected: void displayText( QString, QString); void displayFile( QString, QString); void enableIncidenceActions( bool ); private slots: QSocket* piSocket; QString piFileString; QTime piTime; - void deleteCommandSocket(KCommandSocket* s, bool success); - void deleteCommandSocketFinish(KCommandSocket* s, bool success); + void deleteCommandSocket(KCommandSocket* s, int state ); void fillSyncMenu(); void getFile( bool ); void readFileFromSocket(); private: //QTimer* mTimerCommandSocket; QString mPassWordPiSync; KServerSocket * mServerSocket; bool mClosed; void saveOnClose(); int mCurrentSyncProfile; void enableQuick(); void performQuickQuick(); void syncRemote( KSyncProfile* , bool ask = true); bool mFlagKeyPressed; bool mBlockAtStartup; QPEToolBar *iconToolBar; void initActions(); void setDefaultPreferences(); void keyPressEvent ( QKeyEvent * ) ; void keyReleaseEvent ( QKeyEvent * ) ; QPopupMenu *configureToolBarMenu; QPopupMenu *selectFilterMenu; QPopupMenu *configureAgendaMenu, *syncMenu; CalendarLocal *mCalendar; |