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"
25 #include "libkita/signalcollection.h"
29 ThreadListView::ThreadListView( QWidget* parent, const char* name )
30 : ThreadListViewBase( parent, name )
32 SearchButton->setPixmap( SmallIcon( "find" ) );
33 HideButton->setPixmap( SmallIcon( "filter" ) );
34 ReloadButton->setPixmap( SmallIcon( "reload" ) );
35 closeButton->setPixmap( SmallIcon( "fileclose" ) );
37 subjectList->addColumn( "" );
38 subjectList->addColumn( i18n( "No." ) );
39 subjectList->addColumn( "" );
40 subjectList->addColumn( i18n( "Title" ) );
41 subjectList->addColumn( i18n( "ResNum" ) );
42 subjectList->addColumn( i18n( "ReadNum" ) );
43 subjectList->addColumn( i18n( "Unread" ) );
44 subjectList->addColumn( i18n( "Since" ) );
45 subjectList->addColumn( i18n( "Thread's speed" ) );
47 QHeader *h = subjectList->header();
48 h->setResizeEnabled( FALSE, Col_Mark );
49 h->setResizeEnabled( FALSE, Col_Icon );
50 h->setStretchEnabled( TRUE, Col_Subject );
52 //subjectList->setColumnWidth( Col_Subject, 400 );
53 subjectList->setColumnWidthMode( Col_Subject, QListView::Manual );
55 connect( SearchButton, SIGNAL( clicked() ),
56 SLOT( slotSearchButton() ) );
57 connect( SearchCombo, SIGNAL( activated( int ) ),
58 SLOT( slotSearchButton() ) );
59 connect( HideButton, SIGNAL( toggled( bool ) ),
60 SLOT( slotHideButton( bool ) ) );
61 connect( subjectList, SIGNAL( mouseButtonClicked( int, QListViewItem*, const QPoint&, int ) ),
62 SLOT( slotMouseButtonClicked( int, QListViewItem* ) ) );
63 connect( this, SIGNAL( bookmarked( const QString&, bool ) ),
64 Kita::SignalCollection::getInstance(), SIGNAL( bookmarked( const QString&, bool ) ) );
65 connect( this, SIGNAL( openURLRequestExt(
66 const KURL&, const KParts::URLArgs&, QString, int, int,
67 const KURL&, const KURL&, const QString&, const QString& ) ),
68 Kita::SignalCollection::getInstance(), SIGNAL( openURLRequestExt(
69 const KURL& , const KParts::URLArgs&, QString, int, int,
70 const KURL&, const KURL&, const QString&, const QString& ) ) );
73 ThreadListView::~ThreadListView()
76 void ThreadListView::slotSearchButton()
79 QStringList list = parseSearchQuery( SearchCombo->currentText() );
83 void ThreadListView::insertSearchCombo()
85 for ( int count = 0; count < SearchCombo->count(); ++count ) {
86 if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
90 SearchCombo->insertItem( SearchCombo->currentText() );
93 QStringList ThreadListView::parseSearchQuery( const QString &input )
95 QStringList tmp = QStringList::split( ' ', input );
97 QRegExp truncSpace( "\\s*$" );
98 QStringList::iterator it = tmp.begin();
100 for ( ; it != tmp.end(); ++it ) {
101 ret_list += ( *it ).replace( truncSpace, "" );
106 void ThreadListView::searchNext( const QStringList &query )
108 if ( query.isEmpty() ) return ;
110 if ( query != m_prevquery ) {
112 slotHideButton( HideButton->isOn() );
113 m_nextHitIndex = 0; //A next jump-search target reset to '0'.
117 if ( m_nextHitIndex >= m_hitList.size() ) {
121 KListViewItem* item = m_hitList[ m_nextHitIndex ];
122 subjectList->ensureItemVisible( item );
123 subjectList->setSelected( item, true );
125 if ( m_nextHitIndex >= m_hitList.size() ) m_nextHitIndex = 0;
128 void ThreadListView::searchAll( const QStringList &query )
133 QListViewItemIterator listIt( subjectList );
134 while ( listIt.current() != 0 ) {
135 KListViewItem * item = static_cast<KListViewItem*>( listIt.current() );
136 item->setPixmap( Col_Icon, 0 );
138 QStringList::const_iterator queryIt = query.begin();
139 for ( ; queryIt != query.end(); ++queryIt ) {
140 if ( item->text( Col_Subject ).contains( *queryIt, false ) ) {
141 item->setPixmap( Col_Icon, SmallIcon( "find" ) );
142 m_hitList.append( item );
150 void ThreadListView::slotHideButton( bool on )
152 if ( m_hitList.empty() ) return ;
154 QListViewItemIterator listIt( subjectList );
155 while ( listIt.current() != 0 ) {
156 KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
157 if ( on && ! item->pixmap( Col_Icon ) ) {
158 item->setVisible( false );
160 item->setVisible( true );
166 void ThreadListView::slotMouseButtonClicked( int button, QListViewItem* item )
168 if ( ! item ) return ;
170 KURL datURL = item->text( Col_DatURL );
174 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 1 );
177 if ( KitaConfig::alwaysUseTab() ) {
178 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 1 );
180 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 0 );
186 int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
192 return i->key( col, ascending ).toInt() - key( col, ascending ).toInt();
194 return key( col, ascending ).toInt() - i->key( col, ascending ).toInt();
196 return QString::localeAwareCompare( i->key( Col_MarkOrder, ascending ), key( Col_MarkOrder, ascending ) );
198 return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
200 return static_cast<int>( i->key( col, ascending ).toDouble() * 1000 - key( col, ascending ).toDouble() * 1000 );
202 return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
206 #include "threadlistview.moc"