Commit 79ed43dd authored by mbriand's avatar mbriand

gestion photographe et licence + trad

parent 5320e828
/*
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.
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.
*/
#ifndef ADDDIALOG_H
......@@ -21,19 +36,21 @@ class addDialog : public QDialog
public:
addDialog( MainWindow *win, QWidget *parent = 0);
public slots:
void on_cancelButton_clicked();
void selectFileName();
void selectDirName();
void currentItemChange ( QTreeWidgetItem * current, QTreeWidgetItem * previous );
void enqueueRequested();
void enableClubComboBox(int state);
void enableUserLineEdit(int state);
private:
Ui::addDialog ui;
UbptSession *session;
void initLists();
void initLists();
MainWindow *mainwin;
void processCtx ( contextTreeItem *item, UbptContext *ctx );
};
......@@ -43,8 +60,8 @@ class contextTreeItem : public QTreeWidgetItem
public:
contextTreeItem( QTreeWidgetItem * parent, UbptContext *pCtx );
contextTreeItem( QTreeWidget * parent, UbptContext *pCtx );
UbptContext *Ctx;
};
#endif
\ No newline at end of file
#endif
/*
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.
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.
*/
#ifndef MAINWINDOW_H
......@@ -18,35 +33,39 @@
typedef struct transfertItem
{
public:
public:
QString name;
QString fileName;
QString contextName;
int contextId;
int rights;
QString group;
int photographerUserId;
QString club;
QString licence;
QString comment;
enum itemType { Photo, Video };
itemType type;
} transfertItem;
class transfertTreeItem : public QTreeWidgetItem
{
public:
transfertTreeItem( QString Name, QString FileName, QString ContextName, int ContextId,int Rights, QString Group, QTreeWidget *parent, transfertItem::itemType t = transfertItem::Photo );
transfertTreeItem( QString Name, QString FileName, QString ContextName, int ContextId,int Rights, QString Group, int photographerUserId, QString Club, QString Licence, QString comment, QTreeWidget *parent, transfertItem::itemType t = transfertItem::Photo );
transfertTreeItem( transfertItem transfert, QTreeWidget *parent );
transfertItem transfert;
enum transfertState { ToDo, Encoding, Transfert, Sucess, Error };
transfertState state;
int UBPTError;
};
class MainWindow : public QMainWindow
......@@ -57,14 +76,14 @@ public:
MainWindow(QWidget *parent = 0);
UbptSession session;
void switchMode ( int Mode );
void addFileToQueue ( const QString & name, const QString & fileName, const QString & contextName, int contextId, int rights, const QString & group );
void addVideoFileToQueue ( const QString & name, const QString & fileName, const QString & contextName, int contextId, int rights, const QString & group );
void addFileToQueue ( const QString & name, const QString & fileName, const QString & contextName, int contextId, int rights, const QString & group, int photographerUserId, QString club, QString licence, QString comment );
void addVideoFileToQueue ( const QString & name, const QString & fileName, const QString & contextName, int contextId, int rights, const QString & group, int photographerUserId, QString club, QString licence, QString comment );
Ui::MainWindow ui;
protected:
void closeEvent(QCloseEvent *event);
public slots:
void about();
void openAdd();
......@@ -72,17 +91,17 @@ public slots:
void processPhotos();
void stopPhotos();
void uploaded(transfertTreeItem *Item);
void progress(transfertTreeItem *Item, int precent);
void progress(transfertTreeItem *Item, int precent);
void resetStatesAndRemoveDone();
void removeAll();
void removeSelection();
private:
void createActions();
void createMenus();
void createToolBars();
void writeList();
void readList();
void readElement( const QDomElement &element );
......@@ -95,26 +114,26 @@ private:
QAction *cleanupResetAct;
QAction *removeAllAct;
QAction *removeSelectionAct;
QMenu *fileMenu;
QMenu *photosMenu;
QMenu *helpMenu;
QMenu *helpMenu;
QToolBar *fileToolBar;
QToolBar *photosToolBar;
QToolBar *photosToolBar;
QTreeWidgetItem *rootItem;
void uploadItem (transfertTreeItem *Item );
void nextItem ();
bool stop;
QTime listTime;
QTime itemTime;
int itemsDone;
void refreshRemaingInfo ();
int countRemainingItems ();
int countRemainingItems ();
UploadThread upthread;
};
......
/*
UBPT Transfert 2
Copyright (C) 2005,2006 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.
*/
/**
/**
@addtogroup ubptprococol
@{
*/
......@@ -31,6 +32,7 @@
#define PROTOCOL_H
#include<QStringList>
#include<QMap>
#include <curl/curl.h>
/* In recent version of libcurl, this include doesn't exist anymore, uncomment if it breaks build for you
......@@ -43,7 +45,7 @@
class UbptContext
{
public:
QString Name;
int Id;
int IdParent;
......@@ -67,19 +69,24 @@ public:
QString Name;
QString Message;
QString Url;
int userId;
QStringList Domains;
QList<UbptContext*> Contexts;
QStringList UserGroups;
QMap<QString, int> Clubs;
QMap<QString, int> Licences;
int ConnectToServer ( QString url );
int OpenSession ( QString userName, QString passWord, int domain );
int FetchUserGroups();
int FetchClubs();
int FetchLicences();
int FetchContexts();
int UploadImage ( int contextId, QString description, QString photograph, int rights, QString group, QString file );
int UploadVideoFlv ( int contextId, QString description, QString photograph, int rights, QString group, QString fileImage, QString fileVideo );
int UploadImage ( int contextId, int rights, QString group, int photographerUserId, int clubId, int licenceId, QString comment, QString file );
int UploadVideoFlv ( int contextId, int rights, QString group, int photographerUserId, int clubId, int licenceId, QString comment, QString fileImage, QString fileVideo );
int SetProgress( curl_progress_callback func, void *clientp );
......@@ -102,8 +109,8 @@ private:
// Error in connectivity
#define ERR_UBPT_NOCONNECTION -1
// Other errors
// Other errors
#define ERR_UBPT_USERNAMEORPASSWORD 10
#define ERR_UBPT_NEEDTOUPDATE 11
#define ERR_UBPT_INVALIDIMAGEFILE 3
......
No preview for this file type
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.
......@@ -47,28 +48,28 @@ void addDialog::currentItemChange ( QTreeWidgetItem * current, QTreeWidgetItem *
if ( item ) {
int i = 0;
if ( item->Ctx->Rights & 1 )
ui.allConnectedRadioButton->setChecked(true);
else
else
ui.limitGroupRadioButton->setChecked(true);
i = session->UserGroups.lastIndexOf(item->Ctx->Group);
if ( item->Ctx->Rights & 0x008 )
if ( item->Ctx->Rights & 0x008 )
ui.okButton->setEnabled(true);
else if ( (item->Ctx->Rights & 0x080) && (i != -1) )
else if ( (item->Ctx->Rights & 0x080) && (i != -1) )
ui.okButton->setEnabled(true);
else
ui.okButton->setEnabled(false);
ui.groupComboBox->setCurrentIndex(i);
}
else
ui.okButton->setEnabled(false);
}
addDialog::addDialog(MainWindow *win ,QWidget *parent)
......@@ -78,16 +79,20 @@ addDialog::addDialog(MainWindow *win ,QWidget *parent)
session = &(mainwin->session);
ui.setupUi(this);
initLists();
ui.userLineEdit->setText(QString::number(session->userId));
ui.okButton->setEnabled(false);
ui.clubComboBox->setEnabled(false);
ui.userLineEdit->setEnabled(false);
connect(ui.fileToolButton, SIGNAL(clicked()), this, SLOT(selectFileName()));
connect(ui.dirToolButton, SIGNAL(clicked()), this, SLOT(selectDirName()));
connect(ui.treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)), this, SLOT(currentItemChange(QTreeWidgetItem *,QTreeWidgetItem *)));
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(enqueueRequested()));
connect(ui.clubCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableClubComboBox(int)));
connect(ui.userCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableUserLineEdit(int)));
}
void addDialog::initLists()
......@@ -96,21 +101,33 @@ void addDialog::initLists()
ui.treeWidget->clear();
ui.treeWidget->setColumnCount(1);
ui.treeWidget->setHeaderLabels(QStringList(tr("Name")));
for (int i = 0; i < session->Contexts.size(); ++i) {
UbptContext *sctx = session->Contexts.at(i);
if ( sctx->IdParent == 0 )
{
contextTreeItem *sitem = new contextTreeItem(ui.treeWidget,sctx);
processCtx(sitem,sctx);
}
}
}
for (int i = 0; i < session->UserGroups.size(); ++i) {
ui.groupComboBox->addItem(session->UserGroups.at(i));
}
QMap<QString, int>::iterator mapIter = session->Clubs.begin();
while (mapIter != session->Clubs.end())
{
ui.clubComboBox->addItem(mapIter.key());
++mapIter;
}
mapIter = session->Licences.begin();
while (mapIter != session->Licences.end())
{
ui.licenceComboBox->addItem(mapIter.key());
++mapIter;
}
}
void addDialog::processCtx ( contextTreeItem *item, UbptContext *ctx )
......@@ -123,7 +140,7 @@ void addDialog::processCtx ( contextTreeItem *item, UbptContext *ctx )
contextTreeItem *sitem = new contextTreeItem(item,sctx);
processCtx(sitem,sctx);
}
}
}
......@@ -143,14 +160,14 @@ void addDialog::selectFileName()
void addDialog::selectDirName()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Select a directory"),
ui.dirLineEdit->text(),
QFileDialog::DontResolveSymlinks
| QFileDialog::ShowDirsOnly);
if (!directory.isEmpty())
ui.dirLineEdit->setText(directory);
ui.dirLineEdit->setText(directory);
}
void addDialog::enqueueRequested()
......@@ -158,9 +175,18 @@ void addDialog::enqueueRequested()
int rights = 0xF10;
int contextId = 0;
QString group = ui.groupComboBox->currentText();
QString club = "";
int user = 0;
QString licence = ui.licenceComboBox->currentText();
QString comment = ui.commentTextEdit->toPlainText();
QString contextName;
if ( ui.allConnectedRadioButton->isChecked() )
if (ui.userCheckBox->isChecked())
user = ui.userLineEdit->text().toInt();
if (ui.clubCheckBox->isChecked())
club = ui.clubComboBox->currentText();
if ( ui.allConnectedRadioButton->isChecked() )
rights |= 1;
contextTreeItem* item = (contextTreeItem*) ui.treeWidget->currentItem();
......@@ -171,46 +197,55 @@ void addDialog::enqueueRequested()
contextName = item->Ctx->Name;
if ( ui.fileRadioButton->isChecked() ) {
if ( ui.fileLineEdit->text().isEmpty() ) return;
QFileInfo fileInfo = QFileInfo(ui.fileLineEdit->text());
if ( !fileInfo.exists() ) return;
QString ext = fileInfo.suffix();
if ( ext.toLower() == "jpg" || ext.toLower() == "png" )
mainwin->addFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group);
mainwin->addFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group,user,club,licence,comment);
else if ( ext.toLower() == "avi" || ext.toLower() == "mpg" || ext.toLower() == "mov" || ext.toLower() == "flv" )
mainwin->addVideoFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group);
mainwin->addVideoFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group,user,club,licence,comment);
} else {
if ( ui.dirLineEdit->text().isEmpty() ) return;
QDir dir(ui.dirLineEdit->text());
if (!dir.exists()) return;
dir.setFilter( QDir::Files | QDir::NoSymLinks | QDir::Readable );
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
QString ext = fileInfo.suffix();
if ( ext.toLower() == "jpg" || ext.toLower() == "png" )
mainwin->addFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group);
mainwin->addFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group,user,club,licence,comment);
else if ( ext.toLower() == "avi" || ext.toLower() == "mpg" || ext.toLower() == "mov" )
mainwin->addVideoFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group);
mainwin->addVideoFileToQueue(fileInfo.fileName(),fileInfo.filePath(),contextName,contextId,rights,group,user,club,licence,comment);
}
}
done(1);
}
void addDialog::enableClubComboBox(int state)
{
ui.clubComboBox->setEnabled(state);
}
void addDialog::enableUserLineEdit(int state)
{
ui.userLineEdit->setEnabled(state);
}
void addDialog::on_cancelButton_clicked()
{
......
/*
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.
......@@ -31,12 +32,12 @@ connectDialog::connectDialog(UbptSession *targetSession ,QWidget *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 )
void connectDialog::connectCurrent( int index )
{
Q_UNUSED(index);
connectToServer("https://ae.utbm.fr/sas2/autoup.php");
......@@ -48,36 +49,36 @@ 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..."));
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
else
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(1);
return;
}
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 ) {
......@@ -87,7 +88,7 @@ void connectDialog::enableMode( int mode ) {
ui.userGroupBox->setEnabled( mode == 2 );
ui.okButton->setEnabled( mode == 2 );
ui.cancelButton->setEnabled( mode != 0 );
}
void connectDialog::on_cancelButton_clicked()
......@@ -97,7 +98,7 @@ void connectDialog::on_cancelButton_clicked()
void connectDialog::on_okButton_clicked()
{
if ( connectToUBPT() )
done(1);
}
......@@ -105,38 +106,48 @@ void connectDialog::on_okButton_clicked()
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
else
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
return 0;
}
ui.connectProgress->setValue(50);
ui.connectInfo->setText(tr("Loading groups..."));
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;
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..."));
......@@ -145,11 +156,11 @@ int connectDialog::connectToUBPT()
if ( (err = session->FetchContexts()) ) {
ui.connectInfo->setText(tr("Error %1").arg(err));
enableMode(2);
return 0;
enableMode(2);
return 0;
}
ui.connectProgress->setValue(100);
ui.connectInfo->setText(tr("Connected"));
return 1;
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -14,16 +14,16 @@ UploadThread::UploadThread(QObject *parent)
void UploadThread::upload(transfertTreeItem *Item)
{
QMutexLocker locker(&mutex);
this->item = Item;
if (!isRunning())
start(LowPriority);
else
else
condition.wakeOne();
}
void UploadThread::progress_callback(double dltotal,double dlnow,double ultotal,double ulnow)
void UploadThread::progress_callback(double dltotal,double dlnow,double ultotal,double ulnow)
{
Q_UNUSED(dltotal);