[network-manager-netbook] Remove mux dependency.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Remove mux dependency.
- Date: Tue, 26 May 2009 09:41:45 -0400 (EDT)
commit b7473654a9a1ae95834a8cd1305ea91ddd135159
Author: Tambet Ingo <tambet gmail com>
Date: Tue May 26 10:40:58 2009 +0300
Remove mux dependency.
Copy the ligth switch widget from nbtk.
---
configure.in | 2 +-
src/Makefile.am | 2 +
src/nbtk-gtk-light-switch.c | 387 +++++++++++++++++++++++++++++++++++++++++++
src/nbtk-gtk-light-switch.h | 62 +++++++
src/nmn-applet.c | 24 ++--
5 files changed, 464 insertions(+), 13 deletions(-)
diff --git a/configure.in b/configure.in
index fdfe86a..33ac42e 100644
--- a/configure.in
+++ b/configure.in
@@ -12,7 +12,7 @@ AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_LIBTOOL
-PKG_CHECK_MODULES(NMN, dbus-glib-1 >= 0.75 gtk+-2.0 gconf-2.0 gnome-keyring-1 libnm-util libnm_glib mobile-broadband-provider-info mux)
+PKG_CHECK_MODULES(NMN, dbus-glib-1 >= 0.75 gtk+-2.0 gconf-2.0 gnome-keyring-1 libnm-util libnm_glib mobile-broadband-provider-info)
GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
AC_SUBST(GLIB_GENMARSHAL)
diff --git a/src/Makefile.am b/src/Makefile.am
index 529e470..fe32130 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,8 @@ network_manager_netbook_SOURCES = \
utils.h \
wireless-dialog.c \
wireless-dialog.h \
+ nbtk-gtk-light-switch.c \
+ nbtk-gtk-light-switch.h \
$(NULL)
gladedir = $(datadir)/network-manager-netbook
diff --git a/src/nbtk-gtk-light-switch.c b/src/nbtk-gtk-light-switch.c
new file mode 100644
index 0000000..b15fd2c
--- /dev/null
+++ b/src/nbtk-gtk-light-switch.c
@@ -0,0 +1,387 @@
+/*
+ * Copyright 2009 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "nbtk-gtk-light-switch.h"
+
+G_DEFINE_TYPE (NbtkGtkLightSwitch, nbtk_gtk_light_switch, GTK_TYPE_DRAWING_AREA)
+
+#define NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), NBTK_GTK_TYPE_LIGHT_SWITCH, NbtkGtkLightSwitchPrivate))
+
+static gboolean nbtk_gtk_light_switch_configure (GtkWidget *lightswitch,
+ GdkEventConfigure *event);
+static gboolean nbtk_gtk_light_switch_expose (GtkWidget *lightswitch,
+ GdkEventExpose *event);
+static gboolean nbtk_gtk_light_switch_button_release (GtkWidget *lightswitch,
+ GdkEventButton *event);
+static gboolean nbtk_gtk_light_switch_button_press (GtkWidget *lightswitch,
+ GdkEventButton *event);
+static gboolean nbtk_gtk_light_switch_motion_notify (GtkWidget *lightswitch,
+ GdkEventMotion *event);
+static void nbtk_gtk_light_switch_size_request (GtkWidget *lightswitch,
+ GtkRequisition *req);
+
+static void nbtk_gtk_light_switch_style_set (GtkWidget *lightswitch,
+ GtkStyle *previous_style);
+
+enum {
+ SWITCH_FLIPPED,
+ LAST_SIGNAL
+};
+
+static guint nbtk_gtk_light_switch_signals[LAST_SIGNAL] = { 0 };
+
+typedef struct _NbtkGtkLightSwitchPrivate NbtkGtkLightSwitchPrivate;
+
+struct _NbtkGtkLightSwitchPrivate {
+ gboolean active; /* boolean state of switch */
+ gboolean dragging; /* true if dragging switch */
+ gint x; /* the x position of the switch */
+ gint switch_width;
+ gint switch_height;
+ gint trough_width;
+ gint offset; /* offset of the mouse to slider when dragging */
+};
+
+static void
+nbtk_gtk_light_switch_class_init (NbtkGtkLightSwitchClass *klass)
+{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->configure_event = nbtk_gtk_light_switch_configure;
+ widget_class->expose_event = nbtk_gtk_light_switch_expose;
+ widget_class->button_release_event = nbtk_gtk_light_switch_button_release;
+ widget_class->button_press_event = nbtk_gtk_light_switch_button_press;
+ widget_class->motion_notify_event = nbtk_gtk_light_switch_motion_notify;
+ widget_class->size_request = nbtk_gtk_light_switch_size_request;
+ widget_class->style_set = nbtk_gtk_light_switch_style_set;
+
+ /* NbtkGtkLightSwitch signals */
+ nbtk_gtk_light_switch_signals[SWITCH_FLIPPED] =
+ g_signal_new ("switch-flipped",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NbtkGtkLightSwitchClass, switch_flipped),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
+
+ g_type_class_add_private (klass,
+ sizeof (NbtkGtkLightSwitchPrivate));
+}
+
+static void
+nbtk_gtk_light_switch_init (NbtkGtkLightSwitch *self)
+{
+ NbtkGtkLightSwitchPrivate *priv;
+
+ priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (self);
+ priv->active = FALSE;
+ priv->x = 0;
+
+ /* add events, do initial draw/update, etc */
+ gtk_widget_add_events (GTK_WIDGET (self),
+ GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_POINTER_MOTION_MASK);
+}
+
+static void
+draw (GtkWidget *lightswitch,
+ cairo_t *cr)
+{
+ NbtkGtkLightSwitchPrivate *priv;
+
+ gint on_label_x;
+ gint off_label_x;
+ gint label_width;
+ gint label_height;
+ GtkStyle *style;
+ PangoLayout *layout;
+ PangoContext *context;
+
+ priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+ style = lightswitch->style;
+
+ on_label_x = (priv->trough_width / 5) * 0.75;
+ off_label_x = (priv->trough_width / 8) * 5;
+
+ /* draw the trough */
+ gtk_paint_box (style,
+ lightswitch->window,
+ GTK_STATE_SELECTED,
+ GTK_SHADOW_IN,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ (priv->trough_width / 2),
+ priv->switch_height);
+ gtk_paint_box (style,
+ lightswitch->window,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_IN,
+ NULL,
+ NULL,
+ NULL,
+ (priv->trough_width / 2),
+ 0,
+ (priv->trough_width / 2),
+ priv->switch_height);
+
+ /* Draw the first label; "On" */
+ context = gdk_pango_context_get ();
+ layout = pango_layout_new (context);
+ g_object_unref (context);
+ pango_layout_set_font_description (layout,
+ style->font_desc);
+ pango_layout_set_text (layout, "On", -1);
+ pango_layout_get_size (layout,
+ &label_width,
+ &label_height);
+ gdk_draw_layout (lightswitch->window,
+ style->fg_gc[GTK_STATE_SELECTED],
+ on_label_x,
+ (priv->switch_height
+ - (label_height / PANGO_SCALE)) / 2,
+ layout);
+ /* Draw the second label; "Off" */
+ pango_layout_set_text (layout, "Off", -1);
+ pango_layout_get_size (layout,
+ &label_width,
+ &label_height);
+ gdk_draw_layout (lightswitch->window,
+ style->fg_gc[GTK_STATE_NORMAL],
+ off_label_x,
+ (priv->switch_height
+ - (label_height / PANGO_SCALE)) / 2,
+ layout);
+
+ /* draw the switch itself */
+ gtk_paint_box (style,
+ lightswitch->window,
+ GTK_WIDGET_STATE (lightswitch),
+ GTK_SHADOW_OUT,
+ NULL,
+ NULL,
+ NULL,
+ priv->x,
+ 0,
+ priv->switch_width,
+ priv->switch_height);
+
+ g_object_unref (layout);
+}
+
+static void
+nbtk_gtk_light_switch_size_request (GtkWidget *lightswitch,
+ GtkRequisition *req)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ req->height = priv->switch_height;
+ req->width = priv->trough_width;
+}
+
+static void
+nbtk_gtk_light_switch_style_set (GtkWidget *lightswitch,
+ GtkStyle *previous_style)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+ PangoLayout *layout;
+ gint label_width, label_height;
+ gint off_width, off_height;
+ gint on_width, on_height;
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (lightswitch), NULL);
+ pango_layout_set_text (layout, "Off", -1);
+ pango_layout_get_pixel_size (layout, &off_width, &off_height);
+ pango_layout_set_text (layout, "On", -1);
+ pango_layout_get_pixel_size (layout, &on_width, &on_height);
+ g_object_unref (layout);
+
+ label_width = MAX (off_width, on_width);
+ label_height = MAX (off_height, on_height);
+
+ priv->trough_width = label_width * 5;
+ priv->switch_width = (priv->trough_width / 2) * 1.1;
+ priv->switch_height = (label_height * 2) * 1.1;
+}
+
+static gboolean
+nbtk_gtk_light_switch_configure (GtkWidget *lightswitch,
+ GdkEventConfigure *event)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ if (priv->active)
+ priv->x = priv->trough_width - priv->switch_width;
+ else
+ priv->x = 0;
+
+ return FALSE;
+}
+
+static gboolean
+nbtk_gtk_light_switch_expose (GtkWidget *lightswitch,
+ GdkEventExpose *event)
+{
+ cairo_t *cr;
+ cr = gdk_cairo_create (lightswitch->window);
+
+ cairo_rectangle (cr,
+ event->area.x,
+ event->area.y,
+ event->area.width,
+ event->area.height);
+
+ cairo_clip (cr);
+
+ draw (lightswitch, cr);
+
+ cairo_destroy (cr);
+
+ return FALSE;
+}
+
+static gboolean
+nbtk_gtk_light_switch_motion_notify (GtkWidget *lightswitch,
+ GdkEventMotion *event)
+{
+ NbtkGtkLightSwitchPrivate *priv;
+
+ priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ if (event->state & GDK_BUTTON1_MASK)
+ {
+ gint position = event->x - priv->offset;
+
+ if (position > (priv->trough_width - priv->switch_width))
+ priv->x = (priv->trough_width - priv->switch_width);
+ else if (position < 0)
+ priv->x = 0;
+ else
+ priv->x = position;
+
+ priv->dragging = TRUE;
+ gtk_widget_queue_draw ((GtkWidget *) lightswitch);
+ }
+
+ return TRUE;
+}
+
+gboolean
+nbtk_gtk_light_switch_get_active (NbtkGtkLightSwitch *lightswitch)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ return priv->active;
+}
+
+void
+nbtk_gtk_light_switch_set_active (NbtkGtkLightSwitch *lightswitch,
+ gboolean active)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ if (priv->active == active)
+ {
+ return;
+ }
+ else
+ {
+ priv->active = active;
+ if (active == TRUE)
+ {
+ priv->x = priv->trough_width - priv->switch_width;
+ }
+ else
+ {
+ priv->x = 0;
+ }
+
+ gtk_widget_queue_draw ((GtkWidget *) lightswitch);
+
+ g_signal_emit (lightswitch,
+ nbtk_gtk_light_switch_signals[SWITCH_FLIPPED],
+ 0,
+ priv->active);
+ }
+}
+
+static gboolean
+nbtk_gtk_light_switch_button_press (GtkWidget *lightswitch,
+ GdkEventButton *event)
+{
+ NbtkGtkLightSwitchPrivate *priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ if (priv->active)
+ priv->offset = event->x - (priv->trough_width - priv->switch_width);
+ else
+ priv->offset = event->x;
+
+ return FALSE;
+}
+
+static gboolean
+nbtk_gtk_light_switch_button_release (GtkWidget *lightswitch,
+ GdkEventButton *event)
+{
+ NbtkGtkLightSwitchPrivate *priv;
+
+ priv = NBTK_GTK_LIGHT_SWITCH_GET_PRIVATE (lightswitch);
+
+ /* detect whereabouts we are and "drop" into a state */
+ if (priv->dragging)
+ {
+ priv->dragging = FALSE;
+ if (priv->x + (priv->switch_width / 2) > priv->trough_width / 2)
+ {
+ nbtk_gtk_light_switch_set_active ((NbtkGtkLightSwitch *) lightswitch, TRUE);
+ priv->x = priv->trough_width - priv->switch_width;
+ }
+ else
+ {
+ nbtk_gtk_light_switch_set_active ((NbtkGtkLightSwitch *) lightswitch, FALSE);
+ priv->x = 0;
+ }
+ /* we always need to queue a redraw after dragging to put the slider back
+ * in the correct place */
+ gtk_widget_queue_draw ((GtkWidget *) lightswitch);
+ }
+ else
+ {
+ nbtk_gtk_light_switch_set_active ((NbtkGtkLightSwitch *) lightswitch, !priv->active);
+ }
+
+ return FALSE;
+}
+
+GtkWidget*
+nbtk_gtk_light_switch_new (void)
+{
+ return g_object_new (NBTK_GTK_TYPE_LIGHT_SWITCH, NULL);
+}
+
diff --git a/src/nbtk-gtk-light-switch.h b/src/nbtk-gtk-light-switch.h
new file mode 100644
index 0000000..3c78504
--- /dev/null
+++ b/src/nbtk-gtk-light-switch.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2009 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+#ifndef _NBTK_GTK_LIGHT_SWITCH
+#define _NBTK_GTK_LIGHT_SWITCH
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define NBTK_GTK_TYPE_LIGHT_SWITCH nbtk_gtk_light_switch_get_type ()
+
+#define NBTK_GTK_LIGHT_SWITCH(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), NBTK_GTK_TYPE_LIGHT_SWITCH, NbtkGtkLightSwitch))
+
+#define NBTK_GTK_LIGHT_SWITCH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), NBTK_GTK_TYPE_LIGHT_SWITCH, NbtkGtkLightSwitchClass))
+
+#define NBTK_GTK_IS_LIGHT_SWITCH(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NBTK_GTK_TYPE_LIGHT_SWITCH))
+
+#define NBTK_GTK_IS_LIGHT_SWITCH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), NBTK_GTK_TYPE_LIGHT_SWITCH))
+
+#define NBTK_GTK_LIGHT_SWITCH_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), NBTK_GTK_TYPE_LIGHT_SWITCH, NbtkGtkLightSwitchClass))
+
+typedef struct {
+ GtkDrawingArea parent;
+} NbtkGtkLightSwitch;
+
+typedef struct {
+ GtkDrawingAreaClass parent_class;
+
+ void (*switch_flipped) (NbtkGtkLightSwitch *lightswitch, gboolean state);
+} NbtkGtkLightSwitchClass;
+
+GType nbtk_gtk_light_switch_get_type (void);
+
+void nbtk_gtk_light_switch_set_active (NbtkGtkLightSwitch *lightswitch, gboolean active);
+gboolean nbtk_gtk_light_switch_get_active (NbtkGtkLightSwitch *lightswitch);
+
+GtkWidget* nbtk_gtk_light_switch_new (void);
+
+G_END_DECLS
+
+#endif /* _NBTK_GTK_LIGHT_SWITCH */
diff --git a/src/nmn-applet.c b/src/nmn-applet.c
index a6af0b2..9812482 100644
--- a/src/nmn-applet.c
+++ b/src/nmn-applet.c
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <dbus/dbus-glib-lowlevel.h>
-#include <mux/mux-light-switch.h>
+#include <nbtk-gtk-light-switch.h>
#include "nmn-applet.h"
#include "nmn-nm-data.h"
#include "nmn-status-icon.h"
@@ -61,7 +61,7 @@ nmn_applet_get_plug (NmnApplet *applet)
/* enable/disable wifi button */
static void
-enable_wifi_toggled (MuxLightSwitch *w,
+enable_wifi_toggled (NbtkGtkLightSwitch *w,
gboolean active,
gpointer user_data)
{
@@ -78,7 +78,7 @@ wireless_state_changed (NMClient *client,
NmnAppletPrivate *priv = GET_PRIVATE (user_data);
g_signal_handlers_block_by_func (priv->enable_wifi, enable_wifi_toggled, user_data);
- mux_light_switch_set_active (MUX_LIGHT_SWITCH (priv->enable_wifi),
+ nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_wifi),
nm_client_wireless_get_enabled (client));
g_signal_handlers_unblock_by_func (priv->enable_wifi, enable_wifi_toggled, user_data);
@@ -89,7 +89,7 @@ enable_wifi_setup (NmnApplet *applet)
{
NmnAppletPrivate *priv = GET_PRIVATE (applet);
- priv->enable_wifi = mux_light_switch_new ();
+ priv->enable_wifi = nbtk_gtk_light_switch_new ();
gtk_table_attach (priv->switch_table,
priv->enable_wifi,
1, 2, 0, 1,
@@ -115,7 +115,7 @@ enable_wifi_setup (NmnApplet *applet)
/* enable/disable ethernet button */
static void
-enable_ethernet_toggled (MuxLightSwitch *w,
+enable_ethernet_toggled (NbtkGtkLightSwitch *w,
gboolean active,
gpointer user_data)
{
@@ -126,7 +126,7 @@ enable_ethernet_setup (NmnApplet *applet)
{
NmnAppletPrivate *priv = GET_PRIVATE (applet);
- priv->enable_ethernet = mux_light_switch_new ();
+ priv->enable_ethernet = nbtk_gtk_light_switch_new ();
gtk_table_attach (priv->switch_table,
priv->enable_ethernet,
1, 2, 1, 2,
@@ -137,14 +137,14 @@ enable_ethernet_setup (NmnApplet *applet)
gtk_widget_show (priv->enable_wifi);
/* FIXME: Enable/disable ethernet is not supported yet */
- mux_light_switch_set_active (MUX_LIGHT_SWITCH (priv->enable_ethernet), TRUE);
+ nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_ethernet), TRUE);
gtk_widget_set_sensitive (priv->enable_ethernet, FALSE);
}
/* enable/disable 3G button */
static void
-enable_3g_toggled (MuxLightSwitch *w,
+enable_3g_toggled (NbtkGtkLightSwitch *w,
gboolean active,
gpointer user_data)
{
@@ -155,7 +155,7 @@ enable_3g_setup (NmnApplet *applet)
{
NmnAppletPrivate *priv = GET_PRIVATE (applet);
- priv->enable_3g = mux_light_switch_new ();
+ priv->enable_3g = nbtk_gtk_light_switch_new ();
gtk_table_attach (priv->switch_table,
priv->enable_3g,
1, 2, 2, 3,
@@ -165,14 +165,14 @@ enable_3g_setup (NmnApplet *applet)
gtk_widget_show (priv->enable_3g);
/* FIXME: Enable/disable 3G is not supported yet */
- mux_light_switch_set_active (MUX_LIGHT_SWITCH (priv->enable_3g), TRUE);
+ nbtk_gtk_light_switch_set_active (NBTK_GTK_LIGHT_SWITCH (priv->enable_3g), TRUE);
gtk_widget_set_sensitive (priv->enable_3g, FALSE);
}
/* enable/disable Fligh mode button */
static void
-enable_flightmode_toggled (MuxLightSwitch *w,
+enable_flightmode_toggled (NbtkGtkLightSwitch *w,
gboolean active,
gpointer user_data)
{
@@ -190,7 +190,7 @@ enable_flightmode_setup (NmnApplet *applet)
{
NmnAppletPrivate *priv = GET_PRIVATE (applet);
- priv->enable_flightmode = mux_light_switch_new ();
+ priv->enable_flightmode = nbtk_gtk_light_switch_new ();
gtk_table_attach (priv->switch_table,
priv->enable_flightmode,
1, 2, 4, 5,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]