When there are videos that are being encoded and user tries to quit display dialog with warning.
authorStepan777 <stepik-777@mail.ru>
Fri, 06 Jul 2012 19:15:44 +0400
changeset 7353 0e55228e1303
parent 7350 1dbf3f4340e0
child 7356 1ae5cf294216
When there are videos that are being encoded and user tries to quit display dialog with warning.
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/dialog/ask_quit.cpp
QTfrontend/ui/dialog/ask_quit.h
QTfrontend/ui/page/pagevideos.cpp
QTfrontend/ui/page/pagevideos.h
QTfrontend/util/libav_iteraction.cpp
project_files/hedgewars.pro
--- a/QTfrontend/hwform.cpp	Fri Jul 06 13:22:33 2012 +0400
+++ b/QTfrontend/hwform.cpp	Fri Jul 06 19:15:44 2012 +0400
@@ -520,6 +520,11 @@
     GoToPage(ID_PAGE_SCHEME);
 }
 
+void HWForm::GoToVideos()
+{
+    GoToPage(ID_PAGE_VIDEOS);
+}
+
 void HWForm::OnPageShown(quint8 id, quint8 lastid)
 {
 #ifdef USE_XFIRE
@@ -717,6 +722,8 @@
     int curid = ui.Pages->currentIndex();
     if (curid == ID_PAGE_MAIN)
     {
+        if (!ui.pageVideos->tryQuit(this))
+            return;
         stopAnim = true;
         exit();
     }
--- a/QTfrontend/hwform.h	Fri Jul 06 13:22:33 2012 +0400
+++ b/QTfrontend/hwform.h	Fri Jul 06 19:15:44 2012 +0400
@@ -67,6 +67,7 @@
         void exit();
         void setButtonDescription(QString desc);
         void backDescription();
+        void GoToVideos();
 
     private slots:
         void GoToSaves();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/dialog/ask_quit.cpp	Fri Jul 06 19:15:44 2012 +0400
@@ -0,0 +1,79 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QTimer>
+
+#include "hwform.h"
+#include "ask_quit.h"
+#include "pagevideos.h"
+
+HWAskQuitDialog::HWAskQuitDialog(QWidget* parent, HWForm * form) : QDialog(parent)
+{
+    this->form = form;
+
+    setWindowTitle(tr("Do yot really want to quit?"));
+
+    QVBoxLayout * layout = new QVBoxLayout(this);
+
+    QLabel * lbLabel = new QLabel(this);
+    lbLabel->setText(QLabel::tr("There are videos that are currently being encoded.\n"
+                                "Exiting now will abort them.\n"
+                                "Do yot really want to quit?"));
+    layout->addWidget(lbLabel);
+
+    lbList = new QLabel(this);
+    layout->addWidget(lbList);
+    updateList();
+
+    QDialogButtonBox* dbbButtons = new QDialogButtonBox(this);
+    QPushButton * pbYes = dbbButtons->addButton(QDialogButtonBox::Yes);
+    QPushButton * pbNo  = dbbButtons->addButton(QDialogButtonBox::No);
+    QPushButton * pbMore = dbbButtons->addButton(QPushButton::tr("More info"), QDialogButtonBox::HelpRole);
+    layout->addWidget(dbbButtons);
+
+    connect(pbYes,  SIGNAL(clicked()), this, SLOT(accept()));
+    connect(pbNo,   SIGNAL(clicked()), this, SLOT(reject()));
+    connect(pbMore, SIGNAL(clicked()), this, SLOT(goToPageVideos()));
+
+    // update list periodically
+    QTimer * timer = new QTimer(this);
+    connect(timer, SIGNAL(timeout()), this, SLOT(updateList()));
+    timer->start(200);
+}
+
+void HWAskQuitDialog::goToPageVideos()
+{
+    reject();
+    form->GoToVideos();
+}
+
+void HWAskQuitDialog::updateList()
+{
+    QString text = form->ui.pageVideos->getVideosInProgress();
+    if (text.isEmpty())
+    {
+        // automatically exit when everything is finished
+        accept();
+        return;
+    }
+    lbList->setText(text);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/dialog/ask_quit.h	Fri Jul 06 19:15:44 2012 +0400
@@ -0,0 +1,45 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef ASK_QUIT_H
+#define ASK_QUIT_H
+
+#include <QDialog>
+
+class QLabel;
+class HWForm;
+class PageVideos;
+
+class HWAskQuitDialog : public QDialog
+{
+        Q_OBJECT
+
+    public:
+        HWAskQuitDialog(QWidget* parent, HWForm *form);
+
+    private slots:
+        void goToPageVideos();
+        void updateList();
+
+    private:
+        HWForm * form;
+        QLabel * lbList;
+};
+
+
+#endif // INPUT_PASSWORD_H
--- a/QTfrontend/ui/page/pagevideos.cpp	Fri Jul 06 13:22:33 2012 +0400
+++ b/QTfrontend/ui/page/pagevideos.cpp	Fri Jul 06 19:15:44 2012 +0400
@@ -44,6 +44,7 @@
 #include "libav_iteraction.h"
 #include "gameuiconfig.h"
 #include "recorder.h"
+#include "ask_quit.h"
 
 const int ThumbnailSize = 400;
 
@@ -70,6 +71,7 @@
         HWRecorder * pRecorder; // non NULL if file is being encoded
         bool seen; // used when updating directory
         float lastSizeUpdate;
+        float progress;
 
         bool ready()
         { return !pRecorder; }
@@ -84,6 +86,7 @@
     this->name = name;
     pRecorder = NULL;
     lastSizeUpdate = 0;
+    progress = 0;
 }
 
 VideoItem::~VideoItem()
@@ -300,6 +303,7 @@
     config(0)
 {
     nameChangedFromCode = false;
+    numRecorders = 0;
     initPage();
 }
 
@@ -496,6 +500,8 @@
     connect(pRecorder, SIGNAL(onProgress(float)), this, SLOT(updateProgress(float)));
     connect(pRecorder, SIGNAL(encodingFinished(bool)), this, SLOT(encodingFinished(bool)));
     filesTable->setCellWidget(row, vcProgress, progressBar);
+
+    numRecorders++;
 }
 
 void PageVideos::updateProgress(float value)
@@ -515,10 +521,13 @@
     QProgressBar * progressBar = (QProgressBar*)filesTable->cellWidget(row, vcProgress);
     progressBar->setValue(value*10000);
     progressBar->setFormat(QString("%1%").arg(value*100, 0, 'f', 2));
+    item->progress = value;
 }
 
 void PageVideos::encodingFinished(bool success)
 {
+    numRecorders--;
+
     HWRecorder * pRecorder = (HWRecorder*)sender();
     VideoItem * item = (VideoItem*)pRecorder->item;
     int row = filesTable->row(item);
@@ -583,6 +592,7 @@
             setName(item, oldName);
         }
     }
+    updateDescription();
 }
 
 void PageVideos::setName(VideoItem * item, const QString & newName)
@@ -616,8 +626,6 @@
     item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
     filesTable->setItem(row, vcProgress, item);
 
-   // filesTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
-
     return row;
 }
 
@@ -763,3 +771,32 @@
 {
     QDesktopServices::openUrl(QUrl("file:///"+cfgdir->absolutePath() + "/Videos"));
 }
+
+bool PageVideos::tryQuit(HWForm * form)
+{
+    if (numRecorders == 0)
+        return true;
+
+    // ask user what to do - abort or wait
+    HWAskQuitDialog * askd = new HWAskQuitDialog(this, form);
+    bool answer = askd->exec();
+    delete askd;
+    return answer;
+}
+
+// returns multi-line string with list of videos in progress
+QString PageVideos::getVideosInProgress()
+{
+    QString list = "";
+    int count = filesTable->rowCount();
+    for (int i = 0; i < count; i++)
+    {
+        VideoItem * item = nameItem(i);
+        float progress = 100*item->progress;
+        if (progress > 99.99)
+            progress = 99.99; // displaying 100% may be confusing
+        if (!item->ready())
+            list += item->name + " (" + QString::number(progress, 'f', 2) + "%)\n";
+    }
+    return list;
+}
--- a/QTfrontend/ui/page/pagevideos.h	Fri Jul 06 13:22:33 2012 +0400
+++ b/QTfrontend/ui/page/pagevideos.h	Fri Jul 06 19:15:44 2012 +0400
@@ -26,6 +26,7 @@
 class GameUIConfig;
 class HWRecorder;
 class VideoItem;
+class HWForm;
 
 class PageVideos : public AbstractPage
 {
@@ -54,6 +55,8 @@
         void setDefaultCodecs();
         bool tryCodecs(const QString & format, const QString & vcodec, const QString & acodec);
         void addRecorder(HWRecorder* pRecorder);
+        bool tryQuit(HWForm *form);
+        QString getVideosInProgress(); // get multi-line string with list of videos in progress
 
     private:
         // virtuals from AbstractPage
@@ -91,6 +94,8 @@
         // (in signal cellChanged)
         bool nameChangedFromCode;
 
+        int numRecorders;
+
     private slots:
         void changeAVFormat(int index);
         void changeUseGameRes(int state);
--- a/QTfrontend/util/libav_iteraction.cpp	Fri Jul 06 13:22:33 2012 +0400
+++ b/QTfrontend/util/libav_iteraction.cpp	Fri Jul 06 19:15:44 2012 +0400
@@ -170,7 +170,7 @@
             codec.isRecomended = true;
 
         // FIXME: remove next line
-        codec.longName += QString(" (%1)").arg(codec.shortName);
+       // codec.longName += QString(" (%1)").arg(codec.shortName);
     }
 
     // get list of all formats
@@ -204,7 +204,7 @@
         format.longName = QString("%1 (*.%2)").arg(pFormat->long_name).arg(ext);
 
         // FIXME: remove next line
-        format.longName += QString(" (%1)").arg(format.shortName);
+       // format.longName += QString(" (%1)").arg(format.shortName);
 
         format.isRecomended = strcmp(pFormat->name, "mp4") == 0 || strcmp(pFormat->name, "avi") == 0;
 
--- a/project_files/hedgewars.pro	Fri Jul 06 13:22:33 2012 +0400
+++ b/project_files/hedgewars.pro	Fri Jul 06 19:15:44 2012 +0400
@@ -107,7 +107,8 @@
     ../QTfrontend/model/GameStyleModel.h \
     ../QTfrontend/util/libav_iteraction.h \
     ../QTfrontend/ui/page/pagevideos.h \
-    ../QTfrontend/net/recorder.h
+    ../QTfrontend/net/recorder.h \
+    ../QTfrontend/ui/dialog/ask_quit.h
 
 SOURCES += ../QTfrontend/model/ammoSchemeModel.cpp \
     ../QTfrontend/model/MapModel.cpp \
@@ -192,7 +193,8 @@
     ../QTfrontend/model/GameStyleModel.cpp \
     ../QTfrontend/util/libav_iteraction.cpp \
     ../QTfrontend/ui/page/pagevideos.cpp \
-    ../QTfrontend/net/recorder.cpp
+    ../QTfrontend/net/recorder.cpp \
+    ../QTfrontend/ui/dialog/ask_quit.cpp
 
 win32 {
     SOURCES += ../QTfrontend/xfire.cpp