QTfrontend/ui/page/pagevideos.cpp
changeset 7353 0e55228e1303
parent 7306 3cff5c769509
child 7386 e82a076df09b
equal deleted inserted replaced
7350:1dbf3f4340e0 7353:0e55228e1303
    42 #include "pagevideos.h"
    42 #include "pagevideos.h"
    43 #include "igbox.h"
    43 #include "igbox.h"
    44 #include "libav_iteraction.h"
    44 #include "libav_iteraction.h"
    45 #include "gameuiconfig.h"
    45 #include "gameuiconfig.h"
    46 #include "recorder.h"
    46 #include "recorder.h"
       
    47 #include "ask_quit.h"
    47 
    48 
    48 const int ThumbnailSize = 400;
    49 const int ThumbnailSize = 400;
    49 
    50 
    50 // columns in table with list of video files
    51 // columns in table with list of video files
    51 enum VideosColumns
    52 enum VideosColumns
    68         QString name;
    69         QString name;
    69         QString desc; // description
    70         QString desc; // description
    70         HWRecorder * pRecorder; // non NULL if file is being encoded
    71         HWRecorder * pRecorder; // non NULL if file is being encoded
    71         bool seen; // used when updating directory
    72         bool seen; // used when updating directory
    72         float lastSizeUpdate;
    73         float lastSizeUpdate;
       
    74         float progress;
    73 
    75 
    74         bool ready()
    76         bool ready()
    75         { return !pRecorder; }
    77         { return !pRecorder; }
    76 
    78 
    77         QString path()
    79         QString path()
    82     : QTableWidgetItem(name, UserType)
    84     : QTableWidgetItem(name, UserType)
    83 {
    85 {
    84     this->name = name;
    86     this->name = name;
    85     pRecorder = NULL;
    87     pRecorder = NULL;
    86     lastSizeUpdate = 0;
    88     lastSizeUpdate = 0;
       
    89     progress = 0;
    87 }
    90 }
    88 
    91 
    89 VideoItem::~VideoItem()
    92 VideoItem::~VideoItem()
    90 {}
    93 {}
    91 
    94 
   298 
   301 
   299 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
   302 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
   300     config(0)
   303     config(0)
   301 {
   304 {
   302     nameChangedFromCode = false;
   305     nameChangedFromCode = false;
       
   306     numRecorders = 0;
   303     initPage();
   307     initPage();
   304 }
   308 }
   305 
   309 
   306 // user changed file format, we need to update list of codecs
   310 // user changed file format, we need to update list of codecs
   307 void PageVideos::changeAVFormat(int index)
   311 void PageVideos::changeAVFormat(int index)
   494     progressBar->setMaximum(10000);
   498     progressBar->setMaximum(10000);
   495     progressBar->setValue(0);
   499     progressBar->setValue(0);
   496     connect(pRecorder, SIGNAL(onProgress(float)), this, SLOT(updateProgress(float)));
   500     connect(pRecorder, SIGNAL(onProgress(float)), this, SLOT(updateProgress(float)));
   497     connect(pRecorder, SIGNAL(encodingFinished(bool)), this, SLOT(encodingFinished(bool)));
   501     connect(pRecorder, SIGNAL(encodingFinished(bool)), this, SLOT(encodingFinished(bool)));
   498     filesTable->setCellWidget(row, vcProgress, progressBar);
   502     filesTable->setCellWidget(row, vcProgress, progressBar);
       
   503 
       
   504     numRecorders++;
   499 }
   505 }
   500 
   506 
   501 void PageVideos::updateProgress(float value)
   507 void PageVideos::updateProgress(float value)
   502 {
   508 {
   503     HWRecorder * pRecorder = (HWRecorder*)sender();
   509     HWRecorder * pRecorder = (HWRecorder*)sender();
   513 
   519 
   514     // update progress bar
   520     // update progress bar
   515     QProgressBar * progressBar = (QProgressBar*)filesTable->cellWidget(row, vcProgress);
   521     QProgressBar * progressBar = (QProgressBar*)filesTable->cellWidget(row, vcProgress);
   516     progressBar->setValue(value*10000);
   522     progressBar->setValue(value*10000);
   517     progressBar->setFormat(QString("%1%").arg(value*100, 0, 'f', 2));
   523     progressBar->setFormat(QString("%1%").arg(value*100, 0, 'f', 2));
       
   524     item->progress = value;
   518 }
   525 }
   519 
   526 
   520 void PageVideos::encodingFinished(bool success)
   527 void PageVideos::encodingFinished(bool success)
   521 {
   528 {
       
   529     numRecorders--;
       
   530 
   522     HWRecorder * pRecorder = (HWRecorder*)sender();
   531     HWRecorder * pRecorder = (HWRecorder*)sender();
   523     VideoItem * item = (VideoItem*)pRecorder->item;
   532     VideoItem * item = (VideoItem*)pRecorder->item;
   524     int row = filesTable->row(item);
   533     int row = filesTable->row(item);
   525 
   534 
   526     if (success)
   535     if (success)
   581             // unable to rename for some reason (maybe user entered incorrect name),
   590             // unable to rename for some reason (maybe user entered incorrect name),
   582             // therefore restore old name in cell
   591             // therefore restore old name in cell
   583             setName(item, oldName);
   592             setName(item, oldName);
   584         }
   593         }
   585     }
   594     }
       
   595     updateDescription();
   586 }
   596 }
   587 
   597 
   588 void PageVideos::setName(VideoItem * item, const QString & newName)
   598 void PageVideos::setName(VideoItem * item, const QString & newName)
   589 {
   599 {
   590     nameChangedFromCode = true;
   600     nameChangedFromCode = true;
   613 
   623 
   614     // add 'progress' item
   624     // add 'progress' item
   615     item = new QTableWidgetItem();
   625     item = new QTableWidgetItem();
   616     item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
   626     item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
   617     filesTable->setItem(row, vcProgress, item);
   627     filesTable->setItem(row, vcProgress, item);
   618 
       
   619    // filesTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
       
   620 
   628 
   621     return row;
   629     return row;
   622 }
   630 }
   623 
   631 
   624 VideoItem* PageVideos::nameItem(int row)
   632 VideoItem* PageVideos::nameItem(int row)
   761 
   769 
   762 void PageVideos::openVideosDirectory()
   770 void PageVideos::openVideosDirectory()
   763 {
   771 {
   764     QDesktopServices::openUrl(QUrl("file:///"+cfgdir->absolutePath() + "/Videos"));
   772     QDesktopServices::openUrl(QUrl("file:///"+cfgdir->absolutePath() + "/Videos"));
   765 }
   773 }
       
   774 
       
   775 bool PageVideos::tryQuit(HWForm * form)
       
   776 {
       
   777     if (numRecorders == 0)
       
   778         return true;
       
   779 
       
   780     // ask user what to do - abort or wait
       
   781     HWAskQuitDialog * askd = new HWAskQuitDialog(this, form);
       
   782     bool answer = askd->exec();
       
   783     delete askd;
       
   784     return answer;
       
   785 }
       
   786 
       
   787 // returns multi-line string with list of videos in progress
       
   788 QString PageVideos::getVideosInProgress()
       
   789 {
       
   790     QString list = "";
       
   791     int count = filesTable->rowCount();
       
   792     for (int i = 0; i < count; i++)
       
   793     {
       
   794         VideoItem * item = nameItem(i);
       
   795         float progress = 100*item->progress;
       
   796         if (progress > 99.99)
       
   797             progress = 99.99; // displaying 100% may be confusing
       
   798         if (!item->ready())
       
   799             list += item->name + " (" + QString::number(progress, 'f', 2) + "%)\n";
       
   800     }
       
   801     return list;
       
   802 }