Commit 5a12767d authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by Alexandre Viau

allow disabling call and chat notifications

Adds two new settings which allow enabling/disabling of the
call and chat notifications (individually). They are both enabled
by default.

Change-Id: Ic6996d53740e3f87f348ca8614ecd130495a65eb
Tuleap: #926
parent f8e78cb0
......@@ -26,5 +26,13 @@
<summary>Display the chat to the rigth (default) or at the bottom.</summary>
<description>If the chat pane is horizontal then the chat is displayed to the right of the video; otherwise it will be displayed bellow it.</description>
</key>
<key name="enable-call-notifications" type="b">
<default>true</default>
<summary>Enable notifications for incoming calls.</summary>
</key>
<key name="enable-chat-notifications" type="b">
<default>true</default>
<summary>Enable notifications for new chat messages.</summary>
</key>
</schema>
</schemalist>
......@@ -19,16 +19,19 @@
#include "generalsettingsview.h"
// GTK+ related
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <categorizedhistorymodel.h>
#include "utils/files.h"
#include "avatarmanipulation.h"
/* lrc */
// LRC
#include <person.h>
#include <profile.h>
#include <profilemodel.h>
#include <categorizedhistorymodel.h>
// Ring client
#include "utils/files.h"
#include "avatarmanipulation.h"
struct _GeneralSettingsView
{
......@@ -50,6 +53,8 @@ struct _GeneralSettingsViewPrivate
GtkWidget *checkbutton_autostart;
GtkWidget *checkbutton_showstatusicon;
GtkWidget *checkbutton_bringtofront;
GtkWidget *checkbutton_callnotifications;
GtkWidget *checkbutton_chatnotifications;
GtkWidget *radiobutton_chatright;
GtkWidget *radiobutton_chatbottom;
GtkWidget *box_profil_settings;
......@@ -145,6 +150,12 @@ general_settings_view_init(GeneralSettingsView *self)
g_settings_bind(priv->settings, "bring-window-to-front",
priv->checkbutton_bringtofront, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "enable-call-notifications",
priv->checkbutton_callnotifications, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "enable-chat-notifications",
priv->checkbutton_chatnotifications, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "chat-pane-horizontal",
priv->radiobutton_chatright, "active",
G_SETTINGS_BIND_DEFAULT);
......@@ -173,6 +184,8 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_autostart);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_showstatusicon);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_callnotifications);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_chatnotifications);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatright);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatbottom);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration);
......
......@@ -51,6 +51,8 @@
#include <localprofilecollection.h>
#include <accountmodel.h>
#include <smartinfohub.h>
#include <media/textrecording.h>
#include <media/recordingmodel.h>
// Ring client
#include "ring_client_options.h"
......@@ -112,6 +114,10 @@ struct _RingClientPrivate {
/* NetworkManager */
NMClient *nm_client;
#endif
/* notifications */
QMetaObject::Connection call_notification;
QMetaObject::Connection chat_notification;
};
/* this union is used to pass ints as pointers and vice versa for GAction parameters*/
......@@ -427,6 +433,39 @@ nm_client_cb(G_GNUC_UNUSED GObject *source_object, GAsyncResult *result, RingCli
#endif /* USE_LIBNM */
static void
call_notifications_toggled(RingClient *self)
{
auto priv = RING_CLIENT_GET_PRIVATE(self);
if (g_settings_get_boolean(priv->settings, "enable-call-notifications")) {
priv->call_notification = QObject::connect(
&CallModel::instance(),
&CallModel::incomingCall,
[] (Call *call) { ring_notify_incoming_call(call); }
);
} else {
QObject::disconnect(priv->call_notification);
}
}
static void
chat_notifications_toggled(RingClient *self)
{
auto priv = RING_CLIENT_GET_PRIVATE(self);
if (g_settings_get_boolean(priv->settings, "enable-chat-notifications")) {
priv->chat_notification = QObject::connect(
&Media::RecordingModel::instance(),
&Media::RecordingModel::newTextMessage,
[self] (Media::TextRecording* t, ContactMethod* cm)
{ ring_notify_message(cm, t, self); }
);
} else {
QObject::disconnect(priv->chat_notification);
}
}
static void
ring_client_startup(GApplication *app)
{
......@@ -561,15 +600,12 @@ ring_client_startup(GApplication *app)
}
);
/* send call notifications */
/* enable notifications based on settings */
ring_notify_init();
QObject::connect(&CallModel::instance(), &CallModel::incomingCall,
[] (Call *call) { ring_notify_incoming_call(call);}
);
/* chat notifications for incoming messages on all calls which are not the
* currently selected call */
ring_notify_monitor_chat_notifications(client);
call_notifications_toggled(client);
chat_notifications_toggled(client);
g_signal_connect_swapped(priv->settings, "changed::enable-call-notifications", G_CALLBACK(call_notifications_toggled), client);
g_signal_connect_swapped(priv->settings, "changed::enable-chat-notifications", G_CALLBACK(chat_notifications_toggled), client);
#if USE_LIBNM
/* monitor the network using libnm to notify the daemon about connectivity chagnes */
......@@ -592,6 +628,8 @@ ring_client_shutdown(GApplication *app)
g_object_unref(priv->cancellable);
QObject::disconnect(priv->uam_updated);
QObject::disconnect(priv->call_notification);
QObject::disconnect(priv->chat_notification);
/* free the QCoreApplication, which will destroy all libRingClient models
* and thus send the Unregister signal over dbus to dring */
......
......@@ -379,9 +379,18 @@ delete_idx(QModelIndex *idx)
delete idx;
}
static void
ring_notify_message(ContactMethod *cm, Media::TextRecording *t, RingClient *client)
#endif
void
ring_notify_message(
#if !USE_LIBNOTIFY
ContactMethod*, Media::TextRecording*, RingClient*)
#else
ContactMethod *cm, Media::TextRecording *t, RingClient *client)
#endif
{
#if USE_LIBNOTIFY
g_return_if_fail(cm && t && client);
// get the message
......@@ -405,28 +414,8 @@ ring_notify_message(ContactMethod *cm, Media::TextRecording *t, RingClient *clie
}
}
}
#endif
void
ring_notify_monitor_chat_notifications(
#if !USE_LIBNOTIFY
G_GNUC_UNUSED
#endif
RingClient *client)
{
#if USE_LIBNOTIFY
QObject::connect(
&Media::RecordingModel::instance(),
&Media::RecordingModel::newTextMessage,
[client] (Media::TextRecording* t, ContactMethod* cm)
{
ring_notify_message(cm, t, client);
}
);
#endif
}
}
gboolean
ring_notify_close_chat_notification(
......
......@@ -25,15 +25,18 @@
class Call;
class ContactMethod;
namespace Media {
class TextRecording;
}
G_BEGIN_DECLS
void ring_notify_init();
void ring_notify_uninit();
gboolean ring_notify_is_initted();
gboolean ring_notify_incoming_call(Call *call);
void ring_notify_monitor_chat_notifications(RingClient *client);
gboolean ring_notify_close_chat_notification(ContactMethod *cm);
gboolean ring_notify_incoming_call(Call*);
void ring_notify_message(ContactMethod*, Media::TextRecording*, RingClient*);
gboolean ring_notify_close_chat_notification(ContactMethod*);
G_END_DECLS
......
......@@ -13,14 +13,12 @@
<child>
<object class="GtkBox" id="hbox_main_columns">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">10</property>
<property name="border_width">10</property>
<!-- start profil settings -->
<child>
<object class="GtkBox" id="vbox_main_left">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="frame_profile_settings">
......@@ -42,7 +40,6 @@
<child>
<object class="GtkBox" id="box_profil_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="halign">start</property>
<property name="orientation">vertical</property>
......@@ -63,7 +60,6 @@
<child>
<object class="GtkBox" id="vbox_main_right">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
......@@ -93,7 +89,6 @@
<object class="GtkCheckButton" id="checkbutton_autostart">
<property name="label" translatable="yes">Start Ring on login</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
......@@ -102,7 +97,6 @@
<object class="GtkCheckButton" id="checkbutton_showstatusicon">
<property name="label" translatable="yes">Show Ring icon in the notification area (systray).</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
......@@ -111,7 +105,22 @@
<object class="GtkCheckButton" id="checkbutton_bringtofront">
<property name="label" translatable="yes">Bring Ring to the foreground on incoming calls.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_callnotifications">
<property name="label" translatable="yes">Enable notifications for incoming calls.</property>
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_chatnotifications">
<property name="label" translatable="yes">Enable notifications for new chat messages.</property>
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
......@@ -119,21 +128,18 @@
<child>
<object class="GtkButtonBox" id="buttonbox_chatposition">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="orientation">vertical</property>
<property name="layout-style">start</property>
<child>
<object class="GtkRadioButton" id="radiobutton_chatright">
<property name="label" translatable="yes">Show chat on the right.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_chatbottom">
<property name="label" translatable="yes">Show chat on the bottom.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="group">radiobutton_chatright</property>
</object>
</child>
......@@ -154,7 +160,6 @@
<child type="label">
<object class="GtkLabel" id="label_history_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">History Settings</property>
<attributes>
<attribute name="weight" value="bold"/>
......@@ -166,7 +171,6 @@
<child>
<object class="GtkGrid" id="grid_history_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_top">10</property>
<property name="row_spacing">10</property>
......@@ -174,7 +178,6 @@
<child>
<object class="GtkLabel" id="label_history_duration">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Keep history for (days):</property>
</object>
<packing>
......@@ -185,7 +188,6 @@
<child>
<object class="GtkSpinButton" id="spinbutton_history_duration">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="value">0</property>
<property name="adjustment">adjustment_history_duration</property>
</object>
......@@ -197,7 +199,6 @@
<child>
<object class="GtkLabel" id="label_history_explanation">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(set to 0 for unlimited history)</property>
</object>
<packing>
......@@ -209,7 +210,6 @@
<object class="GtkButton" id="button_clear_history">
<property name="label" translatable="yes">Clear all history</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
</object>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment