@ -48,332 +48,353 @@
# include "autoexpandabledialog.h"
# include "autoexpandabledialog.h"
# include "torrentfilterenum.h"
# include "torrentfilterenum.h"
LabelFiltersList : : LabelFiltersList ( QWidget * parent ) : QListWidget ( parent ) {
LabelFiltersList : : LabelFiltersList ( QWidget * parent ) : QListWidget ( parent )
itemHover = 0 ;
{
// Accept drop
itemHover = 0 ;
setAcceptDrops ( true ) ;
// Accept drop
setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Expanding ) ;
setAcceptDrops ( true ) ;
setStyleSheet ( " QListWidget { background: transparent; border: 0 } " ) ;
setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Expanding ) ;
setStyleSheet ( " QListWidget { background: transparent; border: 0 } " ) ;
# if defined(Q_OS_MAC)
# if defined(Q_OS_MAC)
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
# endif
# endif
}
}
void LabelFiltersList : : addItem ( QListWidgetItem * it ) {
void LabelFiltersList : : addItem ( QListWidgetItem * it )
Q_ASSERT ( count ( ) > = 2 ) ;
{
for ( int i = 2 ; i < count ( ) ; + + i ) {
Q_ASSERT ( count ( ) > = 2 ) ;
if ( item ( i ) - > text ( ) . localeAwareCompare ( it - > text ( ) ) > = 0 ) {
for ( int i = 2 ; i < count ( ) ; + + i ) {
insertItem ( i , it ) ;
if ( item ( i ) - > text ( ) . localeAwareCompare ( it - > text ( ) ) > = 0 ) {
return ;
insertItem ( i , it ) ;
return ;
}
}
}
}
QListWidget : : addItem ( it ) ;
QListWidget : : addItem ( it ) ;
}
}
QString LabelFiltersList : : labelFromRow ( int row ) const {
QString LabelFiltersList : : labelFromRow ( int row ) const
Q_ASSERT ( row > 1 ) ;
{
const QString & label = item ( row ) - > text ( ) ;
Q_ASSERT ( row > 1 ) ;
QStringList parts = label . split ( " " ) ;
const QString & label = item ( row ) - > text ( ) ;
Q_ASSERT ( parts . size ( ) > = 2 ) ;
QStringList parts = label . split ( " " ) ;
parts . removeLast ( ) ; // Remove trailing number
Q_ASSERT ( parts . size ( ) > = 2 ) ;
return parts . join ( " " ) ;
parts . removeLast ( ) ; // Remove trailing number
return parts . join ( " " ) ;
}
}
int LabelFiltersList : : rowFromLabel ( QString label ) const {
int LabelFiltersList : : rowFromLabel ( QString label ) const
Q_ASSERT ( ! label . isEmpty ( ) ) ;
{
for ( int i = 2 ; i < count ( ) ; + + i ) {
Q_ASSERT ( ! label . isEmpty ( ) ) ;
if ( label = = labelFromRow ( i ) ) return i ;
for ( int i = 2 ; i < count ( ) ; + + i )
}
if ( label = = labelFromRow ( i ) ) return i ;
return - 1 ;
return - 1 ;
}
}
void LabelFiltersList : : dragMoveEvent ( QDragMoveEvent * event ) {
void LabelFiltersList : : dragMoveEvent ( QDragMoveEvent * event )
if ( itemAt ( event - > pos ( ) ) & & row ( itemAt ( event - > pos ( ) ) ) > 0 ) {
{
if ( itemHover ) {
if ( itemAt ( event - > pos ( ) ) & & row ( itemAt ( event - > pos ( ) ) ) > 0 ) {
if ( itemHover ! = itemAt ( event - > pos ( ) ) ) {
if ( itemHover ) {
setItemHover ( false ) ;
if ( itemHover ! = itemAt ( event - > pos ( ) ) ) {
itemHover = itemAt ( event - > pos ( ) ) ;
setItemHover ( false ) ;
setItemHover ( true ) ;
itemHover = itemAt ( event - > pos ( ) ) ;
}
setItemHover ( true ) ;
} else {
}
itemHover = itemAt ( event - > pos ( ) ) ;
}
setItemHover ( true ) ;
else {
itemHover = itemAt ( event - > pos ( ) ) ;
setItemHover ( true ) ;
}
event - > acceptProposedAction ( ) ;
}
else {
if ( itemHover )
setItemHover ( false ) ;
event - > ignore ( ) ;
}
}
event - > acceptProposedAction ( ) ;
} else {
if ( itemHover )
setItemHover ( false ) ;
event - > ignore ( ) ;
}
}
}
void LabelFiltersList : : dropEvent ( QDropEvent * event ) {
void LabelFiltersList : : dropEvent ( QDropEvent * event )
qDebug ( " Drop Event in labels list " ) ;
{
if ( itemAt ( event - > pos ( ) ) ) {
qDebug ( " Drop Event in labels list " ) ;
emit torrentDropped ( row ( itemAt ( event - > pos ( ) ) ) ) ;
if ( itemAt ( event - > pos ( ) ) )
}
emit torrentDropped ( row ( itemAt ( event - > pos ( ) ) ) ) ;
event - > ignore ( ) ;
event - > ignore ( ) ;
setItemHover ( false ) ;
setItemHover ( false ) ;
// Select current item again
// Select current item again
currentItem ( ) - > setSelected ( true ) ;
currentItem ( ) - > setSelected ( true ) ;
}
}
void LabelFiltersList : : dragLeaveEvent ( QDragLeaveEvent * ) {
void LabelFiltersList : : dragLeaveEvent ( QDragLeaveEvent * )
if ( itemHover )
{
setItemHover ( false ) ;
if ( itemHover )
// Select current item again
setItemHover ( false ) ;
currentItem ( ) - > setSelected ( true ) ;
// Select current item again
currentItem ( ) - > setSelected ( true ) ;
}
}
void LabelFiltersList : : setItemHover ( bool hover ) {
void LabelFiltersList : : setItemHover ( bool hover )
Q_ASSERT ( itemHover ) ;
{
if ( hover ) {
Q_ASSERT ( itemHover ) ;
itemHover - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " folder-documents.png " ) ) ;
if ( hover ) {
itemHover - > setSelected ( true ) ;
itemHover - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " folder-documents.png " ) ) ;
//setCurrentItem(itemHover);
itemHover - > setSelected ( true ) ;
} else {
//setCurrentItem(itemHover);
itemHover - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory.png " ) ) ;
}
//itemHover->setSelected(false);
else {
itemHover = 0 ;
itemHover - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory.png " ) ) ;
}
//itemHover->setSelected(false);
itemHover = 0 ;
}
}
}
StatusFiltersWidget : : StatusFiltersWidget ( QWidget * parent ) : QListWidget ( parent ) , m_shown ( false ) {
StatusFiltersWidget : : StatusFiltersWidget ( QWidget * parent ) : QListWidget ( parent ) , m_shown ( false )
setUniformItemSizes ( true ) ;
{
setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
setUniformItemSizes ( true ) ;
// Height is fixed (sizeHint().height() is used)
setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Fixed ) ;
// Height is fixed (sizeHint().height() is used)
setStyleSheet ( " QListWidget { background: transparent; border: 0 } " ) ;
setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Fixed ) ;
setStyleSheet ( " QListWidget { background: transparent; border: 0 } " ) ;
# if defined(Q_OS_MAC)
# if defined(Q_OS_MAC)
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
setAttribute ( Qt : : WA_MacShowFocusRect , false ) ;
# endif
# endif
}
}
QSize StatusFiltersWidget : : sizeHint ( ) const {
QSize StatusFiltersWidget : : sizeHint ( ) const
QSize size = QListWidget : : sizeHint ( ) ;
{
// Height should be exactly the height of the content
QSize size = QListWidget : : sizeHint ( ) ;
size . setHeight ( contentsSize ( ) . height ( ) + 2 * frameWidth ( ) + 6 ) ;
// Height should be exactly the height of the content
return size ;
size . setHeight ( contentsSize ( ) . height ( ) + 2 * frameWidth ( ) + 6 ) ;
return size ;
}
}
TransferListFiltersWidget : : TransferListFiltersWidget ( QWidget * parent , TransferListWidget * transferList ) : QFrame ( parent ) , transferList ( transferList ) , nb_labeled ( 0 ) , nb_torrents ( 0 ) {
TransferListFiltersWidget : : TransferListFiltersWidget ( QWidget * parent , TransferListWidget * transferList ) : QFrame ( parent ) , transferList ( transferList ) , nb_labeled ( 0 ) , nb_torrents ( 0 )
// Construct lists
{
vLayout = new QVBoxLayout ( ) ;
// Construct lists
vLayout - > setContentsMargins ( 0 , 4 , 0 , 0 ) ;
vLayout = new QVBoxLayout ( ) ;
QFont font ;
vLayout - > setContentsMargins ( 0 , 4 , 0 , 0 ) ;
font . setBold ( true ) ;
QFont font ;
font . setCapitalization ( QFont : : SmallCaps ) ;
font . setBold ( true ) ;
QLabel * torrentsLabel = new QLabel ( tr ( " Torrents " ) ) ;
font . setCapitalization ( QFont : : SmallCaps ) ;
torrentsLabel - > setIndent ( 2 ) ;
QLabel * torrentsLabel = new QLabel ( tr ( " Torrents " ) ) ;
torrentsLabel - > setFont ( font ) ;
torrentsLabel - > setIndent ( 2 ) ;
vLayout - > addWidget ( torrentsLabel ) ;
torrentsLabel - > setFont ( font ) ;
statusFilters = new StatusFiltersWidget ( this ) ;
vLayout - > addWidget ( torrentsLabel ) ;
vLayout - > addWidget ( statusFilters ) ;
statusFilters = new StatusFiltersWidget ( this ) ;
QLabel * labelsLabel = new QLabel ( tr ( " Labels " ) ) ;
vLayout - > addWidget ( statusFilters ) ;
labelsLabel - > setIndent ( 2 ) ;
QLabel * labelsLabel = new QLabel ( tr ( " Labels " ) ) ;
labelsLabel - > setFont ( font ) ;
labelsLabel - > setIndent ( 2 ) ;
vLayout - > addWidget ( labelsLabel ) ;
labelsLabel - > setFont ( font ) ;
labelFilters = new LabelFiltersList ( this ) ;
vLayout - > addWidget ( labelsLabel ) ;
vLayout - > addWidget ( labelFilters ) ;
labelFilters = new LabelFiltersList ( this ) ;
setLayout ( vLayout ) ;
vLayout - > addWidget ( labelFilters ) ;
labelFilters - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
setLayout ( vLayout ) ;
statusFilters - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
labelFilters - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
statusFilters - > setSpacing ( 0 ) ;
statusFilters - > setHorizontalScrollBarPolicy ( Qt : : ScrollBarAlwaysOff ) ;
setContentsMargins ( 0 , 0 , 0 , 0 ) ;
statusFilters - > setSpacing ( 0 ) ;
vLayout - > setSpacing ( 2 ) ;
setContentsMargins ( 0 , 0 , 0 , 0 ) ;
// Add status filters
vLayout - > setSpacing ( 2 ) ;
QListWidgetItem * all = new QListWidgetItem ( statusFilters ) ;
// Add status filters
all - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All " ) + " (0) " ) ) ;
QListWidgetItem * all = new QListWidgetItem ( statusFilters ) ;
all - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/filterall.png " ) ) ;
all - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All " ) + " (0) " ) ) ;
QListWidgetItem * downloading = new QListWidgetItem ( statusFilters ) ;
all - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/filterall.png " ) ) ;
downloading - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Downloading " ) + " (0) " ) ) ;
QListWidgetItem * downloading = new QListWidgetItem ( statusFilters ) ;
downloading - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/downloading.png " ) ) ;
downloading - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Downloading " ) + " (0) " ) ) ;
QListWidgetItem * completed = new QListWidgetItem ( statusFilters ) ;
downloading - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/downloading.png " ) ) ;
completed - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Completed " ) + " (0) " ) ) ;
QListWidgetItem * completed = new QListWidgetItem ( statusFilters ) ;
completed - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/uploading.png " ) ) ;
completed - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Completed " ) + " (0) " ) ) ;
QListWidgetItem * paused = new QListWidgetItem ( statusFilters ) ;
completed - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/uploading.png " ) ) ;
paused - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Paused " ) + " (0) " ) ) ;
QListWidgetItem * resumed = new QListWidgetItem ( statusFilters ) ;
paused - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/paused.png " ) ) ;
resumed - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Resumed " ) + " (0) " ) ) ;
QListWidgetItem * resumed = new QListWidgetItem ( statusFilters ) ;
resumed - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/resumed.png " ) ) ;
resumed - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Resumed " ) + " (0) " ) ) ;
QListWidgetItem * paused = new QListWidgetItem ( statusFilters ) ;
resumed - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/resumed.png " ) ) ;
paused - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Paused " ) + " (0) " ) ) ;
QListWidgetItem * active = new QListWidgetItem ( statusFilters ) ;
paused - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/paused.png " ) ) ;
active - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Active " ) + " (0) " ) ) ;
QListWidgetItem * active = new QListWidgetItem ( statusFilters ) ;
active - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/filteractive.png " ) ) ;
active - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Active " ) + " (0) " ) ) ;
QListWidgetItem * inactive = new QListWidgetItem ( statusFilters ) ;
active - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/filteractive.png " ) ) ;
inactive - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Inactive " ) + " (0) " ) ) ;
QListWidgetItem * inactive = new QListWidgetItem ( statusFilters ) ;
inactive - > setData ( Qt : : DecorationRole , QIcon ( " :/icons/skin/filterinactive.png " ) ) ;
inactive - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Inactive " ) + " (0) " ) ) ;
inactive - > setData ( Qt : : DecorationRole , QIcon ( " :/Icons/skin/filterinactive.png " ) ) ;
// SIGNAL/SLOT
connect ( statusFilters , SIGNAL ( currentRowChanged ( int ) ) , transferList , SLOT ( applyStatusFilter ( int ) ) ) ;
// SIGNAL/SLOT
connect ( transferList - > getSourceModel ( ) , SIGNAL ( modelRefreshed ( ) ) , SLOT ( updateTorrentNumbers ( ) ) ) ;
connect ( statusFilters , SIGNAL ( currentRowChanged ( int ) ) , transferList , SLOT ( applyStatusFilter ( int ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentAdded ( TorrentModelItem * ) ) , SLOT ( handleNewTorrent ( TorrentModelItem * ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( modelRefreshed ( ) ) , SLOT ( updateTorrentNumbers ( ) ) ) ;
connect ( labelFilters , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( applyLabelFilter ( int ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentAdded ( TorrentModelItem * ) ) , SLOT ( handleNewTorrent ( TorrentModelItem * ) ) ) ;
connect ( labelFilters , SIGNAL ( torrentDropped ( int ) ) , this , SLOT ( torrentDropped ( int ) ) ) ;
connect ( labelFilters , SIGNAL ( currentRowChanged ( int ) ) , this , SLOT ( applyLabelFilter ( int ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentAboutToBeRemoved ( TorrentModelItem * ) ) , SLOT ( torrentAboutToBeDeleted ( TorrentModelItem * ) ) ) ;
connect ( labelFilters , SIGNAL ( torrentDropped ( int ) ) , this , SLOT ( torrentDropped ( int ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentChangedLabel ( TorrentModelItem * , QString , QString ) ) , SLOT ( torrentChangedLabel ( TorrentModelItem * , QString , QString ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentAboutToBeRemoved ( TorrentModelItem * ) ) , SLOT ( torrentAboutToBeDeleted ( TorrentModelItem * ) ) ) ;
connect ( transferList - > getSourceModel ( ) , SIGNAL ( torrentChangedLabel ( TorrentModelItem * , QString , QString ) ) , SLOT ( torrentChangedLabel ( TorrentModelItem * , QString , QString ) ) ) ;
// Add Label filters
QListWidgetItem * allLabels = new QListWidgetItem ( labelFilters ) ;
// Add Label filters
allLabels - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All labels " ) + " (0) " ) ) ;
QListWidgetItem * allLabels = new QListWidgetItem ( labelFilters ) ;
allLabels - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
allLabels - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All labels " ) + " (0) " ) ) ;
QListWidgetItem * noLabel = new QListWidgetItem ( labelFilters ) ;
allLabels - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
noLabel - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Unlabeled " ) + " (0) " ) ) ;
QListWidgetItem * noLabel = new QListWidgetItem ( labelFilters ) ;
noLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
noLabel - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Unlabeled " ) + " (0) " ) ) ;
noLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
// Load settings
loadSettings ( ) ;
// Load settings
loadSettings ( ) ;
labelFilters - > setCurrentRow ( 0 ) ;
//labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
labelFilters - > setCurrentRow ( 0 ) ;
//labelFilters->selectionModel()->select(labelFilters->model()->index(0,0), QItemSelectionModel::Select);
// Label menu
labelFilters - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
// Label menu
connect ( labelFilters , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( showLabelMenu ( QPoint ) ) ) ;
labelFilters - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( labelFilters , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( showLabelMenu ( QPoint ) ) ) ;
}
}
TransferListFiltersWidget : : ~ TransferListFiltersWidget ( ) {
TransferListFiltersWidget : : ~ TransferListFiltersWidget ( )
saveSettings ( ) ;
{
delete statusFilters ;
saveSettings ( ) ;
delete labelFilters ;
delete statusFilters ;
delete vLayout ;
delete labelFilters ;
delete vLayout ;
}
}
StatusFiltersWidget * TransferListFiltersWidget : : getStatusFilters ( ) const {
StatusFiltersWidget * TransferListFiltersWidget : : getStatusFilters ( ) const
return statusFilters ;
{
return statusFilters ;
}
}
void TransferListFiltersWidget : : saveSettings ( ) const {
void TransferListFiltersWidget : : saveSettings ( ) const
Preferences * const pref = Preferences : : instance ( ) ;
{
pref - > setTransSelFilter ( statusFilters - > currentRow ( ) ) ;
Preferences * const pref = Preferences : : instance ( ) ;
pref - > setTorrentLabels ( customLabels . keys ( ) ) ;
pref - > setTransSelFilter ( statusFilters - > currentRow ( ) ) ;
pref - > setTorrentLabels ( customLabels . keys ( ) ) ;
}
}
void TransferListFiltersWidget : : loadSettings ( ) {
void TransferListFiltersWidget : : loadSettings ( )
statusFilters - > setCurrentRow ( Preferences : : instance ( ) - > getTransSelFilter ( ) ) ;
{
const QStringList label_list = Preferences : : instance ( ) - > getTorrentLabels ( ) ;
statusFilters - > setCurrentRow ( Preferences : : instance ( ) - > getTransSelFilter ( ) ) ;
foreach ( const QString & label , label_list ) {
const QStringList label_list = Preferences : : instance ( ) - > getTorrentLabels ( ) ;
customLabels . insert ( label , 0 ) ;
foreach ( const QString & label , label_list ) {
qDebug ( " Creating label QListWidgetItem: %s " , qPrintable ( label ) ) ;
customLabels . insert ( label , 0 ) ;
QListWidgetItem * newLabel = new QListWidgetItem ( ) ;
qDebug ( " Creating label QListWidgetItem: %s " , qPrintable ( label ) ) ;
newLabel - > setText ( label + " (0) " ) ;
QListWidgetItem * newLabel = new QListWidgetItem ( ) ;
newLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
newLabel - > setText ( label + " (0) " ) ;
labelFilters - > addItem ( newLabel ) ;
newLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
}
labelFilters - > addItem ( newLabel ) ;
}
}
}
void TransferListFiltersWidget : : updateTorrentNumbers ( ) {
void TransferListFiltersWidget : : updateTorrentNumbers ( )
const TorrentStatusReport report = transferList - > getSourceModel ( ) - > getTorrentStatusReport ( ) ;
{
statusFilters - > item ( TorrentFilter : : ALL ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All " ) + " ( " + QString : : number ( report . nb_active + report . nb_inactive ) + " ) " ) ) ;
const TorrentStatusReport report = transferList - > getSourceModel ( ) - > getTorrentStatusReport ( ) ;
statusFilters - > item ( TorrentFilter : : DOWNLOADING ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Downloading " ) + " ( " + QString : : number ( report . nb_downloading ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : ALL ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " All " ) + " ( " + QString : : number ( report . nb_active + report . nb_inactive ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : COMPLETED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Completed " ) + " ( " + QString : : number ( report . nb_seeding ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : DOWNLOADING ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Downloading " ) + " ( " + QString : : number ( report . nb_downloading ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : PAUSED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Paused " ) + " ( " + QString : : number ( report . nb_paused ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : COMPLETED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Completed " ) + " ( " + QString : : number ( report . nb_seeding ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : RESUMED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Resumed " ) + " ( " + QString : : number ( report . nb_active + report . nb_inactive - report . nb_paused ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : PAUSED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Paused " ) + " ( " + QString : : number ( report . nb_paused ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : ACTIVE ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Active " ) + " ( " + QString : : number ( report . nb_active ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : RESUMED ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Resumed " ) + " ( " + QString : : number ( report . nb_active + report . nb_inactive - report . nb_paused ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : INACTIVE ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Inactive " ) + " ( " + QString : : number ( report . nb_inactive ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : ACTIVE ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Active " ) + " ( " + QString : : number ( report . nb_active ) + " ) " ) ) ;
statusFilters - > item ( TorrentFilter : : INACTIVE ) - > setData ( Qt : : DisplayRole , QVariant ( tr ( " Inactive " ) + " ( " + QString : : number ( report . nb_inactive ) + " ) " ) ) ;
}
}
void TransferListFiltersWidget : : torrentDropped ( int row ) {
void TransferListFiltersWidget : : torrentDropped ( int row )
Q_ASSERT ( row > 0 ) ;
{
if ( row = = 1 ) {
Q_ASSERT ( row > 0 ) ;
transferList - > setSelectionLabel ( " " ) ;
if ( row = = 1 )
} else {
transferList - > setSelectionLabel ( " " ) ;
transferList - > setSelectionLabel ( labelFilters - > labelFromRow ( row ) ) ;
else
}
transferList - > setSelectionLabel ( labelFilters - > labelFromRow ( row ) ) ;
}
}
void TransferListFiltersWidget : : addLabel ( QString & label ) {
void TransferListFiltersWidget : : addLabel ( QString & label )
label = fsutils : : toValidFileSystemName ( label . trimmed ( ) ) ;
{
if ( label . isEmpty ( ) | | customLabels . contains ( label ) ) return ;
label = fsutils : : toValidFileSystemName ( label . trimmed ( ) ) ;
QListWidgetItem * newLabel = new QListWidgetItem ( ) ;
if ( label . isEmpty ( ) | | customLabels . contains ( label ) ) return ;
newLabel - > setText ( label + " (0) " ) ;
QListWidgetItem * newLabel = new QListWidgetItem ( ) ;
newLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
newLabel - > setText ( label + " (0) " ) ;
labelFilters - > addItem ( newLabel ) ;
newLabel - > setData ( Qt : : DecorationRole , IconProvider : : instance ( ) - > getIcon ( " inode-directory " ) ) ;
customLabels . insert ( label , 0 ) ;
labelFilters - > addItem ( newLabel ) ;
Preferences : : instance ( ) - > addTorrentLabel ( label ) ;
customLabels . insert ( label , 0 ) ;
Preferences : : instance ( ) - > addTorrentLabel ( label ) ;
}
}
void TransferListFiltersWidget : : showLabelMenu ( QPoint ) {
void TransferListFiltersWidget : : showLabelMenu ( QPoint )
QMenu labelMenu ( labelFilters ) ;
{
QAction * addAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) , tr ( " Add label... " ) ) ;
QMenu labelMenu ( labelFilters ) ;
QAction * removeAct = 0 ;
QAction * addAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) , tr ( " Add label... " ) ) ;
QAction * removeUnusedAct = 0 ;
QAction * removeAct = 0 ;
if ( ! labelFilters - > selectedItems ( ) . empty ( ) & & labelFilters - > row ( labelFilters - > selectedItems ( ) . first ( ) ) > 1 )
QAction * removeUnusedAct = 0 ;
removeAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Remove label " ) ) ;
if ( ! labelFilters - > selectedItems ( ) . empty ( ) & & labelFilters - > row ( labelFilters - > selectedItems ( ) . first ( ) ) > 1 )
else
removeAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Remove label " ) ) ;
removeUnusedAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Remove unused labels " ) ) ;
else
labelMenu . addSeparator ( ) ;
removeUnusedAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " list-remove " ) , tr ( " Remove unused labels " ) ) ;
QAction * startAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) , tr ( " Resume torrents " ) ) ;
labelMenu . addSeparator ( ) ;
QAction * pauseAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) , tr ( " Pause torrents " ) ) ;
QAction * startAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " media-playback-start " ) , tr ( " Resume torrents " ) ) ;
QAction * deleteTorrentsAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " edit-delete " ) , tr ( " Delete torrents " ) ) ;
QAction * pauseAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " media-playback-pause " ) , tr ( " Pause torrents " ) ) ;
QAction * act = 0 ;
QAction * deleteTorrentsAct = labelMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " edit-delete " ) , tr ( " Delete torrents " ) ) ;
act = labelMenu . exec ( QCursor : : pos ( ) ) ;
QAction * act = 0 ;
if ( act ) {
act = labelMenu . exec ( QCursor : : pos ( ) ) ;
if ( act = = removeAct ) {
if ( act ) {
removeSelectedLabel ( ) ;
if ( act = = removeAct ) {
return ;
removeSelectedLabel ( ) ;
}
return ;
if ( act = = removeUnusedAct ) {
}
removeUnusedLabels ( ) ;
if ( act = = removeUnusedAct ) {
return ;
removeUnusedLabels ( ) ;
}
return ;
if ( act = = deleteTorrentsAct ) {
}
transferList - > deleteVisibleTorrents ( ) ;
if ( act = = deleteTorrentsAct ) {
return ;
transferList - > deleteVisibleTorrents ( ) ;
}
return ;
if ( act = = startAct ) {
}
transferList - > startVisibleTorrents ( ) ;
if ( act = = startAct ) {
return ;
transferList - > startVisibleTorrents ( ) ;
}
return ;
if ( act = = pauseAct ) {
}
transferList - > pauseVisibleTorrents ( ) ;
if ( act = = pauseAct ) {
return ;
transferList - > pauseVisibleTorrents ( ) ;
}
return ;
if ( act = = addAct ) {
}
bool ok ;
if ( act = = addAct ) {
QString label = " " ;
bool ok ;
bool invalid ;
QString label = " " ;
do {
bool invalid ;
invalid = false ;
do {
label = AutoExpandableDialog : : getText ( this , tr ( " New Label " ) , tr ( " Label: " ) , QLineEdit : : Normal , label , & ok ) ;
invalid = false ;
if ( ok & & ! label . isEmpty ( ) ) {
label = AutoExpandableDialog : : getText ( this , tr ( " New Label " ) , tr ( " Label: " ) , QLineEdit : : Normal , label , & ok ) ;
if ( fsutils : : isValidFileSystemName ( label ) ) {
if ( ok & & ! label . isEmpty ( ) ) {
addLabel ( label ) ;
if ( fsutils : : isValidFileSystemName ( label ) ) {
} else {
addLabel ( label ) ;
QMessageBox : : warning ( this , tr ( " Invalid label name " ) , tr ( " Please don't use any special characters in the label name. " ) ) ;
}
invalid = true ;
else {
}
QMessageBox : : warning ( this , tr ( " Invalid label name " ) , tr ( " Please don't use any special characters in the label name. " ) ) ;
invalid = true ;
}
}
} while ( invalid ) ;
return ;
}
}
} while ( invalid ) ;
return ;
}
}
}
}
}
void TransferListFiltersWidget : : removeSelectedLabel ( ) {
void TransferListFiltersWidget : : removeSelectedLabel ( )
const int row = labelFilters - > row ( labelFilters - > selectedItems ( ) . first ( ) ) ;
{
Q_ASSERT ( row > 1 ) ;
const int row = labelFilters - > row ( labelFilters - > selectedItems ( ) . first ( ) ) ;
const QString & label = labelFilters - > labelFromRow ( row ) ;
Q_ASSERT ( row > 1 ) ;
Q_ASSERT ( customLabels . contains ( label ) ) ;
const QString & label = labelFilters - > labelFromRow ( row ) ;
customLabels . remove ( label ) ;
Q_ASSERT ( customLabels . contains ( label ) ) ;
transferList - > removeLabelFromRows ( label ) ;
customLabels . remove ( label ) ;
// Select first label
transferList - > removeLabelFromRows ( label ) ;
labelFilters - > setCurrentItem ( labelFilters - > item ( 0 ) ) ;
// Select first label
labelFilters - > selectionModel ( ) - > select ( labelFilters - > model ( ) - > index ( 0 , 0 ) , QItemSelectionModel : : Select ) ;
labelFilters - > setCurrentItem ( labelFilters - > item ( 0 ) ) ;
applyLabelFilter ( 0 ) ;
labelFilters - > selectionModel ( ) - > select ( labelFilters - > model ( ) - > index ( 0 , 0 ) , QItemSelectionModel : : Select ) ;
// Un display filter
applyLabelFilter ( 0 ) ;
delete labelFilters - > takeItem ( row ) ;
// Un display filter
// Save custom labels to remember it was deleted
delete labelFilters - > takeItem ( row ) ;
Preferences : : instance ( ) - > removeTorrentLabel ( label ) ;
// Save custom labels to remember it was deleted
Preferences : : instance ( ) - > removeTorrentLabel ( label ) ;
}
}
void TransferListFiltersWidget : : removeUnusedLabels ( ) {
void TransferListFiltersWidget : : removeUnusedLabels ( )
{
QStringList unusedLabels ;
QStringList unusedLabels ;
QHash < QString , int > : : const_iterator i ;
QHash < QString , int > : : const_iterator i ;
for ( i = customLabels . begin ( ) ; i ! = customLabels . end ( ) ; + + i ) {
for ( i = customLabels . begin ( ) ; i ! = customLabels . end ( ) ; + + i )
if ( i . value ( ) = = 0 )
if ( i . value ( ) = = 0 )
unusedLabels < < i . key ( ) ;
unusedLabels < < i . key ( ) ;
}
foreach ( const QString & label , unusedLabels ) {
foreach ( const QString & label , unusedLabels ) {
customLabels . remove ( label ) ;
customLabels . remove ( label ) ;
delete labelFilters - > takeItem ( labelFilters - > rowFromLabel ( label ) ) ;
delete labelFilters - > takeItem ( labelFilters - > rowFromLabel ( label ) ) ;
@ -381,95 +402,100 @@ void TransferListFiltersWidget::removeUnusedLabels() {
}
}
}
}
void TransferListFiltersWidget : : applyLabelFilter ( int row ) {
void TransferListFiltersWidget : : applyLabelFilter ( int row )
switch ( row ) {
{
case 0 :
switch ( row ) {
transferList - > applyLabelFilterAll ( ) ;
case 0 :
break ;
transferList - > applyLabelFilterAll ( ) ;
case 1 :
break ;
transferList - > applyLabelFilter ( QString ( ) ) ;
case 1 :
break ;
transferList - > applyLabelFilter ( QString ( ) ) ;
default :
break ;
transferList - > applyLabelFilter ( labelFilters - > labelFromRow ( row ) ) ;
default :
}
transferList - > applyLabelFilter ( labelFilters - > labelFromRow ( row ) ) ;
}
}
}
void TransferListFiltersWidget : : torrentChangedLabel ( TorrentModelItem * torrentItem , QString old_label , QString new_label ) {
void TransferListFiltersWidget : : torrentChangedLabel ( TorrentModelItem * torrentItem , QString old_label , QString new_label )
Q_UNUSED ( torrentItem ) ;
{
qDebug ( " Torrent label changed from %s to %s " , qPrintable ( old_label ) , qPrintable ( new_label ) ) ;
Q_UNUSED ( torrentItem ) ;
if ( ! old_label . isEmpty ( ) ) {
qDebug ( " Torrent label changed from %s to %s " , qPrintable ( old_label ) , qPrintable ( new_label ) ) ;
if ( customLabels . contains ( old_label ) ) {
if ( ! old_label . isEmpty ( ) ) {
const int new_count = customLabels . value ( old_label , 0 ) - 1 ;
if ( customLabels . contains ( old_label ) ) {
Q_ASSERT ( new_count > = 0 ) ;
const int new_count = customLabels . value ( old_label , 0 ) - 1 ;
customLabels . insert ( old_label , new_count ) ;
Q_ASSERT ( new_count > = 0 ) ;
const int row = labelFilters - > rowFromLabel ( old_label ) ;
customLabels . insert ( old_label , new_count ) ;
Q_ASSERT ( row > = 2 ) ;
const int row = labelFilters - > rowFromLabel ( old_label ) ;
labelFilters - > item ( row ) - > setText ( old_label + " ( " + QString : : number ( new_count ) + " ) " ) ;
Q_ASSERT ( row > = 2 ) ;
labelFilters - > item ( row ) - > setText ( old_label + " ( " + QString : : number ( new_count ) + " ) " ) ;
}
- - nb_labeled ;
}
}
- - nb_labeled ;
if ( ! new_label . isEmpty ( ) ) {
}
if ( ! customLabels . contains ( new_label ) )
if ( ! new_label . isEmpty ( ) ) {
addLabel ( new_label ) ;
if ( ! customLabels . contains ( new_label ) )
const int new_count = customLabels . value ( new_label , 0 ) + 1 ;
addLabel ( new_label ) ;
Q_ASSERT ( new_count > = 1 ) ;
const int new_count = customLabels . value ( new_label , 0 ) + 1 ;
customLabels . insert ( new_label , new_count ) ;
Q_ASSERT ( new_count > = 1 ) ;
const int row = labelFilters - > rowFromLabel ( new_label ) ;
customLabels . insert ( new_label , new_count ) ;
Q_ASSERT ( row > = 2 ) ;
const int row = labelFilters - > rowFromLabel ( new_label ) ;
labelFilters - > item ( row ) - > setText ( new_label + " ( " + QString : : number ( new_count ) + " ) " ) ;
Q_ASSERT ( row > = 2 ) ;
+ + nb_labeled ;
labelFilters - > item ( row ) - > setText ( new_label + " ( " + QString : : number ( new_count ) + " ) " ) ;
}
+ + nb_labeled ;
updateStickyLabelCounters ( ) ;
}
updateStickyLabelCounters ( ) ;
}
}
void TransferListFiltersWidget : : handleNewTorrent ( TorrentModelItem * torrentItem ) {
void TransferListFiltersWidget : : handleNewTorrent ( TorrentModelItem * torrentItem )
QString label = torrentItem - > data ( TorrentModelItem : : TR_LABEL ) . toString ( ) ;
{
qDebug ( " New torrent was added with label: %s " , qPrintable ( label ) ) ;
QString label = torrentItem - > data ( TorrentModelItem : : TR_LABEL ) . toString ( ) ;
if ( ! label . isEmpty ( ) ) {
qDebug ( " New torrent was added with label: %s " , qPrintable ( label ) ) ;
if ( ! customLabels . contains ( label ) ) {
if ( ! label . isEmpty ( ) ) {
addLabel ( label ) ;
if ( ! customLabels . contains ( label ) ) {
// addLabel may have changed the label, update the model accordingly.
addLabel ( label ) ;
torrentItem - > setData ( TorrentModelItem : : TR_LABEL , label ) ;
// addLabel may have changed the label, update the model accordingly.
torrentItem - > setData ( TorrentModelItem : : TR_LABEL , label ) ;
}
// Update label counter
Q_ASSERT ( customLabels . contains ( label ) ) ;
const int new_count = customLabels . value ( label , 0 ) + 1 ;
customLabels . insert ( label , new_count ) ;
const int row = labelFilters - > rowFromLabel ( label ) ;
qDebug ( " torrentAdded, Row: %d " , row ) ;
Q_ASSERT ( row > = 2 ) ;
Q_ASSERT ( labelFilters - > item ( row ) ) ;
labelFilters - > item ( row ) - > setText ( label + " ( " + QString : : number ( new_count ) + " ) " ) ;
+ + nb_labeled ;
}
}
// Update label counter
+ + nb_torrents ;
Q_ASSERT ( customLabels . contains ( label ) ) ;
Q_ASSERT ( nb_torrents > = 0 ) ;
const int new_count = customLabels . value ( label , 0 ) + 1 ;
Q_ASSERT ( nb_labeled > = 0 ) ;
customLabels . insert ( label , new_count ) ;
Q_ASSERT ( nb_labeled < = nb_torrents ) ;
const int row = labelFilters - > rowFromLabel ( label ) ;
updateStickyLabelCounters ( ) ;
qDebug ( " torrentAdded, Row: %d " , row ) ;
Q_ASSERT ( row > = 2 ) ;
Q_ASSERT ( labelFilters - > item ( row ) ) ;
labelFilters - > item ( row ) - > setText ( label + " ( " + QString : : number ( new_count ) + " ) " ) ;
+ + nb_labeled ;
}
+ + nb_torrents ;
Q_ASSERT ( nb_torrents > = 0 ) ;
Q_ASSERT ( nb_labeled > = 0 ) ;
Q_ASSERT ( nb_labeled < = nb_torrents ) ;
updateStickyLabelCounters ( ) ;
}
}
void TransferListFiltersWidget : : torrentAboutToBeDeleted ( TorrentModelItem * torrentItem ) {
void TransferListFiltersWidget : : torrentAboutToBeDeleted ( TorrentModelItem * torrentItem )
Q_ASSERT ( torrentItem ) ;
{
QString label = torrentItem - > data ( TorrentModelItem : : TR_LABEL ) . toString ( ) ;
Q_ASSERT ( torrentItem ) ;
if ( ! label . isEmpty ( ) ) {
QString label = torrentItem - > data ( TorrentModelItem : : TR_LABEL ) . toString ( ) ;
// Update label counter
if ( ! label . isEmpty ( ) ) {
const int new_count = customLabels . value ( label , 0 ) - 1 ;
// Update label counter
customLabels . insert ( label , new_count ) ;
const int new_count = customLabels . value ( label , 0 ) - 1 ;
const int row = labelFilters - > rowFromLabel ( label ) ;
customLabels . insert ( label , new_count ) ;
Q_ASSERT ( row > = 2 ) ;
const int row = labelFilters - > rowFromLabel ( label ) ;
labelFilters - > item ( row ) - > setText ( label + " ( " + QString : : number ( new_count ) + " ) " ) ;
Q_ASSERT ( row > = 2 ) ;
- - nb_labeled ;
labelFilters - > item ( row ) - > setText ( label + " ( " + QString : : number ( new_count ) + " ) " ) ;
}
- - nb_labeled ;
- - nb_torrents ;
}
qDebug ( " nb_torrents: %d, nb_labeled: %d " , nb_torrents , nb_labeled ) ;
- - nb_torrents ;
Q_ASSERT ( nb_torrents > = 0 ) ;
qDebug ( " nb_torrents: %d, nb_labeled: %d " , nb_torrents , nb_labeled ) ;
Q_ASSERT ( nb_labeled > = 0 ) ;
Q_ASSERT ( nb_torrents > = 0 ) ;
Q_ASSERT ( nb_labeled < = nb_torrents ) ;
Q_ASSERT ( nb_labeled > = 0 ) ;
updateStickyLabelCounters ( ) ;
Q_ASSERT ( nb_labeled < = nb_torrents ) ;
updateStickyLabelCounters ( ) ;
}
}
void TransferListFiltersWidget : : updateStickyLabelCounters ( ) {
void TransferListFiltersWidget : : updateStickyLabelCounters ( )
labelFilters - > item ( 0 ) - > setText ( tr ( " All labels " ) + " ( " + QString : : number ( nb_torrents ) + " ) " ) ;
{
labelFilters - > item ( 1 ) - > setText ( tr ( " Unlabeled " ) + " ( " + QString : : number ( nb_torrents - nb_labeled ) + " ) " ) ;
labelFilters - > item ( 0 ) - > setText ( tr ( " All labels " ) + " ( " + QString : : number ( nb_torrents ) + " ) " ) ;
labelFilters - > item ( 1 ) - > setText ( tr ( " Unlabeled " ) + " ( " + QString : : number ( nb_torrents - nb_labeled ) + " ) " ) ;
}
}