• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kremotecontrol

  • sources
  • kde-4.12
  • kdeutils
  • kremotecontrol
  • kcmremotecontrol
editactioncontainer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Michael Zanetti <michael_zanetti@gmx.net>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 
20 #include "editactioncontainer.h"
21 #include "editdbusaction.h"
22 #include "editprofileaction.h"
23 #include "editkeypressaction.h"
24 #include "dbusinterface.h"
25 #include "executionengine.h"
26 
27 #include <kdebug.h>
28 
29 #include "keypressaction.h"
30 
31 
32 EditActionContainer::EditActionContainer(Action *action, const QString &remote, QWidget* parent, Qt::WFlags flags): KDialog(parent, flags) {
33  m_action = action;
34  m_remote = remote;
35 
36  QWidget *widget = new QWidget(this);
37  ui.setupUi(widget);
38  setMainWidget(widget);
39 
40  setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Try);
41 
42  // Init Buttons
43  foreach(const RemoteControlButton &button, RemoteControl(remote).buttons()){
44  ui.cbButton->addItem(button.description(), button.name());
45  }
46  ui.cbButton->setCurrentIndex(ui.cbButton->findData(action->button()));
47  connect(ui.cbButton, SIGNAL(currentIndexChanged(int)), SLOT(checkForComplete()));
48 
49  m_innerWidget = 0;
50  switch(action->type()){
51  case Action::DBusAction:{
52  DBusAction *dbusAction = dynamic_cast<DBusAction*>(action);
53  if(dbusAction){
54  m_innerWidget = new EditDBusAction(dbusAction);
55  }
56  break;
57  }
58  case Action::ProfileAction:{
59  ProfileAction *profileAction = dynamic_cast<ProfileAction*>(action);
60  if(profileAction){
61  m_innerWidget = new EditProfileAction(profileAction);
62  }
63  break;
64  }
65  case Action::KeypressAction: {
66  KeypressAction *keypressAction = dynamic_cast<KeypressAction*>(action);
67  if(keypressAction){
68  m_innerWidget = new EditKeypressAction(keypressAction);
69  }
70  break;
71  }
72  default:
73  kDebug() << "Invalid action type. Not creating inner Widget";
74  }
75 
76  if(m_innerWidget){
77  QHBoxLayout *innerLayout = new QHBoxLayout();
78  innerLayout->setMargin(0);
79 
80  innerLayout->addWidget(m_innerWidget);
81  ui.wActionWidget->setLayout(innerLayout);
82  connect(m_innerWidget, SIGNAL(formComplete(bool)), SLOT(checkForComplete()));
83  }
84  checkForComplete();
85 
86  // Pause remote to make use of button presses here
87  DBusInterface::getInstance()->ignoreButtonEvents(remote);
88  connect(new RemoteControl(remote), SIGNAL(buttonPressed(RemoteControlButton)), SLOT(buttonPressed(RemoteControlButton)));
89 
90 }
91 
92 void EditActionContainer::checkForComplete() {
93  if(ui.cbButton->currentIndex() < 0){
94  enableButtonOk(false);
95  enableButton(Try, false);
96  return;
97  }
98  switch(m_action->type()){
99  case Action::DBusAction:{
100  EditDBusAction *dbusActionEditor = dynamic_cast<EditDBusAction*>(m_innerWidget);
101  if(dbusActionEditor){
102  bool complete = dbusActionEditor->checkForComplete();
103  enableButtonOk(complete);
104  enableButton(Try, complete);
105  return;
106  }
107  }
108  case Action::ProfileAction:{
109  EditProfileAction *profileActionEditor = dynamic_cast<EditProfileAction*>(m_innerWidget);
110  if(profileActionEditor){
111  bool complete = profileActionEditor->checkForComplete();
112  enableButtonOk(complete);
113  enableButton(Try, complete);
114  return;
115  }
116  }
117  case Action::KeypressAction:{
118  EditKeypressAction *keypressActionEditor = dynamic_cast<EditKeypressAction*>(m_innerWidget);
119  if(keypressActionEditor){
120  bool complete = keypressActionEditor->checkForComplete();
121  enableButtonOk(complete);
122  enableButton(Try, complete);
123  return;
124  }
125  }
126  default:
127  kDebug() << "Invalid action type! Nothing to check for completeness!";
128  }
129 }
130 
131 void EditActionContainer::slotButtonClicked(int button) {
132  if (button == KDialog::Ok) {
133  switch(m_action->type()){
134  case Action::DBusAction:{
135  EditDBusAction *dbusActionEditor = dynamic_cast<EditDBusAction*>(m_innerWidget);
136  if(dbusActionEditor){
137  dbusActionEditor->applyChanges();
138  }
139  break;
140  }
141  case Action::ProfileAction:{
142  EditProfileAction *profileActionEditor = dynamic_cast<EditProfileAction*>(m_innerWidget);
143  if(profileActionEditor){
144  profileActionEditor->applyChanges();
145  }
146  break;
147  }
148  case Action::KeypressAction:{
149  EditKeypressAction *keypressActionEditor = dynamic_cast<EditKeypressAction*>(m_innerWidget);
150  if(keypressActionEditor){
151  keypressActionEditor->applyChanges();
152  }
153  break;
154  }
155  default:
156  kDebug() << "Invalid action type! No changes made to action!";
157  }
158  m_action->setButton(ui.cbButton->itemData(ui.cbButton->currentIndex()).toString());
159  } else if(button == KDialog::Try){
160  switch(m_action->type()){
161  case Action::DBusAction:{
162  EditDBusAction *dbusActionEditor = dynamic_cast<EditDBusAction*>(m_innerWidget);
163  if(dbusActionEditor){
164  DBusAction action = dbusActionEditor->action();
165  ExecutionEngine::executeAction(&action);
166  }
167  break;
168  }
169  case Action::ProfileAction:{
170  EditProfileAction *profileActionEditor = dynamic_cast<EditProfileAction*>(m_innerWidget);
171  if(profileActionEditor){
172  ProfileAction action = profileActionEditor->action();
173  ExecutionEngine::executeAction(&action);
174  }
175  break;
176  }
177  case Action::KeypressAction: {
178  EditKeypressAction *keypressActionEditor = dynamic_cast<EditKeypressAction*>(m_innerWidget);
179  if(keypressActionEditor){
180  KeypressAction action = keypressActionEditor->action();
181  kDebug() << action.keySequenceList();
182  ExecutionEngine::executeAction(&action);
183  }
184  break;
185  }
186  default:
187  kDebug() << "Invalid action type! Not executing!";
188  }
189  // return here because try button should not unpause remote
190  return;
191  }
192  DBusInterface::getInstance()->considerButtonEvents(m_remote);
193  KDialog::slotButtonClicked(button);
194 }
195 
196 void EditActionContainer::buttonPressed(const RemoteControlButton& button) {
197  kDebug() << "button event received";
198  if(button.remoteName() == m_remote) {
199  ui.cbButton->setCurrentIndex(ui.cbButton->findData(button.name()));
200  }
201 }
editdbusaction.h
EditDBusAction::checkForComplete
bool checkForComplete() const
Definition: editdbusaction.cpp:87
Action::type
ActionType type() const
Definition: action.cpp:33
dbusinterface.h
EditKeypressAction::action
KeypressAction action() const
Definition: editkeypressaction.cpp:61
RemoteControlButton::remoteName
QString remoteName() const
Retrieves the name of the RemoteControl this button comes from.
Definition: remotecontrolbutton.cpp:305
QWidget
DBusInterface::considerButtonEvents
void considerButtonEvents(const QString &remoteName)
Definition: dbusinterface.cpp:270
Action::button
QString button() const
Definition: action.cpp:37
ExecutionEngine::executeAction
void executeAction(Action *action)
Definition: executionengine.cpp:50
DBusInterface::getInstance
static DBusInterface * getInstance()
Definition: dbusinterface.cpp:50
KDialog
KeypressAction
Definition: keypressaction.h:27
keypressaction.h
Action::KeypressAction
Definition: action.h:33
Action
Definition: action.h:30
EditKeypressAction::checkForComplete
bool checkForComplete() const
Definition: editkeypressaction.cpp:52
EditProfileAction::applyChanges
void applyChanges()
Definition: editprofileaction.cpp:95
EditActionContainer::buttonPressed
void buttonPressed(const RemoteControlButton &button)
Definition: editactioncontainer.cpp:196
DBusAction
Definition: dbusaction.h:32
Action::setButton
void setButton(const QString &button)
Definition: action.cpp:41
RemoteControl
Definition: remotecontrol.h:35
EditKeypressAction::applyChanges
void applyChanges()
Definition: editkeypressaction.cpp:56
RemoteControlButton::name
QString name() const
Retrieves the name of the Button.
Definition: remotecontrolbutton.cpp:315
EditProfileAction::action
ProfileAction action() const
Definition: editprofileaction.cpp:124
EditDBusAction::action
DBusAction action() const
Definition: editdbusaction.cpp:119
Action::DBusAction
Definition: action.h:33
EditActionContainer::checkForComplete
void checkForComplete()
Definition: editactioncontainer.cpp:92
EditProfileAction
Definition: editprofileaction.h:28
EditKeypressAction
Definition: editkeypressaction.h:31
Action::ProfileAction
Definition: action.h:33
EditProfileAction::checkForComplete
bool checkForComplete() const
Definition: editprofileaction.cpp:88
EditDBusAction
Definition: editdbusaction.h:28
executionengine.h
editprofileaction.h
EditActionContainer::EditActionContainer
EditActionContainer(Action *action, const QString &remote, QWidget *parent=0, Qt::WFlags flags=0)
Definition: editactioncontainer.cpp:32
RemoteControlButton::description
QString description() const
Retrieves the description of the Button.
Definition: remotecontrolbutton.cpp:320
editkeypressaction.h
editactioncontainer.h
EditDBusAction::applyChanges
void applyChanges()
Definition: editdbusaction.cpp:94
EditActionContainer::slotButtonClicked
virtual void slotButtonClicked(int button)
Definition: editactioncontainer.cpp:131
DBusInterface::ignoreButtonEvents
void ignoreButtonEvents(const QString &remoteName)
Definition: dbusinterface.cpp:280
ProfileAction
Definition: profileaction.h:26
RemoteControlButton
Definition: remotecontrolbutton.h:30
KeypressAction::keySequenceList
QList< QKeySequence > keySequenceList() const
Definition: keypressaction.cpp:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kremotecontrol

Skip menu "kremotecontrol"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal