1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : image files selector dialog.
9
* Copyright (C) 2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
28
#include <qguardedptr.h>
33
#include <kapplication.h>
35
#include <kstandarddirs.h>
36
#include <kfiledialog.h>
38
#include <kiconloader.h>
40
// LibKDcraw includes.
42
#include <libkdcraw/dcrawbinary.h>
47
#include "dmetadata.h"
48
#include "thumbnailsize.h"
49
#include "thumbnailjob.h"
50
#include "imagedialog.h"
51
#include "imagedialog.moc"
56
class ImageDialogPreviewPrivate
61
ImageDialogPreviewPrivate()
78
QGuardedPtr<ThumbnailJob> thumbJob;
81
ImageDialogPreview::ImageDialogPreview(QWidget *parent)
82
: KPreviewWidgetBase(parent)
84
d = new ImageDialogPreviewPrivate;
86
QVBoxLayout *vlay = new QVBoxLayout(this);
87
d->imageLabel = new QLabel(this);
88
d->imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
89
d->imageLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
91
d->infoLabel = new QLabel(this);
94
vlay->setSpacing(KDialog::spacingHint());
95
vlay->addWidget(d->imageLabel);
96
vlay->addWidget(d->infoLabel);
98
setSupportedMimeTypes(KImageIO::mimeTypes());
100
d->timer = new QTimer(this);
102
connect(d->timer, SIGNAL(timeout()),
103
this, SLOT(showPreview()) );
106
ImageDialogPreview::~ImageDialogPreview()
108
if (!d->thumbJob.isNull())
116
QSize ImageDialogPreview::sizeHint() const
118
return QSize(256, 256);
121
void ImageDialogPreview::resizeEvent(QResizeEvent *)
123
d->timer->start(100, true);
126
void ImageDialogPreview::showPreview()
128
KURL url(d->currentURL);
133
void ImageDialogPreview::showPreview(const KURL& url)
141
if (url != d->currentURL)
146
if (!d->thumbJob.isNull())
152
d->thumbJob = new ThumbnailJob(url, ThumbnailSize::Huge, true, true);
154
connect(d->thumbJob, SIGNAL(signalThumbnail(const KURL&, const QPixmap&)),
155
this, SLOT(slotGotThumbnail(const KURL&, const QPixmap&)));
157
connect(d->thumbJob, SIGNAL(signalFailed(const KURL&)),
158
this, SLOT(slotFailedThumbnail(const KURL&)));
160
d->metaIface.load(d->currentURL.path());
161
PhotoInfoContainer info = d->metaIface.getPhotographInformations();
165
QString make, model, dateTime, aperture, focalLength, exposureTime, sensitivity;
166
QString unavailable(i18n("<i>unavailable</i>"));
167
QString cellBeg("<tr><td><nobr><font size=-1>");
168
QString cellMid("</font></nobr></td><td><nobr><font size=-1>");
169
QString cellEnd("</font></nobr></td></tr>");
171
if (info.make.isEmpty()) make = unavailable;
172
else make = info.make;
174
if (info.model.isEmpty()) model = unavailable;
175
else model = info.model;
177
if (info.dateTime.isValid()) dateTime = unavailable;
178
else dateTime = KGlobal::locale()->formatDateTime(info.dateTime, true, true);
180
if (info.aperture.isEmpty()) aperture = unavailable;
181
else aperture = info.aperture;
183
if (info.focalLength.isEmpty()) focalLength = unavailable;
184
else focalLength = info.focalLength;
186
if (info.exposureTime.isEmpty()) exposureTime = unavailable;
187
else exposureTime = info.exposureTime;
189
if (info.sensitivity.isEmpty()) sensitivity = unavailable;
190
else sensitivity = i18n("%1 ISO").arg(info.sensitivity);
192
identify = "<table cellspacing=0 cellpadding=0>";
193
identify += cellBeg + i18n("Make:") + cellMid + make + cellEnd;
194
identify += cellBeg + i18n("Model:") + cellMid + model + cellEnd;
195
identify += cellBeg + i18n("Created:") + cellMid + dateTime + cellEnd;
196
identify += cellBeg + i18n("Aperture:") + cellMid + aperture + cellEnd;
197
identify += cellBeg + i18n("Focal:") + cellMid + focalLength + cellEnd;
198
identify += cellBeg + i18n("Exposure:") + cellMid + exposureTime + cellEnd;
199
identify += cellBeg + i18n("Sensitivity:") + cellMid + sensitivity + cellEnd;
200
identify += "</table>";
202
d->infoLabel->setText(identify);
205
d->infoLabel->clear();
209
void ImageDialogPreview::slotGotThumbnail(const KURL& url, const QPixmap& pix)
211
if (url == d->currentURL)
214
QSize s = d->imageLabel->contentsRect().size();
216
if (s.width() < pix.width() || s.height() < pix.height())
217
pixmap = pix.convertToImage().smoothScale(s, QImage::ScaleMin);
221
d->imageLabel->setPixmap(pixmap);
225
void ImageDialogPreview::slotFailedThumbnail(const KURL& /*url*/)
227
KIconLoader* iconLoader = KApplication::kApplication()->iconLoader();
228
d->imageLabel->setPixmap(iconLoader->loadIcon("image", KIcon::NoGroup, 128,
229
KIcon::DefaultState, 0, true));
232
void ImageDialogPreview::clearPreview()
234
d->imageLabel->clear();
235
d->infoLabel->clear();
236
d->currentURL = KURL();
239
// ------------------------------------------------------------------------
241
class ImageDialogPrivate
248
singleSelect = false;
259
ImageDialog::ImageDialog(QWidget* parent, const KURL &url, bool singleSelect, const QString& caption)
261
d = new ImageDialogPrivate;
262
d->singleSelect = singleSelect;
264
QStringList patternList = QStringList::split('\n', KImageIO::pattern(KImageIO::Reading));
266
// All Images from list must been always the first entry given by KDE API
267
QString allPictures = patternList[0];
269
// Add other files format witch are missing to All Images" type mime provided by KDE and remplace current.
270
if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
272
allPictures.insert(allPictures.find("|"), QString(KDcrawIface::DcrawBinary::instance()->rawFiles()) + QString(" *.JPE *.TIF"));
273
patternList.remove(patternList[0]);
274
patternList.prepend(allPictures);
277
// Added RAW file formats supported by dcraw program like a type mime.
278
// Nota: we cannot use here "image/x-raw" type mime from KDE because it uncomplete
279
// or unavailable(dcraw_0)(see file #121242 in B.K.O).
280
if (KDcrawIface::DcrawBinary::instance()->versionIsRight())
282
patternList.append(i18n("\n%1|Camera RAW files").arg(QString(KDcrawIface::DcrawBinary::instance()->rawFiles())));
285
d->fileformats = patternList.join("\n");
287
DDebug() << "fileformats=" << d->fileformats << endl;
289
KFileDialog dlg(url.path(), d->fileformats, parent, "imageFileOpenDialog", false);
290
ImageDialogPreview *preview = new ImageDialogPreview(&dlg);
291
dlg.setPreviewWidget(preview);
292
dlg.setOperationMode(KFileDialog::Opening);
296
dlg.setMode(KFile::File);
297
if (caption.isEmpty()) dlg.setCaption(i18n("Select an Image"));
298
else dlg.setCaption(caption);
300
d->url = dlg.selectedURL();
304
dlg.setMode(KFile::Files);
305
if (caption.isEmpty()) dlg.setCaption(i18n("Select Images"));
306
else dlg.setCaption(caption);
308
d->urls = dlg.selectedURLs();
312
ImageDialog::~ImageDialog()
317
bool ImageDialog::singleSelect() const
319
return d->singleSelect;
322
QString ImageDialog::fileformats() const
324
return d->fileformats;
327
KURL ImageDialog::url() const
332
KURL::List ImageDialog::urls() const
337
KURL::List ImageDialog::getImageURLs(QWidget* parent, const KURL& url, const QString& caption)
339
ImageDialog dlg(parent, url, false, caption);
340
if (!dlg.urls().isEmpty())
346
KURL ImageDialog::getImageURL(QWidget* parent, const KURL& url, const QString& caption)
348
ImageDialog dlg(parent, url, true, caption);
349
if (dlg.url() != KURL())
355
} // namespace Digikam