[gnome-control-center/wip/gbsneto/split-info-panel: 1/2] default-apps: introduce Default Applications panel
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/split-info-panel: 1/2] default-apps: introduce Default Applications panel
- Date: Wed, 3 Aug 2016 11:48:38 +0000 (UTC)
commit 051820d674beccce2b8792d4f730a952bf9690c8
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Aug 2 23:27:23 2016 -0300
default-apps: introduce Default Applications panel
The recent move to the new Shell layout with a sidebar forces
us to relayout all the panels that also use a sidebar. One of
these panels is the Details panel.
The first step to move the Details panel away from the sidebar
is moving the Default Applications page to a new, dedicate panel.
This patch introduces the new Default Applications panel.
configure.ac | 4 +
panels/Makefile.am | 1 +
panels/default-apps/Makefile.am | 39 ++++
panels/default-apps/cc-default-apps-panel.c | 228 ++++++++++++++++++++
panels/default-apps/cc-default-apps-panel.h | 35 +++
panels/default-apps/default-apps.gresource.xml | 6 +
panels/default-apps/default-apps.ui | 179 +++++++++++++++
.../gnome-default-apps-panel.desktop.in.in | 20 ++
shell/Makefile.am | 1 +
shell/cc-panel-loader.c | 2 +
10 files changed, 515 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3f4e113..7f38875 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,6 +127,8 @@ PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES
gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
+PKG_CHECK_MODULES(DEFAULT_APPS_PANEL, $COMMON_MODULES libgtop-2.0
+ polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES gnome-desktop-3.0 >= 3.1.0
upower-glib >= 0.99.0)
PKG_CHECK_MODULES(INFO_PANEL, $COMMON_MODULES libgtop-2.0
@@ -453,6 +455,8 @@ panels/bluetooth/gnome-bluetooth-panel.desktop.in
panels/datetime/Makefile
panels/datetime/gnome-datetime-panel.desktop.in
panels/datetime/po-timezones/Makefile
+panels/default-apps/Makefile
+panels/default-apps/gnome-default-apps-panel.desktop.in
panels/display/Makefile
panels/display/gnome-display-panel.desktop.in
panels/keyboard/Makefile
diff --git a/panels/Makefile.am b/panels/Makefile.am
index 9961c25..1e4b0fb 100644
--- a/panels/Makefile.am
+++ b/panels/Makefile.am
@@ -3,6 +3,7 @@ SUBDIRS= \
background \
power \
color \
+ default-apps \
display \
mouse \
notifications \
diff --git a/panels/default-apps/Makefile.am b/panels/default-apps/Makefile.am
new file mode 100644
index 0000000..0f92854
--- /dev/null
+++ b/panels/default-apps/Makefile.am
@@ -0,0 +1,39 @@
+cappletname = default-apps
+
+AM_CPPFLAGS = \
+ $(PANEL_CFLAGS) \
+ $(DEFAULT_APPS_PANEL_CFLAGS) \
+ -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
+ -DDATADIR="\"$(datadir)\"" \
+ -DBINDIR="\"$(bindir)\"" \
+ $(NULL)
+
+noinst_LTLIBRARIES = libdefault-apps.la
+
+BUILT_SOURCES = \
+ cc-default-apps-resources.c \
+ cc-default-apps-resources.h
+
+libdefault_apps_la_SOURCES = \
+ $(BUILT_SOURCES) \
+ cc-default-apps-panel.c \
+ cc-default-apps-panel.h
+
+libdefault_apps_la_LIBADD = $(PANEL_LIBS) $(DEFAULT_APPS_PANEL_CFLAGS)
+
+resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies
$(srcdir)/default-apps.gresource.xml)
+cc-default-apps-resources.c: default-apps.gresource.xml $(resource_files)
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name
cc_default_apps $<
+cc-default-apps-resources.h: default-apps.gresource.xml $(resource_files)
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name
cc_default_apps $<
+
+@INTLTOOL_DESKTOP_RULE@
+
+desktopdir = $(datadir)/applications
+desktop_in_files = gnome-default-apps-panel.desktop.in
+desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+
+CLEANFILES = $(desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES)
+EXTRA_DIST = $(resource_files) default-apps.gresource.xml
+
+-include $(top_srcdir)/git.mk
diff --git a/panels/default-apps/cc-default-apps-panel.c b/panels/default-apps/cc-default-apps-panel.c
new file mode 100644
index 0000000..fe30291
--- /dev/null
+++ b/panels/default-apps/cc-default-apps-panel.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2008 William Jon McCann <jmccann redhat com>
+ * 2010 Red Hat, Inc
+ * 2016 Endless, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "cc-default-apps-resources.h"
+
+#include "cc-default-apps-panel.h"
+
+struct _CcDefaultAppsPanel
+{
+ CcPanel parent;
+
+ GtkWidget *calendar_label;
+ GtkWidget *default_apps_grid;
+ GtkWidget *mail_label;
+ GtkWidget *music_label;
+ GtkWidget *photos_label;
+ GtkWidget *video_label;
+ GtkWidget *web_label;
+};
+
+CC_PANEL_REGISTER (CcDefaultAppsPanel, cc_default_apps_panel)
+
+enum {
+ PROP_0,
+ PROP_PARAMETERS,
+ N_PROPS
+};
+
+#define OFFSET(x) (G_STRUCT_OFFSET (CcDefaultAppsPanel, x))
+#define WIDGET_FROM_DATA(self,data) (G_STRUCT_MEMBER (GtkWidget*, self, data->offset))
+
+typedef struct
+{
+ const char *content_type;
+ const gint offset;
+ /* A pattern used to filter supported mime types
+ when changing preferred applications. NULL
+ means no other types should be changed */
+ const char *extra_type_filter;
+} DefaultAppData;
+
+static DefaultAppData preferred_app_infos[] = {
+ /* for web, we need to support text/html,
+ application/xhtml+xml and x-scheme-handler/https,
+ hence the "*" pattern
+ */
+ { "x-scheme-handler/http", OFFSET (web_label), "*" },
+ { "x-scheme-handler/mailto", OFFSET (mail_label), NULL },
+ { "text/calendar", OFFSET (calendar_label), NULL },
+ { "audio/x-vorbis+ogg", OFFSET (music_label), "audio/*" },
+ { "video/x-ogm+ogg", OFFSET (video_label), "video/*" },
+ { "image/jpeg", OFFSET (photos_label), "image/*" }
+};
+
+static void
+default_app_changed (GtkAppChooserButton *button,
+ CcDefaultAppsPanel *self)
+{
+ DefaultAppData *app_data;
+ GError *error;
+ GAppInfo *info;
+ int i;
+
+ error = NULL;
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (button));
+ app_data = g_object_get_data (G_OBJECT (button), "default-app-data");
+
+ if (g_app_info_set_as_default_for_type (info, app_data->content_type, &error) == FALSE)
+ {
+ g_warning ("Failed to set '%s' as the default application for '%s': %s",
+ g_app_info_get_name (info), app_data->content_type, error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ {
+ g_debug ("Set '%s' as the default handler for '%s'",
+ g_app_info_get_name (info), app_data->content_type);
+ }
+
+ if (app_data->extra_type_filter)
+ {
+ const char *const *mime_types;
+ GPatternSpec *pattern;
+
+ pattern = g_pattern_spec_new (app_data->extra_type_filter);
+ mime_types = g_app_info_get_supported_types (info);
+
+ for (i = 0; mime_types && mime_types[i]; i++)
+ {
+ if (!g_pattern_match_string (pattern, mime_types[i]))
+ continue;
+
+ if (g_app_info_set_as_default_for_type (info, mime_types[i], &error) == FALSE)
+ {
+ g_warning ("Failed to set '%s' as the default application for secondary "
+ "content type '%s': %s",
+ g_app_info_get_name (info), mime_types[i], error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_debug ("Set '%s' as the default handler for '%s'",
+ g_app_info_get_name (info), mime_types[i]);
+ }
+ }
+
+ g_pattern_spec_free (pattern);
+ }
+
+ g_object_unref (info);
+}
+
+static void
+setup_default_app (CcDefaultAppsPanel *self,
+ DefaultAppData *data,
+ guint left_attach,
+ guint top_attach)
+{
+ GtkWidget *button;
+ GtkWidget *grid;
+ GtkWidget *label;
+
+ grid = self->default_apps_grid;
+
+ button = gtk_app_chooser_button_new (data->content_type);
+ g_object_set_data (G_OBJECT (button), "default-app-data", data);
+
+ gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (button), TRUE);
+ gtk_grid_attach (GTK_GRID (grid),
+ button,
+ left_attach,
+ top_attach,
+ 1, 1);
+
+ g_signal_connect (G_OBJECT (button),
+ "changed",
+ G_CALLBACK (default_app_changed),
+ self);
+
+ gtk_widget_show (button);
+
+ label = WIDGET_FROM_DATA (self, data);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
+}
+
+static void
+setup_default_apps (CcDefaultAppsPanel *self)
+{
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (preferred_app_infos); i++)
+ setup_default_app (self, &preferred_app_infos[i], 1, i);
+}
+
+static void
+cc_default_apps_panel_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+cc_default_apps_panel_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_PARAMETERS:
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+cc_default_apps_panel_class_init (CcDefaultAppsPanelClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = cc_default_apps_panel_get_property;
+ object_class->set_property = cc_default_apps_panel_set_property;
+
+ g_object_class_override_property (object_class, PROP_PARAMETERS, "parameters");
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/default-apps/default-apps.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, calendar_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, default_apps_grid);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, mail_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, music_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, photos_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, video_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, web_label);
+}
+
+static void
+cc_default_apps_panel_init (CcDefaultAppsPanel *self)
+{
+ g_resources_register (cc_default_apps_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ setup_default_apps (self);
+}
diff --git a/panels/default-apps/cc-default-apps-panel.h b/panels/default-apps/cc-default-apps-panel.h
new file mode 100644
index 0000000..5431323
--- /dev/null
+++ b/panels/default-apps/cc-default-apps-panel.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Endless, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Georges Basile Stavracas Neto <gbsneto gnome org>
+ *
+ */
+
+#ifndef CC_DEFAULT_APPS_PANEL_H
+#define CC_DEFAULT_APPS_PANEL_H
+
+#include <shell/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_DEFAULT_APPS_PANEL (cc_default_apps_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (CcDefaultAppsPanel, cc_default_apps_panel, CC, DEFAULT_APPS_PANEL, CcPanel)
+
+G_END_DECLS
+
+#endif /* CC_DEFAULT_APPS_PANEL_H */
+
diff --git a/panels/default-apps/default-apps.gresource.xml b/panels/default-apps/default-apps.gresource.xml
new file mode 100644
index 0000000..23a2bb6
--- /dev/null
+++ b/panels/default-apps/default-apps.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/control-center/default-apps">
+ <file preprocess="xml-stripblanks">default-apps.ui</file>
+ </gresource>
+</gresources>
diff --git a/panels/default-apps/default-apps.ui b/panels/default-apps/default-apps.ui
new file mode 100644
index 0000000..c4632fb
--- /dev/null
+++ b/panels/default-apps/default-apps.ui
@@ -0,0 +1,179 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <template class="CcDefaultAppsPanel" parent="CcPanel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkGrid" id="default_apps_grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <property name="border_width">24</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="web_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Web</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="mail_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Mail</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="calendar_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Calendar</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="music_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">M_usic</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="video_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Video</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">4</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label25">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label26">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label27">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label28">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label29">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="photos_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Photos</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">5</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label33">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">5</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/default-apps/gnome-default-apps-panel.desktop.in.in
b/panels/default-apps/gnome-default-apps-panel.desktop.in.in
new file mode 100644
index 0000000..3a0ffd2
--- /dev/null
+++ b/panels/default-apps/gnome-default-apps-panel.desktop.in.in
@@ -0,0 +1,20 @@
+[Desktop Entry]
+# Translators: Add soft hyphens to your translations so that the icon view won't clip your translations. See
https://bugzilla.gnome.org/show_bug.cgi?id=647087#c13 for details
+_Name=Default Applications
+_Comment=Manage the default applications of your system
+Exec=gnome-control-center default-apps
+Icon=application-x-executable
+Terminal=false
+Type=Application
+NoDisplay=true
+StartupNotify=true
+Categories=GNOME;GTK;Settings;X-GNOME-SystemSettings;X-GNOME-Settings-Panel;X-GNOME-DetailsSettings;
+OnlyShowIn=GNOME;Unity;
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-control-center
+X-GNOME-Bugzilla-Component=info
+X-GNOME-Bugzilla-Version=@VERSION@
+# Translators: those are keywords for the System Information panel
+# "Preferred Applications" is the old name for the preference, so make
+# sure that you use the same "translation" for those keywords
+_Keywords=default;application;preferred;
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 45f6363..34adcb6 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -80,6 +80,7 @@ gnome_control_center_LDADD = \
$(top_builddir)/panels/background/libbackground.la \
$(top_builddir)/panels/color/libcolor.la \
$(top_builddir)/panels/datetime/libdate_time.la \
+ $(top_builddir)/panels/default-apps/libdefault-apps.la \
$(top_builddir)/panels/display/libdisplay.la \
$(top_builddir)/panels/info/libinfo.la \
$(top_builddir)/panels/keyboard/libkeyboard.la \
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index 03dbfb1..33a7feb 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -35,6 +35,7 @@ extern GType cc_bluetooth_panel_get_type (void);
#endif /* BUILD_BLUETOOTH */
extern GType cc_color_panel_get_type (void);
extern GType cc_date_time_panel_get_type (void);
+extern GType cc_default_apps_panel_get_type (void);
extern GType cc_display_panel_get_type (void);
extern GType cc_info_panel_get_type (void);
extern GType cc_keyboard_panel_get_type (void);
@@ -79,6 +80,7 @@ static struct {
#endif
PANEL_TYPE("color", cc_color_panel_get_type ),
PANEL_TYPE("datetime", cc_date_time_panel_get_type ),
+ PANEL_TYPE("default-apps", cc_default_apps_panel_get_type ),
PANEL_TYPE("display", cc_display_panel_get_type ),
PANEL_TYPE("info", cc_info_panel_get_type ),
PANEL_TYPE("keyboard", cc_keyboard_panel_get_type ),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]