[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 3 |
|
---|
| 4 | This program 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 2 of the License, or
|
---|
| 7 | (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This program 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 this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "filesettings.h"
|
---|
| 20 | #include "mediasettings.h"
|
---|
[181] | 21 | #include "mediadata.h"
|
---|
[112] | 22 | #include <QSettings>
|
---|
| 23 | #include <QFileInfo>
|
---|
[181] | 24 | #include <QDebug>
|
---|
[112] | 25 |
|
---|
| 26 | FileSettings::FileSettings(QString directory) : FileSettingsBase(directory)
|
---|
| 27 | {
|
---|
| 28 | my_settings = new QSettings(directory + "/smplayer_files.ini", QSettings::IniFormat);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | FileSettings::~FileSettings() {
|
---|
| 32 | delete my_settings;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[181] | 35 | QString FileSettings::filenameToGroupname(const QString & filename, int type) {
|
---|
[112] | 36 | QString s = filename;
|
---|
| 37 | s = s.replace('/', '_');
|
---|
| 38 | s = s.replace('\\', '_');
|
---|
| 39 | s = s.replace(':', '_');
|
---|
| 40 | s = s.replace('.', '_');
|
---|
| 41 | s = s.replace(' ', '_');
|
---|
| 42 |
|
---|
[181] | 43 | if (type == TYPE_FILE) {
|
---|
| 44 | QFileInfo fi(filename);
|
---|
| 45 | if (fi.exists()) {
|
---|
| 46 | s += "_" + QString::number(fi.size());
|
---|
| 47 | }
|
---|
[112] | 48 | }
|
---|
| 49 |
|
---|
[181] | 50 | return s;
|
---|
[112] | 51 | }
|
---|
| 52 |
|
---|
[181] | 53 | bool FileSettings::existSettingsFor(QString filename, int type) {
|
---|
| 54 | qDebug() << "FileSettings::existSettingsFor" << filename;
|
---|
[112] | 55 |
|
---|
[181] | 56 | if (type != TYPE_FILE && type != TYPE_STREAM) return false;
|
---|
[112] | 57 |
|
---|
[181] | 58 | QString group_name = filenameToGroupname(filename, type);
|
---|
[112] | 59 |
|
---|
[181] | 60 | qDebug() << "FileSettings::existSettingsFor: group_name:" << group_name;
|
---|
| 61 |
|
---|
[112] | 62 | my_settings->beginGroup( group_name );
|
---|
| 63 | bool saved = my_settings->value("saved", false).toBool();
|
---|
| 64 | my_settings->endGroup();
|
---|
| 65 |
|
---|
| 66 | return saved;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[181] | 69 | void FileSettings::loadSettingsFor(QString filename, int type, MediaSettings & mset, int player) {
|
---|
| 70 | qDebug() << "FileSettings::loadSettingsFor:" << filename;
|
---|
[112] | 71 |
|
---|
[181] | 72 | if (type != TYPE_FILE && type != TYPE_STREAM) return;
|
---|
[112] | 73 |
|
---|
[181] | 74 | QString group_name = filenameToGroupname(filename, type);
|
---|
[112] | 75 |
|
---|
[181] | 76 | qDebug() << "FileSettings::loadSettingsFor: group_name:" << group_name;
|
---|
| 77 |
|
---|
[112] | 78 | mset.reset();
|
---|
[176] | 79 |
|
---|
[112] | 80 | my_settings->beginGroup( group_name );
|
---|
[176] | 81 | mset.load(my_settings, player);
|
---|
[112] | 82 | my_settings->endGroup();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[181] | 85 | void FileSettings::saveSettingsFor(QString filename, int type, MediaSettings & mset, int player) {
|
---|
| 86 | qDebug() << "FileSettings::saveSettingsFor:" << filename;
|
---|
[112] | 87 |
|
---|
[181] | 88 | if (type != TYPE_FILE && type != TYPE_STREAM) return;
|
---|
[112] | 89 |
|
---|
[181] | 90 | QString group_name = filenameToGroupname(filename, type);
|
---|
[112] | 91 |
|
---|
[181] | 92 | qDebug() << "FileSettings::saveSettingsFor: group_name:" << group_name;
|
---|
| 93 |
|
---|
[112] | 94 | my_settings->beginGroup( group_name );
|
---|
| 95 | my_settings->setValue("saved", true);
|
---|
[176] | 96 | mset.save(my_settings, player);
|
---|
[112] | 97 | my_settings->endGroup();
|
---|
| 98 | }
|
---|
| 99 |
|
---|