~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/library/libraryconfig.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
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.
8
 
 
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.
13
 
 
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/>.
16
 
*/
17
 
 
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"
27
 
 
28
 
#include <QFileDialog>
29
 
#include <QSettings>
30
 
#include <QDir>
31
 
 
32
 
const char* LibraryConfig::kSettingsGroup = "LibraryConfig";
33
 
 
34
 
 
35
 
LibraryConfig::LibraryConfig(QWidget* parent)
36
 
  : QWidget(parent),
37
 
    ui_(new Ui_LibraryConfig),
38
 
    model_(NULL)
39
 
{
40
 
  ui_->setupUi(this);
41
 
  ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this));
42
 
 
43
 
  // Icons
44
 
  ui_->add->setIcon(IconLoader::Load("document-open-folder"));
45
 
 
46
 
  connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
47
 
  connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
48
 
}
49
 
 
50
 
LibraryConfig::~LibraryConfig() {
51
 
  delete ui_;
52
 
}
53
 
 
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)));
59
 
  }
60
 
 
61
 
  model_ = model;
62
 
  ui_->list->setModel(model_);
63
 
 
64
 
  connect(ui_->list->selectionModel(),
65
 
          SIGNAL(currentRowChanged(QModelIndex, QModelIndex)),
66
 
          SLOT(CurrentRowChanged(QModelIndex)));
67
 
}
68
 
 
69
 
void LibraryConfig::Add() {
70
 
  QSettings settings;
71
 
  settings.beginGroup(kSettingsGroup);
72
 
 
73
 
  QString path(settings.value("last_path",
74
 
      Utilities::GetConfigPath(Utilities::Path_DefaultMusicLibrary)).toString());
75
 
  path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
76
 
 
77
 
  if (!path.isNull()) {
78
 
    model_->AddDirectory(path);
79
 
  }
80
 
 
81
 
  settings.setValue("last_path", path);
82
 
}
83
 
 
84
 
void LibraryConfig::Remove() {
85
 
  model_->RemoveDirectory(ui_->list->currentIndex());
86
 
}
87
 
 
88
 
void LibraryConfig::CurrentRowChanged(const QModelIndex& index) {
89
 
  ui_->remove->setEnabled(index.isValid());
90
 
}
91
 
 
92
 
void LibraryConfig::Save() {
93
 
  QSettings s;
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());
98
 
  s.endGroup();
99
 
 
100
 
  s.beginGroup(LibraryWatcher::kSettingsGroup);
101
 
  s.setValue("startup_scan", ui_->startup_scan->isChecked());
102
 
  s.setValue("monitor", ui_->monitor->isChecked());
103
 
  
104
 
  QString filter_text = ui_->cover_art_patterns->text();
105
 
  QStringList filters = filter_text.split(',', QString::SkipEmptyParts);
106
 
  s.setValue("cover_art_patterns", filters);
107
 
  
108
 
  s.endGroup();
109
 
}
110
 
 
111
 
void LibraryConfig::showEvent(QShowEvent *) {
112
 
  Load();
113
 
}
114
 
 
115
 
void LibraryConfig::Load() {
116
 
  QSettings s;
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());
121
 
  s.endGroup();
122
 
 
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());
126
 
  
127
 
  QStringList filters = s.value("cover_art_patterns",
128
 
      QStringList() << "front" << "cover").toStringList();
129
 
  ui_->cover_art_patterns->setText(filters.join(","));
130
 
  
131
 
  s.endGroup();
132
 
}