Diffstat (limited to 'core/pim/osearch/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/osearch/mainwindow.cpp | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp index b80c637..89ab690 100644 --- a/core/pim/osearch/mainwindow.cpp +++ b/core/pim/osearch/mainwindow.cpp | |||
@@ -14,16 +14,17 @@ | |||
14 | 14 | ||
15 | #include <qpe/qpemenubar.h> | 15 | #include <qpe/qpemenubar.h> |
16 | #include <qpe/qpemessagebox.h> | 16 | #include <qpe/qpemessagebox.h> |
17 | #include <qpe/resource.h> | 17 | #include <qpe/resource.h> |
18 | #include <qpe/config.h> | 18 | #include <qpe/config.h> |
19 | #include <qpe/qpetoolbar.h> | 19 | #include <qpe/qpetoolbar.h> |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/config.h> | 21 | #include <qpe/config.h> |
22 | #include <qpe/global.h> | ||
22 | #include <qaction.h> | 23 | #include <qaction.h> |
23 | #include <qmessagebox.h> | 24 | #include <qmessagebox.h> |
24 | #include <qpopupmenu.h> | 25 | #include <qpopupmenu.h> |
25 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
26 | #include <qstring.h> | 27 | #include <qstring.h> |
27 | #include <qlabel.h> | 28 | #include <qlabel.h> |
28 | #include <qfile.h> | 29 | #include <qfile.h> |
29 | #include <qhbuttongroup.h> | 30 | #include <qhbuttongroup.h> |
@@ -79,60 +80,75 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
79 | detailsFrame->hide(); | 80 | detailsFrame->hide(); |
80 | 81 | ||
81 | searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); | 82 | searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); |
82 | searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); | 83 | searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); |
83 | searches.append( new TodoSearch( resultsList, tr("todo") ) ); | 84 | searches.append( new TodoSearch( resultsList, tr("todo") ) ); |
84 | searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); | 85 | searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); |
85 | searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); | 86 | searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); |
86 | 87 | ||
87 | makeMenu(); | ||
88 | setCentralWidget( mainFrame ); | 88 | setCentralWidget( mainFrame ); |
89 | 89 | ||
90 | popupTimer = new QTimer(); | 90 | popupTimer = new QTimer(); |
91 | searchTimer = new QTimer(); | 91 | searchTimer = new QTimer(); |
92 | 92 | ||
93 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); | 93 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); |
94 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); | 94 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); |
95 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); | 95 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); |
96 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); | 96 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); |
97 | connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); | 97 | connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); |
98 | 98 | ||
99 | makeMenu(); | ||
99 | 100 | ||
100 | Config cfg( "osearch", Config::User ); | 101 | Config cfg( "osearch", Config::User ); |
101 | cfg.setGroup( "search_settings" ); | 102 | cfg.setGroup( "search_settings" ); |
102 | actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); | 103 | actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); |
103 | actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); | 104 | actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); |
105 | // actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) ); | ||
104 | } | 106 | } |
105 | 107 | ||
106 | void MainWindow::makeMenu() | 108 | void MainWindow::makeMenu() |
107 | { | 109 | { |
108 | QPEToolBar *toolBar = new QPEToolBar( this ); | 110 | QPEToolBar *toolBar = new QPEToolBar( this ); |
109 | QPEToolBar *searchBar = new QPEToolBar(this); | 111 | QPEToolBar *searchBar = new QPEToolBar(this); |
110 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); | 112 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); |
111 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); | 113 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); |
112 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); | 114 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); |
113 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); | 115 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); |
114 | QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); | 116 | QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); |
115 | 117 | ||
116 | setToolBarsMovable( false ); | 118 | setToolBarsMovable( false ); |
117 | toolBar->setHorizontalStretchable( true ); | 119 | toolBar->setHorizontalStretchable( true ); |
118 | menuBar->insertItem( tr( "Search" ), searchMenu ); | 120 | menuBar->insertItem( tr( "Search" ), searchMenu ); |
119 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); | 121 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); |
122 | |||
123 | //SETTINGS MENU | ||
120 | cfgMenu->insertItem( tr( "Search" ), searchOptions ); | 124 | cfgMenu->insertItem( tr( "Search" ), searchOptions ); |
125 | QPopupMenu *pop; | ||
126 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ | ||
127 | pop = s->popupMenu(); | ||
128 | if (pop){ | ||
129 | qDebug("inserting settings menu for %s",s->text(0).latin1()); | ||
130 | cfgMenu->insertItem( s->text(0), pop ); | ||
131 | //connect( pop, SIGNAL( activated(int) ), SLOT( optionChanged(int) ) ); | ||
132 | } | ||
133 | } | ||
121 | 134 | ||
122 | 135 | ||
123 | //SEARCH | 136 | //SEARCH |
124 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); | 137 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); |
125 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); | 138 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); |
126 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); | 139 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); |
127 | SearchAllAction->addTo( searchMenu ); | 140 | SearchAllAction->addTo( searchMenu ); |
128 | searchMenu->insertItem( tr( "Options" ), searchOptions ); | 141 | searchMenu->insertItem( tr( "Options" ), searchOptions ); |
142 | //connect( searchOptions, SIGNAL( activated(int) ), SLOT( optionChanged(int) ) ); | ||
129 | 143 | ||
130 | //SEARCH OPTIONS | 144 | //SEARCH OPTIONS |
145 | //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true ); | ||
146 | //actionWholeWordsOnly->addTo( searchOptions ); | ||
131 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); | 147 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); |
132 | actionCaseSensitiv->addTo( searchOptions ); | 148 | actionCaseSensitiv->addTo( searchOptions ); |
133 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); | 149 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); |
134 | actionWildcards->addTo( searchOptions ); | 150 | actionWildcards->addTo( searchOptions ); |
135 | 151 | ||
136 | //SEARCH BAR | 152 | //SEARCH BAR |
137 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 153 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
138 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); | 154 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); |
@@ -146,16 +162,17 @@ void MainWindow::makeMenu() | |||
146 | } | 162 | } |
147 | 163 | ||
148 | MainWindow::~MainWindow() | 164 | MainWindow::~MainWindow() |
149 | { | 165 | { |
150 | Config cfg( "osearch", Config::User ); | 166 | Config cfg( "osearch", Config::User ); |
151 | cfg.setGroup( "search_settings" ); | 167 | cfg.setGroup( "search_settings" ); |
152 | cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); | 168 | cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); |
153 | cfg.writeEntry( "wildcards", actionWildcards->isOn() ); | 169 | cfg.writeEntry( "wildcards", actionWildcards->isOn() ); |
170 | //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() ); | ||
154 | } | 171 | } |
155 | 172 | ||
156 | void MainWindow::setCurrent(QListViewItem *item) | 173 | void MainWindow::setCurrent(QListViewItem *item) |
157 | { | 174 | { |
158 | if (!item) return; | 175 | if (!item) return; |
159 | _currentItem = (OListViewItem*)item; | 176 | _currentItem = (OListViewItem*)item; |
160 | //_currentItem = dynamic_cast<OListViewItem*>(item); | 177 | //_currentItem = dynamic_cast<OListViewItem*>(item); |
161 | if (_currentItem->rtti() == OListViewItem::Result){ | 178 | if (_currentItem->rtti() == OListViewItem::Result){ |
@@ -177,61 +194,71 @@ void MainWindow::setCurrent(QListViewItem *item) | |||
177 | button->show(); | 194 | button->show(); |
178 | } | 195 | } |
179 | for (uint i = acts.count(); i < _buttonCount; i++){ | 196 | for (uint i = acts.count(); i < _buttonCount; i++){ |
180 | qDebug("remove button %i of %i",i, _buttonCount); | 197 | qDebug("remove button %i of %i",i, _buttonCount); |
181 | button = buttonGroupActions->find( i ); | 198 | button = buttonGroupActions->find( i ); |
182 | if (button) button->hide(); | 199 | if (button) button->hide(); |
183 | } | 200 | } |
184 | _buttonCount = acts.count(); | 201 | _buttonCount = acts.count(); |
185 | // buttonShow = new QPushButton( detailsFrame, "Show" ) ; | ||
186 | // buttonShow->setText( "test" ); | ||
187 | // buttonLayout->addWidget( buttonShow, 0 ); | ||
188 | // buttonGroupActions->insert(buttonShow); | ||
189 | detailsFrame->show(); | 202 | detailsFrame->show(); |
190 | }else detailsFrame->hide(); | 203 | }else detailsFrame->hide(); |
191 | //_currentItem = (OListViewItem*)item; | 204 | popupTimer->start( 300, true ); |
192 | popupTimer->start( 300 ); | ||
193 | } | 205 | } |
194 | 206 | ||
195 | void MainWindow::stopTimer(QListViewItem*) | 207 | void MainWindow::stopTimer(QListViewItem*) |
196 | { | 208 | { |
197 | popupTimer->stop(); | 209 | popupTimer->stop(); |
198 | } | 210 | } |
199 | 211 | ||
200 | void MainWindow::showPopup() | 212 | void MainWindow::showPopup() |
201 | { | 213 | { |
202 | qDebug("showPopup"); | 214 | qDebug("showPopup"); |
215 | popupTimer->stop(); | ||
203 | if (!_currentItem) return; | 216 | if (!_currentItem) return; |
217 | QPopupMenu *pop = _currentItem->popupMenu(); | ||
218 | if (pop) pop->popup( QCursor::pos() ); | ||
204 | } | 219 | } |
205 | 220 | ||
206 | void MainWindow::setSearch( const QString &key ) | 221 | void MainWindow::setSearch( const QString &key ) |
207 | { | 222 | { |
208 | searchTimer->stop(); | 223 | searchTimer->stop(); |
209 | _searchString = key; | 224 | _searchString = key; |
210 | searchTimer->start( 300 ); | 225 | searchTimer->start( 300 ); |
211 | } | 226 | } |
212 | 227 | ||
213 | void MainWindow::searchStringChanged() | 228 | void MainWindow::searchStringChanged() |
214 | { | 229 | { |
215 | searchTimer->stop(); | 230 | searchTimer->stop(); |
216 | QRegExp re( _searchString, actionCaseSensitiv->isOn(), actionWildcards->isOn() ); | 231 | QString ss = _searchString; |
232 | //ss = Global::stringQuote( _searchString ); | ||
233 | //if (actionWholeWordsOnly->isOn()) | ||
234 | // ss = "\\s"+_searchString+"\\s"; | ||
235 | qDebug(" set searchString >%s<",ss.latin1()); | ||
236 | QRegExp re( ss ); | ||
237 | re.setCaseSensitive( actionCaseSensitiv->isOn() ); | ||
238 | re.setWildcard( actionWildcards->isOn() ); | ||
217 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) | 239 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) |
218 | s->setSearch( re ); | 240 | s->setSearch( re ); |
219 | } | 241 | } |
220 | 242 | ||
221 | void MainWindow::searchAll() | 243 | void MainWindow::searchAll() |
222 | { | 244 | { |
223 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ | 245 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ |
224 | s->doSearch(); | 246 | s->doSearch(); |
225 | //resultsList->repaint(); | 247 | //resultsList->repaint(); |
226 | } | 248 | } |
227 | } | 249 | } |
228 | 250 | ||
229 | void MainWindow::slotAction( int act) | 251 | void MainWindow::slotAction( int act ) |
230 | { | 252 | { |
231 | if (_currentItem->rtti() == OListViewItem::Result){ | 253 | if (_currentItem->rtti() == OListViewItem::Result){ |
232 | ResultItem *res = (ResultItem*)_currentItem; | 254 | ResultItem *res = (ResultItem*)_currentItem; |
233 | // ResultItem *res = dynamic_cast<ResultItem*>(item); | 255 | // ResultItem *res = dynamic_cast<ResultItem*>(item); |
234 | res->action(act); | 256 | res->action(act); |
235 | } | 257 | } |
236 | } | 258 | } |
237 | 259 | ||
260 | void MainWindow::optionChanged(int i) | ||
261 | { | ||
262 | qDebug("optionChanged(%i)",i); | ||
263 | searchStringChanged(); | ||
264 | } | ||