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>
27 enum FavoriteListViewRows {
38 FavoriteListView::FavoriteListView(QWidget* parent, const char *name)
39 : KListView(parent, name)
41 addColumn(i18n("Board"));
43 addColumn(i18n("Title"));
44 addColumn(i18n("ResNum"));
45 addColumn(i18n("ReadNum"));
46 addColumn(i18n("Unread"));
47 addColumn(i18n("Dat"));
49 setColumnWidth(Row_Subject, 400);
50 setColumnWidthMode(Row_Subject, QListView::Manual);
52 connect( this, SIGNAL( clicked(QListViewItem*) ),
53 SLOT( loadThread(QListViewItem*) ) );
54 connect( this, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
55 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
58 FavoriteListView::~FavoriteListView()
62 void FavoriteListView::update()
64 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
65 // FavoriteThreads::const_iterator it;
69 KitaThreadInfo* cache = KitaThreadInfo::getInstance();
71 QDictIterator<Kita::Thread> it( threads );
72 for(; it.current(); ++it) {
73 const Kita::Thread* thread = it.current();
75 int readNum = cache->readNum( thread->datURL() );
76 int resNum = cache->resNum( thread->datURL() ); // TODO unused variables.
78 new KListViewItem( this,
83 QString("%1").arg( readNum, 4 ),
85 KURL( thread->datURL() ).fileName(),
90 void FavoriteListView::loadThread( QListViewItem* item )
94 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
95 // FavoriteThreads::const_iterator it;
97 QDictIterator<Kita::Thread> it( threads );
98 for(; it.current(); ++it) {
99 const Kita::Thread* thread = it.current();
101 if( thread->datURL() == item->text( Row_DatURL ) ) {
102 emit signalShowThread( *thread );
107 void FavoriteListView::updateThread( const Kita::Thread& updated_thread )
109 for( QListViewItem* item = firstChild(); item; item = item->nextSibling() ) {
110 if( item->text( Row_DatURL ) == updated_thread.datURL() ) {
111 item->setText( Row_ResNum, QString("%1").arg( updated_thread.resNum(), 4 ) );
116 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
117 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
123 KPopupMenu popup( 0 );
124 popup.insertItem( i18n("Open with Web Browser"), 0 );
125 popup.insertItem( i18n("Open with new tab"), 1 );
126 popup.insertItem( i18n("Copy title and URL"), 2 );
128 QString datName = item->text(Row_DatName);
129 KURL datURL = KURL( item->text(Row_DatURL) );
131 Kita::Thread thread( datURL.url() );
132 thread.setName( item->text( Row_Subject ) );
133 thread.setResNum( item->text( Row_Read ).toInt() );
135 QClipboard* clipboard = QApplication::clipboard();
137 switch( popup.exec( point ) ) {
139 KRun::runURL( thread.url(), "text/html" );
142 emit signalShowThreadWithNewTab( thread );
145 clipboard->setText( thread.name() + "\n" + thread.url() );