[epiphany] Add option to set browser as default
- From: Jan-Michael Brummer <jbrummer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add option to set browser as default
- Date: Sun, 14 Apr 2019 09:01:32 +0000 (UTC)
commit 5420beedc39e4e46b6fac71302bb6b3acc80b794
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Sat Apr 13 15:51:32 2019 +0200
Add option to set browser as default
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/112
data/org.gnome.epiphany.gschema.xml | 5 ++
lib/ephy-prefs.h | 1 +
src/ephy-window.c | 101 ++++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 0f0c22534..8a6b622c0 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -60,6 +60,11 @@
<summary>List of adblock filters</summary>
<description>List of URLs with filter rules to be used by the adblock.</description>
</key>
+ <key type="b" name="ask-for-default">
+ <default>true</default>
+ <summary>Whether to ask for setting browser as default</summary>
+ <description>When this option is set to true, browser will ask for being default if
it is not already set.</description>
+ </key>
</schema>
<schema path="/org/gnome/epiphany/ui/" id="org.gnome.Epiphany.ui">
<key type="b" name="expand-tabs-bar">
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index d661f62eb..b134957ac 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -170,6 +170,7 @@ static const char * const ephy_prefs_web_schema[] = {
#define EPHY_PREFS_ADBLOCK_FILTERS "adblock-filters"
#define EPHY_PREFS_SEARCH_ENGINES "search-engines"
#define EPHY_PREFS_DEFAULT_SEARCH_ENGINE "default-search-engine"
+#define EPHY_PREFS_ASK_FOR_DEFAULT "ask-for-default"
#define EPHY_PREFS_LOCKDOWN_SCHEMA "org.gnome.Epiphany.lockdown"
#define EPHY_PREFS_LOCKDOWN_FULLSCREEN "disable-fullscreen"
diff --git a/src/ephy-window.c b/src/ephy-window.c
index bde4ff6f3..f5934d752 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -3369,6 +3369,101 @@ browse_with_caret_get_mapping (GValue *value,
return TRUE;
}
+static
+const gchar *supported_mime_types[] = {
+ "x-scheme-handler/http",
+ "x-scheme-handler/https",
+ "text/html",
+ "application/xhtml+xml",
+ NULL
+};
+
+static void
+set_as_default_browser ()
+{
+ g_autoptr(GError) error = NULL;
+ GDesktopAppInfo *desktop_info;
+ GAppInfo *info = NULL;
+ g_autofree gchar *id = g_strconcat (APPLICATION_ID, ".desktop", NULL);
+ int i;
+
+ desktop_info = g_desktop_app_info_new (id);
+ if (!desktop_info)
+ return;
+
+ info = G_APP_INFO (desktop_info);
+
+ for (i = 0; supported_mime_types[i]; i++) {
+ if (!g_app_info_set_as_default_for_type (info, supported_mime_types[i], &error))
+ g_warning ("Failed to set '%s' as the default application for secondary content type '%s': %s",
+ g_app_info_get_name (info), supported_mime_types[i], error->message);
+ else
+ LOG ("Set '%s' as the default application for '%s'",
+ g_app_info_get_name (info),
+ supported_mime_types[i]);
+ }
+}
+
+static void
+on_default_browser_question_response (GtkInfoBar *info_bar,
+ gint response_id,
+ gpointer user_data)
+{
+ if (response_id == GTK_RESPONSE_YES)
+ set_as_default_browser ();
+ else if (response_id == GTK_RESPONSE_NO)
+ g_settings_set_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_ASK_FOR_DEFAULT, FALSE);
+
+ gtk_widget_destroy (GTK_WIDGET (info_bar));
+}
+
+static void
+add_default_browser_question (GtkBox *box)
+{
+ GtkWidget *label;
+ GtkWidget *info_bar;
+ GtkWidget *content_area;
+
+#if !TECH_PREVIEW
+ label = gtk_label_new (_("Set Web as your default browser?"));
+#else
+ label = gtk_label_new (_("Set Epiphany Technology Preview as your default browser?"));
+#endif
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_widget_show (label);
+
+ info_bar = gtk_info_bar_new ();
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_QUESTION);
+ gtk_info_bar_set_show_close_button (GTK_INFO_BAR (info_bar), TRUE);
+
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
+ gtk_container_add (GTK_CONTAINER (content_area), label);
+
+ gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), _("_Yes"), GTK_RESPONSE_YES);
+ gtk_info_bar_add_button (GTK_INFO_BAR (info_bar), _("_No"), GTK_RESPONSE_NO);
+
+ g_signal_connect (info_bar, "response", G_CALLBACK (on_default_browser_question_response), NULL);
+
+ gtk_box_pack_start (box, info_bar, FALSE, FALSE, 0);
+
+ gtk_widget_show (info_bar);
+}
+
+static gboolean
+is_browser_default (void)
+{
+ g_autoptr(GAppInfo) info = g_app_info_get_default_for_type (supported_mime_types[0], TRUE);
+
+ if (info) {
+ g_autofree gchar *id = g_strconcat (APPLICATION_ID, ".desktop", NULL);
+
+ if (!strcmp (g_app_info_get_id (info), id))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
ephy_window_constructed (GObject *object)
{
@@ -3468,6 +3563,12 @@ ephy_window_constructed (GObject *object)
window->location_controller = setup_location_controller (window, EPHY_HEADER_BAR (window->header_bar));
window->action_bar = setup_action_bar (window);
box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
+
+ if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_ASK_FOR_DEFAULT) &&
+ !is_browser_default () &&
+ !ephy_profile_dir_is_web_application ())
+ add_default_browser_question (box);
+
gtk_box_pack_start (box, GTK_WIDGET (window->notebook), TRUE, TRUE, 0);
gtk_box_pack_start (box, GTK_WIDGET (window->action_bar), FALSE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (box));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]