1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "model_recently.h"
26 #include <QDesktopServices>
30 #define ARRAY_SIZE(ARRAY) (sizeof((ARRAY))/sizeof((ARRAY[0])))
31 #define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
33 static const char *KEY_FILTER_IDX = "path/filterIndex";
34 static const char *KEY_SOURCE_DIR = "path/directory_openFrom";
35 static const char *KEY_OUTPUT_DIR = "path/directory_saveTo";
37 RecentlyUsed::RecentlyUsed(void)
39 initRecentlyUsed(this);
42 void RecentlyUsed::initRecentlyUsed(RecentlyUsed *recentlyUsed)
44 recentlyUsed->m_sourceDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
45 recentlyUsed->m_outputDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
46 recentlyUsed->m_filterIndex = 0;
49 void RecentlyUsed::loadRecentlyUsed(RecentlyUsed *recentlyUsed)
51 RecentlyUsed defaults;
53 QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
54 recentlyUsed->m_sourceDirectory = settings.value(KEY_SOURCE_DIR, defaults.m_sourceDirectory).toString();
55 recentlyUsed->m_outputDirectory = settings.value(KEY_OUTPUT_DIR, defaults.m_outputDirectory).toString();
56 recentlyUsed->m_filterIndex = settings.value(KEY_FILTER_IDX, defaults.m_filterIndex).toInt();
58 if(!VALID_DIR(recentlyUsed->m_sourceDirectory)) recentlyUsed->m_sourceDirectory = defaults.m_sourceDirectory;
59 if(!VALID_DIR(recentlyUsed->m_outputDirectory)) recentlyUsed->m_outputDirectory = defaults.m_outputDirectory;
60 recentlyUsed->m_filterIndex = qBound(0, recentlyUsed->m_filterIndex, int(ARRAY_SIZE(X264_FILE_TYPE_FILTERS)-1));
63 void RecentlyUsed::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
65 QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
66 if(settings.isWritable())
68 settings.setValue(KEY_SOURCE_DIR, recentlyUsed->m_sourceDirectory);
69 settings.setValue(KEY_OUTPUT_DIR, recentlyUsed->m_outputDirectory);
70 settings.setValue(KEY_FILTER_IDX, recentlyUsed->m_filterIndex);