author | Stepan777 <stepik-777@mail.ru> |
Mon, 06 Aug 2012 00:44:32 +0400 | |
changeset 7507 | 3032a5739fe1 |
parent 7447 | 01111960a48d |
child 7528 | f8cf277dca36 |
permissions | -rw-r--r-- |
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 | 32 |
#include <QMessageBox> |
33 |
#include <QRegExp> |
|
34 |
#include <QRegExpValidator> |
|
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. |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
41 |
static const QByteArray UserAgent = ("Hedgewars-QtFrontend/" + *cVersionString).toAscii(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
42 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
43 |
// 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
|
44 |
// 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
|
45 |
// 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
|
46 |
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
|
47 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
48 |
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
|
49 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
50 |
this->filename = filename; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
51 |
this->netManager = netManager; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
52 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
53 |
setWindowTitle(tr("Upload video")); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
54 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
55 |
// 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
|
56 |
QString GoogleNotice = |
7507 | 57 |
"By clicking 'upload,' you certify that you own all rights to the content or that " |
58 |
"you are authorized by the owner to make the content publicly available on YouTube, " |
|
59 |
"and that it otherwise complies with the YouTube Terms of Service located at " |
|
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
60 |
"http://www.youtube.com/t/terms."; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
61 |
|
7507 | 62 |
// youtube doesn't understand this characters, even when they are properly escaped |
63 |
// (either with CDATA or with < or >) |
|
64 |
QRegExp rx("[^<>]*"); |
|
65 |
||
66 |
int row = 0; |
|
67 |
||
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
68 |
QGridLayout * layout = new QGridLayout(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
69 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
70 |
QLabel * lbLabel = new QLabel(this); |
7507 | 71 |
lbLabel->setWordWrap(true); |
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
72 |
lbLabel->setText(QLabel::tr( |
7507 | 73 |
"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
|
74 |
"or the email address associated with the Google Account.")); |
7507 | 75 |
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
|
76 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
77 |
lbLabel = new QLabel(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
78 |
lbLabel->setText(QLabel::tr("Account name (or email): ")); |
7507 | 79 |
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
|
80 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
81 |
leAccount = new QLineEdit(this); |
7507 | 82 |
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
|
83 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
84 |
lbLabel = new QLabel(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
85 |
lbLabel->setText(QLabel::tr("Password: ")); |
7507 | 86 |
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
|
87 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
88 |
lePassword = new QLineEdit(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
89 |
lePassword->setEchoMode(QLineEdit::Password); |
7507 | 90 |
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
|
91 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
92 |
cbSave = new QCheckBox(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
93 |
cbSave->setText(QCheckBox::tr("Save account name and password")); |
7507 | 94 |
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
|
95 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
96 |
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
|
97 |
hr->setFrameStyle(QFrame::HLine); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
98 |
hr->setLineWidth(3); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
99 |
hr->setFixedHeight(10); |
7507 | 100 |
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
|
101 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
102 |
lbLabel = new QLabel(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
103 |
lbLabel->setText(QLabel::tr("Video title: ")); |
7507 | 104 |
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
|
105 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
106 |
leTitle = new QLineEdit(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
107 |
leTitle->setText(filename); |
7507 | 108 |
leTitle->setValidator(new QRegExpValidator(rx)); |
109 |
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
|
110 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
111 |
lbLabel = new QLabel(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
112 |
lbLabel->setText(QLabel::tr("Video description: ")); |
7507 | 113 |
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
|
114 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
115 |
teDescription = new QPlainTextEdit(this); |
7507 | 116 |
layout->addWidget(teDescription, row++, 0, 1, 2); |
117 |
||
118 |
lbLabel = new QLabel(this); |
|
119 |
lbLabel->setText(QLabel::tr("Tags (comma separated): ")); |
|
120 |
layout->addWidget(lbLabel, row, 0); |
|
121 |
||
122 |
leTags = new QLineEdit(this); |
|
123 |
leTags->setText("hedgewars"); |
|
124 |
leTags->setMaxLength(500); |
|
125 |
leTags->setValidator(new QRegExpValidator(rx)); |
|
126 |
layout->addWidget(leTags, row++, 1); |
|
127 |
||
128 |
cbPrivate = new QCheckBox(this); |
|
129 |
cbPrivate->setText(QCheckBox::tr("Video is private")); |
|
130 |
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
|
131 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
132 |
hr = new QFrame(this); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
133 |
hr->setFrameStyle(QFrame::HLine); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
134 |
hr->setLineWidth(3); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
135 |
hr->setFixedHeight(10); |
7507 | 136 |
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
|
137 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
138 |
lbLabel = new QLabel(this); |
7507 | 139 |
lbLabel->setWordWrap(true); |
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
140 |
lbLabel->setText(GoogleNotice); |
7507 | 141 |
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
|
142 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
QPushButton * pbCancel = dbbButtons->addButton(QDialogButtonBox::Cancel); |
7507 | 146 |
layout->addWidget(dbbButtons, row++, 0, 1, 2); |
147 |
||
148 |
/* hr = new QFrame(this); |
|
149 |
hr->setFrameStyle(QFrame::HLine); |
|
150 |
hr->setLineWidth(3); |
|
151 |
hr->setFixedHeight(10); |
|
152 |
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
|
153 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
157 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
158 |
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
|
159 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
160 |
leTitle->setEnabled(editable); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
161 |
leAccount->setEnabled(editable); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
162 |
lePassword->setEnabled(editable); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
163 |
btnUpload->setEnabled(editable); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
164 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
165 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
166 |
void HWUploadVideoDialog::upload() |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
167 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
168 |
setEditable(false); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
169 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
170 |
// 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
|
171 |
QNetworkRequest request; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
172 |
request.setUrl(QUrl("https://www.google.com/accounts/ClientLogin")); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
173 |
request.setRawHeader("User-Agent", UserAgent); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
174 |
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
|
175 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
183 |
|
7507 | 184 |
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
|
185 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
186 |
QString str2 = str; |
7507 | 187 |
// youtube doesn't understand this characters, even when they are properly escaped |
188 |
// (either with CDATA or with < >) |
|
189 |
str2.replace('<', ' ').replace('>', ' '); |
|
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
190 |
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
|
191 |
} |
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 |
void HWUploadVideoDialog::authFinished() |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
194 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
195 |
QNetworkReply *reply = (QNetworkReply*)sender(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
196 |
reply->deleteLater(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
197 |
|
7507 | 198 |
int HttpCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
199 |
||
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
200 |
QByteArray answer = reply->readAll(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
201 |
QString authToken = ""; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
205 |
QString str(line); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
206 |
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
|
207 |
continue; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
208 |
str.remove(0, 5); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
209 |
authToken = str; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
210 |
break; |
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 |
if (authToken.isEmpty()) |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
213 |
{ |
7507 | 214 |
QString errorStr = QMessageBox::tr("Error while authenticating at google.com:\n"); |
215 |
if (HttpCode == 403) |
|
216 |
errorStr += QMessageBox::tr("Login or password is incorrect"); |
|
217 |
else |
|
218 |
errorStr += reply->errorString(); |
|
219 |
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
|
220 |
setEditable(true); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
221 |
return; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
222 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
223 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
224 |
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
|
225 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
226 |
// 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
|
227 |
// 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
|
228 |
QByteArray body = |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
229 |
"<?xml version=\"1.0\"?>" |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
230 |
"<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
|
231 |
"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
|
232 |
"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
|
233 |
"<media:group>" |
7507 | 234 |
// "<yt:incomplete/>" |
7447
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
235 |
"<media:category " |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
236 |
"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
|
237 |
"</media:category>" |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
238 |
"<media:title type=\"plain\">" |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
239 |
+ XmlEscape(leTitle->text()).toUtf8() + |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
240 |
"</media:title>" |
7507 | 241 |
"<media:description type=\"plain\">" |
242 |
+ XmlEscape(teDescription->toPlainText()).toUtf8() + |
|
243 |
"</media:description>" |
|
244 |
"<media:keywords type=\"plain\">" |
|
245 |
+ XmlEscape(leTags->text()).toUtf8() + |
|
246 |
"</media:keywords>" |
|
247 |
+ (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
|
248 |
"</media:group>" |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
249 |
"</entry>"; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
250 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
251 |
QNetworkRequest request; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
252 |
request.setUrl(QUrl("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads")); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
253 |
request.setRawHeader("User-Agent", UserAgent); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
254 |
request.setRawHeader("Authorization", auth); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
263 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
264 |
void HWUploadVideoDialog::startUpload() |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
265 |
{ |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
266 |
QNetworkReply *reply = (QNetworkReply*)sender(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
267 |
reply->deleteLater(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
268 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
269 |
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
|
270 |
if (location.isEmpty()) |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
271 |
{ |
7507 | 272 |
QString errorStr = QMessageBox::tr("Error while sending metadata to youtube.com:\n"); |
273 |
errorStr += reply->errorString(); |
|
274 |
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
|
275 |
setEditable(true); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
276 |
return; |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
277 |
} |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
278 |
|
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
279 |
accept(); |
01111960a48d
uploading to youtube, it works, but user interface is still incomplete
Stepan777 <stepik-777@mail.ru>
parents:
diff
changeset
|
280 |
} |