1 /** \file
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 *
10 * Copyright (C) 2000 - 2005 Authors
11 *
12 * Released under GNU GPL. Read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
19 #include <gtkmm/entry.h>
21 #include "ui/widget/entity-entry.h"
22 #include "ui/widget/registry.h"
23 #include "dialogs/rdf.h"
24 #include "inkscape.h"
26 #include "licensor.h"
28 namespace Inkscape {
29 namespace UI {
30 namespace Widget {
32 //===================================================
34 const struct rdf_license_t _proprietary_license =
35 {_("Proprietary"), "", 0};
37 class LicenseItem : public Gtk::RadioButton {
38 public:
39 LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr);
40 protected:
41 void on_toggled();
42 struct rdf_license_t const *_lic;
43 EntityEntry *_eep;
44 Registry &_wr;
45 };
47 LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr)
48 : Gtk::RadioButton(license->name), _lic(license), _eep(entity), _wr(wr)
49 {
50 static Gtk::RadioButtonGroup group = get_group();
51 static bool first = true;
52 if (first) first = false;
53 else set_group (group);
54 }
56 /// \pre it is assumed that the license URI entry is a Gtk::Entry
57 void
58 LicenseItem::on_toggled()
59 {
60 if (_wr.isUpdating()) return;
62 _wr.setUpdating (true);
63 rdf_set_license (SP_ACTIVE_DOCUMENT, _lic->details ? _lic : 0);
64 sp_document_done (SP_ACTIVE_DOCUMENT);
65 _wr.setUpdating (false);
66 reinterpret_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
67 _eep->on_changed();
68 }
70 //---------------------------------------------------
72 Licensor::Licensor()
73 : Gtk::VBox(false,4)
74 {
75 }
77 Licensor::~Licensor()
78 {
79 if (_eentry) delete _eentry;
80 }
82 void
83 Licensor::init (Gtk::Tooltips& tt, Registry& wr)
84 {
85 /* add license-specific metadata entry areas */
86 rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
87 _eentry = EntityEntry::create (entity, tt, wr);
89 LicenseItem *i;
90 wr.setUpdating (true);
91 i = manage (new LicenseItem (&_proprietary_license, _eentry, wr));
92 add (*i);
93 LicenseItem *pd = i;
94 for (struct rdf_license_t * license = rdf_licenses;
95 license && license->name;
96 license++) {
97 i = manage (new LicenseItem (license, _eentry, wr));
98 add(*i);
99 }
100 pd->set_active();
101 wr.setUpdating (false);
103 Gtk::HBox *box = manage (new Gtk::HBox);
104 pack_start (*box, true, true, 0);
106 box->pack_start (_eentry->_label, false, false, 5);
107 box->pack_start (*_eentry->_packable, true, true, 0);
109 show_all_children();
110 }
112 void
113 Licensor::update (SPDocument *doc)
114 {
115 /* identify the license info */
116 struct rdf_license_t * license = rdf_get_license (doc);
118 if (license) {
119 int i;
120 for (i=0; rdf_licenses[i].name; i++)
121 if (license == &rdf_licenses[i])
122 break;
123 reinterpret_cast<LicenseItem*>(children()[i+1].get_widget())->set_active();
124 }
125 else {
126 reinterpret_cast<LicenseItem*>(children()[0].get_widget())->set_active();
127 }
129 /* update the URI */
130 _eentry->update (doc);
131 }
133 } // namespace Dialog
134 } // namespace UI
135 } // namespace Inkscape
137 /*
138 Local Variables:
139 mode:c++
140 c-file-style:"stroustrup"
141 c-file-offsets:((innamespace . 0)(inline-open . 0))
142 indent-tabs-mode:nil
143 fill-column:99
144 End:
145 */
146 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :