Adding upstream version 0.5.9.
[debian/lxpanel.git] / src / plugins / netstat / statusicon.c
CommitLineData
514580cf
DB
1/**
2 * Copyright (c) 2008 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 <string.h>
20#include <stdlib.h>
21#include <glib.h>
22#include <glib/gi18n.h>
23#include "netstat.h"
24#include "statusicon.h"
25
26struct statusicon *create_statusicon(GtkWidget *box, const char *filename,
27 const char *tooltips)
28{
29 struct statusicon *newicon;
30 newicon = malloc(sizeof(struct statusicon));
31
32 /* main */
33 newicon->main = gtk_event_box_new();
34
35 GTK_WIDGET_SET_FLAGS(newicon->main, GTK_NO_WINDOW);
36 gtk_widget_add_events(newicon->main, GDK_BUTTON_PRESS_MASK);
37 gtk_widget_set_size_request(newicon->main, 24, 24);
38 gtk_box_pack_start(GTK_BOX(box), newicon->main, TRUE, TRUE, 0);
39
40 /* icon */
41 newicon->icon = gtk_image_new_from_file(filename);
42 gtk_container_add(GTK_CONTAINER(newicon->main), newicon->icon);
43 gtk_widget_show_all(newicon->main);
44
45 /* tooltip */
46 newicon->tooltips = gtk_tooltips_new();
47#if GLIB_CHECK_VERSION( 2, 10, 0 )
48 g_object_ref_sink(newicon->tooltips);
49#else
50 g_object_ref(newicon->tooltips);
51 gtk_object_sink(newicon->tooltips);
52#endif
53 gtk_tooltips_set_tip(newicon->tooltips, newicon->main, tooltips, NULL);
54
55 return newicon;
56}
57
58void statusicon_destroy(struct statusicon *icon)
59{
60 if (icon==NULL)
61 return;
62
63 g_object_unref(icon->tooltips);
64 gtk_widget_destroy(GTK_WIDGET(icon->icon));
65 gtk_widget_destroy(GTK_WIDGET(icon->main));
66 g_free(icon);
67}
68
69
70void set_statusicon_image_from_file(struct statusicon *widget, const char *filename)
71{
72 gtk_image_set_from_file(GTK_IMAGE(widget->icon), filename);
73}
74
75void set_statusicon_tooltips(struct statusicon *widget, const char *tooltips)
76{
77 gtk_tooltips_set_tip(widget->tooltips, widget->main, tooltips, NULL);
78}
79
80void set_statusicon_visible(struct statusicon *widget, gboolean b)
81{
82 if (b)
83 gtk_widget_show(widget->main);
84 else
85 gtk_widget_hide(widget->main);
86}