From 632287da21f3c7dd664fe7d1b13bf7be2f825367 Mon Sep 17 00:00:00 2001 From: ogirin Date: Sun, 23 Mar 2003 15:48:13 +0000 Subject: [PATCH] Konqueror sidebar plugin-module. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@118 56b19765-1e22-0410-a548-a0f45d66c51a --- k2ch_module/Makefile.am | 22 + k2ch_module/k2chtree.desktop | 10 + k2ch_module/k2chtree_bookmarkitem/Makefile.am | 13 + .../k2chtree_bookmarkitem/bookmark_item.cpp | 73 +++ k2ch_module/k2chtree_bookmarkitem/bookmark_item.h | 60 +++ k2ch_module/k2chtree_k2chitem/Makefile.am | 20 + k2ch_module/k2chtree_k2chitem/k2ch.cpp | 295 ++++++++++++ k2ch_module/k2chtree_k2chitem/k2ch.h | 147 ++++++ k2ch_module/k2chtree_k2chitem/k2chtree_item.cpp | 527 +++++++++++++++++++++ k2ch_module/k2chtree_k2chitem/k2chtree_item.h | 181 +++++++ k2ch_module/k2chtree_module.cpp | 186 ++++++++ k2ch_module/k2chtree_module.desktop | 6 + k2ch_module/k2chtree_module.h | 62 +++ 13 files changed, 1602 insertions(+) create mode 100644 k2ch_module/Makefile.am create mode 100644 k2ch_module/k2chtree.desktop create mode 100644 k2ch_module/k2chtree_bookmarkitem/Makefile.am create mode 100644 k2ch_module/k2chtree_bookmarkitem/bookmark_item.cpp create mode 100644 k2ch_module/k2chtree_bookmarkitem/bookmark_item.h create mode 100644 k2ch_module/k2chtree_k2chitem/Makefile.am create mode 100644 k2ch_module/k2chtree_k2chitem/k2ch.cpp create mode 100644 k2ch_module/k2chtree_k2chitem/k2ch.h create mode 100644 k2ch_module/k2chtree_k2chitem/k2chtree_item.cpp create mode 100644 k2ch_module/k2chtree_k2chitem/k2chtree_item.h create mode 100644 k2ch_module/k2chtree_module.cpp create mode 100644 k2ch_module/k2chtree_module.desktop create mode 100644 k2ch_module/k2chtree_module.h diff --git a/k2ch_module/Makefile.am b/k2ch_module/Makefile.am new file mode 100644 index 0000000..19d3bb6 --- /dev/null +++ b/k2ch_module/Makefile.am @@ -0,0 +1,22 @@ +SUBDIRS = k2chtree_k2chitem k2chtree_bookmarkitem + +INCLUDES = -I$(top_srcdir)/kde-include/konqueror/sidebar -I$(top_srcdir)/kde-include/konqueror/sidebar/trees -Ik2chtree_k2chitem -Ik2chtree_bookmarkitem $(all_includes) + +METASOURCES = AUTO +noinst_HEADERS = k2chtree_module.h + + +kde_module_LTLIBRARIES = konq_sidebartree_k2chtree.la + +konq_sidebartree_k2chtree_la_SOURCES = k2chtree_module.cpp k2chtree_module.h +konq_sidebartree_k2chtree_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +konq_sidebartree_k2chtree_la_LIBADD = $(kde_libraries)/libkonqsidebarplugin.la $(kde_libraries)/libkonq_sidebar_tree.la \ +k2chtree_k2chitem/k2chtree_k2chitem.la \ +k2chtree_bookmarkitem/k2chtree_bookmarkitem.la + +tree_module_DATA = k2chtree_module.desktop +tree_moduledir = $(kde_datadir)/konqsidebartng/dirtree + +sidebar_entry_DATA = k2chtree.desktop +sidebar_entrydir = $(kde_datadir)/konqsidebartng/entries + diff --git a/k2ch_module/k2chtree.desktop b/k2ch_module/k2chtree.desktop new file mode 100644 index 0000000..5f01c77 --- /dev/null +++ b/k2ch_module/k2chtree.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=K2ch +Icon=mozilla +Type=Link +URL=http://pc.2ch.net/linux/ +Encoding=UTF-8 +Comment=Provide a Quick Access to '2ch'. +Open=false +X-KDE-TreeModule=K2chTree_Module +X-KDE-KonqSidebarModule=konqsidebar_tree diff --git a/k2ch_module/k2chtree_bookmarkitem/Makefile.am b/k2ch_module/k2chtree_bookmarkitem/Makefile.am new file mode 100644 index 0000000..59f6a61 --- /dev/null +++ b/k2ch_module/k2chtree_bookmarkitem/Makefile.am @@ -0,0 +1,13 @@ + +SUBDIRS = + +INCLUDES = -I$(top_srcdir)/kde-include/konqueror/sidebar/trees $(all_includes) + +METASOURCES = AUTO +noinst_HEADERS = bookmark_item.h + +kde_module_LTLIBRARIES = k2chtree_bookmarkitem.la + +k2chtree_bookmarkitem_la_SOURCES = bookmark_item.cpp bookmark_item.h +k2chtree_bookmarkitem_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +k2chtree_bookmarkitem_la_LIBADD = $(kde_libraries)/libkonq_sidebar_tree.la diff --git a/k2ch_module/k2chtree_bookmarkitem/bookmark_item.cpp b/k2ch_module/k2chtree_bookmarkitem/bookmark_item.cpp new file mode 100644 index 0000000..1484dad --- /dev/null +++ b/k2ch_module/k2chtree_bookmarkitem/bookmark_item.cpp @@ -0,0 +1,73 @@ +/* This file is part of the KDE project + Copyright (C) 2000 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "bookmark_item.h" +#include +#include +#include +#include + +KonqSidebarBookmarkItem::KonqSidebarBookmarkItem( KonqSidebarTreeItem *parentItem, KonqSidebarTreeTopLevelItem *topLevelItem, const KBookmark & bk, int key ) + : KonqSidebarTreeItem( parentItem, topLevelItem ), m_bk(bk), m_key(key) +{ + setText( 0, bk.text() ); + setPixmap( 0, SmallIcon(bk.icon()) ); +} + +QDragObject * KonqSidebarBookmarkItem::dragObject( QWidget * parent, bool ) +{ + KBookmarkDrag * drag = KBookmarkDrag::newDrag( m_bk, parent ); + // TODO honour bool move ? + return drag; +} + +void KonqSidebarBookmarkItem::middleButtonPressed() +{ + emit tree()->createNewWindow( externalURL() ); +} + +void KonqSidebarBookmarkItem::rightButtonPressed() +{ + kdDebug() << "KonqSidebarBookmarkItem::rightButtonPressed" << endl; + //TODO +} + +void KonqSidebarBookmarkItem::del() +{ + //maybe todo +} + +KURL KonqSidebarBookmarkItem::externalURL() const +{ + return m_bk.url(); +} + +QString KonqSidebarBookmarkItem::toolTipText() const +{ + return m_bk.url().prettyURL(); +} + +void KonqSidebarBookmarkItem::itemSelected() +{ + tree()->enableActions( false, false, false, false, false, false ); +} + +QString KonqSidebarBookmarkItem::key( int /*column*/, bool /*ascending*/ ) const +{ + return QString::number(m_key).rightJustify( 5, '0' ); +} diff --git a/k2ch_module/k2chtree_bookmarkitem/bookmark_item.h b/k2ch_module/k2chtree_bookmarkitem/bookmark_item.h new file mode 100644 index 0000000..4b3c96a --- /dev/null +++ b/k2ch_module/k2chtree_bookmarkitem/bookmark_item.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE project + Copyright (C) 2000 David Faure + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef bookmark_item_h +#define bookmark_item_h + +#include +#include + +/** + * A bookmark item + */ +class KonqSidebarBookmarkItem : public KonqSidebarTreeItem +{ +public: + KonqSidebarBookmarkItem( KonqSidebarTreeItem *parentItem, KonqSidebarTreeTopLevelItem *topLevelItem, + const KBookmark & bk, int key ); + + virtual ~KonqSidebarBookmarkItem() {} + + // Create a drag object from this item. + virtual QDragObject * dragObject( QWidget * parent, bool move = false ); + + virtual void middleButtonPressed(); + virtual void rightButtonPressed(); + + virtual void del(); + + // The URL to open when this link is clicked + virtual KURL externalURL() const; + + // overwrite this if you want a tooltip shown on your item + virtual QString toolTipText() const; + + // Called when this item is selected + virtual void itemSelected(); + + virtual QString key( int column, bool /*ascending*/ ) const; + +private: + KBookmark m_bk; + int m_key; +}; + +#endif diff --git a/k2ch_module/k2chtree_k2chitem/Makefile.am b/k2ch_module/k2chtree_k2chitem/Makefile.am new file mode 100644 index 0000000..ded7985 --- /dev/null +++ b/k2ch_module/k2chtree_k2chitem/Makefile.am @@ -0,0 +1,20 @@ +SUBDIRS = + +INCLUDES = -I$(top_srcdir)/kde-include/konqueror/sidebar/trees $(all_includes) + +METASOURCES = AUTO +noinst_HEADERS = k2chtree_item.h k2ch.h + +kde_module_LTLIBRARIES = k2chtree_k2chitem.la + +k2chtree_k2chitem_la_SOURCES = k2chtree_item.cpp k2chtree_item.h k2ch.cpp k2ch.h + +k2chtree_k2chitem_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined + +k2chtree_k2chitem_la_LIBADD = $(kde_libraries)/libkonq_sidebar_tree.la + +#lib_LTLIBRARIES = libk2ch.la +#libk2ch_la_SOURCES = k2ch.cpp +#libk2ch_la_LDFLAGS = $(all_libraries) -module -export-dynamic -version-info 2:0:0 -no-undefined +#libk2ch_la_LIBADD = $(kde_libraries)/libkio.la + diff --git a/k2ch_module/k2chtree_k2chitem/k2ch.cpp b/k2ch_module/k2chtree_k2chitem/k2ch.cpp new file mode 100644 index 0000000..23a8327 --- /dev/null +++ b/k2ch_module/k2chtree_k2chitem/k2ch.cpp @@ -0,0 +1,295 @@ + +#include "k2ch.h" + +#include +#include +class QTextCodec; + +#include +class QProgressDialog; + +#include +class QRegExp; + +using namespace K2ch; + +Element::~Element() +{ + if ( m_array ) delete m_array; +} + +void Element::recieveData( KIO::Job *, const QByteArray &data) +{ + m_progress->setProgress( (m_progress->progress() < 80)?(m_progress->progress() + 4):m_progress->progress() ); + //printf(" board::recieveData() %d + %d\n", data.size(), m_array->length() ); + m_array->append( data.data() ); +} + +bool Element::refreshChildList() +{ + if( m_currentjob ) { + return false; + } else { + return true; + } +} + +Base::~Base() +{ + if ( ! categoryList.autoDelete() ) categoryList.setAutoDelete( true ); + while( categoryList.remove() ); +} + +bool Base::refreshChildList() +{ + printf(" Base::refreshCategoryList()\n"); + if ( m_currentjob ) { + return false; + } else { + m_progress = new QProgressDialog; + m_progress->setLabel( new QLabel( QString("%1: %2").arg( name ).arg( i18n("Refresh the BBS menu.") ), m_progress ) ); + m_progress->setTotalSteps( 100 ); + m_progress->show(); + + m_array = new QCString; + + m_currentjob = KIO::get( bbsmenu, false, false ); + connect( m_currentjob, SIGNAL( data(KIO::Job *, const QByteArray &) ), + this, SLOT( recieveData(KIO::Job *, const QByteArray &) ) ); + connect( m_currentjob, SIGNAL( result(KIO::Job *) ), + this, SLOT( processBBSMenu(KIO::Job *) ) ); + + m_progress->setProgress( 10 ); + return true; + } +} + +void Base::processBBSMenu( KIO::Job * job ) +{ + printf(" Base::processBBSMenu() length=%d\n", m_array->length() ); + if ( ! job->error() ) { + QString input = QTextCodec::codecForName("sjis")->toUnicode( *m_array ); + //QCString content = QTextCodec::codecForName("eucJP")->fromUnicode( input ); + //printf(" bbsmenu Content:\n%s\n", (const char*)content ); + + QStringList lines = QStringList::split("\n", input ); + + QRegExp category_r("

(.*)
"); + QRegExp board_r("(.*)"); + + QStringList::iterator it = lines.begin(); + int step = ( 100 - m_progress->progress() ) / lines.count(); + + while( categoryList.remove() ); + for( it = lines.begin(); it != lines.end() && category_r.search(*it) == -1; ++it ) + m_progress->setProgress( step + m_progress->progress() ); + + //categoryList.setAutoDelete( true ); + for( ; it != lines.end(); ++it ) + { + if( category_r.search(*it) != -1 ) + { + QString name( category_r.cap(1) ); + + K2ch::Category * new_cate = new K2ch::Category; + new_cate->name = name; + new_cate->base = this; + //new_cate->boardList.setAutoDelete( true ); + + categoryList.append( new_cate ); + } else if ( board_r.search(*it) != -1 ) + { + KURL url( board_r.cap(1) ); + QString name( board_r.cap(2) ); + + K2ch::Board * new_board = new K2ch::Board; + new_board->name = name; + new_board->url = url; + new_board->subject_txt = url.url(-1).append("/subject.txt"); + new_board->subject_txt.setProtocol( "k2ch" ); + new_board->setting_txt = url.url(-1).append("/SETTING.TXT"); + new_board->setting_txt.setProtocol( "k2ch" ); + new_board->category = categoryList.last(); + + new_board->category->boardList.append( new_board ); + } + m_progress->setProgress( step + m_progress->progress() ); + } + } + + delete m_progress; + m_progress = 0; + delete m_array; + m_array = 0; + m_currentjob = 0; + + emit refreshCompleted( this ); +} + +Category::~Category() +{ + if ( ! boardList.autoDelete() ) boardList.setAutoDelete( true ); + while ( boardList.remove() ); +} + +bool Category::refreshChildList() +{ + printf(" Category::refreshChildList()\n"); + if ( base ) { + return base->refreshChildList(); + } else { + return false; + } +} + +Board::~Board() +{ + m_dict.setAutoDelete( true ); +} + +bool Board::refreshChildList() +{ + printf(" board::refreshThreadList() %s %p\n", url.url().latin1(), static_cast(m_currentjob) ); + + if ( m_currentjob ) { + return false; + } else + { + m_progress = new QProgressDialog; + m_progress->setLabel( new QLabel( QString("%1: %2").arg( name ).arg( i18n("Refreshing the list of threads.") ), m_progress ) ); + m_progress->setTotalSteps( 100 ); + m_progress->show(); + + m_array = new QCString; + + m_currentjob = KIO::get( subject_txt, false, false ); + connect( m_currentjob, SIGNAL( data(KIO::Job *, const QByteArray &) ), + this, SLOT( recieveData(KIO::Job *, const QByteArray &) ) ); + connect( m_currentjob, SIGNAL( result(KIO::Job *) ), + this, SLOT( processSubject(KIO::Job *) ) ); + + m_progress->setProgress( 10 ); + return true; + } +} + +void Board::processSubject( KIO::Job *job ) +{ + printf(" board::processSubject() length=%d\n", m_array->length() ); + if ( ! job->error() ) { + while( threadList.remove() ); + + m_progress->setProgress( 90 ); + + QTextCodec * sjis_codec = QTextCodec::codecForName( "sjis" ); + + char * tmp = m_array->data(); + + char * ttitle_start = 0; + char * datnum_start = tmp; + char * resnum_start = 0; + char * ttitle_end = 0; + char * datnum_end = 0; + char * resnum_end = 0; + + int thread_count = 0; + bool exit_loop = false; + + for( ; ! exit_loop; ++tmp ) { + switch( *tmp ) { + case '.': // need the first '.'; + if ( ! datnum_end > 0 ) { + *(datnum_end = tmp) = '\0'; + ttitle_start = (tmp += 6 ); + } + break; + + case '(': // need the last '('. + ttitle_end = tmp; + resnum_start = tmp + 1; + break; + + case ')': //need the last ')'. + resnum_end = tmp; + break; + + case '\0': + exit_loop = true; + case '\n': + if ( datnum_start && datnum_end && + ttitle_start && ttitle_end && + resnum_start && resnum_end ) // maybe changed for others than 2ch. + { + ++thread_count; + *tmp = '\0'; + + *ttitle_end = '\0'; + QString ttitle = sjis_codec->toUnicode( ttitle_start ); + + Thread * new_thread; + if ( !( new_thread = m_dict[ ttitle ] ) ) + { + new_thread = new Thread; + if ( ! new_thread ) break; + new_thread->name = ttitle; + m_dict.insert( ttitle, new_thread ); + } + + new_thread->sortkey = thread_count; + new_thread->board = this; + + if ( resnum_start && resnum_end && + ( resnum_end - resnum_start ) > 0 ) { + *resnum_end = '\0'; + new_thread->rescount = QString( resnum_start ).toInt(); + } + if ( datnum_end ) { + new_thread->url = QString( "%1://%2/test/read.cgi%3/%4/" ) + .arg( url.protocol() ) + .arg( url.host() ) + .arg( url.path(-1) ) + .arg( datnum_start ); + new_thread->dat = QString( "%1://%2%3/dat/%4.dat" ) + .arg( "k2ch" ) + .arg( url.host() ) + .arg( url.path(-1) ) + .arg( datnum_start ); + new_thread->datnumber = QString( datnum_start ); + } + + threadList.append( new_thread ); + } + + + ttitle_start = 0; + datnum_start = tmp + 1; + resnum_start = 0; + ttitle_end = 0; + datnum_end = 0; + resnum_end = 0; + + break; + + default: + break; + } // switch ( tmp ) + } // while ( .... ) + m_progress->setProgress( 100 ); + } // if ( ! job->error() ) + + delete m_array; + delete m_progress; + m_array = 0; + m_currentjob = 0; + + emit refreshCompleted( this ); +} + +void Thread::postMessage( const QString& name, const QString& mail, const QString& message ) +{ + QCString response; + emit postFinished( response ); +} +//#include "k2ch.moc.cpp" + +// vim:sw=4 diff --git a/k2ch_module/k2chtree_k2chitem/k2ch.h b/k2ch_module/k2chtree_k2chitem/k2ch.h new file mode 100644 index 0000000..c4244f6 --- /dev/null +++ b/k2ch_module/k2chtree_k2chitem/k2ch.h @@ -0,0 +1,147 @@ + +#ifndef K2CH_H +#define K2CH_H + +#include + +#include +#include +#include +#include + +#include +#include +#include + +class QProgressDialog; + +namespace K2ch { + + enum Method { + HTTP, + K2CH + }; + + class Element : public QObject { + Q_OBJECT + public: + Element() : QObject(), m_array(0), m_currentjob(0), m_progress(0) {} + virtual ~Element(); + + public slots: + virtual bool refreshChildList(); + signals: + void refreshCompleted( K2ch::Element *); + protected slots: + virtual void recieveData( KIO::Job *, const QByteArray& ); + + protected: + QCString * m_array; + KIO::TransferJob * m_currentjob; + QProgressDialog * m_progress; + }; + + class Base : public Element { + Q_OBJECT + public: + Base() : Element() {} + Base( const Base &_in ) : Element() { *this = _in; } + Base& operator= ( const Base &_in ) { + name = _in.name; topURL = _in.topURL; bbsmenu = _in.bbsmenu; + return *this; + } + + virtual ~Base(); + + QString name; + KURL topURL; + KURL bbsmenu; + QPtrList categoryList; + + public slots: + virtual bool refreshChildList(); + + protected slots: + void processBBSMenu( KIO::Job * ); + }; + + class Category : public Element { + Q_OBJECT + public: + Category() : Element() {} + Category( const QString &_name, struct Base * _base ) : Element() { name = _name; base = _base; } + Category( const Category &_in ) : Element() { *this = _in; } + Category& operator= ( const Category &_in ) { + name = _in.name; base = _in.base; + return *this; + } + + virtual ~Category(); + + QString name; + QPtrList boardList; + struct Base * base; + + public slots: + virtual bool refreshChildList(); + }; + + class Board : public Element { + Q_OBJECT + public: + Board() : Element(), m_dict( 509 ) {} + Board( const Board &_in ) : Element(), m_dict( 509 ) { *this = _in; } + Board& operator= ( const Board &_in ) { name = _in.name; url = _in.url; + subject_txt = _in.subject_txt; setting_txt = _in.setting_txt; + category = _in.category; + return *this; + } + + virtual ~Board(); + + QString name; + KURL url; + KURL subject_txt; + KURL setting_txt; + QPtrList threadList; + struct Category * category; + + public slots: + virtual bool refreshChildList(); + + protected slots: + void processSubject( KIO::Job * ); + + private: + QDict m_dict; + }; + + class Thread : public Element { + Q_OBJECT + public: + Thread() : Element() {} + Thread( const Thread &_in ) : Element() { *this = _in; prev_rescount = rescount; } + Thread& operator= ( const Thread &_in ) { name = _in.name; + sortkey = _in.sortkey; datnumber = _in.datnumber; rescount = _in.rescount; + url = _in.url; dat = _in.dat; board = _in.board; + return *this; + } + + QString name; + QString datnumber; + int sortkey; + int rescount; + int prev_rescount; + KURL url; + KURL dat; + struct Board * board; + + public slots: + void postMessage( const QString& name, const QString& mail, const QString& message ); + + signals: + void postFinished( const QCString& response ); + }; +} +#endif +// vim:sw=4 diff --git a/k2ch_module/k2chtree_k2chitem/k2chtree_item.cpp b/k2ch_module/k2chtree_k2chitem/k2chtree_item.cpp new file mode 100644 index 0000000..39f6367 --- /dev/null +++ b/k2ch_module/k2chtree_k2chitem/k2chtree_item.cpp @@ -0,0 +1,527 @@ + + +#include +#include + +#include +class QCursor; + +#include +class QWidget; +class QListView; +class KListView; +class KonqSidebarTree; + +#include +class QColorGroup; +class QPainter; + +#include +class KonqHistoryManager; + +#include +class QProgressDialog; + +#include +template class QDict; + +#include +class KXMLGUIClient; +class KonqXMLGUIClient; +class QPopupMenu; +class KonqPopupMenu; + +#include "k2chtree_item.h" + + +KonqSidebarK2chTreeItem::KonqSidebarK2chTreeItem( + KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem ) + : KonqSidebarTreeItem( parentItem, topLevelItem ) + , m_parentItem( parentItem ) + , m_topLevelItem( topLevelItem ) + , m_method( K2ch::HTTP ) + , m_menu( listView() ) + , m_collection( listView(), "K2chTreeItemCollection" ) + , m_lastModified( 0 ) + , m_currentjob( 0 ) +{ + KonqSidebarK2chTreeItem * k2ch_item = dynamic_cast( parentItem ); + if ( k2ch_item ) m_method = k2ch_item->m_method; +#if 0 + KStdAction::open( this, SLOT( open() ), &m_collection ); + + m_menu.insertItem( QString( i18n("open with K2ch") ), this, SLOT( openWithK2ch() ) ); + m_menu.insertItem( QString( i18n("Search") ), this, SLOT( ) ); + m_menu.insertItem( QString( i18n("Search") ), this, SLOT( ) ); +#endif + KAction * act; + act = KStdAction::open( this, SLOT( slotOpen() ), &m_collection ); + act->plug( &m_menu ); + act = new KAction( i18n("Create new window"), SmallIcon("window_new"), KShortcut(), + this, SLOT( slotOpenNewWindow() ), &m_collection, "window_new" ); + act->plug( &m_menu ); + act = new KAction( i18n("Close tree."), SmallIcon(""), KShortcut(), + this, SLOT( slotCloseTree() ), &m_collection, "close_tree" ); + act->plug( &m_menu ); +} + +void KonqSidebarK2chTreeItem::slotOpen() +{ emit tree()->openURLRequest( externalURL() ); } + +void KonqSidebarK2chTreeItem::slotOpenNewWindow() +{ emit tree()->createNewWindow( externalURL() ); } + +void KonqSidebarK2chTreeItem::slotCloseTree() +{ m_parentItem->setOpen(false); } + +void KonqSidebarK2chTreeItem::itemSelected() +{ + printf(" KonqSidebarK2chTreeItem::itemSelected() url=%s( K2ch::K2CH? %d)\n", externalURL().url().latin1(), ( m_method == K2ch::K2CH ) ); + if ( ! firstChild() ) + { + refreshChildList(); + } + + tree()->enableActions( true, true, true, false, false, true ); + printf(" size %d\n", sizeof( *this ) ); +} + +void KonqSidebarK2chTreeItem::rightButtonPressed() +{ + m_menu.exec( QCursor::pos() ); + + //emit tree()->popupMenu( QCursor::pos(), externalURL(), QString() ); + + //KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject( tree()->part() ); + //printf(" KParts::BrowserExtension: %p %p\n", static_cast(ext), dynamic_cast(module()) ); + //module()->popupMenu( dynamic_cast(module())->xmlGUIClient(), QCursor::pos(), externalURL(), QString() ); + +#if 0 + KFileItem file( S_IFREG, S_IRUSR | S_IRGRP | S_IROTH, externalURL(), true ); + KFileItemList flist; + flist.append( &file ); + KonqPopupMenu menu( KonqBookmarkManager::self(), flist, externalURL(), m_collection, 0 ); + menu.exec(); +#endif +} + +QDragObject * KonqSidebarK2chTreeItem::dragObject( QWidget * parent, bool ) +{ + KBookmarkDrag * drag = KBookmarkDrag::newDrag( makeKBookmark(), parent ); + return drag; +} + +KBookmark KonqSidebarK2chTreeItem::makeKBookmark() +{ + return KBookmark::standaloneBookmark( text(0), externalURL() ); +} + +void KonqSidebarK2chTreeItem::processStat( KIO::Job * job ) +{ + printf(" KonqSidebarK2chBoardItem::processStat(KIO::Job *job = %p )\n", static_cast(job) ); + if ( ! job->error() ) { + KIO::UDSEntry list = dynamic_cast(job)->statResult(); + KIO::UDSEntry::iterator it = list.begin(); + for( ; !(it == list.end()); ++it ) + { + printf(" "); + switch ( (*it).m_uds ) { + case KIO::UDS_MODIFICATION_TIME : + if ( (*it).m_long != m_lastModified ) + { + m_lastModified = (*it).m_long; + emit urlModified(); + } + break; + } + } + } + m_currentjob = 0; +} + + + + +KonqSidebarK2chBaseItem::KonqSidebarK2chBaseItem( + KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Base &base ) + : KonqSidebarK2chTreeItem( parentItem, topLevelItem ) + , m_base( 0 ) +{ + m_base = new K2ch::Base( base ); + if ( ! m_base ) return; + + setText( TITLE, m_base->name ); + setExpandable( false ); + QString icon = KonqFavIconMgr::iconForURL( m_base->topURL.url() ); + if ( ! icon.isEmpty() ) setPixmap( TITLE, SmallIcon( icon ) ); +} + +KonqSidebarK2chBaseItem::~KonqSidebarK2chBaseItem() +{ + if ( m_base ) delete m_base; +} + +KURL KonqSidebarK2chBaseItem::externalURL( K2ch::Method method ) const +{ + if ( ! m_base ) return 0; + KURL newURL; + switch ( method ) { + case K2ch::K2CH : + newURL = m_base->bbsmenu; + newURL.setProtocol( "k2ch" ); + break; + case K2ch::HTTP : + default : + newURL = m_base->topURL; + break; + } + return newURL; +} + +void KonqSidebarK2chBaseItem::refreshChildList(){ + setExpandable( false ); + QListViewItemIterator it( firstChild() ); + while( *it ) + { + takeItem( *it ); + ++it; + } + connect( m_base, SIGNAL( refreshCompleted( K2ch::Element* ) ), + this, SLOT( refreshCompleted( K2ch::Element* ) ) ); + m_base->refreshChildList(); +} + +void KonqSidebarK2chBaseItem::refreshCompleted( K2ch::Element * ) +{ + printf(" KonqSidebarK2chBaseItem::refreshCompleted()\n"); + if ( ! m_base ) return; + + QProgressDialog progress( tree() ); + progress.setLabel( new QLabel( QString( i18n("wait....") ), &progress ) ); + progress.show(); + + QPtrListIterator it_cate ( m_base->categoryList ); + progress.setTotalSteps( 1 + it_cate.count() ); + printf(" total step: %d\n", it_cate.count() ); + for ( it_cate.toLast() ; *it_cate; --it_cate ) + { + KonqSidebarTreeItem * cate_item = + new KonqSidebarK2chCategoryItem( this, m_topLevelItem, **it_cate ); + + QPtrListIterator it_board( (*it_cate)->boardList ); + for ( it_board.toLast() ; *it_board; --it_board ) + { + //KonqSidebarTreeItem * board_item = + new KonqSidebarK2chBoardItem( cate_item, m_topLevelItem, **it_board ); + } + progress.setProgress( 1 + progress.progress() ); + } + + progress.setProgress( 1 + progress.progress() ); + setExpandable( true ); +} + + + + +KonqSidebarK2chCategoryItem::KonqSidebarK2chCategoryItem( + KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Category &category ) + : KonqSidebarK2chTreeItem( parentItem, topLevelItem ) + , m_category( 0 ) +{ + m_category = new K2ch::Category( category ); + + if ( ! m_category ) return; + setText( TITLE, m_category->name ); + setPixmap( TITLE, SmallIcon( "folder" ) ); +} + +KonqSidebarK2chCategoryItem::~KonqSidebarK2chCategoryItem() +{ + if ( m_category ) delete m_category; +} + +void KonqSidebarK2chCategoryItem::setOpen( bool open ) +{ + if ( open ) setPixmap( TITLE, SmallIcon( "folder_open" ) ); + else setPixmap( TITLE, SmallIcon( "folder" ) ); + + KonqSidebarK2chTreeItem::setOpen( open ); +} + + + + +KonqSidebarK2chBoardItem::KonqSidebarK2chBoardItem( + KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Board &board ) + : KonqSidebarK2chTreeItem( parentItem, topLevelItem ) + , m_board( 0 ) + , m_dict( 0 ) +{ + m_board = new K2ch::Board( board ); + + if ( ! m_board ) return ; + setText( TITLE, m_board->name ); + setExpandable( false ); + QString icon = KonqFavIconMgr::iconForURL( m_board->url.url() ); + if ( ! icon.isEmpty() ) setPixmap( TITLE, SmallIcon( icon ) ); + connect( m_board, SIGNAL( refreshCompleted( K2ch::Element* ) ), + this, SLOT( refreshCompleted( K2ch::Element* ) ) ); + connect( this, SIGNAL( urlModified() ), + this, SLOT( refreshChildList() ) ); +} + +KonqSidebarK2chBoardItem::~KonqSidebarK2chBoardItem() +{ + if ( m_board ) delete m_board; + if ( m_dict ) { + m_dict->setAutoDelete( false ); + delete m_dict; + } +} + +KURL KonqSidebarK2chBoardItem::externalURL( const K2ch::Method method ) const +{ + if ( ! m_board ) return 0; + + KURL newURL; + switch ( method ) { + case K2ch::K2CH : + newURL = m_board->subject_txt; + newURL.setProtocol( "k2ch" ); + break; + case K2ch::HTTP : + default : + newURL = m_board->url; + break; + } + return newURL; +} + +void KonqSidebarK2chBoardItem::refreshChildList() +{ + printf(" KonqSidebarK2chBoardItem::refreshChildList()\n"); + if ( ! m_currentjob ) { + m_currentjob = reinterpret_cast(1); + setExpandable( false ); + if( ! m_board->refreshChildList() ) m_currentjob = 0; + } + + QString icon = KonqFavIconMgr::iconForURL( m_board->url.url() ); + if ( ! icon.isEmpty() ) setPixmap( TITLE, SmallIcon( icon ) ); +} + +void KonqSidebarK2chBoardItem::refreshCompleted( K2ch::Element* ) +{ + printf(" KonqSidebarK2chBoardItem::refreshCompleted()\n"); + //setOpen( false ); + + QProgressDialog progress( tree() ); + progress.setLabel( new QLabel( QString( i18n("Wait.") ), &progress ) ); + progress.show(); + + //QDict * m_dict = 0; + if ( ! m_dict ) { + // min 32 , max 32 //live + // min 300, max 300 //news + // min 500, max 600 // + int prime[] = { 31, 37, 41, 43, 307, 311, 313, 317, + 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, + 601, 607, 613, 617, + 1031 }; // prime numbers. + int thread_count = 5 + m_board->threadList.count(); + int * tmp = prime; + for( ; *tmp < thread_count || *tmp < 1031; ++tmp ); + m_dict = new QDict( *tmp ); + if ( ! m_dict ) return; + } + progress.setTotalSteps( 1 + childCount() + m_board->threadList.count() ); + int step = 0; + + { //remove all items. + KonqSidebarK2chThreadItem * item; + while( ( item = dynamic_cast(firstChild()) ) ) + { + takeItem( item ); + if ( (++step)%10 == 0 ) progress.setProgress( step ); + } + } + + { //insert items. + KonqSidebarK2chThreadItem * item; + QPtrListIterator it_thread( m_board->threadList ); + for ( it_thread.toFirst(); ! it_thread.atLast(); ++it_thread ) + { + if ( ( item = (*m_dict)[ (*it_thread)->name ] ) ) + { + insertItem( item ); + item->setThread( **it_thread ); + } else { + item = new KonqSidebarK2chThreadItem( this, m_topLevelItem, **it_thread ); + m_dict->insert( item->text( NAME_Sort ), item ); + //Memo: QDict use hash internally. + } + //progress.setProgress( 1 + progress.progress() ); + if ( ( (++step)%10 ) == 0 ) progress.setProgress( step ); + } + } + + sortChildItems( ASIS_Sort, true ); + progress.setProgress( ++step ); + setExpandable( true ); + //setOpen( true ); + m_currentjob = 0; +} + +void KonqSidebarK2chBoardItem::itemSelected() +{ + printf(" KonqSidebarK2chBoardItem::itemSelected()\n"); + printf(" size %d\n", sizeof( *this ) ); + KonqSidebarK2chTreeItem::itemSelected(); + checkUpdate(); +} + +void KonqSidebarK2chBoardItem::checkUpdate() +{ + if ( ! m_board ) return ; + printf("\n\n KonqSidebarK2chBoardItem::checkUpdate()\n"); + if ( ! m_currentjob ) + { + KIO::Job * job = KIO::stat( m_board->subject_txt ); + connect( job, SIGNAL( result(KIO::Job *) ), + this, SLOT( processStat(KIO::Job *) ) ); + } +} + + + + +KonqSidebarK2chThreadItem::KonqSidebarK2chThreadItem( + KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Thread & thread ) + : KonqSidebarK2chTreeItem( parentItem, topLevelItem ) + , m_thread( 0 ) +{ + m_thread = new K2ch::Thread( thread ); + initText(); + setExpandable( false ); + //QString icon = KonqFavIconMgr::iconForURL( m_thread->url.url() ); + //if ( ! icon.isEmpty() ) setPixmap( TITLE, SmallIcon( icon ) ); +} + +KonqSidebarK2chThreadItem::~KonqSidebarK2chThreadItem() +{ + if ( m_thread ) delete m_thread; +} + +void KonqSidebarK2chThreadItem::setThread( const K2ch::Thread &_in ) +{ + *m_thread = _in; + initText(); +} + +void KonqSidebarK2chThreadItem::initText() +{ + //setText( TITLE, m_thread->name ); + setText( TITLE, QString("%1: %2 (%3, new:%4)").arg( m_thread->sortkey,3 ).arg( m_thread->name ).arg( m_thread->rescount ).arg( m_thread->rescount - m_thread->prev_rescount ) ); + //setText( TITLE, QString(" %2 (%3)").arg( m_thread->name ).arg( m_thread->rescount ) ); + setText( ASIS_Sort, QString("%1").arg( m_thread->sortkey, 4 ) ); + setText( NAME_Sort, m_thread->name ); +} + +KURL KonqSidebarK2chThreadItem::externalURL() const +{ + switch ( m_method ) + { + case K2ch::K2CH : + default: + return externalURL( K2ch::K2CH ); + return 0; + case K2ch::HTTP : + return externalURL( K2ch::HTTP ); + } +} + +KURL KonqSidebarK2chThreadItem::externalURL( K2ch::Method method ) const +{ + KURL newURL; + switch ( method ) { + case K2ch::K2CH : + newURL = m_thread->dat; + //newURL.setRef( QString::number( m_thread->prev_rescount ) ); + newURL.setProtocol( "k2ch" ); + break; + case K2ch::HTTP : + default : + newURL = m_thread->url.url(-1).append("/%1-").arg( m_thread->rescount - 50 ); + break; + } + return newURL; +} + +void KonqSidebarK2chThreadItem::itemSelected() +{ + m_thread->prev_rescount = m_thread->rescount; + initText(); + KonqSidebarK2chTreeItem::itemSelected(); + //KitaThreadView * wgt = new KitaThreadView( 0 ); + //wgt->showThread( m_thread->dat, m_thread->board->url ); + //wgt->show(); +} + +void KonqSidebarK2chThreadItem::paintCell( QPainter *p, const QColorGroup & cg, int column, int width, int) +{ + + { + QColor bgcolor; + QColor txtcolor; + if( isSelected() ) + { + bgcolor = cg.highlight(); + txtcolor = cg.highlightedText(); + } else { + KonqHistoryList list( KonqHistoryManager::kself()->entries() ); + KURL k2ch = externalURL( K2ch::K2CH ); + KURL http = externalURL( K2ch::HTTP ); + k2ch.setRef(0); + http.setRef(0); + if ( list.findEntry( k2ch ) + || list.findEntry( http ) ) { + txtcolor = cg.linkVisited(); + } else { + txtcolor = cg.text(); + } + + if ( 0 ){ //will be configurable? + bgcolor = cg.base(); + } else { + bool b_isLighter = true; + if( (m_thread->sortkey)%2 ) + { + bgcolor = b_isLighter ? cg.midlight() : cg.midlight(); + } else { + bgcolor = b_isLighter ? cg.button() : cg.mid(); + } + } + } + + p->fillRect( 0, 0, width, height(), bgcolor ); + p->setPen( txtcolor ); + p->drawText( 0, height()-4, text(column) ); + if ( m_thread->rescount != m_thread->prev_rescount ) + { + p->drawPixmap( 0, 0, SmallIcon( "ok" ) ); + } + } +} + +//#include "k2chtree_item.moc.cpp" +// vim:sw=4 diff --git a/k2ch_module/k2chtree_k2chitem/k2chtree_item.h b/k2ch_module/k2chtree_k2chitem/k2chtree_item.h new file mode 100644 index 0000000..33d0e9c --- /dev/null +++ b/k2ch_module/k2chtree_k2chitem/k2chtree_item.h @@ -0,0 +1,181 @@ + +#ifndef K2CHTREE_ITEM_H +#define K2CHTREE_ITEM_H + +#include +#include +#include +#include +#include +#include + +#include +class QListViewItem; +class KonqSidebarTreeItem; + +#include +class KActionCollection; +class KAction; + +template class QDict; + +#include "k2ch.h" + +class KonqSidebarK2chTreeItem; +class KonqSidebarK2chBaseItem; +class KonqSidebarK2chCategoryItem; +class KonqSidebarK2chBoardItem; +class KonqSidebarK2chThreadItem; + +class KonqSidebarK2chTreeItem : public QObject, public KonqSidebarTreeItem +{ + Q_OBJECT +public: + KonqSidebarK2chTreeItem( KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem ); + virtual ~KonqSidebarK2chTreeItem() {}; + + virtual KURL externalURL() const { return externalURL( m_method ); }; + virtual KURL externalURL( const K2ch::Method ) const { return 0; }; + + virtual void setMethod ( const K2ch::Method new_method ) { m_method = new_method; } + virtual K2ch::Method method() const { return m_method; } + + virtual QDragObject * dragObject( QWidget *, bool move = false ); + + virtual void itemSelected(); + + virtual void rightButtonPressed(); + + enum Column { + TITLE = 0 + , ASIS_Sort = 1 + , NAME_Sort = 2 + }; +protected: + virtual KBookmark makeKBookmark(); + +protected slots: + virtual void refreshChildList() {}; + virtual void refreshCompleted( K2ch::Element *) {}; + virtual void processStat( KIO::Job * job ); + virtual void slotOpen(); + virtual void slotOpenNewWindow(); + virtual void slotCloseTree(); + +signals: + void urlModified(); + +protected: + KonqSidebarTreeItem * m_parentItem; + KonqSidebarTreeTopLevelItem * m_topLevelItem; + + K2ch::Method m_method; + + KPopupMenu m_menu; + KActionCollection m_collection; + + Q_UINT16 m_lastModified; + KIO::Job * m_currentjob; +}; + + +class KonqSidebarK2chBaseItem : public KonqSidebarK2chTreeItem +{ + Q_OBJECT +public: + KonqSidebarK2chBaseItem( KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Base &base ); + + virtual ~KonqSidebarK2chBaseItem(); + + K2ch::Base base() const { return *m_base; } + void setBase( const K2ch::Base &_in ) { *m_base = _in; } + + virtual KURL externalURL( const K2ch::Method ) const; + + +protected slots: + virtual void refreshChildList(); + virtual void refreshCompleted( K2ch::Element *); + +protected: + K2ch::Base * m_base; +}; + + +class KonqSidebarK2chCategoryItem : public KonqSidebarK2chTreeItem +{ +public: + KonqSidebarK2chCategoryItem( KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Category &category ); + + virtual ~KonqSidebarK2chCategoryItem(); + + K2ch::Category category() const { return *m_category; } + void setCategory( const K2ch::Category &_in ) { *m_category = _in; } + + virtual void setOpen( bool ); + +protected: + K2ch::Category * m_category; +}; + + +class KonqSidebarK2chBoardItem : public KonqSidebarK2chTreeItem +{ + Q_OBJECT +public: + KonqSidebarK2chBoardItem( KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Board &board ); + + virtual ~KonqSidebarK2chBoardItem(); + + K2ch::Board board() const { return *m_board; } + void setBoard( const K2ch::Board &_in ) { *m_board = _in; } + + virtual KURL externalURL( const K2ch::Method ) const; + + virtual void itemSelected(); + +protected slots: + virtual void refreshChildList(); + virtual void refreshCompleted( K2ch::Element *); + void checkUpdate(); + +protected: + K2ch::Board * m_board; + +private: + QDict * m_dict; +}; + + +class KonqSidebarK2chThreadItem : public KonqSidebarK2chTreeItem +{ +public: + KonqSidebarK2chThreadItem( KonqSidebarTreeItem *parentItem, + KonqSidebarTreeTopLevelItem *topLevelItem, + const K2ch::Thread &thread ); + + virtual ~KonqSidebarK2chThreadItem(); + + K2ch::Thread thread() const { return *m_thread; } + void setThread( const K2ch::Thread &_in ); + + virtual KURL externalURL() const; + virtual KURL externalURL( const K2ch::Method ) const; + + virtual void itemSelected(); + + virtual void paintCell( QPainter *p, const QColorGroup & cg, int column, int width, int align ); +protected: + K2ch::Thread * m_thread; + void initText(); +}; + +#endif +// vim:sw=4 diff --git a/k2ch_module/k2chtree_module.cpp b/k2ch_module/k2chtree_module.cpp new file mode 100644 index 0000000..5282403 --- /dev/null +++ b/k2ch_module/k2chtree_module.cpp @@ -0,0 +1,186 @@ + +#include "k2chtree_module.h" +#include "k2chtree_item.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +extern "C" { + + KonqSidebarTreeModule* create_konq_sidebartree_k2chtree( KonqSidebarTree* pa ) + { //will be called when this modules is loaded. + return new KonqSidebarK2chTreeModule( pa ); + } +} + +class QListView; +class KListView; +class QListViewItem; +class KListViewItem; + +#if 0 +static KStaticDeleter sd; +K2chSettings * KonqSidebarK2chModule::s_settings = 0L; +#endif + +KonqSidebarK2chTreeModule::KonqSidebarK2chTreeModule( KonqSidebarTree * parentTree, const char * name ) + : QObject( 0, name ), KonqSidebarTreeModule( parentTree ) + , m_topLevelItem( 0 ) + , m_base( 0 ) +{ +#if 0 + //Settings + if ( ! s_settings ) { + s_settings = sd.setObject( + new K2chSettings( 0 ) + ); + s_settings->readSettings( true ); + } + + connect( s_settings, SIGNAL( settingsChanged() ), SLOT( slotSettingsChanged() ) ); +#endif + + //ActionCollection + m_xmlguiclient = new KXMLGUIClient(); + //m_collection = new KActionCollection( this, "k2ch_sidebar actions" ); + m_collection = m_xmlguiclient->actionCollection(); + KStdAction::open( this, SLOT( open() ), m_collection ); + new KAction( i18n("Open with K2ch"), KShortcut(), this, SLOT( openWithK2ch() ) ); + //new KAction( i18n(""), "", 0, this, SLOT( slot() ), m_collection, "" ); + + //KParts::BrowserExtension::childObject( tree()->part() ); // not work + tree()->setSorting( -1 ); + + connect( tree(), SIGNAL( clicked(QListViewItem *) ), + this, SLOT( executeItem(QListViewItem *) ) ); +} + +KonqSidebarK2chTreeModule::~KonqSidebarK2chTreeModule(){ + + //delete m_collection; + + //All ListViewItem of child tree will be deleted, + //when m_topLevelItem (parent as QObject) is deleted. + //So we do nothig. + + if ( m_base ) delete m_base; +} + +void KonqSidebarK2chTreeModule::addTopLevelItem( KonqSidebarTreeTopLevelItem * item ) +{ + m_topLevelItem = item; + + + addBookmarkItem(); + + QStringList item_dirList = KGlobal::dirs()->findDirs("data","konq_k2chtree"); + if ( ! m_base ) { + m_base = new K2ch::Base; + QTextCodec *codec = QTextCodec::codecForName( "eucJP" ); + m_base->name = codec->toUnicode( "2¤Á¤ã¤ó¤Í¤ë¤Ø¤è¤¦¤³¤½" ); + m_base->topURL = "http://www.2ch.net/"; + m_base->bbsmenu = "http://www.ff.iij4u.or.jp/~ch2/bbsmenu.html"; + //m_base->topURL = 'url of desktopfile' + } + + KonqSidebarK2chBaseItem * base_item; + + base_item = new KonqSidebarK2chBaseItem( m_topLevelItem, m_topLevelItem, *m_base ); + base_item->setMethod( K2ch::HTTP ); + m_treeItemDict.insert( (static_cast( base_item ))->externalURL().url(-1), base_item ); + base_item->setText( 0, base_item->text( 0 ).prepend("[HTTP]") ); + + base_item = new KonqSidebarK2chBaseItem( m_topLevelItem, m_topLevelItem, *m_base ); + base_item->setMethod( K2ch::K2CH ); + m_treeItemDict.insert( (static_cast( base_item ))->externalURL().url(-1), base_item ); + base_item->setText( 0, base_item->text( 0 ).prepend("[K2ch]") ); + +} + +void KonqSidebarK2chTreeModule::addBookmarkItem() +{ + bool found = false; + KBookmarkManager * mgr = KonqBookmarkManager::self(); + KBookmarkGroup root = mgr->root(); + for ( KBookmark bk = root.first(); ! bk.isNull(); bk = root.next(bk) ) + { + if ( bk.isGroup() && bk.text() == "K2ch" ) { + found = true; + KonqSidebarBookmarkItem * item = new KonqSidebarBookmarkItem( m_topLevelItem, m_topLevelItem, bk, 0 ); + item->setText( 0, i18n("Bookmarks for K2ch") ); + fillBookmarkGroup( item, bk.toGroup() ); + } + + } + if ( ! found ) { + root.createNewFolder( mgr, "K2ch" ); + mgr->emitChanged( root ); + addBookmarkItem(); + } +} + +void KonqSidebarK2chTreeModule::fillBookmarkGroup( KonqSidebarTreeItem * parentItem, KBookmarkGroup group ) +{ + int n = 0; + for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk), ++n ) + { + if ( !bk.isSeparator() ) + { + KonqSidebarTreeItem * tree_item = m_treeItemDict[bk.url().url(-1)]; + + printf( "%p %s\n", static_cast(tree_item), bk.url().url().latin1() ); + if ( tree_item ) { + if ( typeid( tree_item ) == typeid( KonqSidebarK2chBoardItem *) ) + { + } else + if ( typeid( tree_item ) == typeid( KonqSidebarK2chThreadItem *) ) + { + } + } + + KonqSidebarBookmarkItem * bk_item = new KonqSidebarBookmarkItem( parentItem, m_topLevelItem, bk, n ); + if ( bk.isGroup() ) + { + KBookmarkGroup grp = bk.toGroup(); + fillBookmarkGroup( bk_item, grp ); + if ( bk_item->childCount() == 0 ) + { + bk_item->setExpandable( false ); + } + } else { + bk_item->setExpandable( false ); + } + } + } +} + +void KonqSidebarK2chTreeModule::followURL( const KURL & url ){ + KonqSidebarTreeItem * item = m_treeItemDict[ url.url(-1) ]; + printf( " KonqSidebarK2chTreeModule::followURL::\n" ); + printf( " url: %s, item: %p\n", url.url(-1).latin1(), (void*)item ); + if ( item ) { + tree()->ensureItemVisible( item ); + item->setSelected( true ); + } +} + +void KonqSidebarK2chTreeModule::openWithK2ch(){ + KonqSidebarK2chTreeItem * item = dynamic_cast(tree()->selectedItem()); + if ( item ) tree()->openURLRequest( item->externalURL( K2ch::K2CH ) ); +} + +void KonqSidebarK2chTreeModule::executeItem( QListViewItem * item ) +{ + KonqSidebarK2chTreeItem * k2ch_item = dynamic_cast(item); + if ( k2ch_item ) k2ch_item->itemSelected(); +} +//#include "k2chtree_module.moc.cpp" +// vim:sw=4 diff --git a/k2ch_module/k2chtree_module.desktop b/k2ch_module/k2chtree_module.desktop new file mode 100644 index 0000000..ffe7f28 --- /dev/null +++ b/k2ch_module/k2chtree_module.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Type=Services +Open=false +X-KDE-TreeModule=K2chTree_Module +X-KDE-TreeModule-Lib=konq_sidebartree_k2chtree +X-KDE-Default-URL= diff --git a/k2ch_module/k2chtree_module.h b/k2ch_module/k2chtree_module.h new file mode 100644 index 0000000..842f7b3 --- /dev/null +++ b/k2ch_module/k2chtree_module.h @@ -0,0 +1,62 @@ + +#ifndef K2CHTREE_MODULE_H +#define K2CHTREE_MODULE_H + +#include +class KonqSidebarTreeModule; + +#include +template class QDict; + +#include +class KAction; +class KActionCollection; + +//#include "k2ch_settings.h" +#include "k2ch.h" +#include "k2chtree_item.h" +#include "bookmark_item.h" + +class KonqSidebarK2chTreeModule : public QObject, public KonqSidebarTreeModule +{ + Q_OBJECT +public: + KonqSidebarK2chTreeModule( KonqSidebarTree * parentTree, const char * name = 0L ); + virtual ~KonqSidebarK2chTreeModule(); + + virtual void addTopLevelItem( KonqSidebarTreeTopLevelItem * item ); + + //virtual void openTopLevelItem( KonqSidebarTreeTopLevelItem * item ); + + virtual void followURL( const KURL & url ); + + KXMLGUIClient * xmlGUIClient() const { return m_xmlguiclient; } +public slots: + //virtual void rightButtonPressed( QListViewItem *, const QPoint &, int ); + + //Memo: + //KonqSidebarTree : KListView : QListView * KonqSidebarTreeModule::tree(); + // retrieve a Ptr of the QListView Widget. + +private slots: + void slotSettingsChanged() {}; + void openWithK2ch(); + void executeItem( QListViewItem * item ); + +protected: + KonqSidebarTreeTopLevelItem * m_topLevelItem; + K2ch::Base * m_base; //will be removed after release.: Get 'm_base' info. by *.desktop files and the 'm_base' stored as a child of the 'm_topLevelItem'. + QDict m_treeItemDict; // a QDict of QListViewItem-s : Key of the Dict is 'treeItem->externalURL().url()'. + + KActionCollection * m_collection; + KXMLGUIClient * m_xmlguiclient; + //static K2chSettings s_settings; + + void fillBookmarkGroup( KonqSidebarTreeItem * parentItem, KBookmarkGroup group ); + void addBookmarkItem(); + void addBaseItem( KonqSidebarK2chBaseItem * base_item ); + +}; + +#endif +// vim:sw=4 -- 2.11.0