From 30cdea39ec91c7cd1f9052e187485076b90432e7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 17 Nov 2008 10:08:44 +0000 Subject: [PATCH] Ask to save profile before closing profiles dialog, default to pal dv when profile is not found. Should fix: http://www.kdenlive.org/mantis/view.php?id=354 http://www.kdenlive.org/mantis/view.php?id=359 svn path=/branches/KDE4/; revision=2708 --- src/profilesdialog.cpp | 72 +++++++++++++++++++++++++++------ src/profilesdialog.h | 10 ++++- src/widgets/profiledialog_ui.ui | 2 +- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 3cbd5af2..2b7af87d 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -18,6 +18,7 @@ ***************************************************************************/ #include +#include #include #include @@ -27,7 +28,7 @@ #include "kdenlivesettings.h" #include "profilesdialog.h" -ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false) { +ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false), m_profileIsModified(false) { m_view.setupUi(this); QStringList profilesFilter; @@ -47,6 +48,21 @@ ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomPro 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())); +} + +void ProfilesDialog::slotProfileEdited() { + m_profileIsModified = true; } void ProfilesDialog::fillList(const QString selectedProfile) { @@ -69,6 +85,25 @@ void ProfilesDialog::fillList(const QString selectedProfile) { } 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() { @@ -84,7 +119,7 @@ void ProfilesDialog::slotSetDefaultProfile() { if (!path.isEmpty()) KdenliveSettings::setDefault_profile(path); } -void ProfilesDialog::slotSaveProfile() { +bool ProfilesDialog::slotSaveProfile() { const QString profileDesc = m_view.description->text(); int ix = m_view.profiles_list->findText(profileDesc); if (ix != -1) { @@ -92,7 +127,7 @@ void ProfilesDialog::slotSaveProfile() { 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; + return false; } saveProfile(path); } else { @@ -106,7 +141,10 @@ void ProfilesDialog::slotSaveProfile() { } saveProfile(profilePath); } + m_profileIsModified = false; fillList(profileDesc); + m_view.button_create->setEnabled(true); + return true; } void ProfilesDialog::saveProfile(const QString path) { @@ -145,19 +183,18 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name) { if (profilesFiles.contains(name)) path = KdenliveSettings::mltpath() + "/" + name; } if (isCustom || path.isEmpty()) { - // List custom profiles path = name; - /* QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles"); - for (int i = 0; i < customProfiles.size(); ++i) { - profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files); - if (profilesFiles.contains(name)) { - path = customProfiles.at(i) + "/" + name; - break; - } - }*/ } - if (path.isEmpty()) return result; + 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 getVideoProfile("dv_pal"); + } KConfig confFile(path, KConfig::SimpleConfig); result.path = name; result.description = confFile.entryMap().value("description"); @@ -309,6 +346,14 @@ QString ProfilesDialog::getPathFromDescription(const QString profileDesc) { void ProfilesDialog::slotUpdateDisplay() { + if (askForSave() == false) { + m_view.profiles_list->blockSignals(true); + m_view.profiles_list->setCurrentIndex(m_selectedProfileIndex); + m_view.profiles_list->blockSignals(false); + return; + } + + m_selectedProfileIndex = m_view.profiles_list->currentIndex(); QString currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString(); m_isCustomProfile = currentProfile.contains("/"); m_view.button_delete->setEnabled(m_isCustomProfile); @@ -325,6 +370,7 @@ void ProfilesDialog::slotUpdateDisplay() { m_view.frame_num->setValue(values.value("frame_rate_num").toInt()); m_view.frame_den->setValue(values.value("frame_rate_den").toInt()); m_view.progressive->setChecked(values.value("progressive").toInt()); + m_profileIsModified = false; } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 26bfa362..00b23694 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -40,19 +40,27 @@ public: static MltVideoProfile getVideoProfile(QString name); static QMap getProfilesInfo(); +protected: + virtual void closeEvent(QCloseEvent *event); + private slots: void slotUpdateDisplay(); void slotCreateProfile(); - void slotSaveProfile(); + bool slotSaveProfile(); void slotDeleteProfile(); void slotSetDefaultProfile(); + void slotProfileEdited(); + virtual void accept(); private: Ui::ProfilesDialog_UI m_view; QStringList m_mltProfilesList; QStringList m_customProfilesList; + int m_selectedProfileIndex; + bool m_profileIsModified; bool m_isCustomProfile; void saveProfile(const QString path); + bool askForSave(); }; diff --git a/src/widgets/profiledialog_ui.ui b/src/widgets/profiledialog_ui.ui index 63ebf2db..2c5d601b 100644 --- a/src/widgets/profiledialog_ui.ui +++ b/src/widgets/profiledialog_ui.ui @@ -229,7 +229,7 @@ Qt::Horizontal - QDialogButtonBox::Close + QDialogButtonBox::Ok -- 2.39.2