From 2134e13b530b034932cde05803e4b14130d7b6eb Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 30 Mar 2014 17:08:30 +1100 Subject: [PATCH] Make CloudFileServices show logged in state and settings dialog properly in global search. --- src/CMakeLists.txt | 1 + src/globalsearch/globalsearchview.cpp | 6 +++ src/globalsearch/searchprovider.cpp | 8 ++++ src/globalsearch/searchprovider.h | 1 + src/internet/cloudfilesearchprovider.cpp | 48 ++++++++++++++++++++++++ src/internet/cloudfilesearchprovider.h | 40 ++++++++++++++++++++ src/internet/cloudfileservice.cpp | 6 +-- src/internet/cloudfileservice.h | 6 ++- 8 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 src/internet/cloudfilesearchprovider.cpp create mode 100644 src/internet/cloudfilesearchprovider.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4d3ad22a..53939f3a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,6 +164,7 @@ set(SOURCES globalsearch/suggestionwidget.cpp globalsearch/urlsearchprovider.cpp + internet/cloudfilesearchprovider.cpp internet/cloudfileservice.cpp internet/digitallyimportedclient.cpp internet/digitallyimportedservicebase.cpp diff --git a/src/globalsearch/globalsearchview.cpp b/src/globalsearch/globalsearchview.cpp index 9d6231c1f..6cc99ca04 100644 --- a/src/globalsearch/globalsearchview.cpp +++ b/src/globalsearch/globalsearchview.cpp @@ -184,6 +184,8 @@ bool CompareProvider(const QStringList& provider_order, SearchProvider* left, } void GlobalSearchView::ReloadSettings() { + const bool old_show_suggestions = show_suggestions_; + QSettings s; // Library settings @@ -246,6 +248,10 @@ void GlobalSearchView::ReloadSettings() { if (!show_suggestions_) { update_suggestions_timer_->stop(); } + + if (!old_show_suggestions && show_suggestions_) { + UpdateSuggestions(); + } } void GlobalSearchView::UpdateSuggestions() { diff --git a/src/globalsearch/searchprovider.cpp b/src/globalsearch/searchprovider.cpp index 17d2e4c03..fe67c552d 100644 --- a/src/globalsearch/searchprovider.cpp +++ b/src/globalsearch/searchprovider.cpp @@ -37,6 +37,14 @@ void SearchProvider::Init(const QString& name, const QString& id, hints_ = hints; } +void SearchProvider::SetHint(Hint hint, bool set) { + if (set) { + hints_ |= hint; + } else { + hints_ &= ~hint; + } +} + QStringList SearchProvider::TokenizeQuery(const QString& query) { QStringList tokens(query.split(QRegExp("\\s+"))); diff --git a/src/globalsearch/searchprovider.h b/src/globalsearch/searchprovider.h index 81d65d9e4..5e6fc99bc 100644 --- a/src/globalsearch/searchprovider.h +++ b/src/globalsearch/searchprovider.h @@ -164,6 +164,7 @@ signals: // Subclasses must call this from their constructors. void Init(const QString& name, const QString& id, const QIcon& icon, Hints hints = NoHints); + void SetHint(Hint hint, bool set = true); struct PendingState { PendingState() : orig_id_(-1) {} diff --git a/src/internet/cloudfilesearchprovider.cpp b/src/internet/cloudfilesearchprovider.cpp new file mode 100644 index 000000000..f3185b8f1 --- /dev/null +++ b/src/internet/cloudfilesearchprovider.cpp @@ -0,0 +1,48 @@ +/* This file is part of Clementine. + Copyright 2014, David Sansome + + 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 . +*/ + +#include "internet/cloudfilesearchprovider.h" +#include "internet/cloudfileservice.h" +#include "internet/internetmodel.h" + +CloudFileSearchProvider::CloudFileSearchProvider( + LibraryBackendInterface* backend, + const QString& id, + const QIcon& icon, + CloudFileService* service) + : LibrarySearchProvider(backend, + service->name(), + id, + icon, + true, + service->model()->app(), + service), + service_(service) { + SetHint(CanShowConfig); +} + +bool CloudFileSearchProvider::IsLoggedIn() { + return service_->has_credentials(); +} + +void CloudFileSearchProvider::ShowConfig() { + service_->ShowSettingsDialog(); +} + +InternetService* CloudFileSearchProvider::internet_service() { + return service_; +} diff --git a/src/internet/cloudfilesearchprovider.h b/src/internet/cloudfilesearchprovider.h new file mode 100644 index 000000000..3e41298d0 --- /dev/null +++ b/src/internet/cloudfilesearchprovider.h @@ -0,0 +1,40 @@ +/* This file is part of Clementine. + Copyright 2014, David Sansome + + 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 . +*/ + +#ifndef CLOUDFILESEARCHPROVIDER_H +#define CLOUDFILESEARCHPROVIDER_H + +#include "globalsearch/librarysearchprovider.h" + +class CloudFileService; + +class CloudFileSearchProvider : public LibrarySearchProvider { + public: + CloudFileSearchProvider(LibraryBackendInterface* backend, + const QString& id, + const QIcon& icon, + CloudFileService* service); + + virtual bool IsLoggedIn(); + virtual void ShowConfig(); + virtual InternetService* internet_service(); + + private: + CloudFileService* service_; +}; + +#endif // CLOUDFILESEARCHPROVIDER_H diff --git a/src/internet/cloudfileservice.cpp b/src/internet/cloudfileservice.cpp index 7001726a5..96699520c 100644 --- a/src/internet/cloudfileservice.cpp +++ b/src/internet/cloudfileservice.cpp @@ -10,7 +10,7 @@ #include "core/player.h" #include "core/taskmanager.h" #include "globalsearch/globalsearch.h" -#include "globalsearch/librarysearchprovider.h" +#include "internet/cloudfilesearchprovider.h" #include "internet/internetmodel.h" #include "library/librarybackend.h" #include "library/librarymodel.h" @@ -48,8 +48,8 @@ CloudFileService::CloudFileService(Application* app, InternetModel* parent, library_sort_model_->setSortLocaleAware(true); library_sort_model_->sort(0); - app->global_search()->AddProvider(new LibrarySearchProvider( - library_backend_, service_name, service_id, icon_, true, app_, this)); + app->global_search()->AddProvider(new CloudFileSearchProvider( + library_backend_, service_id, icon_, this)); } QStandardItem* CloudFileService::CreateRootItem() { diff --git a/src/internet/cloudfileservice.h b/src/internet/cloudfileservice.h index a0f970c48..44e7cc5dc 100644 --- a/src/internet/cloudfileservice.h +++ b/src/internet/cloudfileservice.h @@ -29,13 +29,16 @@ class CloudFileService : public InternetService { virtual void LazyPopulate(QStandardItem* item); virtual void ShowContextMenu(const QPoint& point); + virtual bool has_credentials() const = 0; bool is_indexing() const { return indexing_task_id_ != -1; } signals: void AllIndexingTasksFinished(); + public slots: + void ShowSettingsDialog(); + protected: - virtual bool has_credentials() const = 0; virtual void Connect() = 0; virtual bool ShouldIndexFile(const QUrl& url, const QString& mime_type) const; virtual void MaybeAddFileToDatabase(const Song& metadata, @@ -48,7 +51,6 @@ class CloudFileService : public InternetService { protected slots: void ShowCoverManager(); void AddToPlaylist(QMimeData* mime); - void ShowSettingsDialog(); void ReadTagsFinished(TagReaderClient::ReplyType* reply, const Song& metadata);