Send correct mouse wheel events when scaling is enabled.
[kdenetwork.git] / knewsticker / feedsettingswidget.cpp
blob020e934ad3e8162b6db71bad3eed4cf272fb3c52
1 /*
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"
13 #include "settings.h"
15 #include <KInputDialog>
16 #include <KProgressDialog>
18 FeedSettingsWidget::FeedSettingsWidget( QWidget *parent )
19 : QWidget( parent ),
20 m_downloadMessageBox( 0 )
22 ui.setupUi( this );
23 ui.feedListWidget->addItems( Settings::feedUrls() );
24 connect( ui.feedListWidget, SIGNAL( itemSelectionChanged() ),
25 this, SLOT( feedItemChanged() ) );
26 connect( ui.addButton, SIGNAL( clicked() ),
27 this, SLOT( addButtonClicked() ) );
28 connect( ui.removeButton, SIGNAL( clicked() ),
29 this, SLOT( removeButtonClicked() ) );
31 if ( ui.feedListWidget->count() > 0 ) {
32 ui.feedListWidget->setCurrentRow( 0 );
33 feedItemChanged();
36 ui.addButton->setIcon( KIcon( "list-add" ) );
37 ui.removeButton->setIcon( KIcon( "list-remove" ) );
40 QStringList FeedSettingsWidget::feedUrls() const
42 QStringList urls;
43 for ( int i = 0; i < ui.feedListWidget->count(); ++i ) {
44 urls.append( ui.feedListWidget->item( i )->text() );
46 return urls;
49 void FeedSettingsWidget::feedItemChanged()
51 QListWidgetItem *item = ui.feedListWidget->currentItem();
52 ui.removeButton->setEnabled( item != 0 );
53 if ( item == 0 ) {
54 return;
57 QMap<QUrl, Syndication::FeedPtr> availableFeeds = NewsFeedManager::self()->availableFeeds();
58 QMap<QUrl, Syndication::FeedPtr>::ConstIterator it = availableFeeds.find( item->text() );
59 if ( it == availableFeeds.end() ) {
60 kDebug( 500 ) << "Don't have this item " << item->text();
61 return;
64 Syndication::FeedPtr feed = *it;
65 ui.feedTitleLabel->setText( feed->title() );
66 ui.feedUrlLabel->setText( feed->link() );
67 ui.feedDescriptionLabel->setText( feed->description() );
71 void FeedSettingsWidget::addButtonClicked()
73 bool ok;
74 QString url = KInputDialog::getText( i18n( "New Newsfeed" ),
75 i18n( "Enter the Address (URL) of the Newsfeed to be added:" ),
76 QString(),
77 &ok,
78 this );
80 if ( ok && !url.isEmpty() ) {
81 m_addedFeedUrl = url;
82 connect( NewsFeedManager::self(), SIGNAL( feedLoaded( const QUrl & ) ),
83 this, SLOT( feedLoaded( const QUrl & ) ) );
85 NewsFeedManager::self()->updateFeed( url );
86 m_downloadMessageBox = new KProgressDialog( this,
87 i18n( "Please wait..." ),
88 i18n( "Please wait while the newsfeed is downloaded..." ) );
89 m_downloadMessageBox->progressBar()->setRange( 0, 0 );
90 m_downloadMessageBox->exec();
94 void FeedSettingsWidget::removeButtonClicked()
96 int row = ui.feedListWidget->currentRow();
97 delete ui.feedListWidget->takeItem( row );
99 const int remainingItems = ui.feedListWidget->count();
100 if ( remainingItems > 0 ) {
101 if ( row == remainingItems ) {
102 row = remainingItems - 1;
104 ui.feedListWidget->setCurrentRow( row );
109 void FeedSettingsWidget::feedLoaded( const QUrl &url )
111 if ( url.toString() != m_addedFeedUrl ) {
112 return;
115 disconnect( NewsFeedManager::self(), SIGNAL( feedLoaded( const QUrl & ) ),
116 this, SLOT( feedLoaded( const QUrl & ) ) );
118 delete m_downloadMessageBox;
119 m_downloadMessageBox = 0;
121 QListWidgetItem *item = new QListWidgetItem( url.toString() );
122 ui.feedListWidget->addItem( item );
123 ui.feedListWidget->setCurrentItem( item );
126 #include "feedsettingswidget.moc"