Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

datebookpluginwidget.cpp

Go to the documentation of this file.
00001  /*
00002  * datebookpluginwidget.cpp
00003  *
00004  * copyright   : (c) 2002,2003, 2004 by Maximilian Reiß
00005  * email       : harlekin@handhelds.org
00006  *
00007  */
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 
00018 #include "datebookpluginwidget.h"
00019 
00020 #include <qpe/config.h>
00021 
00022 #include <qtl.h>
00023 
00024 DatebookPluginWidget::DatebookPluginWidget( QWidget *parent, const char* name )
00025     : QWidget(parent, name ) {
00026 
00027     db = 0l;
00028     m_layoutDates = 0l;
00029 
00030     if ( m_layoutDates )  {
00031         delete m_layoutDates;
00032     }
00033     m_layoutDates = new QVBoxLayout( this );
00034     m_layoutDates->setAutoAdd( true );
00035 
00036     m_eventsList.setAutoDelete( true );
00037 
00038     readConfig();
00039     getDates();
00040 }
00041 
00042 DatebookPluginWidget::~DatebookPluginWidget() {
00043     delete db;
00044     delete m_layoutDates;
00045 }
00046 
00047 
00048 void DatebookPluginWidget::readConfig() {
00049     Config cfg( "todaydatebookplugin" );
00050     cfg.setGroup( "config" );
00051     m_max_lines_meet = cfg.readNumEntry( "maxlinesmeet", 5 );
00052     m_show_location = cfg.readNumEntry( "showlocation", 1 );
00053     m_show_notes = cfg.readNumEntry( "shownotes", 0 );
00054     m_onlyLater = cfg.readNumEntry( "onlylater", 1 );
00055     m_moreDays = cfg.readNumEntry( "moredays", 0 );
00056     m_timeExtraLine = cfg.readNumEntry( "timeextraline",  1 );
00057     m_maxCharClip = cfg.readNumEntry( "maxcharclip", 38 );
00058 }
00059 
00060 void DatebookPluginWidget::reinitialize()  {
00061     readConfig();
00062     refresh();
00063 }
00064 
00065 void DatebookPluginWidget::refresh()  {
00066     m_eventsList.clear();
00067 
00068     if ( m_layoutDates )  {
00069         delete m_layoutDates;
00070     }
00071     m_layoutDates = new QVBoxLayout( this );
00072     m_layoutDates->setAutoAdd( true );
00073 
00074     getDates();
00075 }
00076 
00080 void DatebookPluginWidget::getDates() {
00081 
00082 
00083     if ( db ) {
00084         delete db;
00085     }
00086     db = new DateBookDB;
00087 
00088     QDate date = QDate::currentDate();
00089     QValueList<EffectiveEvent> list = db->getEffectiveEvents( date, date.addDays( m_moreDays )  );
00090     qBubbleSort( list );
00091     int count = 0;
00092 
00093     if ( list.count() > 0 ) {
00094 
00095         for ( QValueList<EffectiveEvent>::ConstIterator it = list.begin(); it  != list.end(); ++it ) {
00096 
00097             if ( count < m_max_lines_meet ) {
00098                 if ( !m_onlyLater ) {
00099                     count++;
00100                     DateBookEvent *l = new DateBookEvent( *it, this, m_show_location, m_show_notes, m_timeExtraLine, m_maxCharClip );
00101                     m_eventsList.append( l );
00102                     l->show();
00103                     QObject::connect ( l, SIGNAL( editEvent(const Event&) ), l, SLOT( editEventSlot(const Event&) ) );
00104                 } else {
00105                         if ( ( QDateTime::currentDateTime()  <=  (*it).event().end() )
00106                              // Show events which span over many days and are not elapsed.
00107                              || ( ( (*it).event().start().date() != date ) &&  (  QDateTime::currentDateTime()  <=  (*it).event().end() )  )
00108                              // Show repeated event for today that is not elapsed.
00109                              || ( ( (*it).event().repeatType() != Event::NoRepeat )
00110                                   && ( ( date.dayOfWeek() == (*it).date().dayOfWeek() )
00111                                        && ( QTime::currentTime() < (*it).event().start().time() ) ) )
00112                              // Show repeated event for next days.
00113                              || ( ( (*it).event().repeatType() != Event::NoRepeat )
00114                                   && ( date.dayOfWeek() != (*it).date().dayOfWeek() ) )
00115                              )
00116                              {
00117                                 count++;
00118                                 // show only later appointments
00119                                 DateBookEvent *l = new DateBookEvent( *it, this, m_show_location, m_show_notes, m_timeExtraLine, m_maxCharClip );
00120                                 m_eventsList.append( l );
00121                                 l->show();
00122                                 QObject::connect ( l, SIGNAL( editEvent(const Event&) ), l, SLOT( editEventSlot(const Event&) ) );
00123                              }
00124                 }
00125             }
00126         }
00127         if ( m_onlyLater && count == 0 ) {
00128             QLabel* noMoreEvents = new QLabel( this );
00129             m_eventsList.append(  noMoreEvents );
00130             noMoreEvents->show();
00131             noMoreEvents->setText( QObject::tr( "No more appointments today" ) );
00132         }
00133     } else {
00134         QLabel* noEvents = new QLabel( this );
00135         m_eventsList.append( noEvents );
00136         noEvents->show();
00137         noEvents->setText( QObject::tr( "No appointments today" ) );
00138     }
00139 }
00140 
00141 

Generated on Sat Nov 5 16:15:55 2005 for OPIE by  doxygen 1.4.2