[gnome-software] GsShell: Add API to get shell window
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] GsShell: Add API to get shell window
- Date: Sat, 5 Jul 2014 20:32:42 +0000 (UTC)
commit 027917c0eacdc2bce7dbdbb3be34cc161a957f1f
Author: Kalev Lember <kalevlember gmail com>
Date: Sat Jul 5 21:15:56 2014 +0200
GsShell: Add API to get shell window
This simplifies calling code, avoiding the need to poke manually at
GtkBuilder to get the shell's main window.
src/gs-application.c | 7 ++---
src/gs-shell-details.c | 17 ++++--------
src/gs-shell-installed.c | 8 ++----
src/gs-shell-search.c | 12 ++++-----
src/gs-shell-updates.c | 11 ++------
src/gs-shell.c | 61 +++++++++++++++++++--------------------------
src/gs-shell.h | 3 +-
src/gs-utils.c | 8 ++----
src/gs-utils.h | 4 +-
9 files changed, 53 insertions(+), 78 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 5ead7c2..888bb14 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -170,7 +170,6 @@ gs_application_initialize_ui (GsApplication *app)
static gboolean initialized = FALSE;
GtkBuilder *builder;
GMenuModel *app_menu;
- GtkWindow *window;
GFile *file;
gchar *theme;
@@ -209,11 +208,11 @@ gs_application_initialize_ui (GsApplication *app)
app->cancellable = g_cancellable_new ();
- window = gs_shell_setup (app->shell, app->plugin_loader, app->cancellable);
- gtk_application_add_window (GTK_APPLICATION (app), window);
+ gs_shell_setup (app->shell, app->plugin_loader, app->cancellable);
+ gtk_application_add_window (GTK_APPLICATION (app), gs_shell_get_window (app->shell));
g_signal_connect_swapped (app->shell, "loaded",
- G_CALLBACK (gtk_window_present), window);
+ G_CALLBACK (gtk_window_present), gs_shell_get_window (app->shell));
}
static void
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 2af6ae9..fc2e906 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1031,8 +1031,8 @@ gs_shell_details_app_installed_cb (GObject *source,
g_warning ("failed to install %s: %s",
gs_app_get_id (helper->app),
error->message);
- gs_app_notify_failed_modal (helper->shell_details->priv->builder,
- helper->app,
+ gs_app_notify_failed_modal (helper->app,
+ gs_shell_get_window (helper->shell_details->priv->shell),
GS_PLUGIN_LOADER_ACTION_INSTALL,
error);
g_error_free (error);
@@ -1069,8 +1069,8 @@ gs_shell_details_app_removed_cb (GObject *source,
g_warning ("failed to remove %s: %s",
gs_app_get_id (helper->app),
error->message);
- gs_app_notify_failed_modal (helper->shell_details->priv->builder,
- helper->app,
+ gs_app_notify_failed_modal (helper->app,
+ gs_shell_get_window (helper->shell_details->priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
g_error_free (error);
@@ -1094,9 +1094,7 @@ gs_shell_details_app_remove (GsShellDetails *shell_details, GsApp *app)
GString *markup;
GtkResponseType response;
GtkWidget *dialog;
- GtkWindow *window;
- window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
markup = g_string_new ("");
g_string_append_printf (markup,
/* TRANSLATORS: this is a prompt message, and
@@ -1105,7 +1103,7 @@ gs_shell_details_app_remove (GsShellDetails *shell_details, GsApp *app)
gs_app_get_name (app));
g_string_prepend (markup, "<b>");
g_string_append (markup, "</b>");
- dialog = gtk_message_dialog_new (window,
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
@@ -1257,13 +1255,10 @@ static void
gs_shell_details_app_history_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
{
GsShellDetailsPrivate *priv = shell_details->priv;
- GtkWidget *toplevel;
gs_history_dialog_set_app (GS_HISTORY_DIALOG (priv->history_dialog), priv->app);
- toplevel = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- gtk_window_set_transient_for (GTK_WINDOW (priv->history_dialog), GTK_WINDOW (toplevel));
-
+ gtk_window_set_transient_for (GTK_WINDOW (priv->history_dialog), gs_shell_get_window (priv->shell));
gtk_window_present (GTK_WINDOW (priv->history_dialog));
}
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index e37910a..a569e71 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -126,8 +126,8 @@ gs_shell_installed_app_removed_cb (GObject *source,
g_warning ("failed to remove %s: %s",
gs_app_get_id (app),
error->message);
- gs_app_notify_failed_modal (priv->builder,
- app,
+ gs_app_notify_failed_modal (app,
+ gs_shell_get_window (priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
g_error_free (error);
@@ -157,10 +157,8 @@ gs_shell_installed_app_remove_cb (GsAppRow *app_row,
GString *markup;
GtkResponseType response;
GtkWidget *dialog;
- GtkWindow *window;
GsShellInstalledHelper *helper;
- window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
markup = g_string_new ("");
app = gs_app_row_get_app (app_row);
g_string_append_printf (markup,
@@ -170,7 +168,7 @@ gs_shell_installed_app_remove_cb (GsAppRow *app_row,
gs_app_get_name (app));
g_string_prepend (markup, "<b>");
g_string_append (markup, "</b>");
- dialog = gtk_message_dialog_new (window,
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 38f6abc..31e6ecb 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -84,8 +84,8 @@ gs_shell_search_app_installed_cb (GObject *source,
g_warning ("failed to install %s: %s",
gs_app_get_id (helper->app),
error->message);
- gs_app_notify_failed_modal (helper->shell_search->priv->builder,
- helper->app,
+ gs_app_notify_failed_modal (helper->app,
+ gs_shell_get_window (helper->shell_search->priv->shell),
GS_PLUGIN_LOADER_ACTION_INSTALL,
error);
g_error_free (error);
@@ -118,8 +118,8 @@ gs_shell_search_app_removed_cb (GObject *source,
if (!ret) {
g_warning ("failed to remove: %s",
error->message);
- gs_app_notify_failed_modal (helper->shell_search->priv->builder,
- helper->app,
+ gs_app_notify_failed_modal (helper->app,
+ gs_shell_get_window (helper->shell_search->priv->shell),
GS_PLUGIN_LOADER_ACTION_REMOVE,
error);
g_error_free (error);
@@ -139,9 +139,7 @@ gs_shell_search_app_remove (GsShellSearch *shell_search, GsApp *app)
GString *markup;
GtkResponseType response;
GtkWidget *dialog;
- GtkWindow *window;
- window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
markup = g_string_new ("");
g_string_append_printf (markup,
/* TRANSLATORS: this is a prompt message, and
@@ -150,7 +148,7 @@ gs_shell_search_app_remove (GsShellSearch *shell_search, GsApp *app)
gs_app_get_name (app));
g_string_prepend (markup, "<b>");
g_string_append (markup, "</b>");
- dialog = gtk_message_dialog_new (window,
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 7b73a28..a038cc5 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -522,14 +522,11 @@ show_update_details (GsApp *app, GsShellUpdates *shell_updates)
{
GsShellUpdatesPrivate *priv = shell_updates->priv;
GtkWidget *dialog;
- GtkWidget *toplevel;
dialog = gs_update_dialog_new ();
gs_update_dialog_show_update_details (GS_UPDATE_DIALOG (dialog), app);
- toplevel = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
-
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), gs_shell_get_window (priv->shell));
gtk_window_present (GTK_WINDOW (dialog));
}
@@ -718,8 +715,7 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
gs_shell_updates_get_new_updates (shell_updates);
break;
case PK_NETWORK_ENUM_OFFLINE:
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- dialog = gtk_message_dialog_new (GTK_WINDOW (widget),
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
GTK_DIALOG_MODAL |
GTK_DIALOG_USE_HEADER_BAR |
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -746,8 +742,7 @@ gs_shell_updates_button_refresh_cb (GtkWidget *widget,
gs_shell_updates_get_new_updates (shell_updates);
break;
}
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- dialog = gtk_message_dialog_new (GTK_WINDOW (widget),
+ dialog = gtk_message_dialog_new (gs_shell_get_window (priv->shell),
GTK_DIALOG_MODAL |
GTK_DIALOG_USE_HEADER_BAR |
GTK_DIALOG_DESTROY_WITH_PARENT,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 04bb60f..ec45068 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -67,6 +67,7 @@ struct GsShellPrivate
GsShellDetails *shell_details;
GsShellCategory *shell_category;
GtkBuilder *builder;
+ GtkWindow *main_window;
GSList *back_entry_stack;
};
@@ -85,10 +86,18 @@ static guint signals [SIGNAL_LAST] = { 0 };
gboolean
gs_shell_is_active (GsShell *shell)
{
- GtkWindow *window;
- window = GTK_WINDOW (gtk_builder_get_object (shell->priv->builder,
- "window_software"));
- return gtk_window_is_active (window);
+ GsShellPrivate *priv = shell->priv;
+ return gtk_window_is_active (priv->main_window);
+}
+
+/**
+ * gs_shell_get_window:
+ **/
+GtkWindow *
+gs_shell_get_window (GsShell *shell)
+{
+ GsShellPrivate *priv = shell->priv;
+ return priv->main_window;
}
/**
@@ -97,9 +106,8 @@ gs_shell_is_active (GsShell *shell)
void
gs_shell_activate (GsShell *shell)
{
- GtkWindow *window;
- window = GTK_WINDOW (gtk_builder_get_object (shell->priv->builder, "window_software"));
- gtk_window_present (window);
+ GsShellPrivate *priv = shell->priv;
+ gtk_window_present (priv->main_window);
}
static void
@@ -111,7 +119,6 @@ gs_shell_change_mode (GsShell *shell,
{
GsShellPrivate *priv = shell->priv;
GtkWidget *widget;
- GtkWindow *window;
const gchar *text;
GtkStyleContext *context;
@@ -156,9 +163,8 @@ gs_shell_change_mode (GsShell *shell,
context = gtk_widget_get_style_context (GTK_WIDGET (gtk_builder_get_object (priv->builder,
"header")));
gtk_style_context_remove_class (context, "selection-mode");
/* set the window title back to default */
- window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
/* TRANSLATORS: this is the main window title */
- gtk_window_set_title (window, _("Software"));
+ gtk_window_set_title (priv->main_window, _("Software"));
/* update main buttons according to mode */
priv->ignore_primary_buttons = TRUE;
@@ -228,10 +234,10 @@ save_back_entry (GsShell *shell)
{
GsShellPrivate *priv = shell->priv;
BackEntry *entry;
- GtkWidget *window;
entry = g_new0 (BackEntry, 1);
entry->mode = priv->mode;
+ entry->focus = gtk_window_get_focus (priv->main_window);
if (priv->mode == GS_SHELL_MODE_CATEGORY) {
entry->category = gs_shell_category_get_category (priv->shell_category);
@@ -242,9 +248,6 @@ save_back_entry (GsShell *shell)
g_object_ref (entry->app);
}
- window = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- entry->focus = gtk_window_get_focus (GTK_WINDOW (window));
-
priv->back_entry_stack = g_slist_prepend (priv->back_entry_stack, entry);
}
@@ -456,11 +459,10 @@ window_key_press_event (GtkWidget *win, GdkEventKey *event, GsShell *shell)
/**
* gs_shell_setup:
*/
-GtkWindow *
+void
gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *cancellable)
{
GsShellPrivate *priv = shell->priv;
- GtkWidget *main_window = NULL;
GtkWidget *widget;
g_return_val_if_fail (GS_IS_SHELL (shell), NULL);
@@ -470,25 +472,24 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
/* get UI */
priv->builder = gtk_builder_new_from_resource ("/org/gnome/software/gnome-software.ui");
+ priv->main_window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
/* add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
GS_DATA G_DIR_SEPARATOR_S "icons");
- /* fix up the header bar */
- main_window = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
-
- g_signal_connect (main_window, "delete-event",
+ g_signal_connect (priv->main_window, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+ /* fix up the header bar */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "header"));
g_object_ref (widget);
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (widget)), widget);
- gtk_window_set_titlebar (GTK_WINDOW (main_window), widget);
+ gtk_window_set_titlebar (GTK_WINDOW (priv->main_window), widget);
g_object_unref (widget);
/* global keynav */
- g_signal_connect_after (main_window, "key_press_event",
+ g_signal_connect_after (priv->main_window, "key_press_event",
G_CALLBACK (window_key_press_event), shell);
/* setup buttons */
@@ -555,8 +556,7 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
g_signal_connect (GTK_EDITABLE (widget), "activate",
G_CALLBACK (gs_shell_search_activated_cb), shell);
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- g_signal_connect (widget, "key-press-event",
+ g_signal_connect (priv->main_window, "key-press-event",
G_CALLBACK (window_keypress_handler), shell);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
g_signal_connect (widget, "key-press-event",
@@ -567,9 +567,6 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
/* load content */
g_signal_connect (priv->shell_overview, "refreshed",
G_CALLBACK (initial_overview_load_done), shell);
-
- main_window = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- return GTK_WINDOW (main_window);
}
/**
@@ -609,7 +606,6 @@ gs_shell_get_installed_updates_cb (GsPluginLoader *plugin_loader,
GError *error = NULL;
GList *list;
GtkWidget *dialog;
- GtkWidget *toplevel;
/* get the results */
list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
@@ -628,9 +624,7 @@ gs_shell_get_installed_updates_cb (GsPluginLoader *plugin_loader,
dialog = gs_update_dialog_new ();
gs_update_dialog_show_installed_updates (GS_UPDATE_DIALOG (dialog), list);
- toplevel = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
-
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->main_window);
gtk_window_present (GTK_WINDOW (dialog));
out:
@@ -661,11 +655,8 @@ gs_shell_show_sources (GsShell *shell)
{
GsShellPrivate *priv = shell->priv;
GtkWidget *dialog;
- GtkWidget *toplevel;
-
- toplevel = GTK_WIDGET (gtk_builder_get_object (priv->builder, "window_software"));
- dialog = gs_sources_dialog_new (GTK_WINDOW (toplevel), priv->plugin_loader);
+ dialog = gs_sources_dialog_new (priv->main_window, priv->plugin_loader);
gtk_window_present (GTK_WINDOW (dialog));
}
diff --git a/src/gs-shell.h b/src/gs-shell.h
index c3959b0..035d60b 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -85,11 +85,12 @@ void gs_shell_show_filename (GsShell *shell,
void gs_shell_show_search_result (GsShell *shell,
const gchar *id,
const gchar *search);
-GtkWindow *gs_shell_setup (GsShell *shell,
+void gs_shell_setup (GsShell *shell,
GsPluginLoader *plugin_loader,
GCancellable *cancellable);
void gs_shell_invalidate (GsShell *shell);
gboolean gs_shell_is_active (GsShell *shell);
+GtkWindow *gs_shell_get_window (GsShell *shell);
G_END_DECLS
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 781f924..004d19b 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -147,13 +147,12 @@ gs_app_notify_installed (GsApp *app)
* gs_app_notify_failed_modal:
**/
void
-gs_app_notify_failed_modal (GtkBuilder *builder,
- GsApp *app,
+gs_app_notify_failed_modal (GsApp *app,
+ GtkWindow *parent_window,
GsPluginLoaderAction action,
const GError *error)
{
GtkWidget *dialog;
- GtkWindow *window;
gchar *title;
gchar *msg;
@@ -173,8 +172,7 @@ gs_app_notify_failed_modal (GtkBuilder *builder,
g_assert_not_reached ();
break;
}
- window = GTK_WINDOW (gtk_builder_get_object (builder, "window_software"));
- dialog = gtk_message_dialog_new (window,
+ dialog = gtk_message_dialog_new (parent_window,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
diff --git a/src/gs-utils.h b/src/gs-utils.h
index ecfdd84..cba1d48 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -35,8 +35,8 @@ void gs_container_remove_all (GtkContainer *container);
void gs_grab_focus_when_mapped (GtkWidget *widget);
void gs_app_notify_installed (GsApp *app);
-void gs_app_notify_failed_modal (GtkBuilder *builder,
- GsApp *app,
+void gs_app_notify_failed_modal (GsApp *app,
+ GtkWindow *parent_window,
GsPluginLoaderAction action,
const GError *error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]