24 #include <tqclipboard.h>
25 #include <tqeventloop.h>
29 #include <tqpopupmenu.h>
32 #include <dcopclient.h>
33 #include <tdeapplication.h>
34 #include <kcharsets.h>
35 #include <tdeconfig.h>
37 #include <tdeglobal.h>
38 #include <kiconloader.h>
39 #include <tdelocale.h>
40 #include <kurllabel.h>
42 #include "summarywidget.h"
44 SummaryWidget::SummaryWidget( TQWidget *parent,
const char *name )
45 : Kontact::Summary( parent, name ),
46 DCOPObject(
"NewsTickerPlugin" ), mLayout( 0 ), mFeedCounter( 0 )
48 TQVBoxLayout *vlay =
new TQVBoxLayout(
this, 3, 3 );
50 TQPixmap icon = TDEGlobal::iconLoader()->loadIcon(
"kontact_news",
51 TDEIcon::Desktop, TDEIcon::SizeMedium );
53 TQWidget *header = createHeader(
this, icon, i18n(
"News Feeds" ) );
54 vlay->addWidget( header );
59 bool dcopAvailable =
true;
60 if ( !kapp->dcopClient()->isApplicationRegistered(
"rssservice" ) ) {
61 if ( TDEApplication::startServiceByDesktopName(
"rssservice", TQStringList(), &error, &appID ) ) {
62 TQLabel *label =
new TQLabel( i18n(
"No rss dcop service available.\nYou need rssservice to use this plugin." ),
this );
63 vlay->addWidget( label, TQt::AlignHCenter );
64 dcopAvailable =
false;
68 mBaseWidget =
new TQWidget(
this,
"baseWidget" );
69 vlay->addWidget( mBaseWidget );
71 connect( &mTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( updateDocuments() ) );
75 connectDCOPSignal( 0, 0,
"documentUpdateError(DCOPRef,int)",
"documentUpdateError(DCOPRef, int)",
false );
80 connectDCOPSignal( 0, 0,
"added(TQString)",
"documentAdded(TQString)",
false );
81 connectDCOPSignal( 0, 0,
"removed(TQString)",
"documentRemoved(TQString)",
false );
84 int SummaryWidget::summaryHeight()
const
86 return ( mFeeds.count() == 0 ? 1 : mFeeds.count() );
89 void SummaryWidget::documentAdded( TQString )
94 void SummaryWidget::documentRemoved( TQString )
99 void SummaryWidget::configChanged()
106 void SummaryWidget::readConfig()
108 TDEConfig config(
"kcmkontactkntrc" );
109 config.setGroup(
"General" );
111 mUpdateInterval = config.readNumEntry(
"UpdateInterval", 600 );
112 mArticleCount = config.readNumEntry(
"ArticleCount", 4 );
115 void SummaryWidget::initDocuments()
119 DCOPRef dcopCall(
"rssservice",
"RSSService" );
121 dcopCall.call(
"list()" ).get( urls );
123 if ( urls.isEmpty() ) {
124 urls.append(
"http://www.kde.org/dotkdeorg.rdf" );
125 dcopCall.send(
"add(TQString)", urls[ 0 ] );
128 TQStringList::Iterator it;
129 for ( it = urls.begin(); it != urls.end(); ++it ) {
130 DCOPRef feedRef = dcopCall.call(
"document(TQString)", *it );
134 feedRef.call(
"title()" ).get( feed.title );
135 feedRef.call(
"link()" ).get( feed.url );
136 feedRef.call(
"pixmap()" ).get( feed.logo );
137 mFeeds.append( feed );
139 disconnectDCOPSignal(
"rssservice", feedRef.obj(),
"documentUpdated(DCOPRef)", 0 );
140 connectDCOPSignal(
"rssservice", feedRef.obj(),
"documentUpdated(DCOPRef)",
141 "documentUpdated(DCOPRef)",
false );
144 tqApp->eventLoop()->processEvents( TQEventLoop::ExcludeUserInput |
145 TQEventLoop::ExcludeSocketNotifiers );
151 void SummaryWidget::updateDocuments()
155 FeedList::Iterator it;
156 for ( it = mFeeds.begin(); it != mFeeds.end(); ++it )
157 (*it).ref.send(
"refresh()" );
159 mTimer.start( 1000 * mUpdateInterval );
162 void SummaryWidget::documentUpdated( DCOPRef feedRef )
166 int numArticles = feedRef.call(
"count()" );
167 for (
int i = 0; i < numArticles; ++i ) {
168 DCOPRef artRef = feedRef.call(
"article(int)", i );
172 tqApp->eventLoop()->processEvents( TQEventLoop::ExcludeUserInput |
173 TQEventLoop::ExcludeSocketNotifiers );
175 artRef.call(
"title()" ).get( title );
176 artRef.call(
"link()" ).get( url );
178 TQPair<TQString, KURL> article(title, KURL( url ));
179 map.append( article );
182 FeedList::Iterator it;
183 for ( it = mFeeds.begin(); it != mFeeds.end(); ++it )
184 if ( (*it).ref.obj() == feedRef.obj() ) {
186 if ( (*it).title.isEmpty() )
187 feedRef.call(
"title()" ).get( (*it).title );
188 if ( (*it).url.isEmpty() )
189 feedRef.call(
"link()" ).get( (*it).url );
190 if ( (*it).logo.isNull() )
191 feedRef.call(
"pixmap()" ).get( (*it).logo );
195 if ( mFeedCounter == mFeeds.count() ) {
201 void SummaryWidget::updateView()
203 mLabels.setAutoDelete(
true );
205 mLabels.setAutoDelete(
false );
208 mLayout =
new TQVBoxLayout( mBaseWidget, 3 );
211 boldFont.setBold(
true );
212 boldFont.setPointSize( boldFont.pointSize() + 2 );
214 FeedList::Iterator it;
215 for ( it = mFeeds.begin(); it != mFeeds.end(); ++it ) {
216 TQHBox *hbox =
new TQHBox( mBaseWidget );
217 mLayout->addWidget( hbox );
220 KURLLabel *urlLabel =
new KURLLabel( hbox );
221 urlLabel->setURL( (*it).url );
222 urlLabel->setPixmap( (*it).logo );
223 urlLabel->setMaximumSize( urlLabel->minimumSizeHint() );
224 mLabels.append( urlLabel );
226 connect( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
227 kapp, TQ_SLOT( invokeBrowser(
const TQString& ) ) );
228 connect( urlLabel, TQ_SIGNAL( rightClickedURL(
const TQString& ) ),
229 this, TQ_SLOT( rmbMenu(
const TQString& ) ) );
232 TQLabel *label =
new TQLabel( hbox );
233 label->setText( KCharsets::resolveEntities( (*it).title ) );
234 label->setAlignment( AlignLeft|AlignVCenter );
235 label->setFont( boldFont );
236 label->setIndent( 6 );
237 label->setMaximumSize( label->minimumSizeHint() );
238 mLabels.append( label );
240 hbox->setMaximumWidth( hbox->minimumSizeHint().width() );
244 ArticleMap articles = (*it).map;
245 ArticleMap::Iterator artIt;
247 for ( artIt = articles.begin(); artIt != articles.end() && numArticles < mArticleCount; ++artIt ) {
248 urlLabel =
new KURLLabel( (*artIt).second.url(), (*artIt).first, mBaseWidget );
249 urlLabel->installEventFilter(
this );
252 mLabels.append( urlLabel );
253 mLayout->addWidget( urlLabel );
255 connect( urlLabel, TQ_SIGNAL( leftClickedURL(
const TQString& ) ),
256 kapp, TQ_SLOT( invokeBrowser(
const TQString& ) ) );
257 connect( urlLabel, TQ_SIGNAL( rightClickedURL(
const TQString& ) ),
258 this, TQ_SLOT( rmbMenu(
const TQString& ) ) );
265 for ( TQLabel *label = mLabels.first(); label; label = mLabels.next() )
269 void SummaryWidget::documentUpdateError( DCOPRef feedRef,
int errorCode )
271 kdDebug() <<
" error while updating document, error code: " << errorCode << endl;
272 FeedList::Iterator it;
273 for ( it = mFeeds.begin(); it != mFeeds.end(); ++it ) {
274 if ( (*it).ref.obj() == feedRef.obj() ) {
280 if ( mFeedCounter == mFeeds.count() ) {
287 TQStringList SummaryWidget::configModules()
const
289 return "kcmkontactknt.desktop";
292 void SummaryWidget::updateSummary(
bool )
297 void SummaryWidget::rmbMenu(
const TQString& url )
300 menu.insertItem( i18n(
"Copy URL to Clipboard" ) );
301 int id = menu.exec( TQCursor::pos() );
303 kapp->clipboard()->setText( url, TQClipboard::Clipboard );
306 bool SummaryWidget::eventFilter( TQObject *obj, TQEvent* e )
308 if ( obj->inherits(
"KURLLabel" ) ) {
309 KURLLabel* label =
static_cast<KURLLabel*
>( obj );
310 if ( e->type() == TQEvent::Enter )
311 emit message( label->url() );
312 if ( e->type() == TQEvent::Leave )
313 emit message( TQString() );
316 return Kontact::Summary::eventFilter( obj, e );
319 #include "summarywidget.moc"