summaryrefslogtreecommitdiff
path: root/core/pim/osearch/mainwindow.cpp
Unidiff
Diffstat (limited to 'core/pim/osearch/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/osearch/mainwindow.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp
index 07403a1..55302cb 100644
--- a/core/pim/osearch/mainwindow.cpp
+++ b/core/pim/osearch/mainwindow.cpp
@@ -3,211 +3,247 @@
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 10// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
11 11
12 12
13 13
14#include <qaction.h> 14#include <qaction.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qpopupmenu.h> 16#include <qpopupmenu.h>
17#include <qtoolbutton.h> 17#include <qtoolbutton.h>
18#include <qstring.h> 18#include <qstring.h>
19#include <qlabel.h> 19#include <qlabel.h>
20#include <qfile.h> 20#include <qfile.h>
21#include <qhbuttongroup.h> 21#include <qhbuttongroup.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qpushbutton.h> 23#include <qpushbutton.h>
24#include <qintdict.h> 24#include <qintdict.h>
25#include <qlayout.h> 25#include <qlayout.h>
26#include <qlineedit.h> 26#include <qlineedit.h>
27#include <qsignalmapper.h> 27#include <qsignalmapper.h>
28#include <qtextbrowser.h> 28#include <qtextbrowser.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qwhatsthis.h> 30#include <qwhatsthis.h>
31#include <qmenubar.h> 31#include <qmenubar.h>
32#include <qpe/qpemessagebox.h> 32#include <qpe/qpemessagebox.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qtoolbar.h> 35#include <qtoolbar.h>
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/global.h> 38#include <qpe/global.h>
39#include <opie/owait.h> 39#include <opie/owait.h>
40 40
41#include "olistview.h" 41#include "olistview.h"
42#include "olistviewitem.h" 42#include "olistviewitem.h"
43#include "resultitem.h" 43#include "resultitem.h"
44#include "adresssearch.h" 44#include "adresssearch.h"
45#include "todosearch.h" 45#include "todosearch.h"
46#include "datebooksearch.h" 46#include "datebooksearch.h"
47#include "applnksearch.h" 47#include "applnksearch.h"
48#include "doclnksearch.h" 48#include "doclnksearch.h"
49#include "mainwindow.h" 49#include "mainwindow.h"
50 50
51static const char* const image1_data[] = {
52"14 14 3 1",
53". c None",
54"# c #000000",
55"a c #ff0000",
56"..............",
57"..##.......###",
58".#aa#....##aa#",
59"#aaaa#.##aaaa#",
60".##aaa#aaaaa##",
61"...#aaaaaaa#..",
62"....#aaaaa#...",
63"...#aaaaa#....",
64"..#aaaaaaa#...",
65".#aaaaaaaaa#..",
66"#aaaa###aaaa#.",
67"#aaa#..##aaa#.",
68"#aaa#...#aa#..",
69".###.....##..."};
70
71
51MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : 72MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
52 QMainWindow( parent, name, f ), _currentItem(0) 73 QMainWindow( parent, name, f ), _currentItem(0)
53{ 74{
54 setCaption( tr("OSearch") ); 75 setCaption( tr("OSearch") );
55 76
56 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); 77 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
57 78
58 QFrame *mainFrame = new QFrame( this, "mainFrame" ); 79 QFrame *mainFrame = new QFrame( this, "mainFrame" );
59 mainFrame->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); 80 mainFrame->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
60 81
61 mainLayout = new QVBoxLayout( mainFrame ); 82 mainLayout = new QVBoxLayout( mainFrame );
62 mainLayout->setSpacing( 0 ); 83 mainLayout->setSpacing( 0 );
63 mainLayout->setMargin( 0 ); 84 mainLayout->setMargin( 3 );
64 85
65 resultsList = new OListView( mainFrame ); 86 resultsList = new OListView( mainFrame );
66 resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); 87 resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
67 mainLayout->addWidget( resultsList ); 88 mainLayout->addWidget( resultsList );
68 89
69 detailsFrame = new QFrame( mainFrame, "detailsFrame" ); 90 detailsFrame = new QFrame( mainFrame, "detailsFrame" );
70 QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); 91 QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame );
71 richEdit = new QTextView( detailsFrame ); 92 richEdit = new QTextView( detailsFrame );
72 QWhatsThis::add( richEdit, tr("The details of the current result") ); 93 QWhatsThis::add( richEdit, tr("The details of the current result") );
73 richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); 94 richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
74 detailsLayout->addWidget( richEdit ); 95 detailsLayout->addWidget( richEdit );
75 96
76 buttonBox = new QHBox( mainFrame, "Button Box" ); 97 buttonBox = new QHBox( mainFrame, "Button Box" );
77 98
78 _buttonCount = 0; 99 _buttonCount = 0;
79 100
80 mainLayout->addWidget( detailsFrame ); 101 mainLayout->addWidget( detailsFrame );
81 mainLayout->addWidget( buttonBox ); 102 mainLayout->addWidget( buttonBox );
82 detailsFrame->hide(); 103 detailsFrame->hide();
83 buttonBox->hide(); 104 buttonBox->hide();
84 105
85 searches.append( new AppLnkSearch( resultsList, tr("Applications") ) ); 106 searches.append( new AppLnkSearch( resultsList, tr("Applications") ) );
86 searches.append( new DocLnkSearch( resultsList, tr("Documents") ) ); 107 searches.append( new DocLnkSearch( resultsList, tr("Documents") ) );
87 searches.append( new TodoSearch( resultsList, tr("Todo List") ) ); 108 searches.append( new TodoSearch( resultsList, tr("Todo List") ) );
88 searches.append( new DatebookSearch( resultsList, tr("Calendar") ) ); 109 searches.append( new DatebookSearch( resultsList, tr("Calendar") ) );
89 searches.append( new AdressSearch( resultsList, tr("Contacts") ) ); 110 searches.append( new AdressSearch( resultsList, tr("Contacts") ) );
90 111
91 setCentralWidget( mainFrame ); 112 setCentralWidget( mainFrame );
92 113
93 popupTimer = new QTimer(); 114 popupTimer = new QTimer();
94 searchTimer = new QTimer(); 115 searchTimer = new QTimer();
95 116
96 connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); 117 connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup()));
97 connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); 118 connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged()));
98 connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); 119 connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*)));
99 connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); 120 connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*)));
100 121
101 signalMapper = new QSignalMapper( this ); 122 signalMapper = new QSignalMapper( this );
102 123
103 connect(signalMapper, SIGNAL(mapped(int)), SLOT( slotAction(int) ) ); 124 connect(signalMapper, SIGNAL(mapped(int)), SLOT( slotAction(int) ) );
104 125
105 makeMenu(); 126 makeMenu();
106 127
107 Config cfg( "osearch", Config::User ); 128 Config cfg( "osearch", Config::User );
108 cfg.setGroup( "search_settings" ); 129 cfg.setGroup( "search_settings" );
109 actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); 130 actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) );
110 actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); 131 actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) );
111// actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) ); 132// actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) );
112} 133}
113 134
114void MainWindow::makeMenu() 135void MainWindow::makeMenu()
115{ 136{
116 QToolBar *toolBar = new QToolBar( this ); 137 QToolBar *toolBar = new QToolBar( this );
117 QToolBar *searchBar = new QToolBar(this); 138 QToolBar *searchBar = new QToolBar(this);
118 QMenuBar *menuBar = new QMenuBar( toolBar ); 139 QMenuBar *menuBar = new QMenuBar( toolBar );
119 QPopupMenu *searchMenu = new QPopupMenu( menuBar ); 140 QPopupMenu *searchMenu = new QPopupMenu( menuBar );
120// QPopupMenu *viewMenu = new QPopupMenu( menuBar ); 141// QPopupMenu *viewMenu = new QPopupMenu( menuBar );
121 QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); 142 QPopupMenu *cfgMenu = new QPopupMenu( menuBar );
122 QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); 143 QPopupMenu *searchOptions = new QPopupMenu( cfgMenu );
123 144
124 setToolBarsMovable( false ); 145 setToolBarsMovable( false );
125 toolBar->setHorizontalStretchable( true ); 146 toolBar->setHorizontalStretchable( true );
126 menuBar->insertItem( tr( "Search" ), searchMenu ); 147 menuBar->insertItem( tr( "Search" ), searchMenu );
127 menuBar->insertItem( tr( "Settings" ), cfgMenu ); 148 menuBar->insertItem( tr( "Settings" ), cfgMenu );
128 149
129 //SETTINGS MENU 150 //SETTINGS MENU
130 cfgMenu->insertItem( tr( "Search" ), searchOptions ); 151 cfgMenu->insertItem( tr( "Search" ), searchOptions );
131 QPopupMenu *pop; 152 QPopupMenu *pop;
132 for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ 153 for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){
133 pop = s->popupMenu(); 154 pop = s->popupMenu();
134 if (pop){ 155 if (pop){
135 cfgMenu->insertItem( s->text(0), pop ); 156 cfgMenu->insertItem( s->text(0), pop );
136 } 157 }
137 } 158 }
138 159
139 160
140 //SEARCH 161 //SEARCH
141 SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); 162 SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 );
142 SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); 163 SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) );
143 // QWhatsThis::add( SearchAllAction, tr("Search everything...") ); 164 // QWhatsThis::add( SearchAllAction, tr("Search everything...") );
144 connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); 165 connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) );
145 SearchAllAction->addTo( searchMenu ); 166 SearchAllAction->addTo( searchMenu );
146 searchMenu->insertItem( tr( "Options" ), searchOptions ); 167 searchMenu->insertItem( tr( "Options" ), searchOptions );
147 168
148 //SEARCH OPTIONS 169 //SEARCH OPTIONS
149 //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true ); 170 //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true );
150 //actionWholeWordsOnly->addTo( searchOptions ); 171 //actionWholeWordsOnly->addTo( searchOptions );
151 actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); 172 actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true );
152 actionCaseSensitiv->addTo( searchOptions ); 173 actionCaseSensitiv->addTo( searchOptions );
153 actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); 174 actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true );
154 actionWildcards->addTo( searchOptions ); 175 actionWildcards->addTo( searchOptions );
155 176
156 //SEARCH BAR 177 //SEARCH BAR
178 LabelEnterText = new QLabel( searchBar, "Label" );
179 LabelEnterText->setAutoMask( FALSE );
180 LabelEnterText->setText( tr( "Search for: " ) );
181
157 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 182 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
158 QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); 183 QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" );
159 QWhatsThis::add( searchEdit, tr("Enter your search terms here") ); 184 QWhatsThis::add( searchEdit, tr("Enter your search terms here") );
160 searchEdit->setFocus(); 185 searchEdit->setFocus();
161 searchBar->setHorizontalStretchable( TRUE ); 186 searchBar->setHorizontalStretchable( TRUE );
162 searchBar->setStretchableWidget( searchEdit ); 187 searchBar->setStretchableWidget( searchEdit );
188
189 //Search button
163 SearchAllAction->addTo( searchBar ); 190 SearchAllAction->addTo( searchBar );
164 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 191
165 this, SLOT( setSearch( const QString & ) ) ); 192 //image ripped of off opie-login/loginwindow.cpp
193 QPixmap image1( ( const char** ) image1_data );
194
195 //Clear text
196 ClearSearchText = new QToolButton( searchBar, "ClearSearchText");
197 ClearSearchText->setText( tr( "" ) );
198 ClearSearchText->setPixmap( image1 );
199
200 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),this, SLOT( setSearch( const QString & ) ) );
201 connect( ClearSearchText, SIGNAL( clicked() ), searchEdit, SLOT( clear() ) );
166 202
167} 203}
168 204
169MainWindow::~MainWindow() 205MainWindow::~MainWindow()
170{ 206{
171 Config cfg( "osearch", Config::User ); 207 Config cfg( "osearch", Config::User );
172 cfg.setGroup( "search_settings" ); 208 cfg.setGroup( "search_settings" );
173 cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); 209 cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() );
174 cfg.writeEntry( "wildcards", actionWildcards->isOn() ); 210 cfg.writeEntry( "wildcards", actionWildcards->isOn() );
175 //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() ); 211 //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() );
176} 212}
177 213
178void MainWindow::setCurrent(QListViewItem *item) 214void MainWindow::setCurrent(QListViewItem *item)
179{ 215{
180 if (!item) return; 216 if (!item) return;
181 _currentItem = (OListViewItem*)item; 217 _currentItem = (OListViewItem*)item;
182 //_currentItem = dynamic_cast<OListViewItem*>(item); 218 //_currentItem = dynamic_cast<OListViewItem*>(item);
183 if (_currentItem->rtti() == OListViewItem::Result){ 219 if (_currentItem->rtti() == OListViewItem::Result){
184 ResultItem *res = (ResultItem*)item; 220 ResultItem *res = (ResultItem*)item;
185 // ResultItem *res = dynamic_cast<ResultItem*>(item); 221 // ResultItem *res = dynamic_cast<ResultItem*>(item);
186 richEdit->setText( res->toRichText() ); 222 richEdit->setText( res->toRichText() );
187 QIntDict<QString> acts = res->actions(); 223 QIntDict<QString> acts = res->actions();
188 QButton *button; 224 QButton *button;
189 for (uint i = 0; i < acts.count(); i++){ 225 for (uint i = 0; i < acts.count(); i++){
190 button = buttonMap[i]; 226 button = buttonMap[i];
191 if (!button) { 227 if (!button) {
192 qWarning(" no button for %s", (*acts[i]).latin1() ); 228 qWarning(" no button for %s", (*acts[i]).latin1() );
193 button = new QPushButton( buttonBox ); 229 button = new QPushButton( buttonBox );
194 buttonMap.insert( i, button ); 230 buttonMap.insert( i, button );
195 signalMapper->setMapping(button, i ); 231 signalMapper->setMapping(button, i );
196 connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) ); 232 connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) );
197 } 233 }
198 button->setText( *acts[i] ); 234 button->setText( *acts[i] );
199 button->show(); 235 button->show();
200 } 236 }
201 for (uint i = acts.count(); i < _buttonCount; i++){ 237 for (uint i = acts.count(); i < _buttonCount; i++){
202 button = buttonMap[i]; 238 button = buttonMap[i];
203 if (button) button->hide(); 239 if (button) button->hide();
204 } 240 }
205 _buttonCount = acts.count(); 241 _buttonCount = acts.count();
206 detailsFrame->show(); 242 detailsFrame->show();
207 buttonBox->show(); 243 buttonBox->show();
208 244
209 }else { 245 }else {
210 detailsFrame->hide(); 246 detailsFrame->hide();
211 buttonBox->hide(); 247 buttonBox->hide();
212 } 248 }
213 popupTimer->start( 300, true ); 249 popupTimer->start( 300, true );