+void ProjectList::slotCreateProxy(const QString id)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item || item->isProxyRunning()) return;
+ setProxyStatus(id, PROXYWAITING);
+ if (m_abortProxyId.contains(id)) m_abortProxyId.removeAll(id);
+ QtConcurrent::run(this, &ProjectList::slotGenerateProxy, id);
+}
+
+void ProjectList::slotAbortProxy(const QString id)
+{
+ if (m_proxyList.contains(id)) m_proxyList.removeAll(id);
+ ProjectItem *item = getItemById(id);
+ if (item) {
+ if (item->isProxyReady()) slotGotProxy(id);
+ else if (item->isProxyRunning()) m_abortProxyId << id;
+ setProxyStatus(id, NOPROXY);
+ }
+}
+
+void ProjectList::slotGenerateProxy(const QString id)
+{
+ setProxyStatus(id, CREATINGPROXY);
+ ProjectItem *item = getItemById(id);
+ if (item == NULL) return;
+ QString path = item->referencedClip()->getProperty("proxy");
+ if (path.isEmpty()) {
+ setProxyStatus(id, PROXYCRASHED);
+ return;
+ }
+
+ QString url = item->clipUrl().path();
+
+ if (QFile::exists(path)) {
+ setProxyStatus(id, PROXYDONE);
+ slotGotProxy(id);
+ return;
+ }
+ else {
+ // Make sure proxy path is writable
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ setProxyStatus(id, PROXYCRASHED);
+ return;
+ }
+ file.close();
+ QFile::remove(path);
+ }
+
+ QStringList parameters;
+ parameters << "-i" << url;
+ QString params = proxyParams();
+ foreach(QString s, params.split(' '))
+ parameters << s;
+
+ // Make sure we don't block when proxy file already exists
+ parameters << "-y";
+ parameters << path;
+ QProcess myProcess;
+ myProcess.start("ffmpeg", parameters);
+ myProcess.waitForStarted();
+ int result = -1;
+ while (myProcess.state() != QProcess::NotRunning) {
+ // building proxy file
+ if (m_abortProxyId.contains(id)) {
+ myProcess.close();
+ myProcess.waitForFinished();
+ m_abortProxyId.removeAll(id);
+ QFile::remove(path);
+ setProxyStatus(id, NOPROXY);
+ result = -2;
+
+ }
+ myProcess.waitForFinished(500);
+ }
+ myProcess.waitForFinished();
+ if (result == -1) result = myProcess.exitStatus();
+ if (result == 0) {
+ // proxy successfully created
+ setProxyStatus(id, PROXYDONE);
+ slotGotProxy(id);
+ }
+ else if (result == 1) {
+ // Proxy process crashed
+ QFile::remove(path);
+ setProxyStatus(id, PROXYCRASHED);
+ }
+}
+