Commit 3ff35903 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 14c23ed5
...@@ -23,21 +23,21 @@ ...@@ -23,21 +23,21 @@
#include "kwrited.h" #include "kwrited.h"
#include <QDebug> #include <QDebug>
#include <kaboutdata.h>
#include <klocalizedstring.h>
#include <knotification.h>
#include <kptydevice.h> #include <kptydevice.h>
#include <kuser.h> #include <kuser.h>
#include <knotification.h>
#include <klocalizedstring.h>
#include <kaboutdata.h>
#if defined(BUILD_AS_EXECUTABLE) #if defined(BUILD_AS_EXECUTABLE)
# include <QGuiApplication> #include <QGuiApplication>
# include <QSessionManager> #include <QSessionManager>
# include <signal.h> #include <signal.h>
# include <sys/types.h> #include <sys/types.h>
# include <unistd.h> #include <unistd.h>
#else #else
# include <kpluginfactory.h> #include <kpluginfactory.h>
# include <kpluginloader.h> #include <kpluginloader.h>
#endif #endif
static inline KAboutData aboutData() static inline KAboutData aboutData()
...@@ -58,13 +58,13 @@ static void sigterm_handler(int signal) ...@@ -58,13 +58,13 @@ static void sigterm_handler(int signal)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
//drop elevated privileges temporarily // drop elevated privileges temporarily
original_euid = geteuid(); original_euid = geteuid();
original_egid = getegid(); original_egid = getegid();
seteuid(getuid()); seteuid(getuid());
setegid(getgid()); setegid(getgid());
//install a signal handler to exit gracefully // install a signal handler to exit gracefully
//(so that pty->logout() is called in ~KWrited()) //(so that pty->logout() is called in ~KWrited())
signal(SIGTERM, sigterm_handler); signal(SIGTERM, sigterm_handler);
signal(SIGINT, sigterm_handler); signal(SIGINT, sigterm_handler);
...@@ -75,7 +75,7 @@ int main(int argc, char **argv) ...@@ -75,7 +75,7 @@ int main(int argc, char **argv)
KAboutData::setApplicationData(aboutData()); KAboutData::setApplicationData(aboutData());
QGuiApplication::setFallbackSessionManagementEnabled(false); QGuiApplication::setFallbackSessionManagementEnabled(false);
auto disableSessionManagement = [](QSessionManager &sm) { auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever); sm.setRestartHint(QSessionManager::RestartNever);
}; };
QObject::connect(&a, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&a, &QGuiApplication::commitDataRequest, disableSessionManagement);
QObject::connect(&a, &QGuiApplication::saveStateRequest, disableSessionManagement); QObject::connect(&a, &QGuiApplication::saveStateRequest, disableSessionManagement);
...@@ -86,7 +86,7 @@ int main(int argc, char **argv) ...@@ -86,7 +86,7 @@ int main(int argc, char **argv)
#else // BUILD_AS_EXECUTABLE #else // BUILD_AS_EXECUTABLE
KWritedModule::KWritedModule(QObject* parent, const QList<QVariant>&) KWritedModule::KWritedModule(QObject *parent, const QList<QVariant> &)
: KDEDModule(parent) : KDEDModule(parent)
{ {
pro = new KWrited; pro = new KWrited;
...@@ -97,52 +97,49 @@ KWritedModule::~KWritedModule() ...@@ -97,52 +97,49 @@ KWritedModule::~KWritedModule()
delete pro; delete pro;
} }
K_PLUGIN_FACTORY_WITH_JSON(KWritedFactory, K_PLUGIN_FACTORY_WITH_JSON(KWritedFactory, "kwrited.json", registerPlugin<KWritedModule>();)
"kwrited.json",
registerPlugin<KWritedModule>();
)
#endif //BUILD_AS_EXECUTABLE #endif // BUILD_AS_EXECUTABLE
KWrited::KWrited()
KWrited::KWrited() : QObject() : QObject()
{ {
pty = new KPtyDevice(); pty = new KPtyDevice();
pty->open(); pty->open();
#if defined(BUILD_AS_EXECUTABLE) #if defined(BUILD_AS_EXECUTABLE)
dup2(pty->slaveFd(), 0); //HACK: login() from glibc requires this to login correctly dup2(pty->slaveFd(), 0); // HACK: login() from glibc requires this to login correctly
//restore elevated privileges // restore elevated privileges
seteuid(original_euid); seteuid(original_euid);
setegid(original_egid); setegid(original_egid);
#endif #endif
pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY").constData()); pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY").constData());
#if defined(BUILD_AS_EXECUTABLE) #if defined(BUILD_AS_EXECUTABLE)
//drop privileges again // drop privileges again
seteuid(getuid()); seteuid(getuid());
setegid(getgid()); setegid(getgid());
#endif #endif
connect(pty, &QIODevice::readyRead, this, &KWrited::block_in); connect(pty, &QIODevice::readyRead, this, &KWrited::block_in);
//qDebug() << "listening on device" << pty->ttyName(); // qDebug() << "listening on device" << pty->ttyName();
} }
KWrited::~KWrited() KWrited::~KWrited()
{ {
#if defined(BUILD_AS_EXECUTABLE) #if defined(BUILD_AS_EXECUTABLE)
//restore elevated privileges // restore elevated privileges
seteuid(original_euid); seteuid(original_euid);
setegid(original_egid); setegid(original_egid);
#endif #endif
pty->logout(); pty->logout();
#if defined(BUILD_AS_EXECUTABLE) #if defined(BUILD_AS_EXECUTABLE)
//drop privileges again // drop privileges again
seteuid(getuid()); seteuid(getuid());
setegid(getgid()); setegid(getgid());
#endif #endif
delete pty; delete pty;
...@@ -150,20 +147,20 @@ KWrited::~KWrited() ...@@ -150,20 +147,20 @@ KWrited::~KWrited()
void KWrited::block_in() void KWrited::block_in()
{ {
QByteArray buf = pty->readAll(); QByteArray buf = pty->readAll();
QString msg = QString::fromLocal8Bit( buf.constData(), buf.size() ); QString msg = QString::fromLocal8Bit(buf.constData(), buf.size());
msg.remove(QLatin1Char('\r')); msg.remove(QLatin1Char('\r'));
msg.remove(QLatin1Char('\a')); msg.remove(QLatin1Char('\a'));
msg = msg.trimmed(); msg = msg.trimmed();
KNotification *notification = new KNotification(QStringLiteral("NewMessage"), KNotification::Persistent); KNotification *notification = new KNotification(QStringLiteral("NewMessage"), KNotification::Persistent);
#if !defined(BUILD_AS_EXECUTABLE) #if !defined(BUILD_AS_EXECUTABLE)
notification->setComponentName( QStringLiteral("kwrited") ); notification->setComponentName(QStringLiteral("kwrited"));
#endif #endif
notification->setText( msg ); notification->setText(msg);
notification->setFlags( KNotification::SkipGrouping ); notification->setFlags(KNotification::SkipGrouping);
connect(notification, &KNotification::closed, notification, &QObject::deleteLater ); connect(notification, &KNotification::closed, notification, &QObject::deleteLater);
notification->sendEvent(); notification->sendEvent();
} }
#if !defined(BUILD_AS_EXECUTABLE) #if !defined(BUILD_AS_EXECUTABLE)
......
...@@ -22,34 +22,35 @@ ...@@ -22,34 +22,35 @@
#ifndef KWRITED_H #ifndef KWRITED_H
#define KWRITED_H #define KWRITED_H
#include <config-kwrited.h>
#include <QObject> #include <QObject>
#include <config-kwrited.h>
class KPtyDevice; class KPtyDevice;
class KWrited : public QObject class KWrited : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
KWrited(); KWrited();
~KWrited() override; ~KWrited() override;
private Q_SLOTS: private Q_SLOTS:
void block_in(); void block_in();
private: private:
KPtyDevice* pty; KPtyDevice *pty;
}; };
#if !defined(BUILD_AS_EXECUTABLE) #if !defined(BUILD_AS_EXECUTABLE)
# include <kdedmodule.h> #include <kdedmodule.h>
class KWritedModule : public KDEDModule class KWritedModule : public KDEDModule
{ {
public: public:
KWritedModule(QObject* parent, const QList<QVariant>&); KWritedModule(QObject *parent, const QList<QVariant> &);
~KWritedModule() override; ~KWritedModule() override;
private: private:
KWrited* pro; KWrited *pro;
}; };
#endif #endif
......
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