Code

display waiting cursor; move credits to a page of its own
[inkscape.git] / src / ui / dialog / document-metadata.cpp
1 /** @file
2  * @brief Document metadata dialog, Gtkmm-style
3  */
4 /* Authors:
5  *   bulia byak <buliabyak@users.sf.net>
6  *   Bryce W. Harrington <bryce@bryceharrington.org>
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   Jon Phillips <jon@rejon.org>
9  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
10  *
11  * Copyright (C) 2000 - 2006 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
22 #include "ui/widget/entity-entry.h"
24 #include "xml/node-event-vector.h"
25 #include "dialogs/rdf.h"
27 #include "inkscape.h"
28 #include "verbs.h"
29 #include "desktop-handles.h"
30 #include "desktop.h"
31 #include "sp-namedview.h"
33 #include "document-metadata.h"
35 //using std::pair;
37 namespace Inkscape {
38 namespace UI {
39 namespace Dialog {
41 #define SPACE_SIZE_X 15
42 #define SPACE_SIZE_Y 15
44 //===================================================
46 //---------------------------------------------------
48 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
50 static Inkscape::XML::NodeEventVector const _repr_events = {
51     NULL, /* child_added */
52     NULL, /* child_removed */
53     on_repr_attr_changed,
54     NULL, /* content_changed */
55     NULL  /* order_changed */
56 };
59 DocumentMetadata &
60 DocumentMetadata::getInstance()
61 {
62     DocumentMetadata &instance = *new DocumentMetadata();
63     instance.init();
64     return instance;
65 }
68 DocumentMetadata::DocumentMetadata()
69     : UI::Widget::Panel ("", "/dialogs/documentmetadata", SP_VERB_DIALOG_METADATA),
70       _page_metadata1(1, 1), _page_metadata2(1, 1)
71 {
72     hide();
73     _tt.enable();
74     _getContents()->set_spacing (4);
75     _getContents()->pack_start(_notebook, true, true);
77     _notebook.append_page(_page_metadata1, _("Metadata"));
78     _notebook.append_page(_page_metadata2, _("License"));
80     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDocumentReplaced));
81     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleActivateDesktop));
82     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDeactivateDesktop));
84     build_metadata();
85 }
87 void
88 DocumentMetadata::init()
89 {
90     update();
92     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
93     repr->addListener (&_repr_events, this);
95     show_all_children();
96 }
98 DocumentMetadata::~DocumentMetadata()
99 {
100     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
101     repr->removeListenerByData (this);
103     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
104         delete (*it);
107 //========================================================================
109 /**
110  * Helper function that attachs widgets in a 3xn table. The widgets come in an
111  * array that has two entries per table row. The two entries code for four
112  * possible cases: (0,0) means insert space in first column; (0, non-0) means
113  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
114  * (non-0, non-0) means two widgets in columns 2 and 3.
115 **/
116 inline void
117 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
119     for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
120     {
121         if (arr[i] && arr[i+1])
122         {
123             table.attach (const_cast<Gtk::Widget&>(*arr[i]),   1, 2, r, r+1,
124                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
125             table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
126                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
127         }
128         else
129         {
130             if (arr[i+1])
131                 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
132                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
133             else if (arr[i])
134             {
135                 Gtk::Label& label = static_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
136                 label.set_alignment (0.0);
137                 table.attach (label, 0, 3, r, r+1,
138                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
139             }
140             else
141             {
142                 Gtk::HBox *space = manage (new Gtk::HBox);
143                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
144                 table.attach (*space, 0, 1, r, r+1,
145                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
146             }
147         }
148         ++r;
149     }
152 void
153 DocumentMetadata::build_metadata()
155     _page_metadata1.show();
157     Gtk::Label *label = manage (new Gtk::Label);
158     label->set_markup (_("<b>Dublin Core Entities</b>"));
159     label->set_alignment (0.0);
160     _page_metadata1.table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
161      /* add generic metadata entry areas */
162     struct rdf_work_entity_t * entity;
163     int row = 1;
164     for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {
165         if ( entity->editable == RDF_EDIT_GENERIC ) {
166             EntityEntry *w = EntityEntry::create (entity, _tt, _wr);
167             _rdflist.push_back (w);
168             Gtk::HBox *space = manage (new Gtk::HBox);
169             space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
170             _page_metadata1.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
171             _page_metadata1.table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
172             _page_metadata1.table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
173         }
174     }
176     _page_metadata2.show();
178     row = 0;
179     Gtk::Label *llabel = manage (new Gtk::Label);
180     llabel->set_markup (_("<b>License</b>"));
181     llabel->set_alignment (0.0);
182     _page_metadata2.table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
183     /* add license selector pull-down and URI */
184     ++row;
185     _licensor.init (_tt, _wr);
186     Gtk::HBox *space = manage (new Gtk::HBox);
187     space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
188     _page_metadata2.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
189     _page_metadata2.table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
192 /**
193  * Update dialog widgets from desktop.
194  */
195 void
196 DocumentMetadata::update()
198     if (_wr.isUpdating()) return;
200     _wr.setUpdating (true);
201     set_sensitive (true);
203     //-----------------------------------------------------------meta pages
204     /* update the RDF entities */
205     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
206         (*it)->update (SP_ACTIVE_DOCUMENT);
208     _licensor.update (SP_ACTIVE_DOCUMENT);
210     _wr.setUpdating (false);
213 void 
214 DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *)
216     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
217     repr->addListener (&_repr_events, this);
218     update();
221 void 
222 DocumentMetadata::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
224     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
225     repr->addListener(&_repr_events, this);
226     update();
229 void
230 DocumentMetadata::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
232     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
233     repr->removeListenerByData(this);
236 //--------------------------------------------------------------------
238 /**
239  * Called when XML node attribute changed; updates dialog widgets.
240  */
241 static void
242 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
244     if (DocumentMetadata *dialog = static_cast<DocumentMetadata *>(data))
245         dialog->update();
248 } // namespace Dialog
249 } // namespace UI
250 } // namespace Inkscape
252 /*
253   Local Variables:
254   mode:c++
255   c-file-style:"stroustrup"
256   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
257   indent-tabs-mode:nil
258   fill-column:99
259   End:
260 */
261 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :