From 20efbd7c8bc742d580bc0779b05c1af96787deee Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 25 Nov 2009 13:35:58 -0500 Subject: Add a --geometry command-line option. Applies the user's window geometry string to the first main window. Suggested in bug #529565. --- doc/reference/shell/tmpl/e-shell-window.sgml | 6 ++++ doc/reference/shell/tmpl/e-shell.sgml | 5 +++ doc/reference/shell/tmpl/e-util.sgml | 13 -------- doc/reference/shell/tmpl/eshell-unused.sgml | 12 +++++++ shell/e-shell-window-private.c | 27 +++++++++++++--- shell/e-shell-window-private.h | 2 ++ shell/e-shell-window.c | 39 +++++++++++++++++++++-- shell/e-shell-window.h | 3 +- shell/e-shell.c | 47 +++++++++++++++++++++++++++- shell/main.c | 4 +++ 10 files changed, 136 insertions(+), 22 deletions(-) diff --git a/doc/reference/shell/tmpl/e-shell-window.sgml b/doc/reference/shell/tmpl/e-shell-window.sgml index 9571632bae..0020ae1eb8 100644 --- a/doc/reference/shell/tmpl/e-shell-window.sgml +++ b/doc/reference/shell/tmpl/e-shell-window.sgml @@ -28,6 +28,11 @@ EShellWindow + + + + + @@ -50,6 +55,7 @@ EShellWindow @shell: @safe_mode: +@geometry: @Returns: diff --git a/doc/reference/shell/tmpl/e-shell.sgml b/doc/reference/shell/tmpl/e-shell.sgml index 80c68cb11d..c2697cc65a 100644 --- a/doc/reference/shell/tmpl/e-shell.sgml +++ b/doc/reference/shell/tmpl/e-shell.sgml @@ -94,6 +94,11 @@ EShell @eshell: the object which received the signal. + + + + + diff --git a/doc/reference/shell/tmpl/e-util.sgml b/doc/reference/shell/tmpl/e-util.sgml index 7f1a282fef..b94e7e8b41 100644 --- a/doc/reference/shell/tmpl/e-util.sgml +++ b/doc/reference/shell/tmpl/e-util.sgml @@ -317,19 +317,6 @@ Miscellaneous Utility Functions @Returns: - - - - - -@filename: -@filename_is_uri: -@buffer: -@read: -@error: -@Returns: - - diff --git a/doc/reference/shell/tmpl/eshell-unused.sgml b/doc/reference/shell/tmpl/eshell-unused.sgml index 0928b8d717..f8c2fbcec9 100644 --- a/doc/reference/shell/tmpl/eshell-unused.sgml +++ b/doc/reference/shell/tmpl/eshell-unused.sgml @@ -2266,6 +2266,18 @@ intelligent @filename: @Returns: + + + + + +@filename: +@filename_is_uri: +@buffer: +@read: +@error: +@Returns: + diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index 4025a934f3..e3d685411f 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -334,14 +334,17 @@ e_shell_window_private_constructed (EShellWindow *shell_window) GtkAction *action; GtkActionGroup *action_group; GtkUIManager *ui_manager; + GtkWindow *window; GObject *object; const gchar *key; const gchar *id; + window = GTK_WINDOW (shell_window); + shell = e_shell_window_get_shell (shell_window); shell_settings = e_shell_get_shell_settings (shell); - e_shell_watch_window (shell, GTK_WINDOW (shell_window)); + e_shell_watch_window (shell, window); /* Create the switcher actions before we set the initial * shell view, because the shell view relies on them for @@ -408,10 +411,6 @@ e_shell_window_private_constructed (EShellWindow *shell_window) bridge = gconf_bridge_get (); - key = "/apps/evolution/shell/view_defaults/window"; - gconf_bridge_bind_window ( - bridge, key, GTK_WINDOW (shell_window), TRUE, TRUE); - object = G_OBJECT (shell_window); key = "/apps/evolution/shell/view_defaults/component_id"; gconf_bridge_bind_property (bridge, key, object, "active-view"); @@ -436,6 +435,22 @@ e_shell_window_private_constructed (EShellWindow *shell_window) key = "/apps/evolution/shell/view_defaults/toolbar_visible"; gconf_bridge_bind_property (bridge, key, object, "active"); + /* Configure the initial size and position of the window by way + * of either a user-supplied geometry string or the last recorded + * values. Note that if a geometry string is applied, the window + * size and position are -not- recorded. */ + if (priv->geometry != NULL) { + if (!gtk_window_parse_geometry (window, priv->geometry)) + g_printerr ( + "Failed to parse geometry '%s'\n", + priv->geometry); + g_free (priv->geometry); + priv->geometry = NULL; + } else { + key = "/apps/evolution/shell/view_defaults/window"; + gconf_bridge_bind_window (bridge, key, window, TRUE, TRUE); + } + shell_window_init_switcher_style (shell_window); id = "org.gnome.evolution.shell"; @@ -495,6 +510,8 @@ e_shell_window_private_finalize (EShellWindow *shell_window) EShellWindowPrivate *priv = shell_window->priv; g_hash_table_destroy (priv->loaded_views); + + g_free (priv->geometry); } void diff --git a/shell/e-shell-window-private.h b/shell/e-shell-window-private.h index c4f2e195d2..4570aba02f 100644 --- a/shell/e-shell-window-private.h +++ b/shell/e-shell-window-private.h @@ -98,6 +98,8 @@ struct _EShellWindowPrivate { /* Shell signal handlers. */ GArray *signal_handler_ids; + gchar *geometry; + guint destroyed : 1; /* XXX Do we still need this? */ guint safe_mode : 1; }; diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index a6ac5706e2..737d9dc4a4 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -29,6 +29,7 @@ enum { PROP_0, PROP_ACTIVE_VIEW, + PROP_GEOMETRY, PROP_SAFE_MODE, PROP_SHELL, PROP_UI_MANAGER @@ -141,6 +142,15 @@ shell_window_update_close_action_cb (EShellWindow *shell_window) gtk_action_set_sensitive (ACTION (CLOSE), n_shell_windows > 1); } +static void +shell_window_set_geometry (EShellWindow *shell_window, + const gchar *geometry) +{ + g_return_if_fail (shell_window->priv->geometry == NULL); + + shell_window->priv->geometry = g_strdup (geometry); +} + static void shell_window_set_shell (EShellWindow *shell_window, EShell *shell) @@ -189,6 +199,12 @@ shell_window_set_property (GObject *object, g_value_get_string (value)); return; + case PROP_GEOMETRY: + shell_window_set_geometry ( + E_SHELL_WINDOW (object), + g_value_get_string (value)); + return; + case PROP_SAFE_MODE: e_shell_window_set_safe_mode ( E_SHELL_WINDOW (object), @@ -294,6 +310,22 @@ shell_window_class_init (EShellWindowClass *class) NULL, G_PARAM_READWRITE)); + /** + * EShellWindow:geometry + * + * User-specified initial window geometry string. + **/ + g_object_class_install_property ( + object_class, + PROP_GEOMETRY, + g_param_spec_string ( + "geometry", + _("Geometry"), + _("Initial window geometry string"), + NULL, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY)); + /** * EShellWindow:safe-mode * @@ -380,6 +412,7 @@ e_shell_window_get_type (void) * e_shell_window_new: * @shell: an #EShell * @safe_mode: whether to initialize the window to "safe mode" + * @geometry: initial window geometry string, or %NULL * * Returns a new #EShellWindow. * @@ -397,11 +430,13 @@ e_shell_window_get_type (void) **/ GtkWidget * e_shell_window_new (EShell *shell, - gboolean safe_mode) + gboolean safe_mode, + const gchar *geometry) { return g_object_new ( E_TYPE_SHELL_WINDOW, - "shell", shell, "safe-mode", safe_mode, NULL); + "shell", shell, "geometry", geometry, + "safe-mode", safe_mode, NULL); } /** diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h index b867490afb..c9ba9280b0 100644 --- a/shell/e-shell-window.h +++ b/shell/e-shell-window.h @@ -75,7 +75,8 @@ struct _EShellWindowClass { GType e_shell_window_get_type (void); GtkWidget * e_shell_window_new (EShell *shell, - gboolean safe_mode); + gboolean safe_mode, + const gchar *geometry); EShell * e_shell_window_get_shell (EShellWindow *shell_window); struct _EShellView * e_shell_window_get_shell_view (EShellWindow *shell_window, diff --git a/shell/e-shell.c b/shell/e-shell.c index 6224021ff9..1e5fecfe67 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -51,6 +51,8 @@ struct _EShellPrivate { gpointer preparing_for_line_change; /* weak pointer */ gpointer preparing_for_quit; /* weak pointer */ + gchar *geometry; + guint auto_reconnect : 1; guint network_available : 1; guint online : 1; @@ -60,6 +62,7 @@ struct _EShellPrivate { enum { PROP_0, + PROP_GEOMETRY, PROP_NETWORK_AVAILABLE, PROP_ONLINE, PROP_SHELL_SETTINGS @@ -458,6 +461,15 @@ shell_sm_quit_cb (EShell *shell, shell_prepare_for_quit (shell); } +static void +shell_set_geometry (EShell *shell, + const gchar *geometry) +{ + g_return_if_fail (shell->priv->geometry == NULL); + + shell->priv->geometry = g_strdup (geometry); +} + static void shell_set_property (GObject *object, guint property_id, @@ -465,6 +477,12 @@ shell_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { + case PROP_GEOMETRY: + shell_set_geometry ( + E_SHELL (object), + g_value_get_string (value)); + return; + case PROP_NETWORK_AVAILABLE: e_shell_set_network_available ( E_SHELL (object), @@ -560,6 +578,8 @@ shell_finalize (GObject *object) if (!unique_app_is_running (UNIQUE_APP (object))) e_file_lock_destroy (); + g_free (priv->geometry); + /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -692,6 +712,23 @@ shell_class_init (EShellClass *class) unique_app_class = UNIQUE_APP_CLASS (class); unique_app_class->message_received = shell_message_received; + /** + * EShell:geometry + * + * User-specified initial window geometry string to apply + * to the first #EShellWindow created. + **/ + g_object_class_install_property ( + object_class, + PROP_GEOMETRY, + g_param_spec_string ( + "geometry", + _("Geometry"), + _("Initial window geometry string"), + NULL, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY)); + /** * EShell:network-available * @@ -1221,7 +1258,15 @@ e_shell_create_shell_window (EShell *shell, } } - shell_window = e_shell_window_new (shell, shell->priv->safe_mode); + shell_window = e_shell_window_new ( + shell, + shell->priv->safe_mode, + shell->priv->geometry); + + /* Clear the first-time-only options. */ + shell->priv->safe_mode = FALSE; + g_free (shell->priv->geometry); + shell->priv->geometry = NULL; gtk_widget_show (shell_window); diff --git a/shell/main.c b/shell/main.c index ab82c2eded..e96620ab24 100644 --- a/shell/main.c +++ b/shell/main.c @@ -89,6 +89,7 @@ static gboolean disable_preview = FALSE; static gboolean import_uris = FALSE; static gboolean idle_cb (gchar **uris); +static gchar *geometry = NULL; static gchar *requested_view = NULL; static gchar *evolution_debug_log = NULL; static gchar **remaining_args; @@ -309,6 +310,8 @@ setup_segv_redirect (void) static GOptionEntry entries[] = { { "component", 'c', 0, G_OPTION_ARG_STRING, &requested_view, N_("Start Evolution activating the specified component"), NULL }, + { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, + N_("Apply the given geometry to the main window"), "GEOMETRY" }, { "offline", '\0', 0, G_OPTION_ARG_NONE, &start_offline, N_("Start in offline mode"), NULL }, { "online", '\0', 0, G_OPTION_ARG_NONE, &start_online, @@ -451,6 +454,7 @@ create_default_shell (void) shell = g_object_new ( E_TYPE_SHELL, "name", "org.gnome.Evolution", + "geometry", geometry, "online", online, NULL); -- cgit v1.2.3