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
)
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
43 mUi
.startDate
->setEditable( false );
44 mUi
.endDate
->setEditable( false );
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>"
58 ).arg( mUi
.searchText
->text().toLower() );
60 if ( mUi
.inSenders
->isChecked() ) {
61 containsPatternParts
<< QString::fromLatin1(
63 " <field name=\"from\"/>"
64 " <string>%1</string>"
67 " <field name=\"sender\"/>"
68 " <string>%1</string>"
70 ).arg( mUi
.searchText
->text().toLower() );
72 if ( mUi
.inRecipients
->isChecked() ) {
73 containsPatternParts
<< QString::fromLatin1(
75 " <field name=\"to\"/>"
76 " <string>%1</string>"
79 " <field name=\"cc\"/>"
80 " <string>%1</string>"
83 " <field name=\"bcc\"/>"
84 " <string>%1</string>"
86 ).arg( mUi
.searchText
->text().toLower() );
88 if ( mUi
.inBodyContents
->isChecked() ) {
89 containsPatternParts
<< QString::fromLatin1( "<contains>"
90 " <field name=\"plainTextMessageContent\"/>"
91 " <string>%1</string>"
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>"
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>"
116 " <field name=\"sentDate\"/>"
117 " <string>%2</string>"
119 ).arg( startDate
).arg( endDate
);
122 const QString isEmail
= QString::fromLatin1(
124 " <field name=\"type\"/>"
125 " <string>Email</string>"
130 query
+= QLatin1String( "<request><query>" );
132 query
+= QLatin1String( " <and>" );
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>" );
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"