Code

A simple layout document as to what, why and how is cppification.
[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  *
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 "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 const struct rdf_license_t _other_license = 
38   {Q_("MetadataLicence|Other"), "", 0};
40 class LicenseItem : public Gtk::RadioButton {
41 public:
42     LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr);
43 protected:
44     void on_toggled();
45     struct rdf_license_t const *_lic;
46     EntityEntry                *_eep;
47     Registry                   &_wr;
48 };
50 LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr)
51 : Gtk::RadioButton(_(license->name)), _lic(license), _eep(entity), _wr(wr)
52 {
53     static Gtk::RadioButtonGroup group = get_group();
54     static bool first = true;
55     if (first) first = false;
56     else       set_group (group);
57 }
59 /// \pre it is assumed that the license URI entry is a Gtk::Entry
60 void
61 LicenseItem::on_toggled()
62 {
63     if (_wr.isUpdating()) return;
65     _wr.setUpdating (true);
66     rdf_set_license (SP_ACTIVE_DOCUMENT, _lic->details ? _lic : 0);
67     SPDocumentUndo::done (SP_ACTIVE_DOCUMENT, SP_VERB_NONE, 
68                       /* TODO: annotate */ "licensor.cpp:65");
69     _wr.setUpdating (false);
70     static_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
71     _eep->on_changed();
72 }
74 //---------------------------------------------------
76 Licensor::Licensor()
77 : Gtk::VBox(false,4)
78 {
79 }
81 Licensor::~Licensor()
82 {
83     if (_eentry) delete _eentry;
84 }
86 void
87 Licensor::init (Gtk::Tooltips& tt, Registry& wr)
88 {
89     /* add license-specific metadata entry areas */
90     rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
91     _eentry = EntityEntry::create (entity, tt, wr);
93     LicenseItem *i;
94     wr.setUpdating (true);
95     i = manage (new LicenseItem (&_proprietary_license, _eentry, wr));
96     add (*i);
97     LicenseItem *pd = i;
99     for (struct rdf_license_t * license = rdf_licenses;
100              license && license->name;
101              license++) {
102         i = manage (new LicenseItem (license, _eentry, wr));
103         add(*i);
104     }
105     // add Other at the end before the URI field for the confused ppl.
106     LicenseItem *io = manage (new LicenseItem (&_other_license, _eentry, wr));
107     add (*io);
109     pd->set_active();
110     wr.setUpdating (false);
112     Gtk::HBox *box = manage (new Gtk::HBox);
113     pack_start (*box, true, true, 0);
115     box->pack_start (_eentry->_label, false, false, 5);
116     box->pack_start (*_eentry->_packable, true, true, 0);
118     show_all_children();
121 void 
122 Licensor::update (SPDocument *doc)
124     /* identify the license info */
125     struct rdf_license_t * license = rdf_get_license (doc);
127     if (license) {
128         int i;
129         for (i=0; rdf_licenses[i].name; i++) 
130             if (license == &rdf_licenses[i]) 
131                 break;
132         static_cast<LicenseItem*>(children()[i+1].get_widget())->set_active();
133     }
134     else {
135         static_cast<LicenseItem*>(children()[0].get_widget())->set_active();
136     }
137     
138     /* update the URI */
139     _eentry->update (doc);
142 } // namespace Dialog
143 } // namespace UI
144 } // namespace Inkscape
146 /*
147   Local Variables:
148   mode:c++
149   c-file-style:"stroustrup"
150   c-file-offsets:((innamespace . 0)(inline-open . 0))
151   indent-tabs-mode:nil
152   fill-column:99
153   End:
154 */
155 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :