summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ellis <johne@bellatlantic.net>1998-05-29 00:04:36 +0000
committerjohne <johne@src.gnome.org>1998-05-29 00:04:36 +0000
commit4e8235143f3498bac2475171845d58bf13778dca (patch)
tree63ce5fd765e8e2d799cc54fb2b7778bf49991b4c
parent8211f503db3823a8351f7d666057ed71295aaceb (diff)
added dial, load, and tooltip. Many changes, so bumped version up to 0.3.0MODEMLIGHTS_ROSALIA_BEFORE_DIALOG_MOD
1998-05-28 John Ellis <johne@bellatlantic.net> * modemlights.[ch], properties.c: added dial, load, and tooltip. Many changes, so bumped version up to 0.3.0 * backgrnd.xpm background_s.xpm: updated * button_on.xpm button_off.xpm: added
-rw-r--r--modemlights/Changelog5
-rw-r--r--modemlights/backgrnd.xpm83
-rw-r--r--modemlights/backgrnd_s.xpm43
-rw-r--r--modemlights/button_off.xpm18
-rw-r--r--modemlights/button_on.xpm18
-rw-r--r--modemlights/lights.xpm40
-rw-r--r--modemlights/modemlights.c315
-rw-r--r--modemlights/modemlights.h8
-rw-r--r--modemlights/properties.c76
9 files changed, 463 insertions, 143 deletions
diff --git a/modemlights/Changelog b/modemlights/Changelog
index 50b79bff8..a41b6fd26 100644
--- a/modemlights/Changelog
+++ b/modemlights/Changelog
@@ -1,3 +1,8 @@
+1998-05-28 John Ellis <johne@bellatlantic.net>
+
+ * modemlights[c.h], properties.c: added dialing, load, tooltip.
+ Many additions, so bumped version up to 0.3.0
+
1998-05-27 Seth Alves <alves@twitch.cp.domain.net>
* modemlights/modemlights.c (update_display):
diff --git a/modemlights/backgrnd.xpm b/modemlights/backgrnd.xpm
index 4af39f27d..9108fe734 100644
--- a/modemlights/backgrnd.xpm
+++ b/modemlights/backgrnd.xpm
@@ -1,49 +1,40 @@
/* XPM */
static char * backgrnd_xpm[] = {
-"10 40 6 1",
+"20 30 7 1",
" c None",
-". c #7F7F7F",
-"+ c #BCBCBC",
-"@ c #004D00",
-"# c #606060",
-"$ c #4C4C4C",
-"...++++...",
-"..+@@@@+..",
-".+@@@@@@#.",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-".+@@@@@@#.",
-"..#@@@@#..",
-"...####...",
-"...++++...",
-"..+@@@@+..",
-".+@@@@@@#.",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-".+@@@@@@#.",
-"..#@@@@#..",
-"...####...",
-"..........",
-"..$$..$$..",
-"..$$..$$..",
-"..........",
-"..$$..$$..",
-"..$$..$$..",
-"..........",
-"..$$..$$..",
-"..$$..$$..",
-"..........",
-"...++++...",
-"..+@@@@+..",
-".+@@@@@@#.",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-".+@@@@@@#.",
-"..#@@@@#..",
-"...####..."};
+". c #FFFFFF",
+"+ c #000000",
+"@ c #7F7F7F",
+"# c #BCBCBC",
+"$ c #004D00",
+"% c #606060",
+"...................+",
+".@@@###@@@@@@###@@@+",
+".@@#$$$#@@@@#$$$#@@+",
+".@#$$$$$%@@#$$$$$%@+",
+".#$$$$$$$%#$$$$$$$%+",
+".#$$$$$$$%#$$$$$$$%+",
+".#$$$$$$$%#$$$$$$$%+",
+".@#$$$$$%@@#$$$$$%@+",
+".@@%$$$%@@@@%$$$%@@+",
+".@@@%%%@@@@@@%%%@@@+",
+".@@@@@@@@@@@@@@@@@@+",
+".%%%%%%%%%%%%%%%%%%+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".%++++++++++++++++#+",
+".##################+",
+".@@@@@@@@@@@@@@@@@@+"};
diff --git a/modemlights/backgrnd_s.xpm b/modemlights/backgrnd_s.xpm
index 1ceecffb9..747ee1b46 100644
--- a/modemlights/backgrnd_s.xpm
+++ b/modemlights/backgrnd_s.xpm
@@ -1,19 +1,30 @@
/* XPM */
static char * backgrnd_s_xpm[] = {
-"40 10 6 1",
+"30 20 7 1",
" c None",
-". c #7F7F7F",
-"+ c #606060",
-"@ c #004D00",
-"# c #BCBCBC",
-"$ c #4C4C4C",
-"...++++......++++................++++...",
-"..+@@@@+....+@@@@+..............+@@@@+..",
-".#@@@@@@+..#@@@@@@+..$$.$$.$$..#@@@@@@+.",
-"#@@@@@@@@+#@@@@@@@@+.$$.$$.$$.#@@@@@@@@+",
-"#@@@@@@@@+#@@@@@@@@+..........#@@@@@@@@+",
-"#@@@@@@@@+#@@@@@@@@+..........#@@@@@@@@+",
-"#@@@@@@@@+#@@@@@@@@+.$$.$$.$$.#@@@@@@@@+",
-".#@@@@@@+..#@@@@@@+..$$.$$.$$..#@@@@@@+.",
-"..#@@@@#....#@@@@#..............#@@@@#..",
-"...####......####................####..."};
+". c #FFFFFF",
+"+ c #000000",
+"@ c #7F7F7F",
+"# c #606060",
+"$ c #BCBCBC",
+"% c #004D00",
+".............................+",
+"@##################@@@@$$$@@@+",
+"@#++++++++++++++++$@@@$%%%$@@+",
+"@#++++++++++++++++$@@$%%%%%#@+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@@$%%%%%#@+",
+"@#++++++++++++++++$@@@#%%%#@@+",
+"@#++++++++++++++++$@@@@###@@@+",
+"@#++++++++++++++++$@@@@$$$@@@+",
+"@#++++++++++++++++$@@@$%%%$@@+",
+"@#++++++++++++++++$@@$%%%%%#@+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@$%%%%%%%#+",
+"@#++++++++++++++++$@@$%%%%%#@+",
+"@#++++++++++++++++$@@@#%%%#@@+",
+"@$$$$$$$$$$$$$$$$$$@@@@###@@@+",
+"++++++++++++++++++++++++++++++"};
diff --git a/modemlights/button_off.xpm b/modemlights/button_off.xpm
new file mode 100644
index 000000000..e52d948a2
--- /dev/null
+++ b/modemlights/button_off.xpm
@@ -0,0 +1,18 @@
+/* XPM */
+static char * button_off_xpm[] = {
+"10 10 5 1",
+" c None",
+". c #7F7F7F",
+"+ c #606060",
+"@ c #004D00",
+"# c #BCBCBC",
+"...++++...",
+"..+@@@@+..",
+".+@@@@@@#.",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+".+@@@@@@#.",
+"..#@@@@#..",
+"...####..."};
diff --git a/modemlights/button_on.xpm b/modemlights/button_on.xpm
new file mode 100644
index 000000000..fbfc4df16
--- /dev/null
+++ b/modemlights/button_on.xpm
@@ -0,0 +1,18 @@
+/* XPM */
+static char * button_on_xpm[] = {
+"10 10 5 1",
+" c None",
+". c #7F7F7F",
+"+ c #606060",
+"@ c #00FF00",
+"# c #BCBCBC",
+"...++++...",
+"..+@@@@+..",
+".+@@@@@@#.",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+"+@@@@@@@@#",
+".+@@@@@@#.",
+"..#@@@@#..",
+"...####..."};
diff --git a/modemlights/lights.xpm b/modemlights/lights.xpm
index 7de3cbfac..2ddf81e98 100644
--- a/modemlights/lights.xpm
+++ b/modemlights/lights.xpm
@@ -1,29 +1,27 @@
/* XPM */
static char * lights_xpm[] = {
-"10 20 6 1",
+"9 18 6 1",
" c None",
". c #7F7F7F",
"+ c #BCBCBC",
"@ c #004D00",
"# c #606060",
"$ c #00FF00",
-"...++++...",
-"..+@@@@+..",
-".+@@@@@@#.",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-"+@@@@@@@@#",
-".+@@@@@@#.",
-"..#@@@@#..",
-"...####...",
-"...++++...",
-"..+$$$$+..",
-".+$$$$$$#.",
-"+$$$$$$$$#",
-"+$$$$$$$$#",
-"+$$$$$$$$#",
-"+$$$$$$$$#",
-".+$$$$$$#.",
-"..#$$$$#..",
-"...####..."};
+"...+++...",
+"..+@@@+..",
+".+@@@@@#.",
+"+@@@@@@@#",
+"+@@@@@@@#",
+"+@@@@@@@#",
+".+@@@@@#.",
+"..#@@@#..",
+"...###...",
+"...+++...",
+"..+$$$+..",
+".+$$$$$#.",
+"+$$$$$$$#",
+"+$$$$$$$#",
+"+$$$$$$$#",
+".+$$$$$#.",
+"..#$$$#..",
+"...###..."};
diff --git a/modemlights/modemlights.c b/modemlights/modemlights.c
index c4f8393db..90835ff82 100644
--- a/modemlights/modemlights.c
+++ b/modemlights/modemlights.c
@@ -1,5 +1,5 @@
/*#####################################################*/
-/*## modemlights applet 0.2.0 alpha ##*/
+/*## modemlights applet 0.3.0 alpha ##*/
/*#####################################################*/
#include "modemlights.h"
@@ -7,23 +7,43 @@
#include "backgrnd.xpm"
#include "backgrnd_s.xpm"
#include "lights.xpm"
+#include "button_off.xpm"
+#include "button_on.xpm"
/* how many times per second to update the lights (1 - 20) */
gint UPDATE_DELAY = 10;
/* the modem lock file */
-gchar lock_file[256];
+gchar *lock_file;
+
+/* connection commands */
+gchar *command_connect;
+gchar *command_disconnect;
static GtkWidget *applet;
static GtkWidget *frame;
static GtkWidget *display_area;
+static GtkWidget *button;
+static GtkWidget *button_pixmap;
static GdkPixmap *display;
static GdkPixmap *display_back;
static GdkPixmap *display_back_s;
static GdkPixmap *lights;
+static GdkPixmap *button_on;
+static GdkPixmap *button_off;
+static GdkGC *gc;
+static GdkColor rxcolor;
+static GdkColor txcolor;
+static GtkTooltips *tooltip;
static int update_timeout_id = FALSE;
static int ip_socket;
+static int load_hist[120];
+static int load_hist_pos = 0;
+static int load_hist_rx[20];
+static int load_hist_tx[20];
+
+static int confirm_dialog = FALSE;
static PanelOrientType orient;
@@ -43,8 +63,8 @@ static void about_cb (AppletWidget *widget, gpointer data)
"(C) 1998",
authors,
_("Released under the GNU general public license.\n"
- "A modem status indicator. "
- "Lights in order from the top or left are RX, TX, and CD."),
+ "A modem status indicator and dialer."
+ "Lights in order from the top or left are RX and TX"),
NULL);
gtk_widget_show (about);
}
@@ -61,12 +81,112 @@ static int Modem_on()
return TRUE;
}
+static void command_connect_cb( gint button, gpointer data)
+{
+ confirm_dialog = FALSE;
+ if (!button) system(command_connect);
+}
+
+static void command_disconnect_cb( gint button, gpointer data)
+{
+ confirm_dialog = FALSE;
+ if (!button) system(command_disconnect);
+}
+
+static void dial_cb()
+{
+ if (confirm_dialog) return;
+
+ confirm_dialog = TRUE;
+
+ if (Modem_on())
+ gnome_question_dialog (_("You are currently connected.\nDo you want to disconnect?"),
+ (GnomeReplyCallback)command_disconnect_cb, NULL);
+ else
+ gnome_question_dialog (_("Do you want to connect?"),
+ (GnomeReplyCallback)command_connect_cb, NULL);
+}
+
+static void update_tooltip(int connected, int rx, int tx)
+{
+ gchar text[64];
+ if (connected)
+ {
+ sprintf(text,"%#.1fM / %#.1fM",(float)rx / 1000000, (float)tx / 1000000);
+ }
+ else
+ strcpy(text, _("not connected"));
+
+ gtk_tooltips_set_tip(tooltip, button, text, NULL);
+}
+
static void redraw_display()
{
gdk_window_set_back_pixmap(display_area->window,display,FALSE);
gdk_window_clear(display_area->window);
}
+static void draw_load(int rxbytes,int txbytes)
+{
+ int load_max = 0;
+ int i;
+ int x,y;
+ float bytes_per_dot;
+
+ if (orient == ORIENT_LEFT || orient == ORIENT_RIGHT)
+ {
+ x = 2;
+ y = 17;
+ }
+ else
+ {
+ x = 2;
+ y = 27;
+ }
+
+ load_hist_pos++;
+ if (load_hist_pos > 119) load_hist_pos = 0;
+ if (txbytes > rxbytes)
+ load_hist[load_hist_pos] = txbytes;
+ else
+ load_hist[load_hist_pos] = rxbytes;
+ for (i=0;i<119;i++)
+ if (load_max < load_hist[i]) load_max = load_hist[i];
+
+ for (i=0;i<16;i++)
+ {
+ load_hist_rx[i] = load_hist_rx[i+1];
+ load_hist_tx[i] = load_hist_tx[i+1];
+ }
+ load_hist_rx[15] = rxbytes;
+ load_hist_tx[15] = txbytes;
+
+ if (load_max < 15)
+ bytes_per_dot = 1.0;
+ else
+ bytes_per_dot = (float)load_max / 15;
+
+ gdk_draw_rectangle(display, display_area->style->black_gc, TRUE, x, y - 15, 16, 16);
+
+ gdk_gc_set_foreground( gc, &rxcolor );
+ for (i=0;i<16;i++)
+ {
+ if( load_hist_rx[i] )
+ gdk_draw_line(display, gc, x+i, y,
+ x+i, y - ((float)load_hist_rx[i] / bytes_per_dot ) + 1);
+ }
+
+ gdk_gc_set_foreground( gc, &txcolor );
+ for (i=0;i<16;i++)
+ {
+ if( load_hist_tx[i] )
+ gdk_draw_line(display, gc, x+i, y,
+ x+i, y - ((float)load_hist_tx[i] / bytes_per_dot ) + 1);
+ }
+
+ redraw_display();
+}
+
static void draw_light(int lit,int x,int y)
{
/* if the orientation is sideways (left or right panel), we swap x and y */
@@ -75,14 +195,14 @@ static void draw_light(int lit,int x,int y)
int t;
t = y;
y = x;
- x = t;
+ x = 21 - t;
}
/* draw the light */
if (lit)
- gdk_draw_pixmap (display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)], lights, 0, 10, x, y, 10, 10);
+ gdk_draw_pixmap (display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)], lights, 0, 9, x, y, 9, 9);
else
- gdk_draw_pixmap (display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)], lights, 0, 0, x, y, 10, 10);
+ gdk_draw_pixmap (display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)], lights, 0, 0, x, y, 9, 9);
}
/* to minimize drawing (pixmap manipulations) we only draw a light if it has changed */
@@ -96,20 +216,22 @@ static void update_lights(int rx,int tx,int cd)
if (rx != o_rx)
{
o_rx = rx;
- draw_light(rx,0,0);
+ draw_light(rx,1,1);
redraw_required = TRUE;
}
if (tx != o_tx)
{
o_tx = tx;
- draw_light(tx,0,10);
+ draw_light(tx,10,1);
redraw_required = TRUE;
}
if (cd != o_cd)
{
o_cd = cd;
- draw_light(cd,0,30);
- redraw_required = TRUE;
+ if (cd)
+ gtk_pixmap_set(GTK_PIXMAP(button_pixmap), button_on, NULL);
+ else
+ gtk_pixmap_set(GTK_PIXMAP(button_pixmap), button_off, NULL);
}
if (redraw_required) redraw_display();
}
@@ -117,12 +239,15 @@ static void update_lights(int rx,int tx,int cd)
static gint update_display()
{
static int old_rx,old_tx;
+ static int load_count;
+ static int modem_was_on = FALSE;
int rx, tx;
int light_rx = FALSE;
int light_tx = FALSE;
struct ifreq ifreq;
struct ppp_stats stats;
+ load_count++;
if (Modem_on())
{
@@ -130,17 +255,18 @@ static gint update_display()
#ifndef __FreeBSD__
strcpy(ifreq.ifr_ifrn.ifrn_name, "ppp0");
#else
- strcpy(ifreq.ifr_name, "ppp0");
+ strcpy(ifreq.ifr_name, "ppp0");
#endif /* __FreeBSD__ */
ifreq.ifr_ifru.ifru_data = (caddr_t)&stats;
#ifndef __FreeBSD__
if ((ioctl(ip_socket,SIOCDEVPRIVATE,(caddr_t)&ifreq) < 0))
#else
- if ((ioctl(ip_socket,SIOCGPPPSTATS,(caddr_t)&ifreq) < 0))
+ if ((ioctl(ip_socket,SIOCGPPPSTATS,(caddr_t)&ifreq) < 0))
#endif /* __FreeBSD__ */
{
- g_print("ioctl failed\n");
+ /* failure means ppp is not up */
old_tx = old_rx = 0;
+ rx = tx = 0;
}
else
{
@@ -151,11 +277,52 @@ static gint update_display()
}
update_lights(light_rx,light_tx,TRUE);
+ if (load_count > UPDATE_DELAY * 2)
+ {
+ static int load_rx, load_tx;
+ static int tooltip_counter;
+
+ tooltip_counter++;
+ if (tooltip_counter > 10)
+ {
+ update_tooltip(TRUE,rx,tx);
+ tooltip_counter = 0;
+ }
+
+ /* This is a check to see if the modem was running before the program
+ started. if it was, we set the past bytes to the current bytes. Otherwise
+ the first load calculation could have a very high number of bytes.
+ (the bytes that accumulated before program start will make max_load too high) */
+ if (!modem_was_on)
+ {
+ load_rx = rx;
+ load_tx = tx;
+ update_tooltip(TRUE,rx,tx);
+ modem_was_on = TRUE;
+ }
+
+ load_count = 0;
+ draw_load(rx - load_rx, tx - load_tx);
+ load_rx = rx;
+ load_tx = tx;
+ }
old_rx = rx;
old_tx = tx;
}
else
+ {
+ if (load_count > UPDATE_DELAY * 2)
+ {
+ load_count = 0;
+ draw_load(0,0);
+ }
update_lights(FALSE,FALSE,FALSE);
+ if (modem_was_on)
+ {
+ update_tooltip(FALSE,0,0);
+ modem_was_on = FALSE;
+ }
+ }
return TRUE;
}
@@ -182,34 +349,68 @@ static void create_pixmaps()
&style->bg[GTK_STATE_NORMAL], (gchar **)backgrnd_s_xpm);
lights = gdk_pixmap_create_from_xpm_d(display_area->window, &mask,
&style->bg[GTK_STATE_NORMAL], (gchar **)lights_xpm);
+ button_off = gdk_pixmap_create_from_xpm_d(applet->window, &mask,
+ &style->bg[GTK_STATE_NORMAL], (gchar **)button_off_xpm);
+ button_on = gdk_pixmap_create_from_xpm_d(applet->window, &mask,
+ &style->bg[GTK_STATE_NORMAL], (gchar **)button_on_xpm);
+
+}
+static void setup_colors()
+{
+ GdkColormap *colormap;
+
+ colormap = gtk_widget_get_colormap(display_area);
+
+ gdk_color_parse("#FF0000", &rxcolor);
+ gdk_color_alloc(colormap, &rxcolor);
+
+ gdk_color_parse("#00FF00", &txcolor);
+ gdk_color_alloc(colormap, &txcolor);
+
+ gc = gdk_gc_new( display_area->window );
+ gdk_gc_copy( gc, display_area->style->white_gc );
}
static void applet_change_orient(GtkWidget *w, PanelOrientType o, gpointer data)
{
/* resize the applet and set the proper background pixmap */
+ static first_call_flag = FALSE;
orient = o;
+ /* catch 22 with the display_area realize and the signal connect for the orient
+ first time through only needs to get the orient, errors if anything is drawn */
+ if (!first_call_flag)
+ {
+ first_call_flag = TRUE;
+ return;
+ }
+
if (orient == ORIENT_LEFT || orient == ORIENT_RIGHT)
{
- display = gdk_pixmap_new(display_area->window,40,10,-1);
- gtk_widget_set_usize(frame, 44, 14);
- gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),40,10);
+ gtk_widget_set_usize(frame, 46, 20);
+ display = gdk_pixmap_new(display_area->window,30,20,-1);
+ gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),30,20);
gdk_draw_pixmap(display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)],
- display_back_s, 0, 0, 0, 0, 40, 10);
+ display_back_s, 0, 0, 0, 0, 30, 20);
+ gtk_widget_set_usize(button,16,20);
+ gtk_fixed_move(GTK_FIXED(frame),display_area,16,0);
+ gtk_fixed_move(GTK_FIXED(frame),button,0,0);
}
else
{
- display = gdk_pixmap_new(display_area->window,10,40,-1);
- gtk_widget_set_usize(frame, 14, 44);
- gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),10,40);
+ gtk_widget_set_usize(frame, 20, 46);
+ display = gdk_pixmap_new(display_area->window,20,30,-1);
+ gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),20,30);
gdk_draw_pixmap(display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)],
- display_back, 0, 0, 0, 0, 10, 40);
+ display_back, 0, 0, 0, 0, 20, 30);
+ gtk_widget_set_usize(button,20,16);
+ gtk_fixed_move(GTK_FIXED(frame),display_area,0,0);
+ gtk_fixed_move(GTK_FIXED(frame),button,0,30);
}
/* we set the lights to off so they will be correct on the next update */
update_lights(FALSE, FALSE, FALSE);
-
-
+ redraw_display();
}
static gint applet_session_save(GtkWidget *widget, char *cfgpath, char *globcfgpath)
@@ -220,10 +421,27 @@ static gint applet_session_save(GtkWidget *widget, char *cfgpath, char *globcfgp
int main (int argc, char *argv[])
{
+ GtkStyle *style;
+ GdkColor button_color = { 0, 0x7F7F, 0x7F7F, 0x7F7F };
+ GdkColor button_color1 = { 0, 0x7A7A, 0x7A7A, 0x7A7A };
+ GdkColor button_color2 = { 0, 0x8A8A, 0x8A8A, 0x8A8A };
+ int i;
+
+ for (i=0;i<119;i++)
+ load_hist[i] = 0;
+
+ for (i=0;i<19;i++)
+ {
+ load_hist_rx[i] = 0;
+ load_hist_tx[i] = 0;
+ }
+
applet_widget_init_defaults("modemlights_applet", NULL, argc, argv, 0,
NULL,argv[0]);
- strcpy(lock_file,"/var/lock/LCK..modem");
+ lock_file = strdup("/var/lock/LCK..modem");
+ command_connect = strdup("pppon");
+ command_disconnect = strdup("pppoff");
orient = ORIENT_UP;
/* open ip socket */
@@ -241,24 +459,46 @@ int main (int argc, char *argv[])
property_load(APPLET_WIDGET(applet)->cfgpath);
/* frame for all widgets */
- frame = gtk_frame_new(NULL);
- gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
+ frame = gtk_fixed_new();
gtk_widget_show(frame);
+ tooltip = gtk_tooltips_new();
+
display_area = gtk_drawing_area_new();
- gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),10,40);
- gtk_container_add(GTK_CONTAINER(frame),display_area);
+ gtk_drawing_area_size(GTK_DRAWING_AREA(display_area),20,30);
+ gtk_fixed_put(GTK_FIXED(frame),display_area,0,0);
gtk_widget_show(display_area);
- applet_widget_add(APPLET_WIDGET(applet), frame);
+ button = gtk_button_new();
- gtk_widget_realize(display_area);
+ /* set button's color */
+ style = gtk_style_new();
+ style->bg[GTK_STATE_NORMAL] = button_color;
+ style->bg[GTK_STATE_ACTIVE] = button_color1;
+ style->bg[GTK_STATE_PRELIGHT] = button_color2;
+ gtk_widget_set_style(button, style);
- display = gdk_pixmap_new(display_area->window,10,40,-1);
+ gtk_widget_set_usize(button,20,16);
+ gtk_fixed_put(GTK_FIXED(frame),button,0,30);
+ gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(dial_cb),NULL);
+ gtk_widget_show(button);
+ gtk_signal_connect(GTK_OBJECT(applet),"change_orient",
+ GTK_SIGNAL_FUNC(applet_change_orient),
+ NULL);
+ applet_widget_add(APPLET_WIDGET(applet), frame);
+ gtk_widget_realize(applet);
+ gtk_widget_realize(display_area);
+
+ setup_colors();
create_pixmaps();
+ applet_change_orient(applet, orient, NULL);
- gtk_widget_show(frame);
+ button_pixmap = gtk_pixmap_new(button_off, NULL);
+ gtk_container_add(GTK_CONTAINER(button), button_pixmap);
+ gtk_widget_show(button_pixmap);
+
+ update_tooltip(FALSE,0,0);
gtk_widget_show(applet);
gtk_signal_connect(GTK_OBJECT(applet),"session_save",
@@ -274,15 +514,6 @@ int main (int argc, char *argv[])
_("About..."),
about_cb, NULL);
- gdk_draw_pixmap (display,display_area->style->fg_gc[GTK_WIDGET_STATE(display_area)],
- display_back, 0, 0, 0, 0, 10, 40);
-
- gtk_signal_connect(GTK_OBJECT(applet),"change_orient",
- GTK_SIGNAL_FUNC(applet_change_orient),
- NULL);
-
- redraw_display();
-
start_callback_update();
applet_widget_gtk_main();
diff --git a/modemlights/modemlights.h b/modemlights/modemlights.h
index d3826d797..aaac1deed 100644
--- a/modemlights/modemlights.h
+++ b/modemlights/modemlights.h
@@ -1,5 +1,5 @@
/*#####################################################*/
-/*## modemlights applet 0.2.0 alpha ##*/
+/*## modemlights applet 0.3.0 alpha ##*/
/*#####################################################*/
#include <stdio.h>
@@ -18,11 +18,13 @@
#include "applet-widget.h"
#define MODEMLIGHTS_APPLET_VERSION_MAJ 0
-#define MODEMLIGHTS_APPLET_VERSION_MIN 2
+#define MODEMLIGHTS_APPLET_VERSION_MIN 3
#define MODEMLIGHTS_APPLET_VERSION_REV 0
extern gint UPDATE_DELAY;
-extern gchar lock_file[];
+extern gchar *lock_file;
+extern gchar *command_connect;
+extern gchar *command_disconnect;
void start_callback_update();
diff --git a/modemlights/properties.c b/modemlights/properties.c
index adeac6fff..6ad495f2c 100644
--- a/modemlights/properties.c
+++ b/modemlights/properties.c
@@ -1,29 +1,28 @@
/*#####################################################*/
-/*## modemlights applet 0.2.0 alpha ##*/
+/*## modemlights applet 0.3.0 alpha ##*/
/*#####################################################*/
#include "modemlights.h"
GtkWidget *propwindow = NULL;
GtkWidget *lockfile_entry = NULL;
+GtkWidget *connect_entry = NULL;
+GtkWidget *disconnect_entry = NULL;
gint P_UPDATE_DELAY = 10;
void property_load(char *path)
{
- gchar * text = NULL;
-
+ if (lock_file) g_free(lock_file);
+ if (command_connect) g_free(command_connect);
+ if (command_disconnect) g_free(command_disconnect);
gnome_config_push_prefix (path);
- UPDATE_DELAY = gnome_config_get_int("delay=10");
- text = gnome_config_get_string("lockfile=/var/lock/LCK..modem");
+ UPDATE_DELAY = gnome_config_get_int("delay=10");
+ lock_file = gnome_config_get_string("lockfile=/var/lock/LCK..modem");
+ command_connect = gnome_config_get_string("connect=pppon");
+ command_disconnect = gnome_config_get_string("disconnect=pppoff");
gnome_config_pop_prefix ();
-
- if (text)
- {
- strcpy(lock_file,text);
- g_free(text);
- }
}
void property_save(char *path)
@@ -31,6 +30,8 @@ void property_save(char *path)
gnome_config_push_prefix(path);
gnome_config_set_int("delay", UPDATE_DELAY);
gnome_config_set_string("lockfile", lock_file);
+ gnome_config_set_string("connect", command_connect);
+ gnome_config_set_string("disconnect", command_disconnect);
gnome_config_sync();
gnome_config_drop_all();
gnome_config_pop_prefix();
@@ -44,9 +45,20 @@ void update_delay_cb( GtkWidget *widget, GtkWidget *spin )
void property_apply_cb( GtkWidget *widget, void *data )
{
- gchar *new_file;
- new_file = gtk_entry_get_text(GTK_ENTRY(lockfile_entry));
- strcpy(lock_file, new_file);
+ gchar *new_text;
+
+ if (lock_file) free(lock_file);
+ new_text = gtk_entry_get_text(GTK_ENTRY(lockfile_entry));
+ lock_file = strdup(new_text);
+
+ if (command_connect) free(command_connect);
+ new_text = gtk_entry_get_text(GTK_ENTRY(connect_entry));
+ command_connect = strdup(new_text);
+
+ if (command_disconnect) free(command_disconnect);
+ new_text = gtk_entry_get_text(GTK_ENTRY(disconnect_entry));
+ command_disconnect = strdup(new_text);
+
UPDATE_DELAY = P_UPDATE_DELAY;
start_callback_update();
}
@@ -62,7 +74,6 @@ void property_show(AppletWidget *applet, gpointer data)
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *label;
- GtkWidget *button;
GtkWidget *delay_w;
GtkObject *delay_adj;
@@ -95,6 +106,7 @@ void property_show(AppletWidget *applet, gpointer data)
gtk_spin_button_set_update_policy( GTK_SPIN_BUTTON(delay_w),GTK_UPDATE_ALWAYS );
gtk_widget_show(delay_w);
+ /* lock file entry */
hbox = gtk_hbox_new(FALSE, 5);
gtk_box_pack_start( GTK_BOX(frame), hbox, FALSE, FALSE, 5);
gtk_widget_show(hbox);
@@ -111,6 +123,40 @@ void property_show(AppletWidget *applet, gpointer data)
gtk_box_pack_start( GTK_BOX(hbox),lockfile_entry , TRUE, TRUE, 5);
gtk_widget_show(lockfile_entry);
+ /* connect entry */
+ hbox = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start( GTK_BOX(frame), hbox, FALSE, FALSE, 5);
+ gtk_widget_show(hbox);
+
+ label = gtk_label_new(_("Connect command:"));
+ gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 5);
+ gtk_widget_show(label);
+
+ connect_entry = gtk_entry_new_with_max_length(255);
+ gtk_entry_set_text(GTK_ENTRY(connect_entry), command_connect);
+ gtk_signal_connect_object(GTK_OBJECT(connect_entry), "changed",
+ GTK_SIGNAL_FUNC(gnome_property_box_changed),
+ GTK_OBJECT(propwindow));
+ gtk_box_pack_start( GTK_BOX(hbox),connect_entry , TRUE, TRUE, 5);
+ gtk_widget_show(connect_entry);
+
+ /* disconnect entry */
+ hbox = gtk_hbox_new(FALSE, 5);
+ gtk_box_pack_start( GTK_BOX(frame), hbox, FALSE, FALSE, 5);
+ gtk_widget_show(hbox);
+
+ label = gtk_label_new(_("Disconnect command:"));
+ gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 5);
+ gtk_widget_show(label);
+
+ disconnect_entry = gtk_entry_new_with_max_length(255);
+ gtk_entry_set_text(GTK_ENTRY(disconnect_entry), command_disconnect);
+ gtk_signal_connect_object(GTK_OBJECT(disconnect_entry), "changed",
+ GTK_SIGNAL_FUNC(gnome_property_box_changed),
+ GTK_OBJECT(propwindow));
+ gtk_box_pack_start( GTK_BOX(hbox),disconnect_entry , TRUE, TRUE, 5);
+ gtk_widget_show(disconnect_entry);
+
label = gtk_label_new(_("General"));
gtk_widget_show(frame);
gnome_property_box_append_page( GNOME_PROPERTY_BOX(propwindow),frame ,label);