22 #include "core/settings.h"
23 #include <akonadi/kmime/messagestatus.h>
24 #include "pimcommon/widgets/lineeditwithcompleter.h"
25 #include <KLocalizedString>
28 #include <KStandardDirs>
30 #include <KIconLoader>
31 #include <KPushButton>
33 #include <QToolButton>
34 #include <QHBoxLayout>
35 #include <QPushButton>
36 #include <QButtonGroup>
39 #include <QSignalMapper>
42 using namespace MessageList::Core;
45 mContainsOutboundMessages(false),
46 mFilterStatusMapper(0)
62 mLockSearch->
setText( i18nc(
"@action:button",
"Lock search" ) );
65 i18nc(
"@info:whatsthis",
66 "Toggle this button if you want to keep your quick search "
67 "locked when moving to other folders or when narrowing the search "
68 "by message status." ) );
69 slotLockSearchClicked(
false);
70 connect( mLockSearch, SIGNAL(toggled(
bool)), SLOT(slotLockSearchClicked(
bool)));
75 mQuickSearchFilterWidget =
new QWidget;
78 mQuickSearchFilterWidget->
setLayout(quickSearchButtonLayout);
81 quickSearchButtonLayout->
addWidget(quickLab);
82 initializeStatusSearchButton(quickSearchButtonLayout);
83 vbox->
addWidget(mQuickSearchFilterWidget);
85 mSearchEdit =
new PimCommon::LineEditWithCompleter(
this );
86 mSearchEdit->setClickMessage( i18nc(
"Search for messages.",
"Search" ) );
88 mSearchEdit->setClearButtonShown(
true );
98 mMoreOptions->setFlat(
true);
99 mMoreOptions->setCheckable(
true);
100 connect( mMoreOptions, SIGNAL(toggled(
bool)), SLOT(slotMoreOptionClicked(
bool)));
104 mTagFilterCombo =
new KComboBox(
this ) ;
105 mTagFilterCombo->setMaximumWidth(300);
106 mTagFilterCombo->setMaximumWidth(200);
107 mTagFilterCombo->hide();
111 mSearchEdit->setEnabled(
false );
112 mTagFilterCombo->setEnabled(
false );
120 mExtraOption->
hide();
126 mSearchEveryWhere =
new QPushButton(i18n(
"Full Message"));
128 mSearchEveryWhere->
setFlat(
true);
131 connect( mSearchEveryWhere, SIGNAL(clicked()),
this, SLOT(slotSearchBy()) );
134 mSearchAgainstBody =
new QPushButton(i18n(
"Body"));
136 mSearchAgainstBody->
setFlat(
true);
138 connect( mSearchAgainstBody, SIGNAL(clicked()),
this, SLOT(slotSearchBy()) );
141 mSearchAgainstSubject =
new QPushButton(i18n(
"Subject"));
143 mSearchAgainstSubject->
setFlat(
true);
145 connect( mSearchAgainstSubject, SIGNAL(clicked()),
this, SLOT(slotSearchBy()) );
149 changeSearchAgainstFromOrToText();
152 mSearchAgainstFromOrTo->
setFlat(
true);
153 connect( mSearchAgainstFromOrTo, SIGNAL(clicked()),
this, SLOT(slotSearchBy()) );
159 mSearchAgainstBcc->
setFlat(
true);
160 connect( mSearchAgainstBcc, SIGNAL(clicked()),
this, SLOT(slotSearchBy()) );
163 mQuickSearchFilterWidget->
hide();
166 mMoreOptions->installEventFilter(
this);
167 mTagFilterCombo->installEventFilter(
this);
184 void QuickSearchLine::slotSearchBy()
187 if (mSearchEveryWhere != button) {
190 if (mSearchAgainstBody != button) {
193 if (mSearchAgainstSubject != button) {
196 if (mSearchAgainstFromOrTo != button) {
199 if (mSearchAgainstBcc != button) {
203 slotSearchOptionChanged();
206 void QuickSearchLine::slotMoreOptionClicked(
bool b)
210 mMoreOptions->setIcon(KIcon(
QLatin1String(
"arrow-up-double")));
212 mMoreOptions->setIcon(KIcon(
QLatin1String(
"arrow-down-double")));
216 void QuickSearchLine::slotSearchEditTextEdited(
const QString &text)
218 int minimumStringLength = 3;
220 minimumStringLength = 5;
223 if (text.
length() >= minimumStringLength) {
224 mExtraOption->
show();
227 mExtraOption->
hide();
230 slotClearButtonClicked();
234 void QuickSearchLine::slotClearButtonClicked()
236 mExtraOption->
hide();
238 if (mTagFilterCombo->isVisible())
239 mTagFilterCombo->setCurrentIndex(0);
243 void QuickSearchLine::slotSearchOptionChanged()
257 if (mSearchAgainstSubject->
isChecked()) {
260 if (mSearchAgainstFromOrTo->
isChecked()) {
261 if (mContainsOutboundMessages)
275 mSearchEdit->setText(selectedText);
277 mSearchEdit->setFocus();
282 return mTagFilterCombo;
295 void QuickSearchLine::slotLockSearchClicked(
bool locked )
299 mLockSearch->
setToolTip( i18nc(
"@info:tooltip",
"Clear the quick search field when changing folders" ) );
302 mLockSearch->
setToolTip( i18nc(
"@info:tooltip",
303 "Prevent the quick search field from being cleared when changing folders" ) );
309 Q_FOREACH(
QToolButton *button, mListStatusButton) {
312 if (mTagFilterCombo->isVisible())
313 mTagFilterCombo->setCurrentIndex( 0 );
321 mExtraOption->
hide();
324 void QuickSearchLine::createQuickSearchButton(
const QIcon &icon,
const QString &text,
int value,
QLayout *quickSearchButtonLayout)
334 mFilterStatusMapper->
setMapping(button, value);
335 connect( button, SIGNAL(clicked(
bool)), mFilterStatusMapper, SLOT(map()) );
336 quickSearchButtonLayout->
addWidget(button);
339 mListStatusButton.
append(button);
344 return mContainsOutboundMessages;
349 if (mContainsOutboundMessages != containsOutboundMessages) {
351 changeSearchAgainstFromOrToText();
355 void QuickSearchLine::changeSearchAgainstFromOrToText()
357 if (mContainsOutboundMessages) {
358 mSearchAgainstFromOrTo->
setText(i18n(
"To"));
360 mSearchAgainstFromOrTo->
setText(i18n(
"From"));
364 void QuickSearchLine::initializeStatusSearchButton(
QLayout *quickSearchButtonLayout)
370 createQuickSearchButton(SmallIcon(
QLatin1String(
"mail-unread" )), i18nc(
"@action:inmenu Status of a message",
"Unread" ), Akonadi::MessageStatus::statusUnread().toQInt32(),quickSearchButtonLayout );
372 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-replied" )),
373 i18nc(
"@action:inmenu Status of a message",
"Replied" ),
374 Akonadi::MessageStatus::statusReplied().toQInt32(), quickSearchButtonLayout );
376 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-forwarded" )),
377 i18nc(
"@action:inmenu Status of a message",
"Forwarded" ),
378 Akonadi::MessageStatus::statusForwarded().toQInt32(), quickSearchButtonLayout );
380 createQuickSearchButton( SmallIcon(
QLatin1String(
"emblem-important" )),
381 i18nc(
"@action:inmenu Status of a message",
"Important"),
382 Akonadi::MessageStatus::statusImportant().toQInt32(), quickSearchButtonLayout );
384 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-task" )),
385 i18nc(
"@action:inmenu Status of a message",
"Action Item" ),
386 Akonadi::MessageStatus::statusToAct().toQInt32(), quickSearchButtonLayout );
388 createQuickSearchButton(
QIcon( KStandardDirs::locate(
"data",
QLatin1String(
"messagelist/pics/mail-thread-watch.png" ) ) ),
389 i18nc(
"@action:inmenu Status of a message",
"Watched" ),
390 Akonadi::MessageStatus::statusWatched().toQInt32(), quickSearchButtonLayout );
392 createQuickSearchButton(
QIcon( KStandardDirs::locate(
"data",
QLatin1String(
"messagelist/pics/mail-thread-ignored.png" ) ) ),
393 i18nc(
"@action:inmenu Status of a message",
"Ignored" ),
394 Akonadi::MessageStatus::statusIgnored().toQInt32(), quickSearchButtonLayout );
396 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-attachment" )),
397 i18nc(
"@action:inmenu Status of a message",
"Has Attachment" ),
398 Akonadi::MessageStatus::statusHasAttachment().toQInt32(), quickSearchButtonLayout );
400 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-invitation" )),
401 i18nc(
"@action:inmenu Status of a message",
"Has Invitation" ),
402 Akonadi::MessageStatus::statusHasInvitation().toQInt32(), quickSearchButtonLayout );
404 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-mark-junk" )),
405 i18nc(
"@action:inmenu Status of a message",
"Spam" ),
406 Akonadi::MessageStatus::statusSpam().toQInt32(), quickSearchButtonLayout );
408 createQuickSearchButton( SmallIcon(
QLatin1String(
"mail-mark-notjunk" )),
409 i18nc(
"@action:inmenu Status of a message",
"Ham" ),
410 Akonadi::MessageStatus::statusHam().toQInt32(), quickSearchButtonLayout );
417 Q_FOREACH(
QToolButton *button, mListStatusButton) {
419 Akonadi::MessageStatus
status;
420 status.fromQInt32( static_cast< qint32 >( button->
property(
"statusvalue").
toInt() ));
429 mTagFilterCombo->setVisible(!mSearchEdit->isHidden() && mTagFilterCombo->count());
434 const bool shortCutOverride = (e->
type() == QEvent::ShortcutOverride);
435 if (shortCutOverride) {
444 mSearchEdit->setVisible( show );
445 mTagFilterCombo->setVisible( show && mTagFilterCombo->count());
447 mMoreOptions->setVisible( show );
void statusButtonsClicked()
QuickSearchLine(QWidget *parent=0)
bool containsOutboundMessages() const
void changeQuicksearchVisibility(bool show)
void searchEditTextEdited(const QString &)
void updateComboboxVisibility()
void focusQuickSearch(const QString &selectedText)
KLineEdit * searchEdit() const
SearchOptions searchOptions() const
bool eventFilter(QObject *object, QEvent *e)
void setMapping(QObject *sender, int id)
void append(const T &value)
QVariant property(const char *name) const
void installEventFilter(QObject *filterObj)
int toInt(bool *ok) const
void setObjectName(const QString &name)
void searchOptionChanged()
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual bool eventFilter(QObject *watched, QEvent *event)
void setMargin(int margin)
QList< Akonadi::MessageStatus > status() const
void setContainsOutboundMessages(bool containsOutboundMessages)
QToolButton * lockSearch() const
void addStretch(int stretch)
void setText(const QString &text)
bool setProperty(const char *name, const QVariant &value)
void clearButtonClicked()
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
void setSpacing(int spacing)
KComboBox * tagFilterComboBox() const