Apply clang-format

This commit is contained in:
Martchus 2017-05-01 03:39:45 +02:00
parent 742dc25984
commit 778b31c0ed
6 changed files with 128 additions and 122 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ Makefile*
# documentation # documentation
/doc /doc
# clang-format
/.clang-format

View File

@ -1,14 +1,14 @@
#include "ffmpeglauncher.h" #include "ffmpeglauncher.h"
#include "playerwatcher.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/conversion/stringconversion.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/inifile.h>
#include <QStringBuilder> #include <QStringBuilder>
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
using namespace std; using namespace std;
using namespace IoUtilities; using namespace IoUtilities;
@ -25,8 +25,7 @@ inline ostream &operator <<(ostream &stream, const QString &str)
inline QString validFileName(const QString &text) inline QString validFileName(const QString &text)
{ {
QString copy(text); QString copy(text);
copy copy.replace(QChar('\\'), QLatin1String(" - "))
.replace(QChar('\\'), QLatin1String(" - "))
.replace(QChar('/'), QLatin1String(" - ")) .replace(QChar('/'), QLatin1String(" - "))
.replace(QChar('\n'), QString()) .replace(QChar('\n'), QString())
.replace(QChar('\r'), QString()) .replace(QChar('\r'), QString())
@ -42,15 +41,15 @@ inline QString validFileName(const QString &text)
return copy; return copy;
} }
FfmpegLauncher::FfmpegLauncher(PlayerWatcher &watcher, QObject *parent) : FfmpegLauncher::FfmpegLauncher(PlayerWatcher &watcher, QObject *parent)
QObject(parent), : QObject(parent)
m_watcher(watcher), , m_watcher(watcher)
m_sink(QStringLiteral("default")), , m_sink(QStringLiteral("default"))
m_inputOptions(), , m_inputOptions()
m_options(), , m_options()
m_targetDir(QStringLiteral(".")), , m_targetDir(QStringLiteral("."))
m_targetExtension(QStringLiteral(".m4a")), , m_targetExtension(QStringLiteral(".m4a"))
m_ffmpeg(new QProcess(this)) , m_ffmpeg(new QProcess(this))
{ {
connect(&watcher, &PlayerWatcher::nextSong, this, &FfmpegLauncher::nextSong); connect(&watcher, &PlayerWatcher::nextSong, this, &FfmpegLauncher::nextSong);
connect(&watcher, &PlayerWatcher::playbackStopped, this, &FfmpegLauncher::stopFfmpeg); connect(&watcher, &PlayerWatcher::playbackStopped, this, &FfmpegLauncher::stopFfmpeg);
@ -85,7 +84,8 @@ void FfmpegLauncher::nextSong()
// determine output file, create target directory // determine output file, create target directory
static const QString miscCategory(QStringLiteral("misc")); static const QString miscCategory(QStringLiteral("misc"));
static const QString unknownTitle(QStringLiteral("unknown track")); 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)) { if (!m_targetDir.mkpath(targetDirPath)) {
cerr << "Error: Can not create target directory: " << targetDirPath << endl; cerr << "Error: Can not create target directory: " << targetDirPath << endl;
return; return;
@ -155,11 +155,13 @@ void FfmpegLauncher::nextSong()
} }
} }
// determine target name/path // 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; unsigned int count = 1;
while (targetDir.exists(targetName)) { while (targetDir.exists(targetName)) {
++count; ++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); auto targetPath = targetDir.absoluteFilePath(targetName);
// set input device // set input device
@ -183,10 +185,12 @@ void FfmpegLauncher::nextSong()
addMetaData(args, QStringLiteral("genre"), genre.isEmpty() ? m_watcher.genre() : genre); addMetaData(args, QStringLiteral("genre"), genre.isEmpty() ? m_watcher.genre() : genre);
addMetaData(args, QStringLiteral("year"), year.isEmpty() ? m_watcher.year() : year); addMetaData(args, QStringLiteral("year"), year.isEmpty() ? m_watcher.year() : year);
if (m_watcher.trackNumber()) { 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()) { 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 // set output file
args << targetPath; args << targetPath;
@ -232,5 +236,4 @@ void FfmpegLauncher::ffmpegFinished(int exitCode)
{ {
cerr << "FFmpeg finished with exit code " << exitCode << endl; cerr << "FFmpeg finished with exit code " << exitCode << endl;
} }
} }

View File

@ -1,16 +1,15 @@
#ifndef FFMPEGLAUNCHER_H #ifndef FFMPEGLAUNCHER_H
#define FFMPEGLAUNCHER_H #define FFMPEGLAUNCHER_H
#include <QDir>
#include <QObject> #include <QObject>
#include <QProcess> #include <QProcess>
#include <QDir>
namespace DBusSoundRecorder { namespace DBusSoundRecorder {
class PlayerWatcher; class PlayerWatcher;
class FfmpegLauncher : public QObject class FfmpegLauncher : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
explicit FfmpegLauncher(PlayerWatcher &watcher, QObject *parent = nullptr); 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; m_targetExtension = extension.startsWith(QChar('.')) ? extension : QStringLiteral(".") + extension;
} }
} }
#endif // FFMPEGLAUNCHER_H #endif // FFMPEGLAUNCHER_H

View File

@ -1,5 +1,5 @@
#include "playerwatcher.h"
#include "ffmpeglauncher.h" #include "ffmpeglauncher.h"
#include "playerwatcher.h"
#include "resources/config.h" #include "resources/config.h"
@ -51,7 +51,8 @@ int main(int argc, char *argv[])
ffmpegOptions.setValueNames({ "options" }); ffmpegOptions.setValueNames({ "options" });
ffmpegOptions.setRequiredValueCount(1); ffmpegOptions.setRequiredValueCount(1);
ffmpegOptions.setCombinable(true); 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 }); parser.setMainArguments({ &helpArg, &recordArg });
// parse command line arguments // parse command line arguments
try { try {

View File

@ -3,8 +3,8 @@
#include "playerinterface.h" #include "playerinterface.h"
#include "propertiesinterface.h" #include "propertiesinterface.h"
#include <QDBusServiceWatcher>
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusServiceWatcher>
#include <iostream> #include <iostream>
@ -19,18 +19,21 @@ inline ostream &operator <<(ostream &stream, const QString &str)
return stream; return stream;
} }
PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus, QObject *parent) : PlayerWatcher::PlayerWatcher(const QString &appName, bool ignorePlaybackStatus, QObject *parent)
QObject(parent), : QObject(parent)
m_mediaPlayerInterfaceName(QStringLiteral("org.mpris.MediaPlayer2.%1").arg(appName)), , m_mediaPlayerInterfaceName(QStringLiteral("org.mpris.MediaPlayer2.%1").arg(appName))
m_mediaPlayerServiceWatcher(new QDBusServiceWatcher(m_mediaPlayerInterfaceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this)), , m_mediaPlayerServiceWatcher(
m_propertiesInterface(new OrgFreedesktopDBusPropertiesInterface(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this)), new QDBusServiceWatcher(m_mediaPlayerInterfaceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this))
m_playerInterface(new OrgMprisMediaPlayer2PlayerInterface(m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this)), , m_propertiesInterface(new OrgFreedesktopDBusPropertiesInterface(
m_isPlaying(false), m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
m_isAd(false), , m_playerInterface(new OrgMprisMediaPlayer2PlayerInterface(
m_trackNumber(0), m_mediaPlayerInterfaceName, QStringLiteral("/org/mpris/MediaPlayer2"), QDBusConnection::sessionBus(), this))
m_diskNumber(0), , m_isPlaying(false)
m_silent(false), , m_isAd(false)
m_ignorePlaybackStatus(ignorePlaybackStatus) , m_trackNumber(0)
, m_diskNumber(0)
, m_silent(false)
, m_ignorePlaybackStatus(ignorePlaybackStatus)
{ {
if (!connect(m_mediaPlayerServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &PlayerWatcher::serviceOwnerChanged)) { if (!connect(m_mediaPlayerServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &PlayerWatcher::serviceOwnerChanged)) {
cout << "Warning: Unable to connect \"serviceOwnerChanged\" signal of service watcher." << endl; 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; // cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
//} //}
// However, the following works: // 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; cout << "Warning: Unable to connect \"PropertiesChanged\" signal of properties interface." << endl;
} }
propertiesChanged(); propertiesChanged();
@ -147,5 +151,4 @@ void PlayerWatcher::seeked(qlonglong pos)
{ {
cerr << "Seeked: " << pos << endl; cerr << "Seeked: " << pos << endl;
} }
} }

View File

@ -12,8 +12,7 @@ class OrgMprisMediaPlayer2PlayerInterface;
namespace DBusSoundRecorder { namespace DBusSoundRecorder {
class PlayerWatcher : public QObject class PlayerWatcher : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
explicit PlayerWatcher(const QString &appName, bool ignorePlaybackStatus = false, QObject *parent = nullptr); explicit PlayerWatcher(const QString &appName, bool ignorePlaybackStatus = false, QObject *parent = nullptr);
@ -127,7 +126,6 @@ inline void PlayerWatcher::setSilent(bool silent)
{ {
m_silent = silent; m_silent = silent;
} }
} }
#endif // PLAYERWATCHER_H #endif // PLAYERWATCHER_H