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/board.h"
15 #include "libkita/kita_misc.h"
16 #include "libkita/threadinfo.h"
18 #include <qtoolbutton.h>
20 #include <qapplication.h>
21 #include <qclipboard.h>
24 #include <kiconloader.h>
25 #include <kpopupmenu.h>
28 #include <klistview.h>
30 enum FavoriteListViewRows {
41 FavoriteListView::FavoriteListView(QWidget* parent, const char *name)
42 : KitaSubjectViewBase(parent, name)
45 SearchButton->setPixmap( SmallIcon("find") );
46 HideButton->setPixmap( SmallIcon("filter") );
49 subjectList->addColumn( i18n( "Board" ) );
50 subjectList->addColumn( "" );
51 subjectList->addColumn( i18n( "Title" ) );
52 subjectList->addColumn( i18n( "ResNum" ) );
53 subjectList->addColumn( i18n( "ReadNum" ) );
54 subjectList->addColumn( i18n( "Unread" ) );
55 subjectList->addColumn( i18n( "Dat" ) );
57 subjectList->setColumnWidth(Row_Subject, 400);
58 subjectList->setColumnWidthMode(Row_Subject, QListView::Manual);
60 connect( subjectList, SIGNAL( clicked( QListViewItem* ) ),
61 SLOT( loadThread( QListViewItem* ) ) );
62 connect( subjectList, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
63 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
66 FavoriteListView::~FavoriteListView()
70 void FavoriteListView::update()
72 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
73 // FavoriteThreads::const_iterator it;
77 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
79 QDictIterator<Kita::Thread> it( threads );
80 for(; it.current(); ++it) {
81 const Kita::Thread* thread = it.current();
83 int readNum = cache->readNum( thread->datURL() );
84 int resNum = cache->resNum( thread->datURL() ); // TODO unused variables.
86 KListViewItem* item = new KListViewItem( subjectList );
87 item->setText( Row_Board, thread->boardName() );
88 item->setText( Row_Subject, thread->name() );
89 item->setText( Row_Read, QString("%1").arg( readNum, 4 ) );
90 item->setText( Row_DatName, KURL( thread->datURL() ).fileName() );
91 item->setText( Row_DatURL, thread->datURL() );
95 void FavoriteListView::loadThread( QListViewItem* item )
99 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
100 // FavoriteThreads::const_iterator it;
102 QDictIterator<Kita::Thread> it( threads );
103 for(; it.current(); ++it) {
104 const Kita::Thread* thread = it.current();
106 if( thread->datURL() == item->text( Row_DatURL ) ) {
107 emit signalShowThread( *thread );
112 void FavoriteListView::updateThread( const Kita::Thread& updated_thread )
114 for( QListViewItem* item = subjectList->firstChild(); item; item = item->nextSibling() ) {
115 if( item->text( Row_DatURL ) == updated_thread.datURL() ) {
116 item->setText( Row_ResNum, QString("%1").arg( updated_thread.resNum(), 4 ) );
121 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
122 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
128 KPopupMenu popup( 0 );
129 popup.insertItem( i18n("Open with Web Browser"), 0 );
130 popup.insertItem( i18n("Open with new tab"), 1 );
131 popup.insertItem( i18n("Copy title and URL"), 2 );
133 QString datName = item->text(Row_DatName);
134 KURL datURL = KURL( item->text(Row_DatURL) );
136 Kita::Thread thread( datURL.url() );
137 thread.setName( item->text( Row_Subject ) );
138 thread.setResNum( item->text( Row_Read ).toInt() );
140 QClipboard* clipboard = QApplication::clipboard();
142 switch( popup.exec( point ) ) {
144 KRun::runURL( thread.url(), "text/html" );
147 emit signalShowThreadWithNewTab( thread );
150 clipboard->setText( thread.name() + "\n" + thread.url() );