Commit be4b7559 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

run git clang-format

parent 18f9550c
......@@ -37,16 +37,20 @@ public:
};
Core::Private::Private(Core *qq)
: q(qq), mLastDate(QDate::currentDate())
: q(qq)
, mLastDate(QDate::currentDate())
{
}
//@endcond
Core::Core(QWidget *parent, Qt::WindowFlags f)
: KParts::MainWindow(parent, f), d(new Private(this))
: KParts::MainWindow(parent, f)
, d(new Private(this))
{
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this]() { d->checkNewDay(); });
connect(timer, &QTimer::timeout, this, [this]() {
d->checkNewDay();
});
timer->start(1000 * 60);
}
......@@ -77,8 +81,9 @@ KParts::Part *Core::createPart(const char *libname)
if (part) {
d->mParts.insert(libname, part);
QObject::connect(part, &KParts::Part::destroyed,
this, [this](QObject* obj) { d->slotPartDestroyed(obj);});
QObject::connect(part, &KParts::Part::destroyed, this, [this](QObject *obj) {
d->slotPartDestroyed(obj);
});
} else {
d->lastErrorMessage = loader.errorString();
qCWarning(KONTACTINTERFACE_LOG) << d->lastErrorMessage;
......
......@@ -17,7 +17,6 @@
namespace KontactInterface
{
class Plugin;
/**
......@@ -104,4 +103,3 @@ private:
}
#endif
......@@ -5,27 +5,27 @@
SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "config-kontactinterface.h"
#include "pimuniqueapplication.h"
#include "config-kontactinterface.h"
#include "kontactinterface_debug.h"
#include <KAboutData>
#include <KStartupInfo>
#include <KWindowSystem>
#include <KAboutData>
#include <QCommandLineParser>
#include <QDir>
#include <QWidget>
#include <QMainWindow>
#include <QWidget>
#include <QDBusInterface>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
using namespace KontactInterface;
namespace {
namespace
{
const char kChromiumFlagsEnv[] = "QTWEBENGINE_CHROMIUM_FLAGS";
const char kDisableInProcessStackTraces[] = "--disable-in-process-stack-traces";
......@@ -37,7 +37,8 @@ class Q_DECL_HIDDEN KontactInterface::PimUniqueApplication::Private
public:
Private()
: cmdArgs(new QCommandLineParser())
{}
{
}
~Private()
{
......@@ -79,25 +80,18 @@ void PimUniqueApplication::setAboutData(KAboutData &aboutData)
aboutData.setupCommandLine(d->cmdArgs);
// This object name is used in start(), and also in kontact's UniqueAppHandler.
const QString objectName = QLatin1Char('/') + QApplication::applicationName() + QLatin1String("_PimApplication");
QDBusConnection::sessionBus().registerObject(
objectName, this,
QDBusConnection::ExportScriptableSlots |
QDBusConnection::ExportScriptableProperties |
QDBusConnection::ExportAdaptors);
QDBusConnection::sessionBus().registerObject(objectName,
this,
QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableProperties
| QDBusConnection::ExportAdaptors);
}
static bool callNewInstance(const QString &appName, const QString &serviceName, const QByteArray &asn_id, const QStringList &arguments)
{
const QString objectName = QLatin1Char('/') + appName + QLatin1String("_PimApplication");
QDBusInterface iface(serviceName,
objectName,
QStringLiteral("org.kde.PIMUniqueApplication"),
QDBusConnection::sessionBus());
QDBusInterface iface(serviceName, objectName, QStringLiteral("org.kde.PIMUniqueApplication"), QDBusConnection::sessionBus());
if (iface.isValid()) {
QDBusReply<int> reply = iface.call(QStringLiteral("newInstance"),
asn_id,
arguments,
QDir::currentPath());
QDBusReply<int> reply = iface.call(QStringLiteral("newInstance"), asn_id, arguments, QDir::currentPath());
if (reply.isValid()) {
return true;
}
......@@ -110,7 +104,6 @@ int PimUniqueApplication::newInstance()
return newInstance(KStartupInfo::startupId(), QStringList() << QApplication::applicationName(), QDir::currentPath());
}
bool PimUniqueApplication::start(const QStringList &arguments)
{
const QString appName = QApplication::applicationName();
......@@ -137,7 +130,7 @@ bool PimUniqueApplication::start(const QStringList &arguments)
KWindowSystem::allowExternalProcessWindowActivation();
if (callNewInstance(appName, serviceName, new_asn_id, arguments)) {
return false; // success means that main() can exit now.
return false; // success means that main() can exit now.
}
}
......@@ -155,19 +148,16 @@ bool PimUniqueApplication::start(const QStringList &arguments)
bool PimUniqueApplication::activateApplication(const QString &appName, const QStringList &additionalArguments)
{
const QString serviceName = QLatin1String("org.kde.") + appName;
QStringList arguments{ appName };
QStringList arguments{appName};
arguments += additionalArguments;
// Start it standalone if not already running (if kontact is running, then this will do nothing)
QDBusConnection::sessionBus().interface()->startService(serviceName);
return callNewInstance(appName, serviceName, KStartupInfo::createNewStartupId(), arguments);
}
// This is called via DBus either by another instance that has just been
// started or by Kontact when the module is activated
int PimUniqueApplication::newInstance(const QByteArray &startupId,
const QStringList &arguments,
const QString &workingDirectory)
int PimUniqueApplication::newInstance(const QByteArray &startupId, const QStringList &arguments, const QString &workingDirectory)
{
KStartupInfo::setStartupId(startupId);
......@@ -194,4 +184,3 @@ int PimUniqueApplication::activate(const QStringList &arguments, const QString &
Q_UNUSED(workingDirectory)
return 0;
}
......@@ -16,7 +16,6 @@ class QCommandLineParser;
namespace KontactInterface
{
/**
* KDEPIM applications which can be integrated into kontact should use
* PimUniqueApplication instead of QApplication + Dbus unique.
......@@ -26,7 +25,6 @@ namespace KontactInterface
*/
class KONTACTINTERFACE_EXPORT PimUniqueApplication : public QApplication
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.PIMUniqueApplication")
......@@ -46,8 +44,7 @@ public:
/**
* Ensure that another PIM application is running.
*/
static bool activateApplication(const QString &application,
const QStringList &additionalArguments = {});
static bool activateApplication(const QString &application, const QStringList &additionalArguments = {});
Q_REQUIRED_RESULT QCommandLineParser *cmdArgs() const;
......
......@@ -9,20 +9,20 @@
#include "plugin.h"
#include "core.h"
#include "processes.h"
#include "kontactinterface_debug.h"
#include "processes.h"
#include <KXMLGUIFactory>
#include <KAboutData>
#include <KIO/CommandLauncherJob>
#include <KXMLGUIFactory>
#include <QDBusConnection>
#include <QDir>
#include <QDomDocument>
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>
#include <QCoreApplication>
#include <QStandardPaths>
using namespace KontactInterface;
......@@ -34,7 +34,6 @@ using namespace KontactInterface;
class Q_DECL_HIDDEN Plugin::Private
{
public:
void partDestroyed();
void setXmlFiles();
void removeInvisibleToolbarActions(Plugin *plugin);
......@@ -56,7 +55,9 @@ public:
//@endcond
Plugin::Plugin(Core *core, QObject *parent, const char *appName, const char *pluginName)
: KXMLGUIClient(core), QObject(parent), d(new Private)
: KXMLGUIClient(core)
, QObject(parent)
, d(new Private)
{
setObjectName(QLatin1String(appName));
core->factory()->addClient(this);
......@@ -139,7 +140,9 @@ KParts::Part *Plugin::part()
if (!d->part) {
d->part = createPart();
if (d->part) {
connect(d->part, &KParts::Part::destroyed, this, [this]() { d->partDestroyed(); });
connect(d->part, &KParts::Part::destroyed, this, [this]() {
d->partDestroyed();
});
d->removeInvisibleToolbarActions(this);
core()->partLoaded(this, d->part);
}
......@@ -247,21 +250,20 @@ void Plugin::Private::removeInvisibleToolbarActions(Plugin *plugin)
// solutions work visually, but only modifying the XML ensures that the
// actions don't appear in "edit toolbars". #207296
const QStringList hideActions = plugin->invisibleToolbarActions();
//qCDebug(KONTACTINTERFACE_LOG) << "Hiding actions" << hideActions << "from" << pluginName << part;
// qCDebug(KONTACTINTERFACE_LOG) << "Hiding actions" << hideActions << "from" << pluginName << part;
QDomDocument doc = part->domDocument();
QDomElement docElem = doc.documentElement();
// 1. Iterate over containers
for (QDomElement containerElem = docElem.firstChildElement();
!containerElem.isNull(); containerElem = containerElem.nextSiblingElement()) {
for (QDomElement containerElem = docElem.firstChildElement(); !containerElem.isNull(); containerElem = containerElem.nextSiblingElement()) {
if (QString::compare(containerElem.tagName(), QLatin1String("ToolBar"), Qt::CaseInsensitive) == 0) {
// 2. Iterate over actions in toolbars
QDomElement actionElem = containerElem.firstChildElement();
while (!actionElem.isNull()) {
QDomElement nextActionElem = actionElem.nextSiblingElement();
if (QString::compare(actionElem.tagName(), QLatin1String("Action"), Qt::CaseInsensitive) == 0) {
//qCDebug(KONTACTINTERFACE_LOG) << "Looking at action" << actionElem.attribute("name");
// qCDebug(KONTACTINTERFACE_LOG) << "Looking at action" << actionElem.attribute("name");
if (hideActions.contains(actionElem.attribute(QStringLiteral("name")))) {
//qCDebug(KONTACTINTERFACE_LOG) << "REMOVING";
// qCDebug(KONTACTINTERFACE_LOG) << "REMOVING";
containerElem.removeChild(actionElem);
}
}
......@@ -276,8 +278,8 @@ void Plugin::Private::removeInvisibleToolbarActions(Plugin *plugin)
// the fast kdeui code for that rather than a full QDomDocument.
// (*) or when invisibleToolbarActions() changes :)
const QString newAppFile =
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/default-") + QLatin1String(pluginName) + QLatin1String(".rc");
const QString newAppFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/default-")
+ QLatin1String(pluginName) + QLatin1String(".rc");
QFileInfo fileInfo(newAppFile);
QDir().mkpath(fileInfo.absolutePath());
......@@ -297,10 +299,10 @@ void Plugin::Private::setXmlFiles()
if (pluginName.isEmpty()) {
return;
}
const QString newAppFile =
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/default-") + QLatin1String(pluginName) + QLatin1String(".rc");
const QString localFile =
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/local-") + QLatin1String(pluginName) + QLatin1String(".rc");
const QString newAppFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/default-")
+ QLatin1String(pluginName) + QLatin1String(".rc");
const QString localFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kontact/local-")
+ QLatin1String(pluginName) + QLatin1String(".rc");
if (!localFile.isEmpty() && !newAppFile.isEmpty()) {
if (part->xmlFile() != newAppFile || part->localXMLFile() != localFile) {
part->replaceXMLFile(newAppFile, localFile);
......@@ -364,8 +366,7 @@ void Plugin::shortcutChanged()
void Plugin::virtual_hook(int, void *)
{
//BASE::virtual_hook( id, data );
// BASE::virtual_hook( id, data );
}
#include "moc_plugin.cpp"
......@@ -40,35 +40,36 @@ class Part;
/**
Exports Kontact plugin. Deprecated in favour of EXPORT_KONTACT_PLUGIN_WITH_JSON
*/
#define EXPORT_KONTACT_PLUGIN( pluginclass, pluginname ) \
class Instance \
{ \
public: \
static QObject *createInstance( QWidget *, QObject *parent, const QVariantList &list ) \
{ return new pluginclass( static_cast<KontactInterface::Core*>( parent ), list ); } \
}; \
K_PLUGIN_FACTORY( KontactPluginFactory, registerPlugin< pluginclass > \
( QString(), Instance::createInstance ); )
#define EXPORT_KONTACT_PLUGIN(pluginclass, pluginname) \
class Instance \
{ \
public: \
static QObject *createInstance(QWidget *, QObject *parent, const QVariantList &list) \
{ \
return new pluginclass(static_cast<KontactInterface::Core *>(parent), list); \
} \
}; \
K_PLUGIN_FACTORY(KontactPluginFactory, registerPlugin<pluginclass>(QString(), Instance::createInstance);)
/**
Exports Kontact plugin.
@param pluginclass the class to instanciate (must derive from KontactInterface::Plugin
@param jsonFile filename of the JSON file, generated from a .desktop file
*/
#define EXPORT_KONTACT_PLUGIN_WITH_JSON( pluginclass, jsonFile ) \
class Instance \
{ \
public: \
static QObject *createInstance( QWidget *, QObject *parent, const QVariantList &list ) \
{ return new pluginclass( static_cast<KontactInterface::Core*>( parent ), list ); } \
}; \
K_PLUGIN_FACTORY_WITH_JSON( KontactPluginFactory, jsonFile, registerPlugin< pluginclass > \
( QString(), Instance::createInstance ); ) \
#define EXPORT_KONTACT_PLUGIN_WITH_JSON(pluginclass, jsonFile) \
class Instance \
{ \
public: \
static QObject *createInstance(QWidget *, QObject *parent, const QVariantList &list) \
{ \
return new pluginclass(static_cast<KontactInterface::Core *>(parent), list); \
} \
}; \
K_PLUGIN_FACTORY_WITH_JSON(KontactPluginFactory, jsonFile, registerPlugin<pluginclass>(QString(), Instance::createInstance);) \
K_EXPORT_PLUGIN_VERSION(KONTACT_PLUGIN_VERSION)
namespace KontactInterface
{
class Core;
class Summary;
/**
......
......@@ -14,22 +14,22 @@
@author Jarosław Staniek \<staniek@kde.org\>
*/
//krazy:excludeall=captruefalse,null
// krazy:excludeall=captruefalse,null
#include "processes.h"
using namespace KontactInterface;
#ifdef Q_OS_WIN
#include <windows.h>
#include <tlhelp32.h>
#include <psapi.h>
#include <signal.h>
#include <tlhelp32.h>
#include <windows.h>
#include <QtDebug>
#include <QCoreApplication>
#include "kontactinterface_debug.h"
#include <QCoreApplication>
// Copy from kdelibs/kinit/kinit_win.cpp
PSID copySid(PSID from)
......@@ -39,7 +39,7 @@ PSID copySid(PSID from)
}
int sidLength = GetLengthSid(from);
PSID to = (PSID) malloc(sidLength);
PSID to = (PSID)malloc(sidLength);
CopySid(sidLength, to, from);
return to;
}
......@@ -63,7 +63,7 @@ static PSID getProcessOwner(HANDLE hProcess)
sid = copySid(userStruct->User.Sid);
CloseHandle(hToken);
delete [] userStruct;
delete[] userStruct;
return sid;
}
}
......@@ -73,11 +73,7 @@ static PSID getProcessOwner(HANDLE hProcess)
// Copy from kdelibs/kinit/kinit_win.cpp
static HANDLE getProcessHandle(int processID)
{
return OpenProcess(SYNCHRONIZE |
PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ |
PROCESS_TERMINATE,
false, processID);
return OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, false, processID);
}
void KontactInterface::getProcessesIdForName(const QString &processName, QList<int> &pids)
......@@ -90,7 +86,7 @@ void KontactInterface::getProcessesIdForName(const QString &processName, QList<i
return;
}
pe32.dwSize = sizeof(PROCESSENTRY32); // Necessary according to MSDN
pe32.dwSize = sizeof(PROCESSENTRY32); // Necessary according to MSDN
if (!Process32First(h, &pe32)) {
return;
}
......@@ -128,7 +124,7 @@ bool KontactInterface::otherProcessesExist(const QString &processName)
int myPid = QCoreApplication::applicationPid();
for (int pid : qAsConst(pids)) {
if (myPid != pid) {
//qCDebug(KONTACTINTERFACE_LOG) << "Process ID is " << pid;
// qCDebug(KONTACTINTERFACE_LOG) << "Process ID is " << pid;
return true;
}
}
......@@ -163,7 +159,10 @@ bool KontactInterface::killProcesses(const QString &processName)
}
struct EnumWindowsStruct {
EnumWindowsStruct() : windowId(0) {}
EnumWindowsStruct()
: windowId(0)
{
}
int pid;
HWND windowId;
};
......@@ -171,7 +170,6 @@ struct EnumWindowsStruct {
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) {
DWORD pidwin;
GetWindowThreadProcessId(hwnd, &pidwin);
......
......@@ -27,7 +27,6 @@ class QString;
namespace KontactInterface
{
#ifdef Q_OS_WIN
/**
* Sets @a pids to a list of processes having name @a processName.
......@@ -58,4 +57,3 @@ KONTACTINTERFACE_EXPORT void activateWindowForProcess(const QString &executableN
}
#endif
......@@ -9,19 +9,19 @@
#include "summary.h"
#include <QFont>
#include <QLabel>
#include <QDrag>
#include <QPainter>
#include <QPixmap>
#include <QMouseEvent>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QDropEvent>
#include <QFont>
#include <QFontDatabase>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QMimeData>
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QStyle>
#include <QFontDatabase>
using namespace KontactInterface;
......@@ -49,7 +49,8 @@ public:
//@endcond
Summary::Summary(QWidget *parent)
: QWidget(parent), d(new Private)
: QWidget(parent)
, d(new Private)
{
setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
setAcceptDrops(true);
......@@ -114,17 +115,14 @@ void Summary::mousePressEvent(QMouseEvent *event)
void Summary::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) &&
(event->pos() - d->mDragStartPoint).manhattanLength() > 4) {
if ((event->buttons() & Qt::LeftButton) && (event->pos() - d->mDragStartPoint).manhattanLength() > 4) {
QDrag *drag = new QDrag(this);
drag->setMimeData(new SummaryMimeData());
drag->setObjectName(QStringLiteral("SummaryWidgetDrag"));
QPixmap pm = grab();
if (pm.width() > 300) {
pm = QPixmap::fromImage(
pm.toImage().scaled(300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation));
pm = QPixmap::fromImage(pm.toImage().scaled(300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
QPainter painter;
......
......@@ -18,7 +18,6 @@ class QDropEvent;
namespace KontactInterface
{
/**
* @short Base class for summary widgets in Kontact.
*
......
......@@ -20,9 +20,8 @@
#include <QCommandLineParser>
#ifdef Q_OS_WIN
# include <process.h>
#include <process.h>
#endif
/*
......@@ -74,7 +73,8 @@ public:
//@endcond
UniqueAppHandler::UniqueAppHandler(Plugin *plugin)
: QObject(plugin), d(new Private)
: QObject(plugin)
, d(new Private)
{
qCDebug(KONTACTINTERFACE_LOG) << "plugin->objectName():" << plugin->objectName();
......@@ -151,17 +151,17 @@ public:
//@endcond
UniqueAppWatcher::UniqueAppWatcher(UniqueAppHandlerFactoryBase *factory, Plugin *plugin)
: QObject(plugin), d(new Private)
: QObject(plugin)
, d(new Private)
{
d->mFactory = factory;
d->mPlugin = plugin;
// The app is running standalone if 1) that name is known to D-Bus
const QString serviceName = QLatin1String("org.kde.") + plugin->objectName();
//Needed for wince build
// Needed for wince build
#undef interface
d->mRunningStandalone =
QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName);
d->mRunningStandalone = QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName);
#ifdef Q_OS_WIN
if (d->mRunningStandalone) {
QList<int> pids;
......@@ -185,13 +185,13 @@ UniqueAppWatcher::UniqueAppWatcher(UniqueAppHandlerFactoryBase *factory, Plugin
d->mRunningStandalone = false;
}
qCDebug(KONTACTINTERFACE_LOG) << " plugin->objectName()=" << plugin->objectName()
<< " running standalone:" << d->mRunningStandalone;
qCDebug(KONTACTINTERFACE_LOG) << " plugin->objectName()=" << plugin->objectName() << " running standalone:" << d->mRunningStandalone;
if (d->mRunningStandalone) {
QObject::connect(QDBusConnection::sessionBus().interface(),
&QDBusConnectionInterface::serviceOwnerChanged,
this, &UniqueAppWatcher::slotApplicationRemoved);
this,
&UniqueAppWatcher::slotApplicationRemoved);
} else {
d->mFactory->createHandler(d->mPlugin);
}
......@@ -208,9 +208,7 @@ bool UniqueAppWatcher::isRunningStandalone() const
return d->mRunningStandalone;
}
void KontactInterface::UniqueAppWatcher::slotApplicationRemoved(const QString &name,
const QString &oldOwner,
const QString &newOwner)
void KontactInterface::UniqueAppWatcher::slotApplicationRemoved(const QString &name, const QString &oldOwner, const QString &newOwner)
{
if (oldOwner.isEmpty() || !newOwner.isEmpty()) {
return;
......@@ -232,4 +230,3 @@ QWidget *KontactInterface::UniqueAppHandler::mainWidget()
{
return s_mainWidget;
}
......@@ -16,7 +16,6 @@ class QCommandLineParser;
namespace KontactInterface
{
/**
* D-Bus Object that has the name of the standalone application (e.g. "kmail")
* and implements newInstance() so that running the separate application does
......@@ -67,7 +66,9 @@ private:
class UniqueAppHandlerFactoryBase
{
public:
virtual ~UniqueAppHandlerFactoryBase() {}
virtual ~UniqueAppHandlerFactoryBase()
{
}
virtual UniqueAppHandler *createHandler(Plugin *) = 0;
};
......@@ -77,10 +78,11 @@ public:
* The template argument is the UniqueAppHandler-derived class.
* This allows to remove the need to subclass UniqueAppWatcher.
*/
template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase