notifications: Refactor app notifications dialog

The current widget has a very generic name "EditDialog" - rename it to something
that reflects better what it is for.

Implement it is as a full GtkWidget using GtkTemplate.

Move some of the logic from inside the dialog to the code that creates the dialog
so less data is passed around.

Store properties using functions instead of g_object_set_data - that passes
everything as a gpointer which is easy to make a mistake with.
This commit is contained in:
Robert Ancell 2018-06-28 12:14:55 +12:00 committed by Georges Basile Stavracas Neto
parent 3edb185fa9
commit 17dbce362e
7 changed files with 465 additions and 564 deletions

View file

@ -0,0 +1,406 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
* Copyright (C) 2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <string.h>
#include <glib/gi18n-lib.h>
#include <glib.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include "list-box-helper.h"
#include "cc-notifications-panel.h"
#include "cc-app-notifications-dialog.h"
/*
* Key Switch
*
* "enable", "notifications-switch" When set to off, all other switches in the dialog are insensitive
* "enable-sound-alerts", "sound-alerts-switch"
* "show-banners", "notification-banners-switch" Off and insensitive when corresponding panel switch is off
* "force-expanded", "notification-banners-content-switch" Off and insensitive when switch above is off
* "show-in-lock-screen", "lock-screen-notifications-switch" Off and insensitive when corresponding panel switch is off
* "details-in-lock-screen", "lock-screen-content-switch" Off and insensitive when switch above is off
*/
static void update_banner_switch (CcAppNotificationsDialog *dialog);
static void update_banner_content_switch (CcAppNotificationsDialog *dialog);
static void update_lock_screen_switch (CcAppNotificationsDialog *dialog);
static void update_lock_screen_content_switch (CcAppNotificationsDialog *dialog);
static void update_sound_switch (CcAppNotificationsDialog *dialog);
static void update_notification_switch (CcAppNotificationsDialog *dialog);
struct _CcAppNotificationsDialog {
GtkDialog parent;
GSettings *settings;
GSettings *master_settings;
gchar *app_id;
GDBusProxy *perm_store;
GtkWidget *main_listbox;
GtkWidget *notifications_switch;
GtkWidget *sound_alerts_switch;
GtkWidget *notification_banners_switch;
GtkWidget *notification_banners_content_switch;
GtkWidget *lock_screen_notifications_switch;
GtkWidget *lock_screen_content_switch;
};
G_DEFINE_TYPE (CcAppNotificationsDialog, cc_app_notifications_dialog, GTK_TYPE_DIALOG)
static void
on_perm_store_set_done (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
g_autoptr(GVariant) results = NULL;
g_autoptr(GError) error = NULL;
results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
res,
&error);
if (results == NULL)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Failed to store permissions: %s", error->message);
return;
}
}
static void
set_portal_permissions_for_app (CcAppNotificationsDialog *dialog, GtkSwitch *the_switch)
{
gboolean allow = gtk_switch_get_active (the_switch);
g_autoptr(GVariant) perms = NULL;
g_autoptr(GVariant) new_perms = NULL;
g_autoptr(GVariant) data = NULL;
GVariantBuilder builder;
gboolean found;
int i;
const char *yes_strv[] = { "yes", NULL };
const char *no_strv[] = { "no", NULL };
g_autoptr(GVariant) reply = NULL;
if (dialog->perm_store == NULL)
{
g_warning ("Could not find PermissionStore, not syncing notification permissions");
return;
}
new_perms = g_variant_new_strv (allow ? yes_strv : no_strv, 1);
g_variant_ref_sink (new_perms);
g_variant_builder_init (&builder, G_VARIANT_TYPE("a{sas}"));
found = FALSE;
reply = g_dbus_proxy_call_sync (dialog->perm_store,
"Lookup",
g_variant_new ("(ss)",
"notifications",
"notification"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL);
if (reply)
{
g_variant_get (reply, "(@a{sas}v)", &perms, &data);
for (i = 0; i < g_variant_n_children (perms); i++)
{
const char *key;
g_autoptr(GVariant) value = NULL;
g_variant_get_child (perms, i, "{&s@as}", &key, &value);
if (g_strcmp0 (key, dialog->app_id) == 0)
{
found = TRUE;
g_variant_builder_add (&builder, "{s@as}", key, new_perms);
}
else
g_variant_builder_add (&builder, "{s@as}", key, value);
}
}
if (!found)
g_variant_builder_add (&builder, "{s@as}", dialog->app_id, new_perms);
g_dbus_proxy_call (dialog->perm_store,
"Set",
g_variant_new ("(sbsa{sas}v)",
"notifications",
TRUE,
"notification",
&builder,
data ? data : g_variant_new_byte (0)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
on_perm_store_set_done,
data);
}
static void
notifications_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "enable", gtk_switch_get_active (widget));
set_portal_permissions_for_app (dialog, widget);
update_sound_switch (dialog);
update_banner_switch (dialog);
update_banner_content_switch (dialog);
update_lock_screen_switch (dialog);
update_lock_screen_content_switch (dialog);
}
static void
sound_alerts_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "enable-sound-alerts", gtk_switch_get_active (widget));
}
static void
notification_banners_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "show-banners", gtk_switch_get_active (widget));
update_banner_content_switch (dialog);
}
static void
notification_banners_content_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "force-expanded", gtk_switch_get_active (widget));
}
static void
lock_screen_notifications_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "show-in-lock-screen", gtk_switch_get_active (widget));
update_lock_screen_content_switch (dialog);
}
static void
lock_screen_content_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
CcAppNotificationsDialog *dialog)
{
g_settings_set_boolean (dialog->settings, "details-in-lock-screen", gtk_switch_get_active (widget));
}
static void
update_switches (CcAppNotificationsDialog *dialog)
{
update_notification_switch (dialog);
update_sound_switch (dialog);
update_banner_switch (dialog);
update_banner_content_switch (dialog);
update_lock_screen_switch (dialog);
update_lock_screen_content_switch (dialog);
}
static void
update_notification_switch (CcAppNotificationsDialog *dialog)
{
g_signal_handlers_block_by_func (G_OBJECT (dialog->notifications_switch), notifications_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->notifications_switch), g_settings_get_boolean (dialog->settings, "enable"));
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->notifications_switch), notifications_switch_state_set_cb, dialog);
}
static void
update_sound_switch (CcAppNotificationsDialog *dialog)
{
g_signal_handlers_block_by_func (G_OBJECT (dialog->sound_alerts_switch), sound_alerts_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->sound_alerts_switch), g_settings_get_boolean (dialog->settings, "enable-sound-alerts"));
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->sound_alerts_switch), sound_alerts_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (dialog->sound_alerts_switch, g_settings_get_boolean (dialog->settings, "enable"));
}
static void
update_banner_switch (CcAppNotificationsDialog *dialog)
{
gboolean notifications_enabled;
gboolean show_banners;
gboolean active;
gboolean sensitive;
show_banners = g_settings_get_boolean (dialog->master_settings, "show-banners");
notifications_enabled = g_settings_get_boolean (dialog->settings, "enable");
active = g_settings_get_boolean (dialog->settings, "show-banners") &&
show_banners;
sensitive = notifications_enabled &&
show_banners;
g_signal_handlers_block_by_func (G_OBJECT (dialog->notification_banners_switch), notification_banners_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->notification_banners_switch), active);
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->notification_banners_switch), notification_banners_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (dialog->notification_banners_switch, sensitive);
}
static void
update_banner_content_switch (CcAppNotificationsDialog *dialog)
{
gboolean notifications_enabled;
gboolean show_banners;
gboolean active;
gboolean sensitive;
show_banners = g_settings_get_boolean (dialog->master_settings, "show-banners");
notifications_enabled = g_settings_get_boolean (dialog->settings, "enable");
active = g_settings_get_boolean (dialog->settings, "force-expanded") &&
g_settings_get_boolean (dialog->settings, "show-banners") &&
show_banners;
sensitive = g_settings_get_boolean (dialog->settings, "show-banners") &&
notifications_enabled &&
show_banners;
g_signal_handlers_block_by_func (G_OBJECT (dialog->notification_banners_content_switch), notification_banners_content_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->notification_banners_content_switch), active);
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->notification_banners_content_switch), notification_banners_content_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (dialog->notification_banners_content_switch, sensitive);
}
static void
update_lock_screen_switch (CcAppNotificationsDialog *dialog)
{
gboolean notifications_enabled;
gboolean show_in_lock_screen;
gboolean active;
gboolean sensitive;
show_in_lock_screen = g_settings_get_boolean (dialog->master_settings, "show-in-lock-screen");
notifications_enabled = g_settings_get_boolean (dialog->settings, "enable");
active = g_settings_get_boolean (dialog->settings, "show-in-lock-screen") &&
show_in_lock_screen;
sensitive = notifications_enabled &&
show_in_lock_screen;
g_signal_handlers_block_by_func (G_OBJECT (dialog->lock_screen_notifications_switch), lock_screen_notifications_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->lock_screen_notifications_switch), active);
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->lock_screen_notifications_switch), lock_screen_notifications_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (dialog->lock_screen_notifications_switch, sensitive);
}
static void
update_lock_screen_content_switch (CcAppNotificationsDialog *dialog)
{
gboolean notifications_enabled;
gboolean show_in_lock_screen;
gboolean active;
gboolean sensitive;
show_in_lock_screen = g_settings_get_boolean (dialog->master_settings, "show-in-lock-screen");
notifications_enabled = g_settings_get_boolean (dialog->settings, "enable");
active = g_settings_get_boolean (dialog->settings, "details-in-lock-screen") &&
g_settings_get_boolean (dialog->settings, "show-in-lock-screen") &&
show_in_lock_screen;
sensitive = g_settings_get_boolean (dialog->settings, "show-in-lock-screen") &&
notifications_enabled &&
show_in_lock_screen;
g_signal_handlers_block_by_func (G_OBJECT (dialog->lock_screen_content_switch), lock_screen_content_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (dialog->lock_screen_content_switch), active);
g_signal_handlers_unblock_by_func (G_OBJECT (dialog->lock_screen_content_switch), lock_screen_content_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (dialog->lock_screen_content_switch, sensitive);
}
static void
cc_app_notifications_dialog_dispose (GObject *object)
{
CcAppNotificationsDialog *dialog = CC_APP_NOTIFICATIONS_DIALOG (object);
g_clear_object (&dialog->settings);
g_clear_object (&dialog->master_settings);
g_clear_pointer (&dialog->app_id, g_free);
g_clear_object (&dialog->perm_store);
G_OBJECT_CLASS (cc_app_notifications_dialog_parent_class)->dispose (object);
}
static void
cc_app_notifications_dialog_class_init (CcAppNotificationsDialogClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = cc_app_notifications_dialog_dispose;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/notifications/cc-app-notifications-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, main_listbox);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, notifications_switch);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, sound_alerts_switch);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, notification_banners_switch);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, notification_banners_content_switch);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, lock_screen_notifications_switch);
gtk_widget_class_bind_template_child (widget_class, CcAppNotificationsDialog, lock_screen_content_switch);
gtk_widget_class_bind_template_callback (widget_class, notifications_switch_state_set_cb);
gtk_widget_class_bind_template_callback (widget_class, sound_alerts_switch_state_set_cb);
gtk_widget_class_bind_template_callback (widget_class, notification_banners_switch_state_set_cb);
gtk_widget_class_bind_template_callback (widget_class, notification_banners_content_switch_state_set_cb);
gtk_widget_class_bind_template_callback (widget_class, lock_screen_notifications_switch_state_set_cb);
gtk_widget_class_bind_template_callback (widget_class, lock_screen_content_switch_state_set_cb);
}
void
cc_app_notifications_dialog_init (CcAppNotificationsDialog *dialog)
{
gtk_widget_init_template (GTK_WIDGET (dialog));
gtk_list_box_set_header_func (GTK_LIST_BOX (dialog->main_listbox),
cc_list_box_update_header_func,
NULL, NULL);
}
CcAppNotificationsDialog *
cc_app_notifications_dialog_new (const gchar *app_id,
const gchar *title,
GSettings *settings,
GSettings *master_settings,
GDBusProxy *perm_store)
{
CcAppNotificationsDialog *dialog;
dialog = g_object_new (CC_TYPE_APP_NOTIFICATIONS_DIALOG,
"use-header-bar", 1,
NULL);
gtk_window_set_title (GTK_WINDOW (dialog), title);
dialog->settings = g_object_ref (settings);
dialog->master_settings = g_object_ref (master_settings);
dialog->app_id = g_strdup (app_id);
dialog->perm_store = g_object_ref (perm_store);
update_switches (dialog);
return dialog;
}

View file

@ -19,14 +19,17 @@
#pragma once
#include "cc-notifications-panel.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
void cc_build_edit_dialog (CcNotificationsPanel *panel,
GAppInfo *app,
GSettings *settings,
GSettings *master_settings,
GDBusProxy *perm_store);
#define CC_TYPE_APP_NOTIFICATIONS_DIALOG (cc_app_notifications_dialog_get_type ())
G_DECLARE_FINAL_TYPE (CcAppNotificationsDialog, cc_app_notifications_dialog, CC, APP_NOTIFICATIONS_DIALOG, GtkDialog)
CcAppNotificationsDialog *cc_app_notifications_dialog_new (const gchar *app_id,
const gchar *title,
GSettings *settings,
GSettings *master_settings,
GDBusProxy *perm_store);
G_END_DECLS

View file

@ -1,23 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkDialog" id="edit-dialog">
<template class="CcAppNotificationsDialog" parent="GtkDialog">
<property name="width_request">450</property>
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="use_header_bar">1</property>
<signal name="response" handler="gtk_widget_destroy" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="edit-dialog-vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<property name="border_width">0</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="edit-dialog-action-area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
@ -34,20 +31,20 @@
</packing>
</child>
<child>
<object class="GtkListBox" id="main-listbox">
<object class="GtkListBox" id="main_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<property name="activate_on_single_click">False</property>
<child>
<object class="GtkListBoxRow" id="notifications-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="notifications-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -55,7 +52,7 @@
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="notifications-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -63,7 +60,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes" context="notifications" comments="This is the per application switch for message tray usage.">_Notifications</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">notifications-switch</property>
<property name="mnemonic_widget">notifications_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -72,7 +69,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="notifications-switch">
<object class="GtkSwitch" id="notifications_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -91,14 +88,14 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="sound-alerts-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="sound-alerts-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -106,7 +103,7 @@
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="sound-alerts-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -115,7 +112,7 @@
<property name="margin_end">15</property>
<property name="label" translatable="yes" context="notifications" comments="This is the setting to configure sounds associated with notifications.">Sound _Alerts</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">sound-alerts-switch</property>
<property name="mnemonic_widget">sound_alerts_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -124,7 +121,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="sound-alerts-switch">
<object class="GtkSwitch" id="sound_alerts_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -142,14 +139,14 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="notification-banners-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="notification-banners-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -162,7 +159,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="notification-banners-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -171,7 +168,7 @@
<property name="margin_end">15</property>
<property name="label" translatable="yes" context="notifications">Notification _Popups</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">notification-banners-switch</property>
<property name="mnemonic_widget">notification_banners_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -180,7 +177,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="notification-banners-info">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="max-width-chars">42</property>
@ -210,7 +207,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="notification-banners-switch">
<object class="GtkSwitch" id="notification_banners_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -228,14 +225,14 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="notification-banners-content-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="notification-banners-content-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -243,7 +240,7 @@
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="notification-banners-content-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -252,7 +249,7 @@
<property name="margin_end">15</property>
<property name="label" translatable="yes" context="notifications" comments="Popups here refers to message tray notifications in the middle of the screen.">Show Message _Content in Popups</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">notification-banners-content-switch</property>
<property name="mnemonic_widget">notification_banners_content_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -261,7 +258,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="notification-banners-content-switch">
<object class="GtkSwitch" id="notification_banners_content_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -279,14 +276,14 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="lock-screen-notifications-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="lock-screen-notifications-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -294,7 +291,7 @@
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="lock-screen-notifications-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -303,7 +300,7 @@
<property name="margin_end">15</property>
<property name="label" translatable="yes" context="notifications">_Lock Screen Notifications</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">lock-screen-notifications-switch</property>
<property name="mnemonic_widget">lock_screen_notifications_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -312,7 +309,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="lock-screen-notifications-switch">
<object class="GtkSwitch" id="lock_screen_notifications_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -330,14 +327,14 @@
</object>
</child>
<child>
<object class="GtkListBoxRow" id="lock-screen-content-listboxrow">
<object class="GtkListBoxRow">
<property name="width_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activatable">False</property>
<property name="selectable">False</property>
<child>
<object class="GtkBox" id="lock-screen-content-box">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">15</property>
@ -345,7 +342,7 @@
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="lock-screen-content-label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
@ -354,7 +351,7 @@
<property name="margin_end">15</property>
<property name="label" translatable="yes" context="notifications">Show Message C_ontent on Lock Screen</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">lock-screen-content-switch</property>
<property name="mnemonic_widget">lock_screen_content_switch</property>
</object>
<packing>
<property name="expand">False</property>
@ -363,7 +360,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="lock-screen-content-switch">
<object class="GtkSwitch" id="lock_screen_content_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
@ -389,5 +386,5 @@
</child>
</object>
</child>
</object>
</template>
</interface>

View file

@ -1,514 +0,0 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* Copyright (C) 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
* Copyright (C) 2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <string.h>
#include <glib/gi18n-lib.h>
#include <glib.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include "list-box-helper.h"
#include "cc-notifications-panel.h"
#include "cc-edit-dialog.h"
/*
* Key Switch
*
* "enable", "notifications-switch" When set to off, all other switches in the dialog are insensitive
* "enable-sound-alerts", "sound-alerts-switch"
* "show-banners", "notification-banners-switch" Off and insensitive when corresponding panel switch is off
* "force-expanded", "notification-banners-content-switch" Off and insensitive when switch above is off
* "show-in-lock-screen", "lock-screen-notifications-switch" Off and insensitive when corresponding panel switch is off
* "details-in-lock-screen", "lock-screen-content-switch" Off and insensitive when switch above is off
*/
static void update_banner_switch (GtkWidget *dialog);
static void update_banner_content_switch (GtkWidget *dialog);
static void update_lock_screen_switch (GtkWidget *dialog);
static void update_lock_screen_content_switch (GtkWidget *dialog);
static void update_sound_switch (GtkWidget *dialog);
static void update_notification_switch (GtkWidget *dialog);
static void update_switches (GtkWidget *dialog);
static void
dialog_set_app_id (GtkWidget *dialog,
const char *app_id)
{
g_object_set_data_full (G_OBJECT (dialog), "app-id", g_strdup (app_id), g_free);
}
static const char *
dialog_get_app_id (GtkWidget *dialog)
{
return (const char*)g_object_get_data (G_OBJECT (dialog), "app-id");
}
static void
dialog_set_perm_store (GtkWidget *dialog,
GDBusProxy *proxy)
{
if (proxy)
g_object_set_data_full (G_OBJECT (dialog), "perm-store", g_object_ref (proxy), g_object_unref);
}
static GDBusProxy *
dialog_get_perm_store (GtkWidget *dialog)
{
return (GDBusProxy *)g_object_get_data (G_OBJECT (dialog), "perm-store");
}
static GtkWidget *
get_switch (GtkBuilder *builder,
const gchar *prefix)
{
g_autofree gchar *name = NULL;
name = g_strdup_printf ("%s-switch", prefix);
return GTK_WIDGET (gtk_builder_get_object (builder, name));
}
static void
set_key_from_switch (GtkWidget *dialog,
const gchar *key,
GtkSwitch *the_switch)
{
GSettings *settings;
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
g_settings_set_boolean (settings, key, gtk_switch_get_active (the_switch));
}
static void
on_perm_store_set_done (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
g_autoptr(GVariant) results = NULL;
g_autoptr(GError) error = NULL;
results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
res,
&error);
if (results == NULL)
{
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Failed to store permissions: %s", error->message);
return;
}
}
static void
set_portal_permissions_for_app (GtkWidget *dialog, GtkSwitch *the_switch)
{
GDBusProxy *perm_store = dialog_get_perm_store (dialog);
const char *app_id = dialog_get_app_id (dialog);
gboolean allow = gtk_switch_get_active (the_switch);
g_autoptr(GVariant) perms = NULL;
g_autoptr(GVariant) new_perms = NULL;
g_autoptr(GVariant) data = NULL;
GVariantBuilder builder;
gboolean found;
int i;
const char *yes_strv[] = { "yes", NULL };
const char *no_strv[] = { "no", NULL };
g_autoptr(GVariant) reply = NULL;
if (perm_store == NULL)
{
g_warning ("Could not find PermissionStore, not syncing notification permissions");
return;
}
new_perms = g_variant_new_strv (allow ? yes_strv : no_strv, 1);
g_variant_ref_sink (new_perms);
g_variant_builder_init (&builder, G_VARIANT_TYPE("a{sas}"));
found = FALSE;
reply = g_dbus_proxy_call_sync (perm_store,
"Lookup",
g_variant_new ("(ss)",
"notifications",
"notification"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL);
if (reply)
{
g_variant_get (reply, "(@a{sas}v)", &perms, &data);
for (i = 0; i < g_variant_n_children (perms); i++)
{
const char *key;
g_autoptr(GVariant) value = NULL;
g_variant_get_child (perms, i, "{&s@as}", &key, &value);
if (g_strcmp0 (key, app_id) == 0)
{
found = TRUE;
g_variant_builder_add (&builder, "{s@as}", key, new_perms);
}
else
g_variant_builder_add (&builder, "{s@as}", key, value);
}
}
if (!found)
g_variant_builder_add (&builder, "{s@as}", app_id, new_perms);
g_dbus_proxy_call (perm_store,
"Set",
g_variant_new ("(sbsa{sas}v)",
"notifications",
TRUE,
"notification",
&builder,
data ? data : g_variant_new_byte (0)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
on_perm_store_set_done,
data);
}
static void
notifications_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "enable", widget);
set_portal_permissions_for_app (dialog, widget);
update_sound_switch (dialog);
update_banner_switch (dialog);
update_banner_content_switch (dialog);
update_lock_screen_switch (dialog);
update_lock_screen_content_switch (dialog);
}
static void
sound_alerts_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "enable-sound-alerts", widget);
}
static void
notification_banners_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "show-banners", widget);
update_banner_content_switch (dialog);
}
static void
notification_banners_content_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "force-expanded", widget);
}
static void
lock_screen_notifications_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "show-in-lock-screen", widget);
update_lock_screen_content_switch (dialog);
}
static void
lock_screen_content_switch_state_set_cb (GtkSwitch *widget,
GParamSpec *pspec,
GtkWidget *dialog)
{
set_key_from_switch (dialog, "details-in-lock-screen", widget);
}
static void
update_switches (GtkWidget *dialog)
{
update_notification_switch (dialog);
update_sound_switch (dialog);
update_banner_switch (dialog);
update_banner_content_switch (dialog);
update_lock_screen_switch (dialog);
update_lock_screen_content_switch (dialog);
}
static void
update_notification_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GtkWidget *widget;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
widget = get_switch (builder, "notifications");
g_signal_handlers_block_by_func (G_OBJECT (widget), notifications_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), g_settings_get_boolean (settings, "enable"));
g_signal_handlers_unblock_by_func (G_OBJECT (widget), notifications_switch_state_set_cb, dialog);
}
static void
update_sound_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GtkWidget *widget;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
widget = get_switch (builder, "sound-alerts");
g_signal_handlers_block_by_func (G_OBJECT (widget), sound_alerts_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), g_settings_get_boolean (settings, "enable-sound-alerts"));
g_signal_handlers_unblock_by_func (G_OBJECT (widget), sound_alerts_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (widget, g_settings_get_boolean (settings, "enable"));
}
static void
update_banner_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GSettings *master_settings;
GtkWidget *widget;
gboolean notifications_enabled;
gboolean show_banners;
gboolean active;
gboolean sensitive;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
master_settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "master-settings"));
show_banners = g_settings_get_boolean (master_settings, "show-banners");
notifications_enabled = g_settings_get_boolean (settings, "enable");
widget = get_switch (builder, "notification-banners");
active = g_settings_get_boolean (settings, "show-banners") &&
show_banners;
sensitive = notifications_enabled &&
show_banners;
g_signal_handlers_block_by_func (G_OBJECT (widget), notification_banners_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), active);
g_signal_handlers_unblock_by_func (G_OBJECT (widget), notification_banners_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (widget, sensitive);
}
static void
update_banner_content_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GSettings *master_settings;
GtkWidget *widget;
gboolean notifications_enabled;
gboolean show_banners;
gboolean active;
gboolean sensitive;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
master_settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "master-settings"));
show_banners = g_settings_get_boolean (master_settings, "show-banners");
notifications_enabled = g_settings_get_boolean (settings, "enable");
widget = get_switch (builder, "notification-banners-content");
active = g_settings_get_boolean (settings, "force-expanded") &&
g_settings_get_boolean (settings, "show-banners") &&
show_banners;
sensitive = g_settings_get_boolean (settings, "show-banners") &&
notifications_enabled &&
show_banners;
g_signal_handlers_block_by_func (G_OBJECT (widget), notification_banners_content_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), active);
g_signal_handlers_unblock_by_func (G_OBJECT (widget), notification_banners_content_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (widget, sensitive);
}
static void
update_lock_screen_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GSettings *master_settings;
GtkWidget *widget;
gboolean notifications_enabled;
gboolean show_in_lock_screen;
gboolean active;
gboolean sensitive;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
master_settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "master-settings"));
show_in_lock_screen = g_settings_get_boolean (master_settings, "show-in-lock-screen");
notifications_enabled = g_settings_get_boolean (settings, "enable");
widget = get_switch (builder, "lock-screen-notifications");
active = g_settings_get_boolean (settings, "show-in-lock-screen") &&
show_in_lock_screen;
sensitive = notifications_enabled &&
show_in_lock_screen;
g_signal_handlers_block_by_func (G_OBJECT (widget), lock_screen_notifications_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), active);
g_signal_handlers_unblock_by_func (G_OBJECT (widget), lock_screen_notifications_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (widget, sensitive);
}
static void
update_lock_screen_content_switch (GtkWidget *dialog)
{
GtkBuilder *builder;
GSettings *settings;
GSettings *master_settings;
GtkWidget *widget;
gboolean notifications_enabled;
gboolean show_in_lock_screen;
gboolean active;
gboolean sensitive;
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (dialog), "builder"));
settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "settings"));
master_settings = G_SETTINGS (g_object_get_data (G_OBJECT (dialog), "master-settings"));
show_in_lock_screen = g_settings_get_boolean (master_settings, "show-in-lock-screen");
notifications_enabled = g_settings_get_boolean (settings, "enable");
widget = get_switch (builder, "lock-screen-content");
active = g_settings_get_boolean (settings, "details-in-lock-screen") &&
g_settings_get_boolean (settings, "show-in-lock-screen") &&
show_in_lock_screen;
sensitive = g_settings_get_boolean (settings, "show-in-lock-screen") &&
notifications_enabled &&
show_in_lock_screen;
g_signal_handlers_block_by_func (G_OBJECT (widget), lock_screen_content_switch_state_set_cb, dialog);
gtk_switch_set_active (GTK_SWITCH (widget), active);
g_signal_handlers_unblock_by_func (G_OBJECT (widget), lock_screen_content_switch_state_set_cb, dialog);
gtk_widget_set_sensitive (widget, sensitive);
}
void
cc_build_edit_dialog (CcNotificationsPanel *panel,
GAppInfo *app,
GSettings *settings,
GSettings *master_settings,
GDBusProxy *perm_store)
{
g_autoptr(GtkBuilder) builder = NULL;
GtkWindow *shell;
GtkWidget *dialog;
GtkWidget *listbox;
g_autoptr(GError) error = NULL;
gchar *objects[] = { "edit-dialog", NULL };
guint builder_result;
g_autofree gchar *app_id = NULL;
builder = gtk_builder_new ();
builder_result = gtk_builder_add_objects_from_resource (builder,
"/org/gnome/control-center/notifications/edit-dialog.ui",
objects,
&error);
if (builder_result == 0)
{
g_warning ("Could not load ui: %s", error->message);
return;
}
shell = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel)));
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "edit-dialog"));
app_id = g_strdup (g_app_info_get_id (app));
if (g_str_has_suffix (app_id, ".desktop"))
app_id[strlen (app_id) - strlen (".desktop")] = '\0';
dialog_set_app_id (dialog, app_id);
dialog_set_perm_store (dialog, perm_store);
g_object_set (dialog,
"title", g_app_info_get_name (app),
"transient-for", shell,
NULL);
listbox = GTK_WIDGET (gtk_builder_get_object (builder,
"main-listbox"));
gtk_list_box_set_header_func (GTK_LIST_BOX (listbox),
cc_list_box_update_header_func,
NULL, NULL);
/*
* Store builder, settings and master_settings to the dialog so we can
* access them from callbacks easily.
*/
g_object_set_data_full (G_OBJECT (dialog),
"builder",
g_object_ref (builder),
g_object_unref);
g_object_set_data_full (G_OBJECT (dialog),
"settings",
g_object_ref (settings),
g_object_unref);
g_object_set_data_full (G_OBJECT (dialog),
"master-settings",
g_object_ref (master_settings),
g_object_unref);
/* Connect signals */
gtk_builder_add_callback_symbols (builder,
"notifications_switch_state_set_cb",
G_CALLBACK (notifications_switch_state_set_cb),
"sound_alerts_switch_state_set_cb",
G_CALLBACK (sound_alerts_switch_state_set_cb),
"notification_banners_switch_state_set_cb",
G_CALLBACK (notification_banners_switch_state_set_cb),
"notification_banners_content_switch_state_set_cb",
G_CALLBACK (notification_banners_content_switch_state_set_cb),
"lock_screen_notifications_switch_state_set_cb",
G_CALLBACK (lock_screen_notifications_switch_state_set_cb),
"lock_screen_content_switch_state_set_cb",
G_CALLBACK (lock_screen_content_switch_state_set_cb),
NULL);
gtk_builder_connect_signals (builder, dialog);
/* Init states of switches */
update_switches (dialog);
/* Show the dialog */
gtk_widget_show_all (dialog);
}

View file

@ -29,7 +29,7 @@
#include "list-box-helper.h"
#include "cc-notifications-panel.h"
#include "cc-notifications-resources.h"
#include "cc-edit-dialog.h"
#include "cc-app-notifications-dialog.h"
#define MASTER_SCHEMA "org.gnome.desktop.notifications"
#define APP_SCHEMA MASTER_SCHEMA ".application"
@ -557,9 +557,18 @@ select_app (GtkListBox *list_box,
CcNotificationsPanel *panel)
{
Application *app;
g_autofree gchar *app_id = NULL;
CcAppNotificationsDialog *dialog;
app = g_object_get_qdata (G_OBJECT (row), application_quark ());
cc_build_edit_dialog (panel, app->app_info, app->settings, panel->master_settings, panel->perm_store);
app_id = g_strdup (g_app_info_get_id (app->app_info));
if (g_str_has_suffix (app_id, ".desktop"))
app_id[strlen (app_id) - strlen (".desktop")] = '\0';
dialog = cc_app_notifications_dialog_new (app_id, g_app_info_get_name (app->app_info), app->settings, panel->master_settings, panel->perm_store);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));
gtk_widget_show (GTK_WIDGET (dialog));
}
static int

View file

@ -19,11 +19,11 @@ i18n.merge_file(
sources = files(
'cc-notifications-panel.c',
'cc-edit-dialog.c'
'cc-app-notifications-dialog.c'
)
resource_data = files(
'edit-dialog.ui',
'cc-app-notifications-dialog.ui',
'notifications.ui'
)

View file

@ -2,6 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/control-center/notifications">
<file preprocess="xml-stripblanks">notifications.ui</file>
<file preprocess="xml-stripblanks">edit-dialog.ui</file>
<file preprocess="xml-stripblanks">cc-app-notifications-dialog.ui</file>
</gresource>
</gresources>