Clementine-audio-player-Mac.../src/library/libraryconfig.cpp

117 lines
3.3 KiB
C++
Raw Normal View History

/* This file is part of Clementine.
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"
#include "libraryview.h"
#include "librarywatcher.h"
#include "ui_libraryconfig.h"
#include "playlist/playlistdelegates.h"
#include "ui/iconloader.h"
2009-12-24 20:16:07 +01:00
#include <QFileDialog>
#include <QSettings>
#include <QDir>
const char* LibraryConfig::kSettingsGroup = "LibraryConfig";
2009-12-24 20:16:07 +01:00
LibraryConfig::LibraryConfig(QWidget* parent)
2010-02-03 17:17:04 +01:00
: QWidget(parent),
ui_(new Ui_LibraryConfig),
2010-02-03 17:17:04 +01:00
model_(NULL)
2009-12-24 20:16:07 +01:00
{
ui_->setupUi(this);
ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this));
2009-12-24 20:16:07 +01:00
// Icons
ui_->add->setIcon(IconLoader::Load("document-open-folder"));
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) {
if (ui_->list->selectionModel()) {
disconnect(ui_->list->selectionModel(),
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
this, SLOT(CurrentRowChanged(QModelIndex)));
}
2010-02-03 17:17:04 +01:00
model_ = model;
ui_->list->setModel(model_);
2009-12-24 20:16:07 +01: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);
QString path(settings.value("last_path", QDir::homePath()).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() {
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) {
ui_->remove->setEnabled(index.isValid());
2009-12-24 20:16:07 +01:00
}
void LibraryConfig::Save() {
QSettings s;
s.beginGroup(LibraryView::kSettingsGroup);
s.setValue("auto_open", ui_->auto_open->isChecked());
s.setValue("autoclear_playlist", ui_->auto_load->isChecked());
s.endGroup();
s.beginGroup(LibraryWatcher::kSettingsGroup);
s.setValue("startup_scan", ui_->startup_scan->isChecked());
s.setValue("monitor", ui_->monitor->isChecked());
s.endGroup();
}
void LibraryConfig::showEvent(QShowEvent *) {
Load();
}
void LibraryConfig::Load() {
QSettings s;
s.beginGroup(LibraryView::kSettingsGroup);
ui_->auto_open->setChecked(s.value("auto_open", true).toBool());
ui_->auto_load->setChecked(s.value("autoclear_playlist", false).toBool());
s.endGroup();
s.beginGroup(LibraryWatcher::kSettingsGroup);
ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool());
ui_->monitor->setChecked(s.value("monitor", true).toBool());
s.endGroup();
}