]> git.sesse.net Git - kdenlive/commitdiff
Proxy clip: allow to abort creation by unselecting the "proxy clip" action in context...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 31 Jan 2011 22:12:33 +0000 (22:12 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 31 Jan 2011 22:12:33 +0000 (22:12 +0000)
svn path=/trunk/kdenlive/; revision=5371

src/docclipbase.cpp
src/docclipbase.h
src/projectitem.cpp
src/projectitem.h
src/projectlist.cpp

index b0a5ed18392618c321d5492aabd9a0654c72382d..06342e6c9dbcbbd6f83d2cfa4c6a85b501e5b3e6 100644 (file)
@@ -53,7 +53,8 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
         m_audioThumbCreated(false),
         m_id(id),
         m_placeHolder(xml.hasAttribute("placeholder")),
-        m_properties()
+        m_properties(),
+        m_abortProxy(false)
 {
     int type = xml.attribute("type").toInt();
     m_clipType = (CLIPTYPE) type;
@@ -1106,10 +1107,39 @@ void DocClipBase::generateProxy(KUrl proxyFolder)
 
 void DocClipBase::slotGenerateProxy(QStringList parameters)
 {
-    int result = QProcess::execute("ffmpeg", parameters);
+    QProcess myProcess;
+    myProcess.start("ffmpeg", parameters);
+    myProcess.waitForStarted();
+    int result = -1;
+    while (myProcess.state() != QProcess::NotRunning) {
+        // building proxy file
+        if (m_abortProxy) {
+            QString path = getProperty("proxy");
+            myProcess.close();
+            myProcess.waitForFinished();
+            QFile::remove(path);
+            m_abortProxy = false;
+            result = 1;
+        }
+        myProcess.waitForFinished(500);
+    }
+    myProcess.waitForFinished();
+    if (result == -1) result = myProcess.exitStatus();
     if (result == 0) emit proxyReady(m_id, true);
     else {
-        resetProducerProperty("proxy");
+        clearProperty("proxy");
+        emit proxyReady(m_id, false);
+    }
+}
+
+void DocClipBase::abortProxy()
+{
+    if (m_proxyThread.isRunning()) {
+        // Proxy is being created, abort
+        m_abortProxy = true;
+    }
+    else {
+        clearProperty("proxy");
         emit proxyReady(m_id, false);
     }
 }
index a17d554f1ba45f8286aa74d8a33fd115a9e853c5..eea1e33df660492600b580fd2567d69ea7bf6cc4 100644 (file)
@@ -206,6 +206,8 @@ Q_OBJECT public:
     void setPlaceHolder(bool place);
     /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */
     void generateProxy(KUrl proxyFolder);
+    /** @brief Abort creation of the proxy clip (lower resolution copy). */
+    void abortProxy();
 
 private:   // Private attributes
 
@@ -235,14 +237,16 @@ private:   // Private attributes
     bool m_placeHolder;
 
     QList <CutZoneInfo> m_cutZones;
-    
-    QFuture<void> m_proxyThread;
 
     void setAudioThumbCreated(bool isDone);
     /** Holds clip infos like fps, size,... */
     QMap <QString, QString> m_properties;
     /** Holds clip metadata like author, copyright,... */
     QMap <QString, QString> m_metadata;
+
+    QFuture<void> m_proxyThread;
+    /** Used to kill the proxy thread */
+    bool m_abortProxy;
     /** Create connections for audio thumbnails */
     void slotCreateAudioTimer();
     void slotRefreshProducer();
index 731c5a69bd359d1c5a9b4b9ad9e926e146676570..9de4b8e814f0170019b87e9e5b26209d2d62138f 100644 (file)
@@ -241,10 +241,19 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
 
 void ProjectItem::setProxyStatus(int status)
 {
+    if (status == data(0, ProxyRole).toInt()) return;
     setData(0, ProxyRole, status);
+    if (m_clip && status == 0) m_clip->abortProxy();
 }
 
 bool ProjectItem::hasProxy() const
 {
-    return data(0, ProxyRole).toInt() == 2;
+    if (m_clip == NULL) return false;
+    return !m_clip->getProperty("proxy").isEmpty();
 }
+
+bool ProjectItem::isProxyRunning() const
+{
+     return (data(0, ProxyRole).toInt() == 1);
+}
+
index 536c34037ca7fbdf0203af5d1dff67c69c746251..3e50a07d5a05729f1c8ea5157b7a11469f575e21 100644 (file)
@@ -65,8 +65,10 @@ public:
     void slotSetToolTip();
     /** \brief Set the status of proxy clip creation. 0 = no proxy, 1 = creating proxy, 2 = proxy created. */
     void setProxyStatus(int status);
-    /** \brief Returns the proxy status for this clip (true means there is a proxy clip. */
+    /** \brief Returns the proxy status for this clip (true means there is a proxy clip). */
     bool hasProxy() const;
+    /** \brief Returns true if we are currently creating the proxy for this clip. */
+    bool isProxyRunning() const;
 
     virtual bool operator<(const QTreeWidgetItem &other)const {
         int column = treeWidget()->sortColumn();
index cd1c8d83b6c8e851e4266d529d293a19bf122145..e44fbc1a1839b8fe088f4b74d8181e52d52c68f9 100644 (file)
@@ -2054,11 +2054,14 @@ void ProjectList::slotProxyCurrentItem(bool doProxy)
                 }
                 else if (!item->referencedClip()->getProperty("proxy").isEmpty()) {
                     // remove proxy
-                    item->referencedClip()->clearProperty("proxy");
-                    QDomElement e = item->toXml().cloneNode().toElement();
-                    e.removeAttribute("file_hash");
-                    e.setAttribute("replace", 1);
-                    m_infoQueue.insert(item->clipId(), e);
+                    if (!item->isProxyRunning()) {
+                        setProxyStatus(item, 0);
+                        QDomElement e = item->toXml().cloneNode().toElement();
+                        e.removeAttribute("file_hash");
+                        e.setAttribute("replace", 1);
+                        m_infoQueue.insert(item->clipId(), e);
+                    }
+                    else setProxyStatus(item, 0);
                 }
             }
         }