1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

Sort providers according to user's preference instead of name

This commit is contained in:
Arnaud Bienner 2013-01-19 16:06:48 +01:00
parent 51d0664eb6
commit 8dfaac8bfb

View File

@ -32,6 +32,8 @@
#include "library/librarymodel.h" #include "library/librarymodel.h"
#include "library/groupbydialog.h" #include "library/groupbydialog.h"
#include <boost/bind.hpp>
#include <QMenu> #include <QMenu>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItem> #include <QStandardItem>
@ -154,8 +156,21 @@ GlobalSearchView::~GlobalSearchView() {
} }
namespace { namespace {
bool CompareProviderName(SearchProvider* left, SearchProvider* right) { bool CompareProvider(const QStringList& provider_order,
SearchProvider* left, SearchProvider* right) {
const int left_index = provider_order.indexOf(left->id());
const int right_index = provider_order.indexOf(right->id());
if (left_index == -1 && right_index == -1) {
// None are in our provider list: compare name instead
return left->name() < right->name(); return left->name() < right->name();
} else if (left_index == -1) {
// Left provider not in provider list
return false;
} else if (right_index == -1) {
// Right provider not in provider list
return true;
}
return left_index < right_index;
} }
} }
@ -191,9 +206,10 @@ void GlobalSearchView::ReloadSettings() {
ui_->providers_group->setVisible(show_providers_); ui_->providers_group->setVisible(show_providers_);
if (show_providers_) { if (show_providers_) {
// Sort the list of providers alphabetically // Sort the list of providers
QList<SearchProvider*> providers = engine_->providers(); QList<SearchProvider*> providers = engine_->providers();
qSort(providers.begin(), providers.end(), CompareProviderName); qSort(providers.begin(), providers.end(),
boost::bind(&CompareProvider, provider_order, _1, _2));
bool any_disabled = false; bool any_disabled = false;