Apply clang-format
This commit is contained in:
parent
742dc25984
commit
778b31c0ed
|
@ -39,3 +39,6 @@ Makefile*
|
|||
|
||||
# documentation
|
||||
/doc
|
||||
|
||||
# clang-format
|
||||
/.clang-format
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "ffmpeglauncher.h"
|
||||
#include "playerwatcher.h"
|
||||
|
||||
#include <c++utilities/io/inifile.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
#include <c++utilities/conversion/stringconversion.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
#include <c++utilities/io/inifile.h>
|
||||
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace IoUtilities;
|
||||
|
@ -25,8 +25,7 @@ inline ostream &operator <<(ostream &stream, const QString &str)
|
|||
inline QString validFileName(const QString &text)
|
||||
{
|
||||
QString copy(text);
|
||||
copy
|
||||
.replace(QChar('\\'), QLatin1String(" - "))
|
||||
copy.replace(QChar('\\'), QLatin1String(" - "))
|
||||
.replace(QChar('/'), QLatin1String(" - "))
|
||||
.replace(QChar('\n'), QString())
|
||||
.replace(QChar('\r'), QString())
|
||||
|
@ -42,15 +41,15 @@ inline QString validFileName(const QString &text)
|
|||
return copy;
|
||||
}
|
||||
|
||||
FfmpegLauncher::FfmpegLauncher(PlayerWatcher &watcher, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_watcher(watcher),
|
||||
m_sink(QStringLiteral("default")),
|
||||
m_inputOptions(),
|
||||
m_options(),
|
||||
m_targetDir(QStringLiteral(".")),
|
||||
m_targetExtension(QStringLiteral(".m4a")),
|
||||
m_ffmpeg(new QProcess(this))
|
||||
FfmpegLauncher::FfmpegLauncher(PlayerWatcher &watcher, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_watcher(watcher)
|
||||
, m_sink(QStringLiteral("default"))
|
||||
, m_inputOptions()
|
||||
, m_options()
|
||||
, m_targetDir(QStringLiteral("."))
|
||||
, m_targetExtension(QStringLiteral(".m4a"))
|
||||
, m_ffmpeg(new QProcess(this))
|
||||
{
|
||||
connect(&watcher, &PlayerWatcher::nextSong, this, &FfmpegLauncher::nextSong);
|
||||
connect(&watcher, &PlayerWatcher::playbackStopped, this, &FfmpegLauncher::stopFfmpeg);
|
||||
|
@ -85,7 +84,8 @@ void FfmpegLauncher::nextSong()
|
|||
// determine output file, create target directory
|
||||
static const QString miscCategory(QStringLiteral("misc"));
|
||||
static const QString unknownTitle(QStringLiteral("unknown track"));
|
||||
const auto targetDirPath = QStringLiteral("%1/%2").arg(m_watcher.artist().isEmpty() ? miscCategory : validFileName(m_watcher.artist()), m_watcher.artist().isEmpty() ? miscCategory : validFileName(m_watcher.album()));
|
||||
const auto targetDirPath = QStringLiteral("%1/%2").arg(m_watcher.artist().isEmpty() ? miscCategory : validFileName(m_watcher.artist()),
|
||||
m_watcher.artist().isEmpty() ? miscCategory : validFileName(m_watcher.album()));
|
||||
if (!m_targetDir.mkpath(targetDirPath)) {
|
||||
cerr << "Error: Can not create target directory: " << targetDirPath << endl;
|
||||
return;
|
||||
|
@ -155,11 +155,13 @@ void FfmpegLauncher::nextSong()
|
|||
}
|
||||
}
|
||||
// determine target name/path
|
||||
QString targetName(QStringLiteral("%3%1%2").arg(m_watcher.title().isEmpty() ? unknownTitle : validFileName(m_watcher.title()), m_targetExtension, number));
|
||||
QString targetName(
|
||||
QStringLiteral("%3%1%2").arg(m_watcher.title().isEmpty() ? unknownTitle : validFileName(m_watcher.title()), m_targetExtension, number));
|
||||
unsigned int count = 1;
|
||||
while (targetDir.exists(targetName)) {
|
||||
++count;
|
||||
targetName = QStringLiteral("%3%1 (%4)%2").arg(m_watcher.title().isEmpty() ? unknownTitle : m_watcher.title(), m_targetExtension, number).arg(count);
|
||||
targetName
|
||||
= QStringLiteral("%3%1 (%4)%2").arg(m_watcher.title().isEmpty() ? unknownTitle : m_watcher.title(), m_targetExtension, number).arg(count);
|
||||
}
|
||||
auto targetPath = targetDir.absoluteFilePath(targetName);
|
||||
// set input device
|
||||
|
@ -183,10 +185,12 @@ void FfmpegLauncher::nextSong()
|
|||
addMetaData(args, QStringLiteral("genre"), genre.isEmpty() ? m_watcher.genre() : genre);
|
||||
addMetaData(args, QStringLiteral("year"), year.isEmpty() ? m_watcher.year() : year);
|
||||
if (m_watcher.trackNumber()) {
|
||||
addMetaData(args, QStringLiteral("track"), totalTracks.isEmpty() ? QString::number(m_watcher.trackNumber()) : QString::number(m_watcher.trackNumber()) % QChar('/') % totalTracks);
|
||||
addMetaData(args, QStringLiteral("track"),
|
||||
totalTracks.isEmpty() ? QString::number(m_watcher.trackNumber()) : QString::number(m_watcher.trackNumber()) % QChar('/') % totalTracks);
|
||||
}
|
||||
if (m_watcher.diskNumber()) {
|
||||
addMetaData(args, QStringLiteral("disk"), totalDisks.isEmpty() ? QString::number(m_watcher.diskNumber()) : QString::number(m_watcher.diskNumber()) % QChar('/') % totalDisks);
|
||||
addMetaData(args, QStringLiteral("disk"),
|
||||
totalDisks.isEmpty() ? QString::number(m_watcher.diskNumber()) : QString::number(m_watcher.diskNumber()) % QChar('/') % totalDisks);
|
||||
}
|
||||
// set output file
|
||||
args << targetPath;
|
||||
|
@ -232,5 +236,4 @@ void FfmpegLauncher::ffmpegFinished(int exitCode)
|
|||
{
|
||||
cerr << "FFmpeg finished with exit code " << exitCode << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#ifndef FFMPEGLAUNCHER_H
|
||||
#define FFMPEGLAUNCHER_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
|
||||
namespace DBusSoundRecorder {
|
||||
|
||||
class PlayerWatcher;
|
||||
|
||||
class FfmpegLauncher : public QObject
|
||||
{
|
||||
class FfmpegLauncher : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FfmpegLauncher(PlayerWatcher &watcher, QObject *parent = nullptr);
|
||||
|
@ -68,7 +67,6 @@ inline void FfmpegLauncher::setTargetExtension(const QString &extension)
|
|||
{
|
||||
m_targetExtension = extension.startsWith(QChar('.')) ? extension : QStringLiteral(".") + extension;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FFMPEGLAUNCHER_H
|
||||
|
|
5
main.cpp
5
main.cpp
|
@ -1,5 +1,5 @@
|
|||
#include "playerwatcher.h"
|
||||
#include "ffmpeglauncher.h"
|
||||
#include "playerwatcher.h"
|
||||
|
||||
#include "resources/config.h"
|
||||
|
||||
|
@ -51,7 +51,8 @@ int main(int argc, char *argv[])
|
|||
ffmpegOptions.setValueNames({ "options" });
|
||||
ffmpegOptions.setRequiredValueCount(1);
|
||||
ffmpegOptions.setCombinable(true);
|
||||
recordArg.setSubArguments({&applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions});
|
||||
recordArg.setSubArguments(
|
||||
{ &applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions });
|
||||
parser.setMainArguments({ &helpArg, &recordArg });
|
||||
// parse command line arguments
|
||||
try {
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "playerinterface.h"
|
||||
#include "propertiesinterface.h"
|
||||
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusServiceWatcher>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -19,18 +19,21 @@ inline ostream &operator <<(ostream &stream, const QString &str)
|
|||
return stream;
|
||||
}
|
||||
|
||||
PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_mediaPlayerInterfaceName(QStringLiteral("org.mpris.MediaPlayer2.%1").arg(appName)),
|
||||
m_mediaPlayerServiceWatcher(new QDBusServiceWatcher(m_mediaPlayerInterfaceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this)),
|
||||
m_propertiesInterface(new OrgFreedesktopDBusPropertiesInterface(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this)),
|
||||
m_playerInterface(new OrgMprisMediaPlayer2PlayerInterface(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this)),
|
||||
m_isPlaying(false),
|
||||
m_isAd(false),
|
||||
m_trackNumber(0),
|
||||
m_diskNumber(0),
|
||||
m_silent(false),
|
||||
m_ignorePlaybackStatus(ignorePlaybackStatus)
|
||||
PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_mediaPlayerInterfaceName(QStringLiteral("org.mpris.MediaPlayer2.%1").arg(appName))
|
||||
, m_mediaPlayerServiceWatcher(
|
||||
new QDBusServiceWatcher(m_mediaPlayerInterfaceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this))
|
||||
, m_propertiesInterface(new OrgFreedesktopDBusPropertiesInterface(
|
||||
m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
|
||||
, m_playerInterface(new OrgMprisMediaPlayer2PlayerInterface(
|
||||
m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
|
||||
, m_isPlaying(false)
|
||||
, m_isAd(false)
|
||||
, m_trackNumber(0)
|
||||
, m_diskNumber(0)
|
||||
, m_silent(false)
|
||||
, m_ignorePlaybackStatus(ignorePlaybackStatus)
|
||||
{
|
||||
if (!connect(m_mediaPlayerServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &PlayerWatcher::serviceOwnerChanged)) {
|
||||
cout << "Warning: Unable to connect \"serviceOwnerChanged\" signal of service watcher." << endl;
|
||||
|
@ -40,7 +43,8 @@ PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus,
|
|||
// cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
|
||||
//}
|
||||
// However, the following works:
|
||||
if(!QDBusConnection::sessionBus().connect(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"), this, SLOT(propertiesChanged()))) {
|
||||
if (!QDBusConnection::sessionBus().connect(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"),
|
||||
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"), this, SLOT(propertiesChanged()))) {
|
||||
cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
|
||||
}
|
||||
propertiesChanged();
|
||||
|
@ -147,5 +151,4 @@ void PlayerWatcher::seeked(qlonglong pos)
|
|||
{
|
||||
cerr << "Seeked: " << pos << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@ class OrgMprisMediaPlayer2PlayerInterface;
|
|||
|
||||
namespace DBusSoundRecorder {
|
||||
|
||||
class PlayerWatcher : public QObject
|
||||
{
|
||||
class PlayerWatcher : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PlayerWatcher(const QString &appName, bool ignorePlaybackStatus = false, QObject *parent = nullptr);
|
||||
|
@ -127,7 +126,6 @@ inline void PlayerWatcher::setSilent(bool silent)
|
|||
{
|
||||
m_silent = silent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // PLAYERWATCHER_H
|
||||
|
|
Loading…
Reference in New Issue