1616 along with this program. If not, see <https://www.gnu.org/licenses/>.
1717*/
1818
19- #include " IntegratedDBusInterface .h"
19+ #include " MainDBusInterface .h"
2020#include < QRegularExpression>
2121#include < libinputactions/InputActionsMain.h>
2222#include < libinputactions/config/ConfigIssueManager.h>
2323#include < libinputactions/config/ConfigLoader.h>
24+ #include < libinputactions/config/GlobalConfig.h>
2425#include < libinputactions/helpers/QDBusConnection.h>
2526#include < libinputactions/input/StrokeRecorder.h>
2627#include < libinputactions/input/backends/InputBackend.h>
28+ #include < libinputactions/input/devices/InputDevice.h>
2729#include < libinputactions/interfaces/OnScreenMessageManager.h>
2830#include < libinputactions/triggers/core/StrokeTriggerCore.h>
2931#include < libinputactions/variables/VariableRegistry.h>
3032
3133namespace InputActions
3234{
3335
34- IntegratedDBusInterface::IntegratedDBusInterface ()
36+ MainDBusInterface::MainDBusInterface ()
3537 : m_bus(QDBusConnectionHelpers::sessionBus())
3638{
3739 m_bus.registerService (INPUTACTIONS_DBUS_SERVICE );
3840 m_bus.registerObject (INPUTACTIONS_DBUS_PATH , this , QDBusConnection::ExportAllSlots);
3941}
4042
41- IntegratedDBusInterface ::~IntegratedDBusInterface ()
43+ MainDBusInterface ::~MainDBusInterface ()
4244{
4345 m_bus.unregisterService (INPUTACTIONS_DBUS_SERVICE );
4446 m_bus.unregisterObject (INPUTACTIONS_DBUS_PATH );
4547}
4648
47- QString IntegratedDBusInterface ::deviceList ()
49+ QString MainDBusInterface ::deviceList ()
4850{
49- return DBusInterfaceBase::deviceList ();
51+ QStringList result;
52+ for (const auto *device : g_inputBackend->devices ()) {
53+ result.push_back (device->toString ());
54+ }
55+ result.sort ();
56+ return result.join (" \n\n " );
5057}
5158
52- QString IntegratedDBusInterface ::issues ()
59+ QString MainDBusInterface ::issues ()
5360{
54- return DBusInterfaceBase::issues ();
61+ return g_configIssueManager-> issuesToString ();
5562}
5663
57- void IntegratedDBusInterface ::recordStroke (const QDBusMessage &message)
64+ void MainDBusInterface ::recordStroke (const QDBusMessage &message)
5865{
5966 if (!g_inputBackend->initialized ()) {
6067 sendErrorReply (QDBusError::Failed, " Stroke recording requires a valid configuration to be active." );
@@ -74,23 +81,60 @@ void IntegratedDBusInterface::recordStroke(const QDBusMessage &message)
7481 });
7582}
7683
77- QString IntegratedDBusInterface ::reloadConfig ()
84+ QString MainDBusInterface ::reloadConfig ()
7885{
86+ if (!m_allowConfigLoading) {
87+ sendErrorReply (QDBusError::Failed, " Loading the configuration is not allowed while the client is inactive." );
88+ return {};
89+ }
90+
7991 g_configLoader->load ({
8092 .manual = true ,
8193 });
8294 return g_configIssueManager->issuesToString ();
8395}
8496
85- QString IntegratedDBusInterface ::suspend ()
97+ QString MainDBusInterface ::suspend ()
8698{
99+ if (m_allowConfigLoading) {
100+ sendErrorReply (QDBusError::Failed, " Suspending is not allowed while the client is inactive." );
101+ return {};
102+ }
103+
87104 g_inputActions->suspend ();
88105 return " success" ;
89106}
90107
91- QString IntegratedDBusInterface::variables (QString filter)
108+ QString MainDBusInterface::variables (QString filter)
109+ {
110+ if (!g_globalConfig->allowExternalVariableAccess ()) {
111+ return " External variable access has been disabled. Set 'external_variable_access' to 'true' to enable." ;
112+ }
113+
114+ QStringList result;
115+ const QRegularExpression filterRegex (filter);
116+ for (const auto &[name, variable] : g_variableRegistry->variables ()) {
117+ if (variable->hidden () || !filterRegex.match (name).hasMatch ()) {
118+ continue ;
119+ }
120+ result.push_back (QString (" %1: %2" ).arg (name, variable->operations ()->toString ()));
121+ }
122+ return result.join (' \n ' );
123+ }
124+
125+ QString MainDBusInterface::strokeToBase64 (const Stroke &stroke)
92126{
93- return variableList (g_variableRegistry.get (), filter);
127+ QByteArray bytes;
128+ const auto &points = stroke.points ();
129+ for (size_t i = 0 ; i < points.size (); i++) {
130+ // All values range from -1 to 1
131+ bytes.push_back (static_cast <char >(points[i].x * 100 ));
132+ bytes.push_back (static_cast <char >(points[i].y * 100 ));
133+ bytes.push_back (static_cast <char >(points[i].t * 100 ));
134+ bytes.push_back (static_cast <char >(points[i].alpha * 100 ));
135+ }
136+
137+ return QString (" '%1'" ).arg (bytes.toBase64 ());
94138}
95139
96140}
0 commit comments