From fdb76bb5c1bdce765479442a70ddca80b867caa6 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Wed, 29 Nov 2017 23:39:35 +0200 Subject: Implement file uploads fixes #24 --- src/TextInputWidget.cc | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/TextInputWidget.cc') diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc index 829784fd..c4d01357 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc @@ -276,30 +276,27 @@ TextInputWidget::command(QString command, QString args) void TextInputWidget::openFileSelection() { - QStringList supportedFiles; - supportedFiles << "jpeg" - << "gif" - << "png" - << "bmp" - << "tiff" - << "webp"; - - auto fileName = QFileDialog::getOpenFileName( - this, - tr("Select an image"), - "", - tr("Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tiff *.webp)")); + QStringList imageExtensions; + imageExtensions << "jpeg" + << "gif" + << "png" + << "bmp" + << "tiff" + << "webp"; + + auto fileName = + QFileDialog::getOpenFileName(this, tr("Select an file"), "", tr("All Files (*)")); if (fileName.isEmpty()) return; - auto imageFormat = QString(QImageReader::imageFormat(fileName)); - if (!supportedFiles.contains(imageFormat)) { - qDebug() << "Unsupported image format for" << fileName; - return; - } + auto format = QString(QImageReader::imageFormat(fileName)); + + if (imageExtensions.contains(format)) + emit uploadImage(fileName); + else + emit uploadFile(fileName); - emit uploadImage(fileName); showUploadSpinner(); } -- cgit 1.5.1