2 * feedsettingswidget.cpp
4 * Copyright (c) 2007 Frerich Raabe <raabe@kde.org>
6 * This program is distributed in the hope that it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8 * FOR A PARTICULAR PURPOSE. For licensing and distribution details, check the
9 * accompanying file 'COPYING'.
11 #include "feedsettingswidget.h"
12 #include "newsfeedmanager.h"
15 #include <QInputDialog>
16 #include <QMessageBox>
18 #include <QProgressDialog>
20 FeedSettingsWidget::FeedSettingsWidget( QWidget
*parent
)
22 m_downloadMessageBox( 0 )
25 ui
.feedListWidget
->addItems( Settings::feedUrls() );
26 connect( ui
.feedListWidget
, SIGNAL( itemSelectionChanged() ),
27 this, SLOT( feedItemChanged() ) );
28 connect( ui
.addButton
, SIGNAL( clicked() ),
29 this, SLOT( addButtonClicked() ) );
30 connect( ui
.removeButton
, SIGNAL( clicked() ),
31 this, SLOT( removeButtonClicked() ) );
33 connect( NewsFeedManager::self(), SIGNAL( feedLoaded( const QUrl
& ) ),
34 this, SLOT( feedLoaded( const QUrl
& ) ) );
36 if ( ui
.feedListWidget
->count() > 0 ) {
37 ui
.feedListWidget
->setCurrentRow( 0 );
42 QStringList
FeedSettingsWidget::feedUrls() const
45 for ( int i
= 0; i
< ui
.feedListWidget
->count(); ++i
) {
46 urls
.append( ui
.feedListWidget
->item( i
)->text() );
51 void FeedSettingsWidget::feedItemChanged()
53 QListWidgetItem
*item
= ui
.feedListWidget
->currentItem();
54 ui
.removeButton
->setEnabled( item
!= 0 );
59 QMap
<QUrl
, Syndication::FeedPtr
> availableFeeds
= NewsFeedManager::self()->availableFeeds();
60 QMap
<QUrl
, Syndication::FeedPtr
>::ConstIterator it
= availableFeeds
.find( item
->text() );
61 if ( it
== availableFeeds
.end() ) {
62 kDebug( 500 ) << "Don't have this item " << item
->text();
66 Syndication::FeedPtr feed
= *it
;
67 ui
.feedTitleLabel
->setText( feed
->title() );
68 ui
.feedUrlLabel
->setText( feed
->link() );
69 ui
.feedDescriptionLabel
->setText( feed
->description() );
73 void FeedSettingsWidget::addButtonClicked()
76 QString url
= QInputDialog::getText( this, i18n( "New Newsfeed" ),
77 i18n( "Enter the Address (URL) of the Newsfeed to be added:" ),
82 if ( ok
&& !url
.isEmpty() ) {
83 NewsFeedManager::self()->updateFeed( url
);
84 m_downloadMessageBox
= new QProgressDialog( i18n( "Please wait while the newsfeed is downloaded..." ),
89 m_downloadMessageBox
->exec();
93 void FeedSettingsWidget::removeButtonClicked()
95 int row
= ui
.feedListWidget
->currentRow();
96 delete ui
.feedListWidget
->takeItem( row
);
98 const int remainingItems
= ui
.feedListWidget
->count();
99 if ( remainingItems
> 0 ) {
100 if ( row
== remainingItems
) {
101 row
= remainingItems
- 1;
103 ui
.feedListWidget
->setCurrentRow( row
);
108 void FeedSettingsWidget::feedLoaded( const QUrl
&url
)
110 delete m_downloadMessageBox
;
111 m_downloadMessageBox
= 0;
113 QListWidgetItem
*item
= new QListWidgetItem( url
.toString() );
114 ui
.feedListWidget
->addItem( item
);
115 ui
.feedListWidget
->setCurrentItem( item
);
118 #include "feedsettingswidget.moc"