author | zautrix <zautrix> | 2004-10-07 17:51:17 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 17:51:17 (UTC) |
commit | 1f1538e5707b59bfcff2014901f29a65589229e3 (patch) (side-by-side diff) | |
tree | 0d91a303524e6ac9f7c954f01a0e1d09d0e305e7 /korganizer/mainwindow.cpp | |
parent | bb8293c794d82a57bc93af85ccd89b601356d577 (diff) | |
download | kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.zip kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.tar.gz kdepimpi-1f1538e5707b59bfcff2014901f29a65589229e3.tar.bz2 |
many cleanups
-rw-r--r-- | korganizer/mainwindow.cpp | 556 |
1 files changed, 23 insertions, 533 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index e3324ee..f7766f8 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -117,80 +117,78 @@ class KOex2phonePrefs : public QDialog } public: QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; QCheckBox* mWriteBackFuture; QSpinBox* mWriteBackFutureWeeks; }; int globalFlagBlockStartup; MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : QMainWindow( parent, name ) { - mPassWordPiSync = "abc"; + #ifdef DESKTOP_VERSION setFont( QFont("Arial"), 14 ); #endif mServerSocket = 0; mClosed = false; //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; QString confFile = locateLocal("config","korganizerrc"); QFileInfo finf ( confFile ); bool showWarning = !finf.exists(); setIcon(SmallIcon( "ko24" ) ); mBlockAtStartup = true; mFlagKeyPressed = false; setCaption("KOrganizer/Pi"); KOPrefs *p = KOPrefs::instance(); KPimGlobalPrefs::instance()->setGlobalConfig(); - // if ( QApplication::desktop()->height() > 480 ) { -// if ( p->mHourSize == 4 ) -// p->mHourSize = 6; -// } if ( p->mHourSize > 18 ) p->mHourSize = 18; QMainWindow::ToolBarDock tbd; if ( p->mToolBarHor ) { if ( p->mToolBarUp ) tbd = Bottom; else tbd = Top; } else { if ( p->mToolBarUp ) tbd = Right; else tbd = Left; } if ( KOPrefs::instance()->mUseAppColors ) QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); globalFlagBlockStartup = 1; iconToolBar = new QPEToolBar( this ); addToolBar (iconToolBar , tbd ); - mBlockSaveFlag = false; mCalendarModifiedFlag = false; QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); splash->setAlignment ( AlignCenter ); setCentralWidget( splash ); #ifndef DESKTOP_VERSION showMaximized(); #endif //qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ()); setDefaultPreferences(); mCalendar = new CalendarLocal(); mView = new CalendarView( mCalendar, this,"mCalendar " ); mView->hide(); //mView->resize(splash->size() ); - initActions(); + initActions(); + mSyncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)mView, KSyncManager::KOPI, KOPrefs::instance(), syncMenu); + mSyncManager->setBlockSave(false); + mView->setSyncManager(mSyncManager); #ifndef DESKTOP_VERSION iconToolBar->show(); qApp->processEvents(); #endif //qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ()); int vh = height() ; int vw = width(); //qDebug("Toolbar hei %d ",iconToolBar->height() ); if ( iconToolBar->orientation () == Qt:: Horizontal ) { vh -= iconToolBar->height(); } else { vw -= iconToolBar->height(); @@ -243,25 +241,35 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) ); mView->setModified( false ); mBlockAtStartup = false; mView->setModified( false ); setCentralWidget( mView ); globalFlagBlockStartup = 0; mView->show(); delete splash; if ( newFile ) mView->updateConfig(); // qApp->processEvents(); //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); - fillSyncMenu(); + //fillSyncMenu(); + + + connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) ); + connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); + connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); + mSyncManager->setDefaultFileName( defaultFileName()); + mSyncManager->fillSyncMenu(); + + + mView->viewManager()->agendaView()->setStartHour( KOPrefs::instance()->mDayBegins ); if ( showWarning ) { KMessageBox::information( this, "You are starting KO/Pi for the first time.\nPlease read menu: Help-What's New,\nif you did an update!\nPlease choose your timezone in the \nConfigure Dialog TAB Time Zone!\nPlease choose your language\nin the TAB Locale!\nYou get the Configure Dialog\nvia Menu: Actions - Configure....\nClick OK to show the Configure Dialog!\n", "KO/Pi information"); qApp->processEvents(); mView->dialogManager()->showSyncOptions(); } //US listen for result adressed from Ka/Pi #ifndef DESKTOP_VERSION connect(qApp, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & ))); #endif @@ -386,25 +394,25 @@ void MainWindow::recieve( const QCString& cmsg, const QByteArray& data ) mView->viewManager()->showTodoView(); } if ( msg == "-showList" ) { mView->viewManager()->showListView(); } else if ( msg == "-showDay" ) { mView->viewManager()->showDayView(); } else if ( msg == "-showWWeek" ) { mView->viewManager()->showWorkWeekView(); } else if ( msg == "-ringSync" ) { - multiSync( false ); + mSyncManager->multiSync( false ); } else if ( msg == "-showWeek" ) { mView->viewManager()->showWeekView(); } else if ( msg == "-showTodo" ) { mView->viewManager()->showTodoView(); } else if ( msg == "-showJournal" ) { mView->dateNavigator()->selectDates( 1 ); mView->dateNavigator()->selectToday(); mView->viewManager()->showJournalView(); } @@ -931,252 +939,25 @@ void MainWindow::initActions() QLabel* dummy = new QLabel( iconToolBar ); dummy->setBackgroundColor( iconToolBar->backgroundColor() ); if (!p-> mShowIconStretch) iconToolBar->setStretchableWidget ( dummy ) ; else configureToolBarMenu->setItemChecked( 5, true ); if (p-> mShowIconWhatsThis) QWhatsThis::whatsThisButton ( iconToolBar ); connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) ); configureAgenda( p->mHourSize ); connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) ); } -void MainWindow::fillSyncMenu() -{ - if ( syncMenu->count() ) - syncMenu->clear(); - syncMenu->insertItem( i18n("Configure..."), 0 ); - syncMenu->insertSeparator(); - if ( mServerSocket == 0 ) { - syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); - } else { - syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); - } - syncMenu->insertSeparator(); - syncMenu->insertItem( i18n("Multiple sync"), 1 ); - syncMenu->insertSeparator(); - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - config.setGroup("General"); - QStringList prof = config.readListEntry("SyncProfileNames"); - KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); - if ( prof.count() < 3 ) { - prof.clear(); - prof << i18n("Sharp_DTM"); - prof << i18n("Local_file"); - prof << i18n("Last_file"); - KSyncProfile* temp = new KSyncProfile (); - temp->setName( prof[0] ); - temp->writeConfig(&config); - temp->setName( prof[1] ); - temp->writeConfig(&config); - temp->setName( prof[2] ); - temp->writeConfig(&config); - config.setGroup("General"); - config.writeEntry("SyncProfileNames",prof); - config.writeEntry("ExternSyncProfiles","Sharp_DTM"); - config.sync(); - delete temp; - } - KOPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); - KOPrefs::instance()->mSyncProfileNames = prof; - int i; - for ( i = 0; i < prof.count(); ++i ) { - - syncMenu->insertItem( prof[i], 1000+i ); - if ( i == 2 ) - syncMenu->insertSeparator(); - } - QDir app_dir; - if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { - syncMenu->setItemEnabled( false , 1000 ); - } -} - -int MainWindow::ringSync() -{ - int syncedProfiles = 0; - int i; - QTime timer; - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - QStringList syncProfileNames = KOPrefs::instance()->mSyncProfileNames; - KSyncProfile* temp = new KSyncProfile (); - KOPrefs::instance()->mAskForPreferences = false; - for ( i = 0; i < syncProfileNames.count(); ++i ) { - mCurrentSyncProfile = i; - temp->setName(syncProfileNames[mCurrentSyncProfile]); - temp->readConfig(&config); - if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { - setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); - ++syncedProfiles; - // KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - 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 = false; - mView->setSyncDevice(syncProfileNames[i] ); - mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); - if ( i == 0 ) { - syncSharp(); - } else { - if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), true ) ) - KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); - } else { - if ( temp->getIsPhoneSync() ) { - KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); - syncPhone(); - } else if ( temp->getIsPiSync() ) { - mPassWordPiSync = temp->getRemotePw(); - KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); - KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); - syncPi(); - } else - syncRemote( temp, false ); - - } - } - timer.start(); - setCaption(i18n("Multiple sync in progress ... please wait!") ); - while ( timer.elapsed () < 2000 ) { - qApp->processEvents(); -#ifndef _WIN32_ - sleep (1); -#endif - } - - } - - } - delete temp; - return syncedProfiles; -} - -void MainWindow::multiSync( bool askforPrefs ) -{ - if (mBlockSaveFlag) - return; - mBlockSaveFlag = true; - QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), - question, - i18n("Yes"), i18n("No"), - 0, 0 ) != 0 ) { - mBlockSaveFlag = false; - setCaption(i18n("Aborted! Nothing synced!")); - return; - } - mView->setSyncDevice(i18n("Multiple profiles") ); - KOPrefs::instance()->mSyncAlgoPrefs = KOPrefs::instance()->mRingSyncAlgoPrefs; - if ( askforPrefs ) { - mView->edit_sync_options(); - KOPrefs::instance()->mRingSyncAlgoPrefs = KOPrefs::instance()->mSyncAlgoPrefs; - } - setCaption(i18n("Multiple sync started.") ); - qApp->processEvents(); - int num = ringSync() ; - if ( num > 1 ) - ringSync(); - mBlockSaveFlag = false; - if ( num ) - save(); - if ( num ) - setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); - else - setCaption(i18n("Nothing synced! No profiles defined for multisync!")); - return; -} -void MainWindow::slotSyncMenu( int action ) -{ - qDebug("syncaction %d ", action); - if ( action == 0 ) { - - // seems to be a Qt2 event handling bug - // syncmenu.clear causes a segfault at first time - // when we call it after the main event loop, it is ok - // same behaviour when calling OM/Pi via QCOP for the first time - QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); - //confSync(); - return; - } - if ( action == 1 ) { - multiSync( true ); - return; - } - if ( action == 2 ) { - enableQuick(); - QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); - return; - } - if ( action == 3 ) { - delete mServerSocket; - mServerSocket = 0; - QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); - return; - } - - if (mBlockSaveFlag) - return; - mBlockSaveFlag = true; - mCurrentSyncProfile = action - 1000 ; - 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(); - if ( action == 1000 ) { - syncSharp(); - - } else if ( action == 1001 ) { - syncLocalFile(); - - } else if ( action == 1002 ) { - quickSyncLocalFile(); - - } else if ( action >= 1003 ) { - if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); - } else { - if ( temp->getIsPhoneSync() ) { - KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); - syncPhone(); - } else if ( temp->getIsPiSync() ) { - mPassWordPiSync = temp->getRemotePw(); - KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); - KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); - syncPi(); - } else - syncRemote( temp ); - - } - } - delete temp; - mBlockSaveFlag = false; -} void MainWindow::exportToPhone( int mode ) { //ex2phone->insertItem(i18n("Complete calendar..."), 1 ); //ex2phone->insertItem(i18n("Filtered calendar..."), 2 ); KOex2phonePrefs ex2phone; ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); if ( mode == 1 ) ex2phone.setCaption(i18n("Export complete calendar")); @@ -1575,56 +1356,55 @@ void MainWindow::saveOnClose() iconToolBar->y() > height()/2; mView->writeSettings(); if ( mCalendarModifiedFlag || mView->checkFileChanged( defaultFileName())) save(); } void MainWindow::slotModifiedChanged( bool changed ) { if ( mBlockAtStartup ) return; int msec; // we store the changes after 1 minute, // and for safety reasons after 10 minutes again - if ( !mBlockSaveFlag ) + if ( !mSyncManager->blockSave() ) msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; else msec = 1000 * 600; mSaveTimer.start( msec, true ); // 1 minute qDebug("KO: Saving File in %d secs!", msec/1000); mCalendarModifiedFlag = true; } void MainWindow::save() { - if ( mBlockSaveFlag ) + if ( mSyncManager->blockSave() ) return; - bool store = mBlockSaveFlag; - mBlockSaveFlag = true; + mSyncManager->setBlockSave(true); if ( mView->checkFileVersion( defaultFileName()) ) { QTime neededSaveTime = QDateTime::currentDateTime().time(); setCaption(i18n("KO/Pi:Saving Data to File ..." )); qDebug("KO: Start saving data to file!"); mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); mView->saveCalendar( defaultFileName() ); int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); mView->watchSavedFile(); qDebug("KO: Needed %d ms for saving.",msNeeded ); QString savemes; savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); setCaption(savemes); } else setCaption(i18n("Saving cancelled!")); mCalendarModifiedFlag = false; - mBlockSaveFlag = store; + mSyncManager->setBlockSave( false ); } void MainWindow::keyReleaseEvent ( QKeyEvent * e) { if ( !e->isAutoRepeat() ) { mFlagKeyPressed = false; } } void MainWindow::keyPressEvent ( QKeyEvent * e ) { qApp->processEvents(); if ( e->isAutoRepeat() && !mFlagKeyPressed ) { @@ -2020,329 +1800,39 @@ void MainWindow::exportVCalendar() if ( createbup ) { if ( mView->exportVCalendar( fn ) ) { KOPrefs::instance()->mLastVcalFile = fn; if ( fn.length() > 20 ) mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; else mes = i18n("KO/Pi:Exported to %1").arg(fn ); setCaption(mes); } } } -QString MainWindow::getPassword( ) -{ - QString retfile = ""; - QDialog dia ( this, "input-dialog", true ); - QLineEdit lab ( &dia ); - lab.setEchoMode( QLineEdit::Password ); - QVBoxLayout lay( &dia ); - lay.setMargin(7); - lay.setSpacing(7); - lay.addWidget( &lab); - dia.setFixedSize( 230,50 ); - dia.setCaption( i18n("Enter password") ); - 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(); - dia.hide(); - qApp->processEvents(); - return retfile; - -} -void MainWindow::enableQuick() +void MainWindow::syncFileRequest() { - QDialog dia ( this, "input-dialog", true ); - QLineEdit lab ( &dia ); - QVBoxLayout lay( &dia ); - lab.setText( KOPrefs::instance()->mPassiveSyncPort ); - lay.setMargin(7); - lay.setSpacing(7); - QLabel label ( i18n("Port number (Default: 9197)"), &dia ); - lay.addWidget( &label); - lay.addWidget( &lab); - - QLineEdit lepw ( &dia ); - lepw.setText( KOPrefs::instance()->mPassiveSyncPw ); - 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(); - if ( ! dia.exec() ) - return; - dia.hide(); - qApp->processEvents(); - KOPrefs::instance()->mPassiveSyncPw = lepw.text(); - KOPrefs::instance()->mPassiveSyncPort = lab.text(); - bool ok; - Q_UINT16 port = KOPrefs::instance()->mPassiveSyncPort.toUInt(&ok); - if ( ! ok ) { - KMessageBox::information( this, i18n("No valid port")); - return; - } - //qDebug("port %d ", port); - mServerSocket = new KServerSocket ( KOPrefs::instance()->mPassiveSyncPw, port ,1 ); - mServerSocket->setFileName( defaultFileName() ); - //qDebug("connected "); - if ( !mServerSocket->ok() ) { - KMessageBox::information( this, i18n("Failed to bind or\nlisten to the port!")); - delete mServerSocket; - mServerSocket = 0; - return; - } - connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); - connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); + save(); } - void MainWindow::getFile( bool success ) { if ( ! success ) { setCaption( i18n("Error receiving file. Nothing changed!") ); return; } mView->watchSavedFile(); mView->openCalendar( defaultFileName() ); setCaption( i18n("Pi-Sync successful!") ); } - -void MainWindow::syncPi() -{ - qApp->processEvents(); - 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*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); - setCaption( i18n("Sending request for remote file ...") ); - commandSocket->readFile( syncFileName() ); -} - -void MainWindow::deleteCommandSocket(KCommandSocket*s, int state) -{ - qDebug("MainWindow::deleteCommandSocket %d", state); - - //enum { success, errorW, errorR, quiet }; - if ( state == KCommandSocket::errorR ) { - setCaption( i18n("ERROR: Receiving remote file failed.") ); - delete s; - 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; - - } else if ( state == KCommandSocket::errorW ) { - setCaption( i18n("ERROR:Writing back file failed.") ); - - } else if ( state == KCommandSocket::successR ) { - QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); - - } else if ( state == KCommandSocket::successW ) { - setCaption( i18n("Pi-Sync succesful!") ); - } - - delete s; -} - -void MainWindow::readFileFromSocket() -{ - 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*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); - if ( KOPrefs::instance()->mWriteBackFile ) - commandSocket->writeFile( fileName ); - 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; - info.setFile( fn ); - QString mess; - bool loadbup = true; - if ( !info. exists() ) { - mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); - int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), - mess ); - return ret; - } - int result = 0; - if ( !quick ) { - mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); - result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), - mess, - i18n("Sync"), i18n("Cancel"), 0, - 0, 1 ); - if ( result ) - return false; - } - if ( KOPrefs::instance()->mAskForPreferences ) - mView->edit_sync_options(); - if ( result == 0 ) { - //qDebug("Now sycing ... "); - if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) - setCaption( i18n("Synchronization successful") ); - else - setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); - if ( ! quick ) - KOPrefs::instance()->mLastSyncedLocalFile = fn; - slotModifiedChanged( true ); - } - return ret; -} -void MainWindow::quickSyncLocalFile() -{ - //mView->setSyncDevice("local-file" ); - //qDebug("quickSyncLocalFile() "); - if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { - // Event* e = mView->getLastSyncEvent(); -// e->setReadOnly( false ); -// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); -// e->setReadOnly( true ); - - } -} - -void MainWindow::confSync() -{ - mView->confSync(); - fillSyncMenu(); -} -void MainWindow::syncRemote( KSyncProfile* prof, bool ask) -{ - QString question; - if ( ask ) { - question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), - question, - i18n("Yes"), i18n("No"), - 0, 0 ) != 0 ) - return; - } - QString command = prof->getPreSyncCommand(); - int fi; - if ( (fi = command.find("$PWD$")) > 0 ) { - QString pwd = getPassword(); - command = command.left( fi )+ pwd + command.mid( fi+5 ); - - } - int maxlen = 30; - if ( QApplication::desktop()->width() > 320 ) - maxlen += 25; - setCaption ( i18n( "Copy remote file to local machine..." ) ); - int fileSize = 0; - int result = system ( command ); - // 0 : okay - // 256: no such file or dir - // - qDebug("KO: Remote copy result(0 = okay): %d ",result ); - if ( result != 0 ) { - int len = maxlen; - while ( len < command.length() ) { - command.insert( len , "\n" ); - len += maxlen +2; - } - question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; - QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), - question, - i18n("Okay!")) ; - setCaption ("KO/Pi"); - return; - } - setCaption ( i18n( "Copying succeed." ) ); - //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); - if ( syncWithFile( prof->getLocalTempFile(), true ) ) { -// Event* e = mView->getLastSyncEvent(); -// e->setReadOnly( false ); -// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); -// e->setReadOnly( true ); - if ( KOPrefs::instance()->mWriteBackFile ) { - command = prof->getPostSyncCommand(); - int fi; - if ( (fi = command.find("$PWD$")) > 0 ) { - QString pwd = getPassword(); - command = command.left( fi )+ pwd + command.mid( fi+5 ); - - } - setCaption ( i18n( "Writing back file ..." ) ); - result = system ( command ); - qDebug("KO: Writing back file result: %d ", result); - if ( result != 0 ) { - setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); - return; - } else { - setCaption ( i18n( "Syncronization sucessfully completed" ) ); - } - } - } - return; -} - -void MainWindow::syncSharp() -{ - if ( mCalendarModifiedFlag ) - save(); - mView->syncSharp(); - slotModifiedChanged( true ); - -} -void MainWindow::syncPhone() -{ - if ( mCalendarModifiedFlag ) - save(); - mView->syncPhone(); - slotModifiedChanged( true ); - -} - void MainWindow::printSel( ) { mView->viewManager()->agendaView()->agenda()->printSelection(); } void MainWindow::printCal() { mView->print();//mCp->showDialog(); } |