int 
main (int    argc,
      char** argv)
{
	NotifyNotification* notification;
	gboolean            success;
	GError*             error = NULL;

	if (!notify_init ("sync-icon-only"))
		return 1;

	/* call this so we can savely use has_cap(CAP_SOMETHING) later */
	init_caps ();

	/* show what's supported */
	print_caps ();

	/* try the sync. icon-only case */
	if (has_cap (CAP_LAYOUT_ICON_ONLY) &&
	    has_cap (CAP_SYNCHRONOUS))
	{
		notification = notify_notification_new (
					"Eject", /* for a11y-reasons put something meaningfull here */
					NULL,
					"notification-device-eject");
		notify_notification_set_hint_string (notification,
						     "x-canonical-private-icon-only",
						     "true");
		notify_notification_set_hint_string (notification,
						     "x-canonical-private-synchronous",
						     "true");
		error = NULL;
		success = notify_notification_show (notification, &error);
		if (!success)
		{
			g_print ("That did not work ... \"%s\".\n",
			         error->message);
			g_error_free (error);
		}

		g_signal_connect (G_OBJECT (notification),
				  "closed",
				  G_CALLBACK (closed_handler),
				  NULL);
	}
	else
	{
		g_print ("The daemon does not support the x-canonical-private-icon-only hint!\n");
		g_print ("The daemon does not support the x-canonical-private-synchronous hint!\n");
	}

	notify_uninit ();

	return 0;
}
void
notification_backend_show (const char *title, const char *text)
{
	NotifyNotification *notification;

	if (strip_markup)
		text = g_markup_escape_text (text, -1);

#if NOTIFY_CHECK_VERSION(0,7,0)
	notification = notify_notification_new (title, text, "hexchat");
#else
	notification = notify_notification_new (title, text, "hexchat", NULL);
#endif
#if NOTIFY_CHECK_VERSION(0,6,0)
	notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("hexchat"));
#else
	notify_notification_set_hint_string (notification, "desktop-entry", "hexchat");
#endif

	notify_notification_show (notification, NULL);

	g_object_unref (notification);
	if (strip_markup)
		g_free ((char*)text);
}
void
push_notification (gchar* title,
		   gchar* body,
		   gchar* icon)
{
	NotifyNotification* notification;
	gboolean            success;
	GError*             error = NULL;

	/* initial notification */
	notification = notify_notification_new (title, body, icon);
	notify_notification_set_hint_string (notification,
					     "x-canonical-append",
					     "true");
	error = NULL;
	success = notify_notification_show (notification, &error);
	if (!success)
	{
		g_print ("That did not work ... \"%s\".\n",
			 error->message);
		g_error_free (error);
	}

	g_signal_connect (G_OBJECT (notification),
			  "closed",
			  G_CALLBACK (closed_handler),
			  NULL);
	g_object_unref (G_OBJECT (notification));
	sleep (3); /* simulate a user typing */
}
 void setNotificationHints() {
     if (notification) {
         notify_notification_clear_hints(NOTIFY_NOTIFICATION(notification));
         
         if (!hints.isEmpty()) {
             QMapIterator<QString, QVariant> iterator(hints);
         
             while (iterator.hasNext()) {
                 iterator.next();
                 
                 switch (iterator.value().type()) {
                 case QVariant::Int:
                 case QVariant::Double:
                     notify_notification_set_hint_int32(NOTIFY_NOTIFICATION(notification), QGSTRING(iterator.key()),
                                                        iterator.value().toInt());
                     break;
                 default:
                     notify_notification_set_hint_string(NOTIFY_NOTIFICATION(notification), QGSTRING(iterator.key()),
                                                         QGSTRING(iterator.value().toString()));
                     break;
                 }
             }
         }
     }
 }
Beispiel #5
0
Datei: main.c Projekt: hluk/red
void notifyInit(NotifyNotification **notification)
{
    notify_init("Red");
    *notification = notify_notification_new("Red", NULL, NULL);
    notify_notification_set_timeout(*notification, NOTIFY_TIMEOUT_MSEC);
    notify_notification_set_hint_string(*notification, "x-canonical-private-synchronous", "");
}
Beispiel #6
0
static void
add_notify (char *summary, char *message)
{
	NotifyNotification *notify = NULL;
	GError *error = NULL;
	gchar *escaped;

	escaped = g_markup_escape_text (message, strlen(message));
	notify = notify_notification_new (summary, escaped, NULL);

	notify_notification_set_urgency (notify, NOTIFY_URGENCY_NORMAL);
	notify_notification_set_icon_from_pixbuf (notify, notify_icon);

	if (notify_manager_has_capability ("x-canonical-append"))
		notify_notification_set_hint_string(notify, "x-canonical-append", "");

	if (!notify_notification_show (notify, &error)) {
		g_warning (_("Failed to send notification: %s\n"), error->message);
		g_error_free (error);
		return;
	}

	notifications = g_slist_prepend (notifications, notify);

	g_free (escaped);
}
Beispiel #7
0
static gboolean
notify_notification_set_hint_variant (NotifyNotification *notification,
                                      const char         *type,
                                      const char         *key,
                                      const char         *value,
                                      GError            **error)
{
        static gboolean conv_error = FALSE;
        if (!strcasecmp (type, "string")) {
                notify_notification_set_hint_string (notification,
                                                     key,
                                                     value);
        } else if (!strcasecmp (type, "int")) {
                if (!g_ascii_isdigit (*value))
                        conv_error = TRUE;
                else {
                        gint h_int = (gint) g_ascii_strtoull (value, NULL, 10);
                        notify_notification_set_hint_int32 (notification,
                                                            key,
                                                            h_int);
                }
        } else if (!strcasecmp (type, "double")) {
                if (!g_ascii_isdigit (*value))
                        conv_error = TRUE;
                else {
                        gdouble h_double = g_strtod (value, NULL);
                        notify_notification_set_hint_double (notification,
                                                             key, h_double);
                }
        } else if (!strcasecmp (type, "byte")) {
                gint h_byte = (gint) g_ascii_strtoull (value, NULL, 10);

                if (h_byte < 0 || h_byte > 0xFF)
                        conv_error = TRUE;
                else {
                        notify_notification_set_hint_byte (notification,
                                                           key,
                                                           (guchar) h_byte);
                }
        } else {
                *error = g_error_new (G_OPTION_ERROR,
                                      G_OPTION_ERROR_BAD_VALUE,
                                      N_("Invalid hint type \"%s\". Valid types "
                                         "are int, double, string and byte."),
                                      type);
                return FALSE;
        }

        if (conv_error) {
                *error = g_error_new (G_OPTION_ERROR,
                                      G_OPTION_ERROR_BAD_VALUE,
                                      N_("Value \"%s\" of hint \"%s\" could not be "
                                         "parsed as type \"%s\"."), value, key,
                                      type);
                return FALSE;
        }

        return TRUE;
}
static gboolean notification_trayicon_popup_add_msg(MsgInfo *msginfo,
						    NotificationFolderType nftype)
{
  gchar *summary;
  gchar *utf8_str;
  gboolean retval;
  GdkPixbuf *pixbuf;

  g_return_val_if_fail(msginfo, FALSE);

  if(!popup.notification)
    return notification_trayicon_popup_create(msginfo,nftype);

  /* Count messages */
  notification_trayicon_popup_count_msgs(nftype);

  if(popup.msg_path) {
    g_free(popup.msg_path);
    popup.msg_path = NULL;
  }

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

  /* make sure we show a logo on many msg arrival */
  pixbuf = notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64);
  if(pixbuf)
    notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf);

  retval = notify_notification_update(popup.notification, summary,
				      utf8_str, NULL);
  g_free(summary);
  g_free(utf8_str);
  if(!retval) {
    debug_print("Notification Plugin: Failed to update notification.\n");
    return FALSE;
  }
  /* 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 updated notification: "
		"%s\n",	popup.error->message);
    g_clear_error(&(popup.error));
    return FALSE;
  }

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

  return TRUE;
}
Beispiel #9
0
    int
notify_hints_type(ErlNifEnv *env, NotifyNotification *notify, int arity, ERL_NIF_TERM key, ERL_NIF_TERM value)
{
    char a_key[256] = {0};

    union {
        ErlNifBinary b;
        int i;
        double d;
    } val;

    const ERL_NIF_TERM *byte = NULL;
    char a_byte[256] = {0};
    int len = 0;

    if (!enif_get_atom(env, key, a_key, sizeof(a_key), ERL_NIF_LATIN1))
        return -1;

    if (enif_get_int(env, value, &val.i))
        notify_notification_set_hint_int32(notify, a_key, val.i);
    else if (enif_get_double(env, value, &val.d))
        notify_notification_set_hint_double(notify, a_key, val.d);
    else if (enif_get_tuple(env, value, &len, &byte)) {
        if (len != 2 ||
                !enif_get_atom(env, byte[0], a_byte, sizeof(a_byte), ERL_NIF_LATIN1) ||
                (strcmp(a_byte, "byte") != 0) ||
                !enif_get_int(env, byte[1], &val.i))
            return -1;
        notify_notification_set_hint_byte(notify, a_key, (u_int8_t)val.i);
    }
    else if (arity == 0 || enif_inspect_iolist_as_binary(env, value, &val.b)) {
        gchar *tmpstr = NULL;

        if (arity > 0)
            tmpstr = stralloc(&val.b);

        notify_notification_set_hint_string(notify, a_key,
                (arity > 0 ? "" : tmpstr));

        strfree(tmpstr);
    }
    else
        return -1;

    return 0;
}
Beispiel #10
0
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;
}
Beispiel #11
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);
        }
    }
}
Beispiel #12
0
void 
xvd_notify_notification(XvdInstance *Inst, 
						gchar* icon, 
						gint value)
{
	GError* error						= NULL;
	gchar*  title						= NULL;

	if ((icon != NULL) && (g_strcmp0(icon, "audio-volume-muted") == 0)) {
		// TRANSLATORS: this is the body of the ATK interface of the volume notifications. This is the case when volume is muted
		title = g_strdup ("Volume is muted");
	}
	else {
		// TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug.
		title = g_strdup_printf ("Volume is at %d%c", value, '%');
	}
	
	notify_notification_update (Inst->notification,
				title,
				NULL,
				icon);
	
	g_free (title);
	
	if (Inst->gauge_notifications) {
		notify_notification_set_hint_int32 (Inst->notification,
							"value",
							value);
		notify_notification_set_hint_string (Inst->notification,
							 "x-canonical-private-synchronous",
							 "");
	}
	
	if (!notify_notification_show (Inst->notification, &error))
	{
		g_warning ("Error while sending notification : %s\n", error->message);
		g_error_free (error);
	}
}
Beispiel #13
0
static void
send_synchronous (const char *type,
		  const char *icon,
		  gint value)
{
        static NotifyNotification *n = NULL;

	if (n == NULL)
		n = notify_notification_new (" ",
					     "",
					     g_strdup (icon),
					     NULL);
	else
		notify_notification_update (n,
					    " ",
					    "",
					    g_strdup (icon));
		
	notify_notification_set_hint_int32(n, "value", value);
	notify_notification_set_hint_string(n, "x-canonical-private-synchronous", g_strdup (type));

	notify_notification_show (n, NULL);
}
    int
notify_hints_type(ErlNifEnv *env, NotifyNotification *notify, int arity, ERL_NIF_TERM key, ERL_NIF_TERM value)
{
    char s_key[1024] = {0};

    char s_value[1024] = {0};
    int i_value = 0;
    double d_value = 0;

    const ERL_NIF_TERM *byte = NULL;
    char s_byte[256] = {0};
    int len = 0;


    if (!enif_get_string(env, key, s_key, sizeof(s_key), ERL_NIF_LATIN1))
        return -1;

    if (enif_get_int(env, value, &i_value))
        notify_notification_set_hint_int32(notify, s_key, (value == atom_undefined ? 0 : i_value));
    else if (enif_get_double(env, value, &d_value))
        notify_notification_set_hint_double(notify, s_key, (value == atom_undefined ? 0 : d_value));
    else if (enif_get_tuple(env, value, &len, &byte)) {
        if ( (len != 2) ||
                !enif_get_atom(env, byte[0], s_byte, sizeof(s_byte), ERL_NIF_LATIN1) || 
                (strcmp(s_byte, "byte") != 0) ||
                !enif_get_int(env, byte[1], &i_value))
            return -1;
        notify_notification_set_hint_byte(notify, s_key, (value == atom_undefined ? 0 : (u_int8_t)i_value));
    }
    else if ((arity == 0) || enif_get_string(env, value, s_value, sizeof(s_value), ERL_NIF_LATIN1))
        notify_notification_set_hint_string(notify, s_key, (value == atom_undefined ? "" : s_value));
    else
        return -1;

    return 0;
}
Beispiel #15
0
static gboolean notification_libnotify_create(MsgInfo *msginfo,
					      NotificationFolderType nftype)
{
  GdkPixbuf *pixbuf;
  NotificationPopup *ppopup;
  gchar *summary = NULL;
  gchar *text = NULL;
  gchar *utf8_str = NULL;
  gchar *subj = NULL;
  gchar *from = NULL;
  gchar *foldname = NULL;
  GList *caps = NULL;
  gboolean support_actions = FALSE;

  g_return_val_if_fail(msginfo, FALSE);

  ppopup = &(popup[nftype]);

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

  switch(nftype) {
  case F_TYPE_MAIL:
    summary = _("New Mail message");
    from    = notification_libnotify_sanitize_str(msginfo->from ?
                                                  msginfo->from : _("(No From)"));
    subj    = notification_libnotify_sanitize_str(msginfo->subject ?
                                                  msginfo->subject : _("(No Subject)"));
	if (notify_config.popup_display_folder_name) {
		foldname = notification_libnotify_sanitize_str(msginfo->folder->path);
    	text = g_strconcat(from,"\n\n", subj, "\n\n", foldname, NULL);
	}
	else
		text = g_strconcat(from, "\n\n",subj, NULL);

    /* Make sure text is valid UTF8 */
    utf8_str = notification_validate_utf8_str(text);
    g_free(text);

    if(from) g_free(from);
    if(subj) g_free(subj);
    if(foldname) g_free(foldname);
    break;
  case F_TYPE_NEWS:
    summary = _("New News post");
    utf8_str    = g_strdup(_("A new message arrived"));
    break;
  case F_TYPE_CALENDAR:
    summary = _("New Calendar message");
    utf8_str    = g_strdup(_("A new calendar message arrived"));
    break;
  case F_TYPE_RSS:
    summary = _("New RSS feed article");
    utf8_str = g_strdup(_("A new article in a RSS feed arrived"));
    break;
  default:
    summary = _("New unknown message");
    utf8_str = g_strdup(_("Unknown message type arrived"));
    break;
  }

  ppopup->notification = notify_notification_new(summary, utf8_str, NULL
#if !NOTIFY_CHECK_VERSION(0, 7, 0)
      , NULL
#endif
      );
  g_free(utf8_str);
  if(ppopup->notification == NULL) {
    debug_print("Notification Plugin: Failed to create a new "
		"notification.\n");
    return FALSE;
  }

  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(ppopup->notification,
				   "default", _("Present main window"),
				   (NotifyActionCallback)default_action_cb,
				   GINT_TO_POINTER(nftype),
				   notification_libnotify_free_func);

  /* Icon */
  pixbuf = NULL;
#ifndef USE_ALT_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(ppopup->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(ppopup->notification, notify_config.popup_timeout);

  /* Category */
  notify_notification_set_category(ppopup->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(ppopup->notification, "desktop-entry", "claws-mail");
  if(!notify_notification_show(ppopup->notification, &(ppopup->error))) {
    debug_print("Notification Plugin: Failed to send notification: %s\n",
		ppopup->error->message);
    g_clear_error(&(ppopup->error));
    g_object_unref(G_OBJECT(ppopup->notification));
    ppopup->notification = NULL;
    return FALSE;
  }

  debug_print("Notification Plugin: Popup created with libnotify.\n");
  ppopup->count = 1;

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

  return TRUE;
}
Beispiel #16
0
static gboolean notification_libnotify_add_msg(MsgInfo *msginfo,
					       NotificationFolderType nftype)
{
  gchar *summary;
  gchar *text;
  gboolean retval;
  NotificationPopup *ppopup;
  GdkPixbuf *pixbuf;

  ppopup = &(popup[nftype]);

  if(!ppopup->notification)
    return notification_libnotify_create(msginfo,nftype);

  ppopup->count++;

  if(ppopup->msg_path) {
    g_free(ppopup->msg_path);
    ppopup->msg_path = NULL;
  }

  /* make sure we show a logo on many msg arrival */
  pixbuf = notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64);
  if(pixbuf)
    notify_notification_set_icon_from_pixbuf(ppopup->notification, pixbuf);

  switch(nftype) {
  case F_TYPE_MAIL:
    summary = _("Mail message");
    text = g_strdup_printf(ngettext("%d new message arrived",
				    "%d new messages arrived",
				    ppopup->count), ppopup->count);
    break;
  case F_TYPE_NEWS:
    summary = _("News message");
    text = g_strdup_printf(ngettext("%d new message arrived",
                                     "%d new messages arrived",
				     ppopup->count), ppopup->count);
    break;
  case F_TYPE_CALENDAR:
    summary = _("Calendar message");
    text = g_strdup_printf(ngettext("%d new calendar message arrived",
                                     "%d new calendar messages arrived",
				     ppopup->count), ppopup->count);
    break;
  case F_TYPE_RSS:
    summary = _("RSS news feed");
    text = g_strdup_printf(ngettext("%d new article in a RSS feed arrived",
                                     "%d new articles in a RSS feed arrived",
				     ppopup->count), ppopup->count);
    break;
  default:
    /* Should not happen */
    debug_print("Notification Plugin: Unknown folder type ignored\n");
    return FALSE;
  }

  retval = notify_notification_update(ppopup->notification, summary,
				      text, NULL);
  g_free(text);
  if(!retval) {
    debug_print("Notification Plugin: Failed to update notification.\n");
    return FALSE;
  }

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

  debug_print("Notification Plugin: Popup successfully modified "
	      "with libnotify.\n");
  return TRUE;
}
Beispiel #17
0
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);
	}
}
Beispiel #18
0
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");
}
Beispiel #19
0
int main(int argc, char **argv)
{
	pa_glib_mainloop *mainloop;
	pa_mainloop_api *mainloop_api;
	pa_context *context;
	GdkWindow *root;
	int status = EXIT_SUCCESS;
	int i;

	gtk_init(&argc, &argv);

	mainloop = pa_glib_mainloop_new(NULL);
	if (!mainloop) {
		fprintf(stderr, "pa_glib_mainloop_new() failed\n");
		status = EXIT_FAILURE;
		goto out;
	}

	mainloop_api = pa_glib_mainloop_get_api(mainloop);

	if (pa_signal_init(mainloop_api) < 0) {
		fprintf(stderr, "pa_signal_init() failed\n");
		status = EXIT_FAILURE;
		goto mainloop_free;
	}
	pa_signal_new(SIGINT, exit_signal_callback, NULL);
	pa_signal_new(SIGTERM, exit_signal_callback, NULL);

	context = pa_context_new(mainloop_api, NULL);
	if (!context) {
		fprintf(stderr, "pa_context_new() failed\n");
		status = EXIT_FAILURE;
		goto mainloop_free;
	}

	pa_context_set_state_callback(context, context_state_callback, NULL);
	if (pa_context_connect(context, NULL, 0, NULL) < 0) {
		fprintf(stderr, "pa_context_connect() failed: %s\n",
			pa_strerror(pa_context_errno(context)));
		status = EXIT_FAILURE;
		goto context_unref;
	}

	if (!notify_init(APP_NAME)) {
		fprintf(stderr, "Could not initialize libnotify\n");
		status = EXIT_FAILURE;
		goto context_unref;
	}

	notification = notify_notification_new(APP_NAME, NULL, NULL);
	if (!notification) {
		fprintf(stderr, "notify_notification_new() failed\n");
		status = EXIT_FAILURE;
		goto notify_uninit;
	}

	notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT);
	notify_notification_set_hint_string(notification, "synchronous", "volume");

	root = gdk_get_default_root_window();

	gdk_window_set_events(root, GDK_KEY_PRESS_MASK);
	gdk_window_add_filter(root, filter, context);

	for (i = 0; i < sizeof(keysyms) / sizeof(keysyms[0]); i++) {
		keycodes[i] = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(root), keysyms[i]);
		if (!keycodes[i]) {
			fprintf(stderr, "%s is not mapped on this keyboard\n",
				XKeysymToString(keysyms[i]));
			continue;
		}
		XGrabKey(GDK_WINDOW_XDISPLAY(root), keycodes[i], AnyModifier,
			 GDK_WINDOW_XID(root), False, GrabModeAsync,
			 GrabModeAsync);
	}

	gtk_main();

	g_object_unref(G_OBJECT(notification));
notify_uninit:
	notify_uninit();
context_unref:
	pa_context_unref(context);
mainloop_free:
	pa_glib_mainloop_free(mainloop);
out:
	return status;
}
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;
}