Commit 53664663 authored by David Jarvie's avatar David Jarvie
Browse files

Bug 437217: Fix 'Choose sound file' dialog showing no audio files

Under XFCE etc., it was impossible to show or even type the names
of audio files in order to select them. This was due to QFileDialog
filters acting differently under different desktops.

BUG:437217
parent 8c3a8c49
Pipeline #72947 passed with stage
in 6 minutes and 15 seconds
KAlarm Change Log
=== Version 3.3.0 (KDE Applications 21.08) --- 27 July 2021 ===
=== Version 3.3.0 (KDE Applications 21.08) --- 1 August 2021 ===
* Add date selector option to enable alarm list view to be filtered.
* Show hamburger menu when menu bar is hidden, to allow access to all options.
* Fix crash when context menu is requested after toolbar has been edited.
* Fix crash when alarm message is shown on a multiple screen system using Wayland [KDE Bug 439853]
* Fix alarm not triggering if a reminder is set after the main alarm (requires kalarmcal 21.08) [KDE Bug 440200]
* Fix 'Choose sound file' dialogue not showing audio files, under XFCE etc [KDE Bug 437217]
* Fix alarm time showing blank in alarm list when using right-to-left languages.
* Fixes to dialogue layouts when using right-to-left languages.
......
......@@ -73,7 +73,7 @@ class PickLogFileRadio : public PickFileRadio
: PickFileRadio(b, e, text, group, parent) { }
bool pickFile(QString& file) override // called when browse button is pressed to select a log file
{
return File::browseFile(file, i18nc("@title:window", "Choose Log File"), mDefaultDir, fileEdit()->text(), QString(),
return File::browseFile(file, i18nc("@title:window", "Choose Log File"), mDefaultDir, fileEdit()->text(),
false, parentWidget());
}
private:
......@@ -731,7 +731,7 @@ void EditDisplayAlarmDlg::slotPickFile()
static QString defaultDir; // default directory for file browse button
QString file;
if (File::browseFile(file, i18nc("@title:window", "Choose Text or Image File to Display"),
defaultDir, mFileMessageEdit->text(), QString(), true, this))
defaultDir, mFileMessageEdit->text(), true, this))
{
if (!file.isEmpty())
{
......@@ -1542,7 +1542,7 @@ void EditEmailAlarmDlg::slotAddAttachment()
{
QString file;
if (File::browseFile(file, i18nc("@title:window", "Choose File to Attach"),
mAttachDefaultDir, QString(), QString(), true, this))
mAttachDefaultDir, QString(), true, this))
{
if (!file.isEmpty())
{
......
/*
* lib/file.cpp - functions to handle files
* Program: kalarm
* SPDX-FileCopyrightText: 2005-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2005-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -155,7 +155,14 @@ QString pathOrUrl(const QString& url)
* the parent widget was probably also deleted).
*/
bool browseFile(QString& file, const QString& caption, QString& defaultDir,
const QString& initialFile, const QString& filter, bool existing, QWidget* parent)
const QString& initialFile, bool existing, QWidget* parent)
{
return browseFile(file, caption, defaultDir, {}, initialFile, existing, parent);
}
bool browseFile(QString& file, const QString& caption, QString& defaultDir,
const QString& fileNameFilter, const QString& initialFile,
bool existing, QWidget* parent)
{
file.clear();
const QString initialDir = !initialFile.isEmpty() ? QString(initialFile).remove(QRegExp(QLatin1String("/[^/]*$")))
......@@ -164,9 +171,14 @@ bool browseFile(QString& file, const QString& caption, QString& defaultDir,
// Use AutoQPointer to guard against crash on application exit while
// the dialogue is still open. It prevents double deletion (both on
// deletion of parent, and on return from this function).
AutoQPointer<QFileDialog> fileDlg = new QFileDialog(parent, caption, initialDir, filter);
AutoQPointer<QFileDialog> fileDlg = new QFileDialog(parent, caption, initialDir);
fileDlg->setAcceptMode(existing ? QFileDialog::AcceptOpen : QFileDialog::AcceptSave);
fileDlg->setFileMode(existing ? QFileDialog::ExistingFile : QFileDialog::AnyFile);
QStringList nameFilters;
if (!fileNameFilter.isEmpty())
nameFilters << fileNameFilter;
nameFilters << QStringLiteral("All files (*)");
fileDlg->setNameFilters(nameFilters);
if (!initialFile.isEmpty())
fileDlg->selectFile(initialFile);
if (fileDlg->exec() != QDialog::Accepted)
......
/*
* lib/file.h - functions to handle files
* Program: kalarm
* SPDX-FileCopyrightText: 2005-2019 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2005-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -47,9 +47,17 @@ bool showFileErrMessage(const QString& filename, FileErr, FileErr blankError, QW
/** If a url string is a local file, strip off the 'file:/' prefix. */
QString pathOrUrl(const QString& url);
/* Display a modal dialog to choose a file, initially highlighting any
* specified file. */
bool browseFile(QString& file, const QString& caption, QString& defaultDir,
const QString& initialFile = QString(),
const QString& filter = QString(), bool existing = false, QWidget* parent = nullptr);
bool existing = false, QWidget* parent = nullptr);
/* Display a modal dialog to choose a file, initially highlighting any
* specified file. */
bool browseFile(QString& file, const QString& caption, QString& defaultDir,
const QString& fileNameFilter, const QString& initialFile,
bool existing = false, QWidget* parent = nullptr);
}
......
/*
* soundpicker.cpp - widget to select a sound file or a beep
* Program: kalarm
* SPDX-FileCopyrightText: 2002-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2002-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -27,6 +27,7 @@
#include <QLabel>
#include <QHBoxLayout>
#include <QStandardPaths>
#include <QMimeDatabase>
//clazy:excludeall=non-pod-global-static
......@@ -307,6 +308,22 @@ void SoundPicker::setLastType()
*/
bool SoundPicker::browseFile(QString& file, QString& defaultDir, const QString& initialFile)
{
static QString audioFilter;
if (audioFilter.isEmpty())
{
audioFilter = QStringLiteral("Audio files (");
QMimeDatabase db;
const QStringList mimeTypes = Phonon::BackendCapabilities::availableMimeTypes();
for (const QString& mimeType : mimeTypes)
if (mimeType.startsWith(QStringLiteral("audio/")))
{
const QMimeType mt = db.mimeTypeForName(mimeType);
audioFilter += mt.globPatterns().join(QLatin1Char(' '));
audioFilter += QLatin1Char(' ');
}
audioFilter[audioFilter.length() - 1] = QLatin1Char(')');
}
static QString kdeSoundDir; // directory containing KDE sound files
if (defaultDir.isEmpty())
{
......@@ -317,9 +334,9 @@ bool SoundPicker::browseFile(QString& file, QString& defaultDir, const QString&
}
defaultDir = kdeSoundDir;
}
const QString filter = Phonon::BackendCapabilities::availableMimeTypes().join(QLatin1Char(' '));
return File::browseFile(file, i18nc("@title:window", "Choose Sound File"),
defaultDir, initialFile, filter, true, nullptr);
return File::browseFile(file, i18nc("@title:window", "Choose Sound File"), defaultDir,
audioFilter, initialFile, true, nullptr);
}
/******************************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment