Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-webphotoalbum-git / original.cpp @ ef177d24

Historique | Voir | Annoter | Télécharger (7,15 ko)

1
/**
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
original::original(QWidget *parent) :
28
    QMainWindow(parent),
29
    ui(new Ui::original)
30
{
31
    ui->setupUi(this);
32
}
33

    
34
original::~original()
35
{
36
    delete ui;
37
}
38

    
39
void original::on_btnExport_clicked()
40
{
41
    //Creation de la destination
42
    QDir rep;
43
    QString dest = ui->leDest->text().trimmed() + "/web-gallery";
44
    rep.mkpath(dest);
45
    rep.mkpath(dest + "/hq");
46
    rep.mkpath(dest + "/lq");
47
    rep.mkpath(dest + "/mq");
48
    rep.mkpath(dest + "/thumbs");
49
    rep.mkpath(dest + "/zip");
50
    rep.mkpath(dest + "/comments");
51

    
52
    //Creation des images
53
    QDir dir(ui->leSource->text().trimmed());
54
    dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
55
    QFileInfoList list = dir.entryInfoList();
56
    for(int i = 0; i < list.count(); i++) {
57
        ui->statusBar->clearMessage();
58
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(list.at(i).fileName()),3000);
59
        qApp->processEvents();
60

    
61
        qDebug() << "Processing : " << list.at(i).absoluteFilePath();
62
        QPixmap pixmap(list.at(i).absoluteFilePath());
63
        pixmap.save(QString("%1/hq/img-%2.jpg").arg(dest).arg(i));
64

    
65
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(list.at(i).fileName()),3000);
66
        QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation));
67
        pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(dest).arg(i));
68

    
69
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(list.at(i).fileName()),3000);
70
        QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation));
71
        pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(dest).arg(i));
72

    
73
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(list.at(i).fileName()),3000);
74
        QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation));
75
        pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(dest).arg(i));
76

    
77

    
78
        QFile file(QString("%1/comments/%2.txt").arg(dest).arg(i));
79
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
80
            return;
81

    
82
        QTextStream out(&file);
83
        out << "<span>Photo " + QString::number(i) + "</span>\n";
84
        file.close();
85
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(list.at(i).fileName()),3000);
86

    
87
        //================== on copie les metadata
88
        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(list.at(i).absoluteFilePath().toStdString());
89
        Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(dest).arg(i).toStdString());
90
        Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(dest).arg(i).toStdString());
91
        Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(dest).arg(i).toStdString());
92
        Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(dest).arg(i).toStdString());
93
        if (image.get() != 0)
94
        {
95
            image->readMetadata();
96
            Exiv2::ExifData &exifData = image->exifData();
97
            if (!exifData.empty())
98
            {
99
                bool setArtist = false;
100
                bool setCopyright = false;
101
                bool setSoftware = false;
102
                Exiv2::ExifData::const_iterator end = exifData.end();
103
                qDebug() << "============================ DEBUT ===============================";
104
                for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
105
                {
106
                    qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
107
                    if (i->key() == "Exif.Image.Artist") {
108
                        exifData["Exif.Image.Artist"]    = "Toto le hero";
109
                        setArtist = true;
110
                    }
111
                    if (i->key() == "Exif.Image.Copyright") {
112
                        exifData["Exif.Image.Copyright"]    = "Toto le hero";
113
                        setCopyright = true;
114
                    }
115
                    if (i->key() == "Exif.Image.Software") {
116
                        exifData["Exif.Image.Software"]  = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/";
117
                        setSoftware = true;
118
                    }
119
                }
120
                //Si on n'a pas les meta il faut les ajouter
121

    
122
                //Mise à jour de l'auteur
123
                if(!setArtist) {
124
                    Exiv2::ExifKey k("Exif.Image.Artist");
125
                    Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString);
126
                    v->read("Toto le hero");
127
                    exifData.add(k,v.get());
128
                }
129

    
130
                if(!setCopyright) {
131
                    Exiv2::ExifKey k2("Exif.Image.Copyright");
132
                    Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString);
133
                    v2->read("Toto le hero");
134
                    exifData.add(k2,v2.get());
135
                }
136

    
137
                if(!setSoftware) {
138
                    Exiv2::ExifKey k3("Exif.Image.Software");
139
                    Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString);
140
                    v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
141
                    exifData.add(k3,v3.get());
142
                }
143

    
144
                qDebug() << "============================ APRES ===============================";
145
                Exiv2::ExifData::const_iterator end2 = exifData.end();
146
                for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
147
                {
148
                    qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
149
                }
150
                qDebug() << "============================ FIN ===============================";
151

    
152
                imageLQ->setExifData(exifData);
153
                imageLQ->writeMetadata();
154

    
155
                imageMQ->setExifData(exifData);
156
                imageMQ->writeMetadata();
157

    
158
                imageHQ->setExifData(exifData);
159
                imageHQ->writeMetadata();
160

    
161
                imageThumb->setExifData(exifData);
162
                imageThumb->writeMetadata();
163
            }
164
        }
165
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(list.at(i).fileName()),3000);
166
    }
167
}
Redmine Appliance - Powered by TurnKey Linux