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"
24 #include <QDesktopServices>
26 #include <QStringList>
28 OptionsModel::OptionsModel(void)
30 m_rcMode = RCMode_CRF;
39 OptionsModel::~OptionsModel(void)
43 QString OptionsModel::rcMode2String(RCMode mode)
48 return QObject::tr("CRF");
51 return QObject::tr("CQ");
54 return QObject::tr("2-Pass");
57 return QObject::tr("ABR");
65 bool OptionsModel::equals(OptionsModel *model)
69 if(this->m_rcMode != model->m_rcMode) equal = false;
70 if(this->m_bitrate!= model->m_bitrate) equal = false;
71 if(this->m_quantizer != model->m_quantizer) equal = false;
72 if(this->m_preset.compare(model->m_preset, Qt::CaseInsensitive)) equal = false;
73 if(this->m_tune.compare(model->m_tune, Qt::CaseInsensitive)) equal = false;
74 if(this->m_profile.compare(model->m_profile, Qt::CaseInsensitive)) equal = false;
75 if(this->m_custom.compare(model->m_custom, Qt::CaseInsensitive)) equal = false;
80 bool OptionsModel::saveTemplate(OptionsModel *model, const QString &name)
82 const QString templateName = name.simplified();
83 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
85 if(templateName.startsWith("<") || templateName.endsWith(">") || templateName.contains("\\") || templateName.contains("/"))
90 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
91 settings.beginGroup(templateName);
93 settings.setValue("rate_control_mode", model->m_rcMode);
94 settings.setValue("target_bitrate", model->m_bitrate);
95 settings.setValue("target_quantizer", model->m_quantizer);
96 settings.setValue("preset_name", model->m_preset);
97 settings.setValue("tuning_name", model->m_tune);
98 settings.setValue("profile_name", model->m_profile);
99 settings.setValue("custom_params", model->m_custom);
107 QMap<QString, OptionsModel*> OptionsModel::loadAllTemplates(void)
109 QMap<QString, OptionsModel*> list;
110 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
111 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
112 QStringList allTemplates = settings.childGroups();
114 while(!allTemplates.isEmpty())
116 settings.beginGroup(allTemplates.takeFirst());
118 bool complete = true;
119 if(!settings.contains("rate_control_mode")) complete = false;
120 if(!settings.contains("target_bitrate")) complete = false;
121 if(!settings.contains("target_quantizer")) complete = false;
122 if(!settings.contains("preset_name")) complete = false;
123 if(!settings.contains("tuning_name")) complete = false;
124 if(!settings.contains("profile_name")) complete = false;
125 if(!settings.contains("custom_params")) complete = false;
129 OptionsModel *options = new OptionsModel();
130 options->setRCMode(static_cast<OptionsModel::RCMode>(settings.value("rate_control_mode", options->m_rcMode).toInt()));
131 options->setBitrate(settings.value("target_bitrate", options->m_bitrate).toUInt());
132 options->setQuantizer(settings.value("target_quantizer", options->m_quantizer).toUInt());
133 options->setPreset(settings.value("preset_name", options->m_preset).toString());
134 options->setTune(settings.value("tuning_name", options->m_tune).toString());
135 options->setProfile(settings.value("profile_name", options->m_profile).toString());
136 options->setCustom(settings.value("custom_params", options->m_custom).toString());
137 list.insert(settings.group(), options);
146 bool OptionsModel::templateExists(const QString &name)
148 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
149 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
150 QStringList allGroups = settings.childGroups();
151 return allGroups.contains(name, Qt::CaseInsensitive);
154 bool OptionsModel::deleteTemplate(const QString &name)
156 const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
157 QSettings settings(QString("%1/templates.ini").arg(appDir), QSettings::IniFormat);
159 if(settings.childGroups().contains(name, Qt::CaseInsensitive))
161 settings.remove(name);