@ -48,6 +48,7 @@
@@ -48,6 +48,7 @@
# include "searchlistdelegate.h"
# include "searchwidget.h"
# include "searchtab.h"
# include "ui_searchtab.h"
namespace
{
@ -58,25 +59,20 @@ namespace
@@ -58,25 +59,20 @@ namespace
SearchTab : : SearchTab ( SearchWidget * parent )
: QWidget ( parent )
, m_ui ( new Ui : : SearchTab ( ) )
, m_parent ( parent )
{
setupUi ( this ) ;
retranslateUi ( this ) ;
m_ui - > setupUi ( this ) ;
m_box = static_cast < QVBoxLayout * > ( this - > layout ( ) ) ;
m_resultsLbl = new QLabel ( this ) ;
m_resultsBrowser = new QTreeView ( this ) ;
# ifdef QBT_USES_QT5
// This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused ;
unused . setVerticalHeader ( m_resultsBrowser - > header ( ) ) ;
m_resultsBrowser - > header ( ) - > setParent ( m_resultsBrowser ) ;
unused . setVerticalHeader ( m_ui - > resultsBrowser - > header ( ) ) ;
m_ui - > resultsBrowser - > header ( ) - > setParent ( m_ui - > resultsBrowser ) ;
unused . setVerticalHeader ( new QHeaderView ( Qt : : Horizontal ) ) ;
# endif
m_resultsBrowser - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
m_box - > addWidget ( m_resultsLbl ) ;
m_box - > addWidget ( m_resultsBrowser ) ;
m_ui - > resultsBrowser - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
// Set Search results list model
m_searchListModel = new QStandardItemModel ( 0 , SearchSortModel : : NB_SEARCH_COLUMNS , this ) ;
@ -89,43 +85,48 @@ SearchTab::SearchTab(SearchWidget *parent)
@@ -89,43 +85,48 @@ SearchTab::SearchTab(SearchWidget *parent)
m_proxyModel = new SearchSortModel ( this ) ;
m_proxyModel - > setDynamicSortFilter ( true ) ;
m_proxyModel - > setSourceModel ( m_searchListModel ) ;
m_resultsBrowser - > setModel ( m_proxyModel ) ;
m_ui - > resultsBrowser - > setModel ( m_proxyModel ) ;
m_searchDelegate = new SearchListDelegate ( this ) ;
m_resultsBrowser - > setItemDelegate ( m_searchDelegate ) ;
m_ui - > resultsBrowser - > setItemDelegate ( m_searchDelegate ) ;
m_resultsBrowser - > hideColumn ( SearchSortModel : : DL_LINK ) ; // Hide url column
m_resultsBrowser - > hideColumn ( SearchSortModel : : DESC_LINK ) ;
m_ui - > resultsBrowser - > hideColumn ( SearchSortModel : : DL_LINK ) ; // Hide url column
m_ui - > resultsBrowser - > hideColumn ( SearchSortModel : : DESC_LINK ) ;
m_resultsBrowser - > setRootIsDecorated ( false ) ;
m_resultsBrowser - > setAllColumnsShowFocus ( true ) ;
m_resultsBrowser - > setSortingEnabled ( true ) ;
m_ui - > resultsBrowser - > setRootIsDecorated ( false ) ;
m_ui - > resultsBrowser - > setAllColumnsShowFocus ( true ) ;
m_ui - > resultsBrowser - > setSortingEnabled ( true ) ;
// Connect signals to slots (search part)
connect ( m_resultsBrowser , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( downloadSelectedItem ( const QModelIndex & ) ) ) ;
connect ( m_ui - > resultsBrowser , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( downloadSelectedItem ( const QModelIndex & ) ) ) ;
// Load last columns width for search results list
if ( ! loadColWidthResultsList ( ) )
m_resultsBrowser - > header ( ) - > resizeSection ( 0 , 275 ) ;
m_ui - > resultsBrowser - > header ( ) - > resizeSection ( 0 , 275 ) ;
// Sort by Seeds
m_resultsBrowser - > sortByColumn ( SearchSortModel : : SEEDS , Qt : : DescendingOrder ) ;
m_ui - > resultsBrowser - > sortByColumn ( SearchSortModel : : SEEDS , Qt : : DescendingOrder ) ;
fillFilterComboBoxes ( ) ;
updateFilter ( ) ;
connect ( filterMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( minSeeds , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( minSeeds , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( maxSeeds , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( maxSeeds , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( minSize , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( minSize , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( maxSize , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( maxSize , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( minSizeUnit , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( maxSizeUnit , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > filterMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > minSeeds , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > minSeeds , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > maxSeeds , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > maxSeeds , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > minSize , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > minSize , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > maxSize , SIGNAL ( editingFinished ( ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > maxSize , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > minSizeUnit , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
connect ( m_ui - > maxSizeUnit , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( updateFilter ( ) ) ) ;
}
SearchTab : : ~ SearchTab ( )
{
delete m_ui ;
}
void SearchTab : : downloadSelectedItem ( const QModelIndex & index )
@ -137,7 +138,7 @@ void SearchTab::downloadSelectedItem(const QModelIndex &index)
@@ -137,7 +138,7 @@ void SearchTab::downloadSelectedItem(const QModelIndex &index)
QHeaderView * SearchTab : : header ( ) const
{
return m_resultsBrowser - > header ( ) ;
return m_ui - > resultsBrowser - > header ( ) ;
}
bool SearchTab : : loadColWidthResultsList ( )
@ -149,16 +150,15 @@ bool SearchTab::loadColWidthResultsList()
@@ -149,16 +150,15 @@ bool SearchTab::loadColWidthResultsList()
if ( widthList . size ( ) > m_searchListModel - > columnCount ( ) )
return false ;
unsigned int listSize = widthList . size ( ) ;
for ( unsigned int i = 0 ; i < listSize ; + + i )
m_resultsBrowser - > header ( ) - > resizeSection ( i , widthList . at ( i ) . toInt ( ) ) ;
for ( int i = 0 ; i < widthList . size ( ) ; + + i )
m_ui - > resultsBrowser - > header ( ) - > resizeSection ( i , widthList . at ( i ) . toInt ( ) ) ;
return true ;
}
QTreeView * SearchTab : : getCurrentTreeView ( ) const
{
return m_resultsBrowser ;
return m_ui - > resultsBrowser ;
}
SearchSortModel * SearchTab : : getCurrentSearchListProxy ( ) const
@ -199,8 +199,8 @@ void SearchTab::updateResultsCount()
@@ -199,8 +199,8 @@ void SearchTab::updateResultsCount()
{
const int totalResults = getCurrentSearchListModel ( ) ? getCurrentSearchListModel ( ) - > rowCount ( QModelIndex ( ) ) : 0 ;
const int filteredResults = getCurrentSearchListProxy ( ) ? getCurrentSearchListProxy ( ) - > rowCount ( QModelIndex ( ) ) : totalResults ;
m_resultsLbl - > setText ( tr ( " Results (showing <i>%1</i> out of <i>%2</i>): " , " i.e: Search results " )
. arg ( filteredResults ) . arg ( totalResults ) ) ;
m_ui - > resultsLbl - > setText ( tr ( " Results (showing <i>%1</i> out of <i>%2</i>): " , " i.e: Search results " )
. arg ( filteredResults ) . arg ( totalResults ) ) ;
}
void SearchTab : : updateFilter ( )
@ -209,14 +209,14 @@ void SearchTab::updateFilter()
@@ -209,14 +209,14 @@ void SearchTab::updateFilter()
SearchSortModel * filterModel = getCurrentSearchListProxy ( ) ;
filterModel - > enableNameFilter ( filteringMode ( ) = = OnlyNames ) ;
// we update size and seeds filter parameters in the model even if they are disabled
// because we need to read them from the model when search tabs switch
filterModel - > setSeedsFilter ( minSeeds - > value ( ) , maxSeeds - > value ( ) ) ;
filterModel - > setSeedsFilter ( m_ui - > minSeeds - > value ( ) , m_ui - > maxSeeds - > value ( ) ) ;
filterModel - > setSizeFilter (
sizeInBytes ( minSize - > value ( ) , static_cast < SizeUnit > ( minSizeUnit - > currentIndex ( ) ) ) ,
sizeInBytes ( maxSize - > value ( ) , static_cast < SizeUnit > ( maxSizeUnit - > currentIndex ( ) ) ) ) ;
sizeInBytes ( m_ui - > m inSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > minSizeUnit - > currentIndex ( ) ) ) ,
sizeInBytes ( m_ui - > m axSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > maxSizeUnit - > currentIndex ( ) ) ) ) ;
SettingsStorage : : instance ( ) - > storeValue ( KEY_FILTER_MODE_SETTING_NAME ,
filterMode - > itemData ( filterMode - > currentIndex ( ) ) ) ;
m_ui - > filterMode - > itemData ( m_ui - > filterMode - > currentIndex ( ) ) ) ;
filterModel - > invalidate ( ) ;
updateResultsCount ( ) ;
}
@ -233,29 +233,29 @@ void SearchTab::fillFilterComboBoxes()
@@ -233,29 +233,29 @@ void SearchTab::fillFilterComboBoxes()
unitStrings . append ( unitString ( SizeUnit : : PebiByte ) ) ;
unitStrings . append ( unitString ( SizeUnit : : ExbiByte ) ) ;
minSizeUnit - > clear ( ) ;
maxSizeUnit - > clear ( ) ;
minSizeUnit - > addItems ( unitStrings ) ;
maxSizeUnit - > addItems ( unitStrings ) ;
m_ui - > m inSizeUnit - > clear ( ) ;
m_ui - > m axSizeUnit - > clear ( ) ;
m_ui - > m inSizeUnit - > addItems ( unitStrings ) ;
m_ui - > m axSizeUnit - > addItems ( unitStrings ) ;
minSize - > setValue ( 0 ) ;
minSizeUnit - > setCurrentIndex ( static_cast < int > ( SizeUnit : : MebiByte ) ) ;
m_ui - > m inSize - > setValue ( 0 ) ;
m_ui - > m inSizeUnit - > setCurrentIndex ( static_cast < int > ( SizeUnit : : MebiByte ) ) ;
maxSize - > setValue ( - 1 ) ;
maxSizeUnit - > setCurrentIndex ( static_cast < int > ( SizeUnit : : TebiByte ) ) ;
m_ui - > m axSize - > setValue ( - 1 ) ;
m_ui - > m axSizeUnit - > setCurrentIndex ( static_cast < int > ( SizeUnit : : TebiByte ) ) ;
filterMode - > clear ( ) ;
m_ui - > filterMode - > clear ( ) ;
QMetaEnum nameFilteringModeEnum =
this - > metaObject ( ) - > enumerator ( this - > metaObject ( ) - > indexOfEnumerator ( " NameFilteringMode " ) ) ;
filterMode - > addItem ( tr ( " Torrent names only " ) , nameFilteringModeEnum . valueToKey ( OnlyNames ) ) ;
filterMode - > addItem ( tr ( " Everywhere " ) , nameFilteringModeEnum . valueToKey ( Everywhere ) ) ;
m_ui - > filterMode - > addItem ( tr ( " Torrent names only " ) , nameFilteringModeEnum . valueToKey ( OnlyNames ) ) ;
m_ui - > filterMode - > addItem ( tr ( " Everywhere " ) , nameFilteringModeEnum . valueToKey ( Everywhere ) ) ;
QVariant selectedMode = SettingsStorage : : instance ( ) - > loadValue (
KEY_FILTER_MODE_SETTING_NAME , nameFilteringModeEnum . valueToKey ( OnlyNames ) ) ;
int index = filterMode - > findData ( selectedMode ) ;
filterMode - > setCurrentIndex ( index = = - 1 ? 0 : index ) ;
int index = m_ui - > filterMode - > findData ( selectedMode ) ;
m_ui - > filterMode - > setCurrentIndex ( index = = - 1 ? 0 : index ) ;
}
QString SearchTab : : statusText ( SearchTab : : Status st )
@ -298,5 +298,5 @@ SearchTab::NameFilteringMode SearchTab::filteringMode() const
@@ -298,5 +298,5 @@ SearchTab::NameFilteringMode SearchTab::filteringMode() const
{
QMetaEnum metaEnum =
this - > metaObject ( ) - > enumerator ( this - > metaObject ( ) - > indexOfEnumerator ( " NameFilteringMode " ) ) ;
return static_cast < NameFilteringMode > ( metaEnum . keyToValue ( filterMode - > itemData ( filterMode - > currentIndex ( ) ) . toByteArray ( ) ) ) ;
return static_cast < NameFilteringMode > ( metaEnum . keyToValue ( m_ui - > filterMode - > itemData ( m_ui - > filterMode - > currentIndex ( ) ) . toByteArray ( ) ) ) ;
}