2
* Copyright (c) 2006 LxDE Developers, see the file AUTHORS for details.
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.
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.
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.
21
#include <gdk-pixbuf/gdk-pixbuf.h>
22
#include <glib/gi18n.h>
37
image_destructor(Plugin *p)
39
image *img = (image *)p->priv;
42
gtk_widget_destroy(img->mainw);
43
g_free( img->config_data );
49
image_constructor(Plugin *p, char **fp)
51
gchar *tooltip, *fname;
56
char *config_start, *config_end;
62
img = g_new0(image, 1);
63
g_return_val_if_fail(img != NULL, 0);
68
while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END) {
69
if (s.type == LINE_NONE) {
70
ERR( "image: illegal token %s\n", s.str);
73
if (s.type == LINE_VAR) {
74
if (!g_ascii_strcasecmp(s.t[0], "image"))
75
fname = expand_tilda(s.t[1]);
76
else if (!g_ascii_strcasecmp(s.t[0], "tooltip"))
77
tooltip = g_strdup(s.t[1]);
79
ERR( "image: unknown var %s\n", s.t[0]);
83
ERR( "image: illegal in this context %s\n", s.str);
88
while( *config_end != '}' && config_end > config_start ) {
91
if( *config_end == '}' )
93
img->config_data = g_strndup( config_start,
94
(config_end-config_start) );
97
config_start = config_end = NULL;
99
img->mainw = gtk_event_box_new();
100
gtk_widget_show(img->mainw);
101
//g_signal_connect(G_OBJECT(img->mainw), "expose_event",
102
// G_CALLBACK(gtk_widget_queue_draw), NULL);
103
gp = gdk_pixbuf_new_from_file(fname, &err);
105
g_warning("image: can't read image %s\n", fname);
106
wid = gtk_label_new("?");
109
ratio = (p->panel->orientation == ORIENT_HORIZ) ?
110
(float) (p->panel->ah - 2) / (float) gdk_pixbuf_get_height(gp)
111
: (float) (p->panel->aw - 2) / (float) gdk_pixbuf_get_width(gp);
112
gps = gdk_pixbuf_scale_simple (gp,
113
ratio * ((float) gdk_pixbuf_get_width(gp)),
114
ratio * ((float) gdk_pixbuf_get_height(gp)),
116
wid = gtk_image_new_from_pixbuf(gps);
121
gtk_widget_show(wid);
122
gtk_container_add(GTK_CONTAINER(img->mainw), wid);
123
gtk_container_set_border_width(GTK_CONTAINER(img->mainw), 0);
127
gtk_widget_set_tooltip_text(img->mainw, tooltip);
139
static void save_config( Plugin* p, FILE* fp )
141
image *img = (image *)p->priv;
142
if( img->config_data ) {
143
char** lines = g_strsplit( img->config_data, "\n", 0 );
145
for( line = lines; *line; ++line ) {
148
lxpanel_put_line( fp, *line );
154
PluginClass image_plugin_class = {
161
description : N_("Display Image and Tooltip"),
163
constructor : image_constructor,
164
destructor : image_destructor,