1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Authors:
4 * bulia byak <buliabyak@users.sf.net>
5 * Bryce W. Harrington <bryce@bryceharrington.org>
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Jon Phillips <jon@rejon.org>
8 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2000 - 2005 Authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16 #include "licensor.h"
17
18 #include <gtkmm/entry.h>
19 #include <gtkmm/radiobutton.h>
20
21 #include "ui/widget/entity-entry.h"
22 #include "ui/widget/registry.h"
23 #include "rdf.h"
24 #include "inkscape.h"
25 #include "document-undo.h"
26 #include "verbs.h"
27
28
29 namespace Inkscape {
30 namespace UI {
31 namespace Widget {
32
33 //===================================================
34
35 const struct rdf_license_t _proprietary_license =
36 {_("Proprietary"), "", nullptr};
37
38 const struct rdf_license_t _other_license =
39 {Q_("MetadataLicence|Other"), "", nullptr};
40
41 class LicenseItem : public Gtk::RadioButton {
42 public:
43 LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr, Gtk::RadioButtonGroup *group);
44 protected:
45 void on_toggled() override;
46 struct rdf_license_t const *_lic;
47 EntityEntry *_eep;
48 Registry &_wr;
49 };
50
LicenseItem(struct rdf_license_t const * license,EntityEntry * entity,Registry & wr,Gtk::RadioButtonGroup * group)51 LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr, Gtk::RadioButtonGroup *group)
52 : Gtk::RadioButton(_(license->name)), _lic(license), _eep(entity), _wr(wr)
53 {
54 if (group) {
55 set_group (*group);
56 }
57 }
58
59 /// \pre it is assumed that the license URI entry is a Gtk::Entry
on_toggled()60 void LicenseItem::on_toggled()
61 {
62 if (_wr.isUpdating() || !_wr.desktop())
63 return;
64
65 _wr.setUpdating (true);
66 SPDocument *doc = _wr.desktop()->getDocument();
67 rdf_set_license (doc, _lic->details ? _lic : nullptr);
68 if (doc->isSensitive()) {
69 DocumentUndo::done(doc, SP_VERB_NONE, _("Document license updated"));
70 }
71 _wr.setUpdating (false);
72 static_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
73 _eep->on_changed();
74 }
75
76 //---------------------------------------------------
77
Licensor()78 Licensor::Licensor()
79 : Gtk::Box(Gtk::ORIENTATION_VERTICAL, 4),
80 _eentry (nullptr)
81 {
82 }
83
~Licensor()84 Licensor::~Licensor()
85 {
86 if (_eentry) delete _eentry;
87 }
88
init(Registry & wr)89 void Licensor::init (Registry& wr)
90 {
91 /* add license-specific metadata entry areas */
92 rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
93 _eentry = EntityEntry::create (entity, wr);
94
95 LicenseItem *i;
96 wr.setUpdating (true);
97 i = Gtk::manage (new LicenseItem (&_proprietary_license, _eentry, wr, nullptr));
98 Gtk::RadioButtonGroup group = i->get_group();
99 add (*i);
100 LicenseItem *pd = i;
101
102 for (struct rdf_license_t * license = rdf_licenses;
103 license && license->name;
104 license++) {
105 i = Gtk::manage (new LicenseItem (license, _eentry, wr, &group));
106 add(*i);
107 }
108 // add Other at the end before the URI field for the confused ppl.
109 LicenseItem *io = Gtk::manage (new LicenseItem (&_other_license, _eentry, wr, &group));
110 add (*io);
111
112 pd->set_active();
113 wr.setUpdating (false);
114
115 Gtk::Box *box = Gtk::manage (new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
116 pack_start (*box, true, true, 0);
117
118 box->pack_start (_eentry->_label, false, false, 5);
119 box->pack_start (*_eentry->_packable, true, true, 0);
120
121 show_all_children();
122 }
123
update(SPDocument * doc)124 void Licensor::update (SPDocument *doc)
125 {
126 /* identify the license info */
127 struct rdf_license_t * license = rdf_get_license (doc);
128
129 if (license) {
130 int i;
131 for (i=0; rdf_licenses[i].name; i++)
132 if (license == &rdf_licenses[i])
133 break;
134 static_cast<LicenseItem*>(get_children()[i+1])->set_active();
135 }
136 else {
137 static_cast<LicenseItem*>(get_children()[0])->set_active();
138 }
139
140 /* update the URI */
141 _eentry->update (doc);
142 }
143
144 } // namespace Dialog
145 } // namespace UI
146 } // namespace Inkscape
147
148 /*
149 Local Variables:
150 mode:c++
151 c-file-style:"stroustrup"
152 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
153 indent-tabs-mode:nil
154 fill-column:99
155 End:
156 */
157 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
158