28 #include <tqcheckbox.h>
29 #include <tqgroupbox.h>
30 #include <tqhbuttongroup.h>
32 #include <tqlineedit.h>
34 #include <tdelocale.h>
35 #include <tdemessagebox.h>
39 #include <libtdepim/kdateedit.h>
41 #include "koglobals.h"
43 #include "kolistview.h"
45 #include "searchdialog.h"
46 #include "searchdialog.moc"
48 SearchDialog::SearchDialog(
Calendar *calendar,TQWidget *parent)
49 : KDialogBase(Plain,i18n(
"Find Events"),User1|Close,User1,parent,0,false,false,
50 KGuiItem( i18n(
"&Find"),
"edit-find") )
54 TQFrame *topFrame = plainPage();
55 TQVBoxLayout *layout =
new TQVBoxLayout(topFrame,0,spacingHint());
58 TQHBoxLayout *subLayout =
new TQHBoxLayout();
59 layout->addLayout(subLayout);
61 searchEdit =
new TQLineEdit(
"*", topFrame );
62 searchLabel =
new TQLabel( searchEdit, i18n(
"&Search for:"), topFrame );
63 subLayout->addWidget( searchLabel );
64 subLayout->addWidget( searchEdit );
65 searchEdit->setFocus();
66 connect( searchEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
67 this, TQ_SLOT( searchTextChanged(
const TQString & ) ) );
70 TQHButtonGroup *itemsGroup =
new TQHButtonGroup( i18n(
"Search For"), topFrame );
71 layout->addWidget( itemsGroup );
72 mEventsCheck =
new TQCheckBox( i18n(
"&Events"), itemsGroup );
73 mTodosCheck =
new TQCheckBox( i18n(
"To-&dos"), itemsGroup );
74 mJournalsCheck =
new TQCheckBox( i18n(
"&Journal entries"), itemsGroup );
75 mEventsCheck->setChecked(
true );
76 mTodosCheck->setChecked(
true );
79 TQGroupBox *rangeGroup =
new TQGroupBox( 1, TQt::Horizontal, i18n(
"Date Range" ),
81 layout->addWidget( rangeGroup );
83 TQWidget *rangeWidget =
new TQWidget( rangeGroup );
84 TQHBoxLayout *rangeLayout =
new TQHBoxLayout( rangeWidget, 0, spacingHint() );
86 mStartDate =
new KDateEdit( rangeWidget );
87 rangeLayout->addWidget(
new TQLabel( mStartDate, i18n(
"Fr&om:"), rangeWidget ) );
88 rangeLayout->addWidget( mStartDate );
90 mEndDate =
new KDateEdit( rangeWidget );
91 rangeLayout->addWidget(
new TQLabel( mEndDate, i18n(
"&To:"), rangeWidget ) );
92 mEndDate->setDate( TQDate::currentDate().addDays( 365 ) );
93 rangeLayout->addWidget( mEndDate );
95 mInclusiveCheck =
new TQCheckBox( i18n(
"E&vents have to be completely included"),
97 mInclusiveCheck->setChecked(
false );
98 mIncludeUndatedTodos =
new TQCheckBox( i18n(
"Include to-dos &without due date"), rangeGroup );
99 mIncludeUndatedTodos->setChecked(
true );
102 TQHButtonGroup *subjectGroup =
new TQHButtonGroup( i18n(
"Search In"), topFrame );
103 layout->addWidget(subjectGroup);
105 mSummaryCheck =
new TQCheckBox( i18n(
"Su&mmaries"), subjectGroup );
106 mSummaryCheck->setChecked(
true );
107 mDescriptionCheck =
new TQCheckBox( i18n(
"Desc&riptions"), subjectGroup );
108 mCategoryCheck =
new TQCheckBox( i18n(
"Cate&gories"), subjectGroup );
112 listView =
new KOListView( mCalendar, topFrame );
113 listView->showDates();
114 layout->addWidget( listView );
116 if ( KOPrefs::instance()->mCompactDialogs ) {
117 KOGlobals::fitDialogToScreen(
this,
true );
120 connect(
this,TQ_SIGNAL(user1Clicked()),TQ_SLOT(doSearch()));
123 connect( listView, TQ_SIGNAL(showIncidenceSignal(
Incidence *,
const TQDate &)),
124 TQ_SIGNAL(showIncidenceSignal(
Incidence *,
const TQDate &)) );
125 connect( listView, TQ_SIGNAL(editIncidenceSignal(
Incidence *,
const TQDate &)),
126 TQ_SIGNAL(editIncidenceSignal(
Incidence *,
const TQDate &)) );
127 connect( listView, TQ_SIGNAL(deleteIncidenceSignal(
Incidence *)),
128 TQ_SIGNAL(deleteIncidenceSignal(
Incidence *)) );
131 SearchDialog::~SearchDialog()
135 void SearchDialog::searchTextChanged(
const TQString &_text )
137 enableButton( KDialogBase::User1, !_text.isEmpty() );
140 void SearchDialog::doSearch()
144 re.setWildcard(
true );
145 re.setCaseSensitive(
false );
146 re.setPattern( searchEdit->text() );
147 if ( !re.isValid() ) {
148 KMessageBox::sorry(
this,
149 i18n(
"Invalid search expression, cannot perform "
150 "the search. Please enter a search expression "
151 "using the wildcard characters '*' and '?' "
158 listView->showIncidences( mMatchedEvents, TQDate() );
160 if ( mMatchedEvents.count() == 0 ) {
161 KMessageBox::information(
this,
162 i18n(
"No events were found matching your search expression."),
167 void SearchDialog::updateView()
170 re.setWildcard(
true );
171 re.setCaseSensitive(
false );
172 re.setPattern( searchEdit->text() );
173 if ( re.isValid() ) {
176 mMatchedEvents.clear();
179 listView->showIncidences( mMatchedEvents, TQDate() );
182 void SearchDialog::search(
const TQRegExp &re )
184 TQDate startDt = mStartDate->date();
185 TQDate endDt = mEndDate->date();
188 if (mEventsCheck->isChecked()) {
189 events = mCalendar->events( startDt, endDt, mInclusiveCheck->isChecked() );
192 if (mTodosCheck->isChecked()) {
193 if ( mIncludeUndatedTodos->isChecked() ) {
194 Todo::List alltodos = mCalendar->todos();
195 Todo::List::iterator it;
197 for (it=alltodos.begin(); it!=alltodos.end(); ++it) {
201 ( todo->
hasDueDate() && (todo->
dtDue().date()>=startDt) && (todo->
dtDue()<=TQDateTime(endDt)) ) ||
203 todos.append( todo );
208 while ( dt <= endDt ) {
209 todos += mCalendar->todos( dt );
210 dt = dt.addDays( 1 );
215 Journal::List journals;
216 if (mJournalsCheck->isChecked()) {
218 while ( dt <= endDt ) {
219 journals += mCalendar->journals( dt );
220 dt = dt.addDays( 1 );
224 Incidence::List allIncidences = Calendar::mergeIncidenceList( events, todos, journals );
226 mMatchedEvents.clear();
227 Incidence::List::ConstIterator it;
228 for( it = allIncidences.begin(); it != allIncidences.end(); ++it ) {
230 if ( mSummaryCheck->isChecked() ) {
231 if ( re.search( ev->
summary() ) != -1 ) {
232 mMatchedEvents.append( ev );
236 if ( mDescriptionCheck->isChecked() ) {
238 mMatchedEvents.append( ev );
242 if ( mCategoryCheck->isChecked() ) {
244 mMatchedEvents.append( ev );
TQString description() const
TQString categoriesStr() const
bool hasStartDate() const
TQDateTime dtStart(bool first=false) const
TQDateTime completed() const
bool hasCompletedDate() const
TQDateTime dtDue(bool first=false) const
This class provides a multi-column list view of events.