00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "olistview.h"
00014 #include "olistviewitem.h"
00015 #include "resultitem.h"
00016 #include "adresssearch.h"
00017 #include "todosearch.h"
00018 #include "datebooksearch.h"
00019 #include "applnksearch.h"
00020 #include "doclnksearch.h"
00021 #include "mainwindow.h"
00022
00023 #include <opie2/odebug.h>
00024 #include <opie2/oresource.h>
00025 #include <opie2/owait.h>
00026
00027 #include <qpe/qpemessagebox.h>
00028 #include <qpe/config.h>
00029
00030 #include <qpe/qpeapplication.h>
00031 #include <qpe/global.h>
00032
00033 #include <qtoolbar.h>
00034 #include <qaction.h>
00035 #include <qmessagebox.h>
00036 #include <qpopupmenu.h>
00037 #include <qtoolbutton.h>
00038 #include <qstring.h>
00039 #include <qlabel.h>
00040 #include <qfile.h>
00041 #include <qhbuttongroup.h>
00042 #include <qhbox.h>
00043 #include <qpushbutton.h>
00044 #include <qintdict.h>
00045 #include <qlayout.h>
00046 #include <qlineedit.h>
00047 #include <qsignalmapper.h>
00048 #include <qtextbrowser.h>
00049 #include <qregexp.h>
00050 #include <qwhatsthis.h>
00051 #include <qmenubar.h>
00052
00053
00054
00055 static const char* const image1_data[] = {
00056 "14 14 3 1",
00057 ". c None",
00058 "# c #000000",
00059 "a c #ff0000",
00060 "..............",
00061 "..##.......###",
00062 ".#aa#....##aa#",
00063 "#aaaa#.##aaaa#",
00064 ".##aaa#aaaaa##",
00065 "...#aaaaaaa#..",
00066 "....#aaaaa#...",
00067 "...#aaaaa#....",
00068 "..#aaaaaaa#...",
00069 ".#aaaaaaaaa#..",
00070 "#aaaa###aaaa#.",
00071 "#aaa#..##aaa#.",
00072 "#aaa#...#aa#..",
00073 ".###.....##..."};
00074
00075
00076 MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
00077 QMainWindow( parent, name, f ), _currentItem(0)
00078 {
00079 setCaption( tr("OSearch") );
00080
00081 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00082
00083 QFrame *mainFrame = new QFrame( this, "mainFrame" );
00084 mainFrame->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00085
00086 mainLayout = new QVBoxLayout( mainFrame );
00087 mainLayout->setSpacing( 0 );
00088 mainLayout->setMargin( 3 );
00089
00090 resultsList = new OListView( mainFrame );
00091 resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00092 mainLayout->addWidget( resultsList );
00093
00094 detailsFrame = new QFrame( mainFrame, "detailsFrame" );
00095 QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame );
00096 richEdit = new QTextView( detailsFrame );
00097 QWhatsThis::add( richEdit, tr("The details of the current result") );
00098 richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00099 detailsLayout->addWidget( richEdit );
00100
00101 buttonBox = new QHBox( mainFrame, "Button Box" );
00102
00103 _buttonCount = 0;
00104
00105 mainLayout->addWidget( detailsFrame );
00106 mainLayout->addWidget( buttonBox );
00107 detailsFrame->hide();
00108 buttonBox->hide();
00109
00110 searches.append( new AppLnkSearch( resultsList, tr("Applications") ) );
00111 searches.append( new DocLnkSearch( resultsList, tr("Documents") ) );
00112 searches.append( new TodoSearch( resultsList, tr("Todo List") ) );
00113 searches.append( new DatebookSearch( resultsList, tr("Calendar") ) );
00114 searches.append( new AdressSearch( resultsList, tr("Contacts") ) );
00115
00116 setCentralWidget( mainFrame );
00117
00118 popupTimer = new QTimer();
00119 searchTimer = new QTimer();
00120
00121 connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup()));
00122 connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged()));
00123 connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*)));
00124 connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*)));
00125
00126 signalMapper = new QSignalMapper( this );
00127
00128 connect(signalMapper, SIGNAL(mapped(int)), SLOT( slotAction(int) ) );
00129
00130 makeMenu();
00131
00132 Config cfg( "osearch", Config::User );
00133 cfg.setGroup( "search_settings" );
00134 actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) );
00135 actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) );
00136
00137 }
00138
00139 void MainWindow::makeMenu()
00140 {
00141 QToolBar *toolBar = new QToolBar( this );
00142 QToolBar *searchBar = new QToolBar(this);
00143 QMenuBar *menuBar = new QMenuBar( toolBar );
00144 QPopupMenu *searchMenu = new QPopupMenu( menuBar );
00145
00146 QPopupMenu *cfgMenu = new QPopupMenu( menuBar );
00147 QPopupMenu *searchOptions = new QPopupMenu( cfgMenu );
00148
00149 setToolBarsMovable( false );
00150 toolBar->setHorizontalStretchable( true );
00151 menuBar->insertItem( tr( "Search" ), searchMenu );
00152 menuBar->insertItem( tr( "Settings" ), cfgMenu );
00153
00154
00155 cfgMenu->insertItem( tr( "Search" ), searchOptions );
00156 QPopupMenu *pop;
00157 for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){
00158 pop = s->popupMenu();
00159 if (pop){
00160 cfgMenu->insertItem( s->text(0), pop );
00161 }
00162 }
00163
00164
00165
00166 SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 );
00167 SearchAllAction->setIconSet( Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ) );
00168
00169 connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) );
00170 SearchAllAction->addTo( searchMenu );
00171 searchMenu->insertItem( tr( "Options" ), searchOptions );
00172
00173
00174
00175
00176 actionCaseSensitiv = new QAction( tr("Case sensitive"),QString::null, 0, this, 0, true );
00177 actionCaseSensitiv->addTo( searchOptions );
00178 actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true );
00179 actionWildcards->addTo( searchOptions );
00180
00181
00182 LabelEnterText = new QLabel( searchBar, "Label" );
00183 LabelEnterText->setAutoMask( FALSE );
00184 LabelEnterText->setText( tr( "Search for: " ) );
00185 LabelEnterText->setFrameStyle( QFrame::NoFrame );
00186 LabelEnterText->setBackgroundMode( PaletteButton );
00187
00188 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
00189 QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" );
00190 QWhatsThis::add( searchEdit, tr("Enter your search terms here") );
00191 searchEdit->setFocus();
00192 searchBar->setHorizontalStretchable( TRUE );
00193 searchBar->setStretchableWidget( searchEdit );
00194
00195
00196 SearchAllAction->addTo( searchBar );
00197
00198
00199 QPixmap image1( ( const char** ) image1_data );
00200
00201
00202 ClearSearchText = new QToolButton( searchBar, "ClearSearchText");
00203 ClearSearchText->setText( "" );
00204 ClearSearchText->setPixmap( image1 );
00205
00206 connect( searchEdit, SIGNAL( textChanged(const QString&) ),this, SLOT( setSearch(const QString&) ) );
00207 connect( ClearSearchText, SIGNAL( clicked() ), searchEdit, SLOT( clear() ) );
00208
00209 }
00210
00211 MainWindow::~MainWindow()
00212 {
00213 Config cfg( "osearch", Config::User );
00214 cfg.setGroup( "search_settings" );
00215 cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() );
00216 cfg.writeEntry( "wildcards", actionWildcards->isOn() );
00217
00218 }
00219
00220 void MainWindow::setCurrent(QListViewItem *item)
00221 {
00222 if (!item) return;
00223 _currentItem = (OListViewItem*)item;
00224
00225 if (_currentItem->rtti() == OListViewItem::Result){
00226 ResultItem *res = (ResultItem*)item;
00227
00228 richEdit->setText( res->toRichText() );
00229 QIntDict<QString> acts = res->actions();
00230 QButton *button;
00231 for (uint i = 0; i < acts.count(); i++){
00232 button = buttonMap[i];
00233 if (!button) {
00234 owarn << " no button for " << *acts[i] << oendl;
00235 button = new QPushButton( buttonBox );
00236 buttonMap.insert( i, button );
00237 signalMapper->setMapping(button, i );
00238 connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) );
00239 }
00240 button->setText( *acts[i] );
00241 button->show();
00242 }
00243 for (uint i = acts.count(); i < _buttonCount; i++){
00244 button = buttonMap[i];
00245 if (button) button->hide();
00246 }
00247 _buttonCount = acts.count();
00248 detailsFrame->show();
00249 buttonBox->show();
00250
00251 }else {
00252 detailsFrame->hide();
00253 buttonBox->hide();
00254 }
00255 popupTimer->start( 300, true );
00256 }
00257
00258 void MainWindow::stopTimer(QListViewItem*)
00259 {
00260 popupTimer->stop();
00261 }
00262
00263 void MainWindow::showPopup()
00264 {
00265 popupTimer->stop();
00266 if (!_currentItem) return;
00267 QPopupMenu *pop = _currentItem->popupMenu();
00268 if (pop) pop->popup( QCursor::pos() );
00269 }
00270
00271 void MainWindow::setSearch( const QString &key )
00272 {
00273 searchTimer->stop();
00274 _searchString = key;
00275 searchTimer->start( 300 );
00276 }
00277
00278 void MainWindow::searchStringChanged()
00279 {
00280 #ifdef NEW_OWAIT
00281 OWait("setting search string");
00282 #endif
00283 searchTimer->stop();
00284 QString ss = _searchString;
00285
00286
00287
00288
00289 QRegExp re( ss );
00290 re.setCaseSensitive( actionCaseSensitiv->isOn() );
00291 re.setWildcard( actionWildcards->isOn() );
00292 for (SearchGroup *s = searches.first(); s != 0; s = searches.next() )
00293 s->setSearch( re );
00294 }
00295
00296 void MainWindow::searchAll()
00297 {
00298 #ifdef NEW_OWAIT
00299 OWait("searching...");
00300 #endif
00301 for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){
00302 s->doSearch();
00303
00304 }
00305 }
00306
00307 void MainWindow::slotAction( int act )
00308 {
00309 if ( _currentItem && _currentItem->rtti() == OListViewItem::Result){
00310 ResultItem *res = (ResultItem*)_currentItem;
00311
00312 res->action(act);
00313 }
00314 }
00315
00316 void MainWindow::optionChanged(int )
00317 {
00318 searchStringChanged();
00319 }