4
Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com>
5
This program is free software: you can redistribute it and/or modify it
6
under the terms of the GNU Lesser General Public License version 3, as published
7
by the Free Software Foundation.
9
This program is distributed in the hope that it will be useful, but
10
WITHOUT ANY WARRANTY; without even the implied warranties of
11
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
PURPOSE. See the GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with this program. If not, see <http://www.gnu.org/licenses/>
22
public class PlankPlug : Pantheon.Switchboard.Plug {
26
var plug = new Plank ();
33
public class Settings {
34
public int iconsize { get; set; default = 48; }
35
public int hidemode { get; set; default = 1; }
36
public int monitor { get; set; default = 0; }
45
public class Plank : VBox {
46
string plank_config_file;
48
GLib.KeyFile plank_settings;
49
Settings settings = new Settings ();
50
string key_group = "PlankDockPreferences";
52
ComboBoxText hidemode;
58
config_dir = Environment.get_user_config_dir ();
59
plank_config_file = config_dir + "/plank/dock1/settings";
63
var label = new Label ("<b>Icon size: </b>");
64
label.use_markup = true;
65
pix_label = new Label ("px");
67
iconsize = new HScale.with_range (24.0, 128.0, 1.0);
68
iconsize.set_draw_value (false);
69
iconsize.set_value (settings.iconsize);
70
iconsize.value_changed.connect (apply);
71
var hbox = new HBox (false, 4);
72
hbox.pack_start (label, false, false, 25);
73
hbox.pack_end (pix_label, false, false, 25);
74
pack_start (hbox, false, false, 10);
75
hbox = new HBox (false, 4);
76
hbox.pack_start (iconsize, true, true, 45);
77
pack_start (hbox, false, true, 0);
79
label = new Label ("<b>Hide mode: </b>");
80
label.use_markup = true;
81
hidemode = new ComboBoxText ();
82
hidemode.append_text ("Never");
83
hidemode.append_text ("Intelligent");
84
hidemode.append_text ("Always");
85
hidemode.set_active (settings.hidemode);
86
hidemode.changed.connect (apply);
87
hbox = new HBox (false, 4);
88
hbox.pack_start (label, false, false, 25);
89
pack_start (hbox, false, false, 10);
90
hbox = new HBox (false, 4);
91
hbox.pack_start (hidemode, false, false, 45);
92
pack_start (hbox, false, true, 0);
94
label = new Label ("<b>Monitor: </b>");
95
label.use_markup = true;
96
monitor = new ComboBoxText ();
97
monitor.append_text ("0");
98
monitor.append_text ("1");
99
monitor.append_text ("2");
100
monitor.set_active (settings.monitor);
101
monitor.changed.connect (apply);
102
hbox = new HBox (false, 4);
103
hbox.pack_start (label, false, false, 25);
104
pack_start (hbox, false, false, 10);
105
hbox = new HBox (false, 4);
106
hbox.pack_start (monitor, false, false, 45);
107
pack_start (hbox, false, true, 0);
109
stdout.printf ("\n\n\n\n");
114
settings.iconsize = (int) iconsize.get_value ();
115
settings.hidemode = hidemode.get_active ();
116
settings.monitor = monitor.get_active ();
118
plank_settings.set_integer (key_group, "IconSize", settings.iconsize);
119
plank_settings.set_integer (key_group, "HideMode", settings.hidemode);
120
plank_settings.set_integer (key_group, "Monitor", settings.monitor);
125
write_plank_settings ();
126
} catch (GLib.Error error) {
127
GLib.critical ("Failed to save \"%s\": %s", plank_config_file, error.message);
132
void write_plank_settings () throws Error {
133
string config_path = Environment.get_user_config_dir () + "/plank/dock1";
134
if (DirUtils.create_with_parents (config_path, 0700) != 0)
135
throw new GLib.FileError.FAILED ("Config folder couldn't be created.");
136
File f = File.new_for_path(plank_config_file);
137
if (f.query_exists(null)) {
140
var f_stream = f.create(FileCreateFlags.REPLACE_DESTINATION, null);
141
var d_stream = new DataOutputStream(f_stream);
142
d_stream.put_string(plank_settings.to_data());
148
/* Load plank settings */
149
plank_settings = new GLib.KeyFile ();
151
plank_settings.load_from_file (plank_config_file, 0);
152
} catch (GLib.Error error) {
153
GLib.debug ("Failed to load \"%s\": %s", plank_config_file, error.message);
157
if (plank_settings.has_key (key_group, "IconSize"))
158
settings.iconsize = plank_settings.get_integer (key_group, "IconSize");
159
if (plank_settings.has_key (key_group, "HideMode"))
160
settings.hidemode = plank_settings.get_integer (key_group, "HideMode");
161
if (plank_settings.has_key (key_group, "Monitor"))
162
settings.monitor = plank_settings.get_integer (key_group, "Monitor");
163
} catch (GLib.KeyFileError error) {
164
GLib.debug ("Failed to load some preferences from \"%s\": %s", plank_config_file, error.message);
170
void set_pixel_label () {
171
pix_label.set_text (settings.iconsize.to_string () + " px");
176
public static int main (string[] args) {
179
var plug = new PlankPlug ();
180
plug.register ("Plank");