kontact Library API Documentation

todosummarywidget.cpp

00001 /*
00002     This file is part of Kontact.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 
00027 #include <kdialog.h>
00028 #include <kglobal.h>
00029 #include <kiconloader.h>
00030 #include <klocale.h>
00031 #include <kparts/part.h>
00032 #include <kstandarddirs.h>
00033 #include <kurllabel.h>
00034 #include <qtooltip.h>
00035 #include <libkcal/resourcecalendar.h>
00036 #include <libkcal/resourcelocal.h>
00037 #include <libkcal/todo.h>
00038 #include <libkdepim/kpimprefs.h>
00039 
00040 #include <korganizer/stdcalendar.h>
00041 
00042 #include "core.h"
00043 #include "plugin.h"
00044 #include "todoplugin.h"
00045 
00046 #include "todosummarywidget.h"
00047 
00048 TodoSummaryWidget::TodoSummaryWidget( TodoPlugin *plugin,
00049                                       QWidget *parent, const char *name )
00050   : Kontact::Summary( parent, name ), mPlugin( plugin )
00051 {
00052   QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );
00053 
00054   QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_todo",
00055                    KIcon::Desktop, KIcon::SizeMedium );
00056   QWidget *header = createHeader( this, icon, i18n( "Todos" ) );
00057   mainLayout->addWidget( header );
00058 
00059   mLayout = new QGridLayout( mainLayout, 7, 5, 3 );
00060   mLayout->setRowStretch( 6, 1 );
00061 
00062   mCalendar = KOrg::StdCalendar::self();
00063   mCalendar->load();
00064 
00065   connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
00066   connect( mPlugin->core(), SIGNAL( dayChanged( const QDate& ) ),
00067            SLOT( updateView() ) );
00068 
00069   updateView();
00070 }
00071 
00072 void TodoSummaryWidget::updateView()
00073 {
00074   mLabels.setAutoDelete( true );
00075   mLabels.clear();
00076   mLabels.setAutoDelete( false );
00077 
00078   KConfig config( "kcmkorgsummaryrc" );
00079   config.setGroup( "Todo" );
00080   bool showAllTodos = config.readBoolEntry( "ShowAllTodos", false );
00081 
00082   KIconLoader loader( "korganizer" );
00083 
00084   QLabel *label = 0;
00085   int counter = 0;
00086 
00087   KCal::Todo::List todos = mCalendar->todos();
00088   if ( todos.count() > 0 ) {
00089     QPixmap pm = loader.loadIcon( "todo", KIcon::Small );
00090     KCal::Todo::List::ConstIterator it;
00091     for ( it = todos.begin(); it != todos.end(); ++it ) {
00092       KCal::Todo *todo = *it;
00093 
00094       bool accepted = false;
00095       QString stateText;
00096 
00097       // show all incomplete todos
00098       if ( showAllTodos && !todo->isCompleted())
00099         accepted = accepted || true;
00100 
00101       // show uncomplete todos from the last days
00102       if ( todo->hasDueDate() && !todo->isCompleted() &&
00103            todo->dtDue().date() < QDate::currentDate() ) {
00104         accepted = accepted || true;
00105         stateText = i18n( "overdue" );
00106       }
00107 
00108       // show todos which started somewhere in the past and has to be finished in future
00109       if ( todo->hasStartDate() && todo->hasDueDate() && todo->dtStart().date()
00110            < QDate::currentDate() && QDate::currentDate() < todo->dtDue().date() ) {
00111         accepted = accepted || true;
00112         stateText = i18n( "in progress" );
00113       }
00114 
00115       // all todos which start today
00116       if ( todo->hasStartDate() && todo->dtStart().date() == QDate::currentDate() ) {
00117         accepted = accepted || true;
00118         stateText = i18n( "starts today" );
00119       }
00120 
00121       // all todos which end today
00122       if ( todo->hasDueDate() && todo->dtDue().date() == QDate::currentDate() ) {
00123         accepted = accepted || true;
00124         stateText = i18n( "ends today" );
00125       }
00126 
00127       if ( !accepted )
00128         continue;
00129 
00130       label = new QLabel( this );
00131       label->setPixmap( pm );
00132       label->setMaximumSize( label->minimumSizeHint() );
00133       mLayout->addWidget( label, counter, 0 );
00134       mLabels.append( label );
00135 
00136       label = new QLabel( QString::number( todo->percentComplete() ) + "%", this );
00137       label->setAlignment( AlignHCenter | AlignVCenter );
00138       mLayout->addWidget( label, counter, 1 );
00139       mLabels.append( label );
00140 
00141       QString sSummary = todo->summary();
00142       if ( todo->relatedTo() ) { // show parent only, not entire ancestry
00143         sSummary = todo->relatedTo()->summary() + ":" + todo->summary();
00144       }
00145       KURLLabel *urlLabel = new KURLLabel( todo->uid(), sSummary, this );
00146       urlLabel->setTextFormat( Qt::RichText );
00147       mLayout->addWidget( urlLabel, counter, 2 );
00148       mLabels.append( urlLabel );
00149 
00150       if ( !todo->description().isEmpty() ) {
00151         QToolTip::add( urlLabel, todo->description() );
00152       }
00153 
00154       label = new QLabel( stateText, this );
00155       label->setAlignment( AlignLeft | AlignVCenter );
00156       mLayout->addWidget( label, counter, 3 );
00157       mLabels.append( label );
00158 
00159       connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00160                this, SLOT( selectEvent( const QString& ) ) );
00161 
00162       counter++;
00163     }
00164   }
00165 
00166   if ( counter == 0 ) {
00167     QLabel *noTodos = new QLabel( i18n( "No Todos pending" ), this );
00168     noTodos->setAlignment( AlignRight );
00169     mLayout->addWidget( noTodos, 0, 2 );
00170     mLabels.append( noTodos );
00171   }
00172 
00173   for ( label = mLabels.first(); label; label = mLabels.next() )
00174     label->show();
00175 }
00176 
00177 void TodoSummaryWidget::selectEvent( const QString & )
00178 {
00179   mPlugin->core()->selectPlugin( "kontact_todoplugin" );
00180   mPlugin->interface()->showTodoView();
00181 }
00182 
00183 QStringList TodoSummaryWidget::configModules() const
00184 {
00185   return QStringList( "kcmkorgsummary.desktop" );
00186 }
00187 
00188 #include "todosummarywidget.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:26:16 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003