summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-09-25 02:09:22 (UTC)
committer zautrix <zautrix>2005-09-25 02:09:22 (UTC)
commit3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6 (patch) (side-by-side diff)
tree0d88d48dc1b9198c9c2deed6b55c70deffcfeadd
parent181bc87d92ecc48cb07c288cb2d135d8fde56716 (diff)
downloadkdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.zip
kdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.tar.gz
kdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.tar.bz2
todo timer fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/main.cpp3
-rw-r--r--korganizer/mainwindow.cpp15
-rw-r--r--libkcal/todo.cpp12
3 files changed, 26 insertions, 4 deletions
diff --git a/korganizer/main.cpp b/korganizer/main.cpp
index a96f7c2..9410c6a 100644
--- a/korganizer/main.cpp
+++ b/korganizer/main.cpp
@@ -60,55 +60,58 @@ int main( int argc, char **argv )
printf(" -newEvent: New Event dialog\n");
printf(" -showList: List view\n");
printf(" -showDay: Day view\n");
printf(" -showWWeek: Work Week view\n");
printf(" -showWeek: Week view\n");
printf(" -showTodo: Todo view\n");
printf(" -showJournal: Journal view\n");
printf(" -showKO: Next Days view\n");
printf(" -showWNext: What's Next view\n");
printf(" -showNextXView: Next X View\n");
printf(" -new[Y] and -show[X] may be used togehther\n");
printf(" KO/Pi is exiting now. Bye!\n");
exitHelp = true;
}
}
if ( ! exitHelp ) {
KGlobal::setAppName( "korganizer" );
QString fileName ;
#ifndef DESKTOP_VERSION
fileName = getenv("QPEDIR");
KGlobal::iconLoader()->setIconPath( fileName +"/pics/kdepim/korganizer/");
#else
fileName = qApp->applicationDirPath () + "/kdepim/korganizer/";
KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName));
#endif
KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "korganizer")));
QApplication::setFont( KPimGlobalPrefs::instance()->mApplicationFont );
KPimGlobalPrefs::instance()->setGlobalConfig();
MainWindow m;
#ifndef DESKTOP_VERSION
QObject::connect( &a, SIGNAL (appMessage ( const QCString &, const QByteArray & )),&m, SLOT(receiveStart( const QCString&, const QByteArray& )));
a.showMainWidget(&m );
#else
a.setMainWidget(&m );
m.show();
//m.resize( 800, 600 );
//QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
#endif
if ( argc > 1 ) {
QCString command = argv[1];
if ( argc > 2 )
command += argv[2];
m.recieve(command, QByteArray() );
}
+#ifndef DESKTOP_VERSION
+ QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
+#endif
a.exec();
dumpMissing();
KPimGlobalPrefs::instance()->writeConfig();
}
qDebug("KO: Bye! ");
}
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index d1e369c..05e5087 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,77 +1,77 @@
#include <stdlib.h>
#include <qaction.h>
#include <qpopupmenu.h>
#include <qpainter.h>
#include <qwhatsthis.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qlineedit.h>
#include <qtextcodec.h>
#include <qfile.h>
#include <qdir.h>
#include <qapp.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <qspinbox.h>
#include <qcheckbox.h>
#include <qmap.h>
#include <qwmatrix.h>
#include <qtextbrowser.h>
#include <qtextstream.h>
#ifndef DESKTOP_VERSION
#include <qpe/global.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qtopia/alarmserver.h>
#include <qtopia/qcopenvelope_qws.h>
-#include <unistd.h> // for sleep
+//#include <unistd.h> // for sleep
#else
#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 "kojournalview.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 "ktoolbar.h"
#include "klocale.h"
#include "kconfig.h"
#include "externalapphandler.h"
#include <kglobalsettings.h>
using namespace KCal;
#ifndef _WIN32_
#include <unistd.h>
#else
#ifdef _OL_IMPORT_
#include "koimportoldialog.h"
#endif
#endif
#include "mainwindow.h"
class KOex2phonePrefs : public QDialog
{
@@ -2000,139 +2000,144 @@ void MainWindow::backupAllFiles()
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 );
+#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 );
+#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:
@@ -2461,98 +2466,104 @@ void MainWindow::setCaptionToDates()
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 );
+#endif
KPimGlobalPrefs::instance()->mBackupEnabled = enabled;
backupAllFiles();
+#ifndef DESKTOP_VERSION
+ 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 );
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index f7d40ad..70a7711 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,79 +1,83 @@
/*
This file is part of libkcal.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <kglobal.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kdebug.h>
#include <qregexp.h>
#include <qfileinfo.h>
#include "calendarlocal.h"
#include "icalformat.h"
#include "todo.h"
+#ifndef DESKTOP_VERSION
+#include <qpe/qpeapplication.h>
+#endif
+
#define SAVETIMER_TIMEOUT_SECONDS 300
//#define SAVETIMER_TIMEOUT_SECONDS 8
#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5
using namespace KCal;
Todo::Todo(): QObject(), Incidence()
{
// mStatus = TENTATIVE;
mHasDueDate = false;
setHasStartDate( false );
mCompleted = getEvenTime(QDateTime::currentDateTime());
mHasCompletedDate = false;
mPercentComplete = 0;
mRunning = false;
mRunSaveTimer = 0;
setFloats( true );
mCurrentTimerDelay = 0;
}
Todo::Todo(const Todo &t) : QObject(),Incidence(t)
{
mDtDue = t.mDtDue;
mHasDueDate = t.mHasDueDate;
mCompleted = t.mCompleted;
mHasCompletedDate = t.mHasCompletedDate;
mPercentComplete = t.mPercentComplete;
mRunning = false;
mRunSaveTimer = 0;
mCurrentTimerDelay = 0;
}
Todo::~Todo()
{
setRunning( false );
//qDebug("Todo::~Todo() ");
}
void Todo::setRunningFalse( QString s )
{
if ( ! mRunning )
return;
mRunning = false;
if ( mRunSaveTimer )
mRunSaveTimer->stop();
saveRunningInfoToFile( s );
}
@@ -94,142 +98,146 @@ void Todo::setRunning( bool run )
mRunSaveTimer = new QTimer ( this );
connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) );
}
mRunning = run;
mRunLastSave = QDateTime::currentDateTime();
if ( mRunning ) {
restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
mRunStart = QDateTime::currentDateTime();
} else {
mRunSaveTimer->stop();
saveRunningInfoToFile();
}
}
void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
{
if ( !mRunning) return;
mRunning = false;
mRunStart = start;
mRunEnd = end;
saveRunningInfoToFile( comment );
}
void Todo::restartSaveTimer( int secs )
{
mRunSaveTimer->start( secs * 1000 );
mRunLastSave = QDateTime::currentDateTime();
mCurrentTimerDelay = secs;
}
void Todo::timerSlotSaveRunningInfoToFile()
{
mRunEnd = QDateTime::currentDateTime();
int secsTo = mRunLastSave.secsTo( mRunEnd );
//if( secsTo == 8 ) ++secsTo;
qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
if ( secsTo > mCurrentTimerDelay ) {
qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
return;
}
int msecs = mRunLastSave.time().msecsTo( mRunEnd.time());
if ( msecs < 0 ) {
restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
return;
}
// qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) {
qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) );
restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS );
return;
-
}
restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS );
saveRunningInfoToFile( QString::null );
}
void Todo::saveRunningInfoToFile()
{
mRunEnd = QDateTime::currentDateTime();
saveRunningInfoToFile( QString::null );
}
void Todo::saveRunningInfoToFile( QString comment )
{
+#ifndef DESKTOP_VERSION
+ QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable );
+#endif
//qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
qDebug("Running time < 15 seconds. Skipped. ");
return;
}
QString dir = KGlobalSettings::timeTrackerDir();
//qDebug("%s ", dir.latin1());
QString file = "%1%2%3-%4%5%6-";
file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
file.replace ( QRegExp (" "), "0" );
file += uid();
//qDebug("File %s ",file.latin1() );
CalendarLocal cal;
cal.setLocalTime();
Todo * to = (Todo*) clone();
to->setFloats( false );
to->setDtStart( mRunStart );
to->setHasStartDate( true );
to->setDtDue( mRunEnd );
to->setHasDueDate( true );
to->setUid( file );
if ( !comment.isEmpty() ) {
QString des = to->description();
if ( des.isEmpty () )
to->setDescription( "TT-Note: " + comment );
else
to->setDescription( "TT-Note: " + comment +"\n" + des );
}
cal.addIncidence( to );
ICalFormat format( false );
file = dir +"/" +file +".ics";
format.save( &cal, file );
saveParents();
-
+#ifndef DESKTOP_VERSION
+ QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable );
+#endif
}
void Todo::saveParents()
{
if (!relatedTo() )
return;
Incidence * inc = relatedTo();
if ( inc->typeID() != todoID )
return;
Todo* to = (Todo*)inc;
bool saveTodo = false;
QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
QFileInfo fi ( file );
if ( fi.exists() ) {
if ( fi.lastModified () < to->lastModified ())
saveTodo = true;
} else {
saveTodo = true;
}
if ( saveTodo ) {
CalendarLocal cal;
cal.setLocalTime();
Todo * par = (Todo *) to->clone();
cal.addIncidence( par );
ICalFormat format( false );
format.save( &cal, file );
}
to->saveParents();
}
int Todo::runTime()
{
if ( !mRunning )
return 0;
return mRunStart.secsTo( QDateTime::currentDateTime() );
}
bool Todo::hasRunningSub()
{
if ( mRunning )
return true;
Incidence *aTodo;
for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
if ( ((Todo*)aTodo)->hasRunningSub() )
return true;
}
return false;
}
Incidence *Todo::clone()
{