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"
# include "FeedDownloader.h"
2009-08-23 12:10:56 +04:00
# include "feedList.h"
2009-08-21 11:40:57 +04:00
# include "bittorrent.h"
2007-04-05 23:26:30 +04:00
2009-08-21 11:40:57 +04:00
// display a right-click menu
2009-08-22 06:19:40 +04:00
void RSSImp : : displayRSSListMenu ( const QPoint & pos ) {
if ( ! listStreams - > indexAt ( pos ) . isValid ( ) ) {
// No item under the mouse, clear selection
listStreams - > clearSelection ( ) ;
}
2009-08-22 19:01:53 +04:00
QMenu myRSSListMenu ( this ) ;
2009-08-21 11:40:57 +04:00
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
if ( selectedItems . size ( ) > 0 ) {
2009-08-22 19:01:53 +04:00
myRSSListMenu . addAction ( actionUpdate ) ;
myRSSListMenu . addAction ( actionMark_items_read ) ;
myRSSListMenu . addSeparator ( ) ;
2009-08-21 11:40:57 +04:00
if ( selectedItems . size ( ) = = 1 ) {
2009-08-24 10:28:31 +04:00
if ( listStreams - > getRSSItem ( selectedItems . first ( ) ) ! = rssmanager ) {
myRSSListMenu . addAction ( actionRename ) ;
myRSSListMenu . addAction ( actionDelete ) ;
myRSSListMenu . addSeparator ( ) ;
if ( listStreams - > getItemType ( selectedItems . first ( ) ) = = RssFile : : FOLDER )
myRSSListMenu . addAction ( actionNew_folder ) ;
}
2007-04-05 23:26:30 +04:00
}
2009-08-23 16:22:19 +04:00
myRSSListMenu . addAction ( actionNew_subscription ) ;
if ( listStreams - > getItemType ( selectedItems . first ( ) ) = = RssFile : : STREAM ) {
2009-08-22 19:01:53 +04:00
myRSSListMenu . addSeparator ( ) ;
2009-08-23 16:22:19 +04:00
myRSSListMenu . addAction ( actionCopy_feed_URL ) ;
if ( selectedItems . size ( ) = = 1 ) {
myRSSListMenu . addSeparator ( ) ;
myRSSListMenu . addAction ( actionRSS_feed_downloader ) ;
}
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
2009-08-21 11:40:57 +04:00
void RSSImp : : displayItemsListMenu ( const QPoint & ) {
QMenu myItemListMenu ( this ) ;
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
if ( selectedItems . size ( ) > 0 ) {
myItemListMenu . addAction ( actionDownload_torrent ) ;
myItemListMenu . addAction ( actionOpen_news_URL ) ;
}
myItemListMenu . exec ( QCursor : : pos ( ) ) ;
}
2007-04-05 23:26:30 +04:00
2009-08-22 19:26:39 +04:00
void RSSImp : : askNewFolder ( ) {
QTreeWidgetItem * parent_item = 0 ;
2009-08-23 16:22:19 +04:00
RssFolder * rss_parent ;
2009-08-22 19:26:39 +04:00
if ( listStreams - > selectedItems ( ) . size ( ) > 0 ) {
parent_item = listStreams - > selectedItems ( ) . at ( 0 ) ;
2009-08-23 16:22:19 +04:00
rss_parent = ( RssFolder * ) listStreams - > getRSSItem ( parent_item ) ;
Q_ASSERT ( rss_parent - > getType ( ) = = RssFile : : FOLDER ) ;
} else {
rss_parent = 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 ) ;
2009-08-22 19:26:39 +04:00
if ( ok ) {
2009-08-23 16:22:19 +04:00
RssFolder * new_folder = rss_parent - > addFolder ( new_name ) ;
2009-08-22 19:26:39 +04:00
QTreeWidgetItem * folder_item ;
if ( parent_item )
folder_item = new QTreeWidgetItem ( parent_item ) ;
else
folder_item = new QTreeWidgetItem ( listStreams ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget
listStreams - > itemAdded ( folder_item , new_folder ) ;
// Set Text
2009-08-22 19:26:39 +04:00
folder_item - > setText ( 0 , new_folder - > getName ( ) + QString : : fromUtf8 ( " (0) " ) ) ;
folder_item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/oxygen/folder.png " ) ) ) ;
2009-08-22 19:33:31 +04:00
// Expand parent folder to display new folder
2009-08-23 12:10:56 +04:00
if ( parent_item )
parent_item - > setExpanded ( true ) ;
2009-08-22 19:26:39 +04:00
rssmanager - > saveStreamList ( ) ;
}
}
2009-08-24 08:01:26 +04:00
void RSSImp : : displayOverwriteError ( QString filename ) {
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
QTreeWidgetItem * parent_item = 0 ;
QList < QTreeWidgetItem * > selected_items = listStreams - > selectedItems ( ) ;
if ( ! selected_items . empty ( ) )
parent_item = selected_items . first ( ) ;
RssFolder * rss_parent ;
if ( parent_item ) {
RssFile * tmp = listStreams - > getRSSItem ( parent_item ) ;
if ( tmp - > getType ( ) = = RssFile : : FOLDER )
rss_parent = ( RssFolder * ) tmp ;
else
rss_parent = tmp - > getParent ( ) ;
} else {
rss_parent = rssmanager ;
}
// Ask for feed URL
2009-08-22 06:19:40 +04:00
bool ok ;
QString clip_txt = qApp - > clipboard ( ) - > text ( ) ;
QString default_url = " http:// " ;
if ( clip_txt . startsWith ( " http:// " , Qt : : CaseInsensitive ) | | clip_txt . startsWith ( " https:// " , Qt : : CaseInsensitive ) | | clip_txt . startsWith ( " ftp:// " , Qt : : CaseInsensitive ) ) {
default_url = clip_txt ;
}
QString newUrl = QInputDialog : : getText ( this , tr ( " Please type a rss stream url " ) , tr ( " Stream URL: " ) , QLineEdit : : Normal , default_url , & ok ) ;
if ( ok ) {
newUrl = newUrl . trimmed ( ) ;
if ( ! newUrl . isEmpty ( ) ) {
2009-08-23 16:22:19 +04:00
if ( listStreams - > 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 ;
}
2009-08-23 16:22:19 +04:00
RssStream * stream = rss_parent - > addStream ( newUrl ) ;
// Create TreeWidget item
2009-08-23 17:52:45 +04:00
QTreeWidgetItem * item = new QTreeWidgetItem ( parent_item ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget
listStreams - > itemAdded ( item , stream ) ;
// Set text
2009-08-22 18:06:05 +04:00
item - > setText ( 0 , stream - > getName ( ) + 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 ( ) ;
2009-08-22 06:19:40 +04:00
rssmanager - > saveStreamList ( ) ;
}
}
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 ( ) {
2009-08-21 11:40:57 +04:00
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
2009-08-22 07:00:31 +04:00
if ( selectedItems . size ( ) = = 0 ) return ;
2009-08-23 16:22:19 +04:00
int ret ;
if ( selectedItems . size ( ) > 1 )
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 ) ;
2009-08-21 11:40:57 +04:00
if ( ! ret ) {
2009-08-22 07:00:31 +04:00
foreach ( QTreeWidgetItem * item , selectedItems ) {
2009-08-23 16:22:19 +04:00
if ( listStreams - > currentFeed ( ) = = item ) {
2007-08-03 18:37:56 +04:00
textBrowser - > clear ( ) ;
listNews - > clear ( ) ;
2007-04-05 23:26:30 +04:00
}
2009-08-23 16:22:19 +04:00
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
// Notify TreeWidget
listStreams - > itemRemoved ( item ) ;
// Actually delete the item
2009-08-23 17:52:45 +04:00
rss_item - > getParent ( ) - > removeFile ( rss_item - > getID ( ) ) ;
2009-08-22 07:00:31 +04:00
delete item ;
2007-04-05 23:26:30 +04:00
}
2009-08-22 07:00:31 +04:00
rssmanager - > saveStreamList ( ) ;
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 ( ) {
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
settings . beginGroup ( " Rss " ) ;
QVariantList open_folders = settings . value ( " open_folders " , QVariantList ( ) ) . toList ( ) ;
settings . endGroup ( ) ;
foreach ( QVariant var_path , open_folders ) {
QStringList path = var_path . toString ( ) . split ( " \\ " ) ;
QTreeWidgetItem * parent = 0 ;
foreach ( QString name , path ) {
QList < QTreeWidgetItem * > children ;
int nbChildren = 0 ;
if ( parent )
nbChildren = parent - > childCount ( ) ;
else
nbChildren = listStreams - > topLevelItemCount ( ) ;
for ( int i = 0 ; i < nbChildren ; + + i ) {
QTreeWidgetItem * child ;
if ( parent )
child = parent - > child ( i ) ;
else
child = listStreams - > topLevelItem ( i ) ;
if ( listStreams - > getRSSItem ( child ) - > getID ( ) = = name ) {
parent = child ;
parent - > setExpanded ( true ) ;
qDebug ( " expanding folder %s " , name . toLocal8Bit ( ) . data ( ) ) ;
break ;
}
}
}
}
}
void RSSImp : : saveFoldersOpenState ( ) {
QVariantList open_folders ;
QList < QTreeWidgetItem * > items = listStreams - > getAllOpenFolders ( ) ;
foreach ( QTreeWidgetItem * item , items ) {
QString path = listStreams - > getItemPath ( item ) . join ( " \\ " ) ;
qDebug ( " saving open folder: %s " , path . toLocal8Bit ( ) . data ( ) ) ;
open_folders < < path ;
}
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
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
2009-08-22 06:19:40 +04:00
void RSSImp : : on_updateAllButton_clicked ( ) {
2009-08-23 17:05:47 +04:00
foreach ( QTreeWidgetItem * item , listStreams - > getAllFeedItems ( ) ) {
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
}
2009-08-22 06:19:40 +04:00
rssmanager - > refreshAll ( ) ;
2009-08-21 11:40:57 +04:00
}
2007-09-09 15:31:51 +04:00
2009-08-21 11:40:57 +04:00
void RSSImp : : downloadTorrent ( ) {
2009-08-24 10:28:31 +04:00
QList < QTreeWidgetItem * > selected_items = listNews - > selectedItems ( ) ;
foreach ( const QTreeWidgetItem * item , selected_items ) {
RssItem * news = listStreams - > getRSSItemFromUrl ( item - > text ( 1 ) ) - > getItem ( item - > text ( 0 ) ) ;
2009-08-21 11:40:57 +04:00
BTSession - > downloadFromUrl ( news - > getTorrentUrl ( ) ) ;
}
}
2007-04-05 23:26:30 +04:00
2009-08-21 11:40:57 +04:00
// open the url of the news in a browser
void RSSImp : : openNewsUrl ( ) {
2009-08-24 10:28:31 +04:00
QList < QTreeWidgetItem * > selected_items = listNews - > selectedItems ( ) ;
foreach ( const QTreeWidgetItem * item , selected_items ) {
RssItem * news = listStreams - > getRSSItemFromUrl ( item - > text ( 1 ) ) - > getItem ( item - > text ( 0 ) ) ;
2009-08-21 11:40:57 +04:00
QString link = news - > getLink ( ) ;
if ( ! link . isEmpty ( ) )
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
2009-08-22 18:06:05 +04:00
void RSSImp : : renameFiles ( ) {
2009-08-21 11:40:57 +04:00
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
Q_ASSERT ( selectedItems . size ( ) = = 1 ) ;
QTreeWidgetItem * item = selectedItems . at ( 0 ) ;
2009-08-23 16:22:19 +04:00
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
2009-08-21 11:40:57 +04:00
bool ok ;
2009-08-23 16:22:19 +04:00
QString newName ;
do {
2009-08-23 17:05:47 +04:00
newName = QInputDialog : : getText ( this , tr ( " Please choose a new name for this RSS feed " ) , tr ( " New feed name: " ) , QLineEdit : : Normal , listStreams - > getRSSItem ( item ) - > getName ( ) , & ok ) ;
// Check if name is already taken
if ( ok & & rss_item - > getParent ( ) - > contains ( newName ) ) {
QMessageBox : : warning ( 0 , tr ( " Name already in use " ) , tr ( " This name is already used by another item, please choose another one. " ) ) ;
ok = false ;
}
2009-08-23 16:22:19 +04:00
} while ( ! ok ) ;
2009-08-21 11:40:57 +04:00
if ( ok ) {
2009-08-23 16:22:19 +04:00
// Rename item
rss_item - > rename ( newName ) ;
// Update TreeWidget
2009-08-23 17:26:16 +04:00
updateItemInfos ( item ) ;
2009-08-21 11:40:57 +04:00
}
}
2007-04-06 02:38:46 +04:00
2009-08-21 11:40:57 +04:00
//right-click on stream : refresh it
2009-08-23 17:20:26 +04:00
void RSSImp : : refreshSelectedItems ( ) {
2009-08-21 11:40:57 +04:00
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
2009-08-23 17:20:26 +04:00
foreach ( QTreeWidgetItem * item , selectedItems ) {
2009-08-23 16:22:19 +04:00
RssFile * file = listStreams - > getRSSItem ( item ) ;
2009-08-23 17:20:26 +04:00
// Update icons
if ( file - > getType ( ) = = RssFile : : STREAM ) {
2009-08-22 18:06:05 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
2009-08-23 17:20:26 +04:00
} else {
// Update feeds in the folder
foreach ( QTreeWidgetItem * feed , listStreams - > getAllFeedItems ( item ) ) {
feed - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
}
}
// Actually refresh
file - > refresh ( ) ;
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 ;
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QTreeWidgetItem * item ;
foreach ( item , selectedItems ) {
2009-08-23 16:22:19 +04:00
URLs < < listStreams - > 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-21 11:40:57 +04:00
void RSSImp : : showFeedDownloader ( ) {
QTreeWidgetItem * item = listStreams - > selectedItems ( ) [ 0 ] ;
2009-08-23 16:22:19 +04:00
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
2009-08-22 18:06:05 +04:00
if ( rss_item - > getType ( ) = = RssFile : : STREAM )
2009-08-23 16:22:19 +04:00
new FeedDownloaderDlg ( this , listStreams - > getItemID ( item ) , rss_item - > getName ( ) , BTSession ) ;
2009-08-21 11:40:57 +04:00
}
2007-07-22 15:53:43 +04:00
2009-08-22 06:19:40 +04:00
void RSSImp : : on_markReadButton_clicked ( ) {
2009-08-21 11:40:57 +04:00
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QTreeWidgetItem * item ;
foreach ( item , selectedItems ) {
2009-08-23 16:22:19 +04:00
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
2009-08-22 18:06:05 +04:00
rss_item - > markAllAsRead ( ) ;
item - > setData ( 0 , Qt : : DisplayRole , rss_item - > getName ( ) + QString : : fromUtf8 ( " (0) " ) ) ;
2009-08-21 11:40:57 +04:00
}
2009-08-21 22:36:50 +04:00
if ( selectedItems . size ( ) )
refreshNewsList ( listStreams - > currentItem ( ) ) ;
2009-08-21 11:40:57 +04:00
}
2007-08-03 18:37:56 +04:00
2009-08-22 18:06:05 +04:00
void RSSImp : : fillFeedsList ( QTreeWidgetItem * parent , RssFolder * rss_parent ) {
QList < RssFile * > children ;
if ( parent ) {
children = rss_parent - > getContent ( ) ;
} else {
children = rssmanager - > getContent ( ) ;
2009-08-21 11:40:57 +04:00
}
2009-08-22 18:06:05 +04:00
foreach ( RssFile * rss_child , children ) {
QTreeWidgetItem * item ;
if ( ! parent )
item = new QTreeWidgetItem ( listStreams ) ;
else
item = new QTreeWidgetItem ( parent ) ;
item - > setData ( 0 , Qt : : DisplayRole , rss_child - > getName ( ) + QString : : fromUtf8 ( " ( " ) + QString : : number ( rss_child - > getNbUnRead ( ) , 10 ) + QString ( " ) " ) ) ;
2009-08-23 16:22:19 +04:00
// Notify TreeWidget of item addition
listStreams - > itemAdded ( item , rss_child ) ;
// Set Icon
2009-08-22 18:06:05 +04:00
if ( rss_child - > getType ( ) = = RssFile : : STREAM ) {
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/loading.png " ) ) ) ) ;
} else {
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( QString : : fromUtf8 ( " :/Icons/oxygen/folder.png " ) ) ) ) ;
// Recurvive call to load sub folders/files
fillFeedsList ( item , ( RssFolder * ) rss_child ) ;
}
2009-08-21 11:40:57 +04:00
}
}
2007-04-05 23:26:30 +04:00
2009-08-21 11:40:57 +04:00
// fills the newsList
2009-08-21 18:48:33 +04:00
void RSSImp : : refreshNewsList ( QTreeWidgetItem * item ) {
2009-08-21 21:49:48 +04:00
if ( ! item ) {
listNews - > clear ( ) ;
return ;
}
2009-08-23 16:22:19 +04:00
2009-08-24 10:28:31 +04:00
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
2009-08-22 19:26:39 +04:00
2009-08-21 11:40:57 +04:00
qDebug ( " Getting the list of news " ) ;
2009-08-24 10:28:31 +04:00
QList < RssItem * > news ;
if ( rss_item = = rssmanager )
news = sortNewsList ( rss_item - > getUnreadNewsList ( ) ) ;
else
news = sortNewsList ( rss_item - > getNewsList ( ) ) ;
2009-08-21 11:40:57 +04:00
// Clear the list first
2009-08-21 22:24:29 +04:00
textBrowser - > clear ( ) ;
2009-08-21 11:40:57 +04:00
listNews - > clear ( ) ;
qDebug ( " Got the list of news " ) ;
foreach ( RssItem * article , news ) {
2009-08-24 10:28:31 +04:00
QTreeWidgetItem * it = new QTreeWidgetItem ( listNews ) ;
it - > setText ( 0 , article - > getTitle ( ) ) ;
it - > setText ( 1 , article - > getParent ( ) - > getUrl ( ) ) ;
2009-08-21 11:40:57 +04:00
if ( article - > isRead ( ) ) {
2009-08-24 10:28:31 +04:00
it - > setData ( 0 , Qt : : ForegroundRole , QVariant ( QColor ( " grey " ) ) ) ;
it - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/sphere.png " ) ) ) ;
2009-08-21 11:40:57 +04:00
} else {
2009-08-24 10:28:31 +04:00
it - > setData ( 0 , Qt : : ForegroundRole , QVariant ( QColor ( " blue " ) ) ) ;
it - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/sphere2.png " ) ) ) ;
2007-08-03 18:37:56 +04:00
}
2009-08-21 11:40:57 +04:00
}
qDebug ( " Added all news to the GUI " ) ;
qDebug ( " First news selected " ) ;
}
2007-08-03 18:37:56 +04:00
2009-08-21 11:40:57 +04:00
// display a news
2009-08-24 10:28:31 +04:00
void RSSImp : : refreshTextBrowser ( QTreeWidgetItem * item ) {
2009-08-21 22:24:29 +04:00
if ( ! item ) return ;
2009-08-24 10:28:31 +04:00
RssStream * stream = listStreams - > getRSSItemFromUrl ( item - > text ( 1 ) ) ;
RssItem * article = stream - > getItem ( item - > text ( 0 ) ) ;
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;'> " ;
html + = " <div style='background-color: #678db2; font-weight: bold; color: #fff;'> " + article - > getTitle ( ) + " </div> " ;
if ( article - > getDate ( ) . isValid ( ) ) {
html + = " <div style='background-color: #efefef;'><b> " + tr ( " Date: " ) + " </b> " + article - > getDate ( ) . toString ( ) + " </div> " ;
}
if ( ! article - > getAuthor ( ) . isEmpty ( ) ) {
html + = " <div style='background-color: #efefef;'><b> " + tr ( " Author: " ) + " </b> " + article - > getAuthor ( ) + " </div> " ;
}
html + = " </div> " ;
html + = " <divstyle='margin-left: 5px; margin-right: 5px;'> " + article - > getDescription ( ) + " </div> " ;
textBrowser - > setHtml ( html ) ;
article - > setRead ( ) ;
2009-08-24 10:28:31 +04:00
item - > setData ( 0 , Qt : : ForegroundRole , QVariant ( QColor ( " grey " ) ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/sphere.png " ) ) ) ;
2009-08-23 17:26:16 +04:00
// Decrement feed nb unread news
2009-08-24 10:28:31 +04:00
updateItemInfos ( listStreams - > getUnreadItem ( ) ) ;
updateItemInfos ( listStreams - > getTreeItemFromUrl ( item - > text ( 1 ) ) ) ;
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
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
settings . setValue ( " rss/splitter_h " , splitter_h - > saveState ( ) ) ;
settings . setValue ( " rss/splitter_v " , splitter_v - > saveState ( ) ) ;
qDebug ( " Splitters position saved " ) ;
}
void RSSImp : : restoreSlidersPosition ( ) {
QSettings settings ( " qBittorrent " , " qBittorrent " ) ;
QByteArray pos_h = settings . value ( " rss/splitter_h " , QByteArray ( ) ) . toByteArray ( ) ;
if ( ! pos_h . isNull ( ) ) {
splitter_h - > restoreState ( pos_h ) ;
}
QByteArray pos_v = settings . value ( " rss/splitter_v " , QByteArray ( ) ) . toByteArray ( ) ;
if ( ! pos_v . isNull ( ) ) {
splitter_v - > restoreState ( pos_v ) ;
}
}
2009-08-23 16:49:37 +04:00
void RSSImp : : updateItemsInfos ( QList < QTreeWidgetItem * > items ) {
foreach ( QTreeWidgetItem * item , items ) {
updateItemInfos ( item ) ;
}
}
void RSSImp : : updateItemInfos ( QTreeWidgetItem * item ) {
RssFile * rss_item = listStreams - > getRSSItem ( item ) ;
item - > setText ( 0 , rss_item - > getName ( ) + QString : : fromUtf8 ( " ( " ) + QString : : number ( rss_item - > getNbUnRead ( ) , 10 ) + QString ( " ) " ) ) ;
2009-08-23 17:05:47 +04:00
// If item has a parent, update it too
if ( item - > parent ( ) )
updateItemInfos ( item - > parent ( ) ) ;
2009-08-23 16:49:37 +04:00
}
2009-08-21 11:40:57 +04:00
void RSSImp : : updateFeedIcon ( QString url , QString icon_path ) {
2009-08-23 16:22:19 +04:00
QTreeWidgetItem * item = listStreams - > getTreeItemFromUrl ( url ) ;
2009-08-21 11:40:57 +04:00
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( icon_path ) ) ) ;
}
void RSSImp : : updateFeedInfos ( QString url , QString aliasOrUrl , unsigned int nbUnread ) {
2009-08-23 16:22:19 +04:00
QTreeWidgetItem * item = listStreams - > getTreeItemFromUrl ( url ) ;
RssStream * stream = ( RssStream * ) listStreams - > getRSSItem ( item ) ;
2009-08-21 11:40:57 +04:00
item - > setText ( 0 , aliasOrUrl + QString : : fromUtf8 ( " ( " ) + QString : : number ( nbUnread , 10 ) + QString ( " ) " ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( stream - > getIconPath ( ) ) ) ) ;
2009-08-23 17:05:47 +04:00
// Update parent
if ( item - > parent ( ) )
updateItemInfos ( item - > parent ( ) ) ;
2009-08-21 11:40:57 +04:00
// If the feed is selected, update the displayed news
2009-08-22 07:00:31 +04:00
if ( listStreams - > currentItem ( ) = = item ) {
2009-08-21 18:48:33 +04:00
refreshNewsList ( item ) ;
2009-08-21 11:40:57 +04:00
}
}
RSSImp : : RSSImp ( bittorrent * BTSession ) : QWidget ( ) , BTSession ( BTSession ) {
setupUi ( this ) ;
2009-08-21 21:49:48 +04:00
2009-08-21 11:40:57 +04:00
rssmanager = new RssManager ( BTSession ) ;
2009-08-23 12:10:56 +04:00
listStreams = new FeedList ( splitter_h , rssmanager ) ;
splitter_h - > insertWidget ( 0 , listStreams ) ;
2009-08-24 10:28:31 +04:00
listNews - > hideColumn ( 1 ) ;
2009-08-23 12:10:56 +04:00
2009-08-21 11:40:57 +04:00
fillFeedsList ( ) ;
2009-08-24 10:28:31 +04:00
refreshNewsList ( listStreams - > currentItem ( ) ) ;
2009-08-23 18:56:44 +04:00
loadFoldersOpenState ( ) ;
2009-08-21 11:40:57 +04:00
connect ( rssmanager , SIGNAL ( feedInfosChanged ( QString , QString , unsigned int ) ) , this , SLOT ( updateFeedInfos ( QString , QString , unsigned int ) ) ) ;
connect ( rssmanager , SIGNAL ( feedIconChanged ( QString , QString ) ) , this , SLOT ( updateFeedIcon ( QString , QString ) ) ) ;
connect ( listStreams , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayRSSListMenu ( const QPoint & ) ) ) ;
connect ( listNews , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayItemsListMenu ( const QPoint & ) ) ) ;
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 ( ) ) ) ;
connect ( actionRename , SIGNAL ( triggered ( ) ) , this , SLOT ( renameFiles ( ) ) ) ;
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 ( ) ) ) ;
connect ( actionUpdate_all_feeds , SIGNAL ( triggered ( ) ) , this , SLOT ( on_updateAllButton_clicked ( ) ) ) ;
2009-08-21 11:40:57 +04:00
connect ( actionCopy_feed_URL , SIGNAL ( triggered ( ) ) , this , SLOT ( copySelectedFeedsURL ( ) ) ) ;
connect ( actionRSS_feed_downloader , SIGNAL ( triggered ( ) ) , this , SLOT ( showFeedDownloader ( ) ) ) ;
2009-08-22 06:19:40 +04:00
connect ( actionMark_items_read , SIGNAL ( triggered ( ) ) , this , SLOT ( on_markReadButton_clicked ( ) ) ) ;
// News list actions
2009-08-21 11:40:57 +04:00
connect ( actionOpen_news_URL , SIGNAL ( triggered ( ) ) , this , SLOT ( openNewsUrl ( ) ) ) ;
connect ( actionDownload_torrent , SIGNAL ( triggered ( ) ) , this , SLOT ( downloadTorrent ( ) ) ) ;
2009-08-21 18:48:33 +04:00
connect ( listStreams , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( refreshNewsList ( QTreeWidgetItem * ) ) ) ;
2009-08-23 16:49:37 +04:00
connect ( listStreams , SIGNAL ( foldersAltered ( QList < QTreeWidgetItem * > ) ) , this , SLOT ( updateItemsInfos ( QList < QTreeWidgetItem * > ) ) ) ;
2009-08-24 08:01:26 +04:00
connect ( listStreams , SIGNAL ( overwriteAttempt ( QString ) ) , this , SLOT ( displayOverwriteError ( QString ) ) ) ;
2009-08-23 16:49:37 +04:00
2009-08-24 10:28:31 +04:00
connect ( listNews , SIGNAL ( itemClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( refreshTextBrowser ( QTreeWidgetItem * ) ) ) ;
connect ( listNews , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( downloadTorrent ( ) ) ) ;
2009-08-22 18:06:05 +04:00
2009-08-21 11:40:57 +04:00
// Refresh all feeds
rssmanager - > refreshAll ( ) ;
// 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 " ) ;
}
RSSImp : : ~ RSSImp ( ) {
qDebug ( " Deleting RSSImp... " ) ;
2009-08-23 18:56:44 +04:00
saveFoldersOpenState ( ) ;
2009-08-23 12:10:56 +04:00
delete listStreams ;
2009-08-21 11:40:57 +04:00
delete rssmanager ;
qDebug ( " RSSImp deleted " ) ;
}
2007-04-05 23:26:30 +04:00