-rw-r--r-- | core/pim/osearch/applnksearch.cpp | 4 | ||||
-rw-r--r-- | core/pim/osearch/applnksearch.h | 6 | ||||
-rw-r--r-- | core/pim/osearch/doclnksearch.cpp | 56 | ||||
-rw-r--r-- | core/pim/osearch/doclnksearch.h | 13 | ||||
-rw-r--r-- | core/pim/osearch/mainwindow.cpp | 10 | ||||
-rw-r--r-- | core/pim/osearch/searchgroup.cpp | 15 | ||||
-rw-r--r-- | core/pim/osearch/searchgroup.h | 3 |
7 files changed, 87 insertions, 20 deletions
diff --git a/core/pim/osearch/applnksearch.cpp b/core/pim/osearch/applnksearch.cpp index 5fa36bb..403c719 100644 --- a/core/pim/osearch/applnksearch.cpp +++ b/core/pim/osearch/applnksearch.cpp @@ -1,67 +1,69 @@ // // // C++ Implementation: $MODULE$ // // Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // #include "applnksearch.h" #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qiconset.h> #include <qpe/resource.h> #include "applnkitem.h" AppLnkSearch::AppLnkSearch(QListView* parent, QString name): SearchGroup(parent, name) { _apps = 0; QIconSet is = Resource::loadIconSet( "osearch/applications" ); //QIconSet is = Resource::loadIconSet( "AppsIcon" ); setPixmap( 0, is.pixmap( QIconSet::Small, true ) ); } AppLnkSearch::~AppLnkSearch() { delete _apps; } void AppLnkSearch::load() { _apps = new AppLnkSet(QPEApplication::qpeDir()); } int AppLnkSearch::search() { QList<AppLnk> appList = _apps->children(); for ( AppLnk *app = appList.first(); app != 0; app = appList.next() ){ if ( (_search.match( app->name() ) != -1) || (_search.match(app->comment()) != -1) || (_search.match(app->exec()) != -1) ) { insertItem( app ); - } + }else + if (searchFile( app )) + insertItem( app ); qApp->processEvents( 100 ); } return _resultCount; } void AppLnkSearch::insertItem( void *rec ) { new AppLnkItem( this, (AppLnk*)rec ); _resultCount++; } void AppLnkSearch::setSearch(QRegExp re) { setOpen( false ); SearchGroup::setSearch( re ); } diff --git a/core/pim/osearch/applnksearch.h b/core/pim/osearch/applnksearch.h index 6bb7486..853064d 100644 --- a/core/pim/osearch/applnksearch.h +++ b/core/pim/osearch/applnksearch.h @@ -1,38 +1,40 @@ // // // C++ Interface: $MODULE$ // // Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // #ifndef APPLNKSEARCH_H #define APPLNKSEARCH_H #include "searchgroup.h" class AppLnkSet; +class AppLnk; /** @author Patrick S. Vogt */ class AppLnkSearch : public SearchGroup { public: AppLnkSearch(QListView* parent, QString name); - ~AppLnkSearch(); virtual void setSearch(QRegExp); + +protected: virtual void load(); virtual int search(); virtual void insertItem( void* ); - + virtual bool searchFile(AppLnk*) { return false; }; AppLnkSet *_apps; }; #endif diff --git a/core/pim/osearch/doclnksearch.cpp b/core/pim/osearch/doclnksearch.cpp index d97eeb8..321d011 100644 --- a/core/pim/osearch/doclnksearch.cpp +++ b/core/pim/osearch/doclnksearch.cpp @@ -1,43 +1,91 @@ // // // C++ Implementation: $MODULE$ // // Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // -#include "doclnksearch.h" -#include <qpe/applnk.h> -#include <qpe/qpeapplication.h> +#include <qaction.h> +#include <qfile.h> #include <qiconset.h> +#include <qpopupmenu.h> +#include <qtextstream.h> +#include <qpe/applnk.h> +#include <qpe/config.h> #include <qpe/resource.h> +#include <qpe/qpeapplication.h> +#include <opie/owait.h> #include "doclnkitem.h" +#include "doclnksearch.h" DocLnkSearch::DocLnkSearch(QListView* parent, QString name) -: AppLnkSearch(parent, name) +: AppLnkSearch(parent, name), _popupMenu(0) { QIconSet is = Resource::loadIconSet( "osearch/documents" ); setPixmap( 0, is.pixmap( QIconSet::Small, true ) ); + + actionSearchInFiles = new QAction( QObject::tr("search content"),QString::null, 0, 0, 0, true ); + Config cfg( "osearch", Config::User ); + cfg.setGroup( "doclnk_settings" ); + actionSearchInFiles->setOn( cfg.readBoolEntry( "search_content", false ) ); } DocLnkSearch::~DocLnkSearch() { + Config cfg( "osearch", Config::User ); + cfg.setGroup( "doclnk_settings" ); + cfg.writeEntry( "search_content", actionSearchInFiles->isOn() ); } void DocLnkSearch::load() { _apps = new DocLnkSet(QPEApplication::documentDir()); } +bool DocLnkSearch::searchFile( AppLnk *app ) +{ + if (!actionSearchInFiles->isOn()) return false; + DocLnk *doc = (DocLnk*)app; + bool found = false; + if ( doc->type().contains( "text" ) ){ +#ifdef NEW_OWAIT + QString ouput = QObject::tr("searching %1").arg(doc->file()); + OWait( output ); +#endif + QFile f(doc->file()); + if ( f.open(IO_ReadOnly) ) { + QTextStream t( &f ); + while ( !t.eof() ) + if (_search.match( t.readLine()) != -1) { + found = true; + break; + } + } + f.close(); + } + return found; +} + void DocLnkSearch::insertItem( void *rec ) { new DocLnkItem( this, (DocLnk*)rec ); _resultCount++; } + + +QPopupMenu* DocLnkSearch::popupMenu() +{ + if (!_popupMenu){ + _popupMenu = new QPopupMenu( 0 ); + actionSearchInFiles->addTo( _popupMenu ); + } + return _popupMenu; +} diff --git a/core/pim/osearch/doclnksearch.h b/core/pim/osearch/doclnksearch.h index e2ac40b..81a8e62 100644 --- a/core/pim/osearch/doclnksearch.h +++ b/core/pim/osearch/doclnksearch.h @@ -1,33 +1,42 @@ // // // C++ Interface: $MODULE$ // -// Description: +// Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // #ifndef DOCLNKSEARCH_H #define DOCLNKSEARCH_H #include "applnksearch.h" +class QAction; +class QPopupMenu; + /** @author Patrick S. Vogt */ -class DocLnkSearch : public AppLnkSearch +class DocLnkSearch : public AppLnkSearch { public: DocLnkSearch(QListView* parent, QString name); ~DocLnkSearch(); + virtual QPopupMenu* popupMenu(); + protected: virtual void load(); + virtual bool searchFile(AppLnk*); virtual void insertItem( void* ); +private: + QAction *actionSearchInFiles; + QPopupMenu *_popupMenu; }; #endif diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp index 89ab690..6070fdf 100644 --- a/core/pim/osearch/mainwindow.cpp +++ b/core/pim/osearch/mainwindow.cpp @@ -1,264 +1,270 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #include "mainwindow.h" #include <qpe/qpemenubar.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/qpetoolbar.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/global.h> +#include <opie/owait.h> #include <qaction.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qtoolbutton.h> #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> #include <qregexp.h> #include "olistview.h" #include "olistviewitem.h" #include "resultitem.h" #include "adresssearch.h" #include "todosearch.h" #include "datebooksearch.h" #include "applnksearch.h" #include "doclnksearch.h" MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), _currentItem(0) { setCaption( tr("OSearch") ); setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); QFrame *mainFrame = new QFrame( this, "mainFrame" ); mainLayout = new QVBoxLayout( mainFrame ); mainLayout->setSpacing( 0 ); mainLayout->setMargin( 0 ); resultsList = new OListView( mainFrame ); 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::Expanding, QSizePolicy::Expanding)); //richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum )); detailsLayout->addWidget( richEdit, 1 ); buttonGroupActions = new QHButtonGroup( this ); buttonGroupActions->hide(); _buttonCount = 0; // buttonGroupActions->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); buttonLayout = new QHBoxLayout( detailsFrame ); detailsLayout->addLayout( buttonLayout ); mainLayout->addWidget( detailsFrame ); detailsFrame->hide(); searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); searches.append( new TodoSearch( resultsList, tr("todo") ) ); searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); setCentralWidget( mainFrame ); popupTimer = new QTimer(); searchTimer = new QTimer(); connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); makeMenu(); Config cfg( "osearch", Config::User ); cfg.setGroup( "search_settings" ); actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); // actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) ); } void MainWindow::makeMenu() { QPEToolBar *toolBar = new QPEToolBar( this ); QPEToolBar *searchBar = new QPEToolBar(this); QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); QPopupMenu *searchMenu = new QPopupMenu( menuBar ); // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); setToolBarsMovable( false ); toolBar->setHorizontalStretchable( true ); menuBar->insertItem( tr( "Search" ), searchMenu ); menuBar->insertItem( tr( "Settings" ), cfgMenu ); //SETTINGS MENU cfgMenu->insertItem( tr( "Search" ), searchOptions ); QPopupMenu *pop; for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ pop = s->popupMenu(); if (pop){ qDebug("inserting settings menu for %s",s->text(0).latin1()); cfgMenu->insertItem( s->text(0), pop ); //connect( pop, SIGNAL( activated(int) ), SLOT( optionChanged(int) ) ); } } //SEARCH SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); SearchAllAction->addTo( searchMenu ); searchMenu->insertItem( tr( "Options" ), searchOptions ); //connect( searchOptions, SIGNAL( activated(int) ), SLOT( optionChanged(int) ) ); //SEARCH OPTIONS //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true ); //actionWholeWordsOnly->addTo( searchOptions ); actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); actionCaseSensitiv->addTo( searchOptions ); actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); actionWildcards->addTo( searchOptions ); //SEARCH BAR addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); searchEdit->setFocus(); searchBar->setHorizontalStretchable( TRUE ); searchBar->setStretchableWidget( searchEdit ); SearchAllAction->addTo( searchBar ); connect( searchEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( setSearch( const QString & ) ) ); } MainWindow::~MainWindow() { Config cfg( "osearch", Config::User ); cfg.setGroup( "search_settings" ); cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); cfg.writeEntry( "wildcards", actionWildcards->isOn() ); //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() ); } void MainWindow::setCurrent(QListViewItem *item) { if (!item) return; _currentItem = (OListViewItem*)item; // _currentItem = dynamic_cast<OListViewItem*>(item); if (_currentItem->rtti() == OListViewItem::Result){ 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(); detailsFrame->show(); }else detailsFrame->hide(); popupTimer->start( 300, true ); } void MainWindow::stopTimer(QListViewItem*) { popupTimer->stop(); } void MainWindow::showPopup() { - qDebug("showPopup"); popupTimer->stop(); if (!_currentItem) return; QPopupMenu *pop = _currentItem->popupMenu(); if (pop) pop->popup( QCursor::pos() ); } void MainWindow::setSearch( const QString &key ) { searchTimer->stop(); _searchString = key; searchTimer->start( 300 ); } void MainWindow::searchStringChanged() { +#ifdef NEW_OWAIT + OWait("setting search string"); +#endif searchTimer->stop(); QString ss = _searchString; //ss = Global::stringQuote( _searchString ); // if (actionWholeWordsOnly->isOn()) // ss = "\\s"+_searchString+"\\s"; - qDebug(" set searchString >%s<",ss.latin1()); +// qDebug(" set searchString >%s<",ss.latin1()); QRegExp re( ss ); re.setCaseSensitive( actionCaseSensitiv->isOn() ); re.setWildcard( actionWildcards->isOn() ); for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) s->setSearch( re ); } void MainWindow::searchAll() { +#ifdef NEW_OWAIT + OWait("searching..."); +#endif for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ s->doSearch(); //resultsList->repaint(); } } void MainWindow::slotAction( int act ) { if (_currentItem->rtti() == OListViewItem::Result){ ResultItem *res = (ResultItem*)_currentItem; // ResultItem *res = dynamic_cast<ResultItem*>(item); res->action(act); } } void MainWindow::optionChanged(int i) { qDebug("optionChanged(%i)",i); searchStringChanged(); } diff --git a/core/pim/osearch/searchgroup.cpp b/core/pim/osearch/searchgroup.cpp index e307696..0b58176 100644 --- a/core/pim/osearch/searchgroup.cpp +++ b/core/pim/osearch/searchgroup.cpp @@ -1,93 +1,92 @@ // // // C++ Implementation: $MODULE$ // // Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // -#include "searchgroup.h" +#include <qobject.h> #include <qregexp.h> #include <qapplication.h> #include <opie/owait.h> #include "olistviewitem.h" +#include "searchgroup.h" -//#define NEW_OWAIT #ifndef NEW_OWAIT static OWait *wait = 0; #endif SearchGroup::SearchGroup(QListView* parent, QString name) : OListViewItem(parent, name) { _name = name; loaded = false; } SearchGroup::~SearchGroup() { } void SearchGroup::expand() { //expanded = true; - clearList(); + if (_lastSearch != _search) clearList(); if (_search.isEmpty()) return; OListViewItem *dummy = new OListViewItem( this, "searching..."); setOpen( true ); repaint(); int res_count = realSearch(); setText(0, _name + " - " + _search.pattern() + " (" + QString::number( res_count ) + ")"); delete dummy; repaint(); } void SearchGroup::doSearch() { clearList(); if (_search.isEmpty()) return; _resultCount = realSearch(); // repaint(); } void SearchGroup::setSearch(QRegExp re) { if (re == _search) return; setText(0, _name+" - "+re.pattern() ); _search = re; if (isOpen()) expand(); else new OListViewItem( this, "searching..."); } int SearchGroup::realSearch() { + if (_lastSearch == _search) return _resultCount; #ifndef NEW_OWAIT - qDebug("NOT using NEW_OWAIT"); if (!wait) wait = new OWait( qApp->mainWidget(), "osearch" ); wait->show(); qApp->processEvents(); #else - qDebug("using NEW_OWAIT"); - OWait::start( "osearch" ); + qDebug("********** NEW_OWAIT *************"); + OWait( "searching" ); #endif if (!loaded) load(); _resultCount = 0; _resultCount = search(); + _lastSearch = _search; setText(0, _name + " - " + _search.pattern() + " (" + QString::number( _resultCount ) + ")"); #ifndef NEW_OWAIT wait->hide(); -#else - OWait::stop(); #endif return _resultCount; } diff --git a/core/pim/osearch/searchgroup.h b/core/pim/osearch/searchgroup.h index a755e06..ad37d4e 100644 --- a/core/pim/osearch/searchgroup.h +++ b/core/pim/osearch/searchgroup.h @@ -1,48 +1,49 @@ // // // C++ Interface: $MODULE$ // // Description: // // // Author: Patrick S. Vogt <tille@handhelds.org>, (C) 2003 // // Copyright: See COPYING file that comes with this distribution // // #ifndef SEARCHGROUP_H #define SEARCHGROUP_H #include "olistviewitem.h" class QRegExp; class QPopupMenu; /** @author Patrick S. Vogt */ class SearchGroup : public OListViewItem { public: SearchGroup(QListView* parent, QString name); ~SearchGroup(); virtual void expand(); virtual void doSearch(); 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; + QRegExp _search; + QRegExp _lastSearch; QString _name; bool loaded; int _resultCount; private: int realSearch(); }; #endif |