From 9e43ebbe5867b2da957bb17c35bd357715424cba Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 09 Apr 2005 20:21:58 +0000 Subject: todo tt --- diff --git a/bin/kdepim/korganizer/germantranslation.txt b/bin/kdepim/korganizer/germantranslation.txt index b4e26c2..5257bff 100644 --- a/bin/kdepim/korganizer/germantranslation.txt +++ b/bin/kdepim/korganizer/germantranslation.txt @@ -1335,6 +1335,18 @@ { " on "," am " }, { "On: ","Am: " }, { "The recurrence is computed from the start datetime!","Die Wiederholung wird vom Startwert aus berechnet!" }, +{ "Start/Stop todo...","Starte/Stoppe Todo..." }, +{ "Color for running todos:","Farbe für laufende Todos:" }, +{ "The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?","Das Todo\n%1\nist gestartet.\nWollen Sie es\nauf gestoppt setzen?" }, +{ "Todo is started","Todo is gestarted" }, +{ "Stop todo","Stoppe Todo" }, +{ "Todo is stopped","Todo ist gestoppt" }, +{ "Start todo","Starte Todo" }, +{ "The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?","Das Todo\n%1\nist gestoppt.\nWollen Sie es auf\ngestartet setzen?" }, +{ "","" }, +{ "","" }, +{ "","" }, +{ "","" }, { "","" }, { "","" }, { "","" }, diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp index 5879a2d..e8c7c76 100644 --- a/korganizer/koprefs.cpp +++ b/korganizer/koprefs.cpp @@ -62,13 +62,9 @@ KOPrefs::KOPrefs() : QColor defaultWorkingHoursColor = QColor(170,223,150);//160,160,160); QColor defaultTodoDueTodayColor = QColor(255,220,100); QColor defaultTodoOverdueColor = QColor(255,153,125); - - + QColor defaultTodoRunColor = QColor(99,194,30); KPrefs::setCurrentGroup("General"); - - addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); - addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true); addItemBool("ShowIconNewEvent",&mShowIconNewEvent,true); addItemBool("ShowIconSearch",&mShowIconSearch,true); @@ -217,6 +213,7 @@ KOPrefs::KOPrefs() : addItemColor("WorkingHours Color",&mWorkingHoursColor,defaultWorkingHoursColor); addItemColor("Todo due today Color",&mTodoDueTodayColor,defaultTodoDueTodayColor); addItemColor("Todo overdue Color",&mTodoOverdueColor,defaultTodoOverdueColor); + addItemColor("Todo running Color",&mTodoRunColor,defaultTodoRunColor); addItemColor("MonthViewEvenColor",&mMonthViewEvenColor,QColor( 160,160,255 )); addItemColor("MonthViewOddColor",&mMonthViewOddColor,QColor( 160,255,160 )); addItemColor("MonthViewHolidayColor",&mMonthViewHolidayColor,QColor( 255,160,160 )); diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h index cf8dae6..d511faa 100644 --- a/korganizer/koprefs.h +++ b/korganizer/koprefs.h @@ -139,6 +139,7 @@ class KOPrefs : public KPimPrefs QColor mWorkingHoursColor; QColor mTodoDueTodayColor; QColor mTodoOverdueColor; + QColor mTodoRunColor; QColor mMonthViewEvenColor; QColor mMonthViewOddColor; QColor mMonthViewHolidayColor; diff --git a/korganizer/koprefsdialog.cpp b/korganizer/koprefsdialog.cpp index 0bbb3bf..a8943de 100644 --- a/korganizer/koprefsdialog.cpp +++ b/korganizer/koprefsdialog.cpp @@ -895,12 +895,22 @@ dummy = topLayout->addWidget(dummy->checkBox(),ii++,0); - QWidget* wid = new QWidget( topFrame ); + QWidget* wid = new QWidget( topFrame ); + // Todo run today color + KPrefsDialogWidColor *todoRunColor = + addWidColor(i18n("Color for running todos:"), + &(KOPrefs::instance()->mTodoRunColor),wid); + QHBoxLayout *widLayout = new QHBoxLayout(wid); + widLayout->addWidget( todoRunColor->label() ); + widLayout->addWidget( todoRunColor->button() ); + topLayout->addWidget(wid,ii++,0); + + wid = new QWidget( topFrame ); // Todo due today color KPrefsDialogWidColor *todoDueTodayColor = addWidColor(i18n("Todo due today color:"), &(KOPrefs::instance()->mTodoDueTodayColor),wid); - QHBoxLayout *widLayout = new QHBoxLayout(wid); + widLayout = new QHBoxLayout(wid); widLayout->addWidget( todoDueTodayColor->label() ); widLayout->addWidget( todoDueTodayColor->button() ); topLayout->addWidget(wid,ii++,0); diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp index 935a5f5..7ee1eef 100644 --- a/korganizer/kotodoview.cpp +++ b/korganizer/kotodoview.cpp @@ -481,6 +481,8 @@ KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : SLOT (cancelTodo())); mItemPopupMenu->insertSeparator(); + mItemPopupMenu->insertItem( i18n("Start/Stop todo..."), this, + SLOT (toggleRunningItem())); mItemPopupMenu->insertItem( i18n("New Todo..."), this, SLOT (newTodo())); mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, @@ -1099,17 +1101,43 @@ void KOTodoView::itemDoubleClicked(QListViewItem *item) newTodo(); return; } else { - if ( row == 1 || row == 2 ) { + if ( row == 2 ) { mActiveItem = (KOTodoViewItem *) item; newSubTodo(); return; } + if ( row == 1 ) { + mActiveItem = (KOTodoViewItem *) item; + toggleRunningItem(); + return; + } } if ( KOPrefs::instance()->mEditOnDoubleClick ) editItem( item ); else showItem( item , QPoint(), 0 ); } +void KOTodoView::toggleRunningItem() +{ + qDebug("KOTodoView::toggleRunning() "); + if ( ! mActiveItem ) + return; + Todo * t = mActiveItem->todo(); + if ( t->isRunning() ) { + int result = KMessageBox::warningContinueCancel(this, + i18n("The todo\n%1\nis started.\nDo you want to set\nthe state to stopped?").arg(mActiveItem->text(0).left( 20 ) ),i18n("Todo is started"),i18n("Stop todo"),i18n("Cancel"), true); + if (result != KMessageBox::Continue) return; + t->setRunning( false ); + mActiveItem->construct(); + } else { + int result = KMessageBox::warningContinueCancel(this, + i18n("The todo\n%1\nis stopped.\nDo you want to set\nthe state to started?").arg(mActiveItem->text(0).left( 20 ) ),i18n("Todo is stopped"),i18n("Start todo"),i18n("Cancel"), true); + if (result != KMessageBox::Continue) return; + t->setRunning( true ); + mActiveItem->construct(); + } +} + void KOTodoView::itemClicked(QListViewItem *item) { //qDebug("KOTodoView::itemClicked %d", item); diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h index d0788a9..d368513 100644 --- a/korganizer/kotodoview.h +++ b/korganizer/kotodoview.h @@ -206,6 +206,7 @@ class KOTodoView : public KOrg::BaseView void purgeCompletedSignal(); protected slots: + void toggleRunningItem(); void paintNeeded(); void processSelectionChange(); void addQuickTodo(); diff --git a/korganizer/kotodoviewitem.cpp b/korganizer/kotodoviewitem.cpp index 6559119..66f8d06 100644 --- a/korganizer/kotodoviewitem.cpp +++ b/korganizer/kotodoviewitem.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "kotodoviewitem.h" @@ -120,24 +121,35 @@ void KOTodoViewItem::construct() - if (mTodo->hasStartDate()) { - setText(5, mTodo->dtStartDateStr()); - QDate d = mTodo->dtStart().date(); - skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); - - if (mTodo->doesFloat()) { - setText(6,""); - } - else { - setText(6,mTodo->dtStartTimeStr()); - QTime t = mTodo->dtStart().time(); + keyd = ""; + keyt = ""; + + if (mTodo->isRunning() ) { + QDate d = mTodo->runStart().date(); + QTime t = mTodo->runStart().time(); skeyt.sprintf("%02d%02d",t.hour(),t.minute()); - - } + skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); + keyd = KGlobal::locale()->formatDate( d ); + keyt = KGlobal::locale()->formatTime( t ); + } else { - setText(5,""); - setText(6,""); + + if (mTodo->hasStartDate()) { + keyd = mTodo->dtStartDateStr(); + QDate d = mTodo->dtStart().date(); + skeyd.sprintf("%04d%02d%02d",d.year(),d.month(),d.day()); + + if ( !mTodo->doesFloat()) { + keyt = mTodo->dtStartTimeStr(); + QTime t = mTodo->dtStart().time(); + skeyt.sprintf("%02d%02d",t.hour(),t.minute()); + + } + + } } + setText(5,keyd); + setText(6,keyt); setSortKey(5,skeyd); setSortKey(6,skeyt); @@ -368,13 +380,21 @@ void KOTodoViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, i // maybe we are in flat-display-mode if ( !firstChild() ) openMode = false; - int odue = mTodo->hasDueSubTodo( openMode ); - if (odue == 2) { - colorToSet = KOPrefs::instance()->mTodoOverdueColor; - setColor = true; - } else if ( odue == 1 ) { - colorToSet = KOPrefs::instance()->mTodoDueTodayColor; + bool colorRunning = mTodo->isRunning(); + if ( ! colorRunning && openMode ) + colorRunning = mTodo->hasRunningSub(); + if ( colorRunning ) { setColor = true; + colorToSet = KOPrefs::instance()->mTodoRunColor; + } else { + int odue = mTodo->hasDueSubTodo( openMode ); + if (odue == 2) { + colorToSet = KOPrefs::instance()->mTodoOverdueColor; + setColor = true; + } else if ( odue == 1 ) { + colorToSet = KOPrefs::instance()->mTodoDueTodayColor; + setColor = true; + } } diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index a496404..7dee4cd 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -35,6 +35,8 @@ Todo::Todo(): Incidence() mCompleted = getEvenTime(QDateTime::currentDateTime()); mHasCompletedDate = false; mPercentComplete = 0; + mRunning = false; + mRunSaveTimer = 0; } Todo::Todo(const Todo &t) : Incidence(t) @@ -44,13 +46,55 @@ Todo::Todo(const Todo &t) : Incidence(t) mCompleted = t.mCompleted; mHasCompletedDate = t.mHasCompletedDate; mPercentComplete = t.mPercentComplete; + mRunning = false; + mRunSaveTimer = 0; } Todo::~Todo() { + setRunning( false ); +} + +void Todo::setRunning( bool run ) +{ + if ( run == mRunning ) + return; + if ( !mRunSaveTimer ) { + mRunSaveTimer = new QTimer ( this ); + connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); + } + mRunning = run; + if ( mRunning ) { + mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min + mRunStart = QDateTime::currentDateTime(); + } else { + mRunSaveTimer->stop(); + saveRunningInfoToFile(); + } +} +void Todo::saveRunningInfoToFile() +{ + qDebug("Todo::saveRunningInfoToFile() "); } +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() { return new Todo(*this); diff --git a/libkcal/todo.h b/libkcal/todo.h index a22d4b7..fe43357 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h @@ -25,13 +25,16 @@ #include "incidence.h" +#include + namespace KCal { /** This class provides a Todo in the sense of RFC2445. */ -class Todo : public Incidence + class Todo : public QObject,public Incidence { + Q_OBJECT public: Todo(); Todo(const Todo &); @@ -114,8 +117,17 @@ class Todo : public Incidence bool contains ( Todo*); void checkSetCompletedFalse(); bool setRecurDates(); - + bool isRunning() {return mRunning;} + bool hasRunningSub(); + void setRunning( bool ); + int runTime(); + QDateTime runStart () const { return mRunStart;} + public slots: + void saveRunningInfoToFile(); private: + bool mRunning; + QTimer * mRunSaveTimer; + QDateTime mRunStart; bool accept(Visitor &v) { return v.visit(this); } QDateTime mDtDue; // due date of todo -- cgit v0.9.0.2