1 /***************************************************************************
2 * Copyright (C) 2003 by Hideki Ikemoto *
3 * ikemo@users.sourceforge.jp *
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 files for Qt
12 #include <qtoolbutton.h>
13 #include <qtextbrowser.h>
14 #include <qtextcodec.h>
19 #include <kio/slaveconfig.h>
20 #include <kio/netaccess.h>
22 // include files for KDE
23 #include <kfilterdev.h>
24 #include <klistview.h>
25 #include <kiconloader.h>
28 #include "kitasubjectview.h"
29 #include "favoritelistview.h"
31 #include "kitacacheinfo.h"
32 #include "part/kita2ch.h"
33 #include "libkita/thread.h"
35 enum SubjectViewRows {
46 KitaSubjectView::KitaSubjectView(QWidget *parent, const char *name)
47 : KitaSubjectViewBase(parent, name)
50 SearchButton->setPixmap( SmallIcon("find") );
51 HideButton->setPixmap( SmallIcon("filter") );
54 subjectList->addColumn(i18n("No."));
55 subjectList->addColumn("");
56 subjectList->addColumn(i18n("Title"));
57 subjectList->addColumn(i18n("ResNum"));
58 subjectList->addColumn(i18n("Vested"));
59 subjectList->addColumn(i18n("Unread"));
60 subjectList->addColumn(i18n("Dat"));
62 subjectList->setColumnWidth(Row_Subject, 400);
63 subjectList->setColumnWidthMode(Row_Subject, QListView::Manual);
65 connect(subjectList, SIGNAL(clicked(QListViewItem*)), SLOT(loadThread(QListViewItem*)));
66 connect( SearchButton, SIGNAL( clicked() ), SLOT( slotSearchButton() ) );
67 connect( SearchCombo, SIGNAL( activated(int) ), SLOT( slotSearchButton() ) );
68 connect(this, SIGNAL(signalSubjectListClicked(QListViewItem*)), subjectList, SIGNAL(clicked(QListViewItem*)));
69 connect( HideButton, SIGNAL( toggled(bool) ), SLOT( slotHideButton(bool) ) );
70 connect( m_subjectTab, SIGNAL( currentChanged(QWidget*) ), SLOT( slotCurrentChanged(QWidget*) ) );
73 KitaSubjectView::~KitaSubjectView()
77 void KitaSubjectView::reloadSubject()
81 void KitaSubjectView::loadThread(QListViewItem* item)
85 QString datName = item->text(Row_DatName);
86 KURL datURL = m_board.url();
87 datURL.addPath("/dat/" + datName);
88 emit signalShowThread(m_board, Kita::Thread(datURL));
91 void KitaSubjectView::loadBoard(const Kita::Board& board)
93 // reset member variables.
101 m_board.refreshChildList();
103 KitaCacheInfo* cache = KitaCacheInfo::getInstance();
104 m_threadList = m_board.getThreadList();
107 subjectList->clear();
109 for(unsigned i=0; i<m_threadList.count(); i++) {
110 Kita::Thread* thread = m_threadList.at(i);
112 int vested = cache->getVestedNum(thread->datURL());
113 new KListViewItem(subjectList,
114 QString("%1").arg(i+1, 4),
117 QString("%1").arg(thread->resNum(), 4),
118 (vested > 0) ? QString::number(vested) : QString(""),
119 (vested > 0 && thread->resNum() != vested) ? QString::number(thread->resNum() - vested) : QString(""),
120 thread->datURL().fileName(),
121 thread->datURL().prettyURL());
124 if( HideButton->isOn() ) {
125 HideButton->toggle();
127 emit loadBoardCompleted(m_board.url());
130 void KitaSubjectView::slotSearchButton()
133 QStringList list = parseSearchQuery( SearchCombo->currentText() );
137 void KitaSubjectView::insertSearchCombo()
142 for( count = 0; count < SearchCombo->count(); ++count ) {
143 if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
148 if ( ! found ) SearchCombo->insertItem( SearchCombo->currentText() );
151 QStringList KitaSubjectView::parseSearchQuery(const QString &input)
153 QStringList tmp = QStringList::split( ' ', input );
154 QStringList ret_list;
155 QRegExp truncSpace("\\s*$");
156 QStringList::iterator it = tmp.begin();
157 for( ; it != tmp.end(); ++it )
158 ret_list += (*it).replace( truncSpace, "" );
162 void KitaSubjectView::searchNext(const QStringList &query)
164 if ( query.isEmpty() ) return;
166 if ( query != m_prevquery ) {
168 slotHideButton( HideButton->isOn() );
169 m_nextHitIndex = 0; //A next jump-search target reset to '0'.
173 if(m_nextHitIndex >= m_hitList.size()) return;
175 KListViewItem* item = m_hitList[m_nextHitIndex];
176 subjectList->ensureItemVisible(item);
177 subjectList->setSelected(item, true);
179 if(m_nextHitIndex >= m_hitList.size()) m_nextHitIndex = 0;
182 void KitaSubjectView::searchAll(const QStringList &query)
187 QListViewItemIterator listIt( subjectList );
188 while( listIt.current() != 0 ) {
189 KListViewItem* item = static_cast<KListViewItem*>(listIt.current());
190 item->setPixmap(Row_Icon, 0);
192 QStringList::const_iterator queryIt = query.begin();
193 for( ; queryIt != query.end(); ++queryIt ) {
194 if( item->text(Row_Subject).contains(*queryIt) ) {
195 item->setPixmap(Row_Icon, SmallIcon("find") );
196 m_hitList.append(item);
204 void KitaSubjectView::slotHideButton(bool on)
206 if(m_hitList.empty()) return;
208 QListViewItemIterator listIt( subjectList );
209 while( listIt.current() != 0 ) {
210 KListViewItem* item = static_cast<KListViewItem*>(listIt.current());
211 if( on && ! item->pixmap(Row_Icon)) {
212 item->setVisible(false);
214 item->setVisible(true);
220 void KitaSubjectView::slotFontChanged(QFont& font)
222 subjectList->setFont(font);
225 void KitaSubjectView::updateThread(const Kita::Thread& updated_thread)
227 for(QListViewItem* item = subjectList->firstChild(); item; item = item->nextSibling() ) {
228 if( item->text(Row_DatURL) == updated_thread.datURL().prettyURL() ) {
229 int resNum = item->text( Row_ResNum ).toInt();
230 int vested = updated_thread.resNum();
231 item->setText( Row_Vested, QString::number( vested ) );
232 item->setText( Row_Unread, vested > 0 && resNum != vested ? QString::number(resNum - vested) : QString(""));
237 void KitaSubjectView::slotCurrentChanged(QWidget* widget)
239 if( QString::compare(widget->name(), "favoriteTab") == 0 ) {
240 m_favoriteListView->update();