1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * This is where the implementation of the DBus based application API lives.
4 * All the methods in here are designed to be called remotly via DBus.
5 * document-interface.cpp has all of the actual manipulation methods.
6 * This interface is just for creating new document interfaces.
7 *
8 * Documentation for these methods is in application-interface.xml
9 * which is the "gold standard" as to how the interface should work.
10 *
11 * Authors:
12 * Soren Berg <Glimmer07@gmail.com>
13 *
14 * Copyright (C) 2009 Soren Berg
15 *
16 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
17 */
18
19 #include "application-interface.h"
20 #include <string.h>
21 #include "dbus-init.h"
22 #include "file.h"
23 #include "inkscape.h"
24
G_DEFINE_TYPE(ApplicationInterface,application_interface,G_TYPE_OBJECT)25 G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT)
26
27 static void
28 application_interface_finalize (GObject *object)
29 {
30 G_OBJECT_CLASS (application_interface_parent_class)->finalize (object);
31 }
32
33
34 static void
application_interface_class_init(ApplicationInterfaceClass * klass)35 application_interface_class_init (ApplicationInterfaceClass *klass)
36 {
37 GObjectClass *object_class;
38 object_class = G_OBJECT_CLASS (klass);
39 object_class->finalize = application_interface_finalize;
40 }
41
42 static void
application_interface_init(ApplicationInterface * app_interface)43 application_interface_init (ApplicationInterface *app_interface)
44 {
45 dbus_g_error_domain_register (INKSCAPE_ERROR,
46 NULL,
47 INKSCAPE_TYPE_ERROR);
48 }
49
50 static bool
ensure_desktop_valid(GError ** error)51 ensure_desktop_valid(GError **error)
52 {
53 if (!INKSCAPE.use_gui()) {
54 g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires a GUI");
55 return false;
56 }
57 return true;
58 }
59
60 static bool
ensure_desktop_not_present(GError ** error)61 ensure_desktop_not_present(GError **error)
62 {
63 if (INKSCAPE.use_gui()) {
64 g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires non-GUI (command line) mode");
65 return false;
66 }
67 return true;
68 }
69
70 ApplicationInterface *
application_interface_new(void)71 application_interface_new (void)
72 {
73 return (ApplicationInterface*)g_object_new (TYPE_APPLICATION_INTERFACE, NULL);
74 }
75
76 /*
77 * Error stuff...
78 *
79 * To add a new error type, edit here and in the .h InkscapeError enum.
80 */
81 GQuark
inkscape_error_quark(void)82 inkscape_error_quark (void)
83 {
84 static GQuark quark = 0;
85 if (!quark)
86 quark = g_quark_from_static_string ("inkscape_error");
87
88 return quark;
89 }
90
91 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
92
inkscape_error_get_type(void)93 GType inkscape_error_get_type(void)
94 {
95 static GType etype = 0;
96
97 if (etype == 0) {
98 static const GEnumValue values[] =
99 {
100
101 ENUM_ENTRY(INKSCAPE_ERROR_SELECTION, "Incompatible_Selection"),
102 ENUM_ENTRY(INKSCAPE_ERROR_OBJECT, "Incompatible_Object"),
103 ENUM_ENTRY(INKSCAPE_ERROR_VERB, "Failed_Verb"),
104 ENUM_ENTRY(INKSCAPE_ERROR_OTHER, "Generic_Error"),
105 { 0, 0, 0 }
106 };
107
108 etype = g_enum_register_static("InkscapeError", values);
109 }
110
111 return etype;
112 }
113
114 /****************************************************************************
115 DESKTOP FUNCTIONS
116 ****************************************************************************/
117
118 gchar*
application_interface_desktop_new(ApplicationInterface * app_interface,GError ** error)119 application_interface_desktop_new (ApplicationInterface *app_interface,
120 GError **error)
121 {
122 g_return_val_if_fail(ensure_desktop_valid(error), NULL);
123 return (gchar*)Inkscape::Extension::Dbus::init_desktop();
124 }
125
126 gchar**
application_interface_get_desktop_list(ApplicationInterface * app_interface)127 application_interface_get_desktop_list (ApplicationInterface *app_interface)
128 {
129 return NULL;
130 }
131
132 gchar*
application_interface_get_active_desktop(ApplicationInterface * app_interface,GError ** error)133 application_interface_get_active_desktop (ApplicationInterface *app_interface,
134 GError **error)
135 {
136 return NULL;
137 }
138
139 gboolean
application_interface_set_active_desktop(ApplicationInterface * app_interface,gchar * document_name,GError ** error)140 application_interface_set_active_desktop (ApplicationInterface *app_interface,
141 gchar* document_name,
142 GError **error)
143 {
144 return TRUE;
145 }
146
147 gboolean
application_interface_desktop_close_all(ApplicationInterface * app_interface,GError ** error)148 application_interface_desktop_close_all (ApplicationInterface *app_interface,
149 GError **error)
150 {
151 return TRUE;
152 }
153
154 gboolean
application_interface_exit(ApplicationInterface * app_interface,GError ** error)155 application_interface_exit (ApplicationInterface *app_interface, GError **error)
156 {
157 sp_file_exit();
158 return TRUE;
159 }
160
161 /****************************************************************************
162 DOCUMENT FUNCTIONS
163 ****************************************************************************/
164
application_interface_document_new(ApplicationInterface * app_interface,GError ** error)165 gchar* application_interface_document_new (ApplicationInterface *app_interface,
166 GError **error)
167 {
168 g_return_val_if_fail(ensure_desktop_not_present(error), NULL);
169 return (gchar*)Inkscape::Extension::Dbus::init_document();
170 }
171
172 gchar*
application_interface_get_active_document(ApplicationInterface * app_interface,GError ** error)173 application_interface_get_active_document(ApplicationInterface *app_interface,
174 GError **error)
175 {
176 gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document();
177 if (!result) {
178 g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "No active document");
179 }
180 return result;
181 }
182
183 gchar**
application_interface_get_document_list(ApplicationInterface * app_interface)184 application_interface_get_document_list (ApplicationInterface *app_interface)
185 {
186 return NULL;
187 }
188
189 gboolean
application_interface_document_close_all(ApplicationInterface * app_interface,GError ** error)190 application_interface_document_close_all (ApplicationInterface *app_interface,
191 GError **error)
192 {
193 return TRUE;
194 }
195
196 /* INTERESTING FUNCTIONS
197 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
198 g_assert(desktop != NULL);
199
200 SPDocument *doc = desktop->getDocument();
201 g_assert(doc != NULL);
202
203 Inkscape::XML::Node *repr = doc->getReprRoot();
204 g_assert(repr != NULL);
205 */
206
207