• 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
  • krcdnotifieritem
krcdnotifieritem.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 "krcdnotifieritem.h"
21 #include "dbusinterface.h"
22 #include "remotecontrolmanager.h"
23 
24 #include <klocalizedstring.h>
25 #include <kicon.h>
26 #include <kiconloader.h>
27 #include <ktoolinvocation.h>
28 #include <kdebug.h>
29 
30 #include <QtCore/QTimer>
31 #include <QtDBus/QDBusConnection>
32 
33 KrcdNotifierItem::KrcdNotifierItem(){
34  setCategory(KStatusNotifierItem::Hardware);
35  updateTray();
36  setContextMenu(&m_menu);
37 
38  // No need for close button...
39  setStandardActionsEnabled(false);
40  setAssociatedWidget(&m_menu);
41  updateContextMenu();
42  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "connectionChanged" ), this, SLOT(updateTray()));
43  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "remoteControlAdded" ), this, SLOT(updateTray()));
44  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "remoteControlAdded" ), this, SLOT(updateContextMenu()));
45  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "remoteControlRemoved" ), this, SLOT(updateTray()));
46  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "remoteControlRemoved" ), this, SLOT(updateContextMenu()));
47  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "buttonPressed" ), this, SLOT(flash()));
48  QDBusConnection::sessionBus().connect(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kremotecontroldaemon" ), QLatin1String( "org.kde.krcd" ), QLatin1String( "modeChanged" ), this, SLOT(updateContextMenu()));
49 }
50 
51 void KrcdNotifierItem::updateTray() {
52  QString toolTipHeader = i18n("Remote Controls\n");
53  QString toolTip;
54  QString icon = QLatin1String( "krcd" );
55  if (!RemoteControlManager::connected()) {
56  toolTipHeader += i18nc("The state of kremotecontrol", "Stopped");
57  toolTip += i18n("No Remote Control is currently available.");
58  icon = QLatin1String( "krcd_off" );
59  setStatus(Passive);
60  } else {
61  toolTipHeader += i18nc("The state of kremotecontrol", "Ready");
62  foreach(const QString &remote, DBusInterface::getInstance()->configuredRemotes()) {
63  QString mode = DBusInterface::getInstance()->currentMode(remote);
64  toolTip += remote + QLatin1String( " <i>(" ) + mode + QLatin1String( ")</i><br>" );
65  }
66  setStatus(Active);
67  }
68  setToolTip(QLatin1String( "infrared-remote" ), toolTipHeader, toolTip);
69  setIconByName(icon);
70 }
71 
72 void KrcdNotifierItem::updateContextMenu(){
73  m_menu.clear();
74  m_menu.addTitle(KIcon( QLatin1String( "infrared-remote")), i18n( "Remote Controls" ) );
75  m_menu.addAction(SmallIcon(QLatin1String( "configure" )), i18n("&Configure..."), this, SLOT(slotConfigure()));
76 
77  foreach(const QString &remote, RemoteControl::allRemoteNames()){
78  KMenu *modeMenu = new KMenu(remote, &m_menu);
79  QActionGroup *actionGroup = new QActionGroup(modeMenu);
80  actionGroup->setExclusive(true);
81  modeMenu->addTitle(KIcon( QLatin1String( "infrared-remote")), i18n("Switch mode to" ));
82  foreach(const QString &mode, DBusInterface::getInstance()->modesForRemote(remote)){
83  QAction *entry = modeMenu->addAction(mode);
84  entry->setActionGroup(actionGroup);
85  entry->setCheckable(true);
86  entry->setIcon(KIcon(DBusInterface::getInstance()->modeIcon(remote, mode)));
87  if(DBusInterface::getInstance()->currentMode(remote) == mode){
88  entry->setChecked(true);
89  }
90  entry->setData(QStringList() << remote << mode);
91  }
92  modeMenu->addSeparator();
93  QAction *entry = modeMenu->addAction(i18n("Pause remote"));
94  entry->setCheckable(true);
95  entry->setData(QStringList() << remote);
96  if(DBusInterface::getInstance()->eventsIgnored(remote)){
97  entry->setChecked(true);
98  }
99  m_menu.addMenu(modeMenu);
100  connect(modeMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotModeSelected(QAction*)));
101 
102  }
103 }
104 
105 void KrcdNotifierItem::slotConfigure() {
106  KToolInvocation::startServiceByDesktopName(QLatin1String( "kcm_remotecontrol" ));
107 }
108 
109 void KrcdNotifierItem::slotModeSelected(QAction* action) {
110  if(action->data().toStringList().count() > 1){
111  QString remote = action->data().toStringList().first();
112  QString mode = action->data().toStringList().last();
113  DBusInterface::getInstance()->changeMode(remote, mode);
114  action->setChecked(true);
115  } else {
116  if(action->isChecked()){
117  DBusInterface::getInstance()->ignoreButtonEvents(action->data().toStringList().first());
118  } else {
119  DBusInterface::getInstance()->considerButtonEvents(action->data().toStringList().first());
120  }
121  }
122  updateTray();
123 }
124 
125 void KrcdNotifierItem::flash() {
126  setIconByName(QLatin1String( "krcd_flash" ));
127  QTimer::singleShot(200, this, SLOT(flashOff()));
128 }
129 
130 void KrcdNotifierItem::flashOff() {
131  setIconByName(QLatin1String( "krcd" ));
132 }
dbusinterface.h
RemoteControl::allRemoteNames
static QStringList allRemoteNames()
Get the Names of the available remotes in the system.
Definition: remotecontrol.cpp:37
DBusInterface::considerButtonEvents
void considerButtonEvents(const QString &remoteName)
Definition: dbusinterface.cpp:270
DBusInterface::getInstance
static DBusInterface * getInstance()
Definition: dbusinterface.cpp:50
DBusInterface::changeMode
void changeMode(const QString &remoteName, const QString &modeName)
Definition: dbusinterface.cpp:485
KrcdNotifierItem::KrcdNotifierItem
KrcdNotifierItem()
Definition: krcdnotifieritem.cpp:33
krcdnotifieritem.h
DBusInterface::currentMode
QString currentMode(const QString &remoteName)
Definition: dbusinterface.cpp:496
remotecontrolmanager.h
DBusInterface::ignoreButtonEvents
void ignoreButtonEvents(const QString &remoteName)
Definition: dbusinterface.cpp:280
RemoteControlManager::connected
KREMOTECONTROL_EXPORT bool connected()
Get the manager connection state.
Definition: remotecontrolmanager.cpp:32
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