Commit 0961db94 authored by Rohit Yadav's avatar Rohit Yadav Committed by Hugo Beauzée-Luyssen

Video sharing export dialog for YouTube etc.

Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent 02f6ab90
/******************************************************************************
* ShareOnInternet.cpp: Configure Video Export to Internet
******************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Rohit Yadav <rohityadav89@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "AbstractSharingService.h"
#include "SettingsManager.h"
#include "ShareOnInternet.h"
#include "Vimeo/VimeoService.h"
#include "YouTube/YouTubeService.h"
#include <QDesktopServices>
#include <QClipboard>
#include <QMessageBox>
#include <QDebug>
ShareOnInternet::ShareOnInternet( QWidget* parent )
: QDialog( parent, Qt::Sheet | Qt::Dialog )
{
m_service = NULL;
m_serviceProvider = 0;
m_ui.setupUi( this );
m_ui.progressBar->setVisible( false );
/* Get DevKey from VLMC settings */
m_devKey = VLMC_GET_STRING( "youtube/DeveloperKey" );
switch( m_serviceProvider )
{
case YOUTUBE:
m_ui.username->setText( VLMC_GET_STRING( "youtube/Username" ) );
m_ui.password->setText( VLMC_GET_STRING( "youtube/Password" ) );
m_ui.title->setText( VLMC_PROJECT_GET_STRING( "general/ProjectName" ) );
break;
}
}
ShareOnInternet::~ShareOnInternet()
{
delete m_service;
}
void
ShareOnInternet::accept()
{
if( m_ui.title->text().isEmpty() |
m_ui.username->text().isEmpty() |
m_ui.password->text().isEmpty() )
{
QMessageBox::critical( this, tr("Error"),
tr("'Username' or 'Password' or 'Title' cannot be empty. "
"Please check these fields.") );
return;
}
publish();
}
void
ShareOnInternet::publish()
{
m_ui.publishButton->setEnabled( false );
/* Check for service provider, if changes delete old one */
if( m_serviceProvider != m_ui.serviceBox->currentIndex() )
{
if( m_service )
delete m_service;
m_service = NULL;
m_serviceProvider = m_ui.serviceBox->currentIndex();
}
if( !m_service )
{
switch( m_serviceProvider )
{
case VIMEO: /* TODO: Implement services for Vimeo */
qDebug() << "[SHARE ON INTERNET]: VIMEO"; break;
case YOUTUBE:
default:
m_service = new YouTubeService( m_devKey, getUsername(), getPassword() );
qDebug() << "[SHARE ON INTERNET]: YOUTUBE"; break;
}
}
else
m_service->setCredentials( getUsername(), getPassword() );
m_ui.statusLabel->setText( tr("Authenticating...") );
m_service->authenticate();
connect( m_service, SIGNAL(authOver()), this, SLOT(authFinished()) );
connect( m_service, SIGNAL(error(QString)), this, SLOT(serviceError(QString)) );
}
void
ShareOnInternet::authFinished()
{
qDebug() << "[SHARE ON INTERNET]: AUTH FINISHED";
/*On Finish, extract out the auth token and upload a test video */
disconnect( m_service, SIGNAL(authOver()), this, SLOT(authFinished()) );
VideoData videoData = getVideoData();
m_service->setVideoParameters( m_fileName, videoData );
connect( m_service, SIGNAL(uploadOver(QString)), this, SLOT(uploadFinished(QString)));
connect( m_service, SIGNAL(uploadProgress(qint64,qint64)),
this, SLOT(uploadProgress(qint64,qint64)) );
if( !m_service->upload() )
{
m_ui.publishButton->setEnabled( true );
disconnect( m_service, SIGNAL(uploadOver(QString)), this, SLOT(uploadFinished(QString)));
disconnect( m_service, SIGNAL(uploadProgress(qint64,qint64)),
this, SLOT(uploadProgress(qint64,qint64)) );
disconnect( m_service, SIGNAL(error(QString)), this, SLOT(serviceError(QString)) );
qDebug() << "[SHARE ON INTERNET]: AUTH Failed";
return;
}
m_ui.statusLabel->setText( tr("Authenticated!") );
m_ui.progressBar->setEnabled( true );
m_ui.progressBar->setVisible( true );
m_ui.mainPanel->setEnabled( false );
qDebug() << "[SHARE ON INTERNET]: UPLOAD STARTED";
}
void
ShareOnInternet::uploadFinished( QString result )
{
/* Add code here to abort stuff */
m_ui.progressBar->setEnabled( false );
m_ui.progressBar->setVisible( false );
QApplication::clipboard()->setText( result );
if( QMessageBox::information( NULL, tr("Video Uploaded"),
tr("Your video has been uploaded."
"\nURL (copied to your clipboard):\n%1"
"\n\nOpen video in your default web browser?").arg( result ),
QMessageBox::Open | QMessageBox::Close ) == QMessageBox::Open )
{
QDesktopServices::openUrl( result );
}
/* Finish exec() */
QDialog::accept();
}
void
ShareOnInternet::uploadProgress(qint64 received, qint64 total)
{
if( total != 0 )
{
qint64 progress = received * 100 / total;
m_ui.progressBar->setValue( progress );
m_ui.statusLabel->setText( tr("%1 Bytes Uploaded").arg( received ) );
}
}
void
ShareOnInternet::serviceError(QString e)
{
qDebug() << "[SHARE ON INTERNET]: ERROR = " << e;
m_ui.statusLabel->setText( e );
emit error( e );
}
QString
ShareOnInternet::getUsername() const
{
return m_ui.username->text();
}
QString
ShareOnInternet::getPassword() const
{
return m_ui.password->text();
}
VideoData
ShareOnInternet::getVideoData() const
{
VideoData data;
data.title = m_ui.title->text();
data.category = m_ui.category->currentText().split(" & ").at( 0 );
data.description = m_ui.description->toPlainText();
data.keywords = m_ui.keywords->text();
data.isPrivate = m_ui.videoPrivacy->isChecked();
return data;
}
void
ShareOnInternet::setVideoFile( QString& fileName )
{
m_fileName = fileName;
}
/***************************************************************************** /******************************************************************************
* ShareOnYoutube.h: Configure Youtube Export * ShareOnInternet.h: Configure Video Export to Internet
***************************************************************************** ******************************************************************************
* Copyright (C) 2008-2010 VideoLAN * Copyright (C) 2008-2010 VideoLAN
* *
* Authors: Rohit Yadav <rohityadav89@gmail.com> * Authors: Rohit Yadav <rohityadav89@gmail.com>
...@@ -20,35 +20,54 @@ ...@@ -20,35 +20,54 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef SHAREONYOUTUBE_H #ifndef SHAREONINTERNET_H
#define SHAREONYOUTUBE_H #define SHAREONINTERNET_H
#include <QDialog> #include <QDialog>
#include "ui_ShareOnYoutube.h" #include "ui_ShareOnInternet.h"
class ShareOnYoutube : public QDialog class AbstractSharingService;
class VideoData;
class ShareOnInternet : public QDialog
{ {
Q_OBJECT Q_OBJECT
enum ServiceProviders
{
YOUTUBE = 0,
VIMEO
};
public: public:
ShareOnYoutube(); ShareOnInternet( QWidget* parent = 0 );
QString username() const; ~ShareOnInternet();
QString password() const;
QString title() const;
QString category() const;
QString description() const;
QString tags() const;
quint32 width() const;
quint32 height() const;
bool videoPrivacy() const;
private slots: QString getUsername() const;
virtual void accept(); QString getPassword() const;
VideoData getVideoData() const;
void setVideoFile( QString& fileName );
private: private:
Ui::ShareOnYoutube m_ui; void publish();
quint32 m_width;
quint32 m_height; Ui::ShareOnInternet m_ui;
AbstractSharingService* m_service;
int m_serviceProvider;
QString m_devKey;
QString m_fileName;
private slots:
void accept();
void authFinished();
void uploadFinished( QString );
void uploadProgress( qint64, qint64 );
void serviceError( QString );
signals:
void error( QString );
void finished();
}; };
#endif // SHAREONYOUTUBE_H #endif // SHAREONINTERNET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShareOnInternet</class>
<widget class="QDialog" name="ShareOnInternet">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>448</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>400</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="windowTitle">
<string>Share Video On Internet</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QWidget" name="mainPanel" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Service</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="serviceBox">
<item>
<property name="text">
<string>YouTube</string>
</property>
<property name="icon">
<iconset resource="../../../resources.qrc">
<normaloff>:/images/youtube</normaloff>:/images/youtube</iconset>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="username"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Category</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QComboBox" name="category">
<item>
<property name="text">
<string>Autos &amp; Vehicles</string>
</property>
</item>
<item>
<property name="text">
<string>Comedy</string>
</property>
</item>
<item>
<property name="text">
<string>Education</string>
</property>
</item>
<item>
<property name="text">
<string>Entertainment</string>
</property>
</item>
<item>
<property name="text">
<string>Film &amp; Animation</string>
</property>
</item>
<item>
<property name="text">
<string>Games</string>
</property>
</item>
<item>
<property name="text">
<string>Howto &amp; Style</string>
</property>
</item>
<item>
<property name="text">
<string>Music</string>
</property>
</item>
<item>
<property name="text">
<string>News &amp; Politics</string>
</property>
</item>
<item>
<property name="text">
<string>Nonprofit &amp; Activism</string>
</property>
</item>
<item>
<property name="text">
<string>People &amp; Blogs</string>
</property>
</item>
<item>
<property name="text">
<string>Animals &amp; Pets</string>
</property>
</item>
<item>
<property name="text">
<string>Tech &amp; Science</string>
</property>
</item>
<item>
<property name="text">
<string>Sports</string>
</property>
</item>
<item>
<property name="text">
<string>Travel &amp; Events</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QLineEdit" name="title"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QPlainTextEdit" name="description">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="backgroundVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Keywords</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="3">
<widget class="QLineEdit" name="keywords"/>
</item>
<item row="6" column="0" colspan="3">
<widget class="QCheckBox" name="videoPrivacy">
<property name="text">
<string>Make this video private</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="4">
<widget class="QLabel" name="label_9">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;By publishing, you agree with the Terms Of Services of &lt;a href=&quot;http://code.google.com/apis/youtube/terms.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;YouTube&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="textDirection">
<enum>QProgressBar::TopToBottom</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>108</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>&amp;Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="publishButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Publish</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../../../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>publishButton</sender>
<signal>clicked()</signal>
<receiver>ShareOnInternet</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>54</x>
<y>381</y>
</hint>
<hint type="destinationlabel">
<x>189</x>
<y>218</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>ShareOnInternet</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>51</x>
<y>414</y>
</hint>
<hint type="destinationlabel">
<x>189</x>
<y>218</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/*****************************************************************************
* ShareOnYoutube.cpp: Configure Youtube Export
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Rohit Yadav <rohityadav89@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "ShareOnYoutube.h"
#include "SettingsManager.h"
#include "ui_ShareOnYoutube.h"
ShareOnYoutube::ShareOnYoutube()
{
m_ui.setupUi( this );
m_ui.title->setText( VLMC_PROJECT_GET_STRING( "general/ProjectName" ) );
}
void
ShareOnYoutube::accept()
{
switch( m_ui.videoSize->currentIndex() )
{
case 0: m_width = 480; m_height = 272; break;
case 1: m_width = 640; m_height = 360; break;
case 2: m_width = 960; m_height = 540; break;
case 3: m_width = 1280; m_height = 720; break;
default: m_width = 640; m_height = 360;
}
//Error checks here
QDialog::accept();
}
QString
ShareOnYoutube::username() const
{
return m_ui.username->text();
}
QString
ShareOnYoutube::password() const
{
return m_ui.password->text();
}
QString
ShareOnYoutube::category() const
{
return m_ui.category->currentText();
}
QString
ShareOnYoutube::title() const
{
return m_ui.title->text();
}
QString
ShareOnYoutube::description() const