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()
40 void FavoriteListView::update()
42 // FIXME: KitaSubjectView::loadBoard()¤Ë¥³¥Ô¡¼
49 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance() ->threads();
50 // FavoriteThreads::const_iterator it;
54 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
56 QDictIterator<Kita::Thread> it( threads );
57 for ( ; it.current(); ++it ) {
58 const Kita::Thread* thread = it.current();
60 int readNum = cache->readNum( thread->datURL() );
61 int resNum = cache->resNum( thread->datURL() ); // TODO unused variables.
63 KListViewItem* item = new KListViewItem( subjectList );
64 item->setText( Row_Board, thread->boardName() );
65 item->setText( Row_Subject, thread->name() );
66 item->setText( Row_Read, QString( "%1" ).arg( readNum, 4 ) );
67 item->setText( Row_DatName, KURL( thread->datURL() ).fileName() );
68 item->setText( Row_DatURL, thread->datURL() );
72 void FavoriteListView::loadThread( QListViewItem* item )
74 if ( ! item ) return ;
76 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance() ->threads();
77 // FavoriteThreads::const_iterator it;
79 QDictIterator<Kita::Thread> it( threads );
80 for ( ; it.current(); ++it ) {
81 const Kita::Thread* thread = it.current();
83 if ( thread->datURL() == item->text( Row_DatURL ) ) {
84 emit signalShowThread( thread );
89 void FavoriteListView::updateThread( const Kita::Thread* updated_thread )
91 for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
92 if ( item->text( Row_DatURL ) == updated_thread->datURL() ) {
93 item->setText( Row_ResNum, QString( "%1" ).arg( updated_thread->resNum(), 4 ) );
98 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
99 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
105 KPopupMenu popup( 0 );
106 popup.insertItem( i18n( "Open with Web Browser" ), 0 );
107 popup.insertItem( i18n( "Open with new tab" ), 1 );
108 popup.insertItem( i18n( "Copy title and URL" ), 2 );
110 QString datName = item->text( Row_DatName );
111 KURL datURL = KURL( item->text( Row_DatURL ) );
113 Kita::Thread* thread = new Kita::Thread( datURL.url() );
114 thread->setName( item->text( Row_Subject ) );
115 thread->setResNum( item->text( Row_Read ).toInt() );
117 QClipboard* clipboard = QApplication::clipboard();
119 switch ( popup.exec( point ) ) {
121 KRun::runURL( thread->url(), "text/html" );
124 emit signalShowThreadWithNewTab( thread );
127 clipboard->setText( thread->name() + "\n" + thread->url() );