29 #include "ui_searchdialog_base.h"
33 #include <calendarsupport/kcalprefs.h>
34 #include <calendarsupport/utils.h>
36 #include <calendarviews/list/listview.h>
38 #include <KMessageBox>
47 m_calendarview( calendarview )
49 setCaption( i18n(
"Search Calendar" ) );
53 m_ui->setupUi( mainWidget );
54 setMainWidget( mainWidget );
57 const QDate currDate = QDate::currentDate();
58 m_ui->startDate->setDate( currDate );
59 m_ui->endDate->setDate( currDate.addYears( 1 ) );
61 connect( m_ui->searchEdit, SIGNAL(textChanged(QString)),
65 QVBoxLayout *layout =
new QVBoxLayout;
66 layout->setMargin( 0 );
67 listView =
new EventViews::ListView( m_calendarview->
calendar(), this );
68 layout->addWidget( listView );
69 m_ui->listViewFrame->setLayout( layout );
71 connect(
this, SIGNAL(user1Clicked()), SLOT(
doSearch()) );
83 setButtons( User1 | Cancel );
84 setDefaultButton( User1 );
85 setButtonGuiItem( User1,
86 KGuiItem( i18nc(
"search in calendar",
"&Search" ),
87 QLatin1String(
"edit-find" ) ) );
88 setButtonToolTip( User1, i18n(
"Start searching" ) );
89 showButtonSeparator(
false );
100 m_ui->searchEdit->setFocus();
105 enableButton( KDialog::User1, !_text.isEmpty() );
111 re.setPatternSyntax( QRegExp::Wildcard );
112 re.setCaseSensitivity( Qt::CaseInsensitive );
113 re.setPattern( m_ui->searchEdit->text() );
114 if ( !re.isValid() ) {
117 i18n(
"Invalid search expression, cannot perform the search. "
118 "Please enter a search expression using the wildcard characters "
119 "'*' and '?' where needed." ) );
124 listView->showIncidences( mMatchedEvents, QDate() );
125 if ( mMatchedEvents.isEmpty() ) {
126 m_ui->numItems->setText ( QString() );
127 KMessageBox::information(
129 i18n(
"No items were found that match your search pattern." ),
130 i18n(
"Search Results" ),
131 QLatin1String(
"NoSearchResults" ) );
133 m_ui->numItems->setText( i18np(
"%1 item",
"%1 items", mMatchedEvents.count() ) );
140 re.setPatternSyntax( QRegExp::Wildcard );
141 re.setCaseSensitivity( Qt::CaseInsensitive );
142 re.setPattern( m_ui->searchEdit->text() );
143 if ( re.isValid() ) {
146 mMatchedEvents.clear();
148 listView->showIncidences( mMatchedEvents, QDate() );
151 void SearchDialog::search(
const QRegExp &re )
153 const QDate startDt = m_ui->startDate->date();
154 const QDate endDt = m_ui->endDate->date();
156 KCalCore::Event::List events;
157 KDateTime::Spec timeSpec = CalendarSupport::KCalPrefs::instance()->timeSpec();
158 if ( m_ui->eventsCheck->isChecked() ) {
161 startDt, endDt, timeSpec, m_ui->inclusiveCheck->isChecked() );
164 KCalCore::Todo::List todos;
166 if ( m_ui->todosCheck->isChecked() ) {
167 if ( m_ui->includeUndatedTodos->isChecked() ) {
168 KDateTime::Spec spec = CalendarSupport::KCalPrefs::instance()->timeSpec();
169 KCalCore::Todo::List alltodos = m_calendarview->
calendar()->todos();
170 Q_FOREACH (
const KCalCore::Todo::Ptr &todo, alltodos ) {
172 if ( ( !todo->hasStartDate() && !todo->hasDueDate() ) ||
173 ( todo->hasStartDate() &&
174 ( todo->dtStart().toTimeSpec( spec ).date() >= startDt ) &&
175 ( todo->dtStart().toTimeSpec( spec ).date() <= endDt ) ) ||
176 ( todo->hasDueDate() &&
177 ( todo->dtDue().toTimeSpec( spec ).date() >= startDt ) &&
178 ( todo->dtDue().toTimeSpec( spec ).date() <= endDt ) ) ||
179 ( todo->hasCompletedDate() &&
180 ( todo->completed().toTimeSpec( spec ).date() >= startDt ) &&
181 ( todo->completed().toTimeSpec( spec ).date() <= endDt ) ) ) {
182 todos.append( todo );
187 while ( dt <= endDt ) {
188 todos += m_calendarview->
calendar()->todos( dt );
189 dt = dt.addDays( 1 );
194 KCalCore::Journal::List journals;
195 if ( m_ui->journalsCheck->isChecked() ) {
197 while ( dt <= endDt ) {
198 journals += m_calendarview->
calendar()->journals( dt );
199 dt = dt.addDays( 1 );
203 mMatchedEvents.clear();
204 KCalCore::Incidence::List incidences =
205 Akonadi::ETMCalendar::mergeIncidenceList( events, todos, journals );
206 Q_FOREACH (
const KCalCore::Incidence::Ptr &ev, incidences ) {
208 Akonadi::Item item = m_calendarview->
calendar()->item( ev->uid() );
209 if ( m_ui->summaryCheck->isChecked() ) {
210 if ( re.indexIn( ev->summary() ) != -1 ) {
211 mMatchedEvents.append( item );
215 if ( m_ui->descriptionCheck->isChecked() ) {
216 if ( re.indexIn( ev->description() ) != -1 ) {
217 mMatchedEvents.append( item );
221 if ( m_ui->categoryCheck->isChecked() ) {
222 if ( re.indexIn( ev->categoriesStr() ) != -1 ) {
223 mMatchedEvents.append( item );
227 if ( m_ui->locationCheck->isChecked() ) {
228 if ( re.indexIn( ev->location() ) != -1 ) {
229 mMatchedEvents.append( item );
233 if ( m_ui->attendeeCheck->isChecked() ) {
234 Q_FOREACH (
const KCalCore::Attendee::Ptr &attendee, ev->attendees() ) {
235 if ( re.indexIn( attendee->fullName() ) != -1 ) {
236 mMatchedEvents.append( item );
244 void SearchDialog::readConfig()
246 KConfigGroup group(
KOGlobals::self()->config(), QLatin1String(
"SearchDialog" ) );
247 const QSize size = group.readEntry(
"Size", QSize( 775, 600 ) );
248 if ( size.isValid() ) {
253 void SearchDialog::writeConfig()
255 KConfigGroup group(
KOGlobals::self()->config(), QLatin1String(
"SearchDialog" ) );
256 group.writeEntry(
"Size", size() );
260 #include "searchdialog.moc"
void showIncidenceSignal(const Akonadi::Item &)
void editIncidenceSignal(const Akonadi::Item &)
This is the main calendar widget.
Akonadi::ETMCalendar::Ptr calendar() const
void deleteIncidenceSignal(const Akonadi::Item &)
SearchDialog(CalendarView *calendarview)
void searchTextChanged(const QString &_text)
virtual void showEvent(QShowEvent *event)
static KOGlobals * self()