Blame SOURCES/0397-tdf-99314-lokdocview-add-new-userprofileurl-property.patch

135360
From 4b8ba14da9d58594e16c317682897f195349a40c Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Tue, 19 Apr 2016 09:09:19 +0200
135360
Subject: [PATCH 397/398] tdf#99314 lokdocview: add new userprofileurl property
135360
MIME-Version: 1.0
135360
Content-Type: text/plain; charset=UTF-8
135360
Content-Transfer-Encoding: 8bit
135360
135360
So that users of the widget can use a custom user profile, allowing
135360
running widgets users and LibreOffice in parallel.
135360
135360
(cherry picked from commit df784ec1bf3d1745a291056df28bec799d4fdee3)
135360
135360
Conflicts:
135360
	libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
135360
Change-Id: I1bd0a8e53aa3216adc721052cf30f0dd174327bd
135360
Reviewed-on: https://gerrit.libreoffice.org/24591
135360
Tested-by: Jenkins <ci@libreoffice.org>
135360
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
135360
Tested-by: Caolán McNamara <caolanm@redhat.com>
135360
(cherry picked from commit 549f67a85774838abdefdb7916beb0f26e2f9d2c)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitGtk.h         | 17 ++++++++++
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 12 +++++--
135360
 libreofficekit/source/gtk/lokdocview.cxx           | 37 +++++++++++++++++++++-
135360
 3 files changed, 63 insertions(+), 3 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
index 1df27c106214..91e29c83db57 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
135360
@@ -55,6 +55,23 @@ GtkWidget*                     lok_doc_view_new                    (const gchar*
135360
                                                                     GError **error);
135360
 
135360
 /**
135360
+ * lok_doc_view_new_from_user_profile:
135360
+ * @pPath: (nullable): LibreOffice install path. Pass null to set it to default
135360
+ * path which in most cases would be $libdir/libreoffice/program
135360
+ * @pUserProfile: (nullable): User profile URL. Pass non-null to be able to
135360
+ * use this widget and LibreOffice itself in parallel.
135360
+ * @cancellable: The cancellable object that you can use to cancel this
135360
+ * operation.
135360
+ * @error: The error that will be set if the object fails to initialize.
135360
+ *
135360
+ * Returns: (transfer none): The #LOKDocView widget instance.
135360
+ */
135360
+GtkWidget*                     lok_doc_view_new_from_user_profile  (const gchar* pPath,
135360
+                                                                    const gchar* pUserProfile,
135360
+                                                                    GCancellable *cancellable,
135360
+                                                                    GError **error);
135360
+
135360
+/**
135360
  * lok_doc_view_new_from_widget:
135360
  * @pDocView: The #LOKDocView instance
135360
  *
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index 3dc9f246f18e..54c9294e5398 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -35,7 +35,7 @@ static int help()
135360
     fprintf(stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install's-program-directory> <path-to-document> [<options> ... ]\n\n");
135360
     fprintf(stderr, "Options:\n\n");
135360
     fprintf(stderr, "--hide-whitespace: Hide whitespace between pages in text documents.\n");
135360
-    fprintf(stderr, "--background-color <color>: Set custom background color, e.g. 'yellow'.\n");
135360
+    fprintf(stderr, "--user-profile: Path to a custom user profile.\n");
135360
     return 1;
135360
 }
135360
 
135360
@@ -497,7 +497,15 @@ static void createView(GtkWidget* pButton, gpointer /*pItem*/)
135360
 /// Creates a new model, i.e. LOK init and document load, one view implicitly.
135360
 static void createModelAndView(const char* pLOPath, const char* pDocPath, const std::vector<std::string>& rArguments)
135360
 {
135360
-    GtkWidget* pDocView = lok_doc_view_new(pLOPath, nullptr, nullptr);
135360
+    std::string aUserProfile;
135360
+    for (size_t i = 0; i < rArguments.size(); ++i)
135360
+    {
135360
+        const std::string& rArgument = rArguments[i];
135360
+        if (rArgument == "--user-profile" && i + 1 < rArguments.size())
135360
+            aUserProfile = std::string("file://") + rArguments[i + 1].c_str();
135360
+    }
135360
+    const gchar* pUserProfile = aUserProfile.empty() ? nullptr : aUserProfile.c_str();
135360
+    GtkWidget* pDocView = lok_doc_view_new_from_user_profile(pLOPath, pUserProfile, nullptr, nullptr);
135360
 
135360
     setupWidgetAndCreateWindow(pDocView);
135360
 
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 9f47138bbc37..13ae6ea00e63 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -48,6 +48,7 @@
135360
 struct LOKDocViewPrivateImpl
135360
 {
135360
     const gchar* m_aLOPath;
135360
+    const gchar* m_pUserProfileURL;
135360
     const gchar* m_aDocPath;
135360
     std::string m_aRenderingArguments;
135360
     gdouble m_nLoadProgress;
135360
@@ -128,6 +129,7 @@ struct LOKDocViewPrivateImpl
135360
 
135360
     LOKDocViewPrivateImpl()
135360
         : m_aLOPath(nullptr),
135360
+        m_pUserProfileURL(nullptr),
135360
         m_aDocPath(nullptr),
135360
         m_nLoadProgress(0),
135360
         m_bIsLoading(false),
135360
@@ -206,6 +208,7 @@ enum
135360
 
135360
     PROP_LO_PATH,
135360
     PROP_LO_POINTER,
135360
+    PROP_USER_PROFILE_URL,
135360
     PROP_DOC_PATH,
135360
     PROP_DOC_POINTER,
135360
     PROP_EDITABLE,
135360
@@ -1932,6 +1935,9 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal
135360
     case PROP_LO_POINTER:
135360
         priv->m_pOffice = static_cast<LibreOfficeKit*>(g_value_get_pointer(value));
135360
         break;
135360
+    case PROP_USER_PROFILE_URL:
135360
+        priv->m_pUserProfileURL = g_value_dup_string(value);
135360
+        break;
135360
     case PROP_DOC_PATH:
135360
         priv->m_aDocPath = g_value_dup_string (value);
135360
         break;
135360
@@ -1982,6 +1988,9 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va
135360
     case PROP_LO_POINTER:
135360
         g_value_set_pointer(value, priv->m_pOffice);
135360
         break;
135360
+    case PROP_USER_PROFILE_URL:
135360
+        g_value_set_string(value, priv->m_pUserProfileURL);
135360
+        break;
135360
     case PROP_DOC_PATH:
135360
         g_value_set_string (value, priv->m_aDocPath);
135360
         break;
135360
@@ -2056,7 +2065,7 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /
135360
     if (priv->m_pOffice != nullptr)
135360
         return TRUE;
135360
 
135360
-    priv->m_pOffice = lok_init (priv->m_aLOPath);
135360
+    priv->m_pOffice = lok_init_2(priv->m_aLOPath, priv->m_pUserProfileURL);
135360
 
135360
     if (priv->m_pOffice == nullptr)
135360
     {
135360
@@ -2120,6 +2129,20 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
135360
                                                       G_PARAM_STATIC_STRINGS));
135360
 
135360
     /**
135360
+     * LOKDocView:userprofileurl:
135360
+     *
135360
+     * The absolute path of the LibreOffice user profile.
135360
+     */
135360
+    properties[PROP_USER_PROFILE_URL] =
135360
+        g_param_spec_string("userprofileurl",
135360
+                            "User profile path",
135360
+                            "LibreOffice user profile path",
135360
+                            nullptr,
135360
+                            static_cast<GParamFlags>(G_PARAM_READWRITE |
135360
+                                                     G_PARAM_CONSTRUCT_ONLY |
135360
+                                                     G_PARAM_STATIC_STRINGS));
135360
+
135360
+    /**
135360
      * LOKDocView:docpath:
135360
      *
135360
      * The path of the document that is currently being viewed.
135360
@@ -2510,11 +2533,23 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
135360
                                        nullptr));
135360
 }
135360
 
135360
+SAL_DLLPUBLIC_EXPORT GtkWidget*
135360
+lok_doc_view_new_from_user_profile (const gchar* pPath, const gchar* pUserProfile, GCancellable *cancellable, GError **error)
135360
+{
135360
+    return GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, cancellable, error,
135360
+                                     "lopath", pPath == nullptr ? LOK_PATH : pPath,
135360
+                                     "userprofileurl", pUserProfile,
135360
+                                     "halign", GTK_ALIGN_CENTER,
135360
+                                     "valign", GTK_ALIGN_CENTER,
135360
+                                     nullptr));
135360
+}
135360
+
135360
 SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView)
135360
 {
135360
     LOKDocViewPrivate& pOldPriv = getPrivate(pOldLOKDocView);
135360
     GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/nullptr, /*error=*/nullptr,
135360
                                                        "lopath", pOldPriv->m_aLOPath,
135360
+                                                       "userprofileurl", pOldPriv->m_pUserProfileURL,
135360
                                                        "lopointer", pOldPriv->m_pOffice,
135360
                                                        "docpointer", pOldPriv->m_pDocument,
135360
                                                        "halign", GTK_ALIGN_CENTER,
135360
-- 
135360
2.12.0
135360