Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-webphotoalbum-git / original.cpp @ 8801fb5e

Historique | Voir | Annoter | Télécharger (11,8 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

    
28
//---------------------------------------------------------------------------
29
QString formatSize(qint64 num)
30
{
31
    QString total;
32
    const qint64 kb = 1024;
33
    const qint64 mb = 1024 * kb;
34
    const qint64 gb = 1024 * mb;
35
    const qint64 tb = 1024 * gb;
36

    
37
    if (num >= tb) total = QString("%1TB").arg(QString::number(qreal(num) / tb, 'f', 2));
38
    else if(num >= gb) total = QString("%1GB").arg(QString::number(qreal(num) / gb, 'f', 2));
39
    else if(num >= mb) total = QString("%1MB").arg(QString::number(qreal(num) / mb, 'f', 1));
40
    else if(num >= kb) total = QString("%1KB").arg(QString::number(qreal(num) / kb,'f', 1));
41
    else total = QString("%1 bytes").arg(num);
42

    
43
    return total;
44
}
45

    
46
// =========================================================================================================================
47

    
48

    
49
original::original(QWidget *parent) :
50
    QMainWindow(parent),
51
    ui(new Ui::original)
52
{
53
    ui->setupUi(this);
54

    
55
    ui->stackedWidget->setCurrentWidget(ui->page);
56

    
57
    QDir dir(QDir::homePath() + "/RyXeo-WebPhotoAlbum");
58
    dir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
59
    QFileInfoList list = dir.entryInfoList();
60
    for(int i = 0; i < list.count(); i++) {
61
        QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
62
        item->setText(0, list.at(i).fileName());
63
        item->setData(1,0,list.at(i).absoluteFilePath());
64
    }
65
}
66

    
67
original::~original()
68
{
69
    delete ui;
70
}
71

    
72
void original::on_btnExport_clicked()
73
{
74
    //Creation de la destination
75
    QDir rep;
76
    QString dest = ui->leDest->text().trimmed() + "/web-gallery";
77
    rep.mkpath(dest);
78
    rep.mkpath(dest + "/hq");
79
    rep.mkpath(dest + "/lq");
80
    rep.mkpath(dest + "/mq");
81
    rep.mkpath(dest + "/thumbs");
82
    rep.mkpath(dest + "/zip");
83
    rep.mkpath(dest + "/comments");
84

    
85
    //Creation des images
86
    QDir dir(ui->leSource->text().trimmed());
87
    dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
88
    QFileInfoList list = dir.entryInfoList();
89
    for(int i = 0; i < list.count(); i++) {
90
        ui->statusBar->clearMessage();
91
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(list.at(i).fileName()),3000);
92
        qApp->processEvents();
93

    
94
        qDebug() << "Processing : " << list.at(i).absoluteFilePath();
95
        QPixmap pixmap(list.at(i).absoluteFilePath());
96
        pixmap.save(QString("%1/hq/img-%2.jpg").arg(dest).arg(i));
97

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

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

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

    
110

    
111
        QFile file(QString("%1/comments/%2.txt").arg(dest).arg(i));
112
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
113
            return;
114

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

    
120
        //================== on copie les metadata
121
        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(list.at(i).absoluteFilePath().toStdString());
122
        Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(dest).arg(i).toStdString());
123
        Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(dest).arg(i).toStdString());
124
        Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(dest).arg(i).toStdString());
125
        Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(dest).arg(i).toStdString());
126
        if (image.get() != 0)
127
        {
128
            image->readMetadata();
129
            Exiv2::ExifData &exifData = image->exifData();
130
            if (!exifData.empty())
131
            {
132
                bool setArtist = false;
133
                bool setCopyright = false;
134
                bool setSoftware = false;
135
                Exiv2::ExifData::const_iterator end = exifData.end();
136
                qDebug() << "============================ DEBUT ===============================";
137
                for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
138
                {
139
                    qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
140
                    if (i->key() == "Exif.Image.Artist") {
141
                        exifData["Exif.Image.Artist"]    = "Eric S.";
142
                        setArtist = true;
143
                    }
144
                    if (i->key() == "Exif.Image.Copyright") {
145
                        exifData["Exif.Image.Copyright"]    = "Eric S.";
146
                        setCopyright = true;
147
                    }
148
                    if (i->key() == "Exif.Image.Software") {
149
                        exifData["Exif.Image.Software"]  = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/";
150
                        setSoftware = true;
151
                    }
152
                }
153
                //Si on n'a pas les meta il faut les ajouter
154

    
155
                //Mise à jour de l'auteur
156
                if(!setArtist) {
157
                    Exiv2::ExifKey k("Exif.Image.Artist");
158
                    Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString);
159
                    v->read("Eric S.");
160
                    exifData.add(k,v.get());
161
                }
162

    
163
                if(!setCopyright) {
164
                    Exiv2::ExifKey k2("Exif.Image.Copyright");
165
                    Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString);
166
                    v2->read("Eric S.");
167
                    exifData.add(k2,v2.get());
168
                }
169

    
170
                if(!setSoftware) {
171
                    Exiv2::ExifKey k3("Exif.Image.Software");
172
                    Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString);
173
                    v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
174
                    exifData.add(k3,v3.get());
175
                }
176

    
177
                qDebug() << "============================ APRES ===============================";
178
                Exiv2::ExifData::const_iterator end2 = exifData.end();
179
                for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
180
                {
181
                    qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
182
                }
183
                qDebug() << "============================ FIN ===============================";
184

    
185
                imageLQ->setExifData(exifData);
186
                imageLQ->writeMetadata();
187

    
188
                imageMQ->setExifData(exifData);
189
                imageMQ->writeMetadata();
190

    
191
                imageHQ->setExifData(exifData);
192
                imageHQ->writeMetadata();
193

    
194
                imageThumb->setExifData(exifData);
195
                imageThumb->writeMetadata();
196
            }
197
        }
198
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(list.at(i).fileName()),3000);
199
    }
200
}
201

    
202
void original::on_action_Nouvel_album_triggered()
203
{
204
    QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
205
    i->setText(0, trUtf8("Nouvel album"));
206
}
207

    
208
void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
209
{
210
    ui->lwPictures->clear();
211
    QDir dir(item->data(1,0).toString()+"/thumbs/");
212
    dir.setFilter(QDir::Files);
213
    dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
214
    QFileInfoList list = dir.entryInfoList();
215
    for(int i = 0; i < list.count(); i++) {
216
        qDebug() << list.at(i).fileName();
217
        QListWidgetItem *newitem = new QListWidgetItem();
218
        QIcon icone(list.at(i).absoluteFilePath());//pour la mettre  à coté de l'item
219
        newitem->setIcon(icone); // ajout de la petite icone sur l'item
220
        newitem->setText(list.at(i).fileName());
221
        ui->lwPictures->insertItem(i,newitem);
222
    }
223
}
224

    
225
void original::on_commandLinkButton_clicked()
226
{
227
    if(ui->stackedWidget->currentWidget() == ui->page_2)
228
        ui->stackedWidget->setCurrentWidget(ui->page);
229
    else {
230
        QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt");
231
        qDebug() << "Lecture de " << fi.absoluteFilePath();
232
        if(fi.exists()) {
233
            QFile file(fi.absoluteFilePath());
234
            if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
235
                return;
236

    
237
            /* Exemple de fichier
238
            name|Sortie Plongée SAGC. (Cala Montjoi, Spain) 28.05.2012
239
            author|Éric Seigne
240
            description|Sortie Plongée SAGC. (Cala Montjoi, Spain)
241
            date|28.05.2012
242
            restricted_user|sagc
243
            restricted_password|motdepasse
244
              */
245
            while (!file.atEnd()) {
246
                QByteArray line = file.readLine();
247
                QStringList tab = QString::fromUtf8(line.constData()).split('|');
248
                if(tab.at(0) == "name")
249
                    ui->leTitre->setText(tab.at(1));
250
                if(tab.at(0) == "author")
251
                    ui->leAuthor->setText(tab.at(1));
252
                if(tab.at(0) == "description")
253
                    ui->leDesc->setText(tab.at(1));
254
                if(tab.at(0) == "date")
255
                    ui->dateEdit->setDate(QDate::fromString(tab.at(1)));
256
                if(tab.at(0) == "restricted_user")
257
                    ui->leLogin->setText(tab.at(1));
258
                if(tab.at(0) == "restricted_password")
259
                    ui->lePasswd->setText(tab.at(1));
260

    
261
            }
262

    
263
        }
264
        ui->stackedWidget->setCurrentWidget(ui->page_2);
265
    }
266
}
267

    
268
void original::on_btnSave_clicked()
269
{
270
    QByteArray data;
271
    data.append(QString("name|%1\n").arg(ui->leTitre->text().trimmed()));
272
    data.append(QString("author|%1\n").arg(ui->leAuthor->text().trimmed()));
273
    data.append(QString("description|%1\n").arg(ui->leDesc->text().trimmed()));
274
    data.append(QString("date|%1\n").arg(ui->dateEdit->text().trimmed()));
275
    if(ui->leLogin->text().trimmed() != "") {
276
        data.append(QString("restricted_user|%1\n").arg(ui->leLogin->text().trimmed()));
277
        data.append(QString("restricted_password|%1\n").arg(ui->lePasswd->text().trimmed()));
278
    }
279
    QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString()+"/info.txt");
280
    qDebug() << "Ecriture de " << fi.absoluteFilePath();
281
    QFile file(fi.absoluteFilePath());
282
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
283
        return;
284
    QTextStream out(&file);
285
    out.setCodec("UTF-8");
286
    out << data;
287
    file.close();
288
}
Redmine Appliance - Powered by TurnKey Linux