Add a settings page for global search - doesn't save yet

This commit is contained in:
David Sansome 2011-10-30 18:52:38 +00:00
parent 6d45415b00
commit 08e09ce5dd
11 changed files with 497 additions and 2 deletions

View File

@ -121,6 +121,7 @@ set(SOURCES
globalsearch/globalsearch.cpp
globalsearch/globalsearchitemdelegate.cpp
globalsearch/globalsearchpopup.cpp
globalsearch/globalsearchsettingspage.cpp
globalsearch/globalsearchsortmodel.cpp
globalsearch/globalsearchtooltip.cpp
globalsearch/globalsearchwidget.cpp
@ -371,6 +372,7 @@ set(HEADERS
globalsearch/librarysearchprovider.h
globalsearch/globalsearch.h
globalsearch/globalsearchpopup.h
globalsearch/globalsearchsettingspage.h
globalsearch/globalsearchtooltip.h
globalsearch/globalsearchwidget.h
globalsearch/groovesharksearchprovider.h
@ -545,6 +547,7 @@ set(UI
devices/deviceproperties.ui
globalsearch/globalsearchpopup.ui
globalsearch/globalsearchsettingspage.ui
globalsearch/globalsearchwidget.ui
internet/digitallyimportedsettingspage.ui

View File

@ -0,0 +1,168 @@
/* This file is part of Clementine.
Copyright 2011, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "globalsearch.h"
#include "globalsearchsettingspage.h"
#include "core/logging.h"
#include "ui/iconloader.h"
#include "ui/settingsdialog.h"
#include "ui_globalsearchsettingspage.h"
#include <QSettings>
GlobalSearchSettingsPage::GlobalSearchSettingsPage(SettingsDialog* dialog)
: SettingsPage(dialog),
ui_(new Ui::GlobalSearchSettingsPage)
{
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("edit-find"));
ui_->sources->header()->setResizeMode(0, QHeaderView::Stretch);
ui_->sources->header()->setResizeMode(1, QHeaderView::ResizeToContents);
warning_icon_ = IconLoader::Load("dialog-warning");
connect(ui_->up, SIGNAL(clicked()), SLOT(MoveUp()));
connect(ui_->down, SIGNAL(clicked()), SLOT(MoveDown()));
connect(ui_->configure, SIGNAL(clicked()), SLOT(ConfigureProvider()));
connect(ui_->sources, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
SLOT(CurrentProviderChanged(QTreeWidgetItem*)));
}
GlobalSearchSettingsPage::~GlobalSearchSettingsPage() {
}
static bool CompareProviderId(SearchProvider* left, SearchProvider* right) {
return left->id() < right->id();
}
void GlobalSearchSettingsPage::Load() {
QSettings s;
s.beginGroup(GlobalSearch::kSettingsGroup);
GlobalSearch* engine = dialog()->global_search();
QList<SearchProvider*> providers = engine->providers();
// Sort the list of providers alphabetically (by id) initially, so any that
// aren't in the provider_order list will take this order.
qSort(providers.begin(), providers.end(), CompareProviderId);
// Add the ones in the configured list first
ui_->sources->clear();
foreach (const QString& id, s.value("provider_order", QStringList() << "library").toStringList()) {
// Find a matching provider for this id
for (QList<SearchProvider*>::iterator it = providers.begin();
it != providers.end() ; ++it) {
if ((*it)->id() == id) {
AddProviderItem(engine, *it);
providers.erase(it);
break;
}
}
}
// Now add any others that are remaining
foreach (SearchProvider* provider, providers) {
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());
}
void GlobalSearchSettingsPage::AddProviderItem(GlobalSearch* engine,
SearchProvider* provider) {
QTreeWidgetItem* item = new QTreeWidgetItem;
item->setText(0, provider->name());
item->setIcon(0, provider->icon());
const bool enabled = engine->is_provider_enabled(provider);
const bool logged_in = provider->IsLoggedIn();
if (!logged_in) {
item->setData(0, Qt::CheckStateRole, Qt::Unchecked);
item->setIcon(1, warning_icon_);
item->setText(1, tr("Not logged in"));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
} else if (enabled) {
item->setData(0, Qt::CheckStateRole, Qt::Checked);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
} else {
item->setData(0, Qt::CheckStateRole, Qt::Unchecked);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
}
item->setData(0, Qt::UserRole, QVariant::fromValue(provider));
ui_->sources->invisibleRootItem()->addChild(item);
}
void GlobalSearchSettingsPage::Save() {
}
void GlobalSearchSettingsPage::MoveUp() {
MoveCurrentItem(-1);
}
void GlobalSearchSettingsPage::MoveDown() {
MoveCurrentItem(+1);
}
void GlobalSearchSettingsPage::MoveCurrentItem(int d) {
QTreeWidgetItem* item = ui_->sources->currentItem();
if (!item)
return;
QTreeWidgetItem* root = ui_->sources->invisibleRootItem();
const int row = root->indexOfChild(item);
const int new_row = qBound(0, row + d, root->childCount());
if (row == new_row)
return;
root->removeChild(item);
root->insertChild(new_row, item);
ui_->sources->setCurrentItem(item);
}
void GlobalSearchSettingsPage::ConfigureProvider() {
QTreeWidgetItem* item = ui_->sources->currentItem();
if (!item)
return;
SearchProvider* provider = item->data(0, Qt::UserRole).value<SearchProvider*>();
provider->ShowConfig();
}
void GlobalSearchSettingsPage::CurrentProviderChanged(QTreeWidgetItem* item) {
if (!item)
return;
QTreeWidgetItem* root = ui_->sources->invisibleRootItem();
SearchProvider* provider = item->data(0, Qt::UserRole).value<SearchProvider*>();
const int row = root->indexOfChild(item);
ui_->up->setEnabled(row != 0);
ui_->down->setEnabled(row != root->childCount() - 1);
ui_->configure->setEnabled(provider->CanShowConfig());
}

View File

@ -0,0 +1,59 @@
/* This file is part of Clementine.
Copyright 2011, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GLOBALSEARCHSETTINGSPAGE_H
#define GLOBALSEARCHSETTINGSPAGE_H
#include "ui/settingspage.h"
#include <QIcon>
#include <QScopedPointer>
class GlobalSearch;
class SearchProvider;
class Ui_GlobalSearchSettingsPage;
class QTreeWidgetItem;
class GlobalSearchSettingsPage : public SettingsPage {
Q_OBJECT
public:
GlobalSearchSettingsPage(SettingsDialog* dialog);
~GlobalSearchSettingsPage();
void Load();
void Save();
private slots:
void MoveUp();
void MoveDown();
void ConfigureProvider();
void CurrentProviderChanged(QTreeWidgetItem* item);
private:
void AddProviderItem(GlobalSearch* engine, SearchProvider* provider);
void MoveCurrentItem(int d);
private:
QScopedPointer<Ui_GlobalSearchSettingsPage> ui_;
QIcon warning_icon_;
};
#endif // GLOBALSEARCHSETTINGSPAGE_H

View File

@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GlobalSearchSettingsPage</class>
<widget class="QWidget" name="GlobalSearchSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>654</width>
<height>506</height>
</rect>
</property>
<property name="windowTitle">
<string>Global Search</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="show_globalsearch">
<property name="text">
<string>Show the Global Search box above the sidebar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hide_others">
<property name="text">
<string>Hide all other search boxes</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="sources_group">
<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 Global Search results. When identical results are available from more than one source, ones at the top will take priority.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="sources">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">2</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="up">
<property name="text">
<string>Move up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="down">
<property name="text">
<string>Move down</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="configure">
<property name="text">
<string>Configure...</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="results_group">
<property name="title">
<string>Results</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="tooltip">
<property name="text">
<string>Show a tooltip with more information about each result</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="tooltip_help">
<property name="text">
<string>Include keyboard shortcut help in the tooltip</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<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>
</ui>

View File

@ -36,6 +36,7 @@ class GroovesharkSearchProvider : public SearchProvider {
void LoadArtAsync(int id, const Result& result);
void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn();
bool CanShowConfig() const { return true; }
void ShowConfig();
private slots:

View File

@ -103,6 +103,7 @@ public:
// If provider needs user login to search and play songs, this method should
// be reimplemented
virtual bool IsLoggedIn() { return true; }
virtual bool CanShowConfig() const { return false; }
virtual void ShowConfig() { }
static QImage ScaleAndPad(const QImage& image);
@ -154,4 +155,6 @@ private slots:
void BlockingSearchFinished();
};
Q_DECLARE_METATYPE(SearchProvider*)
#endif // SEARCHPROVIDER_H

View File

@ -36,6 +36,7 @@ public:
void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn();
bool CanShowConfig() const { return true; }
void ShowConfig();
private slots:

View File

@ -684,6 +684,9 @@ msgstr ""
msgid "Color"
msgstr ""
msgid "Combine identical results from different sources"
msgstr ""
msgid "Comma separated list of class:level, level is 0-3"
msgstr ""
@ -1091,6 +1094,12 @@ msgstr ""
msgid "Enable shortcuts only when Clementine is focused"
msgstr ""
msgid ""
"Enable sources below to include them in Global Search results. When "
"identical results are available from more than one source, ones at the top "
"will take priority."
msgstr ""
msgid "Enable/disable Last.fm scrobbling"
msgstr ""
@ -1333,6 +1342,9 @@ msgstr ""
msgid "Give it a name:"
msgstr ""
msgid "Global Search"
msgstr ""
msgid "Global search"
msgstr ""
@ -1394,6 +1406,9 @@ msgstr ""
msgid "Hardware information is only available while the device is connected."
msgstr ""
msgid "Hide all other search boxes"
msgstr ""
msgid "High"
msgstr ""
@ -1458,6 +1473,9 @@ msgstr ""
msgid "Include all songs"
msgstr ""
msgid "Include keyboard shortcut help in the tooltip"
msgstr ""
msgid "Increase the volume by 4%"
msgstr ""
@ -1942,6 +1960,9 @@ msgstr ""
msgid "Not installed"
msgstr ""
msgid "Not logged in"
msgstr ""
msgid "Not mounted - double click to mount"
msgstr ""
@ -2340,6 +2361,9 @@ msgstr ""
msgid "Restrict to ASCII characters"
msgstr ""
msgid "Results"
msgstr ""
msgid "Rock"
msgstr ""
@ -2517,6 +2541,9 @@ msgstr ""
msgid "Show a pretty OSD"
msgstr ""
msgid "Show a tooltip with more information about each result"
msgstr ""
msgid "Show above status bar"
msgstr ""
@ -2554,6 +2581,9 @@ msgstr ""
msgid "Show the \"love\" and \"ban\" buttons"
msgstr ""
msgid "Show the Global Search box above the sidebar"
msgstr ""
msgid "Show the scrobble button in the main window"
msgstr ""
@ -2644,6 +2674,9 @@ msgstr ""
msgid "Sorting"
msgstr ""
msgid "Sources"
msgstr ""
msgid "Speex"
msgstr ""

View File

@ -1940,10 +1940,9 @@ void MainWindow::EnsureSettingsDialogCreated() {
settings_dialog_.reset(new SettingsDialog(background_streams_));
settings_dialog_->SetLibraryDirectoryModel(library_->model()->directory_model());
settings_dialog_->SetGstEngine(qobject_cast<GstEngine*>(player_->engine()));
settings_dialog_->SetGlobalShortcutManager(global_shortcuts_);
settings_dialog_->SetGlobalSearch(global_search_);
settings_dialog_->SetSongInfoView(song_info_view_);
// Settings

View File

@ -30,6 +30,7 @@
#include "core/networkproxyfactory.h"
#include "engines/enginebase.h"
#include "engines/gstengine.h"
#include "globalsearch/globalsearchsettingspage.h"
#include "internet/digitallyimportedsettingspage.h"
#include "internet/groovesharksettingspage.h"
#include "internet/magnatunesettingspage.h"
@ -100,6 +101,7 @@ SettingsDialog::SettingsDialog(BackgroundStreams* streams, QWidget* parent)
gst_engine_(NULL),
song_info_view_(NULL),
streams_(streams),
global_search_(NULL),
ui_(new Ui_SettingsDialog),
loading_settings_(false)
{
@ -125,6 +127,7 @@ SettingsDialog::SettingsDialog(BackgroundStreams* streams, QWidget* parent)
// User interface
QTreeWidgetItem* interface = AddCategory(tr("User interface"));
AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), interface);
AddPage(Page_GlobalSearch, new GlobalSearchSettingsPage(this), interface);
AddPage(Page_SongInformation, new SongInfoSettingsPage(this), interface);
AddPage(Page_Notifications, new NotificationsSettingsPage(this), interface);

View File

@ -28,6 +28,7 @@ class QScrollArea;
class QTreeWidgetItem;
class BackgroundStreams;
class GlobalSearch;
class GlobalShortcuts;
class LibraryDirectoryModel;
class SettingsPage;
@ -59,6 +60,7 @@ public:
Page_Behaviour,
Page_SongInformation,
Page_GlobalShortcuts,
Page_GlobalSearch,
Page_Notifications,
Page_Library,
Page_Lastfm,
@ -81,6 +83,7 @@ public:
void SetGlobalShortcutManager(GlobalShortcuts* manager) { manager_ = manager; }
void SetGstEngine(const GstEngine* engine) { gst_engine_ = engine; }
void SetSongInfoView(SongInfoView* view) { song_info_view_ = view; }
void SetGlobalSearch(GlobalSearch* global_search) { global_search_ = global_search; }
bool is_loading_settings() const { return loading_settings_; }
@ -89,6 +92,7 @@ public:
const GstEngine* gst_engine() const { return gst_engine_; }
SongInfoView* song_info_view() const { return song_info_view_; }
BackgroundStreams* background_streams() const { return streams_; }
GlobalSearch* global_search() const { return global_search_; }
void OpenAtPage(Page page);
@ -121,6 +125,7 @@ private:
const GstEngine* gst_engine_;
SongInfoView* song_info_view_;
BackgroundStreams* streams_;
GlobalSearch* global_search_;
Ui_SettingsDialog* ui_;
bool loading_settings_;