Rename panel, plugin, and plugin_class to Panel, Plugin, and
[lxde/lxpanel.git] / src / plugins / space.c
1 /**
2 * Copyright (c) 2006 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdlib.h>
20
21 #include <gdk-pixbuf/gdk-pixbuf.h>
22 #include <glib/gi18n.h>
23
24 #include "panel.h"
25 #include "misc.h"
26 #include "plugin.h"
27
28 //#define DEBUG
29 #include "dbg.h"
30
31
32 typedef struct {
33 int size;
34 GtkWidget *mainw;
35
36 } space;
37
38
39
40 static void
41 space_destructor(Plugin *p)
42 {
43 space *sp = (space *)p->priv;
44
45 ENTER;
46 /* The widget is destroyed in plugin_stop().
47 gtk_widget_destroy(sp->mainw);
48 */
49 g_free(sp);
50 RET();
51 }
52
53
54
55
56 static int
57 space_constructor(Plugin *p, char** fp)
58 {
59 space *sp;
60 line s;
61 int w, h;
62
63 ENTER;
64 s.len = 256;
65 sp = g_new0(space, 1);
66 g_return_val_if_fail(sp != NULL, 0);
67 p->priv = sp;
68 if( fp )
69 {
70 while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) {
71 if (s.type == LINE_NONE) {
72 ERR( "space: illegal token %s\n", s.str);
73 goto error;
74 }
75 if (s.type == LINE_VAR) {
76 if (!g_ascii_strcasecmp(s.t[0], "size"))
77 sp->size = atoi(s.t[1]);
78 else {
79 ERR( "space: unknown var %s\n", s.t[0]);
80 goto error;
81 }
82 } else {
83 ERR( "space: illegal in this context %s\n", s.str);
84 goto error;
85 }
86 }
87 }
88 if (!sp->size)
89 sp->size = 2;
90 sp->mainw = gtk_vbox_new(TRUE, 0);
91 gtk_widget_show(sp->mainw);
92 if (p->panel->orientation == ORIENT_HORIZ) {
93 h = 2;
94 w = sp->size;
95 } else {
96 w = 2;
97 h = sp->size;
98 }
99 gtk_widget_set_size_request(sp->mainw, w, h);
100 gtk_container_set_border_width(GTK_CONTAINER(sp->mainw), 0);
101
102 p->pwid = sp->mainw;
103
104 RET(1);
105
106 error:
107 space_destructor(p);
108 RET(0);
109 }
110
111 static void apply_config( Plugin* p )
112 {
113 int w, h;
114 space *sp = (space *)p->priv;
115 /* Apply settings */
116 if (p->panel->orientation == ORIENT_HORIZ) {
117 h = 2;
118 w = sp->size;
119 } else {
120 w = 2;
121 h = sp->size;
122 }
123 gtk_widget_set_size_request(p->pwid, w, h);
124 }
125
126 static void space_config(Plugin* p, GtkWindow* parent )
127 {
128 GtkWidget* dlg;
129 space *sp = (space *)p->priv;
130 dlg = create_generic_config_dlg( _(p->class->name),
131 GTK_WIDGET(parent),
132 (GSourceFunc) apply_config, (gpointer) p,
133 _("Size"), &sp->size, G_TYPE_INT, NULL );
134 gtk_window_present( GTK_WINDOW(dlg) );
135 }
136
137 static void save_config( Plugin* p, FILE* fp )
138 {
139 space *sp = (space *)p->priv;
140 lxpanel_put_int( fp, "Size", sp->size );
141 }
142
143 PluginClass space_plugin_class = {
144 fname: NULL,
145 count: 0,
146
147 type : "space",
148 name : N_("<Space>"),
149 version: "1.0",
150 description : N_("Allocate space"),
151
152 constructor : space_constructor,
153 destructor : space_destructor,
154 config : space_config,
155 save : save_config
156 };