1 /***************************************************************************
2 * Copyright (C) 2003 by Hideki Ikemoto *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #include "threadlistview.h"
13 #include <kiconloader.h>
14 #include <klistview.h>
17 #include <qtoolbutton.h>
18 #include <qcombobox.h>
24 ThreadListView::ThreadListView( QWidget* parent, const char* name )
25 : ThreadListViewBase( parent, name )
27 SearchButton->setPixmap( SmallIcon( "find" ) );
28 HideButton->setPixmap( SmallIcon( "filter" ) );
29 ReloadButton->setPixmap( SmallIcon( "reload" ) );
31 subjectList->addColumn( "" );
32 subjectList->addColumn( i18n( "No." ) );
33 subjectList->addColumn( "" );
34 subjectList->addColumn( i18n( "Title" ) );
35 subjectList->addColumn( i18n( "ResNum" ) );
36 subjectList->addColumn( i18n( "ReadNum" ) );
37 subjectList->addColumn( i18n( "Unread" ) );
38 subjectList->addColumn( i18n( "Since" ) );
39 subjectList->addColumn( i18n( "Board" ) );
41 subjectList->setColumnWidth( Col_Subject, 400 );
42 subjectList->setColumnWidthMode( Col_Subject, QListView::Manual );
44 connect( SearchButton, SIGNAL( clicked() ),
45 SLOT( slotSearchButton() ) );
46 connect( SearchCombo, SIGNAL( activated( int ) ),
47 SLOT( slotSearchButton() ) );
48 connect( HideButton, SIGNAL( toggled( bool ) ),
49 SLOT( slotHideButton( bool ) ) );
52 ThreadListView::~ThreadListView()
55 void ThreadListView::slotSearchButton()
58 QStringList list = parseSearchQuery( SearchCombo->currentText() );
62 void ThreadListView::insertSearchCombo()
64 for ( int count = 0; count < SearchCombo->count(); ++count ) {
65 if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
69 SearchCombo->insertItem( SearchCombo->currentText() );
72 QStringList ThreadListView::parseSearchQuery( const QString &input )
74 QStringList tmp = QStringList::split( ' ', input );
76 QRegExp truncSpace( "\\s*$" );
77 QStringList::iterator it = tmp.begin();
79 for ( ; it != tmp.end(); ++it ) {
80 ret_list += ( *it ).replace( truncSpace, "" );
85 void ThreadListView::searchNext( const QStringList &query )
87 if ( query.isEmpty() ) return ;
89 if ( query != m_prevquery ) {
91 slotHideButton( HideButton->isOn() );
92 m_nextHitIndex = 0; //A next jump-search target reset to '0'.
96 if ( m_nextHitIndex >= m_hitList.size() ) {
100 KListViewItem* item = m_hitList[ m_nextHitIndex ];
101 subjectList->ensureItemVisible( item );
102 subjectList->setSelected( item, true );
104 if ( m_nextHitIndex >= m_hitList.size() ) m_nextHitIndex = 0;
107 void ThreadListView::searchAll( const QStringList &query )
112 QListViewItemIterator listIt( subjectList );
113 while ( listIt.current() != 0 ) {
114 KListViewItem * item = static_cast<KListViewItem*>( listIt.current() );
115 item->setPixmap( Col_Icon, 0 );
117 QStringList::const_iterator queryIt = query.begin();
118 for ( ; queryIt != query.end(); ++queryIt ) {
119 if ( item->text( Col_Subject ).contains( *queryIt, false ) ) {
120 item->setPixmap( Col_Icon, SmallIcon( "find" ) );
121 m_hitList.append( item );
129 void ThreadListView::slotHideButton( bool on )
131 if ( m_hitList.empty() ) return ;
133 QListViewItemIterator listIt( subjectList );
134 while ( listIt.current() != 0 ) {
135 KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
136 if ( on && ! item->pixmap( Col_Icon ) ) {
137 item->setVisible( false );
139 item->setVisible( true );
145 int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
151 return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
153 return QString::localeAwareCompare( i->key( Col_MarkOrder, ascending ), key( Col_MarkOrder, ascending ) );
155 return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
159 #include "threadlistview.moc"