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 "kitacacheinfo.h"
18 #include <qapplication.h>
19 #include <qclipboard.h>
22 #include <kpopupmenu.h>
26 enum FavoriteListViewRows {
37 FavoriteListView::FavoriteListView(QWidget* parent, const char *name)
38 : KListView(parent, name)
40 addColumn(i18n("Board"));
42 addColumn(i18n("Title"));
43 addColumn(i18n("ResNum"));
44 addColumn(i18n("ReadNum"));
45 addColumn(i18n("Unread"));
46 addColumn(i18n("Dat"));
48 setColumnWidth(Row_Subject, 400);
49 setColumnWidthMode(Row_Subject, QListView::Manual);
51 connect( this, SIGNAL( clicked(QListViewItem*) ),
52 SLOT( loadThread(QListViewItem*) ) );
53 connect( this, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
54 SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
57 FavoriteListView::~FavoriteListView()
61 void FavoriteListView::update()
63 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
64 // FavoriteThreads::const_iterator it;
68 KitaCacheInfo* cache = KitaCacheInfo::getInstance();
70 QDictIterator<Kita::Thread> it( threads );
71 for(; it.current(); ++it) {
72 const Kita::Thread* thread = it.current();
74 int readNum = cache->readNum( thread->datURL() );
75 int resNum = cache->resNum( thread->datURL() ); // TODO unused variables.
77 new KListViewItem( this,
82 QString("%1").arg( readNum, 4 ),
84 thread->datURL().fileName(),
85 thread->datURL().url() );
89 void FavoriteListView::loadThread( QListViewItem* item )
93 const QDict<Kita::Thread>& threads = FavoriteThreads::getInstance()->threads();
94 // FavoriteThreads::const_iterator it;
96 QDictIterator<Kita::Thread> it( threads );
97 for(; it.current(); ++it) {
98 const Kita::Thread* thread = it.current();
100 if( thread->datURL().url() == item->text( Row_DatURL ) ) {
101 emit signalShowThread( *thread );
106 void FavoriteListView::updateThread( const Kita::Thread& updated_thread )
108 for( QListViewItem* item = firstChild(); item; item = item->nextSibling() ) {
109 if( item->text( Row_DatURL ) == updated_thread.datURL().url() ) {
110 item->setText( Row_ResNum, QString("%1").arg( updated_thread.resNum(), 4 ) );
115 // TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
116 void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
122 KPopupMenu popup( 0 );
123 popup.insertItem( i18n("Open with Web Browser"), 0 );
124 popup.insertItem( i18n("Open with new tab"), 1 );
125 popup.insertItem( i18n("Copy title and URL"), 2 );
127 QString datName = item->text(Row_DatName);
128 KURL datURL = KURL( item->text(Row_DatURL) );
130 kdDebug() << "datURL = " << datURL.url() << endl;
131 Kita::Board board = Kita::Board( KURL( datURL, ".." ) );
132 kdDebug() << "board.url = " << board.url().url() << endl;
133 Kita::Thread thread( board.name(), datURL );
134 kdDebug() << "thread.url = %s" << thread.url() << endl;
135 thread.setName( item->text( Row_Subject ) );
136 thread.setResNum( item->text( Row_Read ).toInt() );
138 QClipboard* clipboard = QApplication::clipboard();
140 switch( popup.exec( point ) ) {
142 KRun::runURL( thread.url(), "text/html" );
145 emit signalShowThreadWithNewTab( thread );
148 clipboard->setText( thread.name() + "\n" + thread.url() );