ryxeo-webphotoalbum-git / webphotoalbum.cpp @ 83a77071
Historique | Voir | Annoter | Télécharger (22,1 ko)
1 |
/** Classe RyXeo WebPhotoAlbum: fichier principal de l'application
|
---|---|
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 "webphotoalbum.h" |
24 |
#include "ui_webphotoalbum.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 |
WebPhotoAlbum::WebPhotoAlbum(QWidget *parent) : |
49 |
QMainWindow(parent), |
50 |
ui(new Ui::WebPhotoAlbum)
|
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 |
connect(m_tools, SIGNAL(signalUploadEnd()), this, SLOT(uploadEnd()));
|
81 |
|
82 |
//============== l'étiquette invitant a déposer des images
|
83 |
m_labelDeposez = new QLabel(trUtf8("Glissez-déposez ici les photos que vous voulez ajouter à cet album ..."),ui->lwPictures); |
84 |
m_labelDeposez->setStyleSheet("color: #aaa;\nfont-size: 24pt;\nfont-weight: bold;\n");
|
85 |
m_labelDeposez->setScaledContents(true);
|
86 |
m_labelDeposez->setWordWrap(true);
|
87 |
m_labelDeposez->setAlignment(Qt::AlignCenter | Qt::AlignHCenter); |
88 |
m_labelDeposez->hide(); |
89 |
|
90 |
//============== le menu contextuel du treewidget (gauche)
|
91 |
m_menu = new QMenu(ui->treeWidget);
|
92 |
QList<QAction*> actions; |
93 |
|
94 |
QAction *a_nouveau = new QAction(QIcon(":/images/folder_add.png"),trUtf8("&Nouvel album"),m_menu); |
95 |
a_nouveau->setIconVisibleInMenu(true);
|
96 |
a_nouveau->connect(a_nouveau, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
97 |
|
98 |
QAction *a_renommer = new QAction(QIcon(":/images/folder_edit.png"),trUtf8("&Renommer..."),m_menu); |
99 |
a_renommer->setIconVisibleInMenu(true);
|
100 |
//a_renommer->connect(a_renommer, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
101 |
|
102 |
QAction *a_supprimer = new QAction(QIcon(":/images/folder_delete.png"),trUtf8("&Supprimer..."),m_menu); |
103 |
a_supprimer->setIconVisibleInMenu(true);
|
104 |
//a_supprimer->connect(a_supprimer, SIGNAL(triggered()), this, SLOT(on_action_Nouvel_album_triggered()));
|
105 |
|
106 |
actions << a_nouveau << a_renommer << a_supprimer; |
107 |
m_menu->addActions(actions); |
108 |
|
109 |
//============== Accepte le drag & drop
|
110 |
ui->lwPictures->setDragEnabled(true);
|
111 |
ui->lwPictures->setDropIndicatorShown(true);
|
112 |
} |
113 |
|
114 |
WebPhotoAlbum::~WebPhotoAlbum() |
115 |
{ |
116 |
delete ui;
|
117 |
} |
118 |
|
119 |
void WebPhotoAlbum::on_action_Nouvel_album_triggered()
|
120 |
{ |
121 |
m_currentProjectPictureNumber = 0;
|
122 |
bool ok;
|
123 |
QString text = NewAlbumDialog::getValue(this);
|
124 |
//Si ce nom n'existe pas déjà ...
|
125 |
QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
|
126 |
i->setText(0, text);
|
127 |
m_currentProjectDir = m_baseDir.absolutePath() + "/" + text;
|
128 |
i->setData(1,0,m_currentProjectDir); |
129 |
|
130 |
//Creation de la destination
|
131 |
QDir rep; |
132 |
rep.mkpath(m_currentProjectDir); |
133 |
rep.mkpath(m_currentProjectDir + "/hq");
|
134 |
rep.mkpath(m_currentProjectDir + "/lq");
|
135 |
rep.mkpath(m_currentProjectDir + "/mq");
|
136 |
rep.mkpath(m_currentProjectDir + "/thumbs");
|
137 |
rep.mkpath(m_currentProjectDir + "/zip");
|
138 |
rep.mkpath(m_currentProjectDir + "/comments");
|
139 |
|
140 |
} |
141 |
|
142 |
void WebPhotoAlbum::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column) |
143 |
{ |
144 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt"); |
145 |
qDebug() << "Lecture de " << fi.absoluteFilePath();
|
146 |
|
147 |
//Remise a zero
|
148 |
ui->leTitre->clear(); |
149 |
ui->leAuthor->clear(); |
150 |
ui->leDesc->clear(); |
151 |
ui->dateEdit->clear(); |
152 |
ui->leLogin->clear(); |
153 |
ui->lePasswd->clear(); |
154 |
|
155 |
if(fi.exists()) {
|
156 |
QFile file(fi.absoluteFilePath()); |
157 |
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
158 |
return;
|
159 |
|
160 |
/* Exemple de fichier
|
161 |
name|Sortie Plongée SAGC. (Cala Montjoi, Spain) 28.05.2012
|
162 |
author|Éric Seigne
|
163 |
description|Sortie Plongée SAGC. (Cala Montjoi, Spain)
|
164 |
date|28.05.2012
|
165 |
restricted_user|sagc
|
166 |
restricted_password|motdepasse
|
167 |
*/
|
168 |
while (!file.atEnd()) {
|
169 |
QByteArray line = file.readLine(); |
170 |
QStringList tab = QString::fromUtf8(line.constData()).split('|');
|
171 |
if(tab.at(0) == "name") |
172 |
ui->leTitre->setText(tab.at(1));
|
173 |
if(tab.at(0) == "author") |
174 |
ui->leAuthor->setText(tab.at(1));
|
175 |
if(tab.at(0) == "description") |
176 |
ui->leDesc->setText(tab.at(1));
|
177 |
if(tab.at(0) == "date") { |
178 |
qDebug() << "**************** DATE : " << tab.at(1).trimmed(); |
179 |
ui->dateEdit->setDate(QDate::fromString(tab.at(1).trimmed(),"dd.MM.yyyy")); |
180 |
} |
181 |
if(tab.at(0) == "restricted_user") |
182 |
ui->leLogin->setText(tab.at(1));
|
183 |
if(tab.at(0) == "restricted_password") |
184 |
ui->lePasswd->setText(tab.at(1));
|
185 |
|
186 |
} |
187 |
|
188 |
} |
189 |
m_currentProjectPictureNumber++; |
190 |
refreshPictureList(); |
191 |
qDebug() << "On continue la numerotation a " << m_currentProjectPictureNumber;
|
192 |
qDebug() << "Espace de stockage du projet " << m_currentProjectDir;
|
193 |
} |
194 |
|
195 |
void WebPhotoAlbum::on_btnSave_clicked()
|
196 |
{ |
197 |
QByteArray data; |
198 |
data.append(QString("name|%1\n").arg(ui->leTitre->text().trimmed()));
|
199 |
data.append(QString("author|%1\n").arg(ui->leAuthor->text().trimmed()));
|
200 |
data.append(QString("description|%1\n").arg(ui->leDesc->text().trimmed()));
|
201 |
data.append(QString("date|%1\n").arg(ui->dateEdit->date().toString("dd.MM.yyyy"))); |
202 |
if(ui->leLogin->text().trimmed() != "") { |
203 |
data.append(QString("restricted_user|%1\n").arg(ui->leLogin->text().trimmed()));
|
204 |
data.append(QString("restricted_password|%1\n").arg(ui->lePasswd->text().trimmed()));
|
205 |
} |
206 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt"); |
207 |
qDebug() << "Ecriture de " << fi.absoluteFilePath();
|
208 |
QFile file(fi.absoluteFilePath()); |
209 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
210 |
return;
|
211 |
QTextStream out(&file); |
212 |
out.setCodec("UTF-8");
|
213 |
out << data; |
214 |
file.close(); |
215 |
} |
216 |
|
217 |
|
218 |
void WebPhotoAlbum::on_treeWidget_customContextMenuRequested(const QPoint &pos) |
219 |
{ |
220 |
m_menu->exec(ui->treeWidget->mapToGlobal(pos)); |
221 |
} |
222 |
|
223 |
void WebPhotoAlbum::dragEnterEvent(QDragEnterEvent *event)
|
224 |
{ |
225 |
if (event->mimeData()->hasUrls())
|
226 |
{ |
227 |
event->acceptProposedAction(); |
228 |
} |
229 |
else
|
230 |
{ |
231 |
event->ignore(); |
232 |
} |
233 |
} |
234 |
|
235 |
void WebPhotoAlbum::dropEvent(QDropEvent *event)
|
236 |
{ |
237 |
qDebug() << "Accepte le drop d'une image";
|
238 |
|
239 |
if(event->mimeData()->hasUrls())
|
240 |
{ |
241 |
for(int i = 0; i < event->mimeData()->urls().count(); i++) { |
242 |
//recopier l'image dans le projet
|
243 |
qDebug() << "Windows d&drop : " << event->mimeData()->urls().at(i).toString();
|
244 |
|
245 |
//Attention sous windows le drag & drop est un file:/// sous linux file:// et osx ?
|
246 |
#ifdef Q_OS_WIN32
|
247 |
addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file:///"));
|
248 |
#endif
|
249 |
#ifdef Q_OS_LINUX
|
250 |
addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file://"));
|
251 |
#endif
|
252 |
qDebug() << "Accepte le drop d'une image";
|
253 |
event->acceptProposedAction(); |
254 |
} |
255 |
} |
256 |
} |
257 |
|
258 |
void WebPhotoAlbum::addPictureToProject(QString fic)
|
259 |
{ |
260 |
ui->statusBar->clearMessage(); |
261 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(fic),3000); |
262 |
qApp->processEvents(); |
263 |
|
264 |
if(m_currentProjectPictureNumber == 0) |
265 |
m_currentProjectPictureNumber = 1;
|
266 |
|
267 |
qDebug() << "Processing : " << fic;
|
268 |
QPixmap pixmap(fic); |
269 |
pixmap.save(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
270 |
qDebug() << "Save to : " << QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber); |
271 |
|
272 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(fic),3000); |
273 |
QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
274 |
pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
275 |
|
276 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(fic),3000); |
277 |
QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
278 |
pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
279 |
|
280 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(fic),3000); |
281 |
QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
282 |
pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
283 |
|
284 |
|
285 |
QFile file(QString("%1/comments/%2.txt").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
286 |
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
287 |
return;
|
288 |
|
289 |
QTextStream out(&file); |
290 |
out << "<span>Photo " + QString::number(m_currentProjectPictureNumber) + "</span>\n"; |
291 |
file.close(); |
292 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(fic),3000); |
293 |
|
294 |
//================== on copie les metadata
|
295 |
try {
|
296 |
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fic.toStdString()); |
297 |
Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
298 |
Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
299 |
Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
300 |
Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
301 |
if (image.get() != 0) |
302 |
{ |
303 |
image->readMetadata(); |
304 |
Exiv2::ExifData &exifData = image->exifData(); |
305 |
if (!exifData.empty())
|
306 |
{ |
307 |
bool setArtist = false; |
308 |
bool setCopyright = false; |
309 |
bool setSoftware = false; |
310 |
Exiv2::ExifData::const_iterator end = exifData.end(); |
311 |
// qDebug() << "============================ DEBUT ===============================";
|
312 |
for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
|
313 |
{ |
314 |
// qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
|
315 |
if (i->key() == "Exif.Image.Artist") { |
316 |
exifData["Exif.Image.Artist"] = ui->leAuthor->text().trimmed().toStdString();
|
317 |
setArtist = true;
|
318 |
} |
319 |
if (i->key() == "Exif.Image.Copyright") { |
320 |
exifData["Exif.Image.Copyright"] = ui->leAuthor->text().trimmed().toStdString();
|
321 |
setCopyright = true;
|
322 |
} |
323 |
if (i->key() == "Exif.Image.Software") { |
324 |
exifData["Exif.Image.Software"] = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/"; |
325 |
setSoftware = true;
|
326 |
} |
327 |
} |
328 |
//Si on n'a pas les meta il faut les ajouter
|
329 |
|
330 |
//Mise à jour de l'auteur
|
331 |
if(!setArtist) {
|
332 |
Exiv2::ExifKey k("Exif.Image.Artist");
|
333 |
Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString); |
334 |
v->read(ui->leAuthor->text().trimmed().toStdString()); |
335 |
exifData.add(k,v.get()); |
336 |
} |
337 |
|
338 |
if(!setCopyright) {
|
339 |
Exiv2::ExifKey k2("Exif.Image.Copyright");
|
340 |
Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString); |
341 |
v2->read(ui->leAuthor->text().trimmed().toStdString()); |
342 |
exifData.add(k2,v2.get()); |
343 |
} |
344 |
|
345 |
if(!setSoftware) {
|
346 |
Exiv2::ExifKey k3("Exif.Image.Software");
|
347 |
Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString); |
348 |
v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
|
349 |
exifData.add(k3,v3.get()); |
350 |
} |
351 |
|
352 |
// qDebug() << "============================ APRES ===============================";
|
353 |
Exiv2::ExifData::const_iterator end2 = exifData.end(); |
354 |
// for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
|
355 |
// {
|
356 |
// qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
|
357 |
// }
|
358 |
// qDebug() << "============================ FIN ===============================";
|
359 |
|
360 |
imageLQ->setExifData(exifData); |
361 |
imageLQ->writeMetadata(); |
362 |
|
363 |
imageMQ->setExifData(exifData); |
364 |
imageMQ->writeMetadata(); |
365 |
|
366 |
imageHQ->setExifData(exifData); |
367 |
imageHQ->writeMetadata(); |
368 |
|
369 |
imageThumb->setExifData(exifData); |
370 |
imageThumb->writeMetadata(); |
371 |
} |
372 |
} |
373 |
} |
374 |
catch(...) {
|
375 |
qDebug() << "Erreur EXIV2";
|
376 |
} |
377 |
ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(fic),3000); |
378 |
m_currentProjectPictureNumber++; |
379 |
refreshPictureList(); |
380 |
} |
381 |
|
382 |
void WebPhotoAlbum::refreshPictureList()
|
383 |
{ |
384 |
QTreeWidgetItem *item = ui->treeWidget->currentItem(); |
385 |
ui->lwPictures->clear(); |
386 |
m_currentProjectDir = item->data(1,0).toString(); |
387 |
int currentProjectPictureNumber=0; |
388 |
|
389 |
QDir dir(item->data(1,0).toString()+"/thumbs/"); |
390 |
dir.setFilter(QDir::Files); |
391 |
dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); |
392 |
QFileInfoList list = dir.entryInfoList(); |
393 |
for(int i = 0; i < list.count(); i++) { |
394 |
qDebug() << list.at(i).fileName(); |
395 |
QListWidgetItem *newitem = new QListWidgetItem();
|
396 |
QIcon icone(list.at(i).absoluteFilePath());//pour la mettre à coté de l'item
|
397 |
newitem->setIcon(icone); // ajout de la petite icone sur l'item
|
398 |
newitem->setText(list.at(i).fileName()); |
399 |
ui->lwPictures->insertItem(i,newitem); |
400 |
currentProjectPictureNumber = i+1;
|
401 |
} |
402 |
|
403 |
if(currentProjectPictureNumber == 0) { |
404 |
qDebug() << "Pas d'image ... on affiche le message drag & drop";
|
405 |
m_labelDeposez->resize(ui->lwPictures->size()); |
406 |
m_labelDeposez->move(ui->lwPictures->pos()); |
407 |
m_labelDeposez->show(); |
408 |
qDebug() << m_labelDeposez->pos(); |
409 |
qDebug() << m_labelDeposez->size(); |
410 |
} |
411 |
else {
|
412 |
m_labelDeposez->hide(); |
413 |
} |
414 |
m_currentProjectPictureNumber = currentProjectPictureNumber+1;
|
415 |
} |
416 |
|
417 |
void WebPhotoAlbum::on_btnUpload_clicked()
|
418 |
{ |
419 |
qDebug() << "on_btnUpload_clicked : " << ui->treeWidget->currentItem()->data(1,0).toString(); |
420 |
|
421 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/hq", |
422 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/hq.zip"); |
423 |
|
424 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/mq", |
425 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/mq.zip"); |
426 |
|
427 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/lq", |
428 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/lq.zip"); |
429 |
|
430 |
makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/thumbs", |
431 |
m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/thumbs.zip"); |
432 |
|
433 |
QSettings settings; |
434 |
settings.beginGroup("FTP");
|
435 |
settings.setValue("FTPLogin",ui->leFTPLogin->text());
|
436 |
settings.setValue("FTPPass",ui->leFTPPass->text());
|
437 |
settings.setValue("FTPServeur",ui->leFTPServeur->text());
|
438 |
settings.setValue("FTPDirectory",ui->leFTPDirectory->text());
|
439 |
settings.setValue("SiteAdresse",ui->leSiteAdresse->text());
|
440 |
|
441 |
m_tools->clear(); |
442 |
|
443 |
m_tools->ftpConnect(ui->leFTPServeur->text(), |
444 |
ui->leFTPLogin->text(), |
445 |
ui->leFTPPass->text()); |
446 |
|
447 |
m_tools->ftpMkdir(ui->leFTPDirectory->text()); |
448 |
m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries");
|
449 |
m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries/" + ui->treeWidget->currentItem()->text(0)); |
450 |
|
451 |
//On uploade la gallerie
|
452 |
//m_ftp->cd(ui->leFTPDirectory->text());
|
453 |
|
454 |
QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()); |
455 |
QDir dir(fi.absoluteFilePath()); |
456 |
m_tools->parcoursRecursif(dir.absolutePath(),ui->treeWidget->currentItem()->text(0));
|
457 |
//qDebug() << m_fileListToUpload;
|
458 |
m_tools->uploadRecursifGallery(ui->leFTPDirectory->text(),ui->leSiteAdresse->text().trimmed()); |
459 |
connect(m_tools, SIGNAL(signalUpload(int,int,QString)), this, SLOT(updateProgressFichier(int,int,QString))); |
460 |
connect(m_tools, SIGNAL(signalUploadData(int,int)), this, SLOT(updateProgressData(int,int))); |
461 |
} |
462 |
|
463 |
void WebPhotoAlbum::on_action_Assistant_d_installation_triggered()
|
464 |
{ |
465 |
Assistant *a = new Assistant(this); |
466 |
a->show(); |
467 |
} |
468 |
|
469 |
void WebPhotoAlbum::updateProgressFichier(int total, int current, QString fileName) |
470 |
{ |
471 |
ui->pbFTPFichier->setMaximum(total); |
472 |
ui->pbFTPFichier->setValue(current); |
473 |
ui->textBrowser->append(fileName); |
474 |
} |
475 |
|
476 |
void WebPhotoAlbum::updateProgressData(int total, int current) |
477 |
{ |
478 |
ui->pbFTPProgress->setMaximum(total); |
479 |
ui->pbFTPProgress->setValue(current); |
480 |
} |
481 |
|
482 |
void WebPhotoAlbum::makeZip(QString repSource, QString destFileName)
|
483 |
{ |
484 |
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
485 |
ui->statusBar->showMessage(QString::fromUtf8("Création du fichier ZIP %1 en cours").arg(destFileName), 5000); |
486 |
qApp->processEvents(); |
487 |
qDebug() << "WebPhotoAlbum::makeZip " << repSource << " :: " << destFileName; |
488 |
//Creation d'une archive ZIP dans tous les cas
|
489 |
QuaZip zipDestination(destFileName); |
490 |
if(zipDestination.open(QuaZip::mdCreate)) {
|
491 |
//On sauvegarde tout dans ce fichier
|
492 |
QuaZipFile fichierDehors(&zipDestination); |
493 |
|
494 |
//Les droits par defaut en 644 pour les fichiers contenus dans le .zip
|
495 |
QuaZipNewInfo newInfo("");
|
496 |
int permission644 = 33188; |
497 |
newInfo.externalAttr = (permission644 << 16L);
|
498 |
|
499 |
QDir dir(repSource); |
500 |
dir.setFilter(QDir::Files); |
501 |
QFileInfoList fileList = dir.entryInfoList(); |
502 |
qDebug() << "avant " << fileList.count();
|
503 |
for(int i = 0; i < fileList.count(); i++) { |
504 |
QString fileName = fileList.at(i).fileName(); |
505 |
QFile fic(fileList.at(i).absoluteFilePath()); |
506 |
qDebug() << "On ajoute le fichier " << fileName;
|
507 |
newInfo.name = fileName; |
508 |
if(fic.open(QIODevice::ReadOnly) && fichierDehors.open(QIODevice::WriteOnly,newInfo)) {
|
509 |
fichierDehors.write(fic.read(fic.size())); |
510 |
fichierDehors.close(); |
511 |
fic.close(); |
512 |
qDebug() << " ajout ok";
|
513 |
} |
514 |
} |
515 |
zipDestination.close(); |
516 |
} |
517 |
QApplication::restoreOverrideCursor(); |
518 |
} |
519 |
|
520 |
void WebPhotoAlbum::uploadEnd()
|
521 |
{ |
522 |
ui->textBrowser->append(trUtf8("Téléchargement terminé"));
|
523 |
} |
524 |
|
525 |
void WebPhotoAlbum::on_tabWidget_currentChanged(int index) |
526 |
{ |
527 |
if(index == 2) { |
528 |
//Lecture du QSettings pour avoir les infos login / pass / url site
|
529 |
QSettings settings; |
530 |
settings.beginGroup("FTP");
|
531 |
ui->leFTPLogin->setText(settings.value("FTPLogin","identifiant").toString()); |
532 |
ui->leFTPPass->setText(settings.value("FTPPass").toString());
|
533 |
ui->leFTPServeur->setText(settings.value("FTPServeur","ftpperso.free.fr").toString()); |
534 |
ui->leFTPDirectory->setText(settings.value("FTPDirectory","/album").toString()); |
535 |
ui->leSiteAdresse->setText(settings.value("SiteAdresse","http://votresite.free.fr/album/").toString()); |
536 |
} |
537 |
} |