2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "libraryconfig.h"
|
2010-02-03 17:17:04 +01:00
|
|
|
#include "librarydirectorymodel.h"
|
2011-01-02 15:51:01 +01:00
|
|
|
#include "librarymodel.h"
|
2010-04-01 02:12:25 +02:00
|
|
|
#include "libraryview.h"
|
2010-05-25 22:40:45 +02:00
|
|
|
#include "librarywatcher.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_libraryconfig.h"
|
2010-08-28 21:07:23 +02:00
|
|
|
#include "playlist/playlistdelegates.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-12-14 16:00:46 +01:00
|
|
|
#include "core/utilities.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
const char* LibraryConfig::kSettingsGroup = "LibraryConfig";
|
|
|
|
|
2010-08-28 21:07:23 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
LibraryConfig::LibraryConfig(QWidget* parent)
|
2010-02-03 17:17:04 +01:00
|
|
|
: QWidget(parent),
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_(new Ui_LibraryConfig),
|
2010-02-03 17:17:04 +01:00
|
|
|
model_(NULL)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-08-28 21:07:23 +02:00
|
|
|
ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
|
|
|
ui_->add->setIcon(IconLoader::Load("document-open-folder"));
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
|
|
|
|
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
|
|
|
|
}
|
|
|
|
|
|
|
|
LibraryConfig::~LibraryConfig() {
|
|
|
|
delete ui_;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 17:17:04 +01:00
|
|
|
void LibraryConfig::SetModel(LibraryDirectoryModel *model) {
|
2010-05-10 23:50:31 +02:00
|
|
|
if (ui_->list->selectionModel()) {
|
|
|
|
disconnect(ui_->list->selectionModel(),
|
2010-05-09 22:18:05 +02:00
|
|
|
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
|
|
|
|
this, SLOT(CurrentRowChanged(QModelIndex)));
|
|
|
|
}
|
|
|
|
|
2010-02-03 17:17:04 +01:00
|
|
|
model_ = model;
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->list->setModel(model_);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->list->selectionModel(),
|
2010-02-03 17:17:04 +01:00
|
|
|
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
|
|
|
|
SLOT(CurrentRowChanged(QModelIndex)));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryConfig::Add() {
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup(kSettingsGroup);
|
|
|
|
|
2010-12-14 16:00:46 +01:00
|
|
|
QString path(settings.value("last_path",
|
|
|
|
Utilities::GetConfigPath(Utilities::Path_DefaultMusicLibrary)).toString());
|
2010-02-23 19:33:09 +01:00
|
|
|
path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (!path.isNull()) {
|
2010-02-03 17:17:04 +01:00
|
|
|
model_->AddDirectory(path);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
settings.setValue("last_path", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryConfig::Remove() {
|
2010-05-10 23:50:31 +02:00
|
|
|
model_->RemoveDirectory(ui_->list->currentIndex());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 17:17:04 +01:00
|
|
|
void LibraryConfig::CurrentRowChanged(const QModelIndex& index) {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->remove->setEnabled(index.isValid());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-04-01 02:12:25 +02:00
|
|
|
void LibraryConfig::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(LibraryView::kSettingsGroup);
|
2010-05-10 23:50:31 +02:00
|
|
|
s.setValue("auto_open", ui_->auto_open->isChecked());
|
2010-05-15 19:45:04 +02:00
|
|
|
s.setValue("autoclear_playlist", ui_->auto_load->isChecked());
|
2011-01-02 15:51:01 +01:00
|
|
|
s.setValue("pretty_covers", ui_->pretty_covers->isChecked());
|
2010-05-25 22:40:45 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup(LibraryWatcher::kSettingsGroup);
|
|
|
|
s.setValue("startup_scan", ui_->startup_scan->isChecked());
|
2010-07-10 19:03:28 +02:00
|
|
|
s.setValue("monitor", ui_->monitor->isChecked());
|
2010-12-28 13:52:58 +01:00
|
|
|
|
|
|
|
QString filter_text = ui_->cover_art_patterns->text();
|
|
|
|
QStringList filters = filter_text.split(',', QString::SkipEmptyParts);
|
|
|
|
s.setValue("cover_art_patterns", filters);
|
|
|
|
|
2010-05-25 22:40:45 +02:00
|
|
|
s.endGroup();
|
2010-04-01 02:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryConfig::showEvent(QShowEvent *) {
|
2010-04-21 13:24:22 +02:00
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibraryConfig::Load() {
|
2010-04-01 02:12:25 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(LibraryView::kSettingsGroup);
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->auto_open->setChecked(s.value("auto_open", true).toBool());
|
2010-05-15 19:45:04 +02:00
|
|
|
ui_->auto_load->setChecked(s.value("autoclear_playlist", false).toBool());
|
2011-01-02 15:51:01 +01:00
|
|
|
ui_->pretty_covers->setChecked(s.value("pretty_covers", true).toBool());
|
2010-05-25 22:40:45 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup(LibraryWatcher::kSettingsGroup);
|
|
|
|
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
|
2010-07-10 19:03:28 +02:00
|
|
|
ui_->monitor->setChecked(s.value("monitor", true).toBool());
|
2010-12-28 13:52:58 +01:00
|
|
|
|
|
|
|
QStringList filters = s.value("cover_art_patterns",
|
|
|
|
QStringList() << "front" << "cover").toStringList();
|
|
|
|
ui_->cover_art_patterns->setText(filters.join(","));
|
|
|
|
|
2010-05-25 22:40:45 +02:00
|
|
|
s.endGroup();
|
2010-04-01 02:12:25 +02:00
|
|
|
}
|