QTfrontend/ui/page/pagevideos.cpp
branchphysfslayer
changeset 7928 88fde28bbda6
parent 7897 5e7c0810f365
child 8151 25b95d6224fc
child 8185 1c3739ba4352
equal deleted inserted replaced
7778:3331b30e4ef1 7928:88fde28bbda6
    45 #include <QXmlStreamReader>
    45 #include <QXmlStreamReader>
    46 
    46 
    47 #include "hwconsts.h"
    47 #include "hwconsts.h"
    48 #include "pagevideos.h"
    48 #include "pagevideos.h"
    49 #include "igbox.h"
    49 #include "igbox.h"
    50 #include "libav_iteraction.h"
    50 #include "LibavInteraction.h"
    51 #include "gameuiconfig.h"
    51 #include "gameuiconfig.h"
    52 #include "recorder.h"
    52 #include "recorder.h"
    53 #include "ask_quit.h"
    53 #include "ask_quit.h"
    54 #include "upload_video.h"
    54 #include "upload_video.h"
    55 
    55 
    90         QString path()
    90         QString path()
    91         { return cfgdir->absoluteFilePath("Videos/" + name);  }
    91         { return cfgdir->absoluteFilePath("Videos/" + name);  }
    92 };
    92 };
    93 
    93 
    94 VideoItem::VideoItem(const QString& name)
    94 VideoItem::VideoItem(const QString& name)
    95     : QTableWidgetItem(name, UserType)
    95 : QTableWidgetItem(name, UserType)
    96 {
    96 {
    97     this->name = name;
    97     this->name = name;
    98     pRecorder = NULL;
    98     pRecorder = NULL;
    99     pUploading = NULL;
    99     pUploading = NULL;
   100     lastSizeUpdate = 0;
   100     lastSizeUpdate = 0;
   126         pOptLayout->addWidget(labelFormat, 0, 0);
   126         pOptLayout->addWidget(labelFormat, 0, 0);
   127 
   127 
   128         // list of supported formats
   128         // list of supported formats
   129         comboAVFormats = new QComboBox(pOptionsGroup);
   129         comboAVFormats = new QComboBox(pOptionsGroup);
   130         pOptLayout->addWidget(comboAVFormats, 0, 1, 1, 4);
   130         pOptLayout->addWidget(comboAVFormats, 0, 1, 1, 4);
   131         LibavIteraction::instance().fillFormats(comboAVFormats);
   131         LibavInteraction::instance().fillFormats(comboAVFormats);
   132 
   132 
   133         // separator
   133         // separator
   134         QFrame * hr = new QFrame(pOptionsGroup);
   134         QFrame * hr = new QFrame(pOptionsGroup);
   135         hr->setFrameStyle(QFrame::HLine);
   135         hr->setFrameStyle(QFrame::HLine);
   136         hr->setLineWidth(3);
   136         hr->setLineWidth(3);
   215         pOptLayout->addWidget(bitrateBox, 6, 3);
   215         pOptLayout->addWidget(bitrateBox, 6, 3);
   216 
   216 
   217         // button 'set default options'
   217         // button 'set default options'
   218         btnDefaults = new QPushButton(pOptionsGroup);
   218         btnDefaults = new QPushButton(pOptionsGroup);
   219         btnDefaults->setText(QPushButton::tr("Set default options"));
   219         btnDefaults->setText(QPushButton::tr("Set default options"));
       
   220         btnDefaults->setWhatsThis(QPushButton::tr("Restore default coding parameters"));
   220         pOptLayout->addWidget(btnDefaults, 7, 0, 1, 5);
   221         pOptLayout->addWidget(btnDefaults, 7, 0, 1, 5);
   221 
   222 
   222         pPageLayout->addWidget(pOptionsGroup, 1, 0);
   223         pPageLayout->addWidget(pOptionsGroup, 1, 0);
   223     }
   224     }
   224 
   225 
   248         header->setResizeMode(vcSize, QHeaderView::Fixed);
   249         header->setResizeMode(vcSize, QHeaderView::Fixed);
   249         header->resizeSection(vcSize, 100);
   250         header->resizeSection(vcSize, 100);
   250         header->setStretchLastSection(true);
   251         header->setStretchLastSection(true);
   251 
   252 
   252         btnOpenDir = new QPushButton(QPushButton::tr("Open videos directory"), pTableGroup);
   253         btnOpenDir = new QPushButton(QPushButton::tr("Open videos directory"), pTableGroup);
       
   254         btnOpenDir->setWhatsThis(QPushButton::tr("Open the video directory in your system"));
   253 
   255 
   254         QVBoxLayout *box = new QVBoxLayout(pTableGroup);
   256         QVBoxLayout *box = new QVBoxLayout(pTableGroup);
   255         box->addWidget(filesTable);
   257         box->addWidget(filesTable);
   256         box->addWidget(btnOpenDir);
   258         box->addWidget(btnOpenDir);
   257 
   259 
   294         pTopDescLayout->addWidget(labelDesc, 1);
   296         pTopDescLayout->addWidget(labelDesc, 1);
   295 
   297 
   296         // buttons: play and delete
   298         // buttons: play and delete
   297         btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
   299         btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
   298         btnPlay->setEnabled(false);
   300         btnPlay->setEnabled(false);
       
   301         btnPlay->setWhatsThis(QPushButton::tr("Play this video"));
   299         pBottomDescLayout->addWidget(btnPlay);
   302         pBottomDescLayout->addWidget(btnPlay);
   300         btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
   303         btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
   301         btnDelete->setEnabled(false);
   304         btnDelete->setEnabled(false);
       
   305         btnDelete->setWhatsThis(QPushButton::tr("Delete this video"));
   302         pBottomDescLayout->addWidget(btnDelete);
   306         pBottomDescLayout->addWidget(btnDelete);
   303         btnToYouTube = new QPushButton(QPushButton::tr("Upload to YouTube"), pDescGroup);
   307         btnToYouTube = new QPushButton(QPushButton::tr("Upload to YouTube"), pDescGroup);
   304         btnToYouTube->setEnabled(false);
   308         btnToYouTube->setEnabled(false);
       
   309         btnToYouTube->setWhatsThis(QPushButton::tr("Upload this video to your Youtube account"));
   305         pBottomDescLayout->addWidget(btnToYouTube);
   310         pBottomDescLayout->addWidget(btnToYouTube);
   306 
   311 
   307         pDescLayout->addStretch(1);
   312         pDescLayout->addStretch(1);
   308         pDescLayout->addLayout(pTopDescLayout, 0);
   313         pDescLayout->addLayout(pTopDescLayout, 0);
   309         pDescLayout->addStretch(1);
   314         pDescLayout->addStretch(1);
   367     // clear lists of codecs
   372     // clear lists of codecs
   368     comboVideoCodecs->clear();
   373     comboVideoCodecs->clear();
   369     comboAudioCodecs->clear();
   374     comboAudioCodecs->clear();
   370 
   375 
   371     // get list of codecs for specified format
   376     // get list of codecs for specified format
   372     LibavIteraction::instance().fillCodecs(comboAVFormats->itemData(index).toString(), comboVideoCodecs, comboAudioCodecs);
   377     LibavInteraction::instance().fillCodecs(comboAVFormats->itemData(index).toString(), comboVideoCodecs, comboAudioCodecs);
   373 
   378 
   374     // disable audio if there is no audio codec
   379     // disable audio if there is no audio codec
   375     if (comboAudioCodecs->count() == 0)
   380     if (comboAudioCodecs->count() == 0)
   376     {
   381     {
   377         checkRecordAudio->setChecked(false);
   382         checkRecordAudio->setChecked(false);
   409     comboAudioCodecs->setEnabled(!!state);
   414     comboAudioCodecs->setEnabled(!!state);
   410 }
   415 }
   411 
   416 
   412 void PageVideos::setDefaultCodecs()
   417 void PageVideos::setDefaultCodecs()
   413 {
   418 {
       
   419     // VLC should be able to handle any of these configurations
       
   420     // Quicktime X only opens the first one
       
   421     // Windows Media Player TODO
       
   422     if (tryCodecs("mp4", "libx264", "aac"))
       
   423         return;
       
   424     if (tryCodecs("mp4", "libx264", "libfaac"))
       
   425         return;
   414     if (tryCodecs("mp4", "libx264", "libmp3lame"))
   426     if (tryCodecs("mp4", "libx264", "libmp3lame"))
   415         return;
       
   416     if (tryCodecs("mp4", "libx264", "libfaac"))
       
   417         return;
       
   418     if (tryCodecs("mp4", "libx264", "libvo_aacenc"))
       
   419         return;
       
   420     if (tryCodecs("mp4", "libx264", "aac"))
       
   421         return;
   427         return;
   422     if (tryCodecs("mp4", "libx264", "mp2"))
   428     if (tryCodecs("mp4", "libx264", "mp2"))
   423         return;
   429         return;
   424     if (tryCodecs("avi", "libxvid", "libmp3lame"))
   430     if (tryCodecs("avi", "libxvid", "libmp3lame"))
   425         return;
   431         return;
   440     tryCodecs("ogg", "libtheora", "flac");
   446     tryCodecs("ogg", "libtheora", "flac");
   441 }
   447 }
   442 
   448 
   443 void PageVideos::setDefaultOptions()
   449 void PageVideos::setDefaultOptions()
   444 {
   450 {
   445     framerateBox->setValue(25);
   451     framerateBox->setValue(30);
   446     bitrateBox->setValue(400);
   452     bitrateBox->setValue(1000);
   447     checkRecordAudio->setChecked(true);
   453     checkRecordAudio->setChecked(true);
   448     checkUseGameRes->setChecked(true);
   454     checkUseGameRes->setChecked(true);
   449     setDefaultCodecs();
   455     setDefaultCodecs();
   450 }
   456 }
   451 
   457 
   643             setName(item, newName);
   649             setName(item, newName);
   644         }
   650         }
   645     }
   651     }
   646 #ifdef Q_WS_WIN
   652 #ifdef Q_WS_WIN
   647     // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
   653     // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
   648     if (newName.contains(QRegExp("[\"*:<>?\/|]")))
   654     if (newName.contains(QRegExp("[\"*:<>?\\/|]")))
   649     {
   655     {
   650         setName(item, oldName);
   656         setName(item, oldName);
   651         return;
   657         return;
   652     }
   658     }
   653 #endif
   659 #endif
   741         desc += tr("Size: ") + FileSizeStr(path) + '\n';
   747         desc += tr("Size: ") + FileSizeStr(path) + '\n';
   742         if (item->desc.isEmpty())
   748         if (item->desc.isEmpty())
   743         {
   749         {
   744             // Extract description from file;
   750             // Extract description from file;
   745             // It will contain duration, resolution, etc and also comment added by hwengine.
   751             // It will contain duration, resolution, etc and also comment added by hwengine.
   746             item->desc = LibavIteraction::instance().getFileInfo(path);
   752             item->desc = LibavInteraction::instance().getFileInfo(path);
   747 
   753 
   748             // extract prefix (original name) from description (it is enclosed in prefix[???]prefix)
   754             // extract prefix (original name) from description (it is enclosed in prefix[???]prefix)
   749             int prefixBegin = item->desc.indexOf("prefix[");
   755             int prefixBegin = item->desc.indexOf("prefix[");
   750             int prefixEnd   = item->desc.indexOf("]prefix");
   756             int prefixEnd   = item->desc.indexOf("]prefix");
   751             if (prefixBegin != -1 && prefixEnd != -1)
   757             if (prefixBegin != -1 && prefixEnd != -1)
   837     VideoItem * item = nameItem(index);
   843     VideoItem * item = nameItem(index);
   838     if (!item)
   844     if (!item)
   839         return;
   845         return;
   840 
   846 
   841     // ask user if (s)he is serious
   847     // ask user if (s)he is serious
   842     if (QMessageBox::question(this,
   848     QMessageBox reallyDeleteMsg(this);
   843                               tr("Are you sure?"),
   849     reallyDeleteMsg.setIcon(QMessageBox::Question);
   844                               tr("Do you really want do remove %1?").arg(item->name),
   850     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Videos - Are you sure?"));
   845                               QMessageBox::Yes | QMessageBox::No)
   851     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the video '%1'?").arg(item->name));
   846             != QMessageBox::Yes)
   852     reallyDeleteMsg.setWindowModality(Qt::WindowModal);
       
   853     reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
       
   854 
       
   855     if (reallyDeleteMsg.exec() != QMessageBox::Ok)
   847         return;
   856         return;
   848 
   857 
   849     // remove
   858     // remove
   850     if (!item->ready())
   859     if (!item->ready())
   851         item->pRecorder->deleteLater();
   860         item->pRecorder->deleteLater();
   852     else
   861     else
       
   862     {
   853         cfgdir->remove("Videos/" + item->name);
   863         cfgdir->remove("Videos/" + item->name);
       
   864         // we have no idea whether screenshot is going to be bmp or png so let's delete both
       
   865         cfgdir->remove("VideoTemp/" + item->prefix + ".png");
       
   866         cfgdir->remove("VideoTemp/" + item->prefix + ".bmp");
       
   867     }
   854 
   868 
   855 // this code is for removing several files when multiple selection is enabled
   869 // this code is for removing several files when multiple selection is enabled
   856 #if 0
   870 #if 0
   857     QList<QTableWidgetItem*> items = filesTable->selectedItems();
   871     QList<QTableWidgetItem*> items = filesTable->selectedItems();
   858     int num = items.size() / vcNumColumns;
   872     int num = items.size() / vcNumColumns;
   859     if (num == 0)
   873     if (num == 0)
   860         return;
   874         return;
   861 
   875 
   862     // ask user if (s)he is serious
   876     // ask user if (s)he is serious
   863     if (QMessageBox::question(this,
   877     QMessageBox reallyDeleteMsg(this);
   864                               tr("Are you sure?"),
   878     reallyDeleteMsg.setIcon(QMessageBox::Question);
   865                               tr("Do you really want do remove %1 file(s)?", "", num).arg(num),
   879     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Videos - Are you sure?"));
   866                               QMessageBox::Yes | QMessageBox::No)
   880     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to remove %1 file(s)?", "", num).arg(num));
   867             != QMessageBox::Yes)
   881     reallyDeleteMsg.setWindowModality(Qt::WindowModal);
       
   882     reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
       
   883 
       
   884     if (reallyDeleteMsg.exec() != QMessageBox::Ok)
   868         return;
   885         return;
   869 
   886 
   870     // remove
   887     // remove
   871     foreach (QTableWidgetItem * witem, items)
   888     foreach (QTableWidgetItem * witem, items)
   872     {
   889     {
  1079     int row = filesTable->currentRow();
  1096     int row = filesTable->currentRow();
  1080     VideoItem * item = nameItem(row);
  1097     VideoItem * item = nameItem(row);
  1081 
  1098 
  1082     if (item->pUploading)
  1099     if (item->pUploading)
  1083     {
  1100     {
  1084         if (QMessageBox::question(this,
  1101         // ask user if (s)he is serious
  1085                                   tr("Are you sure?"),
  1102         QMessageBox reallyStopMsg(this);
  1086                                   tr("Do you really want do cancel uploading %1?").arg(item->name),
  1103         reallyStopMsg.setIcon(QMessageBox::Question);
  1087                                   QMessageBox::Yes | QMessageBox::No)
  1104         reallyStopMsg.setWindowTitle(QMessageBox::tr("Videos - Are you sure?"));
  1088                 != QMessageBox::Yes)
  1105         reallyStopMsg.setText(QMessageBox::tr("Do you really want to cancel uploading %1?").arg(item->name));
       
  1106         reallyStopMsg.setWindowModality(Qt::WindowModal);
       
  1107         reallyStopMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
       
  1108 
       
  1109         if (reallyStopMsg.exec() != QMessageBox::Ok)
  1089             return;
  1110             return;
  1090         item->pUploading->deleteLater();
  1111         item->pUploading->deleteLater();
  1091         filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
  1112         filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
  1092         numUploads--;
  1113         numUploads--;
  1093         return;
  1114         return;