00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "datebooksearch.h"
00014 #include "eventitem.h"
00015
00016 #include <opie2/odebug.h>
00017 #include <opie2/opimevent.h>
00018 #include <opie2/opimrecurrence.h>
00019 #include <opie2/oresource.h>
00020
00021 #include <qpe/config.h>
00022
00023 #include <qaction.h>
00024 #include <qpopupmenu.h>
00025
00026
00027
00028 DatebookSearch::DatebookSearch(QListView* parent, QString name)
00029 : SearchGroup(parent, name), _dates(0), _popupMenu(0)
00030 {
00031 setPixmap( 0, Opie::Core::OResource::loadPixmap( "datebook/DateBook", Opie::Core::OResource::SmallIcon ) );
00032
00033 actionShowPastEvents = new QAction( QObject::tr("Show past events"),QString::null, 0, 0, 0, true );
00034 actionSearchInDates = new QAction( QObject::tr("Search in dates"),QString::null, 0, 0, 0, true );
00035 Config cfg( "osearch", Config::User );
00036 cfg.setGroup( "datebook_settings" );
00037 actionShowPastEvents->setOn( cfg.readBoolEntry( "show_past_events", false ) );
00038 actionSearchInDates->setOn( cfg.readBoolEntry( "search_in_dates", true ) );
00039 }
00040
00041 DatebookSearch::~DatebookSearch()
00042 {
00043 odebug << "SAVE DATEBOOK SEARCH CONFIG" << oendl;
00044 Config cfg( "osearch", Config::User );
00045 cfg.setGroup( "datebook_settings" );
00046 cfg.writeEntry( "show_past_events", actionShowPastEvents->isOn() );
00047 cfg.writeEntry( "search_in_dates", actionSearchInDates->isOn() );
00048 delete _dates;
00049 delete _popupMenu;
00050 delete actionShowPastEvents;
00051 delete actionSearchInDates;
00052 }
00053
00054
00055 void DatebookSearch::load()
00056 {
00057 _dates = new ODateBookAccess();
00058 _dates->load();
00059 }
00060
00061 int DatebookSearch::search()
00062 {
00063 OPimRecordList<OPimEvent> results = _dates->matchRegexp(_search);
00064 for (uint i = 0; i < results.count(); i++)
00065 insertItem( new OPimEvent( results[i] ) );
00066 return _resultCount;
00067 }
00068
00069 void DatebookSearch::insertItem( void *rec )
00070 {
00071 OPimEvent *ev = (OPimEvent*)rec;
00072 if ( !actionShowPastEvents->isOn() &&
00073 ev->endDateTime() < QDateTime::currentDateTime() &&
00074 !ev->recurrence().doesRecur()
00075 ) return;
00076 if ( !actionSearchInDates->isOn() && (
00077 ev->lastHitField() == Qtopia::StartDateTime ||
00078 ev->lastHitField() == Qtopia::EndDateTime )
00079 ) return;
00080 new EventItem( this, ev );
00081 _resultCount++;
00082 }
00083
00084 QPopupMenu* DatebookSearch::popupMenu()
00085 {
00086 if (!_popupMenu){
00087 _popupMenu = new QPopupMenu( 0 );
00088 actionShowPastEvents->addTo( _popupMenu );
00089 actionSearchInDates->addTo( _popupMenu );
00090 }
00091 return _popupMenu;
00092 }
00093