• 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
editprofileaction.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 "editprofileaction.h"
21 #include <profileserver.h>
22 
23 #include <kdebug.h>
24 
25 EditProfileAction::EditProfileAction(ProfileAction *action, QWidget* parent, Qt::WFlags flags): QWidget(parent, flags) {
26  m_action = action;
27  ui.setupUi(this);
28 
29  // Init Profiles
30  ui.lDBusServices->setText(i18n("Profiles:"));
31  m_profileModel = new ProfileModel(ui.tvDBusApps);
32  ui.tvDBusApps->setModel(m_profileModel);
33  ui.tvDBusApps->setRootIsDecorated(false);
34 
35  //Init Templates
36  ui.lFunctions->setText(i18n("Action templates:"));
37  m_templateModel = new ActionTemplateModel(ui.tvDBusFunctions);
38  ui.tvDBusFunctions->setModel(m_templateModel);
39  connect(ui.tvDBusApps->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(refreshTemplates(QModelIndex)));
40 
41 
42  // Init Arguments View
43  m_argumentsModel = new ArgumentsModel(ui.tvArguments);
44  ui.tvArguments->setModel(m_argumentsModel);
45  ui.tvArguments->setItemDelegate(new ArgumentDelegate(ui.tvArguments));
46  connect(ui.tvDBusFunctions->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(refreshArguments(QModelIndex)));
47 
48 
49  // Load our action here
50  kDebug() << "searching for action:" << m_action->name() << m_action->description() << m_action->application();
51  if(!m_action->application().isEmpty()){
52  // Find Profile and Template in Models and set current index
53  QModelIndex index = m_profileModel->find(m_action);
54  ui.tvDBusApps->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
55  index = m_templateModel->find(m_action);
56  ui.tvDBusFunctions->selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
57 
58  // Load Options tab
59  ui.cbAutostart->setChecked(m_action->autostart());
60  ui.cbRepeat->setChecked(m_action->repeat());
61  switch(m_action->destination()){
62  case DBusAction::Unique:
63  ui.gbUnique->setEnabled(false);
64  break;
65  case DBusAction::Top:
66  ui.rbTop->setChecked(true);
67  break;
68  case DBusAction::Bottom:
69  ui.rbBottom->setChecked(true);
70  break;
71  case DBusAction::All:
72  ui.rbAll->setChecked(true);
73  break;
74  case DBusAction::None:
75  ui.rbNone->setChecked(true);
76  break;
77  }
78  }
79  if(!m_action->function().args().isEmpty()){
80  m_argumentsModel->refresh(m_action->function());
81  }
82 }
83 
84 
85 EditProfileAction::~EditProfileAction() {
86 }
87 
88 bool EditProfileAction::checkForComplete() const {
89  if(ui.tvDBusFunctions->selectionModel()->currentIndex().isValid()){
90  return true;
91  }
92  return false;
93 }
94 
95 void EditProfileAction::applyChanges(){
96  ProfileActionTemplate actionTemplate = m_templateModel->actionTemplate(ui.tvDBusFunctions->selectionModel()->currentIndex());
97  kDebug() << "applyChanges to action:" << actionTemplate.profileId();
98  m_action->setApplication(actionTemplate.service());
99  m_action->setInterface(actionTemplate.interface());
100  m_action->setNode(actionTemplate.node());
101  Prototype prototype = actionTemplate.function();
102  prototype.setArgs(m_argumentsModel->arguments());
103  m_action->setFunction(prototype);
104  m_action->setActionTemplateId(actionTemplate.actionTemplateId());
105  m_action->setProfileId(actionTemplate.profileId());
106 
107  m_action->setAutostart(ui.cbAutostart->isChecked());
108  m_action->setRepeat(ui.cbRepeat->isChecked());
109  if(ui.gbUnique->isEnabled()){
110  if(ui.rbAll->isChecked()){
111  m_action->setDestination(DBusAction::All);
112  } else if(ui.rbNone->isChecked()){
113  m_action->setDestination(DBusAction::None);
114  } else if(ui.rbTop->isChecked()){
115  m_action->setDestination(DBusAction::Top);
116  } else if(ui.rbBottom->isChecked()){
117  m_action->setDestination(DBusAction::Bottom);
118  }
119  } else {
120  m_action->setDestination(DBusAction::Unique);
121  }
122 }
123 
124 ProfileAction EditProfileAction::action() const {
125  ProfileAction action;
126  ProfileActionTemplate actionTemplate = m_templateModel->actionTemplate(ui.tvDBusFunctions->selectionModel()->currentIndex());
127  action.setApplication(actionTemplate.service());
128  action.setNode(actionTemplate.node());
129  Prototype prototype = actionTemplate.function();
130  prototype.setArgs(m_argumentsModel->arguments());
131  action.setInterface(actionTemplate.interface());
132  action.setFunction(prototype);
133  action.setActionTemplateId(actionTemplate.actionTemplateId());
134  action.setProfileId(actionTemplate.profileId());
135 
136  action.setAutostart(ui.cbAutostart->isChecked());
137  action.setRepeat(ui.cbRepeat->isChecked());
138  if(ui.gbUnique->isEnabled()){
139  if(ui.rbAll->isChecked()){
140  action.setDestination(DBusAction::All);
141  } else if(ui.rbNone->isChecked()){
142  action.setDestination(DBusAction::None);
143  } else if(ui.rbTop->isChecked()){
144  action.setDestination(DBusAction::Top);
145  } else if(ui.rbBottom->isChecked()){
146  action.setDestination(DBusAction::Bottom);
147  }
148  } else {
149  action.setDestination(DBusAction::Unique);
150  }
151  return action;
152 }
153 
154 void EditProfileAction::refreshTemplates(const QModelIndex& index) {
155  m_templateModel->refresh(m_profileModel->profile(ui.tvDBusApps->selectionModel()->currentIndex()));
156  m_templateModel->setColumnCount(2);
157  ui.tvDBusFunctions->resizeColumnToContents(0);
158  m_argumentsModel->clear();
159  emit formComplete(index.isValid());
160 }
161 
162 void EditProfileAction::refreshArguments(const QModelIndex &index) {
163  ProfileActionTemplate actionTemplate = m_templateModel->actionTemplate(index);
164  kDebug() << "got template:" << actionTemplate.actionName() << "function:" << actionTemplate.function().name();
165  m_argumentsModel->refresh(actionTemplate.function());
166  ui.tvArguments->resizeColumnsToContents();
167  ui.tvArguments->horizontalHeader()->setStretchLastSection(true);
168 
169  if(actionTemplate.destination() == DBusAction::Unique){
170  ui.gbUnique->setEnabled(false);
171  } else {
172  ui.gbUnique->setEnabled(true);
173  }
174  emit formComplete(index.isValid());
175 
176  ui.cbAutostart->setChecked(actionTemplate.autostart());
177  ui.cbRepeat->setChecked(actionTemplate.repeat());
178  ui.rbAll->setChecked(actionTemplate.destination() == Action::All);
179  ui.rbNone->setChecked(actionTemplate.destination() == Action::None);
180  ui.rbTop->setChecked(actionTemplate.destination() == Action::Top);
181  ui.rbBottom->setChecked(actionTemplate.destination() == Action::Bottom);
182 }
183 
Action::Bottom
Definition: action.h:34
ProfileAction::name
virtual QString name() const
Definition: profileaction.cpp:50
ProfileActionTemplate
Definition: profileactiontemplate.h:31
ActionTemplateModel::refresh
void refresh(const Profile *profile)
Definition: model.cpp:541
Action::destination
ActionDestination destination() const
Definition: action.cpp:61
Prototype::name
QString name() const
Definition: prototype.cpp:28
DBusAction::function
Prototype function() const
Definition: dbusaction.cpp:55
Action::autostart
bool autostart() const
Definition: action.cpp:53
ProfileActionTemplate::destination
ProfileAction::ActionDestination destination() const
Definition: profileactiontemplate.cpp:91
QWidget
ProfileAction::description
virtual QString description() const
Definition: profileaction.cpp:59
ProfileActionTemplate::service
QString service() const
Definition: profileactiontemplate.cpp:70
EditProfileAction::formComplete
void formComplete(bool complete)
ActionTemplateModel
Definition: model.h:132
ProfileModel::find
QModelIndex find(const ProfileAction *action) const
Definition: model.cpp:515
profileserver.h
Action::All
Definition: action.h:34
DBusAction::setInterface
void setInterface(const QString &interface)
Definition: dbusaction.cpp:50
ProfileModel::profile
Profile * profile(const QModelIndex &index) const
Definition: model.cpp:508
ProfileActionTemplate::actionTemplateId
QString actionTemplateId() const
Definition: profileactiontemplate.cpp:62
EditProfileAction::applyChanges
void applyChanges()
Definition: editprofileaction.cpp:95
DBusAction::setApplication
void setApplication(const QString &application)
Definition: dbusaction.cpp:33
DBusAction::setFunction
void setFunction(const Prototype &function)
Definition: dbusaction.cpp:59
Action::setRepeat
void setRepeat(bool repeat)
Definition: action.cpp:49
ProfileActionTemplate::profileId
QString profileId() const
Definition: profileactiontemplate.cpp:58
Action::Unique
Definition: action.h:34
Prototype
Definition: prototype.h:28
EditProfileAction::EditProfileAction
EditProfileAction(ProfileAction *action, QWidget *parent=0, Qt::WFlags flags=0)
Definition: editprofileaction.cpp:25
ArgumentDelegate
Definition: model.h:107
ProfileActionTemplate::node
QString node() const
Definition: profileactiontemplate.cpp:74
ProfileActionTemplate::function
Prototype function() const
Definition: profileactiontemplate.cpp:87
EditProfileAction::action
ProfileAction action() const
Definition: editprofileaction.cpp:124
Action::Top
Definition: action.h:34
Prototype::setArgs
void setArgs(const QList< Argument > &args)
Definition: prototype.cpp:36
Action::setDestination
void setDestination(ActionDestination destination)
Definition: action.cpp:65
EditProfileAction::checkForComplete
bool checkForComplete() const
Definition: editprofileaction.cpp:88
ProfileAction::setActionTemplateId
void setActionTemplateId(const QString &actionTemplateID)
Definition: profileaction.cpp:46
ArgumentsModel
Definition: model.h:88
ProfileModel
Definition: model.h:123
ArgumentsModel::arguments
QList< Argument > arguments() const
Definition: model.cpp:286
editprofileaction.h
Action::setAutostart
void setAutostart(bool autostart)
Definition: action.cpp:57
Prototype::args
QList< Argument > args() const
Definition: prototype.cpp:32
ActionTemplateModel::find
QModelIndex find(const ProfileAction *action) const
Definition: model.cpp:567
Action::None
Definition: action.h:34
EditProfileAction::~EditProfileAction
~EditProfileAction()
Definition: editprofileaction.cpp:85
ProfileActionTemplate::repeat
bool repeat() const
Definition: profileactiontemplate.cpp:99
DBusAction::application
QString application() const
Definition: dbusaction.cpp:29
ProfileAction::setProfileId
void setProfileId(const QString &profileId)
Definition: profileaction.cpp:38
Action::repeat
bool repeat() const
Definition: action.cpp:45
ArgumentsModel::refresh
void refresh(const Prototype &prototype)
Definition: model.cpp:261
DBusAction::setNode
void setNode(const QString &node)
Definition: dbusaction.cpp:41
ProfileActionTemplate::actionName
QString actionName() const
Definition: profileactiontemplate.cpp:66
ActionTemplateModel::actionTemplate
ProfileActionTemplate actionTemplate(const QModelIndex &index) const
Definition: model.cpp:563
ProfileAction
Definition: profileaction.h:26
ProfileActionTemplate::autostart
bool autostart() const
Definition: profileactiontemplate.cpp:95
ProfileActionTemplate::interface
QString interface() const
Definition: profileactiontemplate.cpp:82
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