1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "libraryconfig.h"
19
#include "librarydirectorymodel.h"
20
#include "librarymodel.h"
21
#include "libraryview.h"
22
#include "librarywatcher.h"
23
#include "ui_libraryconfig.h"
24
#include "playlist/playlistdelegates.h"
25
#include "ui/iconloader.h"
26
#include "core/utilities.h"
28
#include <QFileDialog>
32
const char* LibraryConfig::kSettingsGroup = "LibraryConfig";
35
LibraryConfig::LibraryConfig(QWidget* parent)
37
ui_(new Ui_LibraryConfig),
41
ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this));
44
ui_->add->setIcon(IconLoader::Load("document-open-folder"));
46
connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
47
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
50
LibraryConfig::~LibraryConfig() {
54
void LibraryConfig::SetModel(LibraryDirectoryModel *model) {
55
if (ui_->list->selectionModel()) {
56
disconnect(ui_->list->selectionModel(),
57
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
58
this, SLOT(CurrentRowChanged(QModelIndex)));
62
ui_->list->setModel(model_);
64
connect(ui_->list->selectionModel(),
65
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
66
SLOT(CurrentRowChanged(QModelIndex)));
69
void LibraryConfig::Add() {
71
settings.beginGroup(kSettingsGroup);
73
QString path(settings.value("last_path",
74
Utilities::GetConfigPath(Utilities::Path_DefaultMusicLibrary)).toString());
75
path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
78
model_->AddDirectory(path);
81
settings.setValue("last_path", path);
84
void LibraryConfig::Remove() {
85
model_->RemoveDirectory(ui_->list->currentIndex());
88
void LibraryConfig::CurrentRowChanged(const QModelIndex& index) {
89
ui_->remove->setEnabled(index.isValid());
92
void LibraryConfig::Save() {
94
s.beginGroup(LibraryView::kSettingsGroup);
95
s.setValue("auto_open", ui_->auto_open->isChecked());
96
s.setValue("pretty_covers", ui_->pretty_covers->isChecked());
97
s.setValue("show_dividers", ui_->show_dividers->isChecked());
100
s.beginGroup(LibraryWatcher::kSettingsGroup);
101
s.setValue("startup_scan", ui_->startup_scan->isChecked());
102
s.setValue("monitor", ui_->monitor->isChecked());
104
QString filter_text = ui_->cover_art_patterns->text();
105
QStringList filters = filter_text.split(',', QString::SkipEmptyParts);
106
s.setValue("cover_art_patterns", filters);
111
void LibraryConfig::showEvent(QShowEvent *) {
115
void LibraryConfig::Load() {
117
s.beginGroup(LibraryView::kSettingsGroup);
118
ui_->auto_open->setChecked(s.value("auto_open", true).toBool());
119
ui_->pretty_covers->setChecked(s.value("pretty_covers", true).toBool());
120
ui_->show_dividers->setChecked(s.value("show_dividers", true).toBool());
123
s.beginGroup(LibraryWatcher::kSettingsGroup);
124
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
125
ui_->monitor->setChecked(s.value("monitor", true).toBool());
127
QStringList filters = s.value("cover_art_patterns",
128
QStringList() << "front" << "cover").toStringList();
129
ui_->cover_art_patterns->setText(filters.join(","));