mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
Ref T644, allow to fetch notifications sounds from an arbitrary directory
* added settings * utility functions
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include "blackmisc/fileutils.h"
|
||||
|
||||
using namespace BlackMisc::Audio;
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -40,6 +42,19 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::setNotificationSoundDirectory(const QString &dir)
|
||||
{
|
||||
QString d = dir.trimmed();
|
||||
if (d.isEmpty())
|
||||
{
|
||||
// reset
|
||||
m_notificationSoundDir.clear();
|
||||
return;
|
||||
}
|
||||
d = CFileUtils::fixWindowsUncPath(d);
|
||||
m_notificationSoundDir = d;
|
||||
}
|
||||
|
||||
QString CSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
|
||||
@@ -57,6 +57,12 @@ namespace BlackMisc
|
||||
//! Settings value
|
||||
CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag);
|
||||
|
||||
//! Directory
|
||||
void setNotificationSoundDirectory(const QString &dir);
|
||||
|
||||
//! Notification directory
|
||||
const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; }
|
||||
|
||||
//! Init with meaningful default values
|
||||
void initDefaultValues();
|
||||
|
||||
@@ -64,11 +70,13 @@ namespace BlackMisc
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_notificationSoundDir;
|
||||
int m_notification = static_cast<int>(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..)
|
||||
void initNotificationFlags(); //!< init flags
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettings,
|
||||
BLACK_METAMEMBER(notificationSoundDir),
|
||||
BLACK_METAMEMBER(notification)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFlags>
|
||||
#include <QIODevice>
|
||||
#include <QList>
|
||||
@@ -582,9 +583,15 @@ namespace BlackMisc
|
||||
return CFileUtils::appendFilePaths(CDirectoryUtils::soundFilesDirectory(), name);
|
||||
}
|
||||
|
||||
QUrl CFileUtils::soundFileQUrl(const QString &name)
|
||||
QUrl CFileUtils::soundFileQUrl(const QString &directory, const QString &name)
|
||||
{
|
||||
if (name.isEmpty()) { return {}; }
|
||||
if (!directory.isEmpty())
|
||||
{
|
||||
const QString f = CFileUtils::appendFilePathsAndFixUnc(directory, name);
|
||||
const QFileInfo fi(f);
|
||||
if (fi.exists()) { return QUrl::fromLocalFile(f); }
|
||||
}
|
||||
return QUrl::fromLocalFile(CFileUtils::soundFilePathAndFileName(name));
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace BlackMisc
|
||||
static QString soundFilePathAndFileName(const QString &name);
|
||||
|
||||
//! QUrl of soundFilePathAndFileName
|
||||
static QUrl soundFileQUrl(const QString &name);
|
||||
static QUrl soundFileQUrl(const QString &directory, const QString &name);
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
Reference in New Issue
Block a user