QTfrontend/ui/page/pagevideos.cpp
changeset 14892 a414d37278df
parent 14888 ea2a1436cdd3
child 14893 b5a9dd36c7ea
equal deleted inserted replaced
14891:3054b85963ef 14892:a414d37278df
   216 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
   216 PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
   217     config(0)
   217     config(0)
   218 {
   218 {
   219     nameChangedFromCode = false;
   219     nameChangedFromCode = false;
   220     numRecorders = 0;
   220     numRecorders = 0;
       
   221     // Clear VideoTemp at launch in case some garbage remained in here after a crash
       
   222     clearTemp();
   221     initPage();
   223     initPage();
   222 }
   224 }
   223 
   225 
   224 void PageVideos::init(GameUIConfig * config)
   226 void PageVideos::init(GameUIConfig * config)
   225 {
   227 {
   397         return;
   399         return;
   398 
   400 
   399     // user has edited filename, so we should rename the file
   401     // user has edited filename, so we should rename the file
   400     VideoItem * item = nameItem(row);
   402     VideoItem * item = nameItem(row);
   401     QString oldName = item->name;
   403     QString oldName = item->name;
       
   404     int pointPos = oldName.lastIndexOf('.');
       
   405     QString oldPrefix = item->name;
       
   406     oldPrefix.truncate(pointPos);
   402     QString newName = item->text();
   407     QString newName = item->text();
   403     if (!newName.contains('.')) // user forgot an extension
   408     if (!newName.contains('.')) // user forgot an extension
   404     {
   409     {
   405         // restore old extension
   410         // restore old extension
   406         int pt = oldName.lastIndexOf('.');
   411         pointPos = oldName.lastIndexOf('.');
   407         if (pt != -1)
   412         if (pointPos != -1)
   408         {
   413         {
   409             newName += oldName.right(oldName.length() - pt);
   414             newName += oldName.right(oldName.length() - pointPos);
   410             setName(item, newName);
   415             setName(item, newName);
   411         }
   416         }
       
   417     }
       
   418     QString newPrefix;
       
   419     if (newName.contains('.'))
       
   420     {
       
   421         pointPos = newName.lastIndexOf('.');
       
   422         if (pointPos != -1)
       
   423         {
       
   424             newPrefix = newName;
       
   425             newPrefix.truncate(pointPos);
       
   426         }
       
   427     }
       
   428     else
       
   429     {
       
   430         newPrefix = newName;
   412     }
   431     }
   413 #ifdef Q_OS_WIN
   432 #ifdef Q_OS_WIN
   414     // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
   433     // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
   415     if (newName.contains(QRegExp("[\"*:<>?\\/|]")))
   434     if (newName.contains(QRegExp("[\"*:<>?\\/|]")))
   416     {
   435     {
   423         // unable to rename for some reason (maybe user entered incorrect name),
   442         // unable to rename for some reason (maybe user entered incorrect name),
   424         // therefore restore old name in cell
   443         // therefore restore old name in cell
   425         setName(item, oldName);
   444         setName(item, oldName);
   426         return;
   445         return;
   427     }
   446     }
       
   447     if (item->ready())
       
   448     {
       
   449         cfgdir->rename("VideoThumbnails/" + oldPrefix + ".png", "VideoThumbnails/" + newPrefix + ".png");
       
   450         cfgdir->rename("VideoThumbnails/" + oldPrefix + ".bmp", "VideoThumbnails/" + newPrefix + ".bmp");
       
   451     }
   428     item->name = newName;
   452     item->name = newName;
       
   453     item->prefix = newPrefix;
   429     updateDescription();
   454     updateDescription();
   430 }
   455 }
   431 
   456 
   432 void PageVideos::setName(VideoItem * item, const QString & newName)
   457 void PageVideos::setName(VideoItem * item, const QString & newName)
   433 {
   458 {
   537 
   562 
   538     labelDesc->setText(desc);
   563     labelDesc->setText(desc);
   539 
   564 
   540     if (!item->prefix.isEmpty())
   565     if (!item->prefix.isEmpty())
   541     {
   566     {
   542         QString thumbName = cfgdir->absoluteFilePath("VideoTemp/" + item->prefix);
   567         QString thumbName = cfgdir->absoluteFilePath("VideoThumbnails/" + item->prefix);
   543         QPixmap pic;
   568         QPixmap pic;
   544         if (pic.load(thumbName + ".png") || pic.load(thumbName + ".bmp"))
   569         if (pic.load(thumbName + ".png") || pic.load(thumbName + ".bmp"))
   545         {
   570         {
   546             if (pic.height()*ThumbnailSize.width() > pic.width()*ThumbnailSize.height())
   571             if (pic.height()*ThumbnailSize.width() > pic.width()*ThumbnailSize.height())
   547                 pic = pic.scaledToWidth(ThumbnailSize.width());
   572                 pic = pic.scaledToWidth(ThumbnailSize.width());
   602         item->pRecorder->abort();
   627         item->pRecorder->abort();
   603     else
   628     else
   604     {
   629     {
   605         cfgdir->remove("Videos/" + item->name);
   630         cfgdir->remove("Videos/" + item->name);
   606         // we have no idea whether screenshot is going to be bmp or png so let's delete both
   631         // we have no idea whether screenshot is going to be bmp or png so let's delete both
   607         cfgdir->remove("VideoTemp/" + item->prefix + ".png");
   632         cfgdir->remove("VideoThumbnails/" + item->prefix + ".png");
   608         cfgdir->remove("VideoTemp/" + item->prefix + ".bmp");
   633         cfgdir->remove("VideoThumbnails/" + item->prefix + ".bmp");
   609     }
   634     }
   610 
   635 
   611 // this code is for removing several files when multiple selection is enabled
   636 // this code is for removing several files when multiple selection is enabled
   612 #if 0
   637 #if 0
   613     QList<QTableWidgetItem*> items = filesTable->selectedItems();
   638     QList<QTableWidgetItem*> items = filesTable->selectedItems();
   662 {
   687 {
   663     QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Videos");
   688     QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Videos");
   664     QDesktopServices::openUrl(QUrl("file:///" + path));
   689     QDesktopServices::openUrl(QUrl("file:///" + path));
   665 }
   690 }
   666 
   691 
   667 // clear VideoTemp directory (except for thumbnails)
   692 // clear VideoTemp directory
   668 void PageVideos::clearTemp()
   693 void PageVideos::clearTemp()
   669 {
   694 {
       
   695     qDebug("Clearing VideoTemp directory ...");
   670     QDir temp(cfgdir->absolutePath() + "/VideoTemp");
   696     QDir temp(cfgdir->absolutePath() + "/VideoTemp");
   671     QStringList files = temp.entryList(QDir::Files);
   697     QStringList files = temp.entryList(QDir::Files);
   672     foreach (const QString& file, files)
   698     foreach (const QString& file, files)
   673     {
   699     {
   674         if (!file.endsWith(".bmp") && !file.endsWith(".png"))
   700         // Legacy support: Move thumbnails to correct dir
       
   701         if (file.endsWith(".bmp") || file.endsWith(".png"))
       
   702         {
       
   703             qDebug("Moving video thumbnail '%s' to VideoThumbnails directory", qPrintable(file));
       
   704             cfgdir->rename("VideoTemp/" + file, "VideoThumbnails/" + file);
       
   705         }
       
   706         else
   675             temp.remove(file);
   707             temp.remove(file);
   676     }
   708     }
   677 }
   709 }
   678 
   710 
   679 bool PageVideos::tryQuit(HWForm * form)
   711 bool PageVideos::tryQuit(HWForm * form)