libmalcontent-ui: Move widgets over from malcontent-control
They need to be re-used in gnome-initial-setup. The other widgets which remain in malcontent-control don’t need to be used in g-i-s so can stay where they are for now. They might move across to libmalcontent-ui later if there’s a need for it. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
3289a37317
commit
1f3f0a4560
18 changed files with 29 additions and 25 deletions
|
@ -27,10 +27,10 @@
|
|||
#include <glib/gi18n-lib.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libmalcontent-ui/malcontent-ui.h>
|
||||
#include <polkit/polkit.h>
|
||||
|
||||
#include "application.h"
|
||||
#include "user-controls.h"
|
||||
#include "user-selector.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,968 +0,0 @@
|
|||
/* -*- 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 can’t 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;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/* -*- 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
|
|
@ -5,9 +5,6 @@
|
|||
<file>carousel.css</file>
|
||||
<file preprocess="xml-stripblanks">carousel.ui</file>
|
||||
<file preprocess="xml-stripblanks">main.ui</file>
|
||||
<file preprocess="xml-stripblanks">restrict-applications-dialog.ui</file>
|
||||
<file preprocess="xml-stripblanks">restrict-applications-selector.ui</file>
|
||||
<file preprocess="xml-stripblanks">user-controls.ui</file>
|
||||
<file preprocess="xml-stripblanks">user-selector.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
|
@ -16,15 +16,7 @@ malcontent_control = executable('malcontent-control',
|
|||
'application.h',
|
||||
'carousel.c',
|
||||
'carousel.h',
|
||||
'gs-content-rating.c',
|
||||
'gs-content-rating.h',
|
||||
'main.c',
|
||||
'restrict-applications-dialog.c',
|
||||
'restrict-applications-dialog.h',
|
||||
'restrict-applications-selector.c',
|
||||
'restrict-applications-selector.h',
|
||||
'user-controls.c',
|
||||
'user-controls.h',
|
||||
'user-image.c',
|
||||
'user-image.h',
|
||||
'user-selector.c',
|
||||
|
@ -39,6 +31,7 @@ malcontent_control = executable('malcontent-control',
|
|||
dependency('flatpak'),
|
||||
dependency('polkit-gobject-1'),
|
||||
libmalcontent_dep,
|
||||
libmalcontent_ui_dep,
|
||||
],
|
||||
include_directories: root_inc,
|
||||
install: true,
|
||||
|
@ -95,9 +88,6 @@ if xmllint.found()
|
|||
files(
|
||||
'carousel.ui',
|
||||
'main.ui',
|
||||
'restrict-applications-dialog.ui',
|
||||
'restrict-applications-selector.ui',
|
||||
'user-controls.ui',
|
||||
'user-selector.ui',
|
||||
),
|
||||
],
|
||||
|
|
|
@ -1,382 +0,0 @@
|
|||
/* -*- 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 "restrict-applications-dialog.h"
|
||||
#include "restrict-applications-selector.h"
|
||||
|
||||
|
||||
static void update_description (MctRestrictApplicationsDialog *self);
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsDialog:
|
||||
*
|
||||
* The ‘Restrict Applications’ dialog is a dialog which shows the available
|
||||
* applications on the system alongside a column of toggle switches, which
|
||||
* allows the given user to be prevented from running each application.
|
||||
*
|
||||
* The dialog contains a single #MctRestrictApplicationsSelector. It takes a
|
||||
* #MctRestrictApplicationsDialog:user and
|
||||
* #MctRestrictApplicationsDialog:app-filter as input to set up the UI, and
|
||||
* returns its output as set of modifications to a given #MctAppFilterBuilder
|
||||
* using mct_restrict_applications_dialog_build_app_filter().
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
struct _MctRestrictApplicationsDialog
|
||||
{
|
||||
GtkDialog parent_instance;
|
||||
|
||||
MctRestrictApplicationsSelector *selector;
|
||||
GtkLabel *description;
|
||||
|
||||
MctAppFilter *app_filter; /* (owned) (not nullable) */
|
||||
ActUser *user; /* (owned) (nullable) */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, GTK_TYPE_DIALOG)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PROP_APP_FILTER = 1,
|
||||
PROP_USER,
|
||||
} MctRestrictApplicationsDialogProperty;
|
||||
|
||||
static GParamSpec *properties[PROP_USER + 1];
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_constructed (GObject *obj)
|
||||
{
|
||||
MctRestrictApplicationsDialog *self = MCT_RESTRICT_APPLICATIONS_DIALOG (obj);
|
||||
|
||||
g_assert (self->app_filter != NULL);
|
||||
g_assert (self->user == NULL || ACT_IS_USER (self->user));
|
||||
|
||||
G_OBJECT_CLASS (mct_restrict_applications_dialog_parent_class)->constructed (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctRestrictApplicationsDialog *self = MCT_RESTRICT_APPLICATIONS_DIALOG (object);
|
||||
|
||||
switch ((MctRestrictApplicationsDialogProperty) prop_id)
|
||||
{
|
||||
case PROP_APP_FILTER:
|
||||
g_value_set_boxed (value, self->app_filter);
|
||||
break;
|
||||
|
||||
case PROP_USER:
|
||||
g_value_set_object (value, self->user);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctRestrictApplicationsDialog *self = MCT_RESTRICT_APPLICATIONS_DIALOG (object);
|
||||
|
||||
switch ((MctRestrictApplicationsDialogProperty) prop_id)
|
||||
{
|
||||
case PROP_APP_FILTER:
|
||||
mct_restrict_applications_dialog_set_app_filter (self, g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
case PROP_USER:
|
||||
mct_restrict_applications_dialog_set_user (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_dispose (GObject *object)
|
||||
{
|
||||
MctRestrictApplicationsDialog *self = (MctRestrictApplicationsDialog *)object;
|
||||
|
||||
g_clear_pointer (&self->app_filter, mct_app_filter_unref);
|
||||
g_clear_object (&self->user);
|
||||
|
||||
G_OBJECT_CLASS (mct_restrict_applications_dialog_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_class_init (MctRestrictApplicationsDialogClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->constructed = mct_restrict_applications_dialog_constructed;
|
||||
object_class->get_property = mct_restrict_applications_dialog_get_property;
|
||||
object_class->set_property = mct_restrict_applications_dialog_set_property;
|
||||
object_class->dispose = mct_restrict_applications_dialog_dispose;
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsDialog:app-filter: (not nullable)
|
||||
*
|
||||
* The user’s current app filter, used to set up the dialog. As app filters
|
||||
* are immutable, it is not updated as the dialog is changed. Use
|
||||
* mct_restrict_applications_dialog_build_app_filter() to build the new app
|
||||
* filter.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
properties[PROP_APP_FILTER] =
|
||||
g_param_spec_boxed ("app-filter",
|
||||
"App Filter",
|
||||
"The user’s current app filter, used to set up the dialog.",
|
||||
MCT_TYPE_APP_FILTER,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsDialog:user: (nullable)
|
||||
*
|
||||
* The currently selected user account, or %NULL if no user is selected.
|
||||
*
|
||||
* 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_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/restrict-applications-dialog.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, selector);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsDialog, description);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_dialog_init (MctRestrictApplicationsDialog *self)
|
||||
{
|
||||
/* Ensure the types used in the UI are registered. */
|
||||
g_type_ensure (MCT_TYPE_RESTRICT_APPLICATIONS_SELECTOR);
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
get_user_display_name (ActUser *user)
|
||||
{
|
||||
const gchar *display_name;
|
||||
|
||||
g_return_val_if_fail (ACT_IS_USER (user), _("unknown"));
|
||||
|
||||
display_name = act_user_get_real_name (user);
|
||||
if (display_name != NULL)
|
||||
return display_name;
|
||||
|
||||
display_name = act_user_get_user_name (user);
|
||||
if (display_name != NULL)
|
||||
return display_name;
|
||||
|
||||
/* Translators: this is the full name for an unknown user account. */
|
||||
return _("unknown");
|
||||
}
|
||||
|
||||
static void
|
||||
update_description (MctRestrictApplicationsDialog *self)
|
||||
{
|
||||
g_autofree gchar *description = NULL;
|
||||
|
||||
if (self->user == NULL)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (self->description));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Translators: the placeholder is a user’s full name */
|
||||
description = g_strdup_printf (_("Allow %s to use the following installed applications."),
|
||||
get_user_display_name (self->user));
|
||||
gtk_label_set_text (self->description, description);
|
||||
gtk_widget_show (GTK_WIDGET (self->description));
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_new:
|
||||
* @app_filter: (transfer none): the initial app filter configuration to show
|
||||
* @user: (transfer none) (nullable): the user to show the app filter for
|
||||
*
|
||||
* Create a new #MctRestrictApplicationsDialog widget.
|
||||
*
|
||||
* Returns: (transfer full): a new restricted applications editing dialog
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
MctRestrictApplicationsDialog *
|
||||
mct_restrict_applications_dialog_new (MctAppFilter *app_filter,
|
||||
ActUser *user)
|
||||
{
|
||||
g_return_val_if_fail (app_filter != NULL, NULL);
|
||||
g_return_val_if_fail (user == NULL || ACT_IS_USER (user), NULL);
|
||||
|
||||
return g_object_new (MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG,
|
||||
"app-filter", app_filter,
|
||||
"user", user,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_get_app_filter:
|
||||
* @self: an #MctRestrictApplicationsDialog
|
||||
*
|
||||
* Get the value of #MctRestrictApplicationsDialog:app-filter. If the property
|
||||
* was originally set to %NULL, this will be the empty app filter.
|
||||
*
|
||||
* Returns: (transfer none) (not nullable): the initial app filter used to
|
||||
* populate the dialog
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
MctAppFilter *
|
||||
mct_restrict_applications_dialog_get_app_filter (MctRestrictApplicationsDialog *self)
|
||||
{
|
||||
g_return_val_if_fail (MCT_IS_RESTRICT_APPLICATIONS_DIALOG (self), NULL);
|
||||
|
||||
return self->app_filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_set_app_filter:
|
||||
* @self: an #MctRestrictApplicationsDialog
|
||||
* @app_filter: (nullable) (transfer none): the app filter to configure the dialog
|
||||
* from, or %NULL to use an empty app filter
|
||||
*
|
||||
* Set the value of #MctRestrictApplicationsDialog:app-filter.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
void
|
||||
mct_restrict_applications_dialog_set_app_filter (MctRestrictApplicationsDialog *self,
|
||||
MctAppFilter *app_filter)
|
||||
{
|
||||
g_autoptr(MctAppFilter) owned_app_filter = NULL;
|
||||
|
||||
g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_DIALOG (self));
|
||||
|
||||
/* Default app filter, typically for when we’re instantiated by #GtkBuilder. */
|
||||
if (app_filter == NULL)
|
||||
{
|
||||
g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
|
||||
owned_app_filter = mct_app_filter_builder_end (&builder);
|
||||
app_filter = owned_app_filter;
|
||||
}
|
||||
|
||||
if (app_filter == self->app_filter)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&self->app_filter, mct_app_filter_unref);
|
||||
self->app_filter = mct_app_filter_ref (app_filter);
|
||||
|
||||
mct_restrict_applications_selector_set_app_filter (self->selector, self->app_filter);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_APP_FILTER]);
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_get_user:
|
||||
* @self: an #MctRestrictApplicationsDialog
|
||||
*
|
||||
* Get the value of #MctRestrictApplicationsDialog:user.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the user the dialog is configured for,
|
||||
* or %NULL if unknown
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
ActUser *
|
||||
mct_restrict_applications_dialog_get_user (MctRestrictApplicationsDialog *self)
|
||||
{
|
||||
g_return_val_if_fail (MCT_IS_RESTRICT_APPLICATIONS_DIALOG (self), NULL);
|
||||
|
||||
return self->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_set_user:
|
||||
* @self: an #MctRestrictApplicationsDialog
|
||||
* @user: (nullable) (transfer none): the user to configure the dialog for,
|
||||
* or %NULL if unknown
|
||||
*
|
||||
* Set the value of #MctRestrictApplicationsDialog:user.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
void
|
||||
mct_restrict_applications_dialog_set_user (MctRestrictApplicationsDialog *self,
|
||||
ActUser *user)
|
||||
{
|
||||
g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_DIALOG (self));
|
||||
g_return_if_fail (user == NULL || ACT_IS_USER (user));
|
||||
|
||||
if (g_set_object (&self->user, user))
|
||||
{
|
||||
update_description (self);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_dialog_build_app_filter:
|
||||
* @self: an #MctRestrictApplicationsDialog
|
||||
* @builder: an existing #MctAppFilterBuilder to modify
|
||||
*
|
||||
* Get the app filter settings currently configured in the dialog, by modifying
|
||||
* the given @builder.
|
||||
*
|
||||
* Typically this will be called in the handler for #GtkDialog::response.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
void
|
||||
mct_restrict_applications_dialog_build_app_filter (MctRestrictApplicationsDialog *self,
|
||||
MctAppFilterBuilder *builder)
|
||||
{
|
||||
g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_DIALOG (self));
|
||||
g_return_if_fail (builder != NULL);
|
||||
|
||||
mct_restrict_applications_selector_build_app_filter (self->selector, builder);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* -*- 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 <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libmalcontent/manager.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG (mct_restrict_applications_dialog_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MctRestrictApplicationsDialog, mct_restrict_applications_dialog, MCT, RESTRICT_APPLICATIONS_DIALOG, GtkDialog)
|
||||
|
||||
MctRestrictApplicationsDialog *mct_restrict_applications_dialog_new (MctAppFilter *app_filter,
|
||||
ActUser *user);
|
||||
|
||||
MctAppFilter *mct_restrict_applications_dialog_get_app_filter (MctRestrictApplicationsDialog *self);
|
||||
void mct_restrict_applications_dialog_set_app_filter (MctRestrictApplicationsDialog *self,
|
||||
MctAppFilter *app_filter);
|
||||
|
||||
ActUser *mct_restrict_applications_dialog_get_user (MctRestrictApplicationsDialog *self);
|
||||
void mct_restrict_applications_dialog_set_user (MctRestrictApplicationsDialog *self,
|
||||
ActUser *user);
|
||||
|
||||
void mct_restrict_applications_dialog_build_app_filter (MctRestrictApplicationsDialog *self,
|
||||
MctAppFilterBuilder *builder);
|
||||
|
||||
G_END_DECLS
|
|
@ -1,56 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright © 2020 Endless, Inc. -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<template class="MctRestrictApplicationsDialog" parent="GtkDialog">
|
||||
<property name="title" translatable="yes">Restrict Applications</property>
|
||||
<property name="skip-taskbar-hint">True</property>
|
||||
<property name="default-width">300</property>
|
||||
<property name="default-height">500</property>
|
||||
<child internal-child="headerbar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="title" translatable="yes">Restrict Applications</property>
|
||||
<property name="show-close-button">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="margin">18</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="description">
|
||||
<!-- Translated dynamically: -->
|
||||
<property name="label">Allow {username} to use the following installed applications.</property>
|
||||
<property name="visible">False</property>
|
||||
<child internal-child="accessible">
|
||||
<object class="AtkObject">
|
||||
<property name="accessible-role">static</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="MctRestrictApplicationsSelector" id="selector">
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="action">
|
||||
<object class="GtkButton" id="button_save">
|
||||
<property name="can-default">True</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Save</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="apply" default="true">button_save</action-widget>
|
||||
</action-widgets>
|
||||
</template>
|
||||
</interface>
|
|
@ -1,670 +0,0 @@
|
|||
/* -*- 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 <flatpak.h>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libmalcontent/app-filter.h>
|
||||
|
||||
#include "restrict-applications-selector.h"
|
||||
|
||||
|
||||
#define WEB_BROWSERS_CONTENT_TYPE "x-scheme-handler/http"
|
||||
|
||||
static void app_info_changed_cb (GAppInfoMonitor *monitor,
|
||||
gpointer user_data);
|
||||
static void reload_apps (MctRestrictApplicationsSelector *self);
|
||||
static GtkWidget *create_row_for_app_cb (gpointer item,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsSelector:
|
||||
*
|
||||
* The ‘Restrict Applications’ selector is a list box which shows the available
|
||||
* applications on the system alongside a column of toggle switches, which
|
||||
* allows the given user to be prevented from running each application.
|
||||
*
|
||||
* The selector takes an #MctRestrictApplicationsSelector:app-filter as input
|
||||
* to set up the UI, and returns its output as set of modifications to a given
|
||||
* #MctAppFilterBuilder using
|
||||
* mct_restrict_applications_selector_build_app_filter().
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
struct _MctRestrictApplicationsSelector
|
||||
{
|
||||
GtkBox parent_instance;
|
||||
|
||||
GtkListBox *listbox;
|
||||
|
||||
GListStore *apps; /* (owned) */
|
||||
GAppInfoMonitor *app_info_monitor; /* (owned) */
|
||||
gulong app_info_monitor_changed_id;
|
||||
GHashTable *blacklisted_apps; /* (owned) (element-type GAppInfo) */
|
||||
|
||||
MctAppFilter *app_filter; /* (owned) */
|
||||
|
||||
FlatpakInstallation *system_installation; /* (owned) */
|
||||
FlatpakInstallation *user_installation; /* (owned) */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MctRestrictApplicationsSelector, mct_restrict_applications_selector, GTK_TYPE_BOX)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PROP_APP_FILTER = 1,
|
||||
} MctRestrictApplicationsSelectorProperty;
|
||||
|
||||
static GParamSpec *properties[PROP_APP_FILTER + 1];
|
||||
|
||||
enum {
|
||||
SIGNAL_CHANGED,
|
||||
};
|
||||
|
||||
static guint signals[SIGNAL_CHANGED + 1];
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_constructed (GObject *obj)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (obj);
|
||||
|
||||
/* Default app filter, typically for when we’re instantiated by #GtkBuilder. */
|
||||
if (self->app_filter == NULL)
|
||||
{
|
||||
g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
|
||||
self->app_filter = mct_app_filter_builder_end (&builder);
|
||||
}
|
||||
|
||||
g_assert (self->app_filter != NULL);
|
||||
|
||||
G_OBJECT_CLASS (mct_restrict_applications_selector_parent_class)->constructed (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (object);
|
||||
|
||||
switch ((MctRestrictApplicationsSelectorProperty) prop_id)
|
||||
{
|
||||
case PROP_APP_FILTER:
|
||||
g_value_set_boxed (value, self->app_filter);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (object);
|
||||
|
||||
switch ((MctRestrictApplicationsSelectorProperty) prop_id)
|
||||
{
|
||||
case PROP_APP_FILTER:
|
||||
mct_restrict_applications_selector_set_app_filter (self, g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_dispose (GObject *object)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = (MctRestrictApplicationsSelector *)object;
|
||||
|
||||
g_clear_pointer (&self->blacklisted_apps, g_hash_table_unref);
|
||||
g_clear_object (&self->apps);
|
||||
|
||||
if (self->app_info_monitor != NULL && self->app_info_monitor_changed_id != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (self->app_info_monitor, self->app_info_monitor_changed_id);
|
||||
self->app_info_monitor_changed_id = 0;
|
||||
}
|
||||
g_clear_object (&self->app_info_monitor);
|
||||
g_clear_pointer (&self->app_filter, mct_app_filter_unref);
|
||||
g_clear_object (&self->system_installation);
|
||||
g_clear_object (&self->user_installation);
|
||||
|
||||
G_OBJECT_CLASS (mct_restrict_applications_selector_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_class_init (MctRestrictApplicationsSelectorClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->constructed = mct_restrict_applications_selector_constructed;
|
||||
object_class->get_property = mct_restrict_applications_selector_get_property;
|
||||
object_class->set_property = mct_restrict_applications_selector_set_property;
|
||||
object_class->dispose = mct_restrict_applications_selector_dispose;
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsSelector:app-filter: (not nullable)
|
||||
*
|
||||
* The user’s current app filter, used to set up the selector. As app filters
|
||||
* are immutable, it is not updated as the selector is changed. Use
|
||||
* mct_restrict_applications_selector_build_app_filter() to build the new app
|
||||
* filter.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
properties[PROP_APP_FILTER] =
|
||||
g_param_spec_boxed ("app-filter",
|
||||
"App Filter",
|
||||
"The user’s current app filter, used to set up the selector.",
|
||||
MCT_TYPE_APP_FILTER,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
|
||||
|
||||
/**
|
||||
* MctRestrictApplicationsSelector::changed:
|
||||
*
|
||||
* Emitted whenever an application in the list is blocked or unblocked.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
signals[SIGNAL_CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
MCT_TYPE_RESTRICT_APPLICATIONS_SELECTOR,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentControl/ui/restrict-applications-selector.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, MctRestrictApplicationsSelector, listbox);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_restrict_applications_selector_init (MctRestrictApplicationsSelector *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
self->apps = g_list_store_new (G_TYPE_APP_INFO);
|
||||
|
||||
self->app_info_monitor = g_app_info_monitor_get ();
|
||||
self->app_info_monitor_changed_id =
|
||||
g_signal_connect (self->app_info_monitor, "changed",
|
||||
(GCallback) app_info_changed_cb, self);
|
||||
|
||||
gtk_list_box_bind_model (self->listbox,
|
||||
G_LIST_MODEL (self->apps),
|
||||
create_row_for_app_cb,
|
||||
self,
|
||||
NULL);
|
||||
|
||||
self->blacklisted_apps = g_hash_table_new_full (g_direct_hash,
|
||||
g_direct_equal,
|
||||
g_object_unref,
|
||||
NULL);
|
||||
|
||||
self->system_installation = flatpak_installation_new_system (NULL, NULL);
|
||||
self->user_installation = flatpak_installation_new_user (NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
on_switch_active_changed_cb (GtkSwitch *s,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (user_data);
|
||||
GAppInfo *app;
|
||||
gboolean allowed;
|
||||
|
||||
app = g_object_get_data (G_OBJECT (s), "GAppInfo");
|
||||
allowed = gtk_switch_get_active (s);
|
||||
|
||||
if (allowed)
|
||||
{
|
||||
gboolean removed;
|
||||
|
||||
g_debug ("Removing ‘%s’ from blacklisted apps", g_app_info_get_id (app));
|
||||
|
||||
removed = g_hash_table_remove (self->blacklisted_apps, app);
|
||||
g_assert (removed);
|
||||
}
|
||||
else
|
||||
{
|
||||
gboolean added;
|
||||
|
||||
g_debug ("Blacklisting ‘%s’", g_app_info_get_id (app));
|
||||
|
||||
added = g_hash_table_add (self->blacklisted_apps, g_object_ref (app));
|
||||
g_assert (added);
|
||||
}
|
||||
|
||||
g_signal_emit (self, signals[SIGNAL_CHANGED], 0);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_row_for_app_cb (gpointer item,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (user_data);
|
||||
GAppInfo *app = G_APP_INFO (item);
|
||||
g_autoptr(GIcon) icon = NULL;
|
||||
GtkWidget *box, *w;
|
||||
gboolean allowed;
|
||||
const gchar *app_name;
|
||||
gint size;
|
||||
|
||||
app_name = g_app_info_get_name (app);
|
||||
|
||||
g_assert (G_IS_DESKTOP_APP_INFO (app));
|
||||
|
||||
icon = g_app_info_get_icon (app);
|
||||
if (icon == NULL)
|
||||
icon = g_themed_icon_new ("application-x-executable");
|
||||
else
|
||||
g_object_ref (icon);
|
||||
|
||||
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (box), 12);
|
||||
gtk_widget_set_margin_end (box, 12);
|
||||
|
||||
/* Icon */
|
||||
w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
|
||||
gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &size, NULL);
|
||||
gtk_image_set_pixel_size (GTK_IMAGE (w), size);
|
||||
gtk_container_add (GTK_CONTAINER (box), w);
|
||||
|
||||
/* App name label */
|
||||
w = g_object_new (GTK_TYPE_LABEL,
|
||||
"label", app_name,
|
||||
"hexpand", TRUE,
|
||||
"xalign", 0.0,
|
||||
NULL);
|
||||
gtk_container_add (GTK_CONTAINER (box), w);
|
||||
|
||||
/* Switch */
|
||||
w = g_object_new (GTK_TYPE_SWITCH,
|
||||
"valign", GTK_ALIGN_CENTER,
|
||||
NULL);
|
||||
gtk_container_add (GTK_CONTAINER (box), w);
|
||||
|
||||
gtk_widget_show_all (box);
|
||||
|
||||
/* Fetch status from AccountService */
|
||||
allowed = mct_app_filter_is_appinfo_allowed (self->app_filter, app);
|
||||
|
||||
gtk_switch_set_active (GTK_SWITCH (w), allowed);
|
||||
g_object_set_data_full (G_OBJECT (w), "GAppInfo", g_object_ref (app), g_object_unref);
|
||||
|
||||
if (allowed)
|
||||
g_hash_table_remove (self->blacklisted_apps, app);
|
||||
else
|
||||
g_hash_table_add (self->blacklisted_apps, g_object_ref (app));
|
||||
|
||||
g_signal_connect (w, "notify::active", G_CALLBACK (on_switch_active_changed_cb), self);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_app_info_cb (gconstpointer a,
|
||||
gconstpointer b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GAppInfo *app_a = (GAppInfo*) a;
|
||||
GAppInfo *app_b = (GAppInfo*) b;
|
||||
|
||||
return g_utf8_collate (g_app_info_get_display_name (app_a),
|
||||
g_app_info_get_display_name (app_b));
|
||||
}
|
||||
|
||||
static gint
|
||||
app_compare_id_length_cb (gconstpointer a,
|
||||
gconstpointer b)
|
||||
{
|
||||
GAppInfo *info_a = (GAppInfo *) a, *info_b = (GAppInfo *) b;
|
||||
const gchar *id_a, *id_b;
|
||||
|
||||
id_a = g_app_info_get_id (info_a);
|
||||
id_b = g_app_info_get_id (info_b);
|
||||
|
||||
if (id_a == NULL && id_b == NULL)
|
||||
return 0;
|
||||
else if (id_a == NULL)
|
||||
return -1;
|
||||
else if (id_b == NULL)
|
||||
return 1;
|
||||
|
||||
return strlen (id_a) - strlen (id_b);
|
||||
}
|
||||
|
||||
static void
|
||||
reload_apps (MctRestrictApplicationsSelector *self)
|
||||
{
|
||||
GList *iter, *apps;
|
||||
g_autoptr(GHashTable) seen_flatpak_ids = NULL;
|
||||
g_autoptr(GHashTable) seen_executables = NULL;
|
||||
|
||||
apps = g_app_info_get_all ();
|
||||
|
||||
/* Sort the apps by increasing length of #GAppInfo ID. When coupled with the
|
||||
* deduplication of flatpak IDs and executable paths, below, this should ensure that we
|
||||
* pick the ‘base’ app out of any set with matching prefixes and identical app IDs (in
|
||||
* case of flatpak apps) or executables (for non-flatpak apps), and show only that.
|
||||
*
|
||||
* This is designed to avoid listing all the components of LibreOffice for example,
|
||||
* which all share an app ID and hence have the same entry in the parental controls
|
||||
* app filter. */
|
||||
apps = g_list_sort (apps, app_compare_id_length_cb);
|
||||
seen_flatpak_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
seen_executables = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
g_list_store_remove_all (self->apps);
|
||||
|
||||
for (iter = apps; iter; iter = iter->next)
|
||||
{
|
||||
GAppInfo *app;
|
||||
const gchar *app_name;
|
||||
const gchar * const *supported_types;
|
||||
|
||||
app = iter->data;
|
||||
app_name = g_app_info_get_name (app);
|
||||
|
||||
supported_types = g_app_info_get_supported_types (app);
|
||||
|
||||
if (!G_IS_DESKTOP_APP_INFO (app) ||
|
||||
!g_app_info_should_show (app) ||
|
||||
app_name[0] == '\0' ||
|
||||
/* Endless' link apps have the "eos-link" prefix, and should be ignored too */
|
||||
g_str_has_prefix (g_app_info_get_id (app), "eos-link") ||
|
||||
/* FIXME: Only list flatpak apps and apps with X-Parental-Controls
|
||||
* key set for now; we really need a system-wide MAC to be able to
|
||||
* reliably support blacklisting system programs. */
|
||||
(!g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Flatpak") &&
|
||||
!g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Parental-Controls")) ||
|
||||
/* Web browsers are special cased */
|
||||
(supported_types && g_strv_contains (supported_types, WEB_BROWSERS_CONTENT_TYPE)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Flatpak"))
|
||||
{
|
||||
g_autofree gchar *flatpak_id = NULL;
|
||||
|
||||
flatpak_id = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (app), "X-Flatpak");
|
||||
g_debug ("Processing app ‘%s’ (Exec=%s, X-Flatpak=%s)",
|
||||
g_app_info_get_id (app),
|
||||
g_app_info_get_executable (app),
|
||||
flatpak_id);
|
||||
|
||||
/* Have we seen this flatpak ID before? */
|
||||
if (!g_hash_table_add (seen_flatpak_ids, g_steal_pointer (&flatpak_id)))
|
||||
{
|
||||
g_debug (" → Skipping ‘%s’ due to seeing its flatpak ID already",
|
||||
g_app_info_get_id (app));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Parental-Controls"))
|
||||
{
|
||||
g_autofree gchar *parental_controls_type = NULL;
|
||||
g_autofree gchar *executable = NULL;
|
||||
|
||||
parental_controls_type = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (app),
|
||||
"X-Parental-Controls");
|
||||
/* Ignore X-Parental-Controls=none */
|
||||
if (g_strcmp0 (parental_controls_type, "none") == 0)
|
||||
continue;
|
||||
|
||||
executable = g_strdup (g_app_info_get_executable (app));
|
||||
g_debug ("Processing app ‘%s’ (Exec=%s, X-Parental-Controls=%s)",
|
||||
g_app_info_get_id (app),
|
||||
executable,
|
||||
parental_controls_type);
|
||||
|
||||
/* Have we seen this executable before? */
|
||||
if (!g_hash_table_add (seen_executables, g_steal_pointer (&executable)))
|
||||
{
|
||||
g_debug (" → Skipping ‘%s’ due to seeing its executable already",
|
||||
g_app_info_get_id (app));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
g_list_store_insert_sorted (self->apps,
|
||||
app,
|
||||
compare_app_info_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
g_list_free_full (apps, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
app_info_changed_cb (GAppInfoMonitor *monitor,
|
||||
gpointer user_data)
|
||||
{
|
||||
/* FIXME: We should update the list of apps here, but we can’t call
|
||||
* reload_apps() because that will dump and reload the entire list, losing
|
||||
* any changes the user has already made to the set of switches. We need
|
||||
* something more fine-grained.
|
||||
MctRestrictApplicationsSelector *self = MCT_RESTRICT_APPLICATIONS_SELECTOR (user_data);
|
||||
|
||||
reload_apps (self);
|
||||
*/
|
||||
}
|
||||
|
||||
/* Will return %NULL if @flatpak_id is not installed. */
|
||||
static gchar *
|
||||
get_flatpak_ref_for_app_id (MctRestrictApplicationsSelector *self,
|
||||
const gchar *flatpak_id,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
g_autoptr(FlatpakInstalledRef) ref = NULL;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
|
||||
g_assert (self->system_installation != NULL);
|
||||
g_assert (self->user_installation != NULL);
|
||||
|
||||
/* FIXME technically this does local file I/O and should be async */
|
||||
ref = flatpak_installation_get_current_installed_app (self->user_installation,
|
||||
flatpak_id,
|
||||
cancellable,
|
||||
&local_error);
|
||||
|
||||
if (local_error != NULL &&
|
||||
!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED))
|
||||
{
|
||||
g_warning ("Error searching for Flatpak ref: %s", local_error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_clear_error (&local_error);
|
||||
|
||||
if (!ref || !flatpak_installed_ref_get_is_current (ref))
|
||||
{
|
||||
/* FIXME technically this does local file I/O and should be async */
|
||||
ref = flatpak_installation_get_current_installed_app (self->system_installation,
|
||||
flatpak_id,
|
||||
cancellable,
|
||||
&local_error);
|
||||
if (local_error != NULL)
|
||||
{
|
||||
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_INSTALLED))
|
||||
g_warning ("Error searching for Flatpak ref: %s", local_error->message);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return flatpak_ref_format_ref (FLATPAK_REF (ref));
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_selector_new:
|
||||
* @app_filter: (transfer none): app filter to configure the selector from initially
|
||||
*
|
||||
* Create a new #MctRestrictApplicationsSelector widget.
|
||||
*
|
||||
* Returns: (transfer full): a new restricted applications selector
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
MctRestrictApplicationsSelector *
|
||||
mct_restrict_applications_selector_new (MctAppFilter *app_filter)
|
||||
{
|
||||
g_return_val_if_fail (app_filter != NULL, NULL);
|
||||
|
||||
return g_object_new (MCT_TYPE_RESTRICT_APPLICATIONS_SELECTOR,
|
||||
"app-filter", app_filter,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_selector_build_app_filter:
|
||||
* @self: an #MctRestrictApplicationsSelector
|
||||
* @builder: an existing #MctAppFilterBuilder to modify
|
||||
*
|
||||
* Get the app filter settings currently configured in the selector, by modifying
|
||||
* the given @builder.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
void
|
||||
mct_restrict_applications_selector_build_app_filter (MctRestrictApplicationsSelector *self,
|
||||
MctAppFilterBuilder *builder)
|
||||
{
|
||||
GDesktopAppInfo *app;
|
||||
GHashTableIter iter;
|
||||
|
||||
g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_SELECTOR (self));
|
||||
g_return_if_fail (builder != NULL);
|
||||
|
||||
g_hash_table_iter_init (&iter, self->blacklisted_apps);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer) &app, NULL))
|
||||
{
|
||||
g_autofree gchar *flatpak_id = NULL;
|
||||
|
||||
flatpak_id = g_desktop_app_info_get_string (app, "X-Flatpak");
|
||||
if (flatpak_id)
|
||||
flatpak_id = g_strstrip (flatpak_id);
|
||||
|
||||
if (flatpak_id)
|
||||
{
|
||||
g_autofree gchar *flatpak_ref = get_flatpak_ref_for_app_id (self, flatpak_id, NULL);
|
||||
|
||||
if (!flatpak_ref)
|
||||
{
|
||||
g_warning ("Skipping blacklisting Flatpak ID ‘%s’ due to it not being installed", flatpak_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_debug ("\t\t → Blacklisting Flatpak ref: %s", flatpak_ref);
|
||||
mct_app_filter_builder_blacklist_flatpak_ref (builder, flatpak_ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
const gchar *executable = g_app_info_get_executable (G_APP_INFO (app));
|
||||
g_autofree gchar *path = g_find_program_in_path (executable);
|
||||
|
||||
if (!path)
|
||||
{
|
||||
g_warning ("Skipping blacklisting executable ‘%s’ due to it not being found", executable);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_debug ("\t\t → Blacklisting path: %s", path);
|
||||
mct_app_filter_builder_blacklist_path (builder, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_selector_get_app_filter:
|
||||
* @self: an #MctRestrictApplicationsSelector
|
||||
*
|
||||
* Get the value of #MctRestrictApplicationsSelector:app-filter. If the property
|
||||
* was originally set to %NULL, this will be the empty app filter.
|
||||
*
|
||||
* Returns: (transfer none) (not nullable): the initial app filter used to
|
||||
* populate the selector
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
MctAppFilter *
|
||||
mct_restrict_applications_selector_get_app_filter (MctRestrictApplicationsSelector *self)
|
||||
{
|
||||
g_return_val_if_fail (MCT_IS_RESTRICT_APPLICATIONS_SELECTOR (self), NULL);
|
||||
|
||||
return self->app_filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_restrict_applications_selector_set_app_filter:
|
||||
* @self: an #MctRestrictApplicationsSelector
|
||||
* @app_filter: (nullable) (transfer none): the app filter to configure the selector
|
||||
* from, or %NULL to use an empty app filter
|
||||
*
|
||||
* Set the value of #MctRestrictApplicationsSelector:app-filter.
|
||||
*
|
||||
* This will overwrite any user changes to the selector, so they should be saved
|
||||
* first using mct_restrict_applications_selector_build_app_filter() if desired.
|
||||
*
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
void
|
||||
mct_restrict_applications_selector_set_app_filter (MctRestrictApplicationsSelector *self,
|
||||
MctAppFilter *app_filter)
|
||||
{
|
||||
g_autoptr(MctAppFilter) owned_app_filter = NULL;
|
||||
|
||||
g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_SELECTOR (self));
|
||||
|
||||
/* Default app filter, typically for when we’re instantiated by #GtkBuilder. */
|
||||
if (app_filter == NULL)
|
||||
{
|
||||
g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
|
||||
owned_app_filter = mct_app_filter_builder_end (&builder);
|
||||
app_filter = owned_app_filter;
|
||||
}
|
||||
|
||||
if (app_filter == self->app_filter)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&self->app_filter, mct_app_filter_unref);
|
||||
self->app_filter = mct_app_filter_ref (app_filter);
|
||||
|
||||
reload_apps (self);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_APP_FILTER]);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/* -*- 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 <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libmalcontent/app-filter.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MCT_TYPE_RESTRICT_APPLICATIONS_SELECTOR (mct_restrict_applications_selector_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MctRestrictApplicationsSelector, mct_restrict_applications_selector, MCT, RESTRICT_APPLICATIONS_SELECTOR, GtkBox)
|
||||
|
||||
MctRestrictApplicationsSelector *mct_restrict_applications_selector_new (MctAppFilter *app_filter);
|
||||
|
||||
MctAppFilter *mct_restrict_applications_selector_get_app_filter (MctRestrictApplicationsSelector *self);
|
||||
void mct_restrict_applications_selector_set_app_filter (MctRestrictApplicationsSelector *self,
|
||||
MctAppFilter *app_filter);
|
||||
|
||||
void mct_restrict_applications_selector_build_app_filter (MctRestrictApplicationsSelector *self,
|
||||
MctAppFilterBuilder *builder);
|
||||
|
||||
G_END_DECLS
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright © 2020 Endless, Inc. -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<template class="MctRestrictApplicationsSelector" parent="GtkBox">
|
||||
<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>
|
||||
|
||||
<child>
|
||||
<object class="GtkListBox" id="listbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="selection-mode">none</property>
|
||||
|
||||
<child type="placeholder">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">No applications found to restrict.</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
|
@ -1,890 +0,0 @@
|
|||
/* -*- 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>
|
||||
*/
|
||||
|
||||
#include <libmalcontent/malcontent.h>
|
||||
#include <flatpak.h>
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "gs-content-rating.h"
|
||||
#include "restrict-applications-dialog.h"
|
||||
#include "user-controls.h"
|
||||
|
||||
|
||||
#define WEB_BROWSERS_CONTENT_TYPE "x-scheme-handler/http"
|
||||
|
||||
/* The value which we store as an age to indicate that OARS filtering is disabled. */
|
||||
static const guint32 oars_disabled_age = (guint32) -1;
|
||||
|
||||
struct _MctUserControls
|
||||
{
|
||||
GtkGrid parent_instance;
|
||||
|
||||
GMenu *age_menu;
|
||||
GtkSwitch *allow_system_installation_switch;
|
||||
GtkSwitch *allow_user_installation_switch;
|
||||
GtkSwitch *allow_web_browsers_switch;
|
||||
GtkButton *restriction_button;
|
||||
GtkPopover *restriction_popover;
|
||||
MctRestrictApplicationsDialog *restrict_applications_dialog;
|
||||
|
||||
GSimpleActionGroup *action_group; /* (owned) */
|
||||
|
||||
ActUser *user; /* (owned) (nullable) */
|
||||
|
||||
GPermission *permission; /* (owned) (nullable) */
|
||||
gulong permission_allowed_id;
|
||||
|
||||
GCancellable *cancellable; /* (owned) */
|
||||
MctManager *manager; /* (owned) */
|
||||
MctAppFilter *filter; /* (owned) */
|
||||
guint selected_age; /* @oars_disabled_age to disable OARS */
|
||||
|
||||
guint blacklist_apps_source_id;
|
||||
gboolean flushed_on_dispose;
|
||||
};
|
||||
|
||||
static gboolean blacklist_apps_cb (gpointer data);
|
||||
|
||||
static void on_allow_installation_switch_active_changed_cb (GtkSwitch *s,
|
||||
GParamSpec *pspec,
|
||||
MctUserControls *self);
|
||||
|
||||
static void on_allow_web_browsers_switch_active_changed_cb (GtkSwitch *s,
|
||||
GParamSpec *pspec,
|
||||
MctUserControls *self);
|
||||
|
||||
static void on_restrict_applications_button_clicked_cb (GtkButton *button,
|
||||
gpointer user_data);
|
||||
|
||||
static gboolean on_restrict_applications_dialog_delete_event_cb (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer user_data);
|
||||
|
||||
static void on_restrict_applications_dialog_response_cb (GtkDialog *dialog,
|
||||
gint response_id,
|
||||
gpointer user_data);
|
||||
|
||||
static void on_set_age_action_activated (GSimpleAction *action,
|
||||
GVariant *param,
|
||||
gpointer user_data);
|
||||
|
||||
static void on_permission_allowed_cb (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data);
|
||||
|
||||
G_DEFINE_TYPE (MctUserControls, mct_user_controls, GTK_TYPE_GRID)
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_USER = 1,
|
||||
PROP_PERMISSION,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static const GActionEntry actions[] = {
|
||||
{ "set-age", on_set_age_action_activated, "u", NULL, NULL, { 0, }}
|
||||
};
|
||||
|
||||
/* FIXME: Factor this out and rely on code from libappstream-glib or gnome-software
|
||||
* to do it. See: https://gitlab.freedesktop.org/pwithnall/malcontent/issues/7 */
|
||||
static const gchar * const oars_categories[] =
|
||||
{
|
||||
"violence-cartoon",
|
||||
"violence-fantasy",
|
||||
"violence-realistic",
|
||||
"violence-bloodshed",
|
||||
"violence-sexual",
|
||||
"violence-desecration",
|
||||
"violence-slavery",
|
||||
"violence-worship",
|
||||
"drugs-alcohol",
|
||||
"drugs-narcotics",
|
||||
"drugs-tobacco",
|
||||
"sex-nudity",
|
||||
"sex-themes",
|
||||
"sex-homosexuality",
|
||||
"sex-prostitution",
|
||||
"sex-adultery",
|
||||
"sex-appearance",
|
||||
"language-profanity",
|
||||
"language-humor",
|
||||
"language-discrimination",
|
||||
"social-chat",
|
||||
"social-info",
|
||||
"social-audio",
|
||||
"social-location",
|
||||
"social-contacts",
|
||||
"money-purchasing",
|
||||
"money-gambling",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Auxiliary methods */
|
||||
|
||||
static GsContentRatingSystem
|
||||
get_content_rating_system (ActUser *user)
|
||||
{
|
||||
const gchar *user_language;
|
||||
|
||||
user_language = act_user_get_language (user);
|
||||
|
||||
return gs_utils_content_rating_system_from_locale (user_language);
|
||||
}
|
||||
|
||||
static void
|
||||
schedule_update_blacklisted_apps (MctUserControls *self)
|
||||
{
|
||||
if (self->blacklist_apps_source_id > 0)
|
||||
return;
|
||||
|
||||
/* Use a timeout to batch multiple quick changes into a single
|
||||
* update. 1 second is an arbitrary sufficiently small number */
|
||||
self->blacklist_apps_source_id = g_timeout_add_seconds (1, blacklist_apps_cb, self);
|
||||
}
|
||||
|
||||
static void
|
||||
flush_update_blacklisted_apps (MctUserControls *self)
|
||||
{
|
||||
if (self->blacklist_apps_source_id > 0)
|
||||
{
|
||||
/* Remove the timer and forcefully call the timer callback. */
|
||||
g_source_remove (self->blacklist_apps_source_id);
|
||||
self->blacklist_apps_source_id = 0;
|
||||
|
||||
blacklist_apps_cb (self);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_app_filter (MctUserControls *self)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
g_clear_pointer (&self->filter, mct_app_filter_unref);
|
||||
|
||||
if (self->user == NULL)
|
||||
return;
|
||||
|
||||
/* FIXME: It’s expected that, unless authorised already, a user cannot read
|
||||
* another user’s app filter. accounts-service currently (incorrectly) ignores
|
||||
* the missing ‘interactive’ flag and prompts the user for permission if so,
|
||||
* so don’t query at all in that case. */
|
||||
if (act_user_get_uid (self->user) != getuid () &&
|
||||
(self->permission == NULL ||
|
||||
!g_permission_get_allowed (self->permission)))
|
||||
return;
|
||||
|
||||
/* FIXME: make it asynchronous */
|
||||
self->filter = mct_manager_get_app_filter (self->manager,
|
||||
act_user_get_uid (self->user),
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE,
|
||||
self->cancellable,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Error retrieving app filter for user '%s': %s",
|
||||
act_user_get_user_name (self->user),
|
||||
error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug ("Retrieved new app filter for user '%s'", act_user_get_user_name (self->user));
|
||||
}
|
||||
|
||||
static void
|
||||
update_categories_from_language (MctUserControls *self)
|
||||
{
|
||||
GsContentRatingSystem rating_system;
|
||||
const gchar * const * entries;
|
||||
const gchar *rating_system_str;
|
||||
const guint *ages;
|
||||
gsize i;
|
||||
g_autofree gchar *disabled_action = NULL;
|
||||
|
||||
rating_system = get_content_rating_system (self->user);
|
||||
rating_system_str = gs_content_rating_system_to_str (rating_system);
|
||||
|
||||
g_debug ("Using rating system %s", rating_system_str);
|
||||
|
||||
entries = gs_utils_content_rating_get_values (rating_system);
|
||||
ages = gs_utils_content_rating_get_ages (rating_system);
|
||||
|
||||
/* Fill in the age menu */
|
||||
g_menu_remove_all (self->age_menu);
|
||||
|
||||
disabled_action = g_strdup_printf ("permissions.set-age(uint32 %u)", oars_disabled_age);
|
||||
g_menu_append (self->age_menu, _("All Ages"), disabled_action);
|
||||
|
||||
for (i = 0; entries[i] != NULL; i++)
|
||||
{
|
||||
g_autofree gchar *action = g_strdup_printf ("permissions.set-age(uint32 %u)", ages[i]);
|
||||
|
||||
/* Prevent the unlikely case that one of the real ages is the same as our
|
||||
* special ‘disabled’ value. */
|
||||
g_assert (ages[i] != oars_disabled_age);
|
||||
|
||||
g_menu_append (self->age_menu, entries[i], action);
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns a human-readable but untranslated string, not suitable
|
||||
* to be shown in any UI */
|
||||
static const gchar *
|
||||
oars_value_to_string (MctAppFilterOarsValue oars_value)
|
||||
{
|
||||
switch (oars_value)
|
||||
{
|
||||
case MCT_APP_FILTER_OARS_VALUE_UNKNOWN:
|
||||
return "unknown";
|
||||
case MCT_APP_FILTER_OARS_VALUE_NONE:
|
||||
return "none";
|
||||
case MCT_APP_FILTER_OARS_VALUE_MILD:
|
||||
return "mild";
|
||||
case MCT_APP_FILTER_OARS_VALUE_MODERATE:
|
||||
return "moderate";
|
||||
case MCT_APP_FILTER_OARS_VALUE_INTENSE:
|
||||
return "intense";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_oars_level (MctUserControls *self)
|
||||
{
|
||||
GsContentRatingSystem rating_system;
|
||||
const gchar *rating_age_category;
|
||||
guint maximum_age;
|
||||
gsize i;
|
||||
gboolean all_categories_unset;
|
||||
|
||||
g_assert (self->filter != NULL);
|
||||
|
||||
maximum_age = 0;
|
||||
all_categories_unset = TRUE;
|
||||
|
||||
for (i = 0; oars_categories[i] != NULL; i++)
|
||||
{
|
||||
MctAppFilterOarsValue oars_value;
|
||||
guint age;
|
||||
|
||||
oars_value = mct_app_filter_get_oars_value (self->filter, oars_categories[i]);
|
||||
all_categories_unset &= (oars_value == MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
|
||||
age = as_content_rating_id_value_to_csm_age (oars_categories[i], oars_value);
|
||||
|
||||
g_debug ("OARS value for '%s': %s", oars_categories[i], oars_value_to_string (oars_value));
|
||||
|
||||
if (age > maximum_age)
|
||||
maximum_age = age;
|
||||
}
|
||||
|
||||
g_debug ("Effective age for this user: %u; %s", maximum_age,
|
||||
all_categories_unset ? "all categories unset" : "some categories set");
|
||||
|
||||
rating_system = get_content_rating_system (self->user);
|
||||
rating_age_category = gs_utils_content_rating_age_to_str (rating_system, maximum_age);
|
||||
|
||||
/* Unrestricted? */
|
||||
if (rating_age_category == NULL || all_categories_unset)
|
||||
rating_age_category = _("All Ages");
|
||||
|
||||
gtk_button_set_label (self->restriction_button, rating_age_category);
|
||||
}
|
||||
|
||||
static void
|
||||
update_allow_app_installation (MctUserControls *self)
|
||||
{
|
||||
gboolean allow_system_installation;
|
||||
gboolean allow_user_installation;
|
||||
gboolean non_admin_user = TRUE;
|
||||
|
||||
if (act_user_get_account_type (self->user) == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
|
||||
non_admin_user = FALSE;
|
||||
|
||||
/* Admins are always allowed to install apps for all users. This behaviour is governed
|
||||
* by flatpak polkit rules. Hence, these hide these defunct switches for admins. */
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->allow_system_installation_switch), non_admin_user);
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->allow_user_installation_switch), non_admin_user);
|
||||
|
||||
/* If user is admin, we are done here, bail out. */
|
||||
if (!non_admin_user)
|
||||
{
|
||||
g_debug ("User %s is administrator, hiding app installation controls",
|
||||
act_user_get_user_name (self->user));
|
||||
return;
|
||||
}
|
||||
|
||||
allow_system_installation = mct_app_filter_is_system_installation_allowed (self->filter);
|
||||
allow_user_installation = mct_app_filter_is_user_installation_allowed (self->filter);
|
||||
|
||||
/* While the underlying permissions storage allows the system and user settings
|
||||
* to be stored completely independently, force the system setting to OFF if
|
||||
* the user setting is OFF in the UI. This keeps the policy in use for most
|
||||
* people simpler. */
|
||||
if (!allow_user_installation)
|
||||
allow_system_installation = FALSE;
|
||||
|
||||
g_signal_handlers_block_by_func (self->allow_system_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
|
||||
g_signal_handlers_block_by_func (self->allow_user_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
|
||||
gtk_switch_set_active (self->allow_system_installation_switch, allow_system_installation);
|
||||
gtk_switch_set_active (self->allow_user_installation_switch, allow_user_installation);
|
||||
|
||||
g_debug ("Allow system installation: %s", allow_system_installation ? "yes" : "no");
|
||||
g_debug ("Allow user installation: %s", allow_user_installation ? "yes" : "no");
|
||||
|
||||
g_signal_handlers_unblock_by_func (self->allow_system_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
|
||||
g_signal_handlers_unblock_by_func (self->allow_user_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
update_allow_web_browsers (MctUserControls *self)
|
||||
{
|
||||
gboolean allow_web_browsers;
|
||||
|
||||
allow_web_browsers = mct_app_filter_is_content_type_allowed (self->filter,
|
||||
WEB_BROWSERS_CONTENT_TYPE);
|
||||
|
||||
g_signal_handlers_block_by_func (self->allow_web_browsers_switch,
|
||||
on_allow_web_browsers_switch_active_changed_cb,
|
||||
self);
|
||||
|
||||
gtk_switch_set_active (self->allow_web_browsers_switch, allow_web_browsers);
|
||||
|
||||
g_debug ("Allow web browsers: %s", allow_web_browsers ? "yes" : "no");
|
||||
|
||||
g_signal_handlers_unblock_by_func (self->allow_web_browsers_switch,
|
||||
on_allow_web_browsers_switch_active_changed_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
setup_parental_control_settings (MctUserControls *self)
|
||||
{
|
||||
gboolean is_authorized;
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (self), self->filter != NULL);
|
||||
|
||||
if (!self->filter)
|
||||
return;
|
||||
|
||||
/* We only want to make the controls sensitive if we have permission to save
|
||||
* changes (@is_authorized). */
|
||||
if (self->permission != NULL)
|
||||
is_authorized = g_permission_get_allowed (G_PERMISSION (self->permission));
|
||||
else
|
||||
is_authorized = FALSE;
|
||||
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self), is_authorized);
|
||||
|
||||
update_oars_level (self);
|
||||
update_categories_from_language (self);
|
||||
update_allow_app_installation (self);
|
||||
update_allow_web_browsers (self);
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
static gboolean
|
||||
blacklist_apps_cb (gpointer data)
|
||||
{
|
||||
g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
|
||||
g_autoptr(MctAppFilter) new_filter = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
MctUserControls *self = data;
|
||||
gboolean allow_web_browsers;
|
||||
gsize i;
|
||||
|
||||
self->blacklist_apps_source_id = 0;
|
||||
|
||||
g_debug ("Building parental controls settings…");
|
||||
|
||||
/* Blacklist */
|
||||
|
||||
g_debug ("\t → Blacklisting apps");
|
||||
|
||||
mct_restrict_applications_dialog_build_app_filter (self->restrict_applications_dialog, &builder);
|
||||
|
||||
/* Maturity level */
|
||||
|
||||
g_debug ("\t → Maturity level");
|
||||
|
||||
if (self->selected_age == oars_disabled_age)
|
||||
g_debug ("\t\t → Disabled");
|
||||
|
||||
for (i = 0; self->selected_age != oars_disabled_age && oars_categories[i] != NULL; i++)
|
||||
{
|
||||
MctAppFilterOarsValue oars_value;
|
||||
const gchar *oars_category;
|
||||
|
||||
oars_category = oars_categories[i];
|
||||
oars_value = as_content_rating_id_csm_age_to_value (oars_category, self->selected_age);
|
||||
|
||||
g_debug ("\t\t → %s: %s", oars_category, oars_value_to_string (oars_value));
|
||||
|
||||
mct_app_filter_builder_set_oars_value (&builder, oars_category, oars_value);
|
||||
}
|
||||
|
||||
/* Web browsers */
|
||||
allow_web_browsers = gtk_switch_get_active (self->allow_web_browsers_switch);
|
||||
|
||||
g_debug ("\t → %s web browsers", allow_web_browsers ? "Enabling" : "Disabling");
|
||||
|
||||
if (!allow_web_browsers)
|
||||
mct_app_filter_builder_blacklist_content_type (&builder, WEB_BROWSERS_CONTENT_TYPE);
|
||||
|
||||
/* App installation */
|
||||
if (act_user_get_account_type (self->user) != ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
|
||||
{
|
||||
gboolean allow_system_installation;
|
||||
gboolean allow_user_installation;
|
||||
|
||||
allow_system_installation = gtk_switch_get_active (self->allow_system_installation_switch);
|
||||
allow_user_installation = gtk_switch_get_active (self->allow_user_installation_switch);
|
||||
|
||||
g_debug ("\t → %s system installation", allow_system_installation ? "Enabling" : "Disabling");
|
||||
g_debug ("\t → %s user installation", allow_user_installation ? "Enabling" : "Disabling");
|
||||
|
||||
mct_app_filter_builder_set_allow_user_installation (&builder, allow_user_installation);
|
||||
mct_app_filter_builder_set_allow_system_installation (&builder, allow_system_installation);
|
||||
}
|
||||
|
||||
new_filter = mct_app_filter_builder_end (&builder);
|
||||
|
||||
/* FIXME: should become asynchronous */
|
||||
mct_manager_set_app_filter (self->manager,
|
||||
act_user_get_uid (self->user),
|
||||
new_filter,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE,
|
||||
self->cancellable,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Error updating app filter: %s", error->message);
|
||||
setup_parental_control_settings (self);
|
||||
}
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_allow_installation_switch_active_changed_cb (GtkSwitch *s,
|
||||
GParamSpec *pspec,
|
||||
MctUserControls *self)
|
||||
{
|
||||
/* See the comment about policy in update_allow_app_installation(). */
|
||||
if (s == self->allow_user_installation_switch &&
|
||||
!gtk_switch_get_active (s) &&
|
||||
gtk_switch_get_active (self->allow_system_installation_switch))
|
||||
{
|
||||
g_signal_handlers_block_by_func (self->allow_system_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
gtk_switch_set_active (self->allow_system_installation_switch, FALSE);
|
||||
g_signal_handlers_unblock_by_func (self->allow_system_installation_switch,
|
||||
on_allow_installation_switch_active_changed_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
/* Save the changes. */
|
||||
schedule_update_blacklisted_apps (self);
|
||||
}
|
||||
|
||||
static void
|
||||
on_allow_web_browsers_switch_active_changed_cb (GtkSwitch *s,
|
||||
GParamSpec *pspec,
|
||||
MctUserControls *self)
|
||||
{
|
||||
/* Save the changes. */
|
||||
schedule_update_blacklisted_apps (self);
|
||||
}
|
||||
|
||||
static void
|
||||
on_restrict_applications_button_clicked_cb (GtkButton *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (user_data);
|
||||
GtkWidget *toplevel;
|
||||
|
||||
/* Show the restrict applications dialogue modally, making sure to update its
|
||||
* state first. */
|
||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
||||
if (GTK_IS_WINDOW (toplevel))
|
||||
gtk_window_set_transient_for (GTK_WINDOW (self->restrict_applications_dialog),
|
||||
GTK_WINDOW (toplevel));
|
||||
|
||||
mct_restrict_applications_dialog_set_user (self->restrict_applications_dialog, self->user);
|
||||
mct_restrict_applications_dialog_set_app_filter (self->restrict_applications_dialog, self->filter);
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (self->restrict_applications_dialog));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_restrict_applications_dialog_delete_event_cb (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (user_data);
|
||||
|
||||
/* When the ‘Restrict Applications’ dialogue is closed, don’t destroy it,
|
||||
* since it contains the app filter settings which we’ll want to reuse next
|
||||
* time the dialogue is shown or the app filter is saved. */
|
||||
gtk_widget_hide (GTK_WIDGET (self->restrict_applications_dialog));
|
||||
|
||||
/* Schedule an update to the saved state. */
|
||||
schedule_update_blacklisted_apps (self);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_restrict_applications_dialog_response_cb (GtkDialog *dialog,
|
||||
gint response_id,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (user_data);
|
||||
|
||||
on_restrict_applications_dialog_delete_event_cb (GTK_WIDGET (dialog), NULL, self);
|
||||
}
|
||||
|
||||
static void
|
||||
on_set_age_action_activated (GSimpleAction *action,
|
||||
GVariant *param,
|
||||
gpointer user_data)
|
||||
{
|
||||
GsContentRatingSystem rating_system;
|
||||
MctUserControls *self;
|
||||
const gchar * const * entries;
|
||||
const guint *ages;
|
||||
guint age;
|
||||
guint i;
|
||||
|
||||
self = MCT_USER_CONTROLS (user_data);
|
||||
age = g_variant_get_uint32 (param);
|
||||
|
||||
rating_system = get_content_rating_system (self->user);
|
||||
entries = gs_utils_content_rating_get_values (rating_system);
|
||||
ages = gs_utils_content_rating_get_ages (rating_system);
|
||||
|
||||
/* Update the button */
|
||||
if (age == oars_disabled_age)
|
||||
gtk_button_set_label (self->restriction_button, _("All Ages"));
|
||||
|
||||
for (i = 0; age != oars_disabled_age && entries[i] != NULL; i++)
|
||||
{
|
||||
if (ages[i] == age)
|
||||
{
|
||||
gtk_button_set_label (self->restriction_button, entries[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_assert (age == oars_disabled_age || entries[i] != NULL);
|
||||
|
||||
if (age == oars_disabled_age)
|
||||
g_debug ("Selected to disable OARS");
|
||||
else
|
||||
g_debug ("Selected OARS age: %u", age);
|
||||
|
||||
self->selected_age = age;
|
||||
|
||||
schedule_update_blacklisted_apps (self);
|
||||
}
|
||||
|
||||
/* GObject overrides */
|
||||
|
||||
static void
|
||||
mct_user_controls_finalize (GObject *object)
|
||||
{
|
||||
MctUserControls *self = (MctUserControls *)object;
|
||||
|
||||
g_assert (self->blacklist_apps_source_id == 0);
|
||||
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_clear_object (&self->action_group);
|
||||
g_clear_object (&self->cancellable);
|
||||
g_clear_object (&self->user);
|
||||
|
||||
if (self->permission != NULL && self->permission_allowed_id != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (self->permission, self->permission_allowed_id);
|
||||
self->permission_allowed_id = 0;
|
||||
}
|
||||
g_clear_object (&self->permission);
|
||||
|
||||
g_clear_pointer (&self->filter, mct_app_filter_unref);
|
||||
g_clear_object (&self->manager);
|
||||
|
||||
/* Hopefully we don’t have data loss. */
|
||||
g_assert (self->flushed_on_dispose);
|
||||
|
||||
G_OBJECT_CLASS (mct_user_controls_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mct_user_controls_dispose (GObject *object)
|
||||
{
|
||||
MctUserControls *self = (MctUserControls *)object;
|
||||
|
||||
/* Since GTK calls g_object_run_dispose(), dispose() may be called multiple
|
||||
* times. We definitely want to save any unsaved changes, but don’t need to
|
||||
* do it multiple times, and after the first g_object_run_dispose() call,
|
||||
* none of our child widgets are still around to extract data from anyway. */
|
||||
if (!self->flushed_on_dispose)
|
||||
flush_update_blacklisted_apps (self);
|
||||
self->flushed_on_dispose = TRUE;
|
||||
|
||||
G_OBJECT_CLASS (mct_user_controls_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_user_controls_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_USER:
|
||||
g_value_set_object (value, self->user);
|
||||
break;
|
||||
|
||||
case PROP_PERMISSION:
|
||||
g_value_set_object (value, self->permission);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_user_controls_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_USER:
|
||||
mct_user_controls_set_user (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_PERMISSION:
|
||||
mct_user_controls_set_permission (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mct_user_controls_class_init (MctUserControlsClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->finalize = mct_user_controls_finalize;
|
||||
object_class->dispose = mct_user_controls_dispose;
|
||||
object_class->get_property = mct_user_controls_get_property;
|
||||
object_class->set_property = mct_user_controls_set_property;
|
||||
|
||||
properties[PROP_USER] = g_param_spec_object ("user",
|
||||
"User",
|
||||
"User",
|
||||
ACT_TYPE_USER,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_PERMISSION] = g_param_spec_object ("permission",
|
||||
"Permission",
|
||||
"Permission to change parental controls",
|
||||
G_TYPE_PERMISSION,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS |
|
||||
G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/freedesktop/MalcontentControl/ui/user-controls.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, age_menu);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, allow_system_installation_switch);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, allow_user_installation_switch);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, allow_web_browsers_switch);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restriction_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restriction_popover);
|
||||
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_dialog);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_allow_installation_switch_active_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_allow_web_browsers_switch_active_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_button_clicked_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_delete_event_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_response_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
mct_user_controls_init (MctUserControls *self)
|
||||
{
|
||||
g_autoptr(GDBusConnection) system_bus = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
/* Ensure the types used in the UI are registered. */
|
||||
g_type_ensure (MCT_TYPE_RESTRICT_APPLICATIONS_DIALOG);
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
self->selected_age = (guint) -1;
|
||||
|
||||
self->cancellable = g_cancellable_new ();
|
||||
|
||||
/* FIXME: should become asynchronous */
|
||||
system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error);
|
||||
if (system_bus == NULL)
|
||||
{
|
||||
g_warning ("Error getting system bus while setting up app permissions: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
self->manager = mct_manager_new (system_bus);
|
||||
|
||||
self->action_group = g_simple_action_group_new ();
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (self->action_group),
|
||||
actions,
|
||||
G_N_ELEMENTS (actions),
|
||||
self);
|
||||
|
||||
gtk_widget_insert_action_group (GTK_WIDGET (self),
|
||||
"permissions",
|
||||
G_ACTION_GROUP (self->action_group));
|
||||
|
||||
gtk_popover_bind_model (self->restriction_popover, G_MENU_MODEL (self->age_menu), NULL);
|
||||
|
||||
g_object_bind_property (self->allow_user_installation_switch, "active",
|
||||
self->allow_system_installation_switch, "sensitive",
|
||||
G_BINDING_DEFAULT);
|
||||
}
|
||||
|
||||
ActUser *
|
||||
mct_user_controls_get_user (MctUserControls *self)
|
||||
{
|
||||
g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
|
||||
|
||||
return self->user;
|
||||
}
|
||||
|
||||
void
|
||||
mct_user_controls_set_user (MctUserControls *self,
|
||||
ActUser *user)
|
||||
{
|
||||
g_return_if_fail (MCT_IS_USER_CONTROLS (self));
|
||||
g_return_if_fail (user == NULL || ACT_IS_USER (user));
|
||||
|
||||
/* If we have pending unsaved changes from the previous user, force them to be
|
||||
* saved first. */
|
||||
flush_update_blacklisted_apps (self);
|
||||
|
||||
if (g_set_object (&self->user, user))
|
||||
{
|
||||
update_app_filter (self);
|
||||
setup_parental_control_settings (self);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_USER]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_permission_allowed_cb (GObject *obj,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
MctUserControls *self = MCT_USER_CONTROLS (user_data);
|
||||
|
||||
update_app_filter (self);
|
||||
setup_parental_control_settings (self);
|
||||
}
|
||||
|
||||
GPermission * /* (nullable) */
|
||||
mct_user_controls_get_permission (MctUserControls *self)
|
||||
{
|
||||
g_return_val_if_fail (MCT_IS_USER_CONTROLS (self), NULL);
|
||||
|
||||
return self->permission;
|
||||
}
|
||||
|
||||
void
|
||||
mct_user_controls_set_permission (MctUserControls *self,
|
||||
GPermission *permission /* (nullable) */)
|
||||
{
|
||||
g_return_if_fail (MCT_IS_USER_CONTROLS (self));
|
||||
g_return_if_fail (permission == NULL || G_IS_PERMISSION (permission));
|
||||
|
||||
if (self->permission == permission)
|
||||
return;
|
||||
|
||||
if (self->permission != NULL && self->permission_allowed_id != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (self->permission, self->permission_allowed_id);
|
||||
self->permission_allowed_id = 0;
|
||||
}
|
||||
|
||||
g_clear_object (&self->permission);
|
||||
|
||||
if (permission != NULL)
|
||||
{
|
||||
self->permission = g_object_ref (permission);
|
||||
self->permission_allowed_id = g_signal_connect (self->permission,
|
||||
"notify::allowed",
|
||||
(GCallback) on_permission_allowed_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
/* Handle changes. */
|
||||
update_app_filter (self);
|
||||
setup_parental_control_settings (self);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PERMISSION]);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/* -*- 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
|
|
@ -1,535 +0,0 @@
|
|||
<?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>
|
||||
|
||||
<!-- Application Usage Restrictions -->
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.0</property>
|
||||
<property name="label" translatable="yes">Application Usage Restrictions</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold" />
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="left-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkFrame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkListBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selection_mode">none</property>
|
||||
<property name="activate_on_single_click">False</property>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="activatable">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-left">12</property>
|
||||
<property name="margin-right">12</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_web_browsers_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Allow _Web Browsers</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">allow_web_browsers_switch</property>
|
||||
<accessibility>
|
||||
<relation target="allow_web_browsers_switch" type="label-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_web_browsers_description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Prevents the user from running web browsers, but limited web content may still be available in other applications</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="0.88"/>
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
</style>
|
||||
<accessibility>
|
||||
<relation target="allow_web_browsers_switch" type="description-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="allow_web_browsers_switch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<signal name="notify::active" handler="on_allow_web_browsers_switch_active_changed_cb" object="MctUserControls" swapped="no" />
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="activatable">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-left">12</property>
|
||||
<property name="margin-right">12</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="restrict_applications_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">_Restrict Applications</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">restrict_applications_button</property>
|
||||
<accessibility>
|
||||
<relation target="restrict_applications_button" type="label-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="restrict_applications_description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Prevents particular applications from being used</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="0.88"/>
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
</style>
|
||||
<accessibility>
|
||||
<relation target="restrict_applications_button" type="description-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="restrict_applications_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="relief">none</property>
|
||||
<signal name="clicked" handler="on_restrict_applications_button_clicked_cb" object="MctUserControls" swapped="no" />
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="icon-name">pan-end-symbolic</property>
|
||||
<property name="icon-size">4</property><!-- GTK_ICON_SIZE_BUTTON -->
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="top-attach">1</property>
|
||||
<property name="left-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<!-- Software Installation 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">Software Installation Restrictions</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold" />
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="top-attach">2</property>
|
||||
<property name="left-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkFrame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkListBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="selection_mode">none</property>
|
||||
<property name="activate_on_single_click">False</property>
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible" bind-source="allow_user_installation_switch" bind-property="visible" bind-flags="default|sync-create" />
|
||||
<property name="can_focus">True</property>
|
||||
<property name="activatable">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-left">12</property>
|
||||
<property name="margin-right">12</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_user_installation_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Application _Installation</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">allow_user_installation_switch</property>
|
||||
<accessibility>
|
||||
<relation target="allow_user_installation_switch" type="label-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_user_installation_description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Restricts the user from installing applications</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="0.88"/>
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
</style>
|
||||
<accessibility>
|
||||
<relation target="allow_user_installation_switch" type="description-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="allow_user_installation_switch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<signal name="notify::active" handler="on_allow_installation_switch_active_changed_cb" object="MctUserControls" swapped="no" />
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible" bind-source="allow_system_installation_switch" bind-property="visible" bind-flags="default|sync-create" />
|
||||
<property name="can_focus">True</property>
|
||||
<property name="activatable">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-left">12</property>
|
||||
<property name="margin-right">12</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_system_installation_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Application Installation for _Others</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">allow_system_installation_switch</property>
|
||||
<accessibility>
|
||||
<relation target="allow_system_installation_switch" type="label-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="allow_system_installation_description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Restricts the user from installing applications for all users</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="0.88"/>
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
</style>
|
||||
<accessibility>
|
||||
<relation target="allow_system_installation_switch" type="description-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="allow_system_installation_switch">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<signal name="notify::active" handler="on_allow_installation_switch_active_changed_cb" object="MctUserControls" swapped="no" />
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="activatable">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin-left">12</property>
|
||||
<property name="margin-right">12</property>
|
||||
<property name="margin-top">8</property>
|
||||
<property name="margin-bottom">8</property>
|
||||
<property name="row-spacing">4</property>
|
||||
<property name="column-spacing">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="restriction_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Application _Suitability</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">restriction_button</property>
|
||||
<accessibility>
|
||||
<relation target="restriction_button" type="label-for"/>
|
||||
<relation target="restriction_button" type="flows-to"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="restriction_description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Restricts the applications the user can browse or install to those suitable for certain ages</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="0.88"/>
|
||||
</attributes>
|
||||
<style>
|
||||
<class name="dim-label" />
|
||||
</style>
|
||||
<accessibility>
|
||||
<relation target="restriction_button" type="description-for"/>
|
||||
</accessibility>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="restriction_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="popover">restriction_popover</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="height">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="top-attach">3</property>
|
||||
<property name="left-attach">0</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="allow_web_browsers_label" />
|
||||
<widget name="allow_web_browsers_description" />
|
||||
<widget name="restrict_applications_label" />
|
||||
<widget name="restrict_applications_description" />
|
||||
<widget name="restriction_label" />
|
||||
<widget name="allow_user_installation_label" />
|
||||
<widget name="allow_system_installation_label" />
|
||||
</widgets>
|
||||
</object>
|
||||
|
||||
<object class="MctRestrictApplicationsDialog" id="restrict_applications_dialog">
|
||||
<property name="visible">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="destroy-with-parent">False</property>
|
||||
<property name="use-header-bar">1</property>
|
||||
<signal name="delete-event" handler="on_restrict_applications_dialog_delete_event_cb" />
|
||||
<signal name="response" handler="on_restrict_applications_dialog_response_cb" />
|
||||
</object>
|
||||
</interface>
|
Loading…
Add table
Add a link
Reference in a new issue