ryxeo-webphotoalbum-git / original.cpp @ 71c02254
Historique | Voir | Annoter | Télécharger (11,3 ko)
1 | ef177d24 | Eric Seigne | /**
|
---|---|---|---|
2 | * Classe
|
||
3 | * @see https://redmine.ryxeo.com/projects/
|
||
4 | * @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
|
||
5 | * @see The GNU Public License (GNU/GPL) v3
|
||
6 | *
|
||
7 | *
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or modify
|
||
10 | * it under the terms of the GNU General Public License as published by
|
||
11 | * the Free Software Foundation; either version 3 of the License, or
|
||
12 | * (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful, but
|
||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||
16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||
17 | * for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License along
|
||
20 | * with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
21 | */
|
||
22 | |||
23 | |||
24 | #include "original.h" |
||
25 | #include "ui_original.h" |
||
26 | |||
27 | 71c02254 | Eric Seigne | |
28 | //---------------------------------------------------------------------------------
|
||
29 | bool viewsSortProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const |
||
30 | { |
||
31 | if(this->filterRegExp().isEmpty()) return true; |
||
32 | |||
33 | QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
||
34 | myModel* fileModel = qobject_cast<myModel*>(sourceModel()); |
||
35 | |||
36 | if(fileModel->fileInfo(index0).isHidden()) return false; |
||
37 | else return true; |
||
38 | } |
||
39 | |||
40 | |||
41 | //---------------------------------------------------------------------------------
|
||
42 | bool viewsSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const |
||
43 | { |
||
44 | myModel* fsModel = dynamic_cast<myModel*>(sourceModel());
|
||
45 | |||
46 | if(left.column() == 1) //size |
||
47 | { |
||
48 | if(fsModel->size(left) > fsModel->size(right)) return true; |
||
49 | else return false; |
||
50 | } |
||
51 | else
|
||
52 | if(left.column() == 3) //date |
||
53 | { |
||
54 | if(fsModel->fileInfo(left).lastModified() > fsModel->fileInfo(right).lastModified()) return true; |
||
55 | else return false; |
||
56 | } |
||
57 | |||
58 | return QSortFilterProxyModel::lessThan(left,right);
|
||
59 | } |
||
60 | |||
61 | //---------------------------------------------------------------------------------
|
||
62 | QStringList myCompleter::splitPath(const QString& path) const |
||
63 | { |
||
64 | QStringList parts = path.split("/");
|
||
65 | parts[0] = "/"; |
||
66 | |||
67 | return parts;
|
||
68 | } |
||
69 | |||
70 | //---------------------------------------------------------------------------------
|
||
71 | QString myCompleter::pathFromIndex(const QModelIndex& index) const |
||
72 | { |
||
73 | if(!index.isValid()) return ""; |
||
74 | |||
75 | QModelIndex idx = index; |
||
76 | QStringList list; |
||
77 | do
|
||
78 | { |
||
79 | QString t = model()->data(idx, Qt::EditRole).toString(); |
||
80 | list.prepend(t); |
||
81 | QModelIndex parent = idx.parent(); |
||
82 | idx = parent.sibling(parent.row(), index.column()); |
||
83 | } |
||
84 | while (idx.isValid());
|
||
85 | |||
86 | list[0].clear() ; // the join below will provide the separator |
||
87 | |||
88 | return list.join("/"); |
||
89 | } |
||
90 | |||
91 | //---------------------------------------------------------------------------
|
||
92 | QString formatSize(qint64 num) |
||
93 | { |
||
94 | QString total; |
||
95 | const qint64 kb = 1024; |
||
96 | const qint64 mb = 1024 * kb; |
||
97 | const qint64 gb = 1024 * mb; |
||
98 | const qint64 tb = 1024 * gb; |
||
99 | |||
100 | if (num >= tb) total = QString("%1TB").arg(QString::number(qreal(num) / tb, 'f', 2)); |
||
101 | else if(num >= gb) total = QString("%1GB").arg(QString::number(qreal(num) / gb, 'f', 2)); |
||
102 | else if(num >= mb) total = QString("%1MB").arg(QString::number(qreal(num) / mb, 'f', 1)); |
||
103 | else if(num >= kb) total = QString("%1KB").arg(QString::number(qreal(num) / kb,'f', 1)); |
||
104 | else total = QString("%1 bytes").arg(num); |
||
105 | |||
106 | return total;
|
||
107 | } |
||
108 | |||
109 | // =========================================================================================================================
|
||
110 | |||
111 | |||
112 | ef177d24 | Eric Seigne | original::original(QWidget *parent) : |
113 | QMainWindow(parent), |
||
114 | ui(new Ui::original)
|
||
115 | { |
||
116 | ui->setupUi(this);
|
||
117 | } |
||
118 | |||
119 | original::~original() |
||
120 | { |
||
121 | delete ui;
|
||
122 | } |
||
123 | |||
124 | void original::on_btnExport_clicked()
|
||
125 | { |
||
126 | //Creation de la destination
|
||
127 | QDir rep; |
||
128 | QString dest = ui->leDest->text().trimmed() + "/web-gallery";
|
||
129 | rep.mkpath(dest); |
||
130 | rep.mkpath(dest + "/hq");
|
||
131 | rep.mkpath(dest + "/lq");
|
||
132 | rep.mkpath(dest + "/mq");
|
||
133 | rep.mkpath(dest + "/thumbs");
|
||
134 | rep.mkpath(dest + "/zip");
|
||
135 | rep.mkpath(dest + "/comments");
|
||
136 | |||
137 | //Creation des images
|
||
138 | QDir dir(ui->leSource->text().trimmed()); |
||
139 | dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot); |
||
140 | QFileInfoList list = dir.entryInfoList(); |
||
141 | for(int i = 0; i < list.count(); i++) { |
||
142 | ui->statusBar->clearMessage(); |
||
143 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(list.at(i).fileName()),3000); |
||
144 | qApp->processEvents(); |
||
145 | |||
146 | qDebug() << "Processing : " << list.at(i).absoluteFilePath();
|
||
147 | QPixmap pixmap(list.at(i).absoluteFilePath()); |
||
148 | pixmap.save(QString("%1/hq/img-%2.jpg").arg(dest).arg(i));
|
||
149 | |||
150 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(list.at(i).fileName()),3000); |
||
151 | QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
152 | pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(dest).arg(i));
|
||
153 | |||
154 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(list.at(i).fileName()),3000); |
||
155 | QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
156 | pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(dest).arg(i));
|
||
157 | |||
158 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(list.at(i).fileName()),3000); |
||
159 | QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
||
160 | pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(dest).arg(i));
|
||
161 | |||
162 | |||
163 | QFile file(QString("%1/comments/%2.txt").arg(dest).arg(i));
|
||
164 | if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||
165 | return;
|
||
166 | |||
167 | QTextStream out(&file); |
||
168 | out << "<span>Photo " + QString::number(i) + "</span>\n"; |
||
169 | file.close(); |
||
170 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(list.at(i).fileName()),3000); |
||
171 | |||
172 | //================== on copie les metadata
|
||
173 | Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(list.at(i).absoluteFilePath().toStdString()); |
||
174 | Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(dest).arg(i).toStdString());
|
||
175 | Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(dest).arg(i).toStdString());
|
||
176 | Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(dest).arg(i).toStdString());
|
||
177 | Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(dest).arg(i).toStdString());
|
||
178 | if (image.get() != 0) |
||
179 | { |
||
180 | image->readMetadata(); |
||
181 | Exiv2::ExifData &exifData = image->exifData(); |
||
182 | if (!exifData.empty())
|
||
183 | { |
||
184 | bool setArtist = false; |
||
185 | bool setCopyright = false; |
||
186 | bool setSoftware = false; |
||
187 | Exiv2::ExifData::const_iterator end = exifData.end(); |
||
188 | qDebug() << "============================ DEBUT ===============================";
|
||
189 | for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
|
||
190 | { |
||
191 | qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
|
||
192 | if (i->key() == "Exif.Image.Artist") { |
||
193 | exifData["Exif.Image.Artist"] = "Toto le hero"; |
||
194 | setArtist = true;
|
||
195 | } |
||
196 | if (i->key() == "Exif.Image.Copyright") { |
||
197 | exifData["Exif.Image.Copyright"] = "Toto le hero"; |
||
198 | setCopyright = true;
|
||
199 | } |
||
200 | if (i->key() == "Exif.Image.Software") { |
||
201 | exifData["Exif.Image.Software"] = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/"; |
||
202 | setSoftware = true;
|
||
203 | } |
||
204 | } |
||
205 | //Si on n'a pas les meta il faut les ajouter
|
||
206 | |||
207 | //Mise à jour de l'auteur
|
||
208 | if(!setArtist) {
|
||
209 | Exiv2::ExifKey k("Exif.Image.Artist");
|
||
210 | Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString); |
||
211 | v->read("Toto le hero");
|
||
212 | exifData.add(k,v.get()); |
||
213 | } |
||
214 | |||
215 | if(!setCopyright) {
|
||
216 | Exiv2::ExifKey k2("Exif.Image.Copyright");
|
||
217 | Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString); |
||
218 | v2->read("Toto le hero");
|
||
219 | exifData.add(k2,v2.get()); |
||
220 | } |
||
221 | |||
222 | if(!setSoftware) {
|
||
223 | Exiv2::ExifKey k3("Exif.Image.Software");
|
||
224 | Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString); |
||
225 | v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
|
||
226 | exifData.add(k3,v3.get()); |
||
227 | } |
||
228 | |||
229 | qDebug() << "============================ APRES ===============================";
|
||
230 | Exiv2::ExifData::const_iterator end2 = exifData.end(); |
||
231 | for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
|
||
232 | { |
||
233 | qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
|
||
234 | } |
||
235 | qDebug() << "============================ FIN ===============================";
|
||
236 | |||
237 | imageLQ->setExifData(exifData); |
||
238 | imageLQ->writeMetadata(); |
||
239 | |||
240 | imageMQ->setExifData(exifData); |
||
241 | imageMQ->writeMetadata(); |
||
242 | |||
243 | imageHQ->setExifData(exifData); |
||
244 | imageHQ->writeMetadata(); |
||
245 | |||
246 | imageThumb->setExifData(exifData); |
||
247 | imageThumb->writeMetadata(); |
||
248 | } |
||
249 | } |
||
250 | ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(list.at(i).fileName()),3000); |
||
251 | } |
||
252 | } |
||
253 | 71c02254 | Eric Seigne | |
254 | void original::on_action_Nouvel_album_triggered()
|
||
255 | { |
||
256 | QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
|
||
257 | i->setText(0, trUtf8("Nouvel album")); |
||
258 | } |
||
259 | |||
260 | //---------------------------------------------------------------------------
|
||
261 | void original::thumbUpdate(QModelIndex index)
|
||
262 | { |
||
263 | qDebug() << "original::thumbUpdate";
|
||
264 | ui->lvResult->update(m_modelView->mapFromSource(index)); |
||
265 | } |
||
266 | |||
267 | void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column) |
||
268 | { |
||
269 | QStringList items; |
||
270 | m_modelList = new myModel();
|
||
271 | m_modelList->setRootPath("/tmp/");
|
||
272 | |||
273 | m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-000.jpg");
|
||
274 | m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-001.jpg");
|
||
275 | m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-002.jpg");
|
||
276 | m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-003.jpg");
|
||
277 | items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-000.jpg");
|
||
278 | items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-001.jpg");
|
||
279 | items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-002.jpg");
|
||
280 | items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-003.jpg");
|
||
281 | QtConcurrent::run(m_modelList,&myModel::loadThumbsQSL,items); |
||
282 | |||
283 | m_modelView = new viewsSortProxyModel();
|
||
284 | m_modelView->setSourceModel(m_modelList); |
||
285 | m_modelView->setSortCaseSensitivity(Qt::CaseInsensitive); |
||
286 | ui->lvResult->setModel(m_modelView); |
||
287 | |||
288 | connect(m_modelList,SIGNAL(thumbUpdate(QModelIndex)),this,SLOT(thumbUpdate(QModelIndex)));
|
||
289 | |||
290 | } |