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