Merging upstream version 0.8.0 (Closes: #639729, #761971).
[debian/lxpanel.git] / plugins / netstat / statusicon.c
CommitLineData
f8c25730
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"
89173f95 25#include "misc.h"
f8c25730 26
89173f95
AG
27struct statusicon *create_statusicon(LXPanel *panel, GtkWidget *box,
28 const char *filename, const char *tooltips, const char* icon_name)
f8c25730
DB
29{
30 struct statusicon *newicon;
31 newicon = malloc(sizeof(struct statusicon));
32
33 /* main */
34 newicon->main = gtk_event_box_new();
35
00916e98 36 gtk_widget_set_has_window(newicon->main, FALSE);
89173f95 37 //gtk_widget_set_size_request(newicon->main, 24, 24);
f8c25730
DB
38 gtk_box_pack_start(GTK_BOX(box), newicon->main, TRUE, TRUE, 0);
39
40 /* icon */
89173f95 41 newicon->icon = lxpanel_image_new_for_icon(panel, icon_name, -1, filename);
00916e98 42
f8c25730
DB
43 gtk_container_add(GTK_CONTAINER(newicon->main), newicon->icon);
44 gtk_widget_show_all(newicon->main);
45
46 /* tooltip */
00916e98 47 gtk_widget_set_tooltip_text(newicon->main, tooltips);
f8c25730
DB
48
49 return newicon;
50}
51
52void statusicon_destroy(struct statusicon *icon)
53{
00916e98 54 if (icon==NULL)
f8c25730
DB
55 return;
56
f8c25730
DB
57 gtk_widget_destroy(GTK_WIDGET(icon->icon));
58 gtk_widget_destroy(GTK_WIDGET(icon->main));
59 g_free(icon);
60}
61
62
89173f95
AG
63//void set_statusicon_image_from_file(struct statusicon *widget, const char *filename)
64void update_statusicon(struct statusicon *widget, const char *filename, const char *icon_name)
f8c25730 65{
89173f95 66 lxpanel_image_change_icon(widget->icon, icon_name, filename);
f8c25730
DB
67}
68
69void set_statusicon_tooltips(struct statusicon *widget, const char *tooltips)
70{
00916e98 71 gtk_widget_set_tooltip_text(widget->main, tooltips);
f8c25730
DB
72}
73
74void set_statusicon_visible(struct statusicon *widget, gboolean b)
75{
76 if (b)
77 gtk_widget_show(widget->main);
78 else
79 gtk_widget_hide(widget->main);
80}