diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index a4a017fcf..b235de012 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace Tools { @@ -84,4 +85,22 @@ QDateTime currentDateTimeUtc () #endif } +QString imageReaderFilter() +{ + QList formats = QImageReader::supportedImageFormats(); + QStringList formatsStringList; + + Q_FOREACH (const QByteArray& format, formats) { + for (int i = 0; i < format.size(); i++) { + if (!QChar(format.at(i)).isLetterOrNumber()) { + continue; + } + } + + formatsStringList.append("*." + QString::fromAscii(format).toLower()); + } + + return formatsStringList.join(" "); +} + } // namespace Tools diff --git a/src/core/Tools.h b/src/core/Tools.h index b1e0b1ada..46463d2b1 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -30,6 +30,7 @@ QString humanReadableFileSize(qint64 bytes); bool hasChild(const QObject* parent, const QObject* child); bool readAllFromDevice(QIODevice* device, QByteArray& data); QDateTime currentDateTimeUtc(); +QString imageReaderFilter(); } // namespace Tools diff --git a/src/gui/EditEntryWidget.cpp b/src/gui/EditEntryWidget.cpp index a4ae78a6a..26c0d9d0c 100644 --- a/src/gui/EditEntryWidget.cpp +++ b/src/gui/EditEntryWidget.cpp @@ -422,8 +422,11 @@ void EditEntryWidget::removeCurrentAttachment() void EditEntryWidget::addCustomIcon() { if (m_metadata) { + QString filter = QString("%1 (%2);;%3 (*.*)").arg(tr("Images"), + Tools::imageReaderFilter(), tr("All files")); + QString filename = QFileDialog::getOpenFileName( - this, tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); + this, tr("Select Image"), "", filter); if (!filename.isEmpty()) { QImage image(filename); if (!image.isNull()) {