QTfrontend/ui/page/pagevideos.cpp
author unc0rr
Tue, 20 Nov 2012 00:10:12 +0400
changeset 8070 66bc20d089fc
parent 7897 5e7c0810f365
child 8151 25b95d6224fc
child 8185 1c3739ba4352
permissions -rw-r--r--
Okay, remove previous request only if it has same parent as this one. Fixes the last note of previous commit (which was nearly impossible to hit, but whatever, just cleaning implementation)
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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 <QNetworkAccessManager>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    43
#include <QNetworkRequest>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    44
#include <QNetworkReply>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    45
#include <QXmlStreamReader>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    46
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    47
#include "hwconsts.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    48
#include "pagevideos.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    49
#include "igbox.h"
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
    50
#include "LibavInteraction.h"
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    51
#include "gameuiconfig.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    52
#include "recorder.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    53
#include "ask_quit.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    54
#include "upload_video.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    55
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    56
static const QSize ThumbnailSize(350, 350*3/5);
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
// columns in table with list of video files
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    59
enum VideosColumns
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    60
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    61
    vcName,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    62
    vcSize,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    63
    vcProgress, // either encoding or uploading
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
    vcNumColumns,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    66
};
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
// 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
    69
class VideoItem : public QTableWidgetItem
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    70
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    71
    // note: QTableWidgetItem is not Q_OBJECT
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    72
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    73
    public:
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    74
        VideoItem(const QString& name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    75
        ~VideoItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    76
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    77
        QString name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    78
        QString prefix; // original filename without extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    79
        QString desc;   // description (duration, resolution, etc...)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    80
        QString uploadUrl; // http://youtu.be/???????
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    81
        HWRecorder    * pRecorder; // non NULL if file is being encoded
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    82
        QNetworkReply * pUploading; // non NULL if file is being uploaded
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    83
        bool seen; // used when updating directory
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    84
        float lastSizeUpdate;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    85
        float progress;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    86
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    87
        bool ready()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    88
        { return !pRecorder; }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    89
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    90
        QString path()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    91
        { return cfgdir->absoluteFilePath("Videos/" + name);  }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    92
};
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    93
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    94
VideoItem::VideoItem(const QString& name)
7865
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
    95
: QTableWidgetItem(name, UserType)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    96
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    97
    this->name = name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    98
    pRecorder = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
    99
    pUploading = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   100
    lastSizeUpdate = 0;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   101
    progress = 0;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   102
}
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
VideoItem::~VideoItem()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   105
{}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   106
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   107
QLayout * PageVideos::bodyLayoutDefinition()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   108
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   109
    QGridLayout * pPageLayout = new QGridLayout();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   110
    pPageLayout->setColumnStretch(0, 1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   111
    pPageLayout->setColumnStretch(1, 2);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   112
    pPageLayout->setRowStretch(0, 1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   113
    pPageLayout->setRowStretch(1, 1);
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
    // options
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   116
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   117
        IconedGroupBox* pOptionsGroup = new IconedGroupBox(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   118
        pOptionsGroup->setIcon(QIcon(":/res/Settings.png")); // FIXME
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   119
        pOptionsGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   120
        pOptionsGroup->setTitle(QGroupBox::tr("Video recording options"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   121
        QGridLayout * pOptLayout = new QGridLayout(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   122
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   123
        // label for format
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   124
        QLabel *labelFormat = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   125
        labelFormat->setText(QLabel::tr("Format"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   126
        pOptLayout->addWidget(labelFormat, 0, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   127
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   128
        // list of supported formats
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   129
        comboAVFormats = new QComboBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   130
        pOptLayout->addWidget(comboAVFormats, 0, 1, 1, 4);
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
   131
        LibavInteraction::instance().fillFormats(comboAVFormats);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   132
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   133
        // separator
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   134
        QFrame * hr = new QFrame(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   135
        hr->setFrameStyle(QFrame::HLine);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   136
        hr->setLineWidth(3);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   137
        hr->setFixedHeight(10);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   138
        pOptLayout->addWidget(hr, 1, 0, 1, 5);
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
        // label for audio codec
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   141
        QLabel *labelACodec = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   142
        labelACodec->setText(QLabel::tr("Audio codec"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   143
        pOptLayout->addWidget(labelACodec, 2, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   144
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   145
        // list of supported audio codecs
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   146
        comboAudioCodecs = new QComboBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   147
        pOptLayout->addWidget(comboAudioCodecs, 2, 1, 1, 3);
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
        // checkbox 'record audio'
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   150
        checkRecordAudio = new QCheckBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   151
        checkRecordAudio->setText(QCheckBox::tr("Record audio"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   152
        pOptLayout->addWidget(checkRecordAudio, 2, 4);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   153
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   154
        // separator
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   155
        hr = new QFrame(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   156
        hr->setFrameStyle(QFrame::HLine);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   157
        hr->setLineWidth(3);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   158
        hr->setFixedHeight(10);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   159
        pOptLayout->addWidget(hr, 3, 0, 1, 5);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   160
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   161
        // label for video codec
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   162
        QLabel *labelVCodec = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   163
        labelVCodec->setText(QLabel::tr("Video codec"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   164
        pOptLayout->addWidget(labelVCodec, 4, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   165
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   166
        // list of supported video codecs
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   167
        comboVideoCodecs = new QComboBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   168
        pOptLayout->addWidget(comboVideoCodecs, 4, 1, 1, 4);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   169
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   170
        // label for resolution
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   171
        QLabel *labelRes = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   172
        labelRes->setText(QLabel::tr("Resolution"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   173
        pOptLayout->addWidget(labelRes, 5, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   174
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   175
        // width
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   176
        widthEdit = new QLineEdit(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   177
        widthEdit->setValidator(new QIntValidator(this));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   178
        pOptLayout->addWidget(widthEdit, 5, 1);
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
        // x
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   181
        QLabel *labelX = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   182
        labelX->setText("X");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   183
        pOptLayout->addWidget(labelX, 5, 2);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   184
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   185
        // height
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   186
        heightEdit = new QLineEdit(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   187
        heightEdit->setValidator(new QIntValidator(pOptionsGroup));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   188
        pOptLayout->addWidget(heightEdit, 5, 3);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   189
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   190
        // checkbox 'use game resolution'
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   191
        checkUseGameRes = new QCheckBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   192
        checkUseGameRes->setText(QCheckBox::tr("Use game resolution"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   193
        pOptLayout->addWidget(checkUseGameRes, 5, 4);
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
        // label for framerate
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   196
        QLabel *labelFramerate = new QLabel(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   197
        labelFramerate->setText(QLabel::tr("Framerate"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   198
        pOptLayout->addWidget(labelFramerate, 6, 0);
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
        // framerate
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   201
        framerateBox = new QSpinBox(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   202
        framerateBox->setRange(1, 200);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   203
        framerateBox->setSingleStep(1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   204
        pOptLayout->addWidget(framerateBox, 6, 1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   205
7633
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   206
        // label for Bitrate
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   207
        QLabel *labelBitrate = new QLabel(pOptionsGroup);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   208
        labelBitrate->setText(QLabel::tr("Bitrate (Kbps)"));
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   209
        pOptLayout->addWidget(labelBitrate, 6, 2);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   210
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   211
        // bitrate
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   212
        bitrateBox = new QSpinBox(pOptionsGroup);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   213
        bitrateBox->setRange(100, 5000);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   214
        bitrateBox->setSingleStep(100);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   215
        pOptLayout->addWidget(bitrateBox, 6, 3);
d4251e519062 Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents: 7631
diff changeset
   216
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   217
        // button 'set default options'
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   218
        btnDefaults = new QPushButton(pOptionsGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   219
        btnDefaults->setText(QPushButton::tr("Set default options"));
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   220
        btnDefaults->setWhatsThis(QPushButton::tr("Restore default coding parameters"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   221
        pOptLayout->addWidget(btnDefaults, 7, 0, 1, 5);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   222
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   223
        pPageLayout->addWidget(pOptionsGroup, 1, 0);
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
    // list of videos
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
        IconedGroupBox* pTableGroup = new IconedGroupBox(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   229
        pTableGroup->setIcon(QIcon(":/res/graphicsicon.png")); // FIXME
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   230
        pTableGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   231
        pTableGroup->setTitle(QGroupBox::tr("Videos"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   232
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   233
        QStringList columns;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   234
        columns << tr("Name");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   235
        columns << tr("Size");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   236
        columns << "";
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
        filesTable = new QTableWidget(pTableGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   239
        filesTable->setColumnCount(vcNumColumns);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   240
        filesTable->setHorizontalHeaderLabels(columns);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   241
        filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   242
        filesTable->setSelectionMode(QAbstractItemView::SingleSelection);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   243
        filesTable->setEditTriggers(QAbstractItemView::SelectedClicked);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   244
        filesTable->verticalHeader()->hide();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   245
        filesTable->setMinimumWidth(400);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   246
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   247
        QHeaderView * header = filesTable->horizontalHeader();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   248
        header->setResizeMode(vcName, QHeaderView::ResizeToContents);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   249
        header->setResizeMode(vcSize, QHeaderView::Fixed);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   250
        header->resizeSection(vcSize, 100);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   251
        header->setStretchLastSection(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   252
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   253
        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
   254
        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
   255
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   256
        QVBoxLayout *box = new QVBoxLayout(pTableGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   257
        box->addWidget(filesTable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   258
        box->addWidget(btnOpenDir);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   259
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   260
        pPageLayout->addWidget(pTableGroup, 0, 1, 2, 1);
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   263
    // description
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
        IconedGroupBox* pDescGroup = new IconedGroupBox(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   266
        pDescGroup->setIcon(QIcon(":/res/graphicsicon.png")); // FIXME
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   267
        pDescGroup->setTitle(QGroupBox::tr("Description"));
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
        QVBoxLayout* pDescLayout = new QVBoxLayout(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   270
        QHBoxLayout* pTopDescLayout = new QHBoxLayout(0);    // picture and text
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   271
        QHBoxLayout* pBottomDescLayout = new QHBoxLayout(0); // buttons
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   272
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   273
        // label with thumbnail picture
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   274
        labelThumbnail = new QLabel(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   275
        labelThumbnail->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   276
        labelThumbnail->setMaximumSize(ThumbnailSize);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   277
        labelThumbnail->setStyleSheet(
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   278
                    "QFrame {"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   279
                    "border: solid;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   280
                    "border-width: 3px;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   281
                    "border-color: #ffcc00;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   282
                    "border-radius: 4px;"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   283
                    "}" );
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   284
        clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   285
        pTopDescLayout->addWidget(labelThumbnail, 2);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   286
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   287
        // label with file description
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   288
        labelDesc = new QLabel(pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   289
        labelDesc->setAlignment(Qt::AlignLeft | Qt::AlignTop);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   290
        labelDesc->setTextInteractionFlags(Qt::TextSelectableByMouse |
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   291
                                           Qt::TextSelectableByKeyboard	|
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   292
                                           Qt::LinksAccessibleByMouse |
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   293
                                           Qt::LinksAccessibleByKeyboard);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   294
        labelDesc->setTextFormat(Qt::RichText);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   295
        labelDesc->setOpenExternalLinks(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   296
        pTopDescLayout->addWidget(labelDesc, 1);
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
        // buttons: play and delete
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   299
        btnPlay = new QPushButton(QPushButton::tr("Play"), pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   300
        btnPlay->setEnabled(false);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   301
        btnPlay->setWhatsThis(QPushButton::tr("Play this video"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   302
        pBottomDescLayout->addWidget(btnPlay);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   303
        btnDelete = new QPushButton(QPushButton::tr("Delete"), pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   304
        btnDelete->setEnabled(false);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   305
        btnDelete->setWhatsThis(QPushButton::tr("Delete this video"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   306
        pBottomDescLayout->addWidget(btnDelete);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   307
        btnToYouTube = new QPushButton(QPushButton::tr("Upload to YouTube"), pDescGroup);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   308
        btnToYouTube->setEnabled(false);
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   309
        btnToYouTube->setWhatsThis(QPushButton::tr("Upload this video to your Youtube account"));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   310
        pBottomDescLayout->addWidget(btnToYouTube);
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
        pDescLayout->addStretch(1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   313
        pDescLayout->addLayout(pTopDescLayout, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   314
        pDescLayout->addStretch(1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   315
        pDescLayout->addLayout(pBottomDescLayout, 0);
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
        pPageLayout->addWidget(pDescGroup, 0, 0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   318
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   319
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   320
    return pPageLayout;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   321
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   322
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   323
QLayout * PageVideos::footerLayoutDefinition()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   324
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   325
    return NULL;
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   328
void PageVideos::connectSignals()
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
    connect(checkUseGameRes, SIGNAL(stateChanged(int)), this, SLOT(changeUseGameRes(int)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   331
    connect(checkRecordAudio, SIGNAL(stateChanged(int)), this, SLOT(changeRecordAudio(int)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   332
    connect(comboAVFormats, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAVFormat(int)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   333
    connect(btnDefaults, SIGNAL(clicked()), this, SLOT(setDefaultOptions()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   334
    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
   335
    connect(filesTable, SIGNAL(cellChanged(int,int)), this, SLOT(cellChanged(int, int)));
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   336
    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
   337
    connect(btnPlay,   SIGNAL(clicked()), this, SLOT(playSelectedFile()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   338
    connect(btnDelete, SIGNAL(clicked()), this, SLOT(deleteSelectedFiles()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   339
    connect(btnToYouTube, SIGNAL(clicked()), this, SLOT(uploadToYouTube()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   340
    connect(btnOpenDir, SIGNAL(clicked()), this, SLOT(openVideosDirectory()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   341
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   342
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   343
PageVideos::PageVideos(QWidget* parent) : AbstractPage(parent),
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   344
    config(0), netManager(0)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   345
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   346
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   347
    numRecorders = 0;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   348
    numUploads = 0;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   349
    initPage();
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
void PageVideos::init(GameUIConfig * config)
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
    this->config = config;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   355
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   356
    QString path = cfgdir->absolutePath() + "/Videos";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   357
    QFileSystemWatcher * pWatcher = new QFileSystemWatcher(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   358
    pWatcher->addPath(path);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   359
    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
   360
    updateFileList(path);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   361
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   362
    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
   363
}
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
// user changed file format, we need to update list of codecs
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   366
void PageVideos::changeAVFormat(int index)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   367
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   368
    // remember selected codecs
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   369
    QString prevVCodec = videoCodec();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   370
    QString prevACodec = audioCodec();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   371
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   372
    // clear lists of codecs
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   373
    comboVideoCodecs->clear();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   374
    comboAudioCodecs->clear();
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
    // get list of codecs for specified format
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
   377
    LibavInteraction::instance().fillCodecs(comboAVFormats->itemData(index).toString(), comboVideoCodecs, comboAudioCodecs);
7631
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
    // disable audio if there is no audio codec
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   380
    if (comboAudioCodecs->count() == 0)
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
        checkRecordAudio->setChecked(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   383
        checkRecordAudio->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   384
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   385
    else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   386
        checkRecordAudio->setEnabled(true);
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
    // restore selected codecs if possible
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   389
    int iVCodec = comboVideoCodecs->findData(prevVCodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   390
    if (iVCodec != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   391
        comboVideoCodecs->setCurrentIndex(iVCodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   392
    int iACodec = comboAudioCodecs->findData(prevACodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   393
    if (iACodec != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   394
        comboAudioCodecs->setCurrentIndex(iACodec);
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   397
// user switched checkbox 'use game resolution'
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   398
void PageVideos::changeUseGameRes(int state)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   399
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   400
    if (state && config)
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
        // set resolution to game resolution
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   403
        QRect resolution = config->vid_Resolution();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   404
        widthEdit->setText(QString::number(resolution.width()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   405
        heightEdit->setText(QString::number(resolution.height()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   406
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   407
    widthEdit->setEnabled(!state);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   408
    heightEdit->setEnabled(!state);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   409
}
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
// user switched checkbox 'record audio'
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   412
void PageVideos::changeRecordAudio(int state)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   413
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   414
    comboAudioCodecs->setEnabled(!!state);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   415
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   416
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   417
void PageVideos::setDefaultCodecs()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   418
{
7865
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   419
    // VLC should be able to handle any of these configurations
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   420
    // Quicktime X only opens the first one
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   421
    // Windows Media Player TODO
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   422
    if (tryCodecs("mp4", "libx264", "aac"))
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   423
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   424
    if (tryCodecs("mp4", "libx264", "libfaac"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   425
        return;
7865
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   426
    if (tryCodecs("mp4", "libx264", "libmp3lame"))
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   427
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   428
    if (tryCodecs("mp4", "libx264", "mp2"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   429
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   430
    if (tryCodecs("avi", "libxvid", "libmp3lame"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   431
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   432
    if (tryCodecs("avi", "libxvid", "ac3_fixed"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   433
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   434
    if (tryCodecs("avi", "libxvid", "mp2"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   435
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   436
    if (tryCodecs("avi", "mpeg4", "libmp3lame"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   437
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   438
    if (tryCodecs("avi", "mpeg4", "ac3_fixed"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   439
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   440
    if (tryCodecs("avi", "mpeg4", "mp2"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   441
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   442
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   443
    // this shouldn't happen, just in case
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   444
    if (tryCodecs("ogg", "libtheora", "libvorbis"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   445
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   446
    tryCodecs("ogg", "libtheora", "flac");
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   449
void PageVideos::setDefaultOptions()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   450
{
7865
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   451
    framerateBox->setValue(30);
2edc88e9fcd6 increase framerate and bitrate (issue 427)
koda
parents: 7794
diff changeset
   452
    bitrateBox->setValue(1000);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   453
    checkRecordAudio->setChecked(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   454
    checkUseGameRes->setChecked(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   455
    setDefaultCodecs();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   456
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   457
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   458
bool PageVideos::tryCodecs(const QString & format, const QString & vcodec, const QString & acodec)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   459
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   460
    // first we should change format
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   461
    int iFormat = comboAVFormats->findData(format);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   462
    if (iFormat == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   463
        return false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   464
    comboAVFormats->setCurrentIndex(iFormat);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   465
    // format was changed, so lists of codecs were automatically updated to codecs supported by this format
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   466
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   467
    // try to find video codec
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   468
    int iVCodec = comboVideoCodecs->findData(vcodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   469
    if (iVCodec == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   470
        return false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   471
    comboVideoCodecs->setCurrentIndex(iVCodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   472
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   473
    // try to find audio codec
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   474
    int iACodec = comboAudioCodecs->findData(acodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   475
    if (iACodec == -1 && checkRecordAudio->isChecked())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   476
        return false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   477
    if (iACodec != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   478
        comboAudioCodecs->setCurrentIndex(iACodec);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   479
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   480
    return true;
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
// get file size as string
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   484
static QString FileSizeStr(const QString & path)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   485
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   486
    quint64 size = QFileInfo(path).size();
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
    quint64 KiB = 1024;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   489
    quint64 MiB = 1024*KiB;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   490
    quint64 GiB = 1024*MiB;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   491
    QString sizeStr;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   492
    if (size >= GiB)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   493
        return QString("%1 GiB").arg(QString::number(float(size)/GiB, 'f', 2));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   494
    if (size >= MiB)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   495
        return QString("%1 MiB").arg(QString::number(float(size)/MiB, 'f', 2));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   496
     if (size >= KiB)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   497
        return QString("%1 KiB").arg(QString::number(float(size)/KiB, 'f', 2));
7680
46a91cbed8db - Some improvements to tr() calls
unc0rr
parents: 7679
diff changeset
   498
    return PageVideos::tr("%1 bytes", "", size).arg(QString::number(size));
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   499
}
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
// set file size in file list in specified row
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   502
void PageVideos::updateSize(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   503
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   504
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   505
    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
   506
    filesTable->item(row, vcSize)->setText(FileSizeStr(path));
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
// 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
   510
// 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
   511
void PageVideos::updateFileList(const QString & path)
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
    // mark all files as non seen
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   514
    int numRows = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   515
    for (int i = 0; i < numRows; i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   516
        nameItem(i)->seen = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   517
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   518
    QStringList files = QDir(path).entryList(QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   519
    foreach (const QString & name, files)
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
        int row = -1;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   522
        foreach (QTableWidgetItem * item, filesTable->findItems(name, Qt::MatchExactly))
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
            if (item->type() != QTableWidgetItem::UserType || !((VideoItem*)item)->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   525
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   526
            row = item->row();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   527
            break;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   528
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   529
        if (row == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   530
            row = appendRow(name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   531
        VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   532
        item->seen = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   533
        item->desc = "";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   534
        updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   535
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   536
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   537
    // remove all non seen files
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   538
    for (int i = 0; i < filesTable->rowCount();)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   539
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   540
        VideoItem * item = nameItem(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   541
        if (item->ready() && !item->seen)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   542
            filesTable->removeRow(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   543
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   544
            i++;
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
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   547
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   548
void PageVideos::addRecorder(HWRecorder* pRecorder)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   549
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   550
    int row = appendRow(pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   551
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   552
    item->pRecorder = pRecorder;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   553
    pRecorder->item = item;
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
    // add progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   556
    QProgressBar * progressBar = new QProgressBar(filesTable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   557
    progressBar->setMinimum(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   558
    progressBar->setMaximum(10000);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   559
    progressBar->setValue(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   560
    connect(pRecorder, SIGNAL(onProgress(float)), this, SLOT(updateProgress(float)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   561
    connect(pRecorder, SIGNAL(encodingFinished(bool)), this, SLOT(encodingFinished(bool)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   562
    filesTable->setCellWidget(row, vcProgress, progressBar);
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
    numRecorders++;
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   567
void PageVideos::setProgress(int row, VideoItem* item, float value)
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
    QProgressBar * progressBar = (QProgressBar*)filesTable->cellWidget(row, vcProgress);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   570
    progressBar->setValue(value*10000);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   571
    progressBar->setFormat(QString("%1%").arg(value*100, 0, 'f', 2));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   572
    item->progress = value;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   573
}
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
void PageVideos::updateProgress(float value)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   576
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   577
    HWRecorder * pRecorder = (HWRecorder*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   578
    VideoItem * item = pRecorder->item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   579
    int row = filesTable->row(item);
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
    // update file size every percent
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   582
    if (value - item->lastSizeUpdate > 0.01)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   583
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   584
        updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   585
        item->lastSizeUpdate = value;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   586
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   587
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   588
    setProgress(row, item, value);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   589
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   590
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   591
void PageVideos::encodingFinished(bool success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   592
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   593
    numRecorders--;
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
    HWRecorder * pRecorder = (HWRecorder*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   596
    VideoItem * item = (VideoItem*)pRecorder->item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   597
    int row = filesTable->row(item);
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
    if (success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   600
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   601
        // move file to destination
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   602
        success = cfgdir->rename("VideoTemp/" + pRecorder->name, "Videos/" + item->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   603
        if (!success)
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
            // 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
   606
            // try to use temp name instead.
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   607
            success = cfgdir->rename("VideoTemp/" + pRecorder->name, "Videos/" + pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   608
            if (success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   609
                setName(item, pRecorder->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   610
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   611
    }
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
    if (!success)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   614
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   615
        filesTable->removeRow(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   616
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   617
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   618
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   619
    filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   620
    item->pRecorder = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   621
    updateSize(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   622
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   623
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   624
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   625
void PageVideos::cellDoubleClicked(int row, int column)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   626
{
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   627
    Q_UNUSED(column);
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   628
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   629
    play(row);
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   632
void PageVideos::cellChanged(int row, int column)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   633
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   634
    // user can only edit name
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   635
    if (column != vcName || nameChangedFromCode)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   636
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   637
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   638
    // 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
   639
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   640
    QString oldName = item->name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   641
    QString newName = item->text();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   642
    if (!newName.contains('.')) // user forgot an extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   643
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   644
        // restore old extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   645
        int pt = oldName.lastIndexOf('.');
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   646
        if (pt != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   647
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   648
            newName += oldName.right(oldName.length() - pt);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   649
            setName(item, newName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   650
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   651
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   652
#ifdef Q_WS_WIN
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   653
    // 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
   654
    if (newName.contains(QRegExp("[\"*:<>?\\/|]")))
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   655
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   656
        setName(item, oldName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   657
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   658
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   659
#endif
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   660
    if (item->ready() && !cfgdir->rename("Videos/" + oldName, "Videos/" + newName))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   661
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   662
        // 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
   663
        // therefore restore old name in cell
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   664
        setName(item, oldName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   665
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   666
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   667
    item->name = newName;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   668
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   669
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   670
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   671
void PageVideos::setName(VideoItem * item, const QString & newName)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   672
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   673
    nameChangedFromCode = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   674
    item->setText(newName);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   675
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   676
    item->name = newName;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   677
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   678
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   679
int PageVideos::appendRow(const QString & name)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   680
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   681
    int row = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   682
    filesTable->setRowCount(row+1);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   683
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   684
    // add 'name' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   685
    QTableWidgetItem * item = new VideoItem(name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   686
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   687
    nameChangedFromCode = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   688
    filesTable->setItem(row, vcName, item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   689
    nameChangedFromCode = false;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   690
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   691
    // add 'size' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   692
    item = new QTableWidgetItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   693
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   694
    item->setTextAlignment(Qt::AlignRight);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   695
    filesTable->setItem(row, vcSize, item);
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
    // add 'progress' item
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   698
    item = new QTableWidgetItem();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   699
    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   700
    filesTable->setItem(row, vcProgress, item);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   701
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   702
    return row;
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   705
VideoItem* PageVideos::nameItem(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   706
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   707
    return (VideoItem*)filesTable->item(row, vcName);
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   710
void PageVideos::clearThumbnail()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   711
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   712
    // add empty (transparent) image for proper sizing
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   713
    QPixmap pic(ThumbnailSize);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   714
    pic.fill(QColor(0,0,0,0));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   715
    labelThumbnail->setPixmap(pic);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   716
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   717
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   718
void PageVideos::updateDescription()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   719
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   720
    VideoItem * item = nameItem(filesTable->currentRow());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   721
    if (!item)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   722
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   723
        // nothing is selected => clear description and return
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   724
        labelDesc->clear();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   725
        clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   726
        btnPlay->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   727
        btnDelete->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   728
        btnToYouTube->setEnabled(false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   729
        return;
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
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   732
    btnPlay->setEnabled(item->ready());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   733
    btnToYouTube->setEnabled(item->ready());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   734
    btnDelete->setEnabled(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   735
    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
   736
    btnToYouTube->setText(item->pUploading? QPushButton::tr("Cancel uploading") :  QPushButton::tr("Upload to YouTube"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   737
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   738
    // 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
   739
    QString desc = item->name + "\n\n";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   740
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   741
    if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   742
        desc += tr("(in progress...)");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   743
    else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   744
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   745
        QString path = item->path();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   746
        desc += tr("Date: ") + QFileInfo(path).created().toString(Qt::DefaultLocaleLongDate) + '\n';
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   747
        desc += tr("Size: ") + FileSizeStr(path) + '\n';
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   748
        if (item->desc.isEmpty())
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
            // Extract description from file;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   751
            // It will contain duration, resolution, etc and also comment added by hwengine.
7897
5e7c0810f365 libav name refactor
koda
parents: 7881
diff changeset
   752
            item->desc = LibavInteraction::instance().getFileInfo(path);
7631
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
            // 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
   755
            int prefixBegin = item->desc.indexOf("prefix[");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   756
            int prefixEnd   = item->desc.indexOf("]prefix");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   757
            if (prefixBegin != -1 && prefixEnd != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   758
            {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   759
                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
   760
                item->desc.remove(prefixBegin, prefixEnd + 7 - prefixBegin);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   761
            }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   762
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   763
        desc += item->desc + '\n';
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   764
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   765
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   766
    if (item->prefix.isEmpty())
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
        // try to extract prefix from file name instead
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   769
        if (item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   770
            item->prefix = item->name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   771
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   772
            item->prefix = item->pRecorder->name;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   773
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   774
        // remove extension
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   775
        int pt = item->prefix.lastIndexOf('.');
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   776
        if (pt != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   777
            item->prefix.truncate(pt);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   778
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   779
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   780
    if (item->ready() && item->uploadUrl.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   781
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   782
        // try to load url from file
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   783
        QFile * file = new QFile(cfgdir->absoluteFilePath("VideoTemp/" + item->prefix + "-url.txt"), this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   784
        if (!file->open(QIODevice::ReadOnly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   785
            item->uploadUrl = "no";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   786
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   787
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   788
            QByteArray data = file->readAll();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   789
            file->close();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   790
            item->uploadUrl = QString::fromUtf8(data.data());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   791
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   792
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   793
    if (item->uploadUrl != "no")
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   794
        desc += QString("<a href=\"%1\" style=\"color: white;\">%1</a>").arg(item->uploadUrl);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   795
    desc.replace("\n", "<br/>");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   796
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   797
    labelDesc->setText(desc);
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
    if (!item->prefix.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   800
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   801
        QString thumbName = cfgdir->absoluteFilePath("VideoTemp/" + item->prefix);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   802
        QPixmap pic;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   803
        if (pic.load(thumbName + ".png") || pic.load(thumbName + ".bmp"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   804
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   805
            if (pic.height()*ThumbnailSize.width() > pic.width()*ThumbnailSize.height())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   806
                pic = pic.scaledToWidth(ThumbnailSize.width());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   807
            else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   808
                pic = pic.scaledToHeight(ThumbnailSize.height());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   809
            labelThumbnail->setPixmap(pic);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   810
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   811
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   812
            clearThumbnail();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   813
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   814
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   815
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   816
// user selected another cell, so we should change description
7679
bfa26daad684 - Fix some warnings in frontend
unc0rr
parents: 7633
diff changeset
   817
void PageVideos::currentCellChanged()
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   818
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   819
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   820
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   821
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   822
// open video file in external media player
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   823
void PageVideos::play(int row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   824
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   825
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   826
    if (item && item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   827
        QDesktopServices::openUrl(QUrl("file:///" + QDir::toNativeSeparators(item->path())));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   828
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   829
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   830
void PageVideos::playSelectedFile()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   831
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   832
    int index = filesTable->currentRow();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   833
    if (index != -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   834
        play(index);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   835
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   836
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   837
void PageVideos::deleteSelectedFiles()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   838
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   839
    int index = filesTable->currentRow();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   840
    if (index == -1)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   841
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   842
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   843
    VideoItem * item = nameItem(index);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   844
    if (!item)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   845
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   846
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   847
    // 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
   848
    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
   849
    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
   850
    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
   851
    reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the video '%1'?").arg(item->name));
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
   852
    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
   853
    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
   854
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
   855
    if (reallyDeleteMsg.exec() != QMessageBox::Ok)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   856
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   857
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   858
    // remove
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   859
    if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   860
        item->pRecorder->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   861
    else
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   862
    {
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   863
        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
   864
        // we have no idea whether screenshot is going to be bmp or png so let's delete both
7881
3ac3ff6c7c4f use VideoItem::prefix instead of VideoItem::name as suggested by Stepan777
koda
parents: 7867
diff changeset
   865
        cfgdir->remove("VideoTemp/" + item->prefix + ".png");
3ac3ff6c7c4f use VideoItem::prefix instead of VideoItem::name as suggested by Stepan777
koda
parents: 7867
diff changeset
   866
        cfgdir->remove("VideoTemp/" + item->prefix + ".bmp");
7867
a691fd5f98f8 add videorec button descriptions and delete screenshot when video is deleted (issue 427)
koda
parents: 7865
diff changeset
   867
    }
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   868
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   869
// 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
   870
#if 0
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   871
    QList<QTableWidgetItem*> items = filesTable->selectedItems();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   872
    int num = items.size() / vcNumColumns;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   873
    if (num == 0)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   874
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   875
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   876
    // 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
   877
    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
   878
    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
   879
    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
   880
    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
   881
    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
   882
    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
   883
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
   884
    if (reallyDeleteMsg.exec() != QMessageBox::Ok)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   885
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   886
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   887
    // remove
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   888
    foreach (QTableWidgetItem * witem, items)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   889
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   890
        if (witem->type() != QTableWidgetItem::UserType)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   891
            continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   892
        VideoItem * item = (VideoItem*)witem;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   893
        if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   894
            item->pRecorder->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   895
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   896
            cfgdir->remove("Videos/" + item->name);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   897
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   898
#endif
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   899
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   900
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   901
void PageVideos::keyPressEvent(QKeyEvent * pEvent)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   902
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   903
    if (filesTable->hasFocus())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   904
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   905
        if (pEvent->key() == Qt::Key_Delete)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   906
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   907
            deleteSelectedFiles();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   908
            return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   909
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   910
        if (pEvent->key() == Qt::Key_Enter) // doesn't work
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   911
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   912
            playSelectedFile();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   913
            return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   914
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   915
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   916
    AbstractPage::keyPressEvent(pEvent);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   917
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   918
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   919
void PageVideos::openVideosDirectory()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   920
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   921
    QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Videos");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   922
    QDesktopServices::openUrl(QUrl("file:///" + path));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   923
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   924
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   925
// clear VideoTemp directory (except for thumbnails and upload links)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   926
void PageVideos::clearTemp()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   927
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   928
    QDir temp(cfgdir->absolutePath() + "/VideoTemp");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   929
    QStringList files = temp.entryList(QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   930
    foreach (const QString& file, files)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   931
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   932
        if (!file.endsWith(".bmp") && !file.endsWith(".png") && !file.endsWith("-url.txt"))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   933
            temp.remove(file);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   934
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   935
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   936
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   937
bool PageVideos::tryQuit(HWForm * form)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   938
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   939
    bool quit = true;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   940
    if (numRecorders != 0 || numUploads != 0)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   941
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   942
        // ask user what to do - abort or wait
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   943
        HWAskQuitDialog * askd = new HWAskQuitDialog(this, form);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   944
        askd->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   945
        quit = askd->exec();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   946
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   947
    if (quit)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   948
        clearTemp();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   949
    return quit;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   950
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   951
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   952
// 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
   953
/* it will look like this:
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   954
foo.avi (15.21% - encoding)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   955
bar.avi (18.21% - uploading)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   956
*/
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   957
QString PageVideos::getVideosInProgress()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   958
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   959
    QString list = "";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   960
    int count = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   961
    for (int i = 0; i < count; i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   962
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   963
        VideoItem * item = nameItem(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   964
        QString process;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   965
        if (!item->ready())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   966
            process = tr("encoding");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   967
        else if (item->pUploading)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   968
            process = tr("uploading");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   969
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   970
            continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   971
        float progress = 100*item->progress;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   972
        if (progress > 99.99)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   973
            progress = 99.99; // displaying 100% may be confusing
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   974
        list += item->name + " (" + QString::number(progress, 'f', 2) + "% - " + process + ")\n";
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   975
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   976
    return list;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   977
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   978
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   979
void PageVideos::startEncoding(const QByteArray & record)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   980
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   981
    QDir videoTempDir(cfgdir->absolutePath() + "/VideoTemp/");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   982
    QStringList files = videoTempDir.entryList(QStringList("*.txtout"), QDir::Files);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   983
    foreach (const QString & str, files)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   984
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   985
        QString prefix = str;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   986
        prefix.chop(7); // remove ".txtout"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   987
        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
   988
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   989
        HWRecorder* pRecorder = new HWRecorder(config, prefix);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   990
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   991
        if (!record.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   992
            pRecorder->EncodeVideo(record);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   993
        else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   994
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   995
            // 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
   996
            QFile demofile(videoTempDir.absoluteFilePath(prefix + ".hwd"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   997
            if (!demofile.open(QIODevice::ReadOnly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   998
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
   999
            QByteArray demo = demofile.readAll();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1000
            if (demo.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1001
                continue;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1002
            pRecorder->EncodeVideo(demo);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1003
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1004
        addRecorder(pRecorder);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1005
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1006
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1007
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1008
VideoItem * PageVideos::itemFromReply(QNetworkReply* reply, int & row)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1009
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1010
    VideoItem * item = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1011
    int count = filesTable->rowCount();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1012
    // find corresponding item (maybe there is a better way to implement this?)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1013
    for (int i = 0; i < count; i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1014
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1015
        item = nameItem(i);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1016
        if (item->pUploading == reply)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1017
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1018
            row = i;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1019
            break;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1020
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1021
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1022
    return item;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1023
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1024
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1025
void PageVideos::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1026
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1027
    QNetworkReply* reply = (QNetworkReply*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1028
    int row;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1029
    VideoItem * item = itemFromReply(reply, row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1030
    setProgress(row, item, bytesSent*1.0/bytesTotal);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1031
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1032
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1033
void PageVideos::uploadFinished()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1034
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1035
    QNetworkReply* reply = (QNetworkReply*)sender();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1036
    reply->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1037
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1038
    int row;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1039
    VideoItem * item = itemFromReply(reply, row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1040
    if (!item)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1041
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1042
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1043
    item->pUploading = NULL;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1044
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1045
    // extract video id from reply
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1046
    QString videoid;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1047
    QXmlStreamReader xml(reply);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1048
    while (!xml.atEnd())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1049
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1050
        xml.readNext();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1051
        if (xml.qualifiedName() == "yt:videoid")
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1052
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1053
            videoid = xml.readElementText();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1054
            break;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1055
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1056
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1057
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1058
    if (!videoid.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1059
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1060
        item->uploadUrl = "http://youtu.be/" + videoid;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1061
        updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1062
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1063
        // save url in file
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1064
        QFile * file = new QFile(cfgdir->absoluteFilePath("VideoTemp/" + item->prefix + "-url.txt"), this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1065
        if (file->open(QIODevice::WriteOnly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1066
        {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1067
            file->write(item->uploadUrl.toUtf8());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1068
            file->close();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1069
        }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1070
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1071
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1072
    filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1073
    numUploads--;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1074
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1075
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1076
// this will protect saved youtube password from those who cannot read source code
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1077
static QString protectPass(QString str)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1078
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1079
    QByteArray array = str.toUtf8();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1080
    for (int i = 0; i < array.size(); i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1081
        array[i] = array[i] ^ 0xC4 ^ i;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1082
    array = array.toBase64();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1083
    return QString::fromAscii(array.data());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1084
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1085
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1086
static QString unprotectPass(QString str)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1087
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1088
    QByteArray array = QByteArray::fromBase64(str.toAscii());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1089
    for (int i = 0; i < array.size(); i++)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1090
        array[i] = array[i] ^ 0xC4 ^ i;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1091
    return QString::fromUtf8(array);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1092
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1093
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1094
void PageVideos::uploadToYouTube()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1095
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1096
    int row = filesTable->currentRow();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1097
    VideoItem * item = nameItem(row);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1098
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1099
    if (item->pUploading)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1100
    {
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
  1101
        // ask user if (s)he is serious
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
  1102
        QMessageBox reallyStopMsg(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
  1103
        reallyStopMsg.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
  1104
        reallyStopMsg.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
  1105
        reallyStopMsg.setText(QMessageBox::tr("Do you really want to cancel uploading %1?").arg(item->name));
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
  1106
        reallyStopMsg.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
  1107
        reallyStopMsg.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
  1108
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
  1109
        if (reallyStopMsg.exec() != QMessageBox::Ok)
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1110
            return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1111
        item->pUploading->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1112
        filesTable->setCellWidget(row, vcProgress, NULL); // remove progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1113
        numUploads--;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1114
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1115
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1116
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1117
    if (!netManager)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1118
        netManager = new QNetworkAccessManager(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1119
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1120
    HWUploadVideoDialog* dlg = new HWUploadVideoDialog(this, item->name, netManager);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1121
    dlg->deleteLater();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1122
    if (config->value("youtube/save").toBool())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1123
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1124
        dlg->cbSave->setChecked(true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1125
        dlg->leAccount->setText(config->value("youtube/name").toString());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1126
        dlg->lePassword->setText(unprotectPass(config->value("youtube/pswd").toString()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1127
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1128
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1129
    bool result = dlg->exec();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1130
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1131
    if (dlg->cbSave->isChecked())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1132
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1133
        config->setValue("youtube/save", true);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1134
        config->setValue("youtube/name", dlg->leAccount->text());
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1135
        config->setValue("youtube/pswd", protectPass(dlg->lePassword->text()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1136
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1137
    else
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1138
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1139
        config->setValue("youtube/save", false);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1140
        config->setValue("youtube/name", "");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1141
        config->setValue("youtube/pswd", "");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1142
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1143
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1144
    if (!result)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1145
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1146
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1147
    QNetworkRequest request(QUrl(dlg->location));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1148
    request.setRawHeader("Content-Type", "application/octet-stream");
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1149
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1150
    QFile * file = new QFile(item->path(), this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1151
    if (!file->open(QIODevice::ReadOnly))
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1152
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1153
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1154
    // add progress bar
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1155
    QProgressBar * progressBar = new QProgressBar(filesTable);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1156
    progressBar->setMinimum(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1157
    progressBar->setMaximum(10000);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1158
    progressBar->setValue(0);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1159
    // make it different from progress-bar used during encoding (use blue color)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1160
    progressBar->setStyleSheet("* {color: #00ccff; selection-background-color: #00ccff;}" );
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1161
    filesTable->setCellWidget(row, vcProgress, progressBar);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1162
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1163
    QNetworkReply* reply = netManager->put(request, file);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1164
    file->setParent(reply); // automatically close file when needed
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1165
    item->pUploading = reply;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1166
    connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64)));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1167
    connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1168
    numUploads++;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1169
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1170
    updateDescription();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7531
diff changeset
  1171
}