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

krfb

  • sources
  • kde-4.12
  • 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 "invitedialog.h"
22 #include "manageinvitationsdialog.h"
23 #include "rfbservermanager.h"
24 #include "rfbclient.h"
25 
26 #include <KAboutApplicationDialog>
27 #include <KActionCollection>
28 #include <KDialog>
29 #include <KGlobal>
30 #include <KLocale>
31 #include <KMenu>
32 #include <KStandardAction>
33 #include <KDebug>
34 
35 
36 class ClientActions
37 {
38 public:
39  ClientActions(RfbClient *client, KMenu *menu, QAction *before);
40  virtual ~ClientActions();
41 
42 private:
43  KMenu *m_menu;
44  QAction *m_title;
45  QAction *m_disconnectAction;
46  QAction *m_enableControlAction;
47  QAction *m_separator;
48 };
49 
50 ClientActions::ClientActions(RfbClient* client, KMenu* menu, QAction* before)
51  : m_menu(menu)
52 {
53  m_title = m_menu->addTitle(client->name(), before);
54 
55  m_disconnectAction = new KAction(i18n("Disconnect"), m_menu);
56  m_menu->insertAction(before, m_disconnectAction);
57 
58  QObject::connect(m_disconnectAction, SIGNAL(triggered()), client, SLOT(closeConnection()));
59 
60  if (client->controlCanBeEnabled()) {
61  m_enableControlAction = new KToggleAction(i18n("Enable Remote Control"), m_menu);
62  m_enableControlAction->setChecked(client->controlEnabled());
63  m_menu->insertAction(before, m_enableControlAction);
64 
65  QObject::connect(m_enableControlAction, SIGNAL(triggered(bool)),
66  client, SLOT(setControlEnabled(bool)));
67  QObject::connect(client, SIGNAL(controlEnabledChanged(bool)),
68  m_enableControlAction, SLOT(setChecked(bool)));
69  } else {
70  m_enableControlAction = NULL;
71  }
72 
73  m_separator = m_menu->insertSeparator(before);
74 }
75 
76 ClientActions::~ClientActions()
77 {
78  kDebug();
79 
80  m_menu->removeAction(m_title);
81  delete m_title;
82 
83  m_menu->removeAction(m_disconnectAction);
84  delete m_disconnectAction;
85 
86  if (m_enableControlAction) {
87  m_menu->removeAction(m_enableControlAction);
88  delete m_enableControlAction;
89  }
90 
91  m_menu->removeAction(m_separator);
92  delete m_separator;
93 }
94 
95 //**********
96 
97 TrayIcon::TrayIcon(QWidget *mainWindow)
98  : KStatusNotifierItem(mainWindow)
99 {
100  setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
101 
102  setToolTipTitle(i18n("Desktop Sharing - disconnected"));
103  setCategory(KStatusNotifierItem::ApplicationStatus);
104 
105  connect(RfbServerManager::instance(), SIGNAL(clientConnected(RfbClient*)),
106  this, SLOT(onClientConnected(RfbClient*)));
107  connect(RfbServerManager::instance(), SIGNAL(clientDisconnected(RfbClient*)),
108  this, SLOT(onClientDisconnected(RfbClient*)));
109 
110  m_aboutAction = KStandardAction::aboutApp(this, SLOT(showAbout()), actionCollection());
111  contextMenu()->addAction(m_aboutAction);
112 }
113 
114 void TrayIcon::onClientConnected(RfbClient* client)
115 {
116  kDebug();
117 
118  if (m_clientActions.isEmpty()) { //first client connected
119  setIconByName("krfb");
120  setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
121  setStatus(KStatusNotifierItem::Active);
122  } else { //Nth client connected, N != 1
123  setToolTipTitle(i18n("Desktop Sharing - connected"));
124  }
125 
126  m_clientActions[client] = new ClientActions(client, contextMenu(), m_aboutAction);
127 }
128 
129 void TrayIcon::onClientDisconnected(RfbClient* client)
130 {
131  kDebug();
132 
133  ClientActions *actions = m_clientActions.take(client);
134  delete actions;
135 
136  if (m_clientActions.isEmpty()) {
137  setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
138  setToolTipTitle(i18n("Desktop Sharing - disconnected"));
139  setStatus(KStatusNotifierItem::Passive);
140  } else if (m_clientActions.size() == 1) { //clients number dropped back to 1
141  RfbClient *client = m_clientActions.constBegin().key();
142  setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
143  }
144 }
145 
146 void TrayIcon::showAbout()
147 {
148  KDialog *dlg = new KAboutApplicationDialog(KGlobal::mainComponent().aboutData());
149  dlg->setAttribute(Qt::WA_DeleteOnClose, true);
150  dlg->show();
151 }
152 
153 #include "trayicon.moc"
RfbClient::controlEnabled
bool controlEnabled
Definition: krfb/rfbclient.h:29
QWidget
invitedialog.h
TrayIcon::onClientConnected
void onClientConnected(RfbClient *client)
Definition: trayicon.cpp:114
RfbClient::controlCanBeEnabled
static bool controlCanBeEnabled()
Definition: rfbclient.cpp:67
rfbclient.h
trayicon.h
TrayIcon::onClientDisconnected
void onClientDisconnected(RfbClient *client)
Definition: trayicon.cpp:129
RfbClient
Definition: krfb/rfbclient.h:26
RfbServerManager::instance
static RfbServerManager * instance()
Definition: rfbservermanager.cpp:87
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:146
rfbservermanager.h
TrayIcon::TrayIcon
TrayIcon(QWidget *mainWindow)
Definition: trayicon.cpp:97
manageinvitationsdialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:10 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
  • 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