Merge branch 'parental-controls-app' into 'master'

Initial version of parental controls app

See merge request pwithnall/malcontent!20
This commit is contained in:
Philip Withnall 2020-01-31 10:56:28 +00:00
commit 8c904a61ee
26 changed files with 4612 additions and 3 deletions

View File

@ -5,7 +5,7 @@ before_script:
libxml2-devel dbus-daemon
glib2-devel dbus-devel gobject-introspection-devel
gettext-devel polkit-devel polkit-gnome git
lcov pam-devel
lcov pam-devel gtk3-devel accountsservice-devel flatpak-devel
- export LANG=C.UTF-8
stages:

View File

@ -0,0 +1,243 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2019 Endless Mobile, 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:
* - Philip Withnall <withnall@endlessm.com>
*/
#include "config.h"
#include <act/act.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include "application.h"
#include "user-controls.h"
#include "user-selector.h"
static void user_selector_notify_user_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data);
static void user_manager_notify_is_loaded_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data);
/**
* MctApplication:
*
* #MctApplication is a top-level object representing the parental controls
* application.
*
* Since: 0.5.0
*/
struct _MctApplication
{
GtkApplication parent_instance;
ActUserManager *user_manager; /* (owned) */
MctUserSelector *user_selector;
MctUserControls *user_controls;
GtkStack *main_stack;
GtkLabel *error_title;
GtkLabel *error_message;
};
G_DEFINE_TYPE (MctApplication, mct_application, GTK_TYPE_APPLICATION)
static void
mct_application_init (MctApplication *self)
{
/* Nothing to do here. */
}
static void
mct_application_constructed (GObject *object)
{
GApplication *application = G_APPLICATION (object);
g_application_set_application_id (application, "org.freedesktop.MalcontentControl");
/* Localisation */
bindtextdomain ("malcontent", PACKAGE_LOCALE_DIR);
bind_textdomain_codeset ("malcontent", "UTF-8");
textdomain ("malcontent");
g_set_application_name (_("Parental Controls"));
gtk_window_set_default_icon_name ("org.freedesktop.MalcontentControl");
G_OBJECT_CLASS (mct_application_parent_class)->constructed (object);
}
static void
mct_application_dispose (GObject *object)
{
MctApplication *self = MCT_APPLICATION (object);
if (self->user_manager != NULL)
{
g_signal_handlers_disconnect_by_func (self->user_manager,
user_manager_notify_is_loaded_cb, self);
g_clear_object (&self->user_manager);
}
G_OBJECT_CLASS (mct_application_parent_class)->dispose (object);
}
static GtkWindow *
mct_application_get_main_window (MctApplication *self)
{
return gtk_application_get_active_window (GTK_APPLICATION (self));
}
static void
mct_application_activate (GApplication *application)
{
MctApplication *self = MCT_APPLICATION (application);
GtkWindow *window = NULL;
window = mct_application_get_main_window (self);
if (window == NULL)
{
g_autoptr(GtkBuilder) builder = NULL;
g_autoptr(GError) local_error = NULL;
/* Ensure the types used in the UI are registered. */
g_type_ensure (MCT_TYPE_USER_CONTROLS);
g_type_ensure (MCT_TYPE_USER_SELECTOR);
builder = gtk_builder_new ();
g_assert (self->user_manager == NULL);
self->user_manager = g_object_ref (act_user_manager_get_default ());
gtk_builder_set_translation_domain (builder, "malcontent");
gtk_builder_expose_object (builder, "user_manager", G_OBJECT (self->user_manager));
gtk_builder_add_from_resource (builder, "/org/freedesktop/MalcontentControl/ui/main.ui", &local_error);
g_assert (local_error == NULL);
/* Set up the main window. */
window = GTK_WINDOW (gtk_builder_get_object (builder, "main_window"));
gtk_window_set_application (window, GTK_APPLICATION (application));
self->main_stack = GTK_STACK (gtk_builder_get_object (builder, "main_stack"));
self->user_selector = MCT_USER_SELECTOR (gtk_builder_get_object (builder, "user_selector"));
self->user_controls = MCT_USER_CONTROLS (gtk_builder_get_object (builder, "user_controls"));
self->error_title = GTK_LABEL (gtk_builder_get_object (builder, "error_title"));
self->error_message = GTK_LABEL (gtk_builder_get_object (builder, "error_message"));
/* Connect signals. */
g_signal_connect (self->user_selector, "notify::user",
G_CALLBACK (user_selector_notify_user_cb),
self);
g_signal_connect (self->user_manager, "notify::is-loaded",
G_CALLBACK (user_manager_notify_is_loaded_cb), self);
/* Work out whether to show the loading page or the main page, and show
* the controls for the initially selected user. */
user_selector_notify_user_cb (G_OBJECT (self->user_selector), NULL, self);
user_manager_notify_is_loaded_cb (G_OBJECT (self->user_manager), NULL, self);
gtk_widget_show (GTK_WIDGET (window));
}
/* Bring the window to the front. */
gtk_window_present (window);
}
static void
mct_application_class_init (MctApplicationClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
object_class->constructed = mct_application_constructed;
object_class->dispose = mct_application_dispose;
application_class->activate = mct_application_activate;
}
static void
user_selector_notify_user_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
MctUserSelector *selector = MCT_USER_SELECTOR (obj);
MctApplication *self = MCT_APPLICATION (user_data);
ActUser *user;
user = mct_user_selector_get_user (selector);
mct_user_controls_set_user (self->user_controls, user);
}
static void
user_manager_notify_is_loaded_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
MctApplication *self = MCT_APPLICATION (user_data);
ActUserManager *user_manager = ACT_USER_MANAGER (obj);
gboolean is_loaded;
const gchar *new_page_name;
/* The implementation of #ActUserManager guarantees that once is-loaded is
* true, it is never reset to false. */
g_object_get (user_manager, "is-loaded", &is_loaded, NULL);
/* Handle any loading errors. */
if (is_loaded && act_user_manager_no_service (user_manager))
{
gtk_label_set_label (self->error_title,
_("Failed to load user data from the system"));
gtk_label_set_label (self->error_message,
_("Please make sure that the AccountsService is installed and enabled."));
new_page_name = "error";
}
else if (is_loaded)
{
new_page_name = "controls";
}
else
{
new_page_name = "loading";
}
gtk_stack_set_visible_child_name (self->main_stack, new_page_name);
}
/**
* mct_application_new:
*
* Create a new #MctApplication.
*
* Returns: (transfer full): a new #MctApplication
* Since: 0.5.0
*/
MctApplication *
mct_application_new (void)
{
return g_object_new (MCT_TYPE_APPLICATION, NULL);
}

View File

@ -0,0 +1,37 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2019 Endless Mobile, 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:
* - Philip Withnall <withnall@endlessm.com>
*/
#pragma once
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define MCT_TYPE_APPLICATION mct_application_get_type ()
G_DECLARE_FINAL_TYPE (MctApplication, mct_application, MCT, APPLICATION, GtkApplication)
MctApplication *mct_application_new (void);
G_END_DECLS

View File

@ -0,0 +1,461 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2016 Red Hat, Inc.
* Copyright © 2019 Endless Mobile, 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:
* - Felipe Borges <felipeborges@gnome.org>
* - Philip Withnall <withnall@endlessm.com>
*/
#include <glib-object.h>
#include <gtk/gtk.h>
#include "carousel.h"
#define ARROW_SIZE 20
struct _MctCarouselItem {
GtkRadioButton parent;
gint page;
};
G_DEFINE_TYPE (MctCarouselItem, mct_carousel_item, GTK_TYPE_RADIO_BUTTON)
GtkWidget *
mct_carousel_item_new (void)
{
return g_object_new (MCT_TYPE_CAROUSEL_ITEM, NULL);
}
static void
mct_carousel_item_class_init (MctCarouselItemClass *klass)
{
}
static void
mct_carousel_item_init (MctCarouselItem *self)
{
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (self), FALSE);
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
"carousel-item");
}
struct _MctCarousel {
GtkRevealer parent;
GList *children;
gint visible_page;
MctCarouselItem *selected_item;
GtkWidget *last_box;
GtkWidget *arrow;
gint arrow_start_x;
/* Widgets */
GtkStack *stack;
GtkWidget *go_back_button;
GtkWidget *go_next_button;
GtkStyleProvider *provider;
};
G_DEFINE_TYPE (MctCarousel, mct_carousel, GTK_TYPE_REVEALER)
enum {
ITEM_ACTIVATED,
NUM_SIGNALS
};
static guint signals[NUM_SIGNALS] = { 0, };
#define ITEMS_PER_PAGE 3
static gint
mct_carousel_item_get_x (MctCarouselItem *item,
MctCarousel *carousel)
{
GtkWidget *widget, *parent;
gint width;
gint dest_x;
parent = GTK_WIDGET (carousel->stack);
widget = GTK_WIDGET (item);
width = gtk_widget_get_allocated_width (widget);
gtk_widget_translate_coordinates (widget,
parent,
width / 2,
0,
&dest_x,
NULL);
return CLAMP (dest_x - ARROW_SIZE,
0,
gtk_widget_get_allocated_width (parent));
}
static void
mct_carousel_move_arrow (MctCarousel *self)
{
GtkStyleContext *context;
gchar *css;
gint end_x;
GtkSettings *settings;
gboolean animations;
if (!self->selected_item)
return;
end_x = mct_carousel_item_get_x (self->selected_item, self);
context = gtk_widget_get_style_context (self->arrow);
if (self->provider)
gtk_style_context_remove_provider (context, self->provider);
g_clear_object (&self->provider);
settings = gtk_widget_get_settings (GTK_WIDGET (self));
g_object_get (settings, "gtk-enable-animations", &animations, NULL);
/* Animate the arrow movement if animations are enabled. Otherwise,
* jump the arrow to the right location instantly. */
if (animations)
{
css = g_strdup_printf ("@keyframes arrow_keyframes-%d-%d {\n"
" from { margin-left: %dpx; }\n"
" to { margin-left: %dpx; }\n"
"}\n"
"* {\n"
" animation-name: arrow_keyframes-%d-%d;\n"
"}\n",
self->arrow_start_x, end_x,
self->arrow_start_x, end_x,
self->arrow_start_x, end_x);
}
else
{
css = g_strdup_printf ("* { margin-left: %dpx }", end_x);
}
self->provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (self->provider), css, -1, NULL);
gtk_style_context_add_provider (context, self->provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_free (css);
}
static gint
get_last_page_number (MctCarousel *self)
{
if (g_list_length (self->children) == 0)
return 0;
return ((g_list_length (self->children) - 1) / ITEMS_PER_PAGE);
}
static void
update_buttons_visibility (MctCarousel *self)
{
gtk_widget_set_visible (self->go_back_button, (self->visible_page > 0));
gtk_widget_set_visible (self->go_next_button, (self->visible_page < get_last_page_number (self)));
}
/**
* mct_carousel_find_item:
* @carousel: an MctCarousel instance
* @data: user data passed to the comparation function
* @func: the function to call for each element.
* It should return 0 when the desired element is found
*
* Finds an MctCarousel item using the supplied function to find the
* desired element.
* Ideally useful for matching a model object and its correspondent
* widget.
*
* Returns: the found MctCarouselItem, or %NULL if it is not found
*/
MctCarouselItem *
mct_carousel_find_item (MctCarousel *self,
gconstpointer data,
GCompareFunc func)
{
GList *list;
list = self->children;
while (list != NULL)
{
if (!func (list->data, data))
return list->data;
list = list->next;
}
return NULL;
}
static void
on_item_toggled (MctCarouselItem *item,
GdkEvent *event,
gpointer user_data)
{
MctCarousel *self = MCT_CAROUSEL (user_data);
mct_carousel_select_item (self, item);
}
void
mct_carousel_select_item (MctCarousel *self,
MctCarouselItem *item)
{
gchar *page_name;
gboolean page_changed = TRUE;
/* Select first user if none is specified */
if (item == NULL)
{
if (self->children != NULL)
item = self->children->data;
else
return;
}
if (self->selected_item != NULL)
{
page_changed = (self->selected_item->page != item->page);
self->arrow_start_x = mct_carousel_item_get_x (self->selected_item, self);
}
self->selected_item = item;
self->visible_page = item->page;
g_signal_emit (self, signals[ITEM_ACTIVATED], 0, item);
if (!page_changed)
{
mct_carousel_move_arrow (self);
return;
}
page_name = g_strdup_printf ("%d", self->visible_page);
gtk_stack_set_visible_child_name (self->stack, page_name);
g_free (page_name);
update_buttons_visibility (self);
/* mct_carousel_move_arrow is called from on_transition_running */
}
static void
mct_carousel_select_item_at_index (MctCarousel *self,
gint index)
{
GList *l = NULL;
l = g_list_nth (self->children, index);
mct_carousel_select_item (self, l->data);
}
static void
mct_carousel_goto_previous_page (GtkWidget *button,
gpointer user_data)
{
MctCarousel *self = MCT_CAROUSEL (user_data);
self->visible_page--;
if (self->visible_page < 0)
self->visible_page = 0;
/* Select first item of the page */
mct_carousel_select_item_at_index (self, self->visible_page * ITEMS_PER_PAGE);
}
static void
mct_carousel_goto_next_page (GtkWidget *button,
gpointer user_data)
{
MctCarousel *self = MCT_CAROUSEL (user_data);
gint last_page;
last_page = get_last_page_number (self);
self->visible_page++;
if (self->visible_page > last_page)
self->visible_page = last_page;
/* Select first item of the page */
mct_carousel_select_item_at_index (self, self->visible_page * ITEMS_PER_PAGE);
}
static void
mct_carousel_add (GtkContainer *container,
GtkWidget *widget)
{
MctCarousel *self = MCT_CAROUSEL (container);
gboolean last_box_is_full;
if (!MCT_IS_CAROUSEL_ITEM (widget))
{
GTK_CONTAINER_CLASS (mct_carousel_parent_class)->add (container, widget);
return;
}
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "menu");
gtk_button_set_relief (GTK_BUTTON (widget), GTK_RELIEF_NONE);
self->children = g_list_append (self->children, widget);
MCT_CAROUSEL_ITEM (widget)->page = get_last_page_number (self);
if (self->selected_item != NULL)
gtk_radio_button_join_group (GTK_RADIO_BUTTON (widget), GTK_RADIO_BUTTON (self->selected_item));
g_signal_connect (widget, "button-press-event", G_CALLBACK (on_item_toggled), self);
last_box_is_full = ((g_list_length (self->children) - 1) % ITEMS_PER_PAGE == 0);
if (last_box_is_full)
{
g_autofree gchar *page = NULL;
page = g_strdup_printf ("%d", MCT_CAROUSEL_ITEM (widget)->page);
self->last_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_show (self->last_box);
gtk_widget_set_valign (self->last_box, GTK_ALIGN_CENTER);
gtk_stack_add_named (self->stack, self->last_box, page);
}
gtk_widget_show_all (widget);
gtk_box_pack_start (GTK_BOX (self->last_box), widget, TRUE, FALSE, 10);
update_buttons_visibility (self);
}
static void
destroy_widget_cb (GtkWidget *widget,
gpointer user_data)
{
gtk_widget_destroy (widget);
}
void
mct_carousel_purge_items (MctCarousel *self)
{
gtk_container_forall (GTK_CONTAINER (self->stack),
destroy_widget_cb,
NULL);
g_list_free (self->children);
self->children = NULL;
self->visible_page = 0;
self->selected_item = NULL;
}
MctCarousel *
mct_carousel_new (void)
{
return g_object_new (MCT_TYPE_CAROUSEL, NULL);
}
static void
mct_carousel_dispose (GObject *object)
{
MctCarousel *self = MCT_CAROUSEL (object);
g_clear_object (&self->provider);
if (self->children != NULL)
{
g_list_free (self->children);
self->children = NULL;
}
G_OBJECT_CLASS (mct_carousel_parent_class)->dispose (object);
}
static void
mct_carousel_class_init (MctCarouselClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
gtk_widget_class_set_template_from_resource (wclass,
"/org/freedesktop/MalcontentControl/ui/carousel.ui");
gtk_widget_class_bind_template_child (wclass, MctCarousel, stack);
gtk_widget_class_bind_template_child (wclass, MctCarousel, go_back_button);
gtk_widget_class_bind_template_child (wclass, MctCarousel, go_next_button);
gtk_widget_class_bind_template_child (wclass, MctCarousel, arrow);
gtk_widget_class_bind_template_callback (wclass, mct_carousel_goto_previous_page);
gtk_widget_class_bind_template_callback (wclass, mct_carousel_goto_next_page);
object_class->dispose = mct_carousel_dispose;
container_class->add = mct_carousel_add;
signals[ITEM_ACTIVATED] =
g_signal_new ("item-activated",
MCT_TYPE_CAROUSEL,
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
MCT_TYPE_CAROUSEL_ITEM);
}
static void
on_size_allocate (MctCarousel *self)
{
if (self->selected_item == NULL)
return;
if (gtk_stack_get_transition_running (self->stack))
return;
self->arrow_start_x = mct_carousel_item_get_x (self->selected_item, self);
mct_carousel_move_arrow (self);
}
static void
on_transition_running (MctCarousel *self)
{
if (!gtk_stack_get_transition_running (self->stack))
mct_carousel_move_arrow (self);
}
static void
mct_carousel_init (MctCarousel *self)
{
GtkStyleProvider *provider;
gtk_widget_init_template (GTK_WIDGET (self));
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (provider),
"/org/freedesktop/MalcontentControl/ui/carousel.css");
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
g_signal_connect_swapped (self->stack, "size-allocate", G_CALLBACK (on_size_allocate), self);
g_signal_connect_swapped (self->stack, "notify::transition-running", G_CALLBACK (on_transition_running), self);
}
guint
mct_carousel_get_item_count (MctCarousel *self)
{
return g_list_length (self->children);
}

View File

@ -0,0 +1,30 @@
.carousel-arrow-container {
border-bottom: 1px solid @borders;
}
.carousel-arrow,
.carousel-inner-arrow {
border-width: 20px; /* ARROW_SIZE */
border-style: solid;
border-color: transparent;
}
.carousel-arrow {
border-bottom-color: @borders;
margin-bottom: -1px;
animation-duration: 200ms;
animation-timing-function: ease-in-out;
animation-fill-mode: forwards;
}
.carousel-inner-arrow {
border-bottom-color: @theme_bg_color;
margin-bottom: -2px;
}
.carousel-item {
background: transparent;
box-shadow: none;
border: none;
color: @theme_fg_color;
}

View File

@ -0,0 +1,52 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2016 Red Hat, Inc.
* Copyright © 2019 Endless Mobile, 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:
* - Felipe Borges <felipeborges@gnome.org>
* - Philip Withnall <withnall@endlessm.com>
*/
#pragma once
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define MCT_TYPE_CAROUSEL_ITEM (mct_carousel_item_get_type ())
G_DECLARE_FINAL_TYPE (MctCarouselItem, mct_carousel_item, MCT, CAROUSEL_ITEM, GtkRadioButton)
#define MCT_TYPE_CAROUSEL (mct_carousel_get_type ())
G_DECLARE_FINAL_TYPE (MctCarousel, mct_carousel, MCT, CAROUSEL, GtkRevealer)
GtkWidget *mct_carousel_item_new (void);
MctCarousel *mct_carousel_new (void);
void mct_carousel_purge_items (MctCarousel *self);
MctCarouselItem *mct_carousel_find_item (MctCarousel *self,
gconstpointer data,
GCompareFunc func);
void mct_carousel_select_item (MctCarousel *self,
MctCarouselItem *item);
guint mct_carousel_get_item_count (MctCarousel *self);
G_END_DECLS

View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2016 Red Hat, Inc. -->
<!-- Copyright © 2020 Endless, Inc. -->
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="MctCarousel" parent="GtkRevealer">
<property name="transition_duration">400</property>
<property name="reveal-child">True</property>
<child>
<object class="GtkOverlay">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="border_width">16</property>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="transition_duration">400</property>
<property name="transition_type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
<style>
<class name="location-bar"/>
</style>
</object>
</child>
<child type="overlay">
<object class="GtkOverlay">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<property name="border_width">12</property>
<child>
<object class="GtkButton" id="go_back_button">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon-size">4</property>
<property name="icon_name">go-previous-symbolic</property>
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-name" translatable="yes">Previous Page</property>
</object>
</child>
</object>
</child>
<signal name="clicked" handler="mct_carousel_goto_previous_page" object="MctCarousel" swapped="no"/>
</object>
<packing>
<property name="pack_type">GTK_PACK_START</property>
</packing>
</child>
<child>
<object class="GtkButton" id="go_next_button">
<property name="can_focus">True</property>
<property name="valign">center</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon-size">4</property>
<property name="icon_name">go-next-symbolic</property>
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-name" translatable="yes">Next Page</property>
</object>
</child>
</object>
</child>
<signal name="clicked" handler="mct_carousel_goto_next_page" object="MctCarousel" swapped="no"/>
</object>
<packing>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkBox">
<property name="visible">True</property>
<property name="valign">GTK_ALIGN_END</property>
<style>
<class name="carousel-arrow-container"/>
</style>
<child>
<object class="GtkOverlay">
<property name="visible">True</property>
<child>
<object class="GtkBox" id="arrow">
<property name="visible">True</property>
<property name="halign">GTK_ALIGN_END</property>
<style>
<class name="carousel-arrow"/>
</style>
</object>
</child>
<child type="overlay">
<object class="GtkBox">
<property name="visible">True</property>
<property name="halign">GTK_ALIGN_END</property>
<style>
<class name="carousel-inner-arrow"/>
</style>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="pass-through">True</property>
</packing>
</child>
</object>
<packing>
<property name="pass-through">True</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

View File

@ -0,0 +1,968 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2015-2016 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib/gi18n.h>
#include <string.h>
#include "gs-content-rating.h"
const gchar *
gs_content_rating_system_to_str (GsContentRatingSystem system)
{
if (system == GS_CONTENT_RATING_SYSTEM_INCAA)
return "INCAA";
if (system == GS_CONTENT_RATING_SYSTEM_ACB)
return "ACB";
if (system == GS_CONTENT_RATING_SYSTEM_DJCTQ)
return "DJCTQ";
if (system == GS_CONTENT_RATING_SYSTEM_GSRR)
return "GSRR";
if (system == GS_CONTENT_RATING_SYSTEM_PEGI)
return "PEGI";
if (system == GS_CONTENT_RATING_SYSTEM_KAVI)
return "KAVI";
if (system == GS_CONTENT_RATING_SYSTEM_USK)
return "USK";
if (system == GS_CONTENT_RATING_SYSTEM_ESRA)
return "ESRA";
if (system == GS_CONTENT_RATING_SYSTEM_CERO)
return "CERO";
if (system == GS_CONTENT_RATING_SYSTEM_OFLCNZ)
return "OFLCNZ";
if (system == GS_CONTENT_RATING_SYSTEM_RUSSIA)
return "RUSSIA";
if (system == GS_CONTENT_RATING_SYSTEM_MDA)
return "MDA";
if (system == GS_CONTENT_RATING_SYSTEM_GRAC)
return "GRAC";
if (system == GS_CONTENT_RATING_SYSTEM_ESRB)
return "ESRB";
if (system == GS_CONTENT_RATING_SYSTEM_IARC)
return "IARC";
return NULL;
}
const gchar *
gs_content_rating_key_value_to_str (const gchar *id, MctAppFilterOarsValue value)
{
guint i;
const struct {
const gchar *id;
MctAppFilterOarsValue value;
const gchar *desc;
} tab[] = {
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No cartoon violence") },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Cartoon characters in unsafe situations") },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Cartoon characters in aggressive conflict") },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic violence involving cartoon characters") },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No fantasy violence") },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Characters in unsafe situations easily distinguishable from reality") },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Characters in aggressive conflict easily distinguishable from reality") },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic violence easily distinguishable from reality") },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No realistic violence") },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Mildly realistic characters in unsafe situations") },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Depictions of realistic characters in aggressive conflict") },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic violence involving realistic characters") },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No bloodshed") },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Unrealistic bloodshed") },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Realistic bloodshed") },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Depictions of bloodshed and the mutilation of body parts") },
{ "violence-sexual", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No sexual violence") },
{ "violence-sexual", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Rape or other violent sexual behavior") },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to alcohol") },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("References to alcoholic beverages") },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Use of alcoholic beverages") },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to illicit drugs") },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("References to illicit drugs") },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Use of illicit drugs") },
{ "drugs-tobacco", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("References to tobacco products") },
{ "drugs-tobacco", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Use of tobacco products") },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No nudity of any sort") },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Brief artistic nudity") },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Prolonged nudity") },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references or depictions of sexual nature") },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Provocative references or depictions") },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Sexual references or depictions") },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic sexual behavior") },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No profanity of any kind") },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Mild or infrequent use of profanity") },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Moderate use of profanity") },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Strong or frequent use of profanity") },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No inappropriate humor") },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Slapstick humor") },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Vulgar or bathroom humor") },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Mature or sexual humor") },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No discriminatory language of any kind") },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Negativity towards a specific group of people") },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Discrimination designed to cause emotional harm") },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Explicit discrimination based on gender, sexuality, race or religion") },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No advertising of any kind") },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Product placement") },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Explicit references to specific brands or trademarked products") },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Users are encouraged to purchase specific real-world items") },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No gambling of any kind") },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Gambling on random events using tokens or credits") },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Gambling using “play” money") },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Gambling using real money") },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No ability to spend money") },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_MILD, /* v1.1 */
/* TRANSLATORS: content rating description */
_("Users are encouraged to donate real money") },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Ability to spend real money in-game") },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No way to chat with other users") },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("User-to-user game interactions without chat functionality") },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Moderated chat functionality between users") },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Uncontrolled chat functionality between users") },
{ "social-audio", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No way to talk with other users") },
{ "social-audio", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Uncontrolled audio or video chat functionality between users") },
{ "social-contacts", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No sharing of social network usernames or email addresses") },
{ "social-contacts", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Sharing social network usernames or email addresses") },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No sharing of user information with 3rd parties") },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_MILD, /* v1.1 */
/* TRANSLATORS: content rating description */
_("Checking for the latest application version") },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_MODERATE, /* v1.1 */
/* TRANSLATORS: content rating description */
_("Sharing diagnostic data that does not let others identify the user") },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Sharing information that lets others identify the user") },
{ "social-location", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No sharing of physical location to other users") },
{ "social-location", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Sharing physical location to other users") },
/* v1.1 */
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to homosexuality") },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Indirect references to homosexuality") },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Kissing between people of the same gender") },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic sexual behavior between people of the same gender") },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to prostitution") },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Indirect references to prostitution") },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Direct references to prostitution") },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic depictions of the act of prostitution") },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to adultery") },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Indirect references to adultery") },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Direct references to adultery") },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic depictions of the act of adultery") },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No sexualized characters") },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Scantily clad human characters") },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Overtly sexualized human characters") },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to desecration") },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Depictions or references to historical desecration") },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Depictions of modern-day human desecration") },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic depictions of modern-day desecration") },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No visible dead human remains") },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Visible dead human remains") },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Dead human remains that are exposed to the elements") },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic depictions of desecration of human bodies") },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_NONE,
/* TRANSLATORS: content rating description */
_("No references to slavery") },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_MILD,
/* TRANSLATORS: content rating description */
_("Depictions or references to historical slavery") },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_MODERATE,
/* TRANSLATORS: content rating description */
_("Depictions of modern-day slavery") },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_INTENSE,
/* TRANSLATORS: content rating description */
_("Graphic depictions of modern-day slavery") },
{ NULL, 0, NULL } };
for (i = 0; tab[i].id != NULL; i++) {
if (g_strcmp0 (tab[i].id, id) == 0 && tab[i].value == value)
return tab[i].desc;
}
return NULL;
}
/* data obtained from https://en.wikipedia.org/wiki/Video_game_rating_system */
const gchar *
gs_utils_content_rating_age_to_str (GsContentRatingSystem system, guint age)
{
if (system == GS_CONTENT_RATING_SYSTEM_INCAA) {
if (age >= 18)
return "+18";
if (age >= 13)
return "+13";
return "ATP";
}
if (system == GS_CONTENT_RATING_SYSTEM_ACB) {
if (age >= 18)
return "R18+";
if (age >= 15)
return "MA15+";
return "PG";
}
if (system == GS_CONTENT_RATING_SYSTEM_DJCTQ) {
if (age >= 18)
return "18";
if (age >= 16)
return "16";
if (age >= 14)
return "14";
if (age >= 12)
return "12";
if (age >= 10)
return "10";
return "L";
}
if (system == GS_CONTENT_RATING_SYSTEM_GSRR) {
if (age >= 18)
return "限制";
if (age >= 15)
return "輔15";
if (age >= 12)
return "輔12";
if (age >= 6)
return "保護";
return "普通";
}
if (system == GS_CONTENT_RATING_SYSTEM_PEGI) {
if (age >= 18)
return "18";
if (age >= 16)
return "16";
if (age >= 12)
return "12";
if (age >= 7)
return "7";
if (age >= 3)
return "3";
return NULL;
}
if (system == GS_CONTENT_RATING_SYSTEM_KAVI) {
if (age >= 18)
return "18+";
if (age >= 16)
return "16+";
if (age >= 12)
return "12+";
if (age >= 7)
return "7+";
if (age >= 3)
return "3+";
return NULL;
}
if (system == GS_CONTENT_RATING_SYSTEM_USK) {
if (age >= 18)
return "18";
if (age >= 16)
return "16";
if (age >= 12)
return "12";
if (age >= 6)
return "6";
return "0";
}
/* Reference: http://www.esra.org.ir/ */
if (system == GS_CONTENT_RATING_SYSTEM_ESRA) {
if (age >= 18)
return "+18";
if (age >= 15)
return "+15";
if (age >= 12)
return "+12";
if (age >= 7)
return "+7";
if (age >= 3)
return "+3";
return NULL;
}
if (system == GS_CONTENT_RATING_SYSTEM_CERO) {
if (age >= 18)
return "Z";
if (age >= 17)
return "D";
if (age >= 15)
return "C";
if (age >= 12)
return "B";
return "A";
}
if (system == GS_CONTENT_RATING_SYSTEM_OFLCNZ) {
if (age >= 18)
return "R18";
if (age >= 16)
return "R16";
if (age >= 15)
return "R15";
if (age >= 13)
return "R13";
return "G";
}
if (system == GS_CONTENT_RATING_SYSTEM_RUSSIA) {
if (age >= 18)
return "18+";
if (age >= 16)
return "16+";
if (age >= 12)
return "12+";
if (age >= 6)
return "6+";
return "0+";
}
if (system == GS_CONTENT_RATING_SYSTEM_MDA) {
if (age >= 18)
return "M18";
if (age >= 16)
return "ADV";
return "General";
}
if (system == GS_CONTENT_RATING_SYSTEM_GRAC) {
if (age >= 18)
return "18";
if (age >= 15)
return "15";
if (age >= 12)
return "12";
return "ALL";
}
if (system == GS_CONTENT_RATING_SYSTEM_ESRB) {
if (age >= 18)
return "Adults Only";
if (age >= 17)
return "Mature";
if (age >= 13)
return "Teen";
if (age >= 10)
return "Everyone 10+";
if (age >= 6)
return "Everyone";
return "Early Childhood";
}
/* IARC = everything else */
if (age >= 18)
return "18+";
if (age >= 16)
return "16+";
if (age >= 12)
return "12+";
if (age >= 7)
return "7+";
if (age >= 3)
return "3+";
return NULL;
}
/*
* parse_locale:
* @locale: (transfer full): a locale to parse
* @language_out: (out) (optional) (nullable): return location for the parsed
* language, or %NULL to ignore
* @territory_out: (out) (optional) (nullable): return location for the parsed
* territory, or %NULL to ignore
* @codeset_out: (out) (optional) (nullable): return location for the parsed
* codeset, or %NULL to ignore
* @modifier_out: (out) (optional) (nullable): return location for the parsed
* modifier, or %NULL to ignore
*
* Parse @locale as a locale string of the form
* `language[_territory][.codeset][@modifier]` see `man 3 setlocale` for
* details.
*
* On success, %TRUE will be returned, and the components of the locale will be
* returned in the given addresses, with each component not including any
* separators. Otherwise, %FALSE will be returned and the components will be set
* to %NULL.
*
* @locale is modified, and any returned non-%NULL pointers will point inside
* it.
*
* Returns: %TRUE on success, %FALSE otherwise
*/
static gboolean
parse_locale (gchar *locale /* (transfer full) */,
const gchar **language_out,
const gchar **territory_out,
const gchar **codeset_out,
const gchar **modifier_out)
{
gchar *separator;
const gchar *language = NULL, *territory = NULL, *codeset = NULL, *modifier = NULL;
separator = strrchr (locale, '@');
if (separator != NULL) {
modifier = separator + 1;
*separator = '\0';
}
separator = strrchr (locale, '.');
if (separator != NULL) {
codeset = separator + 1;
*separator = '\0';
}
separator = strrchr (locale, '_');
if (separator != NULL) {
territory = separator + 1;
*separator = '\0';
}
language = locale;
/* Parse failure? */
if (*language == '\0') {
language = NULL;
territory = NULL;
codeset = NULL;
modifier = NULL;
}
if (language_out != NULL)
*language_out = language;
if (territory_out != NULL)
*territory_out = territory;
if (codeset_out != NULL)
*codeset_out = codeset;
if (modifier_out != NULL)
*modifier_out = modifier;
return (language != NULL);
}
/* data obtained from https://en.wikipedia.org/wiki/Video_game_rating_system */
GsContentRatingSystem
gs_utils_content_rating_system_from_locale (const gchar *locale)
{
g_autofree gchar *locale_copy = g_strdup (locale);
const gchar *language, *territory;
/* Default to IARC for locales which cant be parsed. */
if (!parse_locale (locale_copy, &language, &territory, NULL, NULL))
return GS_CONTENT_RATING_SYSTEM_IARC;
/* Argentina */
if (g_strcmp0 (language, "ar") == 0)
return GS_CONTENT_RATING_SYSTEM_INCAA;
/* Australia */
if (g_strcmp0 (language, "au") == 0)
return GS_CONTENT_RATING_SYSTEM_ACB;
/* Brazil */
if (g_strcmp0 (language, "pt") == 0 &&
g_strcmp0 (territory, "BR") == 0)
return GS_CONTENT_RATING_SYSTEM_DJCTQ;
/* Taiwan */
if (g_strcmp0 (language, "zh") == 0 &&
g_strcmp0 (territory, "TW") == 0)
return GS_CONTENT_RATING_SYSTEM_GSRR;
/* Europe (but not Finland or Germany), India, Israel,
* Pakistan, Quebec, South Africa */
if ((g_strcmp0 (language, "en") == 0 &&
g_strcmp0 (territory, "GB") == 0) ||
g_strcmp0 (language, "gb") == 0 ||
g_strcmp0 (language, "al") == 0 ||
g_strcmp0 (language, "ad") == 0 ||
g_strcmp0 (language, "am") == 0 ||
g_strcmp0 (language, "at") == 0 ||
g_strcmp0 (language, "az") == 0 ||
g_strcmp0 (language, "by") == 0 ||
g_strcmp0 (language, "be") == 0 ||
g_strcmp0 (language, "ba") == 0 ||
g_strcmp0 (language, "bg") == 0 ||
g_strcmp0 (language, "hr") == 0 ||
g_strcmp0 (language, "cy") == 0 ||
g_strcmp0 (language, "cz") == 0 ||
g_strcmp0 (language, "dk") == 0 ||
g_strcmp0 (language, "ee") == 0 ||
g_strcmp0 (language, "fr") == 0 ||
g_strcmp0 (language, "ge") == 0 ||
g_strcmp0 (language, "gr") == 0 ||
g_strcmp0 (language, "hu") == 0 ||
g_strcmp0 (language, "is") == 0 ||
g_strcmp0 (language, "it") == 0 ||
g_strcmp0 (language, "kz") == 0 ||
g_strcmp0 (language, "xk") == 0 ||
g_strcmp0 (language, "lv") == 0 ||
g_strcmp0 (language, "fl") == 0 ||
g_strcmp0 (language, "lu") == 0 ||
g_strcmp0 (language, "lt") == 0 ||
g_strcmp0 (language, "mk") == 0 ||
g_strcmp0 (language, "mt") == 0 ||
g_strcmp0 (language, "md") == 0 ||
g_strcmp0 (language, "mc") == 0 ||
g_strcmp0 (language, "me") == 0 ||
g_strcmp0 (language, "nl") == 0 ||
g_strcmp0 (language, "no") == 0 ||
g_strcmp0 (language, "pl") == 0 ||
g_strcmp0 (language, "pt") == 0 ||
g_strcmp0 (language, "ro") == 0 ||
g_strcmp0 (language, "sm") == 0 ||
g_strcmp0 (language, "rs") == 0 ||
g_strcmp0 (language, "sk") == 0 ||
g_strcmp0 (language, "si") == 0 ||
g_strcmp0 (language, "es") == 0 ||
g_strcmp0 (language, "se") == 0 ||
g_strcmp0 (language, "ch") == 0 ||
g_strcmp0 (language, "tr") == 0 ||
g_strcmp0 (language, "ua") == 0 ||
g_strcmp0 (language, "va") == 0 ||
g_strcmp0 (language, "in") == 0 ||
g_strcmp0 (language, "il") == 0 ||
g_strcmp0 (language, "pk") == 0 ||
g_strcmp0 (language, "za") == 0)
return GS_CONTENT_RATING_SYSTEM_PEGI;
/* Finland */
if (g_strcmp0 (language, "fi") == 0)
return GS_CONTENT_RATING_SYSTEM_KAVI;
/* Germany */
if (g_strcmp0 (language, "de") == 0)
return GS_CONTENT_RATING_SYSTEM_USK;
/* Iran */
if (g_strcmp0 (language, "ir") == 0)
return GS_CONTENT_RATING_SYSTEM_ESRA;
/* Japan */
if (g_strcmp0 (language, "jp") == 0)
return GS_CONTENT_RATING_SYSTEM_CERO;
/* New Zealand */
if (g_strcmp0 (language, "nz") == 0)
return GS_CONTENT_RATING_SYSTEM_OFLCNZ;
/* Russia: Content rating law */
if (g_strcmp0 (language, "ru") == 0)
return GS_CONTENT_RATING_SYSTEM_RUSSIA;
/* Singapore */
if (g_strcmp0 (language, "sg") == 0)
return GS_CONTENT_RATING_SYSTEM_MDA;
/* South Korea */
if (g_strcmp0 (language, "kr") == 0)
return GS_CONTENT_RATING_SYSTEM_GRAC;
/* USA, Canada, Mexico */
if ((g_strcmp0 (language, "en") == 0 &&
g_strcmp0 (territory, "US") == 0) ||
g_strcmp0 (language, "us") == 0 ||
g_strcmp0 (language, "ca") == 0 ||
g_strcmp0 (language, "mx") == 0)
return GS_CONTENT_RATING_SYSTEM_ESRB;
/* everything else is IARC */
return GS_CONTENT_RATING_SYSTEM_IARC;
}
static const gchar *content_rating_strings[GS_CONTENT_RATING_SYSTEM_LAST][7] = {
{ "3+", "7+", "12+", "16+", "18+", NULL }, /* GS_CONTENT_RATING_SYSTEM_UNKNOWN */
{ "ATP", "+13", "+18", NULL }, /* GS_CONTENT_RATING_SYSTEM_INCAA */
{ "PG", "MA15+", "R18+", NULL }, /* GS_CONTENT_RATING_SYSTEM_ACB */
{ "L", "10", "12", "14", "16", "18", NULL }, /* GS_CONTENT_RATING_SYSTEM_DJCTQ */
{ "普通", "保護", "輔12", "輔15", "限制", NULL }, /* GS_CONTENT_RATING_SYSTEM_GSRR */
{ "3", "7", "12", "16", "18", NULL }, /* GS_CONTENT_RATING_SYSTEM_PEGI */
{ "3+", "7+", "12+", "16+", "18+", NULL }, /* GS_CONTENT_RATING_SYSTEM_KAVI */
{ "0", "6", "12", "16", "18", NULL}, /* GS_CONTENT_RATING_SYSTEM_USK */
{ "+3", "+7", "+12", "+15", "+18", NULL }, /* GS_CONTENT_RATING_SYSTEM_ESRA */
{ "A", "B", "C", "D", "Z", NULL }, /* GS_CONTENT_RATING_SYSTEM_CERO */
{ "G", "R13", "R15", "R16", "R18", NULL }, /* GS_CONTENT_RATING_SYSTEM_OFLCNZ */
{ "0+", "6+", "12+", "16+", "18+", NULL }, /* GS_CONTENT_RATING_SYSTEM_RUSSIA */
{ "General", "ADV", "M18", NULL }, /* GS_CONTENT_RATING_SYSTEM_MDA */
{ "ALL", "12", "15", "18", NULL }, /* GS_CONTENT_RATING_SYSTEM_GRAC */
{ "Early Childhood", "Everyone", "Everyone 10+", "Teen", "Mature", "Adults Only", NULL }, /* GS_CONTENT_RATING_SYSTEM_ESRB */
{ "3+", "7+", "12+", "16+", "18+", NULL }, /* GS_CONTENT_RATING_SYSTEM_IARC */
};
const gchar * const *
gs_utils_content_rating_get_values (GsContentRatingSystem system)
{
g_assert (system < GS_CONTENT_RATING_SYSTEM_LAST);
return content_rating_strings[system];
}
static guint content_rating_ages[GS_CONTENT_RATING_SYSTEM_LAST][7] = {
{ 3, 7, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_UNKNOWN */
{ 0, 13, 18 }, /* GS_CONTENT_RATING_SYSTEM_INCAA */
{ 0, 15, 18 }, /* GS_CONTENT_RATING_SYSTEM_ACB */
{ 0, 10, 12, 14, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_DJCTQ */
{ 0, 6, 12, 15, 18 }, /* GS_CONTENT_RATING_SYSTEM_GSRR */
{ 3, 7, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_PEGI */
{ 3, 7, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_KAVI */
{ 0, 6, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_USK */
{ 3, 7, 12, 15, 18 }, /* GS_CONTENT_RATING_SYSTEM_ESRA */
{ 0, 12, 15, 17, 18 }, /* GS_CONTENT_RATING_SYSTEM_CERO */
{ 0, 13, 15, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_OFLCNZ */
{ 0, 6, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_RUSSIA */
{ 0, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_MDA */
{ 0, 12, 15, 18 }, /* GS_CONTENT_RATING_SYSTEM_GRAC */
{ 0, 6, 10, 13, 17, 18 }, /* GS_CONTENT_RATING_SYSTEM_ESRB */
{ 3, 7, 12, 16, 18 }, /* GS_CONTENT_RATING_SYSTEM_IARC */
};
const guint *
gs_utils_content_rating_get_ages (GsContentRatingSystem system)
{
g_assert (system < GS_CONTENT_RATING_SYSTEM_LAST);
return content_rating_ages[system];
}
const struct {
const gchar *id;
MctAppFilterOarsValue value;
guint csm_age;
} id_to_csm_age[] = {
/* v1.0 */
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_MILD, 3 },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_MODERATE, 4 },
{ "violence-cartoon", MCT_APP_FILTER_OARS_VALUE_INTENSE, 6 },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_MILD, 3 },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_MODERATE, 7 },
{ "violence-fantasy", MCT_APP_FILTER_OARS_VALUE_INTENSE, 8 },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_MILD, 4 },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_MODERATE, 9 },
{ "violence-realistic", MCT_APP_FILTER_OARS_VALUE_INTENSE, 14 },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_MILD, 9 },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_MODERATE, 11 },
{ "violence-bloodshed", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "violence-sexual", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-sexual", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_MILD, 11 },
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_MODERATE, 13 },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_MILD, 12 },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_MODERATE, 14 },
{ "drugs-tobacco", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "drugs-tobacco", MCT_APP_FILTER_OARS_VALUE_MILD, 10 },
{ "drugs-tobacco", MCT_APP_FILTER_OARS_VALUE_MODERATE, 13 },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_MILD, 12 },
{ "sex-nudity", MCT_APP_FILTER_OARS_VALUE_MODERATE, 14 },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_MILD, 13 },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_MODERATE, 14 },
{ "sex-themes", MCT_APP_FILTER_OARS_VALUE_INTENSE, 15 },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_MILD, 8 },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_MODERATE, 11 },
{ "language-profanity", MCT_APP_FILTER_OARS_VALUE_INTENSE, 14 },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_MILD, 3 },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_MODERATE, 8 },
{ "language-humor", MCT_APP_FILTER_OARS_VALUE_INTENSE, 14 },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_MILD, 9 },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_MODERATE,10 },
{ "language-discrimination", MCT_APP_FILTER_OARS_VALUE_INTENSE, 11 },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_MILD, 7 },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_MODERATE, 8 },
{ "money-advertising", MCT_APP_FILTER_OARS_VALUE_INTENSE, 10 },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_MILD, 7 },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_MODERATE, 10 },
{ "money-gambling", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_INTENSE, 15 },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_MILD, 4 },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_MODERATE, 10 },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_INTENSE, 13 },
{ "social-audio", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "social-audio", MCT_APP_FILTER_OARS_VALUE_INTENSE, 15 },
{ "social-contacts", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "social-contacts", MCT_APP_FILTER_OARS_VALUE_INTENSE, 12 },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_INTENSE, 13 },
{ "social-location", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "social-location", MCT_APP_FILTER_OARS_VALUE_INTENSE, 13 },
/* v1.1 additions */
{ "social-info", MCT_APP_FILTER_OARS_VALUE_MILD, 0 },
{ "social-info", MCT_APP_FILTER_OARS_VALUE_MODERATE, 13 },
{ "money-purchasing", MCT_APP_FILTER_OARS_VALUE_MILD, 12 },
{ "social-chat", MCT_APP_FILTER_OARS_VALUE_MODERATE, 14 },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_MILD, 10 },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_MODERATE, 13 },
{ "sex-homosexuality", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_MILD, 12 },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_MODERATE, 14 },
{ "sex-prostitution", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_MILD, 8 },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_MODERATE, 10 },
{ "sex-adultery", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_MODERATE, 10 },
{ "sex-appearance", MCT_APP_FILTER_OARS_VALUE_INTENSE, 15 },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_MILD, 13 },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_MODERATE, 15 },
{ "violence-worship", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_MILD, 13 },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_MODERATE, 15 },
{ "violence-desecration", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_NONE, 0 },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_MILD, 13 },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_MODERATE, 15 },
{ "violence-slavery", MCT_APP_FILTER_OARS_VALUE_INTENSE, 18 },
/* EOS customisation to add at least one CSM ↔ OARS mapping for ages 16 and 17,
* as these are used in many locale-specific ratings systems. Without them,
* mapping (e.g.) OFLCNZ R16 CSM 16 OARS CSM gives CSM 15, which then maps
* back to OFLCNZ R15, which is not what we want. The addition of these two
* mappings should not expose younger users to content they would not have seen
* with the default upstream mappings; it instead slightly raises the age at
* which users are allowed to see intense content in these two categories.
*
* See https://phabricator.endlessm.com/T23897#666769. */
{ "drugs-alcohol", MCT_APP_FILTER_OARS_VALUE_INTENSE, 16 },
{ "drugs-narcotics", MCT_APP_FILTER_OARS_VALUE_INTENSE, 17 },
{ NULL, 0, 0 } };
/**
* as_content_rating_id_value_to_csm_age:
* @id: the subsection ID e.g. "violence-cartoon"
* @value: the #AsContentRatingValue, e.g. %MCT_APP_FILTER_OARS_VALUE_INTENSE
*
* Gets the Common Sense Media approved age for a specific rating level.
*
* Returns: The age in years, or 0 for no details.
*
* Since: 0.5.12
**/
guint
as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value)
{
guint i;
for (i = 0; id_to_csm_age[i].id != NULL; i++) {
if (value == id_to_csm_age[i].value &&
g_strcmp0 (id, id_to_csm_age[i].id) == 0)
return id_to_csm_age[i].csm_age;
}
return 0;
}
/**
* as_content_rating_id_csm_age_to_value:
* @id: the subsection ID e.g. "violence-cartoon"
* @age: the age
*
* Gets the #MctAppFilterOarsValue for a given age.
*
* Returns: the #MctAppFilterOarsValue
**/
MctAppFilterOarsValue
as_content_rating_id_csm_age_to_value (const gchar *id, guint age)
{
MctAppFilterOarsValue value;
guint i;
value = MCT_APP_FILTER_OARS_VALUE_UNKNOWN;
for (i = 0; id_to_csm_age[i].id != NULL; i++) {
if (age >= id_to_csm_age[i].csm_age &&
g_strcmp0 (id, id_to_csm_age[i].id) == 0)
value = MAX (value, id_to_csm_age[i].value);
}
return value;
}

View File

@ -0,0 +1,61 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2015-2016 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
G_BEGIN_DECLS
#include <glib-object.h>
#include <libmalcontent/malcontent.h>
typedef enum {
GS_CONTENT_RATING_SYSTEM_UNKNOWN,
GS_CONTENT_RATING_SYSTEM_INCAA,
GS_CONTENT_RATING_SYSTEM_ACB,
GS_CONTENT_RATING_SYSTEM_DJCTQ,
GS_CONTENT_RATING_SYSTEM_GSRR,
GS_CONTENT_RATING_SYSTEM_PEGI,
GS_CONTENT_RATING_SYSTEM_KAVI,
GS_CONTENT_RATING_SYSTEM_USK,
GS_CONTENT_RATING_SYSTEM_ESRA,
GS_CONTENT_RATING_SYSTEM_CERO,
GS_CONTENT_RATING_SYSTEM_OFLCNZ,
GS_CONTENT_RATING_SYSTEM_RUSSIA,
GS_CONTENT_RATING_SYSTEM_MDA,
GS_CONTENT_RATING_SYSTEM_GRAC,
GS_CONTENT_RATING_SYSTEM_ESRB,
GS_CONTENT_RATING_SYSTEM_IARC,
/*< private >*/
GS_CONTENT_RATING_SYSTEM_LAST
} GsContentRatingSystem;
const gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
guint age);
GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale);
const gchar *gs_content_rating_key_value_to_str (const gchar *id,
MctAppFilterOarsValue value);
const gchar *gs_content_rating_system_to_str (GsContentRatingSystem system);
const gchar * const *gs_utils_content_rating_get_values (GsContentRatingSystem system);
const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system);
guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value);
MctAppFilterOarsValue as_content_rating_id_csm_age_to_value (const gchar *id, guint age);
G_END_DECLS

37
malcontent-control/main.c Normal file
View File

@ -0,0 +1,37 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2019 Endless Mobile, 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:
* - Philip Withnall <withnall@endlessm.com>
*/
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include "application.h"
int
main (int argc,
char *argv[])
{
g_autoptr(MctApplication) app = NULL;
app = mct_application_new ();
return g_application_run (G_APPLICATION (app), argc, argv);
}

118
malcontent-control/main.ui Normal file
View File

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2019, 2020 Endless Mobile, Inc. -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkApplicationWindow" id="main_window">
<property name="default-width">500</property>
<property name="default-height">700</property>
<child>
<object class="GtkStack" id="main_stack">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="border_width">0</property>
<child>
<object class="MctUserSelector" id="user_selector">
<property name="visible">True</property>
<property name="user-manager">user_manager</property>
<accessibility>
<relation target="user_controls" type="controller-for"/>
</accessibility>
</object>
<packing>
<property name="fill">False</property>
<property name="expand">False</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">450</property>
<child>
<object class="MctUserControls" id="user_controls">
<property name="visible">True</property>
<property name="margin">12</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
</object>
<packing>
<property name="name">controls</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child type="center">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Loading…</property>
<attributes>
<attribute name="scale" value="1.4"/>
</attributes>
<child internal-child="accessible">
<object class="AtkObject">
<property name="AtkObject::accessible-role">static</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">loading</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child type="center">
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="error_title">
<property name="visible">True</property>
<property name="label"></property>
<attributes>
<attribute name="scale" value="1.4"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel" id="error_message">
<property name="visible">True</property>
<property name="label"></property>
</object>
</child>
</object>
</child>
<child internal-child="accessible">
<object class="AtkObject">
<property name="AtkObject::accessible-role">alert</property>
</object>
</child>
</object>
<packing>
<property name="name">error</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2019 Endless Mobile, Inc. -->
<gresources>
<gresource prefix="/org/freedesktop/MalcontentControl/ui">
<file>carousel.css</file>
<file preprocess="xml-stripblanks">carousel.ui</file>
<file preprocess="xml-stripblanks">main.ui</file>
<file preprocess="xml-stripblanks">user-controls.ui</file>
<file preprocess="xml-stripblanks">user-selector.ui</file>
</gresource>
</gresources>

View File

@ -0,0 +1,103 @@
application_id = 'org.freedesktop.MalcontentControl'
if not cc.has_function('atexit')
error('atexit() needed for generated GResource files')
endif
resources = gnome.compile_resources(
'resources',
'malcontent-control.gresource.xml',
source_dir: meson.source_root(),
)
malcontent_control = executable('malcontent-control',
[
'application.c',
'application.h',
'carousel.c',
'carousel.h',
'gs-content-rating.c',
'gs-content-rating.h',
'main.c',
'user-controls.c',
'user-controls.h',
'user-image.c',
'user-image.h',
'user-selector.c',
'user-selector.h',
] + resources,
dependencies: [
dependency('accountsservice'),
dependency('gio-2.0', version: '>= 2.44'),
dependency('glib-2.0', version: '>= 2.54.2'),
dependency('gobject-2.0', version: '>= 2.54'),
dependency('gtk+-3.0'),
dependency('flatpak'),
libmalcontent_dep,
],
include_directories: root_inc,
install: true,
)
desktop_file = i18n.merge_file('desktop-file',
type: 'desktop',
input: '@0@.desktop.in'.format(application_id),
output: '@0@.desktop'.format(application_id),
po_dir: join_paths(meson.source_root(), 'po'),
install: true,
install_dir: join_paths(get_option('datadir'), 'applications'),
)
desktop_file_validate = find_program('desktop-file-validate', required: false)
if desktop_file_validate.found()
test(
'validate-desktop',
desktop_file_validate,
args: [
desktop_file.full_path(),
],
suite: ['malcontent-control'],
)
endif
appdata_file = i18n.merge_file('appdata-file',
input: '@0@.appdata.xml.in'.format(application_id),
output: '@0@.appdata.xml'.format(application_id),
po_dir: join_paths(meson.source_root(), 'po'),
install: true,
install_dir: join_paths(get_option('datadir'), 'metainfo'),
)
appstream_util = find_program('appstream-util', required: false)
if appstream_util.found()
test(
'validate-appdata', appstream_util,
args: [
'validate-relax', '--nonet', appdata_file.full_path(),
],
suite: ['malcontent-control'],
)
endif
xmllint = find_program('xmllint', required: false)
if xmllint.found()
gtk_prefix = dependency('gtk+-3.0').get_pkgconfig_variable('prefix')
test(
'validate-ui', xmllint,
args: [
'--nonet', '--noblanks', '--noout',
'--relaxng', join_paths(gtk_prefix, 'share', 'gtk-3.0', 'gtkbuilder.rng'),
files(
'carousel.ui',
'main.ui',
'user-controls.ui',
'user-selector.ui',
),
],
suite: ['malcontent-control'],
)
endif
# FIXME: Add icons and tests
#subdir('icons')
#subdir('tests')

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2019 Endless Mobile, Inc. -->
<component type="desktop">
<id>org.freedesktop.MalcontentControl</id>
<metadata_license>CC-BY-SA-3.0</metadata_license>
<project_license>GPL-2.0+</project_license>
<!-- Translators: the name of the application as it appears in a software center -->
<name>Parental Controls</name>
<!-- Translators: the brief summary of the application as it appears in a software center. -->
<summary>Set parental controls and monitor usage by users</summary>
<description>
<!-- Translators: These are the application description paragraphs in the AppData file. -->
<p>
Manage users parental controls restrictions, controlling how long they
can use the computer for, what software they can install, and what
installed software they can run.
</p>
</description>
<!--
<screenshots>
<screenshot type="default" width="400" height="480">
<image>https://FIXME/malcontent-control.png</image>
</screenshot>
</screenshots>
-->
<provides>
<binary>malcontent-control</binary>
</provides>
<launchable type="desktop-id">org.freedesktop.MalcontentControl.desktop</launchable>
<url type="homepage">https://gitlab.freedesktop.org/pwithnall/malcontent</url>
<url type="bugtracker">https://gitlab.freedesktop.org/pwithnall/malcontent/issues</url>
<url type="donation">http://www.gnome.org/friends/</url>
<url type="translate">https://wiki.gnome.org/TranslationProject/LocalisationGuide</url>
<update_contact>philip_at_tecnocode.co.uk</update_contact>
<project_group>GNOME</project_group>
<developer_name>The GNOME Project</developer_name>
<kudos>
<kudo>AppMenu</kudo>
<kudo>HighContrast</kudo>
<kudo>ModernToolkit</kudo>
</kudos>
<translation type="gettext">malcontent</translation>
<releases>
<release version="0.4.0" date="2019-07-17" type="stable">
<description>
<ul>
<li>Maintenance release of underlying parental controls library</li>
</ul>
</description>
</release>
</releases>
<content_rating type="oars-1.1"/>
</component>

View File

@ -0,0 +1,12 @@
[Desktop Entry]
Name=Parental Controls
Comment=Set parental controls and monitor usage by users
Exec=malcontent-control
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
Icon=org.freedesktop.MalcontentControl
Terminal=false
Type=Application
Categories=GTK;GNOME;System;
StartupNotify=true
# Translators: Search terms to find this application. Do NOT translate or localise the semicolons! The list MUST also end with a semicolon!
Keywords=parental controls;screen time;app restrictions;web browser restrictions;oars;usage;usage limit;kid;child;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2018, 2019, 2020 Endless Mobile, 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 <georges.stavracas@gmail.com>
* - Philip Withnall <withnall@endlessm.com>
*/
#pragma once
#include <act/act.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define MCT_TYPE_USER_CONTROLS (mct_user_controls_get_type())
G_DECLARE_FINAL_TYPE (MctUserControls, mct_user_controls, MCT, USER_CONTROLS, GtkGrid)
ActUser *mct_user_controls_get_user (MctUserControls *self);
void mct_user_controls_set_user (MctUserControls *self,
ActUser *user);
GPermission *mct_user_controls_get_permission (MctUserControls *self);
void mct_user_controls_set_permission (MctUserControls *self,
GPermission *permission);
G_END_DECLS

View File

@ -0,0 +1,327 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2018, 2019, 2020 Endless, Inc. -->
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="MctUserControls" parent="GtkGrid">
<property name="visible">True</property>
<property name="margin-top">18</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<property name="valign">start</property>
<!-- Restricted Apps -->
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Restrict Apps</property>
<attributes>
<attribute name="weight" value="bold" />
</attributes>
<accessibility>
<relation target="listbox" type="label-for"/>
</accessibility>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Prevent this user from opening some apps by turning them off below.</property>
<property name="wrap">True</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">listbox</property>
<attributes>
<attribute name="scale" value="0.83333" />
</attributes>
<accessibility>
<relation target="listbox" type="description-for"/>
</accessibility>
<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="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">100</property>
<property name="max-content-height">400</property>
<property name="propagate-natural-height">True</property>
<property name="shadow-type">etched-in</property>
<!-- Restricted Apps Listbox -->
<child>
<object class="GtkListBox" id="listbox">
<property name="visible">True</property>
<property name="selection-mode">none</property>
</object>
</child>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<!-- Restricted Web Browsers -->
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Restrict Web Browsers</property>
<attributes>
<attribute name="weight" value="bold" />
</attributes>
<accessibility>
<relation target="allow_web_browsers_switch" type="label-for"/>
</accessibility>
</object>
<packing>
<property name="top-attach">3</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">Prevent this user from running web browsers by turning them off below. Note that if the computer is connected to the internet, limited web content may still be available in other applications.</property>
<property name="wrap">True</property>
<property name="max-width-chars">55</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">allow_web_browsers_switch</property>
<attributes>
<attribute name="scale" value="0.83333" />
</attributes>
<accessibility>
<relation target="allow_web_browsers_switch" type="description-for"/>
</accessibility>
<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="GtkBox">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="browsers_label">
<property name="visible">True</property>
<property name="xalign">1.0</property>
<property name="label" translatable="yes">Web _Browsers</property>
<property name="wrap">True</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">allow_web_browsers_switch</property>
<style>
<class name="dim-label" />
</style>
<accessibility>
<relation target="allow_web_browsers_switch" type="label-for"/>
</accessibility>
</object>
</child>
<child>
<object class="GtkSwitch" id="allow_web_browsers_switch">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="halign">start</property>
<signal name="notify::active" handler="on_allow_web_browsers_switch_active_changed_cb" object="MctUserControls" swapped="no" />
</object>
</child>
</object>
<packing>
<property name="top-attach">5</property>
<property name="left-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<!-- App Center Restrictions -->
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="margin-top">12</property>
<property name="xalign">0.0</property>
<property name="label" translatable="yes">App Center Restrictions</property>
<attributes>
<attribute name="weight" value="bold" />
</attributes>
</object>
<packing>
<property name="top-attach">6</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="user_installation_label">
<property name="visible" bind-source="allow_user_installation_switch" bind-property="visible" bind-flags="default|sync-create" />
<property name="xalign">1.0</property>
<property name="label" translatable="yes">App _Installation</property>
<property name="wrap">True</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">allow_user_installation_switch</property>
<style>
<class name="dim-label" />
</style>
<accessibility>
<relation target="allow_user_installation_switch" type="label-for"/>
</accessibility>
</object>
</child>
<child>
<object class="GtkSwitch" id="allow_user_installation_switch">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="halign">start</property>
<signal name="notify::active" handler="on_allow_installation_switch_active_changed_cb" object="MctUserControls" swapped="no" />
</object>
</child>
</object>
<packing>
<property name="top-attach">7</property>
<property name="left-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="system_installation_label">
<property name="visible" bind-source="allow_system_installation_switch" bind-property="visible" bind-flags="default|sync-create" />
<property name="xalign">1.0</property>
<property name="label" translatable="yes">Install Apps for All _Users</property>
<property name="wrap">True</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">allow_system_installation_switch</property>
<style>
<class name="dim-label" />
</style>
<accessibility>
<relation target="allow_system_installation_switch" type="label-for"/>
</accessibility>
</object>
</child>
<child>
<object class="GtkSwitch" id="allow_system_installation_switch">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="halign">start</property>
<signal name="notify::active" handler="on_allow_installation_switch_active_changed_cb" object="MctUserControls" swapped="no" />
</object>
</child>
</object>
<packing>
<property name="top-attach">8</property>
<property name="left-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="app_restriction_label">
<property name="visible">True</property>
<property name="xalign">1.0</property>
<property name="label" translatable="yes">Show Apps _Suitable For</property>
<property name="wrap">True</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">restriction_button</property>
<style>
<class name="dim-label" />
</style>
<accessibility>
<relation target="restriction_button" type="label-for"/>
<relation target="restriction_button" type="flows-to"/>
</accessibility>
</object>
</child>
<child>
<object class="GtkMenuButton" id="restriction_button">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="halign">start</property>
<property name="popover">restriction_popover</property>
<property name="width-request">200</property>
</object>
</child>
</object>
<packing>
<property name="top-attach">9</property>
<property name="left-attach">0</property>
<property name="width">2</property>
</packing>
</child>
</template>
<object class="GtkPopoverMenu" id="restriction_popover">
<accessibility>
<relation target="restriction_button" type="popup-for"/>
</accessibility>
</object>
<menu id="age_menu" />
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="restriction_button" />
<widget name="restriction_popover" />
</widgets>
</object>
<object class="GtkSizeGroup">
<property name="mode">horizontal</property>
<widgets>
<widget name="browsers_label" />
<widget name="app_restriction_label" />
<widget name="user_installation_label" />
<widget name="system_installation_label" />
</widgets>
</object>
</interface>

View File

@ -0,0 +1,174 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2015 Red Hat, 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:
* - Ondrej Holy <oholy@redhat.com>
*/
#include <gtk/gtk.h>
#include <act/act.h>
#include <sys/stat.h>
#include "user-image.h"
struct _MctUserImage
{
GtkImage parent_instance;
ActUser *user;
};
G_DEFINE_TYPE (MctUserImage, mct_user_image, GTK_TYPE_IMAGE)
static GdkPixbuf *
round_image (GdkPixbuf *pixbuf)
{
GdkPixbuf *dest = NULL;
cairo_surface_t *surface;
cairo_t *cr;
gint size;
size = gdk_pixbuf_get_width (pixbuf);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
cr = cairo_create (surface);
/* Clip a circle */
cairo_arc (cr, size / 2, size / 2, size / 2, 0, 2 * G_PI);
cairo_clip (cr);
cairo_new_path (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
dest = gdk_pixbuf_get_from_surface (surface, 0, 0, size, size);
cairo_surface_destroy (surface);
cairo_destroy (cr);
return dest;
}
static cairo_surface_t *
render_user_icon (ActUser *user,
gint icon_size,
gint scale)
{
g_autoptr(GdkPixbuf) source_pixbuf = NULL;
GdkPixbuf *pixbuf = NULL;
GError *error;
const gchar *icon_file;
cairo_surface_t *surface = NULL;
g_return_val_if_fail (ACT_IS_USER (user), NULL);
g_return_val_if_fail (icon_size > 12, NULL);
icon_file = act_user_get_icon_file (user);
pixbuf = NULL;
if (icon_file)
{
source_pixbuf = gdk_pixbuf_new_from_file_at_size (icon_file,
icon_size * scale,
icon_size * scale,
NULL);
if (source_pixbuf)
pixbuf = round_image (source_pixbuf);
}
if (pixbuf != NULL)
goto out;
error = NULL;
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"avatar-default",
icon_size * scale,
GTK_ICON_LOOKUP_FORCE_SIZE,
&error);
if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
}
out:
if (pixbuf != NULL)
{
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
g_object_unref (pixbuf);
}
return surface;
}
static void
render_image (MctUserImage *image)
{
cairo_surface_t *surface;
gint scale, pixel_size;
if (image->user == NULL)
return;
pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (image));
scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
surface = render_user_icon (image->user,
pixel_size > 0 ? pixel_size : 48,
scale);
gtk_image_set_from_surface (GTK_IMAGE (image), surface);
cairo_surface_destroy (surface);
}
void
mct_user_image_set_user (MctUserImage *image,
ActUser *user)
{
g_clear_object (&image->user);
image->user = g_object_ref (user);
render_image (image);
}
static void
mct_user_image_finalize (GObject *object)
{
MctUserImage *image = MCT_USER_IMAGE (object);
g_clear_object (&image->user);
G_OBJECT_CLASS (mct_user_image_parent_class)->finalize (object);
}
static void
mct_user_image_class_init (MctUserImageClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = mct_user_image_finalize;
}
static void
mct_user_image_init (MctUserImage *image)
{
g_signal_connect_swapped (image, "notify::scale-factor", G_CALLBACK (render_image), image);
g_signal_connect_swapped (image, "notify::pixel-size", G_CALLBACK (render_image), image);
}
GtkWidget *
mct_user_image_new (void)
{
return g_object_new (MCT_TYPE_USER_IMAGE, NULL);
}

View File

@ -0,0 +1,37 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2015 Red Hat, 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:
* - Ondrej Holy <oholy@redhat.com>
*/
#pragma once
#include <gtk/gtk.h>
#include <act/act.h>
G_BEGIN_DECLS
#define MCT_TYPE_USER_IMAGE (mct_user_image_get_type ())
G_DECLARE_FINAL_TYPE (MctUserImage, mct_user_image, MCT, USER_IMAGE, GtkImage)
GtkWidget *mct_user_image_new (void);
void mct_user_image_set_user (MctUserImage *image,
ActUser *user);
G_END_DECLS

View File

@ -0,0 +1,470 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2020 Endless Mobile, 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:
* - Philip Withnall <withnall@endlessm.com>
*/
#include <act/act.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "carousel.h"
#include "user-image.h"
#include "user-selector.h"
static void reload_users (MctUserSelector *self,
ActUser *selected_user);
static void notify_is_loaded_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data);
static void user_added_cb (ActUserManager *user_manager,
ActUser *user,
gpointer user_data);
static void user_changed_or_removed_cb (ActUserManager *user_manager,
ActUser *user,
gpointer user_data);
static void carousel_item_activated (MctCarousel *carousel,
MctCarouselItem *item,
gpointer user_data);
/**
* MctUserSelector:
*
* The user selector is a widget which lists available user accounts and allows
* the user to select one.
*
* Since: 0.5.0
*/
struct _MctUserSelector
{
GtkBox parent_instance;
MctCarousel *carousel;
ActUserManager *user_manager; /* (owned) */
ActUser *user; /* (owned) */
};
G_DEFINE_TYPE (MctUserSelector, mct_user_selector, GTK_TYPE_BOX)
typedef enum
{
PROP_USER = 1,
PROP_USER_MANAGER,
} MctUserSelectorProperty;
static GParamSpec *properties[PROP_USER_MANAGER + 1];
static void
mct_user_selector_constructed (GObject *obj)
{
MctUserSelector *self = MCT_USER_SELECTOR (obj);
g_assert (self->user_manager != NULL);
g_signal_connect (self->user_manager, "user-changed",
G_CALLBACK (user_changed_or_removed_cb), self);
g_signal_connect (self->user_manager, "user-is-logged-in-changed",
G_CALLBACK (user_changed_or_removed_cb), self);
g_signal_connect (self->user_manager, "user-added",
G_CALLBACK (user_added_cb), self);
g_signal_connect (self->user_manager, "user-removed",
G_CALLBACK (user_changed_or_removed_cb), self);
g_signal_connect (self->user_manager, "notify::is-loaded",
G_CALLBACK (notify_is_loaded_cb), self);
/* Start loading the user accounts. */
notify_is_loaded_cb (G_OBJECT (self->user_manager), NULL, self);
G_OBJECT_CLASS (mct_user_selector_parent_class)->constructed (obj);
}
static void
mct_user_selector_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MctUserSelector *self = MCT_USER_SELECTOR (object);
switch ((MctUserSelectorProperty) prop_id)
{
case PROP_USER:
g_value_set_object (value, self->user);
break;
case PROP_USER_MANAGER:
g_value_set_object (value, self->user_manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
mct_user_selector_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MctUserSelector *self = MCT_USER_SELECTOR (object);
switch ((MctUserSelectorProperty) prop_id)
{
case PROP_USER:
/* Currently read only */
g_assert_not_reached ();
break;
case PROP_USER_MANAGER:
g_assert (self->user_manager == NULL);
self->user_manager = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
mct_user_selector_dispose (GObject *object)
{
MctUserSelector *self = (MctUserSelector *)object;
g_clear_object (&self->user);
if (self->user_manager != NULL)
{
g_signal_handlers_disconnect_by_func (self->user_manager, notify_is_loaded_cb, self);
g_signal_handlers_disconnect_by_func (self->user_manager, user_changed_or_removed_cb, self);
g_signal_handlers_disconnect_by_func (self->user_manager, user_added_cb, self);
g_clear_object (&self->user_manager);
}
G_OBJECT_CLASS (mct_user_selector_parent_class)->dispose (object);
}
static void
mct_user_selector_class_init (MctUserSelectorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = mct_user_selector_constructed;
object_class->get_property = mct_user_selector_get_property;
object_class->set_property = mct_user_selector_set_property;
object_class->dispose = mct_user_selector_dispose;
/**
* MctUserSelector:user: (nullable)
*
* The currently selected user account, or %NULL if no user is selected.
* Currently read only but may become writable in future.
*
* Since: 0.5.0
*/
properties[PROP_USER] =
g_param_spec_object ("user",
"User",
"The currently selected user account, or %NULL if no user is selected.",
ACT_TYPE_USER,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* MctUserSelector:user-manager: (not nullable)
*
* The user manager providing the data for the widget.
*
* Since: 0.5.0
*/
properties[PROP_USER_MANAGER] =
g_param_spec_object ("user-manager",
"User Manager",
"The user manager providing the data for the widget.",
ACT_TYPE_USER_MANAGER,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentControl/ui/user-selector.ui");
gtk_widget_class_bind_template_child (widget_class, MctUserSelector, carousel);
gtk_widget_class_bind_template_callback (widget_class, carousel_item_activated);
}
static void
mct_user_selector_init (MctUserSelector *self)
{
/* Ensure the types used in the UI are registered. */
g_type_ensure (MCT_TYPE_CAROUSEL);
gtk_widget_init_template (GTK_WIDGET (self));
}
static void
notify_is_loaded_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
MctUserSelector *self = MCT_USER_SELECTOR (user_data);
gboolean is_loaded;
/* The implementation of #ActUserManager guarantees that once is-loaded is
* true, it is never reset to false. */
g_object_get (self->user_manager, "is-loaded", &is_loaded, NULL);
if (is_loaded)
reload_users (self, NULL);
}
static const gchar *
get_real_or_user_name (ActUser *user)
{
const gchar *name;
name = act_user_get_real_name (user);
if (name == NULL)
name = act_user_get_user_name (user);
return name;
}
static void
carousel_item_activated (MctCarousel *carousel,
MctCarouselItem *item,
gpointer user_data)
{
MctUserSelector *self = MCT_USER_SELECTOR (user_data);
uid_t uid;
ActUser *user = NULL;
g_clear_object (&self->user);
uid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "uid"));
user = act_user_manager_get_user_by_id (self->user_manager, uid);
if (g_set_object (&self->user, user))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER]);
}
static gint
sort_users (gconstpointer a,
gconstpointer b)
{
ActUser *ua, *ub;
gint result;
ua = ACT_USER (a);
ub = ACT_USER (b);
/* Make sure the current user is shown first */
if (act_user_get_uid (ua) == getuid ())
{
result = G_MININT32;
}
else if (act_user_get_uid (ub) == getuid ())
{
result = G_MAXINT32;
}
else
{
g_autofree gchar *name1 = NULL, *name2 = NULL;
name1 = g_utf8_collate_key (get_real_or_user_name (ua), -1);
name2 = g_utf8_collate_key (get_real_or_user_name (ub), -1);
result = strcmp (name1, name2);
}
return result;
}
static gint
user_compare (gconstpointer i,
gconstpointer u)
{
MctCarouselItem *item;
ActUser *user;
gint uid_a, uid_b;
gint result;
item = (MctCarouselItem *) i;
user = ACT_USER (u);
uid_a = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "uid"));
uid_b = act_user_get_uid (user);
result = uid_a - uid_b;
return result;
}
static void
reload_users (MctUserSelector *self,
ActUser *selected_user)
{
ActUser *user;
g_autoptr(GSList) list = NULL;
GSList *l;
MctCarouselItem *item = NULL;
GtkSettings *settings;
gboolean animations;
settings = gtk_widget_get_settings (GTK_WIDGET (self->carousel));
g_object_get (settings, "gtk-enable-animations", &animations, NULL);
g_object_set (settings, "gtk-enable-animations", FALSE, NULL);
mct_carousel_purge_items (self->carousel);
list = act_user_manager_list_users (self->user_manager);
g_debug ("Got %u users", g_slist_length (list));
list = g_slist_sort (list, (GCompareFunc) sort_users);
for (l = list; l; l = l->next)
{
user = l->data;
g_debug ("Adding user %s", get_real_or_user_name (user));
user_added_cb (self->user_manager, user, self);
}
if (selected_user)
item = mct_carousel_find_item (self->carousel, selected_user, user_compare);
mct_carousel_select_item (self->carousel, item);
g_object_set (settings, "gtk-enable-animations", animations, NULL);
gtk_revealer_set_reveal_child (GTK_REVEALER (self->carousel), TRUE);
}
static GtkWidget *
create_carousel_entry (MctUserSelector *self,
ActUser *user)
{
GtkWidget *box, *widget;
gchar *label;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
widget = mct_user_image_new ();
mct_user_image_set_user (MCT_USER_IMAGE (widget), user);
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
label = g_strdup_printf ("<b>%s</b>",
get_real_or_user_name (user));
widget = gtk_label_new (label);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END);
gtk_widget_set_margin_top (widget, 5);
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
g_free (label);
if (act_user_get_uid (user) == getuid ())
label = g_strdup_printf ("<small>%s</small>", _("Your account"));
else
label = g_strdup (" ");
widget = gtk_label_new (label);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
g_free (label);
gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
gtk_style_context_add_class (gtk_widget_get_style_context (widget),
"dim-label");
return box;
}
static void
user_added_cb (ActUserManager *user_manager,
ActUser *user,
gpointer user_data)
{
MctUserSelector *self = MCT_USER_SELECTOR (user_data);
GtkWidget *item, *widget;
if (act_user_is_system_account (user))
return;
g_debug ("User added: %u %s", (guint) act_user_get_uid (user), get_real_or_user_name (user));
widget = create_carousel_entry (self, user);
item = mct_carousel_item_new ();
gtk_container_add (GTK_CONTAINER (item), widget);
g_object_set_data (G_OBJECT (item), "uid", GINT_TO_POINTER (act_user_get_uid (user)));
gtk_container_add (GTK_CONTAINER (self->carousel), item);
}
static void
user_changed_or_removed_cb (ActUserManager *user_manager,
ActUser *user,
gpointer user_data)
{
MctUserSelector *self = MCT_USER_SELECTOR (user_data);
reload_users (self, self->user);
}
/**
* mct_user_selector_new:
* @user_manager: (transfer none): an #ActUserManager to provide the user data
*
* Create a new #MctUserSelector widget.
*
* Returns: (transfer full): a new user selector
* Since: 0.5.0
*/
MctUserSelector *
mct_user_selector_new (ActUserManager *user_manager)
{
g_return_val_if_fail (ACT_IS_USER_MANAGER (user_manager), NULL);
return g_object_new (MCT_TYPE_USER_SELECTOR,
"user-manager", user_manager,
NULL);
}
/**
* mct_user_selector_get_user:
* @self: an #MctUserSelector
*
* Get the currently selected user, or %NULL if no user is selected.
*
* Returns: (transfer none) (nullable): the currently selected user
* Since: 0.5.0
*/
ActUser *
mct_user_selector_get_user (MctUserSelector *self)
{
g_return_val_if_fail (MCT_IS_USER_SELECTOR (self), NULL);
return self->user;
}

View File

@ -0,0 +1,37 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2020 Endless Mobile, 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:
* - Philip Withnall <withnall@endlessm.com>
*/
#pragma once
#include <act/act.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define MCT_TYPE_USER_SELECTOR (mct_user_selector_get_type ())
G_DECLARE_FINAL_TYPE (MctUserSelector, mct_user_selector, MCT, USER_SELECTOR, GtkBox)
MctUserSelector *mct_user_selector_new (ActUserManager *user_manager);
ActUser *mct_user_selector_get_user (MctUserSelector *self);
G_END_DECLS

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright © 2020 Endless, Inc. -->
<interface>
<requires lib="gtk+" version="3.12"/>
<template class="MctUserSelector" parent="GtkBox">
<child>
<object class="MctCarousel" id="carousel">
<property name="visible">True</property>
<property name="hexpand">True</property>
<signal name="item-activated" handler="carousel_item_activated"/>
</object>
</child>
</template>
</interface>

View File

@ -48,6 +48,7 @@ libglib_testing_dep = dependency(
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name())
config_h.set_quoted('PACKAGE_LOCALE_DIR', join_paths(get_option('localedir'), meson.project_name()))
configure_file(
output: 'config.h',
configuration: config_h,
@ -126,6 +127,8 @@ test_env = [
]
subdir('accounts-service')
subdir('malcontent-client')
subdir('libmalcontent')
subdir('malcontent-client')
subdir('malcontent-control')
subdir('pam')
subdir('po')

1
po/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
malcontent.pot

View File

@ -1,5 +1,12 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
accounts-service/com.endlessm.ParentalControls.policy
accounts-service/com.endlessm.ParentalControls.policy.in
libmalcontent/manager.c
malcontent-control/application.c
malcontent-control/gs-content-rating.c
malcontent-control/main.ui
malcontent-control/org.freedesktop.MalcontentControl.appdata.xml.in
malcontent-control/org.freedesktop.MalcontentControl.desktop.in
malcontent-control/user-controls.c
malcontent-control/user-controls.ui
pam/pam_malcontent.c