QTfrontend/ui/dialog/upload_video.cpp
changeset 7528 f8cf277dca36
parent 7507 3032a5739fe1
child 7531 0adcad8714c4
equal deleted inserted replaced
7525:5c840e221993 7528:f8cf277dca36
    36 
    36 
    37 #include "upload_video.h"
    37 #include "upload_video.h"
    38 #include "hwconsts.h"
    38 #include "hwconsts.h"
    39 
    39 
    40 // User-agent string used in http requests.
    40 // User-agent string used in http requests.
    41 static const QByteArray UserAgent = ("Hedgewars-QtFrontend/" + *cVersionString).toAscii();
    41 // Don't make it a global varibale - crash on linux because of cVersionString
       
    42 #define USER_AGENT ("Hedgewars-QtFrontend/" + *cVersionString).toAscii()
    42 
    43 
    43 // This is developer key obtained from http://code.google.com/apis/youtube/dashboard/
    44 // This is developer key obtained from http://code.google.com/apis/youtube/dashboard/
    44 // If you are reusing this code outside Hedgewars, don't use this developer key,
    45 // If you are reusing this code outside Hedgewars, don't use this developer key,
    45 // obtain you own at http://code.google.com/apis/youtube/dashboard/
    46 // obtain you own at http://code.google.com/apis/youtube/dashboard/
    46 static const QByteArray devKey = "AI39si5pKjxR0XgNIlmrEFF-LyYD31rps4g2O5dZTxLgD0fvJ2rHxrMrNFY8FYTZrzeI3VlaFVQLKfFnSBugvdZmy8vFzRDefQ";
    47 static const QByteArray devKey = "AI39si5pKjxR0XgNIlmrEFF-LyYD31rps4g2O5dZTxLgD0fvJ2rHxrMrNFY8FYTZrzeI3VlaFVQLKfFnSBugvdZmy8vFzRDefQ";
   103     lbLabel->setText(QLabel::tr("Video title: "));
   104     lbLabel->setText(QLabel::tr("Video title: "));
   104     layout->addWidget(lbLabel, row, 0);
   105     layout->addWidget(lbLabel, row, 0);
   105 
   106 
   106     leTitle = new QLineEdit(this);
   107     leTitle = new QLineEdit(this);
   107     leTitle->setText(filename);
   108     leTitle->setText(filename);
   108     leTitle->setValidator(new QRegExpValidator(rx));
   109     leTitle->setValidator(new QRegExpValidator(rx, leTitle));
   109     layout->addWidget(leTitle, row++, 1);
   110     layout->addWidget(leTitle, row++, 1);
   110 
   111 
   111     lbLabel = new QLabel(this);
   112     lbLabel = new QLabel(this);
   112     lbLabel->setText(QLabel::tr("Video description: "));
   113     lbLabel->setText(QLabel::tr("Video description: "));
   113     layout->addWidget(lbLabel, row++, 0, 1, 2);
   114     layout->addWidget(lbLabel, row++, 0, 1, 2);
   120     layout->addWidget(lbLabel, row, 0);
   121     layout->addWidget(lbLabel, row, 0);
   121 
   122 
   122     leTags = new QLineEdit(this);
   123     leTags = new QLineEdit(this);
   123     leTags->setText("hedgewars");
   124     leTags->setText("hedgewars");
   124     leTags->setMaxLength(500);
   125     leTags->setMaxLength(500);
   125     leTags->setValidator(new QRegExpValidator(rx));
   126     leTags->setValidator(new QRegExpValidator(rx, leTags));
   126     layout->addWidget(leTags, row++, 1);
   127     layout->addWidget(leTags, row++, 1);
   127 
   128 
   128     cbPrivate = new QCheckBox(this);
   129     cbPrivate = new QCheckBox(this);
   129     cbPrivate->setText(QCheckBox::tr("Video is private"));
   130     cbPrivate->setText(QCheckBox::tr("Video is private"));
   130     layout->addWidget(cbPrivate, row++, 0, 1, 2);
   131     layout->addWidget(cbPrivate, row++, 0, 1, 2);
   168     setEditable(false);
   169     setEditable(false);
   169 
   170 
   170     // Documentation is at https://developers.google.com/youtube/2.0/developers_guide_protocol_clientlogin#ClientLogin_Authentication
   171     // Documentation is at https://developers.google.com/youtube/2.0/developers_guide_protocol_clientlogin#ClientLogin_Authentication
   171     QNetworkRequest request;
   172     QNetworkRequest request;
   172     request.setUrl(QUrl("https://www.google.com/accounts/ClientLogin"));
   173     request.setUrl(QUrl("https://www.google.com/accounts/ClientLogin"));
   173     request.setRawHeader("User-Agent", UserAgent);
   174     request.setRawHeader("User-Agent", USER_AGENT);
   174     request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
   175     request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
   175 
   176 
   176     QString account(QUrl::toPercentEncoding(leAccount->text()));
   177     QString account(QUrl::toPercentEncoding(leAccount->text()));
   177     QString pass(QUrl::toPercentEncoding(lePassword->text()));
   178     QString pass(QUrl::toPercentEncoding(lePassword->text()));
   178     QByteArray data = QString("Email=%1&Passwd=%2&service=youtube&source=Hedgewars").arg(account).arg(pass).toAscii();
   179     QByteArray data = QString("Email=%1&Passwd=%2&service=youtube&source=Hedgewars").arg(account).arg(pass).toAscii();
   248                 "</media:group>"
   249                 "</media:group>"
   249             "</entry>";
   250             "</entry>";
   250 
   251 
   251     QNetworkRequest request;
   252     QNetworkRequest request;
   252     request.setUrl(QUrl("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"));
   253     request.setUrl(QUrl("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"));
   253     request.setRawHeader("User-Agent", UserAgent);
   254     request.setRawHeader("User-Agent", USER_AGENT);
   254     request.setRawHeader("Authorization", auth);
   255     request.setRawHeader("Authorization", auth);
   255     request.setRawHeader("GData-Version", "2");
   256     request.setRawHeader("GData-Version", "2");
   256     request.setRawHeader("X-GData-Key", "key=" + devKey);
   257     request.setRawHeader("X-GData-Key", "key=" + devKey);
   257     request.setRawHeader("Slug", filename.toUtf8());
   258     request.setRawHeader("Slug", filename.toUtf8());
   258     request.setRawHeader("Content-Type", "application/atom+xml; charset=UTF-8");
   259     request.setRawHeader("Content-Type", "application/atom+xml; charset=UTF-8");