Code

clean up redundancies. add a placeholder for Export dialog
[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 "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, SP_VERB_NONE, 
65                       /* TODO: annotate */ "licensor.cpp:65");
66     _wr.setUpdating (false);
67     reinterpret_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
68     _eep->on_changed();
69 }
71 //---------------------------------------------------
73 Licensor::Licensor()
74 : Gtk::VBox(false,4)
75 {
76 }
78 Licensor::~Licensor()
79 {
80     if (_eentry) delete _eentry;
81 }
83 void
84 Licensor::init (Gtk::Tooltips& tt, Registry& wr)
85 {
86     /* add license-specific metadata entry areas */
87     rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
88     _eentry = EntityEntry::create (entity, tt, wr);
90     LicenseItem *i;
91     wr.setUpdating (true);
92     i = manage (new LicenseItem (&_proprietary_license, _eentry, wr));
93     add (*i);
94     LicenseItem *pd = i;
95     for (struct rdf_license_t * license = rdf_licenses;
96              license && license->name;
97              license++) {
98         i = manage (new LicenseItem (license, _eentry, wr));
99         add(*i);
100     }
101     pd->set_active();
102     wr.setUpdating (false);
104     Gtk::HBox *box = manage (new Gtk::HBox);
105     pack_start (*box, true, true, 0);
107     box->pack_start (_eentry->_label, false, false, 5);
108     box->pack_start (*_eentry->_packable, true, true, 0);
110     show_all_children();
113 void 
114 Licensor::update (SPDocument *doc)
116     /* identify the license info */
117     struct rdf_license_t * license = rdf_get_license (doc);
119     if (license) {
120         int i;
121         for (i=0; rdf_licenses[i].name; i++) 
122             if (license == &rdf_licenses[i]) 
123                 break;
124         reinterpret_cast<LicenseItem*>(children()[i+1].get_widget())->set_active();
125     }
126     else {
127         reinterpret_cast<LicenseItem*>(children()[0].get_widget())->set_active();
128     }
129     
130     /* update the URI */
131     _eentry->update (doc);
134 } // namespace Dialog
135 } // namespace UI
136 } // namespace Inkscape
138 /*
139   Local Variables:
140   mode:c++
141   c-file-style:"stroustrup"
142   c-file-offsets:((innamespace . 0)(inline-open . 0))
143   indent-tabs-mode:nil
144   fill-column:99
145   End:
146 */
147 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :