[Libreoffice-commits] .: Branch 'feature/tubes2' - 3 commits - Repository.mk tubes/Executable_liboapprover.mk tubes/LibreOfficeApprover.client tubes/LibreOffice.client tubes/Module_tubes.mk tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service tubes/org.freedesktop.Telepathy.Client.LibreOffice.service tubes/README tubes/source

Will Thompson wjt at kemper.freedesktop.org
Wed Mar 21 11:54:55 PDT 2012


 Repository.mk                                                      |    1 
 tubes/Executable_liboapprover.mk                                   |   47 +
 tubes/LibreOffice.client                                           |   11 
 tubes/LibreOfficeApprover.client                                   |    8 
 tubes/Module_tubes.mk                                              |    1 
 tubes/README                                                       |   17 
 tubes/org.freedesktop.Telepathy.Client.LibreOffice.service         |    3 
 tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service |    3 
 tubes/source/approver.c                                            |  246 ++++++++++
 9 files changed, 337 insertions(+)

New commits:
commit 6db31dc4ba6e296d05629c12494007cc80adb019
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Wed Mar 21 18:51:24 2012 +0000

    tubes approver: add error handling in case spawning LibO fails

diff --git a/tubes/source/approver.c b/tubes/source/approver.c
index fdf0799..5f4bbde 100644
--- a/tubes/source/approver.c
+++ b/tubes/source/approver.c
@@ -45,16 +45,21 @@ handle_with_cb (GObject *source,
     gpointer user_data)
 {
   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
-  GError *error;
+  GtkDialog *dialog = GTK_DIALOG (user_data);
+  GError *error = NULL;
 
   if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
     {
       g_print ("HandleWith() failed: %s\n", error->message);
+      gtk_message_dialog_format_secondary_markup (dialog,
+          "<b>Error</b>\n\nAsking LibreOffice to accept the session failed: <i>%s</i>",
+          error->message);
       g_error_free (error);
       return;
     }
 
   g_print ("HandleWith() succeeded\n");
+  gtk_widget_destroy (dialog);
 }
 
 static void
@@ -64,7 +69,7 @@ close_cb (GObject *source,
 
 {
   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
-  GError *error;
+  GError *error = NULL;
 
   if (!tp_channel_dispatch_operation_close_channels_finish (cdo, result, &error))
     {
@@ -90,16 +95,19 @@ dialog_response_cb (
         g_print ("Approve channels\n");
 
         tp_channel_dispatch_operation_handle_with_async (cdo, NULL,
-            handle_with_cb, NULL);
+            handle_with_cb, dialog);
+
+        gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_ACCEPT, FALSE);
+        gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_REJECT, FALSE);
     }
     else
     {
         g_print ("Reject channels\n");
 
-        tp_channel_dispatch_operation_close_channels_async (cdo, close_cb, NULL);
+        tp_channel_dispatch_operation_close_channels_async (cdo, close_cb, dialog);
+        gtk_widget_destroy (dialog);
     }
 
-    gtk_widget_destroy (dialog);
     g_object_unref (cdo);
 }
 
commit 44a4ec0ae0554cbbf1a07a1aecaa62624155527b
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Wed Mar 21 18:38:27 2012 +0000

    Add WIP .client and .service files.
    
    These are roughly what need to get installed to make the approver (the
    little dialog box that pops up for incoming offers) and handler
    (LibreOffice itself) service-activatable.
    
    Without these, your contacts will only see that you're capable of
    LibreOffice tubes while you're running LibreOffice, and you won't get
    a prompt unless liboapprover is running.

diff --git a/tubes/LibreOffice.client b/tubes/LibreOffice.client
new file mode 100644
index 0000000..8c3356f
--- /dev/null
+++ b/tubes/LibreOffice.client
@@ -0,0 +1,11 @@
+[org.freedesktop.Telepathy.Client]
+Interfaces = org.freedesktop.Telepathy.Client.Handler;
+
+[org.freedesktop.Telepathy.Client.Handler]
+BypassApproval = false
+
+[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 0]
+org.freedesktop.Telepathy.Channel.TargetHandleType u = 1
+org.freedesktop.Telepathy.Channel.ChannelType s = org.freedesktop.Telepathy.Channel.Type.DBusTube
+org.freedesktop.Telepathy.Channel.Type.DBusTube.ServiceName s = org.libreoffice.calc
+
diff --git a/tubes/LibreOfficeApprover.client b/tubes/LibreOfficeApprover.client
new file mode 100644
index 0000000..035e022
--- /dev/null
+++ b/tubes/LibreOfficeApprover.client
@@ -0,0 +1,8 @@
+[org.freedesktop.Telepathy.Client]
+Interfaces = org.freedesktop.Telepathy.Client.Approver;
+
+[org.freedesktop.Telepathy.Client.Approver.ApproverChannelFilter 0]
+org.freedesktop.Telepathy.Channel.TargetHandleType u = 1
+org.freedesktop.Telepathy.Channel.ChannelType s = org.freedesktop.Telepathy.Channel.Type.DBusTube
+org.freedesktop.Telepathy.Channel.Type.DBusTube.ServiceName s = org.libreoffice.calc
+
diff --git a/tubes/README b/tubes/README
index 3527a72..84d4892 100644
--- a/tubes/README
+++ b/tubes/README
@@ -8,6 +8,23 @@ the same TeleConference abstraction.
 
 To enable configure LibO with --enable-telepathy
 
+If you have a Telepathy-enabled LibreOffice installed to /usr (including
+liboapprover) you may also want to install the .service and .client files to
+make everything service-activatable:
+
+    mkdir -p $HOME/.local/share/telepathy/clients
+    ln -s $PWD/tubes/LibreOffice.client \
+          $PWD/tubes/LibreOfficeApprover.client \
+          $HOME/.local/share/telepathy/clients
+
+    mkdir -p $HOME/.local/share/dbus-1/services
+    ln -s $PWD/tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service \
+          $PWD/tubes/org.freedesktop.Telepathy.Client.LibreOffice.service \
+          $HOME/.local/share/dbus-1/services
+
+Otherwise, you need to make sure liboapprover and a Telepathy-enabled
+LibreOffice are running.
+
 Status 2012-03-20:
 
 * no LibO code depends on this module yet, so it is not built in a regular
diff --git a/tubes/org.freedesktop.Telepathy.Client.LibreOffice.service b/tubes/org.freedesktop.Telepathy.Client.LibreOffice.service
new file mode 100644
index 0000000..d125724
--- /dev/null
+++ b/tubes/org.freedesktop.Telepathy.Client.LibreOffice.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Telepathy.Client.LibreOffice
+Exec=/usr/bin/libreoffice --calc
diff --git a/tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service b/tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service
new file mode 100644
index 0000000..89e4acf
--- /dev/null
+++ b/tubes/org.freedesktop.Telepathy.Client.LibreOfficeApprover.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Telepathy.Client.LibreOfficeApprover
+Exec=/usr/bin/liboapprover
commit 8e617da5092395154aa39403514404c13a0074d6
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Wed Mar 21 15:11:19 2012 +0000

    tubes: add approver
    
    This is a small external process designed to prompt the user for
    incoming LibreOffice-flavoured D-Bus tubes.
    
    Right now it is not service-activatable, but soon it will be…

diff --git a/Repository.mk b/Repository.mk
index 2ecc636..8de7b0c 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -95,6 +95,7 @@ $(eval $(call gb_Helper_register_executables,OOO,\
     soffice.bin \
     unopkg.bin \
     gengal.bin \
+    liboapprover \
 ))
 
 ifeq ($(OS),MACOSX)
diff --git a/tubes/Executable_liboapprover.mk b/tubes/Executable_liboapprover.mk
new file mode 100644
index 0000000..63f8177
--- /dev/null
+++ b/tubes/Executable_liboapprover.mk
@@ -0,0 +1,47 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# Major Contributor(s):
+# Copyright (C) 2012 Collabora Ltd.
+#
+# All Rights Reserved.
+#
+# For minor contributions see the git repository.
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+$(eval $(call gb_Executable_Executable,liboapprover))
+
+$(eval $(call gb_Executable_set_targettype_gui,liboapprover,YES))
+
+$(eval $(call gb_Executable_set_include,liboapprover,\
+    $$(INCLUDE) \
+    $(GTK_CFLAGS) \
+    $(TELEPATHY_CFLAGS) \
+    -I$(realpath $(SRCDIR)/tubes/inc) \
+))
+
+$(eval $(call gb_Executable_add_libs,liboapprover,\
+    $(GTK_LIBS) \
+    $(TELEPATHY_LIBS) \
+))
+
+$(eval $(call gb_Executable_add_cobjects,liboapprover,\
+    tubes/source/approver \
+))
+
+# vim: set ts=4 sw=4 et:
diff --git a/tubes/Module_tubes.mk b/tubes/Module_tubes.mk
index 9ed4a48..fb1c9d7 100644
--- a/tubes/Module_tubes.mk
+++ b/tubes/Module_tubes.mk
@@ -31,6 +31,7 @@ ifeq ($(ENABLE_TELEPATHY),TRUE)
 
 $(eval $(call gb_Module_add_targets,tubes,\
 	Library_tubes \
+	Executable_liboapprover \
 ))
 
 $(eval $(call gb_Module_add_check_targets,tubes,\
diff --git a/tubes/source/approver.c b/tubes/source/approver.c
new file mode 100644
index 0000000..fdf0799
--- /dev/null
+++ b/tubes/source/approver.c
@@ -0,0 +1,238 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2010-2012 Collabora Ltd.
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <glib.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+
+#include <telepathy-glib/telepathy-glib.h>
+#include <telepathy-glib/debug.h>
+#include <telepathy-glib/simple-approver.h>
+
+#include <tubes/constants.h>
+
+GMainLoop *mainloop = NULL;
+
+static void
+handle_with_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
+  GError *error;
+
+  if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
+    {
+      g_print ("HandleWith() failed: %s\n", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  g_print ("HandleWith() succeeded\n");
+}
+
+static void
+close_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+
+{
+  TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
+  GError *error;
+
+  if (!tp_channel_dispatch_operation_close_channels_finish (cdo, result, &error))
+    {
+      g_print ("Rejecting channels failed: %s\n", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  g_print ("Rejected all the things!\n");
+}
+
+static void
+dialog_response_cb (
+    GtkWidget *dialog,
+    gint response_id,
+    gpointer user_data)
+{
+    TpSimpleApprover *self = TP_SIMPLE_APPROVER (g_object_get_data (dialog, "client"));
+    TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (user_data);
+
+    if (response_id == GTK_RESPONSE_ACCEPT)
+    {
+        g_print ("Approve channels\n");
+
+        tp_channel_dispatch_operation_handle_with_async (cdo, NULL,
+            handle_with_cb, NULL);
+    }
+    else
+    {
+        g_print ("Reject channels\n");
+
+        tp_channel_dispatch_operation_close_channels_async (cdo, close_cb, NULL);
+    }
+
+    gtk_widget_destroy (dialog);
+    g_object_unref (cdo);
+}
+
+static void
+show_dialog (
+    TpSimpleApprover *self,
+    TpChannelDispatchOperation *cdo,
+    TpContact *target)
+{
+    GFile *avatar_file = tp_contact_get_avatar_file (target);
+    GtkWidget *dialog = gtk_message_dialog_new_with_markup (NULL,
+        0, /* flags */
+        GTK_MESSAGE_QUESTION,
+        GTK_BUTTONS_NONE,
+        "<b>%s</b> (<i>%s</i>) would like to edit a spreadsheet in LibreOffice "
+        "with you.",
+        tp_contact_get_alias (target),
+        tp_contact_get_identifier (target));
+
+    if (avatar_file != NULL)
+    {
+        GtkWidget *avatar = gtk_image_new_from_file (g_file_get_path (avatar_file));
+
+        gtk_message_dialog_set_image (dialog, avatar);
+    }
+
+    gtk_dialog_add_buttons (dialog,
+        "_Reject", GTK_RESPONSE_REJECT,
+        "_Accept", GTK_RESPONSE_ACCEPT,
+        NULL);
+
+    g_object_set_data_full (dialog, "client", g_object_ref (self), g_object_unref);
+    g_signal_connect (dialog, "response", dialog_response_cb, g_object_ref (cdo));
+
+    gtk_window_set_skip_taskbar_hint (dialog, FALSE);
+
+    gtk_widget_show_all (dialog);
+}
+
+static void
+add_dispatch_operation_cb (TpSimpleApprover *self,
+    TpAccount *account,
+    TpConnection *connection,
+    GList *channels,
+    TpChannelDispatchOperation *cdo,
+    TpAddDispatchOperationContext *context,
+    gpointer user_data)
+{
+    TpContact *target = NULL;
+    GList *l;
+
+    g_print ("Approving this batch of channels:\n");
+
+    for (l = channels; l != NULL; l = g_list_next (l))
+    {
+        TpChannel *channel = l->data;
+
+        if (TP_IS_DBUS_TUBE_CHANNEL (channel))
+        {
+            target = tp_channel_get_target_contact (channel);
+            break;
+        }
+    }
+
+    if (target == NULL)
+    {
+        g_critical ("Hmm. No 1-1 D-Bus tube in cdo %s, so why did we get it?",
+            tp_proxy_get_object_path (cdo));
+        g_return_if_reached ();
+    }
+
+    tp_add_dispatch_operation_context_accept (context);
+    show_dialog (self, cdo, target);
+}
+
+int
+main (int argc,
+      char **argv)
+{
+  TpAccountManager *manager;
+  TpSimpleClientFactory *factory;
+  TpBaseClient *approver;
+  GError *error = NULL;
+
+  gtk_init (&argc, &argv);
+  tp_debug_set_flags (g_getenv ("LIBO_APPROVER_DEBUG"));
+
+  manager = tp_account_manager_dup ();
+
+    factory = tp_proxy_get_factory (manager);
+    /* We want the target contact on channels to be available... */
+    tp_simple_client_factory_add_channel_features_varargs (factory,
+        TP_CHANNEL_FEATURE_CONTACTS,
+        0);
+    /* ...and for it to have its alias and avatar available */
+    tp_simple_client_factory_add_contact_features_varargs (factory,
+        TP_CONTACT_FEATURE_ALIAS,
+        TP_CONTACT_FEATURE_AVATAR_DATA,
+        TP_CONTACT_FEATURE_INVALID);
+
+  approver = tp_simple_approver_new_with_am (manager, "LibreOfficeApprover",
+      FALSE, add_dispatch_operation_cb, NULL, NULL);
+
+  tp_base_client_take_approver_filter (approver, tp_asv_new (
+        TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
+          TP_IFACE_CHANNEL_TYPE_DBUS_TUBE,
+        TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
+          TP_HANDLE_TYPE_CONTACT,
+        TP_PROP_CHANNEL_TYPE_DBUS_TUBE_SERVICE_NAME, G_TYPE_STRING,
+          LIBO_DTUBE_SERVICE,
+        NULL));
+
+  if (!tp_base_client_register (approver, &error))
+    {
+      g_warning ("Failed to register Approver: %s\n", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  g_print ("Start approving\n");
+
+  mainloop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (mainloop);
+  /* TODO: time out after 5 seconds of inactivity? */
+
+  if (mainloop != NULL)
+    g_main_loop_unref (mainloop);
+
+out:
+  g_object_unref (manager);
+  g_object_unref (approver);
+
+  return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list