@ -31,7 +31,6 @@
# include <QApplication>
# include <QApplication>
# include <QDir>
# include <QDir>
# include <QMenu>
# include <QMenu>
# include <QMetaEnum>
# include <QTreeView>
# include <QTreeView>
# include <QStandardItemModel>
# include <QStandardItemModel>
# include <QHeaderView>
# include <QHeaderView>
@ -43,7 +42,7 @@
# include "base/utils/misc.h"
# include "base/utils/misc.h"
# include "base/preferences.h"
# include "base/preferences.h"
# include "base/settingsstorag e.h"
# include "base/settingvalu e.h"
# include "guiiconprovider.h"
# include "guiiconprovider.h"
# include "searchsortmodel.h"
# include "searchsortmodel.h"
# include "searchlistdelegate.h"
# include "searchlistdelegate.h"
@ -51,13 +50,6 @@
# include "searchtab.h"
# include "searchtab.h"
# include "ui_searchtab.h"
# include "ui_searchtab.h"
namespace
{
# define SETTINGS_KEY(name) "Search / " name
const QString KEY_FILTER_MODE_SETTING_NAME = SETTINGS_KEY ( " FilteringMode " ) ;
}
SearchTab : : SearchTab ( SearchWidget * parent )
SearchTab : : SearchTab ( SearchWidget * parent )
: QWidget ( parent )
: QWidget ( parent )
, m_ui ( new Ui : : SearchTab ( ) )
, m_ui ( new Ui : : SearchTab ( ) )
@ -216,15 +208,14 @@ void SearchTab::updateFilter()
{
{
using Utils : : Misc : : SizeUnit ;
using Utils : : Misc : : SizeUnit ;
SearchSortModel * filterModel = getCurrentSearchListProxy ( ) ;
SearchSortModel * filterModel = getCurrentSearchListProxy ( ) ;
filterModel - > enableNameFilter ( filteringMode ( ) = = OnlyNames ) ;
filterModel - > enableNameFilter ( filteringMode ( ) = = NameFilteringMode : : OnlyNames ) ;
// we update size and seeds filter parameters in the model even if they are disabled
// we update size and seeds filter parameters in the model even if they are disabled
filterModel - > setSeedsFilter ( m_ui - > minSeeds - > value ( ) , m_ui - > maxSeeds - > value ( ) ) ;
filterModel - > setSeedsFilter ( m_ui - > minSeeds - > value ( ) , m_ui - > maxSeeds - > value ( ) ) ;
filterModel - > setSizeFilter (
filterModel - > setSizeFilter (
sizeInBytes ( m_ui - > minSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > minSizeUnit - > currentIndex ( ) ) ) ,
sizeInBytes ( m_ui - > minSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > minSizeUnit - > currentIndex ( ) ) ) ,
sizeInBytes ( m_ui - > maxSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > maxSizeUnit - > currentIndex ( ) ) ) ) ;
sizeInBytes ( m_ui - > maxSize - > value ( ) , static_cast < SizeUnit > ( m_ui - > maxSizeUnit - > currentIndex ( ) ) ) ) ;
SettingsStorage : : instance ( ) - > storeValue ( KEY_FILTER_MODE_SETTING_NAME ,
nameFilteringModeSetting ( ) = filteringMode ( ) ;
m_ui - > filterMode - > itemData ( m_ui - > filterMode - > currentIndex ( ) ) ) ;
filterModel - > invalidate ( ) ;
filterModel - > invalidate ( ) ;
updateResultsCount ( ) ;
updateResultsCount ( ) ;
@ -255,14 +246,10 @@ void SearchTab::fillFilterComboBoxes()
m_ui - > filterMode - > clear ( ) ;
m_ui - > filterMode - > clear ( ) ;
QMetaEnum nameFilteringModeEnum =
m_ui - > filterMode - > addItem ( tr ( " Torrent names only " ) , static_cast < int > ( NameFilteringMode : : OnlyNames ) ) ;
this - > metaObject ( ) - > enumerator ( this - > metaObject ( ) - > indexOfEnumerator ( " NameFilteringMode " ) ) ;
m_ui - > filterMode - > addItem ( tr ( " Everywhere " ) , static_cast < int > ( NameFilteringMode : : Everywhere ) ) ;
m_ui - > filterMode - > addItem ( tr ( " Torrent names only " ) , nameFilteringModeEnum . valueToKey ( OnlyNames ) ) ;
QVariant selectedMode = static_cast < int > ( nameFilteringModeSetting ( ) . value ( ) ) ;
m_ui - > filterMode - > addItem ( tr ( " Everywhere " ) , nameFilteringModeEnum . valueToKey ( Everywhere ) ) ;
QVariant selectedMode = SettingsStorage : : instance ( ) - > loadValue (
KEY_FILTER_MODE_SETTING_NAME , nameFilteringModeEnum . valueToKey ( OnlyNames ) ) ;
int index = m_ui - > filterMode - > findData ( selectedMode ) ;
int index = m_ui - > filterMode - > findData ( selectedMode ) ;
m_ui - > filterMode - > setCurrentIndex ( index = = - 1 ? 0 : index ) ;
m_ui - > filterMode - > setCurrentIndex ( index = = - 1 ? 0 : index ) ;
}
}
@ -305,9 +292,7 @@ QString SearchTab::statusIconName(SearchTab::Status st)
SearchTab : : NameFilteringMode SearchTab : : filteringMode ( ) const
SearchTab : : NameFilteringMode SearchTab : : filteringMode ( ) const
{
{
QMetaEnum metaEnum =
return static_cast < NameFilteringMode > ( m_ui - > filterMode - > itemData ( m_ui - > filterMode - > currentIndex ( ) ) . toInt ( ) ) ;
this - > metaObject ( ) - > enumerator ( this - > metaObject ( ) - > indexOfEnumerator ( " NameFilteringMode " ) ) ;
return static_cast < NameFilteringMode > ( metaEnum . keyToValue ( m_ui - > filterMode - > itemData ( m_ui - > filterMode - > currentIndex ( ) ) . toByteArray ( ) ) ) ;
}
}
void SearchTab : : loadSettings ( )
void SearchTab : : loadSettings ( )
@ -355,3 +340,9 @@ void SearchTab::displayToggleColumnsMenu(const QPoint&)
saveSettings ( ) ;
saveSettings ( ) ;
}
}
}
}
CachedSettingValue < SearchTab : : NameFilteringMode > & SearchTab : : nameFilteringModeSetting ( )
{
static CachedSettingValue < NameFilteringMode > setting ( " Search/FilteringMode " , NameFilteringMode : : OnlyNames ) ;
return setting ;
}