1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/*
This file is part of Kontact.
Copyright (c) 2003 Tobias Koenig <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include <qcursor.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <kdialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kparts/part.h>
#include <kpopupmenu.h>
#include <kstandarddirs.h>
#include <kurllabel.h>
#include <libkcal/resourcecalendar.h>
#include <libkcal/resourcelocal.h>
#include <libkcal/todo.h>
#include <libkcal/incidenceformatter.h>
#include <libkdepim/kpimprefs.h>
#include "korganizeriface_stub.h"
#include "core.h"
#include "plugin.h"
#include "todoplugin.h"
#include "korganizer/stdcalendar.h"
#include "korganizer/koglobals.h"
#include "korganizer/incidencechanger.h"
#include "todosummarywidget.h"
TodoSummaryWidget::TodoSummaryWidget( TodoPlugin *plugin,
QWidget *parent, const char *name )
: Kontact::Summary( parent, name ), mPlugin( plugin )
{
QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_todo",
KIcon::Desktop, KIcon::SizeMedium );
QWidget *header = createHeader( this, icon, i18n( "To-do" ) );
mainLayout->addWidget( header );
mLayout = new QGridLayout( mainLayout, 7, 4, 3 );
mLayout->setRowStretch( 6, 1 );
mCalendar = KOrg::StdCalendar::self();
mCalendar->load();
connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
connect( mPlugin->core(), SIGNAL( dayChanged( const QDate& ) ),
SLOT( updateView() ) );
updateView();
}
TodoSummaryWidget::~TodoSummaryWidget()
{
}
void TodoSummaryWidget::updateView()
{
mLabels.setAutoDelete( true );
mLabels.clear();
mLabels.setAutoDelete( false );
KConfig config( "kcmkorgsummaryrc" );
config.setGroup( "Todo" );
bool showAllTodos = config.readBoolEntry( "ShowAllTodos", false );
KIconLoader loader( "kdepim" );
QLabel *label = 0;
int counter = 0;
QDate currentDate = QDate::currentDate();
KCal::Todo::List todos = mCalendar->todos();
if ( todos.count() > 0 ) {
QPixmap pm = loader.loadIcon( "todo", KIcon::Small );
KCal::Todo::List::ConstIterator it;
for ( it = todos.begin(); it != todos.end(); ++it ) {
KCal::Todo *todo = *it;
bool accepted = false;
QString stateText;
// show all incomplete todos
if ( showAllTodos && !todo->isCompleted())
accepted = true;
// show uncomplete todos from the last days
if ( todo->hasDueDate() && !todo->isCompleted() &&
todo->dtDue().date() < currentDate ) {
accepted = true;
stateText = i18n( "overdue" );
}
// show todos which started somewhere in the past and has to be finished in future
if ( todo->hasStartDate() && todo->hasDueDate() &&
todo->dtStart().date() < currentDate &&
currentDate < todo->dtDue().date() ) {
accepted = true;
stateText = i18n( "in progress" );
}
// all todos which start today
if ( todo->hasStartDate() && todo->dtStart().date() == currentDate ) {
accepted = true;
stateText = i18n( "starts today" );
}
// all todos which end today
if ( todo->hasDueDate() && todo->dtDue().date() == currentDate ) {
accepted = true;
stateText = i18n( "ends today" );
}
if ( !accepted )
continue;
label = new QLabel( this );
label->setPixmap( pm );
label->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
mLayout->addWidget( label, counter, 0 );
mLabels.append( label );
label = new QLabel( QString::number( todo->percentComplete() ) + "%", this );
label->setAlignment( AlignHCenter | AlignVCenter );
label->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
mLayout->addWidget( label, counter, 1 );
mLabels.append( label );
QString sSummary = todo->summary();
if ( todo->relatedTo() ) { // show parent only, not entire ancestry
sSummary = todo->relatedTo()->summary() + ":" + todo->summary();
}
KURLLabel *urlLabel = new KURLLabel( this );
urlLabel->setText( sSummary );
urlLabel->setURL( todo->uid() );
urlLabel->installEventFilter( this );
urlLabel->setTextFormat( Qt::RichText );
mLayout->addWidget( urlLabel, counter, 2 );
mLabels.append( urlLabel );
connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
this, SLOT( viewTodo( const QString& ) ) );
connect( urlLabel, SIGNAL( rightClickedURL( const QString& ) ),
this, SLOT( popupMenu( const QString& ) ) );
QString tipText( KCal::IncidenceFormatter::toolTipString( todo, true ) );
if ( !tipText.isEmpty() ) {
QToolTip::add( urlLabel, tipText );
}
label = new QLabel( stateText, this );
label->setAlignment( AlignLeft | AlignVCenter );
label->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
mLayout->addWidget( label, counter, 3 );
mLabels.append( label );
counter++;
}
}
if ( counter == 0 ) {
QLabel *noTodos = new QLabel( i18n( "No to-dos pending" ), this );
noTodos->setAlignment( AlignHCenter | AlignVCenter );
mLayout->addWidget( noTodos, 0, 1 );
mLabels.append( noTodos );
}
for ( label = mLabels.first(); label; label = mLabels.next() )
label->show();
}
void TodoSummaryWidget::viewTodo( const QString &uid )
{
mPlugin->core()->selectPlugin( "kontact_todoplugin" );//ensure loaded
KOrganizerIface_stub iface( "korganizer", "KOrganizerIface" );
iface.editIncidence( uid );
}
void TodoSummaryWidget::removeTodo( const QString &uid )
{
mPlugin->core()->selectPlugin( "kontact_todoplugin" );//ensure loaded
KOrganizerIface_stub iface( "korganizer", "KOrganizerIface" );
iface.deleteIncidence( uid, false );
}
void TodoSummaryWidget::completeTodo( const QString &uid )
{
KCal::Todo *todo = mCalendar->todo( uid );
IncidenceChanger *changer = new IncidenceChanger( mCalendar, this );
if ( !todo->isReadOnly() && changer->beginChange( todo ) ) {
KCal::Todo *oldTodo = todo->clone();
todo->setCompleted( QDateTime::currentDateTime() );
changer->changeIncidence( oldTodo, todo, KOGlobals::COMPLETION_MODIFIED );
changer->endChange( todo );
delete oldTodo;
updateView();
}
}
void TodoSummaryWidget::popupMenu( const QString &uid )
{
KPopupMenu popup( this );
QToolTip::remove( this );
popup.insertItem( i18n( "&Edit To-do..." ), 0 );
popup.insertItem( KGlobal::iconLoader()->loadIcon( "editdelete", KIcon::Small),
i18n( "&Delete To-do" ), 1 );
KCal::Todo *todo = mCalendar->todo( uid );
if ( !todo->isCompleted() ) {
popup.insertItem( KGlobal::iconLoader()->loadIcon( "checkedbox", KIcon::Small),
i18n( "&Mark To-do Completed" ), 2 );
}
switch ( popup.exec( QCursor::pos() ) ) {
case 0:
viewTodo( uid );
break;
case 1:
removeTodo( uid );
break;
case 2:
completeTodo( uid );
break;
}
}
bool TodoSummaryWidget::eventFilter( QObject *obj, QEvent* e )
{
if ( obj->inherits( "KURLLabel" ) ) {
KURLLabel* label = static_cast<KURLLabel*>( obj );
if ( e->type() == QEvent::Enter )
emit message( i18n( "Edit To-do: \"%1\"" ).arg( label->text() ) );
if ( e->type() == QEvent::Leave )
emit message( QString::null );
}
return Kontact::Summary::eventFilter( obj, e );
}
QStringList TodoSummaryWidget::configModules() const
{
return QStringList( "kcmtodosummary.desktop" );
}
#include "todosummarywidget.moc"
|