diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:45:20 +0000 |
commit | ae1c76ff830d146d41e88d6fba724c0a54bce868 (patch) | |
tree | 3c354bec95af07be35fc71a4b738268496f1a1c4 /panels/default-apps | |
parent | Initial commit. (diff) | |
download | gnome-control-center-ae1c76ff830d146d41e88d6fba724c0a54bce868.tar.xz gnome-control-center-ae1c76ff830d146d41e88d6fba724c0a54bce868.zip |
Adding upstream version 1:43.6.upstream/1%43.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/default-apps')
-rw-r--r-- | panels/default-apps/cc-default-apps-panel.c | 198 | ||||
-rw-r--r-- | panels/default-apps/cc-default-apps-panel.h | 31 | ||||
-rw-r--r-- | panels/default-apps/cc-default-apps-panel.ui | 159 | ||||
-rw-r--r-- | panels/default-apps/default-apps.gresource.xml | 6 | ||||
-rw-r--r-- | panels/default-apps/gnome-default-apps-panel.desktop.in.in | 18 | ||||
-rw-r--r-- | panels/default-apps/icons/meson.build | 4 | ||||
-rw-r--r-- | panels/default-apps/icons/scalable/org.gnome.Settings-default-apps-symbolic.svg | 4 | ||||
-rw-r--r-- | panels/default-apps/meson.build | 43 |
8 files changed, 463 insertions, 0 deletions
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..5949fab --- /dev/null +++ b/panels/default-apps/cc-default-apps-panel.c @@ -0,0 +1,198 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2017 Mohammed Sadiq <sadiq@sadiqpk.org> + * Copyright (C) 2010 Red Hat, Inc + * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com> + * + * 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 <config.h> + +#include "cc-default-apps-panel.h" +#include "cc-default-apps-resources.h" + +typedef struct +{ + const char *content_type; + gint label_offset; + /* Patterns used to filter supported mime types + when changing preferred applications. NULL + means no other types should be changed */ + const char *extra_type_filter; +} DefaultAppData; + +struct _CcDefaultAppsPanel +{ + CcPanel parent_instance; + + GtkWidget *default_apps_grid; + + GtkWidget *web_label; + GtkWidget *mail_label; + GtkWidget *calendar_label; + GtkWidget *music_label; + GtkWidget *video_label; + GtkWidget *photos_label; +}; + + +G_DEFINE_TYPE (CcDefaultAppsPanel, cc_default_apps_panel, CC_TYPE_PANEL) + +static void +default_app_changed (CcDefaultAppsPanel *self, + GtkAppChooserButton *button) +{ + g_autoptr(GAppInfo) info = NULL; + g_autoptr(GError) error = NULL; + DefaultAppData *app_data; + int i; + + info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (button)); + app_data = g_object_get_data (G_OBJECT (button), "cc-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); + } + 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) + { + g_auto(GStrv) entries = NULL; + const char *const *mime_types; + g_autoptr(GPtrArray) patterns = NULL; + + entries = g_strsplit (app_data->extra_type_filter, ";", -1); + patterns = g_ptr_array_new_with_free_func ((GDestroyNotify) g_pattern_spec_free); + for (i = 0; entries[i] != NULL; i++) + { + GPatternSpec *pattern = g_pattern_spec_new (entries[i]); + g_ptr_array_add (patterns, pattern); + } + + mime_types = g_app_info_get_supported_types (info); + for (i = 0; mime_types && mime_types[i]; i++) + { + int j; + gboolean matched = FALSE; + g_autoptr(GError) local_error = NULL; + + for (j = 0; j < patterns->len; j++) + { + GPatternSpec *pattern = g_ptr_array_index (patterns, j); + if (g_pattern_spec_match_string (pattern, mime_types[i])) + matched = TRUE; + } + if (!matched) + continue; + + if (g_app_info_set_as_default_for_type (info, mime_types[i], &local_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], local_error->message); + } + else + { + g_debug ("Set '%s' as the default handler for '%s'", + g_app_info_get_name (info), mime_types[i]); + } + } + } +} + +#define OFFSET(x) (G_STRUCT_OFFSET (CcDefaultAppsPanel, x)) +#define WIDGET_FROM_OFFSET(x) (G_STRUCT_MEMBER (GtkWidget*, self, x)) + +static void +info_panel_setup_default_app (CcDefaultAppsPanel *self, + DefaultAppData *data, + guint left_attach, + guint top_attach) +{ + GtkWidget *button; + GtkWidget *label; + + button = gtk_app_chooser_button_new (data->content_type); + g_object_set_data (G_OBJECT (button), "cc-default-app-data", data); + + gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (button), TRUE); + gtk_grid_attach (GTK_GRID (self->default_apps_grid), button, left_attach, top_attach, + 1, 1); + g_signal_connect_object (G_OBJECT (button), "changed", + G_CALLBACK (default_app_changed), self, G_CONNECT_SWAPPED); + + label = WIDGET_FROM_OFFSET (data->label_offset); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), button); +} + +static DefaultAppData preferred_app_infos[] = { + { "x-scheme-handler/http", OFFSET (web_label), "text/html;application/xhtml+xml;x-scheme-handler/https" }, + { "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 +info_panel_setup_default_apps (CcDefaultAppsPanel *self) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (preferred_app_infos); i++) + { + info_panel_setup_default_app (self, &preferred_app_infos[i], + 1, i); + } +} + +static void +cc_default_apps_panel_class_init (CcDefaultAppsPanelClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/default-apps/cc-default-apps-panel.ui"); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, default_apps_grid); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, web_label); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, mail_label); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, calendar_label); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, music_label); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, video_label); + gtk_widget_class_bind_template_child (widget_class, CcDefaultAppsPanel, photos_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)); + + info_panel_setup_default_apps (self); +} + +GtkWidget * +cc_default_apps_panel_new (void) +{ + return g_object_new (CC_TYPE_DEFAULT_APPS_PANEL, + NULL); +} 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..4aca17b --- /dev/null +++ b/panels/default-apps/cc-default-apps-panel.h @@ -0,0 +1,31 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2017 Mohammed Sadiq <sadiq@sadiqpk.org> + * + * 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/>. + * + */ + +#pragma once + +#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) + +GtkWidget *cc_default_apps_panel_new (void); + +G_END_DECLS diff --git a/panels/default-apps/cc-default-apps-panel.ui b/panels/default-apps/cc-default-apps-panel.ui new file mode 100644 index 0000000..ac8db76 --- /dev/null +++ b/panels/default-apps/cc-default-apps-panel.ui @@ -0,0 +1,159 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <template class="CcDefaultAppsPanel" parent="CcPanel"> + <child type="content"> + <object class="GtkBox"> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="margin_top">32</property> + <property name="margin_bottom">32</property> + <property name="margin_start">24</property> + <property name="margin_end">24</property> + <property name="halign">center</property> + <property name="valign">start</property> + <property name="spacing">10</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkGrid" id="default_apps_grid"> + <property name="column_spacing">12</property> + <property name="row_spacing">12</property> + <child> + <object class="GtkLabel" id="web_label"> + <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="xalign">1</property> + <property name="label" translatable="yes">_Mail</property> + <property name="use_underline">True</property> + <layout> + <property name="row">1</property> + <property name="column">0</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="calendar_label"> + <property name="xalign">1</property> + <property name="label" translatable="yes">_Calendar</property> + <property name="use_underline">True</property> + <layout> + <property name="row">2</property> + <property name="column">0</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="music_label"> + <property name="xalign">1</property> + <property name="label" translatable="yes">M_usic</property> + <property name="use_underline">True</property> + <layout> + <property name="row">3</property> + <property name="column">0</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="video_label"> + <property name="xalign">1</property> + <property name="label" translatable="yes">_Video</property> + <property name="use_underline">True</property> + <layout> + <property name="row">4</property> + <property name="column">0</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="label25"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">0</property> + </layout> + </object> + </child> + <child> + <object class="GtkLabel" id="label26"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">1</property> + </layout> + </object> + </child> + <child> + <object class="GtkLabel" id="label27"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">2</property> + </layout> + </object> + </child> + <child> + <object class="GtkLabel" id="label28"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">3</property> + </layout> + </object> + </child> + <child> + <object class="GtkLabel" id="label29"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">4</property> + </layout> + </object> + </child> + <child> + <object class="GtkLabel" id="photos_label"> + <property name="xalign">1</property> + <property name="label" translatable="yes">_Photos</property> + <property name="use_underline">True</property> + <layout> + <property name="row">5</property> + <property name="column">0</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="label33"> + <property name="label"> </property> + <layout> + <property name="column">2</property> + <property name="row">5</property> + </layout> + </object> + </child> + </object> + </child> + </object> + </child> + </template> +</interface> diff --git a/panels/default-apps/default-apps.gresource.xml b/panels/default-apps/default-apps.gresource.xml new file mode 100644 index 0000000..a2029e7 --- /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">cc-default-apps-panel.ui</file> + </gresource> +</gresources> 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..f03c3ee --- /dev/null +++ b/panels/default-apps/gnome-default-apps-panel.desktop.in.in @@ -0,0 +1,18 @@ +[Desktop Entry] +Name=Default Applications +Comment=Configure Default Applications +Exec=gnome-control-center default-apps +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=org.gnome.Settings-default-apps-symbolic +Terminal=false +Type=Application +NoDisplay=true +StartupNotify=true +Categories=GNOME;GTK;Settings;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: Search terms to find the Default Applications panel. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +Keywords=default;application;preferred;media; diff --git a/panels/default-apps/icons/meson.build b/panels/default-apps/icons/meson.build new file mode 100644 index 0000000..0e9b7ff --- /dev/null +++ b/panels/default-apps/icons/meson.build @@ -0,0 +1,4 @@ +install_data( + 'scalable/org.gnome.Settings-default-apps-symbolic.svg', + install_dir: join_paths(control_center_icondir, 'hicolor', 'scalable', 'apps') +) diff --git a/panels/default-apps/icons/scalable/org.gnome.Settings-default-apps-symbolic.svg b/panels/default-apps/icons/scalable/org.gnome.Settings-default-apps-symbolic.svg new file mode 100644 index 0000000..2dd3fd4 --- /dev/null +++ b/panels/default-apps/icons/scalable/org.gnome.Settings-default-apps-symbolic.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg height="16px" viewBox="0 0 16 16" width="16px" xmlns="http://www.w3.org/2000/svg"> + <path d="m 7.988281 0.0078125 c -0.429687 0 -0.8125 0.2734375 -0.949219 0.6835935 l -1.449218 4.339844 l -4.589844 -0.015625 c -0.9804688 -0.003906 -1.382812 1.257813 -0.582031 1.820313 l 3.625 2.554687 l -1.5 4.285156 c -0.316407 0.902344 0.6875 1.691407 1.492187 1.171875 l 4.003906 -2.59375 l 3.894532 2.585938 c 0.800781 0.53125 1.816406 -0.257813 1.5 -1.160156 l -1.503906 -4.289063 l 3.644531 -2.578125 c 0.789062 -0.5625 0.394531 -1.808594 -0.574219 -1.8125 l -4.660156 -0.015625 l -1.402344 -4.285156 c -0.132812 -0.410157 -0.515625 -0.6875002 -0.949219 -0.6914065 z m 0 0" fill="#2e3436"/> +</svg> diff --git a/panels/default-apps/meson.build b/panels/default-apps/meson.build new file mode 100644 index 0000000..3edf34d --- /dev/null +++ b/panels/default-apps/meson.build @@ -0,0 +1,43 @@ +panels_list += cappletname +desktop = 'gnome-@0@-panel.desktop'.format(cappletname) + +desktop_in = configure_file( + input: desktop + '.in.in', + output: desktop + '.in', + configuration: desktop_conf +) + +i18n.merge_file( + type: 'desktop', + input: desktop_in, + output: desktop, + po_dir: po_dir, + install: true, + install_dir: control_center_desktopdir +) + +sources = files( + 'cc-default-apps-panel.c' +) + +resource_data = files( + 'cc-default-apps-panel.ui' +) + +sources += gnome.compile_resources( + 'cc-' + cappletname + '-resources', + cappletname + '.gresource.xml', + c_name: 'cc_' + cappletname.underscorify (), + dependencies: resource_data, + export: true +) + +panels_libs += static_library( + cappletname, + sources: sources, + include_directories: [ top_inc, common_inc ], + dependencies: common_deps, + c_args: cflags +) + +subdir('icons') |