[gnome-photos] Split out the code to create a GAppLaunchContext from a GtkWidget
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Split out the code to create a GAppLaunchContext from a GtkWidget
- Date: Thu, 18 Jan 2018 13:32:16 +0000 (UTC)
commit be89198c6240258bc95f9f094835df0f11786c0c
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Jan 18 13:35:56 2018 +0100
Split out the code to create a GAppLaunchContext from a GtkWidget
https://bugzilla.gnome.org/show_bug.cgi?id=759413
src/photos-empty-results-box.c | 17 ++++-------------
src/photos-source-notification.c | 17 ++++-------------
src/photos-utils.c | 29 +++++++++++++++++++++++++++++
src/photos-utils.h | 2 ++
4 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/src/photos-empty-results-box.c b/src/photos-empty-results-box.c
index 99656b74..14c557af 100644
--- a/src/photos-empty-results-box.c
+++ b/src/photos-empty-results-box.c
@@ -33,6 +33,7 @@
#include "photos-icons.h"
#include "photos-search-context.h"
#include "photos-source-manager.h"
+#include "photos-utils.h"
struct _PhotosEmptyResultsBox
@@ -57,9 +58,7 @@ static gboolean
photos_empty_results_box_activate_link (PhotosEmptyResultsBox *self, const gchar *uri)
{
g_autoptr (GAppInfo) app = NULL;
- g_autoptr (GdkAppLaunchContext) ctx = NULL;
- GdkDisplay *display;
- GdkScreen *screen;
+ g_autoptr (GAppLaunchContext) ctx = NULL;
gboolean ret_val = FALSE;
if (g_strcmp0 (uri, "system-settings") != 0)
@@ -79,20 +78,12 @@ photos_empty_results_box_activate_link (PhotosEmptyResultsBox *self, const gchar
}
}
- screen = gtk_widget_get_screen (GTK_WIDGET (self));
- if (screen != NULL)
- display = gdk_screen_get_display (screen);
- else
- display = gdk_display_get_default ();
-
- ctx = gdk_display_get_app_launch_context (display);
- if (screen != NULL)
- gdk_app_launch_context_set_screen (ctx, screen);
+ ctx = photos_utils_new_app_launch_context_from_widget (GTK_WIDGET (self));
{
g_autoptr (GError) error = NULL;
- g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+ g_app_info_launch (app, NULL, ctx, &error);
if (error != NULL)
{
g_warning ("Unable to launch gnome-control-center: %s", error->message);
diff --git a/src/photos-source-notification.c b/src/photos-source-notification.c
index 6d0d5416..d1229819 100644
--- a/src/photos-source-notification.c
+++ b/src/photos-source-notification.c
@@ -27,6 +27,7 @@
#include "photos-source-notification.h"
#include "photos-icons.h"
+#include "photos-utils.h"
struct _PhotosSourceNotification
@@ -64,9 +65,7 @@ static void
photos_source_notification_settings_clicked (PhotosSourceNotification *self)
{
g_autoptr (GAppInfo) app = NULL;
- g_autoptr (GdkAppLaunchContext) ctx = NULL;
- GdkDisplay *display;
- GdkScreen *screen;
+ g_autoptr (GAppLaunchContext) ctx = NULL;
GoaAccount *account;
GoaObject *object;
const gchar *id;
@@ -90,20 +89,12 @@ photos_source_notification_settings_clicked (PhotosSourceNotification *self)
}
}
- screen = gtk_widget_get_screen (GTK_WIDGET (self));
- if (screen != NULL)
- display = gdk_screen_get_display (screen);
- else
- display = gdk_display_get_default ();
-
- ctx = gdk_display_get_app_launch_context (display);
- if (screen != NULL)
- gdk_app_launch_context_set_screen (ctx, screen);
+ ctx = photos_utils_new_app_launch_context_from_widget (GTK_WIDGET (self));
{
g_autoptr (GError) error = NULL;
- g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+ g_app_info_launch (app, NULL, ctx, &error);
if (error != NULL)
{
g_warning ("Unable to launch gnome-control-center: %s", error->message);
diff --git a/src/photos-utils.c b/src/photos-utils.c
index e4609bec..44f92c38 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -30,6 +30,7 @@
#include <string.h>
+#include <gdk/gdk.h>
#include <glib.h>
#include <tracker-sparql.h>
#include <libgd/gd.h>
@@ -1274,6 +1275,34 @@ photos_utils_list_box_header_func (GtkListBoxRow *row, GtkListBoxRow *before, gp
}
+GAppLaunchContext *
+photos_utils_new_app_launch_context_from_widget (GtkWidget *widget)
+{
+ GAppLaunchContext *ret_val = NULL;
+ g_autoptr (GdkAppLaunchContext) ctx = NULL;
+ GdkDisplay *display;
+ GdkScreen *screen;
+
+ if (widget == NULL)
+ goto out;
+
+ screen = gtk_widget_get_screen (widget);
+ if (screen != NULL)
+ display = gdk_screen_get_display (screen);
+ else
+ display = gdk_display_get_default ();
+
+ ctx = gdk_display_get_app_launch_context (display);
+ if (screen != NULL)
+ gdk_app_launch_context_set_screen (ctx, screen);
+
+ ret_val = G_APP_LAUNCH_CONTEXT (g_steal_pointer (&ctx));
+
+ out:
+ return ret_val;
+}
+
+
void
photos_utils_object_list_free_full (GList *objects)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 0956f589..ca4f333d 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -172,6 +172,8 @@ void photos_utils_list_box_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data);
+GAppLaunchContext *photos_utils_new_app_launch_context_from_widget (GtkWidget *widget);
+
void photos_utils_object_list_free_full (GList *objects);
gchar *photos_utils_print_zoom_action_detailed_name (const gchar *action_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]