Commit 1154658c authored by Mohammed Sadiq's avatar Mohammed Sadiq Committed by Georges Basile Stavracas Neto

details: Split default apps as a separate panel

https://bugzilla.gnome.org/show_bug.cgi?id=779216
parent 4ac4f4a0
......@@ -23,6 +23,8 @@ libinfo_la_SOURCES = \
cc-info-panel.h \
cc-info-overview-panel.c \
cc-info-overview-panel.h \
cc-info-default-apps-panel.c \
cc-info-default-apps-panel.h \
gsd-disk-space-helper.h \
gsd-disk-space-helper.c \
info-cleanup.h \
......
/* -*- 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-info-panel.h"
#include "cc-info-resources.h"
#include "info-cleanup.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gio/gunixmounts.h>
#include <gio/gdesktopappinfo.h>
#include <glibtop/fsusage.h>
#include <glibtop/mountlist.h>
#include <glibtop/mem.h>
#include <glibtop/sysinfo.h>
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
#endif
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include "gsd-disk-space-helper.h"
#include "cc-info-default-apps-panel.h"
typedef struct
{
const char *content_type;
gint label_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;
struct _CcInfoDefaultAppsPanel
{
GtkBox 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 (CcInfoDefaultAppsPanel, cc_info_default_apps_panel, GTK_TYPE_BOX)
static void
default_app_changed (GtkAppChooserButton *button,
CcInfoDefaultAppsPanel *self)
{
GAppInfo *info;
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);
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);
}
#define OFFSET(x) (G_STRUCT_OFFSET (CcInfoDefaultAppsPanel, x))
#define WIDGET_FROM_OFFSET(x) (G_STRUCT_MEMBER (GtkWidget*, self, x))
static void
info_panel_setup_default_app (CcInfoDefaultAppsPanel *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 (G_OBJECT (button), "changed",
G_CALLBACK (default_app_changed), self);
gtk_widget_show (button);
label = WIDGET_FROM_OFFSET (data->label_offset);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
}
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
info_panel_setup_default_apps (CcInfoDefaultAppsPanel *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_info_default_apps_panel_class_init (CcInfoDefaultAppsPanelClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/info/info-default-apps.ui");
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, default_apps_grid);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, web_label);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, mail_label);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, calendar_label);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, music_label);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, video_label);
gtk_widget_class_bind_template_child (widget_class, CcInfoDefaultAppsPanel, photos_label);
}
static void
cc_info_default_apps_panel_init (CcInfoDefaultAppsPanel *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
info_panel_setup_default_apps (self);
}
GtkWidget *
cc_info_default_apps_panel_new (void)
{
return g_object_new (CC_TYPE_INFO_DEFAULT_APPS_PANEL,
NULL);
}
/* -*- 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/>.
*
*/
#ifndef CC_INFO_DEFAULT_APPS_PANEL_H
#define CC_INFO_DEFAULT_APPS_PANEL_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define CC_TYPE_INFO_DEFAULT_APPS_PANEL (cc_info_default_apps_panel_get_type ())
G_DECLARE_FINAL_TYPE (CcInfoDefaultAppsPanel, cc_info_default_apps_panel, CC, INFO_DEFAULT_APPS_PANEL, GtkBox)
GtkWidget *cc_info_default_apps_panel_new (void);
G_END_DECLS
#endif /* CC_INFO_DEFAULT_APPS_PANEL_H */
......@@ -22,6 +22,7 @@
#include "cc-info-panel.h"
#include "cc-info-overview-panel.h"
#include "cc-info-default-apps-panel.h"
#include "cc-info-resources.h"
#include "info-cleanup.h"
......@@ -64,16 +65,6 @@ CC_PANEL_REGISTER (CcInfoPanel, cc_info_panel)
#define INFO_PANEL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_INFO_PANEL, CcInfoPanelPrivate))
typedef struct
{
const char *content_type;
const char *label;
/* 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;
struct _CcInfoPanelPrivate
{
GtkBuilder *builder;
......@@ -120,6 +111,7 @@ cc_info_panel_class_init (CcInfoPanelClass *klass)
object_class->finalize = cc_info_panel_finalize;
g_type_ensure (CC_TYPE_INFO_OVERVIEW_PANEL);
g_type_ensure (CC_TYPE_INFO_DEFAULT_APPS_PANEL);
}
static void
......@@ -149,116 +141,6 @@ on_section_changed (GtkTreeSelection *selection,
gtk_tree_path_free (path);
}
static void
default_app_changed (GtkAppChooserButton *button,
CcInfoPanel *self)
{
GAppInfo *info;
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);
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
info_panel_setup_default_app (CcInfoPanel *self,
DefaultAppData *data,
guint left_attach,
guint top_attach)
{
GtkWidget *button;
GtkWidget *grid;
GtkWidget *label;
grid = WID ("default_apps_grid");
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 (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 = WID(data->label);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
}
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", "web-label", "*" },
{ "x-scheme-handler/mailto", "mail-label", NULL },
{ "text/calendar", "calendar-label", NULL },
{ "audio/x-vorbis+ogg", "music-label", "audio/*" },
{ "video/x-ogm+ogg", "video-label", "video/*" },
{ "image/jpeg", "photos-label", "image/*" }
};
static void
info_panel_setup_default_apps (CcInfoPanel *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 char **
remove_elem_from_str_array (char **v,
const char *s)
......@@ -825,6 +707,5 @@ cc_info_panel_init (CcInfoPanel *self)
info_panel_setup_selector (self);
info_panel_setup_overview (self);
info_panel_setup_default_apps (self);
info_panel_setup_media (self);
}
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<template class="CcInfoDefaultAppsPanel" parent="GtkBox">
<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">20</property>
<property name="spacing">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid" id="default_apps_grid">
<property name="visible">True</property>
<property name="can_focus">False</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>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</template>
</interface>
......@@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/control-center/info">
<file preprocess="xml-stripblanks">info.ui</file>
<file preprocess="xml-stripblanks">info-overview.ui</file>
<file preprocess="xml-stripblanks">info-default-apps.ui</file>
<file>GnomeLogoVerticalMedium.svg</file>
</gresource>
</gresources>
......@@ -206,207 +206,9 @@
</packing>
</child>
<child>
<object class="GtkBox" id="default_apps_container">
<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">20</property>
<property name="spacing">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid" id="default_apps_grid">
<property name="visible">True</property>