X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=kita%2Fsrc%2Ffavoritelistview.cpp;h=5dedde17c00c59656c571323be1ad08c78d3fa03;hb=5287b142b408e3775966fc60883a277fe0100654;hp=eefb93c54a763f27281619ebec7c1e9aad2a6cb3;hpb=e6034f7a5e2c6de7c1513757138ae332fde12358;p=kita%2Fkita.git diff --git a/kita/src/favoritelistview.cpp b/kita/src/favoritelistview.cpp index eefb93c..5dedde1 100644 --- a/kita/src/favoritelistview.cpp +++ b/kita/src/favoritelistview.cpp @@ -1,153 +1,149 @@ /*************************************************************************** - * Copyright (C) 2003 by Hideki Ikemoto * - * ikemo@users.sourceforge.jp * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - ***************************************************************************/ +* Copyright (C) 2003 by Hideki Ikemoto * +* ikemo@users.sourceforge.jp * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +***************************************************************************/ #include "favoritelistview.h" +#include +#include +#include +#include + +#include +#include +#include + +#include "threadlistviewitem.h" +#include "viewmediator.h" +#include "libkita/boarddatabase.h" +#include "libkita/datmanager.h" #include "libkita/favoritethreads.h" -#include "libkita/board.h" -#include "kitacacheinfo.h" +#include "libkita/kita_misc.h" +#include "libkita/thread.h" -#include -#include -#include +using namespace Kita; -#include -#include -#include -#include - -enum FavoriteListViewRows { - Row_Board, - Row_Icon, - Row_Subject, - Row_ResNum, - Row_Read, - Row_Unread, - Row_DatName, - Row_DatURL -}; - -FavoriteListView::FavoriteListView(QWidget* parent, const char *name) - : KListView(parent, name) +/** + * + */ +FavoriteListView::FavoriteListView(QWidget* parent) : ThreadListView(parent) { - addColumn(i18n("Board")); - addColumn(""); - addColumn(i18n("Title")); - addColumn(i18n("ResNum")); - addColumn(i18n("ReadNum")); - addColumn(i18n("Unread")); - addColumn(i18n("Dat")); - - setColumnWidth(Row_Subject, 400); - setColumnWidthMode(Row_Subject, QListView::Manual); - - connect( this, SIGNAL( clicked(QListViewItem*) ), - SLOT( loadThread(QListViewItem*) ) ); - connect( this, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), - SLOT( slotContextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); -} + kindLabel->hide(); -FavoriteListView::~FavoriteListView() -{ + connect(subjectList, SIGNAL(itemClicked(QTableWidgetItem*)), + SLOT(loadThread(QTableWidgetItem*))); + connect(reloadButton, SIGNAL(clicked()), + SLOT(reload())); + + showColumn(ColumnBoard); } -void FavoriteListView::update() +/** + * + */ +void FavoriteListView::refresh() { - const QDict& threads = FavoriteThreads::getInstance()->threads(); -// FavoriteThreads::const_iterator it; - - clear(); - - KitaCacheInfo* cache = KitaCacheInfo::getInstance(); - - QDictIterator it( threads ); - for(; it.current(); ++it) { - const Kita::Thread* thread = it.current(); - - int readNum = cache->readNum( thread->datURL() ); - int resNum = cache->resNum( thread->datURL() ); // TODO unused variables. - - new KListViewItem( this, - thread->boardName(), - "", - thread->name(), - "", - QString("%1").arg( readNum, 4 ), - "", - thread->datURL().fileName(), - thread->datURL().url() ); - } + // 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); + + 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); + } } -void FavoriteListView::loadThread( QListViewItem* item ) +/** + * + */ +void FavoriteListView::loadThread(QTableWidgetItem* item) { - if( ! item ) return; + if (! item) return ; - const QDict& threads = FavoriteThreads::getInstance()->threads(); -// FavoriteThreads::const_iterator it; + QString itemUrl = subjectList->item(item->row(), ColumnDatUrl)->text(); - QDictIterator it( threads ); - for(; it.current(); ++it) { - const Kita::Thread* thread = it.current(); + for (int i = 0; FavoriteThreads::count() > i; i++) { + QString datUrl = FavoriteThreads::getDatUrl(i); - if( thread->datURL().url() == item->text( Row_DatURL ) ) { - emit signalShowThread( *thread ); + if (datUrl == itemUrl) { + ViewMediator::getInstance()->openThread(datUrl); + } } - } } -void FavoriteListView::updateThread( const Kita::Thread& updated_thread ) +/** + * + */ +void FavoriteListView::reload() { - for( QListViewItem* item = firstChild(); item; item = item->nextSibling() ) { - if( item->text( Row_DatURL ) == updated_thread.datURL().url() ) { - item->setText( Row_ResNum, QString("%1").arg( updated_thread.resNum(), 4 ) ); + QList 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); + } } - } -} -// TODO: KitaSubjectView¥¯¥é¥¹¤ÎƱ¥á¥½¥Ã¥É¤È¤Û¤È¤ó¤ÉƱ¤¸ -void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoint& point, int ) -{ - if( item == 0 ) { - return; - } - - 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 ); - - QString datName = item->text(Row_DatName); - KURL datURL = KURL( item->text(Row_DatURL) ); - - kdDebug() << "datURL = " << datURL.url() << endl; - Kita::Board board = Kita::Board( KURL( datURL, ".." ) ); - kdDebug() << "board.url = " << board.url().url() << endl; - Kita::Thread thread( board.name(), datURL ); - kdDebug() << "thread.url = %s" << thread.url() << endl; - thread.setName( item->text( Row_Subject ) ); - thread.setResNum( item->text( Row_Read ).toInt() ); - - QClipboard* clipboard = QApplication::clipboard(); - - switch( popup.exec( point ) ) { - case 0: - KRun::runURL( thread.url(), "text/html" ); - break; - case 1: - emit signalShowThreadWithNewTab( thread ); - break; - case 2: - clipboard->setText( thread.name() + "\n" + thread.url() ); - break; - default: - break; - } + QList::const_iterator it; + for (it = boardList.begin(); it != boardList.end(); ++it) { + bool online = true; + QList threadList; + QList tmpList; + BoardDatabase db((*it)); + db.getThreadList(false, online, threadList, tmpList); + } }