summaryrefslogtreecommitdiffstats
path: root/src/extension/dbus/application-interface.cpp
blob: 1b4be697d399ba61ba04b7b59d6432650c4885ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * This is where the implementation of the DBus based application API lives.
 * All the methods in here are designed to be called remotly via DBus.
 * document-interface.cpp has all of the actual manipulation methods.
 * This interface is just for creating new document interfaces.
 *
 * Documentation for these methods is in application-interface.xml
 * which is the "gold standard" as to how the interface should work.
 *
 * Authors:
 *   Soren Berg <Glimmer07@gmail.com>
 *
 * Copyright (C) 2009 Soren Berg
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "application-interface.h"
#include <string.h>
#include "dbus-init.h"
#include "file.h"
#include "inkscape.h"

G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT)

static void
application_interface_finalize (GObject *object)
{
        G_OBJECT_CLASS (application_interface_parent_class)->finalize (object);
}


static void
application_interface_class_init (ApplicationInterfaceClass *klass)
{
        GObjectClass *object_class;
        object_class = G_OBJECT_CLASS (klass);
        object_class->finalize = application_interface_finalize;
}

static void
application_interface_init (ApplicationInterface *app_interface)
{
    dbus_g_error_domain_register (INKSCAPE_ERROR,
                NULL,
                INKSCAPE_TYPE_ERROR);
}

static bool
ensure_desktop_valid(GError **error)
{
    if (!INKSCAPE.use_gui()) {
        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires a GUI");
        return false;
    }
    return true;
}

static bool
ensure_desktop_not_present(GError **error)
{
    if (INKSCAPE.use_gui()) {
        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires non-GUI (command line) mode");
        return false;
    }
    return true;
}

ApplicationInterface *
application_interface_new (void)
{
        return (ApplicationInterface*)g_object_new (TYPE_APPLICATION_INTERFACE, NULL);
}

/*
 * Error stuff...
 *
 * To add a new error type, edit here and in the .h InkscapeError enum.
 */
GQuark
inkscape_error_quark (void)
{
  static GQuark quark = 0;
  if (!quark)
    quark = g_quark_from_static_string ("inkscape_error");

  return quark;
}

#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }

GType inkscape_error_get_type(void)
{
    static GType etype = 0;

    if (etype == 0) {
        static const GEnumValue values[] =
            {

                ENUM_ENTRY(INKSCAPE_ERROR_SELECTION, "Incompatible_Selection"),
                ENUM_ENTRY(INKSCAPE_ERROR_OBJECT, "Incompatible_Object"),
                ENUM_ENTRY(INKSCAPE_ERROR_VERB, "Failed_Verb"),
                ENUM_ENTRY(INKSCAPE_ERROR_OTHER, "Generic_Error"),
                { 0, 0, 0 }
            };

        etype = g_enum_register_static("InkscapeError", values);
    }

    return etype;
}

/****************************************************************************
     DESKTOP FUNCTIONS
****************************************************************************/

gchar* 
application_interface_desktop_new (ApplicationInterface *app_interface, 
                                   GError **error) 
{
    g_return_val_if_fail(ensure_desktop_valid(error), NULL);
    return (gchar*)Inkscape::Extension::Dbus::init_desktop();
}

gchar** 
application_interface_get_desktop_list (ApplicationInterface *app_interface)
{
  return NULL;
}

gchar* 
application_interface_get_active_desktop (ApplicationInterface *app_interface,
                                          GError **error)
{
  return NULL;
}

gboolean
application_interface_set_active_desktop (ApplicationInterface *app_interface, 
                                          gchar* document_name,
                                          GError **error)
{
  return TRUE;
}

gboolean
application_interface_desktop_close_all (ApplicationInterface *app_interface,
                                          GError **error) 
{
  return TRUE;
}

gboolean
application_interface_exit (ApplicationInterface *app_interface, GError **error)
{
    sp_file_exit();
    return TRUE;
}

/****************************************************************************
     DOCUMENT FUNCTIONS
****************************************************************************/

gchar* application_interface_document_new (ApplicationInterface *app_interface,
                                           GError **error)
{
    g_return_val_if_fail(ensure_desktop_not_present(error), NULL);
    return (gchar*)Inkscape::Extension::Dbus::init_document();
}

gchar*
application_interface_get_active_document(ApplicationInterface *app_interface,
                                          GError **error)
{
  gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document();
  if (!result) {
      g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "No active document");
  }
  return result;
}

gchar** 
application_interface_get_document_list (ApplicationInterface *app_interface)
{
  return NULL;
}

gboolean
application_interface_document_close_all (ApplicationInterface *app_interface,
                                          GError **error) 
{
  return TRUE;
}

/* INTERESTING FUNCTIONS
    SPDesktop  *desktop = SP_ACTIVE_DESKTOP;
    g_assert(desktop != NULL);

    SPDocument *doc = desktop->getDocument();
    g_assert(doc != NULL);

    Inkscape::XML::Node     *repr = doc->getReprRoot();
    g_assert(repr != NULL);
*/