00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "todosearch.h"
00014 #include "todoitem.h"
00015
00016 #include <opie2/oresource.h>
00017
00018 #include <qpe/config.h>
00019
00020 #include <qaction.h>
00021 #include <qpopupmenu.h>
00022
00023 using namespace Opie;
00024 TodoSearch::TodoSearch(QListView* parent, QString name)
00025 : SearchGroup(parent, name), _todos(0), _popupMenu(0)
00026 {
00027
00028
00029 setPixmap( 0, Opie::Core::OResource::loadPixmap( "todo/TodoList", Opie::Core::OResource::SmallIcon ) );
00030
00031 actionShowCompleted = new QAction( QObject::tr("Show completed tasks"),QString::null, 0, 0, 0, true );
00032 Config cfg( "osearch", Config::User );
00033 cfg.setGroup( "todo_settings" );
00034 actionShowCompleted->setOn( cfg.readBoolEntry( "show_completed_tasks", false ) );
00035
00036 }
00037
00038
00039 TodoSearch::~TodoSearch()
00040 {
00041 Config cfg( "osearch", Config::User );
00042 cfg.setGroup( "todo_settings" );
00043 cfg.writeEntry( "show_completed_tasks", actionShowCompleted->isOn() );
00044 delete _popupMenu;
00045 delete actionShowCompleted;
00046 delete _todos;
00047 }
00048
00049
00050 void TodoSearch::load()
00051 {
00052 _todos = new OPimTodoAccess();
00053 _todos->load();
00054 }
00055
00056 int TodoSearch::search()
00057 {
00058 OPimRecordList<OPimTodo> results = _todos->matchRegexp(_search);
00059 for (uint i = 0; i < results.count(); i++)
00060 insertItem( new OPimTodo( results[i] ));
00061 return _resultCount;
00062 }
00063
00064 void TodoSearch::insertItem( void *rec )
00065 {
00066 OPimTodo *todo = (OPimTodo*)rec;
00067 if (!actionShowCompleted->isOn() &&
00068 todo->isCompleted() ) return;
00069 (void)new TodoItem( this, todo );
00070 _resultCount++;
00071 }
00072
00073 QPopupMenu* TodoSearch::popupMenu()
00074 {
00075 if (!_popupMenu){
00076 _popupMenu = new QPopupMenu( 0 );
00077 actionShowCompleted->addTo( _popupMenu );
00078 }
00079 return _popupMenu;
00080 }