| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 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 <QSettings>
|
|---|
| 22 | #include <QFileInfo>
|
|---|
| 23 |
|
|---|
| 24 | FileSettings::FileSettings(QString directory) : FileSettingsBase(directory)
|
|---|
| 25 | {
|
|---|
| 26 | my_settings = new QSettings(directory + "/smplayer_files.ini", QSettings::IniFormat);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | FileSettings::~FileSettings() {
|
|---|
| 30 | delete my_settings;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | QString FileSettings::filenameToGroupname(const QString & filename) {
|
|---|
| 34 | QString s = filename;
|
|---|
| 35 | s = s.replace('/', '_');
|
|---|
| 36 | s = s.replace('\\', '_');
|
|---|
| 37 | s = s.replace(':', '_');
|
|---|
| 38 | s = s.replace('.', '_');
|
|---|
| 39 | s = s.replace(' ', '_');
|
|---|
| 40 |
|
|---|
| 41 | QFileInfo fi(filename);
|
|---|
| 42 | if (fi.exists()) {
|
|---|
| 43 | s += "_" + QString::number( fi.size() );
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | return s;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | bool FileSettings::existSettingsFor(QString filename) {
|
|---|
| 50 | qDebug("FileSettings::existSettingsFor: '%s'", filename.toUtf8().constData());
|
|---|
| 51 |
|
|---|
| 52 | QString group_name = filenameToGroupname(filename);
|
|---|
| 53 |
|
|---|
| 54 | qDebug("FileSettings::existSettingsFor: group_name: '%s'", group_name.toUtf8().constData());
|
|---|
| 55 |
|
|---|
| 56 | my_settings->beginGroup( group_name );
|
|---|
| 57 | bool saved = my_settings->value("saved", false).toBool();
|
|---|
| 58 | my_settings->endGroup();
|
|---|
| 59 |
|
|---|
| 60 | return saved;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void FileSettings::loadSettingsFor(QString filename, MediaSettings & mset) {
|
|---|
| 64 | qDebug("FileSettings::loadSettingsFor: '%s'", filename.toUtf8().constData());
|
|---|
| 65 |
|
|---|
| 66 | QString group_name = filenameToGroupname(filename);
|
|---|
| 67 |
|
|---|
| 68 | qDebug("FileSettings::loadSettingsFor: group_name: '%s'", group_name.toUtf8().constData());
|
|---|
| 69 |
|
|---|
| 70 | mset.reset();
|
|---|
| 71 | my_settings->beginGroup( group_name );
|
|---|
| 72 | mset.load(my_settings);
|
|---|
| 73 | my_settings->endGroup();
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | void FileSettings::saveSettingsFor(QString filename, MediaSettings & mset) {
|
|---|
| 77 | qDebug("FileSettings::saveSettingsFor: '%s'", filename.toUtf8().constData());
|
|---|
| 78 |
|
|---|
| 79 | QString group_name = filenameToGroupname(filename);
|
|---|
| 80 |
|
|---|
| 81 | qDebug("FileSettings::saveSettingsFor: group_name: '%s'", group_name.toUtf8().constData());
|
|---|
| 82 |
|
|---|
| 83 | my_settings->beginGroup( group_name );
|
|---|
| 84 | my_settings->setValue("saved", true);
|
|---|
| 85 | mset.save(my_settings);
|
|---|
| 86 | my_settings->endGroup();
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|