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 <qhbuttongroup.h>
00029
#include <qlabel.h>
00030
#include <qlineedit.h>
00031
00032
#include <klocale.h>
00033
#include <kmessagebox.h>
00034
00035
#include <libkdepim/kdateedit.h>
00036
00037
#include "koglobals.h"
00038
#include "koprefs.h"
00039
00040
#include "searchdialog.h"
00041
#include "searchdialog.moc"
00042
00043 SearchDialog::SearchDialog(Calendar *calendar,QWidget *parent)
00044 : KDialogBase(Plain,i18n("Find Events"),User1|Close,User1,parent,0,false,false,
00045 KGuiItem( i18n("&Find"), "find"))
00046 {
00047 mCalendar = calendar;
00048
00049 QFrame *topFrame = plainPage();
00050 QVBoxLayout *layout =
new QVBoxLayout(topFrame,0,spacingHint());
00051
00052
00053 QHBoxLayout *subLayout =
new QHBoxLayout();
00054 layout->addLayout(subLayout);
00055
00056 searchEdit =
new QLineEdit(
"*", topFrame );
00057 searchLabel =
new QLabel( searchEdit, i18n(
"&Search for:"), topFrame );
00058 subLayout->addWidget( searchLabel );
00059 subLayout->addWidget( searchEdit );
00060 searchEdit->setFocus();
00061 connect( searchEdit, SIGNAL( textChanged(
const QString & ) ),
00062
this, SLOT( searchTextChanged(
const QString & ) ) );
00063
00064
00065 QHButtonGroup *itemsGroup =
new QHButtonGroup( i18n(
"Search For"), topFrame );
00066 layout->addWidget( itemsGroup );
00067 mEventsCheck =
new QCheckBox( i18n(
"&Events"), itemsGroup );
00068 mTodosCheck =
new QCheckBox( i18n(
"To&dos"), itemsGroup );
00069 mJournalsCheck =
new QCheckBox( i18n(
"&Journal entries"), itemsGroup );
00070 mEventsCheck->setChecked(
true );
00071 mTodosCheck->setChecked(
true );
00072
00073
00074 QGroupBox *rangeGroup =
new QGroupBox( 1, Horizontal, i18n(
"Date Range" ),
00075 topFrame );
00076 layout->addWidget( rangeGroup );
00077
00078 QWidget *rangeWidget =
new QWidget( rangeGroup );
00079 QHBoxLayout *rangeLayout =
new QHBoxLayout( rangeWidget, 0, spacingHint() );
00080
00081 mStartDate =
new KDateEdit( rangeWidget );
00082 rangeLayout->addWidget(
new QLabel( mStartDate, i18n(
"&From:"), rangeWidget ) );
00083 rangeLayout->addWidget( mStartDate );
00084
00085 mEndDate =
new KDateEdit( rangeWidget );
00086 rangeLayout->addWidget(
new QLabel( mEndDate, i18n(
"&To:"), rangeWidget ) );
00087 mEndDate->setDate( QDate::currentDate().addDays( 365 ) );
00088 rangeLayout->addWidget( mEndDate );
00089
00090 mInclusiveCheck =
new QCheckBox( i18n(
"Events have to be &completely included"),
00091 rangeGroup );
00092 mInclusiveCheck->setChecked(
false );
00093 mIncludeUndatedTodos =
new QCheckBox( i18n(
"Include todos &without due date"), rangeGroup );
00094 mIncludeUndatedTodos->setChecked(
true );
00095
00096
00097 QHButtonGroup *subjectGroup =
new QHButtonGroup( i18n(
"Search In"), topFrame );
00098 layout->addWidget(subjectGroup);
00099
00100 mSummaryCheck =
new QCheckBox( i18n(
"Su&mmaries"), subjectGroup );
00101 mSummaryCheck->setChecked(
true );
00102 mDescriptionCheck =
new QCheckBox( i18n(
"Desc&riptions"), subjectGroup );
00103 mCategoryCheck =
new QCheckBox( i18n(
"Cate&gories"), subjectGroup );
00104
00105
00106
00107 listView =
new KOListView( mCalendar, topFrame );
00108 listView->showDates();
00109 layout->addWidget( listView );
00110
00111
if ( KOPrefs::instance()->mCompactDialogs ) {
00112 KOGlobals::fitDialogToScreen(
this,
true );
00113 }
00114
00115 connect(
this,SIGNAL(user1Clicked()),SLOT(doSearch()));
00116
00117
00118 connect( listView, SIGNAL( showIncidenceSignal( Incidence * ) ),
00119 SIGNAL( showIncidenceSignal( Incidence *) ) );
00120 connect( listView, SIGNAL( editIncidenceSignal( Incidence * ) ),
00121 SIGNAL( editIncidenceSignal( Incidence * ) ) );
00122 connect( listView, SIGNAL( deleteIncidenceSignal( Incidence * ) ),
00123 SIGNAL( deleteIncidenceSignal( Incidence * ) ) );
00124 }
00125
00126 SearchDialog::~SearchDialog()
00127 {
00128 }
00129
00130
void SearchDialog::searchTextChanged(
const QString &_text )
00131 {
00132 enableButton( KDialogBase::User1, !_text.isEmpty() );
00133 }
00134
00135
void SearchDialog::doSearch()
00136 {
00137 QRegExp re;
00138
00139 re.setWildcard(
true );
00140 re.setCaseSensitive(
false );
00141 re.setPattern( searchEdit->text() );
00142
if ( !re.isValid() ) {
00143 KMessageBox::sorry(
this,
00144 i18n(
"Invalid search expression, cannot perform "
00145
"the search. Please enter a search expression "
00146
"using the wildcard characters '*' and '?' "
00147
"where needed." ) );
00148
return;
00149 }
00150
00151 search( re );
00152
00153 listView->showIncidences( mMatchedEvents );
00154
00155
if ( mMatchedEvents.count() == 0 ) {
00156 KMessageBox::information(
this,
00157 i18n(
"No events were found matching your search expression.") );
00158 }
00159 }
00160
00161
void SearchDialog::updateView()
00162 {
00163 QRegExp re;
00164 re.setWildcard(
true );
00165 re.setCaseSensitive(
false );
00166 re.setPattern( searchEdit->text() );
00167
if ( re.isValid() ) {
00168 search( re );
00169 }
else {
00170 mMatchedEvents.clear();
00171 }
00172
00173 listView->showIncidences( mMatchedEvents );
00174 }
00175
00176
void SearchDialog::search(
const QRegExp &re )
00177 {
00178 QDate startDt = mStartDate->date();
00179 QDate endDt = mEndDate->date();
00180
00181 Event::List events = mCalendar->events( startDt, endDt,
00182 mInclusiveCheck->isChecked() );
00183 Todo::List todos;
00184
if ( mIncludeUndatedTodos )
00185 todos = mCalendar->todos();
00186
else {
00187 QDate dt = startDt;
00188
while ( dt <= endDt ) {
00189 todos += mCalendar->todos( dt );
00190 dt = dt.addDays( 1 );
00191 }
00192 }
00193
00194 Journal::List journals;
00195 QDate dt = startDt;
00196
while ( dt <= endDt ) {
00197 Journal* j=mCalendar->journal( dt );
00198
if (j) journals.append( j );
00199 dt = dt.addDays( 1 );
00200 }
00201
00202 Incidence::List allIncidences = Calendar::mergeIncidenceList( events, todos, journals );
00203
00204 mMatchedEvents.clear();
00205 Incidence::List::ConstIterator it;
00206
for( it = allIncidences.begin(); it != allIncidences.end(); ++it ) {
00207 Incidence *ev = *it;
00208
if ( mSummaryCheck->isChecked() ) {
00209
#if QT_VERSION >= 300
00210
if ( re.search( ev->summary() ) != -1 ) {
00211
#else
00212
if ( re.match( ev->summary() ) != -1 ) {
00213
#endif
00214
mMatchedEvents.append( ev );
00215
continue;
00216 }
00217 }
00218
if ( mDescriptionCheck->isChecked() ) {
00219
#if QT_VERSION >= 300
00220
if ( re.search( ev->description() ) != -1 ) {
00221
#else
00222
if ( re.match( ev->description() ) != -1 ) {
00223
#endif
00224
mMatchedEvents.append( ev );
00225
continue;
00226 }
00227 }
00228
if ( mCategoryCheck->isChecked() ) {
00229
#if QT_VERSION >= 300
00230
if ( re.search( ev->categoriesStr() ) != -1 ) {
00231
#else
00232
if ( re.match( ev->categoriesStr() ) != -1 ) {
00233
#endif
00234
mMatchedEvents.append( ev );
00235
continue;
00236 }
00237 }
00238 }
00239 }