summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 05e5087..c597138 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1963,228 +1963,228 @@ void MainWindow::saveOnClose()
}
#endif
save();
mView->writeSettings();
mView->checkSuspendAlarm();
}
void MainWindow::slotModifiedChanged( bool )
{
if ( mBlockAtStartup )
return;
int msec;
if ( mCalendarModifiedFlag ) {
//qDebug(" MainWindow timer is running ");
return;
}
// we store the changes after 1 minute,
// and for safety reasons after 10 minutes again
if ( !mSyncManager->blockSave() )
msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
else
msec = 1000 * 600;
mSaveTimer.start( msec, true ); // 1 minute
mSaveTimerStart = QDateTime::currentDateTime();
mSaveDelay = msec/1000;
qDebug("KO: Saving File in %d secs!", msec/1000);
mCalendarModifiedFlag = true;
}
void MainWindow::saveStopTimer()
{
mSaveTimer.stop();
}
void MainWindow::backupAllFiles()
{
QDate reference ( 2000,1,1);
int daysTo = reference.daysTo ( QDate::currentDate() );
setCaption(i18n("Creating backup ... please wait ..." ));
qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate);
// we need the file path, the backup dir and the number of bups as param
QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
bupDir = KGlobalSettings::backupDataDir();
int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
if ( retval == 0 ) {
setCaption(i18n("Backup cancelled" ));
qDebug("KO: Backup cancelled. Will try again tomorrow ");
// retval == 0 : backup skipped for today, try again tomorrow
KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1;
} else if ( retval == 1 ){
qDebug("KO: Backup created.");
// backup ok
QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
KopiCalendarFile * cal = calendars.first();
cal = calendars.next();
while ( cal ) {
if ( !cal->mErrorOnLoad ) {
KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
}
cal = calendars.next();
}
KOPrefs::instance()->mLastBackupDate = daysTo;
setCaption(i18n("Backup succesfully finished" ));
} else if ( retval == 2 ){
setCaption(i18n("Backup globally disabled" ));
qDebug("KO: Backup globally cancelled.");
// backup globally cancelled
KPimGlobalPrefs::instance()->mBackupEnabled = false;
}
// retval == 3: do nothing, try again later
}
void MainWindow::save()
{
if ( mSaveDelay ) {
int elapsed = mSaveTimerStart.secsTo( QDateTime::currentDateTime() );
if ( mSaveDelay < elapsed ) {
qDebug("KO: Pending save after wakeup from suspend detected.");
qDebug("KO: Save delay %d sec. Elapsed save time %d sec.", mSaveDelay, elapsed );
qDebug("KO: Restarting save timer to save in 10 sec.");
int msec = 10000;
mSaveTimer.start( msec, true );
mSaveTimerStart = QDateTime::currentDateTime();
mSaveDelay = msec/1000;
return;
}
}
if ( mView->viewManager()->journalView() )
mView->viewManager()->journalView()->checkModified();
if ( !mCalendarModifiedFlag ) {
qDebug("KO: Calendar not modified. Nothing saved.");
return;
}
if ( mSyncManager->blockSave() ) {
slotModifiedChanged( true );
return;
}
#ifndef DESKTOP_VERSION
- QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
+ // QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
#endif
mSaveDelay = 0;
mSyncManager->setBlockSave(true);
if ( mView->checkAllFileVersions() ) {
if ( KPimGlobalPrefs::instance()->mBackupEnabled ){
QDate reference ( 2000,1,1);
int daysTo = reference.daysTo ( QDate::currentDate() );
if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) {
backupAllFiles();
}
; // KPimGlobalPrefs::instance()->mLastBackupDate
}
QTime neededSaveTime;
neededSaveTime.start();
if ( !isMinimized () )
setCaption(i18n("KO/Pi:Saving Data to File ..." ));
qDebug("KO: Start saving data to file!");
if ( mView->saveCalendars() )
mCalendarModifiedFlag = false;
int msNeeded = neededSaveTime.elapsed();
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 );
if ( !isMinimized () )
setCaption(savemes);
else
qDebug(savemes);
} else {
setCaption(i18n("Saving cancelled!"));
mCalendarModifiedFlag = false;
slotModifiedChanged( true );
}
mSyncManager->setBlockSave( false );
#ifndef DESKTOP_VERSION
- QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
+ //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
#endif
}
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_K:
mView->viewManager()->showMonthViewWeek();
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;
@@ -2419,198 +2419,198 @@ void MainWindow::configureToolBar( int item )
{
configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
KOPrefs *p = KOPrefs::instance();
p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
p-> mShowIconOnetoolbar = configureToolBarMenu->isItemChecked( 6 );
p-> mShowIconFilter = configureToolBarMenu->isItemChecked( 7 );
p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
p->mShowIconNavigator = configureToolBarMenu->isItemChecked( 22 );
p->mShowIconAllday = configureToolBarMenu->isItemChecked( 24 );
p->mShowIconFilterview = configureToolBarMenu->isItemChecked( 26 );
p->mShowIconToggleFull = configureToolBarMenu->isItemChecked( 28 );
p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
p-> mShowIconDay6= configureToolBarMenu->isItemChecked( 75 );
p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
p-> mShowIconWeekNum= configureToolBarMenu->isItemChecked( 400 );
// initActions();
setCaption ( i18n("Toolbar changes needs a restart!") );
}
void MainWindow::setCaption ( const QString & c )
{
QString cap = c;
cap.replace( QRegExp("\n"), " " );
cap = cap.stripWhiteSpace();
if ( cap.isEmpty() )
cap = "KO/Pi";
QWidget::setCaption( cap );
}
void MainWindow::setCaptionToDates()
{
QString selDates;
QDate date = mView->startDate();
if ( ! date.isValid() ) {
setCaption("");
return;
}
selDates = KGlobal::locale()->formatDate( date, true);
if (mView->startDate() < mView->endDate() )
selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true);
else {
QString addString;
if ( date == QDateTime::currentDateTime().date() )
addString = i18n("Today");
else if ( date == QDateTime::currentDateTime().date().addDays(1) )
addString = i18n("Tomorrow");
if ( !addString.isEmpty() )
selDates = addString+", "+selDates ;
}
setCaption( i18n("Dates: ") + selDates );
}
void MainWindow::showConfigureAgenda( )
{
int iii;
for ( iii = 1;iii<= 10 ;++iii ){
configureAgendaMenu->setItemChecked( (iii+1)*2, false );
}
configureAgendaMenu->setItemChecked( (KOPrefs::instance()->mHourSize/2)*2, true );
}
void MainWindow::configureAgenda( int item )
{
if ( KOPrefs::instance()->mHourSize == item )
return;
KOPrefs::instance()->mHourSize=item;
mView->viewManager()->agendaView()->updateConfig();
}
void MainWindow::saveCalendar()
{
QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
bupDir = KGlobalSettings::backupDataDir();
bupDir = KGlobal::formatMessage ( bupDir, 0 );
QString bupHint;
if ( !KPimGlobalPrefs::instance()->mBackupEnabled )
bupHint = i18n("(Hint: You can enable automatic backup in the global settings!)");
if ( KMessageBox::warningContinueCancel( this, i18n("This will <b>backup all calendar files</b> to the directory %1 %2").arg(bupDir).arg(bupHint),i18n("Information") ) != KMessageBox::Continue ) return;
bool enabled = KPimGlobalPrefs::instance()->mBackupEnabled;
KPimGlobalPrefs::instance()->mBackupEnabled = false;
save();
#ifndef DESKTOP_VERSION
- QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
+ //QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
#endif
KPimGlobalPrefs::instance()->mBackupEnabled = enabled;
backupAllFiles();
#ifndef DESKTOP_VERSION
- QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
+ //QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
#endif
}
void MainWindow::loadCalendar()
{
#if 0
QString fn = KOPrefs::instance()->mLastLoadFile;
fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this );
if ( fn == "" )
return;
QFileInfo info;
info.setFile( fn );
QString mess;
bool loadbup = true;
if ( info. exists() ) {
mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
int result = QMessageBox::warning( this, "KO/Pi: Warning!",
mess,
i18n("Load!"), i18n("Cancel"), 0,
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);
}
#endif
}
void MainWindow::quickImportIcal()
{
importFile( KOPrefs::instance()->mLastImportFile, false );
}
void MainWindow::importFile( QString fn, bool quick )
{
QFileInfo info;
info.setFile( fn );
QString mess;
if ( !info. exists() ) {
mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
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"));
}
mView->updateView();
}
}
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::exportCalendar( bool iCalFormat )
{
QString fn = KOPrefs::instance()->mLastVcalFile;
if ( iCalFormat ) {
fn = QDir::homeDirPath()+"/kopiexport.ics";
fn = KFileDialog::getSaveFileName( fn, i18n("Export iCal filename(*.ics)"), this );
}
else
fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
if ( fn == "" )