diff --git a/.clang-format b/.clang-format index f6164387ce08c84a7c9e55f0b7179d1bd7c1a6d5..39f8e65703751e057f5e48f230ca727c006f1f4a 100644 --- a/.clang-format +++ b/.clang-format @@ -1,11 +1,11 @@ --- Language: Cpp -AccessModifierOffset: -2 +AccessModifierOffset: -4 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveBitFields: false -AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: true +AlignConsecutiveBitFields: true +AlignConsecutiveDeclarations: true AlignEscapedNewlines: Right AlignOperands: Align AlignTrailingComments: true @@ -55,7 +55,7 @@ BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 100 CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: trye +CompactNamespaces: true ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 @@ -87,7 +87,7 @@ IndentCaseBlocks: false IndentGotoLabels: true IndentPPDirectives: None IndentExternBlock: AfterExternBlock -IndentWidth: 2 +IndentWidth: 4 IndentWrappedFunctionNames: false InsertTrailingCommas: None JavaScriptQuotes: Leave @@ -98,11 +98,11 @@ MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 +ObjCBlockIndentWidth: 4 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true -PenaltyBreakAssignment: 2 +PenaltyBreakAssignment: 4 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 diff --git a/README.md b/README.md index 9529448e1e8a189c75f7797331019ecbec61ec9d..7c8eba5ddffd21cee5cc9bb828bc3764b74f0220 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,8 @@ If you are developping for lektor, you will need: - the [astyle](http://astyle.sourceforge.net/) command line utility, for a beautifull and uniform coding style for C code. - the [clang-format](https://releases.llvm.org/download.html) command line utility, for a - beautifull and uniform C++ code style. + beautifull and uniform C++ code style. [Here](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) + is the list of all the options to put in the `.clang-format` file. > If you are having problems build lektor (AC macros not defined), try copy the > `.m4` files from `/usr/share/aclocal` to `config/m4`. diff --git a/src/klkt/klkt.cpp b/src/klkt/klkt.cpp index ae6d8fd43aefa58026d18ef08488cc271ca7d9a6..1de9c3e1f830f9175f422bfc5f296d3abee0643e 100644 --- a/src/klkt/klkt.cpp +++ b/src/klkt/klkt.cpp @@ -1,10 +1,9 @@ #include "klkt.hpp" /* A trashy main */ -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { Application app(argc, argv); - int code = app.exec(); + int code = app.exec(); notify_uninit(); return code; } diff --git a/src/klkt/klkt.hpp b/src/klkt/klkt.hpp index 3e0d5b31d63047891677e31a29510fd952c070ee..9c3118c284ba229e353e0b0c359d452e2bc1f2cb 100644 --- a/src/klkt/klkt.hpp +++ b/src/klkt/klkt.hpp @@ -34,17 +34,11 @@ LKT_POP static inline const int UTF8_MIB = 106; /* Hop();; We wrap the glib types */ -#define URGENCY(x) x = NOTIFY_URGENCY_ ##x, -enum Urgency { - URGENCY(LOW) - URGENCY(NORMAL) - URGENCY(CRITICAL) -}; +#define URGENCY(x) x = NOTIFY_URGENCY_##x, +enum Urgency { URGENCY(LOW) URGENCY(NORMAL) URGENCY(CRITICAL) }; #undef URGENCY -static inline const char * -__urgencyToString(Urgency urg) -{ +static inline const char *__urgencyToString(Urgency urg) { switch (urg) { case Urgency::LOW: return "LOW"; @@ -57,13 +51,11 @@ __urgencyToString(Urgency urg) } } -#if defined (Q_OS_LINUX) +#if defined(Q_OS_LINUX) /* Restrict libnotify (thus glib...) only to that function */ -static void -sendNotification(const char *name, const char *msg, enum Urgency urgency) -{ - GdkPixbuf *gtk_icon = gdk_pixbuf_new_from_xpm_data(const_cast<const char **>(icon)); - NotifyNotification *notif = notify_notification_new (name, msg, NULL); +static void sendNotification(const char *name, const char *msg, enum Urgency urgency) { + GdkPixbuf * gtk_icon = gdk_pixbuf_new_from_xpm_data(const_cast<const char **>(icon)); + NotifyNotification *notif = notify_notification_new(name, msg, NULL); notify_notification_set_icon_from_pixbuf(notif, gtk_icon); notify_notification_set_urgency(notif, static_cast<NotifyUrgency>(urgency)); notify_notification_show(notif, NULL); @@ -74,12 +66,12 @@ sendNotification(const char *name, const char *msg, enum Urgency urgency) fflush(stdout); } #else -#error "System is not supported yet, you need to write a 'sendNotification(const char *, const char *, enum Urgency)' function for that system" +#error \ + "System is not supported yet, you need to write a 'sendNotification(const char *, const char *, enum Urgency)' function for that system" #endif /* Config class, the ~/.config/lektor/klkt.ini file */ -class Config final -{ +class Config final { private: static inline const QString opt_host = "lektord/host"; static inline const QString opt_port = "lektord/port"; @@ -97,23 +89,13 @@ public: settings.setValue(opt_port, m_port); } - qint16 - getPort(void) const { - return m_port; - } - bool - isUnix(void) const { - return m_port <= 0; - } - const QString & - getHost(void) const { - return m_host; - } + qint16 getPort(void) const { return m_port; } + bool isUnix(void) const { return m_port <= 0; } + const QString &getHost(void) const { return m_host; } }; /* Socket, can be unix socket or tcp socket. Because QIODevice don't have all that what we need */ -class Socket final : public QObject -{ +class Socket final : public QObject { Q_OBJECT private: enum Type { @@ -127,23 +109,14 @@ private: Type m_type; /* Where to connect */ - QString m_host; - qint16 m_port; + QString m_host; + qint16 m_port; public slots: /* Re-emit signals */ - inline void - triggetConnected(void) { - emit connected(); - } - inline void - triggetDisconnected(void) { - emit disconnected(); - } - inline void - triggetReadyRead(void) { - emit readyRead(); - } + inline void triggetConnected(void) { emit connected(); } + inline void triggetDisconnected(void) { emit disconnected(); } + inline void triggetReadyRead(void) { emit readyRead(); } signals: /* Used signals from TCP and Unix sockets */ @@ -152,78 +125,64 @@ signals: void readyRead(void); public: - Socket(const QString &host, qint16 port) { - reset(host, port); - } + Socket(const QString &host, qint16 port) { reset(host, port); } - void - reset(const QString host, qint16 port) { + void reset(const QString host, qint16 port) { m_host = host; m_port = port; /* Unix specific stuff */ if (port <= 0) { m_type = Type::Unix; - connect(&m_unix, &QLocalSocket::connected, this, &Socket::triggetConnected); + connect(&m_unix, &QLocalSocket::connected, this, &Socket::triggetConnected); connect(&m_unix, &QLocalSocket::disconnected, this, &Socket::triggetDisconnected); - connect(&m_unix, &QLocalSocket::readyRead, this, &Socket::triggetReadyRead); + connect(&m_unix, &QLocalSocket::readyRead, this, &Socket::triggetReadyRead); } /* TCP specific stuff */ else { m_type = Type::Tcp; - connect(&m_tcp, &QTcpSocket::connected, this, &Socket::triggetConnected); + connect(&m_tcp, &QTcpSocket::connected, this, &Socket::triggetConnected); connect(&m_tcp, &QTcpSocket::disconnected, this, &Socket::triggetDisconnected); - connect(&m_tcp, &QTcpSocket::readyRead, this, &Socket::triggetReadyRead); + connect(&m_tcp, &QTcpSocket::readyRead, this, &Socket::triggetReadyRead); } } -#define __DIFFERENTIATE(unix, tcp) { \ - switch (m_type) { \ - case Type::Unix: unix; break; \ - case Type::Tcp: tcp; break; \ - } \ - sendNotification("Klkt fatal error", \ - "Unknown socket type", \ - Urgency::CRITICAL); \ - ::exit(EXIT_FAILURE); \ +#define __DIFFERENTIATE(unix, tcp) \ + { \ + switch (m_type) { \ + case Type::Unix: \ + unix; \ + break; \ + case Type::Tcp: \ + tcp; \ + break; \ + } \ + sendNotification("Klkt fatal error", "Unknown socket type", Urgency::CRITICAL); \ + ::exit(EXIT_FAILURE); \ } - inline bool - isValid(void) __DIFFERENTIATE({ return m_unix.isValid(); }, { return m_tcp.isValid(); }) - inline QByteArray - readAll(void) __DIFFERENTIATE({ return m_unix.readAll(); }, { return m_tcp.readAll(); }) - inline qint64 - write(const char *d) __DIFFERENTIATE({ return m_unix.write(d); }, { return m_tcp.write(d); }) - inline void - close(void) __DIFFERENTIATE({ return m_unix.close(); }, { return m_tcp.close(); }) - - inline void - doConnect(void) __DIFFERENTIATE({ - return m_unix.connectToServer(m_host); - }, { - return m_tcp.connectToHost(m_host, m_port); - }) - - inline bool - waitForConnected(int ms = 30000) __DIFFERENTIATE({ - return m_unix.waitForConnected(ms); - }, { - return m_tcp.waitForConnected(ms); - }) - - inline bool - waitForDisconnected(int ms = 30000) __DIFFERENTIATE({ - return m_unix.waitForDisconnected(ms); - }, { - return m_tcp.waitForDisconnected(ms); - }) + inline bool isValid(void) + __DIFFERENTIATE({ return m_unix.isValid(); }, { return m_tcp.isValid(); }); + inline QByteArray readAll(void) + __DIFFERENTIATE({ return m_unix.readAll(); }, { return m_tcp.readAll(); }); + inline qint64 write(const char *d) + __DIFFERENTIATE({ return m_unix.write(d); }, { return m_tcp.write(d); }); + inline void close(void) __DIFFERENTIATE({ return m_unix.close(); }, { return m_tcp.close(); }); + inline void doConnect(void) __DIFFERENTIATE({ return m_unix.connectToServer(m_host); }, + { return m_tcp.connectToHost(m_host, m_port); }); + inline bool waitForConnected(int ms = 30000) + __DIFFERENTIATE({ return m_unix.waitForConnected(ms); }, + { return m_tcp.waitForConnected(ms); }); + + inline bool waitForDisconnected(int ms = 30000) + __DIFFERENTIATE({ return m_unix.waitForDisconnected(ms); }, + { return m_tcp.waitForDisconnected(ms); }); #undef __DIFFERENTIATE }; /* Used to generate a notification for the state of lektord and get the currently playing kara */ -class Status final : public QWidget -{ +class Status final : public QWidget { Q_OBJECT private: Socket m_sock; @@ -231,35 +190,29 @@ private: QString m_state; QMap<QString, QString> m_current_kara; QMetaObject::Connection m_connect_read; - bool m_deletable = false; + bool m_deletable = false; bool m_send_notif = true; static inline const char *StatusString = "status\n"; static inline const char *CurrentString = "currentsong\n"; - void - sendNotification(const char *title, const char *msg, Urgency urg) { + void sendNotification(const char *title, const char *msg, Urgency urg) { if (!m_send_notif) return; ::sendNotification(title, msg, urg); } private slots: - void - connected(void) { - m_sock.write(StatusString); - } + void connected(void) { m_sock.write(StatusString); } - void - disconnected(void) { + void disconnected(void) { if (m_deletable) return; if (m_state == "play") { // m_current_kara["category"] + " - " + m_current_kara["language"] + "\n" + - QString kara = m_current_kara["source"] + "\n" - + m_current_kara["type"] + " - " + m_current_kara["title"] - + " [" + m_current_kara["author"] + "]"; + QString kara = m_current_kara["source"] + "\n" + m_current_kara["type"] + " - " + + m_current_kara["title"] + " [" + m_current_kara["author"] + "]"; sendNotification("lektord is playing", kara.toStdString().c_str(), Urgency::LOW); emit changeCurrentKara(kara); emit changeStatus(Play); @@ -279,7 +232,10 @@ private slots: else { sendNotification("lektord error", - tr("lektord has the following unkown state: '%1'").arg(m_state).toStdString().c_str(), + tr("lektord has the following unkown state: '%1'") + .arg(m_state) + .toStdString() + .c_str(), Urgency::CRITICAL); emit changeCurrentKara(tr("Unknown state: '%1'").arg(m_state)); emit changeStatus(Unknown); @@ -288,12 +244,11 @@ private slots: m_deletable = true; } - void - readCurrent(void) { - QByteArray got = m_sock.readAll(); - m_pending_data += QTextCodec::codecForMib(UTF8_MIB)->toUnicode(got); + void readCurrent(void) { + QByteArray got = m_sock.readAll(); + m_pending_data += QTextCodec::codecForMib(UTF8_MIB)->toUnicode(got); QStringList lines = m_pending_data.split("\n"); - int return_position; + int return_position; for (auto &line : lines) { return_position = line.length() + 1; @@ -304,10 +259,10 @@ private slots: } /* Decode line */ -#define DECODE(what) \ - if (line.startsWith(what ": ", Qt::CaseInsensitive)) { \ - line.remove(0, static_cast<int>(strlen(what ": "))); \ - m_current_kara.insert(what, line); \ +#define DECODE(what) \ + if (line.startsWith(what ": ", Qt::CaseInsensitive)) { \ + line.remove(0, static_cast<int>(strlen(what ": "))); \ + m_current_kara.insert(what, line); \ } DECODE("title") DECODE("author") @@ -319,12 +274,11 @@ private slots: } } - void - readStatus(void) { - QByteArray got = m_sock.readAll(); - m_pending_data += QTextCodec::codecForMib(UTF8_MIB)->toUnicode(got); + void readStatus(void) { + QByteArray got = m_sock.readAll(); + m_pending_data += QTextCodec::codecForMib(UTF8_MIB)->toUnicode(got); QStringList lines = m_pending_data.split("\n"); - int return_position; + int return_position; for (const auto &line : lines) { return_position = line.length() + 1; @@ -334,7 +288,8 @@ private slots: if (m_state == "play") { QWidget::disconnect(m_connect_read); m_pending_data = ""; - m_connect_read = QWidget::connect(&m_sock, &Socket::readyRead, this, &Status::readCurrent); + m_connect_read = + QWidget::connect(&m_sock, &Socket::readyRead, this, &Status::readCurrent); m_sock.write(CurrentString); } else m_sock.close(); @@ -352,7 +307,7 @@ public: : m_sock(host, port), m_send_notif(send_notif) { fprintf(stdout, "Query status%s\n", send_notif ? "" : " (no notification)"); m_sock.doConnect(); - QWidget::connect(&m_sock, &Socket::connected, this, &Status::connected); + QWidget::connect(&m_sock, &Socket::connected, this, &Status::connected); QWidget::connect(&m_sock, &Socket::disconnected, this, &Status::disconnected); m_connect_read = QWidget::connect(&m_sock, &Socket::readyRead, this, &Status::readStatus); fflush(stdout); @@ -360,14 +315,8 @@ public: Status &operator=(Status &) = delete; - inline bool - isDeletable(void) const { - return m_deletable; - } - inline void - waitForDisconnected(void) { - m_sock.waitForDisconnected(-1); - } + inline bool isDeletable(void) const { return m_deletable; } + inline void waitForDisconnected(void) { m_sock.waitForDisconnected(-1); } enum { Pause, @@ -382,8 +331,7 @@ signals: }; /* Send commends to lektord */ -class Commander final : public QObject -{ +class Commander final : public QObject { Q_OBJECT private: Socket m_sock; @@ -395,18 +343,14 @@ private: static inline const char *CMD_FORCE_PLAY = "play\n"; static inline const char *CMD_TOGGLE = "pause\n"; - void - doCommand(void) { + void doCommand(void) { fprintf(stdout, "Send command %s", m_cmd); m_sock.doConnect(); - connect(&m_sock, &Socket::connected, this, [&]() { - m_sock.write(m_cmd); - }); - connect(&m_sock, &Socket::disconnected, this, [&]() { - emit finished(); - }); - connect(&m_sock, &Socket::readyRead, this, [&]() { - QStringList lines = QTextCodec::codecForMib(UTF8_MIB)->toUnicode(m_sock.readAll()).split("\n"); + connect(&m_sock, &Socket::connected, this, [&]() { m_sock.write(m_cmd); }); + connect(&m_sock, &Socket::disconnected, this, [&]() { emit finished(); }); + connect(&m_sock, &Socket::readyRead, this, [&]() { + QStringList lines = + QTextCodec::codecForMib(UTF8_MIB)->toUnicode(m_sock.readAll()).split("\n"); for (auto &line : lines) { if (line == "OK" || line.left(3) == "ACK") { m_sock.close(); @@ -424,12 +368,11 @@ private: doCommand(); }; - Commander(const QString &host, qint16 port) - : m_sock(host, port), m_cmd(nullptr) - {} + Commander(const QString &host, qint16 port) : m_sock(host, port), m_cmd(nullptr) {} public slots: -#define DECLARE_CMD(name) static void name(const QString &host, qint16 port) { Commander cmd(host, port, CMD_##name); } +#define DECLARE_CMD(name) \ + static void name(const QString &host, qint16 port) { Commander cmd(host, port, CMD_##name); } DECLARE_CMD(NEXT) DECLARE_CMD(PREVIOUS) DECLARE_CMD(SHUFFLE) @@ -451,10 +394,9 @@ public slots: } } - static void - PLAY(const QString &host, qint16 port) { + static void PLAY(const QString &host, qint16 port) { std::cout << "Asked a PLAY command" << std::endl; - Status sta(host, port, false); + Status sta(host, port, false); Commander cmd(host, port); connect(&sta, &Status::changeStatus, &cmd, &Commander::handleCorrectPlay); sta.waitForDisconnected(); @@ -466,8 +408,7 @@ signals: }; /* The application */ -class Application final : public QApplication -{ +class Application final : public QApplication { Q_OBJECT private: bool m_exit; @@ -476,23 +417,22 @@ private: QSystemTrayIcon m_tray_icon; QMenu m_menu; - bool m_already_red = false; - bool m_is_connected = false; - QString m_pending_data; + bool m_already_red = false; + bool m_is_connected = false; + QString m_pending_data; - QString m_host = "127.0.0.1"; - qint16 m_port = 6600; - QString m_config_file; + QString m_host = "127.0.0.1"; + qint16 m_port = 6600; + QString m_config_file; - Socket m_sock; + Socket m_sock; - QList<Status *> m_garbage; + QList<Status *> m_garbage; static inline const char *ListenString = "idle player\n"; protected slots: - void - notifyExit(void) { + void notifyExit(void) { garbageCollect(true); if (m_exit) @@ -506,22 +446,23 @@ protected slots: quit(); } - void - disconnected(void) { + void disconnected(void) { if (m_exit || !m_is_connected) return; - sendNotification("Connexion lost", "Connexion to lektord has been lost!", Urgency::CRITICAL); + sendNotification("Connexion lost", "Connexion to lektord has been lost!", + Urgency::CRITICAL); m_pending_data = ""; m_is_connected = false; } - void - reconnect(void) { + void reconnect(void) { Config conf(this, m_config_file); if (conf.isUnix()) { -#if defined (Q_OS_MSDOS) || defined (Q_OS_WIN32) || defined (Q_OS_WINCE) || defined (Q_OS_WIN) || defined (Q_OS_WINRT) - sendNotification("Klkt fatal error", "The 'unix' socket type is not available on your platform", +#if defined(Q_OS_MSDOS) || defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_WIN) || \ + defined(Q_OS_WINRT) + sendNotification("Klkt fatal error", + "The 'unix' socket type is not available on your platform", Urgency::CRITICAL); #endif } @@ -531,17 +472,17 @@ protected slots: m_sock.reset(m_host, m_port); m_sock.doConnect(); if (!m_sock.waitForConnected(50000)) - sendNotification("Klkt not connected", "Connexion to lektord failed", Urgency::CRITICAL); + sendNotification("Klkt not connected", "Connexion to lektord failed", + Urgency::CRITICAL); else m_is_connected = true; } - void - read(void) { + void read(void) { QByteArray got = m_sock.readAll(); m_pending_data = QTextCodec::codecForMib(UTF8_MIB)->toUnicode(got); - if (! m_already_red) { + if (!m_already_red) { m_already_red = true; m_sock.write(ListenString); } @@ -552,30 +493,26 @@ protected slots: } } - void - connected(void) {} + void connected(void) {} private: - void - queryStatus(void) { + void queryStatus(void) { garbageCollect(); Status *ptr_status = new Status(m_host, m_port); - connect(ptr_status, &Status::changeCurrentKara, this, [&](QString kara) { - m_tray_icon.setToolTip(kara); - }); + connect(ptr_status, &Status::changeCurrentKara, this, + [&](QString kara) { m_tray_icon.setToolTip(kara); }); m_garbage.push_back(ptr_status); } - void - garbageCollect(bool force = false) { - std::transform(m_garbage.begin(), m_garbage.end(), - m_garbage.begin(), [&force] (Status * p_sta) -> Status* { - if (force || (p_sta && p_sta->isDeletable())) { - delete p_sta; - return nullptr; - } else - return p_sta; - }); + void garbageCollect(bool force = false) { + std::transform(m_garbage.begin(), m_garbage.end(), m_garbage.begin(), + [&force](Status *p_sta) -> Status * { + if (force || (p_sta && p_sta->isDeletable())) { + delete p_sta; + return nullptr; + } else + return p_sta; + }); /* Should be enaugh to delete all used status sockets */ while (m_garbage.length() > 0 && m_garbage.front() == nullptr) @@ -594,7 +531,10 @@ public: QDir config_dir(m_config_file); if (!config_dir.mkpath(m_config_file)) { sendNotification("Klkt fatal error", - tr("Failed to create the Klkt config dir %1").arg(m_config_file).toStdString().c_str(), + tr("Failed to create the Klkt config dir %1") + .arg(m_config_file) + .toStdString() + .c_str(), Urgency::CRITICAL); ::exit(EXIT_FAILURE); } @@ -602,7 +542,10 @@ public: QFile conf_file(m_config_file); if (!conf_file.open(QIODevice::ReadWrite | QIODevice::Text)) { sendNotification("Klkt fatal error", - tr("Failed to create Klkt config file %1").arg(m_config_file).toStdString().c_str(), + tr("Failed to create Klkt config file %1") + .arg(m_config_file) + .toStdString() + .c_str(), Urgency::CRITICAL); ::exit(EXIT_FAILURE); } @@ -611,10 +554,10 @@ public: { m_menu.addSection("Playback"); - QAction *playback_play = m_menu.addAction(QIcon(":/icons/play.png"), "Play/Pause"); - QAction *playback_next = m_menu.addAction(QIcon(":/icons/next.png"), "Next"); - QAction *playback_prev = m_menu.addAction(QIcon(":/icons/previous.png"), "Previous"); - QAction *playback_shuf = m_menu.addAction(QIcon(":/icons/shuffle.png"), "Shuffle"); + QAction *playback_play = m_menu.addAction(QIcon(":/icons/play.png"), "Play/Pause"); + QAction *playback_next = m_menu.addAction(QIcon(":/icons/next.png"), "Next"); + QAction *playback_prev = m_menu.addAction(QIcon(":/icons/previous.png"), "Previous"); + QAction *playback_shuf = m_menu.addAction(QIcon(":/icons/shuffle.png"), "Shuffle"); m_menu.addSection("System"); QAction *action_reco = m_menu.addAction("Reconnect"); QAction *action_restart = m_menu.addAction("Restart"); @@ -627,38 +570,32 @@ public: playback_next->setIconVisibleInMenu(true); playback_shuf->setIconVisibleInMenu(true); - connect(playback_play, &QAction::triggered, this, [&]() { - Commander::PLAY(m_host, m_port); - }); - connect(playback_next, &QAction::triggered, this, [&]() { - Commander::NEXT(m_host, m_port); - }); - connect(playback_prev, &QAction::triggered, this, [&]() { - Commander::PREVIOUS(m_host, m_port); - }); - connect(playback_shuf, &QAction::triggered, this, [&]() { - Commander::SHUFFLE(m_host, m_port); - }); - - connect(action_quit, &QAction::triggered, this, &Application::notifyExit); - connect(action_reco, &QAction::triggered, this, &Application::reconnect); + connect(playback_play, &QAction::triggered, this, + [&]() { Commander::PLAY(m_host, m_port); }); + connect(playback_next, &QAction::triggered, this, + [&]() { Commander::NEXT(m_host, m_port); }); + connect(playback_prev, &QAction::triggered, this, + [&]() { Commander::PREVIOUS(m_host, m_port); }); + connect(playback_shuf, &QAction::triggered, this, + [&]() { Commander::SHUFFLE(m_host, m_port); }); + + connect(action_quit, &QAction::triggered, this, &Application::notifyExit); + connect(action_reco, &QAction::triggered, this, &Application::reconnect); connect(action_restart, &QAction::triggered, this, &Application::restart); - connect(&m_tray_icon, &QSystemTrayIcon::activated, &m_menu, [&]() { - m_menu.popup(QCursor::pos()); - }); + connect(&m_tray_icon, &QSystemTrayIcon::activated, &m_menu, + [&]() { m_menu.popup(QCursor::pos()); }); } m_tray_icon.show(); - connect(&m_sock, &Socket::connected, this, &Application::connected); + connect(&m_sock, &Socket::connected, this, &Application::connected); connect(&m_sock, &Socket::disconnected, this, &Application::disconnected); - connect(&m_sock, &Socket::readyRead, this, &Application::read); + connect(&m_sock, &Socket::readyRead, this, &Application::read); reconnect(); } - void - restart(void) const { + void restart(void) const { sendNotification("Klkt restart", "Klkt will restart", Urgency::LOW); QStringList args{QApplication::applicationFilePath()}; QProcess::startDetached(args[0], args); diff --git a/src/main/luka.cpp b/src/main/luka.cpp index 48f6d8205593b8e1f3c3bb293306520afedd336a..eef2c8af6d9e46b00dbba4771aff86483331d62c 100644 --- a/src/main/luka.cpp +++ b/src/main/luka.cpp @@ -3,29 +3,31 @@ #include <iostream> -int main() -{ - cli::CmdHandler colorCmd; - cli::CmdHandler nocolorCmd; - +int main() { auto rootMenu = std::make_unique<cli::Menu>("luka"); rootMenu->Insert("toto", [](std::ostream &out) noexcept { out << "This is the toto command for the luka client\n"; }); - rootMenu->Insert("color", [](std::ostream &out) noexcept { - out << "Enabling colors\n"; - cli::SetColor(); - }, "Enable colors in output"); - rootMenu->Insert("nocolor", [](std::ostream &out) noexcept { - out << "Enabling colors\n"; - cli::SetNoColor(); - }, "Disable colors in output"); + rootMenu->Insert( + "color", + [](std::ostream &out) noexcept { + out << "Enabling colors\n"; + cli::SetColor(); + }, + "Enable colors in output"); + rootMenu->Insert( + "nocolor", + [](std::ostream &out) noexcept { + out << "Enabling colors\n"; + cli::SetNoColor(); + }, + "Disable colors in output"); cli::Cli cli(std::move(rootMenu)); - cli.ExitAction([] (auto &out) noexcept { out << "The luka client is quitting!\n"; }); - cli.StdExceptionHandler([](auto& out, const auto& cmd, const std::exception& e) noexcept { - out << "Luka caught an exception while handling the command " - << cmd << " : " << e.what() << "\n"; + cli.ExitAction([](auto &out) noexcept { out << "The luka client is quitting!\n"; }); + cli.StdExceptionHandler([](auto &out, const auto &cmd, const std::exception &e) noexcept { + out << "Luka caught an exception while handling the command " << cmd << " : " << e.what() + << "\n"; }); cli::CliFileSession input(cli); diff --git a/src/main/server.c b/src/main/server.c index 9971c2130cb8177f8a8a31237008c7015f75a9e3..dc5b72a01e24422326bb5e2a3041cbe46471e8d6 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -333,7 +333,7 @@ retry_config: FILE *file_desc = fopen(conf_file, "w+"); FAIL_UNLESS(file_desc, "Failed to open default config file '%s' to initialize it", - conf_file); + conf_file); config_default(file_desc); fclose(file_desc); diff --git a/utils/scripts/astyle.bash b/utils/scripts/style.bash similarity index 61% rename from utils/scripts/astyle.bash rename to utils/scripts/style.bash index ec046c84bf539ebf606c2ac96245eebbeecf6955..acee2671dc7679abf9668671bb15067ee60eb007 100755 --- a/utils/scripts/astyle.bash +++ b/utils/scripts/style.bash @@ -1,5 +1,10 @@ #!/bin/bash +## Clang-Format +find ./src -name '*.cpp' -exec clang-format -i {} \; +find ./src -name '*.hpp' -exec clang-format -i {} \; + +## Astyle OPTIONS=' --style=linux -s4 --pad-oper --pad-header --pad-comma @@ -22,6 +27,6 @@ if [ $# -gt 0 ] && [ "$1" = "--check" ] ; then [ $? -eq 1 ] && exit 0 || exit 1 fi -find ./src ./inc -name '*.c' -exec astyle $OPTIONS --quiet {} \; -find ./src ./inc -name '*.h' -exec astyle $OPTIONS --quiet {} \; -find ./src ./inc -name '*.orig' -exec rm {} \; +find ./src ./inc/lektor -name '*.c' -exec astyle $OPTIONS --quiet {} \; +find ./src ./inc/lektor -name '*.h' -exec astyle $OPTIONS --quiet {} \; +find ./src ./inc/lektor -name '*.orig' -exec rm {} \;