1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 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_options.h"
26 #include <QDesktopServices>
28 #include <QStringList>
30 OptionsModel::OptionsModel(void)
32 m_rcMode = RCMode_CRF;
41 OptionsModel::~OptionsModel(void)
45 QString OptionsModel::rcMode2String(RCMode mode)
50 return QObject::tr("CRF");
53 return QObject::tr("CQ");
56 return QObject::tr("2-Pass");
59 return QObject::tr("ABR");
67 bool OptionsModel::equals(OptionsModel *model)
71 if(this->m_rcMode != model->m_rcMode) equal = false;
72 if(this->m_bitrate!= model->m_bitrate) equal = false;
73 if(this->m_quantizer != model->m_quantizer) equal = false;
74 if(this->m_preset.compare(model->m_preset, Qt::CaseInsensitive)) equal = false;
75 if(this->m_tune.compare(model->m_tune, Qt::CaseInsensitive)) equal = false;
76 if(this->m_profile.compare(model->m_profile, Qt::CaseInsensitive)) equal = false;
77 if(this->m_custom.compare(model->m_custom, Qt::CaseInsensitive)) equal = false;
82 bool OptionsModel::saveTemplate(OptionsModel *model, const QString &name)
84 const QString templateName = name.simplified();
85 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
87 if(templateName.contains('\\') || templateName.contains('/'))
92 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
93 settings.beginGroup(templateName);
95 settings.setValue("rate_control_mode", model->m_rcMode);
96 settings.setValue("target_bitrate", model->m_bitrate);
97 settings.setValue("target_quantizer", model->m_quantizer);
98 settings.setValue("preset_name", model->m_preset);
99 settings.setValue("tuning_name", model->m_tune);
100 settings.setValue("profile_name", model->m_profile);
101 settings.setValue("custom_params", model->m_custom);
109 bool OptionsModel::loadTemplate(OptionsModel *model, const QString &name)
111 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
113 if(name.contains('\\') || name.contains('/'))
118 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
119 settings.beginGroup(name);
121 bool complete = true;
122 if(!settings.contains("rate_control_mode")) complete = false;
123 if(!settings.contains("target_bitrate")) complete = false;
124 if(!settings.contains("target_quantizer")) complete = false;
125 if(!settings.contains("preset_name")) complete = false;
126 if(!settings.contains("tuning_name")) complete = false;
127 if(!settings.contains("profile_name")) complete = false;
128 if(!settings.contains("custom_params")) complete = false;
132 model->setRCMode(static_cast<OptionsModel::RCMode>(settings.value("rate_control_mode", model->m_rcMode).toInt()));
133 model->setBitrate(settings.value("target_bitrate", model->m_bitrate).toUInt());
134 model->setQuantizer(settings.value("target_quantizer", model->m_quantizer).toDouble());
135 model->setPreset(settings.value("preset_name", model->m_preset).toString());
136 model->setTune(settings.value("tuning_name", model->m_tune).toString());
137 model->setProfile(settings.value("profile_name", model->m_profile).toString());
138 model->setCustom(settings.value("custom_params", model->m_custom).toString());
145 QMap<QString, OptionsModel*> OptionsModel::loadAllTemplates(void)
147 QMap<QString, OptionsModel*> list;
148 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
149 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
150 QStringList allTemplates = settings.childGroups();
152 while(!allTemplates.isEmpty())
154 QString name = allTemplates.takeFirst();
155 if(!(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/')))
157 OptionsModel *options = new OptionsModel();
158 if(loadTemplate(options, name))
160 list.insert(name, options);
163 X264_DELETE(options);
170 bool OptionsModel::templateExists(const QString &name)
172 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
173 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
174 QStringList allGroups = settings.childGroups();
175 return allGroups.contains(name, Qt::CaseInsensitive);
178 bool OptionsModel::deleteTemplate(const QString &name)
180 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
181 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
183 if(settings.childGroups().contains(name, Qt::CaseInsensitive))
185 settings.remove(name);