00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "doclnkitem.h"
00016 #include "doclnksearch.h"
00017
00018 #include <opie2/oresource.h>
00019 #include <opie2/owait.h>
00020
00021 #include <qpe/applnk.h>
00022 #include <qpe/config.h>
00023 #include <qpe/qpeapplication.h>
00024
00025 #include <qaction.h>
00026 #include <qfile.h>
00027 #include <qpopupmenu.h>
00028 #include <qtextstream.h>
00029
00030
00031 DocLnkSearch::DocLnkSearch(QListView* parent, QString name)
00032 : AppLnkSearch(parent, name), _popupMenu(0)
00033 {
00034 setPixmap( 0, Opie::Core::OResource::loadPixmap( "osearch/documents", Opie::Core::OResource::SmallIcon ) );
00035
00036 actionSearchInFiles = new QAction( QObject::tr("Search content"),QString::null, 0, 0, 0, true );
00037 Config cfg( "osearch", Config::User );
00038 cfg.setGroup( "doclnk_settings" );
00039 actionSearchInFiles->setOn( cfg.readBoolEntry( "search_content", false ) );
00040 }
00041
00042
00043 DocLnkSearch::~DocLnkSearch()
00044 {
00045 Config cfg( "osearch", Config::User );
00046 cfg.setGroup( "doclnk_settings" );
00047 cfg.writeEntry( "search_content", actionSearchInFiles->isOn() );
00048 }
00049
00050 void DocLnkSearch::load()
00051 {
00052 _apps = new DocLnkSet(QPEApplication::documentDir());
00053 }
00054
00055 bool DocLnkSearch::searchFile( AppLnk *app )
00056 {
00057 if (!actionSearchInFiles->isOn()) return false;
00058 DocLnk *doc = (DocLnk*)app;
00059 bool found = false;
00060 if ( doc->type().contains( "text" ) ){
00061 #ifdef NEW_OWAIT
00062 QString ouput = QObject::tr("searching %1").arg(doc->file());
00063 OWait( output );
00064 #endif
00065 QFile f(doc->file());
00066 if ( f.open(IO_ReadOnly) ) {
00067 QTextStream t( &f );
00068 while ( !t.eof() )
00069 if (_search.match( t.readLine()) != -1) {
00070 found = true;
00071 break;
00072 }
00073 }
00074 f.close();
00075 }
00076 return found;
00077 }
00078
00079 void DocLnkSearch::insertItem( void *rec )
00080 {
00081 (void)new DocLnkItem( this, (DocLnk*)rec );
00082 _resultCount++;
00083 }
00084
00085
00086 QPopupMenu* DocLnkSearch::popupMenu()
00087 {
00088 if (!_popupMenu){
00089 _popupMenu = new QPopupMenu( 0 );
00090 actionSearchInFiles->addTo( _popupMenu );
00091 }
00092 return _popupMenu;
00093
00094
00095 #warning FIXME
00096 _resultCount++;
00097 }