QTfrontend/ui/page/pagevideos.cpp
author Wuzzy <Wuzzy2@mail.ru>
Mon, 06 May 2019 01:25:50 +0200
changeset 14909 b5a9dd36c7ea
parent 14908 a414d37278df
child 14963 05cde9ba4183
permissions -rw-r--r--
pagevideos: Prevent renaming video if file name prefix is already used This prevents some issues and weirdnesses with losing the video thumbnail, etc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     1
/*
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10248
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     4
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     8
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    12
 * GNU General Public License for more details.
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    13
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    14
 * You should have received a copy of the GNU General Public License
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10015
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    17
 */
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    18
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    19
#include <QGridLayout>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    20
#include <QPushButton>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    21
#include <QGroupBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    22
#include <QComboBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    23
#include <QCheckBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    24
#include <QLabel>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    25
#include <QLineEdit>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    26
#include <QSpinBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    27
#include <QTableWidget>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    28
#include <QDir>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    29
#include <QProgressBar>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    30
#include <QStringList>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    31
#include <QDesktopServices>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    32
#include <QUrl>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    33
#include <QList>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    34
#include <QMessageBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    35
#include <QHeaderView>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    36
#include <QKeyEvent>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    37
#include <QVBoxLayout>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    38
#include <QHBoxLayout>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    39
#include <QFileSystemWatcher>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    40
#include <QDateTime>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    41
#include <QRegExp>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    42
#include <QXmlStreamReader>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    43
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    44
#include "hwconsts.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    45
#include "pagevideos.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    46
#include "igbox.h"
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
    47
#include "LibavInteraction.h"
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    48
#include "gameuiconfig.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    49
#include "recorder.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    50
#include "ask_quit.h"
14650
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
    51
#include "util/MessageDialog.h"
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    52
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    53
static const QSize ThumbnailSize(350, 350*3/5);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    54
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    55
// columns in table with list of video files
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    56
enum VideosColumns
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    57
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    58
    vcName,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    59
    vcSize,
13232
2a3c52c49e8e Remove “Upload to YouTube” functionality which has been broken for years
Wuzzy <Wuzzy2@mail.ru>
parents: 12897
diff changeset
    60
    vcProgress, // for encoding
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    61
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    62
    vcNumColumns,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    63
};
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    64
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    65
// this class is used for items in first column in file-table
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    66
class VideoItem : public QTableWidgetItem
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    67
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    68
    // note: QTableWidgetItem is not Q_OBJECT
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    69
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    70
    public:
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    71
        VideoItem(const QString& name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    72
        ~VideoItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    73
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    74
        QString name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    75
        QString prefix; // original filename without extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    76
        QString desc;   // description (duration, resolution, etc...)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    77
        HWRecorder    * pRecorder; // non NULL if file is being encoded
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    78
        bool seen; // used when updating directory
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    79
        float lastSizeUpdate;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    80
        float progress;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    81
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    82
        bool ready()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    83
        { return !pRecorder; }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    84
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    85
        QString path()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    86
        { return cfgdir->absoluteFilePath("Videos/" + name);  }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    87
};
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    88
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    89
VideoItem::VideoItem(const QString& name)
7865
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
    90
: QTableWidgetItem(name, UserType)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    91
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    92
    this->name = name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    93
    pRecorder = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    94
    lastSizeUpdate = 0;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    95
    progress = 0;
10248
7b9b44a051f8 Fix some of issues found by coverity
unc0rr
parents: 10108
diff changeset
    96
    seen = false;
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    97
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    98
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    99
VideoItem::~VideoItem()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   100
{}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   101
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   102
QLayout * PageVideos::bodyLayoutDefinition()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   103
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   104
    QGridLayout * pPageLayout = new QGridLayout();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   105
    pPageLayout->setColumnStretch(0, 1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   106
    pPageLayout->setColumnStretch(1, 2);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   107
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   108
    // list of videos
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   109
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   110
        IconedGroupBox* pTableGroup = new IconedGroupBox(this);
12483
a830a92b6c5c Use misc icon for description group box in videos page
Wuzzy <almikes@aol.com>
parents: 12472
diff changeset
   111
        pTableGroup->setIcon(QIcon(":/res/Videos.png"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   112
        pTableGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   113
        pTableGroup->setTitle(QGroupBox::tr("Videos"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   114
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   115
        QStringList columns;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   116
        columns << tr("Name");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   117
        columns << tr("Size");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   118
        columns << "";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   119
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   120
        filesTable = new QTableWidget(pTableGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   121
        filesTable->setColumnCount(vcNumColumns);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   122
        filesTable->setHorizontalHeaderLabels(columns);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   123
        filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   124
        filesTable->setSelectionMode(QAbstractItemView::SingleSelection);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   125
        filesTable->setEditTriggers(QAbstractItemView::SelectedClicked);
14904
ea2a1436cdd3 Frontend: Normalize appearance/style of all tables
Wuzzy <Wuzzy2@mail.ru>
parents: 14857
diff changeset
   126
        filesTable->setShowGrid(false);
ea2a1436cdd3 Frontend: Normalize appearance/style of all tables
Wuzzy <Wuzzy2@mail.ru>
parents: 14857
diff changeset
   127
        filesTable->setAlternatingRowColors(true);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   128
        filesTable->verticalHeader()->hide();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   129
        filesTable->setMinimumWidth(400);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   130
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   131
        QHeaderView * header = filesTable->horizontalHeader();
12897
fc47fc4af6bd Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents: 12483
diff changeset
   132
        header->setSectionResizeMode(vcName, QHeaderView::ResizeToContents);
fc47fc4af6bd Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents: 12483
diff changeset
   133
        header->setSectionResizeMode(vcSize, QHeaderView::Fixed);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   134
        header->resizeSection(vcSize, 100);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   135
        header->setStretchLastSection(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   136
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   137
        btnOpenDir = new QPushButton(QPushButton::tr("Open videos directory"), pTableGroup);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   138
        btnOpenDir->setWhatsThis(QPushButton::tr("Open the video directory in your system"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   139
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   140
        QVBoxLayout *box = new QVBoxLayout(pTableGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   141
        box->addWidget(filesTable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   142
        box->addWidget(btnOpenDir);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   143
8151
25b95d6224fc Google Code-in: Move video preferences in settings tab
Mitchell Kember <mk12360@gmail.com>
parents: 7897
diff changeset
   144
        pPageLayout->addWidget(pTableGroup, 0, 1);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   145
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   146
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   147
    // description
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   148
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   149
        IconedGroupBox* pDescGroup = new IconedGroupBox(this);
12483
a830a92b6c5c Use misc icon for description group box in videos page
Wuzzy <almikes@aol.com>
parents: 12472
diff changeset
   150
        pDescGroup->setIcon(QIcon(":/res/miscicon.png"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   151
        pDescGroup->setTitle(QGroupBox::tr("Description"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   152
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   153
        QVBoxLayout* pDescLayout = new QVBoxLayout(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   154
        QHBoxLayout* pBottomDescLayout = new QHBoxLayout(0); // buttons
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   155
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   156
        // label with thumbnail picture
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   157
        labelThumbnail = new QLabel(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   158
        labelThumbnail->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   159
        labelThumbnail->setMaximumSize(ThumbnailSize);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   160
        labelThumbnail->setStyleSheet(
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   161
                    "QFrame {"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   162
                    "border: solid;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   163
                    "border-width: 3px;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   164
                    "border-color: #ffcc00;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   165
                    "border-radius: 4px;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   166
                    "}" );
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   167
        clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   168
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   169
        // label with file description
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   170
        labelDesc = new QLabel(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   171
        labelDesc->setAlignment(Qt::AlignLeft | Qt::AlignTop);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   172
        labelDesc->setTextInteractionFlags(Qt::TextSelectableByMouse |
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8362
diff changeset
   173
                                           Qt::TextSelectableByKeyboard |
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   174
                                           Qt::LinksAccessibleByMouse |
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   175
                                           Qt::LinksAccessibleByKeyboard);
13691
b5a7f83fa607 Use plain text mode in video description label to avoid HTML trouble
Wuzzy <Wuzzy2@mail.ru>
parents: 13644
diff changeset
   176
        labelDesc->setTextFormat(Qt::PlainText);
8362
89a6b7cc6f95 - Unbreak build with .pro file
unc0rr
parents: 8219
diff changeset
   177
        labelDesc->setWordWrap(true);
13691
b5a7f83fa607 Use plain text mode in video description label to avoid HTML trouble
Wuzzy <Wuzzy2@mail.ru>
parents: 13644
diff changeset
   178
        labelDesc->setOpenExternalLinks(false);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   179
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   180
        // buttons: play and delete
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   181
        btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   182
        btnPlay->setEnabled(false);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   183
        btnPlay->setWhatsThis(QPushButton::tr("Play this video"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   184
        pBottomDescLayout->addWidget(btnPlay);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   185
        btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   186
        btnDelete->setEnabled(false);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   187
        btnDelete->setWhatsThis(QPushButton::tr("Delete this video"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   188
        pBottomDescLayout->addWidget(btnDelete);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   189
8200
90f524718f3d Move video description text underneath thumbnail to prevent the layout from resizing.
Mitchell Kember <mk12360@gmail.com>
parents: 8190
diff changeset
   190
        pDescLayout->addWidget(labelThumbnail, 0);
8362
89a6b7cc6f95 - Unbreak build with .pro file
unc0rr
parents: 8219
diff changeset
   191
        pDescLayout->addWidget(labelDesc, 0);
89a6b7cc6f95 - Unbreak build with .pro file
unc0rr
parents: 8219
diff changeset
   192
        pDescLayout->addLayout(pBottomDescLayout, 0);
8200
90f524718f3d Move video description text underneath thumbnail to prevent the layout from resizing.
Mitchell Kember <mk12360@gmail.com>
parents: 8190
diff changeset
   193
        pDescLayout->addStretch(1);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   194
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   195
        pPageLayout->addWidget(pDescGroup, 0, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   196
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   197
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   198
    return pPageLayout;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   199
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   200
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   201
QLayout * PageVideos::footerLayoutDefinition()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   202
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   203
    return NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   204
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   205
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   206
void PageVideos::connectSignals()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   207
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   208
    connect(filesTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(cellDoubleClicked(int, int)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   209
    connect(filesTable, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int, int)));
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   210
    connect(filesTable, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(currentCellChanged()));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   211
    connect(btnPlay,   SIGNAL(clicked()), this, SLOT(playSelectedFile()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   212
    connect(btnDelete, SIGNAL(clicked()), this, SLOT(deleteSelectedFiles()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   213
    connect(btnOpenDir, SIGNAL(clicked()), this, SLOT(openVideosDirectory()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   214
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   215
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   216
PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
13232
2a3c52c49e8e Remove “Upload to YouTube” functionality which has been broken for years
Wuzzy <Wuzzy2@mail.ru>
parents: 12897
diff changeset
   217
    config(0)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   218
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   219
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   220
    numRecorders = 0;
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   221
    // Clear VideoTemp at launch in case some garbage remained in here after a crash
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   222
    clearTemp();
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   223
    initPage();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   224
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   225
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   226
void PageVideos::init(GameUIConfig * config)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   227
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   228
    this->config = config;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   229
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   230
    QString path = cfgdir->absolutePath() + "/Videos";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   231
    QFileSystemWatcher * pWatcher = new QFileSystemWatcher(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   232
    pWatcher->addPath(path);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   233
    connect(pWatcher, SIGNAL(directoryChanged(const QString &)), this, SLOT(updateFileList(const QString &)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   234
    updateFileList(path);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   235
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   236
    startEncoding(); // this is for videos recorded from demos which were executed directly (without frontend)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   237
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   238
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   239
// get file size as string
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   240
static QString FileSizeStr(const QString & path)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   241
{
13286
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   242
    qint64 size = QFileInfo(path).size();
13289
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   243
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   244
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
13286
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   245
    return QLocale().formattedDataSize(size);
13289
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   246
#else
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   247
    qint64 KiB = 1024;
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   248
    qint64 MiB = 1024*KiB;
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   249
    qint64 GiB = 1024*MiB;
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   250
    QString sizeStr;
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   251
    float fsize = (float) size;
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   252
    if (size >= GiB)
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   253
        return QString("%1 GiB").arg(QLocale().toString(fsize/GiB, 'f', 2));
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   254
    if (size >= MiB)
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   255
        return QString("%1 MiB").arg(QLocale().toString(fsize/MiB, 'f', 2));
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   256
    if (size >= KiB)
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   257
        return QString("%1 KiB").arg(QLocale().toString(fsize/KiB, 'f', 2));
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   258
    return PageVideos::tr("%1 bytes", "", size).arg(QString::number(size));
6927e51acaef Fix compile fail due to dependency in Qt 5.10 in pagevideos.cpp
Wuzzy <Wuzzy2@mail.ru>
parents: 13286
diff changeset
   259
#endif
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   260
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   261
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   262
// set file size in file list in specified row
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   263
void PageVideos::updateSize(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   264
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   265
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   266
    QString path = item->ready()? item->path() : cfgdir->absoluteFilePath("VideoTemp/" + item->pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   267
    filesTable->item(row, vcSize)->setText(FileSizeStr(path));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   268
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   269
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   270
// There is a button 'Open videos dir', so it is possible that user will open
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   271
// this dir and rename/delete some files there, so we should handle this.
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   272
void PageVideos::updateFileList(const QString & path)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   273
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   274
    // mark all files as non seen
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   275
    int numRows = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   276
    for (int i = 0; i < numRows; i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   277
        nameItem(i)->seen = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   278
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   279
    QStringList files = QDir(path).entryList(QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   280
    foreach (const QString & name, files)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   281
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   282
        int row = -1;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   283
        foreach (QTableWidgetItem * item, filesTable->findItems(name, Qt::MatchExactly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   284
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   285
            if (item->type() != QTableWidgetItem::UserType || !((VideoItem*)item)->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   286
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   287
            row = item->row();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   288
            break;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   289
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   290
        if (row == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   291
            row = appendRow(name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   292
        VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   293
        item->seen = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   294
        item->desc = "";
14909
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   295
        setName(item, item->name);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   296
        updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   297
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   298
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   299
    // remove all non seen files
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   300
    for (int i = 0; i < filesTable->rowCount();)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   301
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   302
        VideoItem * item = nameItem(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   303
        if (item->ready() && !item->seen)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   304
            filesTable->removeRow(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   305
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   306
            i++;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   307
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   308
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   309
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   310
void PageVideos::addRecorder(HWRecorder* pRecorder)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   311
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   312
    int row = appendRow(pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   313
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   314
    item->pRecorder = pRecorder;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   315
    pRecorder->item = item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   316
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   317
    // add progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   318
    QProgressBar * progressBar = new QProgressBar(filesTable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   319
    progressBar->setMinimum(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   320
    progressBar->setMaximum(10000);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   321
    progressBar->setValue(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   322
    connect(pRecorder, SIGNAL(onProgress(float)), this, SLOT(updateProgress(float)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   323
    connect(pRecorder, SIGNAL(encodingFinished(bool)), this, SLOT(encodingFinished(bool)));
14650
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   324
    connect(pRecorder, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowFatalErrorMessage(const QString &)), Qt::QueuedConnection);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   325
    filesTable->setCellWidget(row, vcProgress, progressBar);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   326
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   327
    numRecorders++;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   328
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   329
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   330
void PageVideos::setProgress(int row, VideoItem* item, float value)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   331
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   332
    QProgressBar * progressBar = (QProgressBar*)filesTable->cellWidget(row, vcProgress);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   333
    progressBar->setValue(value*10000);
13286
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   334
    //: Video encoding progress. %1 = number
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   335
    progressBar->setFormat(QString(tr("%1%")).arg(QLocale().toString(value*100, 'f', 2)));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   336
    item->progress = value;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   337
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   338
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   339
void PageVideos::updateProgress(float value)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   340
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   341
    HWRecorder * pRecorder = (HWRecorder*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   342
    VideoItem * item = pRecorder->item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   343
    int row = filesTable->row(item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   344
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   345
    // update file size every percent
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   346
    if (value - item->lastSizeUpdate > 0.01)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   347
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   348
        updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   349
        item->lastSizeUpdate = value;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   350
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   351
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   352
    setProgress(row, item, value);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   353
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   354
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   355
void PageVideos::encodingFinished(bool success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   356
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   357
    numRecorders--;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   358
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   359
    HWRecorder * pRecorder = (HWRecorder*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   360
    VideoItem * item = (VideoItem*)pRecorder->item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   361
    int row = filesTable->row(item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   362
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   363
    if (success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   364
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   365
        // move file to destination
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   366
        success = cfgdir->rename("VideoTemp/" + pRecorder->name, "Videos/" + item->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   367
        if (!success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   368
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   369
            // unable to rename for some reason (maybe user entered incorrect name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   370
            // try to use temp name instead.
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   371
            success = cfgdir->rename("VideoTemp/" + pRecorder->name, "Videos/" + pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   372
            if (success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   373
                setName(item, pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   374
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   375
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   376
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   377
    if (!success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   378
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   379
        filesTable->removeRow(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   380
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   381
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   382
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   383
    filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   384
    item->pRecorder = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   385
    updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   386
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   387
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   388
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   389
void PageVideos::cellDoubleClicked(int row, int column)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   390
{
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   391
    Q_UNUSED(column);
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   392
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   393
    play(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   394
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   395
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   396
void PageVideos::cellChanged(int row, int column)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   397
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   398
    // user can only edit name
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   399
    if (column != vcName || nameChangedFromCode)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   400
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   401
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   402
    // user has edited filename, so we should rename the file
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   403
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   404
    QString oldName = item->name;
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   405
    int pointPos = oldName.lastIndexOf('.');
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   406
    QString oldPrefix = item->name;
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   407
    oldPrefix.truncate(pointPos);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   408
    QString newName = item->text();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   409
    if (!newName.contains('.')) // user forgot an extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   410
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   411
        // restore old extension
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   412
        pointPos = oldName.lastIndexOf('.');
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   413
        if (pointPos != -1)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   414
        {
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   415
            newName += oldName.right(oldName.length() - pointPos);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   416
            setName(item, newName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   417
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   418
    }
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   419
    QString newPrefix;
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   420
    if (newName.contains('.'))
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   421
    {
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   422
        pointPos = newName.lastIndexOf('.');
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   423
        if (pointPos != -1)
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   424
        {
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   425
            newPrefix = newName;
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   426
            newPrefix.truncate(pointPos);
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   427
        }
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   428
    }
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   429
    else
14909
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   430
        newPrefix = newName;
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   431
    for (int i = 0; i < filesTable->rowCount(); i++)
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   432
    {
14909
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   433
        // don't allow rename if duplicate prefix
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   434
        VideoItem * iterateItem = nameItem(i);
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   435
        if ((i != row) && (newPrefix == iterateItem->prefix))
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   436
        {
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   437
            setName(item, oldName);
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   438
            return;
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   439
        }
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   440
    }
9163
67334acaaac7 port all Q_WS_* to Q_OS_* so that we are forward compatible with Qt5
koda
parents: 9107
diff changeset
   441
#ifdef Q_OS_WIN
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   442
    // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
   443
    if (newName.contains(QRegExp("[\"*:<>?\\/|]")))
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   444
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   445
        setName(item, oldName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   446
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   447
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   448
#endif
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   449
    if (item->ready() && !cfgdir->rename("Videos/" + oldName, "Videos/" + newName))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   450
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   451
        // unable to rename for some reason (maybe user entered incorrect name),
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   452
        // therefore restore old name in cell
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   453
        setName(item, oldName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   454
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   455
    }
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   456
    if (item->ready())
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   457
    {
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   458
        cfgdir->rename("VideoThumbnails/" + oldPrefix + ".png", "VideoThumbnails/" + newPrefix + ".png");
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   459
        cfgdir->rename("VideoThumbnails/" + oldPrefix + ".bmp", "VideoThumbnails/" + newPrefix + ".bmp");
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   460
    }
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   461
    item->name = newName;
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   462
    item->prefix = newPrefix;
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   463
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   464
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   465
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   466
void PageVideos::setName(VideoItem * item, const QString & newName)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   467
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   468
    nameChangedFromCode = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   469
    item->setText(newName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   470
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   471
    item->name = newName;
14909
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   472
    // try to extract prefix
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   473
    if (item->ready())
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   474
        item->prefix = item->name;
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   475
    else
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   476
        item->prefix = item->pRecorder->name;
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   477
    // remove extension
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   478
    int pt = item->prefix.lastIndexOf('.');
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   479
    if (pt != -1)
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   480
        item->prefix.truncate(pt);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   481
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   482
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   483
int PageVideos::appendRow(const QString & name)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   484
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   485
    int row = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   486
    filesTable->setRowCount(row+1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   487
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   488
    // add 'name' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   489
    QTableWidgetItem * item = new VideoItem(name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   490
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   491
    nameChangedFromCode = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   492
    filesTable->setItem(row, vcName, item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   493
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   494
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   495
    // add 'size' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   496
    item = new QTableWidgetItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   497
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   498
    item->setTextAlignment(Qt::AlignRight);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   499
    filesTable->setItem(row, vcSize, item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   500
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   501
    // add 'progress' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   502
    item = new QTableWidgetItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   503
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   504
    filesTable->setItem(row, vcProgress, item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   505
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   506
    return row;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   507
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   508
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   509
VideoItem* PageVideos::nameItem(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   510
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   511
    return (VideoItem*)filesTable->item(row, vcName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   512
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   513
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   514
void PageVideos::clearThumbnail()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   515
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   516
    // add empty (transparent) image for proper sizing
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   517
    QPixmap pic(ThumbnailSize);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   518
    pic.fill(QColor(0,0,0,0));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   519
    labelThumbnail->setPixmap(pic);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   520
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   521
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   522
void PageVideos::updateDescription()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   523
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   524
    VideoItem * item = nameItem(filesTable->currentRow());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   525
    if (!item)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   526
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   527
        // nothing is selected => clear description and return
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   528
        labelDesc->clear();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   529
        clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   530
        btnPlay->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   531
        btnDelete->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   532
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   533
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   534
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   535
    btnPlay->setEnabled(item->ready());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   536
    btnDelete->setEnabled(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   537
    btnDelete->setText(item->ready()? QPushButton::tr("Delete") :  QPushButton::tr("Cancel"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   538
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   539
    // construct string with desctiption of this file to display it
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   540
    QString desc = item->name + "\n\n";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   541
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   542
    if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   543
        desc += tr("(in progress...)");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   544
    else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   545
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   546
        QString path = item->path();
9107
4dde5fecffe2 Less confusion to translators
unc0rr
parents: 9080
diff changeset
   547
        desc += tr("Date: %1").arg(QFileInfo(path).created().toString(Qt::DefaultLocaleLongDate)) + "\n";
4dde5fecffe2 Less confusion to translators
unc0rr
parents: 9080
diff changeset
   548
        desc += tr("Size: %1").arg(FileSizeStr(path)) + "\n";
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   549
        if (item->desc.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   550
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   551
            // Extract description from file;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   552
            // It will contain duration, resolution, etc and also comment added by hwengine.
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
   553
            item->desc = LibavInteraction::instance().getFileInfo(path);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   554
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   555
            // extract prefix (original name) from description (it is enclosed in prefix[???]prefix)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   556
            int prefixBegin = item->desc.indexOf("prefix[");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   557
            int prefixEnd   = item->desc.indexOf("]prefix");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   558
            if (prefixBegin != -1 && prefixEnd != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   559
            {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   560
                item->prefix = item->desc.mid(prefixBegin + 7, prefixEnd - (prefixBegin + 7));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   561
                item->desc.remove(prefixBegin, prefixEnd + 7 - prefixBegin);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   562
            }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   563
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   564
        desc += item->desc + '\n';
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   565
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   566
14909
b5a9dd36c7ea pagevideos: Prevent renaming video if file name prefix is already used
Wuzzy <Wuzzy2@mail.ru>
parents: 14908
diff changeset
   567
    if (item->prefix.isNull() || item->prefix.isEmpty())
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   568
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   569
        // try to extract prefix from file name instead
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   570
        if (item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   571
            item->prefix = item->name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   572
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   573
            item->prefix = item->pRecorder->name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   574
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   575
        // remove extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   576
        int pt = item->prefix.lastIndexOf('.');
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   577
        if (pt != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   578
            item->prefix.truncate(pt);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   579
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   580
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   581
    labelDesc->setText(desc);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   582
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   583
    if (!item->prefix.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   584
    {
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   585
        QString thumbName = cfgdir->absoluteFilePath("VideoThumbnails/" + item->prefix);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   586
        QPixmap pic;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   587
        if (pic.load(thumbName + ".png") || pic.load(thumbName + ".bmp"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   588
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   589
            if (pic.height()*ThumbnailSize.width() > pic.width()*ThumbnailSize.height())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   590
                pic = pic.scaledToWidth(ThumbnailSize.width());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   591
            else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   592
                pic = pic.scaledToHeight(ThumbnailSize.height());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   593
            labelThumbnail->setPixmap(pic);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   594
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   595
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   596
            clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   597
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   598
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   599
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   600
// user selected another cell, so we should change description
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   601
void PageVideos::currentCellChanged()
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   602
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   603
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   604
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   605
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   606
// open video file in external media player
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   607
void PageVideos::play(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   608
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   609
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   610
    if (item && item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   611
        QDesktopServices::openUrl(QUrl("file:///" + QDir::toNativeSeparators(item->path())));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   612
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   613
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   614
void PageVideos::playSelectedFile()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   615
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   616
    int index = filesTable->currentRow();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   617
    if (index != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   618
        play(index);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   619
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   620
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   621
void PageVideos::deleteSelectedFiles()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   622
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   623
    int index = filesTable->currentRow();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   624
    if (index == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   625
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   626
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   627
    VideoItem * item = nameItem(index);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   628
    if (!item)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   629
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   630
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   631
    // ask user if (s)he is serious
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   632
    QMessageBox reallyDeleteMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   633
    reallyDeleteMsg.setIcon(QMessageBox::Question);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   634
    reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Videos - Are you sure?"));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   635
    reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the video '%1'?").arg(item->name));
14857
b9437746bffb Frontend: Force plain text mode for many message windows
Wuzzy <Wuzzy2@mail.ru>
parents: 14650
diff changeset
   636
    reallyDeleteMsg.setTextFormat(Qt::PlainText);
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   637
    reallyDeleteMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   638
    reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   639
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   640
    if (reallyDeleteMsg.exec() != QMessageBox::Ok)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   641
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   642
13644
1b536e268519 Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents: 13289
diff changeset
   643
    // abort / remove
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   644
    if (!item->ready())
13644
1b536e268519 Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents: 13289
diff changeset
   645
        item->pRecorder->abort();
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   646
    else
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   647
    {
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   648
        cfgdir->remove("Videos/" + item->name);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   649
        // we have no idea whether screenshot is going to be bmp or png so let's delete both
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   650
        cfgdir->remove("VideoThumbnails/" + item->prefix + ".png");
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   651
        cfgdir->remove("VideoThumbnails/" + item->prefix + ".bmp");
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   652
    }
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   653
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   654
// this code is for removing several files when multiple selection is enabled
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   655
#if 0
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   656
    QList<QTableWidgetItem*> items = filesTable->selectedItems();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   657
    int num = items.size() / vcNumColumns;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   658
    if (num == 0)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   659
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   660
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   661
    // ask user if (s)he is serious
7794
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   662
    QMessageBox reallyDeleteMsg(this);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   663
    reallyDeleteMsg.setIcon(QMessageBox::Question);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   664
    reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Videos - Are you sure?"));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   665
    reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to remove %1 file(s)?", "", num).arg(num));
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   666
    reallyDeleteMsg.setWindowModality(Qt::WindowModal);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   667
    reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   668
ab7b94c03bc9 QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents: 7680
diff changeset
   669
    if (reallyDeleteMsg.exec() != QMessageBox::Ok)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   670
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   671
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   672
    // remove
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   673
    foreach (QTableWidgetItem * witem, items)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   674
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   675
        if (witem->type() != QTableWidgetItem::UserType)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   676
            continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   677
        VideoItem * item = (VideoItem*)witem;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   678
        if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   679
            item->pRecorder->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   680
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   681
            cfgdir->remove("Videos/" + item->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   682
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   683
#endif
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   684
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   685
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   686
void PageVideos::keyPressEvent(QKeyEvent * pEvent)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   687
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   688
    if (filesTable->hasFocus())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   689
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   690
        if (pEvent->key() == Qt::Key_Delete)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   691
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   692
            deleteSelectedFiles();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   693
            return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   694
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   695
        if (pEvent->key() == Qt::Key_Enter) // doesn't work
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   696
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   697
            playSelectedFile();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   698
            return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   699
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   700
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   701
    AbstractPage::keyPressEvent(pEvent);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   702
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   703
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   704
void PageVideos::openVideosDirectory()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   705
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   706
    QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Videos");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   707
    QDesktopServices::openUrl(QUrl("file:///" + path));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   708
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   709
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   710
// clear VideoTemp directory
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   711
void PageVideos::clearTemp()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   712
{
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   713
    qDebug("Clearing VideoTemp directory ...");
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   714
    QDir temp(cfgdir->absolutePath() + "/VideoTemp");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   715
    QStringList files = temp.entryList(QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   716
    foreach (const QString& file, files)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   717
    {
14908
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   718
        // Legacy support: Move thumbnails to correct dir
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   719
        if (file.endsWith(".bmp") || file.endsWith(".png"))
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   720
        {
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   721
            qDebug("Moving video thumbnail '%s' to VideoThumbnails directory", qPrintable(file));
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   722
            cfgdir->rename("VideoTemp/" + file, "VideoThumbnails/" + file);
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   723
        }
a414d37278df Move video thumbnails to VideoThumbnails/, fix video renaming not renaming the thumbnail as well
Wuzzy <Wuzzy2@mail.ru>
parents: 14904
diff changeset
   724
        else
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   725
            temp.remove(file);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   726
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   727
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   728
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   729
bool PageVideos::tryQuit(HWForm * form)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   730
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   731
    bool quit = true;
13232
2a3c52c49e8e Remove “Upload to YouTube” functionality which has been broken for years
Wuzzy <Wuzzy2@mail.ru>
parents: 12897
diff changeset
   732
    if (numRecorders != 0)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   733
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   734
        // ask user what to do - abort or wait
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   735
        HWAskQuitDialog * askd = new HWAskQuitDialog(this, form);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   736
        askd->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   737
        quit = askd->exec();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   738
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   739
    if (quit)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   740
        clearTemp();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   741
    return quit;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   742
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   743
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   744
// returns multi-line string with list of videos in progress
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   745
/* it will look like this:
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   746
foo.avi (15.21% - encoding)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   747
*/
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   748
QString PageVideos::getVideosInProgress()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   749
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   750
    QString list = "";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   751
    int count = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   752
    for (int i = 0; i < count; i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   753
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   754
        VideoItem * item = nameItem(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   755
        QString process;
13286
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   756
        if (item->ready())
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   757
            continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   758
        float progress = 100*item->progress;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   759
        if (progress > 99.99)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   760
            progress = 99.99; // displaying 100% may be confusing
13286
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   761
        //: Video encoding list entry. %1 = file name, %2 = percent complete, %3 = video operation type (e.g. “encoding”)
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   762
        list += QString(tr("%1 (%2%) - %3"))
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   763
            .arg(item->name)
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   764
            .arg(QLocale().toString(progress, 'f', 2))
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   765
            .arg(tr("encoding"))
1fbf2ac1f13e Videos frontend page: Locale-aware text formatting
Wuzzy <Wuzzy2@mail.ru>
parents: 13232
diff changeset
   766
            + "\n";
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   767
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   768
    return list;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   769
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   770
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   771
void PageVideos::startEncoding(const QByteArray & record)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   772
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   773
    QDir videoTempDir(cfgdir->absolutePath() + "/VideoTemp/");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   774
    QStringList files = videoTempDir.entryList(QStringList("*.txtout"), QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   775
    foreach (const QString & str, files)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   776
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   777
        QString prefix = str;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   778
        prefix.chop(7); // remove ".txtout"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   779
        videoTempDir.rename(prefix + ".txtout", prefix + ".txtin"); // rename this file to not open it twice
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   780
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   781
        HWRecorder* pRecorder = new HWRecorder(config, prefix);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   782
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   783
        if (!record.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   784
            pRecorder->EncodeVideo(record);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   785
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   786
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   787
            // this is for videos recorded from demos which were executed directly (without frontend)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   788
            QFile demofile(videoTempDir.absoluteFilePath(prefix + ".hwd"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   789
            if (!demofile.open(QIODevice::ReadOnly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   790
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   791
            QByteArray demo = demofile.readAll();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   792
            if (demo.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   793
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   794
            pRecorder->EncodeVideo(demo);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   795
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   796
        addRecorder(pRecorder);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   797
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   798
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   799
14650
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   800
void PageVideos::ShowFatalErrorMessage(const QString & msg)
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   801
{
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   802
    MessageDialog::ShowFatalMessage(msg, this);
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   803
}
8ffa0c27f434 Show error message in frontend if video encoding failed in engine
Wuzzy <Wuzzy2@mail.ru>
parents: 13691
diff changeset
   804