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

List:       kde-commits
Subject:    playground/network/kopete
From:       George Goldberg <grundleborg () googlemail ! com>
Date:       2009-08-31 16:13:39
Message-ID: 1251735219.725901.28546.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1017828 by gberg:

Implement the share-my-desktop plugin. It now shows a button in the chat UI, which \
will ensure a stream channel of type rfb when clicked, leaving it for another APP to \
pick up and handle the tube.

 M  +4 -1      plugins/sharemydesktop/CMakeLists.txt  
 M  +6 -1      plugins/sharemydesktop/share-my-desktop-chat-ui.rc  
 M  +191 -1    plugins/sharemydesktop/share-my-desktop-gui-client.cpp  
 M  +59 -1     plugins/sharemydesktop/share-my-desktop-gui-client.h  
 M  +4 -0      plugins/sharemydesktop/share-my-desktop-plugin.cpp  
 M  +1 -1      protocols/telepathy/KopeteTelepathy/telepathychatsession.h  


--- trunk/playground/network/kopete/plugins/sharemydesktop/CMakeLists.txt \
#1017827:1017828 @@ -2,6 +2,8 @@
 
 include_directories (${CMAKE_CURRENT_SOURCE_DIR}
                      ${CMAKE_CURRENT_BINARY_DIR}
+                     \
${CMAKE_CURRENT_SOURCE_DIR}../../protocols/telepathy/KopeteTelepathy/ +               \
${TELEPATHY_QT4_INCLUDE_DIR}  )
 
 set (kopete_plugin_sharemydesktop_SRCS
@@ -14,7 +16,8 @@
 )
 
 target_link_libraries (kopete_sharemydesktop
-                       ${TELEPATHY_QT4_LIBS}
+                       kopetetelepathy
+                       ${TELEPATHY_QT4_LIBRARIES}
                        ${KDE4_KDEUI_LIBS}
                        ${KOPETE_LIBRARIES}
 )
--- trunk/playground/network/kopete/plugins/sharemydesktop/share-my-desktop-chat-ui.rc \
#1017827:1017828 @@ -1 +1,6 @@
- 
+<!DOCTYPE kpartgui>
+<kpartgui name="kopete_sharemydesktop" version="1">
+    <ToolBar name="chatToolBar" fullWidth="true">
+        <Action name="shareMyDesktop" />
+    </ToolBar>
+</kpartgui>
--- trunk/playground/network/kopete/plugins/sharemydesktop/share-my-desktop-gui-client.cpp \
#1017827:1017828 @@ -1 +1,191 @@
- 
+/*
+ * This file is part of Kopete
+ *
+ * Copyright (C) 2009 Collabora Ltd. <info@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "share-my-desktop-gui-client.h"
+
+#include "share-my-desktop-plugin.h"
+
+#include <KopeteTelepathy/telepathychatsession.h>
+#include <KopeteTelepathy/telepathycontact.h>
+
+#include <kopeteaccount.h>
+#include <kopetechatsession.h>
+
+#include <KAction>
+#include <KActionCollection>
+#include <KDebug>
+#include <KGenericFactory>
+#include <KShortcut>
+
+#include <TelepathyQt4/PendingChannelRequest>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/PendingReady>
+#include <TelepathyQt4/ReferencedHandles>
+
+ShareMyDesktopGuiClient::ShareMyDesktopGuiClient(Kopete::ChatSession *parent)
+ : QObject(parent),
+   KXMLGUIClient(parent),
+   m_chatSession(parent)
+{
+    kDebug();
+
+    // Set the component data to use as the plugin's
+    setComponentData(KGenericFactory<ShareMyDesktopPlugin>::componentData());
+
+    // If the chat session is invalid or empty, this instance should never have \
happened, but best +    // to be safe and check again anyway.
+    if (!m_chatSession || m_chatSession->members().isEmpty()) {
+        kWarning() << "Invalid Chat Session.";
+        deleteLater();
+    }
+
+    // Same for if it is a telepathy chat.
+    TelepathyChatSession *tpChatSession = \
qobject_cast<TelepathyChatSession*>(m_chatSession); +
+    if (!tpChatSession) {
+        kWarning() << "Not a Telepathy Chat Session.";
+        deleteLater();
+    }
+
+    // Add a KAction for Share My Desktop.
+    // FIXME: Are the label and accelerator and shortcut here OK?
+    KAction *shareMyDesktop = new KAction(KIcon("krfb"), i18n("S&hare My Desktop"), \
this); +    actionCollection()->addAction( "shareMyDesktop", shareMyDesktop );
+    shareMyDesktop->setShortcut(KShortcut (Qt::CTRL + Qt::Key_D));
+    connect(shareMyDesktop, SIGNAL(triggered(bool)), this, \
SLOT(onShareMyDesktopTriggered())); +
+    // Set the RC file to use to be the one with our toolbar button in it.
+    setXMLFile("share-my-desktop-chat-ui.rc");
+}
+
+ShareMyDesktopGuiClient::~ShareMyDesktopGuiClient()
+{
+    kDebug();
+}
+
+void ShareMyDesktopGuiClient::onShareMyDesktopTriggered()
+{
+    kDebug();
+
+    // When the share-my-desktop button is pressed this slot is called.
+
+    // First check that the Chat Session is valid.
+    if (!m_chatSession) {
+        kWarning() << "Chat session is no longer valid.";
+        return;
+    }
+
+    // Get the remote contacts we are chatting with. Sharing a desktop to more than \
one contact +    // in the same chat is not currently supported.
+    // FIXME: Support sharing desktop to everyone in a Multi-User-Chat
+    Kopete::ContactPtrList members = m_chatSession->members();
+
+    if (members.size() <= 0) {
+        kWarning() << "Invalid number of people in the chat. Aborting \
share-my-desktop."; +        return;
+    }
+
+    if (members.size() > 1) {
+        kWarning() << "Share-My-Desktop only supports 1-1 chats at the moment.";
+        return;
+    }
+
+    // Cast the only member of the chat to a TelepathyContact.
+    TelepathyContact *tpContact = qobject_cast<TelepathyContact*>(members.at(0));
+
+    // Check the member really is a telepathy contact.
+    if (!tpContact) {
+        kWarning() << "Chat member is not a telepathy contact. Aborting \
share-my-desktop."; +        return;
+    }
+
+    // Get the internal Tp::Contact and save it as a member variable.
+    m_contact = tpContact->internalContact();
+
+    if (!m_contact) {
+        kWarning() << "Internal Contact is null. Aborting share-my-desktop.";
+        return;
+    }
+
+    // Get the Account on which we are requesting a channel.
+    Kopete::Account *kAccount = tpContact->account();
+
+    // Check the account is not null
+    if (!kAccount) {
+        kWarning() << "Contact's account is not valid. Aborting share-my-desktop.";
+        return;
+    }
+
+    // Cast to a telepathy account
+    TelepathyAccount *tpAccount = qobject_cast<TelepathyAccount*>(kAccount);
+
+    // Check the TelepathyAccount is valid.
+    if (!tpAccount) {
+        kWarning() << "Account is not a a TelepathyAccount. Aborting \
share-my-desktop."; +        return;
+    }
+
+    // The account is valid. Get its telepathy account and save it as a member \
variable. +    m_account = tpAccount->account();
+
+    // Check that the internal telepathy account is valid.
+    if (!m_account) {
+        kWarning() << "Tp::Account is not valid. Aborting share-my-desktop.";
+        return;
+    }
+
+    // Now we get the Tp::Account ready with the core feature.
+    connect(m_account->becomeReady(Tp::Account::FeatureCore),
+            SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onAccountReady(Tp::PendingOperation*)));
+}
+
+void ShareMyDesktopGuiClient::onAccountReady(Tp::PendingOperation *op)
+{
+    kDebug();
+
+    if (op->isError()) {
+        kWarning() << "Making the Account ready failed:" << op->errorName() << \
op->errorMessage(); +        return;
+    }
+
+    // Ensure a rfb stream tube channel to this contact.
+    QVariantMap parameters;
+    parameters.insert("org.freedesktop.Telepathy.Channel.ChannelType", \
"org.freedesktop.Telepathy.Channel.Type.StreamTube"); +    \
parameters.insert("org.freedesktop.Teleapthy.Channel.TargetHandleType", \
Tp::HandleTypeContact); +    \
parameters.insert("org.freedesktop.Telepathy.Channel.TargetHandle", \
m_contact->handle().first()); +    \
parameters.insert("org.freedesktop.Telepathy.Channel.Type.StreamTube.Service", \
"rfb"); +
+    connect(m_account->ensureChannel(parameters),
+            SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onEnsureChannelFinished(Tp::PendingOperation*)));
+}
+
+void ShareMyDesktopGuiClient::onEnsureChannelFinished(Tp::PendingOperation *op)
+{
+    if (op->isError()) {
+        kWarning() << "Ensuring channel failed:" << op->errorName() << \
op->errorMessage(); +        return;
+    }
+}
+
+
+#include "share-my-desktop-gui-client.moc"
+
--- trunk/playground/network/kopete/plugins/sharemydesktop/share-my-desktop-gui-client.h \
#1017827:1017828 @@ -1 +1,59 @@
- 
+/*
+ * This file is part of Kopete
+ *
+ * Copyright (C) 2009 Collabora Ltd. <info@collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef KOPETE_PLUGIN_SHAREMYDESKTOP_SHARE_MY_DESKTOP_GUI_CLIENT_H
+#define KOPETE_PLUGIN_SHAREMYDESKTOP_SHARE_MY_DESKTOP_GUI_CLIENT_H
+
+#include <KXMLGUIClient>
+
+#include <TelepathyQt4/Account>
+#include <TelepathyQt4/Contact>
+
+namespace Kopete {
+    class ChatSession;
+}
+
+namespace Tp {
+    class PendingOperation;
+}
+
+class ShareMyDesktopGuiClient : public QObject, public KXMLGUIClient
+{
+    Q_OBJECT
+
+public:
+    ShareMyDesktopGuiClient(Kopete::ChatSession *parent = 0);
+    ~ShareMyDesktopGuiClient();
+
+private Q_SLOTS:
+    void onShareMyDesktopTriggered();
+    void onAccountReady(Tp::PendingOperation *op);
+    void onEnsureChannelFinished(Tp::PendingOperation *op);
+
+private:
+    Kopete::ChatSession *m_chatSession;
+
+    Tp::AccountPtr m_account;
+    Tp::ContactPtr m_contact;
+};
+
+
+#endif  // Header guard
+
--- trunk/playground/network/kopete/plugins/sharemydesktop/share-my-desktop-plugin.cpp \
#1017827:1017828 @@ -20,6 +20,8 @@
 
 #include "share-my-desktop-plugin.h"
 
+#include "share-my-desktop-gui-client.h"
+
 #include <KAboutData>
 #include <KComponentData>
 #include <KDebug>
@@ -77,6 +79,8 @@
     }
 
     kDebug() << "Chat is using Telepathy protocol :):):)";
+
+    new ShareMyDesktopGuiClient(session);
 }
 
 
--- trunk/playground/network/kopete/protocols/telepathy/KopeteTelepathy/telepathychatsession.h \
#1017827:1017828 @@ -38,7 +38,7 @@
     class PendingOperation;
 }
 
-class TelepathyChatSession : public Kopete::ChatSession
+class KOPETE_EXPORT TelepathyChatSession : public Kopete::ChatSession
 {
     Q_OBJECT
 


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

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