kmail Library API Documentation

headerlistquicksearch.cpp

00001 /*
00002     This file is part of KMail, the KDE mail client.
00003     Copyright (c) 2004 Till Adam <adam@kde.org>
00004 
00005     KMail is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     KMail is distributed in the hope that it will be useful, but
00011     WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019     In addition, as a special exception, the copyright holders give
00020     permission to link the code of this program with any edition of
00021     the Qt library by Trolltech AS, Norway (or with modified versions
00022     of Qt that use the same license as Qt), and distribute linked
00023     combinations including the two.  You must obey the GNU General
00024     Public License in all respects for all of the code used other than
00025     Qt.  If you modify this file, you may extend this exception to
00026     your version of the file, but you are not obligated to do so.  If
00027     you do not wish to do so, delete this exception statement from
00028     your version.
00029 */
00030 #include "headerlistquicksearch.h"
00031 
00032 #include <qapplication.h>
00033 #include <qlabel.h>
00034 #include <qcombobox.h>
00035 #include <qtimer.h>
00036 
00037 #include <kaction.h>
00038 #include <klistview.h>
00039 #include <klocale.h>
00040 
00041 #include "kmheaders.h"
00042 #include "kmsearchpattern.h"
00043 
00044 namespace KMail {
00045 
00046 HeaderListQuickSearch::HeaderListQuickSearch( QWidget *parent,
00047                                               KListView *listView,
00048                                               KActionCollection *actionCollection,
00049                                               const char *name )
00050   : KListViewSearchLine(parent, listView, name), mStatusCombo(0), mStatus(0)
00051 {
00052   KAction *resetQuickSearch = new KAction( i18n( "Reset Quick Search" ),
00053                                            QApplication::reverseLayout()
00054                                            ? "clear_left"
00055                                            : "locationbar_erase",
00056                                            0, this,
00057                                            SLOT( reset() ),
00058                                            actionCollection,
00059                                            "reset_quicksearch" );
00060   resetQuickSearch->plug( parent );
00061   resetQuickSearch->setWhatsThis( i18n( "Reset Quick Search\n"
00062                                         "Resets the quick search so that "
00063                                         "all messages are shown again." ) );
00064 
00065   QLabel *label = new QLabel( i18n("Stat&us:"), parent, "kde toolbar widget" );
00066 
00067   mStatusCombo = new QComboBox( parent, "quick search status combo box" );
00068   mStatusCombo->insertItem( i18n("Any Status") );
00069   for ( int i = 0; i < KMail::StatusValueCount; i++ )
00070     mStatusCombo->insertItem( i18n( KMail::StatusValues[i] ) );
00071   mStatusCombo->setCurrentItem( 0 );
00072   connect( mStatusCombo, SIGNAL ( activated( int ) ),
00073            this, SLOT( slotStatusChanged( int ) ) );
00074 
00075   label->setBuddy( mStatusCombo );
00076 
00077   /* Disable the signal connected by KListViewSearchLine since it will call 
00078    * itemAdded during KMHeaders::readSortOrder() which will in turn result
00079    * in getMsgBaseForItem( item ) wanting to access items which are no longer
00080    * there. Rather rely on KMHeaders::msgAdded and its signal. */
00081   disconnect(listView, SIGNAL(itemAdded(QListViewItem *)),
00082              this, SLOT(itemAdded(QListViewItem *)));
00083   KMHeaders *headers = static_cast<KMHeaders*>( listView );
00084   connect( headers, SIGNAL( msgAddedToListView( QListViewItem * ) ),
00085            this, SLOT( itemAdded( QListViewItem* ) ) );
00086 }
00087 
00088 HeaderListQuickSearch::~HeaderListQuickSearch()
00089 {
00090 }
00091 
00092 
00093 bool HeaderListQuickSearch::itemMatches(const QListViewItem *item, const QString &s) const
00094 {
00095   if ( mStatus != 0 ) {
00096     KMHeaders *headers = static_cast<KMHeaders*>( item->listView() );
00097     const KMMsgBase *msg = headers->getMsgBaseForItem( item );
00098     if ( !msg || ! ( msg->status() & mStatus ) )
00099       return false;
00100   }
00101   return KListViewSearchLine::itemMatches(item, s);
00102 }
00103 
00104 //-----------------------------------------------------------------------------
00105 void HeaderListQuickSearch::reset()
00106 {
00107   clear();
00108   mStatusCombo->setCurrentItem( 0 );
00109   slotStatusChanged( 0 );
00110 }
00111 
00112 void HeaderListQuickSearch::slotStatusChanged( int index )
00113 {
00114   if ( index == 0 )
00115     mStatus = 0;
00116   else
00117     mStatus =
00118       KMSearchRuleStatus::statusFromEnglishName( KMail::StatusValues[index-1] );
00119   updateSearch();
00120 }
00121 
00122 } // namespace KMail
00123 
00124 #include "headerlistquicksearch.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:24:42 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003