OLD | NEW |
1 /* This file is part of Clementine. | 1 /* This file is part of Clementine. |
2 Copyright 2010, David Sansome <me@davidsansome.com> | 2 Copyright 2010, David Sansome <me@davidsansome.com> |
3 | 3 |
4 Clementine is free software: you can redistribute it and/or modify | 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 | 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 | 6 the Free Software Foundation, either version 3 of the License, or |
7 (at your option) any later version. | 7 (at your option) any later version. |
8 | 8 |
9 Clementine is distributed in the hope that it will be useful, | 9 Clementine is distributed in the hope that it will be useful, |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui_librarysettingspage.h" | 23 #include "ui_librarysettingspage.h" |
24 #include "core/utilities.h" | 24 #include "core/utilities.h" |
25 #include "playlist/playlistdelegates.h" | 25 #include "playlist/playlistdelegates.h" |
26 #include "ui/iconloader.h" | 26 #include "ui/iconloader.h" |
27 #include "ui/settingsdialog.h" | 27 #include "ui/settingsdialog.h" |
28 | 28 |
29 #include <QFileDialog> | 29 #include <QFileDialog> |
30 #include <QSettings> | 30 #include <QSettings> |
31 #include <QDir> | 31 #include <QDir> |
32 | 32 |
| 33 |
33 const char* LibrarySettingsPage::kSettingsGroup = "LibraryConfig"; | 34 const char* LibrarySettingsPage::kSettingsGroup = "LibraryConfig"; |
34 | 35 |
35 | 36 |
36 LibrarySettingsPage::LibrarySettingsPage(SettingsDialog* dialog) | 37 LibrarySettingsPage::LibrarySettingsPage(SettingsDialog* dialog) |
37 : SettingsPage(dialog), | 38 : SettingsPage(dialog), |
38 ui_(new Ui_LibrarySettingsPage), | 39 ui_(new Ui_LibrarySettingsPage), |
39 initialised_model_(false) | 40 initialised_model_(false) |
40 { | 41 { |
41 ui_->setupUi(this); | 42 ui_->setupUi(this); |
42 ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this)); | 43 ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this)); |
(...skipping 12 matching lines...) Expand all Loading... |
55 | 56 |
56 void LibrarySettingsPage::Add() { | 57 void LibrarySettingsPage::Add() { |
57 QSettings settings; | 58 QSettings settings; |
58 settings.beginGroup(kSettingsGroup); | 59 settings.beginGroup(kSettingsGroup); |
59 | 60 |
60 QString path(settings.value("last_path", | 61 QString path(settings.value("last_path", |
61 Utilities::GetConfigPath(Utilities::Path_DefaultMusicLibrary)).toString())
; | 62 Utilities::GetConfigPath(Utilities::Path_DefaultMusicLibrary)).toString())
; |
62 path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path); | 63 path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path); |
63 | 64 |
64 if (!path.isNull()) { | 65 if (!path.isNull()) { |
65 dialog()->library_directory_model()->AddDirectory(path); | 66 //retrieving current folder filenames and.. |
| 67 QList<QString> new_folder_filenames; |
| 68 QModelIndex index; |
| 69 int number_rows=dialog()->library_directory_model()->rowCount(); |
| 70 for(int i=0; i<number_rows; i++) { |
| 71 index=dialog()->library_directory_model()->index(i,0,QModelIndex()); |
| 72 new_folder_filenames.append(dialog()->library_directory_model()->data(inde
x,Qt::DisplayRole).toString()); |
| 73 } |
| 74 //checking first if the folder already exits |
| 75 » if(!new_folder_filenames.contains(path)) dialog()->library_directory_mod
el()->AddDirectory(path); |
| 76 » else { |
| 77 index=dialog()->library_directory_model()->index(new_folder_filenames.inde
xOf(path),0,QModelIndex()); |
| 78 ui_->list->setCurrentIndex(index); |
| 79 } |
66 } | 80 } |
67 | 81 |
68 settings.setValue("last_path", path); | 82 settings.setValue("last_path", path); |
69 } | 83 } |
70 | 84 |
71 void LibrarySettingsPage::Remove() { | 85 void LibrarySettingsPage::Remove() { |
72 dialog()->library_directory_model()->RemoveDirectory(ui_->list->currentIndex()
); | 86 dialog()->library_directory_model()->RemoveDirectory(ui_->list->currentIndex()
); |
73 } | 87 } |
74 | 88 |
75 void LibrarySettingsPage::CurrentRowChanged(const QModelIndex& index) { | 89 void LibrarySettingsPage::CurrentRowChanged(const QModelIndex& index) { |
(...skipping 12 matching lines...) Expand all Loading... |
88 s.setValue("startup_scan", ui_->startup_scan->isChecked()); | 102 s.setValue("startup_scan", ui_->startup_scan->isChecked()); |
89 s.setValue("monitor", ui_->monitor->isChecked()); | 103 s.setValue("monitor", ui_->monitor->isChecked()); |
90 ·· | 104 ·· |
91 QString filter_text = ui_->cover_art_patterns->text(); | 105 QString filter_text = ui_->cover_art_patterns->text(); |
92 QStringList filters = filter_text.split(',', QString::SkipEmptyParts); | 106 QStringList filters = filter_text.split(',', QString::SkipEmptyParts); |
93 s.setValue("cover_art_patterns", filters); | 107 s.setValue("cover_art_patterns", filters); |
94 ·· | 108 ·· |
95 s.endGroup(); | 109 s.endGroup(); |
96 } | 110 } |
97 | 111 |
| 112 //restoring efficiently all pre-existed paths |
| 113 void LibrarySettingsPage::Cancel() { |
| 114 QList<QString> new_folder_filenames; |
| 115 int i; |
| 116 QModelIndex index; |
| 117 int number_rows=dialog()->library_directory_model()->rowCount(); |
| 118 //retrieve the paths |
| 119 for(i=0; i<number_rows; ++i) { |
| 120 index=dialog()->library_directory_model()->index(i,0,QModelIndex()); |
| 121 new_folder_filenames.append(dialog()->library_directory_model()->data(index,
Qt::DisplayRole).toString()); |
| 122 } |
| 123 i=0; |
| 124 //remove any newly added paths |
| 125 while(i<number_rows) { |
| 126 index=dialog()->library_directory_model()->index(i,0,QModelIndex()); |
| 127 if(!folder_filenames_.contains(dialog()->library_directory_model()->data(ind
ex,Qt::DisplayRole).toString())) { |
| 128 dialog()->library_directory_model()->RemoveDirectory(dialog()->library_dir
ectory_model()->index(i,0,QModelIndex())); |
| 129 new_folder_filenames.removeAll(dialog()->library_directory_model()->data(i
ndex,Qt::DisplayRole).toString()); |
| 130 //since we removed one path the number of rows decremented by 1.. |
| 131 //..and i now points to the next path so no need to increase it |
| 132 number_rows--; |
| 133 } |
| 134 else ++i; |
| 135 } |
| 136 //add any previously deleted paths |
| 137 for(int i=0; i<folder_filenames_.length(); ++i) { |
| 138 if(!new_folder_filenames.contains(folder_filenames_[i])) { |
| 139 dialog()->library_directory_model()->AddDirectory(folder_filenames_[i]); |
| 140 } |
| 141 } |
| 142 //erase the contents of global variable |
| 143 folder_filenames_.erase(folder_filenames_.begin(),folder_filenames_.end()); |
| 144 } |
| 145 |
98 void LibrarySettingsPage::Load() { | 146 void LibrarySettingsPage::Load() { |
99 if (!initialised_model_) { | 147 if (!initialised_model_) { |
100 if (ui_->list->selectionModel()) { | 148 if (ui_->list->selectionModel()) { |
101 disconnect(ui_->list->selectionModel(), | 149 disconnect(ui_->list->selectionModel(), |
102 SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), | 150 SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), |
103 this, SLOT(CurrentRowChanged(QModelIndex))); | 151 this, SLOT(CurrentRowChanged(QModelIndex))); |
104 } | 152 } |
105 | 153 |
106 ui_->list->setModel(dialog()->library_directory_model()); | 154 ui_->list->setModel(dialog()->library_directory_model()); |
107 initialised_model_ = true; | 155 initialised_model_ = true; |
(...skipping 12 matching lines...) Expand all Loading... |
120 | 168 |
121 s.beginGroup(LibraryWatcher::kSettingsGroup); | 169 s.beginGroup(LibraryWatcher::kSettingsGroup); |
122 ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool()); | 170 ui_->startup_scan->setChecked(s.value("startup_scan", true).toBool()); |
123 ui_->monitor->setChecked(s.value("monitor", true).toBool()); | 171 ui_->monitor->setChecked(s.value("monitor", true).toBool()); |
124 ·· | 172 ·· |
125 QStringList filters = s.value("cover_art_patterns", | 173 QStringList filters = s.value("cover_art_patterns", |
126 QStringList() << "front" << "cover").toStringList(); | 174 QStringList() << "front" << "cover").toStringList(); |
127 ui_->cover_art_patterns->setText(filters.join(",")); | 175 ui_->cover_art_patterns->setText(filters.join(",")); |
128 ·· | 176 ·· |
129 s.endGroup(); | 177 s.endGroup(); |
| 178 |
| 179 //Retrieving all existing folders |
| 180 QModelIndex index; |
| 181 int number_rows=dialog()->library_directory_model()->rowCount(); |
| 182 for(int i=0; i<number_rows; ++i) { |
| 183 index=dialog()->library_directory_model()->index(i,0,QModelIndex()); |
| 184 folder_filenames_.append(dialog()->library_directory_model()->data(index,Qt:
:DisplayRole).toString()); |
| 185 } |
130 } | 186 } |
OLD | NEW |