ryxeo-webphotoalbum-git / original.cpp @ 7938c308
Historique | Voir | Annoter | Télécharger (20,6 ko)
1 |
/** Classe original: nom du projet prototype :)
|
---|---|
2 |
* @see https://redmine.ryxeo.com/projects/
|
3 |
* @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
|
4 |
* @see The GNU Public License (GNU/GPL) v3
|
5 |
*
|
6 |
*
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or modify
|
9 |
* it under the terms of the GNU General Public License as published by
|
10 |
* the Free Software Foundation; either version 3 of the License, or
|
11 |
* (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful, but
|
14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16 |
* for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License along
|
19 |
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
*/
|
21 |
|
22 |
|
23 |
#include "original.h" |
24 |
#include "ui_original.h" |
25 |
|
26 |
|
27 |
//---------------------------------------------------------------------------
|
28 |
QString formatSize(qint64 num) |
29 |
{ |
30 |
QString total; |
31 |
const qint64 kb = 1024; |
32 |
const qint64 mb = 1024 * kb; |
33 |
const qint64 gb = 1024 * mb; |
34 |
const qint64 tb = 1024 * gb; |
35 |
|
36 |
if (num >= tb) total = QString("%1TB").arg(QString::number(qreal(num) / tb, 'f', 2)); |
37 |
else if(num >= gb) total = QString("%1GB").arg(QString::number(qreal(num) / gb, 'f', 2)); |
38 |
else if(num >= mb) total = QString("%1MB").arg(QString::number(qreal(num) / mb, 'f', 1)); |
39 |
else if(num >= kb) total = QString("%1KB").arg(QString::number(qreal(num) / kb,'f', 1)); |
40 |
else total = QString("%1 bytes").arg(num); |
41 |
|
42 |
return total;
|
43 |
} |
44 |
|
45 |
// =========================================================================================================================
|
46 |
|
47 |
|
48 |
original::original(QWidget *parent) : |
49 |
QMainWindow(parent), |
50 |
ui(new Ui::original)
|
51 |
{ |
52 |
ui->setupUi(this);
|
53 |
|
54 |
m_currentProjectPictureNumber = 0;
|
55 |
|
56 |
//Hop pour que le splitter soit a peu pres a la bonne taille dès le début
|
57 |
QList<int> sizes;
|
58 |
sizes.append(200);
|
59 |
sizes.append(500);
|
60 |
ui->splitter->setSizes(sizes); |
61 |
|
62 |
#ifdef Q_OS_WIN32
|
63 |
QSettings settings(QSettings::UserScope, "Microsoft", "Windows"); |
64 |
settings.beginGroup("CurrentVersion/Explorer/Shell Folders");
|
65 |
m_baseDir = QDir(settings.value("Personal").toString() + "/RyXeo-Applications/WebPhotoAlbum"); |
66 |
qDebug() << "Sous windows " << m_baseDir;
|
67 |
#else
|
68 |
m_baseDir = QDir(QDir::homePath() + "/RyXeo-Applications/WebPhotoAlbum");
|
69 |
#endif
|
70 |
m_baseDir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); |
71 |
QFileInfoList list = m_baseDir.entryInfoList(); |
72 |
for(int i = 0; i < list.count(); i++) { |
73 |
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
|
74 |
item->setText(0, list.at(i).fileName());
|
75 |
item->setData(1,0,list.at(i).absoluteFilePath()); |
76 |
} |
77 |
|
78 |
ui->dateEdit->setDate(QDate::currentDate()); |
79 |
m_tools = new tools(m_baseDir, this); |
80 |
|
81 |
//============== l'étiquette invitant a déposer des images
|
82 |
m_labelDeposez = new QLabel(trUtf8("Glissez-déposez ici les photos que vous voulez ajouter à cet album ..."),ui->lwPictures); |
83 |
m_labelDeposez->setStyleSheet("color: #aaa;\nfont-size: 24pt;\nfont-weight: bold;\n");
|
84 |
m_labelDeposez->setScaledContents(true);
|
85 |
m_labelDeposez->setWordWrap(true);
|
86 |
m_labelDeposez->setAlignment(Qt::AlignCenter | Qt::AlignHCenter); |
87 |
m_labelDeposez->hide(); |
88 |
|
89 |
//============== le menu contextuel du treewidget (gauche)
|
90 |
m_menu = new QMenu(ui->treeWidget);
|
91 |
QList<QAction*> actions; |
92 |
|
93 |
QAction *a_nouveau = new QAction(QIcon(":/images/folder_add.png"),trUtf8("&Nouvel album"),m_menu); |
94 |
a_nouveau->setIconVisibleInMenu(true);
|
95 |
a_nouveau->connect(a_nouveau, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
96 |
|
97 |
QAction *a_renommer = new QAction(QIcon(":/images/folder_edit.png"),trUtf8("&Renommer..."),m_menu); |
98 |
a_renommer->setIconVisibleInMenu(true);
|
99 |
//a_renommer->connect(a_renommer, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
100 |
|
101 |
QAction *a_supprimer = new QAction(QIcon(":/images/folder_delete.png"),trUtf8("&Supprimer..."),m_menu); |
102 |
a_supprimer->setIconVisibleInMenu(true);
|
103 |
//a_supprimer->connect(a_supprimer, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
104 |
|
105 |
actions << a_nouveau << a_renommer << a_supprimer; |
106 |
m_menu->addActions(actions); |
107 |
|
108 |
//============== Accepte le drag & drop
|
109 |
ui->lwPictures->setDragEnabled(true);
|
110 |
ui->lwPictures->setDropIndicatorShown(true);
|
111 |
} |
112 |
|
113 |
original::~original() |
114 |
{ |
115 |
delete ui;
|
116 |
} |
117 |
|
118 |
void original::on_action_Nouvel_album_triggered()
|
119 |
{ |
120 |
m_currentProjectPictureNumber = 0;
|
121 |
bool ok;
|
122 |
QString text = NewAlbumDialog::getValue(this);
|
123 |
//Si ce nom n'existe pas déjà ...
|
124 |
QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
|
125 |
i->setText(0, text);
|
126 |
m_currentProjectDir = m_baseDir.absolutePath() + "/" + text;
|
127 |
i->setData(1,0,m_currentProjectDir); |
128 |
|
129 |
//Creation de la destination
|
130 |
QDir rep; |
131 |
rep.mkpath(m_currentProjectDir); |
132 |
rep.mkpath(m_currentProjectDir + "/hq");
|
133 |
rep.mkpath(m_currentProjectDir + "/lq");
|
134 |
rep.mkpath(m_currentProjectDir + "/mq");
|
135 |
rep.mkpath(m_currentProjectDir + "/thumbs");
|
136 |
rep.mkpath(m_currentProjectDir + "/zip");
|
137 |
rep.mkpath(m_currentProjectDir + "/comments");
|
138 |
|
139 |
} |
140 |
|
141 |
void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column) |
142 |
{ |
143 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt"); |
144 |
qDebug() << "Lecture de " << fi.absoluteFilePath();
|
145 |
|
146 |
//Remise a zero
|
147 |
ui->leTitre->clear(); |
148 |
ui->leAuthor->clear(); |
149 |
ui->leDesc->clear(); |
150 |
ui->dateEdit->clear(); |
151 |
ui->leLogin->clear(); |
152 |
ui->lePasswd->clear(); |
153 |
|
154 |
if(fi.exists()) {
|
155 |
QFile file(fi.absoluteFilePath()); |
156 |
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
157 |
return;
|
158 |
|
159 |
/* Exemple de fichier
|
160 |
name|Sortie Plongée SAGC. (Cala Montjoi, Spain) 28.05.2012
|
161 |
author|Éric Seigne
|
162 |
description|Sortie Plongée SAGC. (Cala Montjoi, Spain)
|
163 |
date|28.05.2012
|
164 |
restricted_user|sagc
|
165 |
restricted_password|motdepasse
|
166 |
*/
|
167 |
while (!file.atEnd()) {
|
168 |
QByteArray line = file.readLine(); |
169 |
QStringList tab = QString::fromUtf8(line.constData()).split('|');
|
170 |
if(tab.at(0) == "name") |
171 |
ui->leTitre->setText(tab.at(1));
|
172 |
if(tab.at(0) == "author") |
173 |
ui->leAuthor->setText(tab.at(1));
|
174 |
if(tab.at(0) == "description") |
175 |
ui->leDesc->setText(tab.at(1));
|
176 |
if(tab.at(0) == "date") { |
177 |
qDebug() << "**************** DATE : " << tab.at(1).trimmed(); |
178 |
ui->dateEdit->setDate(QDate::fromString(tab.at(1).trimmed(),"dd.MM.yyyy")); |
179 |
} |
180 |
if(tab.at(0) == "restricted_user") |
181 |
ui->leLogin->setText(tab.at(1));
|
182 |
if(tab.at(0) == "restricted_password") |
183 |
ui->lePasswd->setText(tab.at(1));
|
184 |
|
185 |
} |
186 |
|
187 |
} |
188 |
m_currentProjectPictureNumber++; |
189 |
refreshPictureList(); |
190 |
qDebug() << "On continue la numerotation a " << m_currentProjectPictureNumber;
|
191 |
qDebug() << "Espace de stockage du projet " << m_currentProjectDir;
|
192 |
} |
193 |
|
194 |
void original::on_btnSave_clicked()
|
195 |
{ |
196 |
QByteArray data; |
197 |
data.append(QString("name|%1\n").arg(ui->leTitre->text().trimmed()));
|
198 |
data.append(QString("author|%1\n").arg(ui->leAuthor->text().trimmed()));
|
199 |
data.append(QString("description|%1\n").arg(ui->leDesc->text().trimmed()));
|
200 |
data.append(QString("date|%1\n").arg(ui->dateEdit->date().toString("dd.MM.yyyy"))); |
201 |
if(ui->leLogin->text().trimmed() != "") { |
202 |
data.append(QString("restricted_user|%1\n").arg(ui->leLogin->text().trimmed()));
|
203 |
data.append(QString("restricted_password|%1\n").arg(ui->lePasswd->text().trimmed()));
|
204 |
} |
205 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt"); |
206 |
qDebug() << "Ecriture de " << fi.absoluteFilePath();
|
207 |
QFile file(fi.absoluteFilePath()); |
208 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
209 |
return;
|
210 |
QTextStream out(&file); |
211 |
out.setCodec("UTF-8");
|
212 |
out << data; |
213 |
file.close(); |
214 |
} |
215 |
|
216 |
|
217 |
void original::on_treeWidget_customContextMenuRequested(const QPoint &pos) |
218 |
{ |
219 |
m_menu->exec(ui->treeWidget->mapToGlobal(pos)); |
220 |
} |
221 |
|
222 |
void original::dragEnterEvent(QDragEnterEvent *event)
|
223 |
{ |
224 |
if (event->mimeData()->hasUrls())
|
225 |
{ |
226 |
event->acceptProposedAction(); |
227 |
} |
228 |
else
|
229 |
{ |
230 |
event->ignore(); |
231 |
} |
232 |
} |
233 |
|
234 |
void original::dropEvent(QDropEvent *event)
|
235 |
{ |
236 |
qDebug() << "Accepte le drop d'une image";
|
237 |
|
238 |
if(event->mimeData()->hasUrls())
|
239 |
{ |
240 |
for(int i = 0; i < event->mimeData()->urls().count(); i++) { |
241 |
//recopier l'image dans le projet
|
242 |
qDebug() << "Windows d&drop : " << event->mimeData()->urls().at(i).toString();
|
243 |
|
244 |
//Attention sous windows le drag & drop est un file:/// sous linux file:// et osx ?
|
245 |
#ifdef Q_OS_WIN32
|
246 |
addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file:///"));
|
247 |
#endif
|
248 |
#ifdef Q_OS_LINUX
|
249 |
addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file://"));
|
250 |
#endif
|
251 |
qDebug() << "Accepte le drop d'une image";
|
252 |
event->acceptProposedAction(); |
253 |
} |
254 |
} |
255 |
} |
256 |
|
257 |
void original::addPictureToProject(QString fic)
|
258 |
{ |
259 |
ui->statusBar->clearMessage(); |
260 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(fic),3000); |
261 |
qApp->processEvents(); |
262 |
|
263 |
if(m_currentProjectPictureNumber == 0) |
264 |
m_currentProjectPictureNumber = 1;
|
265 |
|
266 |
qDebug() << "Processing : " << fic;
|
267 |
QPixmap pixmap(fic); |
268 |
pixmap.save(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
269 |
qDebug() << "Save to : " << QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber); |
270 |
|
271 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(fic),3000); |
272 |
QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
273 |
pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
274 |
|
275 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(fic),3000); |
276 |
QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
277 |
pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
278 |
|
279 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(fic),3000); |
280 |
QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
281 |
pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
282 |
|
283 |
|
284 |
QFile file(QString("%1/comments/%2.txt").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
285 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
286 |
return;
|
287 |
|
288 |
QTextStream out(&file); |
289 |
out << "<span>Photo " + QString::number(m_currentProjectPictureNumber) + "</span>\n"; |
290 |
file.close(); |
291 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(fic),3000); |
292 |
|
293 |
//================== on copie les metadata
|
294 |
try {
|
295 |
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fic.toStdString()); |
296 |
Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
297 |
Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
298 |
Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
299 |
Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
300 |
if (image.get() != 0) |
301 |
{ |
302 |
image->readMetadata(); |
303 |
Exiv2::ExifData &exifData = image->exifData(); |
304 |
if (!exifData.empty())
|
305 |
{ |
306 |
bool setArtist = false; |
307 |
bool setCopyright = false; |
308 |
bool setSoftware = false; |
309 |
Exiv2::ExifData::const_iterator end = exifData.end(); |
310 |
// qDebug() << "============================ DEBUT ===============================";
|
311 |
for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
|
312 |
{ |
313 |
// qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
|
314 |
if (i->key() == "Exif.Image.Artist") { |
315 |
exifData["Exif.Image.Artist"] = ui->leAuthor->text().trimmed().toStdString();
|
316 |
setArtist = true;
|
317 |
} |
318 |
if (i->key() == "Exif.Image.Copyright") { |
319 |
exifData["Exif.Image.Copyright"] = ui->leAuthor->text().trimmed().toStdString();
|
320 |
setCopyright = true;
|
321 |
} |
322 |
if (i->key() == "Exif.Image.Software") { |
323 |
exifData["Exif.Image.Software"] = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/"; |
324 |
setSoftware = true;
|
325 |
} |
326 |
} |
327 |
//Si on n'a pas les meta il faut les ajouter
|
328 |
|
329 |
//Mise à jour de l'auteur
|
330 |
if(!setArtist) {
|
331 |
Exiv2::ExifKey k("Exif.Image.Artist");
|
332 |
Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString); |
333 |
v->read(ui->leAuthor->text().trimmed().toStdString()); |
334 |
exifData.add(k,v.get()); |
335 |
} |
336 |
|
337 |
if(!setCopyright) {
|
338 |
Exiv2::ExifKey k2("Exif.Image.Copyright");
|
339 |
Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString); |
340 |
v2->read(ui->leAuthor->text().trimmed().toStdString()); |
341 |
exifData.add(k2,v2.get()); |
342 |
} |
343 |
|
344 |
if(!setSoftware) {
|
345 |
Exiv2::ExifKey k3("Exif.Image.Software");
|
346 |
Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString); |
347 |
v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
|
348 |
exifData.add(k3,v3.get()); |
349 |
} |
350 |
|
351 |
// qDebug() << "============================ APRES ===============================";
|
352 |
Exiv2::ExifData::const_iterator end2 = exifData.end(); |
353 |
// for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
|
354 |
// {
|
355 |
// qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
|
356 |
// }
|
357 |
// qDebug() << "============================ FIN ===============================";
|
358 |
|
359 |
imageLQ->setExifData(exifData); |
360 |
imageLQ->writeMetadata(); |
361 |
|
362 |
imageMQ->setExifData(exifData); |
363 |
imageMQ->writeMetadata(); |
364 |
|
365 |
imageHQ->setExifData(exifData); |
366 |
imageHQ->writeMetadata(); |
367 |
|
368 |
imageThumb->setExifData(exifData); |
369 |
imageThumb->writeMetadata(); |
370 |
} |
371 |
} |
372 |
} |
373 |
catch(...) {
|
374 |
qDebug() << "Erreur EXIV2";
|
375 |
} |
376 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(fic),3000); |
377 |
m_currentProjectPictureNumber++; |
378 |
refreshPictureList(); |
379 |
} |
380 |
|
381 |
void original::refreshPictureList()
|
382 |
{ |
383 |
QTreeWidgetItem *item = ui->treeWidget->currentItem(); |
384 |
ui->lwPictures->clear(); |
385 |
m_currentProjectDir = item->data(1,0).toString(); |
386 |
int currentProjectPictureNumber=0; |
387 |
|
388 |
QDir dir(item->data(1,0).toString()+"/thumbs/"); |
389 |
dir.setFilter(QDir::Files); |
390 |
dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); |
391 |
QFileInfoList list = dir.entryInfoList(); |
392 |
for(int i = 0; i < list.count(); i++) { |
393 |
qDebug() << list.at(i).fileName(); |
394 |
QListWidgetItem *newitem = new QListWidgetItem();
|
395 |
QIcon icone(list.at(i).absoluteFilePath());//pour la mettre à coté de l'item
|
396 |
newitem->setIcon(icone); // ajout de la petite icone sur l'item
|
397 |
newitem->setText(list.at(i).fileName()); |
398 |
ui->lwPictures->insertItem(i,newitem); |
399 |
currentProjectPictureNumber = i+1;
|
400 |
} |
401 |
|
402 |
if(currentProjectPictureNumber == 0) { |
403 |
qDebug() << "Pas d'image ... on affiche le message drag & drop";
|
404 |
m_labelDeposez->resize(ui->lwPictures->size()); |
405 |
m_labelDeposez->move(ui->lwPictures->pos()); |
406 |
m_labelDeposez->show(); |
407 |
qDebug() << m_labelDeposez->pos(); |
408 |
qDebug() << m_labelDeposez->size(); |
409 |
} |
410 |
else {
|
411 |
m_labelDeposez->hide(); |
412 |
} |
413 |
m_currentProjectPictureNumber = currentProjectPictureNumber+1;
|
414 |
} |
415 |
|
416 |
void original::on_btnUpload_clicked()
|
417 |
{ |
418 |
qDebug() << "on_btnUpload_clicked : " << ui->treeWidget->currentItem()->data(1,0).toString(); |
419 |
|
420 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/hq", |
421 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/hq.zip"); |
422 |
|
423 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/mq", |
424 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/mq.zip"); |
425 |
|
426 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/lq", |
427 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/lq.zip"); |
428 |
|
429 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/thumbs", |
430 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/thumbs.zip"); |
431 |
|
432 |
m_tools->clear(); |
433 |
|
434 |
m_tools->ftpConnect(ui->leFTPServeur->text(), |
435 |
ui->leFTPLogin->text(), |
436 |
ui->leFTPPass->text()); |
437 |
|
438 |
m_tools->ftpMkdir(ui->leFTPDirectory->text()); |
439 |
m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries");
|
440 |
m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries/" + ui->treeWidget->currentItem()->text(0)); |
441 |
|
442 |
//On uploade la gallerie
|
443 |
//m_ftp->cd(ui->leFTPDirectory->text());
|
444 |
|
445 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()); |
446 |
QDir dir(fi.absoluteFilePath()); |
447 |
m_tools->parcoursRecursif(dir.absolutePath(),ui->treeWidget->currentItem()->text(0));
|
448 |
//qDebug() << m_fileListToUpload;
|
449 |
m_tools->uploadRecursifGallery(ui->leFTPDirectory->text()); |
450 |
connect(m_tools, SIGNAL(signalUpload(int,int)), this, SLOT(updateProgressFichier(int,int))); |
451 |
connect(m_tools, SIGNAL(signalUploadData(int,int)), this, SLOT(updateProgressData(int,int))); |
452 |
} |
453 |
|
454 |
void original::on_action_Assistant_d_installation_triggered()
|
455 |
{ |
456 |
Assistant *a = new Assistant(this); |
457 |
a->show(); |
458 |
} |
459 |
|
460 |
void original::updateProgressFichier(int total, int current) |
461 |
{ |
462 |
ui->pbFTPFichier->setMaximum(total); |
463 |
ui->pbFTPFichier->setValue(current); |
464 |
} |
465 |
|
466 |
void original::updateProgressData(int total, int current) |
467 |
{ |
468 |
ui->pbFTPProgress->setMaximum(total); |
469 |
ui->pbFTPProgress->setValue(current); |
470 |
} |
471 |
|
472 |
void original::makeZip(QString repSource, QString destFileName)
|
473 |
{ |
474 |
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
475 |
ui->statusBar->showMessage(QString::fromUtf8("Création du fichier ZIP %1 en cours").arg(destFileName), 5000); |
476 |
qApp->processEvents(); |
477 |
qDebug() << "original::makeZip " << repSource << " :: " << destFileName; |
478 |
//Creation d'une archive ZIP dans tous les cas
|
479 |
QuaZip zipDestination(destFileName); |
480 |
if(zipDestination.open(QuaZip::mdCreate)) {
|
481 |
//On sauvegarde tout dans ce fichier
|
482 |
QuaZipFile fichierDehors(&zipDestination); |
483 |
|
484 |
//Les droits par defaut en 644 pour les fichiers contenus dans le .zip
|
485 |
QuaZipNewInfo newInfo("");
|
486 |
int permission644 = 33188; |
487 |
newInfo.externalAttr = (permission644 << 16L);
|
488 |
|
489 |
QDir dir(repSource); |
490 |
dir.setFilter(QDir::Files); |
491 |
QFileInfoList fileList = dir.entryInfoList(); |
492 |
qDebug() << "avant " << fileList.count();
|
493 |
for(int i = 0; i < fileList.count(); i++) { |
494 |
QString fileName = fileList.at(i).fileName(); |
495 |
QFile fic(fileList.at(i).absoluteFilePath()); |
496 |
qDebug() << "On ajoute le fichier " << fileName;
|
497 |
newInfo.name = fileName; |
498 |
if(fic.open(QIODevice::ReadOnly) && fichierDehors.open(QIODevice::WriteOnly,newInfo)) {
|
499 |
fichierDehors.write(fic.read(fic.size())); |
500 |
fichierDehors.close(); |
501 |
fic.close(); |
502 |
qDebug() << " ajout ok";
|
503 |
} |
504 |
} |
505 |
zipDestination.close(); |
506 |
} |
507 |
QApplication::restoreOverrideCursor(); |
508 |
} |