From 7a6bb350c80b3cb066c43d8d6b2e5fd147636149 Mon Sep 17 00:00:00 2001
From: Valentin
Date: Tue, 30 Aug 2011 19:08:54 +0200
Subject: [PATCH] Implementation of notifications and dtmf tones systems
---
configure.ac | 23 ++++++++++-
coreapi/callbacks.c | 3 +-
coreapi/ec-calibrator.c | 6 ++-
coreapi/linphonecore.c | 26 +++++++++++-
coreapi/linphonecore.h | 1 +
gtk/Makefile.am | 2 +-
gtk/main.c | 103 +++++++++++++++++++++++++++++++++++++---------
7 files changed, 138 insertions(+), 26 deletions(-)
diff --git a/configure.ac b/configure.ac
index 379f234..82a20ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,6 +145,28 @@ else
echo "GTK interface compilation is disabled."
fi
+dnl conditionnal build of the notify library
+if test "$mingw_found" != "yes" -a "$gtk_ui" = "true" ; then
+ AC_ARG_ENABLE(notify,
+ [ --enable-notify=[yes/no] Enable libnotify support [default=yes]],
+ [case "${enableval}" in
+ yes) notify=true ;;
+ no) notify=false ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-notify) ;;
+ esac],[notify=true])
+
+ if test "$notify" = "true"; then
+ PKG_CHECK_MODULES([NOTIFY], [libnotify], [found_notify=yes], foo=bar)
+ case "$found_notify" in
+ yes)
+ AC_SUBST(NOTIFY_CFLAGS)
+ AC_SUBST(NOTIFY_LIBS)
+ AC_DEFINE([HAVE_NOTIFY],[1],[NOTIFY support])
+ esac
+ else
+ echo "Libnotify support is disabled."
+ fi
+fi
dnl os-specific problems not handled by existing macros.
case "$host_os" in
@@ -239,7 +261,6 @@ else
package_prefix=${prefix}
fi
-
if test "$relativeprefix" = "yes" ; then
dnl allow binaries to install everywhere
package_prefix="."
diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c
index a101dbc..634022c 100644
--- a/coreapi/callbacks.c
+++ b/coreapi/callbacks.c
@@ -194,7 +194,8 @@ static void call_received(SalOp *h){
ms_message("the local ring is already started");
}
}else{
- /*TODO : play a tone within the context of the current call */
+ /* play a tone within the context of the current call */
+ linphone_core_play_dtmf_tone(lc);
}
diff --git a/coreapi/ec-calibrator.c b/coreapi/ec-calibrator.c
index 38b83f0..b0ec20c 100644
--- a/coreapi/ec-calibrator.c
+++ b/coreapi/ec-calibrator.c
@@ -110,7 +110,8 @@ static void ecc_play_tones(EcCalibrator *ecc){
ms_filter_call_method (ecc->det,MS_TONE_DETECTOR_ADD_SCAN,&expected_tone);
- tone.frequency=1000;
+ tone.lowfreq=1000;
+ tone.highfreq=0;
tone.duration=1000;
tone.amplitude=1.0;
@@ -119,7 +120,8 @@ static void ecc_play_tones(EcCalibrator *ecc){
ms_sleep(2);
ms_filter_set_notify_callback(ecc->gen,on_tone_sent,ecc);
- tone.frequency=2000;
+ tone.lowfreq=2000;
+ tone.highfreq=0;
tone.duration=100;
ms_filter_call_method(ecc->gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c
index aa33e66..b607ca1 100644
--- a/coreapi/linphonecore.c
+++ b/coreapi/linphonecore.c
@@ -2306,7 +2306,6 @@ int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
ms_message("ring stopped");
lc->ringstream=NULL;
}
-
linphone_core_get_default_proxy(lc,&cfg);
dest_proxy=cfg;
dest_proxy=linphone_core_lookup_known_proxy(lc,call->log->to);
@@ -2362,6 +2361,11 @@ static void terminate_call(LinphoneCore *lc, LinphoneCall *call){
ring_stop(lc->ringstream);
lc->ringstream=NULL;
}
+
+ /*stop any dtmf tone still playing */
+ ms_message("test");
+ linphone_core_stop_dtmf(lc);
+
linphone_call_stop_media_streams(call);
if (lc->vtable.display_status!=NULL)
lc->vtable.display_status(lc,_("Call ended") );
@@ -3676,6 +3680,26 @@ void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms){
/**
* @ingroup media_parameters
+ * Plays a repeated tone to the local user until next further call to #linphone_core_stop_dtmf()
+ * @param lc #LinphoneCore
+**/
+void linphone_core_play_dtmf_tone(LinphoneCore *lc){
+ MSFilter *f=get_dtmf_gen(lc);
+ MSDtmfGenCustomTone def;
+ if (f==NULL){
+ ms_error("No dtmf generator at this time !");
+ return;
+ }
+ def.duration=100;
+ def.lowfreq=852;
+ def.highfreq=1633;
+ def.amplitude=0.5;
+ def.interval=600;
+ ms_filter_call_method(f, MS_DTMF_GEN_PLAY_CUSTOM,&def);
+}
+
+/**
+ * @ingroup media_parameters
*
* Stops playing a dtmf started by linphone_core_play_dtmf().
**/
diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h
index 010b158..d85f014 100644
--- a/coreapi/linphonecore.h
+++ b/coreapi/linphonecore.h
@@ -941,6 +941,7 @@ void linphone_core_set_play_file(LinphoneCore *lc, const char *file);
void linphone_core_set_record_file(LinphoneCore *lc, const char *file);
void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms);
+void linphone_core_play_dtmf_tone(LinphoneCore *lc);
void linphone_core_stop_dtmf(LinphoneCore *lc);
int linphone_core_get_current_call_duration(const LinphoneCore *lc);
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index c51234e..56ac4a3 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -49,7 +49,7 @@ linphone_SOURCES= \
linphone_LDADD=$(ORTP_LIBS) \
$(MEDIASTREAMER_LIBS) \
$(top_builddir)/coreapi/liblinphone.la \
- $(LIBGTK_LIBS) $(LIBGTKMAC_LIBS) $(INTLLIBS)
+ $(LIBGTK_LIBS) $(NOTIFY_LIBS) $(LIBGTKMAC_LIBS) $(INTLLIBS)
if BUILD_WIN32
diff --git a/gtk/main.c b/gtk/main.c
index 6fea842..05d20a9 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -36,6 +36,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define chdir _chdir
#endif
+#ifdef HAVE_NOTIFY
+#include
+#endif
+
#define LINPHONE_ICON "linphone.png"
const char *this_program_ident_string="linphone_ident_string=" LINPHONE_VERSION;
@@ -622,6 +626,24 @@ static void completion_add_text(GtkEntry *entry, const char *text){
save_uri_history();
}
+
+static void linphone_gtk_show_main_window(){
+ GtkWidget *w=linphone_gtk_get_main_window();
+ LinphoneCore *lc=linphone_gtk_get_core();
+ if (linphone_core_video_enabled(lc)){
+ linphone_core_enable_video_preview(lc,linphone_gtk_get_ui_config_int("videoselfview",
+ VIDEOSELFVIEW_DEFAULT));
+ }
+ gtk_widget_show(w);
+ gtk_window_present(GTK_WINDOW(w));
+}
+
+static void linphone_gtk_show(LinphoneCore *lc){
+#ifndef HAVE_NOTIFY
+ linphone_gtk_show_main_window();
+#endif
+}
+
void linphone_gtk_call_terminated(LinphoneCall *call, const char *error){
GtkWidget *mw=linphone_gtk_get_main_window();
if (linphone_core_get_calls(linphone_gtk_get_core())==NULL){
@@ -753,6 +775,7 @@ void linphone_gtk_answer_clicked(GtkWidget *button){
if (call){
linphone_core_pause_all_calls(linphone_gtk_get_core());
linphone_core_accept_call(linphone_gtk_get_core(),call);
+ linphone_gtk_show_main_window(); /* useful when the button is clicked on a notification */
}
}
@@ -763,7 +786,7 @@ void linphone_gtk_enable_video(GtkWidget *w){
gtk_widget_set_sensitive(selfview_item,val);
if (val){
linphone_core_enable_video_preview(linphone_gtk_get_core(),
- linphone_gtk_get_ui_config_int("videoselfview",VIDEOSELFVIEW_DEFAULT));
+ linphone_gtk_get_ui_config_int("videoselfview",VIDEOSELFVIEW_DEFAULT));
}else{
linphone_core_enable_video_preview(linphone_gtk_get_core(),FALSE);
}
@@ -787,21 +810,6 @@ void linphone_gtk_used_identity_changed(GtkWidget *w){
if (sel) g_free(sel);
}
-static void linphone_gtk_show_main_window(){
- GtkWidget *w=linphone_gtk_get_main_window();
- LinphoneCore *lc=linphone_gtk_get_core();
- if (linphone_core_video_enabled(lc)){
- linphone_core_enable_video_preview(lc,linphone_gtk_get_ui_config_int("videoselfview",
- VIDEOSELFVIEW_DEFAULT));
- }
- gtk_widget_show(w);
- gtk_window_present(GTK_WINDOW(w));
-}
-
-static void linphone_gtk_show(LinphoneCore *lc){
- linphone_gtk_show_main_window();
-}
-
static void linphone_gtk_notify_recv(LinphoneCore *lc, LinphoneFriend * fid){
linphone_gtk_show_friends();
}
@@ -942,6 +950,57 @@ static void linphone_gtk_call_log_updated(LinphoneCore *lc, LinphoneCallLog *cl)
if (w) linphone_gtk_call_log_update(w);
}
+static void linphone_gtk_notify(LinphoneCall *call, const char *msg){
+#ifdef HAVE_NOTIFY
+ NotifyNotification *n;
+ if (!notify_is_initted())
+ if (!notify_init ("Linphone")) ms_error("Libnotify failed to init.");
+#endif
+ if (!call) {
+#ifdef HAVE_NOTIFY
+ if (!notify_notification_show(notify_notification_new(Linphone,msg,NULL),NULL))
+ ms_error("Failed to send notification.");
+#else
+ linphone_gtk_show_main_window();
+#endif
+ } else if (!gtk_window_is_active((GtkWindow*)linphone_gtk_get_main_window())) {
+#ifdef HAVE_NOTIFY
+ switch(linphone_call_get_state(call)){
+ case LinphoneCallError:
+ n = notify_notification_new(_("Call Error"),g_markup_printf_escaped("%s\n%s",msg,linphone_call_get_remote_address_as_string(call)),NULL);
+ break;
+ case LinphoneCallEnd:
+ n = notify_notification_new(_("Call Ended"),g_markup_printf_escaped("%s",linphone_call_get_remote_address_as_string(call)),NULL);
+ break;
+ case LinphoneCallIncomingReceived:
+ n = notify_notification_new(_("Incoming call"),g_markup_printf_escaped("%s",linphone_call_get_remote_address_as_string(call)),NULL);
+ notify_notification_add_action (n,"answer",
+ (all_other_calls_paused (call,linphone_core_get_calls(linphone_gtk_get_core(lc)))) ?
+ _("Answer") : _("Pause all calls\nand answer"),
+ NOTIFY_ACTION_CALLBACK(linphone_gtk_answer_clicked),
+ NULL,
+ NULL);
+ notify_notification_add_action (n,"decline",_("Decline"),NOTIFY_ACTION_CALLBACK(linphone_gtk_decline_clicked),NULL,NULL);
+ break;
+ case LinphoneCallResuming:
+ n = notify_notification_new(_("Call resumed"),"",NULL);
+ break;
+ case LinphoneCallPausing:
+ n = notify_notification_new(_("Call Paused"),"",NULL);
+ break;
+ case LinphoneCallPausedByRemote:
+ n = notify_notification_new(_("Call Paused"),g_markup_printf_escaped("%s",linphone_call_get_remote_address_as_string(call)),NULL);
+ break;
+ default:
+ n = NULL;
+ break;
+ }
+ if (n && !notify_notification_show(n,NULL))
+ ms_error("Failed to send notification.");
+#endif
+ }
+}
+
static void linphone_gtk_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cs, const char *msg){
switch(cs){
case LinphoneCallOutgoingInit:
@@ -985,6 +1044,7 @@ static void linphone_gtk_call_state_changed(LinphoneCore *lc, LinphoneCall *call
default:
break;
}
+ linphone_gtk_notify(call, msg);
linphone_gtk_update_call_buttons (call);
}
@@ -1274,6 +1334,9 @@ gboolean linphone_gtk_close(GtkWidget *mw){
#else
gtk_widget_hide(mw);
#endif
+#ifdef HAVE_NOTIFY
+ notify_uninit();
+#endif
return TRUE;
}
@@ -1352,9 +1415,9 @@ void linphone_gtk_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
static void linphone_gtk_refer_received(LinphoneCore *lc, const char *refer_to){
- GtkEntry * uri_bar =GTK_ENTRY(linphone_gtk_get_widget(
+ GtkEntry * uri_bar =GTK_ENTRY(linphone_gtk_get_widget(
linphone_gtk_get_main_window(), "uribar"));
- linphone_gtk_show_main_window();
+ linphone_gtk_notify(NULL,ms_strdup_printf(_("We are transferred to %s"),refer_to));
gtk_entry_set_text(uri_bar, refer_to);
linphone_gtk_start_call(linphone_gtk_get_main_window());
}
@@ -1363,8 +1426,8 @@ static void linphone_gtk_check_soundcards(){
const char **devices=linphone_core_get_sound_devices(linphone_gtk_get_core());
if (devices==NULL || devices[0]==NULL){
linphone_gtk_display_something(GTK_MESSAGE_WARNING,
- _("No sound cards have been detected on this computer.\n"
- "You won't be able to send or receive audio calls."));
+ _("No sound cards have been detected on this computer.\n"
+ "You won't be able to send or receive audio calls."));
}
}
--
1.7.5.4