QTfrontend/ui/page/pagevideos.cpp
changeset 7392 bc3306c59a08
parent 7386 e82a076df09b
child 7447 01111960a48d
--- a/QTfrontend/ui/page/pagevideos.cpp	Fri Jul 13 16:35:42 2012 +0400
+++ b/QTfrontend/ui/page/pagevideos.cpp	Fri Jul 13 16:39:20 2012 +0400
@@ -301,13 +301,7 @@
     connect(btnPlay,   SIGNAL(clicked()), this, SLOT(playSelectedFile()));
     connect(btnDelete, SIGNAL(clicked()), this, SLOT(deleteSelectedFiles()));
     connect(btnOpenDir, SIGNAL(clicked()), this, SLOT(openVideosDirectory()));
-
-    QString path = cfgdir->absolutePath() + "/Videos";
-    QFileSystemWatcher * pWatcher = new QFileSystemWatcher(this);
-    pWatcher->addPath(path);
-    connect(pWatcher, SIGNAL(directoryChanged(const QString &)), this, SLOT(updateFileList(const QString &)));
-    updateFileList(path);
-}
+ }
 
 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
     config(0)
@@ -317,6 +311,19 @@
     initPage();
 }
 
+void PageVideos::init(GameUIConfig * config)
+{
+    this->config = config;
+
+    QString path = cfgdir->absolutePath() + "/Videos";
+    QFileSystemWatcher * pWatcher = new QFileSystemWatcher(this);
+    pWatcher->addPath(path);
+    connect(pWatcher, SIGNAL(directoryChanged(const QString &)), this, SLOT(updateFileList(const QString &)));
+    updateFileList(path);
+
+    startEncoding(); // this is for videos recorded from demos which were executed directly (without frontend)
+}
+
 // user changed file format, we need to update list of codecs
 void PageVideos::changeAVFormat(int index)
 {
@@ -844,3 +851,32 @@
     }
     return list;
 }
+
+void PageVideos::startEncoding(const QByteArray & record)
+{
+    QDir videoTempDir(cfgdir->absolutePath() + "/VideoTemp/");
+    QStringList files = videoTempDir.entryList(QStringList("*.txtout"), QDir::Files);
+    foreach (const QString & str, files)
+    {
+        QString prefix = str;
+        prefix.chop(7); // remove ".txtout"
+        videoTempDir.rename(prefix + ".txtout", prefix + ".txtin"); // rename this file to not open it twice
+
+        HWRecorder* pRecorder = new HWRecorder(config, prefix);
+
+        if (!record.isEmpty())
+            pRecorder->EncodeVideo(record);
+        else
+        {
+            // this is for videos recorded from demos which were executed directly (without frontend)
+            QFile demofile(videoTempDir.absoluteFilePath(prefix + ".hwd"));
+            if (!demofile.open(QIODevice::ReadOnly))
+                continue;
+            QByteArray demo = demofile.readAll();
+            if (demo.isEmpty())
+                continue;
+            pRecorder->EncodeVideo(demo);
+        }
+        addRecorder(pRecorder);
+    }
+}