~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mobile/calendar/searchwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
 
3
    Copyright (c) 2010 Tobias Koenig <tobias.koenig@kdab.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Lesser General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2.1 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Lesser General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Lesser General Public
 
16
    License along with this library; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
18
*/
 
19
 
 
20
#include "searchwidget.h"
 
21
 
 
22
#include "stylesheetloader.h"
 
23
 
 
24
#include <kcalcore/event.h>
 
25
#include <kcalcore/todo.h>
 
26
 
 
27
#include <QtCore/QDate>
 
28
 
 
29
SearchWidget::SearchWidget( QWidget *parent )
 
30
  : QWidget( parent )
 
31
{
 
32
  mUi.setupUi( this );
 
33
 
 
34
  // set defaults
 
35
  mUi.inSummaries->setChecked( true );
 
36
  mUi.inDescriptions->setChecked( true );
 
37
  mUi.includeTodosWithoutDueDate->setChecked( true );
 
38
  mUi.startDate->setDate( QDate::currentDate() );
 
39
  mUi.endDate->setDate( QDate::currentDate().addYears( 1 ) );
 
40
  mUi.collectionCombo->setMimeTypeFilter( QStringList() << KCalCore::Event::eventMimeType()
 
41
                                                        << KCalCore::Todo::todoMimeType() );
 
42
 
 
43
  // UI workarounds for Maemo5
 
44
#ifdef Q_WS_MAEMO_5
 
45
  mUi.startDate->setEditable( false );
 
46
  mUi.endDate->setEditable( false );
 
47
#endif
 
48
}
 
49
 
 
50
QString SearchWidget::query() const
 
51
{
 
52
#ifdef AKONADI_USE_STRIGI_SEARCH
 
53
  QStringList containsPatternParts;
 
54
 
 
55
  if ( mUi.inSummaries->isChecked() ) {
 
56
    containsPatternParts << QString::fromLatin1( "<contains>"
 
57
                                                 "  <field name=\"summary\"/>"
 
58
                                                 "  <string>%1</string>"
 
59
                                                 "</contains>"
 
60
                                               ).arg( mUi.searchText->text().toLower() );
 
61
  }
 
62
  if ( mUi.inDescriptions->isChecked() ) {
 
63
    containsPatternParts << QString::fromLatin1( "<contains>"
 
64
                                                 "  <field name=\"description\"/>"
 
65
                                                 "  <string>%1</string>"
 
66
                                                 "</contains>"
 
67
                                               ).arg( mUi.searchText->text().toLower() );
 
68
  }
 
69
  if ( mUi.inCategories->isChecked() ) {
 
70
    containsPatternParts << QString::fromLatin1( "<contains>"
 
71
                                                 "  <field name=\"categories\"/>"
 
72
                                                 "  <string>%1</string>"
 
73
                                                 "</contains>"
 
74
                                               ).arg( mUi.searchText->text().toLower() );
 
75
  }
 
76
  if ( mUi.inLocations->isChecked() ) {
 
77
    containsPatternParts << QString::fromLatin1( "<contains>"
 
78
                                                 "  <field name=\"location\"/>"
 
79
                                                 "  <string>%1</string>"
 
80
                                                 "</contains>"
 
81
                                               ).arg( mUi.searchText->text().toLower() );
 
82
  }
 
83
 
 
84
  const QString containsPattern = containsPatternParts.isEmpty() ? QString() :
 
85
                                                                   QLatin1String( "<or>" ) +
 
86
                                                                   containsPatternParts.join( QLatin1String( "\n" ) ) +
 
87
                                                                   QLatin1String( "</or>" );
 
88
 
 
89
  const QString inCollection = QString::fromLatin1( "<equals>"
 
90
                                                    "  <field name=\"isPartOf\"/>"
 
91
                                                    "  <string>%1</string>"
 
92
                                                    "</equals>"
 
93
                                                  ).arg( mUi.collectionCombo->currentCollection().id() );
 
94
 
 
95
  const QString startDate = mUi.startDate->date().toString( "yyyyMMdd" );
 
96
  const QString endDate = mUi.endDate->date().toString( "yyyyMMdd" );
 
97
 
 
98
  const QString inTimeRange = QString::fromLatin1(
 
99
                                                   "<greaterThanEquals>"
 
100
                                                   "  <field name=\"dtstart\"/>"
 
101
                                                   "  <string>%1</string>"
 
102
                                                   "</greaterThanEquals>"
 
103
                                                   "<lessThanEquals>"
 
104
                                                   "  <field name=\"dtstart\"/>"
 
105
                                                   "  <string>%2</string>"
 
106
                                                   "</lessThanEquals>"
 
107
                                                 ).arg( startDate ).arg( endDate );
 
108
 
 
109
 
 
110
  const QString isEvent = QString::fromLatin1(
 
111
                                               "<equals>"
 
112
                                               "  <field name=\"type\"/>"
 
113
                                               "  <string>Event</string>"
 
114
                                               "</equals>"
 
115
                                             );
 
116
 
 
117
  const QString isTodo = QString::fromLatin1(
 
118
                                              "<equals>"
 
119
                                              "  <field name=\"type\"/>"
 
120
                                              "  <string>Todo</string>"
 
121
                                              "</equals>"
 
122
                                            );
 
123
 
 
124
  QString query;
 
125
  query += QLatin1String( "<request><query>" );
 
126
  query += QLatin1String( "<or>" );
 
127
 
 
128
  query += QLatin1String( "  <and>" );
 
129
  query += isEvent;
 
130
  query += containsPattern;
 
131
  if ( mUi.includeDateRange->isChecked() )
 
132
    query += inTimeRange;
 
133
  if ( mUi.locatedInSpecificCollection->isChecked() )
 
134
    query += inCollection;
 
135
  query += QLatin1String( "  </and>" );
 
136
 
 
137
  query += QLatin1String( "  <and>" );
 
138
  query += isTodo;
 
139
  query += containsPattern;
 
140
  if ( !mUi.includeTodosWithoutDueDate->isChecked() )
 
141
    query += inTimeRange;
 
142
  if ( mUi.locatedInSpecificCollection->isChecked() )
 
143
    query += inCollection;
 
144
  query += QLatin1String( "  </and>" );
 
145
 
 
146
  query += QLatin1String( "</or>" );
 
147
  query += QLatin1String( "</query></request>" );
 
148
 
 
149
  return query;
 
150
#else
 
151
 
 
152
  return QString();
 
153
#endif
 
154
}
 
155
 
 
156
DeclarativeSearchWidget::DeclarativeSearchWidget( QGraphicsItem *parent )
 
157
  : QGraphicsProxyWidget( parent ), mSearchWidget( new SearchWidget )
 
158
{
 
159
  QPalette palette = mSearchWidget->palette();
 
160
  palette.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
 
161
  mSearchWidget->setPalette( palette );
 
162
  StyleSheetLoader::applyStyle( mSearchWidget );
 
163
 
 
164
  setWidget( mSearchWidget );
 
165
  setFocusPolicy( Qt::StrongFocus );
 
166
}
 
167
 
 
168
DeclarativeSearchWidget::~DeclarativeSearchWidget()
 
169
{
 
170
}
 
171
 
 
172
QString DeclarativeSearchWidget::query() const
 
173
{
 
174
  return mSearchWidget->query();
 
175
}
 
176
 
 
177
#include "searchwidget.moc"