Commit 8c80a991 authored by François Grisez's avatar François Grisez
Browse files

Add the StatusNotifier implementation

parent 9cb0974e
......@@ -65,6 +65,7 @@ set(SOURCE_FILES
propertybox.c
singleinstance.c
status_icon.c
status_notifier.c
support.c
update.c
utils.c
......
......@@ -56,6 +56,7 @@ linphone_SOURCES= \
audio_assistant.c \
videowindow.c \
status_icon.c \
status_notifier.c \
linphone.h
if BUILD_WIZARD
linphone_SOURCES+= \
......
......@@ -1548,19 +1548,31 @@ static void handle_icon_click(LinphoneStatusIcon *si, void *user_data) {
}
}
static void linphone_gtk_status_icon_initialised_cb(LinphoneStatusIconParams *params) {
LinphoneStatusIcon *icon = linphone_status_icon_get();
if(icon) {
linphone_status_icon_start(icon, params);
}
linphone_status_icon_params_unref(params);
}
static void linphone_gtk_init_status_icon(void) {
if(linphone_status_icon_init(NULL, NULL)) {
GtkWidget *menu = create_icon_menu();
LinphoneStatusIconParams *params = linphone_status_icon_params_new();
linphone_status_icon_params_set_menu(params, menu);
linphone_status_icon_params_set_title(params, _("Linphone - a video internet phone"));
linphone_status_icon_params_set_on_click_cb(params, handle_icon_click, NULL);
g_object_unref(G_OBJECT(menu));
if(linphone_status_icon_init(
(LinphoneStatusIconReadyCb)linphone_gtk_status_icon_initialised_cb,
params)) {
LinphoneStatusIcon *icon = linphone_status_icon_get();
if(icon) {
GtkWidget *menu = create_icon_menu();
LinphoneStatusIconParams *params = linphone_status_icon_params_new();
linphone_status_icon_params_set_menu(params, menu);
linphone_status_icon_params_set_title(params, _("Linphone - a video internet phone"));
linphone_status_icon_params_set_on_click_cb(params, handle_icon_click, NULL);
linphone_status_icon_start(icon, params);
g_object_unref(G_OBJECT(menu));
linphone_status_icon_params_unref(params);
}
linphone_status_icon_params_unref(params);
}
}
......
......@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <gtkosxapplication.h>
#endif
#include "status_notifier.h"
typedef struct __LinphoneStatusIconDesc _LinphoneStatusIconDesc;
static LinphoneStatusIcon *_linphone_status_icon_instance = NULL;
......@@ -216,6 +218,8 @@ void _linphone_status_icon_init_cb(const _LinphoneStatusIconDesc *desc, void *us
gboolean linphone_status_icon_init(LinphoneStatusIconReadyCb ready_cb, void *user_data) {
const _LinphoneStatusIconDesc *desc;
void **ctx = g_new(void *, 2);
ctx[0] = ready_cb;
ctx[1] = user_data;
if(_linphone_status_icon_find_first_available_impl(&desc, _linphone_status_icon_init_cb, ctx)) {
_linphone_status_icon_selected_desc = desc;
g_free(ctx);
......@@ -335,7 +339,7 @@ static void _linphone_status_icon_impl_gtkosx_app_enable_blinking(StatusIcon *si
}
}
static gboolean _linphone_satus_icon_impl_gtkosx_app_is_supported(
static gboolean _linphone_status_icon_impl_gtkosx_app_is_supported(
const _LinphoneStatusIconDesc *desc,
gboolean *result,
LinphoneStatusIconDescIsSupportedResultCb cb,
......@@ -356,7 +360,122 @@ static const _LinphoneStatusIconDesc _linphone_status_icon_impl_gtkosx_app_desc
#endif
/* Implementation based on the StatusNotifier Freedesktop standard */
typedef struct {
int x;
int y;
} _LinphoneStatusIconPosition;
static void _linphone_status_icon_impl_sn_init(LinphoneStatusIcon *si) {
si->data = bc_status_notifier_new();
}
static void _linphone_status_icon_impl_sn_uninit(LinphoneStatusIcon *si) {
bc_status_notifier_unref((BcStatusNotifier *)si->data);
}
static void _linphone_status_icon_impl_sn_activated_cb(BcStatusNotifier *sn, int x, int y, void *user_data) {
LinphoneStatusIcon *si = (LinphoneStatusIcon *)user_data;
_linphone_status_icon_notify_click(si);
}
static void _linphone_status_icon_impr_sn_get_position(GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer data) {
_LinphoneStatusIconPosition *pos = (_LinphoneStatusIconPosition *)data;
*x = pos->x;
*y = pos->y;
*push_in = TRUE;
}
static void _linphone_status_icon_impl_sn_menu_called_cb(BcStatusNotifier *sn, int x, int y, void *user_data) {
LinphoneStatusIcon *si = (LinphoneStatusIcon *)user_data;
GtkWidget *menu = si->params->menu;
_LinphoneStatusIconPosition pos = {x, y};
gtk_menu_popup(
GTK_MENU(menu),
NULL,
NULL,
_linphone_status_icon_impr_sn_get_position,
&pos,
0,
gtk_get_current_event_time()
);
}
static void _linphone_status_icon_impl_sn_start(LinphoneStatusIcon *si) {
BcStatusNotifier *sn = (BcStatusNotifier *)si->data;
BcStatusNotifierParams *params;
BcStatusNotifierToolTip *tooltip = bc_status_notifier_tool_tip_new("linphone", "Linphone", NULL);
BcStatusNotifierSignalsVTable vtable = {NULL};
vtable.activate_called_cb = _linphone_status_icon_impl_sn_activated_cb;
vtable.context_menu_called_cb = _linphone_status_icon_impl_sn_menu_called_cb;
params = bc_status_notifier_params_new();
bc_status_notifier_params_set_dbus_prefix(params, "org.kde");
bc_status_notifier_params_set_category(params, BcStatusNotifierCategoryCommunications);
bc_status_notifier_params_set_id(params, "linphone");
bc_status_notifier_params_set_title(params, "Linphone");
bc_status_notifier_params_set_icon_name(params, "linphone");
bc_status_notifier_params_set_tool_tip(params, tooltip);
bc_status_notifier_params_set_vtable(params, &vtable, si);
bc_status_notifier_start(sn, params, NULL, NULL);
bc_status_notifier_tool_tip_unref(tooltip);
bc_status_notifier_params_unref(params);
}
static void _linphone_status_icon_impl_sn_enable_blinking(LinphoneStatusIcon *si, gboolean val) {
BcStatusNotifier *sn = (BcStatusNotifier *)si->data;
if(val) {
bc_status_notifier_update_status(sn, BcStatusNotifierStatusNeedsAttention);
} else {
bc_status_notifier_update_status(sn, BcStatusNotifierStatusPassive);
}
}
static void _linphone_status_icon_impl_is_supported_cb(const char *prefix, gboolean result, void **data) {
_LinphoneStatusIconDesc *desc = (_LinphoneStatusIconDesc *)data[0];
LinphoneStatusIconDescIsSupportedResultCb cb = (LinphoneStatusIconDescIsSupportedResultCb)data[1];
if(cb) cb(desc, result, data[2]);
g_free(data);
g_free(desc);
}
static gboolean _linphone_status_icon_impl_sn_is_supported(
const _LinphoneStatusIconDesc *desc,
gboolean *result,
LinphoneStatusIconDescIsSupportedResultCb cb,
void *user_data) {
_LinphoneStatusIconDesc *desc2 = g_new(_LinphoneStatusIconDesc, 1);
void **data = g_new(void *, 3);
*desc2 = *desc;
data[0] = desc2;
data[1] = cb;
data[2] = user_data;
bc_status_notifier_is_supported(
"org.kde",
(BcStatusNotifierSupportDetectionCb)_linphone_status_icon_impl_is_supported_cb,
data
);
return 0;
}
static const _LinphoneStatusIconDesc _linphone_status_icon_impl_status_notifier = {
.impl_name = "status_notifier",
.init = _linphone_status_icon_impl_sn_init,
.uninit = _linphone_status_icon_impl_sn_uninit,
.start = _linphone_status_icon_impl_sn_start,
.enable_blinking = _linphone_status_icon_impl_sn_enable_blinking,
.is_supported = _linphone_status_icon_impl_sn_is_supported
};
/* List of implementations */
static const _LinphoneStatusIconDesc *_linphone_status_icon_impls[] = {
&_linphone_status_icon_impl_status_notifier,
#ifndef HAVE_GTK_OSX
&_linphone_status_icon_impl_gtk_desc,
#else
......
This diff is collapsed.
/*
linphone, gtk-glade interface.
Copyright (C) 2015 Belledonne Communications <info@belledonne-communications.com>
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef STATUS_NOTIFIER_H
#define STATUS_NOTIFIER_H
#include <glib.h>
struct _BcStatusNotifier;
typedef enum {
BcStatusNotifierCategoryApplicationStatus,
BcStatusNotifierCategoryCommunications,
BcStatusNotifierCategorySystemService,
BcStatusNotifierCategoryHardware
} BcStatusNotifierCategory;
const gchar *bc_status_notifier_category_to_string(BcStatusNotifierCategory c);
typedef enum {
BcStatusNotifierStatusPassive,
BcStatusNotifierStatusActive,
BcStatusNotifierStatusNeedsAttention
} BcStatusNotifierStatus;
const gchar *bc_status_notifier_status_to_string(BcStatusNotifierStatus s);
typedef struct _BcStatusNotifierToolTip BcStatusNotifierToolTip;
BcStatusNotifierToolTip *bc_status_notifier_tool_tip_new(const char *icon_name, const char *title, const char *text);
BcStatusNotifierToolTip *bc_status_notifier_tool_tip_ref(BcStatusNotifierToolTip *obj);
void bc_status_notifier_tool_tip_unref(BcStatusNotifierToolTip *obj);
typedef enum _BcStatusNotifierOrientation {
BcStatusNotifierOrientationVertical,
BcStatusNotifierOrientationHorizontal
} BcStatusNotifierOrientation;
typedef void (*BcStatusNotifierContextMenuCalledCb)(struct _BcStatusNotifier *sn, int x, int y, void *user_data);
typedef void (*BcStatusNotifierActivateCalledCb)(struct _BcStatusNotifier *sn, int x, int y, void *user_data);
typedef void (*BcStatusNotifierSecondaryActivateCb)(struct _BcStatusNotifier *sn, int x, int y, void *user_data);
typedef void (*BcStatusNotifierScrollCalledCb)(struct _BcStatusNotifier *sn, int delta, BcStatusNotifierOrientation o, void *user_data);
typedef struct _BcStatusNotifierSignalsVTable {
BcStatusNotifierContextMenuCalledCb context_menu_called_cb;
BcStatusNotifierActivateCalledCb activate_called_cb;
BcStatusNotifierSecondaryActivateCb secondary_activate_called_cb;
BcStatusNotifierScrollCalledCb scroll_called_cb;
} BcStatusNotifierSignalsVTable;
typedef struct _BcStatusNotifierParams BcStatusNotifierParams;
BcStatusNotifierParams *bc_status_notifier_params_new(void);
BcStatusNotifierParams *bc_status_notifier_params_ref(BcStatusNotifierParams *obj);
void bc_status_notifier_params_unref(BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_dbus_prefix(BcStatusNotifierParams *obj, const char *prefix);
const char *bc_satus_notifier_params_get_dbus_prefix(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_item_id(BcStatusNotifierParams *obj, int item_id);
int bc_status_notifier_params_get_item_id(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_category(BcStatusNotifierParams *obj, BcStatusNotifierCategory category);
BcStatusNotifierCategory bc_status_notifier_params_get_category(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_id(BcStatusNotifierParams *obj, const char *id);
const char *bc_status_notifier_params_get_id(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_title(BcStatusNotifierParams *obj, const char *title);
const char *bc_status_notifier_params_get_title(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_status(BcStatusNotifierParams *obj, BcStatusNotifierStatus status);
BcStatusNotifierStatus bc_status_notifier_params_get_status(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_window_id(BcStatusNotifierParams *obj, guint32 window_id);
guint32 bc_status_notifier_params_get_window_id(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_icon_name(BcStatusNotifierParams *obj, const char *name);
const char *bc_status_notifier_params_get_icon_name(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_overlay_icon_name(BcStatusNotifierParams *obj, const char *name);
const char *bc_status_notifier_params_get_overlay_icon_name(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_attention_icon_name(BcStatusNotifierParams *obj, const char *icon_name);
const char *bc_status_notifier_params_get_attention_icon_name(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_attention_movie_name(BcStatusNotifierParams *obj, const char *name);
const char *bc_status_notifier_params_get_attention_movie_name(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_tool_tip(BcStatusNotifierParams *obj, BcStatusNotifierToolTip *tool_tip);
const BcStatusNotifierToolTip *bc_status_notifier_params_get_tool_tip(const BcStatusNotifierParams *obj);
void bc_status_notifier_params_set_vtable(BcStatusNotifierParams *obj, const BcStatusNotifierSignalsVTable *vtable, void *user_data);
typedef enum _BcStatusNotifierState {
BcStatusNotifierStateStopped,
BcStatusNotifierStateStarting,
BcStatusNotifierStateRunning
} BcStatusNotifierState;
typedef void (*BcStatusNotifierStartedCb)(struct _BcStatusNotifier *sn, void *user_data);
typedef void (*BcStatusNotifierStartingFailedCb)(struct _BcStatusNotifier *sn, void *user_data);
typedef struct _BcStatusNotifierStateVTable {
BcStatusNotifierStartedCb success;
BcStatusNotifierStartingFailedCb fail;
} BcStatusNotifierStateVTable;
typedef struct _BcStatusNotifier BcStatusNotifier;
BcStatusNotifier *bc_status_notifier_new(void);
BcStatusNotifier *bc_status_notifier_ref(BcStatusNotifier *obj);
void bc_status_notifier_unref(BcStatusNotifier *obj);
void bc_status_notifier_start(BcStatusNotifier* obj, BcStatusNotifierParams* params, const BcStatusNotifierStateVTable* vtable, void* user_data);
void bc_status_notifier_stop(BcStatusNotifier* obj);
const BcStatusNotifierParams *bc_status_notifier_get_params(const BcStatusNotifier *obj);
void bc_status_notifier_update_title(BcStatusNotifier* obj, const char* title);
void bc_status_notifier_update_icon(BcStatusNotifier* obj, const char* icon_name);
void bc_status_notifier_update_attention_icon(BcStatusNotifier* obj, const char* icon_name);
void bc_status_notifier_update_overlay_icon(BcStatusNotifier* obj, const char* icon_name);
void bc_status_notifier_update_tool_tip(BcStatusNotifier* obj, BcStatusNotifierToolTip* tool_tip);
void bc_status_notifier_update_status(BcStatusNotifier* obj, BcStatusNotifierStatus status);
typedef void (*BcStatusNotifierSupportDetectionCb)(const char *prefix, gboolean is_supported, void *user_data);
void bc_status_notifier_is_supported(const char* prefix, BcStatusNotifierSupportDetectionCb cb, void *user_data);
#endif
\ No newline at end of file
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