From: Jean-Baptiste Mardelle Date: Thu, 13 Oct 2011 00:30:36 +0000 (+0000) Subject: Display proxy creation progress in project tree X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=ebccca909041f8086a443e5691f5a84cb7b4be28;p=kdenlive Display proxy creation progress in project tree svn path=/trunk/kdenlive/; revision=5957 --- diff --git a/src/definitions.h b/src/definitions.h index 7bedcd26..8f52d01b 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -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; diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 4f6ab88a..e7b942b3 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -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 diff --git a/src/projectitem.h b/src/projectitem.h index 3015acf6..64f00920 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -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. */ diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 08935c33..3c972d20 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -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 (*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); } diff --git a/src/projectlist.h b/src/projectlist.h index 4b4ba236..575e1423 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -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: