1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include "gtv-application.hxx"
13 #include "gtv-application-window.hxx"
17 struct GtvApplicationPrivate
19 GtvRenderingArgs
* m_pRenderingArgs
;
23 #if __has_warning("-Wdeprecated-volatile")
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
28 G_DEFINE_TYPE_WITH_PRIVATE(GtvApplication
, gtv_application
, GTK_TYPE_APPLICATION
);
30 #if __has_warning("-Wdeprecated-volatile")
31 #pragma clang diagnostic pop
35 static GtvApplicationPrivate
*
36 getPrivate(GtvApplication
* app
)
38 return static_cast<GtvApplicationPrivate
*>(gtv_application_get_instance_private(app
));
42 gtv_application_activate(GApplication
*)
44 // If this isn't provided, some GTK versions fail to run us at all.
48 gtv_application_open(GApplication
* app
, GFile
** file
, gint
/*nFiles*/, const gchar
* /*hint*/)
50 // TODO: add some option to create a new view for existing document
51 // For now, this just opens a new document
52 GtvApplicationWindow
* window
= GTV_APPLICATION_WINDOW(gtv_application_window_new(GTK_APPLICATION(app
)));
53 gtk_window_present(GTK_WINDOW(window
));
55 GtvApplicationPrivate
* priv
= getPrivate(GTV_APPLICATION(app
));
56 gtv_application_window_load_document(window
, priv
->m_pRenderingArgs
, std::string(g_file_get_path(file
[0])));
60 gtv_application_init(GtvApplication
* app
)
62 static const GOptionEntry commandLineOptions
[] =
64 { "version", 0, 0, G_OPTION_ARG_NONE
, nullptr, "Show LOkit version", nullptr },
65 { "lo-path", 0, 0, G_OPTION_ARG_STRING
, nullptr, "LO path", nullptr },
66 { "unipoll", 0, 0, G_OPTION_ARG_NONE
, nullptr, "Enable unified polling loop", nullptr },
67 { "user-profile", 0, 0, G_OPTION_ARG_STRING
, nullptr, "User profile to use", nullptr },
68 { "enable-tiled-annotations", 0, 0, G_OPTION_ARG_NONE
, nullptr, "Whether tiled annotations should be enabled", nullptr },
69 { "background-color", 0, 0, G_OPTION_ARG_STRING
, nullptr, "Background color", nullptr },
70 { "hide-page-shadow", 0, 0, G_OPTION_ARG_NONE
, nullptr, "Hide page shadow", nullptr },
71 { "hide-whitespace", 0, 0, G_OPTION_ARG_NONE
, nullptr, "Hide whitespace", nullptr },
72 { nullptr, 0, 0, G_OPTION_ARG_NONE
, nullptr, nullptr, nullptr },
75 g_application_add_main_option_entries(G_APPLICATION(app
), commandLineOptions
);
77 GtvApplicationPrivate
* priv
= getPrivate(GTV_APPLICATION(app
));
78 priv
->m_pRenderingArgs
= new GtvRenderingArgs();
82 gtv_application_dispose (GObject
* object
)
84 GtvApplicationPrivate
* priv
= getPrivate(GTV_APPLICATION(object
));
86 delete priv
->m_pRenderingArgs
;
87 priv
->m_pRenderingArgs
= nullptr;
89 G_OBJECT_CLASS (gtv_application_parent_class
)->dispose (object
);
93 gtv_application_handle_local_options(GApplication
* app
, GVariantDict
* options
)
95 GtvApplicationPrivate
* priv
= getPrivate(GTV_APPLICATION(app
));
97 if (g_variant_dict_contains(options
, "lo-path"))
99 gchar
* loPath
= nullptr;
100 g_variant_dict_lookup(options
, "lo-path", "s", &loPath
);
103 priv
->m_pRenderingArgs
->m_aLoPath
= std::string(loPath
);
109 g_print("--lo-path= is mandatory. Please provide the path to LO installation.\n");
110 return 1; // Cannot afford to continue in absence of this param
113 if (g_variant_dict_contains(options
, "unipoll"))
114 priv
->m_pRenderingArgs
->m_bUnipoll
= true;
116 if (g_variant_dict_contains(options
, "version"))
118 if (!priv
->m_pRenderingArgs
->m_aLoPath
.empty())
120 GtkWidget
* pDocView
= lok_doc_view_new(priv
->m_pRenderingArgs
->m_aLoPath
.c_str(), nullptr, nullptr);
121 const gchar
* versionInfo
= lok_doc_view_get_version_info(LOK_DOC_VIEW(pDocView
));
123 g_print("LOKit version: %s", versionInfo
);
126 return 1; // exit anyway
130 if (g_variant_dict_contains(options
, "user-profile"))
132 gchar
* userProfile
= nullptr;
133 g_variant_dict_lookup(options
, "user-profile", "s", &userProfile
);
136 priv
->m_pRenderingArgs
->m_aUserProfile
= std::string("vnd.sun.star.pathname:") + std::string(userProfile
);
141 if (g_variant_dict_contains(options
, "background-color"))
143 gchar
* backgroundColor
= nullptr;
144 g_variant_dict_lookup(options
, "background-color", "s", &backgroundColor
);
147 priv
->m_pRenderingArgs
->m_aBackgroundColor
= std::string(backgroundColor
);
148 g_free(backgroundColor
);
152 if (g_variant_dict_contains(options
, "enable-tiled-annotations"))
153 priv
->m_pRenderingArgs
->m_bEnableTiledAnnotations
= true;
154 if (g_variant_dict_contains(options
, "hide-page-shadow"))
155 priv
->m_pRenderingArgs
->m_bHidePageShadow
= true;
156 if (g_variant_dict_contains(options
, "hide-whitespace"))
157 priv
->m_pRenderingArgs
->m_bHideWhiteSpace
= true;
163 gtv_application_class_init(GtvApplicationClass
* klass
)
165 G_APPLICATION_CLASS(klass
)->activate
= gtv_application_activate
;
166 G_APPLICATION_CLASS(klass
)->open
= gtv_application_open
;
167 G_APPLICATION_CLASS(klass
)->handle_local_options
= gtv_application_handle_local_options
;
168 G_OBJECT_CLASS(klass
)->dispose
= gtv_application_dispose
;
171 GtvApplication
* gtv_application_new()
173 return GTV_APPLICATION(g_object_new(GTV_TYPE_APPLICATION
,
174 "application-id", "org.libreoffice.gtktiledviewer",
175 "flags", G_APPLICATION_HANDLES_OPEN
,
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */