summaryrefslogtreecommitdiffstats
path: root/panels/notifications
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--panels/notifications/cc-app-notifications-dialog.c406
-rw-r--r--panels/notifications/cc-app-notifications-dialog.h35
-rw-r--r--panels/notifications/cc-app-notifications-dialog.ui389
-rw-r--r--panels/notifications/cc-notifications-panel.c567
-rw-r--r--panels/notifications/cc-notifications-panel.h31
-rw-r--r--panels/notifications/cc-notifications-panel.ui134
-rw-r--r--panels/notifications/gnome-notifications-panel.desktop.in.in19
-rw-r--r--panels/notifications/meson.build44
-rw-r--r--panels/notifications/notifications.gresource.xml7
9 files changed, 1632 insertions, 0 deletions
diff --git a/panels/notifications/cc-app-notifications-dialog.c b/panels/notifications/cc-app-notifications-dialog.c
new file mode 100644
index 0000000..4d8ffdd
--- /dev/null
+++ b/panels/notifications/cc-app-notifications-dialog.c
@@ -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;
+}
diff --git a/panels/notifications/cc-app-notifications-dialog.h b/panels/notifications/cc-app-notifications-dialog.h
new file mode 100644
index 0000000..99b1e38
--- /dev/null
+++ b/panels/notifications/cc-app-notifications-dialog.h
@@ -0,0 +1,35 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
+ *
+ * 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/>.
+ *
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#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
diff --git a/panels/notifications/cc-app-notifications-dialog.ui b/panels/notifications/cc-app-notifications-dialog.ui
new file mode 100644
index 0000000..1bb2909
--- /dev/null
+++ b/panels/notifications/cc-app-notifications-dialog.ui
@@ -0,0 +1,389 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="CcAppNotificationsDialog" parent="GtkDialog">
+ <property name="width_request">360</property>
+ <property name="can_focus">False</property>
+ <property name="modal">True</property>
+ <property name="type_hint">dialog</property>
+ <signal name="response" handler="gtk_widget_destroy" swapped="no"/>
+ <child internal-child="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">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <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">
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="notifications_switch">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="active">True</property>
+ <signal name="notify::active" handler="notifications_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="xalign">0</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="sound_alerts_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="sound_alerts_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="xalign">0</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="max-width-chars">42</property>
+ <property name="wrap-mode">word</property>
+ <property name="label" translatable="yes">Notifications will continue to appear in the notification list when popups are disabled.</property>
+ <property name="wrap">True</property>
+ <property name="lines">-1</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ <attributes>
+ <attribute name="scale" value="0.83"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="notification_banners_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="notification_banners_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="xalign">0</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="notification_banners_content_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="notification_banners_content_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="xalign">0</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="lock_screen_notifications_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="lock_screen_notifications_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="xalign">0</property>
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="lock_screen_content_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="lock_screen_content_switch_state_set_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/notifications/cc-notifications-panel.c b/panels/notifications/cc-notifications-panel.c
new file mode 100644
index 0000000..510d706
--- /dev/null
+++ b/panels/notifications/cc-notifications-panel.c
@@ -0,0 +1,567 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
+ *
+ * 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 "cc-list-row.h"
+#include "list-box-helper.h"
+#include "cc-notifications-panel.h"
+#include "cc-notifications-resources.h"
+#include "cc-app-notifications-dialog.h"
+
+#define MASTER_SCHEMA "org.gnome.desktop.notifications"
+#define APP_SCHEMA MASTER_SCHEMA ".application"
+#define APP_PREFIX "/org/gnome/desktop/notifications/application/"
+
+struct _CcNotificationsPanel {
+ CcPanel parent_instance;
+
+ GtkListBox *app_listbox;
+ CcListRow *lock_screen_row;
+ GtkScrolledWindow *main_scrolled_window;
+ GtkBox *main_box;
+ GtkListBox *options_listbox;
+ CcListRow *dnd_row;
+ GtkSizeGroup *sizegroup1;
+
+ GSettings *master_settings;
+
+ GCancellable *cancellable;
+
+ GHashTable *known_applications;
+
+ GtkAdjustment *focus_adjustment;
+
+ GList *sections;
+ GList *sections_reverse;
+
+ GDBusProxy *perm_store;
+};
+
+struct _CcNotificationsPanelClass {
+ CcPanelClass parent;
+};
+
+typedef struct {
+ char *canonical_app_id;
+ GAppInfo *app_info;
+ GSettings *settings;
+
+ /* Temporary pointer, to pass from the loading thread
+ to the app */
+ CcNotificationsPanel *panel;
+} Application;
+
+static void build_app_store (CcNotificationsPanel *panel);
+static void select_app (CcNotificationsPanel *panel, GtkListBoxRow *row);
+static int sort_apps (gconstpointer one, gconstpointer two, gpointer user_data);
+
+CC_PANEL_REGISTER (CcNotificationsPanel, cc_notifications_panel);
+
+static void
+cc_notifications_panel_dispose (GObject *object)
+{
+ CcNotificationsPanel *panel = CC_NOTIFICATIONS_PANEL (object);
+
+ g_clear_object (&panel->master_settings);
+ g_clear_pointer (&panel->known_applications, g_hash_table_unref);
+ g_clear_pointer (&panel->sections, g_list_free);
+ g_clear_pointer (&panel->sections_reverse, g_list_free);
+
+ G_OBJECT_CLASS (cc_notifications_panel_parent_class)->dispose (object);
+}
+
+static void
+cc_notifications_panel_finalize (GObject *object)
+{
+ CcNotificationsPanel *panel = CC_NOTIFICATIONS_PANEL (object);
+
+ g_clear_object (&panel->perm_store);
+
+ G_OBJECT_CLASS (cc_notifications_panel_parent_class)->finalize (object);
+}
+
+static gboolean
+keynav_failed (CcNotificationsPanel *panel,
+ GtkDirectionType direction,
+ GtkWidget *widget)
+{
+ gdouble value, lower, upper, page;
+ GList *item, *sections;
+
+ /* Find the widget in the list of GtkWidgets */
+ if (direction == GTK_DIR_DOWN)
+ sections = panel->sections;
+ else
+ sections = panel->sections_reverse;
+
+ item = g_list_find (sections, widget);
+ g_assert (item);
+ if (item->next)
+ {
+ gtk_widget_child_focus (GTK_WIDGET (item->next->data), direction);
+ return TRUE;
+ }
+
+ value = gtk_adjustment_get_value (panel->focus_adjustment);
+ lower = gtk_adjustment_get_lower (panel->focus_adjustment);
+ upper = gtk_adjustment_get_upper (panel->focus_adjustment);
+ page = gtk_adjustment_get_page_size (panel->focus_adjustment);
+
+ if (direction == GTK_DIR_UP && value > lower)
+ {
+ gtk_adjustment_set_value (panel->focus_adjustment, lower);
+ return TRUE;
+ }
+ else if (direction == GTK_DIR_DOWN && value < upper - page)
+ {
+ gtk_adjustment_set_value (panel->focus_adjustment, upper - page);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+on_perm_store_ready (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ CcNotificationsPanel *self;
+ GDBusProxy *proxy;
+ g_autoptr(GError) error = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+ if (proxy == NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Failed to connect to xdg-app permission store: %s",
+ error->message);
+ return;
+ }
+ self = user_data;
+ self->perm_store = proxy;
+}
+
+static void
+cc_notifications_panel_init (CcNotificationsPanel *panel)
+{
+ g_resources_register (cc_notifications_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (panel));
+
+ panel->known_applications = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, g_free);
+
+ panel->master_settings = g_settings_new (MASTER_SCHEMA);
+
+ g_settings_bind (panel->master_settings, "show-banners",
+ panel->dnd_row,
+ "active", G_SETTINGS_BIND_INVERT_BOOLEAN);
+ g_settings_bind (panel->master_settings, "show-in-lock-screen",
+ panel->lock_screen_row,
+ "active", G_SETTINGS_BIND_DEFAULT);
+
+ panel->focus_adjustment = gtk_scrolled_window_get_vadjustment (panel->main_scrolled_window);
+
+ gtk_container_set_focus_vadjustment (GTK_CONTAINER (panel->main_box), panel->focus_adjustment);
+
+ panel->sections = g_list_append (panel->sections, panel->options_listbox);
+ panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->options_listbox);
+ gtk_list_box_set_header_func (panel->options_listbox,
+ cc_list_box_update_header_func,
+ NULL, NULL);
+
+ panel->sections = g_list_append (panel->sections, panel->app_listbox);
+ panel->sections_reverse = g_list_prepend (panel->sections_reverse, panel->app_listbox);
+ gtk_list_box_set_sort_func (panel->app_listbox, (GtkListBoxSortFunc)sort_apps, NULL, NULL);
+ gtk_list_box_set_header_func (panel->app_listbox,
+ cc_list_box_update_header_func,
+ NULL, NULL);
+
+ build_app_store (panel);
+
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.impl.portal.PermissionStore",
+ "/org/freedesktop/impl/portal/PermissionStore",
+ "org.freedesktop.impl.portal.PermissionStore",
+ cc_panel_get_cancellable (CC_PANEL (panel)),
+ on_perm_store_ready,
+ panel);
+}
+
+static const char *
+cc_notifications_panel_get_help_uri (CcPanel *panel)
+{
+ return "help:gnome-help/shell-notifications";
+}
+
+static void
+cc_notifications_panel_class_init (CcNotificationsPanelClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
+
+ panel_class->get_help_uri = cc_notifications_panel_get_help_uri;
+
+ /* Separate dispose() and finalize() functions are necessary
+ * to make sure we cancel the running thread before the panel
+ * gets finalized */
+ object_class->dispose = cc_notifications_panel_dispose;
+ object_class->finalize = cc_notifications_panel_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/notifications/cc-notifications-panel.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, app_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, lock_screen_row);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_scrolled_window);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, main_box);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, options_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, dnd_row);
+ gtk_widget_class_bind_template_child (widget_class, CcNotificationsPanel, sizegroup1);
+
+ gtk_widget_class_bind_template_callback (widget_class, keynav_failed);
+ gtk_widget_class_bind_template_callback (widget_class, select_app);
+}
+
+static inline GQuark
+application_quark (void)
+{
+ static GQuark quark;
+
+ if (G_UNLIKELY (quark == 0))
+ quark = g_quark_from_static_string ("cc-application");
+
+ return quark;
+}
+
+static gboolean
+on_off_label_mapping_get (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_value_set_string (value, g_variant_get_boolean (variant) ? _("On") : _("Off"));
+
+ return TRUE;
+}
+
+static void
+application_free (Application *app)
+{
+ g_free (app->canonical_app_id);
+ g_object_unref (app->app_info);
+ g_object_unref (app->settings);
+
+ g_slice_free (Application, app);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Application, application_free)
+
+static void
+add_application (CcNotificationsPanel *panel,
+ Application *app)
+{
+ GtkWidget *box, *w, *row;
+ g_autoptr(GIcon) icon = NULL;
+ const gchar *app_name;
+ int size;
+
+ app_name = g_app_info_get_name (app->app_info);
+ if (app_name == NULL || *app_name == '\0')
+ return;
+
+ icon = g_app_info_get_icon (app->app_info);
+ if (icon == NULL)
+ icon = g_themed_icon_new ("application-x-executable");
+ else
+ g_object_ref (icon);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_widget_show (box);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 10);
+
+ row = gtk_list_box_row_new ();
+ gtk_widget_show (row);
+ g_object_set_qdata_full (G_OBJECT (row), application_quark (),
+ app, (GDestroyNotify) application_free);
+
+ gtk_container_add (GTK_CONTAINER (panel->app_listbox), row);
+ gtk_container_add (GTK_CONTAINER (row), box);
+
+ w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+ gtk_style_context_add_class (gtk_widget_get_style_context (w), "lowres-icon");
+ gtk_widget_show (w);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &size, NULL);
+ gtk_image_set_pixel_size (GTK_IMAGE (w), size);
+ gtk_size_group_add_widget (panel->sizegroup1, w);
+ gtk_container_add (GTK_CONTAINER (box), w);
+
+ w = gtk_label_new (app_name);
+ gtk_widget_show (w);
+ gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_END);
+ gtk_label_set_xalign (GTK_LABEL (w), 0.0f);
+ gtk_container_add (GTK_CONTAINER (box), w);
+
+ w = gtk_label_new ("");
+ gtk_widget_show (w);
+ g_settings_bind_with_mapping (app->settings, "enable",
+ w, "label",
+ G_SETTINGS_BIND_GET |
+ G_SETTINGS_BIND_NO_SENSITIVITY,
+ on_off_label_mapping_get,
+ NULL,
+ NULL,
+ NULL);
+ gtk_widget_set_margin_end (w, 12);
+ gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
+ gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);
+
+ g_hash_table_add (panel->known_applications, g_strdup (app->canonical_app_id));
+}
+
+static void
+maybe_add_app_id (CcNotificationsPanel *panel,
+ const char *canonical_app_id)
+{
+ Application *app;
+ g_autofree gchar *path = NULL;
+ g_autofree gchar *full_app_id = NULL;
+ g_autoptr(GSettings) settings = NULL;
+ g_autoptr(GAppInfo) app_info = NULL;
+
+ if (*canonical_app_id == '\0')
+ return;
+
+ if (g_hash_table_contains (panel->known_applications,
+ canonical_app_id))
+ return;
+
+ path = g_strconcat (APP_PREFIX, canonical_app_id, "/", NULL);
+ settings = g_settings_new_with_path (APP_SCHEMA, path);
+
+ full_app_id = g_settings_get_string (settings, "application-id");
+ app_info = G_APP_INFO (g_desktop_app_info_new (full_app_id));
+
+ if (app_info == NULL) {
+ g_debug ("Not adding application '%s' (canonical app ID: %s)",
+ full_app_id, canonical_app_id);
+ /* The application cannot be found, probably it was uninstalled */
+ return;
+ }
+
+ app = g_slice_new (Application);
+ app->canonical_app_id = g_strdup (canonical_app_id);
+ app->settings = g_object_ref (settings);
+ app->app_info = g_object_ref (app_info);
+
+ g_debug ("Adding application '%s' (canonical app ID: %s)",
+ full_app_id, canonical_app_id);
+
+ add_application (panel, app);
+}
+
+static gboolean
+queued_app_info (gpointer data)
+{
+ g_autoptr(Application) app = NULL;
+ g_autoptr(CcNotificationsPanel) panel = NULL;
+
+ app = data;
+ panel = g_steal_pointer (&app->panel);
+
+ if (g_cancellable_is_cancelled (panel->cancellable) ||
+ g_hash_table_contains (panel->known_applications,
+ app->canonical_app_id))
+ return FALSE;
+
+ g_debug ("Processing queued application %s", app->canonical_app_id);
+
+ add_application (panel, app);
+ g_steal_pointer (&app);
+
+ return FALSE;
+}
+
+static char *
+app_info_get_id (GAppInfo *app_info)
+{
+ const char *desktop_id;
+ g_autofree gchar *ret = NULL;
+ const char *filename;
+ int l;
+
+ desktop_id = g_app_info_get_id (app_info);
+ if (desktop_id != NULL)
+ {
+ ret = g_strdup (desktop_id);
+ }
+ else
+ {
+ filename = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app_info));
+ ret = g_path_get_basename (filename);
+ }
+
+ if (G_UNLIKELY (g_str_has_suffix (ret, ".desktop") == FALSE))
+ return NULL;
+
+ l = strlen (desktop_id);
+ *(ret + l - strlen(".desktop")) = '\0';
+ return g_steal_pointer (&ret);
+}
+
+static void
+process_app_info (CcNotificationsPanel *panel,
+ GTask *task,
+ GAppInfo *app_info)
+{
+ Application *app;
+ g_autofree gchar *app_id = NULL;
+ g_autofree gchar *path = NULL;
+ g_autoptr(GSettings) settings = NULL;
+ GSource *source;
+ guint i;
+
+ app_id = app_info_get_id (app_info);
+ g_strcanon (app_id,
+ "0123456789"
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "-",
+ '-');
+ for (i = 0; app_id[i] != '\0'; i++)
+ app_id[i] = g_ascii_tolower (app_id[i]);
+
+ path = g_strconcat (APP_PREFIX, app_id, "/", NULL);
+ settings = g_settings_new_with_path (APP_SCHEMA, path);
+
+ app = g_slice_new (Application);
+ app->canonical_app_id = g_steal_pointer (&app_id);
+ app->settings = g_object_ref (settings);
+ app->app_info = g_object_ref (app_info);
+ app->panel = g_object_ref (panel);
+
+ source = g_idle_source_new ();
+ g_source_set_callback (source, queued_app_info, app, NULL);
+ g_source_attach (source, g_task_get_context (task));
+}
+
+static void
+load_apps_thread (GTask *task,
+ gpointer panel,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GList *iter, *apps;
+
+ apps = g_app_info_get_all ();
+
+ for (iter = apps; iter && !g_cancellable_is_cancelled (cancellable); iter = iter->next)
+ {
+ GDesktopAppInfo *app;
+
+ app = iter->data;
+ if (g_desktop_app_info_get_boolean (app, "X-GNOME-UsesNotifications")) {
+ process_app_info (panel, task, G_APP_INFO (app));
+ g_debug ("Processing app '%s'", g_app_info_get_id (G_APP_INFO (app)));
+ } else {
+ g_debug ("Skipped app '%s', doesn't use notifications", g_app_info_get_id (G_APP_INFO (app)));
+ }
+ }
+
+ g_list_free_full (apps, g_object_unref);
+}
+
+static void
+load_apps_async (CcNotificationsPanel *panel)
+{
+ g_autoptr(GTask) task = NULL;
+
+ panel->cancellable = cc_panel_get_cancellable (CC_PANEL (panel)); // FIXME: Storing reference to cancellable because it will be accessed inside the thread
+ task = g_task_new (panel, cc_panel_get_cancellable (CC_PANEL (panel)), NULL, NULL);
+ g_task_run_in_thread (task, load_apps_thread);
+}
+
+static void
+children_changed (CcNotificationsPanel *panel,
+ const char *key)
+{
+ int i;
+ g_auto (GStrv) new_app_ids = NULL;
+
+ g_settings_get (panel->master_settings,
+ "application-children",
+ "^as", &new_app_ids);
+ for (i = 0; new_app_ids[i]; i++)
+ maybe_add_app_id (panel, new_app_ids[i]);
+}
+
+static void
+build_app_store (CcNotificationsPanel *panel)
+{
+ /* Build application entries for known applications */
+ children_changed (panel, NULL);
+ g_signal_connect_object (panel->master_settings,
+ "changed::application-children",
+ G_CALLBACK (children_changed), panel, G_CONNECT_SWAPPED);
+
+ /* Scan applications that statically declare to show notifications */
+ load_apps_async (panel);
+}
+
+static void
+select_app (CcNotificationsPanel *panel,
+ GtkListBoxRow *row)
+{
+ Application *app;
+ g_autofree gchar *app_id = NULL;
+ CcAppNotificationsDialog *dialog;
+
+ app = g_object_get_qdata (G_OBJECT (row), application_quark ());
+
+ 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
+sort_apps (gconstpointer one,
+ gconstpointer two,
+ gpointer user_data)
+{
+ Application *a1, *a2;
+
+ a1 = g_object_get_qdata (G_OBJECT (one), application_quark ());
+ a2 = g_object_get_qdata (G_OBJECT (two), application_quark ());
+
+ return g_utf8_collate (g_app_info_get_name (a1->app_info),
+ g_app_info_get_name (a2->app_info));
+}
diff --git a/panels/notifications/cc-notifications-panel.h b/panels/notifications/cc-notifications-panel.h
new file mode 100644
index 0000000..386e3d8
--- /dev/null
+++ b/panels/notifications/cc-notifications-panel.h
@@ -0,0 +1,31 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
+ *
+ * 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/>.
+ *
+ */
+
+#pragma once
+
+#include <gio/gio.h>
+#include <shell/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_NOTIFICATIONS_PANEL (cc_notifications_panel_get_type ())
+
+G_DECLARE_FINAL_TYPE (CcNotificationsPanel, cc_notifications_panel, CC, NOTIFICATIONS_PANEL, CcPanel)
+
+G_END_DECLS
diff --git a/panels/notifications/cc-notifications-panel.ui b/panels/notifications/cc-notifications-panel.ui
new file mode 100644
index 0000000..31e041c
--- /dev/null
+++ b/panels/notifications/cc-notifications-panel.ui
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="CcNotificationsPanel" parent="CcPanel">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkScrolledWindow" id="main_scrolled_window">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">never</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="HdyClamp">
+ <property name="visible">True</property>
+ <property name="margin_top">32</property>
+ <property name="margin_bottom">32</property>
+ <property name="margin_start">12</property>
+ <property name="margin_end">12</property>
+ <child>
+ <object class="GtkBox" id="main_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="hexpand">True</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_bottom">32</property>
+ <property name="hexpand">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkListBox" id="options_listbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="selection_mode">none</property>
+ <signal name="keynav-failed" handler="keynav_failed" object="CcNotificationsPanel" swapped="yes" />
+ <child>
+ <object class="CcListRow" id="dnd_row">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">_Do Not Disturb</property>
+ <property name="use-underline">True</property>
+ <property name="show-switch">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="CcListRow" id="lock_screen_row">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">_Lock Screen Notifications</property>
+ <property name="use-underline">True</property>
+ <property name="show-switch">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label_item">
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="app_list_heading_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="margin_bottom">12</property>
+ <property name="label" translatable="yes" comments="List of applications.">Applications</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ <accessibility>
+ <relation type="label-for" target="app_listbox"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</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" id="app_listbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="selection_mode">none</property>
+ <signal name="keynav-failed" handler="keynav_failed" object="CcNotificationsPanel" swapped="yes" />
+ <signal name="row-activated" handler="select_app" object="CcNotificationsPanel" swapped="yes" />
+ <accessibility>
+ <relation type="labelled-by" target="app_list_heading_label"/>
+ </accessibility>
+ </object>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkSizeGroup" id="sizegroup1">
+ <property name="mode">both</property>
+ </object>
+</interface>
diff --git a/panels/notifications/gnome-notifications-panel.desktop.in.in b/panels/notifications/gnome-notifications-panel.desktop.in.in
new file mode 100644
index 0000000..4b27b3f
--- /dev/null
+++ b/panels/notifications/gnome-notifications-panel.desktop.in.in
@@ -0,0 +1,19 @@
+[Desktop Entry]
+Name=Notifications
+Comment=Control which notifications are displayed and what they show
+Exec=gnome-control-center notifications
+# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
+Icon=preferences-system-notifications
+Terminal=false
+Type=Application
+NoDisplay=true
+StartupNotify=true
+Categories=GNOME;GTK;Settings;DesktopSettings;X-GNOME-Settings-Panel;X-GNOME-PersonalizationSettings;
+OnlyShowIn=GNOME;Unity;
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-control-center
+X-GNOME-Bugzilla-Component=Notifications
+X-GNOME-Bugzilla-Version=@VERSION@
+X-GNOME-Settings-Panel=notifications
+# Translators: Search terms to find the Notifications panel. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
+Keywords=Notifications;Banner;Message;Tray;Popup;
diff --git a/panels/notifications/meson.build b/panels/notifications/meson.build
new file mode 100644
index 0000000..df70261
--- /dev/null
+++ b/panels/notifications/meson.build
@@ -0,0 +1,44 @@
+panels_list += cappletname
+desktop = 'gnome-@0@-panel.desktop'.format(cappletname)
+
+desktop_in = configure_file(
+ input: desktop + '.in.in',
+ output: desktop + '.in',
+ configuration: desktop_conf
+)
+
+i18n.merge_file(
+ desktop,
+ type: 'desktop',
+ input: desktop_in,
+ output: desktop,
+ po_dir: po_dir,
+ install: true,
+ install_dir: control_center_desktopdir
+)
+
+sources = files(
+ 'cc-notifications-panel.c',
+ 'cc-app-notifications-dialog.c'
+)
+
+resource_data = files(
+ 'cc-app-notifications-dialog.ui',
+ 'cc-notifications-panel.ui'
+)
+
+sources += gnome.compile_resources(
+ 'cc-' + cappletname + '-resources',
+ cappletname + '.gresource.xml',
+ c_name: 'cc_' + cappletname,
+ dependencies: resource_data,
+ export: true
+)
+
+panels_libs += static_library(
+ cappletname,
+ sources: sources,
+ include_directories: [ top_inc, common_inc ],
+ dependencies: common_deps,
+ c_args: cflags
+)
diff --git a/panels/notifications/notifications.gresource.xml b/panels/notifications/notifications.gresource.xml
new file mode 100644
index 0000000..8f1d5db
--- /dev/null
+++ b/panels/notifications/notifications.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/control-center/notifications">
+ <file preprocess="xml-stripblanks">cc-app-notifications-dialog.ui</file>
+ <file preprocess="xml-stripblanks">cc-notifications-panel.ui</file>
+ </gresource>
+</gresources>