Example #1
0
/**
 * g_notification_add_button_with_target: (skip)
 * @notification: a #GNotification
 * @label: label of the button
 * @action: an action name
 * @target_format: (allow-none): a #GVariant format string, or %NULL
 * @...: positional parameters, as determined by @target_format
 *
 * Adds a button to @notification that activates @action when clicked.
 * @action must be an application-wide action (it must start with "app.").
 *
 * If @target_format is given, it is used to collect remaining
 * positional parameters into a #GVariant instance, similar to
 * g_variant_new(). @action will be activated with that #GVariant as its
 * parameter.
 *
 * Since: 2.40
 */
void
g_notification_add_button_with_target (GNotification *notification,
                                       const gchar   *label,
                                       const gchar   *action,
                                       const gchar   *target_format,
                                       ...)
{
  va_list args;
  GVariant *target = NULL;

  if (target_format)
    {
      va_start (args, target_format);
      target = g_variant_new_va (target_format, NULL, &args);
      va_end (args);
    }

  g_notification_add_button_with_target_value (notification, label, action, target);
}
Example #2
0
/**
 * g_notification_add_button:
 * @notification: a #GNotification
 * @label: label of the button
 * @detailed_action: a detailed action name
 *
 * Adds a button to @notification that activates the action in
 * @detailed_action when clicked. That action must be an
 * application-wide action (starting with "app."). If @detailed_action
 * contains a target, the action will be activated with that target as
 * its parameter.
 *
 * See g_action_parse_detailed_name() for a description of the format
 * for @detailed_action.
 *
 * Since: 2.40
 */
void
g_notification_add_button (GNotification *notification,
                           const gchar   *label,
                           const gchar   *detailed_action)
{
  gchar *action;
  GVariant *target;
  GError *error = NULL;

  g_return_if_fail (detailed_action != NULL);

  if (!g_action_parse_detailed_name (detailed_action, &action, &target, &error))
    {
      g_warning ("%s: %s", G_STRFUNC, error->message);
      g_error_free (error);
      return;
    }

  g_notification_add_button_with_target_value (notification, label, action, target);

  g_free (action);
  if (target)
    g_variant_unref (target);
}
Example #3
0
static void notify_incoming_call(struct gtk_mod *mod,
		struct call *call)
{
	static const char *title = "Incoming call";
	const char *msg = call_peeruri(call);
	GtkWidget *call_menu;
	GtkWidget *menu_item;
#if defined(USE_LIBNOTIFY)
	NotifyNotification *notification;

	if (!notify_is_initted())
		return;
	notification = notify_notification_new(title, msg, "baresip");
	notify_notification_set_urgency(notification, NOTIFY_URGENCY_CRITICAL);
	notify_notification_show(notification, NULL);
	g_object_unref(notification);

#elif GLIB_CHECK_VERSION(2,40,0)
	char id[64];
	GVariant *target;
	GNotification *notification = g_notification_new(title);

	re_snprintf(id, sizeof id, "incoming-call-%p", call);
	id[sizeof id - 1] = '\0';

#if GLIB_CHECK_VERSION(2,42,0)
	g_notification_set_priority(notification,
			G_NOTIFICATION_PRIORITY_URGENT);
#else
	g_notification_set_urgent(notification, TRUE);
#endif

	target = g_variant_new_int64(GPOINTER_TO_INT(call));
	g_notification_set_body(notification, msg);
	g_notification_add_button_with_target_value(notification,
			"Answer", "app.answer", target);
	g_notification_add_button_with_target_value(notification,
			"Reject", "app.reject", target);
	g_application_send_notification(mod->app, id, notification);
	g_object_unref(notification);

#else
	(void)msg;
	(void)title;
#endif

	/* Add incoming call to the app menu */
	call_menu = gtk_menu_new();
	menu_item = gtk_menu_item_new_with_mnemonic("_Incoming call");
	g_object_set_data(G_OBJECT(menu_item), "call", call);
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item),
			call_menu);
	gtk_menu_shell_prepend(GTK_MENU_SHELL(mod->app_menu), menu_item);
	mod->incoming_call_menus = g_slist_append(mod->incoming_call_menus,
			menu_item);

	menu_item = gtk_menu_item_new_with_label(call_peeruri(call));
	gtk_widget_set_sensitive(menu_item, FALSE);
	gtk_menu_shell_append(GTK_MENU_SHELL(call_menu), menu_item);

	menu_item = gtk_menu_item_new_with_mnemonic("_Accept");
	g_object_set_data(G_OBJECT(menu_item), "call", call);
	g_signal_connect(G_OBJECT(menu_item), "activate",
			G_CALLBACK(menu_on_incoming_call_answer), mod);
	gtk_menu_shell_append(GTK_MENU_SHELL(call_menu), menu_item);

	menu_item = gtk_menu_item_new_with_mnemonic("_Reject");
	g_object_set_data(G_OBJECT(menu_item), "call", call);
	g_signal_connect(G_OBJECT(menu_item), "activate",
			G_CALLBACK(menu_on_incoming_call_reject), mod);
	gtk_menu_shell_append(GTK_MENU_SHELL(call_menu), menu_item);
}