From 8dfaac8bfb5c0179aadccbae545ee8d326488e7d Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Sat, 19 Jan 2013 16:06:48 +0100 Subject: [PATCH] Sort providers according to user's preference instead of name --- src/globalsearch/globalsearchview.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/globalsearch/globalsearchview.cpp b/src/globalsearch/globalsearchview.cpp index 08f382b4b..c28a1c2ce 100644 --- a/src/globalsearch/globalsearchview.cpp +++ b/src/globalsearch/globalsearchview.cpp @@ -32,6 +32,8 @@ #include "library/librarymodel.h" #include "library/groupbydialog.h" +#include + #include #include #include @@ -154,8 +156,21 @@ GlobalSearchView::~GlobalSearchView() { } namespace { - bool CompareProviderName(SearchProvider* left, SearchProvider* right) { - return left->name() < right->name(); + 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(); + } 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_); if (show_providers_) { - // Sort the list of providers alphabetically + // Sort the list of providers QList 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;