Code

Line-end fix
[inkscape.git] / src / ui / dialog / document-metadata.cpp
1 /** \file
2  *
3  * Document metadata dialog, Gtkmm-style
4  *
5  * Authors:
6  *   bulia byak <buliabyak@users.sf.net>
7  *   Bryce W. Harrington <bryce@bryceharrington.org>
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Jon Phillips <jon@rejon.org>
10  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
11  *
12  * Copyright (C) 2000 - 2006 Authors
13  *
14  * Released under GNU GPL.  Read the file 'COPYING' for more information
15  */
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
23 #include "ui/widget/entity-entry.h"
25 #include "xml/node-event-vector.h"
26 #include "dialogs/rdf.h"
28 #include "inkscape.h"
29 #include "verbs.h"
30 #include "desktop-handles.h"
31 #include "desktop.h"
32 #include "sp-namedview.h"
34 #include "document-metadata.h"
36 //using std::pair;
38 namespace Inkscape {
39 namespace UI {
40 namespace Dialog {
42 #define SPACE_SIZE_X 15
43 #define SPACE_SIZE_Y 15
45 //===================================================
47 //---------------------------------------------------
49 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
51 static Inkscape::XML::NodeEventVector const _repr_events = {
52     NULL, /* child_added */
53     NULL, /* child_removed */
54     on_repr_attr_changed,
55     NULL, /* content_changed */
56     NULL  /* order_changed */
57 };
60 DocumentMetadata &
61 DocumentMetadata::getInstance()
62 {
63     DocumentMetadata &instance = *new DocumentMetadata();
64     instance.init();
65     return instance;
66 }
69 DocumentMetadata::DocumentMetadata()
70     : UI::Widget::Panel ("", "dialogs.documentmetadata", SP_VERB_DIALOG_METADATA),
71       _page_metadata1(1, 1), _page_metadata2(1, 1),
72       _prefs_path("dialogs.documentmetadata")
73 {
74     hide();
75     _tt.enable();
76     _getContents()->set_spacing (4);
77     _getContents()->pack_start(_notebook, true, true);
79     _notebook.append_page(_page_metadata1, _("Metadata"));
80     _notebook.append_page(_page_metadata2, _("License"));
82     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDocumentReplaced));
83     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleActivateDesktop));
84     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDeactivateDesktop));
86     build_metadata();
87 }
89 void
90 DocumentMetadata::init()
91 {
92     update();
94     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
95     repr->addListener (&_repr_events, this);
97     show_all_children();
98 }
100 DocumentMetadata::~DocumentMetadata()
102     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
103     repr->removeListenerByData (this);
105     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
106         delete (*it);
109 //========================================================================
111 /**
112  * Helper function that attachs widgets in a 3xn table. The widgets come in an
113  * array that has two entries per table row. The two entries code for four
114  * possible cases: (0,0) means insert space in first column; (0, non-0) means
115  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
116  * (non-0, non-0) means two widgets in columns 2 and 3.
117 **/
118 inline void
119 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
121     for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
122     {
123         if (arr[i] && arr[i+1])
124         {
125             table.attach (const_cast<Gtk::Widget&>(*arr[i]),   1, 2, r, r+1,
126                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
127             table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
128                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
129         }
130         else
131         {
132             if (arr[i+1])
133                 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
134                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
135             else if (arr[i])
136             {
137                 Gtk::Label& label = static_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
138                 label.set_alignment (0.0);
139                 table.attach (label, 0, 3, r, r+1,
140                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
141             }
142             else
143             {
144                 Gtk::HBox *space = manage (new Gtk::HBox);
145                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
146                 table.attach (*space, 0, 1, r, r+1,
147                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
148             }
149         }
150         ++r;
151     }
154 void
155 DocumentMetadata::build_metadata()
157     _page_metadata1.show();
159     Gtk::Label *label = manage (new Gtk::Label);
160     label->set_markup (_("<b>Dublin Core Entities</b>"));
161     label->set_alignment (0.0);
162     _page_metadata1.table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
163      /* add generic metadata entry areas */
164     struct rdf_work_entity_t * entity;
165     int row = 1;
166     for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {
167         if ( entity->editable == RDF_EDIT_GENERIC ) {
168             EntityEntry *w = EntityEntry::create (entity, _tt, _wr);
169             _rdflist.push_back (w);
170             Gtk::HBox *space = manage (new Gtk::HBox);
171             space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
172             _page_metadata1.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
173             _page_metadata1.table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
174             _page_metadata1.table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
175         }
176     }
178     _page_metadata2.show();
180     row = 0;
181     Gtk::Label *llabel = manage (new Gtk::Label);
182     llabel->set_markup (_("<b>License</b>"));
183     llabel->set_alignment (0.0);
184     _page_metadata2.table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
185     /* add license selector pull-down and URI */
186     ++row;
187     _licensor.init (_tt, _wr);
188     Gtk::HBox *space = manage (new Gtk::HBox);
189     space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
190     _page_metadata2.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
191     _page_metadata2.table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
194 /**
195  * Update dialog widgets from desktop.
196  */
197 void
198 DocumentMetadata::update()
200     if (_wr.isUpdating()) return;
202     _wr.setUpdating (true);
203     set_sensitive (true);
205     //-----------------------------------------------------------meta pages
206     /* update the RDF entities */
207     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
208         (*it)->update (SP_ACTIVE_DOCUMENT);
210     _licensor.update (SP_ACTIVE_DOCUMENT);
212     _wr.setUpdating (false);
215 void 
216 DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *)
218     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
219     repr->addListener (&_repr_events, this);
220     update();
223 void 
224 DocumentMetadata::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
226     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
227     repr->addListener(&_repr_events, this);
228     update();
231 void
232 DocumentMetadata::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
234     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
235     repr->removeListenerByData(this);
238 //--------------------------------------------------------------------
240 /**
241  * Called when XML node attribute changed; updates dialog widgets.
242  */
243 static void
244 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
246     if (DocumentMetadata *dialog = static_cast<DocumentMetadata *>(data))
247         dialog->update();
250 } // namespace Dialog
251 } // namespace UI
252 } // namespace Inkscape
254 /*
255   Local Variables:
256   mode:c++
257   c-file-style:"stroustrup"
258   c-file-offsets:((innamespace . 0)(inline-open . 0))
259   indent-tabs-mode:nil
260   fill-column:99
261   End:
262 */
263 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :