2005-02-05 02:12:01 +08:00
|
|
|
/*
|
2010-12-07 23:46:31 +08:00
|
|
|
* Copyright 2003-2007 Bernhard Walle <bernhard@bwalle.de>
|
|
|
|
* Copyright 2010 Florian Rivoal <frivoal@gmail.com>
|
2005-02-05 02:12:01 +08:00
|
|
|
* -------------------------------------------------------------------------------------------------
|
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
2003-08-14 02:14:27 +08:00
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2003-08-14 02:14:27 +08:00
|
|
|
*
|
2010-12-08 10:00:54 +08:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 675 Mass
|
|
|
|
* Ave, Cambridge, MA 02139, USA.
|
2005-02-05 02:12:01 +08:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------------------------------
|
2003-08-14 02:14:27 +08:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
#include "net.h"
|
|
|
|
#include "utils.h"
|
2005-08-01 06:54:22 +08:00
|
|
|
#include "global.h"
|
2003-08-26 05:08:58 +08:00
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
#include <libxfce4util/libxfce4util.h>
|
|
|
|
#include <libxfcegui4/libxfcegui4.h>
|
|
|
|
#include <libxfce4panel/xfce-panel-plugin.h>
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
#define BORDER 8
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
/* Defaults */
|
|
|
|
#define DEFAULT_TEXT "Net"
|
2003-08-27 04:34:46 +08:00
|
|
|
|
|
|
|
#define INIT_MAX 4096
|
|
|
|
#define MINIMAL_MAX 1024
|
|
|
|
#define SHRINK_MAX 0.75
|
|
|
|
|
|
|
|
#define HISTSIZE_CALCULATE 4
|
|
|
|
#define HISTSIZE_STORE 20
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
static gchar* DEFAULT_COLOR[] = { "#FF4F00", "#FFE500" };
|
|
|
|
|
|
|
|
#define UPDATE_TIMEOUT 250
|
|
|
|
#define MAX_LENGTH 10
|
|
|
|
|
|
|
|
#define IN 0
|
|
|
|
#define OUT 1
|
|
|
|
#define TOT 2
|
2003-08-25 04:05:10 +08:00
|
|
|
#define SUM 2
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-09-06 20:37:20 +08:00
|
|
|
#define APP_NAME N_("Xfce4-Netload-Plugin")
|
|
|
|
|
|
|
|
static char *errormessages[] = {
|
|
|
|
N_("Unknown error."),
|
|
|
|
N_("Linux proc device '/proc/net/dev' not found."),
|
|
|
|
N_("Interface was not found.")
|
|
|
|
};
|
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean use_label;
|
2012-01-07 21:05:32 +08:00
|
|
|
gboolean show_bars;
|
|
|
|
gboolean show_values;
|
2003-08-25 04:05:10 +08:00
|
|
|
gboolean auto_max;
|
|
|
|
gulong max[SUM];
|
2003-08-27 04:34:46 +08:00
|
|
|
gint update_interval;
|
2003-08-14 02:14:27 +08:00
|
|
|
GdkColor color[SUM];
|
|
|
|
gchar *label_text;
|
|
|
|
gchar *network_device;
|
2003-08-31 20:54:36 +08:00
|
|
|
gchar *old_network_device;
|
2003-08-14 02:14:27 +08:00
|
|
|
} t_monitor_options;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *label;
|
2012-01-07 21:05:32 +08:00
|
|
|
GtkWidget *rcv_label;
|
|
|
|
GtkWidget *sent_label;
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkWidget *status[SUM];
|
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
gulong history[SUM][HISTSIZE_STORE];
|
2003-08-25 04:05:10 +08:00
|
|
|
gulong net_max[SUM];
|
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
t_monitor_options options;
|
2003-08-26 05:08:58 +08:00
|
|
|
|
|
|
|
/* for the network part */
|
|
|
|
netdata data;
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Displayed text */
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkBox *opt_vbox;
|
|
|
|
GtkWidget *opt_entry;
|
|
|
|
GtkBox *opt_hbox;
|
|
|
|
GtkWidget *opt_use_label;
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
/* Update interval */
|
|
|
|
GtkWidget *update_spinner;
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Network device */
|
|
|
|
GtkWidget *net_entry;
|
|
|
|
|
|
|
|
/* Maximum */
|
|
|
|
GtkWidget *max_use_label;
|
|
|
|
GtkWidget *max_entry[SUM];
|
|
|
|
GtkBox *max_hbox[SUM];
|
|
|
|
|
2012-01-07 21:14:41 +08:00
|
|
|
/* Bars and values */
|
|
|
|
GtkWidget *opt_present_data_hbox;
|
|
|
|
GtkWidget *opt_present_data_label;
|
|
|
|
GtkWidget *opt_present_data_combobox;
|
|
|
|
GtkWidget *opt_color_hbox[SUM];
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Color */
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkWidget *opt_button[SUM];
|
|
|
|
GtkWidget *opt_da[SUM];
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
} t_monitor;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
XfcePanelPlugin *plugin;
|
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkWidget *ebox;
|
|
|
|
GtkWidget *box;
|
2010-11-12 09:32:47 +08:00
|
|
|
GtkWidget *tooltip_text;
|
2003-08-14 02:14:27 +08:00
|
|
|
guint timeout_id;
|
|
|
|
t_monitor *monitor;
|
|
|
|
|
|
|
|
/* options dialog */
|
|
|
|
GtkWidget *opt_dialog;
|
|
|
|
} t_global_monitor;
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-27 04:34:46 +08:00
|
|
|
static gboolean update_monitors(t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2003-08-25 04:05:10 +08:00
|
|
|
char buffer[SUM+1][BUFSIZ];
|
2003-08-14 02:14:27 +08:00
|
|
|
gchar caption[BUFSIZ];
|
2012-01-07 21:05:32 +08:00
|
|
|
gchar received[BUFSIZ];
|
|
|
|
gchar sent[BUFSIZ];
|
2003-08-25 04:05:10 +08:00
|
|
|
gulong net[SUM+1];
|
2003-08-27 04:34:46 +08:00
|
|
|
gulong display[SUM+1], max;
|
|
|
|
guint64 histcalculate;
|
2003-08-25 04:05:10 +08:00
|
|
|
double temp;
|
2003-08-27 04:34:46 +08:00
|
|
|
gint i, j;
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-12-18 05:11:54 +08:00
|
|
|
if (!get_interface_up(&(global->monitor->data)))
|
|
|
|
{
|
|
|
|
g_snprintf(caption, sizeof(caption),
|
|
|
|
_("<< %s >> (Interface down)"),
|
|
|
|
get_name(&(global->monitor->data)));
|
2010-11-12 09:32:47 +08:00
|
|
|
gtk_label_set_text(GTK_LABEL(global->tooltip_text), caption);
|
2006-12-18 05:11:54 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-08-26 05:08:58 +08:00
|
|
|
get_current_netload( &(global->monitor->data), &(net[IN]), &(net[OUT]), &(net[TOT]) );
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
/* correct value to be from 1 ... 100 */
|
2003-08-25 04:05:10 +08:00
|
|
|
global->monitor->history[i][0] = net[i];
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
if (global->monitor->history[i][0] < 0)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
global->monitor->history[i][0] = 0;
|
|
|
|
}
|
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
histcalculate = 0;
|
|
|
|
for( j = 0; j < HISTSIZE_CALCULATE; j++ )
|
|
|
|
{
|
|
|
|
histcalculate += global->monitor->history[i][j];
|
|
|
|
}
|
|
|
|
display[i] = histcalculate / HISTSIZE_CALCULATE;
|
|
|
|
|
|
|
|
/* shift for next run */
|
|
|
|
for( j = HISTSIZE_STORE - 1; j > 0; j-- )
|
|
|
|
{
|
|
|
|
global->monitor->history[i][j] = global->monitor->history[i][j-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update maximum */
|
|
|
|
if( global->monitor->options.auto_max )
|
|
|
|
{
|
|
|
|
max = max_array( global->monitor->history[i], HISTSIZE_STORE );
|
|
|
|
if( display[i] > global->monitor->net_max[i] )
|
|
|
|
{
|
|
|
|
global->monitor->net_max[i] = display[i];
|
|
|
|
}
|
|
|
|
else if( max < global->monitor->net_max[i] * SHRINK_MAX
|
|
|
|
&& global->monitor->net_max[i] * SHRINK_MAX >= MINIMAL_MAX )
|
|
|
|
{
|
|
|
|
global->monitor->net_max[i] *= SHRINK_MAX;
|
|
|
|
}
|
|
|
|
}
|
2003-08-29 03:38:38 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-02-05 02:12:01 +08:00
|
|
|
switch (i)
|
2003-08-27 04:34:46 +08:00
|
|
|
{
|
2003-08-29 03:38:38 +08:00
|
|
|
case IN:
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("input: Max = %lu", global->monitor->net_max[i]);
|
2003-08-29 03:38:38 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OUT:
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("output: Max = %lu", global->monitor->net_max[i]);
|
2003-08-29 03:38:38 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOT:
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("total: Max = %lu", global->monitor->net_max[i]);
|
2003-08-29 03:38:38 +08:00
|
|
|
break;
|
2003-08-27 04:34:46 +08:00
|
|
|
}
|
2003-08-29 03:38:38 +08:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
temp = (double)display[i] / global->monitor->net_max[i];
|
2005-02-05 02:12:01 +08:00
|
|
|
if (temp > 1)
|
2003-08-25 04:05:10 +08:00
|
|
|
{
|
|
|
|
temp = 1.0;
|
|
|
|
}
|
2005-02-05 02:12:01 +08:00
|
|
|
else if (temp < 0)
|
2003-08-25 04:05:10 +08:00
|
|
|
{
|
|
|
|
temp = 0.0;
|
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
|
|
|
|
if (global->monitor->options.show_bars)
|
|
|
|
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(global->monitor->status[i]), temp);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
format_with_thousandssep( buffer[i], BUFSIZ, display[i] / 1024.0, 2 );
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2012-01-07 21:05:32 +08:00
|
|
|
format_with_thousandssep( buffer[TOT], BUFSIZ, (display[IN]+display[OUT]) / 1024.0, 2 );
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
{
|
|
|
|
char* ip = get_ip_address(&(global->monitor->data));
|
|
|
|
g_snprintf(caption, sizeof(caption),
|
|
|
|
_("<< %s >> (%s)\nAverage of last %d measures:\n"
|
|
|
|
"Incoming: %s kByte/s\nOutgoing: %s kByte/s\nTotal: %s kByte/s"),
|
|
|
|
get_name(&(global->monitor->data)), ip ? ip : _("no IP address"),
|
|
|
|
HISTSIZE_CALCULATE, buffer[IN], buffer[OUT], buffer[TOT]);
|
2010-11-12 09:32:47 +08:00
|
|
|
gtk_label_set_text(GTK_LABEL(global->tooltip_text), caption);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
|
|
|
if (global->monitor->options.show_values)
|
|
|
|
{
|
|
|
|
g_snprintf(received, sizeof(received), "%s kByte/s", buffer[IN]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(global->monitor->rcv_label), received);
|
|
|
|
|
|
|
|
g_snprintf(sent, sizeof(sent), _("%s kByte/s"), buffer[OUT]);
|
|
|
|
gtk_label_set_text(GTK_LABEL(global->monitor->sent_label), sent);
|
|
|
|
}
|
2005-02-05 02:12:01 +08:00
|
|
|
}
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-27 04:34:46 +08:00
|
|
|
static void run_update (t_global_monitor *global)
|
|
|
|
{
|
2005-02-05 02:12:01 +08:00
|
|
|
if (global->timeout_id > 0)
|
2003-08-27 04:34:46 +08:00
|
|
|
{
|
2005-02-05 02:12:01 +08:00
|
|
|
g_source_remove(global->timeout_id);
|
2003-08-27 04:34:46 +08:00
|
|
|
global->timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global->monitor->options.update_interval > 0)
|
|
|
|
{
|
|
|
|
global->timeout_id = g_timeout_add( global->monitor->options.update_interval,
|
|
|
|
(GtkFunction)update_monitors, global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void monitor_set_orientation (XfcePanelPlugin *plugin, GtkOrientation orientation,
|
|
|
|
t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (global->timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove(global->timeout_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_hide(GTK_WIDGET(global->ebox));
|
2006-04-26 04:26:28 +08:00
|
|
|
if (global->box)
|
|
|
|
{
|
|
|
|
gtk_container_remove(GTK_CONTAINER(global->ebox), GTK_WIDGET(global->box));
|
|
|
|
}
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
global->box = gtk_hbox_new(FALSE, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global->box = gtk_vbox_new(FALSE, 0);
|
|
|
|
}
|
|
|
|
gtk_widget_show(global->box);
|
|
|
|
|
|
|
|
global->monitor->label = gtk_label_new(global->monitor->options.label_text);
|
|
|
|
gtk_widget_show(global->monitor->label);
|
|
|
|
|
2012-01-07 21:05:32 +08:00
|
|
|
global->monitor->rcv_label = gtk_label_new("");
|
|
|
|
gtk_label_set_width_chars(GTK_LABEL(global->monitor->rcv_label), 13);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(global->monitor->rcv_label), 1.0f, 0.5f);
|
|
|
|
gtk_widget_show(global->monitor->rcv_label);
|
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
global->monitor->status[i] = GTK_WIDGET(gtk_progress_bar_new());
|
|
|
|
}
|
|
|
|
|
2012-01-07 21:05:32 +08:00
|
|
|
global->monitor->sent_label = gtk_label_new("");
|
|
|
|
gtk_label_set_width_chars(GTK_LABEL(global->monitor->sent_label), 13);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(global->monitor->sent_label), 0.0f, 0.5f);
|
|
|
|
gtk_widget_show(global->monitor->sent_label);
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
global->monitor->box = GTK_WIDGET(gtk_hbox_new(FALSE, 0));
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(global->monitor->status[i]),
|
|
|
|
GTK_PROGRESS_BOTTOM_TO_TOP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global->monitor->box = GTK_WIDGET(gtk_vbox_new(FALSE, 0));
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(global->monitor->status[i]),
|
|
|
|
GTK_PROGRESS_LEFT_TO_RIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->box),
|
|
|
|
GTK_WIDGET(global->monitor->label),
|
2012-01-07 21:05:32 +08:00
|
|
|
TRUE, FALSE, BORDER / 2);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->box),
|
|
|
|
GTK_WIDGET(global->monitor->rcv_label),
|
|
|
|
TRUE, FALSE, BORDER / 2);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2011-02-26 18:53:40 +08:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(global->monitor->box), BORDER / 2);
|
2003-08-14 02:14:27 +08:00
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->box));
|
|
|
|
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
2010-10-15 19:27:09 +08:00
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_PRELIGHT,
|
|
|
|
&global->monitor->options.color[i]);
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_SELECTED,
|
|
|
|
&global->monitor->options.color[i]);
|
|
|
|
gtk_widget_modify_base(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_SELECTED,
|
|
|
|
&global->monitor->options.color[i]);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->status[i]));
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->box),
|
|
|
|
GTK_WIDGET(global->monitor->status[i]), FALSE, FALSE, 0);
|
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->box),
|
|
|
|
GTK_WIDGET(global->monitor->sent_label),
|
|
|
|
TRUE, FALSE, BORDER / 2);
|
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(global->box),
|
2006-04-26 04:26:28 +08:00
|
|
|
GTK_WIDGET(global->monitor->box), FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(global->ebox), GTK_WIDGET(global->box));
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->ebox));
|
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
run_update( global );
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:32:47 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
|
|
|
static gboolean tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard, GtkTooltip *tooltip, t_global_monitor *global)
|
|
|
|
{
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_tooltip_set_custom(tooltip, global->tooltip_text);
|
|
|
|
return TRUE;
|
2010-11-12 09:32:47 +08:00
|
|
|
}
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void monitor_free(XfcePanelPlugin *plugin, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
if (global->timeout_id)
|
|
|
|
{
|
|
|
|
g_source_remove(global->timeout_id);
|
|
|
|
}
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if (global->monitor->options.label_text)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.label_text);
|
|
|
|
}
|
2010-11-12 09:32:47 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy(global->tooltip_text);
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
g_free(global);
|
|
|
|
|
|
|
|
close_netload( &(global->monitor->data) );
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static t_global_monitor * monitor_new(XfcePanelPlugin *plugin)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
t_global_monitor *global;
|
2006-04-26 04:26:28 +08:00
|
|
|
gint i;
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global = g_new(t_global_monitor, 1);
|
|
|
|
global->timeout_id = 0;
|
|
|
|
global->ebox = gtk_event_box_new();
|
2010-11-12 09:32:47 +08:00
|
|
|
gtk_widget_set_has_tooltip(global->ebox, TRUE);
|
|
|
|
g_signal_connect(global->ebox, "query-tooltip", G_CALLBACK(tooltip_cb), global);
|
2006-04-26 04:26:28 +08:00
|
|
|
gtk_widget_show(global->ebox);
|
|
|
|
global->box = NULL;
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2010-11-12 09:32:47 +08:00
|
|
|
global->tooltip_text = gtk_label_new(NULL);
|
|
|
|
g_object_ref(global->tooltip_text);
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global->plugin = plugin;
|
|
|
|
xfce_panel_plugin_add_action_widget (plugin, global->ebox);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor = g_new(t_monitor, 1);
|
|
|
|
global->monitor->options.label_text = g_strdup(DEFAULT_TEXT);
|
|
|
|
global->monitor->options.network_device = g_strdup("");
|
|
|
|
global->monitor->options.old_network_device = g_strdup("");
|
|
|
|
global->monitor->options.use_label = TRUE;
|
2012-01-07 21:05:32 +08:00
|
|
|
global->monitor->options.show_values = FALSE;
|
|
|
|
global->monitor->options.show_bars = TRUE;
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor->options.auto_max = TRUE;
|
|
|
|
global->monitor->options.update_interval = UPDATE_TIMEOUT;
|
|
|
|
|
|
|
|
for (i = 0; i < SUM; i++)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
gdk_color_parse(DEFAULT_COLOR[i], &global->monitor->options.color[i]);
|
|
|
|
|
|
|
|
global->monitor->history[i][0] = 0;
|
|
|
|
global->monitor->history[i][1] = 0;
|
|
|
|
global->monitor->history[i][2] = 0;
|
|
|
|
global->monitor->history[i][3] = 0;
|
|
|
|
global->monitor->net_max[i] = INIT_MAX;
|
|
|
|
|
|
|
|
global->monitor->options.max[i] = INIT_MAX;
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
monitor_set_orientation (plugin, xfce_panel_plugin_get_orientation (plugin), global);
|
2003-08-18 02:55:46 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
return global;
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-10-02 03:16:03 +08:00
|
|
|
static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
gtk_widget_hide(GTK_WIDGET(global->monitor->box));
|
2003-08-14 02:14:27 +08:00
|
|
|
gtk_widget_hide(global->monitor->label);
|
|
|
|
gtk_label_set_text(GTK_LABEL(global->monitor->label),
|
|
|
|
global->monitor->options.label_text);
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_widget_hide(global->monitor->rcv_label);
|
2003-08-14 02:14:27 +08:00
|
|
|
for (i = 0; i < SUM; i++)
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_widget_hide(global->monitor->status[i]);
|
|
|
|
gtk_widget_hide(global->monitor->sent_label);
|
|
|
|
|
|
|
|
if (global->monitor->options.show_bars)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2012-01-07 21:05:32 +08:00
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
gtk_widget_show(global->monitor->status[i]);
|
|
|
|
|
2010-10-15 19:27:09 +08:00
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_PRELIGHT,
|
|
|
|
&global->monitor->options.color[i]);
|
|
|
|
gtk_widget_modify_bg(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_SELECTED,
|
|
|
|
&global->monitor->options.color[i]);
|
|
|
|
gtk_widget_modify_base(GTK_WIDGET(global->monitor->status[i]),
|
|
|
|
GTK_STATE_SELECTED,
|
|
|
|
&global->monitor->options.color[i]);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
|
|
|
/* Maximum */
|
|
|
|
if( global->monitor->options.auto_max )
|
|
|
|
{
|
2003-08-27 04:34:46 +08:00
|
|
|
global->monitor->net_max[i] = INIT_MAX;
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global->monitor->net_max[i] = global->monitor->options.max[i];
|
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
}
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->box));
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
if (global->monitor->options.use_label)
|
|
|
|
{
|
|
|
|
gtk_widget_show(global->monitor->label);
|
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
|
|
|
|
if (global->monitor->options.show_values)
|
|
|
|
{
|
|
|
|
gtk_widget_show(global->monitor->rcv_label);
|
|
|
|
gtk_widget_show(global->monitor->sent_label);
|
|
|
|
}
|
|
|
|
|
2005-08-21 18:11:03 +08:00
|
|
|
if (!init_netload( &(global->monitor->data), global->monitor->options.network_device)
|
|
|
|
&& !supress_warnings)
|
2003-08-31 20:54:36 +08:00
|
|
|
{
|
2005-08-21 18:11:03 +08:00
|
|
|
xfce_err (_("%s: Error in initalizing:\n%s"),
|
|
|
|
_(APP_NAME),
|
|
|
|
_(errormessages[
|
|
|
|
global->monitor->data.errorcode == 0
|
|
|
|
? INTERFACE_NOT_FOUND
|
|
|
|
: global->monitor->data.errorcode ]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (global->monitor->options.old_network_device)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.old_network_device);
|
2003-08-31 20:54:36 +08:00
|
|
|
}
|
2005-08-21 18:11:03 +08:00
|
|
|
global->monitor->options.old_network_device = g_strdup(global->monitor->options.network_device);
|
2003-08-27 04:34:46 +08:00
|
|
|
|
|
|
|
run_update( global );
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void monitor_read_config(XfcePanelPlugin *plugin, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
const char *value;
|
|
|
|
char *file;
|
|
|
|
XfceRc *rc;
|
|
|
|
|
|
|
|
if (!(file = xfce_panel_plugin_lookup_rc_file (plugin)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rc = xfce_rc_simple_open (file, TRUE);
|
|
|
|
g_free (file);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if (!rc)
|
|
|
|
return;
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor->options.use_label = xfce_rc_read_bool_entry (rc, "Use_Label", TRUE);
|
2012-01-07 21:05:32 +08:00
|
|
|
global->monitor->options.show_values = xfce_rc_read_bool_entry (rc, "Show_Values", FALSE);
|
|
|
|
global->monitor->options.show_bars = xfce_rc_read_bool_entry (rc, "Show_Bars", TRUE);
|
2012-01-07 21:14:41 +08:00
|
|
|
if (!global->monitor->options.show_bars && !global->monitor->options.show_values)
|
|
|
|
global->monitor->options.show_bars = TRUE;
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
if ((value = xfce_rc_read_entry (rc, "Color_In", NULL)) != NULL)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
gdk_color_parse(value,
|
|
|
|
&global->monitor->options.color[IN]);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
2006-04-26 04:26:28 +08:00
|
|
|
if ((value = xfce_rc_read_entry (rc, "Color_Out", NULL)) != NULL)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
gdk_color_parse(value,
|
|
|
|
&global->monitor->options.color[OUT]);
|
|
|
|
}
|
|
|
|
if ((value = xfce_rc_read_entry (rc, "Text", NULL)) && *value)
|
|
|
|
{
|
|
|
|
if (global->monitor->options.label_text)
|
|
|
|
g_free(global->monitor->options.label_text);
|
|
|
|
global->monitor->options.label_text = g_strdup(value);
|
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if ((value = xfce_rc_read_entry (rc, "Network_Device", NULL)) && *value)
|
|
|
|
{
|
|
|
|
if (global->monitor->options.network_device)
|
|
|
|
g_free(global->monitor->options.network_device);
|
|
|
|
global->monitor->options.network_device = g_strdup(value);
|
|
|
|
}
|
|
|
|
if ((value = xfce_rc_read_entry (rc, "Max_In", NULL)) != NULL)
|
|
|
|
{
|
|
|
|
global->monitor->options.max[IN] = strtol (value, NULL, 0);
|
|
|
|
}
|
|
|
|
if ((value = xfce_rc_read_entry (rc, "Max_Out", NULL)) != NULL)
|
|
|
|
{
|
|
|
|
global->monitor->options.max[OUT] = strtol (value, NULL, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
global->monitor->options.auto_max = xfce_rc_read_bool_entry (rc, "Auto_Max", TRUE);
|
|
|
|
|
|
|
|
global->monitor->options.update_interval =
|
|
|
|
xfce_rc_read_int_entry (rc, "Update_Interval", UPDATE_TIMEOUT);
|
|
|
|
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("monitor_read_config");
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, TRUE);
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
xfce_rc_close (rc);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void monitor_write_config(XfcePanelPlugin *plugin, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
XfceRc *rc;
|
|
|
|
char *file;
|
2003-08-25 04:05:10 +08:00
|
|
|
char value[20];
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rc = xfce_rc_simple_open (file, FALSE);
|
|
|
|
g_free (file);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
if (!rc)
|
|
|
|
return;
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_bool_entry (rc, "Use_Label", global->monitor->options.use_label);
|
2012-01-07 21:05:32 +08:00
|
|
|
xfce_rc_write_bool_entry (rc, "Show_Values", global->monitor->options.show_values);
|
|
|
|
xfce_rc_write_bool_entry (rc, "Show_Bars", global->monitor->options.show_bars);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
g_snprintf(value, 8, "#%02X%02X%02X",
|
|
|
|
(guint)global->monitor->options.color[IN].red >> 8,
|
|
|
|
(guint)global->monitor->options.color[IN].green >> 8,
|
|
|
|
(guint)global->monitor->options.color[IN].blue >> 8);
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Color_In", value);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
g_snprintf(value, 8, "#%02X%02X%02X",
|
|
|
|
(guint)global->monitor->options.color[OUT].red >> 8,
|
|
|
|
(guint)global->monitor->options.color[OUT].green >> 8,
|
|
|
|
(guint)global->monitor->options.color[OUT].blue >> 8);
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Color_Out", value);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Text", global->monitor->options.label_text ?
|
|
|
|
global->monitor->options.label_text : "");
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Network_Device", global->monitor->options.network_device ?
|
|
|
|
global->monitor->options.network_device : "");
|
2003-08-25 04:05:10 +08:00
|
|
|
|
|
|
|
g_snprintf(value, 20, "%lu", global->monitor->options.max[IN]);
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Max_In", value);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
|
|
|
g_snprintf(value, 20, "%lu", global->monitor->options.max[OUT]);
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_entry (rc, "Max_Out", value);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_bool_entry (rc, "Auto_Max", global->monitor->options.auto_max);
|
2003-08-27 04:34:46 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_write_int_entry (rc, "Update_Interval", global->monitor->options.update_interval);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_rc_close (rc);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static gboolean monitor_set_size(XfcePanelPlugin *plugin, int size, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(global->monitor->status[i]),
|
2006-12-31 00:31:11 +08:00
|
|
|
BORDER, size - BORDER);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(global->monitor->status[i]),
|
2006-12-31 00:31:11 +08:00
|
|
|
size - BORDER, BORDER);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
}
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("monitor_set_size");
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, TRUE);
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void monitor_apply_options(t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2003-08-25 04:05:10 +08:00
|
|
|
gint i;
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-14 02:14:27 +08:00
|
|
|
if (global->monitor->options.label_text)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.label_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
global->monitor->options.label_text =
|
|
|
|
g_strdup(gtk_entry_get_text(GTK_ENTRY(global->monitor->opt_entry)));
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
|
|
|
if (global->monitor->options.network_device)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.network_device);
|
|
|
|
}
|
|
|
|
global->monitor->options.network_device =
|
|
|
|
g_strdup(gtk_entry_get_text(GTK_ENTRY(global->monitor->net_entry)));
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
|
|
|
for( i = 0; i < SUM; i++ )
|
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor->options.max[i] =
|
|
|
|
strtol(gtk_entry_get_text(GTK_ENTRY(global->monitor->max_entry[i])), NULL, 0) * 1024;
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
2003-08-27 04:34:46 +08:00
|
|
|
|
|
|
|
global->monitor->options.update_interval =
|
|
|
|
(gint)(gtk_spin_button_get_value(
|
|
|
|
GTK_SPIN_BUTTON(global->monitor->update_spinner) ) * 1000 + 0.5);
|
|
|
|
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("monitor_apply_options_cb");
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static void label_changed(GtkWidget *button, t_global_monitor *global)
|
2005-02-05 02:12:01 +08:00
|
|
|
{
|
2003-08-14 02:14:27 +08:00
|
|
|
if (global->monitor->options.label_text)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.label_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
global->monitor->options.label_text =
|
|
|
|
g_strdup(gtk_entry_get_text(GTK_ENTRY(global->monitor->opt_entry)));
|
|
|
|
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("label_changed");
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-25 04:05:10 +08:00
|
|
|
static void max_label_changed(GtkWidget *button, t_global_monitor *global)
|
2005-02-05 02:12:01 +08:00
|
|
|
{
|
2003-08-25 04:05:10 +08:00
|
|
|
gint i;
|
|
|
|
for( i = 0; i < SUM; i++ )
|
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor->options.max[i] =
|
|
|
|
strtol(gtk_entry_get_text(GTK_ENTRY(global->monitor->max_entry[i])), NULL, 0) * 1024;
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("max_label_changed");
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static void network_changed(GtkWidget *button, t_global_monitor *global)
|
|
|
|
{
|
|
|
|
if (global->monitor->options.network_device)
|
|
|
|
{
|
|
|
|
g_free(global->monitor->options.network_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
global->monitor->options.network_device =
|
|
|
|
g_strdup(gtk_entry_get_text(GTK_ENTRY(global->monitor->net_entry)));
|
|
|
|
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("network_changed");
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-31 20:54:36 +08:00
|
|
|
static void label_toggled(GtkWidget *check_button, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
global->monitor->options.use_label = !global->monitor->options.use_label;
|
2003-08-14 02:14:27 +08:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(global->monitor->opt_use_label),
|
|
|
|
global->monitor->options.use_label);
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(global->monitor->opt_entry),
|
|
|
|
global->monitor->options.use_label);
|
|
|
|
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("label_toggled");
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2012-01-07 21:05:32 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2012-01-07 21:14:41 +08:00
|
|
|
static void present_data_combobox_changed(GtkWidget *combobox, t_global_monitor *global)
|
2012-01-07 21:05:32 +08:00
|
|
|
{
|
2012-01-07 21:14:41 +08:00
|
|
|
gint option = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox));
|
|
|
|
g_assert(option >= 0 && option <= 2);
|
|
|
|
|
|
|
|
global->monitor->options.show_bars = (option == 0 || option == 2);
|
|
|
|
global->monitor->options.show_values = (option == 1 || option == 2);
|
|
|
|
|
2012-01-07 21:05:32 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2012-01-07 21:14:41 +08:00
|
|
|
PRINT_DBG("present_data_combobox_changed");
|
2012-01-07 21:05:32 +08:00
|
|
|
}
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-25 04:05:10 +08:00
|
|
|
static void max_label_toggled(GtkWidget *check_button, t_global_monitor *global)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
global->monitor->options.auto_max = !global->monitor->options.auto_max;
|
|
|
|
|
|
|
|
for( i = 0; i < SUM; i++ )
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(global->monitor->max_hbox[i]),
|
|
|
|
!(global->monitor->options.auto_max));
|
|
|
|
|
|
|
|
/* reset maximum if necessary */
|
|
|
|
if( global->monitor->options.auto_max )
|
|
|
|
{
|
2003-08-27 04:34:46 +08:00
|
|
|
global->monitor->net_max[i] = INIT_MAX;
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
}
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("max_label_toggled");
|
2003-10-02 03:16:03 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static gboolean expose_event_cb(GtkWidget *widget, GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
if (widget->window)
|
|
|
|
{
|
|
|
|
GtkStyle *style;
|
|
|
|
|
|
|
|
style = gtk_widget_get_style(widget);
|
|
|
|
|
|
|
|
gdk_draw_rectangle(widget->window,
|
|
|
|
style->bg_gc[GTK_STATE_NORMAL],
|
|
|
|
TRUE,
|
|
|
|
event->area.x, event->area.y,
|
|
|
|
event->area.width, event->area.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static void change_color(GtkWidget *button, t_global_monitor *global, gint type)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkColorSelection *colorsel;
|
|
|
|
gint response;
|
|
|
|
|
|
|
|
dialog = gtk_color_selection_dialog_new(_("Select color"));
|
|
|
|
gtk_window_set_transient_for(GTK_WINDOW(dialog),
|
|
|
|
GTK_WINDOW(global->opt_dialog));
|
|
|
|
colorsel =
|
|
|
|
GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);
|
|
|
|
gtk_color_selection_set_previous_color(colorsel,
|
|
|
|
&global->monitor->options.color[type]);
|
|
|
|
gtk_color_selection_set_current_color(colorsel,
|
|
|
|
&global->monitor->options.color[type]);
|
|
|
|
gtk_color_selection_set_has_palette(colorsel, TRUE);
|
|
|
|
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
gtk_color_selection_get_current_color(colorsel,
|
|
|
|
&global->monitor->options.color[type]);
|
|
|
|
gtk_widget_modify_bg(global->monitor->opt_da[type],
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
&global->monitor->options.color[type]);
|
2003-10-02 03:16:03 +08:00
|
|
|
setup_monitor(global, FALSE);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
2005-08-01 06:54:22 +08:00
|
|
|
PRINT_DBG("change_color");
|
2003-08-14 02:14:27 +08:00
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static void change_color_in(GtkWidget *button, t_global_monitor *global)
|
|
|
|
{
|
|
|
|
change_color(button, global, IN);
|
|
|
|
}
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2003-08-14 02:14:27 +08:00
|
|
|
static void change_color_out(GtkWidget *button, t_global_monitor *global)
|
|
|
|
{
|
|
|
|
change_color(button, global, OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void
|
|
|
|
monitor_dialog_response (GtkWidget *dlg, int response, t_global_monitor *global)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
monitor_apply_options (global);
|
|
|
|
gtk_widget_destroy (dlg);
|
|
|
|
xfce_panel_plugin_unblock_menu (global->plugin);
|
|
|
|
monitor_write_config (global->plugin, global);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void monitor_create_options(XfcePanelPlugin *plugin, t_global_monitor *global)
|
|
|
|
{
|
|
|
|
GtkWidget *dlg, *header;
|
2003-08-25 04:05:10 +08:00
|
|
|
GtkBox *vbox, *global_vbox, *net_hbox;
|
|
|
|
GtkWidget *device_label, *unit_label[SUM], *max_label[SUM];
|
|
|
|
GtkWidget *sep1, *sep2;
|
2003-08-27 04:34:46 +08:00
|
|
|
GtkBox *update_hbox;
|
|
|
|
GtkWidget *update_label, *update_unit_label;
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkWidget *color_label[SUM];
|
|
|
|
GtkWidget *align;
|
2012-01-07 21:14:41 +08:00
|
|
|
gint present_data_active;
|
2003-08-14 02:14:27 +08:00
|
|
|
GtkSizeGroup *sg;
|
|
|
|
gint i;
|
2003-08-25 04:05:10 +08:00
|
|
|
gchar buffer[BUFSIZ];
|
2003-08-14 02:14:27 +08:00
|
|
|
gchar *color_text[] = {
|
|
|
|
N_("Bar color (incoming):"),
|
|
|
|
N_("Bar color (outgoing):")
|
|
|
|
};
|
2003-08-25 04:05:10 +08:00
|
|
|
gchar *maximum_text_label[] = {
|
|
|
|
N_("Maximum (incoming):"),
|
|
|
|
N_("Maximum (outgoing):")
|
|
|
|
};
|
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_panel_plugin_block_menu (plugin);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2007-01-05 09:15:52 +08:00
|
|
|
dlg = xfce_titled_dialog_new_with_buttons (_("Network Monitor"), NULL,
|
|
|
|
GTK_DIALOG_NO_SEPARATOR,
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
|
|
|
|
NULL);
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2007-01-05 09:15:52 +08:00
|
|
|
gtk_window_set_icon_name (GTK_WINDOW (dlg), "xfce4-settings");
|
2006-04-26 04:26:28 +08:00
|
|
|
g_signal_connect (dlg, "response", G_CALLBACK (monitor_dialog_response),
|
|
|
|
global);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global->opt_dialog = dlg;
|
|
|
|
|
|
|
|
global_vbox = GTK_BOX (gtk_vbox_new(FALSE, BORDER));
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (global_vbox), BORDER - 2);
|
|
|
|
gtk_widget_show(GTK_WIDGET (global_vbox));
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), GTK_WIDGET (global_vbox), TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
vbox = GTK_BOX(gtk_vbox_new(FALSE, 5));
|
|
|
|
gtk_widget_show(GTK_WIDGET(vbox));
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
global->monitor->opt_vbox = GTK_BOX(gtk_vbox_new(FALSE, 5));
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->opt_vbox));
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Displayed text */
|
|
|
|
global->monitor->opt_hbox = GTK_BOX(gtk_hbox_new(FALSE, 5));
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->opt_hbox));
|
|
|
|
|
|
|
|
global->monitor->opt_use_label =
|
|
|
|
gtk_check_button_new_with_mnemonic(_("Text to display:"));
|
|
|
|
gtk_widget_show(global->monitor->opt_use_label);
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_hbox),
|
|
|
|
GTK_WIDGET(global->monitor->opt_use_label),
|
|
|
|
FALSE, FALSE, 0);
|
2003-08-27 04:34:46 +08:00
|
|
|
gtk_size_group_add_widget(sg, global->monitor->opt_use_label);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
global->monitor->opt_entry = gtk_entry_new();
|
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(global->monitor->opt_entry),
|
|
|
|
MAX_LENGTH);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(global->monitor->opt_entry),
|
|
|
|
global->monitor->options.label_text);
|
|
|
|
gtk_widget_show(global->monitor->opt_entry);
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_hbox),
|
|
|
|
GTK_WIDGET(global->monitor->opt_entry),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
|
|
|
GTK_WIDGET(global->monitor->opt_hbox),
|
|
|
|
FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(global->monitor->opt_use_label),
|
|
|
|
global->monitor->options.use_label);
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(global->monitor->opt_entry),
|
|
|
|
global->monitor->options.use_label);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Network device */
|
|
|
|
net_hbox = GTK_BOX(gtk_hbox_new(FALSE, 5));
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
|
|
|
GTK_WIDGET(net_hbox), FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
device_label = gtk_label_new(_("Network device:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(device_label), 0, 0.5);
|
|
|
|
gtk_widget_show(GTK_WIDGET(device_label));
|
|
|
|
gtk_box_pack_start(GTK_BOX(net_hbox), GTK_WIDGET(device_label),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
global->monitor->net_entry = gtk_entry_new();
|
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(global->monitor->net_entry),
|
|
|
|
MAX_LENGTH);
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(global->monitor->net_entry),
|
|
|
|
global->monitor->options.network_device);
|
|
|
|
gtk_widget_show(global->monitor->opt_entry);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(net_hbox), GTK_WIDGET(global->monitor->net_entry),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gtk_size_group_add_widget(sg, device_label);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_widget_show_all(GTK_WIDGET(net_hbox));
|
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
|
|
|
|
/* Update timevalue */
|
|
|
|
update_hbox = GTK_BOX(gtk_hbox_new(FALSE, 5));
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
|
|
|
GTK_WIDGET(update_hbox), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
update_label = gtk_label_new(_("Update interval:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(update_label), 0, 0.5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(update_hbox), GTK_WIDGET(update_label), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
global->monitor->update_spinner = gtk_spin_button_new_with_range (0.1, 10.0, 0.05);
|
|
|
|
gtk_spin_button_set_digits( GTK_SPIN_BUTTON(global->monitor->update_spinner), 2 );
|
|
|
|
gtk_spin_button_set_value( GTK_SPIN_BUTTON(global->monitor->update_spinner),
|
|
|
|
global->monitor->options.update_interval / 1000.0 );
|
|
|
|
gtk_box_pack_start(GTK_BOX(update_hbox), GTK_WIDGET(global->monitor->update_spinner),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
2003-09-06 20:37:20 +08:00
|
|
|
update_unit_label = gtk_label_new(_("s"));
|
2003-08-27 04:34:46 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(update_hbox), GTK_WIDGET(update_unit_label),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(update_hbox));
|
|
|
|
gtk_size_group_add_widget(sg, update_label);
|
|
|
|
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
sep1 = gtk_hseparator_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox), GTK_WIDGET(sep1), FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(sep1);
|
|
|
|
|
|
|
|
global->monitor->max_use_label =
|
|
|
|
gtk_check_button_new_with_mnemonic(_("Automatic maximum"));
|
|
|
|
gtk_widget_show(global->monitor->max_use_label);
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
|
|
|
GTK_WIDGET(global->monitor->max_use_label), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(global->monitor->max_use_label),
|
|
|
|
global->monitor->options.auto_max);
|
|
|
|
|
|
|
|
/* Input maximum */
|
|
|
|
for( i = 0; i < SUM; i++)
|
|
|
|
{
|
|
|
|
global->monitor->max_hbox[i] = GTK_BOX(gtk_hbox_new(FALSE, 5));
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
|
|
|
GTK_WIDGET(global->monitor->max_hbox[i]), FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
max_label[i] = gtk_label_new(_(maximum_text_label[i]));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(max_label[i]), 0, 0.5);
|
|
|
|
gtk_widget_show(GTK_WIDGET(max_label[i]));
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->max_hbox[i]), GTK_WIDGET(max_label[i]), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
global->monitor->max_entry[i] = gtk_entry_new();
|
|
|
|
gtk_entry_set_max_length(GTK_ENTRY(global->monitor->max_entry[i]), MAX_LENGTH);
|
|
|
|
|
|
|
|
g_snprintf( buffer, BUFSIZ, "%.2f", global->monitor->options.max[i] / 1024.0 );
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(global->monitor->max_entry[i]), buffer);
|
|
|
|
|
2003-08-27 04:34:46 +08:00
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(global->monitor->max_entry[i]), 7);
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_widget_show(global->monitor->max_entry[i]);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->max_hbox[i]), GTK_WIDGET(global->monitor->max_entry[i]),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
unit_label[i] = gtk_label_new(_("kByte/s"));
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->max_hbox[i]), GTK_WIDGET(unit_label[i]), FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_size_group_add_widget(sg, max_label[i]);
|
|
|
|
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(global->monitor->max_hbox[i]));
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(global->monitor->max_hbox[i]),
|
|
|
|
!(global->monitor->options.auto_max) );
|
|
|
|
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->max_entry[i]), "activate",
|
|
|
|
G_CALLBACK(max_label_changed), global);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sep2 = gtk_hseparator_new();
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox), GTK_WIDGET(sep2), FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show(sep2);
|
|
|
|
|
2012-01-07 21:14:41 +08:00
|
|
|
/* Show bars and values */
|
|
|
|
global->monitor->opt_present_data_hbox = GTK_WIDGET(gtk_hbox_new(FALSE, 5));
|
|
|
|
gtk_widget_show(global->monitor->opt_present_data_hbox);
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
2012-01-07 21:14:41 +08:00
|
|
|
GTK_WIDGET(global->monitor->opt_present_data_hbox), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
global->monitor->opt_present_data_label = gtk_label_new_with_mnemonic(_("_Present data as:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(global->monitor->opt_present_data_label), 0, 0.5);
|
|
|
|
gtk_widget_show(global->monitor->opt_present_data_label);
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_present_data_hbox),
|
|
|
|
global->monitor->opt_present_data_label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
global->monitor->opt_present_data_combobox = gtk_combo_box_new_text();
|
|
|
|
gtk_label_set_mnemonic_widget(GTK_LABEL(global->monitor->opt_present_data_label),
|
|
|
|
global->monitor->opt_present_data_combobox);
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(global->monitor->opt_present_data_combobox), _("Bars"));
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(global->monitor->opt_present_data_combobox), _("Values"));
|
|
|
|
gtk_combo_box_append_text(GTK_COMBO_BOX(global->monitor->opt_present_data_combobox), _("Bars and Values"));
|
|
|
|
|
|
|
|
if(global->monitor->options.show_values)
|
|
|
|
if(global->monitor->options.show_bars)
|
|
|
|
present_data_active = 2;
|
|
|
|
else
|
|
|
|
present_data_active = 1;
|
|
|
|
else
|
|
|
|
present_data_active = 0;
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(global->monitor->opt_present_data_combobox), present_data_active);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2012-01-07 21:14:41 +08:00
|
|
|
gtk_widget_show(global->monitor->opt_present_data_combobox);
|
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_present_data_hbox),
|
|
|
|
global->monitor->opt_present_data_combobox, FALSE, FALSE, 0);
|
|
|
|
gtk_size_group_add_widget(sg, global->monitor->opt_present_data_label);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
/* Color 1 */
|
|
|
|
for (i = 0; i < SUM; i++)
|
|
|
|
{
|
2012-01-07 21:05:32 +08:00
|
|
|
global->monitor->opt_color_hbox[i] = gtk_hbox_new(FALSE, 5);
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->opt_color_hbox[i]));
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_vbox),
|
2012-01-07 21:05:32 +08:00
|
|
|
GTK_WIDGET(global->monitor->opt_color_hbox[i]), FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
color_label[i] = gtk_label_new(_(color_text[i]));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(color_label[i]), 0, 0.5);
|
|
|
|
gtk_widget_show(GTK_WIDGET(color_label[i]));
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_color_hbox[i]), GTK_WIDGET(color_label[i]),
|
2003-08-25 04:05:10 +08:00
|
|
|
FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
global->monitor->opt_button[i] = gtk_button_new();
|
|
|
|
global->monitor->opt_da[i] = gtk_drawing_area_new();
|
|
|
|
|
|
|
|
gtk_widget_modify_bg(global->monitor->opt_da[i], GTK_STATE_NORMAL,
|
|
|
|
&global->monitor->options.color[i]);
|
|
|
|
gtk_widget_set_size_request(global->monitor->opt_da[i], 64, 12);
|
|
|
|
gtk_container_add(GTK_CONTAINER(global->monitor->opt_button[i]),
|
|
|
|
global->monitor->opt_da[i]);
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->opt_button[i]));
|
|
|
|
gtk_widget_show(GTK_WIDGET(global->monitor->opt_da[i]));
|
2012-01-07 21:05:32 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(global->monitor->opt_color_hbox[i]),
|
2003-08-25 04:05:10 +08:00
|
|
|
GTK_WIDGET(global->monitor->opt_button[i]),
|
|
|
|
FALSE, FALSE, 0);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_size_group_add_widget(sg, color_label[i]);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
}
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox),
|
|
|
|
GTK_WIDGET(global->monitor->opt_vbox),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
align = gtk_alignment_new(0, 0, 0, 0);
|
|
|
|
gtk_widget_set_size_request(align, 5, 5);
|
|
|
|
gtk_widget_show(GTK_WIDGET(align));
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(align), FALSE, FALSE, 0);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
gtk_box_pack_start( GTK_BOX(global_vbox), GTK_WIDGET(vbox), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->max_use_label), "toggled",
|
|
|
|
G_CALLBACK(max_label_toggled), global);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_da[0]), "expose_event",
|
|
|
|
G_CALLBACK(expose_event_cb), NULL);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_da[1]), "expose_event",
|
|
|
|
G_CALLBACK(expose_event_cb), NULL);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_button[IN]), "clicked",
|
|
|
|
G_CALLBACK(change_color_in), global);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_button[OUT]), "clicked",
|
|
|
|
G_CALLBACK(change_color_out), global);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_use_label), "toggled",
|
|
|
|
G_CALLBACK(label_toggled), global);
|
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_entry), "activate",
|
|
|
|
G_CALLBACK(label_changed), global);
|
2012-01-07 21:14:41 +08:00
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->opt_present_data_combobox), "changed",
|
|
|
|
G_CALLBACK(present_data_combobox_changed), global);
|
2003-08-25 04:05:10 +08:00
|
|
|
g_signal_connect(GTK_WIDGET(global->monitor->net_entry), "activate",
|
|
|
|
G_CALLBACK(network_changed), global);
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
gtk_widget_show (dlg);
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
|
|
|
|
2003-08-25 04:05:10 +08:00
|
|
|
|
2005-02-05 02:12:01 +08:00
|
|
|
/* ---------------------------------------------------------------------------------------------- */
|
2006-04-26 04:26:28 +08:00
|
|
|
static void netload_construct (XfcePanelPlugin *plugin)
|
2003-08-14 02:14:27 +08:00
|
|
|
{
|
2006-04-26 04:26:28 +08:00
|
|
|
t_global_monitor *global;
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
global = monitor_new(plugin);
|
2003-08-14 02:14:27 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
monitor_read_config (plugin, global);
|
|
|
|
|
|
|
|
g_signal_connect (plugin, "free-data", G_CALLBACK (monitor_free), global);
|
|
|
|
|
|
|
|
g_signal_connect (plugin, "save", G_CALLBACK (monitor_write_config), global);
|
|
|
|
|
|
|
|
xfce_panel_plugin_menu_show_configure (plugin);
|
|
|
|
g_signal_connect (plugin, "configure-plugin", G_CALLBACK (monitor_create_options), global);
|
|
|
|
|
|
|
|
g_signal_connect (plugin, "size-changed", G_CALLBACK (monitor_set_size), global);
|
|
|
|
|
|
|
|
g_signal_connect (plugin, "orientation-changed", G_CALLBACK (monitor_set_orientation), global);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(plugin), global->ebox);
|
2012-01-07 21:05:32 +08:00
|
|
|
|
2006-04-26 04:26:28 +08:00
|
|
|
run_update( global );
|
2003-08-14 02:14:27 +08:00
|
|
|
}
|
2006-04-26 04:26:28 +08:00
|
|
|
|
|
|
|
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (netload_construct);
|