summaryrefslogtreecommitdiff
path: root/core/pim/osearch/datebooksearch.cpp
blob: 13df6bf363b420a28aca4c7740480046d8ca3548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
//
// C++ Implementation: $MODULE$
//
// Description:
//
//
// Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "datebooksearch.h"
#include "eventitem.h"

#include <opie2/odebug.h>
#include <opie2/opimevent.h>
#include <opie2/opimrecurrence.h>
#include <opie2/oresource.h>

#include <qpe/config.h>

#include <qaction.h>
#include <qpopupmenu.h>



DatebookSearch::DatebookSearch(QListView* parent, QString name)
: SearchGroup(parent, name), _dates(0), _popupMenu(0)
{
    setPixmap( 0, Opie::Core::OResource::loadPixmap( "datebook/DateBook", Opie::Core::OResource::SmallIcon ) );

	actionShowPastEvents = new QAction( QObject::tr("Show past events"),QString::null,  0, 0, 0, true );
	actionSearchInDates = new QAction( QObject::tr("Search in dates"),QString::null,  0, 0, 0, true );
	Config cfg( "osearch", Config::User );
   	cfg.setGroup( "datebook_settings" );
   	actionShowPastEvents->setOn( cfg.readBoolEntry( "show_past_events", false ) );
   	actionSearchInDates->setOn( cfg.readBoolEntry( "search_in_dates", true ) );
}

DatebookSearch::~DatebookSearch()
{
	odebug << "SAVE DATEBOOK SEARCH CONFIG" << oendl;
	Config cfg( "osearch", Config::User );
   	cfg.setGroup( "datebook_settings" );
   	cfg.writeEntry( "show_past_events", actionShowPastEvents->isOn() );
   	cfg.writeEntry( "search_in_dates", actionSearchInDates->isOn() );
	delete _dates;
	delete _popupMenu;
	delete actionShowPastEvents;
	delete actionSearchInDates;
}


void DatebookSearch::load()
{
	 _dates = new ODateBookAccess();
	 _dates->load();
}

int DatebookSearch::search()
{
	OPimRecordList<OPimEvent> results = _dates->matchRegexp(_search);
	for (uint i = 0; i < results.count(); i++)
		insertItem( new OPimEvent( results[i] ) );
	return _resultCount;
}

void DatebookSearch::insertItem( void *rec )
{
	OPimEvent *ev = (OPimEvent*)rec;
	if ( !actionShowPastEvents->isOn() &&
	      ev->endDateTime() < QDateTime::currentDateTime() &&
	      !ev->recurrence().doesRecur()
	    ) return;
	if ( !actionSearchInDates->isOn() && (
	      ev->lastHitField() == Qtopia::StartDateTime ||
 	      ev->lastHitField() == Qtopia::EndDateTime )
	    ) return;
	new EventItem( this, ev );
	_resultCount++;
}

QPopupMenu* DatebookSearch::popupMenu()
{
	if (!_popupMenu){
		_popupMenu = new QPopupMenu( 0 );
 		actionShowPastEvents->addTo( _popupMenu );
 		actionSearchInDates->addTo( _popupMenu );
	}
	return _popupMenu;
}