swift
Loading...
Searching...
No Matches
contextapplicationimpl.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QFile>
7#include <QFlags>
8#include <QIODevice>
9#include <QTextStream>
10#include <QtGlobal>
11
12#include "core/application.h"
13#include "core/inputmanager.h"
14#include "misc/dbusserver.h"
15#include "misc/logcategories.h"
16#include "misc/logmessage.h"
17#include "misc/settingscache.h"
19
20using namespace swift::misc;
21
22namespace swift::core::context
23{
25 : IContextApplication(mode, runtime), CIdentifiable(this)
26 {}
27
29 {
30 // Intentionally don't check for round trip here
31 emit this->settingsChanged(settings, origin);
32 }
33
42
51
53 {
54 if (isDebugEnabled())
55 {
56 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO;
57 }
60 for (const QString &key : keys)
61 {
62 result.insert(key, CSettingsCache::instance()->getHumanReadableName(key));
63 }
64 return result;
65 }
66
68 {
69 // no-op: proxy implements this method by calling getAllSettings
70 }
71
73 {
74 if (isDebugEnabled())
75 {
76 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << keyPrefix;
77 }
78 return CSettingsCache::instance()->saveToStore(keyPrefix);
79 }
80
82 {
83 if (isDebugEnabled())
84 {
85 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << keys.join(", ");
86 }
88 }
89
98
100 {
101 // Intentionally don't check for round trip here
102 emit this->hotkeyActionsRegistered(actions, origin);
103 }
104
105 void CContextApplication::callHotkeyActionRemotely(const QString &action, bool argument, const CIdentifier &origin)
106 {
107 if (origin.hasApplicationProcessId())
108 {
109 // If it originated from this process, then we are going to emit a signal
110 emit this->remoteHotkeyAction(action, argument, origin);
111 }
112 else
113 {
114 // action came from a different process but on the same machine. Ignore
115 if (origin.isFromLocalMachine())
116 {
117 return;
118 }
119
120 // Different process and different machine. Process it.
121 // However, it should not emit a remote action itself.
122 sApp->getInputManager()->callFunctionsBy(action, argument, false);
123 }
124 }
125
127 {
128 if (isDebugEnabled())
129 {
130 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << application;
131 }
132
133 if (!m_registeredApplications.contains(application))
134 {
135 m_registeredApplications.push_back(application);
136 emit this->registrationChanged();
137 emit this->hotkeyActionsRegistered(sApp->getInputManager()->allAvailableActions(), {});
138 }
139
140 this->cleanupRegisteredApplications();
141 return application;
142 }
143
145 {
146 if (isDebugEnabled())
147 {
148 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << application;
149 }
150 int r = m_registeredApplications.remove(application);
151 this->cleanupRegisteredApplications();
152 if (r > 0)
153 {
154 emit registrationChanged();
155 }
156 }
157
158 void CContextApplication::cleanupRegisteredApplications()
159 {
160 // static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
161 // m_registeredApplications.removeOlderThanNowMinusOffset(outdatedMs);
162 }
163
165 {
166 if (isDebugEnabled())
167 {
168 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO;
169 }
170 // static const int outdatedMs = qRound(1.5 * PingIdentifiersMs);
171 // return m_registeredApplications.findAfterNowMinusOffset(outdatedMs);
172 return m_registeredApplications;
173 }
174
176 {
177 if (isDebugEnabled())
178 {
179 CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO;
180 }
181 return this->identifier();
182 }
183} // namespace swift::core::context
ContextMode
How to handle a given context.
void callHotkeyActionRemotely(const QString &action, bool argument, const swift::misc::CIdentifier &origin)
Call a hotkey action on a remote process.
swift::misc::CStatusMessage loadSettings()
Load core settings from disk.
void unregisterApplication(const swift::misc::CIdentifier &application)
Unregister application.
swift::misc::CValueCachePacket getAllSettings() const
Get all settings currently in core settings cache.
swift::misc::CStatusMessage saveSettings(const QString &keyPrefix={})
Save core settings to disk.
swift::misc::CIdentifier getApplicationIdentifier() const
Identifier of application, remote side if distributed.
swift::misc::CStatusMessage saveSettingsByKey(const QStringList &keys)
Save core settings to disk.
void registerHotkeyActions(const QStringList &actions, const swift::misc::CIdentifier &origin)
Register hotkey action implemented by another process.
CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime)
Constructor.
void synchronizeLocalSettings()
Update local settings with settings from core.
void changeSettings(const swift::misc::CValueCachePacket &settings, const swift::misc::CIdentifier &origin)
Ratify some settings changed by another process.
QStringList getUnsavedSettingsKeys() const
Get keys of all unsaved settings currently in core settings cache.
swift::misc::CIdentifierList getRegisteredApplications() const
All registered applications.
swift::misc::CIdentifier registerApplication(const swift::misc::CIdentifier &application)
Register application, can also be used for ping.
swift::core::context::CSettingsDictionary getUnsavedSettingsKeysDescribed() const
Get keys and descriptions of all unsaved settings currently in core settings cache.
void remoteHotkeyAction(const QString &action, bool argument, const swift::misc::CIdentifier &origin)
Call a hotkey action on a remote process.
void registrationChanged()
A component changes.
void hotkeyActionsRegistered(const QStringList &actions, const swift::misc::CIdentifier &origin)
New action was registered.
void settingsChanged(const swift::misc::CValueCachePacket &settings, const swift::misc::CIdentifier &origin)
One or more settings were changed.
bool isDebugEnabled() const
Debug enabled?
Definition context.cpp:62
iterator insert(const Key &key, const Value &value)
Insert new item with key and value.
Definition dictionary.h:414
CIdentifiable(const QString &objectName)
Use literal based object name.
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
bool hasApplicationProcessId() const
Check if originating from the same process id.
bool isFromLocalMachine() const
Check if originating from the same local machine.
Value object encapsulating a list of object identifiers.
static const QString & contextSlot()
Context slots.
Class for emitting a log message.
Definition logmessage.h:27
Derived & debug()
Set the severity to debug.
CStatusMessage loadFromStore()
Load settings from disk.
static CSettingsCache * instance()
Return the singleton instance.
CStatusMessage saveToStore(const QString &keyPrefix={})
Save settings to disk.
Streamable status message, e.g.
swift::misc::CValueCachePacket getAllValuesWithTimestamps(const QString &keyPrefix={}) const
Return map containing all values in the cache, and timestamps when they were modified.
QStringList getAllUnsavedKeys(const QString &keyPrefix={}) const
Return keys of all values which have been changed but not saved.
Value class used for signalling changed values in the cache.
Definition valuecache.h:67
swift::misc::CDictionary< QString, QString, QMap > CSettingsDictionary
Value type for settings keys with descriptions.
Free functions in swift::misc.
QString join(QChar separator) const const