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