]> git.sesse.net Git - kdenlive/commitdiff
Fix image sequence clips
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 16 Aug 2010 08:43:31 +0000 (08:43 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 16 Aug 2010 08:43:31 +0000 (08:43 +0000)
svn path=/trunk/kdenlive/; revision=4725

src/clipproperties.cpp
src/projectlist.cpp
src/slideshowclip.cpp
src/slideshowclip.h

index 0073e9998131cfedfc65064c6d5cc7d539514186..5bbc0e323cf1e08100d596c2089c6a9e92f7a7f6 100644 (file)
@@ -579,14 +579,17 @@ QMap <QString, QString> ClipProperties::properties()
         if (m_old_props.value("fade") != value) props["fade"] = value;
         value = QString::number((int) m_view.luma_softness->value());
         if (m_old_props.value("softness") != value) props["softness"] = value;
-
-        QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
-        QString new_path = m_view.clip_path->text() + extension;
-        if (new_path != m_old_props.value("resource")) {
-            m_clipNeedsReLoad = true;
-            props["resource"] = new_path;
-            kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
-        }
+       
+       bool isMime = !(m_view.clip_path->text().contains('%'));
+       if (isMime) {
+           QString extension = "/.all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+           QString new_path = m_view.clip_path->text() + extension;
+           if (new_path != m_old_props.value("resource")) {
+               m_clipNeedsReLoad = true;
+               props["resource"] = new_path;
+               kDebug() << "////  SLIDE EDIT, NEW:" << new_path << ", OLD; " << m_old_props.value("resource");
+           }
+       }
         int duration;
         if (m_view.slide_duration_format->currentIndex() == 1) {
             // we are in frames mode
@@ -643,7 +646,7 @@ bool ClipProperties::needsTimelineReload() const
 void ClipProperties::parseFolder()
 {
     QString path = m_view.clip_path->text();
-    bool isMime = !(path.contains("%d"));
+    bool isMime = !(path.contains('%'));
     if (!isMime) path = KUrl(path).directory();
     QDir dir(path);
 
@@ -663,7 +666,7 @@ void ClipProperties::parseFolder()
         // find pattern
         QString filter = KUrl(m_view.clip_path->text()).fileName();
         QString ext = filter.section('.', -1);
-        filter = filter.section("%d", 0, -2);
+        filter = filter.section('%', 0, -2);
         QString regexp = "^" + filter + "\\d+\\." + ext + "$";
         QRegExp rx(regexp);
         QStringList entries;
index b3ede704f21c2561b601e4e5b5afb33bae799841..73c7d3b3e62e45f8d6eb90093c4213a7548a8fd5 100644 (file)
@@ -1091,9 +1091,10 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
             if (fileName.at(fileName.size() - 1).isDigit()) {
                 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
                 if (item.mimetype().startsWith("image")) {
-                    int count = SlideshowClip::sequenceCount(url);
+                    int count = 0;
                     // import as sequence if we found at least 5 images in the sequence
-                    if (count > 4) {
+                    QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
+                    if (count > 1) {
                         delete d;
                         QStringList groupInfo = getGroup();
 
@@ -1101,11 +1102,8 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
                         while (fileName.at(fileName.size() - 1).isDigit()) {
                             fileName.chop(1);
                         }
-                        QString folder = url.directory(KUrl::AppendTrailingSlash);
-                        QString ext = url.path().section('.', -1);
-                        folder.append(fileName + "%d." + ext);
 
-                        m_doc->slotCreateSlideshowClipFile(fileName, folder, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()), false, false, m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0, groupInfo.at(0), groupInfo.at(1));
+                        m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()), false, false, m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0, groupInfo.at(0), groupInfo.at(1));
                         return;
                     }
                 }
index 46923c529fcff00f98b103cc0a7b48bd48a67ece..49494fefb80c3346f9f087474ad5ae8f575ccac7 100644 (file)
@@ -267,26 +267,58 @@ void SlideshowClip::slotSetPixmap(const KFileItem &fileItem, const QPixmap &pix)
 }
 
 
-QString SlideshowClip::selectedPath() const
+QString SlideshowClip::selectedPath()
 {
-    QString extension;
-    QString folder;
+    return selectedPath(m_view.folder_url->url(), m_view.method_mime->isChecked(), ".all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString(), &m_count);
 
-    bool isMime = m_view.method_mime->isChecked();
+
+}
+// static
+QString SlideshowClip::selectedPath(KUrl url, bool isMime, QString extension, int *count)
+{
+    QString folder;
 
     if (isMime) {
-        folder = m_view.folder_url->url().path(KUrl::AddTrailingSlash);
-        extension = ".all." + m_view.image_type->itemData(m_view.image_type->currentIndex()).toString();
+        folder = url.path(KUrl::AddTrailingSlash);
     } else {
-        folder = m_view.pattern_url->url().directory(KUrl::AppendTrailingSlash);
-        QString filter = m_view.pattern_url->url().fileName();
-        QString ext = filter.section('.', -1);
+        folder = url.directory(KUrl::AppendTrailingSlash);
+        QString filter = url.fileName();
+        QString ext = '.' + filter.section('.', -1);
         filter = filter.section('.', 0, -2);
 
         while (filter.at(filter.size() - 1).isDigit()) {
             filter.chop(1);
         }
-        extension = filter + "%d." + ext;
+        // Check that the first image exists and which format it has (image1.jpg or image001.jpg, ...)
+
+        // Find first image in sequence
+        QString regexp = "^" + filter + "\\d+" + ext + "$";
+        QRegExp rx(regexp);
+        QStringList entries;
+
+        QDir dir(folder);
+        QStringList result = dir.entryList(QDir::Files);
+        int precision = 1;
+        QString pathValue;
+        QMap <int, QString> sortedList;
+        foreach(const QString &path, result) {
+            if (rx.exactMatch(path)) {
+                pathValue = path.section('.', 0, -2);
+                pathValue.remove(0, filter.size());
+                sortedList.insert(pathValue.toInt(), path);
+            }
+        }
+        *count = sortedList.size();
+        if (*count == 0) kDebug() << "No IMAGE FOUND!!!!!!!";
+        else  {
+            QMapIterator<int, QString> i(sortedList);
+            i.next();
+            QString result = i.value();
+            result.remove(0, filter.size());
+            result = result.section('.', 0, -2);
+            precision = result.size();
+        }
+        extension = filter + "%." + QString::number(precision) + "d" + ext;
     }
     return  folder + extension;
 }
index 9120de9a3ecfc8a7c4d83ac0bbb70334b449994e..dc9d07bbe70b5b9e9d8bcccd5327a3e5bc412680 100644 (file)
@@ -37,7 +37,7 @@ public:
     SlideshowClip(Timecode tc, QWidget * parent = 0);
     virtual ~ SlideshowClip();
     /** return selected path for slideshow in MLT format */
-    QString selectedPath() const;
+    QString selectedPath();
     QString clipName() const;
     QString clipDuration() const;
     QString lumaDuration() const;
@@ -49,6 +49,8 @@ public:
 
     /** @brief Check if there are several files with filename pattern, like: image_001.jpg, image_002.jpg,... */
     static int sequenceCount(KUrl file);
+    /** @brief return the url pattern for selected slideshow. */
+    static QString selectedPath(KUrl url, bool isMime, QString extension, int *count);
 
 private slots:
     void parseFolder();