Commit 9cff2b04 authored by Skia's avatar Skia

Clean up repository

parent c027eeeb
/*
UBPT Transfert 2
Copyright (C) 2005 Julien Etelain. Tous droits réservés.. 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.
*/
#ifndef CONNECTDIALOG_H
#define CONNECTDIALOG_H
#include "ui_connect.h"
#include "protocol.h"
class connectDialog : public QDialog
{
Q_OBJECT
public:
connectDialog( UbptSession *targetSession, QWidget *parent = 0);
void enableMode(int mode);
void connectToServer( QString Url );
public slots:
void on_okButton_clicked();
void on_cancelButton_clicked();
void connectCurrent(int index=0);
private:
Ui::connectDialog ui;
UbptSession *session;
int connectToUBPT();
};
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/*
UBPT Transfert 2
Copyright (C) 2005 Julien Etelain. Tous droits réservés..
Copyright (C) 2011 Mathieu Briand.
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 <QtCore>
#include <QtGui>
#include "mainwindow.h"
#include "connectdialog.h"
connectDialog::connectDialog(UbptSession *targetSession ,QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
session = targetSession;
connect(ui.serverToolButton, SIGNAL(clicked()), this, SLOT(connectCurrent()));
connect(ui.serverComboBox, SIGNAL(activated(int)), this, SLOT(connectCurrent(int)));
}
void connectDialog::connectCurrent( int index )
{
Q_UNUSED(index);
connectToServer("https://ae.utbm.fr/sas2/autoup.php");
}
void connectDialog::connectToServer( QString Url ) {
int err;
enableMode(0);
ui.connectProgress->setValue(0);
ui.connectInfo->setText(tr("Connecting to server..."));
repaint();
QCoreApplication::processEvents();
if ( (err = session->ConnectToServer(Url)) ) {
if ( err == ERR_UBPT_NOCONNECTION )
ui.connectInfo->setText(tr("Unable to connect to server."));
else if ( err == ERR_UBPT_USERNAMEORPASSWORD )
ui.connectInfo->setText(tr("This server requires you to update this software."));
else
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(1);
return;
}
ui.connectProgress->setValue(100);
ui.connectInfo->setText(tr("Connected to %1 - %2").arg(session->Name).arg(session->Url));
ui.userDomainCombo->clear();
for (int i = 0; i < session->Domains.size(); ++i) {
ui.userDomainCombo->addItem(session->Domains.at(i));
}
enableMode(2);
}
void connectDialog::enableMode( int mode ) {
ui.serverComboBox->setEnabled( mode != 0 );
ui.infoGroupBox->setEnabled( mode == 0 );
ui.userGroupBox->setEnabled( mode == 2 );
ui.okButton->setEnabled( mode == 2 );
ui.cancelButton->setEnabled( mode != 0 );
}
void connectDialog::on_cancelButton_clicked()
{
done(0);
}
void connectDialog::on_okButton_clicked()
{
if ( connectToUBPT() )
done(1);
}
int connectDialog::connectToUBPT()
{
int err;
enableMode(0);
ui.connectProgress->setValue(25);
ui.connectInfo->setText(tr("Opening session..."));
repaint();
QCoreApplication::processEvents();
if ( (err = session->OpenSession(ui.userNameLine->text(),ui.passWordLine->text(),ui.userDomainCombo->currentIndex())) ) {
if ( err == ERR_UBPT_NOCONNECTION )
ui.connectInfo->setText(tr("Unable to connect to server."));
else if ( err == ERR_UBPT_USERNAMEORPASSWORD )
ui.connectInfo->setText(tr("Invalid password or username."));
else if ( err == ERR_UBPT_USERNAMEORPASSWORD )
ui.connectInfo->setText(tr("Please update this software."));
else
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
}
ui.connectProgress->setValue(50);
ui.connectInfo->setText(tr("Loading groups, clubs and licences..."));
repaint();
QCoreApplication::processEvents();
if ( (err = session->FetchUserGroups()) ) {
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
}
if ( (err = session->FetchClubs()) ) {
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
}
if ( (err = session->FetchLicences()) ) {
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
}
ui.connectProgress->setValue(75);
ui.connectInfo->setText(tr("Loading categories..."));
repaint();
QCoreApplication::processEvents();
if ( (err = session->FetchContexts()) ) {
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
}
ui.connectProgress->setValue(100);
ui.connectInfo->setText(tr("Connected"));
return 1;
}
#include <QtGui>
#include <QDebug>
#include "uploadthread.h"
#include "mainwindow.h"
UploadThread::UploadThread(QObject *parent)
: QThread(parent)
{
current = NULL;
item = NULL;
}
void UploadThread::upload(transfertTreeItem *Item)
{
QMutexLocker locker(&mutex);
this->item = Item;
if (!isRunning())
start(LowPriority);
else
condition.wakeOne();
}
void UploadThread::progress_callback(double dltotal,double dlnow,double ultotal,double ulnow)
{
Q_UNUSED(dltotal);
Q_UNUSED(dlnow);
if ( current )
{
int percent = (int)(ulnow*100/ultotal);
emit progress(current, percent);
}
}
void UploadThread::run()
{
forever
{
if ( item )
{
mutex.lock();
current = item;
item = NULL;
mutex.unlock();
current->UBPTError = 0;
int licenceId = session->Licences[current->transfert.licence];
int clubId = session->Clubs[current->transfert.club];
if ( current->transfert.type == transfertItem::Video )
{
qDebug("video");
current->UBPTError = ERR_UBPT_NONE;
QDir appPath(QCoreApplication::applicationDirPath ());
QFileInfo fi(current->transfert.fileName);
QString tempImg = appPath.filePath("tmp.jpg");
QString tempFlv = appPath.filePath("tmp.flv");
#ifdef Q_WS_MAC
QString ffmpeg = appPath.filePath("ffmpeg");
#else
#ifdef Q_WS_WIN
QString ffmpeg = appPath.filePath("ffmpeg.exe");
#else
QString ffmpeg = "ffmpeg";
#endif
#endif
bool delTempFlv = true;
current->state = transfertTreeItem::Encoding;
emit progress(current, -1);
if ( fi.suffix().toLower() == "flv" )
{
tempFlv = current->transfert.fileName;
delTempFlv = false;
}
else
{
QProcess mencoder;
QString cmd1 = QString("%3 -y -i \"%1\" -acodec mp3 -f flv -ab 56 -ar 22050 -b 200 -r 15 -s 320x240 \"%2\"").arg(current->transfert.fileName).arg(tempFlv).arg(ffmpeg);
qDebug()<<cmd1;
mencoder.start(cmd1);
mencoder.waitForFinished(-1);
qDebug("%d",(int)mencoder.error());
qDebug("%d",(int)mencoder.exitCode());
if ( mencoder.error() != QProcess::UnknownError || mencoder.exitCode() != 0 )
current->UBPTError = ERR_UBPT_VIDEOTRANSCODE;
}
if ( current->UBPTError == ERR_UBPT_NONE )
{
QProcess mplayer;
QString cmd2 = QString("%3 -an -y -vframes 1 -i \"%1\" -f image2 -ss 1 \"%2\"").arg(current->transfert.fileName).arg(tempImg).arg(ffmpeg);
qDebug()<<cmd2;
mplayer.start(cmd2);
mplayer.waitForFinished(-1);
qDebug("%d",(int)mplayer.error());
qDebug("%d",(int)mplayer.exitCode());
if ( mplayer.error() != QProcess::UnknownError || mplayer.exitCode() != 0 )
current->UBPTError = ERR_UBPT_VIDEOSHOT;
}
// encode to flv and capture an image
if ( current->UBPTError == ERR_UBPT_NONE )
{
current->state = transfertTreeItem::Transfert;
current->UBPTError = session->UploadVideoFlv ( current->transfert.contextId, current->transfert.rights, current->transfert.group, current->transfert.photographerUserId, clubId, licenceId, current->transfert.comment, tempImg, tempFlv );
QFile::remove(tempImg);
if ( delTempFlv )
QFile::remove(tempFlv);
}
}
else
{
qDebug("photo");
current->state = transfertTreeItem::Transfert;
current->UBPTError = session->UploadImage ( current->transfert.contextId, current->transfert.rights, current->transfert.group, current->transfert.photographerUserId, clubId, licenceId, current->transfert.comment, current->transfert.fileName );
}
if ( !current->UBPTError )
current->state = transfertTreeItem::Sucess;
else
current->state = transfertTreeItem::Error;
emit uploaded(current);
}
mutex.lock();
if ( !item )
condition.wait(&mutex);
mutex.unlock();
}
}
<ui version="4.0" >
<author>Julien Etelain</author>
<comment></comment>
<exportmacro></exportmacro>
<class>connectDialog</class>
<widget class="QDialog" name="connectDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>487</width>
<height>234</height>
</rect>
</property>
<property name="windowTitle" >
<string>Connection</string>
</property>
<property name="sizeGripEnabled" >
<bool>false</bool>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>8</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Server :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="serverComboBox" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text" >
<string>AE UTBM</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QToolButton" name="serverToolButton" >
<property name="text" >
<string>ok</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="addServerToolButton" >
<property name="text" >
<string>+</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="userGroupBox" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title" >
<string/>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>8</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="label_4_2" >
<property name="text" >
<string>Email adress</string>
</property>
<property name="buddy" >
<cstring>userNameLine</cstring>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2_2_2" >
<property name="text" >
<string>Password</string>
</property>
<property name="buddy" >
<cstring>passWordLine</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="userNameLine" />
</item>
<item row="0" column="2" >
<widget class="QComboBox" name="userDomainCombo" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="currentIndex" >
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2" >
<widget class="QLineEdit" name="passWordLine" >
<property name="echoMode" >
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="infoGroupBox" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title" >
<string/>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>8</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="connectInfo" >
<property name="text" >
<string>Waiting...</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="connectProgress" >
<property name="value" >
<number>0</number>
</property>
<property name="alignment" >
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
<property name="textVisible" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>131</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<tabstops>
<tabstop>okButton</tabstop>
<tabstop>cancelButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
DESTDIR = bin
INCLUDEPATH = include
LIBS += -lcurl
OBJECTS_DIR = obj
UI_DIR = src/ui/
UI_HEADERS_DIR = include/ui
TARGET = ubpttr
MOC_DIR = moc
RCC_DIR = ressources
HEADERS += include/protocol.h \
include/mainwindow.h \
include/adddialog.h \
include/uploadthread.h \
include/connectdialog.h
SOURCES += src/protocol.cpp \
src/qt/mainwindow.cpp \
src/qt/connectdialog.cpp \
src/qt/uploadthread.cpp \
src/qt/adddialog.cpp \
src/qt/main.cpp
FORMS += src/ui/main.ui \
src/ui/add.ui \
src/ui/connect.ui
TRANSLATIONS = ressources/ubpttr_fr.ts
TEMPLATE = app
CONFIG += qt release
RESOURCES = ressources/ubpttr.qrc
QT += xml
mac {
ICON = ressources/macicon.icns
QMAKE_INFO_PLIST = ressources/mac.plist
TARGET = UBPTTransfert
CONFIG += x86 ppc
QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
}
# Doxyfile 1.3.8