summaryrefslogtreecommitdiff
path: root/core/pim/today/plugins/todolist/todopluginwidget.cpp
Unidiff
Diffstat (limited to 'core/pim/today/plugins/todolist/todopluginwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/today/plugins/todolist/todopluginwidget.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/core/pim/today/plugins/todolist/todopluginwidget.cpp b/core/pim/today/plugins/todolist/todopluginwidget.cpp
new file mode 100644
index 0000000..2a0e5a3
--- a/dev/null
+++ b/core/pim/today/plugins/todolist/todopluginwidget.cpp
@@ -0,0 +1,132 @@
1/*
2 * todopluginwidget.cpp
3 *
4 * copyright : (c) 2002 by Maximilian Reiß
5 * email : harlekin@handhelds.org
6 *
7 */
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "todopluginwidget.h"
18
19#include <qvaluelist.h>
20#include <qtl.h>
21#include <qstring.h>
22#include <qscrollview.h>
23#include <qobject.h>
24#include <qlayout.h>
25
26#include <qpe/config.h>
27#include <qpe/timestring.h>
28#include <qpe/qcopenvelope_qws.h>
29
30TodolistPluginWidget::TodolistPluginWidget( QWidget *parent, const char* name)
31 : QWidget(parent, name ) {
32
33 todoLabel= 0l;
34
35 todo = 0l;
36 if ( todo ) {
37 delete todo;
38 }
39 todo = new ToDoDB();
40
41 readConfig();
42 m_maxCharClip = 36;
43 getTodo();
44}
45
46TodolistPluginWidget::~TodolistPluginWidget() {
47 delete todo;
48}
49
50void TodolistPluginWidget::readConfig() {
51 Config cfg( "todaytodolistplugin" );
52 cfg.setGroup( "config" );
53 m_maxLinesTask = cfg.readNumEntry( "maxlinestask", 5 );
54}
55
56
57/**
58 * Get the todos
59 */
60void TodolistPluginWidget::getTodo() {
61
62 QVBoxLayout* layoutTodo = new QVBoxLayout( this );
63
64 if ( todoLabel ) {
65 delete todoLabel;
66 }
67
68 todoLabel = new OClickableLabel( this );
69 todoLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
70 connect( todoLabel, SIGNAL( clicked() ), this, SLOT( startTodolist() ) );
71 QString output;
72 QString tmpout;
73 int count = 0;
74 int ammount = 0;
75
76 // get overdue todos first
77 QValueList<ToDoEvent> overDueList = todo->overDue();
78 qBubbleSort(overDueList);
79 for ( QValueList<ToDoEvent>::Iterator it = overDueList.begin();
80 it!=overDueList.end(); ++it ) {
81 if (!(*it).isCompleted() && ( ammount < m_maxLinesTask ) ) {
82 QString desc = (*it).summary();
83 if( desc.isEmpty() ) {
84 desc = (*it).description();
85 }
86 tmpout += "<font color=#e00000><b>-" + desc.mid(0, m_maxCharClip) + "</b></font><br>";
87 ammount++;
88 }
89 }
90
91 // get total number of still open todos
92 QValueList<ToDoEvent> openTodo = todo->rawToDos();
93 qBubbleSort( openTodo );
94 for ( QValueList<ToDoEvent>::Iterator it=openTodo.begin();
95 it!=openTodo.end(); ++it ) {
96 if ( !(*it).isCompleted() ){
97 count +=1;
98 // not the overdues, we allready got them, and not if we are
99 // over the maxlines
100 if ( !(*it).isOverdue() && ( ammount < m_maxLinesTask ) ) {
101 QString desc = (*it).summary();
102 if( desc.isEmpty() ) {
103 desc = (*it).description();
104 }
105 tmpout += "<b>-</b>" + desc.mid(0, m_maxCharClip) + "<br>";
106 ammount++;
107 }
108 }
109 }
110
111
112 if ( count > 0 ) {
113 if( count == 1 ) {
114 output += QObject::tr( "There is <b> 1</b> active task: <br>" );
115 } else {
116 output += QObject::tr( "There are <b> %1</b> active tasks: <br>" ).arg(count);
117 }
118 output += tmpout;
119 } else {
120 output = QObject::tr( "No active tasks" );
121 }
122 todoLabel->setText( output );
123 layoutTodo->addWidget( todoLabel );
124}
125
126/**
127 * start the todolist
128 */
129void TodolistPluginWidget::startTodolist() {
130 QCopEnvelope e("QPE/System", "execute(QString)");
131 e << QString("todolist");
132}