summaryrefslogtreecommitdiffstats
path: root/src/extension/prefdialog/widget.cpp
blob: 1297edb1c69edcfc32ff12de266eea8be84eaac4 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * Parameters for extensions.
 *//*
 * Author:
 *   Patrick Storz <eduard.braun2@gmx.de>
 *
 * Copyright (C) 2019 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "widget.h"
#include "widget-label.h"

#include <sigc++/sigc++.h>

#include "extension/extension.h"

#include "xml/node.h"


namespace Inkscape {
namespace Extension {

InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext)
{
    InxWidget *widget = nullptr;

    const char *name = in_repr->name();
    if (!name) {
        // we can't create a widget without name
        g_warning("InxWidget without name in extension '%s'.", in_ext->get_id());
    } else if (!strcmp(name, "description")) {
        widget = new WidgetLabel(in_repr, in_ext);
    } else {
        g_warning("Unknown widget name ('%s') in extension '%s'", name, in_ext->get_id());
    }

    // Note: widget could equal nullptr
    return widget;
}

InxWidget::InxWidget (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext)
    : _extension(ext)
{
    // translatable (optional)
    const char *translatable = in_repr->attribute("translatable");
    if (translatable) {
        if (!strcmp(translatable, "yes")) {
            _translatable = YES;
        } else if (!strcmp(translatable, "no"))  {
            _translatable = NO;
        } else {
            g_warning("Invalid value ('%s') for translatable attribute of widget '%s' in extension '%s'",
                      translatable, in_repr->name(), _extension->get_id());
        }
    }

    // context (optional)
    const char *context = in_repr->attribute("context");
    if (!context) {
        context = in_repr->attribute("msgctxt"); // backwards-compatibility with previous name
    }
    if (context) {
        _context = g_strdup(context);
    }

    // gui-hidden (optional)
    const char *gui_hidden = in_repr->attribute("gui-hidden");
    if (gui_hidden != nullptr) {
        if (strcmp(gui_hidden, "true") == 0) {
            _hidden = true;
        }
    }

    // indent (optional)
    const char *indent = in_repr->attribute("indent");
    if (indent != nullptr) {
        _indent = strtol(indent, nullptr, 0);
    }

    // appearance (optional, does not apply to all parameters)
    const char *appearance = in_repr->attribute("appearance");
    if (appearance) {
        _appearance = g_strdup(appearance);
    }
}

InxWidget::~InxWidget()
{
    g_free(_context);
    _context = nullptr;

    g_free(_appearance);
    _appearance = nullptr;
}

/** Basically, if there is no widget pass a NULL. */
Gtk::Widget *
InxWidget::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/)
{
    return nullptr;
}

const char *InxWidget::get_translation(const char* msgid) {
    return _extension->get_translation(msgid, _context);
}

}  // namespace Extension
}  // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :