]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Improve profile autodetection
[kdenlive] / src / projectlist.cpp
index 35bec5148f529003227e6aca0013525cc869a47f..18562312f62821e09ddc82d3d787e8be209bf200 100644 (file)
@@ -32,6 +32,7 @@
 #include "kthumb.h"
 #include "projectlistview.h"
 #include "timecodedisplay.h"
+#include "profilesdialog.h"
 #include "editclipcommand.h"
 #include "editclipcutcommand.h"
 #include "editfoldercommand.h"
 #include <QInputDialog>
 
 ProjectList::ProjectList(QWidget *parent) :
-        QWidget(parent),
-        m_render(NULL),
-        m_fps(-1),
-        m_commandStack(NULL),
-        m_editAction(NULL),
-        m_deleteAction(NULL),
-        m_openAction(NULL),
-        m_reloadAction(NULL),
-        m_transcodeAction(NULL),
-        m_doc(NULL),
-        m_refreshed(false),
-        m_infoQueue(),
-        m_thumbnailQueue()
+    QWidget(parent),
+    m_render(NULL),
+    m_fps(-1),
+    m_commandStack(NULL),
+    m_editAction(NULL),
+    m_deleteAction(NULL),
+    m_openAction(NULL),
+    m_reloadAction(NULL),
+    m_transcodeAction(NULL),
+    m_doc(NULL),
+    m_refreshed(false),
+    m_infoQueue(),
+    m_thumbnailQueue()
 {
 
     m_listView = new ProjectListView(this);;
@@ -559,9 +560,9 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
         if (data.count() > 2) {
             condition = data.at(2);
             if (condition.startsWith("vcodec"))
-                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
+                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
             else if (condition.startsWith("acodec"))
-                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
+                transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
         }
     }
 
@@ -1058,7 +1059,7 @@ QString ProjectList::getExtensions()
                             << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
 
     QString allExtensions;
-    foreach(const QString& mimeType, mimeTypes) {
+    foreach(const QString & mimeType, mimeTypes) {
         KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
         if (mime) {
             allExtensions.append(mime->patterns().join(" "));
@@ -1092,7 +1093,7 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
                 if (item.mimetype().startsWith("image")) {
                     int count = 0;
-                    // import as sequence if we found at least 5 images in the sequence
+                    // import as sequence if we found more than one image in the sequence
                     QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
                     if (count > 1) {
                         delete d;
@@ -1118,7 +1119,7 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
             list << givenList.at(i);
     }
 
-    foreach(const KUrl &file, list) {
+    foreach(const KUrl & file, list) {
         // Check there is no folder here
         KMimeType::Ptr type = KMimeType::findByUrl(file);
         if (type->is("inode/directory")) {
@@ -1472,11 +1473,56 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
     int max = m_doc->clipManager()->clipsCount();
     if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
         m_listView->setCurrentItem(item);
+        bool displayClipInMonitor = true;
         if (item->parent()) {
             if (item->parent()->type() == PROJECTFOLDERTYPE)
                 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
+        } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
+            // this is the first clip loaded in project, check if we want to adjust project settings to the clip
+            int width = properties.value("frame_size").section('x', 0, 0).toInt();
+            int height = properties.value("frame_size").section('x', -1).toInt();
+            double fps = properties.value("fps").toDouble();
+            double par = properties.value("aspect_ratio").toDouble();
+            if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
+                if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
+                    // get a list of compatible profiles
+                    QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
+                    if (!suggestedProfiles.isEmpty()) {
+                        KDialog *dialog = new KDialog(this);
+                        dialog->setCaption(i18n("Change project profile"));
+                        dialog->setButtons(KDialog::Ok | KDialog::Cancel);
+
+                        QWidget container;
+                        QVBoxLayout *l = new QVBoxLayout;
+                        QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", properties.value("frame_size"), fps));
+                        l->addWidget(label);
+                        QListWidget *list = new QListWidget;
+                        list->setAlternatingRowColors(true);
+                        QMapIterator<QString, QString> i(suggestedProfiles);
+                        while (i.hasNext()) {
+                            i.next();
+                            QListWidgetItem *item = new QListWidgetItem(i.value(), list);
+                            item->setData(Qt::UserRole, i.key());
+                            item->setToolTip(i.key());
+                        }
+                        list->setCurrentRow(0);
+                        l->addWidget(list);
+                        container.setLayout(l);
+                        dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
+                        dialog->setMainWidget(&container);
+                        if (dialog->exec() == QDialog::Accepted) {
+                            //Change project profile
+                            displayClipInMonitor = false;
+                            if (list->currentItem())
+                                emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
+                        }
+                        delete list;
+                        delete label;
+                    } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", properties.value("frame_size"), fps));
+                }
+            }
         }
-        emit clipSelected(item->referencedClip());
+        if (displayClipInMonitor) emit clipSelected(item->referencedClip());
     } else {
         emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
     }
@@ -1621,9 +1667,9 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
             continue;
         DocClipBase *clip = item->referencedClip();
         if (!condition.isEmpty()) {
-            if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1)))
+            if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
                 continue;
-            else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1)))
+            else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
                 continue;
         }
         result.append(item->clipUrl());