[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/krfb/krfb
From:       George Kiagiadakis <kiagiadakis.george () gmail ! com>
Date:       2010-11-10 18:57:37
Message-ID: 20101110185737.CA51DAC8B3 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1195294 by gkiagia:

Show actions for controlling the clients in the tray menu. BUG: 210699

This currently includes a "disconnect" action and a toggle action
for enabling/disabling input devices control, which was there previously
but applied only to one client. With the current design every client gets
its own control actions.

 M  +6 -0      rfbservermanager.cpp  
 M  +113 -45   trayicon.cpp  
 M  +6 -9      trayicon.h  


--- trunk/KDE/kdenetwork/krfb/krfb/rfbservermanager.cpp #1195293:1195294
@@ -32,6 +32,7 @@
 #include <KDebug>
 #include <KLocale>
 #include <KUser>
+#include <KNotification>
 
 static const char *cur =
     "                   "
@@ -209,6 +210,9 @@
     }
     d->clients.insert(cc);
 
+    KNotification::event("UserAcceptsConnection",
+                         i18n("The remote user %1 is now connected.", cc->name()));
+
     Q_EMIT clientConnected(cc);
 }
 
@@ -221,6 +225,8 @@
         d->rfbUpdateTimer.stop();
     }
 
+    KNotification::event("ConnectionClosed", i18n("The remote user %1 disconnected.", cc->name()));
+
     Q_EMIT clientDisconnected(cc);
 }
 
--- trunk/KDE/kdenetwork/krfb/krfb/trayicon.cpp #1195293:1195294
@@ -1,24 +1,27 @@
-/***************************************************************************
-                                trayicon.cpp
-                             -------------------
-    begin                : Tue Dec 11 2001
-    copyright            : (C) 2001-2002 by Tim Jansen
-    email                : tim@tjansen.de
- ***************************************************************************/
+/*
+    Copyright (C) 2010 Collabora Ltd <info@collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
+    Copyright (C) 2001-2002 Tim Jansen <tim@tjansen.de>
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
 
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include "trayicon.h"
 
 #include "invitedialog.h"
 #include "manageinvitationsdialog.h"
+#include "rfbservermanager.h"
+#include "rfbclient.h"
 
 #include <KAboutApplicationDialog>
 #include <KActionCollection>
@@ -26,9 +29,71 @@
 #include <KGlobal>
 #include <KLocale>
 #include <KMenu>
-#include <KNotification>
 #include <KStandardAction>
+#include <KDebug>
 
+
+class ClientActions
+{
+public:
+    ClientActions(RfbClient *client, KMenu *menu, QAction *before);
+    virtual ~ClientActions();
+
+private:
+    KMenu *m_menu;
+    QAction *m_title;
+    QAction *m_disconnectAction;
+    QAction *m_enableControlAction;
+    QAction *m_separator;
+};
+
+ClientActions::ClientActions(RfbClient* client, KMenu* menu, QAction* before)
+    : m_menu(menu)
+{
+    m_title = m_menu->addTitle(client->name(), before);
+
+    m_disconnectAction = new KAction(i18n("Disconnect"), m_menu);
+    m_menu->insertAction(before, m_disconnectAction);
+
+    QObject::connect(m_disconnectAction, SIGNAL(triggered()), client, SLOT(closeConnection()));
+
+    if (client->controlCanBeEnabled()) {
+        m_enableControlAction = new KToggleAction(i18n("Enable Remote Control"), m_menu);
+        m_enableControlAction->setChecked(client->controlEnabled());
+        m_menu->insertAction(before, m_enableControlAction);
+
+        QObject::connect(m_enableControlAction, SIGNAL(triggered(bool)),
+                         client, SLOT(setControlEnabled(bool)));
+        QObject::connect(client, SIGNAL(controlEnabledChanged(bool)),
+                         m_enableControlAction, SLOT(setChecked(bool)));
+    } else {
+        m_enableControlAction = NULL;
+    }
+
+    m_separator = m_menu->insertSeparator(before);
+}
+
+ClientActions::~ClientActions()
+{
+    kDebug();
+
+    m_menu->removeAction(m_title);
+    delete m_title;
+
+    m_menu->removeAction(m_disconnectAction);
+    delete m_disconnectAction;
+
+    if (m_enableControlAction) {
+        m_menu->removeAction(m_enableControlAction);
+        delete m_enableControlAction;
+    }
+
+    m_menu->removeAction(m_separator);
+    delete m_separator;
+}
+
+//**********
+
 TrayIcon::TrayIcon(KDialog *d)
     : KStatusNotifierItem(d)
 {
@@ -37,49 +102,52 @@
     setToolTipTitle(i18n("Desktop Sharing - disconnected"));
     setCategory(KStatusNotifierItem::ApplicationStatus);
 
-    enableControlAction = new KToggleAction(i18n("Enable Remote Control"), actionCollection());
-    enableControlAction->setCheckedState(KGuiItem(i18n("Disable Remote Control")));
-    enableControlAction->setEnabled(false);
-    connect(enableControlAction, SIGNAL(toggled(bool)), SIGNAL(enableDesktopControl(bool)));
-    contextMenu()->addAction(enableControlAction);
+    connect(RfbServerManager::instance(), SIGNAL(clientConnected(RfbClient*)),
+            this, SLOT(onClientConnected(RfbClient*)));
+    connect(RfbServerManager::instance(), SIGNAL(clientDisconnected(RfbClient*)),
+            this, SLOT(onClientDisconnected(RfbClient*)));
 
-    contextMenu()->addSeparator();
-    contextMenu()->addAction(KStandardAction::aboutApp(this, SLOT(showAbout()), actionCollection()));
+    m_aboutAction = KStandardAction::aboutApp(this, SLOT(showAbout()), actionCollection());
+    contextMenu()->addAction(m_aboutAction);
 }
 
-void TrayIcon::showAbout()
+void TrayIcon::onClientConnected(RfbClient* client)
 {
-    KDialog *dlg = new KAboutApplicationDialog(KGlobal::mainComponent().aboutData());
-    dlg->setAttribute(Qt::WA_DeleteOnClose, true);
-    dlg->show();
+    kDebug();
+
+    if (m_clientActions.isEmpty()) { //first client connected
+        setIconByName("krfb");
+        setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
+        setStatus(KStatusNotifierItem::Active);
+    } else { //Nth client connected, N != 1
+        setToolTipTitle(i18n("Desktop Sharing - connected"));
 }
 
-void TrayIcon::showConnectedMessage(const QString &host)
+    m_clientActions[client] = new ClientActions(client, contextMenu(), m_aboutAction);
+}
+
+void TrayIcon::onClientDisconnected(RfbClient* client)
 {
-    setIconByPixmap(KIcon("krfb"));
-    KNotification::event("UserAcceptsConnection",
-                         i18n("The remote user %1 is now connected.",
-                              host));
-    setToolTipTitle(i18n("Desktop Sharing - connected with %1", host));
+    kDebug();
 
-    setStatus(KStatusNotifierItem::Active);
-}
+    ClientActions *actions = m_clientActions.take(client);
+    delete actions;
 
-void TrayIcon::showDisconnectedMessage()
-{
+    if (m_clientActions.isEmpty()) {
+        setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
     setToolTipTitle(i18n("Desktop Sharing - disconnected"));
-    setIconByPixmap(KIcon("krfb").pixmap(22, 22, KIcon::Disabled));
-    KNotification::event("ConnectionClosed", i18n("The remote user has closed the connection."));
-
     setStatus(KStatusNotifierItem::Passive);
-
-    Q_EMIT disconnectedMessageDisplayed();
+    } else if (m_clientActions.size() == 1) { //clients number dropped back to 1
+        RfbClient *client = m_clientActions.constBegin().key();
+        setToolTipTitle(i18n("Desktop Sharing - connected with %1", client->name()));
 }
+}
 
-void TrayIcon::setDesktopControlSetting(bool b)
+void TrayIcon::showAbout()
 {
-    enableControlAction->setEnabled(true);
-    enableControlAction->setChecked(b);
+    KDialog *dlg = new KAboutApplicationDialog(KGlobal::mainComponent().aboutData());
+    dlg->setAttribute(Qt::WA_DeleteOnClose, true);
+    dlg->show();
 }
 
 #include "trayicon.moc"
--- trunk/KDE/kdenetwork/krfb/krfb/trayicon.h #1195293:1195294
@@ -22,6 +22,8 @@
 #include <KToggleAction>
 
 class KDialog;
+class RfbClient;
+class ClientActions;
 
 /**
   * Implements the trayicon.
@@ -34,19 +36,14 @@
 public:
     TrayIcon(KDialog *);
 
-signals:
-    void disconnectedMessageDisplayed();
-    void enableDesktopControl(bool);
-
 public Q_SLOTS:
-    void showConnectedMessage(const QString &host);
-    void showDisconnectedMessage();
-    void setDesktopControlSetting(bool);
+    void onClientConnected(RfbClient *client);
+    void onClientDisconnected(RfbClient *client);
     void showAbout();
 
 private:
-    KAction *aboutAction;
-    KToggleAction *enableControlAction;
+    KAction *m_aboutAction;
+    QHash<RfbClient*, ClientActions*> m_clientActions;
 };
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic