File indexing completed on 2024-09-08 13:16:50
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "menuentry_action_widget.h" 0008 0009 #include <KOpenWithDialog> 0010 #include <QDebug> 0011 0012 MenuentryActionWidget::MenuentryActionWidget(KHotKeys::MenuEntryAction *action, QWidget *parent) 0013 : ActionWidgetBase(action, parent) 0014 , storage_id() 0015 { 0016 ui.setupUi(this); 0017 0018 connect(ui.applicationButton, SIGNAL(clicked()), this, SLOT(selectApplicationClicked())); 0019 0020 connect(ui.application, SIGNAL(textChanged(QString)), _changedSignals, SLOT(map())); 0021 _changedSignals->setMapping(ui.application, "application"); 0022 } 0023 0024 MenuentryActionWidget::~MenuentryActionWidget() 0025 { 0026 } 0027 0028 KHotKeys::MenuEntryAction *MenuentryActionWidget::action() 0029 { 0030 Q_ASSERT(dynamic_cast<KHotKeys::MenuEntryAction *>(_action)); 0031 return static_cast<KHotKeys::MenuEntryAction *>(_action); 0032 } 0033 0034 const KHotKeys::MenuEntryAction *MenuentryActionWidget::action() const 0035 { 0036 Q_ASSERT(dynamic_cast<KHotKeys::MenuEntryAction *>(_action)); 0037 return static_cast<const KHotKeys::MenuEntryAction *>(_action); 0038 } 0039 0040 void MenuentryActionWidget::doCopyFromObject() 0041 { 0042 Q_ASSERT(action()); 0043 KService::Ptr service = action()->service(); 0044 0045 if (service) { 0046 ui.application->setText(service->name()); 0047 storage_id = service->storageId(); 0048 } else { 0049 ui.application->setText(QString()); 0050 storage_id = QString(); 0051 } 0052 } 0053 0054 void MenuentryActionWidget::doCopyToObject() 0055 { 0056 Q_ASSERT(action()); 0057 action()->set_service(KService::serviceByStorageId(storage_id)); 0058 } 0059 0060 bool MenuentryActionWidget::isChanged() const 0061 { 0062 Q_ASSERT(action()); 0063 0064 bool changed; 0065 0066 // There could be no service set, so be careful! 0067 if (action()->service()) { 0068 changed = ui.application->text() != action()->service()->name(); 0069 } else { 0070 // No service set. If the string is not empty something changed. 0071 changed = !ui.application->text().isEmpty(); 0072 } 0073 0074 return changed; 0075 } 0076 0077 void MenuentryActionWidget::selectApplicationClicked() 0078 { 0079 KOpenWithDialog dlg; 0080 dlg.exec(); 0081 0082 KService::Ptr service = dlg.service(); 0083 0084 if (service) { 0085 ui.application->setText(service->name()); 0086 storage_id = service->storageId(); 0087 } 0088 } 0089 0090 #include "moc_menuentry_action_widget.cpp"