kontact Library API Documentation

summarywidget.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 
00035 #include <dcopref.h>
00036 
00037 #include <libkcal/event.h>
00038 #include <libkcal/resourcecalendar.h>
00039 #include <libkcal/resourcelocal.h>
00040 #include <libkcal/todo.h>
00041 
00042 #include "core.h"
00043 #include "plugin.h"
00044 
00045 #include "summarywidget.h"
00046 
00047 SummaryWidget::SummaryWidget( Kontact::Plugin* plugin, QWidget *parent,
00048                               const char *name )
00049   : Kontact::Summary( parent, name ), mPlugin(plugin), mLayout( 0 )
00050 {
00051   mMainLayout = new QVBoxLayout( this, 3, 3 );
00052 
00053   QPixmap icon = KGlobal::iconLoader()->loadIcon( "korganizer", 
00054                    KIcon::Desktop, KIcon::SizeMedium );
00055   QWidget *header = createHeader( this, icon, i18n( "Appointments" ) );
00056   mMainLayout->addWidget(header);
00057 
00058   KConfig config( "korganizerrc" );
00059   mCalendar = new KCal::CalendarResources( config.readEntry( "TimeZoneId" ) );
00060   KCal::CalendarResourceManager *manager = mCalendar->resourceManager();
00061   if ( manager->isEmpty() ) {
00062     config.setGroup("General");
00063     QString fileName = config.readPathEntry( "Active Calendar" );
00064 
00065     QString resourceName;
00066     if ( fileName.isEmpty() ) {
00067       fileName = locateLocal( "data", "korganizer/std.ics" );
00068       resourceName = i18n("Default KOrganizer resource");
00069     } else {
00070       resourceName = i18n("Active Calendar");
00071     }
00072 
00073     KCal::ResourceCalendar *defaultResource =
00074                              new KCal::ResourceLocal( fileName );
00075 
00076     defaultResource->setResourceName( resourceName );
00077 
00078     manager->add( defaultResource );
00079     manager->setStandardResource( defaultResource );
00080   }
00081 
00082   connect( mCalendar, SIGNAL( calendarChanged() ), SLOT( updateView() ) );
00083 
00084   updateView();
00085   show();
00086 }
00087 
00088 void SummaryWidget::updateView()
00089 {
00090 
00091   delete mLayout;
00092 
00093   mLabels.setAutoDelete( true );
00094   mLabels.clear();
00095   mLabels.setAutoDelete( false );
00096 
00097   mLayout = new QGridLayout( 7, 5, 3 );
00098   mMainLayout->addLayout( mLayout );
00099   mLayout->setRowStretch( 6, 1 );
00100 
00101   KIconLoader loader( "korganizer" );
00102 
00103   QLabel *label = 0;
00104   int counter = 0;
00105   KCal::Event::List events = mCalendar->events( QDate::currentDate(), true );
00106   if ( events.count() > 0 ) {
00107     QPixmap pm = loader.loadIcon( "appointment", KIcon::Small );
00108 
00109     KCal::Event::List::ConstIterator it2;
00110     for( it2 = events.begin(); it2 != events.end() && counter < 5; ++it2 ) {
00111       KCal::Event *ev = *it2;
00112       if ( !ev->recurrence()->doesRecur() || ev->recursOn( QDate::currentDate() ) ) {
00113         if ( !ev->doesFloat() ) {
00114           label = new QLabel( this );
00115           label->setPixmap( pm );
00116           label->setMaximumSize( label->sizeHint() );
00117           mLayout->addWidget( label, counter, 0 );
00118           mLabels.append( label );
00119 
00120           QString date = ev->dtStartTimeStr() + " - " + ev->dtEndTimeStr();
00121           label = new QLabel( date, this );
00122           mLayout->addWidget( label, counter, 1 );
00123           mLabels.append( label );
00124 
00125           KURLLabel *urlLabel = new KURLLabel( ev->uid(), ev->summary(), this );
00126           mLayout->addWidget( urlLabel, counter, 2 );
00127           mLabels.append( urlLabel );
00128 
00129           connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00130                    this, SLOT( selectEvent( const QString& ) ) );
00131 
00132           counter++;
00133         }
00134       }
00135     }
00136   }
00137   else {
00138     QLabel *noEvents = new QLabel( i18n("No appointments pending"), this );
00139     noEvents->setAlignment( AlignRight );
00140     mLayout->addWidget( noEvents, 0, 2 );
00141     mLabels.append(noEvents);
00142   }
00143 
00144   KCal::Todo::List todos = mCalendar->todos();
00145   if ( todos.count() > 0 ) {
00146     QPixmap pm = loader.loadIcon( "todo", KIcon::Small );
00147     KCal::Todo::List::ConstIterator it;
00148     for( it = todos.begin(); it != todos.end(); ++it ) {
00149       KCal::Todo *todo = *it;
00150       if ( todo->hasDueDate() && todo->dtDue().date() == QDate::currentDate() && !todo->isCompleted() ) {
00151         label = new QLabel( this );
00152         label->setPixmap( pm );
00153         mLayout->addWidget( label, counter, 0 );
00154         mLabels.append( label );
00155 
00156         KURLLabel *urlLabel = new KURLLabel( todo->uid(), todo->summary(), this );
00157         mLayout->addWidget( urlLabel, counter, 2 );
00158         mLabels.append( urlLabel );
00159           
00160         connect( urlLabel, SIGNAL( leftClickedURL( const QString& ) ),
00161                  this, SLOT( selectEvent( const QString& ) ) );
00162 
00163         counter++;
00164       }
00165     }
00166   }
00167 
00168 }
00169 
00170 void SummaryWidget::selectEvent( const QString & /* uid */ )
00171 {
00172   if ( !mPlugin->isRunningStandalone() )
00173     mPlugin->core()->selectPlugin( mPlugin );
00174   else
00175     mPlugin->bringToForeground();
00176 
00177 /*
00178   DCOPRef dcopCall( "korganizer", "KOrganizerIface" );
00179   dcopCall.send( "showEventEditor(QString)", uid );
00180 */
00181 }
00182 
00183 #include "summarywidget.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:39:00 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003