-rw-r--r-- | korganizer/searchdialog.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/korganizer/searchdialog.cpp b/korganizer/searchdialog.cpp index cef59a2..678e1bd 100644 --- a/korganizer/searchdialog.cpp +++ b/korganizer/searchdialog.cpp | |||
@@ -1,224 +1,231 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qcheckbox.h> | 26 | #include <qcheckbox.h> |
27 | #include <qgroupbox.h> | 27 | #include <qgroupbox.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qlistview.h> | ||
29 | #include <qwhatsthis.h> | 30 | #include <qwhatsthis.h> |
30 | #include <qlineedit.h> | 31 | #include <qlineedit.h> |
31 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
32 | 33 | ||
33 | #include <klocale.h> | 34 | #include <klocale.h> |
34 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
35 | 36 | ||
36 | #include <libkdepim/kdateedit.h> | 37 | #include <libkdepim/kdateedit.h> |
37 | 38 | ||
38 | #include "koglobals.h" | 39 | #include "koglobals.h" |
39 | #include "koprefs.h" | 40 | #include "koprefs.h" |
41 | #include "klineedit.h" | ||
40 | 42 | ||
41 | #include "calendarview.h" | 43 | #include "calendarview.h" |
42 | #include "koviewmanager.h" | 44 | #include "koviewmanager.h" |
43 | #include "searchdialog.h" | 45 | #include "searchdialog.h" |
44 | 46 | ||
45 | SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent) | 47 | SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent) |
46 | : QVBox( 0 ) | 48 | : QVBox( 0 ) |
47 | 49 | ||
48 | { | 50 | { |
49 | mCalendar = calendar; | 51 | mCalendar = calendar; |
50 | QFrame *topFrame = new QFrame( this ) ;//plainPage(); | 52 | QFrame *topFrame = new QFrame( this ) ;//plainPage(); |
51 | QVBoxLayout *layout = new QVBoxLayout(topFrame,KDialog::marginHint(),KDialog::spacingHint()); | 53 | QVBoxLayout *layout = new QVBoxLayout(topFrame,KDialog::marginHint(),KDialog::spacingHint()); |
52 | 54 | ||
53 | // Search expression | 55 | // Search expression |
54 | QHBoxLayout *subLayout = new QHBoxLayout(); | 56 | QHBoxLayout *subLayout = new QHBoxLayout(); |
55 | layout->addLayout(subLayout); | 57 | layout->addLayout(subLayout); |
56 | searchLabel = new QLabel(topFrame); | 58 | searchLabel = new QLabel(topFrame); |
57 | searchLabel->setText(i18n("Search for:")); | 59 | searchLabel->setText(i18n("Search for:")); |
58 | subLayout->addWidget(searchLabel); | 60 | subLayout->addWidget(searchLabel); |
59 | 61 | ||
60 | searchEdit = new QLineEdit(topFrame); | 62 | searchEdit = new KLineEdit(topFrame); |
61 | subLayout->addWidget(searchEdit); | 63 | subLayout->addWidget(searchEdit); |
62 | QPushButton *OkButton = new QPushButton( i18n("&Find"), topFrame ); | 64 | QPushButton *OkButton = new QPushButton( i18n("&Find"), topFrame ); |
63 | //OkButton->setDefault( true ); | 65 | //OkButton->setDefault( true ); |
64 | connect(OkButton,SIGNAL(clicked()),SLOT(doSearch())); | 66 | connect(OkButton,SIGNAL(clicked()),SLOT(doSearch())); |
65 | subLayout->addWidget(OkButton); | 67 | subLayout->addWidget(OkButton); |
66 | searchEdit->setText("*"); // Find all events by default | 68 | searchEdit->setText("*"); // Find all events by default |
67 | searchEdit->setFocus(); | 69 | searchEdit->setFocus(); |
68 | connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & ))); | 70 | connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & ))); |
69 | connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch())); | 71 | connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch())); |
70 | // Subjects to search | 72 | // Subjects to search |
71 | // QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"), | 73 | // QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"), |
72 | // topFrame); | 74 | // topFrame); |
73 | 75 | ||
74 | QHBox *incidenceGroup = new QHBox( topFrame ); | 76 | QHBox *incidenceGroup = new QHBox( topFrame ); |
75 | layout->addWidget(incidenceGroup); | 77 | layout->addWidget(incidenceGroup); |
76 | 78 | ||
77 | mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup); | 79 | mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup); |
78 | mSearchEvent->setChecked(true); | 80 | mSearchEvent->setChecked(true); |
79 | mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup); | 81 | mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup); |
80 | mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup); | 82 | mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup); |
81 | 83 | ||
82 | QHBox *subjectGroup = new QHBox( topFrame ); | 84 | QHBox *subjectGroup = new QHBox( topFrame ); |
83 | layout->addWidget(subjectGroup); | 85 | layout->addWidget(subjectGroup); |
84 | 86 | ||
85 | mSummaryCheck = new QCheckBox(i18n("Summary/Loc."),subjectGroup); | 87 | mSummaryCheck = new QCheckBox(i18n("Summary/Loc."),subjectGroup); |
86 | mSummaryCheck->setChecked(true); | 88 | mSummaryCheck->setChecked(true); |
87 | mDescriptionCheck = new QCheckBox(i18n("Details"),subjectGroup); | 89 | mDescriptionCheck = new QCheckBox(i18n("Details"),subjectGroup); |
88 | mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup); | 90 | mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup); |
89 | 91 | ||
90 | QHBox *attendeeGroup = new QHBox( topFrame ); | 92 | QHBox *attendeeGroup = new QHBox( topFrame ); |
91 | layout->addWidget(attendeeGroup ); | 93 | layout->addWidget(attendeeGroup ); |
92 | new QLabel( i18n("Attendee:"),attendeeGroup ); | 94 | new QLabel( i18n("Attendee:"),attendeeGroup ); |
93 | mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup ); | 95 | mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup ); |
94 | mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup ); | 96 | mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup ); |
95 | // Date range | 97 | // Date range |
96 | // QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"), | 98 | // QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"), |
97 | // topFrame); | 99 | // topFrame); |
98 | // layout->addWidget(rangeGroup); | 100 | // layout->addWidget(rangeGroup); |
99 | 101 | ||
100 | QWidget *rangeWidget = new QWidget(topFrame); | 102 | QWidget *rangeWidget = new QWidget(topFrame); |
101 | QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,KDialog::spacingHint()); | 103 | QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,KDialog::spacingHint()); |
102 | rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget)); | 104 | rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget)); |
103 | mStartDate = new KDateEdit(rangeWidget); | 105 | mStartDate = new KDateEdit(rangeWidget); |
104 | rangeLayout->addWidget(mStartDate); | 106 | rangeLayout->addWidget(mStartDate); |
105 | rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget)); | 107 | rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget)); |
106 | mEndDate = new KDateEdit(rangeWidget); | 108 | mEndDate = new KDateEdit(rangeWidget); |
107 | mEndDate->setDate(QDate::currentDate().addDays(365)); | 109 | mEndDate->setDate(QDate::currentDate().addDays(365)); |
108 | rangeLayout->addWidget(mEndDate); | 110 | rangeLayout->addWidget(mEndDate); |
109 | QToolButton *wt = QWhatsThis::whatsThisButton ( rangeWidget ); | 111 | QToolButton *wt = QWhatsThis::whatsThisButton ( rangeWidget ); |
110 | rangeLayout->addWidget( (QWidget*)wt ); | 112 | rangeLayout->addWidget( (QWidget*)wt ); |
111 | layout->addWidget(rangeWidget); | 113 | layout->addWidget(rangeWidget); |
112 | // Results list view | 114 | // Results list view |
113 | listView = new KOListView(mCalendar,topFrame); | 115 | listView = new KOListView(mCalendar,topFrame); |
114 | layout->addWidget(listView); | 116 | layout->addWidget(listView); |
115 | 117 | ||
116 | listView->readSettings(KOGlobals::config(),"SearchListView Layout"); | 118 | listView->readSettings(KOGlobals::config(),"SearchListView Layout"); |
119 | connect(searchEdit,SIGNAL(scrollDOWN()),SLOT(setFocusToList())); | ||
117 | 120 | ||
118 | setCaption( i18n("KO/Pi Find: ")); | 121 | setCaption( i18n("KO/Pi Find: ")); |
119 | #ifdef DESKTOP_VERSION | 122 | #ifdef DESKTOP_VERSION |
120 | OkButton = new QPushButton( i18n("Close"), this ); | 123 | OkButton = new QPushButton( i18n("Close"), this ); |
121 | connect(OkButton,SIGNAL(clicked()),SLOT(hide())); | 124 | connect(OkButton,SIGNAL(clicked()),SLOT(hide())); |
122 | #endif | 125 | #endif |
123 | } | 126 | } |
124 | 127 | ||
125 | SearchDialog::~SearchDialog() | 128 | SearchDialog::~SearchDialog() |
126 | { | 129 | { |
127 | 130 | ||
128 | } | 131 | } |
132 | void SearchDialog::setFocusToList() | ||
133 | { | ||
134 | listView->resetFocus(); | ||
135 | } | ||
129 | void SearchDialog::accept() | 136 | void SearchDialog::accept() |
130 | { | 137 | { |
131 | doSearch(); | 138 | doSearch(); |
132 | } | 139 | } |
133 | void SearchDialog::updateList() | 140 | void SearchDialog::updateList() |
134 | { | 141 | { |
135 | //listView->updateList(); | 142 | //listView->updateList(); |
136 | if ( isVisible() ) { | 143 | if ( isVisible() ) { |
137 | updateView(); | 144 | updateView(); |
138 | //qDebug("SearchDialog::updated "); | 145 | //qDebug("SearchDialog::updated "); |
139 | } | 146 | } |
140 | else { | 147 | else { |
141 | listView->clear(); | 148 | listView->clear(); |
142 | //qDebug("SearchDialog::cleared "); | 149 | //qDebug("SearchDialog::cleared "); |
143 | 150 | ||
144 | } | 151 | } |
145 | } | 152 | } |
146 | void SearchDialog::searchTextChanged( const QString &_text ) | 153 | void SearchDialog::searchTextChanged( const QString &_text ) |
147 | { | 154 | { |
148 | #if 0 | 155 | #if 0 |
149 | enableButton( KDialogBase::User1, !_text.isEmpty() ); | 156 | enableButton( KDialogBase::User1, !_text.isEmpty() ); |
150 | #endif | 157 | #endif |
151 | } | 158 | } |
152 | 159 | ||
153 | void SearchDialog::doSearch() | 160 | void SearchDialog::doSearch() |
154 | { | 161 | { |
155 | QRegExp re; | 162 | QRegExp re; |
156 | 163 | ||
157 | re.setWildcard(true); // most people understand these better. | 164 | re.setWildcard(true); // most people understand these better. |
158 | re.setCaseSensitive(false); | 165 | re.setCaseSensitive(false); |
159 | re.setPattern(searchEdit->text()); | 166 | re.setPattern(searchEdit->text()); |
160 | if (!re.isValid() ) { | 167 | if (!re.isValid() ) { |
161 | KMessageBox::sorry(this, | 168 | KMessageBox::sorry(this, |
162 | i18n("Invalid search expression,\ncannot perform " | 169 | i18n("Invalid search expression,\ncannot perform " |
163 | "the search.\nPlease enter a search expression\n" | 170 | "the search.\nPlease enter a search expression\n" |
164 | "using the wildcard characters\n '*' and '?'" | 171 | "using the wildcard characters\n '*' and '?'" |
165 | "where needed.")); | 172 | "where needed.")); |
166 | return; | 173 | return; |
167 | } | 174 | } |
168 | 175 | ||
169 | search(re); | 176 | search(re); |
170 | 177 | ||
171 | listView->setStartDate( mStartDate->date() ); | 178 | listView->setStartDate( mStartDate->date() ); |
172 | listView->showEvents(mMatchedEvents); | 179 | listView->showEvents(mMatchedEvents); |
173 | listView->addTodos(mMatchedTodos); | 180 | listView->addTodos(mMatchedTodos); |
174 | listView->addJournals(mMatchedJournals); | 181 | listView->addJournals(mMatchedJournals); |
175 | 182 | ||
176 | if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) { | 183 | if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) { |
177 | setCaption(i18n("No items found. Use '*' and '?' where needed.")); | 184 | setCaption(i18n("No items found. Use '*' and '?' where needed.")); |
178 | } else { | 185 | } else { |
179 | QString mess; | 186 | QString mess; |
180 | mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() ); | 187 | mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() ); |
181 | setCaption( i18n("KO/Pi Find: ") + mess); | 188 | setCaption( i18n("KO/Pi Find: ") + mess); |
182 | 189 | ||
183 | } | 190 | } |
184 | searchEdit->setFocus(); | 191 | searchEdit->setFocus(); |
185 | } | 192 | } |
186 | void SearchDialog::updateConfig() | 193 | void SearchDialog::updateConfig() |
187 | { | 194 | { |
188 | listView->updateConfig(); | 195 | listView->updateConfig(); |
189 | } | 196 | } |
190 | void SearchDialog::updateView() | 197 | void SearchDialog::updateView() |
191 | { | 198 | { |
192 | 199 | ||
193 | QRegExp re; | 200 | QRegExp re; |
194 | re.setWildcard(true); // most people understand these better. | 201 | re.setWildcard(true); // most people understand these better. |
195 | re.setCaseSensitive(false); | 202 | re.setCaseSensitive(false); |
196 | re.setPattern(searchEdit->text()); | 203 | re.setPattern(searchEdit->text()); |
197 | if (re.isValid()) { | 204 | if (re.isValid()) { |
198 | search(re); | 205 | search(re); |
199 | } else { | 206 | } else { |
200 | mMatchedEvents.clear(); | 207 | mMatchedEvents.clear(); |
201 | mMatchedTodos.clear(); | 208 | mMatchedTodos.clear(); |
202 | mMatchedJournals.clear(); | 209 | mMatchedJournals.clear(); |
203 | } | 210 | } |
204 | listView->setStartDate( mStartDate->date() ); | 211 | listView->setStartDate( mStartDate->date() ); |
205 | listView->showEvents(mMatchedEvents); | 212 | listView->showEvents(mMatchedEvents); |
206 | listView->addTodos(mMatchedTodos); | 213 | listView->addTodos(mMatchedTodos); |
207 | listView->addJournals(mMatchedJournals); | 214 | listView->addJournals(mMatchedJournals); |
208 | } | 215 | } |
209 | 216 | ||
210 | void SearchDialog::search(const QRegExp &re) | 217 | void SearchDialog::search(const QRegExp &re) |
211 | { | 218 | { |
212 | QPtrList<Event> events = mCalendar->events( mStartDate->date(), | 219 | QPtrList<Event> events = mCalendar->events( mStartDate->date(), |
213 | mEndDate->date(), | 220 | mEndDate->date(), |
214 | false /*mInclusiveCheck->isChecked()*/ ); | 221 | false /*mInclusiveCheck->isChecked()*/ ); |
215 | 222 | ||
216 | mMatchedEvents.clear(); | 223 | mMatchedEvents.clear(); |
217 | if ( mSearchEvent->isChecked() ) { | 224 | if ( mSearchEvent->isChecked() ) { |
218 | Event *ev; | 225 | Event *ev; |
219 | for(ev=events.first();ev;ev=events.next()) { | 226 | for(ev=events.first();ev;ev=events.next()) { |
220 | if (mSummaryCheck->isChecked()) { | 227 | if (mSummaryCheck->isChecked()) { |
221 | #if QT_VERSION >= 0x030000 | 228 | #if QT_VERSION >= 0x030000 |
222 | if (re.search(ev->summary()) != -1) | 229 | if (re.search(ev->summary()) != -1) |
223 | #else | 230 | #else |
224 | if (re.match(ev->summary()) != -1) | 231 | if (re.match(ev->summary()) != -1) |