Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / src / gtkmm / dialogsettings.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialogsettings.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 "dialogsettings.h"
33 #include <synfigapp/main.h>
34
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44 using namespace studio;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 DialogSettings::DialogSettings(Gtk::Window* window,const synfig::String& name):
55         window(window),
56         name(name)
57 {
58         synfigapp::Main::settings().add_domain(this,"window."+name);
59 }
60
61 DialogSettings::~DialogSettings()
62 {
63         synfigapp::Main::settings().remove_domain("window."+name);
64 }
65
66 bool
67 DialogSettings::get_value(const synfig::String& key, synfig::String& value)const
68 {
69         if(key=="pos")
70         {
71                 if(!window->is_visible())return false;
72                 int x,y; window->get_position(x,y);
73                 value=strprintf("%d %d",x,y);
74                 return true;
75         }
76         if(key=="size")
77         {
78                 if(!window->is_visible())return false;
79                 int x,y; window->get_size(x,y);
80                 value=strprintf("%d %d",x,y);
81                 return true;
82         }
83         if(key=="x")
84         {
85                 int x,y; window->get_position(x,y);
86                 value=strprintf("%d",x);
87                 return true;
88         }
89         if(key=="y")
90         {
91                 int x,y; window->get_position(x,y);
92                 value=strprintf("%d",y);
93                 return true;
94         }
95         if(key=="w")
96         {
97                 int x,y; window->get_size(x,y);
98                 value=strprintf("%d",x);
99                 return true;
100         }
101         if(key=="h")
102         {
103                 int x,y; window->get_size(x,y);
104                 value=strprintf("%d",y);
105                 return true;
106         }
107         if(key=="visible")
108         {
109                 value=window->is_visible()?"1":"0";
110                 return true;
111         }
112
113         return synfigapp::Settings::get_value(key,value);
114 }
115
116 bool
117 DialogSettings::set_value(const synfig::String& key,const synfig::String& value)
118 {
119         if(value.empty())
120                 return false;
121
122         if(key=="pos")
123         {
124                 int x,y;
125                 if(!strscanf(value,"%d %d",&x, &y))
126                         return false;
127                 window->move(x,y);
128                 return true;
129         }
130         if(key=="size")
131         {
132                 int x,y;
133                 if(!strscanf(value,"%d %d",&x, &y))
134                         return false;
135                 window->set_default_size(x,y);
136                 return true;
137         }
138         if(key=="x")
139         {
140                 int x,y; window->get_position(x,y);
141                 x=atoi(value.c_str());
142                 window->move(x,y);
143                 return true;
144         }
145         if(key=="y")
146         {
147                 int x,y; window->get_position(x,y);
148                 y=atoi(value.c_str());
149                 window->move(x,y);
150                 return true;
151         }
152         if(key=="w")
153         {
154                 int x,y; window->get_size(x,y);
155                 x=atoi(value.c_str());
156                 window->set_default_size(x,y);
157                 return true;
158         }
159         if(key=="h")
160         {
161                 int x,y; window->get_size(x,y);
162                 y=atoi(value.c_str());
163                 window->set_default_size(x,y);
164                 return true;
165         }
166         if(key=="visible")
167         {
168                 if(value=="0")
169                         window->hide();
170                 else
171                         window->present();
172                 return true;
173         }
174
175         return synfigapp::Settings::set_value(key,value);
176 }
177
178 synfigapp::Settings::KeyList
179 DialogSettings::get_key_list()const
180 {
181         synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
182
183         ret.push_back("size");
184         ret.push_back("pos");
185         ret.push_back("visible");
186
187         return ret;
188 }