Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuedescconvert.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuedescconvert.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 /*
33 #include "valuenodereplace.h"
34 #include "layerparamconnect.h"
35 #include "valuenodelinkconnect.h"
36 */
37
38 #include "valuedescconnect.h"
39
40 #include "valuedescconvert.h"
41
42 #include <synfigapp/canvasinterface.h>
43 #include <synfig/valuenode_const.h>
44
45 #include <synfigapp/general.h>
46
47 #endif
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace synfigapp;
53 using namespace Action;
54
55 /* === M A C R O S ========================================================= */
56
57 ACTION_INIT(Action::ValueDescConvert);
58 ACTION_SET_NAME(Action::ValueDescConvert,"value_desc_convert");
59 ACTION_SET_LOCAL_NAME(Action::ValueDescConvert,N_("Convert"));
60 ACTION_SET_TASK(Action::ValueDescConvert,"convert");
61 ACTION_SET_CATEGORY(Action::ValueDescConvert,Action::CATEGORY_VALUEDESC);
62 ACTION_SET_PRIORITY(Action::ValueDescConvert,0);
63 ACTION_SET_VERSION(Action::ValueDescConvert,"0.0");
64 ACTION_SET_CVS_ID(Action::ValueDescConvert,"$Id$");
65
66 /* === G L O B A L S ======================================================= */
67
68 /* === P R O C E D U R E S ================================================= */
69
70 /* === M E T H O D S ======================================================= */
71
72 Action::ValueDescConvert::ValueDescConvert()
73 {
74 }
75
76 Action::ParamVocab
77 Action::ValueDescConvert::get_param_vocab()
78 {
79         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80
81         ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
82                 .set_local_name(_("ValueDesc"))
83         );
84
85         ret.push_back(ParamDesc("type",Param::TYPE_STRING)
86                 .set_local_name(_("Type"))
87                 .set_desc(_("The type of ValueNode that you want to be converted to"))
88         );
89
90         return ret;
91 }
92
93 bool
94 Action::ValueDescConvert::is_candidate(const ParamList &x)
95 {
96         return candidate_check(get_param_vocab(),x);
97 }
98
99 bool
100 Action::ValueDescConvert::set_param(const synfig::String& name, const Action::Param &param)
101 {
102         if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
103         {
104                 value_desc=param.get_value_desc();
105
106                 return true;
107         }
108
109         if(name=="type" && param.get_type()==Param::TYPE_STRING)
110         {
111                 type=param.get_string();
112
113                 return true;
114         }
115
116         return Action::CanvasSpecific::set_param(name,param);
117 }
118
119 bool
120 Action::ValueDescConvert::is_ready()const
121 {
122         if(!value_desc || type.empty())
123                 return false;
124         return Action::CanvasSpecific::is_ready();
125 }
126
127 void
128 Action::ValueDescConvert::prepare()
129 {
130         clear();
131
132         ValueBase value;
133
134         if(value_desc.is_const())
135                 value=value_desc.get_value();
136         else if(value_desc.is_value_node())
137                 value=(*value_desc.get_value_node())(0);
138         else
139                 throw Error(_("Unable to decipher ValueDesc (Bug?)"));
140
141         ValueNode::Handle src_value_node(LinkableValueNode::create(type,value));
142
143         if(!src_value_node)
144                 throw Error(_("Unable to create new value node"));
145
146
147         ValueNode::Handle dest_value_node;
148         dest_value_node=value_desc.get_value_node();
149
150         Action::Handle action(ValueDescConnect::create());
151
152         action->set_param("canvas",get_canvas());
153         action->set_param("canvas_interface",get_canvas_interface());
154         action->set_param("src",src_value_node);
155         action->set_param("dest",value_desc);
156
157         assert(action->is_ready());
158         if(!action->is_ready())
159                 throw Error(Error::TYPE_NOTREADY);
160
161         add_action_front(action);
162
163 /*
164         return;
165
166
167         if(value_desc.parent_is_canvas())
168         {
169                 ValueNode::Handle dest_value_node;
170                 dest_value_node=value_desc.get_value_node();
171
172                 Action::Handle action(ValueNodeReplace::create());
173
174                 action->set_param("canvas",get_canvas());
175                 action->set_param("canvas_interface",get_canvas_interface());
176                 action->set_param("src",src_value_node);
177                 action->set_param("dest",dest_value_node);
178
179                 assert(action->is_ready());
180                 if(!action->is_ready())
181                         throw Error(Error::TYPE_NOTREADY);
182
183                 add_action_front(action);
184                 return;
185         }
186         else
187         if(value_desc.parent_is_linkable_value_node())
188         {
189                 Action::Handle action(ValueNodeLinkConnect::create());
190
191                 action->set_param("canvas",get_canvas());
192                 action->set_param("canvas_interface",get_canvas_interface());
193                 action->set_param("parent_value_node",value_desc.get_parent_value_node());
194                 action->set_param("value_node", src_value_node);
195                 action->set_param("index",value_desc.get_index());
196
197                 assert(action->is_ready());
198                 if(!action->is_ready())
199                         throw Error(Error::TYPE_NOTREADY);
200
201                 add_action_front(action);
202                 return;
203         }
204         else
205         if(value_desc.parent_is_layer_param())
206         {
207                 Action::Handle action(LayerParamConnect::create());
208
209                 action->set_param("canvas",get_canvas());
210                 action->set_param("canvas_interface",get_canvas_interface());
211                 action->set_param("layer",value_desc.get_layer());
212                 action->set_param("param",value_desc.get_param_name());
213                 action->set_param("value_node",src_value_node);
214
215                 assert(action->is_ready());
216                 if(!action->is_ready())
217                         throw Error(Error::TYPE_NOTREADY);
218
219                 add_action_front(action);
220                 return;
221         }
222
223
224
225         throw Error(_("ValueDesc is not recognized or supported."));
226 */
227 }