Update the Search settings page, use the configured provider order

This commit is contained in:
David Sansome 2012-06-11 16:26:33 +01:00
parent 9d6b72b4ab
commit 7b4ff1d2ee
12 changed files with 134 additions and 191 deletions

View File

@ -331,7 +331,6 @@
<file>providers/skyfm.png</file>
<file>providers/digitallyimported-32.png</file>
<file>providers/grooveshark.png</file>
<file>allthethings.png</file>
<file>globalsearch.css</file>
<file>clementine-spotify-public.pem</file>
<file>icons/22x22/user-away.png</file>

View File

@ -343,14 +343,6 @@ void GlobalSearch::ReloadSettings() {
}
}
bool GlobalSearch::HideOtherSearchBoxes() {
QSettings s;
s.beginGroup(kSettingsGroup);
return s.value("show_globalsearch", true).toBool() &&
s.value("hide_others", false).toBool();
}
void GlobalSearch::SaveProvidersSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);

View File

@ -60,8 +60,6 @@ public:
bool is_provider_enabled(const SearchProvider* provider) const;
bool is_provider_usable(SearchProvider* provider) const;
static bool HideOtherSearchBoxes();
public slots:
void ReloadSettings();

View File

@ -42,8 +42,13 @@ void GlobalSearchModel::AddResults(const SearchProvider::ResultList& results) {
SearchProvider* provider = results.first().provider_;
if (!provider_sort_indices_.contains(provider)) {
// TODO: Check if the user has configured a sort order for this provider.
sort_index = next_provider_sort_index_ ++;
// Use the user's preferred order if one was set
int configured_index = provider_order_.indexOf(provider->id());
if (configured_index != -1) {
sort_index = configured_index;
} else {
sort_index = next_provider_sort_index_ ++;
}
QStandardItem* divider = new QStandardItem(provider->icon(), provider->name());
divider->setData(true, LibraryModel::Role_IsDivider);

View File

@ -45,6 +45,7 @@ public:
};
void set_use_pretty_covers(bool pretty) { use_pretty_covers_ = pretty; }
void set_provider_order(const QStringList& provider_order) { provider_order_ = provider_order; }
void Clear();
@ -73,6 +74,7 @@ private:
int next_provider_sort_index_;
QMap<ContainerKey, QStandardItem*> containers_;
QStringList provider_order_;
bool use_pretty_covers_;
QIcon artist_icon_;
QIcon album_icon_;

View File

@ -79,11 +79,8 @@ void GlobalSearchSettingsPage::Load() {
AddProviderItem(engine, provider);
}
ui_->show_globalsearch->setChecked(s.value("show_globalsearch", true).toBool());
ui_->hide_others->setChecked(s.value("hide_others", false).toBool());
ui_->combine->setChecked(s.value("combine_identical_results", true).toBool());
ui_->tooltip->setChecked(s.value("tooltip", true).toBool());
ui_->tooltip_help->setChecked(s.value("tooltip_help", true).toBool());
ui_->show_providers->setChecked(s.value("show_providers", true).toBool());
ui_->show_suggestions->setChecked(s.value("show_suggestions", true).toBool());
}
void GlobalSearchSettingsPage::AddProviderItem(GlobalSearch* engine,
@ -144,11 +141,8 @@ void GlobalSearchSettingsPage::Save() {
}
s.setValue("provider_order", provider_order);
s.setValue("show_globalsearch", ui_->show_globalsearch->isChecked());
s.setValue("hide_others", ui_->hide_others->isChecked() && ui_->show_globalsearch->isChecked());
s.setValue("combine_identical_results", ui_->combine->isChecked());
s.setValue("tooltip", ui_->tooltip->isChecked());
s.setValue("tooltip_help", ui_->tooltip_help->isChecked());
s.setValue("show_providers", ui_->show_providers->isChecked());
s.setValue("show_suggestions", ui_->show_suggestions->isChecked());
}
void GlobalSearchSettingsPage::MoveUp() {

View File

@ -18,43 +18,16 @@
<normaloff>:/icons/32x32/search.png</normaloff>:/icons/32x32/search.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="show_globalsearch">
<property name="text">
<string>Show the &quot;Search for anything&quot; box above the sidebar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hide_others">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Hide all other search boxes</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="sources_group">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Sources</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="combine">
<property name="text">
<string>Combine identical results from different sources</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Enable sources below to include them in search results. When identical results are available from more than one source, ones at the top will take priority.</string>
<string>Enable sources below to include them in search results. Results will be displayed in this order.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -136,28 +109,22 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="results_group">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QGroupBox" name="empty_list_group">
<property name="title">
<string>Results</string>
<string>When the list is empty...</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="tooltip">
<widget class="QCheckBox" name="show_providers">
<property name="text">
<string>Show a tooltip with more information about each result</string>
<string>Show which sources are enabled and disabled</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="tooltip_help">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QCheckBox" name="show_suggestions">
<property name="text">
<string>Include keyboard shortcut help in the tooltip</string>
<string>Show search suggestions</string>
</property>
</widget>
</item>
@ -166,73 +133,16 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>sources</tabstop>
<tabstop>up</tabstop>
<tabstop>down</tabstop>
<tabstop>configure</tabstop>
<tabstop>show_providers</tabstop>
<tabstop>show_suggestions</tabstop>
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
</resources>
<connections>
<connection>
<sender>show_globalsearch</sender>
<signal>toggled(bool)</signal>
<receiver>hide_others</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>86</x>
<y>23</y>
</hint>
<hint type="destinationlabel">
<x>88</x>
<y>53</y>
</hint>
</hints>
</connection>
<connection>
<sender>show_globalsearch</sender>
<signal>toggled(bool)</signal>
<receiver>sources_group</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>171</x>
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>165</x>
<y>77</y>
</hint>
</hints>
</connection>
<connection>
<sender>show_globalsearch</sender>
<signal>toggled(bool)</signal>
<receiver>results_group</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>18</y>
</hint>
<hint type="destinationlabel">
<x>240</x>
<y>416</y>
</hint>
</hints>
</connection>
<connection>
<sender>tooltip</sender>
<signal>toggled(bool)</signal>
<receiver>tooltip_help</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>121</x>
<y>447</y>
</hint>
<hint type="destinationlabel">
<x>123</x>
<y>469</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View File

@ -55,7 +55,9 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent)
swap_models_timer_(new QTimer(this)),
update_suggestions_timer_(new QTimer(this)),
search_icon_(IconLoader::Load("search")),
warning_icon_(IconLoader::Load("dialog-warning"))
warning_icon_(IconLoader::Load("dialog-warning")),
show_providers_(true),
show_suggestions_(true)
{
ui_->setupUi(this);
@ -139,38 +141,60 @@ namespace {
}
void GlobalSearchView::ReloadSettings() {
// Delete any old status widgets
qDeleteAll(provider_status_widgets_);
provider_status_widgets_.clear();
// Sort the list of providers alphabetically
QList<SearchProvider*> providers = engine_->providers();
qSort(providers.begin(), providers.end(), CompareProviderName);
bool any_disabled = false;
foreach (SearchProvider* provider, providers) {
QWidget* parent = ui_->enabled_list;
if (!engine_->is_provider_usable(provider)) {
parent = ui_->disabled_list;
any_disabled = true;
}
SearchProviderStatusWidget* widget =
new SearchProviderStatusWidget(warning_icon_, engine_, provider);
parent->layout()->addWidget(widget);
provider_status_widgets_ << widget;
}
ui_->disabled_label->setVisible(any_disabled);
// Update models to use pretty covers.
QSettings s;
// Library settings
s.beginGroup(LibraryView::kSettingsGroup);
const bool pretty = s.value("pretty_covers", true).toBool();
front_model_->set_use_pretty_covers(pretty);
back_model_->set_use_pretty_covers(pretty);
s.endGroup();
// Global search settings
s.beginGroup(GlobalSearch::kSettingsGroup);
const QStringList provider_order =
s.value("provider_order", QStringList() << "library").toStringList();
front_model_->set_provider_order(provider_order);
back_model_->set_provider_order(provider_order);
show_providers_ = s.value("show_providers", true).toBool();
show_suggestions_ = s.value("show_suggestions", true).toBool();
s.endGroup();
// Delete any old status widgets
qDeleteAll(provider_status_widgets_);
provider_status_widgets_.clear();
// Toggle visibility of the providers group
ui_->providers_group->setVisible(show_providers_);
if (show_providers_) {
// Sort the list of providers alphabetically
QList<SearchProvider*> providers = engine_->providers();
qSort(providers.begin(), providers.end(), CompareProviderName);
bool any_disabled = false;
foreach (SearchProvider* provider, providers) {
QWidget* parent = ui_->enabled_list;
if (!engine_->is_provider_usable(provider)) {
parent = ui_->disabled_list;
any_disabled = true;
}
SearchProviderStatusWidget* widget =
new SearchProviderStatusWidget(warning_icon_, engine_, provider);
parent->layout()->addWidget(widget);
provider_status_widgets_ << widget;
}
ui_->disabled_label->setVisible(any_disabled);
}
ui_->suggestions_group->setVisible(show_suggestions_);
if (!show_suggestions_) {
update_suggestions_timer_->stop();
}
}
void GlobalSearchView::UpdateSuggestions() {
@ -398,8 +422,10 @@ void GlobalSearchView::OpenSelectedInNewPlaylist() {
}
void GlobalSearchView::showEvent(QShowEvent* e) {
UpdateSuggestions();
update_suggestions_timer_->start();
if (show_suggestions_) {
UpdateSuggestions();
update_suggestions_timer_->start();
}
QWidget::showEvent(e);
}

View File

@ -114,6 +114,9 @@ private:
QIcon search_icon_;
QIcon warning_icon_;
bool show_providers_;
bool show_suggestions_;
};
#endif // GLOBALSEARCHVIEW_H

View File

@ -80,7 +80,7 @@
<x>0</x>
<y>0</y>
<width>435</width>
<height>605</height>
<height>604</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -116,38 +116,56 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Clementine will find music in:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<widget class="QWidget" name="providers_group" native="true">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Clementine will find music in:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="enabled_list" native="true"/>
</item>
<item>
<widget class="QLabel" name="disabled_label">
<property name="text">
<string>But these sources are disabled:</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="disabled_list" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="enabled_list" native="true"/>
</item>
<item>
<widget class="QLabel" name="disabled_label">
<property name="text">
<string>But these sources are disabled:</string>
</property>
<widget class="QWidget" name="suggestions_group" native="true">
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Why not try...</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="suggestions_list" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="disabled_list" native="true"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Why not try...</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="suggestions_list" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -108,9 +108,6 @@ void InternetViewContainer::SetHeaderVisible(QWidget* header, bool visible) {
if (!header)
return;
if (visible && GlobalSearch::HideOtherSearchBoxes())
return;
HeaderData& d = headers_[header];
if (d.visible_ == visible)
return;

View File

@ -47,6 +47,5 @@ LibraryFilterWidget* LibraryViewContainer::filter() const {
}
void LibraryViewContainer::ReloadSettings() {
filter()->setVisible(!GlobalSearch::HideOtherSearchBoxes());
view()->ReloadSettings();
}