Diffstat (limited to 'core/pim/osearch/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/osearch/mainwindow.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp index 093ca54..b80c637 100644 --- a/core/pim/osearch/mainwindow.cpp +++ b/core/pim/osearch/mainwindow.cpp | |||
@@ -1,185 +1,201 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
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 | #include "mainwindow.h" | 13 | #include "mainwindow.h" |
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 <qaction.h> | 22 | #include <qaction.h> |
22 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
23 | #include <qpopupmenu.h> | 24 | #include <qpopupmenu.h> |
24 | #include <qtoolbutton.h> | 25 | #include <qtoolbutton.h> |
25 | #include <qstring.h> | 26 | #include <qstring.h> |
26 | #include <qlabel.h> | 27 | #include <qlabel.h> |
27 | #include <qfile.h> | 28 | #include <qfile.h> |
28 | #include <qhbuttongroup.h> | 29 | #include <qhbuttongroup.h> |
29 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
30 | #include <qintdict.h> | 31 | #include <qintdict.h> |
31 | #include <qlayout.h> | 32 | #include <qlayout.h> |
32 | #include <qlineedit.h> | 33 | #include <qlineedit.h> |
33 | #include <qtextbrowser.h> | 34 | #include <qtextbrowser.h> |
34 | #include <qregexp.h> | 35 | #include <qregexp.h> |
35 | 36 | ||
36 | #include "olistview.h" | 37 | #include "olistview.h" |
37 | #include "olistviewitem.h" | 38 | #include "olistviewitem.h" |
38 | #include "resultitem.h" | 39 | #include "resultitem.h" |
39 | #include "adresssearch.h" | 40 | #include "adresssearch.h" |
40 | #include "todosearch.h" | 41 | #include "todosearch.h" |
41 | #include "datebooksearch.h" | 42 | #include "datebooksearch.h" |
42 | #include "applnksearch.h" | 43 | #include "applnksearch.h" |
43 | #include "doclnksearch.h" | 44 | #include "doclnksearch.h" |
44 | 45 | ||
45 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | 46 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : |
46 | QMainWindow( parent, name, f ), _currentItem(0) | 47 | QMainWindow( parent, name, f ), _currentItem(0) |
47 | { | 48 | { |
48 | setCaption( tr("OSearch") ); | 49 | setCaption( tr("OSearch") ); |
49 | 50 | ||
50 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); | 51 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); |
51 | 52 | ||
52 | QFrame *mainFrame = new QFrame( this, "mainFrame" ); | 53 | QFrame *mainFrame = new QFrame( this, "mainFrame" ); |
53 | 54 | ||
54 | mainLayout = new QVBoxLayout( mainFrame ); | 55 | mainLayout = new QVBoxLayout( mainFrame ); |
55 | mainLayout->setSpacing( 0 ); | 56 | mainLayout->setSpacing( 0 ); |
56 | mainLayout->setMargin( 0 ); | 57 | mainLayout->setMargin( 0 ); |
57 | 58 | ||
58 | resultsList = new OListView( mainFrame ); | 59 | resultsList = new OListView( mainFrame ); |
59 | resultsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); | 60 | resultsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); |
60 | mainLayout->addWidget( resultsList, 1 ); | 61 | mainLayout->addWidget( resultsList, 1 ); |
61 | 62 | ||
62 | detailsFrame = new QFrame( mainFrame, "detailsFrame" ); | 63 | detailsFrame = new QFrame( mainFrame, "detailsFrame" ); |
63 | QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); | 64 | QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); |
64 | richEdit = new QTextView( detailsFrame ); | 65 | richEdit = new QTextView( detailsFrame ); |
65 | richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); | 66 | richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding)); |
66 | //richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum )); | 67 | //richEdit->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum )); |
67 | detailsLayout->addWidget( richEdit, 1 ); | 68 | detailsLayout->addWidget( richEdit, 1 ); |
68 | 69 | ||
69 | buttonGroupActions = new QHButtonGroup( this ); | 70 | buttonGroupActions = new QHButtonGroup( this ); |
70 | buttonGroupActions->hide(); | 71 | buttonGroupActions->hide(); |
71 | _buttonCount = 0; | 72 | _buttonCount = 0; |
72 | // buttonGroupActions->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); | 73 | // buttonGroupActions->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); |
73 | 74 | ||
74 | buttonLayout = new QHBoxLayout( detailsFrame ); | 75 | buttonLayout = new QHBoxLayout( detailsFrame ); |
75 | detailsLayout->addLayout( buttonLayout ); | 76 | detailsLayout->addLayout( buttonLayout ); |
76 | 77 | ||
77 | mainLayout->addWidget( detailsFrame ); | 78 | mainLayout->addWidget( detailsFrame ); |
78 | detailsFrame->hide(); | 79 | detailsFrame->hide(); |
79 | 80 | ||
80 | searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); | 81 | searches.append( new AppLnkSearch( resultsList, tr("applications") ) ); |
81 | searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); | 82 | searches.append( new DocLnkSearch( resultsList, tr("documents") ) ); |
82 | searches.append( new TodoSearch( resultsList, tr("todo") ) ); | 83 | searches.append( new TodoSearch( resultsList, tr("todo") ) ); |
83 | searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); | 84 | searches.append( new DatebookSearch( resultsList, tr("datebook") ) ); |
84 | searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); | 85 | searches.append( new AdressSearch( resultsList, tr("adressbook") ) ); |
85 | 86 | ||
86 | makeMenu(); | 87 | makeMenu(); |
87 | setCentralWidget( mainFrame ); | 88 | setCentralWidget( mainFrame ); |
88 | 89 | ||
89 | popupTimer = new QTimer(); | 90 | popupTimer = new QTimer(); |
90 | searchTimer = new QTimer(); | 91 | searchTimer = new QTimer(); |
91 | 92 | ||
92 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); | 93 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); |
93 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); | 94 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); |
94 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); | 95 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); |
95 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); | 96 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); |
96 | connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); | 97 | connect(buttonGroupActions, SIGNAL(clicked(int)), SLOT( slotAction(int) ) ); |
97 | 98 | ||
99 | |||
100 | Config cfg( "osearch", Config::User ); | ||
101 | cfg.setGroup( "search_settings" ); | ||
102 | actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); | ||
103 | actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); | ||
98 | } | 104 | } |
99 | 105 | ||
100 | void MainWindow::makeMenu() | 106 | void MainWindow::makeMenu() |
101 | { | 107 | { |
102 | QPEToolBar *toolBar = new QPEToolBar( this ); | 108 | QPEToolBar *toolBar = new QPEToolBar( this ); |
103 | QPEToolBar *searchBar = new QPEToolBar(this); | 109 | QPEToolBar *searchBar = new QPEToolBar(this); |
104 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); | 110 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); |
105 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); | 111 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); |
106 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); | 112 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); |
107 | // QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); | 113 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); |
108 | // | 114 | QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); |
115 | |||
109 | setToolBarsMovable( false ); | 116 | setToolBarsMovable( false ); |
110 | toolBar->setHorizontalStretchable( true ); | 117 | toolBar->setHorizontalStretchable( true ); |
111 | menuBar->insertItem( tr( "Search" ), searchMenu ); | 118 | menuBar->insertItem( tr( "Search" ), searchMenu ); |
112 | // menuBar->insertItem( tr( "View" ), viewMenu ); | 119 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); |
113 | // menuBar->insertItem( tr( "Settings" ), cfgMenu ); | 120 | cfgMenu->insertItem( tr( "Search" ), searchOptions ); |
121 | |||
114 | 122 | ||
115 | //SEARCH | 123 | //SEARCH |
116 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); | 124 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); |
117 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); | 125 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); |
118 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); | 126 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); |
119 | SearchAllAction->addTo( searchMenu ); | 127 | SearchAllAction->addTo( searchMenu ); |
128 | searchMenu->insertItem( tr( "Options" ), searchOptions ); | ||
129 | |||
130 | //SEARCH OPTIONS | ||
120 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); | 131 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); |
121 | actionCaseSensitiv->addTo( searchMenu ); | 132 | actionCaseSensitiv->addTo( searchOptions ); |
122 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); | 133 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); |
123 | actionWildcards->addTo( searchMenu ); | 134 | actionWildcards->addTo( searchOptions ); |
124 | 135 | ||
136 | //SEARCH BAR | ||
125 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 137 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
126 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); | 138 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); |
127 | searchEdit->setFocus(); | 139 | searchEdit->setFocus(); |
128 | searchBar->setHorizontalStretchable( TRUE ); | 140 | searchBar->setHorizontalStretchable( TRUE ); |
129 | searchBar->setStretchableWidget( searchEdit ); | 141 | searchBar->setStretchableWidget( searchEdit ); |
130 | SearchAllAction->addTo( searchBar ); | 142 | SearchAllAction->addTo( searchBar ); |
131 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 143 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
132 | this, SLOT( setSearch( const QString & ) ) ); | 144 | this, SLOT( setSearch( const QString & ) ) ); |
133 | 145 | ||
134 | } | 146 | } |
135 | 147 | ||
136 | MainWindow::~MainWindow() | 148 | MainWindow::~MainWindow() |
137 | { | 149 | { |
150 | Config cfg( "osearch", Config::User ); | ||
151 | cfg.setGroup( "search_settings" ); | ||
152 | cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); | ||
153 | cfg.writeEntry( "wildcards", actionWildcards->isOn() ); | ||
138 | } | 154 | } |
139 | 155 | ||
140 | void MainWindow::setCurrent(QListViewItem *item) | 156 | void MainWindow::setCurrent(QListViewItem *item) |
141 | { | 157 | { |
142 | if (!item) return; | 158 | if (!item) return; |
143 | _currentItem = (OListViewItem*)item; | 159 | _currentItem = (OListViewItem*)item; |
144 | //_currentItem = dynamic_cast<OListViewItem*>(item); | 160 | //_currentItem = dynamic_cast<OListViewItem*>(item); |
145 | if (_currentItem->rtti() == OListViewItem::Result){ | 161 | if (_currentItem->rtti() == OListViewItem::Result){ |
146 | ResultItem *res = (ResultItem*)item; | 162 | ResultItem *res = (ResultItem*)item; |
147 | // ResultItem *res = dynamic_cast<ResultItem*>(item); | 163 | // ResultItem *res = dynamic_cast<ResultItem*>(item); |
148 | richEdit->setText( res->toRichText() ); | 164 | richEdit->setText( res->toRichText() ); |
149 | QIntDict<QString> acts = res->actions(); | 165 | QIntDict<QString> acts = res->actions(); |
150 | QButton *button; | 166 | QButton *button; |
151 | for (uint i = 0; i < acts.count(); i++){ | 167 | for (uint i = 0; i < acts.count(); i++){ |
152 | button = buttonGroupActions->find( i ); | 168 | button = buttonGroupActions->find( i ); |
153 | qDebug("action %i >%s<",i,acts[i]->latin1()); | 169 | qDebug("action %i >%s<",i,acts[i]->latin1()); |
154 | if (!button) { | 170 | if (!button) { |
155 | qDebug("BUTTON"); | 171 | qDebug("BUTTON"); |
156 | button = new QPushButton( detailsFrame ); | 172 | button = new QPushButton( detailsFrame ); |
157 | buttonLayout->addWidget( button, 0 ); | 173 | buttonLayout->addWidget( button, 0 ); |
158 | buttonGroupActions->insert( button, i); | 174 | buttonGroupActions->insert( button, i); |
159 | } | 175 | } |
160 | button->setText( *acts[i] ); | 176 | button->setText( *acts[i] ); |
161 | button->show(); | 177 | button->show(); |
162 | } | 178 | } |
163 | for (uint i = acts.count(); i < _buttonCount; i++){ | 179 | for (uint i = acts.count(); i < _buttonCount; i++){ |
164 | qDebug("remove button %i of %i",i, _buttonCount); | 180 | qDebug("remove button %i of %i",i, _buttonCount); |
165 | button = buttonGroupActions->find( i ); | 181 | button = buttonGroupActions->find( i ); |
166 | if (button) button->hide(); | 182 | if (button) button->hide(); |
167 | } | 183 | } |
168 | _buttonCount = acts.count(); | 184 | _buttonCount = acts.count(); |
169 | // buttonShow = new QPushButton( detailsFrame, "Show" ) ; | 185 | // buttonShow = new QPushButton( detailsFrame, "Show" ) ; |
170 | // buttonShow->setText( "test" ); | 186 | // buttonShow->setText( "test" ); |
171 | // buttonLayout->addWidget( buttonShow, 0 ); | 187 | // buttonLayout->addWidget( buttonShow, 0 ); |
172 | // buttonGroupActions->insert(buttonShow); | 188 | // buttonGroupActions->insert(buttonShow); |
173 | detailsFrame->show(); | 189 | detailsFrame->show(); |
174 | }else detailsFrame->hide(); | 190 | }else detailsFrame->hide(); |
175 | //_currentItem = (OListViewItem*)item; | 191 | //_currentItem = (OListViewItem*)item; |
176 | popupTimer->start( 300 ); | 192 | popupTimer->start( 300 ); |
177 | } | 193 | } |
178 | 194 | ||
179 | void MainWindow::stopTimer(QListViewItem*) | 195 | void MainWindow::stopTimer(QListViewItem*) |
180 | { | 196 | { |
181 | popupTimer->stop(); | 197 | popupTimer->stop(); |
182 | } | 198 | } |
183 | 199 | ||
184 | void MainWindow::showPopup() | 200 | void MainWindow::showPopup() |
185 | { | 201 | { |