summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitGtk.h17
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx11
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx37
3 files changed, 63 insertions, 2 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 5e24eb9c5187..8a64bffd5844 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 c0d4ac7f33df..b3079a7bbdd4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -36,6 +36,7 @@ static int help()
fprintf(stderr, "--background-color <color>: Set custom background color, e.g. 'yellow'.\n");
fprintf(stderr, "--hide-page-shadow: Hide page/slide shadow.\n");
fprintf(stderr, "--hide-whitespace: Hide whitespace between pages in text documents.\n");
+ fprintf(stderr, "--user-profile: Path to a custom user profile.\n");
return 1;
}
@@ -529,7 +530,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<std::string>& 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 81ccb378cb4a..fdb07fe861f8 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;
@@ -139,6 +140,7 @@ struct LOKDocViewPrivateImpl
LOKDocViewPrivateImpl()
: m_aLOPath(nullptr),
+ m_pUserProfileURL(nullptr),
m_aDocPath(nullptr),
m_nLoadProgress(0),
m_bIsLoading(false),
@@ -221,6 +223,7 @@ enum
PROP_LO_PATH,
PROP_LO_POINTER,
+ PROP_USER_PROFILE_URL,
PROP_DOC_PATH,
PROP_DOC_POINTER,
PROP_EDITABLE,
@@ -2013,6 +2016,9 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal
case PROP_LO_POINTER:
priv->m_pOffice = static_cast<LibreOfficeKit*>(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;
@@ -2063,6 +2069,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;
@@ -2137,7 +2146,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)
{
@@ -2201,6 +2210,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<GParamFlags>(G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* LOKDocView:docpath:
*
* The path of the document that is currently being viewed.
@@ -2591,11 +2614,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,