1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-06-28 06:39:32 +00:00

Add class for in-app notification

This commit is contained in:
Julian Sparber 2020-03-02 18:49:53 +01:00
parent cad79a4834
commit e7e95efcfb
No known key found for this signature in database
GPG key ID: 7A0E81F405F35D6A
5 changed files with 272 additions and 0 deletions

View file

@ -0,0 +1,179 @@
/*
* Copyright (C) 2020 Purism SPC
*
* This file is part of Calls.
*
* Calls is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calls is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Julian Sparber <julian@sparber.net>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "calls-in-app-notification.h"
#define DEFAULT_TIMEOUT_SECONDS 3
struct _CallsInAppNotification
{
GtkRevealer parent_instance;
GtkLabel *label;
gint timeout;
guint timeout_id;
};
G_DEFINE_TYPE (CallsInAppNotification, calls_in_app_notification, GTK_TYPE_REVEALER)
enum {
PROP_0,
PROP_TIMEOUT,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static gboolean
timeout_cb (CallsInAppNotification *self)
{
calls_in_app_notification_hide (self);
return G_SOURCE_REMOVE;
}
static void
calls_in_app_notification_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object);
switch (property_id) {
case PROP_TIMEOUT:
g_value_set_int (value, self->timeout);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
calls_in_app_notification_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object);
switch (property_id)
{
case PROP_TIMEOUT:
self->timeout = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
calls_in_app_notification_finalize (GObject *object)
{
CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object);
if (self->timeout_id)
g_source_remove (self->timeout_id);
G_OBJECT_CLASS (calls_in_app_notification_parent_class)->finalize (object);
}
static void
calls_in_app_notification_class_init (CallsInAppNotificationClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = calls_in_app_notification_get_property;
object_class->set_property = calls_in_app_notification_set_property;
object_class->finalize = calls_in_app_notification_finalize;
props[PROP_TIMEOUT] = g_param_spec_int ("timeout",
"Timeout",
"The time the in-app notifaction should be shown",
-1,
G_MAXINT,
3,
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/in-app-notification.ui");
gtk_widget_class_bind_template_child (widget_class, CallsInAppNotification, label);
gtk_widget_class_bind_template_callback (widget_class, calls_in_app_notification_hide);
}
static void
calls_in_app_notification_init (CallsInAppNotification *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
self->timeout = DEFAULT_TIMEOUT_SECONDS;
}
CallsInAppNotification *
calls_in_app_notification_new ()
{
return g_object_new (CALLS_TYPE_IN_APP_NOTIFICATION, NULL);
}
void
calls_in_app_notification_show (CallsInAppNotification *self, const gchar *message)
{
g_return_if_fail (CALLS_IS_IN_APP_NOTIFICATION (self));
gtk_label_set_text (self->label, message);
if (self->timeout_id)
g_source_remove (self->timeout_id);
gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
self->timeout_id = g_timeout_add_seconds (self->timeout, (GSourceFunc)timeout_cb, self);
}
void
calls_in_app_notification_hide (CallsInAppNotification *self)
{
g_return_if_fail (CALLS_IS_IN_APP_NOTIFICATION (self));
if (self->timeout_id)
{
g_source_remove (self->timeout_id);
self->timeout_id = 0;
}
gtk_revealer_set_reveal_child (GTK_REVEALER(self), FALSE);
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (C) 2020 Purism SPC
*
* This file is part of Calls.
*
* Calls is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calls is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Julian Sparber <julian@sparber.net>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef CALLS_IN_APP_NOTIFICATION_H__
#define CALLS_IN_APP_NOTIFICATION_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define CALLS_TYPE_IN_APP_NOTIFICATION (calls_in_app_notification_get_type ())
G_DECLARE_FINAL_TYPE (CallsInAppNotification, calls_in_app_notification, CALLS, IN_APP_NOTIFICATION, GtkRevealer)
CallsInAppNotification * calls_in_app_notification_new ();
void calls_in_app_notification_show (CallsInAppNotification *self, const gchar *message);
void calls_in_app_notification_hide (CallsInAppNotification *self);
G_END_DECLS
#endif /* CALLS_IN_APP_NOTIFICATION_H__ */

View file

@ -11,6 +11,7 @@
<file preprocess="xml-stripblanks">new-call-box.ui</file>
<file preprocess="xml-stripblanks">new-call-header-bar.ui</file>
<file preprocess="xml-stripblanks">call-record-row.ui</file>
<file preprocess="xml-stripblanks">in-app-notification.ui</file>
</gresource>
<gresource prefix="/sm/puri/calls/">
<file>style.css</file>

View file

@ -88,6 +88,7 @@ calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
'calls-call-record-row.c', 'calls-call-record-row.h',
'calls-contacts.c', 'calls-contacts.h',
'calls-best-match.c', 'calls-best-match.h',
'calls-in-app-notification.c', 'calls-in-app-notification.h',
])
calls_config_data = config_data

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="CallsInAppNotification" parent="GtkRevealer">
<property name="reveal-child">False</property>
<property name="transition-type">slide-down</property>
<property name="valign">start</property>
<property name="halign">center</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="calls_in_app_notification_hide" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">window-close-symbolic</property>
</object>
</child>
<style>
<class name="flat"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="wrap">True</property>
<property name="margin-left">24</property>
<property name="margin-right">24</property>
</object>
</child>
<style>
<class name="app-notification"/>
</style>
</object>
</child>
</template>
</interface>