my log
[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: dialogsettings.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "dialogsettings.h"
32 #include <synfigapp/main.h>
33
34 #endif
35
36 /* === U S I N G =========================================================== */
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41 using namespace studio;
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 /* === P R O C E D U R E S ================================================= */
48
49 /* === M E T H O D S ======================================================= */
50
51 DialogSettings::DialogSettings(Gtk::Window* window,const synfig::String& name):
52         window(window),
53         name(name)
54 {
55         synfigapp::Main::settings().add_domain(this,"window."+name);
56 }
57
58 DialogSettings::~DialogSettings()
59 {
60         synfigapp::Main::settings().remove_domain("window."+name);
61 }
62
63 bool
64 DialogSettings::get_value(const synfig::String& key, synfig::String& value)const
65 {
66         if(key=="pos")
67         {
68                 if(!window->is_visible())return false;
69                 int x,y; window->get_position(x,y);
70                 value=strprintf("%d %d",x,y);
71                 return true;
72         }
73         if(key=="size")
74         {
75                 if(!window->is_visible())return false;
76                 int x,y; window->get_size(x,y);
77                 value=strprintf("%d %d",x,y);
78                 return true;
79         }
80         if(key=="x")
81         {
82                 int x,y; window->get_position(x,y);
83                 value=strprintf("%d",x);
84                 return true;
85         }
86         if(key=="y")
87         {
88                 int x,y; window->get_position(x,y);
89                 value=strprintf("%d",y);
90                 return true;
91         }
92         if(key=="w")
93         {
94                 int x,y; window->get_size(x,y);
95                 value=strprintf("%d",x);
96                 return true;
97         }
98         if(key=="h")
99         {
100                 int x,y; window->get_size(x,y);
101                 value=strprintf("%d",y);
102                 return true;
103         }
104         if(key=="visible")
105         {
106                 value=window->is_visible()?"1":"0";
107                 return true;
108         }
109
110         return synfigapp::Settings::get_value(key,value);
111 }
112
113 bool
114 DialogSettings::set_value(const synfig::String& key,const synfig::String& value)
115 {
116         if(value.empty())
117                 return false;
118         
119         if(key=="pos") 
120         {
121                 int x,y;
122                 if(!strscanf(value,"%d %d",&x, &y))
123                         return false;
124                 window->move(x,y);
125                 return true;
126         }
127         if(key=="size") 
128         {
129                 int x,y;
130                 if(!strscanf(value,"%d %d",&x, &y))
131                         return false;
132                 window->set_default_size(x,y);
133                 return true;
134         }
135         if(key=="x") 
136         {
137                 int x,y; window->get_position(x,y);
138                 x=atoi(value.c_str());
139                 window->move(x,y);
140                 return true;
141         }
142         if(key=="y")
143         {
144                 int x,y; window->get_position(x,y);
145                 y=atoi(value.c_str());
146                 window->move(x,y);
147                 return true;
148         }
149         if(key=="w")
150         {
151                 int x,y; window->get_size(x,y);
152                 x=atoi(value.c_str());
153                 window->set_default_size(x,y);
154                 return true;
155         }
156         if(key=="h")
157         {
158                 int x,y; window->get_size(x,y);
159                 y=atoi(value.c_str());
160                 window->set_default_size(x,y);
161                 return true;
162         }
163         if(key=="visible")
164         {
165                 if(value=="0")
166                         window->hide();
167                 else
168                         window->present();
169                 return true;
170         }
171
172         return synfigapp::Settings::set_value(key,value);
173 }
174
175 synfigapp::Settings::KeyList
176 DialogSettings::get_key_list()const
177 {
178         synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
179         
180         ret.push_back("size");
181         ret.push_back("pos");
182         ret.push_back("visible");
183         
184         return ret;
185 }