summaryrefslogtreecommitdiff
path: root/core/pim/osearch/todosearch.cpp
blob: 1ed7370a8b658d31431dbeaccefc112fce3e4758 (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
//
//
// C++ Implementation: $MODULE$
//
// Description:
//
//
// Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "todosearch.h"
#include "todoitem.h"

#include <qpe/resource.h>
#include <qpe/config.h>

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

using namespace Opie;
TodoSearch::TodoSearch(QListView* parent, QString name)
: SearchGroup(parent, name), _todos(0), _popupMenu(0)
{
//	AppLnkSet als(QPEApplication::qpeDir());
//	setPixmap( 0, als.findExec("todolist")->pixmap() );
        QIconSet is = Resource::loadIconSet( "todo/TodoList" );
	setPixmap( 0, is.pixmap( QIconSet::Large, true ) );
	actionShowCompleted = new QAction( QObject::tr("Show completed tasks"),QString::null,  0, 0, 0, true );
	Config cfg( "osearch", Config::User );
   	cfg.setGroup( "todo_settings" );
   	actionShowCompleted->setOn( cfg.readBoolEntry( "show_completed_tasks", false ) );

}


TodoSearch::~TodoSearch()
{
	Config cfg( "osearch", Config::User );
   	cfg.setGroup( "todo_settings" );
   	cfg.writeEntry( "show_completed_tasks", actionShowCompleted->isOn() );
	delete _popupMenu;
	delete actionShowCompleted;
	delete _todos;
}


void TodoSearch::load()
{
	 _todos = new OPimTodoAccess();
	 _todos->load();
}

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

void TodoSearch::insertItem( void *rec )
{
	OPimTodo *todo = (OPimTodo*)rec;
	if (!actionShowCompleted->isOn() &&
		todo->isCompleted() ) return;
	(void)new TodoItem( this, todo );
	_resultCount++;
}

QPopupMenu* TodoSearch::popupMenu()
{
	if (!_popupMenu){
		_popupMenu = new QPopupMenu( 0 );
 		actionShowCompleted->addTo( _popupMenu );
	}
	return _popupMenu;
}