Code

merge
[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
20 #include "desktop.h"
21 #include "desktop-handles.h"
22 #include "inkscape.h"
23 #include "rdf.h"
24 #include "sp-namedview.h"
25 #include "ui/widget/entity-entry.h"
26 #include "verbs.h"
27 #include "xml/node-event-vector.h"
29 #include "document-metadata.h"
31 //using std::pair;
33 namespace Inkscape {
34 namespace UI {
35 namespace Dialog {
37 #define SPACE_SIZE_X 15
38 #define SPACE_SIZE_Y 15
40 //===================================================
42 //---------------------------------------------------
44 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
46 static Inkscape::XML::NodeEventVector const _repr_events = {
47     NULL, /* child_added */
48     NULL, /* child_removed */
49     on_repr_attr_changed,
50     NULL, /* content_changed */
51     NULL  /* order_changed */
52 };
55 DocumentMetadata &
56 DocumentMetadata::getInstance()
57 {
58     DocumentMetadata &instance = *new DocumentMetadata();
59     instance.init();
60     return instance;
61 }
64 DocumentMetadata::DocumentMetadata()
65     : UI::Widget::Panel ("", "/dialogs/documentmetadata", SP_VERB_DIALOG_METADATA),
66       _page_metadata1(1, 1), _page_metadata2(1, 1)
67 {
68     hide();
69     _tt.enable();
70     _getContents()->set_spacing (4);
71     _getContents()->pack_start(_notebook, true, true);
73     _notebook.append_page(_page_metadata1, _("Metadata"));
74     _notebook.append_page(_page_metadata2, _("License"));
76     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDocumentReplaced));
77     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleActivateDesktop));
78     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDeactivateDesktop));
80     build_metadata();
81 }
83 void
84 DocumentMetadata::init()
85 {
86     update();
88     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
89     repr->addListener (&_repr_events, this);
91     show_all_children();
92 }
94 DocumentMetadata::~DocumentMetadata()
95 {
96     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
97     repr->removeListenerByData (this);
99     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
100         delete (*it);
103 //========================================================================
105 /**
106  * Helper function that attachs widgets in a 3xn table. The widgets come in an
107  * array that has two entries per table row. The two entries code for four
108  * possible cases: (0,0) means insert space in first column; (0, non-0) means
109  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
110  * (non-0, non-0) means two widgets in columns 2 and 3.
111 **/
112 inline void
113 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
115     for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
116     {
117         if (arr[i] && arr[i+1])
118         {
119             table.attach (const_cast<Gtk::Widget&>(*arr[i]),   1, 2, r, r+1,
120                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
121             table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
122                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
123         }
124         else
125         {
126             if (arr[i+1])
127                 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
128                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
129             else if (arr[i])
130             {
131                 Gtk::Label& label = static_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
132                 label.set_alignment (0.0);
133                 table.attach (label, 0, 3, r, r+1,
134                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
135             }
136             else
137             {
138                 Gtk::HBox *space = manage (new Gtk::HBox);
139                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
140                 table.attach (*space, 0, 1, r, r+1,
141                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
142             }
143         }
144         ++r;
145     }
148 void
149 DocumentMetadata::build_metadata()
151     _page_metadata1.show();
153     Gtk::Label *label = manage (new Gtk::Label);
154     label->set_markup (_("<b>Dublin Core Entities</b>"));
155     label->set_alignment (0.0);
156     _page_metadata1.table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
157      /* add generic metadata entry areas */
158     struct rdf_work_entity_t * entity;
159     int row = 1;
160     for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {
161         if ( entity->editable == RDF_EDIT_GENERIC ) {
162             EntityEntry *w = EntityEntry::create (entity, _tt, _wr);
163             _rdflist.push_back (w);
164             Gtk::HBox *space = manage (new Gtk::HBox);
165             space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
166             _page_metadata1.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
167             _page_metadata1.table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
168             _page_metadata1.table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
169         }
170     }
172     _page_metadata2.show();
174     row = 0;
175     Gtk::Label *llabel = manage (new Gtk::Label);
176     llabel->set_markup (_("<b>License</b>"));
177     llabel->set_alignment (0.0);
178     _page_metadata2.table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
179     /* add license selector pull-down and URI */
180     ++row;
181     _licensor.init (_tt, _wr);
182     Gtk::HBox *space = manage (new Gtk::HBox);
183     space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
184     _page_metadata2.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
185     _page_metadata2.table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
188 /**
189  * Update dialog widgets from desktop.
190  */
191 void
192 DocumentMetadata::update()
194     if (_wr.isUpdating()) return;
196     _wr.setUpdating (true);
197     set_sensitive (true);
199     //-----------------------------------------------------------meta pages
200     /* update the RDF entities */
201     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
202         (*it)->update (SP_ACTIVE_DOCUMENT);
204     _licensor.update (SP_ACTIVE_DOCUMENT);
206     _wr.setUpdating (false);
209 void 
210 DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *)
212     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
213     repr->addListener (&_repr_events, this);
214     update();
217 void 
218 DocumentMetadata::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
220     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
221     repr->addListener(&_repr_events, this);
222     update();
225 void
226 DocumentMetadata::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
228     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
229     repr->removeListenerByData(this);
232 //--------------------------------------------------------------------
234 /**
235  * Called when XML node attribute changed; updates dialog widgets.
236  */
237 static void
238 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
240     if (DocumentMetadata *dialog = static_cast<DocumentMetadata *>(data))
241         dialog->update();
244 } // namespace Dialog
245 } // namespace UI
246 } // namespace Inkscape
248 /*
249   Local Variables:
250   mode:c++
251   c-file-style:"stroustrup"
252   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
253   indent-tabs-mode:nil
254   fill-column:99
255   End:
256 */
257 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :