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 <qscriptengine.h>
30 #include <QCloseEvent>
31 #include <QScriptEngine>
33 ProfilesDialog::ProfilesDialog(QWidget * parent) :
35 m_profileIsModified(false),
36 m_isCustomProfile(false)
40 // Fill colorspace list (see mlt_profile.h)
41 m_view.colorspace->addItem(getColorspaceDescription(601), 601);
42 m_view.colorspace->addItem(getColorspaceDescription(709), 709);
43 m_view.colorspace->addItem(getColorspaceDescription(240), 240);
44 m_view.colorspace->addItem(getColorspaceDescription(0), 0);
46 QStringList profilesFilter;
47 profilesFilter << "*";
49 m_view.button_delete->setIcon(KIcon("trash-empty"));
50 m_view.button_delete->setToolTip(i18n("Delete profile"));
51 m_view.button_save->setIcon(KIcon("document-save"));
52 m_view.button_save->setToolTip(i18n("Save profile"));
53 m_view.button_create->setIcon(KIcon("document-new"));
54 m_view.button_create->setToolTip(i18n("Create new profile"));
58 connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
59 connect(m_view.button_create, SIGNAL(clicked()), this, SLOT(slotCreateProfile()));
60 connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
61 connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
62 connect(m_view.button_default, SIGNAL(clicked()), this, SLOT(slotSetDefaultProfile()));
64 connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
65 connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
66 connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
67 connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
68 connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
69 connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
70 connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
71 connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
72 connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
73 connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
77 ProfilesDialog::ProfilesDialog(QString profilePath, QWidget * parent) :
79 m_profileIsModified(false),
80 m_isCustomProfile(true),
81 m_customProfilePath(profilePath)
85 // Fill colorspace list (see mlt_profile.h)
86 m_view.colorspace->addItem(getColorspaceDescription(601), 601);
87 m_view.colorspace->addItem(getColorspaceDescription(709), 709);
88 m_view.colorspace->addItem(getColorspaceDescription(240), 240);
89 m_view.colorspace->addItem(getColorspaceDescription(0), 0);
91 QStringList profilesFilter;
92 profilesFilter << "*";
94 m_view.button_save->setIcon(KIcon("document-save"));
95 m_view.button_save->setToolTip(i18n("Save profile"));
96 m_view.button_create->setHidden(true);
97 m_view.profiles_list->setHidden(true);
98 m_view.button_delete->setHidden(true);
99 m_view.button_default->setHidden(true);
100 m_view.description->setEnabled(false);
102 slotUpdateDisplay(profilePath);
103 connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
105 connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
106 connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
107 connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
108 connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
109 connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
110 connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
111 connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
112 connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
113 connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
114 connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
117 void ProfilesDialog::slotProfileEdited()
119 m_profileIsModified = true;
122 void ProfilesDialog::fillList(const QString selectedProfile)
124 // List the Mlt profiles
125 m_view.profiles_list->clear();
126 QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
127 QMapIterator<QString, QString> i(profilesInfo);
128 while (i.hasNext()) {
130 m_view.profiles_list->addItem(i.key(), i.value());
133 if (!KdenliveSettings::default_profile().isEmpty()) {
134 for (int i = 0; i < m_view.profiles_list->count(); i++) {
135 if (m_view.profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
136 m_view.profiles_list->setCurrentIndex(i);
141 int ix = m_view.profiles_list->findText(selectedProfile);
142 if (ix != -1) m_view.profiles_list->setCurrentIndex(ix);
143 m_selectedProfileIndex = m_view.profiles_list->currentIndex();
146 void ProfilesDialog::accept()
148 if (askForSave()) QDialog::accept();
151 void ProfilesDialog::closeEvent(QCloseEvent *event)
160 bool ProfilesDialog::askForSave()
162 if (!m_profileIsModified) return true;
163 if (KMessageBox::questionYesNo(this, i18n("The custom profile was modified, do you want to save it?")) != KMessageBox::Yes) return true;
164 return slotSaveProfile();
167 void ProfilesDialog::slotCreateProfile()
169 m_view.button_delete->setEnabled(false);
170 m_view.button_create->setEnabled(false);
171 m_view.button_save->setEnabled(true);
172 m_view.properties->setEnabled(true);
175 void ProfilesDialog::slotSetDefaultProfile()
177 int ix = m_view.profiles_list->currentIndex();
178 QString path = m_view.profiles_list->itemData(ix).toString();
179 if (!path.isEmpty()) KdenliveSettings::setDefault_profile(path);
182 bool ProfilesDialog::slotSaveProfile()
184 if (!m_customProfilePath.isEmpty()) {
185 saveProfile(m_customProfilePath);
188 const QString profileDesc = m_view.description->text();
189 int ix = m_view.profiles_list->findText(profileDesc);
191 // this profile name already exists
192 const QString path = m_view.profiles_list->itemData(ix).toString();
193 if (!path.contains('/')) {
194 KMessageBox::sorry(this, i18n("A profile with same name already exists in MLT's default profiles, please choose another description for your custom profile."));
200 QString customName = "profiles/customprofile";
201 QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
202 kDebug() << " TYING PROFILE FILE: " << profilePath;
203 while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, this)) {
205 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
207 saveProfile(profilePath);
209 m_profileIsModified = false;
210 fillList(profileDesc);
211 m_view.button_create->setEnabled(true);
215 void ProfilesDialog::saveProfile(const QString path)
218 if (!file.open(QIODevice::WriteOnly)) {
219 KMessageBox::sorry(this, i18n("Cannot write to file %1", path));
222 QTextStream out(&file);
223 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";
224 if (file.error() != QFile::NoError) {
225 KMessageBox::error(this, i18n("Cannot write to file %1", path));
230 void ProfilesDialog::slotDeleteProfile()
232 const QString path = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
233 if (path.contains('/')) {
234 KIO::NetAccess::del(KUrl(path), this);
236 } else kDebug() << "//// Cannot delete profile " << path << ", does not seem to be custom one";
240 MltVideoProfile ProfilesDialog::getVideoProfile(QString name)
242 MltVideoProfile result;
243 QStringList profilesNames;
244 QStringList profilesFiles;
245 QStringList profilesFilter;
246 profilesFilter << "*";
248 bool isCustom = false;
249 if (name.contains('/')) isCustom = true;
252 // List the Mlt profiles
253 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
254 if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + name;
256 if (isCustom || path.isEmpty()) {
260 if (path.isEmpty() || !QFile::exists(path)) {
261 if (name == "dv_pal") {
262 kDebug() << "!!! WARNING, COULD NOT FIND DEFAULT MLT PROFILE";
265 if (name == KdenliveSettings::default_profile()) KdenliveSettings::setDefault_profile("dv_pal");
266 kDebug() << "// WARNING, COULD NOT FIND PROFILE " << name;
269 KConfig confFile(path, KConfig::SimpleConfig);
271 result.description = confFile.entryMap().value("description");
272 result.frame_rate_num = confFile.entryMap().value("frame_rate_num").toInt();
273 result.frame_rate_den = confFile.entryMap().value("frame_rate_den").toInt();
274 result.width = confFile.entryMap().value("width").toInt();
275 result.height = confFile.entryMap().value("height").toInt();
276 result.progressive = confFile.entryMap().value("progressive").toInt();
277 result.sample_aspect_num = confFile.entryMap().value("sample_aspect_num").toInt();
278 result.sample_aspect_den = confFile.entryMap().value("sample_aspect_den").toInt();
279 result.display_aspect_num = confFile.entryMap().value("display_aspect_num").toInt();
280 result.display_aspect_den = confFile.entryMap().value("display_aspect_den").toInt();
281 result.colorspace = confFile.entryMap().value("colorspace").toInt();
286 double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval, QPoint frameSize)
288 QScriptEngine sEngine;
289 sEngine.globalObject().setProperty("maxWidth", profile.width > frameSize.x() ? profile.width : frameSize.x());
290 sEngine.globalObject().setProperty("maxHeight", profile.height > frameSize.y() ? profile.height : frameSize.y());
291 sEngine.globalObject().setProperty("width", profile.width);
292 sEngine.globalObject().setProperty("height", profile.height);
293 return sEngine.evaluate(eval.remove('%')).toNumber();
298 bool ProfilesDialog::existingProfileDescription(const QString &desc)
300 QStringList profilesFilter;
301 profilesFilter << "*";
303 // List the Mlt profiles
304 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
305 for (int i = 0; i < profilesFiles.size(); ++i) {
306 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
307 if (desc == confFile.entryMap().value("description")) return true;
310 // List custom profiles
311 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
312 for (int i = 0; i < customProfiles.size(); ++i) {
313 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
314 for (int j = 0; j < profilesFiles.size(); ++j) {
315 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
316 if (desc == confFile.entryMap().value("description")) return true;
323 QString ProfilesDialog::existingProfile(MltVideoProfile profile)
325 // Check if the profile has a matching entry in existing ones
326 QStringList profilesFilter;
327 profilesFilter << "*";
329 // Check the Mlt profiles
330 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
331 for (int i = 0; i < profilesFiles.size(); ++i) {
332 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
333 if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
334 if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
335 if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
336 if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
337 if (profile.width != confFile.entryMap().value("width").toInt()) continue;
338 if (profile.height != confFile.entryMap().value("height").toInt()) continue;
339 if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
340 if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
341 if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
342 if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
343 return profilesFiles.at(i);
346 // Check custom profiles
347 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
348 for (int i = 0; i < customProfiles.size(); ++i) {
349 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
350 for (int j = 0; j < profilesFiles.size(); ++j) {
351 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
352 if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
353 if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
354 if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
355 if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
356 if (profile.width != confFile.entryMap().value("width").toInt()) continue;
357 if (profile.height != confFile.entryMap().value("height").toInt()) continue;
358 if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
359 if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
360 if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
361 if (profile.colorspace != confFile.entryMap().value("colorspace").toInt()) continue;
362 return customProfiles.at(i) + profilesFiles.at(j);
369 QMap <QString, QString> ProfilesDialog::getProfilesInfo()
371 QMap <QString, QString> result;
372 QStringList profilesFilter;
373 profilesFilter << "*";
375 // List the Mlt profiles
376 QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
377 for (int i = 0; i < profilesFiles.size(); ++i) {
378 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
379 QString desc = confFile.entryMap().value("description");
380 if (!desc.isEmpty()) result.insert(desc, profilesFiles.at(i));
383 // List custom profiles
384 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
385 for (int i = 0; i < customProfiles.size(); ++i) {
386 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
387 for (int j = 0; j < profilesFiles.size(); ++j) {
388 KConfig confFile(customProfiles.at(i) + profilesFiles.at(j), KConfig::SimpleConfig);
389 QString desc = confFile.entryMap().value("description");
390 if (!desc.isEmpty()) result.insert(desc, customProfiles.at(i) + profilesFiles.at(j));
397 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path)
399 QStringList profilesNames;
400 QStringList profilesFiles;
401 QStringList profilesFilter;
402 profilesFilter << "*";
404 if (!path.contains('/')) {
405 // This is an MLT profile
406 KConfig confFile(KdenliveSettings::mltpath() + path, KConfig::SimpleConfig);
407 return confFile.entryMap();
409 // This is a custom profile
410 KConfig confFile(path, KConfig::SimpleConfig);
411 return confFile.entryMap();
416 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName)
418 QStringList profilesNames;
419 QStringList profilesFiles;
420 QStringList profilesFilter;
421 profilesFilter << "*";
423 // List the Mlt profiles
424 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
425 for (int i = 0; i < profilesFiles.size(); ++i) {
426 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
427 QMap< QString, QString > values = confFile.entryMap();
428 if (values.value("description") == profileName) {
429 values.insert("path", profilesFiles.at(i));
434 // List custom profiles
435 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
436 for (int i = 0; i < customProfiles.size(); ++i) {
437 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
438 for (int j = 0; j < profiles.size(); ++j) {
439 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
440 QMap< QString, QString > values = confFile.entryMap();
441 if (values.value("description") == profileName) {
442 values.insert("path", customProfiles.at(i) + profiles.at(j));
447 return QMap< QString, QString >();
451 bool ProfilesDialog::matchProfile(int width, int height, double fps, double par, bool isImage, MltVideoProfile profile)
455 // when using image, compare with display width
456 profileWidth = profile.height * profile.display_aspect_num / profile.display_aspect_den + 0.5;
457 } else profileWidth = profile.width;
458 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;
463 QMap <QString, QString> ProfilesDialog::getProfilesFromProperties(int width, int height, double fps, double par, bool useDisplayWidth)
465 QStringList profilesNames;
466 QStringList profilesFiles;
467 QStringList profilesFilter;
468 QMap <QString, QString> result;
469 profilesFilter << "*";
470 // List the Mlt profiles
471 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
472 for (int i = 0; i < profilesFiles.size(); ++i) {
473 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
474 QMap< QString, QString > values = confFile.entryMap();
476 if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
477 else profileWidth = values.value("width").toInt();
478 if (profileWidth == width && values.value("height").toInt() == height) {
479 double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
480 double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
481 if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
482 result.insert(profilesFiles.at(i), values.value("description"));
486 // List custom profiles
487 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
488 for (int i = 0; i < customProfiles.size(); ++i) {
489 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
490 for (int j = 0; j < profiles.size(); j++) {
491 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
492 QMap< QString, QString > values = confFile.entryMap();
494 if (useDisplayWidth) profileWidth = values.value("height").toInt() * values.value("display_aspect_num").toInt() / values.value("display_aspect_den").toInt() + 0.5;
495 else profileWidth = values.value("width").toInt();
496 if (profileWidth == width && values.value("height").toInt() == height) {
497 double profile_fps = values.value("frame_rate_num").toDouble() / values.value("frame_rate_den").toDouble();
498 double profile_par = values.value("sample_aspect_num").toDouble() / values.value("sample_aspect_den").toDouble();
499 if ((fps <= 0 || qAbs(profile_fps - fps) < 0.5) && (par <= 0 || qAbs(profile_par - par) < 0.1))
500 result.insert(customProfiles.at(i) + profiles.at(j), values.value("description"));
508 QString ProfilesDialog::getPathFromDescription(const QString profileDesc)
510 QStringList profilesNames;
511 QStringList profilesFiles;
512 QStringList profilesFilter;
513 profilesFilter << "*";
515 // List the Mlt profiles
516 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
517 for (int i = 0; i < profilesFiles.size(); ++i) {
518 KConfig confFile(KdenliveSettings::mltpath() + profilesFiles.at(i), KConfig::SimpleConfig);
519 QMap< QString, QString > values = confFile.entryMap();
520 if (values.value("description") == profileDesc) return profilesFiles.at(i);
523 // List custom profiles
524 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
525 for (int i = 0; i < customProfiles.size(); ++i) {
526 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
527 for (int j = 0; j < profiles.size(); ++j) {
528 KConfig confFile(customProfiles.at(i) + profiles.at(j), KConfig::SimpleConfig);
529 QMap< QString, QString > values = confFile.entryMap();
530 if (values.value("description") == profileDesc) return customProfiles.at(i) + profiles.at(j);
537 void ProfilesDialog::saveProfile(MltVideoProfile &profile, QString profilePath)
539 if (profilePath.isEmpty()) {
541 QString customName = "profiles/customprofile";
542 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
543 kDebug() << " TYING PROFILE FILE: " << profilePath;
544 while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, 0)) {
546 profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
549 QFile file(profilePath);
550 if (!file.open(QIODevice::WriteOnly)) {
551 KMessageBox::sorry(0, i18n("Cannot write to file %1", profilePath));
554 QTextStream out(&file);
555 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";
556 if (file.error() != QFile::NoError) {
557 KMessageBox::error(0, i18n("Cannot write to file %1", profilePath));
560 profile.path = profilePath;
564 void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
566 if (askForSave() == false) {
567 m_view.profiles_list->blockSignals(true);
568 m_view.profiles_list->setCurrentIndex(m_selectedProfileIndex);
569 m_view.profiles_list->blockSignals(false);
573 m_selectedProfileIndex = m_view.profiles_list->currentIndex();
574 if (currentProfile.isEmpty()) currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
575 m_isCustomProfile = currentProfile.contains('/');
576 m_view.button_create->setEnabled(true);
577 m_view.button_delete->setEnabled(m_isCustomProfile);
578 m_view.properties->setEnabled(m_isCustomProfile);
579 m_view.button_save->setEnabled(m_isCustomProfile);
580 QMap< QString, QString > values = ProfilesDialog::getSettingsFromFile(currentProfile);
581 m_view.description->setText(values.value("description"));
582 m_view.size_w->setValue(values.value("width").toInt());
583 m_view.size_h->setValue(values.value("height").toInt());
584 m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
585 m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
586 m_view.display_num->setValue(values.value("display_aspect_num").toInt());
587 m_view.display_den->setValue(values.value("display_aspect_den").toInt());
588 m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
589 m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
590 m_view.progressive->setChecked(values.value("progressive").toInt());
591 if (values.value("progressive").toInt()) {
592 m_view.fields->setText(locale.toString((double) values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
594 m_view.fields->setText(locale.toString((double) 2 * values.value("frame_rate_num").toInt() / values.value("frame_rate_den").toInt(), 'f', 2));
597 int colorix = m_view.colorspace->findData(values.value("colorspace").toInt());
598 if (colorix > -1) m_view.colorspace->setCurrentIndex(colorix);
599 m_profileIsModified = false;
603 QString ProfilesDialog::getColorspaceDescription(int colorspace)
605 //TODO: should the descriptions be translated?
606 switch (colorspace) {
608 return QString("ITU-R 601");
610 return QString("ITU-R 709");
612 return QString("SMPTE240M");
614 return i18n("Unknown");
619 int ProfilesDialog::getColorspaceFromDescription(const QString &description)
621 //TODO: should the descriptions be translated?
622 if (description == "SMPTE240M") return 240;
623 if (description == "ITU-R 709") return 709;
627 #include "profilesdialog.moc"