27 #include <tqtooltip.h>
30 #include <tdeglobal.h>
31 #include <kiconloader.h>
32 #include <tdelocale.h>
33 #include <tdeparts/part.h>
34 #include <tdepopupmenu.h>
35 #include <kstandarddirs.h>
36 #include <kurllabel.h>
37 #include <libkcal/resourcecalendar.h>
38 #include <libkcal/resourcelocal.h>
39 #include <libkcal/todo.h>
40 #include <libkcal/incidenceformatter.h>
41 #include <libtdepim/kpimprefs.h>
43 #include "korganizeriface_stub.h"
47 #include "todoplugin.h"
49 #include "korganizer/stdcalendar.h"
50 #include "korganizer/koglobals.h"
51 #include "korganizer/incidencechanger.h"
53 #include "todosummarywidget.h"
55 TodoSummaryWidget::TodoSummaryWidget( TodoPlugin *plugin,
56 TQWidget *parent,
const char *name )
57 : Kontact::Summary( parent, name ), mPlugin( plugin )
59 TQVBoxLayout *mainLayout =
new TQVBoxLayout(
this, 3, 3 );
61 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_todo",
62 TDEIcon::Desktop, TDEIcon::SizeMedium );
63 TQWidget *header = createHeader(
this, icon, i18n(
"To-do" ) );
64 mainLayout->addWidget( header );
66 mLayout =
new TQGridLayout( mainLayout, 7, 4, 3 );
67 mLayout->setRowStretch( 6, 1 );
69 mCalendar = KOrg::StdCalendar::self();
71 connect( mCalendar, TQ_SIGNAL( calendarChanged() ), TQ_SLOT( updateView() ) );
72 connect( mPlugin->core(), TQ_SIGNAL( dayChanged(
const TQDate& ) ),
73 TQ_SLOT( updateView() ) );
78 TodoSummaryWidget::~TodoSummaryWidget()
82 void TodoSummaryWidget::updateView()
84 mLabels.setAutoDelete(
true );
86 mLabels.setAutoDelete(
false );
88 TDEConfig config(
"kcmkorgsummaryrc" );
89 config.setGroup(
"Todo" );
90 bool showAllTodos = config.readBoolEntry(
"ShowAllTodos",
false );
92 TDEIconLoader loader(
"tdepim" );
97 TQDate currentDate = TQDate::currentDate();
98 KCal::Todo::List todos = mCalendar->todos();
99 if ( todos.count() > 0 ) {
100 TQPixmap pm = loader.loadIcon(
"todo", TDEIcon::Small );
101 KCal::Todo::List::ConstIterator it;
102 for ( it = todos.begin(); it != todos.end(); ++it ) {
105 bool accepted =
false;
114 todo->
dtDue().date() < currentDate ) {
116 stateText = i18n(
"overdue" );
121 todo->
dtStart().date() < currentDate &&
122 currentDate < todo->dtDue().date() ) {
124 stateText = i18n(
"in progress" );
130 stateText = i18n(
"starts today" );
136 stateText = i18n(
"ends today" );
142 label =
new TQLabel(
this );
143 label->setPixmap( pm );
144 label->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
145 mLayout->addWidget( label, counter, 0 );
146 mLabels.append( label );
148 label =
new TQLabel( TQString::number( todo->
percentComplete() ) +
"%",
this );
149 label->setAlignment( AlignHCenter | AlignVCenter );
150 label->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
151 mLayout->addWidget( label, counter, 1 );
152 mLabels.append( label );
154 TQString sSummary = todo->
summary();
158 KURLLabel *urlLabel =
new KURLLabel(
this );
159 urlLabel->setText( sSummary );
160 urlLabel->setURL( todo->
uid() );
161 urlLabel->installEventFilter(
this );
162 urlLabel->setTextFormat( TQt::RichText );
163 mLayout->addWidget( urlLabel, counter, 2 );
164 mLabels.append( urlLabel );
166 connect( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
167 this, TQ_SLOT( viewTodo(
const TQString& ) ) );
168 connect( urlLabel, TQ_SIGNAL( rightClickedURL(
const TQString& ) ),
169 this, TQ_SLOT( popupMenu(
const TQString& ) ) );
171 TQString tipText( KCal::IncidenceFormatter::toolTipStr( mCalendar, todo, currentDate,
true ) );
172 if ( !tipText.isEmpty() ) {
173 TQToolTip::add( urlLabel, tipText );
176 label =
new TQLabel( stateText,
this );
177 label->setAlignment( AlignLeft | AlignVCenter );
178 label->setSizePolicy( TQSizePolicy::Maximum, TQSizePolicy::Maximum );
179 mLayout->addWidget( label, counter, 3 );
180 mLabels.append( label );
186 if ( counter == 0 ) {
187 TQLabel *noTodos =
new TQLabel( i18n(
"No to-dos pending" ),
this );
188 noTodos->setAlignment( AlignHCenter | AlignVCenter );
189 mLayout->addWidget( noTodos, 0, 1 );
190 mLabels.append( noTodos );
193 for ( label = mLabels.first(); label; label = mLabels.next() )
197 void TodoSummaryWidget::viewTodo(
const TQString &uid )
199 mPlugin->core()->selectPlugin(
"kontact_todoplugin" );
200 KOrganizerIface_stub iface(
"korganizer",
"KOrganizerIface" );
201 iface.editIncidence( uid );
204 void TodoSummaryWidget::removeTodo(
const TQString &uid )
206 mPlugin->core()->selectPlugin(
"kontact_todoplugin" );
207 KOrganizerIface_stub iface(
"korganizer",
"KOrganizerIface" );
208 iface.deleteIncidence( uid,
false );
211 void TodoSummaryWidget::completeTodo(
const TQString &uid )
214 IncidenceChanger *changer =
new IncidenceChanger( mCalendar,
this );
215 if ( !todo->
isReadOnly() && changer->beginChange( todo, 0, TQString() ) ) {
218 changer->changeIncidence( oldTodo, todo, KOGlobals::COMPLETION_MODIFIED,
this );
219 changer->endChange( todo, 0, TQString() );
225 void TodoSummaryWidget::popupMenu(
const TQString &uid )
227 TDEPopupMenu popup(
this );
228 TQToolTip::remove(
this );
229 popup.insertItem( i18n(
"&Edit To-do..." ), 0 );
230 popup.insertItem( TDEGlobal::iconLoader()->loadIcon(
"edit-delete", TDEIcon::Small),
231 i18n(
"&Delete To-do" ), 1 );
234 popup.insertItem( TDEGlobal::iconLoader()->loadIcon(
"checkedbox", TDEIcon::Small),
235 i18n(
"&Mark To-do Completed" ), 2 );
238 switch ( popup.exec( TQCursor::pos() ) ) {
251 bool TodoSummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
253 if ( obj->inherits(
"KURLLabel" ) ) {
254 KURLLabel* label =
static_cast<KURLLabel*
>( obj );
255 if ( e->type() == TQEvent::Enter )
256 emit message( i18n(
"Edit To-do: \"%1\"" ).arg( label->text() ) );
257 if ( e->type() == TQEvent::Leave )
258 emit message( TQString() );
261 return Kontact::Summary::eventFilter( obj, e );
264 TQStringList TodoSummaryWidget::configModules()
const
266 return TQStringList(
"kcmtodosummary.desktop" );
269 #include "todosummarywidget.moc"
Incidence * relatedTo() const
bool hasStartDate() const
void setCompleted(bool completed)
TQDateTime dtStart(bool first=false) const
int percentComplete() const
TQDateTime dtDue(bool first=false) const