• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
searchdialog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
6  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of Qt, and distribute the resulting executable,
24  without including the source code for Qt in the source distribution.
25 */
26 
27 #include "searchdialog.h"
28 
29 #include "ui_searchdialog_base.h"
30 #include "calendarview.h"
31 #include "koglobals.h"
32 
33 #include <calendarsupport/kcalprefs.h>
34 #include <calendarsupport/utils.h>
35 
36 #include <calendarviews/list/listview.h>
37 
38 #include <KMessageBox>
39 
40 #include <QTimer>
41 
42 using namespace KOrg;
43 
44 SearchDialog::SearchDialog( CalendarView *calendarview )
45  : KDialog( calendarview ),
46  m_ui( new Ui::SearchDialog ),
47  m_calendarview( calendarview )
48 {
49  setCaption( i18n( "Search Calendar" ) );
50  setModal( false );
51 
52  QWidget *mainWidget = new QWidget( this );
53  m_ui->setupUi( mainWidget );
54  setMainWidget( mainWidget );
55 
56  // Set nice initial start and end dates for the search
57  const QDate currDate = QDate::currentDate();
58  m_ui->startDate->setDate( currDate );
59  m_ui->endDate->setDate( currDate.addYears( 1 ) );
60 
61  connect( m_ui->searchEdit, SIGNAL(textChanged(QString)),
62  this, SLOT(searchTextChanged(QString)) );
63 
64  // Results list view
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 );
70 
71  connect( this, SIGNAL(user1Clicked()), SLOT(doSearch()) );
72 
73  // Propagate edit and delete event signals from event list view
74  connect( listView, SIGNAL(showIncidenceSignal(Akonadi::Item)),
75  SIGNAL(showIncidenceSignal(Akonadi::Item)) );
76  connect( listView, SIGNAL(editIncidenceSignal(Akonadi::Item)),
77  SIGNAL(editIncidenceSignal(Akonadi::Item)) );
78  connect( listView, SIGNAL(deleteIncidenceSignal(Akonadi::Item)),
79  SIGNAL(deleteIncidenceSignal(Akonadi::Item)) );
80 
81  readConfig();
82 
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 );
90 }
91 
92 SearchDialog::~SearchDialog()
93 {
94  writeConfig();
95 }
96 
97 void SearchDialog::showEvent( QShowEvent *event )
98 {
99  Q_UNUSED( event );
100  m_ui->searchEdit->setFocus();
101 }
102 
103 void SearchDialog::searchTextChanged( const QString &_text )
104 {
105  enableButton( KDialog::User1, !_text.isEmpty() );
106 }
107 
108 void SearchDialog::doSearch()
109 {
110  QRegExp re;
111  re.setPatternSyntax( QRegExp::Wildcard ); // most people understand these better.
112  re.setCaseSensitivity( Qt::CaseInsensitive );
113  re.setPattern( m_ui->searchEdit->text() );
114  if ( !re.isValid() ) {
115  KMessageBox::sorry(
116  this,
117  i18n( "Invalid search expression, cannot perform the search. "
118  "Please enter a search expression using the wildcard characters "
119  "'*' and '?' where needed." ) );
120  return;
121  }
122 
123  search( re );
124  listView->showIncidences( mMatchedEvents, QDate() );
125  if ( mMatchedEvents.isEmpty() ) {
126  m_ui->numItems->setText ( QString() );
127  KMessageBox::information(
128  this,
129  i18n( "No items were found that match your search pattern." ),
130  i18n( "Search Results" ),
131  QLatin1String( "NoSearchResults" ) );
132  } else {
133  m_ui->numItems->setText( i18np( "%1 item","%1 items", mMatchedEvents.count() ) );
134  }
135 }
136 
137 void SearchDialog::updateView()
138 {
139  QRegExp re;
140  re.setPatternSyntax( QRegExp::Wildcard ); // most people understand these better.
141  re.setCaseSensitivity( Qt::CaseInsensitive );
142  re.setPattern( m_ui->searchEdit->text() );
143  if ( re.isValid() ) {
144  search( re );
145  } else {
146  mMatchedEvents.clear();
147  }
148  listView->showIncidences( mMatchedEvents, QDate() );
149 }
150 
151 void SearchDialog::search( const QRegExp &re )
152 {
153  const QDate startDt = m_ui->startDate->date();
154  const QDate endDt = m_ui->endDate->date();
155 
156  KCalCore::Event::List events;
157  KDateTime::Spec timeSpec = CalendarSupport::KCalPrefs::instance()->timeSpec();
158  if ( m_ui->eventsCheck->isChecked() ) {
159  events =
160  m_calendarview->calendar()->events(
161  startDt, endDt, timeSpec, m_ui->inclusiveCheck->isChecked() );
162  }
163 
164  KCalCore::Todo::List todos;
165 
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 ) {
171  Q_ASSERT( todo );
172  if ( ( !todo->hasStartDate() && !todo->hasDueDate() ) || // undated
173  ( todo->hasStartDate() &&
174  ( todo->dtStart().toTimeSpec( spec ).date() >= startDt ) &&
175  ( todo->dtStart().toTimeSpec( spec ).date() <= endDt ) ) || //start dt in range
176  ( todo->hasDueDate() &&
177  ( todo->dtDue().toTimeSpec( spec ).date() >= startDt ) &&
178  ( todo->dtDue().toTimeSpec( spec ).date() <= endDt ) ) || //due dt in range
179  ( todo->hasCompletedDate() &&
180  ( todo->completed().toTimeSpec( spec ).date() >= startDt ) &&
181  ( todo->completed().toTimeSpec( spec ).date() <= endDt ) ) ) {//completed dt in range
182  todos.append( todo );
183  }
184  }
185  } else {
186  QDate dt = startDt;
187  while ( dt <= endDt ) {
188  todos += m_calendarview->calendar()->todos( dt );
189  dt = dt.addDays( 1 );
190  }
191  }
192  }
193 
194  KCalCore::Journal::List journals;
195  if ( m_ui->journalsCheck->isChecked() ) {
196  QDate dt = startDt;
197  while ( dt <= endDt ) {
198  journals += m_calendarview->calendar()->journals( dt );
199  dt = dt.addDays( 1 );
200  }
201  }
202 
203  mMatchedEvents.clear();
204  KCalCore::Incidence::List incidences =
205  Akonadi::ETMCalendar::mergeIncidenceList( events, todos, journals );
206  Q_FOREACH ( const KCalCore::Incidence::Ptr &ev, incidences ) {
207  Q_ASSERT( ev );
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 );
212  continue;
213  }
214  }
215  if ( m_ui->descriptionCheck->isChecked() ) {
216  if ( re.indexIn( ev->description() ) != -1 ) {
217  mMatchedEvents.append( item );
218  continue;
219  }
220  }
221  if ( m_ui->categoryCheck->isChecked() ) {
222  if ( re.indexIn( ev->categoriesStr() ) != -1 ) {
223  mMatchedEvents.append( item );
224  continue;
225  }
226  }
227  if ( m_ui->locationCheck->isChecked() ) {
228  if ( re.indexIn( ev->location() ) != -1 ) {
229  mMatchedEvents.append( item );
230  continue;
231  }
232  }
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 );
237  break;
238  }
239  }
240  }
241  }
242 }
243 
244 void SearchDialog::readConfig()
245 {
246  KConfigGroup group( KOGlobals::self()->config(), QLatin1String( "SearchDialog" ) );
247  const QSize size = group.readEntry( "Size", QSize( 775, 600 ) );
248  if ( size.isValid() ) {
249  resize( size );
250  }
251 }
252 
253 void SearchDialog::writeConfig()
254 {
255  KConfigGroup group( KOGlobals::self()->config(), QLatin1String( "SearchDialog" ) );
256  group.writeEntry( "Size", size() );
257  group.sync();
258 }
259 
260 #include "searchdialog.moc"
koglobals.h
SearchDialog::showIncidenceSignal
void showIncidenceSignal(const Akonadi::Item &)
SearchDialog::~SearchDialog
virtual ~SearchDialog()
Definition: searchdialog.cpp:92
QWidget
KDialog
searchdialog.h
SearchDialog::editIncidenceSignal
void editIncidenceSignal(const Akonadi::Item &)
CalendarView
This is the main calendar widget.
Definition: calendarview.h:99
CalendarView::calendar
Akonadi::ETMCalendar::Ptr calendar() const
Definition: calendarview.cpp:313
SearchDialog::deleteIncidenceSignal
void deleteIncidenceSignal(const Akonadi::Item &)
SearchDialog::SearchDialog
SearchDialog(CalendarView *calendarview)
Definition: searchdialog.cpp:44
SearchDialog::searchTextChanged
void searchTextChanged(const QString &_text)
Definition: searchdialog.cpp:103
SearchDialog::doSearch
void doSearch()
Definition: searchdialog.cpp:108
SearchDialog::showEvent
virtual void showEvent(QShowEvent *event)
Definition: searchdialog.cpp:97
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
SearchDialog::updateView
void updateView()
Definition: searchdialog.cpp:137
calendarview.h
SearchDialog
Definition: searchdialog.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal