]> git.sesse.net Git - kdenlive/commitdiff
Display proxy creation progress in project tree
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 13 Oct 2011 00:30:36 +0000 (00:30 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Thu, 13 Oct 2011 00:30:36 +0000 (00:30 +0000)
svn path=/trunk/kdenlive/; revision=5957

src/definitions.h
src/projectitem.cpp
src/projectitem.h
src/projectlist.cpp
src/projectlist.h

index 7bedcd26fcc6921500e893cb9140b42cb2528800..8f52d01b73b7c874720bd774e3a8a585bab06b70 100644 (file)
@@ -57,7 +57,7 @@ enum MessageType {
 
 enum TRACKTYPE { AUDIOTRACK = 0, VIDEOTRACK = 1 };
 
-enum PROXYSTATUS { NOPROXY = 0, PROXYWAITING = 1, CREATINGPROXY = 2, PROXYDONE = 3, PROXYCRASHED = 4};
+enum PROXYSTATUS { NOPROXY = 0, PROXYWAITING = -1, CREATINGPROXY = -2, PROXYDONE = -3, PROXYCRASHED = -4};
 
 struct TrackInfo {
     TRACKTYPE type;
index 4f6ab88a7e14d68ed2d41135e2f7e575dbdd6dc2..e7b942b30a9be9f37bc59c9b52569d8d4a6e13a4 100644 (file)
@@ -253,9 +253,10 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
     }
 }
 
-void ProjectItem::setProxyStatus(PROXYSTATUS status)
+void ProjectItem::setProxyStatus(PROXYSTATUS status, int progress)
 {
-    setData(0, ProxyRole, status);
+    if (progress > 0) setData(0, ProxyRole, progress);
+    else setData(0, ProxyRole, status);
 }
 
 bool ProjectItem::hasProxy() const
index 3015acf6b94e50a8cccb0884663f9a5db79254d8..64f009209f1776eea03af2575e674e2bc034ccda 100644 (file)
@@ -64,7 +64,7 @@ public:
     static int itemDefaultHeight();
     void slotSetToolTip();
     /** \brief Set the status of proxy clip creation. 0 = no proxy, 1 = creating proxy, 2 = proxy created. */
-    void setProxyStatus(PROXYSTATUS status);
+    void setProxyStatus(PROXYSTATUS status, int progress = 0);
     /** \brief Returns the proxy status for this clip (true means there is a proxy clip). */
     bool hasProxy() const;
     /** \brief Returns true if the proxy for this clip is ready. */
index 08935c338cba790877d26614577efb92d1b7b682..3c972d20402ba52fd81d9a4c1f5848513bfffd08 100644 (file)
@@ -2277,6 +2277,7 @@ void ProjectList::slotGenerateProxy()
         myProcess.start(KdenliveSettings::rendererpath(), parameters);
         myProcess.waitForStarted();
         int result = -1;
+        int duration = 0;
         while (myProcess.state() != QProcess::NotRunning) {
             // building proxy file
             if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
@@ -2287,7 +2288,11 @@ void ProjectList::slotGenerateProxy()
                 m_processingProxy.removeAll(info.dest);
                 setProxyStatus(info.dest, NOPROXY);
                 result = -2;
-
+            }
+            else {
+                QString log = QString(myProcess.readAllStandardOutput());
+                log.append(QString(myProcess.readAllStandardError()));
+                processLogInfo(info.dest, &duration, log);
             }
             myProcess.waitForFinished(500);
         }
@@ -2375,6 +2380,7 @@ void ProjectList::slotGenerateProxy()
     myProcess.start("ffmpeg", parameters);
     myProcess.waitForStarted();
     int result = -1;
+    int duration = 0;
     while (myProcess.state() != QProcess::NotRunning) {
         // building proxy file
         if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
@@ -2387,6 +2393,11 @@ void ProjectList::slotGenerateProxy()
             result = -2;
             
         }
+        else {
+            QString log = QString(myProcess.readAllStandardOutput());
+            log.append(QString(myProcess.readAllStandardError()));
+            processLogInfo(info.dest, &duration, log);
+        }
         myProcess.waitForFinished(500);
     }
     myProcess.waitForFinished();
@@ -2405,6 +2416,28 @@ void ProjectList::slotGenerateProxy()
     m_processingProxy.removeAll(info.dest);
 }
 
+
+void ProjectList::processLogInfo(const QString &path, int *duration, const QString &log)
+{
+    int progress;
+    if (*duration == 0) {
+        if (log.contains("Duration:")) {
+            QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
+            QStringList numbers = data.split(':');
+            *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
+        }
+    }
+    else if (log.contains("time=")) {
+        QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
+        if (time.contains(':')) {
+            QStringList numbers = time.split(':');
+            progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
+        }
+        else progress = (int) time.toDouble();
+        setProxyStatus(path, CREATINGPROXY, (int) (100.0 * progress / (*duration)));
+    }
+}
+
 void ProjectList::updateProxyConfig()
 {
     ProjectItem *item;
@@ -2554,7 +2587,7 @@ void ProjectList::slotDeleteProxy(const QString proxyPath)
     QFile::remove(proxyPath);
 }
 
-void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status)
+void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress)
 {
     if (proxyPath.isEmpty() || m_abortAllProxies) return;
     QTreeWidgetItemIterator it(m_listView);
@@ -2563,18 +2596,18 @@ void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status)
         if ((*it)->type() == PROJECTCLIPTYPE) {
             item = static_cast <ProjectItem *>(*it);
             if (item->referencedClip()->getProperty("proxy") == proxyPath) {
-                setProxyStatus(item, status);
+                setProxyStatus(item, status, progress);
             }
         }
         ++it;
     }
 }
 
-void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status)
+void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
 {
     if (item == NULL) return;
     monitorItemEditing(false);
-    item->setProxyStatus(status);
+    item->setProxyStatus(status, progress);
     monitorItemEditing(true);
 }
 
index 4b4ba236ac3d687a119dbefefe7d8097a231520d..575e14238a59c44171888f7e6152a24b51ebd860 100644 (file)
@@ -113,12 +113,19 @@ public:
             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
             
             int proxy = index.data(Qt::UserRole + 5).toInt();
-            if (proxy > 0) {
+            if (proxy != 0) {
                 QRectF txtBounding;
                 QString proxyText;
                 QBrush brush;
                 QColor color;
-                if (proxy == PROXYDONE) {
+                if (proxy > 0) {
+                    proxyText = QString::number(proxy) + "% ";
+                    proxyText.append(i18n("Generating proxy ..."));
+                    brush = option.palette.highlight();
+                    color = option.palette.color(QPalette::HighlightedText);
+                    
+                }
+                else if (proxy == PROXYDONE) {
                     proxyText = i18n("Proxy");
                     brush = option.palette.mid();
                     color = option.palette.color(QPalette::WindowText);
@@ -307,9 +314,10 @@ private:
     /** @brief Set the Proxy status on a clip. 
      * @param item The clip item to set status
      * @param status The proxy status (see definitions.h) */
-    void setProxyStatus(const QString proxyPath, PROXYSTATUS status);
-    void setProxyStatus(ProjectItem *item, PROXYSTATUS status);
-
+    void setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress = 0);
+    void setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress = 0);
+    /** @brief Process ffmpeg output to find out process progress. */
+    void processLogInfo(const QString &path, int *duration, const QString &log);
     void monitorItemEditing(bool enable);
 
 private slots: