[network-manager-netbook/MplPanelClient: 39/44] Add stand-alone mode
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-netbook/MplPanelClient: 39/44] Add stand-alone mode
- Date: Tue, 10 Nov 2009 14:12:59 +0000 (UTC)
commit b1559925e6c66a09d3f10c375a1c1555f9b9c2ee
Author: Bastien Nocera <hadess hadess net>
Date: Wed Sep 30 16:55:09 2009 +0100
Add stand-alone mode
So we can run it without mutter-moblin.
https://bugzilla.gnome.org/show_bug.cgi?id=596890
src/main.c | 44 ++++++++++++++++++++++++++++++++++----------
src/nmn-applet.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
src/nmn-applet.h | 2 ++
3 files changed, 85 insertions(+), 15 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 58e7aa3..61b7aff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,28 +34,52 @@ main (int argc, char *argv[])
{
MplPanelClient *panel_client;
NmnApplet *applet;
+ gboolean standalone = FALSE;
+ GError *error = NULL;
+ GOptionEntry entries[] = {
+ { "standalone", 's', 0, G_OPTION_ARG_NONE, &standalone, _("Run in standalone mode"), NULL }, { NULL }
+ };
bindtextdomain (GETTEXT_PACKAGE, NMNLOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- gtk_init (&argc, &argv);
textdomain (GETTEXT_PACKAGE);
+ g_set_application_name (_("NetworkManager Netbook"));
+ gtk_init_with_args (&argc, &argv, _("- NetworkManager Netbook"),
+ entries, GETTEXT_PACKAGE, &error);
+
+ if (error) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
/* Force to the moblin theme */
gtk_settings_set_string_property (gtk_settings_get_default (),
"gtk-theme-name",
"Moblin-Netbook",
NULL);
- panel_client = mpl_panel_gtk_new (MPL_PANEL_NETWORK,
- _("network"),
- THEME_PATH "/network-manager-netbook.css",
- "unknown",
- TRUE);
-
- applet = nmn_applet_new (panel_client);
- mpl_panel_client_set_height_request (panel_client, 499);
+ if (standalone) {
+ GtkWidget *window;
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (window, "delete-event", (GCallback) gtk_main_quit,
+ NULL);
+ applet = nmn_applet_new_standalone (GTK_WINDOW (window));
+ gtk_widget_set_size_request (window, 1000, -1);
+ utils_set_main_widget (G_OBJECT (window));
+ gtk_widget_show (window);
+ } else {
+ panel_client = mpl_panel_gtk_new (MPL_PANEL_NETWORK,
+ _("network"),
+ THEME_PATH "/network-manager-netbook.css",
+ "unknown",
+ TRUE);
- utils_set_main_widget (G_OBJECT (panel_client));
+ mpl_panel_client_set_height_request (panel_client, 499);
+ applet = nmn_applet_new (NULL);
+ utils_set_main_widget (G_OBJECT (panel_client));
+ }
gtk_main ();
diff --git a/src/nmn-applet.c b/src/nmn-applet.c
index d305d45..eb207f2 100644
--- a/src/nmn-applet.c
+++ b/src/nmn-applet.c
@@ -31,6 +31,7 @@ G_DEFINE_TYPE (NmnApplet, nmn_applet, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_PANEL_CLIENT,
+ PROP_WINDOW,
LAST_PROP
};
@@ -40,6 +41,7 @@ enum {
typedef struct {
NmnNMData *nm_data;
MplPanelClient *panel_client;
+ GtkWindow *window;
NmnStatusIcon *status_icon;
GtkBuilder *builder;
@@ -69,6 +71,16 @@ nmn_applet_new (MplPanelClient *panel_client)
NULL));
}
+NmnApplet *
+nmn_applet_new_standalone (GtkWindow *window)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+ return NMN_APPLET (g_object_new (NMN_TYPE_APPLET,
+ NMN_APPLET_WINDOW, window,
+ NULL));
+}
+
/* enable/disable wifi button */
static void
@@ -436,11 +448,16 @@ constructor (GType type,
priv = GET_PRIVATE (object);
- if (!priv->panel_client) {
+ if (!priv->panel_client && !priv->window) {
g_warning ("Missing constructor arguments");
g_object_unref (object);
return NULL;
}
+ if (priv->panel_client && priv->window) {
+ g_warning ("You can only use a PanelClient if you don't pass a window");
+ g_object_unref (object);
+ return NULL;
+ }
box = gtk_vbox_new (FALSE, 0);
gtk_widget_show (priv->pane);
@@ -450,13 +467,20 @@ constructor (GType type,
gtk_box_pack_end (GTK_BOX (box), priv->new_dialog, TRUE, TRUE, 0);
gtk_widget_show (box);
- window = mpl_panel_gtk_get_window (MPL_PANEL_GTK (priv->panel_client));
+ if (priv->panel_client)
+ window = mpl_panel_gtk_get_window (MPL_PANEL_GTK (priv->panel_client));
+ else
+ window = GTK_WIDGET (priv->window);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_modify_bg (window, GTK_STATE_NORMAL, >k_widget_get_style (window)->white);
gtk_widget_show (GTK_WIDGET (window));
- g_signal_connect (priv->panel_client, "show-begin", G_CALLBACK (show_begin_cb), object);
- g_signal_connect (priv->panel_client, "hide-end", G_CALLBACK (hide_end_cb), object);
+ if (priv->panel_client) {
+ g_signal_connect (priv->panel_client, "show-begin", G_CALLBACK (show_begin_cb), object);
+ g_signal_connect (priv->panel_client, "hide-end", G_CALLBACK (hide_end_cb), object);
+ } else {
+ show_begin_cb (NULL, object);
+ }
return object;
}
@@ -471,7 +495,17 @@ set_property (GObject *object, guint prop_id,
case PROP_PANEL_CLIENT:
/* Construct only */
priv->panel_client = g_value_dup_object (value);
- nmn_status_icon_set_panel_client (priv->status_icon, priv->panel_client);
+ if (priv->panel_client)
+ nmn_status_icon_set_panel_client (priv->status_icon, priv->panel_client);
+ break;
+ case PROP_WINDOW:
+ /* Construct only */
+ priv->window = g_value_dup_object (value);
+ //FIXME we'd like to show a status icon somewhere though
+#if 0
+ if (priv->window)
+ nmn_status_icon_set_panel_client (priv->status_icon, priv->panel_client);
+#endif
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -523,6 +557,9 @@ dispose (GObject *object)
if (priv->panel_client)
g_object_unref (priv->panel_client);
+ if (priv->window)
+ g_object_unref (priv->window);
+
G_OBJECT_CLASS (nmn_applet_parent_class)->dispose (object);
}
@@ -546,4 +583,11 @@ nmn_applet_class_init (NmnAppletClass *class)
"Panel client",
MPL_TYPE_PANEL_CLIENT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property
+ (object_class, PROP_WINDOW,
+ g_param_spec_object (NMN_APPLET_WINDOW,
+ "GtkWindow",
+ "Top-level window",
+ GTK_TYPE_WINDOW,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
diff --git a/src/nmn-applet.h b/src/nmn-applet.h
index 48a3c65..d5a47ce 100644
--- a/src/nmn-applet.h
+++ b/src/nmn-applet.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
#define NMN_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMN_TYPE_APPLET, NmnAppletClass))
#define NMN_APPLET_PANEL_CLIENT "panel-client"
+#define NMN_APPLET_WINDOW "window"
typedef struct {
GObject parent;
@@ -50,6 +51,7 @@ typedef struct {
GType nmn_applet_get_type (void);
NmnApplet *nmn_applet_new (MplPanelClient *panel_client);
+NmnApplet *nmn_applet_new_standalone (GtkWindow *window);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]