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 @@ -33,462 +33,470 @@ #include <qtoolbar.h> #include <qapplication.h> //#include <resource.h> #endif #include <libkcal/calendarlocal.h> #include <libkcal/todo.h> #include <libkcal/phoneformat.h> #include <libkdepim/ksyncprofile.h> #include <libkdepim/phoneaccess.h> #include <libkcal/kincidenceformatter.h> #include <libkdepim/kpimglobalprefs.h> #include "calendarview.h" #include "koviewmanager.h" #include "datenavigator.h" #include "koagendaview.h" #include "koagenda.h" #include "kodialogmanager.h" #include "kdialogbase.h" #include "kapplication.h" #include "kofilterview.h" #include "kstandarddirs.h" #include "koprefs.h" #include "kfiledialog.h" #include "koglobals.h" #include "kglobal.h" #include "klocale.h" #include "kconfig.h" #include "simplealarmclient.h" #include "externalapphandler.h" using namespace KCal; #ifndef _WIN32_ #include <unistd.h> #else #include "koimportoldialog.h" #endif #include "mainwindow.h" class KOex2phonePrefs : public QDialog { public: KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) : QDialog( parent, name, true ) { setCaption( i18n("Export to phone options") ); QVBoxLayout* lay = new QVBoxLayout( this ); lay->setSpacing( 3 ); lay->setMargin( 3 ); QLabel *lab; lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); lab->setAlignment (AlignHCenter ); QHBox* temphb; temphb = new QHBox( this ); new QLabel( i18n("I/O device: "), temphb ); mPhoneDevice = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Connection: "), temphb ); mPhoneConnection = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Model(opt.): "), temphb ); mPhoneModel = new QLineEdit( temphb); lay->addWidget( temphb ); mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this ); mWriteBackFuture->setChecked( true ); lay->addWidget( mWriteBackFuture ); temphb = new QHBox( this ); new QLabel( i18n("Max. weeks in future: ") , temphb ); mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb); mWriteBackFutureWeeks->setValue( 8 ); lay->addWidget( temphb ); lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) ); lab->setAlignment (AlignHCenter ); QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); resize( 220, 240 ); } 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(); } //mView->setMaximumSize( splash->size() ); //mView->resize( splash->size() ); //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ()); mView->readSettings(); bool newFile = false; if( !QFile::exists( defaultFileName() ) ) { QFileInfo finfo ( defaultFileName() ); QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics"); qDebug("oldfile %s ", oldFile.latin1()); QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n"; finfo.setFile( oldFile ); if (finfo.exists() ) { KMessageBox::information( this, message); mView->openCalendar( oldFile ); qApp->processEvents(); } else { oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics"); finfo.setFile( oldFile ); if (finfo.exists() ) { KMessageBox::information( this, message); mView->openCalendar( oldFile ); qApp->processEvents(); } } mView->saveCalendar( defaultFileName() ); newFile = true; } QTime neededSaveTime = QDateTime::currentDateTime().time(); mView->openCalendar( defaultFileName() ); int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); qDebug("KO: Calendar loading time: %d ms",msNeeded ); if ( KOPrefs::instance()->mLanguageChanged ) { KOPrefs::instance()->setCategoryDefaults(); int count = mView->addCategories(); KOPrefs::instance()->mLanguageChanged = false; } processIncidenceSelection( 0 ); connect( mView, SIGNAL( incidenceSelected( Incidence * ) ), SLOT( processIncidenceSelection( Incidence * ) ) ); connect( mView, SIGNAL( modifiedChanged( bool ) ), SLOT( slotModifiedChanged( bool ) ) ); 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 } MainWindow::~MainWindow() { //qDebug("MainWindow::~MainWindow() "); //save toolbar location delete mServerSocket; delete mCalendar; delete KOPrefs::instance(); delete KIncidenceFormatter::instance(); } void MainWindow::showMaximized () { #ifndef DESKTOP_VERSION if ( ! globalFlagBlockStartup ) if ( mClosed ) mView->goToday(); #endif QWidget::showMaximized () ; mClosed = false; } void MainWindow::closeEvent( QCloseEvent* ce ) { if ( ! KOPrefs::instance()->mAskForQuit ) { saveOnClose(); mClosed = true; ce->accept(); return; } switch( QMessageBox::information( this, "KO/Pi", i18n("Do you really want\nto close KO/Pi?"), i18n("Close"), i18n("No"), 0, 0 ) ) { case 0: saveOnClose(); mClosed = true; ce->accept(); break; case 1: ce->ignore(); break; case 2: default: break; } } void MainWindow::recieve( const QCString& cmsg, const QByteArray& data ) { QDataStream stream( data, IO_ReadOnly ); // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" ); //QString datamess; //qDebug("message "); qDebug("KO: QCOP message received: %s ", cmsg.data() ); if ( cmsg == "-writeFile" ) { // I made from the "-writeFile" an "-writeAlarm" mView->viewManager()->showWhatsNextView(); mCalendar->checkAlarmForIncidence( 0, true); showMaximized(); raise(); return; } if ( cmsg == "-writeFile" ) { // I made from the "-writeFile" an "-writeAlarm" mView->viewManager()->showWhatsNextView(); mCalendar->checkAlarmForIncidence( 0, true); showMaximized(); raise(); return; } if ( cmsg == "-writeFileSilent" ) { // I made from the "-writeFile" an "-writeAlarm" // mView->viewManager()->showWhatsNextView(); mCalendar->checkAlarmForIncidence( 0, true); //showMaximized(); //raise(); hide(); return; } if ( cmsg == "-newCountdown" ) { qDebug("newCountdown "); } QString msg ; QString allmsg = cmsg; while ( allmsg.length() > 0 ) { int nextC = allmsg.find( "-", 1 ); if ( nextC == -1 ) { msg = allmsg; allmsg = ""; } else{ msg = allmsg.left( nextC ); allmsg = allmsg.mid( nextC, allmsg.length()-nextC ); } //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() ); if ( msg == "-newEvent" ) { mView->newEvent(); } if ( msg == "-newTodo" ) { mView->newTodo(); } if ( msg == "-showWN" ) { mView->viewManager()->showWhatsNextView(); } if ( msg == "-showTodo" ) { 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(); } else if ( msg == "-showKO" ) { mView->viewManager()->showNextXView(); } else if ( msg == "-showWNext" || msg == "nextView()" ) { mView->viewManager()->showWhatsNextView(); } else if ( msg == "-showNextXView" ) { mView->viewManager()->showNextXView(); } } showMaximized(); raise(); } QPixmap MainWindow::loadPixmap( QString name ) { return SmallIcon( name ); } void MainWindow::initActions() { //KOPrefs::instance()->mShowFullMenu iconToolBar->clear(); KOPrefs *p = KOPrefs::instance(); //QPEMenuBar *menuBar1;// = new QPEMenuBar( iconToolBar ); QPopupMenu *viewMenu = new QPopupMenu( this ); QPopupMenu *actionMenu = new QPopupMenu( this ); QPopupMenu *importMenu = new QPopupMenu( this ); selectFilterMenu = new QPopupMenu( this ); selectFilterMenu->setCheckable( true ); syncMenu = new QPopupMenu( this ); configureAgendaMenu = new QPopupMenu( this ); configureToolBarMenu = new QPopupMenu( this ); QPopupMenu *helpMenu = new QPopupMenu( this ); if ( KOPrefs::instance()->mShowFullMenu ) { QMenuBar *menuBar1; menuBar1 = menuBar(); menuBar1->insertItem( i18n("File"), importMenu ); menuBar1->insertItem( i18n("View"), viewMenu ); menuBar1->insertItem( i18n("Actions"), actionMenu ); menuBar1->insertItem( i18n("Synchronize"), syncMenu ); menuBar1->insertItem( i18n("AgendaSize"),configureAgendaMenu ); //menuBar1->insertItem( i18n("Toolbar"),configureToolBarMenu ); menuBar1->insertItem( i18n("Filter"),selectFilterMenu ); menuBar1->insertItem( i18n("Help"), helpMenu ); } else { QPEMenuBar *menuBar1; menuBar1 = new QPEMenuBar( iconToolBar ); QPopupMenu *menuBar = new QPopupMenu( this ); menuBar1->insertItem( i18n("ME"), menuBar); menuBar->insertItem( i18n("File"), importMenu ); menuBar->insertItem( i18n("View"), viewMenu ); menuBar->insertItem( i18n("Actions"), actionMenu ); menuBar->insertItem( i18n("Synchronize"), syncMenu ); menuBar->insertItem( i18n("AgendaSize"),configureAgendaMenu ); menuBar->insertItem( i18n("Toolbar"),configureToolBarMenu ); menuBar->insertItem( i18n("Filter"),selectFilterMenu ); menuBar->insertItem( i18n("Help"), helpMenu ); //menuBar1->setMaximumWidth( menuBar1->sizeHint().width() ); menuBar1->setMaximumSize( menuBar1->sizeHint( )); } connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); connect ( selectFilterMenu, SIGNAL( activated ( int ) ), this, SLOT (selectFilter( int ) ) ); connect ( selectFilterMenu, SIGNAL( aboutToShow () ), this, SLOT (fillFilterMenu() ) ); // ****************** QAction *action; QIconSet icon; // QPopupMenu *configureMenu= new QPopupMenu( menuBar ); configureToolBarMenu->setCheckable( true ); QString pathString = ""; if ( !p->mToolBarMiniIcons ) { if ( QApplication::desktop()->width() < 480 ) pathString += "icons16/"; } else pathString += "iconsmini/"; configureAgendaMenu->setCheckable( true ); configureAgendaMenu->insertItem(i18n("Toggle Allday"), 1 ); configureAgendaMenu->insertSeparator(); @@ -847,420 +855,193 @@ void MainWindow::initActions() day5_action->addTo( iconToolBar ); if (p-> mShowIconDay7) day7_action->addTo( iconToolBar ); if (p-> mShowIconMonth) month_action->addTo( iconToolBar ); if (p-> mShowIconTodoview) todoview_action->addTo( iconToolBar ); if (p-> mShowIconJournal) viewjournal_action->addTo( iconToolBar ); icon = loadPixmap( pathString + "2leftarrowB" ); configureToolBarMenu->insertItem(icon, i18n("Prev. month"), 200, 14); if (p-> mShowIconBackFast) { action = new QAction( i18n("Prev. month"), icon, i18n("Prev. month"),0 , this ); connect( action, SIGNAL( activated() ), mView, SLOT( goPreviousMonth() ) ); action->addTo( iconToolBar ); } icon = loadPixmap( pathString + "1leftarrowB" ); configureToolBarMenu->insertItem(icon, i18n("Go backward"), 210,15); if (p-> mShowIconBack) { action = new QAction( i18n("Go backward"), icon, i18n("Go backward"),0 , this ); connect( action, SIGNAL( activated() ), mView, SLOT( goPrevious() ) ); action->addTo( iconToolBar ); } if (p-> mShowIconToday) today_action->addTo( iconToolBar ); icon = loadPixmap( pathString + "1rightarrowB" ); configureToolBarMenu->insertItem(icon, i18n("Go forward"), 220); if (p-> mShowIconForward) { action = new QAction( i18n("Go forward"), icon, i18n("Go forward"),0 , this ); connect( action, SIGNAL( activated() ), mView, SLOT( goNext() ) ); action->addTo( iconToolBar ); } icon = loadPixmap( pathString + "2rightarrowB" ); configureToolBarMenu->insertItem(icon, i18n("Next month"), 230); if (p-> mShowIconForwardFast) { action = new QAction( i18n("Next month"), icon, i18n("Next month"),0 , this ); connect( action, SIGNAL( activated() ), mView, SLOT( goNextMonth() ) ); action->addTo( iconToolBar ); } configureToolBarMenu->insertItem(i18n("What's This?"), 300); if (p-> mShowIconNewEvent) configureToolBarMenu->setItemChecked( 10, true ); if (p->mShowIconNewTodo ) configureToolBarMenu->setItemChecked( 20, true ); if (p-> mShowIconSearch) configureToolBarMenu->setItemChecked( 120, true ); if (p-> mShowIconList) configureToolBarMenu->setItemChecked( 30, true ); if (p-> mShowIconDay1) configureToolBarMenu->setItemChecked( 40, true ); if (p-> mShowIconDay5) configureToolBarMenu->setItemChecked( 50, true ); if (p-> mShowIconDay7) configureToolBarMenu->setItemChecked( 60, true ); if (p-> mShowIconMonth) configureToolBarMenu->setItemChecked( 70, true ); if (p-> mShowIconTodoview) configureToolBarMenu->setItemChecked( 80, true ); if (p-> mShowIconBackFast) configureToolBarMenu->setItemChecked( 200, true ); if (p-> mShowIconBack) configureToolBarMenu->setItemChecked( 210, true ); if (p-> mShowIconToday) configureToolBarMenu->setItemChecked( 130, true ); if (p-> mShowIconForward) configureToolBarMenu->setItemChecked( 220, true ); if (p-> mShowIconForwardFast) configureToolBarMenu->setItemChecked( 230, true ); if (p-> mShowIconNextDays) configureToolBarMenu->setItemChecked( 100, true ); if (p-> mShowIconNext) configureToolBarMenu->setItemChecked( 110, true ); if (p-> mShowIconJournal) configureToolBarMenu->setItemChecked( 90, true ); if (p-> mShowIconWhatsThis) configureToolBarMenu->setItemChecked( 300, true ); 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")); if ( mode == 2 ) ex2phone.setCaption(i18n("Export filtered calendar")); if ( !ex2phone.exec() ) { return; } KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); int inFuture = 0; if ( ex2phone.mWriteBackFuture->isChecked() ) inFuture = ex2phone.mWriteBackFutureWeeks->value(); QPtrList<Incidence> delSel; if ( mode == 1 ) delSel = mCalendar->rawIncidences(); if ( mode == 2 ) delSel = mCalendar->incidences(); CalendarLocal* cal = new CalendarLocal(); cal->setLocalTime(); Incidence *incidence = delSel.first(); QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); QDateTime end = cur.addDays( ( inFuture +1 ) *7 ); while ( incidence ) { if ( incidence->type() != "Journal" ) { bool add = true; if ( inFuture ) { QDateTime dt; if ( incidence->type() == "Todo" ) { Todo * t = (Todo*)incidence; if ( t->hasDueDate() ) dt = t->dtDue(); else dt = cur.addSecs( 62 ); } else { bool ok; dt = incidence->getNextOccurence( cur, &ok ); if ( !ok ) dt = cur.addSecs( -62 ); } if ( dt < cur || dt > end ) { add = false; } } if ( add ) { Incidence *in = incidence->clone(); cal->addIncidence( in ); } } incidence = delSel.next(); } PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, KPimGlobalPrefs::instance()->mEx2PhoneConnection, KPimGlobalPrefs::instance()->mEx2PhoneModel ); setCaption( i18n("Writing to phone...")); if ( PhoneFormat::writeToPhone( cal ) ) setCaption( i18n("Export to phone successful!")); else setCaption( i18n("Error exporting to phone!")); delete cal; } void MainWindow::setDefaultPreferences() { KOPrefs *p = KOPrefs::instance(); p->mCompactDialogs = true; p->mConfirm = true; // p->mEnableQuickTodo = false; } QString MainWindow::resourcePath() { return KGlobal::iconLoader()->iconPath(); } void MainWindow::displayText( QString text ,QString cap ) { QDialog dia( this, "name", true ); ; dia.setCaption( cap ); @@ -1491,224 +1272,223 @@ void MainWindow::processIncidenceSelection( Incidence *incidence ) enableIncidenceActions( true ); if ( incidence->type() == "Event" ) { mShowAction->setText( i18n("Show Event...") ); mEditAction->setText( i18n("Edit Event...") ); mDeleteAction->setText( i18n("Delete Event...") ); mNewSubTodoAction->setEnabled( false ); } else if ( incidence->type() == "Todo" ) { mShowAction->setText( i18n("Show Todo...") ); mEditAction->setText( i18n("Edit Todo...") ); mDeleteAction->setText( i18n("Delete Todo...") ); mNewSubTodoAction->setEnabled( true ); } else { mShowAction->setText( i18n("Show...") ); mShowAction->setText( i18n("Edit...") ); mShowAction->setText( i18n("Delete...") ); mNewSubTodoAction->setEnabled( false ); } } void MainWindow::enableIncidenceActions( bool enabled ) { mShowAction->setEnabled( enabled ); mEditAction->setEnabled( enabled ); mDeleteAction->setEnabled( enabled ); mCloneAction->setEnabled( enabled ); mMoveAction->setEnabled( enabled ); mBeamAction->setEnabled( enabled ); mCancelAction->setEnabled( enabled ); } void MainWindow::importOL() { #ifdef _WIN32_ KOImportOLdialog *id = new KOImportOLdialog("Import from OL - select folder!" , mView->calendar(),this ); id->exec(); delete id; mView->updateView(); #endif } void MainWindow::importBday() { int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), i18n("When importing birthdays twice\nduplicated events will be ignored,\nif the event has not been\nchanged in KO/Pi!\n"), i18n("Import!"), i18n("Cancel"), 0, 0, 1 ); if ( result == 0 ) { mView->importBday(); } } void MainWindow::importQtopia() { #ifndef DESKTOP_VERSION int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), i18n("When importing a calendar twice\nduplicated events will be ignored!\nYou can create a backup file with\nFile - Save Calendar Backup\nto revert importing"), i18n("Import!"), i18n("Cancel"), 0, 0, 1 ); if ( result == 0 ) { QString datebook = Global::applicationFileName( "datebook", "datebook.xml"); QString todolist = Global::applicationFileName( "todolist", "todolist.xml"); QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml"; mView->importQtopia( categories, datebook, todolist ); } #else int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), i18n("Not supported \non desktop!\n"), i18n("Ok"), i18n("Cancel"), 0, 0, 1 ); #endif } void MainWindow::saveOnClose() { KOPrefs *p = KOPrefs::instance(); p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal ); p->mToolBarUp = iconToolBar->x() > width()/2 || 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 ) { e->ignore(); // qDebug(" ignore %d",e->isAutoRepeat() ); return; } if (! e->isAutoRepeat() ) mFlagKeyPressed = true; KOPrefs *p = KOPrefs::instance(); bool showSelectedDates = false; int size; int pro = 0; //qDebug("MainWindow::keyPressEvent "); switch ( e->key() ) { case Qt::Key_Right: if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) mView->goNextMonth(); else mView->goNext(); showSelectedDates = true; break; case Qt::Key_Left: if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) mView->goPreviousMonth(); else mView->goPrevious(); showSelectedDates = true; break; case Qt::Key_Down: mView->viewManager()->agendaView()->scrollOneHourDown(); break; case Qt::Key_Up: mView->viewManager()->agendaView()->scrollOneHourUp(); break; case Qt::Key_I: mView->showIncidence(); break; case Qt::Key_Delete: case Qt::Key_Backspace: mView->deleteIncidence(); break; case Qt::Key_D: mView->viewManager()->showDayView(); showSelectedDates = true; break; case Qt::Key_O: mView->toggleFilerEnabled( ); break; case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: pro = e->key()-48; if ( pro == 0 ) pro = 10; if ( e->state() == Qt::ControlButton) pro += 10; break; case Qt::Key_M: mView->viewManager()->showMonthView(); showSelectedDates = true; break; case Qt::Key_Insert: mView->newEvent(); break; case Qt::Key_S : if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) mView->newSubTodo(); else mView->dialogManager()->showSearchDialog(); break; case Qt::Key_Y : case Qt::Key_Z : mView->viewManager()->showWorkWeekView(); showSelectedDates = true; break; case Qt::Key_U : mView->viewManager()->showWeekView(); showSelectedDates = true; break; @@ -1936,413 +1716,123 @@ void MainWindow::loadCalendar() 0, 1 ); if ( result != 0 ) { loadbup = false; } } else { QMessageBox::warning( this, i18n("KO/Pi: Warning!"), i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, 0, 1 ); return; } if ( loadbup ) { mView->openCalendar( fn ); KOPrefs::instance()->mLastLoadFile = fn; mess = i18n("KO/Pi:Loaded %1").arg(fn) ; setCaption(mess); } } void MainWindow::quickImportIcal() { importFile( KOPrefs::instance()->mLastImportFile, false ); } void MainWindow::importFile( QString fn, bool quick ) { QFileInfo info; info.setFile( fn ); QString mess; bool loadbup = true; if ( !info. exists() ) { mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), mess ); return; } int result = 0; if ( !quick ) { mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); result = QMessageBox::warning( this, "KO/Pi: Warning!", mess, "Import", "Cancel", 0, 0, 1 ); } if ( result == 0 ) { if ( mView->openCalendar( fn, true )) { KOPrefs::instance()->mLastImportFile = fn; setCaption(i18n("Imported file successfully")); } else { setCaption(i18n("Error importing file")); } } } void MainWindow::importIcal() { QString fn =KOPrefs::instance()->mLastImportFile; fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); if ( fn == "" ) return; importFile( fn, true ); } void MainWindow::exportVCalendar() { QString fn = KOPrefs::instance()->mLastVcalFile; fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); if ( fn == "" ) return; QFileInfo info; info.setFile( fn ); QString mes; bool createbup = true; if ( info. exists() ) { mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, i18n("Overwrite!"), i18n("Cancel"), 0, 0, 1 ); if ( result != 0 ) { createbup = false; } } 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(); } |