author | tille <tille> | 2003-05-11 19:19:30 (UTC) |
---|---|---|
committer | tille <tille> | 2003-05-11 19:19:30 (UTC) |
commit | 43c18630840a98aed8deb96b454957c40f0a4344 (patch) (side-by-side diff) | |
tree | 60e5b68d1d172c77560d5af7bea83e81be7144a6 /core/pim/osearch | |
parent | 38dc2fd6258f11ba0507c7bd8f8dfd5b39bc0df5 (diff) | |
download | opie-43c18630840a98aed8deb96b454957c40f0a4344.zip opie-43c18630840a98aed8deb96b454957c40f0a4344.tar.gz opie-43c18630840a98aed8deb96b454957c40f0a4344.tar.bz2 |
improved applnk and doclnk searching
clean up:
- mainwindow: handling of searchgroups
- searchgroups: introduced load, search and insertItem functions
- flexible actions handling
- doclnksearch inherits applnksearch
26 files changed, 279 insertions, 210 deletions
diff --git a/core/pim/osearch/adresssearch.cpp b/core/pim/osearch/adresssearch.cpp index 0ee8eba..69ad9ef 100644 --- a/core/pim/osearch/adresssearch.cpp +++ b/core/pim/osearch/adresssearch.cpp @@ -30,16 +30,21 @@ AdressSearch::~AdressSearch() delete _contacts; } +void AdressSearch::load() +{ + _contacts = new OContactAccess("osearch"); +} -void AdressSearch::expand() +int AdressSearch::search() { - SearchGroup::expand(); - if (_search.isEmpty()) return; - if (!_contacts) _contacts = new OContactAccess("osearch"); ORecordList<OContact> results = _contacts->matchRegexp(_search); - setText(0, text(0) + " (" + QString::number( results.count() ) + ")" ); for (uint i = 0; i < results.count(); i++) { new ContactItem( this, new OContact( results[i] )); } + return results.count(); } +void AdressSearch::insertItem( void* ) +{ + +} diff --git a/core/pim/osearch/adresssearch.h b/core/pim/osearch/adresssearch.h index ab560d0..d5c7622 100644 --- a/core/pim/osearch/adresssearch.h +++ b/core/pim/osearch/adresssearch.h @@ -26,10 +26,10 @@ public: AdressSearch(QListView* parent, QString name); ~AdressSearch(); - virtual void expand(); - protected: - + virtual void load(); + virtual int search(); + virtual void insertItem( void* ); private: OContactAccess *_contacts; diff --git a/core/pim/osearch/applnkitem.cpp b/core/pim/osearch/applnkitem.cpp index f45ed68..2152da4 100644 --- a/core/pim/osearch/applnkitem.cpp +++ b/core/pim/osearch/applnkitem.cpp @@ -2,7 +2,7 @@ // // C++ Implementation: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -30,25 +30,21 @@ AppLnkItem::~AppLnkItem() QString AppLnkItem::toRichText() { QString text; - text += "<b><h3>"; - text += _app->name(); - text += "</b></h3><br>"; - text += _app->comment(); - text += "<br><br>`"; - text += _app->exec(); - text += "`"; + text += "<b><h3>" + _app->name() + "</b></h3><br>"; + text += _app->comment() + "<br>"; + text += "<br>`" + _app->exec() + "`<br>"; return text; } -void AppLnkItem::editItem() +void AppLnkItem::action( int act ) { - _app->execute(); + if (!_app->isValid()) qDebug("INVALID"); + if (act == 0) _app->execute(); } -void AppLnkItem::showItem() +QIntDict<QString> AppLnkItem::actions() { -/* QCopEnvelope e("QPE/Application/addressbook", "edit(int)"); - e << _contact->uid();*/ - ResultItem::showItem(); + QIntDict<QString> result; + result.insert( 0, new QString( QObject::tr("execute") ) ); + return result; } - diff --git a/core/pim/osearch/applnkitem.h b/core/pim/osearch/applnkitem.h index b28631a..4aa1274 100644 --- a/core/pim/osearch/applnkitem.h +++ b/core/pim/osearch/applnkitem.h @@ -27,8 +27,8 @@ public: ~AppLnkItem(); virtual QString toRichText(); - virtual void editItem(); - virtual void showItem(); + virtual void action( int ); + virtual QIntDict<QString> actions(); private: AppLnk *_app; diff --git a/core/pim/osearch/applnksearch.cpp b/core/pim/osearch/applnksearch.cpp index 7872ae3..d5b2930 100644 --- a/core/pim/osearch/applnksearch.cpp +++ b/core/pim/osearch/applnksearch.cpp @@ -2,7 +2,7 @@ // // C++ Implementation: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -29,18 +29,27 @@ AppLnkSearch::~AppLnkSearch() } -void AppLnkSearch::expand() +void AppLnkSearch::load() { - SearchGroup::expand(); - if (_search.isEmpty()) return; - if (!_apps) _apps = new AppLnkSet(QPEApplication::qpeDir()); + _apps = new AppLnkSet(QPEApplication::qpeDir()); +} + +int AppLnkSearch::search() +{ + int count = 0; QList<AppLnk> appList = _apps->children(); for ( AppLnk *app = appList.first(); app != 0; app = appList.next() ){ -// if (app->name().contains(_search) || app->comment().contains(_search)) if ( (_search.match( app->name() ) != -1) || (_search.match(app->comment()) != -1) - || (_search.match(app->exec()) != -1) ) - new AppLnkItem( this, app ); + || (_search.match(app->exec()) != -1) ) { + count++; + insertItem( app ); + } } + return count; } +void AppLnkSearch::insertItem( void *rec ) +{ + new AppLnkItem( this, (AppLnk*)rec ); +} diff --git a/core/pim/osearch/applnksearch.h b/core/pim/osearch/applnksearch.h index e283cd3..d88a8ce 100644 --- a/core/pim/osearch/applnksearch.h +++ b/core/pim/osearch/applnksearch.h @@ -2,7 +2,7 @@ // // C++ Interface: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -27,9 +27,12 @@ public: ~AppLnkSearch(); - virtual void expand(); -private: - AppLnkSet *_apps; +protected: + virtual void load(); + virtual int search(); + virtual void insertItem( void* ); + + AppLnkSet *_apps; }; #endif diff --git a/core/pim/osearch/contactitem.cpp b/core/pim/osearch/contactitem.cpp index 788a415..7d8ecf1 100644 --- a/core/pim/osearch/contactitem.cpp +++ b/core/pim/osearch/contactitem.cpp @@ -2,7 +2,7 @@ // // C++ Implementation: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -34,18 +34,23 @@ QString ContactItem::toRichText() return _contact->toRichText(); } - -void ContactItem::editItem() +void ContactItem::action( int act ) { - QCopEnvelope e("QPE/Application/addressbook", "edit(int)"); -// QCopEnvelope e("QPE/Addressbook", "edit(int)"); +if (act == 0){ + QCopEnvelope e("QPE/Application/addressbook", "show(int)"); e << _contact->uid(); +}else if(act == 1){ + QCopEnvelope e("QPE/Application/addressbook", "edit(int)"); + e << _contact->uid(); } -void ContactItem::showItem() -{ - QCopEnvelope e("QPE/Application/addressbook", "show(int)"); -// QCopEnvelope e("QPE/Addressbook", "show(int)"); - e << _contact->uid(); } +QIntDict<QString> ContactItem::actions() +{ + QIntDict<QString> result; + result.insert( 0, new QString( QObject::tr("show") ) ); + result.insert( 1, new QString( QObject::tr("edit") ) ); + return result; + +} diff --git a/core/pim/osearch/contactitem.h b/core/pim/osearch/contactitem.h index 431adef..5e0017d 100644 --- a/core/pim/osearch/contactitem.h +++ b/core/pim/osearch/contactitem.h @@ -28,8 +28,9 @@ public: ~ContactItem(); virtual QString toRichText(); - virtual void showItem(); - virtual void editItem(); + virtual void action( int ); + virtual QIntDict<QString> actions(); + private: OContact *_contact; diff --git a/core/pim/osearch/datebooksearch.cpp b/core/pim/osearch/datebooksearch.cpp index 83b99f5..68699fa 100644 --- a/core/pim/osearch/datebooksearch.cpp +++ b/core/pim/osearch/datebooksearch.cpp @@ -30,17 +30,21 @@ DatebookSearch::~DatebookSearch() } -void DatebookSearch::expand() +void DatebookSearch::load() { - SearchGroup::expand(); - if (!_dates){ _dates = new ODateBookAccess(); _dates->load(); - } +} + +int DatebookSearch::search() +{ ORecordList<OEvent> results = _dates->matchRegexp(_search); - setText(0, text(0) + " (" + QString::number( results.count() ) + ")" ); - for (uint i = 0; i < results.count(); i++) { + for (uint i = 0; i < results.count(); i++) new EventItem( this, new OEvent( results[i] )); - } + return results.count(); } +void DatebookSearch::insertItem( void* ) +{ + +} diff --git a/core/pim/osearch/datebooksearch.h b/core/pim/osearch/datebooksearch.h index 35bbe5a..bb31462 100644 --- a/core/pim/osearch/datebooksearch.h +++ b/core/pim/osearch/datebooksearch.h @@ -27,7 +27,11 @@ public: ~DatebookSearch(); - virtual void expand(); +protected: + virtual void load(); + virtual int search(); + virtual void insertItem( void* ); + private: ODateBookAccess *_dates; diff --git a/core/pim/osearch/doclnkitem.cpp b/core/pim/osearch/doclnkitem.cpp index fd19727..75dee58 100644 --- a/core/pim/osearch/doclnkitem.cpp +++ b/core/pim/osearch/doclnkitem.cpp @@ -2,7 +2,7 @@ // // C++ Implementation: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -13,6 +13,8 @@ #include "doclnkitem.h" #include <qpe/applnk.h> +#include <qfile.h> +#include <qtextstream.h> DocLnkItem::DocLnkItem(OListViewItem* parent, DocLnk *app) : ResultItem(parent) @@ -21,34 +23,48 @@ DocLnkItem::DocLnkItem(OListViewItem* parent, DocLnk *app) setText(0, _doc->name() ); } - DocLnkItem::~DocLnkItem() { } - QString DocLnkItem::toRichText() { QString text; - text += "<b><h3>"; - text += _doc->name(); - text += "</b></h3><br>"; - text += _doc->comment(); - text += "<br><br>`"; + text += "<b><h3>" + _doc->name() + "</b></h3><br>"; + text += _doc->comment() + "<br>"; + text += "File: " + _doc->file() + "<br>"; + text += "Mimetype: " + _doc->type() + "<br>"; + if ( _doc->type().contains( "text" ) ){ + text += "<br><br><hr><br>"; + QFile f(_doc->file()); + if ( f.open(IO_ReadOnly) ) { + QTextStream t( &f ); + while ( !t.eof() ) + text += t.readLine() + "<br>"; + } + f.close(); + } + /* text += "<br><br>`"; text += _doc->exec(); - text += "`"; + text += "`";*/ + QStringList list = _doc->mimeTypes(); + int i = 0; + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + text += QString::number( i++) + " - " + *it ; + } return text; } -void DocLnkItem::editItem() +void DocLnkItem::action( int act ) { - _doc->execute(); + qDebug("action %i",act); + if (!_doc->isValid()) qDebug("INVALID"); + if (act == 0) _doc->execute(); } -void DocLnkItem::showItem() +QIntDict<QString> DocLnkItem::actions() { -/* QCopEnvelope e("QPE/Application/addressbook", "edit(int)"); - e << _contact->uid();*/ - ResultItem::showItem(); + QIntDict<QString> result; + result.insert( 0, new QString( QObject::tr("open with ") + _doc->exec() ) ); + return result; } - diff --git a/core/pim/osearch/doclnkitem.h b/core/pim/osearch/doclnkitem.h index 2718733..4fd6dd7 100644 --- a/core/pim/osearch/doclnkitem.h +++ b/core/pim/osearch/doclnkitem.h @@ -27,8 +27,8 @@ public: ~DocLnkItem(); virtual QString toRichText(); - virtual void editItem(); - virtual void showItem(); + virtual void action( int ); + virtual QIntDict<QString> actions(); private: DocLnk *_doc; diff --git a/core/pim/osearch/doclnksearch.cpp b/core/pim/osearch/doclnksearch.cpp index e99a385..f2a60e9 100644 --- a/core/pim/osearch/doclnksearch.cpp +++ b/core/pim/osearch/doclnksearch.cpp @@ -17,30 +17,22 @@ #include "doclnkitem.h" -DocLnkSearch::DocLnkSearch(QListView* parent, QString name): SearchGroup(parent, name) +DocLnkSearch::DocLnkSearch(QListView* parent, QString name) +: AppLnkSearch(parent, name) { - _docs = 0; } DocLnkSearch::~DocLnkSearch() { - delete _docs; } - -void DocLnkSearch::expand() +void DocLnkSearch::load() { - SearchGroup::expand(); - if (_search.isEmpty()) return; - if (!_docs) _docs = new DocLnkSet(QPEApplication::documentDir()); - QList<DocLnk> appList = _docs->children(); - for ( DocLnk *app = appList.first(); app != 0; app = appList.next() ){ -// if (app->name().contains(_search) || app->comment().contains(_search)) - if ( (_search.match( app->name() ) != -1) - || (_search.match(app->comment()) != -1) - || (_search.match(app->exec()) != -1) ) - new DocLnkItem( this, app ); - } + _apps = new DocLnkSet(QPEApplication::documentDir()); } +void DocLnkSearch::insertItem( void *rec ) +{ + new DocLnkItem( this, (DocLnk*)rec ); +} diff --git a/core/pim/osearch/doclnksearch.h b/core/pim/osearch/doclnksearch.h index ec740de..e2ac40b 100644 --- a/core/pim/osearch/doclnksearch.h +++ b/core/pim/osearch/doclnksearch.h @@ -13,23 +13,21 @@ #ifndef DOCLNKSEARCH_H #define DOCLNKSEARCH_H -#include "searchgroup.h" - -class DocLnkSet; +#include "applnksearch.h" /** @author Patrick S. Vogt */ -class DocLnkSearch : public SearchGroup +class DocLnkSearch : public AppLnkSearch { public: DocLnkSearch(QListView* parent, QString name); - ~DocLnkSearch(); - virtual void expand(); -private: - DocLnkSet *_docs; +protected: + virtual void load(); + virtual void insertItem( void* ); + }; #endif diff --git a/core/pim/osearch/eventitem.cpp b/core/pim/osearch/eventitem.cpp index 758ad85..3b84b42 100644 --- a/core/pim/osearch/eventitem.cpp +++ b/core/pim/osearch/eventitem.cpp @@ -34,17 +34,21 @@ QString EventItem::toRichText() return _event->toRichText(); } -void EventItem::editItem() +void EventItem::action( int act ) { - QCopEnvelope e("QPE/Application/datebook", "editEvent(int)"); - e << _event->uid(); + if (act == 0){ + QCopEnvelope e("QPE/Application/datebook", "viewDefault(QDate)"); + e << _event->startDateTime().date(); + }else if(act == 1){ + QCopEnvelope e("QPE/Application/datebook", "editEvent(int)"); + e << _event->uid(); + } } -void EventItem::showItem() +QIntDict<QString> EventItem::actions() { - QCopEnvelope e("QPE/Application/datebook", "viewDefault(QDate)"); - QDate day = _event->startDateTime().date(); - qDebug("sending view day %s",day.toString().latin1()); - e << day; + QIntDict<QString> result; + result.insert( 0, new QString( QObject::tr("show") ) ); + result.insert( 1, new QString( QObject::tr("edit") ) ); + return result; } - diff --git a/core/pim/osearch/eventitem.h b/core/pim/osearch/eventitem.h index 999f0ac..d0d45a8 100644 --- a/core/pim/osearch/eventitem.h +++ b/core/pim/osearch/eventitem.h @@ -28,8 +28,8 @@ public: ~EventItem(); virtual QString toRichText(); - virtual void editItem(); - virtual void showItem(); + virtual void action( int ); + virtual QIntDict<QString> actions(); private: OEvent *_event; diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp index 140d7bb..a0b7b23 100644 --- a/core/pim/osearch/mainwindow.cpp +++ b/core/pim/osearch/mainwindow.cpp @@ -25,7 +25,9 @@ #include <qstring.h> #include <qlabel.h> #include <qfile.h> +#include <qhbuttongroup.h> #include <qpushbutton.h> +#include <qintdict.h> #include <qlayout.h> #include <qlineedit.h> #include <qtextbrowser.h> @@ -44,7 +46,7 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : { setCaption( tr("OSearch") ); - setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); + setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); QFrame *mainFrame = new QFrame( this, "mainFrame" ); @@ -53,33 +55,41 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : mainLayout->setMargin( 0 ); resultsList = new OListView( mainFrame ); - resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); - mainLayout->addWidget( resultsList ); + resultsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); + mainLayout->addWidget( resultsList, 1 ); detailsFrame = new QFrame( mainFrame, "detailsFrame" ); QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); richEdit = new QTextView( detailsFrame ); - richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); - detailsLayout->addWidget( richEdit, 0 ); - QHBoxLayout *buttonLayout = new QHBoxLayout( detailsFrame ); - detailsLayout->addLayout( buttonLayout, 0 ); + richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); + //richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum )); + detailsLayout->addWidget( richEdit, 1 ); + + buttonGroupActions = new QHButtonGroup( this ); + _buttonCount = 0; +// buttonGroupActions->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); + + buttonLayout = new QHBoxLayout( detailsFrame ); + buttonGroupActions->hide(); + //buttonLayout->addWidget( buttonGroupActions, 0 ); + + detailsLayout->addLayout( buttonLayout ); + /* QPushButton *buttonShow = new QPushButton( detailsFrame, "Show" ); buttonShow->setText( tr("show") ); -// buttonShow->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); QPushButton *buttonEdit = new QPushButton( detailsFrame, "Edit" ); buttonEdit->setText( tr("edit") ); - // buttonEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); buttonLayout->addWidget( buttonShow, 0 ); buttonLayout->addWidget( buttonEdit, 0 ); - - mainLayout->addWidget( detailsFrame, 0 ); +*/ + mainLayout->addWidget( detailsFrame ); detailsFrame->hide(); - adrSearch = new AdressSearch( resultsList, tr("adressbook") ); - todoSearch = new TodoSearch( resultsList, tr("todo") ); - datebookSearch = new DatebookSearch( resultsList, tr("datebook") ); - applnkSearch = new AppLnkSearch( resultsList, tr("applications") ); - doclnkSearch = new DocLnkSearch( resultsList, tr("documents") ); + searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); + searches.append( new TodoSearch( resultsList, tr("todo") ) ); + searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); + searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); + searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); makeMenu(); setCentralWidget( mainFrame ); @@ -89,9 +99,8 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); - connect(buttonShow, SIGNAL(clicked()), SLOT( showItem() ) ); - connect(buttonEdit, SIGNAL(clicked()), SLOT( editItem() ) ); - + connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); +// connect(buttonEdit, SIGNAL(clicked()), SLOT( editItem() ) ); } @@ -136,6 +145,30 @@ void MainWindow::setCurrent(QListViewItem *item) ResultItem *res = (ResultItem*)item; // ResultItem *res = dynamic_cast<ResultItem*>(item); richEdit->setText( res->toRichText() ); + QIntDict<QString> acts = res->actions(); + QButton *button; + for (uint i = 0; i < acts.count(); i++){ + button = buttonGroupActions->find( i ); + qDebug("action %i >%s<",i,acts[i]->latin1()); + if (!button) { + qDebug("BUTTON"); + button = new QPushButton( detailsFrame ); + buttonLayout->addWidget( button, 0 ); + buttonGroupActions->insert( button, i); + } + button->setText( *acts[i] ); + button->show(); + } + for (uint i = acts.count(); i < _buttonCount; i++){ + qDebug("remove button %i of %i",i, _buttonCount); + button = buttonGroupActions->find( i ); + if (button) button->hide(); + } + _buttonCount = acts.count(); +// buttonShow = new QPushButton( detailsFrame, "Show" ) ; +// buttonShow->setText( "test" ); +// buttonLayout->addWidget( buttonShow, 0 ); +// buttonGroupActions->insert(buttonShow); detailsFrame->show(); }else detailsFrame->hide(); //_currentItem = (OListViewItem*)item; @@ -150,33 +183,22 @@ void MainWindow::stopTimer(QListViewItem*) void MainWindow::showPopup() { qDebug("showPopup"); - if (!_item) return; + if (!_currentItem) return; } void MainWindow::setSearch( const QString &key ) { - adrSearch->setSearch(key); - todoSearch->setSearch(key); - datebookSearch->setSearch(key); - applnkSearch->setSearch(key); - doclnkSearch->setSearch(key); + for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) + s->setSearch( key ); } -void MainWindow::showItem() +void MainWindow::slotAction( int act) { if (_currentItem->rtti() == OListViewItem::Result){ ResultItem *res = (ResultItem*)_currentItem; // ResultItem *res = dynamic_cast<ResultItem*>(item); - res->showItem(); + res->action(act); } } -void MainWindow::editItem() -{ - if (_currentItem->rtti() == OListViewItem::Result){ - ResultItem *res = (ResultItem*)_currentItem; -// ResultItem *res = dynamic_cast<ResultItem*>(item); - res->editItem(); - } -} diff --git a/core/pim/osearch/mainwindow.h b/core/pim/osearch/mainwindow.h index 424b4ba..f6ae0a4 100644 --- a/core/pim/osearch/mainwindow.h +++ b/core/pim/osearch/mainwindow.h @@ -15,21 +15,21 @@ #include <qmainwindow.h> #include <qdialog.h> #include <qaction.h> +#include <qlist.h> #include <qtimer.h> #include <qpopupmenu.h> class QPEToolBar; class QVBoxLayout; +class QHBoxLayout; class QTextView; class QFrame; class QListViewItem; class OListView; class OListViewItem; -class AdressSearch; -class TodoSearch; -class DatebookSearch; -class AppLnkSearch; -class DocLnkSearch; +class QHButtonGroup; + +class SearchGroup; class MainWindow : public QMainWindow { @@ -48,24 +48,21 @@ public slots: void setSearch( const QString& ); protected slots: - void showItem(); - void editItem(); + void slotAction(int); private: OListView *resultsList; QTextView *richEdit; OListViewItem *_currentItem; QVBoxLayout *mainLayout; + QHBoxLayout *buttonLayout; QFrame *detailsFrame; - OListViewItem *_item; +// OListViewItem *_item; QTimer *popupTimer; - AdressSearch *adrSearch; - TodoSearch *todoSearch; - DatebookSearch *datebookSearch; - AppLnkSearch *applnkSearch; - DocLnkSearch *doclnkSearch; - + QList<SearchGroup> searches; + QHButtonGroup *buttonGroupActions; + uint _buttonCount; void makeMenu(); }; diff --git a/core/pim/osearch/resultitem.cpp b/core/pim/osearch/resultitem.cpp index 31114d2..2c1e95a 100644 --- a/core/pim/osearch/resultitem.cpp +++ b/core/pim/osearch/resultitem.cpp @@ -27,15 +27,3 @@ ResultItem::ResultItem(OListViewItem* parent) ResultItem::~ResultItem() { } - -void ResultItem::showItem() -{ - QMessageBox::warning(0,"Not implemented","show is not yet implemented for this"); -} - - -void ResultItem::editItem() -{ - QMessageBox::warning(0,"Not implemented","edit is not yet implemented for this"); -} - diff --git a/core/pim/osearch/resultitem.h b/core/pim/osearch/resultitem.h index 2cfb7f8..9e87f99 100644 --- a/core/pim/osearch/resultitem.h +++ b/core/pim/osearch/resultitem.h @@ -13,6 +13,8 @@ #ifndef RESULTITEM_H #define RESULTITEM_H +#include <qintdict.h> + #include "olistviewitem.h" /** @@ -26,8 +28,8 @@ public: virtual QString toRichText() {return "no text";}; virtual int rtti() { return Result;} - virtual void showItem(); - virtual void editItem(); + virtual void action( int ) = 0; + virtual QIntDict<QString> actions() = 0; }; #endif diff --git a/core/pim/osearch/searchgroup.cpp b/core/pim/osearch/searchgroup.cpp index dce3b14..d062207 100644 --- a/core/pim/osearch/searchgroup.cpp +++ b/core/pim/osearch/searchgroup.cpp @@ -11,12 +11,16 @@ // // #include "searchgroup.h" + +#include <qregexp.h> + #include "olistviewitem.h" SearchGroup::SearchGroup(QListView* parent, QString name) : OListViewItem(parent, name) { _name = name; + loaded = false; expanded = false; } @@ -28,14 +32,26 @@ SearchGroup::~SearchGroup() void SearchGroup::expand() { + clearList(); + if (_search.isEmpty()) return; + OListViewItem *dummy = new OListViewItem( this, "searching..."); + setOpen( expanded ); + if (!loaded) load(); + int res_count = search(); + setText(0, _name + " - " + _search.pattern() + " (" + QString::number( res_count ) + ")"); + delete dummy; +} + + +void SearchGroup::clearList() +{ QListViewItem *item = firstChild(); QListViewItem *toDel; while ( item != 0 ) { - toDel = item; - item = item->nextSibling(); - //takeItem(toDel); - delete toDel; + toDel = item; + item = item->nextSibling(); + delete toDel; } expanded = true; } diff --git a/core/pim/osearch/searchgroup.h b/core/pim/osearch/searchgroup.h index d26ff17..ebe1193 100644 --- a/core/pim/osearch/searchgroup.h +++ b/core/pim/osearch/searchgroup.h @@ -15,7 +15,7 @@ #include "olistviewitem.h" -#include <qregexp.h> +class QRegExp; /** @author Patrick S. Vogt @@ -32,11 +32,18 @@ public: virtual void setSearch(QRegExp); virtual int rtti() { return Searchgroup;} + + protected: QRegExp _search; + virtual void load() = 0; + virtual int search() = 0; + virtual void insertItem( void* ) = 0; private: + void clearList(); QString _name; bool expanded; + bool loaded; }; #endif diff --git a/core/pim/osearch/todoitem.cpp b/core/pim/osearch/todoitem.cpp index 145b423..8b354f1 100644 --- a/core/pim/osearch/todoitem.cpp +++ b/core/pim/osearch/todoitem.cpp @@ -2,7 +2,7 @@ // // C++ Implementation: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -22,33 +22,31 @@ TodoItem::TodoItem(OListViewItem* parent, OTodo *todo) setText( 0, todo->toShortText() ); } - TodoItem::~TodoItem() { delete _todo; } - -void TodoItem::expand() -{ - ResultItem::expand(); -} - QString TodoItem::toRichText() { return _todo->toRichText(); } -void TodoItem::showItem() +void TodoItem::action( int act ) { -// QCopEnvelope e("QPE/Todolist", "show(int)"); - QCopEnvelope e("QPE/Application/todolist", "show(int)"); - e << _todo->uid(); + if (act == 0){ + QCopEnvelope e("QPE/Application/todolist", "show(int)"); + e << _todo->uid(); + }else if (act == 1){ + QCopEnvelope e("QPE/Application/todolist", "edit(int)"); + e << _todo->uid(); + } } -void TodoItem::editItem() +QIntDict<QString> TodoItem::actions() { -// QCopEnvelope e("QPE/Todolist", "edit(int)"); - QCopEnvelope e("QPE/Application/todolist", "edit(int)"); - e << _todo->uid(); + QIntDict<QString> result; + result.insert( 0, new QString( QObject::tr("show") ) ); + result.insert( 1, new QString( QObject::tr("edit") ) ); + return result; } diff --git a/core/pim/osearch/todoitem.h b/core/pim/osearch/todoitem.h index 6f34915..9dfd4ff 100644 --- a/core/pim/osearch/todoitem.h +++ b/core/pim/osearch/todoitem.h @@ -2,7 +2,7 @@ // // C++ Interface: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 @@ -25,10 +25,9 @@ public: TodoItem(OListViewItem* parent, OTodo *todo); ~TodoItem(); - virtual void expand(); virtual QString toRichText(); - virtual void showItem(); - virtual void editItem(); + virtual void action( int ); + virtual QIntDict<QString> actions(); private: OTodo *_todo; diff --git a/core/pim/osearch/todosearch.cpp b/core/pim/osearch/todosearch.cpp index cbe356b..6a73530 100644 --- a/core/pim/osearch/todosearch.cpp +++ b/core/pim/osearch/todosearch.cpp @@ -30,22 +30,21 @@ TodoSearch::~TodoSearch() } -void TodoSearch::expand() +void TodoSearch::load() { - SearchGroup::expand(); - if (_search.isEmpty()) return; - - if (!_todos){ _todos = new OTodoAccess(); _todos->load(); - } +} +int TodoSearch::search() +{ ORecordList<OTodo> results = _todos->matchRegexp(_search); - setText(0, text(0) + " (" + QString::number( results.count() ) + ")"); - for (uint i = 0; i < results.count(); i++) { + for (uint i = 0; i < results.count(); i++) new TodoItem( this, new OTodo( results[i] )); - } - + return results.count(); } +void TodoSearch::insertItem( void* ) +{ +} diff --git a/core/pim/osearch/todosearch.h b/core/pim/osearch/todosearch.h index 856be1f..1d025d6 100644 --- a/core/pim/osearch/todosearch.h +++ b/core/pim/osearch/todosearch.h @@ -20,14 +20,18 @@ class OTodoAccess; /** @author Patrick S. Vogt */ -class TodoSearch : public SearchGroup +class TodoSearch : public SearchGroup { public: TodoSearch(QListView* parent, QString name); ~TodoSearch(); - virtual void expand(); +protected: + virtual void load(); + virtual int search(); + virtual void insertItem( void* ); + private: OTodoAccess *_todos; }; |