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

addresspluginwidget.cpp

Go to the documentation of this file.
00001 /*
00002  * addresspluginwidget.cpp
00003  *
00004  * copyright   : (c) 2003 by Stefan Eilers
00005  * email       : eilers.stefan@epost.de
00006  *
00007  * This implementation was derived from the todolist plugin implementation
00008  *
00009  */
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "addresspluginwidget.h"
00020 
00021 #include <opie2/odebug.h>
00022 #include <opie2/opimcontact.h>
00023 
00024 #include <qpe/config.h>
00025 
00026 AddressBookPluginWidget::AddressBookPluginWidget( QWidget *parent,  const char* name )
00027     : QWidget( parent, name ) {
00028 
00029     addressLabel = 0l;
00030     m_contactdb = 0l;
00031     layoutTodo = 0l;
00032 
00033     m_contactdb = new Opie::OPimContactAccess("addressplugin");
00034 
00035     connect( m_contactdb, SIGNAL( signalChanged(const Opie::OPimContactAccess*) ),
00036              this, SLOT( refresh(const Opie::OPimContactAccess*) ) );
00037 
00038 
00039     readConfig();
00040     getAddress();
00041 }
00042 
00043 AddressBookPluginWidget::~AddressBookPluginWidget() {
00044     delete m_contactdb;
00045 }
00046 
00047 void AddressBookPluginWidget::refresh( const Opie::OPimContactAccess* )
00048 {
00049         owarn << " AddressBookPluginWidget::Database was changed externally ! " << oendl;
00050         m_contactdb->reload();
00051         getAddress();
00052 }
00053 
00054 void AddressBookPluginWidget::reinitialize() {
00055         readConfig();
00056         getAddress();
00057 }
00058 
00059 void AddressBookPluginWidget::readConfig() {
00060     Config cfg( "todayaddressplugin" );
00061     cfg.setGroup( "config" );
00062     m_maxLinesTask  = cfg.readNumEntry( "maxlinestask", 5 );
00063     m_maxCharClip   = cfg.readNumEntry( "maxcharclip", 38 );
00064     m_daysLookAhead = cfg.readNumEntry( "dayslookahead", 14 );
00065     m_urgentDays    = cfg.readNumEntry( "urgentdays", 7 );
00066     m_entryColor    = cfg.readEntry("entrycolor", Qt::black.name() );
00067     m_headlineColor = cfg.readEntry( "headlinecolor", Qt::black.name() );
00068     m_urgentColor   = cfg.readEntry( "urgentcolor", Qt::red.name() );
00069     m_showBirthdays = cfg.readBoolEntry( "showBirthdays", true );
00070     m_showAnniversaries = cfg.readBoolEntry( "showAnniversaries", true );
00071 }
00072 
00073 
00077 void AddressBookPluginWidget::getAddress() {
00078 
00079         if ( ! layoutTodo ){
00080                 layoutTodo = new QVBoxLayout( this );
00081         }
00082 
00083         if ( ! addressLabel ) {
00084                 addressLabel = new Opie::Ui::OClickableLabel( this );
00085                 connect( addressLabel, SIGNAL( clicked() ), this, SLOT( startAddressBook() ) );
00086                 layoutTodo->addWidget( addressLabel );
00087         }
00088 
00089         QString output;
00090 
00091         // Check whether the database provide the search option..
00092     if ( !m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){
00093                 // Libopie seems to be old..
00094                 output = QObject::tr( "Database does not provide this search query ! Please upgrade libOpie !<br>" );
00095                 addressLabel->setText( output );
00096                 return;
00097         }
00098 
00099         // Define the query for birthdays and start search..
00100         QDate lookAheadDate = QDate::currentDate().addDays( m_daysLookAhead );
00101         int ammount = 0;
00102         if ( m_showBirthdays ){
00103                 owarn << "Searching from now (" << QDate::currentDate().toString() << ") until "
00104                                                 << lookAheadDate.toString() << " ! " << oendl;
00105 
00106                 if ( m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDiff ) ){
00107 
00108 
00109                         Opie::OPimContact querybirthdays;
00110                         querybirthdays.setBirthday( lookAheadDate );
00111 
00112                         m_list = m_contactdb->queryByExample( querybirthdays,
00113                                                                   Opie::OPimContactAccess::DateDiff );
00114                         if ( m_list.count() > 0 ){
00115                                 output = "<font color=" + m_headlineColor + ">"
00116                                         + QObject::tr( "Next birthdays in <b> %1 </b> days:" )
00117                                         .arg( m_daysLookAhead )
00118                                         + "</font> <br>";
00119 
00120                                 // Sort filtered results
00121                                 m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortBirthdayWithoutYear,
00122                                                                   Opie::OPimContactAccess::FilterOff, 0 );
00123 
00124                                 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
00125                                         if ( ammount++ < m_maxLinesTask ){
00126                                                 // Now we want to calculate how many days
00127                                                 //until birthday. We have to set
00128                                                 // the correct year to calculate the day diff...
00129                                                 QDate destdate = (*m_it).birthday();
00130                                                 destdate.setYMD( QDate::currentDate().year(),
00131                                                                  destdate.month(), destdate.day() );
00132                                                 if ( QDate::currentDate().daysTo(destdate) < 0 )
00133                                                         destdate.setYMD( QDate::currentDate().year()+1,
00134                                                                          destdate.month(), destdate.day() );
00135 
00136 
00137                                                 if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
00138                                                         output += "<font color=" + m_urgentColor + "><b>-"
00139                                                                 + (*m_it).fullName()
00140                                                                 + " ("
00141                                                                 + QString::number(QDate::currentDate()
00142                                                                                   .daysTo(destdate))
00143                                                                 + " Days) </b></font><br>";
00144 
00145                                                 else
00146                                                         output += "<font color=" + m_entryColor + "><b>-"
00147                                                                 + (*m_it).fullName()
00148                                                                 + " ("
00149                                                                 + QString::number(QDate::currentDate()
00150                                                                                   .daysTo(destdate))
00151                                                                 + " Days) </b></font><br>";
00152                                         }
00153                                 }
00154                         } else {
00155                                 output = "<font color=" + m_headlineColor + ">"
00156                                         + QObject::tr( "No birthdays in <b> %1 </b> days!" )
00157                                         .arg( m_daysLookAhead )
00158                                         + "</font> <br>";
00159                         }
00160                 }
00161     }
00162 
00163         if ( m_showAnniversaries ){
00164                 // Define the query for anniversaries and start search..
00165                 Opie::OPimContact queryanniversaries;
00166                 queryanniversaries.setAnniversary( lookAheadDate );
00167 
00168                 m_list = m_contactdb->queryByExample( queryanniversaries, Opie::OPimContactAccess::DateDiff );
00169 
00170                 ammount = 0;
00171                 if ( m_list.count() > 0 ){
00172                         output += "<font color=" + m_headlineColor + ">"
00173                                 + QObject::tr( "Next anniversaries in <b> %1 </b> days:" )
00174                                 .arg( m_daysLookAhead )
00175                                 + "</font> <br>";
00176 
00177                         // Sort filtered results
00178                         m_list = m_contactdb->sorted( m_list, true, Opie::OPimContactAccess::SortAnniversaryWithoutYear,
00179                                                           Opie::OPimContactAccess::FilterOff, 0 );
00180 
00181                         for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
00182                                 if ( ammount++ < m_maxLinesTask ){
00183                                         // Now we want to calculate how many days until anniversary.
00184                                         // We have to set the correct year to calculate the day diff...
00185                                         QDate destdate = (*m_it).anniversary();
00186                                         destdate.setYMD( QDate::currentDate().year(), destdate.month(),
00187                                                          destdate.day() );
00188                                         if ( QDate::currentDate().daysTo(destdate) < 0 )
00189                                                 destdate.setYMD( QDate::currentDate().year()+1,
00190                                                                  destdate.month(), destdate.day() );
00191 
00192                                         if ( QDate::currentDate().daysTo(destdate) < m_urgentDays )
00193                                                 output += "<font color=" + m_urgentColor + "><b>-"
00194                                                         + (*m_it).fullName()
00195                                                         + " ("
00196                                                         + QString::number(QDate::currentDate()
00197                                                                           .daysTo( destdate ) )
00198                                                         + " Days) </b></font><br>";
00199                                         else
00200                                                 output += "<font color=" + m_entryColor + "><b>-"
00201                                                         + (*m_it).fullName()
00202                                                         + " ("
00203                                                         + QString::number(QDate::currentDate()
00204                                                                           .daysTo( destdate ) )
00205                                                         + " Days) </b></font><br>";
00206                                 }
00207                         }
00208                 } else {
00209                         output += "<font color=" + m_headlineColor + ">"
00210                                 + QObject::tr( "No anniversaries in <b> %1 </b> days!" )
00211                                 .arg( m_daysLookAhead )
00212                                 + "</font> <br>";
00213                 }
00214         }
00215 
00216         addressLabel->setText( output );
00217 }
00218 
00222 void AddressBookPluginWidget::startAddressBook() {
00223     QCopEnvelope e( "QPE/System", "execute(QString)" );
00224     e << QString( "addressbook" );
00225 }

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