Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc1 / 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 #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 DialogSettings::DialogSettings(Gtk::Window* window,const synfig::String& name):
53         window(window),
54         name(name)
55 {
56         synfigapp::Main::settings().add_domain(this,"window."+name);
57 }
58
59 DialogSettings::~DialogSettings()
60 {
61         synfigapp::Main::settings().remove_domain("window."+name);
62 }
63
64 bool
65 DialogSettings::get_value(const synfig::String& key, synfig::String& value)const
66 {
67         if(key=="pos")
68         {
69                 if(!window->is_visible())return false;
70                 int x,y; window->get_position(x,y);
71                 value=strprintf("%d %d",x,y);
72                 return true;
73         }
74         if(key=="size")
75         {
76                 if(!window->is_visible())return false;
77                 int x,y; window->get_size(x,y);
78                 value=strprintf("%d %d",x,y);
79                 return true;
80         }
81         if(key=="x")
82         {
83                 int x,y; window->get_position(x,y);
84                 value=strprintf("%d",x);
85                 return true;
86         }
87         if(key=="y")
88         {
89                 int x,y; window->get_position(x,y);
90                 value=strprintf("%d",y);
91                 return true;
92         }
93         if(key=="w")
94         {
95                 int x,y; window->get_size(x,y);
96                 value=strprintf("%d",x);
97                 return true;
98         }
99         if(key=="h")
100         {
101                 int x,y; window->get_size(x,y);
102                 value=strprintf("%d",y);
103                 return true;
104         }
105         if(key=="visible")
106         {
107                 value=window->is_visible()?"1":"0";
108                 return true;
109         }
110
111         return synfigapp::Settings::get_value(key,value);
112 }
113
114 bool
115 DialogSettings::set_value(const synfig::String& key,const synfig::String& value)
116 {
117         if(value.empty())
118                 return false;
119
120         if(key=="pos")
121         {
122                 int x,y;
123                 if(!strscanf(value,"%d %d",&x, &y))
124                         return false;
125                 window->move(x,y);
126                 return true;
127         }
128         if(key=="size")
129         {
130                 int x,y;
131                 if(!strscanf(value,"%d %d",&x, &y))
132                         return false;
133                 window->set_default_size(x,y);
134                 return true;
135         }
136         if(key=="x")
137         {
138                 int x,y; window->get_position(x,y);
139                 x=atoi(value.c_str());
140                 window->move(x,y);
141                 return true;
142         }
143         if(key=="y")
144         {
145                 int x,y; window->get_position(x,y);
146                 y=atoi(value.c_str());
147                 window->move(x,y);
148                 return true;
149         }
150         if(key=="w")
151         {
152                 int x,y; window->get_size(x,y);
153                 x=atoi(value.c_str());
154                 window->set_default_size(x,y);
155                 return true;
156         }
157         if(key=="h")
158         {
159                 int x,y; window->get_size(x,y);
160                 y=atoi(value.c_str());
161                 window->set_default_size(x,y);
162                 return true;
163         }
164         if(key=="visible")
165         {
166                 if(value=="0")
167                         window->hide();
168                 else
169                         window->present();
170                 return true;
171         }
172
173         return synfigapp::Settings::set_value(key,value);
174 }
175
176 synfigapp::Settings::KeyList
177 DialogSettings::get_key_list()const
178 {
179         synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
180
181         ret.push_back("size");
182         ret.push_back("pos");
183         ret.push_back("visible");
184
185         return ret;
186 }