1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "profilesdialog.h"
21 #include "kdenlivesettings.h"
23 #include <KStandardDirs>
25 #include <KMessageBox>
26 #include <KIO/NetAccess>
29 #include <QCloseEvent>
31 ProfilesDialog::ProfilesDialog(QWidget * parent) :
33 m_profileIsModified(false),
34 m_isCustomProfile(false)
38 // Fill colorspace list (see mlt_profile.h)
39 m_view.colorspace->addItem(getColorspaceDescription(601), 601);
40 m_view.colorspace->addItem(getColorspaceDescription(709), 709);
41 m_view.colorspace->addItem(getColorspaceDescription(240), 240);
42 m_view.colorspace->addItem(getColorspaceDescription(0), 0);
44 QStringList profilesFilter;
45 profilesFilter << "*";
47 m_view.button_delete->setIcon(KIcon("trash-empty"));
48 m_view.button_delete->setToolTip(i18n("Delete profile"));
49 m_view.button_save->setIcon(KIcon("document-save"));
50 m_view.button_save->setToolTip(i18n("Save profile"));
51 m_view.button_create->setIcon(KIcon("document-new"));
52 m_view.button_create->setToolTip(i18n("Create new profile"));
56 connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
57 connect(m_view.button_create, SIGNAL(clicked()), this, SLOT(slotCreateProfile()));
58 connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
59 connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
60 connect(m_view.button_default, SIGNAL(clicked()), this, SLOT(slotSetDefaultProfile()));
62 connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
63 connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
64 connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
65 connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
66 connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
67 connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
68 connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
69 connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
70 connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
71 connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
75 ProfilesDialog::ProfilesDialog(QString profilePath, QWidget * parent) :
77 m_profileIsModified(false),
78 m_isCustomProfile(true),
79 m_customProfilePath(profilePath)
83 // Fill colorspace list (see mlt_profile.h)
84 m_view.colorspace->addItem(getColorspaceDescription(601), 601);
85 m_view.colorspace->addItem(getColorspaceDescription(709), 709);
86 m_view.colorspace->addItem(getColorspaceDescription(240), 240);
87 m_view.colorspace->addItem(getColorspaceDescription(0), 0);
89 QStringList profilesFilter;
90 profilesFilter << "*";
92 m_view.button_save->setIcon(KIcon("document-save"));
93 m_view.button_save->setToolTip(i18n("Save profile"));
94 m_view.button_create->setHidden(true);
95 m_view.profiles_list->setHidden(true);
96 m_view.button_delete->setHidden(true);
97 m_view.button_default->setHidden(true);
98 m_view.description->setEnabled(false);
100 slotUpdateDisplay(profilePath);
101 connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
103 connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
104 connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
105 connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
106 connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
107 connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
108 connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
109 connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
110 connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
111 connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
112 connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
115 void ProfilesDialog::slotProfileEdited()
117 m_profileIsModified = true;
120 void ProfilesDialog::fillList(const QString selectedProfile)
122 // List the Mlt profiles
123 m_view.profiles_list->clear();
124 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
125 QMapIterator<QString, QString> i(profilesInfo);
126 while (i.hasNext()) {
128 m_view.profiles_list->addItem(i.key(), i.value());
131 if (!KdenliveSettings::default_profile().isEmpty()) {
132 for (int i = 0; i < m_view.profiles_list->count(); i++) {
133 if (m_view.profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
134 m_view.profiles_list->setCurrentIndex(i);
139 int ix = m_view.profiles_list->findText(selectedProfile);
140 if (ix != -1) m_view.profiles_list->setCurrentIndex(ix);
141 m_selectedProfileIndex = m_view.profiles_list->currentIndex();
144 void ProfilesDialog::accept()
146 if (askForSave()) QDialog::accept();
149 void ProfilesDialog::closeEvent(QCloseEvent *event)
158 bool ProfilesDialog::askForSave()
160 if (!m_profileIsModified) return true;
161 if (KMessageBox::questionYesNo(this, i18n("The custom profile was modified, do you want to save it?")) != KMessageBox::Yes) return true;
162 return slotSaveProfile();
165 void ProfilesDialog::slotCreateProfile()
167 m_view.button_delete->setEnabled(false);
168 m_view.button_create->setEnabled(false);
169 m_view.button_save->setEnabled(true);
170 m_view.properties->setEnabled(true);
173 void ProfilesDialog::slotSetDefaultProfile()
175 int ix = m_view.profiles_list->currentIndex();
176 QString path = m_view.profiles_list->itemData(ix).toString();
177 if (!path.isEmpty()) KdenliveSettings::setDefault_profile(path);
180 bool ProfilesDialog::slotSaveProfile()
182 if (!m_customProfilePath.isEmpty()) {
183 saveProfile(m_customProfilePath);
186 const QString profileDesc = m_view.description->text();
187 int ix = m_view.profiles_list->findText(profileDesc);
189 // this profile name already exists
190 const QString path = m_view.profiles_list->itemData(ix).toString();
191 if (!path.contains('/')) {
192 KMessageBox::sorry(this, i18n("A profile with same name already exists in MLT's default profiles, please choose another description for your custom profile."));
198 QString customName = "profiles/customprofile";
199 QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
200 kDebug() << " TYING PROFILE FILE: " << profilePath;
201 while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, this)) {
203 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
205 saveProfile(profilePath);
207 m_profileIsModified = false;
208 fillList(profileDesc);
209 m_view.button_create->setEnabled(true);
213 void ProfilesDialog::saveProfile(const QString path)
216 if (!file.open(QIODevice::WriteOnly)) {
217 KMessageBox::sorry(this, i18n("Cannot write to file %1", path));
220 QTextStream out(&file);
221 out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n" << "colorspace=" << m_view.colorspace->itemData(m_view.colorspace->currentIndex()).toInt() << "\n";
222 if (file.error() != QFile::NoError) {
223 KMessageBox::error(this, i18n("Cannot write to file %1", path));
228 void ProfilesDialog::slotDeleteProfile()
230 const QString path = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
231 if (path.contains('/')) {
232 KIO::NetAccess::del(KUrl(path), this);
234 } else kDebug() << "//// Cannot delete profile " << path << ", does not seem to be custom one";
238 MltVideoProfile ProfilesDialog::getVideoProfile(QString name)
240 MltVideoProfile result;
241 QStringList profilesNames;
242 QStringList profilesFiles;
243 QStringList profilesFilter;
244 profilesFilter << "*";
246 bool isCustom = false;
247 if (name.contains('/')) isCustom = true;
250 // List the Mlt profiles
251 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
252 if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + name;
254 if (isCustom || path.isEmpty()) {
258 if (path.isEmpty() || !QFile::exists(path)) {
259 if (name == "dv_pal") {
260 kDebug() << "!!! WARNING, COULD NOT FIND DEFAULT MLT PROFILE";
263 if (name == KdenliveSettings::default_profile()) KdenliveSettings::setDefault_profile("dv_pal");
264 kDebug() << "// WARNING, COULD NOT FIND PROFILE " << name;
267 KConfig confFile(path, KConfig::SimpleConfig);
269 result.description = confFile.entryMap().value("description");
270 result.frame_rate_num = confFile.entryMap().value("frame_rate_num").toInt();
271 result.frame_rate_den = confFile.entryMap().value("frame_rate_den").toInt();
272 result.width = confFile.entryMap().value("width").toInt();
273 result.height = confFile.entryMap().value("height").toInt();
274 result.progressive = confFile.entryMap().value("progressive").toInt();
275 result.sample_aspect_num = confFile.entryMap().value("sample_aspect_num").toInt();
276 result.sample_aspect_den = confFile.entryMap().value("sample_aspect_den").toInt();
277 result.display_aspect_num = confFile.entryMap().value("display_aspect_num").toInt();
278 result.display_aspect_den = confFile.entryMap().value("display_aspect_den").toInt();
279 result.colorspace = confFile.entryMap().value("colorspace").toInt();
284 double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval)
287 eval.replace("%width", QString::number(profile.width));
288 eval.replace("%height", QString::number(profile.height));
289 if (eval.contains('/')) result = (double) eval.section('/', 0, 0).toInt() / eval.section('/', 1, 1).toInt();
290 else if (eval.contains('*')) result = (double) eval.section('*', 0, 0).toInt() * eval.section('*', 1, 1).toInt();
291 else if (eval.contains('+')) result = (double) eval.section('+', 0, 0).toInt() + eval.section('+', 1, 1).toInt();
292 else if (eval.contains('-')) result = (double) eval.section('-', 0, 0).toInt() - eval.section('-', 1, 1).toInt();
293 else result = eval.toDouble();
299 bool ProfilesDialog::existingProfileDescription(const QString &desc)
301 QStringList profilesFilter;
302 profilesFilter << "*";
304 // List the Mlt profiles
305 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
306 for (int i = 0; i < profilesFiles.size(); ++i) {
307 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
308 if (desc == confFile.entryMap().value("description")) return true;
311 // List custom profiles
312 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
313 for (int i = 0; i < customProfiles.size(); ++i) {
314 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
315 for (int j = 0; j < profilesFiles.size(); ++j) {
316 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
317 if (desc == confFile.entryMap().value("description")) return true;
324 QString ProfilesDialog::existingProfile(MltVideoProfile profile)
326 // Check if the profile has a matching entry in existing ones
327 QStringList profilesFilter;
328 profilesFilter << "*";
330 // Check the Mlt profiles
331 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
332 for (int i = 0; i < profilesFiles.size(); ++i) {
333 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
334 if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
335 if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
336 if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
337 if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
338 if (profile.width != confFile.entryMap().value("width").toInt()) continue;
339 if (profile.height != confFile.entryMap().value("height").toInt()) continue;
340 if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
341 if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
342 if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
343 if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
344 return profilesFiles.at(i);
347 // Check custom profiles
348 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
349 for (int i = 0; i < customProfiles.size(); ++i) {
350 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
351 for (int j = 0; j < profilesFiles.size(); ++j) {
352 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
353 if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
354 if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
355 if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
356 if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
357 if (profile.width != confFile.entryMap().value("width").toInt()) continue;
358 if (profile.height != confFile.entryMap().value("height").toInt()) continue;
359 if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
360 if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
361 if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
362 if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
363 return customProfiles.at(i) + profilesFiles.at(j);
370 QMap <QString, QString> ProfilesDialog::getProfilesInfo()
372 QMap <QString, QString> result;
373 QStringList profilesFilter;
374 profilesFilter << "*";
376 // List the Mlt profiles
377 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
378 for (int i = 0; i < profilesFiles.size(); ++i) {
379 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
380 QString desc = confFile.entryMap().value("description");
381 if (!desc.isEmpty()) result.insert(desc, profilesFiles.at(i));
384 // List custom profiles
385 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
386 for (int i = 0; i < customProfiles.size(); ++i) {
387 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
388 for (int j = 0; j < profilesFiles.size(); ++j) {
389 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
390 QString desc = confFile.entryMap().value("description");
391 if (!desc.isEmpty()) result.insert(desc, customProfiles.at(i) + profilesFiles.at(j));
398 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path)
400 QStringList profilesNames;
401 QStringList profilesFiles;
402 QStringList profilesFilter;
403 profilesFilter << "*";
405 if (!path.contains('/')) {
406 // This is an MLT profile
407 KConfig confFile(KdenliveSettings::mltpath() + path, KConfig::SimpleConfig);
408 return confFile.entryMap();
410 // This is a custom profile
411 KConfig confFile(path, KConfig::SimpleConfig);
412 return confFile.entryMap();
417 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName)
419 QStringList profilesNames;
420 QStringList profilesFiles;
421 QStringList profilesFilter;
422 profilesFilter << "*";
424 // List the Mlt profiles
425 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
426 for (int i = 0; i < profilesFiles.size(); ++i) {
427 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
428 QMap< QString, QString > values = confFile.entryMap();
429 if (values.value("description") == profileName) {
430 values.insert("path", profilesFiles.at(i));
435 // List custom profiles
436 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
437 for (int i = 0; i < customProfiles.size(); ++i) {
438 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
439 for (int j = 0; j < profiles.size(); ++j) {
440 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
441 QMap< QString, QString > values = confFile.entryMap();
442 if (values.value("description") == profileName) {
443 values.insert("path", customProfiles.at(i) + profiles.at(j));
448 return QMap< QString, QString >();
452 bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, MltVideoProfile profile)
456 // when using image, compare with display width
457 profileWidth = profile.height * profile.display_aspect_num / profile.display_aspect_den + 0.5;
458 } else profileWidth = profile.width;
459 if (width != profileWidth || height != profile.height || (fps > 0 && qAbs((double) profile.frame_rate_num / profile.frame_rate_den - fps) > 0.4) || (!isImage && par > 0 && qAbs((double) profile.sample_aspect_num / profile.sample_aspect_den - par) > 0.1)) return false;
464 QMap <QString, QString> ProfilesDialog::getProfilesFromProperties(int width, int height, double fps, double par, bool useDisplayWidth)
466 QStringList profilesNames;
467 QStringList profilesFiles;
468 QStringList profilesFilter;
469 QMap <QString, QString> result;
470 profilesFilter << "*";
471 // List the Mlt profiles
472 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
473 for (int i = 0; i < profilesFiles.size(); ++i) {
474 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
475 QMap< QString, QString > values = confFile.entryMap();
477 if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
478 else profileWidth = values.value("width").toInt();
479 if (profileWidth == width && values.value("height").toInt() == height) {
480 double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
481 double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
482 if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
483 result.insert(profilesFiles.at(i), values.value("description"));
487 // List custom profiles
488 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
489 for (int i = 0; i < customProfiles.size(); ++i) {
490 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
491 for (int j = 0; j < profiles.size(); j++) {
492 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
493 QMap< QString, QString > values = confFile.entryMap();
495 if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
496 else profileWidth = values.value("width").toInt();
497 if (profileWidth == width && values.value("height").toInt() == height) {
498 double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
499 double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
500 if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
501 result.insert(customProfiles.at(i) + profiles.at(j), values.value("description"));
509 QString ProfilesDialog::getPathFromDescription(const QString profileDesc)
511 QStringList profilesNames;
512 QStringList profilesFiles;
513 QStringList profilesFilter;
514 profilesFilter << "*";
516 // List the Mlt profiles
517 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
518 for (int i = 0; i < profilesFiles.size(); ++i) {
519 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
520 QMap< QString, QString > values = confFile.entryMap();
521 if (values.value("description") == profileDesc) return profilesFiles.at(i);
524 // List custom profiles
525 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
526 for (int i = 0; i < customProfiles.size(); ++i) {
527 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
528 for (int j = 0; j < profiles.size(); ++j) {
529 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
530 QMap< QString, QString > values = confFile.entryMap();
531 if (values.value("description") == profileDesc) return customProfiles.at(i) + profiles.at(j);
538 void ProfilesDialog::saveProfile(MltVideoProfile &profile, QString profilePath)
540 if (profilePath.isEmpty()) {
542 QString customName = "profiles/customprofile";
543 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
544 kDebug() << " TYING PROFILE FILE: " << profilePath;
545 while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, 0)) {
547 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
550 QFile file(profilePath);
551 if (!file.open(QIODevice::WriteOnly)) {
552 KMessageBox::sorry(0, i18n("Cannot write to file %1", profilePath));
555 QTextStream out(&file);
556 out << "description=" << profile.description << "\n" << "frame_rate_num=" << profile.frame_rate_num << "\n" << "frame_rate_den=" << profile.frame_rate_den << "\n" << "width=" << profile.width << "\n" << "height=" << profile.height << "\n" << "progressive=" << profile.progressive << "\n" << "sample_aspect_num=" << profile.sample_aspect_num << "\n" << "sample_aspect_den=" << profile.sample_aspect_den << "\n" << "display_aspect_num=" << profile.display_aspect_num << "\n" << "display_aspect_den=" << profile.display_aspect_den << "\n" << "colorspace=" << profile.colorspace << "\n";
557 if (file.error() != QFile::NoError) {
558 KMessageBox::error(0, i18n("Cannot write to file %1", profilePath));
561 profile.path = profilePath;
565 void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
567 if (askForSave() == false) {
568 m_view.profiles_list->blockSignals(true);
569 m_view.profiles_list->setCurrentIndex(m_selectedProfileIndex);
570 m_view.profiles_list->blockSignals(false);
574 m_selectedProfileIndex = m_view.profiles_list->currentIndex();
575 if (currentProfile.isEmpty()) currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
576 m_isCustomProfile = currentProfile.contains('/');
577 m_view.button_create->setEnabled(true);
578 m_view.button_delete->setEnabled(m_isCustomProfile);
579 m_view.properties->setEnabled(m_isCustomProfile);
580 m_view.button_save->setEnabled(m_isCustomProfile);
581 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
582 m_view.description->setText(values.value("description"));
583 m_view.size_w->setValue(values.value("width").toInt());
584 m_view.size_h->setValue(values.value("height").toInt());
585 m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
586 m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
587 m_view.display_num->setValue(values.value("display_aspect_num").toInt());
588 m_view.display_den->setValue(values.value("display_aspect_den").toInt());
589 m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
590 m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
591 m_view.progressive->setChecked(values.value("progressive").toInt());
592 if (values.value("progressive").toInt()) {
593 m_view.fields->setText(QString::number((double) values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
595 m_view.fields->setText(QString::number((double) 2 * values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
598 int colorix = m_view.colorspace->findData(values.value("colorspace").toInt());
599 if (colorix > -1) m_view.colorspace->setCurrentIndex(colorix);
600 m_profileIsModified = false;
604 QString ProfilesDialog::getColorspaceDescription(int colorspace)
606 //TODO: should the descriptions be translated?
607 switch (colorspace) {
609 return QString("ITU-R 601");
611 return QString("ITU-R 709");
613 return QString("SMPTE240M");
615 return i18n("Unknown");
620 int ProfilesDialog::getColorspaceFromDescription(const QString &description)
622 //TODO: should the descriptions be translated?
623 if (description == "SMPTE240M") return 240;
624 if (description == "ITU-R 709") return 709;
628 #include "profilesdialog.moc"