Make sure we don't create a new profile with existing name, nor create a...

Make sure we don't create a new profile with existing name, nor create a duplicate of already existing one when opening a document with unknown profile:
http://kdenlive.org/mantis/view.php?id=595

svn path=/trunk/kdenlive/; revision=3539
parent 2468e476
......@@ -41,6 +41,7 @@
#include <QCryptographicHash>
#include <QFile>
#include <QInputDialog>
#include <mlt++/Mlt.h>
......@@ -578,7 +579,6 @@ void KdenliveDoc::setProfilePath(QString path)
KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
} else {
KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
m_profile.description = profileInfo.attribute("description");
m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
......@@ -589,7 +589,29 @@ void KdenliveDoc::setProfilePath(QString path)
m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
ProfilesDialog::saveProfile(m_profile);
QString existing = ProfilesDialog::existingProfile(m_profile);
if (!existing.isEmpty()) {
m_profile = ProfilesDialog::getVideoProfile(existing);
KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
} else {
QString newDesc = m_profile.description;
bool ok = true;
while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
newDesc = QInputDialog::getText(kapp->activeWindow(), i18n("Existing Profile"), i18n("Your project uses an unknown profile.\nIt uses an existing profile name: %1.\nPlease choose a new name to save it", newDesc), QLineEdit::Normal, newDesc, &ok);
}
if (ok == false) {
// User canceled, use default profile
m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
} else {
if (newDesc != m_profile.description) {
// Profile description existed, was replaced by new one
m_profile.description = newDesc;
} else {
KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
}
ProfilesDialog::saveProfile(m_profile);
}
}
setModified(true);
}
}
......
......@@ -256,6 +256,75 @@ QString ProfilesDialog::getProfileDescription(QString name)
return QString();
}
// static
bool ProfilesDialog::existingProfileDescription(const QString &desc)
{
QStringList profilesFilter;
profilesFilter << "*";
// List the Mlt profiles
QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
for (int i = 0; i < profilesFiles.size(); ++i) {
KConfig confFile(KdenliveSettings::mltpath() + '/' + profilesFiles.at(i), KConfig::SimpleConfig);
if (desc == confFile.entryMap().value("description")) return true;
}
// List custom profiles
QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
for (int i = 0; i < customProfiles.size(); ++i) {
profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
for (int j = 0; j < profilesFiles.size(); ++j) {
KConfig confFile(customProfiles.at(i) + '/' + profilesFiles.at(j), KConfig::SimpleConfig);
if (desc == confFile.entryMap().value("description")) return true;
}
}
return false;
}
// static
QString ProfilesDialog::existingProfile(MltVideoProfile profile)
{
// Check if the profile has a matching entry in existing ones
QStringList profilesFilter;
profilesFilter << "*";
// Check the Mlt profiles
QStringList profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
for (int i = 0; i < profilesFiles.size(); ++i) {
KConfig confFile(KdenliveSettings::mltpath() + '/' + profilesFiles.at(i), KConfig::SimpleConfig);
if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
if (profile.width != confFile.entryMap().value("width").toInt()) continue;
if (profile.height != confFile.entryMap().value("height").toInt()) continue;
if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
return profilesFiles.at(i);
}
// Check custom profiles
QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
for (int i = 0; i < customProfiles.size(); ++i) {
profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
for (int j = 0; j < profilesFiles.size(); ++j) {
KConfig confFile(customProfiles.at(i) + '/' + profilesFiles.at(j), KConfig::SimpleConfig);
if (profile.display_aspect_den != confFile.entryMap().value("display_aspect_den").toInt()) continue;
if (profile.display_aspect_num != confFile.entryMap().value("display_aspect_num").toInt()) continue;
if (profile.sample_aspect_den != confFile.entryMap().value("sample_aspect_den").toInt()) continue;
if (profile.sample_aspect_num != confFile.entryMap().value("sample_aspect_num").toInt()) continue;
if (profile.width != confFile.entryMap().value("width").toInt()) continue;
if (profile.height != confFile.entryMap().value("height").toInt()) continue;
if (profile.frame_rate_den != confFile.entryMap().value("frame_rate_den").toInt()) continue;
if (profile.frame_rate_num != confFile.entryMap().value("frame_rate_num").toInt()) continue;
if (profile.progressive != confFile.entryMap().value("progressive").toInt()) continue;
return customProfiles.at(i) + '/' + profilesFiles.at(j);
}
}
return QString();
}
// static
QMap <QString, QString> ProfilesDialog::getProfilesInfo()
{
......
......@@ -40,6 +40,8 @@ public:
static MltVideoProfile getVideoProfile(QString name);
static QMap <QString, QString> getProfilesInfo();
static void saveProfile(MltVideoProfile &profile);
static QString existingProfile(MltVideoProfile profile);
static bool existingProfileDescription(const QString &desc);
protected:
virtual void closeEvent(QCloseEvent *event);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment