QTfrontend/ui/dialog/upload_video.cpp
author Stepan777 <stepik-777@mail.ru>
Sun, 12 Aug 2012 23:05:15 +0400
changeset 7544 a72ace943bfd
parent 7531 0adcad8714c4
child 7631 01b599d6f72d
permissions -rw-r--r--
minor changes in list of codecs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     1
/*
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     4
 *
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     8
 *
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    13
 *
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    17
 */
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    18
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    19
#include <QLineEdit>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    20
#include <QDialogButtonBox>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    21
#include <QPushButton>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    22
#include <QGridLayout>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    23
#include <QCheckBox>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    24
#include <QLabel>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    25
#include <QFrame>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    26
#include <QPlainTextEdit>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    27
#include <QSslError>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    28
#include <QUrl>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    29
#include <QNetworkAccessManager>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    30
#include <QNetworkRequest>
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    31
#include <QNetworkReply>
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    32
#include <QMessageBox>
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    33
#include <QRegExp>
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    34
#include <QRegExpValidator>
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    35
#include <QMessageBox>
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    36
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    37
#include "upload_video.h"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    38
#include "hwconsts.h"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    39
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    40
// User-agent string used in http requests.
7528
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
    41
// Don't make it a global varibale - crash on linux because of cVersionString
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
    42
#define USER_AGENT ("Hedgewars-QtFrontend/" + *cVersionString).toAscii()
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    43
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    44
// This is developer key obtained from http://code.google.com/apis/youtube/dashboard/
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    45
// If you are reusing this code outside Hedgewars, don't use this developer key,
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    46
// obtain you own at http://code.google.com/apis/youtube/dashboard/
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    47
static const QByteArray devKey = "AI39si5pKjxR0XgNIlmrEFF-LyYD31rps4g2O5dZTxLgD0fvJ2rHxrMrNFY8FYTZrzeI3VlaFVQLKfFnSBugvdZmy8vFzRDefQ";
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    48
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    49
HWUploadVideoDialog::HWUploadVideoDialog(QWidget* parent, const QString &filename, QNetworkAccessManager* netManager) : QDialog(parent)
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    50
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    51
    this->filename = filename;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    52
    this->netManager = netManager;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    53
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    54
    setWindowTitle(tr("Upload video"));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    55
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    56
    // Google requires us to display this, see https://developers.google.com/youtube/terms
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    57
    QString GoogleNotice =
7531
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
    58
        "<p>By clicking 'upload,' you certify that you own all rights to the content or that "
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    59
        "you are authorized by the owner to make the content publicly available on YouTube, "
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    60
        "and that it otherwise complies with the YouTube Terms of Service located at "
7531
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
    61
        "<a href=\"http://www.youtube.com/t/terms\" style=\"color: white;\">http://www.youtube.com/t/terms</a>.</p>";
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    62
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    63
    // youtube doesn't understand this characters, even when they are properly escaped
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    64
    // (either with CDATA or with &lt or &gt)
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    65
    QRegExp rx("[^<>]*");
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    66
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    67
    int row = 0;
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    68
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    69
    QGridLayout * layout = new QGridLayout(this);
7531
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
    70
    layout->setColumnStretch(0, 1);
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
    71
    layout->setColumnStretch(1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    72
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    73
    QLabel * lbLabel = new QLabel(this);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    74
    lbLabel->setWordWrap(true);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    75
    lbLabel->setText(QLabel::tr(
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    76
                         "Please provide either the YouTube account name "
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    77
                         "or the email address associated with the Google Account."));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    78
    layout->addWidget(lbLabel, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    79
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    80
    lbLabel = new QLabel(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    81
    lbLabel->setText(QLabel::tr("Account name (or email): "));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    82
    layout->addWidget(lbLabel, row, 0);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    83
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    84
    leAccount = new QLineEdit(this);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    85
    layout->addWidget(leAccount, row++, 1);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    86
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    87
    lbLabel = new QLabel(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    88
    lbLabel->setText(QLabel::tr("Password: "));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    89
    layout->addWidget(lbLabel, row, 0);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    90
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    91
    lePassword = new QLineEdit(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    92
    lePassword->setEchoMode(QLineEdit::Password);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    93
    layout->addWidget(lePassword, row++, 1);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    94
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    95
    cbSave = new QCheckBox(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    96
    cbSave->setText(QCheckBox::tr("Save account name and password"));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
    97
    layout->addWidget(cbSave, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    98
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    99
    QFrame * hr = new QFrame(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   100
    hr->setFrameStyle(QFrame::HLine);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   101
    hr->setLineWidth(3);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   102
    hr->setFixedHeight(10);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   103
    layout->addWidget(hr, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   104
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   105
    lbLabel = new QLabel(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   106
    lbLabel->setText(QLabel::tr("Video title: "));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   107
    layout->addWidget(lbLabel, row, 0);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   108
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   109
    leTitle = new QLineEdit(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   110
    leTitle->setText(filename);
7528
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
   111
    leTitle->setValidator(new QRegExpValidator(rx, leTitle));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   112
    layout->addWidget(leTitle, row++, 1);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   113
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   114
    lbLabel = new QLabel(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   115
    lbLabel->setText(QLabel::tr("Video description: "));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   116
    layout->addWidget(lbLabel, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   117
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   118
    teDescription = new QPlainTextEdit(this);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   119
    layout->addWidget(teDescription, row++, 0, 1, 2);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   120
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   121
    lbLabel = new QLabel(this);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   122
    lbLabel->setText(QLabel::tr("Tags (comma separated): "));
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   123
    layout->addWidget(lbLabel, row, 0);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   124
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   125
    leTags = new QLineEdit(this);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   126
    leTags->setText("hedgewars");
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   127
    leTags->setMaxLength(500);
7528
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
   128
    leTags->setValidator(new QRegExpValidator(rx, leTags));
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   129
    layout->addWidget(leTags, row++, 1);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   130
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   131
    cbPrivate = new QCheckBox(this);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   132
    cbPrivate->setText(QCheckBox::tr("Video is private"));
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   133
    layout->addWidget(cbPrivate, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   134
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   135
    hr = new QFrame(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   136
        hr->setFrameStyle(QFrame::HLine);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   137
        hr->setLineWidth(3);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   138
        hr->setFixedHeight(10);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   139
        layout->addWidget(hr, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   140
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   141
    lbLabel = new QLabel(this);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   142
    lbLabel->setWordWrap(true);
7531
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   143
    lbLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   144
    lbLabel->setTextFormat(Qt::RichText);
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   145
    lbLabel->setOpenExternalLinks(true);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   146
    lbLabel->setText(GoogleNotice);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   147
    layout->addWidget(lbLabel, row++, 0, 1, 2);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   148
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   149
    QDialogButtonBox* dbbButtons = new QDialogButtonBox(this);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   150
    btnUpload = dbbButtons->addButton(tr("Upload"), QDialogButtonBox::ActionRole);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   151
    QPushButton * pbCancel = dbbButtons->addButton(QDialogButtonBox::Cancel);
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   152
    layout->addWidget(dbbButtons, row++, 0, 1, 2);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   153
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   154
   /* hr = new QFrame(this);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   155
        hr->setFrameStyle(QFrame::HLine);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   156
        hr->setLineWidth(3);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   157
        hr->setFixedHeight(10);
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   158
        layout->addWidget(hr, row++, 0, 1, 2);*/
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   159
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   160
    connect(btnUpload, SIGNAL(clicked()), this, SLOT(upload()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   161
    connect(pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   162
}
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   163
7531
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   164
void HWUploadVideoDialog::showEvent(QShowEvent * event)
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   165
{
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   166
    QDialog::showEvent(event);
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   167
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   168
    // set width to the same value as height (otherwise dialog has too small width)
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   169
    QSize s = size();
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   170
    QPoint p = pos();
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   171
    resize(s.height(), s.height());
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   172
    move(p.x() - (s.height() - s.width())/2, p.y());
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   173
}
0adcad8714c4 improve html links + small bugfixes
Stepan777 <stepik-777@mail.ru>
parents: 7528
diff changeset
   174
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   175
void HWUploadVideoDialog::setEditable(bool editable)
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   176
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   177
    leTitle->setEnabled(editable);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   178
    leAccount->setEnabled(editable);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   179
    lePassword->setEnabled(editable);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   180
    btnUpload->setEnabled(editable);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   181
}
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   182
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   183
void HWUploadVideoDialog::upload()
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   184
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   185
    setEditable(false);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   186
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   187
    // Documentation is at https://developers.google.com/youtube/2.0/developers_guide_protocol_clientlogin#ClientLogin_Authentication
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   188
    QNetworkRequest request;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   189
    request.setUrl(QUrl("https://www.google.com/accounts/ClientLogin"));
7528
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
   190
    request.setRawHeader("User-Agent", USER_AGENT);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   191
    request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   192
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   193
    QString account(QUrl::toPercentEncoding(leAccount->text()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   194
    QString pass(QUrl::toPercentEncoding(lePassword->text()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   195
    QByteArray data = QString("Email=%1&Passwd=%2&service=youtube&source=Hedgewars").arg(account).arg(pass).toAscii();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   196
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   197
    QNetworkReply *reply = netManager->post(request, data);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   198
    connect(reply, SIGNAL(finished()), this, SLOT(authFinished()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   199
}
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   200
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   201
static QString XmlEscape(const QString& str)
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   202
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   203
    QString str2 = str;
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   204
    // youtube doesn't understand this characters, even when they are properly escaped
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   205
    // (either with CDATA or with &lt; &gt;)
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   206
    str2.replace('<', ' ').replace('>', ' ');
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   207
    return "<![CDATA[" + str2.replace("]]>", "]]]]><![CDATA[>") + "]]>";
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   208
}
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   209
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   210
void HWUploadVideoDialog::authFinished()
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   211
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   212
    QNetworkReply *reply = (QNetworkReply*)sender();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   213
    reply->deleteLater();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   214
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   215
    int HttpCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   216
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   217
    QByteArray answer = reply->readAll();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   218
    QString authToken = "";
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   219
    QList<QByteArray> lines = answer.split('\n');
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   220
    foreach (const QByteArray& line, lines)
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   221
    {
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   222
        QString str(line);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   223
        if (!str.startsWith("Auth=", Qt::CaseInsensitive))
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   224
            continue;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   225
        str.remove(0, 5);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   226
        authToken = str;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   227
        break;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   228
    }
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   229
    if (authToken.isEmpty())
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   230
    {
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   231
        QString errorStr = QMessageBox::tr("Error while authenticating at google.com:\n");
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   232
        if (HttpCode == 403)
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   233
            errorStr += QMessageBox::tr("Login or password is incorrect");
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   234
        else
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   235
            errorStr += reply->errorString();
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   236
        QMessageBox::warning(this, QMessageBox::tr("Error"), errorStr);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   237
        setEditable(true);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   238
        return;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   239
    }
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   240
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   241
    QByteArray auth = ("GoogleLogin auth=" + authToken).toAscii();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   242
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   243
    // We have authenticated, now we can send metadata and start upload
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   244
    // Documentation is here: https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads#Resumable_uploads
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   245
    QByteArray body =
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   246
            "<?xml version=\"1.0\"?>"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   247
            "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   248
                "xmlns:media=\"http://search.yahoo.com/mrss/\" "
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   249
                "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   250
                "<media:group>"
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   251
                  //  "<yt:incomplete/>"
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   252
                    "<media:category "
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   253
                        "scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">Games"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   254
                    "</media:category>"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   255
                    "<media:title type=\"plain\">"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   256
                        + XmlEscape(leTitle->text()).toUtf8() +
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   257
                    "</media:title>"
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   258
                    "<media:description type=\"plain\">"
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   259
                        + XmlEscape(teDescription->toPlainText()).toUtf8() +
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   260
                    "</media:description>"
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   261
                    "<media:keywords type=\"plain\">"
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   262
                        + XmlEscape(leTags->text()).toUtf8() +
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   263
                    "</media:keywords>"
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   264
                    + (cbPrivate->isChecked()? "<yt:private/>" : "") +
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   265
                "</media:group>"
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   266
            "</entry>";
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   267
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   268
    QNetworkRequest request;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   269
    request.setUrl(QUrl("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"));
7528
f8cf277dca36 FindFFMPEG.cmake (used only for frontend for now).
Stepan777 <stepik-777@mail.ru>
parents: 7507
diff changeset
   270
    request.setRawHeader("User-Agent", USER_AGENT);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   271
    request.setRawHeader("Authorization", auth);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   272
    request.setRawHeader("GData-Version", "2");
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   273
    request.setRawHeader("X-GData-Key", "key=" + devKey);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   274
    request.setRawHeader("Slug", filename.toUtf8());
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   275
    request.setRawHeader("Content-Type", "application/atom+xml; charset=UTF-8");
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   276
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   277
    reply = netManager->post(request, body);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   278
    connect(reply, SIGNAL(finished()), this, SLOT(startUpload()));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   279
}
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   280
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   281
void HWUploadVideoDialog::startUpload()
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   282
{
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   283
    QNetworkReply *reply = (QNetworkReply*)sender();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   284
    reply->deleteLater();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   285
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   286
    location = QString::fromAscii(reply->rawHeader("Location"));
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   287
    if (location.isEmpty())
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   288
    {
7507
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   289
        QString errorStr = QMessageBox::tr("Error while sending metadata to youtube.com:\n");
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   290
        errorStr += reply->errorString();
3032a5739fe1 improve video uploading
Stepan777 <stepik-777@mail.ru>
parents: 7447
diff changeset
   291
        QMessageBox::warning(this, QMessageBox::tr("Error"), errorStr);
7447
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   292
        setEditable(true);
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   293
        return;
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   294
    }
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   295
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   296
    accept();
01111960a48d uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   297
}