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>
18 #include <qtoolbutton.h>
19 #include <qcombobox.h>
23 #include "libkita/thread.h"
24 #include "libkita/kitaconfig.h"
28 ThreadListView::ThreadListView( QWidget* parent, const char* name )
29 : ThreadListViewBase( parent, name )
31 SearchButton->setPixmap( SmallIcon( "find" ) );
32 HideButton->setPixmap( SmallIcon( "filter" ) );
33 ReloadButton->setPixmap( SmallIcon( "reload" ) );
35 subjectList->addColumn( "" );
36 subjectList->addColumn( i18n( "No." ) );
37 subjectList->addColumn( "" );
38 subjectList->addColumn( i18n( "Title" ) );
39 subjectList->addColumn( i18n( "ResNum" ) );
40 subjectList->addColumn( i18n( "ReadNum" ) );
41 subjectList->addColumn( i18n( "Unread" ) );
42 subjectList->addColumn( i18n( "Since" ) );
44 QHeader *h = subjectList->header();
45 h->setResizeEnabled( FALSE, Col_Mark );
46 h->setResizeEnabled( FALSE, Col_Icon );
47 h->setStretchEnabled( TRUE, Col_Subject );
49 //subjectList->setColumnWidth( Col_Subject, 400 );
50 subjectList->setColumnWidthMode( Col_Subject, QListView::Manual );
52 connect( SearchButton, SIGNAL( clicked() ),
53 SLOT( slotSearchButton() ) );
54 connect( SearchCombo, SIGNAL( activated( int ) ),
55 SLOT( slotSearchButton() ) );
56 connect( HideButton, SIGNAL( toggled( bool ) ),
57 SLOT( slotHideButton( bool ) ) );
58 connect( subjectList, SIGNAL( mouseButtonClicked( int, QListViewItem*, const QPoint&, int ) ),
59 SLOT( slotMouseButtonClicked( int, QListViewItem* ) ) );
60 connect( this, SIGNAL( bookmarked( const QString&, bool ) ),
61 Kita::SignalCollection::getInstance(), SIGNAL( bookmarked( const QString&, bool ) ) );
64 ThreadListView::~ThreadListView()
67 void ThreadListView::slotSearchButton()
70 QStringList list = parseSearchQuery( SearchCombo->currentText() );
74 void ThreadListView::insertSearchCombo()
76 for ( int count = 0; count < SearchCombo->count(); ++count ) {
77 if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
81 SearchCombo->insertItem( SearchCombo->currentText() );
84 QStringList ThreadListView::parseSearchQuery( const QString &input )
86 QStringList tmp = QStringList::split( ' ', input );
88 QRegExp truncSpace( "\\s*$" );
89 QStringList::iterator it = tmp.begin();
91 for ( ; it != tmp.end(); ++it ) {
92 ret_list += ( *it ).replace( truncSpace, "" );
97 void ThreadListView::searchNext( const QStringList &query )
99 if ( query.isEmpty() ) return ;
101 if ( query != m_prevquery ) {
103 slotHideButton( HideButton->isOn() );
104 m_nextHitIndex = 0; //A next jump-search target reset to '0'.
108 if ( m_nextHitIndex >= m_hitList.size() ) {
112 KListViewItem* item = m_hitList[ m_nextHitIndex ];
113 subjectList->ensureItemVisible( item );
114 subjectList->setSelected( item, true );
116 if ( m_nextHitIndex >= m_hitList.size() ) m_nextHitIndex = 0;
119 void ThreadListView::searchAll( const QStringList &query )
124 QListViewItemIterator listIt( subjectList );
125 while ( listIt.current() != 0 ) {
126 KListViewItem * item = static_cast<KListViewItem*>( listIt.current() );
127 item->setPixmap( Col_Icon, 0 );
129 QStringList::const_iterator queryIt = query.begin();
130 for ( ; queryIt != query.end(); ++queryIt ) {
131 if ( item->text( Col_Subject ).contains( *queryIt, false ) ) {
132 item->setPixmap( Col_Icon, SmallIcon( "find" ) );
133 m_hitList.append( item );
141 void ThreadListView::slotHideButton( bool on )
143 if ( m_hitList.empty() ) return ;
145 QListViewItemIterator listIt( subjectList );
146 while ( listIt.current() != 0 ) {
147 KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
148 if ( on && ! item->pixmap( Col_Icon ) ) {
149 item->setVisible( false );
151 item->setVisible( true );
157 void ThreadListView::slotMouseButtonClicked( int button, QListViewItem* item )
159 if ( ! item ) return ;
161 KURL datURL = item->text( Col_DatURL );
163 Kita::Thread* thread = Kita::Thread::getByURL( datURL.url() );
167 emit showThreadRequested( thread->datURL(), true );
170 if ( KitaConfig::alwaysUseTab() ) {
171 emit showThreadRequested( thread->datURL(), true );
173 emit showThreadRequested( thread->datURL(), false );
179 int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
185 return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
187 return QString::localeAwareCompare( i->key( Col_MarkOrder, ascending ), key( Col_MarkOrder, ascending ) );
189 return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
193 #include "threadlistview.moc"