summaryrefslogtreecommitdiffstats
path: root/dcoprss/feedbrowser.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /dcoprss/feedbrowser.cpp
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dcoprss/feedbrowser.cpp')
-rw-r--r--dcoprss/feedbrowser.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/dcoprss/feedbrowser.cpp b/dcoprss/feedbrowser.cpp
new file mode 100644
index 00000000..59a55040
--- /dev/null
+++ b/dcoprss/feedbrowser.cpp
@@ -0,0 +1,144 @@
+#include "feedbrowser.h"
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <klistview.h>
+#include <klocale.h>
+#include <dcopclient.h>
+
+#include <qcstring.h>
+#include <qdatastream.h>
+#include <qvbox.h>
+
+CategoryItem::CategoryItem( KListView *parent, const QString &category )
+ : KListViewItem( parent ),
+ m_category( category )
+{
+ init();
+}
+
+CategoryItem::CategoryItem( KListViewItem *parent, const QString &category )
+ : KListViewItem( parent ),
+ m_category( category )
+{
+ init();
+}
+
+void CategoryItem::init()
+{
+ m_populated = false;
+ m_dcopIface = 0;
+
+ setText( 0, m_category.mid( m_category.findRev( '/' ) + 1 ).replace( '_', ' ' ) );
+}
+
+void CategoryItem::setOpen( bool open )
+{
+ if ( open && !m_populated ) {
+ populate();
+ m_populated = true;
+ }
+ KListViewItem::setOpen( open );
+}
+
+void CategoryItem::populate()
+{
+ m_dcopIface = new DCOPRSSIface( this, "m_dcopIface" );
+ connect( m_dcopIface, SIGNAL( gotCategories( const QStringList & ) ),
+ this, SLOT( gotCategories( const QStringList & ) ) );
+ m_dcopIface->getCategories( m_category );
+}
+
+void CategoryItem::gotCategories( const QStringList &categories )
+{
+ delete m_dcopIface;
+ m_dcopIface = 0;
+
+ QStringList::ConstIterator it = categories.begin();
+ QStringList::ConstIterator end = categories.end();
+ for ( ; it != end; ++it )
+ new CategoryItem( this, *it );
+
+ if ( !categories.isEmpty() )
+ KListViewItem::setOpen( true );
+}
+
+DCOPRSSIface::DCOPRSSIface( QObject *parent, const char *name ) :
+ QObject( parent, name ), DCOPObject( "FeedBrowser" )
+{
+ connectDCOPSignal( "rssservice", "RSSQuery", "gotCategories(QStringList)",
+ "slotGotCategories(QStringList)", false );
+}
+
+void DCOPRSSIface::getCategories( const QString &cat )
+{
+ QByteArray data;
+ QDataStream stream( data, IO_WriteOnly );
+ stream << cat;
+ kapp->dcopClient()->send( "rssservice", "RSSQuery",
+ "getCategories(QString)", data );
+}
+
+void DCOPRSSIface::slotGotCategories( const QStringList &categories )
+{
+ emit gotCategories( categories );
+}
+
+FeedBrowserDlg::FeedBrowserDlg( QWidget *parent, const char *name )
+ : KDialogBase( parent, name, true, i18n( "DCOPRSS Feed Browser" ),
+ Close, Close, true )
+{
+ m_dcopIface = new DCOPRSSIface( this, "m_dcopIface" );
+ connect( m_dcopIface, SIGNAL( gotCategories( const QStringList & ) ),
+ this, SLOT( gotTopCategories( const QStringList & ) ) );
+
+ QVBox *mainWidget = makeVBoxMainWidget();
+
+ m_feedList = new KListView( mainWidget, "m_feedList" );
+ m_feedList->setAllColumnsShowFocus( true );
+ m_feedList->setRootIsDecorated( true );
+ m_feedList->addColumn( i18n( "Name" ) );
+ connect( m_feedList, SIGNAL( executed( QListViewItem * ) ),
+ this, SLOT( itemSelected( QListViewItem * ) ) );
+ connect( m_feedList, SIGNAL( returnPressed( QListViewItem * ) ),
+ this, SLOT( itemSelected( QListViewItem * ) ) );
+
+ resize( 500, 400 );
+
+ getTopCategories();
+}
+
+void FeedBrowserDlg::getTopCategories()
+{
+ m_dcopIface->getCategories( "Top" );
+}
+
+void FeedBrowserDlg::gotTopCategories( const QStringList &categories )
+{
+ QStringList::ConstIterator it = categories.begin();
+ QStringList::ConstIterator end = categories.end();
+ for ( ; it != end; ++it )
+ new CategoryItem( m_feedList, *it );
+}
+
+void FeedBrowserDlg::itemSelected( QListViewItem *item )
+{
+ item->setOpen( !item->isOpen() );
+}
+
+int main( int argc, char **argv )
+{
+ KGlobal::locale()->setMainCatalogue( "dcoprss" );
+ KAboutData aboutData( "feedbrowser", I18N_NOOP( "Feed Browser" ), "0.1" );
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KApplication app;
+ FeedBrowserDlg *dlg = new FeedBrowserDlg( 0 );
+ app.setMainWidget( dlg );
+ dlg->show();
+ return app.exec();
+}
+
+#include "feedbrowser.moc"