30 #include "headerlistquicksearch.h"
32 #include <tqapplication.h>
34 #include <tqcombobox.h>
35 #include <tqvaluevector.h>
38 #include <tdeaction.h>
39 #include <kiconloader.h>
40 #include <tdelistview.h>
41 #include <tdelocale.h>
42 #include <tdetoolbarbutton.h>
44 #include "kmheaders.h"
45 #include "kmsearchpattern.h"
46 #include "kmmainwidget.h"
50 HeaderListQuickSearch::HeaderListQuickSearch( TQWidget *parent,
51 TDEListView *listView,
52 TDEActionCollection *actionCollection,
54 : TDEListViewSearchLine(parent, listView, name), mStatusCombo(0), mStatus(0), statusList()
56 TDEAction *resetQuickSearch =
new TDEAction( i18n(
"Reset Quick Search" ),
57 TQApplication::reverseLayout()
59 :
"locationbar_erase",
63 "reset_quicksearch" );
64 resetQuickSearch->plug( parent );
65 resetQuickSearch->setWhatsThis( i18n(
"Reset Quick Search\n"
66 "Resets the quick search so that "
67 "all messages are shown again." ) );
69 TQLabel *label =
new TQLabel( i18n(
"Stat&us:"), parent,
"tde toolbar widget" );
71 mStatusCombo =
new TQComboBox( parent,
"quick search status combo box" );
72 mStatusCombo->setSizeLimit( 12 );
73 mStatusCombo->insertItem( SmallIcon(
"system-run" ), i18n(
"Any Status") );
75 inserStatus( StatusUnread );
76 inserStatus( StatusNew );
77 inserStatus( StatusImportant );
78 inserStatus( StatusReplied );
79 inserStatus( StatusForwarded );
80 inserStatus( StatusToDo );
81 inserStatus( StatusHasAttachment );
82 inserStatus( StatusInvitation );
83 inserStatus( StatusWatched );
84 inserStatus( StatusIgnored );
85 mStatusCombo->setCurrentItem( 0 );
86 mStatusCombo->installEventFilter(
this );
87 connect( mStatusCombo, TQ_SIGNAL ( activated(
int ) ),
88 this, TQ_SLOT( slotStatusChanged(
int ) ) );
90 label->setBuddy( mStatusCombo );
92 TDEToolBarButton * btn =
new TDEToolBarButton(
"mail_find", 0, parent,
93 0, i18n(
"Open Full Search" ) );
94 connect( btn, TQ_SIGNAL( clicked() ), TQ_SIGNAL( requestFullSearch() ) );
100 disconnect(listView, TQ_SIGNAL(itemAdded(TQListViewItem *)),
101 this, TQ_SLOT(itemAdded(TQListViewItem *)));
103 connect( headers, TQ_SIGNAL( msgAddedToListView( TQListViewItem* ) ),
104 this, TQ_SLOT( itemAdded( TQListViewItem* ) ) );
108 HeaderListQuickSearch::~HeaderListQuickSearch()
113 bool HeaderListQuickSearch::eventFilter( TQObject *watched, TQEvent *event )
115 if ( watched == mStatusCombo ) {
116 KMMainWidget *mainWidget = 0;
119 for ( TQWidget *curWidget = parentWidget(); curWidget; curWidget = curWidget->parentWidget() ) {
120 mainWidget = ::tqt_cast<KMMainWidget *>( curWidget );
126 switch ( event->type() ) {
127 case TQEvent::FocusIn:
128 mainWidget->setAccelsEnabled(
false );
130 case TQEvent::FocusOut:
131 mainWidget->setAccelsEnabled(
true );
145 bool HeaderListQuickSearch::itemMatches(
const TQListViewItem *item,
const TQString &s)
const
147 mCurrentSearchTerm = s;
148 if ( mStatus != 0 ) {
151 if ( !msg || ! ( msg->status() & mStatus ) )
158 if ( headerItem->from().lower().contains( s.lower() ) ) {
161 if ( headerItem->to().lower().contains( s.lower() ) ) {
165 return TDEListViewSearchLine::itemMatches(item, s);
169 void HeaderListQuickSearch::reset()
172 mStatusCombo->setCurrentItem( 0 );
173 slotStatusChanged( 0 );
176 void HeaderListQuickSearch::slotStatusChanged(
int index )
181 mStatus = KMSearchRuleStatus::statusFromEnglishName( statusList[index - 1] );
185 void HeaderListQuickSearch::inserStatus(KMail::StatusValueTypes which)
187 mStatusCombo->insertItem( SmallIcon( KMail::StatusValues[which].icon ),
188 i18n( KMail::StatusValues[ which ].text ) );
189 statusList.append( KMail::StatusValues[ which ].text );
193 TQString HeaderListQuickSearch::currentSearchTerm()
const
195 return mCurrentSearchTerm;
199 int HeaderListQuickSearch::currenStatus()
const
206 #include "headerlistquicksearch.moc"