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 "kitasubjectview.h"
13 // include files for Qt
14 #include <qtoolbutton.h>
15 #include <qtextbrowser.h>
16 #include <qtextcodec.h>
19 #include <qclipboard.h>
20 #include <qapplication.h>
21 #include <qdatetime.h>
25 #include <kio/slaveconfig.h>
26 #include <kio/netaccess.h>
28 // include files for KDE
30 #include <kfilterdev.h>
31 #include <klistview.h>
32 #include <kiconloader.h>
34 #include <kpopupmenu.h>
38 #include "libkita/threadinfo.h"
39 #include "libkita/thread.h"
40 #include "libkita/kita_misc.h"
41 #include "libkita/kitaconfig.h"
42 #include "libkita/favoritethreads.h"
43 #include "part/kita2ch.h"
45 KitaSubjectView::KitaSubjectView( QWidget* parent, const char* name )
46 : Kita::ThreadListView( parent, name )
47 , m_unreadNum( 0 ), m_readNum( 0 ), m_newNum( 0 )
49 connect( subjectList, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
50 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
51 connect( subjectList, SIGNAL( returnPressed( QListViewItem* ) ),
52 SLOT( loadThread( QListViewItem* ) ) );
53 connect( ReloadButton, SIGNAL( clicked() ),
54 SLOT( slotReloadButton() ) );
57 KitaSubjectView::~KitaSubjectView()
60 void KitaSubjectView::reloadSubject()
63 const QString KitaSubjectView::boardURL()
68 const QString KitaSubjectView::boardName()
70 return Kita::Board::getName( m_boardURL );
73 void KitaSubjectView::loadThread( QListViewItem* item )
75 if ( ! item ) return ;
77 KURL datURL = item->text( Col_DatURL );
79 Kita::Thread* thread = Kita::Thread::getByURL( datURL.url() );
81 if ( KitaConfig::alwaysUseTab() ) {
82 emit showThreadRequested( thread->datURL(), true );
84 emit showThreadRequested( thread->datURL(), false );
89 ts_readed : ´ûÆɤÇ1000Ķ¤¨¤Æ¤¤¤ë¤â¤Î
90 ts_normal : ̤¼èÆÀ¤Ç1Æü°Ê¾å·Ð¤Ã¤Æ¤¤¤ë¤â¤Î
91 ts_new : ̤¼èÆÀ¤Ç1Æü°ÊÆâ¤Î¤â¤Î
92 ts_read : ´ûÆɤÇ1000°Ê²¼¤Î¤â¤Î
93 ts_hasunread: ̤Æɤ¢¤ê
104 void KitaSubjectView::loadBoard( const QString& boardURL )
107 topLevelWidget() ->raise();
108 QDateTime currentdat = QDateTime::currentDateTime();
110 // reset member variables.
111 // FIXME: FavoriteListView::update()¤Ë¥³¥Ô¡¼
118 m_boardURL = boardURL;
123 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
124 QPtrList<Kita::Thread> threadList = Kita::Board::getThreadList( boardURL );
127 subjectList->clear();
129 for ( unsigned i = 0; i < threadList.count(); i++ ) {
130 Kita::Thread* thread = threadList.at( i );
133 since.setTime_t( KURL( thread->datURL() ).fileName().section( '.', 0, 0 ).toInt() );
135 int readNum = cache->readNum( thread->datURL() );
136 int resNum = thread->resNum();
138 Kita::ThreadListViewItem* item = new Kita::ThreadListViewItem( subjectList );
139 item->setText( Col_ID, QString( "%1" ).arg( i + 1, 4 ) );
140 item->setText( Col_Subject, Kita::unescape( thread->name() ) );
141 item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
142 item->setText( Col_Read, ( readNum > 0 ) ? QString( "%1" ).arg( readNum, 4 ) : QString( "" ) );
143 item->setText( Col_Unread, ( readNum > 0 && resNum != readNum ) ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
144 item->setText( Col_Board, thread->boardName() );
145 item->setText( Col_Since, since.toString( "yy/MM/dd hh:mm" ) );
146 item->setText( Col_DatURL, thread->datURL() );
148 // FIXME: updateThread¤Ë¥³¥Ô¡¼¤·¤Æ¤¤¤ë
149 // TODO: 'N'¤Î¥¢¥¤¥³¥ó¤òºîÀ®
150 if ( readNum > 0 && resNum != readNum ) {
152 item->setPixmap( Col_Mark, SmallIcon( "unread" ) );
154 item->setText( Col_MarkOrder, QString::number( ts_hasunread ) );
155 } else if ( readNum > 0 ) {
157 item->setPixmap( Col_Mark, SmallIcon( "read" ) );
159 //if( readNum > 1000) item->setText( Col_MarkOrder, "0" );
160 //else item->setText( Col_MarkOrder, "3" );
161 item->setText( Col_MarkOrder, QString::number( ( readNum > 1000 ) ? ts_readed : ts_read ) );
162 } else if ( since.secsTo( currentdat ) < 3600 * KitaConfig::MarkTime() ) {
163 item->setPixmap( Col_Mark, SmallIcon( "newthread" ) );
165 item->setText( Col_MarkOrder, QString::number( ts_new ) );
167 item->setText( Col_MarkOrder, QString::number( ts_normal ) );
171 if ( HideButton->isOn() ) {
172 HideButton->toggle();
174 emit loadBoardCompleted( boardURL );
176 switch ( KitaConfig::sortOrder() ) {
177 case KitaConfig::Order_Mark:
178 subjectList->setSorting( Col_Mark );
180 case KitaConfig::Order_ID:
181 subjectList->setSorting( Col_ID );
188 subjectList->setFocus();
192 void KitaSubjectView::UpdateKindLabel()
195 fmtstr += QString( "<font color=#C50000>%1</font>" ).arg( m_unreadNum );
196 fmtstr += QString( "/<font color=#00C200>%1</font>" ).arg( m_readNum );
197 fmtstr += QString( "/<font color=#5AAAFF>%1</font>" ).arg( m_newNum );
198 KindLabel->setText( fmtstr );
201 void KitaSubjectView::setFont( const QFont& font )
203 subjectList->setFont( font );
206 void KitaSubjectView::updateThread( const Kita::Thread* updated_thread )
208 for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
209 if ( item->text( Col_DatURL ) == updated_thread->datURL() ) {
210 int resNum = updated_thread->resNum();
211 int readNum = KitaThreadInfo::readNum( updated_thread->datURL() );
212 item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
213 item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
214 item->setText( Col_Unread, readNum > 0 && resNum != readNum ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
216 switch ( item->text( Col_MarkOrder ).toInt() ) {
218 case ts_read : m_readNum--; break;
219 case ts_new : m_newNum--; break;
220 case ts_hasunread : m_unreadNum--; break;
223 if ( readNum > 0 && resNum != readNum ) {
225 item->setPixmap( Col_Mark, SmallIcon( "unread" ) );
227 item->setText( Col_MarkOrder, QString::number( ts_hasunread ) );
228 } else if ( readNum > 0 ) {
230 item->setPixmap( Col_Mark, SmallIcon( "read" ) );
232 item->setText( Col_MarkOrder, QString::number( ts_read ) );
234 item->setText( Col_MarkOrder, QString::number( ts_normal ) );
241 void KitaSubjectView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
247 Kita::Thread* thread = Kita::Thread::getByURL( item->text( Col_DatURL ) );
248 bool isFavorites = FavoriteThreads::getInstance()->contains( thread->datURL() );
250 KPopupMenu popup( 0 );
251 popup.insertItem( i18n( "Open with Web Browser" ), 0 );
252 popup.insertItem( i18n( "Open with new tab" ), 1 );
253 popup.insertItem( i18n( "Copy title and URL" ), 2 );
255 popup.insertItem( i18n( "Remove from Favorites" ), 3 );
257 popup.insertItem( i18n( "Add to Favorites" ), 3 );
260 QClipboard* clipboard = QApplication::clipboard();
262 switch ( popup.exec( point ) ) {
264 KRun::runURL( thread->url(), "text/html" );
267 emit showThreadRequested( thread->datURL(), true );
270 clipboard->setText( thread->name() + "\n" + thread->url() );
274 emit bookmarked( thread->datURL(), false );
276 emit bookmarked( thread->datURL(), true );
283 void KitaSubjectView::slotReloadButton()
285 if ( ! m_boardURL.isEmpty() ) {
286 loadBoard( m_boardURL );