+#include <QDir>
+#include <qscriptengine.h>
+#include <QCloseEvent>
+#include <QScriptEngine>
+
+ProfilesDialog::ProfilesDialog(QWidget * parent) :
+ QDialog(parent),
+ m_profileIsModified(false),
+ m_isCustomProfile(false)
+{
+ m_view.setupUi(this);
+
+ // Fill colorspace list (see mlt_profile.h)
+ m_view.colorspace->addItem(getColorspaceDescription(601), 601);
+ m_view.colorspace->addItem(getColorspaceDescription(709), 709);
+ m_view.colorspace->addItem(getColorspaceDescription(240), 240);
+ m_view.colorspace->addItem(getColorspaceDescription(0), 0);
+
+ QStringList profilesFilter;
+ profilesFilter << "*";
+
+ m_view.button_delete->setIcon(KIcon("trash-empty"));
+ m_view.button_delete->setToolTip(i18n("Delete profile"));
+ m_view.button_save->setIcon(KIcon("document-save"));
+ m_view.button_save->setToolTip(i18n("Save profile"));
+ m_view.button_create->setIcon(KIcon("document-new"));
+ m_view.button_create->setToolTip(i18n("Create new profile"));
+
+ fillList();
+ slotUpdateDisplay();
+ connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
+ connect(m_view.button_create, SIGNAL(clicked()), this, SLOT(slotCreateProfile()));
+ connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
+ connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
+ connect(m_view.button_default, SIGNAL(clicked()), this, SLOT(slotSetDefaultProfile()));
+
+ connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
+ connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+}
+
+
+ProfilesDialog::ProfilesDialog(QString profilePath, QWidget * parent) :
+ QDialog(parent),
+ m_profileIsModified(false),
+ m_isCustomProfile(true),
+ m_customProfilePath(profilePath)
+{
+ m_view.setupUi(this);
+
+ // Fill colorspace list (see mlt_profile.h)
+ m_view.colorspace->addItem(getColorspaceDescription(601), 601);
+ m_view.colorspace->addItem(getColorspaceDescription(709), 709);
+ m_view.colorspace->addItem(getColorspaceDescription(240), 240);
+ m_view.colorspace->addItem(getColorspaceDescription(0), 0);
+
+ QStringList profilesFilter;
+ profilesFilter << "*";
+
+ m_view.button_save->setIcon(KIcon("document-save"));
+ m_view.button_save->setToolTip(i18n("Save profile"));
+ m_view.button_create->setHidden(true);
+ m_view.profiles_list->setHidden(true);
+ m_view.button_delete->setHidden(true);
+ m_view.button_default->setHidden(true);
+ m_view.description->setEnabled(false);
+
+ slotUpdateDisplay(profilePath);
+ connect(m_view.button_save, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
+
+ connect(m_view.description, SIGNAL(textChanged(const QString &)), this, SLOT(slotProfileEdited()));
+ connect(m_view.frame_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.frame_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.aspect_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.aspect_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.display_num, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.display_den, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.progressive, SIGNAL(stateChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.size_h, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+ connect(m_view.size_w, SIGNAL(valueChanged(int)), this, SLOT(slotProfileEdited()));
+}
+
+void ProfilesDialog::slotProfileEdited()
+{
+ m_profileIsModified = true;
+}
+
+void ProfilesDialog::fillList(const QString selectedProfile)
+{
+ // List the Mlt profiles
+ m_view.profiles_list->clear();
+ QMap <QString, QString> profilesInfo = ProfilesDialog::getProfilesInfo();
+ QMapIterator<QString, QString> i(profilesInfo);
+ while (i.hasNext()) {
+ i.next();
+ m_view.profiles_list->addItem(i.key(), i.value());
+ }
+
+ if (!KdenliveSettings::default_profile().isEmpty()) {
+ for (int i = 0; i < m_view.profiles_list->count(); i++) {
+ if (m_view.profiles_list->itemData(i).toString() == KdenliveSettings::default_profile()) {
+ m_view.profiles_list->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
+ int ix = m_view.profiles_list->findText(selectedProfile);
+ if (ix != -1) m_view.profiles_list->setCurrentIndex(ix);
+ m_selectedProfileIndex = m_view.profiles_list->currentIndex();
+}
+
+void ProfilesDialog::accept()
+{
+ if (askForSave()) QDialog::accept();
+}
+
+void ProfilesDialog::closeEvent(QCloseEvent *event)
+{
+ if (askForSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
+bool ProfilesDialog::askForSave()
+{
+ if (!m_profileIsModified) return true;
+ if (KMessageBox::questionYesNo(this, i18n("The custom profile was modified, do you want to save it?")) != KMessageBox::Yes) return true;
+ return slotSaveProfile();
+}
+
+void ProfilesDialog::slotCreateProfile()
+{
+ m_view.button_delete->setEnabled(false);
+ m_view.button_create->setEnabled(false);
+ m_view.button_save->setEnabled(true);
+ m_view.properties->setEnabled(true);
+}
+
+void ProfilesDialog::slotSetDefaultProfile()
+{
+ int ix = m_view.profiles_list->currentIndex();
+ QString path = m_view.profiles_list->itemData(ix).toString();
+ if (!path.isEmpty()) KdenliveSettings::setDefault_profile(path);
+}
+
+bool ProfilesDialog::slotSaveProfile()
+{
+ if (!m_customProfilePath.isEmpty()) {
+ saveProfile(m_customProfilePath);
+ return true;
+ }
+ const QString profileDesc = m_view.description->text();
+ int ix = m_view.profiles_list->findText(profileDesc);
+ if (ix != -1) {
+ // this profile name already exists
+ const QString path = m_view.profiles_list->itemData(ix).toString();
+ if (!path.contains('/')) {
+ KMessageBox::sorry(this, i18n("A profile with same name already exists in MLT's default profiles, please choose another description for your custom profile."));
+ return false;
+ }
+ saveProfile(path);
+ } else {
+ int i = 0;
+ QString customName = "profiles/customprofile";
+ QString profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
+ kDebug() << " TYING PROFILE FILE: " << profilePath;
+ while (KIO::NetAccess::exists(KUrl(profilePath), KIO::NetAccess::SourceSide, this)) {
+ i++;
+ profilePath = KStandardDirs::locateLocal("appdata", customName + QString::number(i));
+ }
+ saveProfile(profilePath);
+ }
+ m_profileIsModified = false;
+ fillList(profileDesc);
+ m_view.button_create->setEnabled(true);
+ return true;
+}
+
+void ProfilesDialog::saveProfile(const QString path)
+{
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly)) {
+ KMessageBox::sorry(this, i18n("Cannot write to file %1", path));
+ return;
+ }
+ QTextStream out(&file);
+ 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";
+ if (file.error() != QFile::NoError) {
+ KMessageBox::error(this, i18n("Cannot write to file %1", path));
+ }
+ file.close();
+}
+
+void ProfilesDialog::slotDeleteProfile()
+{
+ const QString path = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
+ if (path.contains('/')) {
+ KIO::NetAccess::del(KUrl(path), this);
+ fillList();
+ } else kDebug() << "//// Cannot delete profile " << path << ", does not seem to be custom one";
+}
+
+// static
+MltVideoProfile ProfilesDialog::getVideoProfile(QString name)
+{
+ MltVideoProfile result;
+ QStringList profilesNames;
+ QStringList profilesFiles;
+ QStringList profilesFilter;
+ profilesFilter << "*";
+ QString path;
+ bool isCustom = false;
+ if (name.contains('/')) isCustom = true;
+
+ if (!isCustom) {
+ // List the Mlt profiles
+ profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+ if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + name;
+ }
+ if (isCustom || path.isEmpty()) {
+ path = name;
+ }
+
+ if (path.isEmpty() || !QFile::exists(path)) {
+ if (name == "dv_pal") {
+ kDebug() << "!!! WARNING, COULD NOT FIND DEFAULT MLT PROFILE";
+ return result;
+ }
+ if (name == KdenliveSettings::default_profile()) KdenliveSettings::setDefault_profile("dv_pal");
+ kDebug() << "// WARNING, COULD NOT FIND PROFILE " << name;
+ return result;
+ }
+ KConfig confFile(path, KConfig::SimpleConfig);
+ result.path = name;
+ result.description = confFile.entryMap().value("description");
+ result.frame_rate_num = confFile.entryMap().value("frame_rate_num").toInt();
+ result.frame_rate_den = confFile.entryMap().value("frame_rate_den").toInt();
+ result.width = confFile.entryMap().value("width").toInt();
+ result.height = confFile.entryMap().value("height").toInt();
+ result.progressive = confFile.entryMap().value("progressive").toInt();
+ result.sample_aspect_num = confFile.entryMap().value("sample_aspect_num").toInt();
+ result.sample_aspect_den = confFile.entryMap().value("sample_aspect_den").toInt();
+ result.display_aspect_num = confFile.entryMap().value("display_aspect_num").toInt();
+ result.display_aspect_den = confFile.entryMap().value("display_aspect_den").toInt();
+ result.colorspace = confFile.entryMap().value("colorspace").toInt();
+ return result;
+}