2007-04-05 23:26:30 +04:00
/*
* Bittorrent Client using Qt4 and libtorrent .
2007-07-14 18:31:59 +04:00
* Copyright ( C ) 2006 Christophe Dumez , Arnaud Demaiziere
2007-04-05 23:26:30 +04:00
*
2007-07-14 18:31:59 +04:00
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
2007-04-05 23:26:30 +04:00
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2007-07-14 18:31:59 +04:00
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
2009-04-05 21:00:55 +04:00
* In addition , as a special exception , the copyright holders give permission to
* link this program with the OpenSSL project ' s " OpenSSL " library ( or with
* modified versions of it that use the same license as the " OpenSSL " library ) ,
* and distribute the linked executables . You must obey the GNU General Public
* License in all respects for all of the code used other than " OpenSSL " . If you
* modify file ( s ) , you may extend this exception to your version of the file ( s ) ,
* but you are not obligated to do so . If you do not wish to do so , delete this
* exception statement from your version .
*
2007-07-14 18:31:59 +04:00
* Contact : chris @ qbittorrent . org arnaud @ qbittorrent . org
2007-04-05 23:26:30 +04:00
*/
# include <QDesktopServices>
# include <QInputDialog>
# include <QMenu>
# include <QStandardItemModel>
2007-07-23 16:12:55 +04:00
# include <QMessageBox>
2007-09-29 12:00:14 +04:00
# include <QString>
2009-08-21 11:40:57 +04:00
# include <QClipboard>
2009-08-23 12:10:56 +04:00
# include <QDragMoveEvent>
2007-04-05 23:26:30 +04:00
2009-08-21 11:40:57 +04:00
# include "rss_imp.h"
2010-10-10 15:03:09 +04:00
# include "feedlistwidget.h"
2010-10-09 18:06:35 +04:00
# include "qbtsession.h"
2010-05-17 18:57:45 +04:00
# include "cookiesdlg.h"
# include "preferences.h"
2010-10-31 15:35:07 +03:00
# include "rsssettingsdlg.h"
2010-10-16 21:39:03 +04:00
# include "rssmanager.h"
# include "rssfolder.h"
# include "rssarticle.h"
2012-08-18 19:43:20 +04:00
# include "rssparser.h"
2010-10-16 21:39:03 +04:00
# include "rssfeed.h"
2010-11-16 23:34:31 +03:00
# include "rsssettings.h"
2010-11-13 13:49:22 +03:00
# include "automatedrssdownloader.h"
2011-01-01 16:19:28 +03:00
# include "iconprovider.h"
2007-04-05 23:26:30 +04:00
2011-01-29 16:03:12 +03:00
namespace Article {
enum ArticleRoles {
TitleRole = Qt : : DisplayRole ,
IconRole = Qt : : DecorationRole ,
ColorRole = Qt : : ForegroundRole ,
IdRole = Qt : : UserRole + 1 ,
FeedUrlRole = Qt : : UserRole + 2
} ;
}
2009-09-01 21:24:47 +04:00
2009-08-21 11:40:57 +04:00
// display a right-click menu
2012-02-20 21:56:07 +04:00
void RSSImp : : displayRSSListMenu ( const QPoint & pos ) {
2012-02-20 21:30:53 +04:00
if ( ! m_feedList - > indexAt ( pos ) . isValid ( ) ) {
2009-08-22 06:19:40 +04:00
// No item under the mouse, clear selection
2011-01-29 16:44:56 +03:00
m_feedList - > clearSelection ( ) ;
2009-08-22 06:19:40 +04:00
}
2009-08-22 19:01:53 +04:00
QMenu myRSSListMenu ( this ) ;
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
if ( selectedItems . size ( ) > 0 ) {
2009-08-22 19:01:53 +04:00
myRSSListMenu . addAction ( actionUpdate ) ;
myRSSListMenu . addAction ( actionMark_items_read ) ;
myRSSListMenu . addSeparator ( ) ;
2012-02-20 21:30:53 +04:00
if ( selectedItems . size ( ) = = 1 ) {
if ( m_feedList - > getRSSItem ( selectedItems . first ( ) ) ! = m_rssManager ) {
2009-08-24 10:28:31 +04:00
myRSSListMenu . addAction ( actionRename ) ;
myRSSListMenu . addAction ( actionDelete ) ;
myRSSListMenu . addSeparator ( ) ;
2012-02-20 21:30:53 +04:00
if ( m_feedList - > isFolder ( selectedItems . first ( ) ) ) {
2009-08-24 10:28:31 +04:00
myRSSListMenu . addAction ( actionNew_folder ) ;
2010-05-17 18:57:45 +04:00
} else {
myRSSListMenu . addAction ( actionManage_cookies ) ;
}
2009-08-24 10:28:31 +04:00
}
2007-04-05 23:26:30 +04:00
}
2009-08-23 16:22:19 +04:00
myRSSListMenu . addAction ( actionNew_subscription ) ;
2012-02-20 21:30:53 +04:00
if ( m_feedList - > isFeed ( selectedItems . first ( ) ) ) {
2009-08-22 19:01:53 +04:00
myRSSListMenu . addSeparator ( ) ;
2009-08-23 16:22:19 +04:00
myRSSListMenu . addAction ( actionCopy_feed_URL ) ;
2009-08-21 13:06:57 +04:00
}
2009-08-21 11:40:57 +04:00
} else {
2009-08-22 19:01:53 +04:00
myRSSListMenu . addAction ( actionNew_subscription ) ;
myRSSListMenu . addAction ( actionNew_folder ) ;
myRSSListMenu . addSeparator ( ) ;
myRSSListMenu . addAction ( actionUpdate_all_feeds ) ;
2009-08-21 11:40:57 +04:00
}
2009-08-22 19:01:53 +04:00
myRSSListMenu . exec ( QCursor : : pos ( ) ) ;
2009-08-21 11:40:57 +04:00
}
2007-04-05 23:26:30 +04:00
2012-02-20 21:56:07 +04:00
void RSSImp : : displayItemsListMenu ( const QPoint & ) {
2009-08-21 11:40:57 +04:00
QMenu myItemListMenu ( this ) ;
2011-01-29 16:03:12 +03:00
QList < QListWidgetItem * > selectedItems = listArticles - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
if ( selectedItems . size ( ) > 0 ) {
2009-08-29 07:47:14 +04:00
bool has_attachment = false ;
2012-02-20 21:30:53 +04:00
foreach ( const QListWidgetItem * item , selectedItems ) {
2011-01-29 16:03:12 +03:00
qDebug ( " text(3) URL: %s " , qPrintable ( item - > data ( Article : : FeedUrlRole ) . toString ( ) ) ) ;
qDebug ( " text(2) TITLE: %s " , qPrintable ( item - > data ( Article : : TitleRole ) . toString ( ) ) ) ;
2012-02-20 21:30:53 +04:00
if ( m_feedList - > getRSSItemFromUrl ( item - > data ( Article : : FeedUrlRole ) . toString ( ) )
2012-02-19 18:38:41 +04:00
- > getItem ( item - > data ( Article : : IdRole ) . toString ( ) ) - > hasAttachment ( ) ) {
2009-08-29 07:47:14 +04:00
has_attachment = true ;
break ;
}
}
2012-02-20 21:30:53 +04:00
if ( has_attachment )
2009-08-29 07:47:14 +04:00
myItemListMenu . addAction ( actionDownload_torrent ) ;
2009-08-21 11:40:57 +04:00
myItemListMenu . addAction ( actionOpen_news_URL ) ;
}
myItemListMenu . exec ( QCursor : : pos ( ) ) ;
}
2007-04-05 23:26:30 +04:00
2010-05-17 18:57:45 +04:00
void RSSImp : : on_actionManage_cookies_triggered ( ) {
2011-01-29 16:44:56 +03:00
Q_ASSERT ( ! m_feedList - > selectedItems ( ) . empty ( ) ) ;
2010-05-17 18:57:45 +04:00
// Get feed hostname
2011-01-29 16:44:56 +03:00
QString feed_url = m_feedList - > getItemID ( m_feedList - > selectedItems ( ) . first ( ) ) ;
2012-05-20 17:03:10 +04:00
QString feed_hostname = QUrl : : fromEncoded ( feed_url . toUtf8 ( ) ) . host ( ) ;
2010-05-17 18:57:45 +04:00
qDebug ( " RSS Feed hostname is: %s " , qPrintable ( feed_hostname ) ) ;
Q_ASSERT ( ! feed_hostname . isEmpty ( ) ) ;
bool ok = false ;
2010-11-17 23:21:03 +03:00
RssSettings settings ;
QList < QByteArray > raw_cookies = CookiesDlg : : askForCookies ( this , settings . getHostNameCookies ( feed_hostname ) , & ok ) ;
2012-02-20 21:30:53 +04:00
if ( ok ) {
2012-05-20 17:03:10 +04:00
qDebug ( ) < < " Settings cookies for host name: " < < feed_hostname ;
2010-11-17 23:21:03 +03:00
settings . setHostNameCookies ( feed_hostname , raw_cookies ) ;
2010-05-17 18:57:45 +04:00
}
}
2009-08-22 19:26:39 +04:00
void RSSImp : : askNewFolder ( ) {
QTreeWidgetItem * parent_item = 0 ;
2012-02-19 20:53:10 +04:00
RssFolderPtr rss_parent ;
2012-02-20 21:30:53 +04:00
if ( m_feedList - > selectedItems ( ) . size ( ) > 0 ) {
2011-01-29 16:44:56 +03:00
parent_item = m_feedList - > selectedItems ( ) . at ( 0 ) ;
2012-02-19 20:53:10 +04:00
rss_parent = qSharedPointerDynamicCast < RssFolder > ( m_feedList - > getRSSItem ( parent_item ) ) ;
Q_ASSERT ( rss_parent ) ;
2009-08-23 16:22:19 +04:00
} else {
2011-01-29 16:44:56 +03:00
rss_parent = m_rssManager ;
2009-08-22 19:26:39 +04:00
}
bool ok ;
2009-08-23 16:22:19 +04:00
QString new_name = QInputDialog : : getText ( this , tr ( " Please choose a folder name " ) , tr ( " Folder name: " ) , QLineEdit : : Normal , tr ( " New folder " ) , & ok ) ;
2012-02-20 21:30:53 +04:00
if ( ok ) {
2012-08-19 16:48:28 +04:00
RssFolderPtr newFolder = rss_parent - > addFolder ( new_name ) ;
QTreeWidgetItem * folderItem = createFolderListItem ( newFolder ) ;
2012-02-20 21:30:53 +04:00
if ( parent_item )
2012-08-19 16:48:28 +04:00
parent_item - > addChild ( folderItem ) ;
2009-08-22 19:26:39 +04:00
else
2012-08-19 16:48:28 +04:00
m_feedList - > addTopLevelItem ( folderItem ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget
2012-08-19 16:48:28 +04:00
m_feedList - > itemAdded ( folderItem , newFolder ) ;
2009-08-22 19:33:31 +04:00
// Expand parent folder to display new folder
2012-02-20 21:30:53 +04:00
if ( parent_item )
2009-08-23 12:10:56 +04:00
parent_item - > setExpanded ( true ) ;
2011-01-29 16:44:56 +03:00
m_rssManager - > saveStreamList ( ) ;
2009-08-22 19:26:39 +04:00
}
}
2011-01-29 16:44:56 +03:00
void RSSImp : : displayOverwriteError ( const QString & filename ) {
2009-08-24 08:01:26 +04:00
QMessageBox : : warning ( this , tr ( " Overwrite attempt " ) ,
2009-08-24 10:28:31 +04:00
tr ( " You cannot overwrite %1 item. " , " You cannot overwrite myFolder item. " ) . arg ( filename ) ,
QMessageBox : : Ok ) ;
2009-08-24 08:01:26 +04:00
}
2009-08-21 11:40:57 +04:00
// add a stream by a button
2009-08-22 06:19:40 +04:00
void RSSImp : : on_newFeedButton_clicked ( ) {
2009-08-23 16:22:19 +04:00
// Determine parent folder for new feed
2009-08-24 11:57:56 +04:00
QTreeWidgetItem * parent_item = 0 ;
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selected_items = m_feedList - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
if ( ! selected_items . empty ( ) ) {
2009-08-23 16:22:19 +04:00
parent_item = selected_items . first ( ) ;
2009-08-24 11:57:56 +04:00
// Consider the case where the user clicked on Unread item
2012-02-20 21:30:53 +04:00
if ( parent_item = = m_feedList - > stickyUnreadItem ( ) ) {
2009-08-24 11:57:56 +04:00
parent_item = 0 ;
2009-08-24 12:17:45 +04:00
} else {
2012-07-11 21:10:15 +04:00
if ( ! m_feedList - > isFolder ( parent_item ) )
2009-08-24 12:17:45 +04:00
parent_item = parent_item - > parent ( ) ;
}
2009-08-24 11:57:56 +04:00
}
2012-02-19 20:53:10 +04:00
RssFolderPtr rss_parent ;
2012-02-20 21:30:53 +04:00
if ( parent_item ) {
2012-02-19 20:53:10 +04:00
rss_parent = qSharedPointerCast < RssFolder > ( m_feedList - > getRSSItem ( parent_item ) ) ;
2009-08-23 16:22:19 +04:00
} else {
2011-01-29 16:44:56 +03:00
rss_parent = m_rssManager ;
2009-08-23 16:22:19 +04:00
}
// Ask for feed URL
2009-08-22 06:19:40 +04:00
bool ok ;
QString clip_txt = qApp - > clipboard ( ) - > text ( ) ;
QString default_url = " http:// " ;
2012-02-20 21:30:53 +04:00
if ( clip_txt . startsWith ( " http:// " , Qt : : CaseInsensitive ) | | clip_txt . startsWith ( " https:// " , Qt : : CaseInsensitive ) | | clip_txt . startsWith ( " ftp:// " , Qt : : CaseInsensitive ) ) {
2009-08-22 06:19:40 +04:00
default_url = clip_txt ;
}
QString newUrl = QInputDialog : : getText ( this , tr ( " Please type a rss stream url " ) , tr ( " Stream URL: " ) , QLineEdit : : Normal , default_url , & ok ) ;
2012-02-20 21:30:53 +04:00
if ( ok ) {
2009-08-22 06:19:40 +04:00
newUrl = newUrl . trimmed ( ) ;
2012-02-20 21:56:07 +04:00
if ( ! newUrl . isEmpty ( ) ) {
2012-02-20 21:30:53 +04:00
if ( m_feedList - > hasFeed ( newUrl ) ) {
2009-08-22 06:19:40 +04:00
QMessageBox : : warning ( this , tr ( " qBittorrent " ) ,
tr ( " This rss feed is already in the list. " ) ,
QMessageBox : : Ok ) ;
return ;
}
2012-02-19 20:53:10 +04:00
RssFeedPtr stream = rss_parent - > addStream ( m_rssManager . data ( ) , newUrl ) ;
2009-08-23 16:22:19 +04:00
// Create TreeWidget item
2009-08-24 12:03:28 +04:00
QTreeWidgetItem * item ;
2012-02-20 21:30:53 +04:00
if ( parent_item )
2009-08-24 12:03:28 +04:00
item = new QTreeWidgetItem ( parent_item ) ;
else
2011-01-29 16:44:56 +03:00
item = new QTreeWidgetItem ( m_feedList ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget
2011-01-29 16:44:56 +03:00
m_feedList - > itemAdded ( item , stream ) ;
2009-08-23 16:22:19 +04:00
// Set text
2011-01-27 20:18:56 +03:00
item - > setText ( 0 , stream - > displayName ( ) + QString : : fromUtf8 ( " (0) " ) ) ;
2009-08-22 06:19:40 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
2009-08-22 18:06:05 +04:00
stream - > refresh ( ) ;
2011-01-29 16:44:56 +03:00
m_rssManager - > saveStreamList ( ) ;
2009-08-22 06:19:40 +04:00
}
}
2009-08-21 11:40:57 +04:00
}
2007-04-15 23:06:19 +04:00
2009-08-21 11:40:57 +04:00
// delete a stream by a button
2009-08-22 18:06:05 +04:00
void RSSImp : : deleteSelectedItems ( ) {
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
if ( selectedItems . size ( ) = = 0 ) return ;
2009-08-23 16:22:19 +04:00
int ret ;
2012-02-20 21:30:53 +04:00
if ( selectedItems . size ( ) > 1 )
2009-08-23 16:22:19 +04:00
ret = QMessageBox : : question ( this , tr ( " Are you sure? -- qBittorrent " ) , tr ( " Are you sure you want to delete these elements from the list? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
else
ret = QMessageBox : : question ( this , tr ( " Are you sure? -- qBittorrent " ) , tr ( " Are you sure you want to delete this element from the list? " ) ,
tr ( " &Yes " ) , tr ( " &No " ) ,
QString ( ) , 0 , 1 ) ;
2012-02-20 21:30:53 +04:00
if ( ! ret ) {
2012-02-20 21:56:07 +04:00
foreach ( QTreeWidgetItem * item , selectedItems ) {
if ( m_feedList - > currentFeed ( ) = = item ) {
2007-08-03 18:37:56 +04:00
textBrowser - > clear ( ) ;
2011-01-29 16:03:12 +03:00
m_currentArticle = 0 ;
listArticles - > clear ( ) ;
2007-04-05 23:26:30 +04:00
}
2012-02-19 20:53:10 +04:00
RssFilePtr rss_item = m_feedList - > getRSSItem ( item ) ;
2011-10-05 19:41:23 +04:00
QTreeWidgetItem * parent = item - > parent ( ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget
2011-01-29 16:44:56 +03:00
m_feedList - > itemAboutToBeRemoved ( item ) ;
2009-08-23 16:22:19 +04:00
// Actually delete the item
2011-01-27 21:03:28 +03:00
rss_item - > parent ( ) - > removeChild ( rss_item - > id ( ) ) ;
2009-08-22 07:00:31 +04:00
delete item ;
2011-10-05 19:41:23 +04:00
// Update parents count
while ( parent & & parent ! = m_feedList - > invisibleRootItem ( ) ) {
updateItemInfos ( parent ) ;
parent = parent - > parent ( ) ;
}
2012-08-18 19:43:20 +04:00
// Clear feed data from RSS parser (possible caching).
RssFeed * rssFeed = dynamic_cast < RssFeed * > ( rss_item . data ( ) ) ;
if ( rssFeed ) {
m_rssManager - > rssParser ( ) - > clearFeedData ( rssFeed - > url ( ) ) ;
}
2007-04-05 23:26:30 +04:00
}
2011-01-29 16:44:56 +03:00
m_rssManager - > saveStreamList ( ) ;
2009-08-29 08:06:25 +04:00
// Update Unread items
2011-01-29 16:44:56 +03:00
updateItemInfos ( m_feedList - > stickyUnreadItem ( ) ) ;
2009-08-21 11:40:57 +04:00
}
}
2007-04-05 23:26:30 +04:00
2009-08-23 18:56:44 +04:00
void RSSImp : : loadFoldersOpenState ( ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( " qBittorrent " , " qBittorrent " ) ;
2009-08-23 18:56:44 +04:00
settings . beginGroup ( " Rss " ) ;
2010-06-05 22:59:05 +04:00
QStringList open_folders = settings . value ( " open_folders " , QStringList ( ) ) . toStringList ( ) ;
2009-08-23 18:56:44 +04:00
settings . endGroup ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( QString var_path , open_folders ) {
2010-06-05 22:59:05 +04:00
QStringList path = var_path . split ( " \\ " ) ;
2009-08-23 18:56:44 +04:00
QTreeWidgetItem * parent = 0 ;
2012-02-20 21:30:53 +04:00
foreach ( QString name , path ) {
2009-08-23 18:56:44 +04:00
int nbChildren = 0 ;
2012-02-20 21:30:53 +04:00
if ( parent )
2009-08-23 18:56:44 +04:00
nbChildren = parent - > childCount ( ) ;
else
2011-01-29 16:44:56 +03:00
nbChildren = m_feedList - > topLevelItemCount ( ) ;
2012-02-20 21:30:53 +04:00
for ( int i = 0 ; i < nbChildren ; + + i ) {
2009-08-23 18:56:44 +04:00
QTreeWidgetItem * child ;
2012-02-20 21:30:53 +04:00
if ( parent )
2009-08-23 18:56:44 +04:00
child = parent - > child ( i ) ;
else
2011-01-29 16:44:56 +03:00
child = m_feedList - > topLevelItem ( i ) ;
2012-02-20 21:30:53 +04:00
if ( m_feedList - > getRSSItem ( child ) - > id ( ) = = name ) {
2009-08-23 18:56:44 +04:00
parent = child ;
parent - > setExpanded ( true ) ;
2010-03-04 23:19:25 +03:00
qDebug ( " expanding folder %s " , qPrintable ( name ) ) ;
2009-08-23 18:56:44 +04:00
break ;
}
}
}
}
}
void RSSImp : : saveFoldersOpenState ( ) {
2010-06-05 22:59:05 +04:00
QStringList open_folders ;
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > items = m_feedList - > getAllOpenFolders ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( QTreeWidgetItem * item , items ) {
2011-01-29 16:44:56 +03:00
QString path = m_feedList - > getItemPath ( item ) . join ( " \\ " ) ;
2010-03-04 23:19:25 +03:00
qDebug ( " saving open folder: %s " , qPrintable ( path ) ) ;
2009-08-23 18:56:44 +04:00
open_folders < < path ;
}
2010-07-16 19:03:18 +04:00
QIniSettings settings ( " qBittorrent " , " qBittorrent " ) ;
2009-08-23 18:56:44 +04:00
settings . beginGroup ( " Rss " ) ;
settings . setValue ( " open_folders " , open_folders ) ;
settings . endGroup ( ) ;
}
2009-08-21 11:40:57 +04:00
// refresh all streams by a button
2012-08-19 16:12:08 +04:00
void RSSImp : : refreshAllFeeds ( ) {
2012-02-20 21:30:53 +04:00
foreach ( QTreeWidgetItem * item , m_feedList - > getAllFeedItems ( ) ) {
2009-08-23 17:05:47 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
}
2011-01-29 16:44:56 +03:00
m_rssManager - > refresh ( ) ;
2009-08-21 11:40:57 +04:00
}
2007-09-09 15:31:51 +04:00
2012-08-19 16:00:07 +04:00
void RSSImp : : downloadSelectedTorrents ( ) {
2011-01-29 16:03:12 +03:00
QList < QListWidgetItem * > selected_items = listArticles - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QListWidgetItem * item , selected_items ) {
2012-02-19 18:38:41 +04:00
RssArticlePtr article = m_feedList - > getRSSItemFromUrl ( item - > data ( Article : : FeedUrlRole ) . toString ( ) )
2011-01-29 16:03:12 +03:00
- > getItem ( item - > data ( Article : : IdRole ) . toString ( ) ) ;
2012-06-24 11:27:32 +04:00
2012-08-19 16:00:07 +04:00
QString torrentLink = article - > torrentUrl ( ) ;
2012-06-24 11:27:32 +04:00
// Check if it is a magnet link
if ( torrentLink . startsWith ( " magnet: " , Qt : : CaseInsensitive ) )
QBtSession : : instance ( ) - > addMagnetInteractive ( torrentLink ) ;
else {
// Load possible cookies
QList < QNetworkCookie > cookies ;
QString feed_url = m_feedList - > getItemID ( m_feedList - > selectedItems ( ) . first ( ) ) ;
QString feed_hostname = QUrl : : fromEncoded ( feed_url . toUtf8 ( ) ) . host ( ) ;
const QList < QByteArray > raw_cookies = RssSettings ( ) . getHostNameCookies ( feed_hostname ) ;
foreach ( const QByteArray & raw_cookie , raw_cookies ) {
QList < QByteArray > cookie_parts = raw_cookie . split ( ' = ' ) ;
if ( cookie_parts . size ( ) = = 2 ) {
qDebug ( " Loading cookie: %s = %s " , cookie_parts . first ( ) . constData ( ) , cookie_parts . last ( ) . constData ( ) ) ;
cookies < < QNetworkCookie ( cookie_parts . first ( ) , cookie_parts . last ( ) ) ;
}
2012-05-20 17:03:10 +04:00
}
2012-06-24 11:27:32 +04:00
qDebug ( " Loaded %d cookies for RSS item \n " , cookies . size ( ) ) ;
QBtSession : : instance ( ) - > downloadFromUrl ( torrentLink , cookies ) ;
2009-08-29 07:47:14 +04:00
}
2009-08-21 11:40:57 +04:00
}
}
2007-04-05 23:26:30 +04:00
2012-08-19 16:48:28 +04:00
// open the url of the selected RSS articles in the Web browser
void RSSImp : : openSelectedArticlesUrls ( ) {
2011-01-29 16:03:12 +03:00
QList < QListWidgetItem * > selected_items = listArticles - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
foreach ( const QListWidgetItem * item , selected_items ) {
2012-02-19 18:38:41 +04:00
RssArticlePtr news = m_feedList - > getRSSItemFromUrl ( item - > data ( Article : : FeedUrlRole ) . toString ( ) )
2011-01-29 16:03:12 +03:00
- > getItem ( item - > data ( Article : : IdRole ) . toString ( ) ) ;
2012-02-19 18:38:41 +04:00
const QString link = news - > link ( ) ;
2012-02-20 21:30:53 +04:00
if ( ! link . isEmpty ( ) )
2009-08-21 11:40:57 +04:00
QDesktopServices : : openUrl ( QUrl ( link ) ) ;
}
}
2007-08-03 18:37:56 +04:00
2009-08-23 13:05:36 +04:00
//right-click on stream : give it an alias
2012-08-19 16:48:28 +04:00
void RSSImp : : renameSelectedRssFile ( ) {
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2009-08-21 11:40:57 +04:00
Q_ASSERT ( selectedItems . size ( ) = = 1 ) ;
2012-08-19 16:48:28 +04:00
QTreeWidgetItem * item = selectedItems . first ( ) ;
2012-02-19 20:53:10 +04:00
RssFilePtr rss_item = m_feedList - > getRSSItem ( item ) ;
2009-08-21 11:40:57 +04:00
bool ok ;
2009-08-23 16:22:19 +04:00
QString newName ;
do {
2011-01-29 16:44:56 +03:00
newName = QInputDialog : : getText ( this , tr ( " Please choose a new name for this RSS feed " ) , tr ( " New feed name: " ) , QLineEdit : : Normal , m_feedList - > getRSSItem ( item ) - > displayName ( ) , & ok ) ;
2009-08-23 17:05:47 +04:00
// Check if name is already taken
2012-02-20 21:30:53 +04:00
if ( ok ) {
if ( rss_item - > parent ( ) - > hasChild ( newName ) ) {
2009-12-01 22:28:45 +03:00
QMessageBox : : warning ( 0 , tr ( " Name already in use " ) , tr ( " This name is already used by another item, please choose another one. " ) ) ;
ok = false ;
}
} else {
return ;
2009-08-23 17:05:47 +04:00
}
2012-08-19 16:48:28 +04:00
} while ( ! ok ) ;
2009-12-01 22:28:45 +03:00
// Rename item
2011-01-27 21:03:28 +03:00
rss_item - > rename ( newName ) ;
2009-12-01 22:28:45 +03:00
// Update TreeWidget
updateItemInfos ( item ) ;
2009-08-21 11:40:57 +04:00
}
2007-04-06 02:38:46 +04:00
2012-08-19 16:48:28 +04:00
// right-click on stream : refresh it
2009-08-23 17:20:26 +04:00
void RSSImp : : refreshSelectedItems ( ) {
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2012-02-20 21:56:07 +04:00
foreach ( QTreeWidgetItem * item , selectedItems ) {
2012-02-19 20:53:10 +04:00
RssFilePtr file = m_feedList - > getRSSItem ( item ) ;
2009-08-23 17:20:26 +04:00
// Update icons
2012-02-20 21:30:53 +04:00
if ( item = = m_feedList - > stickyUnreadItem ( ) ) {
2012-08-19 16:12:08 +04:00
refreshAllFeeds ( ) ;
return ;
2009-08-24 12:12:42 +04:00
} else {
2012-08-19 16:12:08 +04:00
if ( ! file - > refresh ( ) )
continue ;
// Update UI
2012-02-19 20:53:10 +04:00
if ( qSharedPointerDynamicCast < RssFeed > ( file ) ) {
2012-08-18 19:06:29 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
2012-02-19 20:53:10 +04:00
} else if ( qSharedPointerDynamicCast < RssFolder > ( file ) ) {
2009-08-24 12:12:42 +04:00
// Update feeds in the folder
2012-08-19 16:12:08 +04:00
foreach ( QTreeWidgetItem * feed , m_feedList - > getAllFeedItems ( item ) )
2012-08-18 19:06:29 +04:00
feed - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
2009-08-24 12:12:42 +04:00
}
2009-08-23 17:20:26 +04:00
}
2009-08-21 11:40:57 +04:00
}
}
2007-04-05 23:26:30 +04:00
2009-08-21 11:40:57 +04:00
void RSSImp : : copySelectedFeedsURL ( ) {
QStringList URLs ;
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2009-08-21 11:40:57 +04:00
QTreeWidgetItem * item ;
2012-02-20 21:56:07 +04:00
foreach ( item , selectedItems ) {
2012-02-20 21:30:53 +04:00
if ( m_feedList - > isFeed ( item ) )
2011-01-29 16:44:56 +03:00
URLs < < m_feedList - > getItemID ( item ) ;
2009-08-21 11:40:57 +04:00
}
qApp - > clipboard ( ) - > setText ( URLs . join ( " \n " ) ) ;
}
2007-04-05 23:26:30 +04:00
2009-08-22 06:19:40 +04:00
void RSSImp : : on_markReadButton_clicked ( ) {
2011-01-29 16:44:56 +03:00
QList < QTreeWidgetItem * > selectedItems = m_feedList - > selectedItems ( ) ;
2012-08-19 16:48:28 +04:00
foreach ( QTreeWidgetItem * item , selectedItems ) {
2012-02-19 20:53:10 +04:00
RssFilePtr rss_item = m_feedList - > getRSSItem ( item ) ;
2012-08-19 16:48:28 +04:00
Q_ASSERT ( rss_item ) ;
2011-01-27 20:18:56 +03:00
rss_item - > markAsRead ( ) ;
2009-08-24 10:35:15 +04:00
updateItemInfos ( item ) ;
2009-08-21 11:40:57 +04:00
}
2012-08-19 16:48:28 +04:00
// Update article list
if ( ! selectedItems . isEmpty ( ) )
2012-08-19 15:55:30 +04:00
populateArticleList ( m_feedList - > currentItem ( ) ) ;
2009-08-21 11:40:57 +04:00
}
2007-08-03 18:37:56 +04:00
2012-08-19 16:48:28 +04:00
QTreeWidgetItem * RSSImp : : createFolderListItem ( const RssFilePtr & rssFile )
{
Q_ASSERT ( rssFile ) ;
QTreeWidgetItem * item = new QTreeWidgetItem ;
item - > setData ( 0 , Qt : : DisplayRole , QVariant ( rssFile - > displayName ( ) + QString : : fromUtf8 ( " ( " ) + QString : : number ( rssFile - > unreadCount ( ) , 10 ) + QString ( " ) " ) ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , rssFile - > icon ( ) ) ;
return item ;
}
void RSSImp : : fillFeedsList ( QTreeWidgetItem * parent , const RssFolderPtr & rss_parent ) {
2012-02-19 20:53:10 +04:00
QList < RssFilePtr > children ;
2012-02-20 21:30:53 +04:00
if ( parent ) {
2009-08-22 18:06:05 +04:00
children = rss_parent - > getContent ( ) ;
} else {
2011-01-29 16:44:56 +03:00
children = m_rssManager - > getContent ( ) ;
2009-08-21 11:40:57 +04:00
}
2012-08-19 16:48:28 +04:00
foreach ( const RssFilePtr & rssFile , children ) {
QTreeWidgetItem * item = createFolderListItem ( rssFile ) ;
Q_ASSERT ( item ) ;
if ( parent )
parent - > addChild ( item ) ;
2009-08-22 18:06:05 +04:00
else
2012-08-19 16:48:28 +04:00
m_feedList - > addTopLevelItem ( item ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget of item addition
2012-08-19 16:48:28 +04:00
m_feedList - > itemAdded ( item , rssFile ) ;
// Recursive call if this is a folder.
if ( RssFolderPtr folder = qSharedPointerDynamicCast < RssFolder > ( rssFile ) )
2012-02-19 20:53:10 +04:00
fillFeedsList ( item , folder ) ;
2009-08-21 11:40:57 +04:00
}
}
2007-04-05 23:26:30 +04:00
2012-08-19 15:55:30 +04:00
QListWidgetItem * RSSImp : : createArticleListItem ( const RssArticlePtr & article )
{
Q_ASSERT ( article ) ;
QListWidgetItem * item = new QListWidgetItem ;
item - > setData ( Article : : TitleRole , article - > title ( ) ) ;
item - > setData ( Article : : FeedUrlRole , article - > parent ( ) - > url ( ) ) ;
item - > setData ( Article : : IdRole , article - > guid ( ) ) ;
if ( article - > isRead ( ) ) {
item - > setData ( Article : : ColorRole , QVariant ( QColor ( " grey " ) ) ) ;
item - > setData ( Article : : IconRole , QVariant ( QIcon ( " :/Icons/sphere.png " ) ) ) ;
} else {
item - > setData ( Article : : ColorRole , QVariant ( QColor ( " blue " ) ) ) ;
item - > setData ( Article : : IconRole , QVariant ( QIcon ( " :/Icons/sphere2.png " ) ) ) ;
}
return item ;
}
2009-08-21 11:40:57 +04:00
// fills the newsList
2012-08-19 15:55:30 +04:00
void RSSImp : : populateArticleList ( QTreeWidgetItem * item )
{
2012-02-20 21:30:53 +04:00
if ( ! item ) {
2011-01-29 16:03:12 +03:00
listArticles - > clear ( ) ;
2009-08-21 21:49:48 +04:00
return ;
}
2009-08-23 16:22:19 +04:00
2012-02-19 20:53:10 +04:00
RssFilePtr rss_item = m_feedList - > getRSSItem ( item ) ;
2012-08-19 15:55:30 +04:00
if ( ! rss_item )
return ;
2009-08-22 19:26:39 +04:00
2009-08-21 11:40:57 +04:00
// Clear the list first
2009-08-21 22:24:29 +04:00
textBrowser - > clear ( ) ;
2011-01-29 16:03:12 +03:00
m_currentArticle = 0 ;
listArticles - > clear ( ) ;
2012-08-19 15:55:30 +04:00
qDebug ( " Getting the list of news " ) ;
RssArticleList articles ;
if ( rss_item = = m_rssManager )
articles = rss_item - > unreadArticleListByDateDesc ( ) ;
else
articles = rss_item - > articleListByDateDesc ( ) ;
2009-08-21 11:40:57 +04:00
qDebug ( " Got the list of news " ) ;
2012-08-19 15:55:30 +04:00
foreach ( const RssArticlePtr & article , articles ) {
QListWidgetItem * articleItem = createArticleListItem ( article ) ;
listArticles - > addItem ( articleItem ) ;
2009-08-21 11:40:57 +04:00
}
qDebug ( " Added all news to the GUI " ) ;
}
2007-08-03 18:37:56 +04:00
2009-08-21 11:40:57 +04:00
// display a news
2009-11-06 21:29:32 +03:00
void RSSImp : : refreshTextBrowser ( ) {
2011-01-29 16:03:12 +03:00
QList < QListWidgetItem * > selection = listArticles - > selectedItems ( ) ;
2012-02-20 21:30:53 +04:00
if ( selection . empty ( ) ) return ;
2010-05-05 18:28:40 +04:00
Q_ASSERT ( selection . size ( ) = = 1 ) ;
2011-01-29 16:03:12 +03:00
QListWidgetItem * item = selection . first ( ) ;
2010-11-02 21:04:39 +03:00
Q_ASSERT ( item ) ;
2012-02-20 21:30:53 +04:00
if ( item = = m_currentArticle ) return ;
2009-08-28 21:29:34 +04:00
// Stop displaying previous news if necessary
2012-02-20 21:30:53 +04:00
if ( m_feedList - > currentFeed ( ) = = m_feedList - > stickyUnreadItem ( ) ) {
if ( m_currentArticle ) {
2011-01-29 16:03:12 +03:00
disconnect ( listArticles , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( refreshTextBrowser ( ) ) ) ;
listArticles - > removeItemWidget ( m_currentArticle ) ;
Q_ASSERT ( m_currentArticle ) ;
delete m_currentArticle ;
connect ( listArticles , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( refreshTextBrowser ( ) ) ) ;
2009-08-28 21:29:34 +04:00
}
2011-01-29 16:03:12 +03:00
m_currentArticle = item ;
2009-08-28 21:29:34 +04:00
}
2012-02-19 20:53:10 +04:00
RssFeedPtr stream = m_feedList - > getRSSItemFromUrl ( item - > data ( Article : : FeedUrlRole ) . toString ( ) ) ;
2012-02-19 18:38:41 +04:00
RssArticlePtr article = stream - > getItem ( item - > data ( Article : : IdRole ) . toString ( ) ) ;
2009-08-21 11:40:57 +04:00
QString html ;
html + = " <div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'> " ;
2012-02-19 18:38:41 +04:00
html + = " <div style='background-color: #678db2; font-weight: bold; color: #fff;'> " + article - > title ( ) + " </div> " ;
2012-02-20 21:30:53 +04:00
if ( article - > date ( ) . isValid ( ) ) {
2012-02-19 18:38:41 +04:00
html + = " <div style='background-color: #efefef;'><b> " + tr ( " Date: " ) + " </b> " + article - > date ( ) . toLocalTime ( ) . toString ( Qt : : SystemLocaleLongDate ) + " </div> " ;
2009-08-21 11:40:57 +04:00
}
2012-02-20 21:30:53 +04:00
if ( ! article - > author ( ) . isEmpty ( ) ) {
2012-02-19 18:38:41 +04:00
html + = " <div style='background-color: #efefef;'><b> " + tr ( " Author: " ) + " </b> " + article - > author ( ) + " </div> " ;
2009-08-21 11:40:57 +04:00
}
html + = " </div> " ;
2012-02-19 18:38:41 +04:00
html + = " <divstyle='margin-left: 5px; margin-right: 5px;'> " + article - > description ( ) + " </div> " ;
2009-08-21 11:40:57 +04:00
textBrowser - > setHtml ( html ) ;
2012-02-19 18:38:41 +04:00
article - > markAsRead ( ) ;
2011-01-29 16:03:12 +03:00
item - > setData ( Article : : ColorRole , QVariant ( QColor ( " grey " ) ) ) ;
item - > setData ( Article : : IconRole , QVariant ( QIcon ( " :/Icons/sphere.png " ) ) ) ;
2009-08-23 17:26:16 +04:00
// Decrement feed nb unread news
2011-01-29 16:44:56 +03:00
updateItemInfos ( m_feedList - > stickyUnreadItem ( ) ) ;
updateItemInfos ( m_feedList - > getTreeItemFromUrl ( item - > data ( Article : : FeedUrlRole ) . toString ( ) ) ) ;
2009-08-21 11:40:57 +04:00
}
2007-08-03 18:37:56 +04:00
2009-08-21 11:40:57 +04:00
void RSSImp : : saveSlidersPosition ( ) {
// Remember sliders positions
2010-07-16 19:03:18 +04:00
QIniSettings settings ( " qBittorrent " , " qBittorrent " ) ;
2009-08-21 11:40:57 +04:00
settings . setValue ( " rss/splitter_h " , splitter_h - > saveState ( ) ) ;
settings . setValue ( " rss/splitter_v " , splitter_v - > saveState ( ) ) ;
qDebug ( " Splitters position saved " ) ;
}
void RSSImp : : restoreSlidersPosition ( ) {
2010-07-16 19:03:18 +04:00
QIniSettings settings ( " qBittorrent " , " qBittorrent " ) ;
2009-08-21 11:40:57 +04:00
QByteArray pos_h = settings . value ( " rss/splitter_h " , QByteArray ( ) ) . toByteArray ( ) ;
2012-02-20 21:30:53 +04:00
if ( ! pos_h . isNull ( ) ) {
2009-08-21 11:40:57 +04:00
splitter_h - > restoreState ( pos_h ) ;
}
QByteArray pos_v = settings . value ( " rss/splitter_v " , QByteArray ( ) ) . toByteArray ( ) ;
2012-02-20 21:30:53 +04:00
if ( ! pos_v . isNull ( ) ) {
2009-08-21 11:40:57 +04:00
splitter_v - > restoreState ( pos_v ) ;
}
}
2011-01-29 16:44:56 +03:00
void RSSImp : : updateItemsInfos ( const QList < QTreeWidgetItem * > & items ) {
2012-02-20 21:30:53 +04:00
foreach ( QTreeWidgetItem * item , items ) {
2009-08-23 16:49:37 +04:00
updateItemInfos ( item ) ;
}
}
void RSSImp : : updateItemInfos ( QTreeWidgetItem * item ) {
2012-02-19 20:53:10 +04:00
RssFilePtr rss_item = m_feedList - > getRSSItem ( item ) ;
2011-10-05 19:41:23 +04:00
if ( ! rss_item )
return ;
2009-08-24 10:31:11 +04:00
QString name ;
2012-02-20 21:30:53 +04:00
if ( rss_item = = m_rssManager )
2009-08-24 10:31:11 +04:00
name = tr ( " Unread " ) ;
else
2011-01-27 20:18:56 +03:00
name = rss_item - > displayName ( ) ;
item - > setText ( 0 , name + QString : : fromUtf8 ( " ( " ) + QString : : number ( rss_item - > unreadCount ( ) , 10 ) + QString ( " ) " ) ) ;
2009-08-23 17:05:47 +04:00
// If item has a parent, update it too
2012-02-20 21:30:53 +04:00
if ( item - > parent ( ) )
2009-08-23 17:05:47 +04:00
updateItemInfos ( item - > parent ( ) ) ;
2009-08-23 16:49:37 +04:00
}
2012-02-20 21:56:07 +04:00
void RSSImp : : updateFeedIcon ( const QString & url , const QString & icon_path ) {
2011-01-29 16:44:56 +03:00
QTreeWidgetItem * item = m_feedList - > getTreeItemFromUrl ( url ) ;
2009-08-21 11:40:57 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( icon_path ) ) ) ;
}
2012-08-18 23:25:21 +04:00
void RSSImp : : updateFeedInfos ( const QString & url , const QString & display_name , uint nbUnread )
{
2011-01-27 20:18:56 +03:00
qDebug ( ) < < Q_FUNC_INFO < < display_name ;
2011-01-29 16:44:56 +03:00
QTreeWidgetItem * item = m_feedList - > getTreeItemFromUrl ( url ) ;
2012-02-19 20:53:10 +04:00
RssFeedPtr stream = qSharedPointerCast < RssFeed > ( m_feedList - > getRSSItem ( item ) ) ;
2012-08-18 23:25:21 +04:00
item - > setText ( 0 , display_name + QString : : fromUtf8 ( " ( " ) + QString : : number ( nbUnread ) + QString ( " ) " ) ) ;
2012-02-20 21:30:53 +04:00
if ( ! stream - > isLoading ( ) )
2012-08-19 16:48:28 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( stream - > icon ( ) ) ) ;
2009-08-23 17:05:47 +04:00
// Update parent
2012-02-20 21:30:53 +04:00
if ( item - > parent ( ) )
2009-08-23 17:05:47 +04:00
updateItemInfos ( item - > parent ( ) ) ;
2009-08-24 13:47:13 +04:00
// Update Unread item
2011-01-29 16:44:56 +03:00
updateItemInfos ( m_feedList - > stickyUnreadItem ( ) ) ;
2012-08-18 23:25:21 +04:00
}
void RSSImp : : onFeedContentChanged ( const QString & url )
{
qDebug ( ) < < Q_FUNC_INFO < < url ;
QTreeWidgetItem * item = m_feedList - > getTreeItemFromUrl ( url ) ;
2009-08-21 11:40:57 +04:00
// If the feed is selected, update the displayed news
2012-02-20 21:56:07 +04:00
if ( m_feedList - > currentItem ( ) = = item ) {
2012-08-19 15:55:30 +04:00
populateArticleList ( item ) ;
2009-08-27 11:57:52 +04:00
} else {
// Update unread items
2012-02-20 21:30:53 +04:00
if ( m_feedList - > currentItem ( ) = = m_feedList - > stickyUnreadItem ( ) ) {
2012-08-19 15:55:30 +04:00
populateArticleList ( m_feedList - > stickyUnreadItem ( ) ) ;
2009-08-27 11:57:52 +04:00
}
2009-08-21 11:40:57 +04:00
}
}
2011-01-29 16:44:56 +03:00
void RSSImp : : updateRefreshInterval ( uint val ) {
m_rssManager - > updateRefreshInterval ( val ) ;
2009-11-15 11:53:33 +03:00
}
2012-02-19 20:53:10 +04:00
RSSImp : : RSSImp ( QWidget * parent ) : QWidget ( parent ) , m_rssManager ( new RssManager ) {
2009-08-21 11:40:57 +04:00
setupUi ( this ) ;
2010-12-12 22:37:59 +03:00
// Icons
2011-01-01 16:19:28 +03:00
actionCopy_feed_URL - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " edit-copy " ) ) ;
actionDelete - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " edit-delete " ) ) ;
actionDownload_torrent - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " download " ) ) ;
actionManage_cookies - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " preferences-web-browser-cookies " ) ) ;
actionMark_items_read - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " mail-mark-read " ) ) ;
actionNew_folder - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " folder-new " ) ) ;
actionNew_subscription - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) ) ;
actionOpen_news_URL - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " application-x-mswinurl " ) ) ;
actionRename - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " edit-rename " ) ) ;
actionUpdate - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " view-refresh " ) ) ;
actionUpdate_all_feeds - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " view-refresh " ) ) ;
newFeedButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) ) ;
markReadButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " mail-mark-read " ) ) ;
updateAllButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " view-refresh " ) ) ;
rssDownloaderBtn - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " download " ) ) ;
settingsButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " preferences-system " ) ) ;
2009-08-21 21:49:48 +04:00
2011-01-29 16:44:56 +03:00
m_feedList = new FeedListWidget ( splitter_h , m_rssManager ) ;
splitter_h - > insertWidget ( 0 , m_feedList ) ;
2011-01-29 16:03:12 +03:00
listArticles - > setSelectionBehavior ( QAbstractItemView : : SelectItems ) ;
listArticles - > setSelectionMode ( QAbstractItemView : : SingleSelection ) ;
2009-08-23 12:10:56 +04:00
2011-01-29 16:44:56 +03:00
m_rssManager - > loadStreamList ( ) ;
2009-08-21 11:40:57 +04:00
fillFeedsList ( ) ;
2012-08-19 15:55:30 +04:00
populateArticleList ( m_feedList - > currentItem ( ) ) ;
2009-08-24 10:28:31 +04:00
2009-08-23 18:56:44 +04:00
loadFoldersOpenState ( ) ;
2012-08-18 23:25:21 +04:00
connect ( m_rssManager . data ( ) , SIGNAL ( feedInfosChanged ( QString , QString , unsigned int ) ) , SLOT ( updateFeedInfos ( QString , QString , unsigned int ) ) ) ;
connect ( m_rssManager . data ( ) , SIGNAL ( feedContentChanged ( QString ) ) , SLOT ( onFeedContentChanged ( QString ) ) ) ;
connect ( m_rssManager . data ( ) , SIGNAL ( feedIconChanged ( QString , QString ) ) , SLOT ( updateFeedIcon ( QString , QString ) ) ) ;
2009-08-21 11:40:57 +04:00
2012-08-18 23:25:21 +04:00
connect ( m_feedList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , SLOT ( displayRSSListMenu ( const QPoint & ) ) ) ;
connect ( listArticles , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , SLOT ( displayItemsListMenu ( const QPoint & ) ) ) ;
2009-08-21 11:40:57 +04:00
2009-08-22 06:19:40 +04:00
// Feeds list actions
2009-08-22 19:01:53 +04:00
connect ( actionDelete , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteSelectedItems ( ) ) ) ;
2012-08-19 16:48:28 +04:00
connect ( actionRename , SIGNAL ( triggered ( ) ) , this , SLOT ( renameSelectedRssFile ( ) ) ) ;
2009-08-23 17:20:26 +04:00
connect ( actionUpdate , SIGNAL ( triggered ( ) ) , this , SLOT ( refreshSelectedItems ( ) ) ) ;
2009-08-22 19:26:39 +04:00
connect ( actionNew_folder , SIGNAL ( triggered ( ) ) , this , SLOT ( askNewFolder ( ) ) ) ;
2009-08-22 06:19:40 +04:00
connect ( actionNew_subscription , SIGNAL ( triggered ( ) ) , this , SLOT ( on_newFeedButton_clicked ( ) ) ) ;
2012-08-19 16:12:08 +04:00
connect ( actionUpdate_all_feeds , SIGNAL ( triggered ( ) ) , this , SLOT ( refreshAllFeeds ( ) ) ) ;
connect ( updateAllButton , SIGNAL ( clicked ( ) ) , SLOT ( refreshAllFeeds ( ) ) ) ;
2009-08-21 11:40:57 +04:00
connect ( actionCopy_feed_URL , SIGNAL ( triggered ( ) ) , this , SLOT ( copySelectedFeedsURL ( ) ) ) ;
2009-08-22 06:19:40 +04:00
connect ( actionMark_items_read , SIGNAL ( triggered ( ) ) , this , SLOT ( on_markReadButton_clicked ( ) ) ) ;
// News list actions
2012-08-19 16:48:28 +04:00
connect ( actionOpen_news_URL , SIGNAL ( triggered ( ) ) , this , SLOT ( openSelectedArticlesUrls ( ) ) ) ;
2012-08-19 16:00:07 +04:00
connect ( actionDownload_torrent , SIGNAL ( triggered ( ) ) , this , SLOT ( downloadSelectedTorrents ( ) ) ) ;
2009-08-21 11:40:57 +04:00
2012-08-19 15:55:30 +04:00
connect ( m_feedList , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( populateArticleList ( QTreeWidgetItem * ) ) ) ;
2011-01-29 16:44:56 +03:00
connect ( m_feedList , SIGNAL ( foldersAltered ( QList < QTreeWidgetItem * > ) ) , this , SLOT ( updateItemsInfos ( QList < QTreeWidgetItem * > ) ) ) ;
connect ( m_feedList , SIGNAL ( overwriteAttempt ( QString ) ) , this , SLOT ( displayOverwriteError ( QString ) ) ) ;
2009-08-23 16:49:37 +04:00
2011-01-29 16:03:12 +03:00
connect ( listArticles , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( refreshTextBrowser ( ) ) ) ;
2012-08-19 16:00:07 +04:00
connect ( listArticles , SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ) , this , SLOT ( downloadSelectedTorrents ( ) ) ) ;
2009-08-22 18:06:05 +04:00
2009-08-21 11:40:57 +04:00
// Refresh all feeds
2011-01-29 16:44:56 +03:00
m_rssManager - > refresh ( ) ;
2009-08-21 11:40:57 +04:00
// Restore sliders position
restoreSlidersPosition ( ) ;
// Bind saveSliders slots
connect ( splitter_v , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
connect ( splitter_h , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
2009-08-23 12:10:56 +04:00
2009-08-21 11:40:57 +04:00
qDebug ( " RSSImp constructed " ) ;
}
2012-02-20 21:56:07 +04:00
RSSImp : : ~ RSSImp ( ) {
2009-08-21 11:40:57 +04:00
qDebug ( " Deleting RSSImp... " ) ;
2009-08-23 18:56:44 +04:00
saveFoldersOpenState ( ) ;
2011-01-29 16:44:56 +03:00
delete m_feedList ;
2009-08-21 11:40:57 +04:00
qDebug ( " RSSImp deleted " ) ;
}
2007-04-05 23:26:30 +04:00
2010-06-22 17:39:49 +04:00
void RSSImp : : on_settingsButton_clicked ( ) {
2010-10-31 15:35:07 +03:00
RssSettingsDlg dlg ( this ) ;
2012-02-20 21:30:53 +04:00
if ( dlg . exec ( ) )
2010-11-17 23:21:03 +03:00
updateRefreshInterval ( RssSettings ( ) . getRSSRefreshInterval ( ) ) ;
2010-06-22 17:39:49 +04:00
}
2010-11-13 13:49:22 +03:00
void RSSImp : : on_rssDownloaderBtn_clicked ( )
{
2012-02-19 20:53:10 +04:00
AutomatedRssDownloader dlg ( m_rssManager , this ) ;
2010-11-13 13:49:22 +03:00
dlg . exec ( ) ;
2012-02-20 21:30:53 +04:00
if ( dlg . isRssDownloaderEnabled ( ) )
2012-08-19 16:12:08 +04:00
refreshAllFeeds ( ) ;
2010-11-13 13:49:22 +03:00
}