doc fixes found while translating
[kdepim.git] / mobile / mail / searchwidget.cpp
blob21fd2c85898ac32028edde9e4bb7f1c2b13d2abe
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>
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.
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.
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
20 #include "searchwidget.h"
22 #include "stylesheetloader.h"
24 #include <kmime/kmime_message.h>
26 #include <QtCore/QDate>
28 SearchWidget::SearchWidget( QWidget *parent )
29 : QWidget( parent )
31 mUi.setupUi( this );
33 // set defaults
34 mUi.inSubjects->setChecked( true );
35 mUi.inSenders->setChecked( true );
36 mUi.inBodyContents->setChecked( true );
37 mUi.startDate->setDate( QDate::currentDate() );
38 mUi.endDate->setDate( QDate::currentDate().addYears( 1 ) );
39 mUi.collectionCombo->setMimeTypeFilter( QStringList() << KMime::Message::mimeType() );
41 // UI workarounds for Maemo5
42 #ifdef Q_WS_MAEMO_5
43 mUi.startDate->setEditable( false );
44 mUi.endDate->setEditable( false );
45 #endif
48 QString SearchWidget::query() const
50 #ifdef AKONADI_USE_STRIGI_SEARCH
51 QStringList containsPatternParts;
53 if ( mUi.inSubjects->isChecked() ) {
54 containsPatternParts << QString::fromLatin1( "<contains>"
55 " <field name=\"subject\"/>"
56 " <string>%1</string>"
57 "</contains>"
58 ).arg( mUi.searchText->text().toLower() );
60 if ( mUi.inSenders->isChecked() ) {
61 containsPatternParts << QString::fromLatin1(
62 "<contains>"
63 " <field name=\"from\"/>"
64 " <string>%1</string>"
65 "</contains>"
66 "<contains>"
67 " <field name=\"sender\"/>"
68 " <string>%1</string>"
69 "</contains>"
70 ).arg( mUi.searchText->text().toLower() );
72 if ( mUi.inRecipients->isChecked() ) {
73 containsPatternParts << QString::fromLatin1(
74 "<contains>"
75 " <field name=\"to\"/>"
76 " <string>%1</string>"
77 "</contains>"
78 "<contains>"
79 " <field name=\"cc\"/>"
80 " <string>%1</string>"
81 "</contains>"
82 "<contains>"
83 " <field name=\"bcc\"/>"
84 " <string>%1</string>"
85 "</contains>"
86 ).arg( mUi.searchText->text().toLower() );
88 if ( mUi.inBodyContents->isChecked() ) {
89 containsPatternParts << QString::fromLatin1( "<contains>"
90 " <field name=\"plainTextMessageContent\"/>"
91 " <string>%1</string>"
92 "</contains>"
93 ).arg( mUi.searchText->text().toLower() );
96 const QString containsPattern = containsPatternParts.isEmpty() ? QString() :
97 QLatin1String( "<or>" ) +
98 containsPatternParts.join( QLatin1String( "\n" ) ) +
99 QLatin1String( "</or>" );
101 const QString inCollection = QString::fromLatin1( "<equals>"
102 " <field name=\"isPartOf\"/>"
103 " <string>%1</string>"
104 "</equals>"
105 ).arg( mUi.collectionCombo->currentCollection().id() );
107 const QString startDate = mUi.startDate->date().toString( "yyyyMMdd" );
108 const QString endDate = mUi.endDate->date().toString( "yyyyMMdd" );
110 const QString inTimeRange = QString::fromLatin1(
111 "<greaterThanEquals>"
112 " <field name=\"sentDate\"/>"
113 " <string>%1</string>"
114 "</greaterThanEquals>"
115 "<lessThanEquals>"
116 " <field name=\"sentDate\"/>"
117 " <string>%2</string>"
118 "</lessThanEquals>"
119 ).arg( startDate ).arg( endDate );
122 const QString isEmail = QString::fromLatin1(
123 "<equals>"
124 " <field name=\"type\"/>"
125 " <string>Email</string>"
126 "</equals>"
129 QString query;
130 query += QLatin1String( "<request><query>" );
132 query += QLatin1String( " <and>" );
133 query += isEmail;
134 query += containsPattern;
135 if ( mUi.includeDateRange->isChecked() )
136 query += inTimeRange;
137 if ( mUi.locatedInSpecificCollection->isChecked() )
138 query += inCollection;
139 query += QLatin1String( " </and>" );
141 query += QLatin1String( "</query></request>" );
143 return query;
144 #else
146 return QString();
147 #endif
150 DeclarativeSearchWidget::DeclarativeSearchWidget( QGraphicsItem *parent )
151 : QGraphicsProxyWidget( parent ), mSearchWidget( new SearchWidget )
153 QPalette palette = mSearchWidget->palette();
154 palette.setColor( QPalette::Window, QColor( 0, 0, 0, 0 ) );
155 mSearchWidget->setPalette( palette );
156 StyleSheetLoader::applyStyle( mSearchWidget );
158 setWidget( mSearchWidget );
159 setFocusPolicy( Qt::StrongFocus );
162 DeclarativeSearchWidget::~DeclarativeSearchWidget()
166 QString DeclarativeSearchWidget::query() const
168 return mSearchWidget->query();
171 #include "searchwidget.moc"