Adding upstream version 0.8.2.
[debian/lxpanel.git] / plugins / space.c
1 /*
2 * Copyright (C) 2006-2008 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
3 * 2006-2008 Jim Huang <jserv.tw@gmail.com>
4 * 2009 Marty Jack <martyj19@comcast.net>
5 * 2010 Julien Lavergne <julien.lavergne@gmail.com>
6 * 2014 Andriy Grytsenko <andrej@rep.kiev.ua>
7 *
8 * This file is a part of LXPanel project.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program 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
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25 #include <stdlib.h>
26
27 #include <glib/gi18n.h>
28
29 #include "plugin.h"
30
31 /* Private context for space plugin. */
32 typedef struct {
33 LXPanel *panel; /* The panel and settings are required to apply config */
34 config_setting_t *settings;
35 int size; /* Size of spacer */
36 } SpacePlugin;
37
38 static gboolean space_apply_configuration(gpointer user_data);
39
40 /* Plugin constructor. */
41 static GtkWidget *space_constructor(LXPanel *panel, config_setting_t *settings)
42 {
43 /* Allocate plugin context and set into Plugin private data pointer. */
44 SpacePlugin * sp = g_new0(SpacePlugin, 1);
45 GtkWidget * p;
46
47 /* Load parameters from the configuration file. */
48 config_setting_lookup_int(settings, "Size", &sp->size);
49
50 /* Save construction pointers */
51 sp->panel = panel;
52 sp->settings = settings;
53
54 /* Default the size parameter. */
55 if (sp->size == 0)
56 sp->size = 2;
57
58 /* Allocate top level widget and set into Plugin widget pointer. */
59 p = gtk_event_box_new();
60 lxpanel_plugin_set_data(p, sp, g_free);
61 gtk_widget_set_has_window(p,FALSE);
62
63 /* Apply the configuration and show the widget. */
64 space_apply_configuration(p);
65 return p;
66 }
67
68 /* Callback when the configuration dialog has recorded a configuration change. */
69 static gboolean space_apply_configuration(gpointer user_data)
70 {
71 GtkWidget * p = user_data;
72 SpacePlugin * sp = lxpanel_plugin_get_data(p);
73
74 /* Apply settings. */
75 if (panel_get_orientation(sp->panel) == GTK_ORIENTATION_HORIZONTAL)
76 gtk_widget_set_size_request(p, sp->size, 2);
77 else
78 gtk_widget_set_size_request(p, 2, sp->size);
79 /* Save config values */
80 config_group_set_int(sp->settings, "Size", sp->size);
81 return FALSE;
82 }
83
84 /* Callback when the configuration dialog is to be shown. */
85 static GtkWidget *space_configure(LXPanel *panel, GtkWidget *instance)
86 {
87 SpacePlugin * sp = lxpanel_plugin_get_data(instance);
88 GtkWidget * dlg;
89
90 dlg = lxpanel_generic_config_dlg(_("Spacer"), panel,
91 space_apply_configuration, instance,
92 _("Size"), &sp->size, CONF_TYPE_INT, NULL);
93 gtk_widget_set_size_request(dlg, 200, -1); /* Improve geometry */
94 return dlg;
95 }
96
97 /* Plugin descriptor. */
98 LXPanelPluginInit lxpanel_static_plugin_space = {
99 .name = N_("Spacer"),
100 .description = N_("Allocate space"),
101
102 /* Stretch is available but not default for this plugin. */
103 .expand_available = TRUE,
104
105 .new_instance = space_constructor,
106 .config = space_configure,
107 };