Change the Jamendo logic a bit:

Instead of prompting the user to download the catalogue when the library
backend is initialised (which is now always), only do it when the service
node in the InternetView is expanded, or the global search provider is enabled.

Fixes issue 3009
This commit is contained in:
David Sansome 2012-06-19 21:07:58 +01:00
parent f95afa4cb3
commit 45104adca9
5 changed files with 33 additions and 10 deletions

View File

@ -311,6 +311,7 @@ bool GlobalSearch::SetProviderEnabled(const SearchProvider* const_provider,
return false;
} else {
providers_[provider].enabled_ = enabled;
emit ProviderToggled(provider, enabled);
SaveProvidersSettings();
return true;
}
@ -338,8 +339,12 @@ void GlobalSearch::ReloadSettings() {
QVariant value = s.value("enabled_" + provider->id());
if (!value.isValid())
continue;
const bool enabled = value.toBool();
providers_[provider].enabled_ = value.toBool();
if (enabled != providers_[provider].enabled_) {
providers_[provider].enabled_ = enabled;
emit ProviderToggled(provider, enabled);
}
}
}

View File

@ -72,6 +72,7 @@ signals:
void ProviderAdded(const SearchProvider* provider);
void ProviderRemoved(const SearchProvider* provider);
void ProviderToggled(const SearchProvider* provider, bool enabled);
protected:
void timerEvent(QTimerEvent* e);

View File

@ -78,6 +78,7 @@ JamendoService::JamendoService(Application* app, InternetModel* parent)
library_filter_(NULL),
library_model_(NULL),
library_sort_model_(new QSortFilterProxyModel(this)),
search_provider_(NULL),
load_database_task_id_(0),
total_song_count_(0),
accepted_download_(false) {
@ -120,12 +121,16 @@ JamendoService::JamendoService(Application* app, InternetModel* parent)
library_sort_model_->setDynamicSortFilter(true);
library_sort_model_->sort(0);
app_->global_search()->AddProvider(new LibrarySearchProvider(
search_provider_ = new LibrarySearchProvider(
library_backend_,
tr("Jamendo"),
"jamendo",
QIcon(":/providers/jamendo.png"),
false, app_, this));
false, app_, this);
app_->global_search()->AddProvider(search_provider_);
connect(app_->global_search(),
SIGNAL(ProviderToggled(const SearchProvider*,bool)),
SLOT(SearchProviderToggled(const SearchProvider*,bool)));
}
JamendoService::~JamendoService() {
@ -140,7 +145,9 @@ QStandardItem* JamendoService::CreateRootItem() {
void JamendoService::LazyPopulate(QStandardItem* item) {
switch (item->data(InternetModel::Role_Type).toInt()) {
case InternetModel::Type_Service: {
library_model_->Init();
if (total_song_count_ == 0 && !load_database_task_id_) {
DownloadDirectory();
}
model()->merged_model()->AddSubModel(item->index(), library_sort_model_);
break;
}
@ -151,11 +158,7 @@ void JamendoService::LazyPopulate(QStandardItem* item) {
void JamendoService::UpdateTotalSongCount(int count) {
total_song_count_ = count;
if (total_song_count_ == 0 && !load_database_task_id_) {
DownloadDirectory();
}
else {
//show smart playlist in song count if the db is loaded
if (total_song_count_ > 0) {
library_model_->set_show_smart_playlists(true);
accepted_download_ = true; //the user has previously accepted
}
@ -484,3 +487,12 @@ void JamendoService::DownloadAlbum() {
void JamendoService::Homepage() {
QDesktopServices::openUrl(QUrl(kHomepage));
}
void JamendoService::SearchProviderToggled(const SearchProvider* provider,
bool enabled) {
// If the use enabled our provider and he hasn't downloaded the directory yet,
// prompt him to do so now.
if (provider == search_provider_ && enabled && total_song_count_ == 0) {
DownloadDirectory();
}
}

View File

@ -27,7 +27,10 @@
class LibraryBackend;
class LibraryFilterWidget;
class LibraryModel;
class LibrarySearchProvider;
class NetworkAccessManager;
class SearchProvider;
class QIODevice;
class QMenu;
class QSortFilterProxyModel;
@ -95,6 +98,8 @@ class JamendoService : public InternetService {
void DownloadAlbum();
void Homepage();
void SearchProviderToggled(const SearchProvider* provider, bool enabled);
private:
NetworkAccessManager* network_;
@ -107,6 +112,7 @@ class JamendoService : public InternetService {
LibraryFilterWidget* library_filter_;
LibraryModel* library_model_;
QSortFilterProxyModel* library_sort_model_;
LibrarySearchProvider* search_provider_;
int load_database_task_id_;

View File

@ -44,7 +44,6 @@
#include "globalsearch/globalsearch.h"
#include "globalsearch/globalsearchview.h"
#include "globalsearch/librarysearchprovider.h"
#include "internet/jamendoservice.h"
#include "internet/magnatuneservice.h"
#include "internet/internetmodel.h"
#include "internet/internetview.h"