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>
46 m_calendarview( calendarview )
48 setCaption( i18n(
"Search Calendar" ) );
52 m_ui->setupUi( mainWidget );
53 setMainWidget( mainWidget );
57 m_ui->startDate->setDate( currDate );
58 m_ui->endDate->setDate( currDate.
addYears( 1 ) );
60 connect( m_ui->searchEdit, SIGNAL(textChanged(
QString)),
66 listView =
new EventViews::ListView( m_calendarview->
calendar(), this );
68 m_ui->listViewFrame->setLayout( layout );
70 connect(
this, SIGNAL(user1Clicked()), SLOT(
doSearch()) );
82 setButtons( User1 | Cancel );
83 setDefaultButton( User1 );
84 setButtonGuiItem( User1,
85 KGuiItem( i18nc(
"search in calendar",
"&Search" ),
87 setButtonToolTip( User1, i18n(
"Start searching" ) );
88 showButtonSeparator(
false );
100 m_ui->searchEdit->setFocus();
105 enableButton( KDialog::User1, !_text.
isEmpty() );
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" ),
133 m_ui->numItems->setText( i18np(
"%1 item",
"%1 items", mMatchedEvents.
count() ) );
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 );
194 KCalCore::Journal::List journals;
195 if ( m_ui->journalsCheck->isChecked() ) {
197 while ( dt <= endDt ) {
198 journals += m_calendarview->
calendar()->journals( dt );
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()
247 const QSize size = group.readEntry(
"Size",
QSize( 775, 600 ) );
253 void SearchDialog::writeConfig()
256 group.writeEntry(
"Size", size() );
void setPatternSyntax(PatternSyntax syntax)
QDate addYears(int nyears) const
void showIncidenceSignal(const Akonadi::Item &)
void setPattern(const QString &pattern)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
int count(const T &value) const
void append(const T &value)
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)
void setMargin(int margin)
void setCaseSensitivity(Qt::CaseSensitivity cs)
virtual void showEvent(QShowEvent *event)
static KOGlobals * self()
QDate addDays(int ndays) const