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 struct Col_Attr ThreadListView::s_colAttr[] = {
30 // labelName, itemName, keyName, showDefault
31 {"", "Mark", "Col_Mark", true },
32 {"No.", "ID", "Col_ID", true},
33 {"", "Icon", "Col_Icon", true},
34 {"Title", "Subject", "Col_Subject", true},
35 {"ResNum", "ResNum", "Col_ResNum", true},
36 {"ReadNum", "Read", "Col_Read", true},
37 {"ViewPos", "ViewPos", "Col_ViewPos", true},
38 {"Unread", "Unread", "Col_Unread", true},
39 {"Since", "Since", "Col_Since", true},
40 {"Thread's speed", "Speed", "Col_Speed", true},
41 {"Board", "Board", "Col_Board", false},
42 {"Dat URL", "DatURL", "Col_DatURL", false},
43 {"Mark Order", "MarkOrder", "Col_MarkOrder", false},
44 {"ID Order", "IDOrder", "Col_IDOrder", false}
47 ThreadListView::ThreadListView( QWidget* parent, const char* name )
48 : ThreadListViewBase( parent, name )
50 SearchButton->setPixmap( SmallIcon( "find" ) );
51 HideButton->setPixmap( SmallIcon( "filter" ) );
52 ReloadButton->setPixmap( SmallIcon( "reload" ) );
53 closeButton->setPixmap( SmallIcon( "fileclose" ) );
55 QHeader* header = subjectList->header();
56 for( int i = Col_Begin; i <= Col_End; i++ ) {
57 subjectList->addColumn( i18n( s_colAttr[i].labelName ) );
59 if ( s_colAttr[i].showDefault != true ) {
60 subjectList->setColumnWidthMode( i, QListView::Manual );
61 header->setResizeEnabled( false, i );
62 subjectList->setColumnWidth( i, 0 );
65 header->setStretchEnabled( true, Col_Subject );
67 connect( SearchButton, SIGNAL( clicked() ),
68 SLOT( slotSearchButton() ) );
69 connect( SearchCombo, SIGNAL( activated( int ) ),
70 SLOT( slotSearchButton() ) );
71 connect( HideButton, SIGNAL( toggled( bool ) ),
72 SLOT( slotHideButton( bool ) ) );
73 connect( subjectList, SIGNAL( mouseButtonClicked( int, QListViewItem*, const QPoint&, int ) ),
74 SLOT( slotMouseButtonClicked( int, QListViewItem* ) ) );
75 connect( this, SIGNAL( bookmarked( const QString&, bool ) ),
76 Kita::SignalCollection::getInstance(), SIGNAL( bookmarked( const QString&, bool ) ) );
77 connect( this, SIGNAL( openURLRequestExt(
78 const KURL&, const KParts::URLArgs&, QString, int, int,
79 const KURL&, const KURL&, const QString&, const QString& ) ),
80 Kita::SignalCollection::getInstance(), SIGNAL( openURLRequestExt(
81 const KURL& , const KParts::URLArgs&, QString, int, int,
82 const KURL&, const KURL&, const QString&, const QString& ) ) );
85 ThreadListView::~ThreadListView()
88 void ThreadListView::slotSearchButton()
91 QStringList list = parseSearchQuery( SearchCombo->currentText() );
95 void ThreadListView::insertSearchCombo()
97 for ( int count = 0; count < SearchCombo->count(); ++count ) {
98 if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
102 SearchCombo->insertItem( SearchCombo->currentText() );
105 QStringList ThreadListView::parseSearchQuery( const QString &input )
107 QStringList tmp = QStringList::split( ' ', input );
108 QStringList ret_list;
109 QRegExp truncSpace( "\\s*$" );
110 QStringList::iterator it = tmp.begin();
112 for ( ; it != tmp.end(); ++it ) {
113 ret_list += ( *it ).replace( truncSpace, "" );
118 void ThreadListView::searchNext( const QStringList &query )
120 if ( query.isEmpty() ) return ;
122 if ( query != m_prevquery ) {
124 slotHideButton( HideButton->isOn() );
125 m_nextHitIndex = 0; //A next jump-search target reset to '0'.
129 if ( m_nextHitIndex >= m_hitList.size() ) {
133 KListViewItem* item = m_hitList[ m_nextHitIndex ];
134 subjectList->ensureItemVisible( item );
135 subjectList->setSelected( item, true );
137 if ( m_nextHitIndex >= m_hitList.size() ) m_nextHitIndex = 0;
140 void ThreadListView::searchAll( const QStringList &query )
145 QListViewItemIterator listIt( subjectList );
146 while ( listIt.current() != 0 ) {
147 KListViewItem * item = static_cast<KListViewItem*>( listIt.current() );
148 item->setPixmap( Col_Icon, 0 );
150 QStringList::const_iterator queryIt = query.begin();
151 for ( ; queryIt != query.end(); ++queryIt ) {
152 if ( item->text( Col_Subject ).contains( *queryIt, false ) ) {
153 item->setPixmap( Col_Icon, SmallIcon( "find" ) );
154 m_hitList.append( item );
162 void ThreadListView::slotHideButton( bool on )
164 if ( m_hitList.empty() ) return ;
166 QListViewItemIterator listIt( subjectList );
167 while ( listIt.current() != 0 ) {
168 KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
169 if ( on && ! item->pixmap( Col_Icon ) ) {
170 item->setVisible( false );
172 item->setVisible( true );
178 void ThreadListView::slotMouseButtonClicked( int button, QListViewItem* item )
180 if ( ! item ) return ;
182 KURL datURL = item->text( Col_DatURL );
186 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 1 );
189 if ( KitaConfig::alwaysUseTab() ) {
190 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 1 );
192 emit openURLRequestExt( datURL.prettyURL(), KParts::URLArgs(), "kita_open_2chthread", 0 );
198 int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
204 return i->key( col, ascending ).toInt() - key( col, ascending ).toInt();
206 return key( Col_IDOrder, ascending ).toInt() - i->key( Col_IDOrder, ascending ).toInt();
208 return QString::localeAwareCompare( i->key( Col_MarkOrder, ascending ), key( Col_MarkOrder, ascending ) );
210 return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
212 return static_cast<int>( i->key( col, ascending ).toDouble() * 1000 - key( col, ascending ).toDouble() * 1000 );
214 return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
218 #include "threadlistview.moc"