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 "favoritelistview.h"
13 #include "libkita/favoritethreads.h"
14 #include "libkita/kita_misc.h"
15 #include "libkita/threadinfo.h"
16 #include "libkita/signalcollection.h"
19 #include <qapplication.h>
20 #include <qclipboard.h>
21 #include <qdatetime.h>
22 #include <qtoolbutton.h>
26 #include <kpopupmenu.h>
29 #include <klistview.h>
31 FavoriteListView::FavoriteListView( QWidget* parent, const char* name )
32 : Kita::ThreadListView( parent, name )
34 subjectList->addColumn( i18n( "Board" ) );
38 Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
39 connect( subjectList, SIGNAL( returnPressed( QListViewItem* ) ),
40 SLOT( loadThread( QListViewItem* ) ) );
41 connect( subjectList, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
42 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
43 connect( ReloadButton, SIGNAL( clicked() ),
44 SLOT( slotReloadButton() ) );
45 connect( this, SIGNAL( openBoardRequested( const QString&, bool ) ),
46 signalCollection, SIGNAL( openBoardRequested( const QString&, bool ) ) );
49 FavoriteListView::~FavoriteListView()
52 void FavoriteListView::update()
54 // FIXME: KitaSubjectView::loadBoard()¤Ë¥³¥Ô¡¼
61 const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
65 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
67 QValueList<QString>::const_iterator it;
68 for ( it = threadList.begin(); it != threadList.end(); ++it ) {
69 const Kita::Thread* thread = Kita::Thread::getByURL( *it );
72 since.setTime_t( KURL( thread->datURL() ).fileName().section( '.', 0, 0 ).toInt() );
74 int readNum = cache->readNum( thread->datURL() );
75 int resNum = KitaThreadInfo::resNum( thread->datURL() );
77 KListViewItem* item = new KListViewItem( subjectList );
78 item->setText( Col_Board, thread->boardName() );
79 item->setText( Col_Subject, Kita::unescape( thread->name() ) );
80 item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
82 item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
83 if ( resNum != readNum ) {
84 item->setText( Col_Unread, QString( "%1" ).arg( resNum - readNum, 4 ) );
87 item->setText( Col_Since, since.toString( "yy/MM/dd hh:mm" ) );
88 item->setText( Col_DatURL, thread->datURL() );
92 void FavoriteListView::loadThread( QListViewItem* item )
94 if ( ! item ) return ;
96 const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
98 QValueList<QString>::const_iterator it;
99 for ( it = threadList.begin(); it != threadList.end(); ++it ) {
100 const Kita::Thread* thread = Kita::Thread::getByURL( *it );
102 if ( thread->datURL() == item->text( Col_DatURL ) ) {
103 emit showThreadRequested( thread->datURL(), false );
108 void FavoriteListView::updateThread( const Kita::Thread* updated_thread )
110 for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
111 if ( item->text( Col_DatURL ) == updated_thread->datURL() ) {
112 int resNum = updated_thread->resNum();
113 int readNum = KitaThreadInfo::readNum( updated_thread->datURL() );
114 item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
115 item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
120 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
121 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
127 KPopupMenu popup( 0 );
128 popup.insertItem( i18n( "Open with Web Browser" ), 0 );
129 popup.insertItem( i18n( "Open with new tab" ), 1 );
130 popup.insertItem( i18n( "Copy title and URL" ), 2 );
131 popup.insertItem( i18n( "Remove from Favorites" ), 3 );
133 Kita::Thread* thread = Kita::Thread::getByURL( item->text( Col_DatURL ) );
135 QClipboard* clipboard = QApplication::clipboard();
137 switch ( popup.exec( point ) ) {
139 KRun::runURL( thread->url(), "text/html" );
142 emit showThreadRequested( thread->datURL(), true );
145 clipboard->setText( thread->name() + "\n" + thread->url() );
148 emit bookmarked( thread->datURL(), false );
155 void FavoriteListView::slotReloadButton()
157 QValueList<QString> boardList;
159 const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
160 QValueList<QString>::const_iterator it;
161 for ( it = threadList.begin(); it != threadList.end(); ++it ) {
162 const Kita::Thread* thread = Kita::Thread::getByURL( *it );
163 QString boardURL = Kita::datToBoard( thread->datURL() );
164 if ( boardList.contains( boardURL ) == 0 ) {
165 boardList.append( boardURL );
169 QValueList<QString>::const_iterator it2;
170 for ( it2 = boardList.begin(); it2 != boardList.end(); ++it2 ) {
171 emit openBoardRequested( (*it2), true );