Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
licensor.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/*
7 * Authors:
8 * bulia byak <buliabyak@users.sf.net>
9 * Bryce W. Harrington <bryce@bryceharrington.org>
10 * Lauris Kaplinski <lauris@kaplinski.com>
11 * Jon Phillips <jon@rejon.org>
12 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
13 * Abhishek Sharma
14 *
15 * Copyright (C) 2000 - 2005 Authors
16 *
17 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
18 */
19
20#include "licensor.h"
21
22#include <algorithm>
23#include <cassert>
24#include <gtkmm/entry.h>
25#include <gtkmm/checkbutton.h>
26
27#include "desktop.h"
28#include "document.h"
29#include "document-undo.h"
30#include "rdf.h"
31#include "ui/pack.h"
33#include "ui/widget/registry.h"
34
35namespace Inkscape::UI::Widget {
36
38 {_("Proprietary"), "", nullptr};
39
41 {Q_("MetadataLicence|Other"), "", nullptr};
42
43class LicenseItem final : public Gtk::CheckButton {
44public:
45 LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr, Gtk::CheckButton *group);
46 [[nodiscard]] rdf_license_t const *get_license() const { return _lic; }
47
48private:
49 void on_toggled() final;
50 struct rdf_license_t const *_lic;
51 EntityEntry *_eep;
52 Registry &_wr;
53};
54
55LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr, Gtk::CheckButton *group)
56: Gtk::CheckButton(_(license->name)), _lic(license), _eep(entity), _wr(wr)
57{
58 if (group) {
59 set_group (*group);
60 }
61}
62
64void LicenseItem::on_toggled()
65{
66 if (_wr.isUpdating() || !_wr.desktop())
67 return;
68
69 _wr.setUpdating (true);
70 SPDocument *doc = _wr.desktop()->getDocument();
71 rdf_set_license (doc, _lic->details ? _lic : nullptr);
72 if (doc->isSensitive()) {
73 DocumentUndo::done(doc, _("Document license updated"), "");
74 }
75 _wr.setUpdating (false);
76 static_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
77 _eep->on_changed();
78}
79
81: Gtk::Box{Gtk::Orientation::VERTICAL, 4}
82{
83}
84
85Licensor::~Licensor() = default;
86
88{
89 /* add license-specific metadata entry areas */
90 rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
91 _eentry.reset(EntityEntry::create(entity, wr));
92
93 wr.setUpdating (true);
94
95 auto const item = add_item(wr, _proprietary_license, nullptr);
96 item->set_active(true);
97
98 for (auto license = rdf_licenses; license && license->name; ++license) {
99 add_item(wr, *license, item);
100 }
101
102 // add Other at the end before the URI field for the confused ppl.
104
105 wr.setUpdating (false);
106
107 auto const box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
108 UI::pack_start(*this, *box, true, true, 0);
109 UI::pack_start(*box, _eentry->_label, false, false, 5);
110 UI::pack_start(*box, *_eentry->_packable, true, true, 0);
111}
112
113LicenseItem *Licensor::add_item(Registry &wr, rdf_license_t const &license,
114 Gtk::CheckButton * const group)
115{
116 assert(_eentry);
117 auto const item = Gtk::make_managed<LicenseItem>(&license, _eentry.get(), wr, group);
118 append(*item);
119 _items.push_back(item);
120 return item;
121}
122
124{
125 assert(_eentry);
126 assert(!_items.empty());
127
128 /* identify the license info */
129 constexpr bool read_only = false;
130 auto const license = rdf_get_license(doc, read_only);
131
132 // Set the active licenseʼs button to active/checked.
133 auto item = std::find_if(_items.begin(), _items.end(),
134 [=](auto const item){ return item->get_license() == license; });
135 // If we canʼt match license, just activate 1st.
136 if (item == _items.end()) item = _items.begin();
137 (*item)->set_active(true);
138
139 /* update the URI */
140 _eentry->update(doc, read_only);
141}
142
143} // namespace Inkscape::UI::Widget
144
145/*
146 Local Variables:
147 mode:c++
148 c-file-style:"stroustrup"
149 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150 indent-tabs-mode:nil
151 fill-column:99
152 End:
153*/
154// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
static EntityEntry * create(rdf_work_entity_t *ent, Registry &wr)
std::unique_ptr< EntityEntry > _eentry
Definition licensor.h:55
void update(SPDocument *doc)
Definition licensor.cpp:123
std::vector< LicenseItem * > _items
Definition licensor.h:56
LicenseItem * add_item(Registry &wr, rdf_license_t const &license, Gtk::CheckButton *group)
Definition licensor.cpp:113
Typed SVG document implementation.
Definition document.h:101
bool isSensitive() const
Definition document.h:363
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-item.cpp:779
Editable view implementation.
TODO: insert short description here.
SPItem * item
Widget for specifying a document's license; part of document preferences dialog.
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126
const struct rdf_license_t _other_license
Definition licensor.cpp:40
const struct rdf_license_t _proprietary_license
Definition licensor.cpp:37
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
static void append(std::vector< T > &target, std::vector< T > &&source)
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
struct rdf_license_t rdf_licenses[]
Definition rdf.cpp:179
struct rdf_work_entity_t * rdf_find_entity(gchar const *name)
Retrieves a known RDF/Work entity by name.
Definition rdf.cpp:364
struct rdf_license_t * rdf_get_license(SPDocument *document, bool read_only)
Attempts to match and retrieve a known RDF/License from the document XML.
Definition rdf.cpp:1047
void rdf_set_license(SPDocument *doc, struct rdf_license_t const *license)
Stores an RDF/License XML in the document XML.
Definition rdf.cpp:1146
headers for RDF types
Holds license name and RDF information.
Definition rdf.h:33
char const * uri
Definition rdf.h:35
char const * name
Definition rdf.h:34
struct rdf_double_t * details
Definition rdf.h:36
Holds known RDF/Work tags.
Definition rdf.h:71
Glib::ustring name
Definition toolbars.cpp:55