@ -35,9 +35,11 @@
# include <QMessageBox>
# include <QMessageBox>
# include <QString>
# include <QString>
# include <QClipboard>
# include <QClipboard>
# include <QDragMoveEvent>
# include "rss_imp.h"
# include "rss_imp.h"
# include "FeedDownloader.h"
# include "FeedDownloader.h"
# include "feedList.h"
# include "bittorrent.h"
# include "bittorrent.h"
// display a right-click menu
// display a right-click menu
@ -54,7 +56,7 @@ void RSSImp::displayRSSListMenu(const QPoint& pos){
myRSSListMenu . addSeparator ( ) ;
myRSSListMenu . addSeparator ( ) ;
if ( selectedItems . size ( ) = = 1 ) {
if ( selectedItems . size ( ) = = 1 ) {
myRSSListMenu . addAction ( actionRename ) ;
myRSSListMenu . addAction ( actionRename ) ;
RssFile * rss_item = rssmanager - > getFile ( getItemPath ( selectedItems . first ( ) ) ) ;
RssFile * rss_item = rssmanager - > getFile ( listStreams - > getItemPath ( selectedItems . first ( ) ) ) ;
if ( rss_item - > getType ( ) = = RssFile : : FOLDER )
if ( rss_item - > getType ( ) = = RssFile : : FOLDER )
myRSSListMenu . addAction ( actionNew_folder ) ;
myRSSListMenu . addAction ( actionNew_folder ) ;
}
}
@ -85,19 +87,8 @@ void RSSImp::displayItemsListMenu(const QPoint&){
myItemListMenu . exec ( QCursor : : pos ( ) ) ;
myItemListMenu . exec ( QCursor : : pos ( ) ) ;
}
}
QStringList RSSImp : : getItemPath ( QTreeWidgetItem * item ) const {
QStringList path ;
if ( item ) {
if ( item - > parent ( ) ) {
path = getItemPath ( item - > parent ( ) ) ;
}
path < < item - > text ( 1 ) ;
}
return path ;
}
QStringList RSSImp : : getCurrentFeedPath ( ) const {
QStringList RSSImp : : getCurrentFeedPath ( ) const {
return getItemPath ( listStreams - > currentItem ( ) ) ;
return listStreams - > getItemPath ( listStreams - > currentItem ( ) ) ;
}
}
RssFile : : FileType RSSImp : : getItemType ( QTreeWidgetItem * item ) const {
RssFile : : FileType RSSImp : : getItemType ( QTreeWidgetItem * item ) const {
@ -111,7 +102,7 @@ void RSSImp::askNewFolder() {
QTreeWidgetItem * parent_item = 0 ;
QTreeWidgetItem * parent_item = 0 ;
if ( listStreams - > selectedItems ( ) . size ( ) > 0 ) {
if ( listStreams - > selectedItems ( ) . size ( ) > 0 ) {
parent_item = listStreams - > selectedItems ( ) . at ( 0 ) ;
parent_item = listStreams - > selectedItems ( ) . at ( 0 ) ;
foreach ( QString name , getItemPath ( parent_item ) ) {
foreach ( QString name , listStreams - > getItemPath ( parent_item ) ) {
dest_path < < name ;
dest_path < < name ;
}
}
}
}
@ -130,6 +121,7 @@ void RSSImp::askNewFolder() {
folder_item - > setData ( 2 , Qt : : DisplayRole , QVariant ( ( int ) RssFile : : FOLDER ) ) ;
folder_item - > setData ( 2 , Qt : : DisplayRole , QVariant ( ( int ) RssFile : : FOLDER ) ) ;
folder_item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/oxygen/folder.png " ) ) ) ;
folder_item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/oxygen/folder.png " ) ) ) ;
// Expand parent folder to display new folder
// Expand parent folder to display new folder
if ( parent_item )
parent_item - > setExpanded ( true ) ;
parent_item - > setExpanded ( true ) ;
rssmanager - > saveStreamList ( ) ;
rssmanager - > saveStreamList ( ) ;
}
}
@ -140,9 +132,9 @@ void RSSImp::on_newFeedButton_clicked() {
QStringList dest_path ;
QStringList dest_path ;
QTreeWidgetItem * current_item = listStreams - > currentItem ( ) ;
QTreeWidgetItem * current_item = listStreams - > currentItem ( ) ;
if ( getItemType ( current_item ) ! = RssFile : : FOLDER )
if ( getItemType ( current_item ) ! = RssFile : : FOLDER )
dest_path = getItemPath ( current_item - > parent ( ) ) ;
dest_path = listStreams - > getItemPath ( current_item - > parent ( ) ) ;
else
else
dest_path = getItemPath ( current_item ) ;
dest_path = listStreams - > getItemPath ( current_item ) ;
bool ok ;
bool ok ;
QString clip_txt = qApp - > clipboard ( ) - > text ( ) ;
QString clip_txt = qApp - > clipboard ( ) - > text ( ) ;
QString default_url = " http:// " ;
QString default_url = " http:// " ;
@ -189,7 +181,7 @@ void RSSImp::deleteSelectedItems() {
textBrowser - > clear ( ) ;
textBrowser - > clear ( ) ;
listNews - > clear ( ) ;
listNews - > clear ( ) ;
}
}
rssmanager - > removeFile ( getItemPath ( item ) ) ;
rssmanager - > removeFile ( listStreams - > getItemPath ( item ) ) ;
delete item ;
delete item ;
}
}
rssmanager - > saveStreamList ( ) ;
rssmanager - > saveStreamList ( ) ;
@ -229,9 +221,9 @@ void RSSImp::renameFiles() {
Q_ASSERT ( selectedItems . size ( ) = = 1 ) ;
Q_ASSERT ( selectedItems . size ( ) = = 1 ) ;
QTreeWidgetItem * item = selectedItems . at ( 0 ) ;
QTreeWidgetItem * item = selectedItems . at ( 0 ) ;
bool ok ;
bool ok ;
QString newName = QInputDialog : : getText ( this , tr ( " Please choose a new name for this RSS feed " ) , tr ( " New feed name: " ) , QLineEdit : : Normal , rssmanager - > getFile ( getItemPath ( item ) ) - > getName ( ) , & ok ) ;
QString newName = QInputDialog : : getText ( this , tr ( " Please choose a new name for this RSS feed " ) , tr ( " New feed name: " ) , QLineEdit : : Normal , rssmanager - > getFile ( listStreams - > getItemPath ( item ) ) - > getName ( ) , & ok ) ;
if ( ok ) {
if ( ok ) {
rssmanager - > rename ( getItemPath ( item ) , newName ) ;
rssmanager - > rename ( listStreams - > getItemPath ( item ) , newName ) ;
item - > setText ( 0 , newName ) ;
item - > setText ( 0 , newName ) ;
item - > setText ( 1 , newName ) ;
item - > setText ( 1 , newName ) ;
}
}
@ -242,7 +234,7 @@ void RSSImp::refreshSelectedStreams() {
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QTreeWidgetItem * item ;
QTreeWidgetItem * item ;
foreach ( item , selectedItems ) {
foreach ( item , selectedItems ) {
rssmanager - > refresh ( getItemPath ( item ) ) ;
rssmanager - > refresh ( listStreams - > getItemPath ( item ) ) ;
if ( getItemType ( item ) = = RssFile : : STREAM )
if ( getItemType ( item ) = = RssFile : : STREAM )
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( " :/Icons/loading.png " ) ) ) ;
}
}
@ -260,7 +252,7 @@ void RSSImp::copySelectedFeedsURL() {
void RSSImp : : showFeedDownloader ( ) {
void RSSImp : : showFeedDownloader ( ) {
QTreeWidgetItem * item = listStreams - > selectedItems ( ) [ 0 ] ;
QTreeWidgetItem * item = listStreams - > selectedItems ( ) [ 0 ] ;
RssFile * rss_item = rssmanager - > getFile ( getItemPath ( item ) ) ;
RssFile * rss_item = rssmanager - > getFile ( listStreams - > getItemPath ( item ) ) ;
if ( rss_item - > getType ( ) = = RssFile : : STREAM )
if ( rss_item - > getType ( ) = = RssFile : : STREAM )
new FeedDownloaderDlg ( this , item - > text ( 1 ) , rss_item - > getName ( ) , BTSession ) ;
new FeedDownloaderDlg ( this , item - > text ( 1 ) , rss_item - > getName ( ) , BTSession ) ;
}
}
@ -269,7 +261,7 @@ void RSSImp::on_markReadButton_clicked() {
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QList < QTreeWidgetItem * > selectedItems = listStreams - > selectedItems ( ) ;
QTreeWidgetItem * item ;
QTreeWidgetItem * item ;
foreach ( item , selectedItems ) {
foreach ( item , selectedItems ) {
RssFile * rss_item = rssmanager - > getFile ( getItemPath ( item ) ) ;
RssFile * rss_item = rssmanager - > getFile ( listStreams - > getItemPath ( item ) ) ;
rss_item - > markAllAsRead ( ) ;
rss_item - > markAllAsRead ( ) ;
item - > setData ( 0 , Qt : : DisplayRole , rss_item - > getName ( ) + QString : : fromUtf8 ( " (0) " ) ) ;
item - > setData ( 0 , Qt : : DisplayRole , rss_item - > getName ( ) + QString : : fromUtf8 ( " (0) " ) ) ;
}
}
@ -407,7 +399,7 @@ QString RSSImp::getCurrentFeedUrl() const {
void RSSImp : : updateFeedInfos ( QString url , QString aliasOrUrl , unsigned int nbUnread ) {
void RSSImp : : updateFeedInfos ( QString url , QString aliasOrUrl , unsigned int nbUnread ) {
QTreeWidgetItem * item = getTreeItemFromUrl ( url ) ;
QTreeWidgetItem * item = getTreeItemFromUrl ( url ) ;
RssStream * stream = ( RssStream * ) rssmanager - > getFile ( getItemPath ( item ) ) ;
RssStream * stream = ( RssStream * ) rssmanager - > getFile ( listStreams - > getItemPath ( item ) ) ;
item - > setText ( 0 , aliasOrUrl + QString : : fromUtf8 ( " ( " ) + QString : : number ( nbUnread , 10 ) + QString ( " ) " ) ) ;
item - > setText ( 0 , aliasOrUrl + QString : : fromUtf8 ( " ( " ) + QString : : number ( nbUnread , 10 ) + QString ( " ) " ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( stream - > getIconPath ( ) ) ) ) ;
item - > setData ( 0 , Qt : : DecorationRole , QVariant ( QIcon ( stream - > getIconPath ( ) ) ) ) ;
// If the feed is selected, update the displayed news
// If the feed is selected, update the displayed news
@ -419,11 +411,11 @@ void RSSImp::updateFeedInfos(QString url, QString aliasOrUrl, unsigned int nbUnr
RSSImp : : RSSImp ( bittorrent * BTSession ) : QWidget ( ) , BTSession ( BTSession ) {
RSSImp : : RSSImp ( bittorrent * BTSession ) : QWidget ( ) , BTSession ( BTSession ) {
setupUi ( this ) ;
setupUi ( this ) ;
// Hide second column (url) and third column (type)
listStreams - > hideColumn ( 1 ) ;
listStreams - > hideColumn ( 2 ) ;
rssmanager = new RssManager ( BTSession ) ;
rssmanager = new RssManager ( BTSession ) ;
listStreams = new FeedList ( splitter_h , rssmanager ) ;
splitter_h - > insertWidget ( 0 , listStreams ) ;
fillFeedsList ( ) ;
fillFeedsList ( ) ;
connect ( rssmanager , SIGNAL ( feedInfosChanged ( QString , QString , unsigned int ) ) , this , SLOT ( updateFeedInfos ( QString , QString , unsigned int ) ) ) ;
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 ( rssmanager , SIGNAL ( feedIconChanged ( QString , QString ) ) , this , SLOT ( updateFeedIcon ( QString , QString ) ) ) ;
@ -458,6 +450,7 @@ RSSImp::RSSImp(bittorrent *BTSession) : QWidget(), BTSession(BTSession){
// Bind saveSliders slots
// Bind saveSliders slots
connect ( splitter_v , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
connect ( splitter_v , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
connect ( splitter_h , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
connect ( splitter_h , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( saveSlidersPosition ( ) ) ) ;
qDebug ( " RSSImp constructed " ) ;
qDebug ( " RSSImp constructed " ) ;
}
}
@ -470,6 +463,7 @@ void RSSImp::selectFirstFeed(){
RSSImp : : ~ RSSImp ( ) {
RSSImp : : ~ RSSImp ( ) {
qDebug ( " Deleting RSSImp... " ) ;
qDebug ( " Deleting RSSImp... " ) ;
delete listStreams ;
delete rssmanager ;
delete rssmanager ;
qDebug ( " RSSImp deleted " ) ;
qDebug ( " RSSImp deleted " ) ;
}
}