ryxeo-webphotoalbum-git / webphotoalbum.cpp @ 4437014e
Historique | Voir | Annoter | Télécharger (22,2 ko)
1 | 925ac0ca | Eric Seigne | /** Classe RyXeo WebPhotoAlbum: fichier principal de l'application
|
---|---|---|---|
2 | ef177d24 | Eric Seigne | * @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 | 8ed8fc1a | Eric Seigne | #include "webphotoalbum.h" |
24 | #include "ui_webphotoalbum.h" |
||
25 | ef177d24 | Eric Seigne | |
26 | 71c02254 | Eric Seigne | |
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 | 8ed8fc1a | Eric Seigne | WebPhotoAlbum::WebPhotoAlbum(QWidget *parent) : |
49 | ef177d24 | Eric Seigne | QMainWindow(parent), |
50 | 8ed8fc1a | Eric Seigne | ui(new Ui::WebPhotoAlbum)
|
51 | ef177d24 | Eric Seigne | { |
52 | ui->setupUi(this);
|
||
53 | 92dc01fa | Eric Seigne | |
54 | a535756c | Eric Seigne | m_currentProjectPictureNumber = 0;
|
55 | |||
56 | db5783a6 | Eric Seigne | //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 | 7938c308 | Eric Seigne | #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 | d044a969 | Eric Seigne | m_baseDir = QDir(QDir::homePath() + "/RyXeo-Applications/WebPhotoAlbum");
|
69 | 7938c308 | Eric Seigne | #endif
|
70 | 61556262 | Eric Seigne | m_baseDir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); |
71 | cf314c59 | Eric Seigne | QFileInfoList list = m_baseDir.entryInfoList(); |
72 | 92dc01fa | Eric Seigne | 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 | d4a9c7c8 | Eric Seigne | |
78 | ui->dateEdit->setDate(QDate::currentDate()); |
||
79 | 293017f7 | Eric Seigne | m_tools = new tools(m_baseDir, this); |
80 | 925ac0ca | Eric Seigne | connect(m_tools, SIGNAL(signalUploadEnd()), this, SLOT(uploadEnd()));
|
81 | b489456c | Eric Seigne | |
82 | db5783a6 | Eric Seigne | //============== 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 | b489456c | Eric Seigne | //============== 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 | d4b9f775 | Eric Seigne | |
109 | a535756c | Eric Seigne | //============== Accepte le drag & drop
|
110 | ui->lwPictures->setDragEnabled(true);
|
||
111 | ui->lwPictures->setDropIndicatorShown(true);
|
||
112 | ef177d24 | Eric Seigne | } |
113 | |||
114 | 8ed8fc1a | Eric Seigne | WebPhotoAlbum::~WebPhotoAlbum() |
115 | ef177d24 | Eric Seigne | { |
116 | delete ui;
|
||
117 | } |
||
118 | |||
119 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_action_Nouvel_album_triggered()
|
120 | 71c02254 | Eric Seigne | { |
121 | a535756c | Eric Seigne | m_currentProjectPictureNumber = 0;
|
122 | 61556262 | Eric Seigne | bool ok;
|
123 | d4a9c7c8 | Eric Seigne | QString text = NewAlbumDialog::getValue(this);
|
124 | 61556262 | Eric Seigne | //Si ce nom n'existe pas déjà ...
|
125 | 71c02254 | Eric Seigne | QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
|
126 | 61556262 | Eric Seigne | i->setText(0, text);
|
127 | a535756c | Eric Seigne | m_currentProjectDir = m_baseDir.absolutePath() + "/" + text;
|
128 | 24cec736 | Eric Seigne | i->setData(1,0,m_currentProjectDir); |
129 | a535756c | Eric Seigne | |
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 | 71c02254 | Eric Seigne | } |
141 | |||
142 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column) |
143 | 71c02254 | Eric Seigne | { |
144 | db5783a6 | Eric Seigne | 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 | d4a9c7c8 | Eric Seigne | 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 | db5783a6 | Eric Seigne | 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 | d4a9c7c8 | Eric Seigne | m_currentProjectPictureNumber++; |
190 | d8d0edae | Eric Seigne | refreshPictureList(); |
191 | db5783a6 | Eric Seigne | qDebug() << "On continue la numerotation a " << m_currentProjectPictureNumber;
|
192 | qDebug() << "Espace de stockage du projet " << m_currentProjectDir;
|
||
193 | 92dc01fa | Eric Seigne | } |
194 | |||
195 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_btnSave_clicked()
|
196 | 71c02254 | Eric Seigne | { |
197 | 8801fb5e | Eric Seigne | 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 | d4a9c7c8 | Eric Seigne | data.append(QString("date|%1\n").arg(ui->dateEdit->date().toString("dd.MM.yyyy"))); |
202 | 8801fb5e | Eric Seigne | 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 | 71c02254 | Eric Seigne | } |
216 | b489456c | Eric Seigne | |
217 | |||
218 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_treeWidget_customContextMenuRequested(const QPoint &pos) |
219 | b489456c | Eric Seigne | { |
220 | m_menu->exec(ui->treeWidget->mapToGlobal(pos)); |
||
221 | } |
||
222 | d4b9f775 | Eric Seigne | |
223 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::dragEnterEvent(QDragEnterEvent *event)
|
224 | d4b9f775 | Eric Seigne | { |
225 | if (event->mimeData()->hasUrls())
|
||
226 | { |
||
227 | event->acceptProposedAction(); |
||
228 | } |
||
229 | else
|
||
230 | { |
||
231 | event->ignore(); |
||
232 | } |
||
233 | } |
||
234 | |||
235 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::dropEvent(QDropEvent *event)
|
236 | d4b9f775 | Eric Seigne | { |
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 | a535756c | Eric Seigne | |
245 | d4b9f775 | Eric Seigne | //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 | a535756c | Eric Seigne | addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file://"));
|
251 | d4b9f775 | Eric Seigne | #endif
|
252 | 4437014e | Eric Seigne | #ifdef Q_OS_MAC
|
253 | addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file://"));
|
||
254 | #endif
|
||
255 | d4b9f775 | Eric Seigne | qDebug() << "Accepte le drop d'une image";
|
256 | event->acceptProposedAction(); |
||
257 | } |
||
258 | } |
||
259 | } |
||
260 | a535756c | Eric Seigne | |
261 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::addPictureToProject(QString fic)
|
262 | a535756c | Eric Seigne | { |
263 | ui->statusBar->clearMessage(); |
||
264 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(fic),3000); |
||
265 | qApp->processEvents(); |
||
266 | |||
267 | d8d0edae | Eric Seigne | if(m_currentProjectPictureNumber == 0) |
268 | m_currentProjectPictureNumber = 1;
|
||
269 | |||
270 | a535756c | Eric Seigne | qDebug() << "Processing : " << fic;
|
271 | QPixmap pixmap(fic); |
||
272 | pixmap.save(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
||
273 | qDebug() << "Save to : " << QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber); |
||
274 | |||
275 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(fic),3000); |
||
276 | QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
277 | pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
||
278 | |||
279 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(fic),3000); |
||
280 | QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
281 | pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
||
282 | |||
283 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(fic),3000); |
||
284 | QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
285 | pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
||
286 | |||
287 | |||
288 | QFile file(QString("%1/comments/%2.txt").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
|
||
289 | if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||
290 | return;
|
||
291 | |||
292 | QTextStream out(&file); |
||
293 | out << "<span>Photo " + QString::number(m_currentProjectPictureNumber) + "</span>\n"; |
||
294 | file.close(); |
||
295 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(fic),3000); |
||
296 | |||
297 | //================== on copie les metadata
|
||
298 | d8d0edae | Eric Seigne | try {
|
299 | Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fic.toStdString()); |
||
300 | Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
||
301 | Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
||
302 | Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
||
303 | Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
|
||
304 | if (image.get() != 0) |
||
305 | a535756c | Eric Seigne | { |
306 | d8d0edae | Eric Seigne | image->readMetadata(); |
307 | Exiv2::ExifData &exifData = image->exifData(); |
||
308 | if (!exifData.empty())
|
||
309 | a535756c | Eric Seigne | { |
310 | d8d0edae | Eric Seigne | bool setArtist = false; |
311 | bool setCopyright = false; |
||
312 | bool setSoftware = false; |
||
313 | Exiv2::ExifData::const_iterator end = exifData.end(); |
||
314 | d4a9c7c8 | Eric Seigne | // qDebug() << "============================ DEBUT ===============================";
|
315 | d8d0edae | Eric Seigne | for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
|
316 | { |
||
317 | d4a9c7c8 | Eric Seigne | // qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
|
318 | d8d0edae | Eric Seigne | if (i->key() == "Exif.Image.Artist") { |
319 | 108e72d8 | Eric Seigne | exifData["Exif.Image.Artist"] = ui->leAuthor->text().trimmed().toStdString();
|
320 | d8d0edae | Eric Seigne | setArtist = true;
|
321 | } |
||
322 | if (i->key() == "Exif.Image.Copyright") { |
||
323 | 108e72d8 | Eric Seigne | exifData["Exif.Image.Copyright"] = ui->leAuthor->text().trimmed().toStdString();
|
324 | d8d0edae | Eric Seigne | setCopyright = true;
|
325 | } |
||
326 | if (i->key() == "Exif.Image.Software") { |
||
327 | exifData["Exif.Image.Software"] = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/"; |
||
328 | setSoftware = true;
|
||
329 | } |
||
330 | a535756c | Eric Seigne | } |
331 | d8d0edae | Eric Seigne | //Si on n'a pas les meta il faut les ajouter
|
332 | |||
333 | //Mise à jour de l'auteur
|
||
334 | if(!setArtist) {
|
||
335 | Exiv2::ExifKey k("Exif.Image.Artist");
|
||
336 | Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString); |
||
337 | 108e72d8 | Eric Seigne | v->read(ui->leAuthor->text().trimmed().toStdString()); |
338 | d8d0edae | Eric Seigne | exifData.add(k,v.get()); |
339 | a535756c | Eric Seigne | } |
340 | |||
341 | d8d0edae | Eric Seigne | if(!setCopyright) {
|
342 | Exiv2::ExifKey k2("Exif.Image.Copyright");
|
||
343 | Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString); |
||
344 | 108e72d8 | Eric Seigne | v2->read(ui->leAuthor->text().trimmed().toStdString()); |
345 | d8d0edae | Eric Seigne | exifData.add(k2,v2.get()); |
346 | } |
||
347 | a535756c | Eric Seigne | |
348 | d8d0edae | Eric Seigne | if(!setSoftware) {
|
349 | Exiv2::ExifKey k3("Exif.Image.Software");
|
||
350 | Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString); |
||
351 | v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
|
||
352 | exifData.add(k3,v3.get()); |
||
353 | } |
||
354 | a535756c | Eric Seigne | |
355 | d4a9c7c8 | Eric Seigne | // qDebug() << "============================ APRES ===============================";
|
356 | d8d0edae | Eric Seigne | Exiv2::ExifData::const_iterator end2 = exifData.end(); |
357 | d4a9c7c8 | Eric Seigne | // for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
|
358 | // {
|
||
359 | // qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
|
||
360 | // }
|
||
361 | // qDebug() << "============================ FIN ===============================";
|
||
362 | a535756c | Eric Seigne | |
363 | d8d0edae | Eric Seigne | imageLQ->setExifData(exifData); |
364 | imageLQ->writeMetadata(); |
||
365 | a535756c | Eric Seigne | |
366 | d8d0edae | Eric Seigne | imageMQ->setExifData(exifData); |
367 | imageMQ->writeMetadata(); |
||
368 | a535756c | Eric Seigne | |
369 | d8d0edae | Eric Seigne | imageHQ->setExifData(exifData); |
370 | imageHQ->writeMetadata(); |
||
371 | a535756c | Eric Seigne | |
372 | d8d0edae | Eric Seigne | imageThumb->setExifData(exifData); |
373 | imageThumb->writeMetadata(); |
||
374 | } |
||
375 | a535756c | Eric Seigne | } |
376 | } |
||
377 | d8d0edae | Eric Seigne | catch(...) {
|
378 | qDebug() << "Erreur EXIV2";
|
||
379 | } |
||
380 | a535756c | Eric Seigne | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(fic),3000); |
381 | d4a9c7c8 | Eric Seigne | m_currentProjectPictureNumber++; |
382 | d8d0edae | Eric Seigne | refreshPictureList(); |
383 | a535756c | Eric Seigne | } |
384 | db5783a6 | Eric Seigne | |
385 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::refreshPictureList()
|
386 | d8d0edae | Eric Seigne | { |
387 | QTreeWidgetItem *item = ui->treeWidget->currentItem(); |
||
388 | ui->lwPictures->clear(); |
||
389 | m_currentProjectDir = item->data(1,0).toString(); |
||
390 | int currentProjectPictureNumber=0; |
||
391 | |||
392 | QDir dir(item->data(1,0).toString()+"/thumbs/"); |
||
393 | dir.setFilter(QDir::Files); |
||
394 | dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); |
||
395 | QFileInfoList list = dir.entryInfoList(); |
||
396 | for(int i = 0; i < list.count(); i++) { |
||
397 | qDebug() << list.at(i).fileName(); |
||
398 | QListWidgetItem *newitem = new QListWidgetItem();
|
||
399 | QIcon icone(list.at(i).absoluteFilePath());//pour la mettre à coté de l'item
|
||
400 | newitem->setIcon(icone); // ajout de la petite icone sur l'item
|
||
401 | newitem->setText(list.at(i).fileName()); |
||
402 | ui->lwPictures->insertItem(i,newitem); |
||
403 | currentProjectPictureNumber = i+1;
|
||
404 | } |
||
405 | |||
406 | if(currentProjectPictureNumber == 0) { |
||
407 | qDebug() << "Pas d'image ... on affiche le message drag & drop";
|
||
408 | m_labelDeposez->resize(ui->lwPictures->size()); |
||
409 | m_labelDeposez->move(ui->lwPictures->pos()); |
||
410 | m_labelDeposez->show(); |
||
411 | qDebug() << m_labelDeposez->pos(); |
||
412 | qDebug() << m_labelDeposez->size(); |
||
413 | } |
||
414 | else {
|
||
415 | m_labelDeposez->hide(); |
||
416 | } |
||
417 | d4a9c7c8 | Eric Seigne | m_currentProjectPictureNumber = currentProjectPictureNumber+1;
|
418 | d8d0edae | Eric Seigne | } |
419 | |||
420 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_btnUpload_clicked()
|
421 | bbebc37b | Eric Seigne | { |
422 | 5ea3da39 | Eric Seigne | qDebug() << "on_btnUpload_clicked : " << ui->treeWidget->currentItem()->data(1,0).toString(); |
423 | cf314c59 | Eric Seigne | |
424 | makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/hq", |
||
425 | m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/hq.zip"); |
||
426 | |||
427 | makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/mq", |
||
428 | m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/mq.zip"); |
||
429 | |||
430 | makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/lq", |
||
431 | m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/lq.zip"); |
||
432 | |||
433 | makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/thumbs", |
||
434 | m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/thumbs.zip"); |
||
435 | |||
436 | 83a77071 | Eric Seigne | QSettings settings; |
437 | settings.beginGroup("FTP");
|
||
438 | settings.setValue("FTPLogin",ui->leFTPLogin->text());
|
||
439 | settings.setValue("FTPPass",ui->leFTPPass->text());
|
||
440 | settings.setValue("FTPServeur",ui->leFTPServeur->text());
|
||
441 | settings.setValue("FTPDirectory",ui->leFTPDirectory->text());
|
||
442 | settings.setValue("SiteAdresse",ui->leSiteAdresse->text());
|
||
443 | |||
444 | 293017f7 | Eric Seigne | m_tools->clear(); |
445 | 5ea3da39 | Eric Seigne | |
446 | d4a9c7c8 | Eric Seigne | m_tools->ftpConnect(ui->leFTPServeur->text(), |
447 | ui->leFTPLogin->text(), |
||
448 | ui->leFTPPass->text()); |
||
449 | |||
450 | m_tools->ftpMkdir(ui->leFTPDirectory->text()); |
||
451 | m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries");
|
||
452 | m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries/" + ui->treeWidget->currentItem()->text(0)); |
||
453 | |||
454 | //On uploade la gallerie
|
||
455 | //m_ftp->cd(ui->leFTPDirectory->text());
|
||
456 | |||
457 | QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()); |
||
458 | QDir dir(fi.absoluteFilePath()); |
||
459 | 04d4d726 | Eric Seigne | m_tools->parcoursRecursif(dir.absolutePath(),ui->treeWidget->currentItem()->text(0));
|
460 | d4a9c7c8 | Eric Seigne | //qDebug() << m_fileListToUpload;
|
461 | 83a77071 | Eric Seigne | m_tools->uploadRecursifGallery(ui->leFTPDirectory->text(),ui->leSiteAdresse->text().trimmed()); |
462 | 925ac0ca | Eric Seigne | connect(m_tools, SIGNAL(signalUpload(int,int,QString)), this, SLOT(updateProgressFichier(int,int,QString))); |
463 | d4a9c7c8 | Eric Seigne | connect(m_tools, SIGNAL(signalUploadData(int,int)), this, SLOT(updateProgressData(int,int))); |
464 | f68f673d | Eric Seigne | } |
465 | 293017f7 | Eric Seigne | |
466 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::on_action_Assistant_d_installation_triggered()
|
467 | 293017f7 | Eric Seigne | { |
468 | Assistant *a = new Assistant(this); |
||
469 | a->show(); |
||
470 | } |
||
471 | d4a9c7c8 | Eric Seigne | |
472 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::updateProgressFichier(int total, int current, QString fileName) |
473 | d4a9c7c8 | Eric Seigne | { |
474 | ui->pbFTPFichier->setMaximum(total); |
||
475 | ui->pbFTPFichier->setValue(current); |
||
476 | 83a77071 | Eric Seigne | ui->textBrowser->append(fileName); |
477 | d4a9c7c8 | Eric Seigne | } |
478 | |||
479 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::updateProgressData(int total, int current) |
480 | d4a9c7c8 | Eric Seigne | { |
481 | ui->pbFTPProgress->setMaximum(total); |
||
482 | ui->pbFTPProgress->setValue(current); |
||
483 | } |
||
484 | cf314c59 | Eric Seigne | |
485 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::makeZip(QString repSource, QString destFileName)
|
486 | cf314c59 | Eric Seigne | { |
487 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
488 | ui->statusBar->showMessage(QString::fromUtf8("Création du fichier ZIP %1 en cours").arg(destFileName), 5000); |
||
489 | qApp->processEvents(); |
||
490 | 8ed8fc1a | Eric Seigne | qDebug() << "WebPhotoAlbum::makeZip " << repSource << " :: " << destFileName; |
491 | cf314c59 | Eric Seigne | //Creation d'une archive ZIP dans tous les cas
|
492 | QuaZip zipDestination(destFileName); |
||
493 | if(zipDestination.open(QuaZip::mdCreate)) {
|
||
494 | //On sauvegarde tout dans ce fichier
|
||
495 | QuaZipFile fichierDehors(&zipDestination); |
||
496 | |||
497 | //Les droits par defaut en 644 pour les fichiers contenus dans le .zip
|
||
498 | QuaZipNewInfo newInfo("");
|
||
499 | int permission644 = 33188; |
||
500 | newInfo.externalAttr = (permission644 << 16L);
|
||
501 | |||
502 | QDir dir(repSource); |
||
503 | dir.setFilter(QDir::Files); |
||
504 | QFileInfoList fileList = dir.entryInfoList(); |
||
505 | qDebug() << "avant " << fileList.count();
|
||
506 | for(int i = 0; i < fileList.count(); i++) { |
||
507 | QString fileName = fileList.at(i).fileName(); |
||
508 | QFile fic(fileList.at(i).absoluteFilePath()); |
||
509 | qDebug() << "On ajoute le fichier " << fileName;
|
||
510 | newInfo.name = fileName; |
||
511 | if(fic.open(QIODevice::ReadOnly) && fichierDehors.open(QIODevice::WriteOnly,newInfo)) {
|
||
512 | fichierDehors.write(fic.read(fic.size())); |
||
513 | fichierDehors.close(); |
||
514 | fic.close(); |
||
515 | qDebug() << " ajout ok";
|
||
516 | } |
||
517 | } |
||
518 | zipDestination.close(); |
||
519 | } |
||
520 | QApplication::restoreOverrideCursor(); |
||
521 | } |
||
522 | 925ac0ca | Eric Seigne | |
523 | 8ed8fc1a | Eric Seigne | void WebPhotoAlbum::uploadEnd()
|
524 | 925ac0ca | Eric Seigne | { |
525 | 83a77071 | Eric Seigne | ui->textBrowser->append(trUtf8("Téléchargement terminé"));
|
526 | } |
||
527 | |||
528 | void WebPhotoAlbum::on_tabWidget_currentChanged(int index) |
||
529 | { |
||
530 | if(index == 2) { |
||
531 | //Lecture du QSettings pour avoir les infos login / pass / url site
|
||
532 | QSettings settings; |
||
533 | settings.beginGroup("FTP");
|
||
534 | ui->leFTPLogin->setText(settings.value("FTPLogin","identifiant").toString()); |
||
535 | ui->leFTPPass->setText(settings.value("FTPPass").toString());
|
||
536 | ui->leFTPServeur->setText(settings.value("FTPServeur","ftpperso.free.fr").toString()); |
||
537 | ui->leFTPDirectory->setText(settings.value("FTPDirectory","/album").toString()); |
||
538 | ui->leSiteAdresse->setText(settings.value("SiteAdresse","http://votresite.free.fr/album/").toString()); |
||
539 | } |
||
540 | 925ac0ca | Eric Seigne | } |