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"
19 #include <qapplication.h>
20 #include <qclipboard.h>
23 #include <kpopupmenu.h>
26 #include <klistview.h>
28 FavoriteListView::FavoriteListView(QWidget* parent, const char *name)
29 : Kita::ThreadListView(parent, name)
31 connect( subjectList, SIGNAL( clicked( QListViewItem* ) ),
32 SLOT( loadThread( QListViewItem* ) ) );
33 connect( subjectList, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
34 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
37 FavoriteListView::~FavoriteListView()
41 void FavoriteListView::update()
43 // FIXME: KitaSubjectView::loadBoard()¤Ë¥³¥Ô¡¼
50 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
51 // FavoriteThreads::const_iterator it;
55 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
57 QDictIterator<Kita::Thread> it( threads );
58 for(; it.current(); ++it) {
59 const Kita::Thread* thread = it.current();
61 int readNum = cache->readNum( thread->datURL() );
62 int resNum = cache->resNum( thread->datURL() ); // TODO unused variables.
64 KListViewItem* item = new KListViewItem( subjectList );
65 item->setText( Row_Board, thread->boardName() );
66 item->setText( Row_Subject, thread->name() );
67 item->setText( Row_Read, QString("%1").arg( readNum, 4 ) );
68 item->setText( Row_DatName, KURL( thread->datURL() ).fileName() );
69 item->setText( Row_DatURL, thread->datURL() );
73 void FavoriteListView::loadThread( QListViewItem* item )
77 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
78 // FavoriteThreads::const_iterator it;
80 QDictIterator<Kita::Thread> it( threads );
81 for(; it.current(); ++it) {
82 const Kita::Thread* thread = it.current();
84 if( thread->datURL() == item->text( Row_DatURL ) ) {
85 emit signalShowThread( *thread );
90 void FavoriteListView::updateThread( const Kita::Thread& updated_thread )
92 for( QListViewItem* item = subjectList->firstChild(); item; item = item->nextSibling() ) {
93 if( item->text( Row_DatURL ) == updated_thread.datURL() ) {
94 item->setText( Row_ResNum, QString("%1").arg( updated_thread.resNum(), 4 ) );
99 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
100 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
106 KPopupMenu popup( 0 );
107 popup.insertItem( i18n("Open with Web Browser"), 0 );
108 popup.insertItem( i18n("Open with new tab"), 1 );
109 popup.insertItem( i18n("Copy title and URL"), 2 );
111 QString datName = item->text(Row_DatName);
112 KURL datURL = KURL( item->text(Row_DatURL) );
114 Kita::Thread thread( datURL.url() );
115 thread.setName( item->text( Row_Subject ) );
116 thread.setResNum( item->text( Row_Read ).toInt() );
118 QClipboard* clipboard = QApplication::clipboard();
120 switch( popup.exec( point ) ) {
122 KRun::runURL( thread.url(), "text/html" );
125 emit signalShowThreadWithNewTab( thread );
128 clipboard->setText( thread.name() + "\n" + thread.url() );