#include "favoritelistview.h"
-#include "libkita/favoritethreads.h"
-#include "libkita/kita_misc.h"
-#include "libkita/threadinfo.h"
-#include "libkita/signalcollection.h"
-#include "libkita/parsemisc.h"
-
-#include <qmap.h>
-#include <qapplication.h>
-#include <qclipboard.h>
-#include <qdatetime.h>
-#include <qtoolbutton.h>
-#include <qlabel.h>
-
-#include <klocale.h>
-#include <kpopupmenu.h>
+#include <QtCore/QDateTime>
+#include <QtGui/QApplication>
+#include <QtGui/QClipboard>
+#include <QtGui/QTableWidgetItem>
+
+#include <kaction.h>
+#include <kmenu.h>
#include <krun.h>
-#include <kdebug.h>
-#include <klistview.h>
-FavoriteListView::FavoriteListView( QWidget* parent, const char* name )
- : Kita::ThreadListView( parent, name )
-{
- subjectList->addColumn( i18n( "Board" ) );
-
- KindLabel->hide();
-
- Kita::SignalCollection* signalCollection = Kita::SignalCollection::getInstance();
- connect( subjectList, SIGNAL( returnPressed( QListViewItem* ) ),
- SLOT( loadThread( QListViewItem* ) ) );
- connect( subjectList, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ),
- SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
- connect( ReloadButton, SIGNAL( clicked() ),
- SLOT( slotReloadButton() ) );
- connect( this, SIGNAL( openBoardRequested( const QString&, bool ) ),
- signalCollection, SIGNAL( openBoardRequested( const QString&, bool ) ) );
- connect( signalCollection, SIGNAL( favoritesUpdated() ),
- SLOT( update() ) );
-
- connect( signalCollection, SIGNAL( updateSubjectTab( const KURL& ) ),
- SLOT( slotUpdateSubject( const KURL& ) ) );
-}
+#include "threadlistviewitem.h"
+#include "viewmediator.h"
+#include "libkita/boarddatabase.h"
+#include "libkita/datmanager.h"
+#include "libkita/favoritethreads.h"
+#include "libkita/kita_misc.h"
+#include "libkita/thread.h"
-FavoriteListView::~FavoriteListView()
-{}
+using namespace Kita;
-void FavoriteListView::update()
+/**
+ *
+ */
+FavoriteListView::FavoriteListView(QWidget* parent) : ThreadListView(parent)
{
- // FIXME: KitaSubjectView::loadBoard()¤Ë¥³¥Ô¡¼
- {
- m_hitList.clear();
- m_nextHitIndex = 0;
- m_prevquery = "";
- }
-
- const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
-
- subjectList->clear();
-
- KitaThreadInfo* cache = KitaThreadInfo::getInstance();
+ kindLabel->hide();
- QValueList<QString>::const_iterator it;
- for ( it = threadList.begin(); it != threadList.end(); ++it ) {
- const Kita::Thread* thread = Kita::Thread::getByURL( *it );
+ connect(subjectList, SIGNAL(itemClicked(QTableWidgetItem*)),
+ SLOT(loadThread(QTableWidgetItem*)));
+ connect(reloadButton, SIGNAL(clicked()),
+ SLOT(reload()));
- QDateTime since;
- since.setTime_t( KURL( thread->datURL() ).fileName().section( '.', 0, 0 ).toInt() );
-
- int readNum = cache->readNum( thread->datURL() );
- int resNum = KitaThreadInfo::resNum( thread->datURL() );
-
- KListViewItem* item = new KListViewItem( subjectList );
- item->setText( Col_Board, thread->boardName() );
- item->setText( Col_Subject, Kita::unescape( thread->name() ) );
- item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
- if ( resNum > 0 ) {
- item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
- if ( resNum != readNum ) {
- item->setText( Col_Unread, QString( "%1" ).arg( resNum - readNum, 4 ) );
- }
- }
- item->setText( Col_Since, since.toString( "yy/MM/dd hh:mm" ) );
- item->setText( Col_DatURL, thread->datURL() );
- }
- subjectList->setSorting( Col_Board );
+ showColumn(ColumnBoard);
}
-void FavoriteListView::loadThread( QListViewItem* item )
+/**
+ *
+ */
+void FavoriteListView::refresh()
{
- if ( ! item ) return ;
-
- const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
-
- QValueList<QString>::const_iterator it;
- for ( it = threadList.begin(); it != threadList.end(); ++it ) {
- const Kita::Thread* thread = Kita::Thread::getByURL( *it );
-
- if ( thread->datURL() == item->text( Col_DatURL ) ) {
- emit showThreadRequested( thread->datURL(), false );
+ // clear
+ m_hitList.clear();
+ m_nextHitIndex = 0;
+ m_prevquery = QStringList();
+
+ subjectList->clearContents();
+
+ subjectList->setSortingEnabled(false);
+ int count = FavoriteThreads::count();
+ subjectList->setRowCount(count);
+ for (int i = 0; i < count; i++) {
+ for (int j = 0, k = subjectList->columnCount(); j < k; j++) {
+ ThreadListViewItem* item = new ThreadListViewItem(j);
+ subjectList->setItem(i, j, item);
}
}
-}
+ subjectList->setSortingEnabled(true);
+ // insert item.
+ for (int i = 0; i < count; i++) {
+ QString datUrl = FavoriteThreads::getDatUrl(i);
-void FavoriteListView::slotUpdateSubject( const KURL& url )
-{
- KURL datURL = Kita::ParseMisc::parseURLonly( url );
- Kita::Thread* updated_thread = Kita::Thread::getByURLNew( datURL );
- for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
- if ( item->text( Col_DatURL ) == datURL.prettyURL() ) {
- int resNum = updated_thread->resNum();
- int readNum = KitaThreadInfo::readNum( updated_thread->datURL() );
- item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
- item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
+ QDateTime since;
+ since.setTime_t(datToSince(datUrl));
+
+ DatManager datManager(datUrl);
+ int viewPos = datManager.getViewPos();
+ int resNum = datManager.getResNum();
+
+ BoardDatabase db(datUrl);
+ subjectList->item(i, ColumnBoard)->setText(db.boardName());
+ subjectList->item(i, ColumnSubject)
+ ->setText(datManager.threadName());
+ subjectList->item(i, ColumnReadNum)
+ ->setText(QString("%1").arg(viewPos, 4));
+ if (resNum > 0) {
+ subjectList->item(i, ColumnResNum)
+ ->setText(QString("%1").arg(resNum, 4));
+ }
+ if (resNum != 0 && resNum != viewPos) {
+ subjectList->item(i, ColumnUnread)
+ ->setText(QString("%1").arg(resNum - viewPos, 4));
}
+ subjectList->item(i, ColumnSince)
+ ->setText(since.toString("yy/MM/dd hh:mm"));
+ subjectList->item(i, ColumnDatUrl)->setText(datUrl);
+ }
+ subjectList->sortItems(ColumnBoard);
+ for (int i = 0, j = subjectList->columnCount(); i < j; i++) {
+ subjectList->resizeColumnToContents(i);
+ }
+ for (int i = 0, j = subjectList->rowCount(); i < j; i++) {
+ subjectList->resizeRowToContents(i);
}
}
-// TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸
-void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int )
+/**
+ *
+ */
+void FavoriteListView::loadThread(QTableWidgetItem* item)
{
- if ( item == 0 ) {
- return ;
- }
+ if (! item) return ;
+
+ QString itemUrl = subjectList->item(item->row(), ColumnDatUrl)->text();
- KPopupMenu popup( 0 );
- popup.insertItem( i18n( "Open with Web Browser" ), 0 );
- popup.insertItem( i18n( "Open with new tab" ), 1 );
- popup.insertItem( i18n( "Copy title and URL" ), 2 );
- popup.insertItem( i18n( "Remove from Favorites" ), 3 );
-
- Kita::Thread* thread = Kita::Thread::getByURL( item->text( Col_DatURL ) );
-
- QClipboard* clipboard = QApplication::clipboard();
-
- switch ( popup.exec( point ) ) {
- case 0:
- KRun::runURL( thread->url(), "text/html" );
- break;
- case 1:
- emit showThreadRequested( thread->datURL(), true );
- break;
- case 2:
- clipboard->setText( thread->name() + "\n" + thread->url() );
- break;
- case 3:
- emit bookmarked( thread->datURL(), false );
- break;
- default:
- break;
+ for (int i = 0; FavoriteThreads::count() > i; i++) {
+ QString datUrl = FavoriteThreads::getDatUrl(i);
+
+ if (datUrl == itemUrl) {
+ ViewMediator::getInstance()->openThread(datUrl);
+ }
}
}
-void FavoriteListView::slotReloadButton()
+/**
+ *
+ */
+void FavoriteListView::reload()
{
- QValueList<QString> boardList;
-
- const QValueList<QString> threadList = FavoriteThreads::getInstance() -> threadList();
- QValueList<QString>::const_iterator it;
- for ( it = threadList.begin(); it != threadList.end(); ++it ) {
- const Kita::Thread* thread = Kita::Thread::getByURL( *it );
- QString boardURL = Kita::datToBoard( thread->datURL() );
- if ( boardList.contains( boardURL ) == 0 ) {
- boardList.append( boardURL );
+ QList<QString> boardList;
+
+ for (int i = 0; FavoriteThreads::count() > i; i++) {
+ QString datUrl = FavoriteThreads::getDatUrl(i);
+ BoardDatabase db(datUrl);
+ QString boardUrl = db.boardUrl();
+ if (boardList.contains(boardUrl) == 0) {
+ boardList.append(boardUrl);
}
}
- QValueList<QString>::const_iterator it2;
- for ( it2 = boardList.begin(); it2 != boardList.end(); ++it2 ) {
- // ³ÆÈĤÎsubject.txt¤ò¼èÆÀ¡£
- Kita::Board::getThreadList( (*it2 ) );
+ QList<QString>::const_iterator it;
+ for (it = boardList.begin(); it != boardList.end(); ++it) {
+ bool online = true;
+ QList<Thread*> threadList;
+ QList<Thread*> tmpList;
+ BoardDatabase db((*it));
+ db.getThreadList(false, online, threadList, tmpList);
}
}
-