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

krfb

  • sources
  • kde-4.14
  • kdenetwork
  • krfb
  • krfb
trayicon.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Collabora Ltd <info@collabora.co.uk>
3  @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
4  Copyright (C) 2001-2002 Tim Jansen <tim@tjansen.de>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "trayicon.h"
20 
21 #include "mainwindow.h"
22 #include "rfbservermanager.h"
23 #include "rfbclient.h"
24 
25 #include <KAboutApplicationDialog>
26 #include <KActionCollection>
27 #include <KDialog>
28 #include <KGlobal>
29 #include <KLocale>
30 #include <KMenu>
31 #include <KStandardAction>
32 #include <KDebug>
33 
34 
35 class ClientActions
36 {
37 public:
38  ClientActions(RfbClient *client, KMenu *menu, QAction *before);
39  virtual ~ClientActions();
40 
41 private:
42  KMenu *m_menu;
43  QAction *m_title;
44  QAction *m_disconnectAction;
45  QAction *m_enableControlAction;
46  QAction *m_separator;
47 };
48 
49 ClientActions::ClientActions(RfbClient* client, KMenu* menu, QAction* before)
50  : m_menu(menu)
51 {
52  m_title = m_menu->addTitle(client->name(), before);
53 
54  m_disconnectAction = new KAction(i18n("Disconnect"), m_menu);
55  m_menu->insertAction(before, m_disconnectAction);
56 
57  QObject::connect(m_disconnectAction, SIGNAL(triggered()), client, SLOT(closeConnection()));
58 
59  if (client->controlCanBeEnabled()) {
60  m_enableControlAction = new KToggleAction(i18n("Enable Remote Control"), m_menu);
61  m_enableControlAction->setChecked(client->controlEnabled());
62  m_menu->insertAction(before, m_enableControlAction);
63 
64  QObject::connect(m_enableControlAction, SIGNAL(triggered(bool)),
65  client, SLOT(setControlEnabled(bool)));
66  QObject::connect(client, SIGNAL(controlEnabledChanged(bool)),
67  m_enableControlAction, SLOT(setChecked(bool)));
68  } else {
69  m_enableControlAction = NULL;
70  }
71 
72  m_separator = m_menu->insertSeparator(before);
73 }
74 
75 ClientActions::~ClientActions()
76 {
77  kDebug();
78 
79  m_menu->removeAction(m_title);
80  delete m_title;
81 
82  m_menu->removeAction(m_disconnectAction);
83  delete m_disconnectAction;
84 
85  if (m_enableControlAction) {
86  m_menu->removeAction(m_enableControlAction);
87  delete m_enableControlAction;
88  }
89 
90  m_menu->removeAction(m_separator);
91  delete m_separator;
92 }
93 
94 //**********
95 
96 TrayIcon::TrayIcon(QWidget *mainWindow)
97  : KStatusNotifierItem(mainWindow)
98 {
99  setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
100 
101  setToolTipTitle(i18n("Desktop Sharing - disconnected"));
102  setCategory(KStatusNotifierItem::ApplicationStatus);
103 
104  connect(RfbServerManager::instance(), SIGNAL(clientConnected(RfbClient*)),
105  this, SLOT(onClientConnected(RfbClient*)));
106  connect(RfbServerManager::instance(), SIGNAL(clientDisconnected(RfbClient*)),
107  this, SLOT(onClientDisconnected(RfbClient*)));
108 
109  m_aboutAction = KStandardAction::aboutApp(this, SLOT(showAbout()), actionCollection());
110  contextMenu()->addAction(m_aboutAction);
111 }
112 
113 void TrayIcon::onClientConnected(RfbClient* client)
114 {
115  kDebug();
116 
117  if (m_clientActions.isEmpty()) { //first client connected
118  setIconByName("krfb");
119  setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
120  setStatus(KStatusNotifierItem::Active);
121  } else { //Nth client connected, N != 1
122  setToolTipTitle(i18n("Desktop Sharing - connected"));
123  }
124 
125  m_clientActions[client] = new ClientActions(client, contextMenu(), m_aboutAction);
126 }
127 
128 void TrayIcon::onClientDisconnected(RfbClient* client)
129 {
130  kDebug();
131 
132  ClientActions *actions = m_clientActions.take(client);
133  delete actions;
134 
135  if (m_clientActions.isEmpty()) {
136  setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
137  setToolTipTitle(i18n("Desktop Sharing - disconnected"));
138  setStatus(KStatusNotifierItem::Passive);
139  } else if (m_clientActions.size() == 1) { //clients number dropped back to 1
140  RfbClient *client = m_clientActions.constBegin().key();
141  setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
142  }
143 }
144 
145 void TrayIcon::showAbout()
146 {
147  KDialog *dlg = new KAboutApplicationDialog(KGlobal::mainComponent().aboutData());
148  dlg->setAttribute(Qt::WA_DeleteOnClose, true);
149  dlg->show();
150 }
151 
152 #include "trayicon.moc"
QWidget
RfbClient::controlEnabled
bool controlEnabled
Definition: krfb/rfbclient.h:29
QHash::size
int size() const
TrayIcon::onClientConnected
void onClientConnected(RfbClient *client)
Definition: trayicon.cpp:113
RfbClient::controlCanBeEnabled
static bool controlCanBeEnabled()
Definition: rfbclient.cpp:67
mainwindow.h
rfbclient.h
trayicon.h
TrayIcon::onClientDisconnected
void onClientDisconnected(RfbClient *client)
Definition: trayicon.cpp:128
QHash::constBegin
const_iterator constBegin() const
RfbClient
Definition: krfb/rfbclient.h:26
RfbServerManager::instance
static RfbServerManager * instance()
Definition: rfbservermanager.cpp:87
QHash::take
T take(const Key &key)
QHash::isEmpty
bool isEmpty() const
QAction
RfbClient::name
virtual QString name() const
Returns a name for the client, to be shown to the user.
Definition: rfbclient.cpp:61
KStatusNotifierItem
TrayIcon::showAbout
void showAbout()
Definition: trayicon.cpp:145
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
rfbservermanager.h
TrayIcon::TrayIcon
TrayIcon(QWidget *mainWindow)
Definition: trayicon.cpp:96
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

krfb

Skip menu "krfb"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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