Skip to content
Snippets Groups Projects
Commit ad911b2a authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

[#1403] Remove all actions on notifications; code refactoring

parent a2d2f37e
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,6 @@ icondir = $(datadir)/pixmaps ...@@ -2,6 +2,6 @@ icondir = $(datadir)/pixmaps
icon_DATA = sflphone.svg icon_DATA = sflphone.svg
buttons_DATA = accept.svg current.svg transfert.svg hang_up.svg hold.svg unhold.svg refuse.svg call.svg ring.svg dial.svg mic.svg mic_25.svg mic_50.svg mic_75.svg speaker.svg speaker_25.svg speaker_50.svg speaker_75.svg fail.svg incoming.svg outgoing.svg missed.svg mailbox.svg busy.svg icon_accept.svg icon_hold.svg icon_unhold.svg icon_hangup.svg icon_call.svg icon_dialpad.svg icon_volume.svg icon_dialpad_off.svg icon_volume_off.svg history2.svg sflphone.svg sflphone_notif.svg stock_person.svg icon_rec.svg rec_call.svg addressbook.svg contact_default.svg face-monkey.svg users.svg home.svg wait-on.gif buttons_DATA = accept.svg current.svg transfert.svg hang_up.svg hold.svg unhold.svg refuse.svg call.svg ring.svg dial.svg mic.svg mic_25.svg mic_50.svg mic_75.svg speaker.svg speaker_25.svg speaker_50.svg speaker_75.svg fail.svg incoming.svg outgoing.svg missed.svg mailbox.svg busy.svg icon_accept.svg icon_hold.svg icon_unhold.svg icon_hangup.svg icon_call.svg icon_dialpad.svg icon_volume.svg icon_dialpad_off.svg icon_volume_off.svg history2.svg sflphone.svg sflphone_small.svg stock_person.svg icon_rec.svg rec_call.svg addressbook.svg contact_default.svg face-monkey.svg users.svg home.svg wait-on.gif
buttonsdir = $(datadir)/sflphone buttonsdir = $(datadir)/sflphone
EXTRA_DIST = $(buttons_DATA) $(icon_DATA) EXTRA_DIST = $(buttons_DATA) $(icon_DATA)
...@@ -19,17 +19,50 @@ ...@@ -19,17 +19,50 @@
#include <sflnotify.h> #include <sflnotify.h>
static NotifyNotification *notification; GnomeNotification *_gnome_notification;
void create_new_gnome_notification (gchar *title, gchar *body, NotifyUrgency urgency, gint timeout, GnomeNotification **notif)
{
GnomeNotification *_notif;
if( dbus_get_notify()){
_notif = g_new0 (GnomeNotification, 1);
notify_init ("SFLphone");
// Set struct fields
_notif->notification = notify_notification_new (title, body, NULL, NULL);
//_notif->icon = gdk_pixbuf_new_from_file_at_size (LOGO, 120, 120, NULL);
_notif->icon = gdk_pixbuf_new_from_file (LOGO, NULL);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon (_notif->notification , get_status_icon() );
#endif
notify_notification_set_urgency (_notif->notification, urgency);
if (_notif->icon != NULL)
notify_notification_set_icon_from_pixbuf (_notif->notification, _notif->icon);
else
ERROR ("notify(), cannot load notification icon");
notify_notification_set_timeout (_notif->notification, timeout);
if (!notify_notification_show (_notif->notification, NULL)) {
ERROR("notify(), failed to send notification");
}
*notif = _notif;
}
}
void void
notify_incoming_call (call_t* c) notify_incoming_call (call_t* c)
{ {
if( dbus_get_notify()){
GdkPixbuf *pixbuf;
gchar* callerid; gchar* callerid;
gchar* title; gchar* title;
notify_init("sflphone");
if (g_strcasecmp (c->accountID,"") == 0) { if (g_strcasecmp (c->accountID,"") == 0) {
title = g_markup_printf_escaped ("IP-to-IP call"); title = g_markup_printf_escaped ("IP-to-IP call");
...@@ -41,102 +74,39 @@ notify_incoming_call( call_t* c ) ...@@ -41,102 +74,39 @@ notify_incoming_call( call_t* c )
} }
callerid = g_markup_printf_escaped(_("<i>From:</i> %s") , c->from); callerid = g_markup_printf_escaped(_("<i>From:</i> %s") , c->from);
pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/ring.svg", NULL); create_new_gnome_notification (title,
notification = notify_notification_new( title,
callerid, callerid,
NULL, NOTIFY_URGENCY_CRITICAL,
NULL); (g_strcasecmp(__TIMEOUT_MODE, "default") == 0 )? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER,
notify_notification_set_urgency( notification , NOTIFY_URGENCY_CRITICAL ); &_gnome_notification);
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon( notification , get_status_icon() );
#endif
notify_notification_set_timeout( notification , (( g_strcasecmp(__TIMEOUT_MODE, "default") == 0 )? __TIMEOUT_TIME : NOTIFY_EXPIRES_NEVER ));
g_object_set_data( G_OBJECT( notification ) , "call" , c );
notify_notification_add_action( notification , "accept" , _("Accept") , (NotifyActionCallback) answer_call_cb , NULL, NULL );
notify_notification_add_action( notification , "refuse" , _("Refuse") , (NotifyActionCallback) refuse_call_cb , NULL , NULL );
notify_notification_add_action( notification , "ignore" , _("Ignore") , (NotifyActionCallback) ignore_call_cb , NULL , NULL );
if (!notify_notification_show (notification, NULL)) {
ERROR("notify(), failed to send notification");
}
}
}
void
answer_call_cb( NotifyNotification *notification, gpointer data UNUSED )
{
call_t* c = (call_t*)g_object_get_data( G_OBJECT( notification ) , "call" );
c->history_state = INCOMING;
calltree_update_call( history , c );
dbus_accept(c);
#if GTK_CHECK_VERSION(2,10,0)
if( __POPUP_WINDOW )
status_icon_unminimize();
#endif
g_object_unref( notification );
}
void
refuse_call_cb( NotifyNotification *notification, gpointer data UNUSED)
{
call_t* c = (call_t*)g_object_get_data( G_OBJECT( notification ) , "call" );
dbus_refuse(c);
g_object_unref( notification );
}
void
ignore_call_cb( NotifyNotification *notification, gpointer data UNUSED)
{
g_object_unref( notification );
} }
void void
notify_voice_mails (guint count, account_t* acc) notify_voice_mails (guint count, account_t* acc)
{ {
if( dbus_get_mail_notify()) {
// the account is different from NULL // the account is different from NULL
GdkPixbuf *pixbuf;
gchar* title; gchar* title;
gchar* body; gchar* body;
notify_init("sflphone");
title = g_markup_printf_escaped(_("%s account: %s") , 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(_("%d voice mails"), count); body = g_markup_printf_escaped(_("%d voice mails"), count);
pixbuf = gdk_pixbuf_new_from_file(LOGO, NULL); create_new_gnome_notification (title,
notification = notify_notification_new( title,
body, body,
NULL, NOTIFY_URGENCY_LOW,
NULL); NOTIFY_EXPIRES_DEFAULT,
notify_notification_set_urgency( notification , NOTIFY_URGENCY_LOW ); &_gnome_notification);
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon( notification , get_status_icon() );
#endif
notify_notification_set_timeout( notification , NOTIFY_EXPIRES_DEFAULT );
notify_notification_add_action( notification , "ignore" , _("Ignore") , (NotifyActionCallback) ignore_call_cb , NULL , NULL );
if (!notify_notification_show (notification, NULL)) {
ERROR("notify(), failed to send notification");
}
}
} }
void void
notify_current_account (account_t* acc) notify_current_account (account_t* acc)
{ {
if( dbus_get_notify()){
// the account is different from NULL // the account is different from NULL
GdkPixbuf *pixbuf;
gchar* title; gchar* title;
gchar* body=""; gchar* body="";
notify_init("sflphone");
body = g_markup_printf_escaped(_("Calling with %s account <i>%s</i>") , 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_TYPE) ,
...@@ -144,109 +114,70 @@ notify_current_account( account_t* acc ) ...@@ -144,109 +114,70 @@ notify_current_account( account_t* acc )
title = g_markup_printf_escaped(_("Current account")); title = g_markup_printf_escaped(_("Current account"));
pixbuf = gdk_pixbuf_new_from_file(LOGO, NULL); create_new_gnome_notification (title,
notification = notify_notification_new( title,
body, body,
NULL, NOTIFY_URGENCY_NORMAL,
NULL); NOTIFY_EXPIRES_DEFAULT,
notify_notification_set_urgency( notification , NOTIFY_URGENCY_NORMAL ); &_gnome_notification);
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon( notification , get_status_icon() );
#endif
notify_notification_set_timeout( notification , NOTIFY_EXPIRES_DEFAULT );
notify_notification_add_action( notification , "ignore" , _("Ignore") , (NotifyActionCallback) ignore_call_cb , NULL , NULL );
if (!notify_notification_show (notification, NULL)) {
ERROR("notify(), failed to send notification");
}
}
} }
void void
notify_no_accounts () notify_no_accounts ()
{ {
GdkPixbuf *pixbuf;
gchar* title; gchar* title;
gchar* body=""; gchar* body="";
notify_init("sflphone");
body = g_markup_printf_escaped(_("You haven't setup any accounts")); body = g_markup_printf_escaped(_("You haven't setup any accounts"));
title = g_markup_printf_escaped(_("Error")); title = g_markup_printf_escaped(_("Error"));
pixbuf = gdk_pixbuf_new_from_file(LOGO, NULL); create_new_gnome_notification (title,
notification = notify_notification_new( title,
body, body,
NULL, NOTIFY_URGENCY_CRITICAL,
NULL); NOTIFY_EXPIRES_DEFAULT,
notify_notification_set_urgency( notification , NOTIFY_URGENCY_CRITICAL ); &_gnome_notification);
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon( notification , get_status_icon() );
#endif
notify_notification_set_timeout( notification , NOTIFY_EXPIRES_DEFAULT );
//notify_notification_add_action( notification , "setup" , _("Setup Accounts") , (NotifyActionCallback) setup_accounts_cb , NULL , NULL );
if (!notify_notification_show (notification, NULL)) {
ERROR("notify(), failed to send notification");
}
} }
void
setup_accounts_cb( NotifyNotification *notification, gpointer data UNUSED)
{
//gtk_widget_set_parent( show_accounts_window() , GTK_WIDGET(get_main_window()));
show_accounts_window();
g_object_unref( notification );
}
void void
notify_no_registered_accounts () notify_no_registered_accounts ()
{ {
GdkPixbuf *pixbuf;
gchar* title; gchar* title;
gchar* body=""; gchar* body="";
notify_init("sflphone");
body = g_markup_printf_escaped(_("You have no registered accounts")); body = g_markup_printf_escaped(_("You have no registered accounts"));
title = g_markup_printf_escaped(_("Error")); title = g_markup_printf_escaped(_("Error"));
pixbuf = gdk_pixbuf_new_from_file(LOGO, NULL); create_new_gnome_notification (title,
notification = notify_notification_new( title,
body, body,
NULL, NOTIFY_URGENCY_CRITICAL,
NULL); NOTIFY_EXPIRES_DEFAULT,
notify_notification_set_urgency( notification , NOTIFY_URGENCY_CRITICAL ); &_gnome_notification);
notify_notification_set_icon_from_pixbuf (notification, pixbuf);
#if GTK_CHECK_VERSION(2,10,0)
notify_notification_attach_to_status_icon( notification , get_status_icon() );
#endif
notify_notification_set_timeout( notification , NOTIFY_EXPIRES_DEFAULT );
//notify_notification_add_action( notification , "setup" , _("Setup Accounts") , (NotifyActionCallback) setup_accounts_cb , NULL , NULL );
if (!notify_notification_show (notification, NULL)) {
ERROR("notify(), failed to send notification");
}
} }
void void
stop_notification( void ) stop_notification( void )
{ {
if( notification != NULL ) if( _gnome_notification->notification != NULL )
{ {
if(notify_notification_show( notification , NULL)) if(notify_notification_show (_gnome_notification->notification, NULL))
{ {
notify_notification_close( notification , NULL); notify_notification_close (_gnome_notification->notification, NULL);
g_object_unref( notification ); g_object_unref(_gnome_notification->notification );
notification = NULL; _gnome_notification->notification = NULL;
}
_gnome_notification->notification = NULL;
} }
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->notification);
g_free(g->icon);
g_free(g);
} }
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef __GNOME_NOTIFICATION_H__
#ifndef __SFL_NOTIFY_H__ #define __GNOME_NOTIFICATION_H__
#define __SFL_NOTIFY_H__
/** @file sflnotify.h /** @file sflnotify.h
* @brief Implements desktop notification for incoming events. * @brief Implements desktop notification for incoming events.
...@@ -29,11 +28,22 @@ ...@@ -29,11 +28,22 @@
#include <accountlist.h> #include <accountlist.h>
#include <calllist.h> #include <calllist.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <actions.h>
#include <statusicon.h> #include <statusicon.h>
#include <configwindow.h>
#include <sflphone_const.h> #include <sflphone_const.h>
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
...@@ -65,41 +75,11 @@ void notify_no_accounts( ); ...@@ -65,41 +75,11 @@ void notify_no_accounts( );
*/ */
void notify_no_registered_accounts( ); void notify_no_registered_accounts( );
/**
* Callback when answer button is pressed.
* Action associated: Pick up the incoming call
* @param notification The pointer on the notification structure
* @param data The data associated. Here: call_t*
*/
void answer_call_cb( NotifyNotification *notification, gpointer data );
/**
* Callback when refuse button is pressed
* Action associated: Hang up the incoming call
* @param notification The pointer on the notification structure
* @param data The data associated. Here: call_t*
*/
void refuse_call_cb( NotifyNotification *notification, gpointer data );
/**
* Callback when ignore button is pressed
* Action associated: Nothing - The call continues ringing
* @param notification The pointer on the notification structure
* @param data The data associated. Here: call_t*
*/
void ignore_call_cb( NotifyNotification *notification, gpointer data );
/**
* Callback when you try to make a call without accounts setup and 'setup account' button is clicked.
* Action associated: Open the account window
* @param notification The pointer on the notification structure
* @param data The data associated. Here: account_t*
*/
void setup_accounts_cb(NotifyNotification *notification, gpointer data);
/** /**
* Stop and close the current notification if an action occured before the timeout * Stop and close the current notification if an action occured before the timeout
*/ */
void stop_notification( void ); void stop_notification( void );
G_END_DECLS
#endif #endif
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
* @brief Contains the global variables for the client code * @brief Contains the global variables for the client code
*/ */
#define LOGO ICONS_DIR "/sflphone.svg" #define LOGO ICONS_DIR "/sflphone.svg"
#define LOGO_SMALL ICONS_DIR "/sflphone_small.svg"
/** Locale */ /** Locale */
#define _(STRING) gettext( STRING ) #define _(STRING) gettext( STRING )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment