Add a setting for disabling moodbar generation.

Fixes issue #3161
This commit is contained in:
John Maguire 2012-11-19 14:32:39 +01:00
parent 3df7f61b07
commit c4c7265e7a
5 changed files with 41 additions and 26 deletions

View File

@ -37,7 +37,8 @@ MoodbarLoader::MoodbarLoader(Application* app, QObject* parent)
cache_(new QNetworkDiskCache(this)),
thread_(new QThread(this)),
kMaxActiveRequests(qMax(1, QThread::idealThreadCount() / 2)),
save_alongside_originals_(false)
save_alongside_originals_(false),
disable_moodbar_calculation_(false)
{
cache_->setCacheDirectory(Utilities::GetConfigPath(Utilities::Path_MoodbarCache));
cache_->setMaximumCacheSize(60 * 1024 * 1024); // 60MB - enough for 20,000 moodbars
@ -55,6 +56,9 @@ void MoodbarLoader::ReloadSettings() {
QSettings s;
s.beginGroup("Moodbar");
save_alongside_originals_ = s.value("save_alongside_originals", false).toBool();
disable_moodbar_calculation_ = !s.value("calculate", true).toBool();
MaybeTakeNextRequest();
}
QStringList MoodbarLoader::MoodFilenames(const QString& song_filename) {
@ -75,7 +79,7 @@ MoodbarLoader::Result MoodbarLoader::Load(
if (url.scheme() != "file") {
return CannotLoad;
}
// Are we in the middle of loading this moodbar already?
if (requests_.contains(url)) {
*async_pipeline = requests_[url];
@ -111,8 +115,8 @@ MoodbarLoader::Result MoodbarLoader::Load(
MoodbarPipeline* pipeline = new MoodbarPipeline(url);
pipeline->moveToThread(thread_);
NewClosure(pipeline, SIGNAL(Finished(bool)),
this, SLOT(RequestFinished(MoodbarPipeline*,QUrl)),
pipeline, url);
this, SLOT(RequestFinished(MoodbarPipeline*,QUrl)),
pipeline, url);
requests_[url] = pipeline;
queued_requests_ << url;
@ -127,13 +131,14 @@ void MoodbarLoader::MaybeTakeNextRequest() {
Q_ASSERT(QThread::currentThread() == qApp->thread());
if (active_requests_.count() >= kMaxActiveRequests ||
queued_requests_.isEmpty()) {
queued_requests_.isEmpty() || disable_moodbar_calculation_) {
return;
}
const QUrl url = queued_requests_.takeFirst();
active_requests_ << url;
qLog(Info) << "Creating moodbar data for" << url.toLocalFile();
QMetaObject::invokeMethod(requests_[url], "Start", Qt::QueuedConnection);
}
@ -143,11 +148,11 @@ void MoodbarLoader::RequestFinished(MoodbarPipeline* request, const QUrl& url) {
if (request->success()) {
qLog(Info) << "Moodbar data generated successfully for" << url.toLocalFile();
// Save the data in the cache
QNetworkCacheMetaData metadata;
metadata.setUrl(url);
QIODevice* cache_file = cache_->prepare(metadata);
cache_file->write(request->data());
cache_->insert(cache_file);

View File

@ -30,24 +30,24 @@ class MoodbarPipeline;
class MoodbarLoader : public QObject {
Q_OBJECT
public:
MoodbarLoader(Application* app, QObject* parent = 0);
~MoodbarLoader();
enum Result {
// The URL isn't a local file or the moodbar plugin was not available -
// moodbar data can never be loaded.
CannotLoad,
// Moodbar data was loaded and returned.
Loaded,
// Moodbar data will be loaded in the background, a MoodbarPipeline* was
// was returned that you can connect to the Finished() signal on.
WillLoadAsync
};
Result Load(const QUrl& url, QByteArray* data, MoodbarPipeline** async_pipeline);
private slots:
@ -58,18 +58,19 @@ private slots:
private:
static QStringList MoodFilenames(const QString& song_filename);
private:
QNetworkDiskCache* cache_;
QThread* thread_;
const int kMaxActiveRequests;
QMap<QUrl, MoodbarPipeline*> requests_;
QList<QUrl> queued_requests_;
QSet<QUrl> active_requests_;
bool save_alongside_originals_;
bool disable_moodbar_calculation_;
};
#endif // MOODBARLOADER_H

View File

@ -88,7 +88,7 @@ void AppearanceSettingsPage::Load() {
// Keep in mind originals colors, in case the user clicks on Cancel, to be
// able to restore colors
original_use_a_custom_color_set_ = s.value(Appearance::kUseCustomColorSet, false).toBool();
original_foreground_color_ = s.value(Appearance::kForegroundColor,
p.color(QPalette::WindowText)).value<QColor>();
current_foreground_color_ = original_foreground_color_;
@ -127,13 +127,14 @@ void AppearanceSettingsPage::Load() {
DisableBlurSlider(true);
}
ui_->background_image_filename->setText(playlist_view_background_image_filename_);
s.endGroup();
// Moodbar settings
s.beginGroup("Moodbar");
ui_->moodbar_show->setChecked(s.value("show", true).toBool());
ui_->moodbar_style->setCurrentIndex(s.value("style", 0).toInt());
ui_->moodbar_calculate->setChecked(!s.value("calculate", true).toBool());
ui_->moodbar_save->setChecked(s.value("save_alongside_originals", false).toBool());
s.endGroup();
@ -168,12 +169,13 @@ void AppearanceSettingsPage::Save() {
playlist_view_background_image_filename_);
}
s.setValue(PlaylistView::kSettingBackgroundImageType,
playlist_view_background_image_type_);
playlist_view_background_image_type_);
s.setValue("blur_radius", ui_->blur_slider->value());
s.endGroup();
// Moodbar settings
s.beginGroup("Moodbar");
s.setValue("calculate", !ui_->moodbar_calculate->isChecked());
s.setValue("show", ui_->moodbar_show->isChecked());
s.setValue("style", ui_->moodbar_style->currentIndex());
s.setValue("save_alongside_originals", ui_->moodbar_save->isChecked());
@ -193,7 +195,7 @@ void AppearanceSettingsPage::SelectForegroundColor() {
QColor color_selected = QColorDialog::getColor(current_foreground_color_);
if (!color_selected.isValid())
return;
current_foreground_color_ = color_selected;
dialog()->appearance()->ChangeForegroundColor(color_selected);
@ -204,7 +206,7 @@ void AppearanceSettingsPage::SelectBackgroundColor() {
QColor color_selected = QColorDialog::getColor(current_background_color_);
if (!color_selected.isValid())
return;
current_background_color_ = color_selected;
dialog()->appearance()->ChangeBackgroundColor(color_selected);
@ -248,7 +250,6 @@ void AppearanceSettingsPage::SelectBackgroundImage() {
void AppearanceSettingsPage::BlurLevelChanged(int value) {
background_blur_radius_ = value;
ui_->background_blur_radius_label->setText(QString("%1px").arg(value));
}
void AppearanceSettingsPage::InitMoodbarPreviews() {

View File

@ -28,7 +28,7 @@ class Ui_AppearanceSettingsPage;
class AppearanceSettingsPage : public SettingsPage {
Q_OBJECT
public:
AppearanceSettingsPage(SettingsDialog* dialog);
~AppearanceSettingsPage();
@ -65,8 +65,9 @@ private:
PlaylistView::BackgroundImageType playlist_view_background_image_type_;
QString playlist_view_background_image_filename_;
int background_blur_radius_;
bool initialised_moodbar_previews_;
bool dont_calculate_moodbar_;
};
#endif // APPEARANCESETTINGSPAGE_H

View File

@ -210,30 +210,37 @@
<string>Moodbars</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="moodbar_show">
<property name="text">
<string>Show a moodbar in the track progress bar</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Moodbar style</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="moodbar_style"/>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="moodbar_save">
<property name="text">
<string>Save .mood files in your music library</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="moodbar_calculate">
<property name="text">
<string>Disable moodbar generation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>