TDE network applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

feedbrowser.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "feedbrowser.h"
  2. #include <tdeaboutdata.h>
  3. #include <tdeapplication.h>
  4. #include <tdecmdlineargs.h>
  5. #include <kdebug.h>
  6. #include <kdialogbase.h>
  7. #include <tdelistview.h>
  8. #include <tdelocale.h>
  9. #include <dcopclient.h>
  10. #include <tqcstring.h>
  11. #include <tqdatastream.h>
  12. #include <tqvbox.h>
  13. CategoryItem::CategoryItem( TDEListView *parent, const TQString &category )
  14. : TDEListViewItem( parent ),
  15. m_category( category )
  16. {
  17. init();
  18. }
  19. CategoryItem::CategoryItem( TDEListViewItem *parent, const TQString &category )
  20. : TDEListViewItem( parent ),
  21. m_category( category )
  22. {
  23. init();
  24. }
  25. void CategoryItem::init()
  26. {
  27. m_populated = false;
  28. m_dcopIface = 0;
  29. setText( 0, m_category.mid( m_category.findRev( '/' ) + 1 ).replace( '_', ' ' ) );
  30. }
  31. void CategoryItem::setOpen( bool open )
  32. {
  33. if ( open && !m_populated ) {
  34. populate();
  35. m_populated = true;
  36. }
  37. TDEListViewItem::setOpen( open );
  38. }
  39. void CategoryItem::populate()
  40. {
  41. m_dcopIface = new DCOPRSSIface( this, "m_dcopIface" );
  42. connect( m_dcopIface, TQT_SIGNAL( gotCategories( const TQStringList & ) ),
  43. this, TQT_SLOT( gotCategories( const TQStringList & ) ) );
  44. m_dcopIface->getCategories( m_category );
  45. }
  46. void CategoryItem::gotCategories( const TQStringList &categories )
  47. {
  48. delete m_dcopIface;
  49. m_dcopIface = 0;
  50. TQStringList::ConstIterator it = categories.begin();
  51. TQStringList::ConstIterator end = categories.end();
  52. for ( ; it != end; ++it )
  53. new CategoryItem( this, *it );
  54. if ( !categories.isEmpty() )
  55. TDEListViewItem::setOpen( true );
  56. }
  57. DCOPRSSIface::DCOPRSSIface( TQObject *parent, const char *name ) :
  58. TQObject( parent, name ), DCOPObject( "FeedBrowser" )
  59. {
  60. connectDCOPSignal( "rssservice", "RSSQuery", "gotCategories(TQStringList)",
  61. "slotGotCategories(TQStringList)", false );
  62. }
  63. void DCOPRSSIface::getCategories( const TQString &cat )
  64. {
  65. TQByteArray data;
  66. TQDataStream stream( data, IO_WriteOnly );
  67. stream << cat;
  68. kapp->dcopClient()->send( "rssservice", "RSSQuery",
  69. "getCategories(TQString)", data );
  70. }
  71. void DCOPRSSIface::slotGotCategories( const TQStringList &categories )
  72. {
  73. emit gotCategories( categories );
  74. }
  75. FeedBrowserDlg::FeedBrowserDlg( TQWidget *parent, const char *name )
  76. : KDialogBase( parent, name, true, i18n( "DCOPRSS Feed Browser" ),
  77. Close, Close, true )
  78. {
  79. m_dcopIface = new DCOPRSSIface( TQT_TQOBJECT(this), "m_dcopIface" );
  80. connect( m_dcopIface, TQT_SIGNAL( gotCategories( const TQStringList & ) ),
  81. this, TQT_SLOT( gotTopCategories( const TQStringList & ) ) );
  82. TQVBox *mainWidget = makeVBoxMainWidget();
  83. m_feedList = new TDEListView( mainWidget, "m_feedList" );
  84. m_feedList->setAllColumnsShowFocus( true );
  85. m_feedList->setRootIsDecorated( true );
  86. m_feedList->addColumn( i18n( "Name" ) );
  87. connect( m_feedList, TQT_SIGNAL( executed( TQListViewItem * ) ),
  88. this, TQT_SLOT( itemSelected( TQListViewItem * ) ) );
  89. connect( m_feedList, TQT_SIGNAL( returnPressed( TQListViewItem * ) ),
  90. this, TQT_SLOT( itemSelected( TQListViewItem * ) ) );
  91. resize( 500, 400 );
  92. getTopCategories();
  93. }
  94. void FeedBrowserDlg::getTopCategories()
  95. {
  96. m_dcopIface->getCategories( "Top" );
  97. }
  98. void FeedBrowserDlg::gotTopCategories( const TQStringList &categories )
  99. {
  100. TQStringList::ConstIterator it = categories.begin();
  101. TQStringList::ConstIterator end = categories.end();
  102. for ( ; it != end; ++it )
  103. new CategoryItem( m_feedList, *it );
  104. }
  105. void FeedBrowserDlg::itemSelected( TQListViewItem *item )
  106. {
  107. item->setOpen( !item->isOpen() );
  108. }
  109. int main( int argc, char **argv )
  110. {
  111. TDEGlobal::locale()->setMainCatalogue( "dcoprss" );
  112. TDEAboutData aboutData( "feedbrowser", I18N_NOOP( "Feed Browser" ), "0.1" );
  113. TDECmdLineArgs::init( argc, argv, &aboutData );
  114. TDEApplication app;
  115. FeedBrowserDlg *dlg = new FeedBrowserDlg( 0 );
  116. app.setMainWidget( dlg );
  117. dlg->show();
  118. return app.exec();
  119. }
  120. #include "feedbrowser.moc"