summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Unidiff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp69
1 files changed, 55 insertions, 14 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 2af605f..98d3e35 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -478,120 +478,139 @@ void MainWindow::disableBR(bool b)
478 } 478 }
479 mBRdisabled = true; 479 mBRdisabled = true;
480 } else { 480 } else {
481 if ( mBRdisabled ) { 481 if ( mBRdisabled ) {
482 mBRdisabled = false; 482 mBRdisabled = false;
483 //makes no sense,because other cal ap is probably running 483 //makes no sense,because other cal ap is probably running
484 // toggleBeamReceive(); 484 // toggleBeamReceive();
485 } 485 }
486 } 486 }
487#endif 487#endif
488 488
489} 489}
490bool MainWindow::beamReceiveEnabled() 490bool MainWindow::beamReceiveEnabled()
491{ 491{
492#ifndef DESKTOP_VERSION 492#ifndef DESKTOP_VERSION
493 return ( infrared != 0 ); 493 return ( infrared != 0 );
494#endif 494#endif
495 return false; 495 return false;
496} 496}
497 497
498void MainWindow::toggleBeamReceive() 498void MainWindow::toggleBeamReceive()
499{ 499{
500 if ( mBRdisabled ) 500 if ( mBRdisabled )
501 return; 501 return;
502#ifndef DESKTOP_VERSION 502#ifndef DESKTOP_VERSION
503 if ( infrared ) { 503 if ( infrared ) {
504 qDebug("KO: Disable BeamReceive "); 504 qDebug("KO: Disable BeamReceive ");
505 delete infrared; 505 delete infrared;
506 infrared = 0; 506 infrared = 0;
507 brAction->setOn(false); 507 brAction->setOn(false);
508 return; 508 return;
509 } 509 }
510 qDebug("KO: Enable BeamReceive "); 510 qDebug("KO: Enable BeamReceive ");
511 brAction->setOn(true); 511 brAction->setOn(true);
512 infrared = new QCopChannel("QPE/Application/datebook",this, "channel" ) ; 512 infrared = new QCopChannel("QPE/Application/datebook",this, "channel" ) ;
513 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(recieve( const QCString&, const QByteArray& ))); 513 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(recieve( const QCString&, const QByteArray& )));
514#endif 514#endif
515} 515}
516void MainWindow::showMaximized () 516void MainWindow::showMaximized ()
517{ 517{
518#ifndef DESKTOP_VERSION 518#ifndef DESKTOP_VERSION
519 if ( ! globalFlagBlockStartup ) 519 if ( ! globalFlagBlockStartup )
520 if ( mClosed ) 520 if ( mClosed )
521 mView->goToday(); 521 mView->goToday();
522#endif 522#endif
523 QWidget::showMaximized () ; 523 QWidget::showMaximized () ;
524 mClosed = false; 524 mClosed = false;
525} 525}
526
527bool MainWindow::askForQuitOnSaveError()
528{
529 bool retval = false;
530 switch( QMessageBox::information( this, "KO/Pi",
531 i18n("Error saving data") + "!\n" +
532 i18n("You can save all data\nto another file via\nFile->Export->Export All Data") + "!\n" +
533 i18n("Do you really want\nto close KO/Pi?"),
534 i18n(" Yes, close "), i18n("No"),
535 0, 1 ) ) {
536 case 0:
537 retval = true;
538 break;
539 default:
540 break;
541 }
542 return retval;
543}
544
526void MainWindow::closeEvent( QCloseEvent* ce ) 545void MainWindow::closeEvent( QCloseEvent* ce )
527{ 546{
528 547
529 548
530 549
531 if ( ! KOPrefs::instance()->mAskForQuit ) { 550 if ( ! KOPrefs::instance()->mAskForQuit ) {
532 saveOnClose(); 551 saveOnClose();
533 if ( mCalendarModifiedFlag ) { 552 if ( mCalendarModifiedFlag && !askForQuitOnSaveError() ) {
534 ce->ignore(); 553 ce->ignore();
535 return; 554 return;
536 } 555 }
537 mClosed = true; 556 mClosed = true;
538 ce->accept(); 557 ce->accept();
539 return; 558 return;
540 559
541 } 560 }
542 561
543 switch( QMessageBox::information( this, "KO/Pi", 562 switch( QMessageBox::information( this, "KO/Pi",
544 i18n("Do you really want\nto close KO/Pi?"), 563 i18n("Do you really want\nto close KO/Pi?"),
545 i18n("Close"), i18n("No"), 564 i18n("Close"), i18n("No"),
546 0, 0 ) ) { 565 0, 0 ) ) {
547 case 0: 566 case 0:
548 saveOnClose(); 567 saveOnClose();
549 if ( mCalendarModifiedFlag ) { 568 if ( mCalendarModifiedFlag && !askForQuitOnSaveError() ) {
550 ce->ignore(); 569 ce->ignore();
551 return; 570 return;
552 } 571 }
553 mClosed = true; 572 mClosed = true;
554 ce->accept(); 573 ce->accept();
555 break; 574 break;
556 case 1: 575 case 1:
557 ce->ignore(); 576 ce->ignore();
558 break; 577 break;
559 case 2: 578 case 2:
560 579
561 default: 580 default:
562 break; 581 break;
563 } 582 }
564 583
565 584
566} 585}
567void MainWindow::receiveStart( const QCString& cmsg, const QByteArray& data ) 586void MainWindow::receiveStart( const QCString& cmsg, const QByteArray& data )
568{ 587{
569 qDebug("KO: QCOP start message received: %s ", cmsg.data() ); 588 qDebug("KO: QCOP start message received: %s ", cmsg.data() );
570 mCStringMess = cmsg; 589 mCStringMess = cmsg;
571 mByteData = data; 590 mByteData = data;
572} 591}
573void MainWindow::recieve( const QCString& cmsg, const QByteArray& data ) 592void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
574{ 593{
575 QDataStream stream( data, IO_ReadOnly ); 594 QDataStream stream( data, IO_ReadOnly );
576 // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" ); 595 // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" );
577 //QString datamess; 596 //QString datamess;
578 //qDebug("message "); 597 //qDebug("message ");
579 qDebug("KO: QCOP message received: %s ", cmsg.data() ); 598 qDebug("KO: QCOP message received: %s ", cmsg.data() );
580 599
581 if ( cmsg == "setDocument(QString)" ) { 600 if ( cmsg == "setDocument(QString)" ) {
582 QDataStream stream( data, IO_ReadOnly ); 601 QDataStream stream( data, IO_ReadOnly );
583 QString fileName; 602 QString fileName;
584 stream >> fileName; 603 stream >> fileName;
585 //qDebug("filename %s ", fileName.latin1()); 604 //qDebug("filename %s ", fileName.latin1());
586 showMaximized(); 605 showMaximized();
587 raise(); 606 raise();
588 KOPrefs::instance()->mLastSyncedLocalFile = fileName ; 607 KOPrefs::instance()->mLastSyncedLocalFile = fileName ;
589 mSyncManager->slotSyncMenu( 1002 ); 608 mSyncManager->slotSyncMenu( 1002 );
590 return; 609 return;
591 } 610 }
592 611
593 if ( cmsg == "-writeFile" ) { 612 if ( cmsg == "-writeFile" ) {
594 // I made from the "-writeFile" an "-writeAlarm" 613 // I made from the "-writeFile" an "-writeAlarm"
595 mView->viewManager()->showWhatsNextView(); 614 mView->viewManager()->showWhatsNextView();
596 mCalendar->checkAlarmForIncidence( 0, true); 615 mCalendar->checkAlarmForIncidence( 0, true);
597 showMaximized(); 616 showMaximized();
@@ -1120,96 +1139,100 @@ void MainWindow::initActions()
1120 if ( KOPrefs::instance()->mShowFullMenu ) { 1139 if ( KOPrefs::instance()->mShowFullMenu ) {
1121 actionMenu->insertItem( i18n("Configure Toolbar"),configureToolBarMenu ); 1140 actionMenu->insertItem( i18n("Configure Toolbar"),configureToolBarMenu );
1122 1141
1123 } 1142 }
1124 // actionMenu->insertSeparator(); 1143 // actionMenu->insertSeparator();
1125 action = new QAction( "import_qtopia", i18n("Import (*.ics/*.vcs) file"), 0, 1144 action = new QAction( "import_qtopia", i18n("Import (*.ics/*.vcs) file"), 0,
1126 this ); 1145 this );
1127 action->addTo( importMenu_X ); 1146 action->addTo( importMenu_X );
1128 connect( action, SIGNAL( activated() ), SLOT( importIcal() ) ); 1147 connect( action, SIGNAL( activated() ), SLOT( importIcal() ) );
1129 action = new QAction( "import_quick", i18n("Import last file"), 0, 1148 action = new QAction( "import_quick", i18n("Import last file"), 0,
1130 this ); 1149 this );
1131 action->addTo( importMenu_X ); 1150 action->addTo( importMenu_X );
1132 connect( action, SIGNAL( activated() ), SLOT( quickImportIcal() ) ); 1151 connect( action, SIGNAL( activated() ), SLOT( quickImportIcal() ) );
1133 importMenu_X->insertSeparator(); 1152 importMenu_X->insertSeparator();
1134 action = new QAction( "import_bday", i18n("Import Birthdays (KA/Pi)"), 0, 1153 action = new QAction( "import_bday", i18n("Import Birthdays (KA/Pi)"), 0,
1135 this ); 1154 this );
1136 action->addTo( importMenu_X ); 1155 action->addTo( importMenu_X );
1137 connect( action, SIGNAL( activated() ), SLOT( importBday() ) ); 1156 connect( action, SIGNAL( activated() ), SLOT( importBday() ) );
1138 //#ifndef DESKTOP_VERSION 1157 //#ifndef DESKTOP_VERSION
1139 importMenu_X->insertSeparator(); 1158 importMenu_X->insertSeparator();
1140 action = new QAction( "import_qtopia", i18n("Import Opie/Qtopia Cal."), 0, 1159 action = new QAction( "import_qtopia", i18n("Import Opie/Qtopia Cal."), 0,
1141 this ); 1160 this );
1142 action->addTo( importMenu_X ); 1161 action->addTo( importMenu_X );
1143 connect( action, SIGNAL( activated() ), SLOT( importQtopia() ) ); 1162 connect( action, SIGNAL( activated() ), SLOT( importQtopia() ) );
1144 //#else 1163 //#else
1145#ifdef _OL_IMPORT_ 1164#ifdef _OL_IMPORT_
1146 importMenu_X->insertSeparator(); 1165 importMenu_X->insertSeparator();
1147 action = new QAction( "import_ol", i18n("Import from OL"), 0, 1166 action = new QAction( "import_ol", i18n("Import from OL"), 0,
1148 this ); 1167 this );
1149 action->addTo( importMenu_X ); 1168 action->addTo( importMenu_X );
1150 connect( action, SIGNAL( activated() ), SLOT( importOL() ) ); 1169 connect( action, SIGNAL( activated() ), SLOT( importOL() ) );
1151#endif 1170#endif
1152 //#endif 1171 //#endif
1153 1172
1154 //importMenu->insertSeparator(); 1173 //importMenu->insertSeparator();
1155#if 0 1174#if 0
1156 action = new QAction( "load_cal", i18n("Load Calendar Backup"), 0, 1175 action = new QAction( "load_cal", i18n("Load Calendar Backup"), 0,
1157 this ); 1176 this );
1158 action->addTo( importMenu ); 1177 action->addTo( importMenu );
1159 connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) ); 1178 connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) );
1160#endif 1179#endif
1161 action = new QAction( "save_cal", i18n("Save Backup..."), 0, 1180 action = new QAction( "save_cal", i18n("Save Backup..."), 0,
1162 this ); 1181 this );
1163 action->addTo( importMenu ); 1182 action->addTo( importMenu );
1164 connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) ); 1183 connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) );
1165 importMenu->insertSeparator(); 1184 importMenu->insertSeparator();
1166 importMenu->insertItem( i18n("Import"), importMenu_X ); 1185 importMenu->insertItem( i18n("Import"), importMenu_X );
1167 //importMenu->insertSeparator(); 1186 //importMenu->insertSeparator();
1187 action = new QAction( "export ical", i18n("Export All Data"), 0,
1188 this );
1189 action->addTo( exportMenu_X );
1190 connect( action, SIGNAL( activated() ), SLOT( exportICalendar() ) );
1168 action = new QAction( "import_qtopia", i18n("Export VCalendar"), 0, 1191 action = new QAction( "import_qtopia", i18n("Export VCalendar"), 0,
1169 this ); 1192 this );
1170 action->addTo( exportMenu_X ); 1193 action->addTo( exportMenu_X );
1171 connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) ); 1194 connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) );
1172 1195
1173 1196
1174 //LR 1197 //LR
1175 QPopupMenu *ex2phone = new QPopupMenu( this ); 1198 QPopupMenu *ex2phone = new QPopupMenu( this );
1176 ex2phone->insertItem(i18n("Complete calendar..."), 1 ); 1199 ex2phone->insertItem(i18n("Complete calendar..."), 1 );
1177 ex2phone->insertItem(i18n("Filtered calendar..."), 2 ); 1200 ex2phone->insertItem(i18n("Filtered calendar..."), 2 );
1178 connect( ex2phone, SIGNAL( activated(int) ), this, SLOT( exportToPhone( int)) ); 1201 connect( ex2phone, SIGNAL( activated(int) ), this, SLOT( exportToPhone( int)) );
1179 exportMenu_X->insertItem( i18n("Export to phone"), ex2phone ); 1202 exportMenu_X->insertItem( i18n("Export to phone"), ex2phone );
1180 1203
1181 importMenu->insertItem( i18n("Export"), exportMenu_X ); 1204 importMenu->insertItem( i18n("Export"), exportMenu_X );
1182 mPrintSelAction = 0; 1205 mPrintSelAction = 0;
1183#ifndef DESKTOP_VERSION 1206#ifndef DESKTOP_VERSION
1184 //importMenu->insertSeparator(); 1207 //importMenu->insertSeparator();
1185 brAction = new QAction( "beam toggle", i18n("Beam receive enabled"), 0, 1208 brAction = new QAction( "beam toggle", i18n("Beam receive enabled"), 0,
1186 this ); 1209 this );
1187 brAction->addTo( beamMenu_X ); 1210 brAction->addTo( beamMenu_X );
1188 brAction->setToggleAction (true ) ; 1211 brAction->setToggleAction (true ) ;
1189 connect( brAction, SIGNAL( activated() ), this, SLOT( toggleBeamReceive() ) ); 1212 connect( brAction, SIGNAL( activated() ), this, SLOT( toggleBeamReceive() ) );
1190 1213
1191 action = new QAction( "beam all", i18n("Beam complete calendar..."), 0, 1214 action = new QAction( "beam all", i18n("Beam complete calendar..."), 0,
1192 this ); 1215 this );
1193 action->addTo( beamMenu_X ); 1216 action->addTo( beamMenu_X );
1194 connect( action, SIGNAL( activated() ), mView, SLOT( beamCalendar() ) ); 1217 connect( action, SIGNAL( activated() ), mView, SLOT( beamCalendar() ) );
1195 1218
1196 action = new QAction( "beam all", i18n("Beam filtered calendar..."), 0, 1219 action = new QAction( "beam all", i18n("Beam filtered calendar..."), 0,
1197 this ); 1220 this );
1198 action->addTo( beamMenu_X ); 1221 action->addTo( beamMenu_X );
1199 connect( action, SIGNAL( activated() ), mView, SLOT( beamFilteredCalendar()) ); 1222 connect( action, SIGNAL( activated() ), mView, SLOT( beamFilteredCalendar()) );
1200 importMenu->insertItem( i18n("Beam"), beamMenu_X ); 1223 importMenu->insertItem( i18n("Beam"), beamMenu_X );
1201#else 1224#else
1202 //importMenu->insertSeparator(); 1225 //importMenu->insertSeparator();
1203 icon = loadPixmap( pathString + "print" ); 1226 icon = loadPixmap( pathString + "print" );
1204 action = new QAction( i18n("Print calendar..."),icon,i18n("Print calendar..."), 0, this ); 1227 action = new QAction( i18n("Print calendar..."),icon,i18n("Print calendar..."), 0, this );
1205 action->addTo( beamMenu_X ); 1228 action->addTo( beamMenu_X );
1206 connect( action, SIGNAL( activated() ), 1229 connect( action, SIGNAL( activated() ),
1207 this, SLOT( printCal() ) ); 1230 this, SLOT( printCal() ) );
1208 1231
1209 icon = loadPixmap( pathString + "week" ); 1232 icon = loadPixmap( pathString + "week" );
1210 action = new QAction( i18n("Print agenda selection..."),icon,i18n("Print agenda selection..."), 0, this ); 1233 action = new QAction( i18n("Print agenda selection..."),icon,i18n("Print agenda selection..."), 0, this );
1211 action->addTo( beamMenu_X ); 1234 action->addTo( beamMenu_X );
1212 connect( action, SIGNAL( activated() ), 1235 connect( action, SIGNAL( activated() ),
1213 this, SLOT( printSel() ) ); 1236 this, SLOT( printSel() ) );
1214 icon = loadPixmap( pathString + "whatsnext" ); 1237 icon = loadPixmap( pathString + "whatsnext" );
1215 action = new QAction( i18n("Print What's Next View..."),icon,i18n("Print What's Next View..."), 0, this ); 1238 action = new QAction( i18n("Print What's Next View..."),icon,i18n("Print What's Next View..."), 0, this );
@@ -1922,152 +1945,154 @@ void MainWindow::saveOnClose()
1922 myP = mapFromGlobal( filterToolBar->mapToGlobal( QPoint( 0,0) ) ); 1945 myP = mapFromGlobal( filterToolBar->mapToGlobal( QPoint( 0,0) ) );
1923 if ( p->mToolBarHorF ) 1946 if ( p->mToolBarHorF )
1924 p->mToolBarUpF = myP.y() > height()/2; 1947 p->mToolBarUpF = myP.y() > height()/2;
1925 else 1948 else
1926 p->mToolBarUpF = myP.x() > width()/2 ; 1949 p->mToolBarUpF = myP.x() > width()/2 ;
1927 } 1950 }
1928#else 1951#else
1929 if ( p->mToolBarHor ) 1952 if ( p->mToolBarHor )
1930 p->mToolBarUp = iconToolBar->y() > height()/2; 1953 p->mToolBarUp = iconToolBar->y() > height()/2;
1931 else 1954 else
1932 p->mToolBarUp = iconToolBar->x() > width()/2; 1955 p->mToolBarUp = iconToolBar->x() > width()/2;
1933 if ( p->mToolBarHorV ) 1956 if ( p->mToolBarHorV )
1934 p->mToolBarUpV = viewToolBar->y() > height()/2; 1957 p->mToolBarUpV = viewToolBar->y() > height()/2;
1935 else 1958 else
1936 p->mToolBarUpV = viewToolBar->x() > width()/2 ; 1959 p->mToolBarUpV = viewToolBar->x() > width()/2 ;
1937 1960
1938 if ( p->mToolBarHorN ) 1961 if ( p->mToolBarHorN )
1939 p->mToolBarUpN = navigatorToolBar->y() > height()/2; 1962 p->mToolBarUpN = navigatorToolBar->y() > height()/2;
1940 else 1963 else
1941 p->mToolBarUpN = navigatorToolBar->x() > width()/2 ; 1964 p->mToolBarUpN = navigatorToolBar->x() > width()/2 ;
1942 if ( filterToolBar ) { 1965 if ( filterToolBar ) {
1943 if ( p->mToolBarHorF ) 1966 if ( p->mToolBarHorF )
1944 p->mToolBarUpF = filterToolBar->y() > height()/2; 1967 p->mToolBarUpF = filterToolBar->y() > height()/2;
1945 else 1968 else
1946 p->mToolBarUpF = filterToolBar->x() > width()/2 ; 1969 p->mToolBarUpF = filterToolBar->x() > width()/2 ;
1947 } 1970 }
1948#endif 1971#endif
1949 save(); 1972 save();
1950 mView->writeSettings(); 1973 mView->writeSettings();
1951 mView->checkSuspendAlarm(); 1974 mView->checkSuspendAlarm();
1952} 1975}
1953void MainWindow::slotModifiedChanged( bool ) 1976void MainWindow::slotModifiedChanged( bool )
1954{ 1977{
1955 if ( mBlockAtStartup ) 1978 if ( mBlockAtStartup )
1956 return; 1979 return;
1957 1980
1958 int msec; 1981 int msec;
1959 if ( mCalendarModifiedFlag ) { 1982 if ( mCalendarModifiedFlag ) {
1960 //qDebug(" MainWindow timer is running "); 1983 //qDebug(" MainWindow timer is running ");
1961 return; 1984 return;
1962 } 1985 }
1963 // we store the changes after 1 minute, 1986 // we store the changes after 1 minute,
1964 // and for safety reasons after 10 minutes again 1987 // and for safety reasons after 10 minutes again
1965 if ( !mSyncManager->blockSave() ) 1988 if ( !mSyncManager->blockSave() )
1966 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; 1989 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
1967 else 1990 else
1968 msec = 1000 * 600; 1991 msec = 1000 * 600;
1969 mSaveTimer.start( msec, true ); // 1 minute 1992 mSaveTimer.start( msec, true ); // 1 minute
1970 mSaveTime.restart(); 1993 mSaveTimerStart = QDateTime::currentDateTime();
1971 mSaveDelay = msec/1000; 1994 mSaveDelay = msec/1000;
1972 qDebug("KO: Saving File in %d secs!", msec/1000); 1995 qDebug("KO: Saving File in %d secs!", msec/1000);
1973 mCalendarModifiedFlag = true; 1996 mCalendarModifiedFlag = true;
1974} 1997}
1975void MainWindow::saveStopTimer() 1998void MainWindow::saveStopTimer()
1976{ 1999{
1977 mSaveTimer.stop(); 2000 mSaveTimer.stop();
1978} 2001}
1979void MainWindow::backupAllFiles() 2002void MainWindow::backupAllFiles()
1980{ 2003{
1981 QDate reference ( 2000,1,1); 2004 QDate reference ( 2000,1,1);
1982 int daysTo = reference.daysTo ( QDate::currentDate() ); 2005 int daysTo = reference.daysTo ( QDate::currentDate() );
1983 setCaption(i18n("Creating backup ... please wait ..." )); 2006 setCaption(i18n("Creating backup ... please wait ..." ));
1984 qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate); 2007 qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate);
1985 // we need the file path, the backup dir and the number of bups as param 2008 // we need the file path, the backup dir and the number of bups as param
1986 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir; 2009 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
1987 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir) 2010 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
1988 bupDir = KGlobalSettings::backupDataDir(); 2011 bupDir = KGlobalSettings::backupDataDir();
1989 int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); 2012 int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
1990 if ( retval == 0 ) { 2013 if ( retval == 0 ) {
1991 setCaption(i18n("Backup cancelled" )); 2014 setCaption(i18n("Backup cancelled" ));
1992 qDebug("KO: Backup cancelled. Will try again tomorrow "); 2015 qDebug("KO: Backup cancelled. Will try again tomorrow ");
1993 // retval == 0 : backup skipped for today, try again tomorrow 2016 // retval == 0 : backup skipped for today, try again tomorrow
1994 KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1; 2017 KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1;
1995 } else if ( retval == 1 ){ 2018 } else if ( retval == 1 ){
1996 qDebug("KO: Backup created."); 2019 qDebug("KO: Backup created.");
1997 // backup ok 2020 // backup ok
1998 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2021 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1999 KopiCalendarFile * cal = calendars.first(); 2022 KopiCalendarFile * cal = calendars.first();
2000 cal = calendars.next(); 2023 cal = calendars.next();
2001 while ( cal ) { 2024 while ( cal ) {
2002 if ( !cal->mErrorOnLoad ) { 2025 if ( !cal->mErrorOnLoad ) {
2003 KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); 2026 KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
2004 } 2027 }
2005 cal = calendars.next(); 2028 cal = calendars.next();
2006 } 2029 }
2007 KOPrefs::instance()->mLastBackupDate = daysTo; 2030 KOPrefs::instance()->mLastBackupDate = daysTo;
2008 setCaption(i18n("Backup succesfully finished" )); 2031 setCaption(i18n("Backup succesfully finished" ));
2009 } else if ( retval == 2 ){ 2032 } else if ( retval == 2 ){
2010 setCaption(i18n("Backup globally disabled" )); 2033 setCaption(i18n("Backup globally disabled" ));
2011 qDebug("KO: Backup globally cancelled."); 2034 qDebug("KO: Backup globally cancelled.");
2012 // backup globally cancelled 2035 // backup globally cancelled
2013 KPimGlobalPrefs::instance()->mBackupEnabled = false; 2036 KPimGlobalPrefs::instance()->mBackupEnabled = false;
2014 } 2037 }
2015 // retval == 3: do nothing, try again later 2038 // retval == 3: do nothing, try again later
2016} 2039}
2017void MainWindow::save() 2040void MainWindow::save()
2018{ 2041{
2019 if ( mSaveDelay ) { 2042 if ( mSaveDelay ) {
2020 if ( mSaveDelay + 60 < mSaveTime.elapsed()/1000 ) { 2043 int elapsed = mSaveTimerStart.secsTo( QDateTime::currentDateTime() );
2021 qDebug("KO: Save delay %d. Elapsed save time %d ", mSaveDelay, mSaveTime.elapsed()/1000 ); 2044 if ( mSaveDelay < elapsed ) {
2022 qDebug("KO: Restarting save timer"); 2045 qDebug("KO: Pending save after wakeup from suspend detected.");
2023 int msec = 10000; 2046 qDebug("KO: Save delay %d sec. Elapsed save time %d sec.", mSaveDelay, elapsed );
2024 mSaveTimer.start( msec, true ); // 1 minute 2047 qDebug("KO: Restarting save timer to save in 15 sec.");
2025 mSaveTime.restart(); 2048 int msec = 15000;
2049 mSaveTimer.start( msec, true );
2050 mSaveTimerStart = QDateTime::currentDateTime();
2026 mSaveDelay = msec/1000; 2051 mSaveDelay = msec/1000;
2027 return; 2052 return;
2028 } 2053 }
2029 } 2054 }
2030 2055
2031 if ( mView->viewManager()->journalView() ) 2056 if ( mView->viewManager()->journalView() )
2032 mView->viewManager()->journalView()->checkModified(); 2057 mView->viewManager()->journalView()->checkModified();
2033 if ( !mCalendarModifiedFlag ) { 2058 if ( !mCalendarModifiedFlag ) {
2034 qDebug("KO: Calendar not modified. Nothing saved."); 2059 qDebug("KO: Calendar not modified. Nothing saved.");
2035 return; 2060 return;
2036 } 2061 }
2037 if ( mSyncManager->blockSave() ) { 2062 if ( mSyncManager->blockSave() ) {
2038 slotModifiedChanged( true ); 2063 slotModifiedChanged( true );
2039 return; 2064 return;
2040 } 2065 }
2041 mSaveDelay = 0; 2066 mSaveDelay = 0;
2042 mSyncManager->setBlockSave(true); 2067 mSyncManager->setBlockSave(true);
2043 if ( mView->checkAllFileVersions() ) { 2068 if ( mView->checkAllFileVersions() ) {
2044 if ( KPimGlobalPrefs::instance()->mBackupEnabled ){ 2069 if ( KPimGlobalPrefs::instance()->mBackupEnabled ){
2045 QDate reference ( 2000,1,1); 2070 QDate reference ( 2000,1,1);
2046 int daysTo = reference.daysTo ( QDate::currentDate() ); 2071 int daysTo = reference.daysTo ( QDate::currentDate() );
2047 if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) { 2072 if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) {
2048 backupAllFiles(); 2073 backupAllFiles();
2049 } 2074 }
2050 ; // KPimGlobalPrefs::instance()->mLastBackupDate 2075 ; // KPimGlobalPrefs::instance()->mLastBackupDate
2051 } 2076 }
2052 QTime neededSaveTime; 2077 QTime neededSaveTime;
2053 neededSaveTime.start(); 2078 neededSaveTime.start();
2054 if ( !isMinimized () ) 2079 if ( !isMinimized () )
2055 setCaption(i18n("KO/Pi:Saving Data to File ..." )); 2080 setCaption(i18n("KO/Pi:Saving Data to File ..." ));
2056 qDebug("KO: Start saving data to file!"); 2081 qDebug("KO: Start saving data to file!");
2057 if ( mView->saveCalendars() ) 2082 if ( mView->saveCalendars() )
2058 mCalendarModifiedFlag = false; 2083 mCalendarModifiedFlag = false;
2059 int msNeeded = neededSaveTime.elapsed(); 2084 int msNeeded = neededSaveTime.elapsed();
2060 qDebug("KO: Needed %d ms for saving.",msNeeded ); 2085 qDebug("KO: Needed %d ms for saving.",msNeeded );
2061 QString savemes; 2086 QString savemes;
2062 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); 2087 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 );
2063 if ( !isMinimized () ) 2088 if ( !isMinimized () )
2064 setCaption(savemes); 2089 setCaption(savemes);
2065 else 2090 else
2066 qDebug(savemes); 2091 qDebug(savemes);
2067 } else { 2092 } else {
2068 setCaption(i18n("Saving cancelled!")); 2093 setCaption(i18n("Saving cancelled!"));
2069 mCalendarModifiedFlag = false; 2094 mCalendarModifiedFlag = false;
2070 slotModifiedChanged( true ); 2095 slotModifiedChanged( true );
2071 } 2096 }
2072 mSyncManager->setBlockSave( false ); 2097 mSyncManager->setBlockSave( false );
2073} 2098}
@@ -2530,128 +2555,144 @@ void MainWindow::loadCalendar()
2530#endif 2555#endif
2531 2556
2532} 2557}
2533void MainWindow::quickImportIcal() 2558void MainWindow::quickImportIcal()
2534{ 2559{
2535 importFile( KOPrefs::instance()->mLastImportFile, false ); 2560 importFile( KOPrefs::instance()->mLastImportFile, false );
2536} 2561}
2537void MainWindow::importFile( QString fn, bool quick ) 2562void MainWindow::importFile( QString fn, bool quick )
2538{ 2563{
2539 QFileInfo info; 2564 QFileInfo info;
2540 info.setFile( fn ); 2565 info.setFile( fn );
2541 QString mess; 2566 QString mess;
2542 if ( !info. exists() ) { 2567 if ( !info. exists() ) {
2543 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); 2568 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
2544 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2569 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2545 mess ); 2570 mess );
2546 return; 2571 return;
2547 } 2572 }
2548 int result = 0; 2573 int result = 0;
2549 if ( !quick ) { 2574 if ( !quick ) {
2550 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 )); 2575 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 ));
2551 result = QMessageBox::warning( this, "KO/Pi: Warning!", 2576 result = QMessageBox::warning( this, "KO/Pi: Warning!",
2552 mess, 2577 mess,
2553 "Import", "Cancel", 0, 2578 "Import", "Cancel", 0,
2554 0, 1 ); 2579 0, 1 );
2555 } 2580 }
2556 if ( result == 0 ) { 2581 if ( result == 0 ) {
2557 if ( mView->openCalendar( fn, true )) { 2582 if ( mView->openCalendar( fn, true )) {
2558 KOPrefs::instance()->mLastImportFile = fn; 2583 KOPrefs::instance()->mLastImportFile = fn;
2559 setCaption(i18n("Imported file successfully")); 2584 setCaption(i18n("Imported file successfully"));
2560 } else { 2585 } else {
2561 setCaption(i18n("Error importing file")); 2586 setCaption(i18n("Error importing file"));
2562 } 2587 }
2563 mView->updateView(); 2588 mView->updateView();
2564 } 2589 }
2565} 2590}
2566 2591
2567void MainWindow::importIcal() 2592void MainWindow::importIcal()
2568{ 2593{
2569 2594
2570 QString fn =KOPrefs::instance()->mLastImportFile; 2595 QString fn =KOPrefs::instance()->mLastImportFile;
2571 2596
2572 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 2597 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
2573 if ( fn == "" ) 2598 if ( fn == "" )
2574 return; 2599 return;
2575 importFile( fn, true ); 2600 importFile( fn, true );
2576 2601
2577} 2602}
2578 2603void MainWindow::exportCalendar( bool iCalFormat )
2579void MainWindow::exportVCalendar()
2580{ 2604{
2581 QString fn = KOPrefs::instance()->mLastVcalFile; 2605 QString fn = KOPrefs::instance()->mLastVcalFile;
2582 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 2606 if ( iCalFormat ) {
2607 fn = QDir::homeDirPath()+"/kopiexport.ics";
2608 fn = KFileDialog::getSaveFileName( fn, i18n("Export iCal filename(*.ics)"), this );
2609 }
2610 else
2611 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
2583 if ( fn == "" ) 2612 if ( fn == "" )
2584 return; 2613 return;
2585 QFileInfo info; 2614 QFileInfo info;
2586 info.setFile( fn ); 2615 info.setFile( fn );
2587 QString mes; 2616 QString mes;
2588 bool createbup = true; 2617 bool createbup = true;
2589 if ( info. exists() ) { 2618 if ( info. exists() ) {
2590 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 2619 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
2591 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 2620 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
2592 i18n("Overwrite!"), i18n("Cancel"), 0, 2621 i18n("Overwrite!"), i18n("Cancel"), 0,
2593 0, 1 ); 2622 0, 1 );
2594 if ( result != 0 ) { 2623 if ( result != 0 ) {
2595 createbup = false; 2624 createbup = false;
2596 } 2625 }
2597 } 2626 }
2598 if ( createbup ) { 2627 if ( createbup ) {
2599 if ( mView->exportVCalendar( fn ) ) { 2628 bool success = false;
2600 KOPrefs::instance()->mLastVcalFile = fn; 2629 if ( iCalFormat )
2630 success = mView->exportICalendar( fn );
2631 else
2632 success = mView->exportVCalendar( fn );
2633 if ( success ) {
2601 if ( fn.length() > 20 ) 2634 if ( fn.length() > 20 )
2602 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 2635 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
2603 else 2636 else
2604 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 2637 mes = i18n("KO/Pi:Exported to %1").arg(fn );
2605 setCaption(mes); 2638 setCaption(mes);
2606 } 2639 }
2607 } 2640 }
2608 2641
2609} 2642}
2643void MainWindow::exportICalendar()
2644{
2645 exportCalendar( true );
2646}
2647void MainWindow::exportVCalendar()
2648{
2649 exportCalendar( false );
2650}
2610QString MainWindow::sentSyncFile() 2651QString MainWindow::sentSyncFile()
2611{ 2652{
2612#ifdef DESKTOP_VERSION 2653#ifdef DESKTOP_VERSION
2613 return QDir::convertSeparators( locateLocal( "tmp", "copysynccal.ics" ) ); 2654 return QDir::convertSeparators( locateLocal( "tmp", "copysynccal.ics" ) );
2614#else 2655#else
2615 return QString( "/tmp/copysynccal.ics" ); 2656 return QString( "/tmp/copysynccal.ics" );
2616#endif 2657#endif
2617} 2658}
2618 2659
2619void MainWindow::syncFileRequest() 2660void MainWindow::syncFileRequest()
2620{ 2661{
2621 while ( mSyncManager->blockSave() ) { 2662 while ( mSyncManager->blockSave() ) {
2622 qApp->processEvents(); 2663 qApp->processEvents();
2623 } 2664 }
2624 mSyncManager->setBlockSave(true); 2665 mSyncManager->setBlockSave(true);
2625 2666
2626 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2667 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2627 mSyncManager->slotSyncMenu( 999 ); 2668 mSyncManager->slotSyncMenu( 999 );
2628 } 2669 }
2629 2670
2630 setCaption(i18n("Saving Data to temp file ..." )); 2671 setCaption(i18n("Saving Data to temp file ..." ));
2631 mView->saveCalendar( sentSyncFile() ); 2672 mView->saveCalendar( sentSyncFile() );
2632 setCaption(i18n("Data saved to temp file!" )); 2673 setCaption(i18n("Data saved to temp file!" ));
2633 mSyncManager->setBlockSave( false ); 2674 mSyncManager->setBlockSave( false );
2634 2675
2635} 2676}
2636void MainWindow::getFile( bool success ) 2677void MainWindow::getFile( bool success )
2637{ 2678{
2638 if ( ! success ) { 2679 if ( ! success ) {
2639 setCaption( i18n("Error receiving file. Nothing changed!") ); 2680 setCaption( i18n("Error receiving file. Nothing changed!") );
2640 return; 2681 return;
2641 } 2682 }
2642 mView->mergeFile( sentSyncFile() ); 2683 mView->mergeFile( sentSyncFile() );
2643 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2684 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2644 mSyncManager->slotSyncMenu( 999 ); 2685 mSyncManager->slotSyncMenu( 999 );
2645 } 2686 }
2646 setCaption( i18n("Pi-Sync successful!") ); 2687 setCaption( i18n("Pi-Sync successful!") );
2647} 2688}
2648void MainWindow::printListView() 2689void MainWindow::printListView()
2649{ 2690{
2650 2691
2651 QString message = i18n("You can make a printout of the <b>List View</b> and the list view in the <b>Search Dialog</b>! To do this, please go to the <b>List View/Search Dialog</b>. Right click on the list. Select in the popup menu the entry <b>Print complete list</b>. That prints the list as you see it. You can remove items from the list before printing without deleting the corresponding event/todo! Simply select all items you do not want to print out. Then right click on one of the items and choose <b>Hide selected items</b>. After that you can print the list without these items."); 2692 QString message = i18n("You can make a printout of the <b>List View</b> and the list view in the <b>Search Dialog</b>! To do this, please go to the <b>List View/Search Dialog</b>. Right click on the list. Select in the popup menu the entry <b>Print complete list</b>. That prints the list as you see it. You can remove items from the list before printing without deleting the corresponding event/todo! Simply select all items you do not want to print out. Then right click on one of the items and choose <b>Hide selected items</b>. After that you can print the list without these items.");
2652 2693
2653 KMessageBox::information( this, message); 2694 KMessageBox::information( this, message);
2654} 2695}
2655void MainWindow::printSel( ) 2696void MainWindow::printSel( )
2656{ 2697{
2657 mView->viewManager()->agendaView()->agenda()->printSelection(); 2698 mView->viewManager()->agendaView()->agenda()->printSelection();