Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / widget / licensor.cpp
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  *   Abhishek Sharma
10  *
11  * Copyright (C) 2000 - 2005 Authors
12  *
13  * Released under GNU GPL.  Read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 #include <gtkmm/entry.h>
22 #include "ui/widget/entity-entry.h"
23 #include "ui/widget/registry.h"
24 #include "rdf.h"
25 #include "inkscape.h"
27 #include "licensor.h"
29 namespace Inkscape {
30 namespace UI {
31 namespace Widget {
33 //===================================================
35 const struct rdf_license_t _proprietary_license = 
36   {_("Proprietary"), "", 0};
38 const struct rdf_license_t _other_license = 
39   {Q_("MetadataLicence|Other"), "", 0};
41 class LicenseItem : public Gtk::RadioButton {
42 public:
43     LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr);
44 protected:
45     void on_toggled();
46     struct rdf_license_t const *_lic;
47     EntityEntry                *_eep;
48     Registry                   &_wr;
49 };
51 LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr)
52 : Gtk::RadioButton(_(license->name)), _lic(license), _eep(entity), _wr(wr)
53 {
54     static Gtk::RadioButtonGroup group = get_group();
55     static bool first = true;
56     if (first) first = false;
57     else       set_group (group);
58 }
60 /// \pre it is assumed that the license URI entry is a Gtk::Entry
61 void
62 LicenseItem::on_toggled()
63 {
64     if (_wr.isUpdating()) return;
66     _wr.setUpdating (true);
67     rdf_set_license (SP_ACTIVE_DOCUMENT, _lic->details ? _lic : 0);
68     DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_NONE, 
69                        /* TODO: annotate */ "licensor.cpp:65");
70     _wr.setUpdating (false);
71     static_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
72     _eep->on_changed();
73 }
75 //---------------------------------------------------
77 Licensor::Licensor()
78 : Gtk::VBox(false,4)
79 {
80 }
82 Licensor::~Licensor()
83 {
84     if (_eentry) delete _eentry;
85 }
87 void
88 Licensor::init (Gtk::Tooltips& tt, Registry& wr)
89 {
90     /* add license-specific metadata entry areas */
91     rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
92     _eentry = EntityEntry::create (entity, tt, wr);
94     LicenseItem *i;
95     wr.setUpdating (true);
96     i = manage (new LicenseItem (&_proprietary_license, _eentry, wr));
97     add (*i);
98     LicenseItem *pd = i;
100     for (struct rdf_license_t * license = rdf_licenses;
101              license && license->name;
102              license++) {
103         i = manage (new LicenseItem (license, _eentry, wr));
104         add(*i);
105     }
106     // add Other at the end before the URI field for the confused ppl.
107     LicenseItem *io = manage (new LicenseItem (&_other_license, _eentry, wr));
108     add (*io);
110     pd->set_active();
111     wr.setUpdating (false);
113     Gtk::HBox *box = manage (new Gtk::HBox);
114     pack_start (*box, true, true, 0);
116     box->pack_start (_eentry->_label, false, false, 5);
117     box->pack_start (*_eentry->_packable, true, true, 0);
119     show_all_children();
122 void 
123 Licensor::update (SPDocument *doc)
125     /* identify the license info */
126     struct rdf_license_t * license = rdf_get_license (doc);
128     if (license) {
129         int i;
130         for (i=0; rdf_licenses[i].name; i++) 
131             if (license == &rdf_licenses[i]) 
132                 break;
133         static_cast<LicenseItem*>(children()[i+1].get_widget())->set_active();
134     }
135     else {
136         static_cast<LicenseItem*>(children()[0].get_widget())->set_active();
137     }
138     
139     /* update the URI */
140     _eentry->update (doc);
143 } // namespace Dialog
144 } // namespace UI
145 } // namespace Inkscape
147 /*
148   Local Variables:
149   mode:c++
150   c-file-style:"stroustrup"
151   c-file-offsets:((innamespace . 0)(inline-open . 0))
152   indent-tabs-mode:nil
153   fill-column:99
154   End:
155 */
156 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :