searchdialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qlayout.h>
00026 #include <qcheckbox.h>
00027 #include <qgroupbox.h>
00028 #include <qlabel.h>
00029 #include <qlineedit.h>
00030
00031 #include <klocale.h>
00032 #include <kmessagebox.h>
00033
00034 #include <libkdepim/kdateedit.h>
00035
00036 #include "koglobals.h"
00037 #include "koprefs.h"
00038
00039 #include "searchdialog.h"
00040 #include "searchdialog.moc"
00041
00042 SearchDialog::SearchDialog(Calendar *calendar,QWidget *parent)
00043 : KDialogBase(Plain,i18n("Find Events"),User1|Close,User1,parent,0,false,false,
00044 i18n("&Find"))
00045 {
00046 mCalendar = calendar;
00047
00048 QFrame *topFrame = plainPage();
00049 QVBoxLayout *layout = new QVBoxLayout(topFrame,0,spacingHint());
00050
00051
00052 QHBoxLayout *subLayout = new QHBoxLayout();
00053 layout->addLayout(subLayout);
00054
00055 searchLabel = new QLabel(topFrame);
00056 searchLabel->setText(i18n("Search for:"));
00057 subLayout->addWidget(searchLabel);
00058
00059 searchEdit = new QLineEdit(topFrame);
00060 subLayout->addWidget(searchEdit);
00061 searchEdit->setText("*");
00062 searchEdit->setFocus();
00063 connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & )));
00064
00065
00066 QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"),
00067 topFrame);
00068 layout->addWidget(rangeGroup);
00069
00070 QWidget *rangeWidget = new QWidget(rangeGroup);
00071 QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,spacingHint());
00072
00073 rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget));
00074 mStartDate = new KDateEdit(rangeWidget);
00075 rangeLayout->addWidget(mStartDate);
00076 rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget));
00077 mEndDate = new KDateEdit(rangeWidget);
00078 mEndDate->setDate(QDate::currentDate().addDays(365));
00079 rangeLayout->addWidget(mEndDate);
00080
00081 mInclusiveCheck = new QCheckBox(i18n("Events have to be completely included"),
00082 rangeGroup);
00083 mInclusiveCheck->setChecked(false);
00084
00085
00086 QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"),
00087 topFrame);
00088 layout->addWidget(subjectGroup);
00089
00090 mSummaryCheck = new QCheckBox(i18n("Summaries"),subjectGroup);
00091 mSummaryCheck->setChecked(true);
00092 mDescriptionCheck = new QCheckBox(i18n("Descriptions"),subjectGroup);
00093 mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup);
00094
00095
00096 listView = new KOListView(mCalendar,topFrame);
00097 listView->showDates();
00098 layout->addWidget(listView);
00099
00100 if ( KOPrefs::instance()->mCompactDialogs ) {
00101 KOGlobals::fitDialogToScreen( this, true );
00102 }
00103
00104 connect(this,SIGNAL(user1Clicked()),SLOT(doSearch()));
00105
00106
00107 connect(listView,SIGNAL(showEventSignal(Event *)),
00108 SIGNAL(showEventSignal(Event *)));
00109 connect(listView,SIGNAL(editEventSignal(Event *)),
00110 SIGNAL(editEventSignal(Event *)));
00111 connect(listView,SIGNAL(deleteEventSignal(Event *)),
00112 SIGNAL(deleteEventSignal(Event *)));
00113 }
00114
00115 SearchDialog::~SearchDialog()
00116 {
00117 }
00118
00119 void SearchDialog::searchTextChanged( const QString &_text )
00120 {
00121 enableButton( KDialogBase::User1, !_text.isEmpty() );
00122 }
00123
00124 void SearchDialog::doSearch()
00125 {
00126 QRegExp re;
00127
00128 re.setWildcard(true);
00129 re.setCaseSensitive(false);
00130 re.setPattern(searchEdit->text());
00131 if (!re.isValid()) {
00132 KMessageBox::sorry(this,
00133 i18n("Invalid search expression, cannot perform "
00134 "the search. Please enter a search expression "
00135 "using the wildcard characters '*' and '?' "
00136 "where needed."));
00137 return;
00138 }
00139
00140 search(re);
00141
00142 listView->showEvents(mMatchedEvents);
00143
00144 if (mMatchedEvents.count() == 0) {
00145 KMessageBox::information(this,
00146 i18n("No events were found matching your search expression."));
00147 }
00148 }
00149
00150 void SearchDialog::updateView()
00151 {
00152 QRegExp re;
00153 re.setWildcard(true);
00154 re.setCaseSensitive(false);
00155 re.setPattern(searchEdit->text());
00156 if (re.isValid()) {
00157 search(re);
00158 } else {
00159 mMatchedEvents.clear();
00160 }
00161
00162 listView->showEvents(mMatchedEvents);
00163 }
00164
00165 void SearchDialog::search(const QRegExp &re)
00166 {
00167 QPtrList<Event> events = mCalendar->events( mStartDate->date(),
00168 mEndDate->date(),
00169 mInclusiveCheck->isChecked() );
00170
00171 mMatchedEvents.clear();
00172 Event *ev;
00173 for(ev=events.first();ev;ev=events.next()) {
00174 if (mSummaryCheck->isChecked()) {
00175 #if QT_VERSION >= 300
00176 if (re.search(ev->summary()) != -1) {
00177 #else
00178 if (re.match(ev->summary()) != -1) {
00179 #endif
00180 mMatchedEvents.append(ev);
00181 continue;
00182 }
00183 }
00184 if (mDescriptionCheck->isChecked()) {
00185 #if QT_VERSION >= 300
00186 if (re.search(ev->description()) != -1) {
00187 #else
00188 if (re.match(ev->description()) != -1) {
00189 #endif
00190 mMatchedEvents.append(ev);
00191 continue;
00192 }
00193 }
00194 if (mCategoryCheck->isChecked()) {
00195 #if QT_VERSION >= 300
00196 if (re.search(ev->categoriesStr()) != -1) {
00197 #else
00198 if (re.match(ev->categoriesStr()) != -1) {
00199 #endif
00200 mMatchedEvents.append(ev);
00201 continue;
00202 }
00203 }
00204 }
00205 }
This file is part of the documentation for kdelibs Version 3.1.4.