• 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
  • libkremotecontrol
  • backends
  • lirc
lircremotecontrolmanager.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) <2009> 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 "lircremotecontrolmanager.h"
21 #include "lircremotecontrol.h"
22 #include "lircclient.h"
23 
24 #include <unistd.h>
25 #include <sys/un.h>
26 #include <sys/socket.h>
27 
28 #include <kdebug.h>
29 
30 #include <QStringList>
31 #include <QLocalSocket>
32 
33 class LircRemoteControlManagerPrivate
34 {
35 public:
36  LircRemoteControlManagerPrivate();
37  bool connected;
38  bool cachedState;
39  LircClient *m_client;
40 
41  QHash<QString, LircRemoteControl *> remotes;
42 
43  bool recacheState();
44 
45 };
46 
47 LircRemoteControlManagerPrivate::LircRemoteControlManagerPrivate()
48  : connected(false), cachedState(false)
49 {
50  m_client = LircClient::self();
51 }
52 
53 bool LircRemoteControlManagerPrivate::recacheState()
54 {
55  connected = m_client->isConnected();
56  if(!connected){
57  connected = m_client->connectToLirc();
58  }
59 
60  if(cachedState != connected){
61  cachedState = connected;
62  return true;
63  } else {
64  return false;
65  }
66 }
67 
68 LircRemoteControlManager::LircRemoteControlManager(QObject * parent, const QVariantList & /*args */)
69  : RemoteControlManager(parent), d(new LircRemoteControlManagerPrivate())
70 {
71 
72  m_dirWatch.addFile("/var/run/lirc/lircd");
73  m_dirWatch.addFile("/dev/lircd");
74  connect(&m_dirWatch, SIGNAL(created(QString)), this, SLOT(reconnect()));
75 
76  if(d->recacheState()){
77  readRemotes();
78  }
79 
80  connect(d->m_client, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()));
81 }
82 
83 LircRemoteControlManager::~LircRemoteControlManager()
84 {
85  delete d;
86 }
87 
88 void LircRemoteControlManager::reconnect()
89 {
90 
91  if(!d->connected){
92  if(d->recacheState()){
93  readRemotes();
94  foreach(const QString &remote, m_remotes){
95  emit remoteControlAdded(remote);
96  }
97  emit statusChanged(true);
98  }
99  }
100 }
101 
102 void LircRemoteControlManager::connectionClosed(){
103  d->connected = false;
104  d->cachedState = false;
105  kDebug() << "Lirc now disconnected";
106  foreach(const QString &remote, m_remotes){
107  emit remoteControlRemoved(remote);
108  }
109  readRemotes();
110  emit statusChanged(false);
111 }
112 
113 void LircRemoteControlManager::newRemoteList(const QStringList &remoteList){
114  foreach(const QString &remote, m_remotes){
115  emit remoteControlRemoved(remote);
116  }
117  m_remotes = remoteList;
118  foreach(const QString &remote, m_remotes){
119  emit remoteControlAdded(remote);
120  }
121 
122 }
123 
124 bool LircRemoteControlManager::connected() const
125 {
126  return d->connected;
127 }
128 
129 void LircRemoteControlManager::readRemotes() {
130  m_remotes = d->m_client->remotes();
131 }
132 
133 QStringList LircRemoteControlManager::remoteNames() const
134 {
135  // Connect to lirc and read the available remotes
136  if(!d->connected){
137  kDebug() << "not connected... connecting to lircd";
138  if(!d->recacheState()){
139  kDebug() << "error: lirc not running";
140  return QStringList();
141  }
142  }
143 
144  return m_remotes;
145 
146 }
147 
148 Iface::RemoteControl * LircRemoteControlManager::createRemoteControl(const QString &name)
149 {
150  kDebug(1441) << name;
151 
152  // Check lirc if the requested remote is avaialble and create the interface
153  if (!remoteNames().contains(name)) {
154  kDebug() << "Remote Control not present in the available list, returning 0";
155  return 0;
156  }
157 
158  LircRemoteControl * rcInterface = 0;
159  QHash<QString, LircRemoteControl *>::Iterator it = d->remotes.find(name);
160  if (it == d->remotes.end()) {
161  kDebug() << "unknown interface:" << name << "creating it";
162  } else {
163  kDebug() << "Interface already created";
164  return it.value();
165  }
166 
167  rcInterface = new LircRemoteControl(name);
168 
169  return rcInterface;
170 }
171 
172 #include "lircremotecontrolmanager.moc"
LircRemoteControlManager::connected
bool connected() const
Get the manager connection state.
Definition: lircremotecontrolmanager.cpp:124
Iface::RemoteControlManager::remoteControlAdded
void remoteControlAdded(const QString &name)
This signal is emitted when a new remote control is available.
Iface::RemoteControlManager::statusChanged
void statusChanged(bool connected)
This signal is emitted when the system's connection state changes.
LircRemoteControlManager::LircRemoteControlManager
LircRemoteControlManager(QObject *parent, const QVariantList &args)
Definition: lircremotecontrolmanager.cpp:68
QObject
LircClient::self
static LircClient * self()
Get the instance,.
Definition: lircclient.cpp:57
LircClient
Definition: lircclient.h:37
LircRemoteControlManager::~LircRemoteControlManager
virtual ~LircRemoteControlManager()
Definition: lircremotecontrolmanager.cpp:83
Iface::RemoteControl
Definition: remotecontrolinterface.h:30
lircremotecontrol.h
lircremotecontrolmanager.h
Iface::RemoteControlManager::remoteControlRemoved
void remoteControlRemoved(const QString &name)
This signal is emitted when a remote control is not available anymore.
LircRemoteControl
Definition: lircremotecontrol.h:32
lircclient.h
RemoteControlManager::connected
KREMOTECONTROL_EXPORT bool connected()
Get the manager connection state.
Definition: remotecontrolmanager.cpp:32
LircRemoteControlManager::createRemoteControl
Iface::RemoteControl * createRemoteControl(const QString &)
Instantiates a new RemoteControlInterface object from this backend given its remote.
Definition: lircremotecontrolmanager.cpp:148
LircRemoteControlManager::remoteNames
QStringList remoteNames() const
Retrieves the list of all the remotes installed in the system.
Definition: lircremotecontrolmanager.cpp:133
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