Commit 0810ac5b 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 c39d7ba5
......@@ -13,7 +13,6 @@
#include "triggers/gestures.h"
#include <QDebug>
#include <kglobalaccel.h>
#include <kpluginfactory.h>
......@@ -23,171 +22,146 @@
#define COMPONENT_NAME "khotkeys"
K_PLUGIN_FACTORY_WITH_JSON(KHotKeysModuleFactory,
"khotkeys.json",
registerPlugin<KHotKeysModule>();)
K_PLUGIN_FACTORY_WITH_JSON(KHotKeysModuleFactory, "khotkeys.json", registerPlugin<KHotKeysModule>();)
using namespace KHotKeys;
// KhotKeysModule
KHotKeysModule::KHotKeysModule(QObject* parent, const QList<QVariant>&)
KHotKeysModule::KHotKeysModule(QObject *parent, const QList<QVariant> &)
: KDEDModule(parent)
, actions_root(nullptr)
, _settingsDirty(false)
, _settings()
,_initialized(false)
{
, _initialized(false)
{
// initialize
qDebug() << "Installing the delayed initialization callback.";
QMetaObject::invokeMethod( this, "initialize", Qt::QueuedConnection);
}
QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection);
}
void KHotKeysModule::initialize()
{
if (_initialized)
{
{
if (_initialized) {
return;
}
}
qDebug() << "Delayed initialization.";
_initialized = true;
// Initialize the global data, grab keys
KHotKeys::init_global_data( true, this );
KHotKeys::init_global_data(true, this);
// If a shortcut was changed (global shortcuts kcm), save
connect(
keyboard_handler.data(), SIGNAL(shortcutChanged()),
this, SLOT(scheduleSave()));
connect(keyboard_handler.data(), SIGNAL(shortcutChanged()), this, SLOT(scheduleSave()));
// Read the configuration from file khotkeysrc
reread_configuration();
KGlobalAccel::cleanComponent(COMPONENT_NAME);
if (_settings.update())
{
if (_settings.update()) {
save();
}
}
}
KHotKeysModule::~KHotKeysModule()
{
{
// actions_root belongs to _settings.
actions_root = nullptr;
}
}
void KHotKeysModule::reread_configuration()
{
{
qDebug() << "Reloading the khotkeys configuration";
// Stop listening
actions_root = nullptr; // Disables the dbus interface effectively
KHotKeys::khotkeys_set_active( false );
KHotKeys::khotkeys_set_active(false);
// Load the settings
_settings.reread_settings(true);
KHotKeys::gesture_handler->set_mouse_button( _settings.gestureMouseButton() );
KHotKeys::gesture_handler->set_timeout( _settings.gestureTimeOut() );
KHotKeys::gesture_handler->set_mouse_button(_settings.gestureMouseButton());
KHotKeys::gesture_handler->set_timeout(_settings.gestureTimeOut());
qDebug() << _settings.areGesturesDisabled();
KHotKeys::gesture_handler->enable( !_settings.areGesturesDisabled() );
KHotKeys::gesture_handler->set_exclude( _settings.gesturesExclude() );
KHotKeys::gesture_handler->enable(!_settings.areGesturesDisabled());
KHotKeys::gesture_handler->set_exclude(_settings.gesturesExclude());
// FIXME: SOUND
// KHotKeys::voice_handler->set_shortcut( _settings.voice_shortcut );
actions_root = _settings.actions();
KHotKeys::khotkeys_set_active( true );
}
KHotKeys::khotkeys_set_active(true);
}
SimpleActionData* KHotKeysModule::menuentry_action(const QString &storageId)
{
ActionDataGroup *menuentries = _settings.get_system_group(
ActionDataGroup::SYSTEM_MENUENTRIES);
SimpleActionData *KHotKeysModule::menuentry_action(const QString &storageId)
{
ActionDataGroup *menuentries = _settings.get_system_group(ActionDataGroup::SYSTEM_MENUENTRIES);
// Now try to find the action
Q_FOREACH(ActionDataBase* element, menuentries->children())
{
SimpleActionData *actionData = dynamic_cast<SimpleActionData*>(element);
if (actionData && actionData->action())
{
MenuEntryAction *action = dynamic_cast<MenuEntryAction*>(actionData->action());
if (action && action->service() && (action->service()->storageId() == storageId))
{
Q_FOREACH (ActionDataBase *element, menuentries->children()) {
SimpleActionData *actionData = dynamic_cast<SimpleActionData *>(element);
if (actionData && actionData->action()) {
MenuEntryAction *action = dynamic_cast<MenuEntryAction *>(actionData->action());
if (action && action->service() && (action->service()->storageId() == storageId)) {
return actionData;
}
}
}
return nullptr;
}
return nullptr;
}
QString KHotKeysModule::get_menuentry_shortcut(const QString &storageId)
{
SimpleActionData* actionData = menuentry_action(storageId);
{
SimpleActionData *actionData = menuentry_action(storageId);
// No action found
if (actionData == nullptr) return "";
if (actionData == nullptr)
return "";
// The action must have a shortcut trigger. but don't assume to much
ShortcutTrigger* shortcutTrigger = dynamic_cast<ShortcutTrigger*>(actionData->trigger());
ShortcutTrigger *shortcutTrigger = dynamic_cast<ShortcutTrigger *>(actionData->trigger());
Q_ASSERT(shortcutTrigger);
if (shortcutTrigger == nullptr) return "";
if (shortcutTrigger == nullptr)
return "";
qDebug() << shortcutTrigger->primaryShortcut();
return shortcutTrigger->primaryShortcut();
}
}
QString KHotKeysModule::register_menuentry_shortcut(
const QString &storageId,
const QString &sequence)
{
QString KHotKeysModule::register_menuentry_shortcut(const QString &storageId, const QString &sequence)
{
qDebug() << storageId << "(" << sequence << ")";
// Check the service we got. If it is invalid there is no need to
// continue.
KService::Ptr wantedService = KService::serviceByStorageId(storageId);
if (!wantedService)
{
if (!wantedService) {
qCritical() << "Storage Id " << storageId << "not valid";
return "";
}
}
// Look for the action
SimpleActionData* actionData = menuentry_action(storageId);
SimpleActionData *actionData = menuentry_action(storageId);
// No action found. Create on if sequence is != ""
if (actionData == nullptr)
{
if (actionData == nullptr) {
qDebug() << "No action found";
// If the sequence is empty there is no need to create a action.
if (sequence.isEmpty()) return "";
if (sequence.isEmpty())
return "";
qDebug() << "Creating a new action";
// Create the action
ActionDataGroup *menuentries = _settings.get_system_group(
ActionDataGroup::SYSTEM_MENUENTRIES);
ActionDataGroup *menuentries = _settings.get_system_group(ActionDataGroup::SYSTEM_MENUENTRIES);
MenuEntryShortcutActionData *newAction = new MenuEntryShortcutActionData(
menuentries,
wantedService->name(),
storageId,
QKeySequence(sequence),
storageId);
MenuEntryShortcutActionData *newAction =
new MenuEntryShortcutActionData(menuentries, wantedService->name(), storageId, QKeySequence(sequence), storageId);
newAction->enable();
......@@ -195,26 +169,22 @@ QString KHotKeysModule::register_menuentry_shortcut(
// Return the real shortcut
return newAction->trigger()->primaryShortcut();
}
}
// We found a action
else
{
if (sequence.isEmpty())
{
else {
if (sequence.isEmpty()) {
qDebug() << "Deleting the action";
actionData->aboutToBeErased();
delete actionData;
_settings.write();
return "";
}
else
{
} else {
qDebug() << "Changing the action";
// The action must have a shortcut trigger. but don't assume to much
ShortcutTrigger* shortcutTrigger =
dynamic_cast<ShortcutTrigger*>(actionData->trigger());
ShortcutTrigger *shortcutTrigger = dynamic_cast<ShortcutTrigger *>(actionData->trigger());
Q_ASSERT(shortcutTrigger);
if (shortcutTrigger == nullptr) return "";
if (shortcutTrigger == nullptr)
return "";
// Change the actionData
shortcutTrigger->set_key_sequence(sequence);
......@@ -222,39 +192,37 @@ QString KHotKeysModule::register_menuentry_shortcut(
// Remove the resulting real shortcut
return shortcutTrigger->primaryShortcut();
}
}
}
Q_ASSERT(false);
return "";
}
}
void KHotKeysModule::quit()
{
{
deleteLater();
}
}
void KHotKeysModule::scheduleSave()
{
if (!_settingsDirty)
{
{
if (!_settingsDirty) {
_settingsDirty = true;
QMetaObject::invokeMethod(this, "save", Qt::QueuedConnection);
}
}
}
void KHotKeysModule::save()
{
{
_settingsDirty = false;
KHotKeys::khotkeys_set_active( false );
KHotKeys::khotkeys_set_active(false);
_settings.write();
KHotKeys::khotkeys_set_active( true );
}
KHotKeys::khotkeys_set_active(true);
}
void KHotKeysModule::declareConfigOutdated()
{
{
Settings::isOutdated = true;
}
}
#include "kded.moc"
......@@ -6,100 +6,96 @@
#ifndef _KHOTKEYS_KDED_H_
#define _KHOTKEYS_KDED_H_
#include <kdedmodule.h>
#include "settings.h"
#include <kdedmodule.h>
#include <QKeySequence>
#include <QObject>
#include <QtDBus>
#include <QKeySequence>
#include <KService>
namespace KHotKeys
{
class ActionDataGroup;
class SimpleActionData;
}
class KHotKeysModule
: public KDEDModule
{
{
class ActionDataGroup;
class SimpleActionData;
}
class KHotKeysModule : public KDEDModule
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.khotkeys")
public Q_SLOTS:
Q_SCRIPTABLE Q_NOREPLY void reread_configuration();
Q_SCRIPTABLE Q_NOREPLY void quit();
/**
* Register an shortcut for service @serviceStorageId with the key
* sequence @seq.
*
* @param serviceStorageId the KService::storageId of the service
* @param sequence the key sequence to use
*
* @returns @c true if the key sequence was successfully set, @c if
* the sequence is not available.
*/
Q_SCRIPTABLE QString register_menuentry_shortcut(const QString &storageId, const QString &sequence);
/**
* Get the currently active shortcut for service @p serviceStorageId.
*
* @param serviceStorageId the KService::storageId of the service
*
* @returns the active global shortcuts for that service
*/
Q_SCRIPTABLE QString get_menuentry_shortcut(const QString &storageId);
/**
* declare daemon settings outdated, do not write back until re-read has been triggered
*/
Q_SCRIPTABLE Q_NOREPLY void declareConfigOutdated();
private Q_SLOTS:
//! Save
void scheduleSave();
void save();
//! Initialize the module. Delayed initialization.
void initialize();
public:
KHotKeysModule(QObject* parent, const QList<QVariant>&);
virtual ~KHotKeysModule();
private:
//! The action list from _settings for convenience
KHotKeys::ActionDataGroup* actions_root;
//! The current settings
bool _settingsDirty;
KHotKeys::Settings _settings;
//! Is the module initialized
bool _initialized;
/**
* @name Some method in need for a better home
*/
//@{
//! Get the group for the menuentries. Will create it if needed
KHotKeys::ActionDataGroup *menuentries_group();
//! Find a menuentry_action for the service with @storageId in group @group
KHotKeys::SimpleActionData *menuentry_action(const QString &storageId);
//@}
};
public Q_SLOTS:
Q_SCRIPTABLE Q_NOREPLY void reread_configuration();
Q_SCRIPTABLE Q_NOREPLY void quit();
/**
* Register an shortcut for service @serviceStorageId with the key
* sequence @seq.
*
* @param serviceStorageId the KService::storageId of the service
* @param sequence the key sequence to use
*
* @returns @c true if the key sequence was successfully set, @c if
* the sequence is not available.
*/
Q_SCRIPTABLE QString register_menuentry_shortcut(const QString &storageId, const QString &sequence);
/**
* Get the currently active shortcut for service @p serviceStorageId.
*
* @param serviceStorageId the KService::storageId of the service
*
* @returns the active global shortcuts for that service
*/
Q_SCRIPTABLE QString get_menuentry_shortcut(const QString &storageId);
/**
* declare daemon settings outdated, do not write back until re-read has been triggered
*/
Q_SCRIPTABLE Q_NOREPLY void declareConfigOutdated();
private Q_SLOTS:
//! Save
void scheduleSave();
void save();
//! Initialize the module. Delayed initialization.
void initialize();
public:
KHotKeysModule(QObject *parent, const QList<QVariant> &);
virtual ~KHotKeysModule();
private:
//! The action list from _settings for convenience
KHotKeys::ActionDataGroup *actions_root;
//! The current settings
bool _settingsDirty;
KHotKeys::Settings _settings;
//! Is the module initialized
bool _initialized;
/**
* @name Some method in need for a better home
*/
//@{
//! Get the group for the menuentries. Will create it if needed
KHotKeys::ActionDataGroup *menuentries_group();
//! Find a menuentry_action for the service with @storageId in group @group
KHotKeys::SimpleActionData *menuentry_action(const QString &storageId);
//@}
};
//***************************************************************************
// Inline
//***************************************************************************
#endif
......@@ -13,30 +13,25 @@
#include <QDBusInterface>
void Test::initTestCase()
{
{
daemonActive = KHotKeys::Daemon::isRunning();
if (daemonActive)
{
if (daemonActive) {
qWarning() << "Shutting down a running daemon";
KHotKeys::Daemon::stop();
}
}
}
void Test::cleanupTestCase()
{
if (daemonActive)
{
{
if (daemonActive) {
qWarning() << "Restarting the stopped daemon";
KHotKeys::Daemon::start();
}
}
}
void Test::testLoading()
{
{
// Check loading/unloading. We have to do it more than once. When
// something is amiss kded will crash after reloading it.
QVERIFY(!KHotKeys::KdedModuleDaemon::isRunning());
......@@ -54,9 +49,9 @@ void Test::testLoading()
QVERIFY(KHotKeys::KdedModuleDaemon::start());
QVERIFY(KHotKeys::KdedModuleDaemon::isRunning());
// Ensure kded is still there
QVERIFY(QDBusInterface( "org.kde.kded5", "/kded","org.kde.kded5" ).isValid());
QVERIFY(QDBusInterface("org.kde.kded5", "/kded", "org.kde.kded5").isValid());
QVERIFY(KHotKeys::KdedModuleDaemon::stop());
}
}
QTEST_MAIN(Test)
#include "moc_kdedmodule_daemon_test.cpp"
......@@ -4,7 +4,7 @@
#include <QObject>
class Test : public QObject
{
{
Q_OBJECT
private Q_SLOTS:
......@@ -15,9 +15,8 @@ private Q_SLOTS:
void testLoading();
private:
bool daemonActive;
}; // class Test
}; // class Test
#endif
......@@ -10,24 +10,21 @@
#include "action_data/action_data_group.h"
ActionGroupWidget::ActionGroupWidget( QWidget *parent )
: HotkeysWidgetBase(parent)
,_conditions(new ConditionsWidget)
{
ActionGroupWidget::ActionGroupWidget(QWidget *parent)
: HotkeysWidgetBase(parent)
, _conditions(new ConditionsWidget)
{
extend(_conditions, i18n("Conditions"));
connect(_conditions, SIGNAL(changed(bool)),
SLOT(slotChanged()));
}
connect(_conditions, SIGNAL(changed(bool)), SLOT(slotChanged()));
}
ActionGroupWidget::~ActionGroupWidget()
{
{
_conditions = nullptr;
}
}
void ActionGroupWidget::setActionData(KHotKeys::ActionDataGroup *group)
{
{
_data = group;
// BUG: conditions copies twice from the original. Once in
......@@ -36,33 +33,29 @@ void ActionGroupWidget::setActionData(KHotKeys::ActionDataGroup *group)
_conditions->setConditionsList(group->conditions());
Base::copyFromObject();
}
}
void ActionGroupWidget::doCopyFromObject()
{
{
Q_ASSERT(data());
Base::doCopyFromObject();
Q_ASSERT(_conditions);
_conditions->copyFromObject();
}
}
void ActionGroupWidget::doCopyToObject()
{
{
Q_ASSERT(data());
Base::doCopyToObject();
Q_ASSERT(_conditions);
_conditions->copyToObject();
}
}
bool ActionGroupWidget::isChanged() const
{
{
return _conditions->hasChanges() || Base::isChanged();
}