[gnome-software/wip/launcher: 5/7] Start up in true service mode
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/launcher: 5/7] Start up in true service mode
- Date: Mon, 16 Sep 2013 02:29:06 +0000 (UTC)
commit a9cae306dab3d5a52ad4a9a1e4f51506d94f4177
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 15 20:59:04 2013 -0400
Start up in true service mode
Only initialize the UI when we have been activated.
Merely starting the service process should not show
a window.
In the future, we will monitor for available updates
in the service process, and keep the service process
alive for that, but for now, it will exit after the
10 second grace period that GApplication provides for
services.
src/gs-application.c | 165 +++++++++++++++++++++++++++++---------------------
1 files changed, 97 insertions(+), 68 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 8d547c7..e35f8a4 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -57,6 +57,82 @@ gs_application_init (GsApplication *application)
}
static void
+gs_application_initialize_ui (GsApplication *app)
+{
+ static gboolean initialized = FALSE;
+ GtkBuilder *builder;
+ GMenuModel *app_menu;
+ GtkWindow *window;
+ GFile *file;
+ GError *error = NULL;
+
+ if (initialized)
+ return;
+
+ initialized = TRUE;
+
+ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+ DATADIR "/gnome-software/icons/hicolor");
+
+ /* set up the app menu */
+ builder = gtk_builder_new_from_resource ("/org/gnome/software/app-menu.ui");
+ app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
+ g_object_unref (builder);
+
+ /* get CSS */
+ app->provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (app->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ file = g_file_new_for_uri ("resource:///org/gnome/software/gtk-style.css");
+ gtk_css_provider_load_from_file (app->provider, file, NULL);
+ g_object_unref (file);
+
+ /* setup pk */
+ app->task = pk_task_new ();
+ g_object_set (app->task, "background", FALSE, NULL);
+
+ /* setup plugins */
+ app->plugin_loader = gs_plugin_loader_new ();
+ gs_plugin_loader_set_location (app->plugin_loader, NULL);
+ if (!gs_plugin_loader_setup (app->plugin_loader, &error)) {
+ g_warning ("Failed to setup plugins: %s", error->message);
+ exit (1);
+ }
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-featured", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-kind", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-popular", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-ratings", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-screenshots", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-menu-spec", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "local-ratings", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-refine", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-history", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-offline", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "appstream", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "desktopdb", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-apps", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename", TRUE);
+ gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename-local", TRUE);
+
+ /* show the priority of each plugin */
+ gs_plugin_loader_dump_state (app->plugin_loader);
+
+ /* setup UI */
+ app->shell = gs_shell_new ();
+
+ app->cancellable = g_cancellable_new ();
+
+ window = gs_shell_setup (app->shell, app->plugin_loader, app->cancellable);
+ gtk_application_add_window (GTK_APPLICATION (app), window);
+
+ g_signal_connect_swapped (app->shell, "loaded",
+ G_CALLBACK (gtk_window_present), window);
+}
+
+static void
about_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
@@ -75,6 +151,8 @@ about_activated (GSimpleAction *action,
GList *windows;
GtkWindow *parent = NULL;
+ gs_application_initialize_ui (app);
+
windows = gtk_application_get_windows (GTK_APPLICATION (app));
if (windows)
parent = windows->data;
@@ -105,7 +183,14 @@ quit_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
- g_application_quit (G_APPLICATION (app));
+ GList *windows;
+ GtkWidget *window;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ if (windows) {
+ window = windows->data;
+ gtk_widget_hide (window);
+ }
}
static void
@@ -115,6 +200,15 @@ set_mode_activated (GSimpleAction *action,
{
GsApplication *app = GS_APPLICATION (data);
const gchar *mode;
+ GList *windows;
+ GtkWindow *window = NULL;
+
+ gs_application_initialize_ui (app);
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ if (windows) {
+ window = windows->data;
+ gtk_window_present (window);
+ }
mode = g_variant_get_string (parameter, NULL);
if (g_strcmp0 (mode, "updates") == 0) {
@@ -139,81 +233,15 @@ static GActionEntry actions[] = {
static void
gs_application_startup (GApplication *application)
{
- GsApplication *app = GS_APPLICATION (application);
- GtkBuilder *builder;
- GMenuModel *app_menu;
- GtkWindow *window;
- GFile *file;
- GError *error = NULL;
-
G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
notify_init ("gnome-software");
g_type_ensure (GS_TYPE_BOX);
- gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
- DATADIR "/gnome-software/icons/hicolor");
-
- /* set up the app menu */
- g_action_map_add_action_entries (G_ACTION_MAP (app),
+ g_action_map_add_action_entries (G_ACTION_MAP (application),
actions, G_N_ELEMENTS (actions),
application);
- builder = gtk_builder_new_from_resource ("/org/gnome/software/app-menu.ui");
- app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
- gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
- g_object_unref (builder);
-
- /* get CSS */
- app->provider = gtk_css_provider_new ();
- gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
- GTK_STYLE_PROVIDER (app->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- file = g_file_new_for_uri ("resource:///org/gnome/software/gtk-style.css");
- gtk_css_provider_load_from_file (app->provider, file, NULL);
- g_object_unref (file);
-
- /* setup pk */
- app->task = pk_task_new ();
- g_object_set (app->task, "background", FALSE, NULL);
-
- /* setup plugins */
- app->plugin_loader = gs_plugin_loader_new ();
- gs_plugin_loader_set_location (app->plugin_loader, NULL);
- if (!gs_plugin_loader_setup (app->plugin_loader, &error)) {
- g_warning ("Failed to setup plugins: %s", error->message);
- exit (1);
- }
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-featured", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-kind", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-popular", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-ratings", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-screenshots", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-menu-spec", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "local-ratings", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-refine", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-history", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-offline", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "appstream", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "desktopdb", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-apps", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename", TRUE);
- gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-filename-local", TRUE);
-
- /* show the priority of each plugin */
- gs_plugin_loader_dump_state (app->plugin_loader);
-
- /* setup UI */
- app->shell = gs_shell_new ();
-
- app->cancellable = g_cancellable_new ();
-
- window = gs_shell_setup (app->shell, app->plugin_loader, app->cancellable);
- gtk_application_add_window (GTK_APPLICATION (app), window);
-
- g_signal_connect_swapped (app->shell, "loaded",
- G_CALLBACK (gtk_window_present), window);
}
static void
@@ -250,6 +278,7 @@ gs_application_finalize (GObject *object)
g_clear_object (&app->cancellable);
g_clear_object (&app->shell);
g_clear_object (&app->provider);
+
G_OBJECT_CLASS (gs_application_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]