Adding upstream version 0.7.2.
[debian/lxpanel.git] / 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,
aaccad27 27 const char *tooltips, const char* icon_name)
514580cf
DB
28{
29 struct statusicon *newicon;
30 newicon = malloc(sizeof(struct statusicon));
31
32 /* main */
33 newicon->main = gtk_event_box_new();
34
6b775dbb 35 gtk_widget_set_has_window(newicon->main, FALSE);
514580cf
DB
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 */
6b775dbb 41
aaccad27
AL
42 /*icon theme*/
43 GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
6b775dbb 44
aaccad27
AL
45 /*if we've got a theme*/
46 if(gtk_icon_theme_has_icon(icon_theme, icon_name)) {
6b775dbb
AG
47 GdkPixbuf* temp_pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, 24, 0, NULL);
48 newicon->icon = gtk_image_new_from_pixbuf(temp_pixbuf);
49 }
50
aaccad27
AL
51 /* oh well...*/
52 else {
6b775dbb
AG
53 newicon->icon = gtk_image_new_from_file(filename);
54 }
514580cf
DB
55 gtk_container_add(GTK_CONTAINER(newicon->main), newicon->icon);
56 gtk_widget_show_all(newicon->main);
57
58 /* tooltip */
6b775dbb 59 gtk_widget_set_tooltip_text(newicon->main, tooltips);
514580cf
DB
60
61 return newicon;
62}
63
64void statusicon_destroy(struct statusicon *icon)
65{
6b775dbb 66 if (icon==NULL)
514580cf
DB
67 return;
68
514580cf
DB
69 gtk_widget_destroy(GTK_WIDGET(icon->icon));
70 gtk_widget_destroy(GTK_WIDGET(icon->main));
71 g_free(icon);
72}
73
74
75void set_statusicon_image_from_file(struct statusicon *widget, const char *filename)
76{
77 gtk_image_set_from_file(GTK_IMAGE(widget->icon), filename);
78}
79
80void set_statusicon_tooltips(struct statusicon *widget, const char *tooltips)
81{
6b775dbb 82 gtk_widget_set_tooltip_text(widget->main, tooltips);
514580cf
DB
83}
84
85void set_statusicon_visible(struct statusicon *widget, gboolean b)
86{
87 if (b)
88 gtk_widget_show(widget->main);
89 else
90 gtk_widget_hide(widget->main);
91}