• 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
  • kded
kremotecontroldaemon.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) <2010> <Frank Scheffold (fscheffold@googlemail.com)>
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 
24 #include "kremotecontroldaemon.h"
25 #include "krcdadaptor.h"
26 
27 #include <dbusinterface.h>
28 #include <mode.h>
29 #include <action.h>
30 #include <executionengine.h>
31 
32 #include <KCModuleInfo>
33 #include <KDebug>
34 #include <KNotification>
35 #include <KAboutData>
36 #include <KIconLoader>
37 #include <KToolInvocation>
38 
39 #include <QtGui/QPixmap>
40 #include <libkremotecontrol/action.h>
41 
42 
43 K_PLUGIN_FACTORY(KRemoteControlDaemonFactory, registerPlugin<KRemoteControlDaemon>();)
44 K_EXPORT_PLUGIN(KRemoteControlDaemonFactory("kremotecontroldaemon"))
45 
46 KRemoteControlDaemon::KRemoteControlDaemon(QObject* parent, const QVariantList& ): KDEDModule(parent) {
47 
48  new KrcdAdaptor(this);
49  KAboutData aboutData("kremotecontroldaemon", "kremotecontroldaemon", ki18n("K Remote Control Daemon"),
50  "0.5", ki18n("Remote Control Daemon for KDE4"),
51  KAboutData::License_GPL, ki18n("(c) 2010 Frank Scheffold"),
52  KLocalizedString(), "http://www.kde.org");
53 
54  aboutData.addAuthor(ki18n("Michael Zanetti"), ki18n("Maintainer"), "michal_zanetti@gmx.net");
55  aboutData.addAuthor(ki18n("Frank Scheffold"), ki18n("Developer"), "fscheffold@googlemail.com");
56  aboutData.addCredit(ki18n("Gav Wood"), ki18n("Original KDELirc Developer"), "gav.wood@kde.org");
57 
58  m_applicationData = KComponentData(aboutData);
59 
60  connect(RemoteControlManager::notifier(), SIGNAL(statusChanged(bool)), this, SLOT(slotStatusChanged(bool)));
61  connect(RemoteControlManager::notifier(), SIGNAL(remoteControlAdded(QString)), this, SLOT(slotRemoteControlAdded(QString)));
62  connect(RemoteControlManager::notifier(), SIGNAL(remoteControlRemoved(QString)), this, SLOT(slotRemoteControlRemoved(QString)));
63 
64  m_remoteList.loadFromConfig(QLatin1String( "kremotecontrolrc" ));
65  KConfig config(QLatin1String( "kremotecontrolrc" ));
66  KConfigGroup globalGroup(&config, "Global");
67  if(globalGroup.readEntry("ShowTrayIcon", false)){
68  kDebug() << "starting notifier item";
69  KToolInvocation::kdeinitExec(QLatin1String( "krcdnotifieritem" ));
70  } else {
71  emit unloadTray();
72  }
73 
74  foreach(const QString &remote, RemoteControl::allRemoteNames()){
75  RemoteControl *rc = new RemoteControl(remote);
76  kDebug() << "connecting to remote" << remote;
77  connect(rc, SIGNAL(buttonPressed(RemoteControlButton)),
78  this, SLOT(gotMessage(RemoteControlButton)));
79  }
80 
81  m_modeSwitchTimer.setSingleShot(true);
82 }
83 
84 KRemoteControlDaemon::~KRemoteControlDaemon() {
85  emit unloadTray();
86 }
87 
88 void KRemoteControlDaemon::slotStatusChanged(bool connected) {
89  if(connected){
90  foreach(const QString &remote, RemoteControl::allRemoteNames()){
91  RemoteControl *rc = new RemoteControl(remote);
92  kDebug() << "connecting to remote" << remote;
93  connect(rc,
94  SIGNAL(buttonPressed(RemoteControlButton)),
95  this,
96  SLOT(gotMessage(RemoteControlButton)));
97  }
98  }
99  kDebug() << "connection changed" << connected;
100  emit connectionChanged(connected);
101 }
102 
103 void KRemoteControlDaemon::gotMessage(const RemoteControlButton& button) {
104  kDebug()<< "Got message from remote " << button.remoteName() << " button " << button.name() << "repeat" << button.repeatCounter();
105  Remote *remote = m_remoteList.remote(button.remoteName());
106  if(!remote){
107  kDebug()<< "No remote found for remote" << button.remoteName();
108  return;
109  }
110 
111  if(eventsIgnored(remote->name())){
112  kDebug() << "Events for "<< remote->name() << " are currently ignored";
113  return;
114  }
115 
116  emit(buttonPressed());
117 
118  if(remote->currentMode()){
119  QVector<Action*> actionList;
120  if(remote->currentMode() != remote->masterMode()){
121  actionList += remote->masterMode()->actionsForButton(button.name());
122  }
123  actionList += remote->currentMode()->actionsForButton(button.name());
124  if(button.repeatCounter() == 0 && remote->nextMode(button.name())){
125  Mode *mode = remote->currentMode();
126  notifyModeChanged(remote);
127  if(remote->currentMode()-> doAfter()){
128  actionList += remote->currentMode()->actionsForButton(button.name());
129  }
130  emit(modeChanged(remote->name(), mode->name()));
131  }
132  foreach(Action *action, actionList){
133  if(action->repeat() || (button.repeatCounter() == 0)) {
134  kDebug() << "executing " << action->name() << action->description() << "repeat" << action->repeat();
135  ExecutionEngine::executeAction(action);
136  } else {
137  kDebug() << "not executing because of repeatblock. repeat:" << action->repeat() << "counter:" << button.repeatCounter();
138  }
139  }
140  }
141 }
142 
143 void KRemoteControlDaemon::reloadConfiguration() {
144  foreach(Remote *remote, m_remoteList){
145  delete remote;
146  }
147  m_remoteList.clear();
148  m_remoteList.loadFromConfig(QLatin1String( "kremotecontrolrc" ));
149  KConfig config(QLatin1String( "kremotecontrolrc" ));
150  KConfigGroup globalGroup(&config, "Global");
151 
152  if(globalGroup.readEntry("ShowTrayIcon", false)){
153  kDebug() << "starting notifier item";
154  KToolInvocation::kdeinitExec(QLatin1String( "krcdnotifieritem" ));
155  } else {
156  emit unloadTray();
157  }
158 
159  notifyEvent(i18n("Configuration reloaded."));
160  foreach(const Remote *remote, m_remoteList){
161  emit modeChanged(remote->name(), remote->masterMode()->name());
162  }
163 }
164 
165 void KRemoteControlDaemon::changeMode(const QString& remoteName, Mode* mode) {
166  Remote *remote = m_remoteList.remote(remoteName);
167  if(remote && remote->allModes().contains(mode)){
168  remote->setCurrentMode(mode);
169  }
170 }
171 
172 void KRemoteControlDaemon::ignoreButtonEvents(const QString& remoteName) {
173  if(remoteName.isEmpty()){
174  foreach(const Remote *remote, m_remoteList){
175  kDebug() << "muting remote" << remote->name();
176  m_ignoreNextButtonList.append(remote->name());
177  }
178  m_ignoreNextButtonList.removeDuplicates();
179  } else {
180  kDebug() << "muting remote" << remoteName;
181  m_ignoreNextButtonList.append(remoteName);
182  m_ignoreNextButtonList.removeDuplicates();
183  }
184 }
185 
186 void KRemoteControlDaemon::considerButtonEvents(const QString& remoteName) {
187  if(remoteName.isEmpty()){
188  m_remoteList.clear();
189  } else {
190  foreach(const Remote *remote, m_remoteList){
191  kDebug() << "unmuting remote" << remote->name();
192  m_ignoreNextButtonList.removeAll(remote->name());
193  }
194  }
195 }
196 
197 void KRemoteControlDaemon::slotRemoteControlAdded(const QString& name) {
198  if(m_remoteList.remote(name)){
199  kDebug() << "remote found";
200  notifyEvent(i18n("The remote control %1 is now available.", name));
201  }else{
202  kDebug() << "remote not found";
203  KNotification *notification = KNotification::event(QLatin1String( "global_event" ), i18n("An unconfigured remote control %1 is now available.", name),
204  DesktopIcon(QLatin1String( "infrared-remote" )), 0, KNotification::Persistant, m_applicationData);
205  notification->setActions(QStringList() << i18nc("Configure the remote", "Configure remote"));
206  connect(notification, SIGNAL(activated(uint)), SLOT(lauchKcmShell()));
207  }
208  emit remoteControlAdded(name);
209 }
210 
211 void KRemoteControlDaemon::lauchKcmShell() {
212  kDebug() << "Launch kcmshell";
213  KToolInvocation::startServiceByDesktopName(QLatin1String( "kcm_remotecontrol" ));
214 }
215 
216 void KRemoteControlDaemon::slotRemoteControlRemoved(const QString& name) {
217  notifyEvent(i18n("The remote %1 was removed from system.", name));
218  emit remoteControlRemoved(name);
219 }
220 
221 bool KRemoteControlDaemon::changeMode(const QString& remoteName, const QString& modeName) {
222  Remote *remote = m_remoteList.remote(remoteName);
223  if(remote){
224  foreach(Mode *mode, remote-> allModes()){
225  if(mode->name() == modeName){
226  remote->setCurrentMode(mode);
227  notifyModeChanged(remote);
228  return true;
229  }
230  }
231  }
232  return false;
233 }
234 
235 QStringList KRemoteControlDaemon::modesForRemote(const QString& remoteName) {
236  QStringList list;
237  Remote *remote = m_remoteList.remote(remoteName);
238  if(remote){
239  foreach(const Mode *mode, remote->allModes()){
240  list << mode->name();
241  }
242  }
243  return list;
244 }
245 
246 QStringList KRemoteControlDaemon::configuredRemotes() {
247  QStringList list;
248  foreach(Remote *remote, m_remoteList){
249  list << remote->name();
250  }
251  return list;
252 }
253 
254 void KRemoteControlDaemon::notifyModeChanged(Remote* remote) {
255  if(m_notification) {
256  m_notification->setText(QLatin1String( "<b>" ) + remote->name() + QLatin1String( ":</b><br>" ) + i18n("Mode switched to %1" , remote->currentMode()->name()));
257  m_notification->setPixmap(DesktopIcon(remote->currentMode()->iconName().isEmpty() ? QLatin1String( "infrared-remote" ) : remote->currentMode()->iconName()));
258  m_notification->update();
259  m_modeSwitchTimer.start(5000);
260  } else {
261  m_notification = KNotification::event(QLatin1String( "mode_event" ),
262  QLatin1String( "<b>" ) + remote->name() + QLatin1String( ":</b><br>" ) + i18n("Mode switched to %1" , remote->currentMode()->name()),
263  DesktopIcon(remote->currentMode()->iconName().isEmpty() ? QLatin1String( "infrared-remote" ) : remote->currentMode()->iconName())
264  , 0, KNotification::Persistent, m_applicationData);
265  m_modeSwitchTimer.start(5000);
266  connect(&m_modeSwitchTimer, SIGNAL(timeout()), m_notification, SLOT(close()));
267  }
268 }
269 
270 QString KRemoteControlDaemon::currentMode(const QString& remoteName) {
271  Remote *remote = m_remoteList.remote(remoteName);
272  if(remote){
273  return remote->currentMode()->name();
274  }
275  return QLatin1String( "modeNotFound" );
276 }
277 
278 QString KRemoteControlDaemon::modeIcon(const QString &remoteName, const QString& modeName) {
279  Remote *remote = m_remoteList.remote(remoteName);
280  if(remote){
281  Mode *mode = remote->modeByName(modeName);
282  if(mode){
283  return mode->iconName();
284  }
285  }
286  return QString();
287 }
288 
289 void KRemoteControlDaemon::notifyEvent(const QString& message, const QString& iconName, const QString& event) {
290  KNotification::event(event, message, DesktopIcon(iconName), 0, KNotification::CloseOnTimeout, m_applicationData);
291 }
292 
293 bool KRemoteControlDaemon::eventsIgnored(const QString& remoteName) {
294  return m_ignoreNextButtonList.contains(remoteName);
295 }
KRemoteControlDaemon::configuredRemotes
QStringList configuredRemotes()
Definition: kremotecontroldaemon.cpp:246
KRemoteControlDaemon::modeChanged
void modeChanged(const QString &remoteName, const QString &modeName)
RemoteList::remote
Remote * remote(const QString &remoteName)
Definition: remotelist.cpp:135
KRemoteControlDaemon::modesForRemote
QStringList modesForRemote(const QString &remoteName)
Definition: kremotecontroldaemon.cpp:235
KRemoteControlDaemon::remoteControlRemoved
void remoteControlRemoved(const QString &remote)
Remote::name
QString name() const
Definition: remote.cpp:247
Action::description
virtual QString description() const =0
dbusinterface.h
KRemoteControlDaemon::~KRemoteControlDaemon
virtual ~KRemoteControlDaemon()
Definition: kremotecontroldaemon.cpp:84
RemoteControl::allRemoteNames
static QStringList allRemoteNames()
Get the Names of the available remotes in the system.
Definition: remotecontrol.cpp:37
KRemoteControlDaemon::buttonPressed
void buttonPressed()
KRemoteControlDaemon::ignoreButtonEvents
void ignoreButtonEvents(const QString &remoteName)
Definition: kremotecontroldaemon.cpp:172
KDEDModule
RemoteControlButton::remoteName
QString remoteName() const
Retrieves the name of the RemoteControl this button comes from.
Definition: remotecontrolbutton.cpp:305
KRemoteControlDaemon::reloadConfiguration
void reloadConfiguration()
Definition: kremotecontroldaemon.cpp:143
Remote::modeByName
Mode * modeByName(const QString &name) const
Definition: remote.cpp:334
Mode
Definition: mode.h:31
ExecutionEngine::executeAction
void executeAction(Action *action)
Definition: executionengine.cpp:50
QVector
QObject
Remote::allModes
QVector< Mode * > allModes() const
Definition: remote.cpp:269
Action
Definition: action.h:30
Mode::actionsForButton
QVector< Action * > actionsForButton(const QString &button) const
Definition: mode.cpp:93
RemoteList::loadFromConfig
void loadFromConfig(const QString &configName)
Definition: remotelist.cpp:74
Action::name
virtual QString name() const =0
RemoteControl
Definition: remotecontrol.h:35
action.h
KRemoteControlDaemon::currentMode
QString currentMode(const QString &remoteName)
Definition: kremotecontroldaemon.cpp:270
RemoteControlButton::name
QString name() const
Retrieves the name of the Button.
Definition: remotecontrolbutton.cpp:315
KRemoteControlDaemon::eventsIgnored
bool eventsIgnored(const QString &remoteName)
Definition: kremotecontroldaemon.cpp:293
kremotecontroldaemon.h
RemoteControlManager::notifier
KREMOTECONTROL_EXPORT Notifier * notifier()
Definition: remotecontrolmanager.cpp:37
Remote::currentMode
Mode * currentMode() const
Definition: remote.cpp:343
KRemoteControlDaemon::modeIcon
QString modeIcon(const QString &remoteName, const QString &modeName)
Definition: kremotecontroldaemon.cpp:278
executionengine.h
KRemoteControlDaemon::unloadTray
void unloadTray()
KRemoteControlDaemon::connectionChanged
void connectionChanged(bool connected)
Remote::masterMode
Mode * masterMode() const
Definition: remote.cpp:300
KRemoteControlDaemon::considerButtonEvents
void considerButtonEvents(const QString &remoteName)
Definition: kremotecontroldaemon.cpp:186
KRemoteControlDaemon::remoteControlAdded
void remoteControlAdded(const QString &remote)
Action::repeat
bool repeat() const
Definition: action.cpp:45
KRemoteControlDaemon
Definition: kremotecontroldaemon.h:41
KRemoteControlDaemon::changeMode
void changeMode(const QString &remoteName, Mode *mode)
Definition: kremotecontroldaemon.cpp:165
RemoteControlManager::connected
KREMOTECONTROL_EXPORT bool connected()
Get the manager connection state.
Definition: remotecontrolmanager.cpp:32
mode.h
RemoteControlButton::repeatCounter
int repeatCounter() const
Retrieves the repeat count for the buttonpress.
Definition: remotecontrolbutton.cpp:434
Mode::name
QString name() const
Definition: mode.cpp:36
RemoteControlButton
Definition: remotecontrolbutton.h:30
Remote::setCurrentMode
void setCurrentMode(Mode *mode)
Definition: remote.cpp:351
Remote
Definition: remote.h:32
Remote::nextMode
bool nextMode(const QString &button)
Definition: remote.cpp:359
Mode::iconName
QString iconName() const
Definition: mode.cpp:40
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