licensor.cpp revision 0e0ded38da27b91261c0a27d788ec3e71f7bdcd1
1276N/A/** \file
1577N/A *
1276N/A * Authors:
1276N/A * bulia byak <buliabyak@users.sf.net>
1276N/A * Bryce W. Harrington <bryce@bryceharrington.org>
479N/A * Lauris Kaplinski <lauris@kaplinski.com>
851N/A * Jon Phillips <jon@rejon.org>
479N/A * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
1003N/A *
479N/A * Copyright (C) 2000 - 2005 Authors
479N/A *
479N/A * Released under GNU GPL. Read the file 'COPYING' for more information
479N/A */
1276N/A
479N/A#ifdef HAVE_CONFIG_H
479N/A# include <config.h>
479N/A#endif
479N/A
479N/A#include <gtkmm/entry.h>
479N/A
479N/A#include "ui/widget/entity-entry.h"
851N/A#include "ui/widget/registry.h"
1003N/A#include "dialogs/rdf.h"
1577N/A#include "inkscape.h"
851N/A
851N/A#include "licensor.h"
851N/A
851N/Anamespace Inkscape {
851N/Anamespace UI {
1577N/Anamespace Widget {
479N/A
479N/A//===================================================
479N/A
479N/Aconst struct rdf_license_t _proprietary_license =
479N/A {_("Proprietary"), "", 0};
479N/A
479N/Aclass LicenseItem : public Gtk::RadioButton {
479N/Apublic:
1003N/A LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr);
851N/Aprotected:
479N/A void on_toggled();
1003N/A struct rdf_license_t const *_lic;
479N/A EntityEntry *_eep;
479N/A Registry &_wr;
479N/A};
479N/A
1577N/ALicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* entity, Registry &wr)
1577N/A: Gtk::RadioButton(_(license->name)), _lic(license), _eep(entity), _wr(wr)
1577N/A{
1577N/A static Gtk::RadioButtonGroup group = get_group();
1577N/A static bool first = true;
479N/A if (first) first = false;
851N/A else set_group (group);
1577N/A}
479N/A
1577N/A/// \pre it is assumed that the license URI entry is a Gtk::Entry
479N/Avoid
851N/ALicenseItem::on_toggled()
1577N/A{
479N/A if (_wr.isUpdating()) return;
479N/A
479N/A _wr.setUpdating (true);
479N/A rdf_set_license (SP_ACTIVE_DOCUMENT, _lic->details ? _lic : 0);
1276N/A sp_document_done (SP_ACTIVE_DOCUMENT);
1276N/A _wr.setUpdating (false);
1276N/A reinterpret_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri);
1276N/A _eep->on_changed();
1276N/A}
1276N/A
1276N/A//---------------------------------------------------
1276N/A
Licensor::Licensor()
: Gtk::VBox(false,4)
{
}
Licensor::~Licensor()
{
if (_eentry) delete _eentry;
}
void
Licensor::init (Gtk::Tooltips& tt, Registry& wr)
{
/* add license-specific metadata entry areas */
rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" );
_eentry = EntityEntry::create (entity, tt, wr);
LicenseItem *i;
wr.setUpdating (true);
i = manage (new LicenseItem (&_proprietary_license, _eentry, wr));
add (*i);
LicenseItem *pd = i;
for (struct rdf_license_t * license = rdf_licenses;
license && license->name;
license++) {
i = manage (new LicenseItem (license, _eentry, wr));
add(*i);
}
pd->set_active();
wr.setUpdating (false);
Gtk::HBox *box = manage (new Gtk::HBox);
pack_start (*box, true, true, 0);
box->pack_start (_eentry->_label, false, false, 5);
box->pack_start (*_eentry->_packable, true, true, 0);
show_all_children();
}
void
Licensor::update (SPDocument *doc)
{
/* identify the license info */
struct rdf_license_t * license = rdf_get_license (doc);
if (license) {
int i;
for (i=0; rdf_licenses[i].name; i++)
if (license == &rdf_licenses[i])
break;
reinterpret_cast<LicenseItem*>(children()[i+1].get_widget())->set_active();
}
else {
reinterpret_cast<LicenseItem*>(children()[0].get_widget())->set_active();
}
/* update the URI */
_eentry->update (doc);
}
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :