Projet

Général

Profil

Révision ef177d24

Voir les différences:

main.cpp
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 <QtGui/QApplication>
25
#include "original.h"
26

  
27
int main(int argc, char *argv[])
28
{
29
    QApplication a(argc, argv);
30
    original w;
31
    w.show();
32
    
33
    return a.exec();
34
}
original.cpp
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
}
original.h
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
#ifndef ORIGINAL_H
25
#define ORIGINAL_H
26

  
27
#include <QDir>
28
#include <QDebug>
29
#include <QMainWindow>
30
#include <exiv2/image.hpp>
31
#include <exiv2/exif.hpp>
32

  
33
namespace Ui {
34
class original;
35
}
36

  
37
class original : public QMainWindow
38
{
39
    Q_OBJECT
40
    
41
public:
42
    explicit original(QWidget *parent = 0);
43
    ~original();
44
    
45
private slots:
46
    void on_btnExport_clicked();
47

  
48
private:
49
    Ui::original *ui;
50
};
51

  
52
#endif // ORIGINAL_H
original.pro
1
#-------------------------------------------------
2
#
3
# Project created by QtCreator 2012-06-03T15:06:58
4
#
5
#-------------------------------------------------
6

  
7
QT       += core gui
8

  
9
TARGET = original
10
TEMPLATE = app
11

  
12

  
13
SOURCES += main.cpp\
14
        original.cpp
15

  
16
HEADERS  += original.h
17

  
18
FORMS    += original.ui
19

  
20
# include("lib/openexif/openexif.pri")
21
# include("lib/exiv2/exiv2.pri")
22

  
23
unix:LIBS += -lexiv2
24
win32:LIBS += -lexiv2
original.ui
1
<?xml version="1.0" encoding="UTF-8"?>
2
<ui version="4.0">
3
 <class>original</class>
4
 <widget class="QMainWindow" name="original">
5
  <property name="geometry">
6
   <rect>
7
    <x>0</x>
8
    <y>0</y>
9
    <width>738</width>
10
    <height>300</height>
11
   </rect>
12
  </property>
13
  <property name="windowTitle">
14
   <string>original</string>
15
  </property>
16
  <widget class="QWidget" name="centralWidget">
17
   <widget class="QPushButton" name="btnExport">
18
    <property name="geometry">
19
     <rect>
20
      <x>70</x>
21
      <y>70</y>
22
      <width>92</width>
23
      <height>27</height>
24
     </rect>
25
    </property>
26
    <property name="text">
27
     <string>PushButton</string>
28
    </property>
29
   </widget>
30
   <widget class="QLineEdit" name="leDest">
31
    <property name="geometry">
32
     <rect>
33
      <x>70</x>
34
      <y>40</y>
35
      <width>113</width>
36
      <height>27</height>
37
     </rect>
38
    </property>
39
    <property name="text">
40
     <string>/tmp/w</string>
41
    </property>
42
   </widget>
43
   <widget class="QLineEdit" name="leSource">
44
    <property name="geometry">
45
     <rect>
46
      <x>70</x>
47
      <y>10</y>
48
      <width>113</width>
49
      <height>27</height>
50
     </rect>
51
    </property>
52
    <property name="text">
53
     <string>/tmp/t</string>
54
    </property>
55
   </widget>
56
  </widget>
57
  <widget class="QMenuBar" name="menuBar">
58
   <property name="geometry">
59
    <rect>
60
     <x>0</x>
61
     <y>0</y>
62
     <width>738</width>
63
     <height>25</height>
64
    </rect>
65
   </property>
66
  </widget>
67
  <widget class="QToolBar" name="mainToolBar">
68
   <attribute name="toolBarArea">
69
    <enum>TopToolBarArea</enum>
70
   </attribute>
71
   <attribute name="toolBarBreak">
72
    <bool>false</bool>
73
   </attribute>
74
  </widget>
75
  <widget class="QStatusBar" name="statusBar"/>
76
 </widget>
77
 <layoutdefault spacing="6" margin="11"/>
78
 <resources/>
79
 <connections/>
80
</ui>

Formats disponibles : Unified diff

Redmine Appliance - Powered by TurnKey Linux