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