| [90] | 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| [186] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <[email protected]>
|
|---|
| [90] | 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"
|
|---|
| [179] | 21 | #include "mediadata.h"
|
|---|
| [90] | 22 | #include <QSettings>
|
|---|
| 23 | #include <QFileInfo>
|
|---|
| [179] | 24 | #include <QDebug>
|
|---|
| [90] | 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 |
|
|---|
| [179] | 35 | QString FileSettings::filenameToGroupname(const QString & filename, int type) {
|
|---|
| [90] | 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 |
|
|---|
| [179] | 43 | if (type == TYPE_FILE) {
|
|---|
| 44 | QFileInfo fi(filename);
|
|---|
| 45 | if (fi.exists()) {
|
|---|
| 46 | s += "_" + QString::number(fi.size());
|
|---|
| 47 | }
|
|---|
| [90] | 48 | }
|
|---|
| 49 |
|
|---|
| [179] | 50 | return s;
|
|---|
| [90] | 51 | }
|
|---|
| 52 |
|
|---|
| [179] | 53 | bool FileSettings::existSettingsFor(QString filename, int type) {
|
|---|
| 54 | qDebug() << "FileSettings::existSettingsFor" << filename;
|
|---|
| [90] | 55 |
|
|---|
| [179] | 56 | if (type != TYPE_FILE && type != TYPE_STREAM) return false;
|
|---|
| [90] | 57 |
|
|---|
| [179] | 58 | QString group_name = filenameToGroupname(filename, type);
|
|---|
| [90] | 59 |
|
|---|
| [179] | 60 | qDebug() << "FileSettings::existSettingsFor: group_name:" << group_name;
|
|---|
| 61 |
|
|---|
| [90] | 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 |
|
|---|
| [179] | 69 | void FileSettings::loadSettingsFor(QString filename, int type, MediaSettings & mset, int player) {
|
|---|
| 70 | qDebug() << "FileSettings::loadSettingsFor:" << filename;
|
|---|
| [90] | 71 |
|
|---|
| [179] | 72 | if (type != TYPE_FILE && type != TYPE_STREAM) return;
|
|---|
| [90] | 73 |
|
|---|
| [179] | 74 | QString group_name = filenameToGroupname(filename, type);
|
|---|
| [90] | 75 |
|
|---|
| [179] | 76 | qDebug() << "FileSettings::loadSettingsFor: group_name:" << group_name;
|
|---|
| 77 |
|
|---|
| [90] | 78 | mset.reset();
|
|---|
| [175] | 79 |
|
|---|
| [90] | 80 | my_settings->beginGroup( group_name );
|
|---|
| [175] | 81 | mset.load(my_settings, player);
|
|---|
| [90] | 82 | my_settings->endGroup();
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| [179] | 85 | void FileSettings::saveSettingsFor(QString filename, int type, MediaSettings & mset, int player) {
|
|---|
| 86 | qDebug() << "FileSettings::saveSettingsFor:" << filename;
|
|---|
| [90] | 87 |
|
|---|
| [179] | 88 | if (type != TYPE_FILE && type != TYPE_STREAM) return;
|
|---|
| [90] | 89 |
|
|---|
| [179] | 90 | QString group_name = filenameToGroupname(filename, type);
|
|---|
| [90] | 91 |
|
|---|
| [179] | 92 | qDebug() << "FileSettings::saveSettingsFor: group_name:" << group_name;
|
|---|
| 93 |
|
|---|
| [90] | 94 | my_settings->beginGroup( group_name );
|
|---|
| 95 | my_settings->setValue("saved", true);
|
|---|
| [175] | 96 | mset.save(my_settings, player);
|
|---|
| [90] | 97 | my_settings->endGroup();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|