File indexing completed on 2024-09-15 12:55:41
0001 /* SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0002 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "dbus_action_widget.h" 0007 0008 #include <KDialogJobUiDelegate> 0009 #include <KIO/CommandLauncherJob> 0010 0011 DbusActionWidget::DbusActionWidget(KHotKeys::DBusAction *action, QWidget *parent) 0012 : Base(action, parent) 0013 { 0014 ui.setupUi(this); 0015 0016 connect(ui.application, SIGNAL(textChanged(QString)), _changedSignals, SLOT(map())); 0017 _changedSignals->setMapping(ui.application, "application"); 0018 connect(ui.object, SIGNAL(textChanged(QString)), _changedSignals, SLOT(map())); 0019 _changedSignals->setMapping(ui.object, "object"); 0020 connect(ui.function, SIGNAL(textChanged(QString)), _changedSignals, SLOT(map())); 0021 _changedSignals->setMapping(ui.function, "function"); 0022 connect(ui.arguments, SIGNAL(textChanged(QString)), _changedSignals, SLOT(map())); 0023 _changedSignals->setMapping(ui.arguments, "arguments"); 0024 0025 connect(ui.launchButton, SIGNAL(clicked()), this, SLOT(launchDbusBrowser())); 0026 connect(ui.execButton, SIGNAL(clicked()), this, SLOT(execCommand())); 0027 } 0028 0029 DbusActionWidget::~DbusActionWidget() 0030 { 0031 } 0032 0033 KHotKeys::DBusAction *DbusActionWidget::action() 0034 { 0035 return static_cast<KHotKeys::DBusAction *>(_action); 0036 } 0037 0038 const KHotKeys::DBusAction *DbusActionWidget::action() const 0039 { 0040 return static_cast<const KHotKeys::DBusAction *>(_action); 0041 } 0042 0043 void DbusActionWidget::doCopyFromObject() 0044 { 0045 Q_ASSERT(action()); 0046 ui.application->setText(action()->remote_application()); 0047 ui.object->setText(action()->remote_object()); 0048 ui.function->setText(action()->called_function()); 0049 ui.arguments->setText(action()->arguments()); 0050 } 0051 0052 void DbusActionWidget::doCopyToObject() 0053 { 0054 Q_ASSERT(action()); 0055 action()->set_remote_application(ui.application->text()); 0056 action()->set_remote_object(ui.object->text()); 0057 action()->set_called_function(ui.function->text()); 0058 action()->set_arguments(ui.arguments->text()); 0059 } 0060 0061 void DbusActionWidget::execCommand() const 0062 { 0063 KHotKeys::DBusAction action(nullptr, ui.application->text(), ui.object->text(), ui.function->text(), ui.arguments->text()); 0064 0065 // TODO: Error handling 0066 action.execute(); 0067 } 0068 0069 bool DbusActionWidget::isChanged() const 0070 { 0071 Q_ASSERT(action()); 0072 // clang-format off 0073 return ui.application->text() != action()->remote_application() 0074 || ui.object->text() != action()->remote_object() 0075 || ui.function->text() != action()->called_function() 0076 || ui.arguments->text() != action()->arguments(); 0077 // clang-format on 0078 } 0079 0080 void DbusActionWidget::launchDbusBrowser() const 0081 { 0082 auto *job = new KIO::CommandLauncherJob("qdbusviewer"); 0083 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, window())); 0084 job->start(); 0085 } 0086 0087 #include "moc_dbus_action_widget.cpp"