#include "threadlistview.h"
+#include "viewmediator.h"
+
#include <kiconloader.h>
#include <klistview.h>
#include <klocale.h>
#include "libkita/thread.h"
#include "libkita/kitaconfig.h"
#include "libkita/signalcollection.h"
+#include "libkita/config_xt.h"
+#include "libkita/kita_misc.h"
+
+#include "threadlistviewitem.h"
using namespace Kita;
+struct Col_Attr ThreadListView::s_colAttr[] =
+ {
+ // labelName, itemName, keyName, showDefault
+ { I18N_NOOP( " " ), I18N_NOOP( "Mark" ), "Col_Mark", true },
+ { I18N_NOOP( "No." ), I18N_NOOP( "ID" ), "Col_ID", true },
+ { I18N_NOOP( " " ), I18N_NOOP( "Icon" ), "Col_Icon", true },
+ { I18N_NOOP( "Title" ), I18N_NOOP( "Subject" ), "Col_Subject", true },
+ { I18N_NOOP( "ResNum" ), I18N_NOOP( "ResNum" ), "Col_ResNum", true },
+ { I18N_NOOP( "ReadNum" ), I18N_NOOP( "ReadNum" ), "Col_ReadNum", true },
+ { I18N_NOOP( "ViewPos" ), I18N_NOOP( "ViewPos" ), "Col_ViewPos", false },
+ { I18N_NOOP( "Unread" ), I18N_NOOP( "Unread" ), "Col_Unread", true },
+ { I18N_NOOP( "Since" ), I18N_NOOP( "Since" ), "Col_Since", true },
+ { I18N_NOOP( "Thread's speed" ), I18N_NOOP( "Speed" ), "Col_Speed", true },
+ { I18N_NOOP( "Board" ), I18N_NOOP( "Board" ), "Col_Board", false },
+ { I18N_NOOP( "Dat URL" ), I18N_NOOP( "DatURL" ), "Col_DatURL", false },
+ { I18N_NOOP( "Mark Order" ), I18N_NOOP( "MarkOrder" ), "Col_MarkOrder", false },
+ { I18N_NOOP( "ID Order" ), I18N_NOOP( "IDOrder" ), "Col_IDOrder", false }
+ };
+
ThreadListView::ThreadListView( QWidget* parent, const char* name )
: ThreadListViewBase( parent, name )
{
- SearchButton->setPixmap( SmallIcon( "find" ) );
HideButton->setPixmap( SmallIcon( "filter" ) );
ReloadButton->setPixmap( SmallIcon( "reload" ) );
+ closeButton->setPixmap( SmallIcon( "fileclose" ) );
- subjectList->addColumn( "" );
- subjectList->addColumn( i18n( "No." ) );
- subjectList->addColumn( "" );
- subjectList->addColumn( i18n( "Title" ) );
- subjectList->addColumn( i18n( "ResNum" ) );
- subjectList->addColumn( i18n( "ReadNum" ) );
- subjectList->addColumn( i18n( "Unread" ) );
- subjectList->addColumn( i18n( "Since" ) );
+ QHeader* header = subjectList->header();
+ for ( int i = Col_Begin; i <= Col_End; i++ ) {
+ subjectList->addColumn( i18n( s_colAttr[ i ].labelName ) );
- QHeader *h = subjectList->header();
- h->setResizeEnabled( FALSE, Col_Mark );
- h->setResizeEnabled( FALSE, Col_Icon );
- h->setStretchEnabled( TRUE, Col_Subject );
-
- //subjectList->setColumnWidth( Col_Subject, 400 );
- subjectList->setColumnWidthMode( Col_Subject, QListView::Manual );
+ if ( s_colAttr[ i ].showDefault != true ) {
+ hideColumn( i );
+ }
+ }
+ header->setStretchEnabled( true, Col_Subject );
- connect( SearchButton, SIGNAL( clicked() ),
- SLOT( slotSearchButton() ) );
connect( SearchCombo, SIGNAL( activated( int ) ),
SLOT( slotSearchButton() ) );
+ connect( SearchCombo, SIGNAL( textChanged( const QString& ) ),
+ SLOT( slotSearchButton() ) );
connect( HideButton, SIGNAL( toggled( bool ) ),
SLOT( slotHideButton( bool ) ) );
connect( subjectList, SIGNAL( mouseButtonClicked( int, QListViewItem*, const QPoint&, int ) ),
SLOT( slotMouseButtonClicked( int, QListViewItem* ) ) );
- connect( this, SIGNAL( bookmarked( const QString&, bool ) ),
- Kita::SignalCollection::getInstance(), SIGNAL( bookmarked( const QString&, bool ) ) );
}
ThreadListView::~ThreadListView()
void ThreadListView::slotSearchButton()
{
insertSearchCombo();
- QStringList list = parseSearchQuery( SearchCombo->currentText() );
- searchNext( list );
+ QStringList list = Kita::parseSearchQuery( SearchCombo->currentText() );
+
+ if ( list.isEmpty() ) {
+ clearSearch();
+ } else if ( list != m_prevquery ) {
+ searchNew( list );
+ HideButton->setOn( true );
+ } else {
+ searchNext( list );
+ }
}
void ThreadListView::insertSearchCombo()
{
for ( int count = 0; count < SearchCombo->count(); ++count ) {
if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
- return ;
+ return;
}
}
SearchCombo->insertItem( SearchCombo->currentText() );
}
-QStringList ThreadListView::parseSearchQuery( const QString &input )
-{
- QStringList tmp = QStringList::split( ' ', input );
- QStringList ret_list;
- QRegExp truncSpace( "\\s*$" );
- QStringList::iterator it = tmp.begin();
-
- for ( ; it != tmp.end(); ++it ) {
- ret_list += ( *it ).replace( truncSpace, "" );
- }
- return ret_list;
-}
-
void ThreadListView::searchNext( const QStringList &query )
{
- if ( query.isEmpty() ) return ;
-
- if ( query != m_prevquery ) {
- searchAll( query );
- slotHideButton( HideButton->isOn() );
- m_nextHitIndex = 0; //A next jump-search target reset to '0'.
- return ;
- }
-
- if ( m_nextHitIndex >= m_hitList.size() ) {
- return ;
- }
+ Q_ASSERT( query == m_prevquery );
+ Q_ASSERT( m_nextHitIndex < m_hitList.size() );
KListViewItem* item = m_hitList[ m_nextHitIndex ];
subjectList->ensureItemVisible( item );
subjectList->setSelected( item, true );
+
m_nextHitIndex++;
if ( m_nextHitIndex >= m_hitList.size() ) m_nextHitIndex = 0;
}
-void ThreadListView::searchAll( const QStringList &query )
+void ThreadListView::searchNew( const QStringList &query )
{
m_hitList.clear();
+ m_nextHitIndex = 0;
m_prevquery = query;
QListViewItemIterator listIt( subjectList );
}
}
-void ThreadListView::slotHideButton( bool on )
+void ThreadListView::clearSearch()
{
- if ( m_hitList.empty() ) return ;
+ QListViewItemIterator listIt( subjectList );
+ while ( listIt.current() != 0 ) {
+ KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
+ item->setPixmap( Col_Icon, 0 );
+ item->setVisible( true );
+ ++listIt;
+ }
+}
+void ThreadListView::slotHideButton( bool on )
+{
QListViewItemIterator listIt( subjectList );
while ( listIt.current() != 0 ) {
KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
KURL datURL = item->text( Col_DatURL );
- Kita::Thread* thread = Kita::Thread::getByURL( datURL.url() );
-
- switch ( button ) {
- case MidButton:
- emit showThreadRequested( thread->datURL(), true );
- break;
- case LeftButton:
- if ( KitaConfig::alwaysUseTab() ) {
- emit showThreadRequested( thread->datURL(), true );
- } else {
- emit showThreadRequested( thread->datURL(), false );
- }
- break;
+ if ( button == LeftButton ) {
+ ViewMediator::getInstance()->openThread( datURL );
}
}
-int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
+void ThreadListView::hideColumn( int col )
{
- switch ( col ) {
- case Col_ResNum:
- case Col_Read:
- case Col_Unread:
- return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
- case Col_Mark:
- return QString::localeAwareCompare( i->key( Col_MarkOrder, ascending ), key( Col_MarkOrder, ascending ) );
- default:
- return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
- }
+ QHeader* header = subjectList->header();
+ subjectList->setColumnWidthMode( col, QListView::Manual );
+ header->setResizeEnabled( false, col );
+ subjectList->setColumnWidth( col, 0 );
+}
+
+void ThreadListView::showColumn( int col )
+{
+ QHeader* header = subjectList->header();
+ subjectList->setColumnWidthMode( col, QListView::Maximum );
+ header->setResizeEnabled( true, col );
+ subjectList->adjustColumn( col );
}
#include "threadlistview.moc"