Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_06 / src / gtkmm / metadatatreestore.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file metadatatreestore.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "metadatatreestore.h"
33 #include <synfigapp/canvasinterface.h>
34
35 #endif
36
37 /* === U S I N G =========================================================== */
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace studio;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 static MetaDataTreeStore::Model& ModelHack()
53 {
54         static MetaDataTreeStore::Model* model(0);
55         if(!model)model=new MetaDataTreeStore::Model;
56         return *model;
57 }
58
59 MetaDataTreeStore::MetaDataTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
60         Gtk::TreeStore  (ModelHack()),
61         canvas_interface_               (canvas_interface_)
62 {
63         // Connect the signal
64         get_canvas()->signal_meta_data_changed().connect(sigc::mem_fun(*this,&MetaDataTreeStore::meta_data_changed));
65
66         rebuild();
67 }
68
69 MetaDataTreeStore::~MetaDataTreeStore()
70 {
71         synfig::info("MetaDataTreeStore::~MetaDataTreeStore(): Deleted");
72
73 }
74
75 Glib::RefPtr<MetaDataTreeStore>
76 MetaDataTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
77 {
78         return Glib::RefPtr<MetaDataTreeStore>(new MetaDataTreeStore(canvas_interface_));
79 }
80
81 void
82 MetaDataTreeStore::meta_data_changed(synfig::String key)
83 {
84         rebuild();
85 }
86
87 void
88 MetaDataTreeStore::rebuild()
89 {
90         clear();
91
92         std::list<String> keys(get_canvas()->get_meta_data_keys());
93
94         for(;!keys.empty();keys.pop_front())
95         {
96                 Gtk::TreeRow row(*append());
97                 row[model.key]=keys.front();
98         }
99 }
100
101 void
102 MetaDataTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
103 {
104         if(column>=get_n_columns_vfunc())
105         {
106                 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
107                 return;
108         }
109
110         if(column==model.data.index())
111         {
112                 synfig::String key((Glib::ustring)(*iter)[model.key]);
113                 g_value_init(value.gobj(),G_TYPE_STRING);
114                 g_value_set_string(value.gobj(),get_canvas()->get_meta_data(key).c_str());
115                 return;
116         }
117         else
118                 Gtk::TreeStore::get_value_vfunc(iter,column,value);
119 }
120
121 void
122 MetaDataTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
123 {
124         if(column>=get_n_columns_vfunc())
125         {
126                 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
127                 return;
128         }
129
130         if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
131         {
132                 g_warning("KeyframeTreeStore::set_value_impl: Bad value type");
133                 return;
134         }
135
136         if(column==model.data.index())
137         {
138                 Glib::Value<Glib::ustring> x;
139                 g_value_init(x.gobj(),model.data.type());
140                 g_value_copy(value.gobj(),x.gobj());
141
142                 synfig::String key((Glib::ustring)(*iter)[model.key]);
143                 synfig::String new_data(x.get());
144
145                 get_canvas_interface()->set_meta_data(key,new_data);
146         }
147         else
148                 Gtk::TreeStore::set_value_impl(iter,column, value);
149 }