コード例 #1
0
ファイル: TrayIcon.cpp プロジェクト: poxip/qcodedesk
/** \copydoc notify */
void qcd::TrayIcon::notify(const QString& title, const QString& message, const QUrl url)
{
    if (!url.isEmpty() && !url.isValid())
    {
        qDebug() << "Url is invalid. Specified url: " << url;
        return;
    }

#ifdef Q_OS_LINUX
    NotifyNotification *popup = notify_notification_new(
                QSTRING_TO_CHAR(title),
                QSTRING_TO_CHAR(message),
                "mail-message-new");

    if (!url.isEmpty())
    {
        auto* tray_data = new TrayNotifyData(url, this);

        notify_notification_add_action(popup, "default", "default", onNotifyClick, (gpointer)tray_data, NULL);
        notify_notification_add_action(popup, "open-url", "Otwórz", onNotifyClick, (gpointer)tray_data, NULL);
    }

    notify_notification_show(popup, NULL);
    if (url.isEmpty())
        g_object_unref(G_OBJECT(popup));
#else
    url_to_open = QUrl(url);
    showMessage(title, message);
#endif // Q_OS_LINUX

    // Change icon to notify the user (if has not clicked the notify baloon)
    setState(State::Notify);
}
コード例 #2
0
/*
 * open a notification window (expires in 5 seconds) to say thank you
 * to the user for his bug feedback.
 */
static void sent_an_oops(void)
{
	char *summary = _("Kernel bug diagnostic information sent");
	char *message = NULL;
	char *message_1 =
		_("Diagnostic information from your Linux kernel has been "
		  "sent to http://oops.kernel.org/ "
		  "for the Linux kernel developers to work on. \n"
		  "Thank you for contributing to improve the quality of the Linux kernel.\n");

	char *message_2 =
		_("Diagnostic information from your Linux kernel has been "
		  "sent to http://oops.kernel.org "
		  "for the Linux kernel developers to work on. \n"
		  "Thank you for contributing to improve the quality of the Linux kernel.\n"
		"You can view your submitted oops here: %s\n");
	NotifyActionCallback callback = notify_action;

	close_notification();


	if (strlen(url_to_oops)==0)
		message = g_strdup_printf("%s", message_1);
	else
		message = g_strdup_printf(message_2, url_to_oops);


	url_to_oops[0] = 0;

#if NOTIFY_CHECK_VERSION(0,7,0)
	notify = notify_notification_new(summary, message,
				"/usr/share/kerneloops/icon.png");
#else
	notify = notify_notification_new(summary, message,
				"/usr/share/kerneloops/icon.png", NULL);
#endif

	notify_notification_set_timeout(notify, 5000);
	notify_notification_set_urgency(notify, NOTIFY_URGENCY_LOW);


	notify_notification_add_action(notify, "default", "action",
						callback, "default", NULL);

	if (user_preference <= 0)
		notify_notification_add_action(notify, "always", _("Always"),
						callback, "always", NULL);
	notify_notification_add_action(notify, "never", _("Never again"),
						callback, "never", NULL);

	notify_notification_show(notify, NULL);
	g_free(message);
}
コード例 #3
0
ファイル: trayicon.c プロジェクト: Newterm/florence
/* Display startup notification */
gboolean trayicon_notification_start(gpointer userdata)
{
	START_FUNC
	struct trayicon *trayicon=(struct trayicon *)userdata;
	if (!notify_init(_("Florence"))) flo_warn(_("libnotify failed to initialize"));
#ifdef ENABLE_NOTIFICATION_ICON
	trayicon->notification=notify_notification_new_with_status_icon(
#else
	trayicon->notification=notify_notification_new(
#endif
		_("Florence is running"),
		_("Click on Florence icon to show/hide Florence.\n"
		"Right click on it to display menu and get help."),
#ifdef ENABLE_NOTIFICATION_ICON
		GTK_STOCK_INFO, trayicon->tray_icon);
#else
		GTK_STOCK_INFO);
#endif
	notify_notification_add_action(trayicon->notification, "STOP",
		_("Do not show again"), trayicon_notification_stop, NULL, NULL);
	notify_notification_set_timeout(trayicon->notification, 5000);
	if (!notify_notification_show(trayicon->notification, NULL))
		flo_warn(_("Notification failed"));
	END_FUNC
	return FALSE;
}
コード例 #4
0
ファイル: mailme.c プロジェクト: jku/mailme
static void
on_account_added (MailmeTelepathy        *tp_provider,
                  MailmeTelepathyAccount *account,
                  gpointer                user_data)
{
  /* Translators: button on a "unread mail" notification, will open
     a web page (e.g. gmail.com inbox) or a mail client */
  char *title = _("Open");
  NotifyNotification *notification;

  notification = notify_notification_new ("", NULL, NULL);
  notify_notification_set_category (notification, "email.arrived");

  notify_notification_add_action (notification,
                                  "open", title,
                                  on_open_action,
                                  account, NULL);

  g_object_set_data_full (G_OBJECT (account), "notification",
                          notification, g_object_unref);
  g_object_set_data (G_OBJECT (account), "last-unread-count",
                     GUINT_TO_POINTER(0));
  g_signal_connect (account,
                    "notify::unread-count",
                    G_CALLBACK (on_unread_count_changed),
                    NULL);
}
コード例 #5
0
nsresult
nsAlertsIconListener::ShowAlert(GdkPixbuf* aPixbuf)
{
  mNotification = notify_notification_new(mAlertTitle.get(), mAlertText.get(),
                                          nullptr, nullptr);

  if (!mNotification)
    return NS_ERROR_OUT_OF_MEMORY;

  if (aPixbuf)
    notify_notification_set_icon_from_pixbuf(mNotification, aPixbuf);

  NS_ADDREF(this);
  if (mAlertHasAction) {
    // What we put as the label doesn't matter here, if the action
    // string is "default" then that makes the entire bubble clickable
    // rather than creating a button.
    notify_notification_add_action(mNotification, "default", "Activate",
                                   notify_action_cb, this, nullptr);
  }

  // Fedora 10 calls NotifyNotification "closed" signal handlers with a
  // different signature, so a marshaller is used instead of a C callback to
  // get the user_data (this) in a parseable format.  |closure| is created
  // with a floating reference, which gets sunk by g_signal_connect_closure().
  GClosure* closure = g_closure_new_simple(sizeof(GClosure), this);
  g_closure_set_marshal(closure, notify_closed_marshal);
  mClosureHandler = g_signal_connect_closure(mNotification, "closed", closure, FALSE);
  gboolean result = notify_notification_show(mNotification, nullptr);

  return result ? NS_OK : NS_ERROR_FAILURE;
}
コード例 #6
0
int
main ()
{
        NotifyNotification *n;
        DBusConnection     *conn;

        if (!notify_init ("Default Action Test"))
                exit (1);

        conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
        loop = g_main_loop_new (NULL, FALSE);

        dbus_connection_setup_with_g_main (conn, NULL);

        n = notify_notification_new ("Matt is online", "", NULL, NULL);
        notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
        notify_notification_add_action (n,
                                        "default",
                                        "Do Default Action",
                                        (NotifyActionCallback) callback,
                                        NULL,
                                        NULL);
        notify_notification_set_category (n, "presence.online");

        if (!notify_notification_show (n, NULL)) {
                fprintf (stderr, "failed to send notification\n");
                return 1;
        }

        g_main_loop_run (loop);

        return 0;
}
コード例 #7
0
ファイル: notify.c プロジェクト: mcmihail/cinnamon-bluetooth
void show_notification(const gchar *summary, const gchar *message,
			const gchar *action, gint timeout, GCallback handler)
{
	NotifyActionCallback callback;
#ifndef HAVE_APP_INDICATOR
	GdkScreen *screen;
	GdkRectangle area;
#endif /* HAVE_APP_INDICATOR */

	if (notify_is_initted() == FALSE)
		return;

	if (notify) {
		g_signal_handlers_destroy(notify);
		notify_notification_close(notify, NULL);
	}

	notify = notify_notification_new(summary, message, ACTIVE_ICON_NAME);

	notify_notification_set_timeout(notify, timeout);

#ifndef HAVE_APP_INDICATOR
	if (gtk_status_icon_get_visible(statusicon) == TRUE) {
		gtk_status_icon_get_geometry(statusicon, &screen, &area, NULL);

		notify_notification_set_hint_int32(notify,
					"x", area.x + area.width / 2);
		notify_notification_set_hint_int32(notify,
					"y", area.y + area.height / 2);
	}
#endif /* HAVE_APP_INDICATOR */

	notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL);

	callback = handler ? NOTIFY_ACTION_CALLBACK(handler) : notify_action;

	notify_notification_add_action(notify, "default", "action",
						callback, NULL, NULL);
	if (action != NULL)
		notify_notification_add_action(notify, "button", action,
							callback, NULL, NULL);

	notify_notification_show(notify, NULL);
}
コード例 #8
0
ファイル: totimer.cpp プロジェクト: ztuowen/pomodori
bool notify(gpointer user_data)
{
    timeout=false;
    tres* lastres = (tres*)user_data;
    NotifyNotification *n;
    char str[20];
    if (lastres->time>POTIME)
        sprintf(str,"Time's up!(%d)",lastres->time-POTIME);
    else
        sprintf(str,"Time's up!");
    n = notify_notification_new (APPNAME,str, NULL);
    notify_notification_set_urgency(n,NOTIFY_URGENCY_CRITICAL);
    notify_notification_add_action(n,"M", "More",(NotifyActionCallback)timeup,lastres,NULL);
    notify_notification_add_action(n,"G", "Good",(NotifyActionCallback)timeup,lastres,NULL);
    g_signal_connect (n, "closed", G_CALLBACK(quit), NULL);
    notify_notification_set_timeout(n,0); //3 seconds
    notify_notification_show(n,NULL);
    return FALSE;
}
コード例 #9
0
ファイル: vino-prompt.c プロジェクト: cctsao1008/vino
static gboolean
vino_prompt_display (VinoPrompt   *prompt,
		     rfbClientPtr  rfb_client)
{
  char *host_label;

  if (prompt->priv->current_client)
    return prompt->priv->current_client == rfb_client;

  if (!vino_prompt_setup_dialog (prompt))
    return FALSE;

  host_label = g_strdup_printf (_("A user on the computer '%s' is trying to remotely view or control your desktop."),
				rfb_client->host);

  prompt->priv->notification = notify_notification_new (_("Another user is trying to view your desktop."),
							host_label,
							"preferences-desktop-remote-desktop");
  notify_notification_set_hint_string (prompt->priv->notification, "desktop-entry", "vino-server");
  notify_notification_add_action (prompt->priv->notification,
				  "refuse",
				  _("Refuse"),
				  vino_prompt_handle_response,
				  prompt,
				  NULL);
  notify_notification_add_action (prompt->priv->notification,
				  "accept",
				  _("Accept"),
				  vino_prompt_handle_response,
				  prompt,
				  NULL);

  g_free (host_label);

  prompt->priv->current_client = rfb_client;

  notify_notification_show (prompt->priv->notification, NULL);

  dprintf (PROMPT, "Prompting for client %p\n", rfb_client);

  return TRUE;
}
コード例 #10
0
ファイル: notify.c プロジェクト: cmassiot/vlc-broadcast
static int Notify( vlc_object_t *p_this, const char *psz_temp, GdkPixbuf *pix,
                   intf_thread_t *p_intf )
{
    intf_sys_t *p_sys = p_intf->p_sys;

    NotifyNotification * notification;

    /* Close previous notification if still active */
    if( p_sys->notification )
    {
        GError *p_error = NULL;
        notify_notification_close( p_sys->notification, &p_error );
        g_object_unref( p_sys->notification );
    }

    notification = notify_notification_new( _("Now Playing"),
                                            psz_temp, NULL, NULL );
    notify_notification_set_timeout( notification,
                                var_InheritInteger(p_this, "notify-timeout") );
    notify_notification_set_urgency( notification, NOTIFY_URGENCY_LOW );
    if( pix )
    {
        notify_notification_set_icon_from_pixbuf( notification, pix );
        gdk_pixbuf_unref( pix );
    }

    /* Adds previous and next buttons in the notification if actions are supported. */
    if( p_sys->b_has_actions )
    {
      notify_notification_add_action( notification, "previous", _("Previous"), Prev,
                                      (gpointer*)p_intf, NULL );
      notify_notification_add_action( notification, "next", _("Next"), Next,
                                      (gpointer*)p_intf, NULL );
    }

    notify_notification_show( notification, NULL);

    /* Stores the notification to be able to close it */
    p_sys->notification = notification;
    return VLC_SUCCESS;
}
コード例 #11
0
void NotificationBackendLibnotify::publish(
    const std::string& summary, const std::string& body,
    const std::string& viewParams)
{
    if(!m_initialized)
        return;

    if(m_notification) {
        notify_notification_clear_actions(m_notification);
        notify_notification_close(m_notification, NULL);
    }
#ifndef NOTIFY_CHECK_VERSION
# define NOTIFY_CHECK_VERSION(_x,_y,_z) 0
#endif
#if !NOTIFY_CHECK_VERSION(0,7,0) || defined(NOTIFY_COMPATIBILITY)
    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL, NULL);
#else
    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL);
#endif
    //if actions are not supported, don't add actions
    //An example is Ubuntu Notify OSD. It uses an alert box
    //instead of a bubble when a notification is appended with actions.
    //the alert box won't be closed until user inputs.
    //so disable it in case of no support of actions
    if(m_acceptsActions) {
        notify_notification_add_action(m_notification, "view",
                                       _("View"), notifyAction,
                                       (gpointer)viewParams.c_str(),
                                       NULL);
        // Use "default" as ID because that is what mutter-moblin
        // recognizes: it then skips the action instead of adding it
        // in addition to its own "Dismiss" button (always added).
        notify_notification_add_action(m_notification, "default",
                                       _("Dismiss"), notifyAction,
                                       (gpointer)viewParams.c_str(),
                                       NULL);
    }
    notify_notification_show(m_notification, NULL);
}
コード例 #12
0
ファイル: osd.c プロジェクト: brassy/audacious-plugins
void osd_setup_buttons (NotifyNotification *notification)
{
    notify_notification_clear_actions (notification);

    if (! aud_get_bool ("notify", "actions"))
        return;

    notify_notification_add_action (notification, "default", _("Show"),
     NOTIFY_ACTION_CALLBACK (show_cb), NULL, NULL);

    bool_t playing = aud_drct_get_playing ();
    bool_t paused = aud_drct_get_paused ();

    if (playing && ! paused)
        notify_notification_add_action (notification, "media-playback-pause",
         _("Pause"), NOTIFY_ACTION_CALLBACK (aud_drct_pause), NULL, NULL);
    else
        notify_notification_add_action (notification, "media-playback-start",
         _("Play"), NOTIFY_ACTION_CALLBACK (aud_drct_play), NULL, NULL);

    if (playing)
        notify_notification_add_action (notification, "media-skip-forward",
         _("Next"), NOTIFY_ACTION_CALLBACK (aud_drct_pl_next), NULL, NULL);
}
コード例 #13
0
ファイル: test-xy-actions.c プロジェクト: CaJIbePu/libnotify
int
main(int argc, char **argv)
{
	NotifyNotification *n;
	DBusConnection *conn;

	notify_init("XY");

	conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
	loop = g_main_loop_new(NULL, FALSE);

	dbus_connection_setup_with_g_main(conn, NULL);

	n = notify_notification_new("System update available",
								"New system updates are available. It is "
								"recommended that you install the updates.",
								NULL, NULL);

	notify_notification_set_hint_int32(n, "x", 600);
	notify_notification_set_hint_int32(n, "y", 10);
	notify_notification_add_action(n, "help", "Help",
								   (NotifyActionCallback)action_cb,
								   NULL, NULL);
	notify_notification_add_action(n, "update", "Update",
								   (NotifyActionCallback)action_cb,
								   NULL, NULL);

	if (!notify_notification_show(n, NULL)) {
		fprintf(stderr, "failed to send notification\n");
		return 1;
	}

	g_main_loop_run(loop);

	return 0;
}
コード例 #14
0
ファイル: imap.c プロジェクト: GCrean/hybrid
static void
process_unread_mails(hybrid_imap *imap, gint unread)
{
    if (imap->unread == unread || unread == 0) {
        if (unread == 0) {
            imap->unread = 0;
        }
        return;
    }

#ifdef USE_LIBNOTIFY
    gchar       *summary;
    GdkPixbuf   *pixbuf;
    const gchar *title = _("New Mail.");
    NotifyNotification *notification = NULL;

    summary = g_strdup_printf(_("<b>%s</b>\n<span size='xx-large' "
                              "foreground='red'><b>%d</b></span> "
                                "<span size='large'>unread mails.</span>"),
                              imap->email_addr, unread);
#ifdef LIBNOTIFY_OLD
    notification = notify_notification_new(title, summary, NULL, NULL);
#else
    notification = notify_notification_new(title, summary, NULL);
#endif
    notify_notification_set_timeout(notification, 5000);

    imap->tmp_unread = unread;
    notify_notification_clear_actions(notification);
    notify_notification_add_action(notification, "test", _("I Know"),
                                   NOTIFY_ACTION_CALLBACK(action_cb),
                                   imap, NULL);

    pixbuf = hybrid_create_proto_icon(imap->account->proto->info->name, 48);
    if (pixbuf) {
        notify_notification_set_icon_from_pixbuf(notification, pixbuf);
        g_object_unref(pixbuf);
    }

    notify_notification_show(notification, NULL);
    g_free(summary);

#endif
}
コード例 #15
0
 void init() {
     if (!notify_is_initted()) {
         notify_init(QGSTRING(QCoreApplication::applicationName()));
     }
     
     Q_Q(QchNotification);
     notification = hildon_notification_new(QGSTRING(title), QGSTRING(text), QGSTRING(iconSource), NULL);
     notify_notification_add_action(NOTIFY_NOTIFICATION(notification), "default",
                                    QGSTRING(QCoreApplication::applicationName()),
                                    NOTIFY_ACTION_CALLBACK(onNotificationClicked), q, NULL);
     g_signal_connect(G_OBJECT(notification), "closed", G_CALLBACK(onNotificationClosed), q);
     
     setNotificationCategory();
     setNotificationHints();
     setNotificationSound();
     setNotificationTimeout();
     
     if (showOnInit) {
         showNotification();
     }
 }
コード例 #16
0
static void got_a_message(void)
{
	char *summary = _("Your system had a kernel failure");
	char *message =
	       _("There is diagnostic information available for this failure."
		" Do you want to submit this information to the http://oops.kernel.org/"
		" website for use by the Linux kernel developers?\n");

	NotifyActionCallback callback = notify_action;

	/* if there's a notification active already, close it first */
	close_notification();

#if NOTIFY_CHECK_VERSION(0,7,0)
	notify = notify_notification_new(summary, message,
				"/usr/share/kerneloops/icon.png");
#else
	notify = notify_notification_new(summary, message,
				"/usr/share/kerneloops/icon.png", NULL);
#endif

	notify_notification_set_timeout(notify, 0);
	notify_notification_set_urgency(notify, NOTIFY_URGENCY_CRITICAL);


	/*
	 * add the buttons and default action
	 */

	notify_notification_add_action(notify, "default", "action",
						callback, "default", NULL);

	notify_notification_add_action(notify, "always", _("Always"),
						callback, "always", NULL);
	notify_notification_add_action(notify, "yes", _("Yes"),
						callback, "yes", NULL);
	notify_notification_add_action(notify, "no", _("No"),
						callback, "no", NULL);
	notify_notification_add_action(notify, "never", _("Never"),
						callback, "never", NULL);
	if (detail_file_name) {
		notify_notification_add_action(notify,
			"details", _("Show Details"),
			detail_action, "details", NULL);
	}

	notify_notification_show(notify, NULL);
}
コード例 #17
0
static void
update_notification (GduSdMonitor        *monitor,
                     GList               *problems,
                     NotifyNotification **notification,
                     const gchar         *title,
                     const gchar         *text,
                     const gchar         *icon_name,
                     const gchar         *action,
                     const gchar         *action_label)
{
  if (g_list_length (problems) > 0)
    {
      /* it could be the notification has already been presented, in that
       * case, don't show another one
       */
      if (*notification == NULL)
        {
          *notification = notify_notification_new (title, text, icon_name);
          notify_notification_set_urgency (*notification, NOTIFY_URGENCY_CRITICAL);
          notify_notification_set_timeout (*notification, NOTIFY_EXPIRES_NEVER);
          notify_notification_set_hint_string (*notification, "desktop-entry", "gnome-disks");
          notify_notification_add_action (*notification,
                                          action,
                                          action_label,
                                          (NotifyActionCallback) on_examine_action_clicked,
                                          monitor,
                                          NULL);
          notify_notification_show (*notification, NULL);
        }
    }
  else
    {
      if (*notification != NULL)
        {
          notify_notification_close (*notification, NULL);
          g_clear_object (notification);
        }
    }
}
コード例 #18
0
ファイル: notification.c プロジェクト: Rocik/memp
NotifyNotification *sendNotify(char *title, char *message, pid_t *p_PID)
{
	NotifyNotification *notification;
	
	notification = notify_notification_new(title, message, iconType);
	
	notify_notification_set_urgency(notification, NOTIFY_URGENCY_CRITICAL);
	notify_notification_set_timeout(notification, NOTIFY_EXPIRES_NEVER);
	
    notify_notification_add_action(notification, "button", "Kill this process",
	   (NotifyActionCallback)killApp, p_PID, NULL
	);

    if (!notify_notification_show(notification, &error)) {
		g_error("Sending notification failed: %s", error->message);
        g_error_free(error);
    }
	
	g_signal_connect(notification, "closed", G_CALLBACK(notifyClosed), NULL);
	
	isNotifyActive = 1;
	return notification;
}
コード例 #19
0
static void
progress_ui_handler_ensure_notification (NautilusProgressUIHandler *self)
{
	NotifyNotification *notify;

	if (self->priv->progress_notification) {
		return;
	}

	notify = notify_notification_new (_("File Operations"),
					  NULL, NULL);
	self->priv->progress_notification = notify;

	notify_notification_set_category (notify, "transfer");
	notify_notification_set_hint (notify, "resident",
				      g_variant_new_boolean (TRUE));

	notify_notification_add_action (notify, ACTION_DETAILS,
					_("Show Details"),
					notification_show_details_cb,
					self,
					NULL);
}
コード例 #20
0
gboolean
ring_notify_incoming_call(
#if !USE_LIBNOTIFY
    G_GNUC_UNUSED
#endif
    Call* call)
{
    gboolean success = FALSE;
#if USE_LIBNOTIFY
    g_return_val_if_fail(call, FALSE);

    gchar *body = g_markup_escape_text(call->formattedName().toUtf8().constData(), -1);
    std::shared_ptr<NotifyNotification> notification(
        notify_notification_new(_("Incoming call"), body, NULL), g_object_unref);
    g_free(body);

    /* get photo */
    QVariant var_p = GlobalInstances::pixmapManipulator().callPhoto(
        call->peerContactMethod(), QSize(50, 50), false);
    std::shared_ptr<GdkPixbuf> photo = var_p.value<std::shared_ptr<GdkPixbuf>>();
    notify_notification_set_image_from_pixbuf(notification.get(), photo.get());

    /* calls have highest urgency */
    notify_notification_set_urgency(notification.get(), NOTIFY_URGENCY_CRITICAL);
    notify_notification_set_timeout(notification.get(), NOTIFY_EXPIRES_DEFAULT);

    /* if the notification server supports actions, make the default action to show the call */
    if (server_info.actions) {
        notify_notification_add_action(notification.get(),
                                       "default",
                                       C_("notification action name", "Show"),
                                       (NotifyActionCallback)ring_notify_show_cm,
                                       call->peerContactMethod(),
                                       nullptr);
    }

    GError *error = NULL;
    success = notify_notification_show(notification.get(), &error);

    if (success) {
        /* monitor the life cycle of the call and try to close the notification
         * once the call has been aswered */
        auto state_changed_conn = std::make_shared<QMetaObject::Connection>();
        *state_changed_conn = QObject::connect(
            call,
            &Call::lifeCycleStateChanged,
            [notification, state_changed_conn] (Call::LifeCycleState newState, G_GNUC_UNUSED Call::LifeCycleState previousState)
                {
                    g_return_if_fail(NOTIFY_IS_NOTIFICATION(notification.get()));
                    if (newState > Call::LifeCycleState::INITIALIZATION) {
                        /* note: not all systems will actually close the notification
                         * even if the above function returns as true */
                        if (!notify_notification_close(notification.get(), NULL))
                            g_warning("could not close notification");

                        /* once we (try to) close the notification, we can
                         * disconnect from this signal; this should also destroy
                         * the notification shared_ptr as its ref count will
                         * drop to 0 */
                        QObject::disconnect(*state_changed_conn);
                    }
                }
            );
    } else {
        g_warning("failed to show notification: %s", error->message);
        g_clear_error(&error);
    }
#endif
    return success;
}
コード例 #21
0
static gboolean notification_trayicon_popup_create(MsgInfo *msginfo,
						   NotificationFolderType nftype)
{
  gchar *summary = NULL;
  gchar *utf8_str = NULL;
  GdkPixbuf *pixbuf;
  GList *caps = NULL;
  gboolean support_actions = FALSE;

  /* init libnotify if necessary */
  if(!notify_is_initted()) {
    if(!notify_init("claws-mail")) {
      debug_print("Notification Plugin: Failed to initialize libnotify. "
		  "No popups will be shown.\n");
      return FALSE;
    }
  }

  /* Count messages */
  notification_trayicon_popup_count_msgs(nftype);

  summary  = notification_trayicon_popup_assemble_summary();
  utf8_str = notification_trayicon_popup_assemble_body(msginfo);

#if NOTIFY_CHECK_VERSION(0, 7, 0)
  popup.notification = notify_notification_new(summary, utf8_str, NULL);
#else
  popup.notification = notify_notification_new(summary, utf8_str, NULL, NULL);
  notify_notification_attach_to_status_icon(popup.notification, trayicon);
#endif

  g_free(summary);
  g_free(utf8_str);

  caps = notify_get_server_caps();
    if(caps != NULL) {
      GList *c;
      for(c = caps; c != NULL; c = c->next) {
	if(strcmp((char*)c->data, "actions") == 0 ) {
	  support_actions = TRUE;
	  break;
        }
      }

    g_list_foreach(caps, (GFunc)g_free, NULL);
    g_list_free(caps);
  }

  /* Default action */
  if (support_actions)
    notify_notification_add_action(popup.notification,
				   "default", "Present main window",
				   (NotifyActionCallback)
				   notification_trayicon_popup_default_action_cb,
				   GINT_TO_POINTER(nftype),
				   notification_trayicon_popup_free_func);

  if(popup.notification == NULL) {
    debug_print("Notification Plugin: Failed to create a new notification.\n");
    return FALSE;
  }

  /* Icon */
  pixbuf = NULL;
#ifndef USE_NEW_ADDRBOOK
  if(msginfo && msginfo->from) {
    gchar *icon_path;
    icon_path = addrindex_get_picture_file(msginfo->from);
    if(is_file_exist(icon_path)) {
      GError *error = NULL;
      gint w, h;

      gdk_pixbuf_get_file_info(icon_path, &w, &h);
      if((w > 64) || (h > 64))
	pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path,
						   64, 64, TRUE, &error);
      else
	pixbuf = gdk_pixbuf_new_from_file(icon_path, &error);

      if(!pixbuf) {
	debug_print("Could not load picture file: %s\n",
		    error ? error->message : "no details");
	g_error_free(error);
      }
    }
    else
      debug_print("Picture path does not exist: %s\n",icon_path);
    g_free(icon_path);
  }
#endif
  if(!pixbuf)
    pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64));

  if(pixbuf) {
    notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf);
    g_object_unref(pixbuf);
  }
  else /* This is not fatal */
    debug_print("Notification plugin: Icon could not be loaded.\n");

  /* timeout */
  notify_notification_set_timeout(popup.notification, notify_config.trayicon_popup_timeout);

  /* Category */
  notify_notification_set_category(popup.notification, "email.arrived");

  /* get notified on bubble close */
  g_signal_connect(G_OBJECT(popup.notification), "closed", G_CALLBACK(popup_timeout_fun), NULL);

  /* Show the popup */
  notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail");
  if(!notify_notification_show(popup.notification, &(popup.error))) {
    debug_print("Notification Plugin: Failed to send notification: %s\n",
		popup.error->message);
    g_clear_error(&(popup.error));
    g_object_unref(G_OBJECT(popup.notification));
    popup.notification = NULL;
    return FALSE;
  }

  /* Store path to message */
  if(nftype == F_TYPE_MAIL) {
    if(msginfo->folder && msginfo->folder) {
      gchar *ident;
      ident = folder_item_get_identifier(msginfo->folder);
      popup.msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S,
				       msginfo->msgnum);
      g_free(ident);
    }
    else
      popup.msg_path = NULL;
  }

  debug_print("Notification Plugin: Popup created with libnotify.\n");

  return TRUE;
}
コード例 #22
0
static void
goa_daemon_update_notifications (GoaDaemon *daemon)
{
  gboolean show_notification;
  GList *objects;
  GList *l;

  show_notification = FALSE;
  objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (daemon->object_manager));
  for (l = objects; l != NULL; l = l->next)
    {
      GoaObject *object = GOA_OBJECT (l->data);
      GoaAccount *account;
      account = goa_object_peek_account (object);
      if (account != NULL)
        {
          if (goa_account_get_attention_needed (account))
            {
              show_notification = TRUE;
              break;
            }
        }
    }

  if (show_notification)
    {
      if (daemon->notification == NULL)
        {
          GError *error;

          daemon->notification = notify_notification_new (_("An online account needs attention"),
                                                          NULL,
                                                          NULL);
          notify_notification_set_timeout (daemon->notification, NOTIFY_EXPIRES_NEVER);
          g_object_set (daemon->notification, "icon-name", "gtk-dialog-error", NULL);
          notify_notification_add_action (daemon->notification,
                                          "open-online-accounts",
                                          _("Open Online Accounts..."),
                                          notification_cb,
                                          daemon,
                                          NULL); /* GFreeFunc */

          error = NULL;
          if (!notify_notification_show (daemon->notification, &error))
            {
              goa_warning ("Error showing notification: %s (%s, %d)",
                           error->message, g_quark_to_string (error->domain), error->code);
              g_error_free (error);
              g_object_unref (daemon->notification);
              daemon->notification = NULL;
            }
          else
            {
              g_signal_connect (daemon->notification,
                                "closed",
                                G_CALLBACK (on_notification_closed),
                                daemon);
            }
        }
    }
  else
    {
      if (daemon->notification != NULL)
        {
          GError *error;
          error = NULL;
          if (!notify_notification_close (daemon->notification, &error))
            {
              goa_warning ("Error closing notification: %s (%s, %d)",
                           error->message, g_quark_to_string (error->domain), error->code);
              g_error_free (error);
            }
          g_signal_handlers_disconnect_by_func (daemon->notification,
                                                G_CALLBACK (on_notification_closed),
                                                daemon);
          g_object_unref (daemon->notification);
          daemon->notification = NULL;
        }
    }

  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);
}
コード例 #23
0
ファイル: libnotify.c プロジェクト: LMephisto/liferea
static void
notif_libnotify_node_has_new_items (nodePtr node, gboolean enforced)
{
	itemSetPtr	itemSet;
	GList		*iter;

	NotifyNotification *n;

	gchar		*labelSummary_p;
	gint		item_count = 0;

	gboolean	show_popup_windows;

	conf_get_bool_value(SHOW_POPUP_WINDOWS, &show_popup_windows);

	if (!show_popup_windows && !enforced)
		return;

	/* Count updated feed */
	itemSet = node_get_itemset (node);
	iter = itemSet->ids;
	while (iter) {
		itemPtr item = item_load (GPOINTER_TO_UINT (iter->data));
		if (item->popupStatus && !item->readStatus)
			item_count++;
		item_unload (item);
		iter = g_list_next (iter);
	}
	itemset_free (itemSet);

	if (item_count == 0)
		return;

	labelSummary_p = g_strdup_printf (ngettext ("<b>%s</b> has <b>%d</b> update", "<b>%s</b> has <b>%d</b> updates", item_count), 
	                                  node_get_title (node), item_count);
	n = notify_notification_new (_("Feed Update"), labelSummary_p, "liferea", NULL);
	g_free (labelSummary_p);

 	if (supports_append) {
 		notify_notification_set_hint_string(n, "append", "allow");
 	} else {
		notify_notification_set_icon_from_pixbuf (n, node_get_icon (node));
	}
	
	notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
	if (supports_actions) {
		notify_notification_add_action (n, "show_details", _("Show details"),
	                                (NotifyActionCallback)notif_libnotify_callback_show_details,
	                                node->id, NULL);
		notify_notification_add_action (n, "open", _("Open feed"),
	                                (NotifyActionCallback)notif_libnotify_callback_open,
	                                node->id, NULL);
		notify_notification_add_action (n, "mark_read", _("Mark all as read"),
	                                (NotifyActionCallback)notif_libnotify_callback_mark_read,
	                                node->id, NULL);
	}
	notify_notification_set_category (n, "feed");

	notify_notification_attach_to_status_icon (n, ui_tray_get_status_icon ());

	if (!notify_notification_show (n, NULL))
		g_warning ("notif_libnotify.c - failed to send notification via libnotify");
}
コード例 #24
0
ファイル: libnotify.c プロジェクト: LMephisto/liferea
static void
notif_libnotify_callback_show_details (NotifyNotification *n, gchar *action, gpointer user_data)
{
	nodePtr node_p;

	GList *list_p;
	itemPtr item_p;

	gchar *labelText_p;
	gchar *labelText_now_p = NULL;
	gchar *labelText_prev_p;

	gchar *labelHeadline_p;
	const gchar *labelURL_p;

	gint item_count = 0;

	g_assert (action != NULL);
	g_assert (strcmp(action, "show_details") == 0);
	node_p = node_from_id (user_data);

	if (node_p) {
		itemSetPtr itemSet = node_get_itemset (node_p);

		labelText_now_p = g_strdup ("");

		/* Gather the feed's headlines */
		list_p = itemSet->ids;
		while (list_p) {
			item_p = item_load (GPOINTER_TO_UINT (list_p->data));
			if (item_p->popupStatus && !item_p->readStatus) {
				item_p->popupStatus = FALSE;
				item_count += 1;

				labelHeadline_p = g_strdup (item_get_title (item_p));
				if (labelHeadline_p == NULL ) {
					labelHeadline_p = g_strdup_printf (_("This news entry has no headline"));
				}

				labelURL_p = item_get_base_url (item_p);
				if (labelURL_p) {
					labelText_p = g_strdup_printf ("%s <a href='%s'>%s</a>\n", labelHeadline_p, labelURL_p, _("Visit"));
				} else {
					labelText_p = g_strdup_printf ("%s\n", labelHeadline_p);
				}

				labelText_prev_p = labelText_now_p;
				labelText_now_p = g_strconcat(labelText_now_p, labelText_p, NULL);

				g_free(labelHeadline_p);
				g_free(labelText_p);
				g_free(labelText_prev_p);
			}
			item_unload (item_p);
			list_p = g_list_next (list_p);
		}
		itemset_free (itemSet);

		if (item_count == 0) {
			g_free (labelText_now_p);
			return;
		}
	} else {
		ui_show_error_box(_("This feed does not exist anymore!"));
	}

	notify_notification_close (n, NULL);

	if (node_p) {
//		notify_notification_update ( n, node_get_title(node_p), labelText_now_p, NULL);
//		notify_notification_clear_actions(n);

		n = notify_notification_new (node_get_title (node_p), labelText_now_p, NULL, NULL);

		notify_notification_set_icon_from_pixbuf (n, node_get_icon (node_p));
		notify_notification_set_category (n, "feed");
		notify_notification_set_timeout (n, NOTIFY_EXPIRES_NEVER);

		if (supports_actions) {
			notify_notification_add_action (n, "open", _("Open feed"),
							(NotifyActionCallback)notif_libnotify_callback_open,
							node_p->id, NULL);
			notify_notification_add_action (n, "mark_read", _("Mark all as read"),
							(NotifyActionCallback)notif_libnotify_callback_mark_read,
							node_p->id, NULL);
		}

		notify_notification_attach_to_status_icon (n, ui_tray_get_status_icon ());

		if (!notify_notification_show (n, NULL)) {
			g_warning ("libnotify.c - failed to update notification via libnotify\n");
		}

		g_free (labelText_now_p);
	}
}
コード例 #25
0
static gboolean
ldsm_notify_for_mount (LdsmMountInfo *mount,
                       gboolean       multiple_volumes,
                       gboolean       other_usable_volumes)
{
        gchar  *name, *program;
        gint64 free_space;
        gint response;
        gboolean has_trash;
        gboolean has_disk_analyzer;
        gboolean retval = TRUE;
        gchar *path;

        /* Don't show a notice if one is already displayed */
        if (dialog != NULL || notification != NULL)
                return retval;

        name = g_unix_mount_guess_name (mount->mount);
        free_space = (gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail;
        has_trash = ldsm_mount_has_trash (mount);
        path = g_strdup (g_unix_mount_get_mount_path (mount->mount));

        program = g_find_program_in_path (DISK_SPACE_ANALYZER);
        has_disk_analyzer = (program != NULL);
        g_free (program);

        if (server_has_actions ()) {
                char *free_space_str;
                char *summary;
                char *body;

                free_space_str = g_format_size (free_space);

                if (multiple_volumes) {
                        summary = g_strdup_printf (_("Low Disk Space on \"%s\""), name);
                        if (has_trash) {
                                body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining.  You may free up some space by emptying the trash."),
                                                        name,
                                                        free_space_str);
                        } else {
                                body = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."),
                                                        name,
                                                        free_space_str);
                        }
                } else {
                        summary = g_strdup (_("Low Disk Space"));
                        if (has_trash) {
                                body = g_strdup_printf (_("This computer has only %s disk space remaining.  You may free up some space by emptying the trash."),
                                                        free_space_str);
                        } else {
                                body = g_strdup_printf (_("This computer has only %s disk space remaining."),
                                                        free_space_str);
                        }
                }
                g_free (free_space_str);

                notification = notify_notification_new (summary, body, "drive-harddisk-symbolic");
                g_free (summary);
                g_free (body);

                g_signal_connect (notification,
                                  "closed",
                                  G_CALLBACK (on_notification_closed),
                                  NULL);

                notify_notification_set_app_name (notification, _("Disk space"));
                notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
                notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
                notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
                if (has_disk_analyzer) {
                        notify_notification_add_action (notification,
                                                        "examine",
                                                        _("Examine"),
                                                        (NotifyActionCallback) examine_callback,
                                                        g_strdup (path),
                                                        g_free);
                }
                if (has_trash) {
                        notify_notification_add_action (notification,
                                                        "empty-trash",
                                                        _("Empty Trash"),
                                                        (NotifyActionCallback) empty_trash_callback,
                                                        NULL,
                                                        NULL);
                }
                notify_notification_add_action (notification,
                                                "ignore",
                                                _("Ignore"),
                                                (NotifyActionCallback) ignore_callback,
                                                NULL,
                                                NULL);
                notify_notification_set_category (notification, "device");

                if (!notify_notification_show (notification, NULL)) {
                        g_warning ("failed to send disk space notification\n");
                }

        } else {
                dialog = csd_ldsm_dialog_new (other_usable_volumes,
                                              multiple_volumes,
                                              has_disk_analyzer,
                                              has_trash,
                                              free_space,
                                              name,
                                              path);

                g_object_ref (G_OBJECT (dialog));
                response = gtk_dialog_run (GTK_DIALOG (dialog));

                gtk_widget_destroy (GTK_WIDGET (dialog));
                dialog = NULL;

                switch (response) {
                case GTK_RESPONSE_CANCEL:
                        retval = FALSE;
                        break;
                case CSD_LDSM_DIALOG_RESPONSE_ANALYZE:
                        retval = FALSE;
                        ldsm_analyze_path (path);
                        break;
                case CSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH:
                        retval = TRUE;
                        csd_ldsm_show_empty_trash ();
                        break;
                case GTK_RESPONSE_NONE:
                case GTK_RESPONSE_DELETE_EVENT:
                        retval = TRUE;
                        break;
                default:
                        g_assert_not_reached ();
                }
        }

        g_free (name);
        g_free (path);

        return retval;
}
コード例 #26
0
static gboolean
ring_notify_show_text_message(ContactMethod *cm, const QModelIndex& idx)
{
    g_return_val_if_fail(idx.isValid() && cm, FALSE);
    gboolean success = FALSE;

    auto title = g_markup_printf_escaped(C_("Text message notification", "%s says:"), idx.data(static_cast<int>(Ring::Role::Name)).toString().toUtf8().constData());
    auto body = g_markup_escape_text(idx.data(Qt::DisplayRole).toString().toUtf8().constData(), -1);

    NotifyNotification *notification_new = nullptr;
    NotifyNotification *notification_old = nullptr;

    /* try to get the previous notification */
    auto chat_table = ring_notify_get_chat_table();
    auto list = (GList *)g_hash_table_lookup(chat_table, cm);
    if (list)
        notification_old = (NotifyNotification *)list->data;

    /* we display chat notifications in different ways to suit different notification servers and
     * their capabilities:
     * 1. if the server doesn't support appending (eg: Notification Daemon) then we update the
     *    previous notification (if exists) with new text; otherwise it takes we have many
     *    notifications from the same person... we don't concatinate the old messages because
     *    servers which don't support append usually don't support multi line bodies
     * 2. the notify-osd server supports appending; however it doesn't clear the old notifications
     *    on demand, which means in our case that chat messages which have already been read could
     *    still be displayed when a new notification is appended, thus in this case, we update
     *    the old notification body manually to only contain the unread messages
     * 3. the 3rd case is that the server supports append but is not notify-osd, then we simply use
     *    the append feature
     */

    if (notification_old && !server_info.append) {
        /* case 1 */
        notify_notification_update(notification_old, title, body, nullptr);
        notification_new = notification_old;
    } else if (notification_old && g_strcmp0(server_info.name, SERVER_NOTIFY_OSD) == 0) {
        /* case 2 */
        /* print up to MAX_NOTIFICATIONS unread messages */
        int msg_count = 0;
        auto idx_next = idx.sibling(idx.row() - 1, idx.column());
        auto read = idx_next.data(static_cast<int>(Media::TextRecording::Role::IsRead)).toBool();
        while (idx_next.isValid() && !read && msg_count < MAX_NOTIFICATIONS) {

            auto body_prev = body;
            body = g_markup_printf_escaped("%s\n%s", body_prev, idx_next.data(Qt::DisplayRole).toString().toUtf8().constData());
            g_free(body_prev);

            idx_next = idx_next.sibling(idx_next.row() - 1, idx_next.column());
            read = idx_next.data(static_cast<int>(Media::TextRecording::Role::IsRead)).toBool();
            ++msg_count;
        }

        notify_notification_update(notification_old, title, body, nullptr);

        notification_new = notification_old;
    } else {
        /* need new notification for case 1, 2, or 3 */
        notification_new = notify_notification_new(title, body, nullptr);

        /* track in hash table */
        auto list = (GList *)g_hash_table_lookup(chat_table, cm);
        list = g_list_append(list, notification_new);
        g_hash_table_replace(chat_table, cm, list);

        /* get photo */
        QVariant var_p = GlobalInstances::pixmapManipulator().callPhoto(
            cm, QSize(50, 50), false);
        std::shared_ptr<GdkPixbuf> photo = var_p.value<std::shared_ptr<GdkPixbuf>>();
        notify_notification_set_image_from_pixbuf(notification_new, photo.get());

        /* normal priority for messages */
        notify_notification_set_urgency(notification_new, NOTIFY_URGENCY_NORMAL);

        /* remove the key and value from the hash table once the notification is
         * closed; note that this will also unref the notification */
        g_signal_connect(notification_new, "closed", G_CALLBACK(notification_closed), cm);

        /* if the notification server supports actions, make the default action to show the chat view */
        if (server_info.actions) {
            notify_notification_add_action(notification_new,
                                           "default",
                                           C_("notification action name", "Show"),
                                           (NotifyActionCallback)ring_notify_show_cm,
                                           cm,
                                           nullptr);
        }
    }

    GError *error = nullptr;
    success = notify_notification_show(notification_new, &error);
    if (!success) {
        g_warning("failed to show notification: %s", error->message);
        g_clear_error(&error);
    }

    g_free(title);
    g_free(body);

    return success;
}
コード例 #27
0
ファイル: drwright.c プロジェクト: GNOME/drwright
static void
show_warning_notification (DrWright *dr, gboolean show)
{
	NotifyNotification *notification;
	gint minutes, seconds;
	gchar *summary, *body;
	GError *error = NULL;

	if (show == FALSE) {
		if (dr->notification) {
			gboolean success = notify_notification_close (dr->notification, &error);
			if (success) {
				g_object_unref (dr->notification);
				dr->notification = NULL;
			}
			else {
				g_warning ("%s", error->message);
			}
			g_clear_error (&error);
		}
		dr->num_minutes_last_displayed = -1;
		return;
	}

	seconds = dr->type_time - drw_timer_elapsed (dr->timer) - dr->save_last_time;
	minutes = (seconds / 60) + 1;

	if (minutes == dr->num_minutes_last_displayed) {
		return;
	}
	dr->num_minutes_last_displayed = minutes;

	summary = _("Typing Break Reminder");

	if (minutes > 1) {
		body = g_strdup_printf (ngettext ("Approximately %d minute to the next break.",
		                                  "Approximately %d minutes to the next break.",
		                                  minutes),
		                        minutes);
	}
	else {
		body = g_strdup (_("Less than one minute to the next break."));
	}

	if (dr->notification) {
		notification = dr->notification;
		notify_notification_update (notification, summary, body, "typing-monitor");
	}
	else {
		notification = notify_notification_new (summary, body, "typing-monitor");
		notify_notification_set_hint (notification, "resident",
		                              g_variant_new_boolean (TRUE));
		notify_notification_add_action (notification,
		                                "settings", _("Settings…"),
		                                NOTIFY_ACTION_CALLBACK (notification_action_cb),
		                                dr, NULL);
		notify_notification_add_action (notification,
		                                "take-break", _("Take Break Now"),
		                                NOTIFY_ACTION_CALLBACK (notification_action_cb),
		                                dr, NULL);
		dr->notification = notification;
	}

	if (!notify_notification_show (notification, &error)) {
		g_warning ("%s", error->message);
	}

	g_clear_error (&error);
	g_free (body);
}
コード例 #28
0
ファイル: taskbarex.cpp プロジェクト: abergstr/BOINC
bool wxTaskBarIconEx::SetBalloon(const wxIcon& icon, const wxString title, const wxString message, unsigned int iconballoon)
{
    wxLogTrace(wxT("Function Start/End"), wxT("wxTaskBarIconEx::SetBalloon - Function Begin"));

    bool retval = false;
    GError* error = NULL;

    if (!IsOK())
        return false;

    if (!icon.Ok())
        return false;

    if (!SetIcon(icon, wxEmptyString))
        return false;

    gchar* desired_icon = NULL;
    switch(iconballoon)
    {
        case BALLOONTYPE_INFO:
            desired_icon = GTK_STOCK_DIALOG_INFO;
            break;
        case BALLOONTYPE_WARNING:
            desired_icon = GTK_STOCK_DIALOG_WARNING;
            break;
        case BALLOONTYPE_ERROR:
            desired_icon = GTK_STOCK_DIALOG_ERROR;
            break;
    }

    if (!g_pNotification)
    {
        // Old Style
        if (my_notify_notification_new_with_status_icon) {
            g_pNotification =
                (*my_notify_notification_new_with_status_icon)(
                    title.mb_str(),
                    message.mb_str(),
                    desired_icon,
                    g_pStatusIcon
                );
        }

        // New Style
        if (my_notify_notification_new) {
            g_pNotification =
                (*my_notify_notification_new)(
                    title.mb_str(),
                    message.mb_str(),
                    gtk_status_icon_get_icon_name(g_pStatusIcon)
            );
        }

        g_signal_connect(
            g_pNotification,
            "closed",
            G_CALLBACK(status_icon_notification_closed),
            this
        );

        notify_notification_add_action(
            g_pNotification,
            "default",
            "Do Default Action",
            NOTIFY_ACTION_CALLBACK(status_icon_notification_actions),
            this,
            NULL
        );
    }
    else
    {
        notify_notification_update(
            g_pNotification,
            title.mb_str(),
            message.mb_str(),
            desired_icon
        );
    }

    retval = notify_notification_show(g_pNotification, &error);
    g_clear_error(&error);

    wxLogTrace(wxT("Function Start/End"), wxT("wxTaskBarIconEx::SetBalloon - Function End"));
    return retval;
}
コード例 #29
0
static void
notify (const gchar *title,
		const gchar *body,
		PurpleBuddy *buddy,
		PurpleConversation *conv)
{
	NotifyNotification *notification = NULL;
	GdkPixbuf *icon;
	PurpleBuddyIcon *buddy_icon;
	gchar *tr_body;
	PurpleContact *contact;

	if (buddy)
		contact = purple_buddy_get_contact (buddy);
	else
		contact = NULL;

	if (body)
		tr_body = truncate_escape_string (body, 60);
	else
		tr_body = NULL;

	if (!conv && buddy)
		conv = purple_find_conversation_with_account (PURPLE_CONV_TYPE_ANY, buddy->name, buddy->account);

	if (conv && conv->ui_ops && conv->ui_ops->has_focus) {
	    if (conv->ui_ops->has_focus(conv) == TRUE) {
		/* do not notify if the conversation is currently in focus */
		return;
	    }
	}

	if (contact)
		notification = g_hash_table_lookup (buddy_hash, contact);
	else if (conv)
		notification = g_hash_table_lookup (buddy_hash, conv);
	else
		notification = NULL;

	if (notification != NULL) {
		notify_notification_update (notification, title, tr_body, NULL);
		notify_notification_set_timeout(notification, purple_prefs_get_int("/plugins/gtk/libnotify/timeout"));
		/* this shouldn't be necessary, file a bug */
		notify_notification_show (notification, NULL);

		purple_debug_info (PLUGIN_ID, "notify(), update: "
						 "title: '%s', body: '%s', buddy: '%s'\n",
						 title, tr_body, buddy ? best_name (buddy) : "");

		g_free (tr_body);
		return;
	}
#ifdef LIBNOTIFY_07
	notification = notify_notification_new (title, tr_body, NULL);
#else
	notification = notify_notification_new (title, tr_body, NULL, NULL);
#endif
	purple_debug_info (PLUGIN_ID, "notify(), new: "
					 "title: '%s', body: '%s', buddy: '%s'\n",
					 title, tr_body, buddy ? best_name (buddy) : "");

	g_free (tr_body);

	if (buddy)
		buddy_icon = purple_buddy_get_icon (buddy);
	else
		buddy_icon = NULL;

	if (buddy_icon) {
		icon = pixbuf_from_buddy_icon (buddy_icon);
		purple_debug_info (PLUGIN_ID, "notify(), has a buddy icon.\n");
	} else if (buddy) {
		icon = pidgin_create_prpl_icon (buddy->account, 1);
		purple_debug_info (PLUGIN_ID, "notify(), has a prpl icon.\n");
	} else if (conv) {
		icon = pidgin_create_prpl_icon (conv->account, 1);
		purple_debug_info (PLUGIN_ID, "notify(), has a prpl icon.\n");
	} else {
		icon = NULL;
		purple_debug_info (PLUGIN_ID, "notify(), has no icon.\n");
	}

	if (icon) {
		notify_notification_set_icon_from_pixbuf (notification, icon);
		g_object_unref (icon);
	} else {
		purple_debug_warning (PLUGIN_ID, "notify(), couldn't find any icon!\n");
	}

	if (contact)
		g_hash_table_insert (buddy_hash, contact, notification);
	else if (conv)
		g_hash_table_insert (buddy_hash, conv, notification);

	g_object_set_data (G_OBJECT(notification), "contact", contact);
	g_object_set_data (G_OBJECT(notification), "conv", conv);
	g_object_set_data (G_OBJECT(notification), "buddy", buddy);

	g_signal_connect (notification, "closed", G_CALLBACK(closed_cb), NULL);

	notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);

	notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);

	notify_notification_set_timeout(notification, purple_prefs_get_int("/plugins/gtk/libnotify/timeout"));
	if (!notify_notification_show (notification, NULL)) {
		purple_debug_error (PLUGIN_ID, "notify(), failed to send notification\n");
	}

}
コード例 #30
0
ファイル: empathy-status-icon.c プロジェクト: mirsal/empathy
static void
status_icon_update_notification (EmpathyStatusIcon *icon)
{
	EmpathyStatusIconPriv *priv = GET_PRIV (icon);
	GdkPixbuf *pixbuf = NULL;

	if (!empathy_notify_manager_notification_is_enabled (priv->notify_mgr)) {
		/* always close the notification if this happens */
		notification_close_helper (priv);
		return;
	}

	if (priv->event) {
		gchar *message_esc = NULL;
		gboolean has_x_canonical_append;
		NotifyNotification *notification = priv->notification;

		if (priv->event->message != NULL)
			message_esc = g_markup_escape_text (priv->event->message, -1);

		has_x_canonical_append =
				empathy_notify_manager_has_capability (priv->notify_mgr,
					EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND);

		if (notification != NULL && ! has_x_canonical_append) {
			/* if the notification server supports x-canonical-append, it is
			   better to not use notify_notification_update to avoid
			   overwriting the current notification message */
			notify_notification_update (notification,
						    priv->event->header, message_esc,
						    NULL);
		} else {
			/* if the notification server supports x-canonical-append,
			   the hint will be added, so that the message from the
			   just created notification will be automatically appended
			   to an existing notification with the same title.
			   In this way the previous message will not be lost: the new
			   message will appear below it, in the same notification */
			notification = notify_notification_new_with_status_icon
				(priv->event->header, message_esc, NULL, priv->icon);

			if (priv->notification == NULL) {
				priv->notification = notification;
			}

			notify_notification_set_timeout (notification,
							 NOTIFY_EXPIRES_DEFAULT);

			if (has_x_canonical_append) {
				notify_notification_set_hint_string (notification,
					EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "");
			}

			if (empathy_notify_manager_has_capability (priv->notify_mgr,
			           EMPATHY_NOTIFY_MANAGER_CAP_ACTIONS) &&
			           priv->event->type != EMPATHY_EVENT_TYPE_PRESENCE) {
				notify_notification_add_action (notification,
					"respond",
					_("Respond"),
					(NotifyActionCallback) notification_action_cb,
					icon,
					NULL);
			}

			g_signal_connect (notification, "closed",
					  G_CALLBACK (status_icon_notification_closed_cb), icon);
		}

		pixbuf = empathy_notify_manager_get_pixbuf_for_notification (
								   priv->notify_mgr, priv->event->contact,
								   priv->event->icon_name);

		if (pixbuf != NULL) {
			notify_notification_set_icon_from_pixbuf (notification, pixbuf);
			g_object_unref (pixbuf);
		}

		notify_notification_show (notification, NULL);

		g_free (message_esc);
	} else {
		notification_close_helper (priv);
	}
}