Commit 26db78d8 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6894: fix leaks, cleanup in sflnotify

parent 34a0d59b
...@@ -414,7 +414,6 @@ sflphone_hang_up() ...@@ -414,7 +414,6 @@ sflphone_hang_up()
call_remove_all_errors (selectedCall); call_remove_all_errors (selectedCall);
selectedCall->_state = CALL_STATE_DIALING; selectedCall->_state = CALL_STATE_DIALING;
DEBUG ("from sflphone_hang_up : "); DEBUG ("from sflphone_hang_up : ");
stop_notification();
break; break;
case CALL_STATE_TRANSFER: case CALL_STATE_TRANSFER:
dbus_hang_up (selectedCall); dbus_hang_up (selectedCall);
...@@ -465,7 +464,6 @@ sflphone_pick_up() ...@@ -465,7 +464,6 @@ sflphone_pick_up()
} }
dbus_accept (selectedCall); dbus_accept (selectedCall);
stop_notification();
break; break;
case CALL_STATE_TRANSFER: case CALL_STATE_TRANSFER:
dbus_transfer (selectedCall); dbus_transfer (selectedCall);
...@@ -766,11 +764,9 @@ sflphone_keypad (guint keyval, gchar * key) ...@@ -766,11 +764,9 @@ sflphone_keypad (guint keyval, gchar * key)
c->_history_state = INCOMING; c->_history_state = INCOMING;
calltree_update_call (history, c, NULL); calltree_update_call (history, c, NULL);
dbus_accept (c); dbus_accept (c);
stop_notification();
break; break;
case GDK_Escape: case GDK_Escape:
dbus_refuse (c); dbus_refuse (c);
stop_notification();
break; break;
} }
...@@ -825,15 +821,14 @@ sflphone_keypad (guint keyval, gchar * key) ...@@ -825,15 +821,14 @@ sflphone_keypad (guint keyval, gchar * key)
break; break;
} }
} else { } else
sflphone_new_call(); sflphone_new_call();
}
} }
static void place_direct_call (const callable_obj_t * c) static void place_direct_call (const callable_obj_t * c)
{ {
assert(c->_state == CALL_STATE_DIALING); g_assert(c->_state == CALL_STATE_DIALING);
dbus_place_call (c); dbus_place_call(c);
} }
static int place_registered_call (callable_obj_t * c) static int place_registered_call (callable_obj_t * c)
...@@ -861,7 +856,7 @@ static int place_registered_call (callable_obj_t * c) ...@@ -861,7 +856,7 @@ static int place_registered_call (callable_obj_t * c)
DEBUG ("Actions: Get account for this call"); DEBUG ("Actions: Get account for this call");
if (g_strcasecmp (c->_accountID, "") != 0) { if (strlen(c->_accountID) != 0) {
DEBUG ("Actions: Account %s already set for this call", c->_accountID); DEBUG ("Actions: Account %s already set for this call", c->_accountID);
current = account_list_get_by_id (c->_accountID); current = account_list_get_by_id (c->_accountID);
} else { } else {
......
...@@ -202,7 +202,6 @@ row_activated (GtkTreeView *tree_view UNUSED, ...@@ -202,7 +202,6 @@ row_activated (GtkTreeView *tree_view UNUSED,
switch (selectedCall->_state) { switch (selectedCall->_state) {
case CALL_STATE_INCOMING: case CALL_STATE_INCOMING:
dbus_accept (selectedCall); dbus_accept (selectedCall);
stop_notification();
break; break;
case CALL_STATE_HOLD: case CALL_STATE_HOLD:
dbus_unhold (selectedCall); dbus_unhold (selectedCall);
......
...@@ -160,8 +160,6 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state ...@@ -160,8 +160,6 @@ call_state_cb (DBusGProxy *proxy UNUSED, const gchar* callID, const gchar* state
time(&c->_time_stop); time(&c->_time_stop);
calltree_update_call (history, c, NULL); calltree_update_call (history, c, NULL);
} }
stop_notification();
calltree_update_call (history, c, NULL); calltree_update_call (history, c, NULL);
status_bar_display_account(); status_bar_display_account();
sflphone_hung_up (c); sflphone_hung_up (c);
......
...@@ -32,245 +32,175 @@ ...@@ -32,245 +32,175 @@
#include "config.h" #include "config.h"
#include "sflnotify.h" #include "sflnotify.h"
static GnomeNotification *_gnome_notification; typedef struct {
NotifyNotification *notification;
void create_new_gnome_notification (gchar *title, gchar *body, NotifyUrgency urgency, gint timeout, GnomeNotification **notif) gchar *title;
gchar *body;
GdkPixbuf *icon;
} GnomeNotification;
static void
create_new_gnome_notification (gchar *title, gchar *body, NotifyUrgency urgency, gint timeout)
{ {
GnomeNotification *_notif; GnomeNotification notif;
if (eel_gconf_get_integer (NOTIFY_ALL)) { if (eel_gconf_get_integer (NOTIFY_ALL)) {
_notif = g_new0 (GnomeNotification, 1);
notify_init ("SFLphone"); notify_init ("SFLphone");
// Set struct fields // Set struct fields
#ifdef LIBNOTIFY_VERSION_0_7_2 #ifdef LIBNOTIFY_VERSION_0_7_2
_notif->notification = notify_notification_new (title, body, NULL); notif.notification = notify_notification_new (title, body, NULL);
#else #else
_notif->notification = notify_notification_new (title, body, NULL, NULL); notif.notification = notify_notification_new (title, body, NULL, NULL);
#endif #endif
_notif->icon = gdk_pixbuf_new_from_file (LOGO_SMALL, NULL); notif.icon = gdk_pixbuf_new_from_file (LOGO_SMALL, NULL);
#ifdef LIBNOTIFY_VERSION_0_7_2 #ifdef LIBNOTIFY_VERSION_0_7_2
#else #else
#if GTK_CHECK_VERSION(2,10,0) #if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon (_notif->notification , get_status_icon()); notify_notification_attach_to_status_icon (notif.notification , get_status_icon());
#endif #endif
#endif #endif
notify_notification_set_urgency (_notif->notification, urgency); notify_notification_set_urgency (notif.notification, urgency);
if (_notif->icon != NULL) if (notif.icon != NULL)
notify_notification_set_icon_from_pixbuf (_notif->notification, _notif->icon); notify_notification_set_icon_from_pixbuf (notif.notification, notif.icon);
else else
ERROR ("notify(), cannot load notification icon"); ERROR ("notify(), cannot load notification icon");
notify_notification_set_timeout (_notif->notification, timeout); notify_notification_set_timeout (notif.notification, timeout);
if (!notify_notification_show (_notif->notification, NULL)) { if (!notify_notification_show (notif.notification, NULL)) {
ERROR ("notify(), failed to send notification"); ERROR ("notify(), failed to send notification");
} }
*notif = _notif;
} }
g_free(title);
g_free(body);
} }
void void
notify_incoming_message (const gchar *callID, const gchar *msg) notify_incoming_message (const gchar *callID, const gchar *msg)
{ {
gchar* title = g_markup_printf_escaped(_("%s says:"), callID);
gchar* title; create_new_gnome_notification(title,
(gchar *)msg,
title = g_markup_printf_escaped (_ ("%s says:"), callID); NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
create_new_gnome_notification (title,
(gchar *)msg,
NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
&_gnome_notification);
} }
void void
notify_incoming_call (callable_obj_t* c) notify_incoming_call (callable_obj_t* c)
{ {
gchar* callerid;
gchar* title; gchar* title;
if (g_strcasecmp (c->_accountID,"") == 0) { if (strlen(c->_accountID) == 0)
title = g_markup_printf_escaped ("IP-to-IP call"); title = g_markup_printf_escaped("IP-to-IP call");
} else { else {
title = g_markup_printf_escaped (_ ("%s account : %s") , title = g_markup_printf_escaped(_ ("%s account : %s") ,
(gchar*) g_hash_table_lookup (account_list_get_by_id (c->_accountID)->properties , ACCOUNT_TYPE) , (gchar*) g_hash_table_lookup (account_list_get_by_id (c->_accountID)->properties , ACCOUNT_TYPE) ,
(gchar*) g_hash_table_lookup (account_list_get_by_id (c->_accountID)->properties , ACCOUNT_ALIAS)) ; (gchar*) g_hash_table_lookup (account_list_get_by_id (c->_accountID)->properties , ACCOUNT_ALIAS)) ;
} }
callerid = g_markup_printf_escaped (_ ("<i>From</i> %s"), c->_peer_number); gchar *callerid = g_markup_printf_escaped(_("<i>From</i> %s"), c->_peer_number);
create_new_gnome_notification (title, create_new_gnome_notification(title,
callerid, callerid,
NOTIFY_URGENCY_CRITICAL, NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER, (g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
&_gnome_notification);
} }
void void
notify_voice_mails (guint count, account_t* acc) notify_voice_mails(guint count, account_t* acc)
{ {
// the account is different from NULL // the account is different from NULL
gchar* title; gchar *title = g_markup_printf_escaped(_("%s account : %s") ,
gchar* body;
title = g_markup_printf_escaped (_ ("%s account : %s") ,
(gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_TYPE) , (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_TYPE) ,
(gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_ALIAS)) ; (gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_ALIAS)) ;
body = g_markup_printf_escaped (n_ ("%d voice mail", "%d voice mails", count), count); gchar *body = g_markup_printf_escaped(n_("%d voice mail", "%d voice mails", count), count);
create_new_gnome_notification (title, create_new_gnome_notification(title,
body, body,
NOTIFY_URGENCY_LOW, NOTIFY_URGENCY_LOW,
NOTIFY_EXPIRES_DEFAULT, NOTIFY_EXPIRES_DEFAULT);
&_gnome_notification);
} }
void void
notify_current_account (account_t* acc) notify_current_account (account_t* acc)
{ {
// the account is different from NULL // the account is different from NULL
gchar* title; gchar *body = g_markup_printf_escaped (_("Calling with %s account <i>%s</i>"),
gchar* body=""; (gchar*) g_hash_table_lookup(acc->properties, ACCOUNT_TYPE) ,
(gchar*) g_hash_table_lookup(acc->properties, ACCOUNT_ALIAS));
body = g_markup_printf_escaped (_ ("Calling with %s account <i>%s</i>") ,
(gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_TYPE) ,
(gchar*) g_hash_table_lookup (acc->properties , ACCOUNT_ALIAS));
title = g_markup_printf_escaped (_ ("Current account")); gchar *title = g_markup_printf_escaped(_("Current account"));
create_new_gnome_notification (title, create_new_gnome_notification(title, body, NOTIFY_URGENCY_NORMAL,
body, NOTIFY_EXPIRES_DEFAULT);
NOTIFY_URGENCY_NORMAL,
NOTIFY_EXPIRES_DEFAULT,
&_gnome_notification);
} }
void void
notify_no_accounts () notify_no_accounts()
{ {
gchar* title; gchar *body = g_markup_printf_escaped(_("You have no accounts set up"));
gchar* body=""; gchar *title = g_markup_printf_escaped(_("Error"));
body = g_markup_printf_escaped (_ ("You have no accounts set up")); create_new_gnome_notification(title, body, NOTIFY_URGENCY_CRITICAL,
title = g_markup_printf_escaped (_ ("Error")); NOTIFY_EXPIRES_DEFAULT);
create_new_gnome_notification (title,
body,
NOTIFY_URGENCY_CRITICAL,
NOTIFY_EXPIRES_DEFAULT,
&_gnome_notification);
} }
void void
notify_no_registered_accounts () notify_no_registered_accounts ()
{ {
gchar* title; gchar *body = g_markup_printf_escaped(_("You have no registered accounts"));
gchar* body=""; gchar *title = g_markup_printf_escaped(_("Error"));
body = g_markup_printf_escaped (_ ("You have no registered accounts"));
title = g_markup_printf_escaped (_ ("Error"));
create_new_gnome_notification (title, create_new_gnome_notification(title, body, NOTIFY_URGENCY_CRITICAL,
body, NOTIFY_EXPIRES_DEFAULT);
NOTIFY_URGENCY_CRITICAL,
NOTIFY_EXPIRES_DEFAULT,
&_gnome_notification);
}
void
stop_notification (void)
{
/*
if( _gnome_notification != NULL )
{
if(_gnome_notification->notification != NULL)
{
notify_notification_close (_gnome_notification->notification, NULL);
g_object_unref(_gnome_notification->notification );
_gnome_notification->notification = NULL;
}
free_notification (_gnome_notification);
}*/
} }
/**
* Freeing a notification instance
*/
void free_notification (GnomeNotification *g)
{
g_free (g->title);
g_free (g->body);
g_free (g);
}
void void
notify_secure_on (callable_obj_t* c) notify_secure_on (callable_obj_t* c)
{ {
gchar *title = g_markup_printf_escaped("Secure mode on.");
gchar* callerid; gchar *callerid = g_markup_printf_escaped(_("<i>With:</i> %s \nusing %s") , c->_peer_number, c->_srtp_cipher);
gchar* title; create_new_gnome_notification(title,
title = g_markup_printf_escaped ("Secure mode on."); callerid,
callerid = g_markup_printf_escaped (_ ("<i>With:</i> %s \nusing %s") , c->_peer_number, c->_srtp_cipher); NOTIFY_URGENCY_CRITICAL,
create_new_gnome_notification (title, (g_strcasecmp(__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
callerid,
NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
&_gnome_notification);
} }
void void
notify_zrtp_not_supported (callable_obj_t* c) notify_zrtp_not_supported (callable_obj_t* c)
{ {
gchar *title = g_markup_printf_escaped ("ZRTP Error.");
gchar* callerid; gchar *callerid = g_markup_printf_escaped (_("%s does not support ZRTP.") , c->_peer_number);
gchar* title;
title = g_markup_printf_escaped ("ZRTP Error.");
callerid = g_markup_printf_escaped (_ ("%s does not support ZRTP.") , c->_peer_number);
create_new_gnome_notification (title, create_new_gnome_notification (title,
callerid, callerid,
NOTIFY_URGENCY_CRITICAL, NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER, (g_strcasecmp(__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
&_gnome_notification);
} }
void void
notify_zrtp_negotiation_failed (callable_obj_t* c) notify_zrtp_negotiation_failed (callable_obj_t* c)
{ {
gchar *title = g_markup_printf_escaped("ZRTP Error.");
gchar* callerid; gchar *callerid = g_markup_printf_escaped(_("ZRTP negotiation failed with %s"), c->_peer_number);
gchar* title; create_new_gnome_notification(title,
title = g_markup_printf_escaped ("ZRTP Error."); callerid,
callerid = g_markup_printf_escaped (_ ("ZRTP negotiation failed with %s") , c->_peer_number); NOTIFY_URGENCY_CRITICAL,
create_new_gnome_notification (title, (g_strcasecmp(__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
callerid,
NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
&_gnome_notification);
} }
void void
notify_secure_off (callable_obj_t* c) notify_secure_off (callable_obj_t* c)
{ {
gchar *title = g_markup_printf_escaped ("Secure mode is off.");
gchar* callerid; gchar *callerid = g_markup_printf_escaped(_("<i>With:</i> %s"), c->_peer_number);
gchar* title; create_new_gnome_notification(title,
title = g_markup_printf_escaped ("Secure mode is off."); callerid,
callerid = g_markup_printf_escaped (_ ("<i>With:</i> %s") , c->_peer_number); NOTIFY_URGENCY_CRITICAL,
create_new_gnome_notification (title, (g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER);
callerid,
NOTIFY_URGENCY_CRITICAL,
(g_strcasecmp (__TIMEOUT_MODE, "default") == 0) ? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
&_gnome_notification);
} }
...@@ -44,17 +44,6 @@ ...@@ -44,17 +44,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct {
NotifyNotification *notification;
gchar *title;
gchar *body;
GdkPixbuf *icon;
} GnomeNotification;
void create_new_gnome_notification (gchar *title, gchar *body, NotifyUrgency urgency, gint timeout, GnomeNotification **notif);
void free_notification (GnomeNotification *g);
/** /**
* Notify an incoming call * Notify an incoming call
* A dialog box is attached to the status icon * A dialog box is attached to the status icon
...@@ -93,11 +82,6 @@ void notify_no_accounts(); ...@@ -93,11 +82,6 @@ void notify_no_accounts();
*/ */
void notify_no_registered_accounts(); void notify_no_registered_accounts();
/**
* Stop and close the current notification if an action occured before the timeout
*/
void stop_notification (void);
/** /**
* Notify that the RTP session is secured * Notify that the RTP session is secured
*/ */
......
Supports Markdown
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