static void
notify_plus_adapt_to_server_capabilities()
{
	GList *capabilities;
	GList *capability;

	notify_plus_data.modify_notification = TRUE;
	notify_plus_data.use_svg = FALSE;
	notify_plus_data.overlay_icon = TRUE;
	notify_plus_data.set_transcient = FALSE;
	notify_plus_data.actions = FALSE;

	capabilities = notify_get_server_caps();
	for ( capability = capabilities ; capability != NULL ; capability = g_list_next(capability) )
	{
		gchar *cap_name = capability->data;

		if ( g_strcmp0(cap_name, "persistence") == 0 )
			notify_plus_data.set_transcient = TRUE;
		else if ( g_strcmp0(cap_name, "image/svg+xml") == 0 )
			notify_plus_data.use_svg = TRUE;
		else if ( g_strcmp0(cap_name, "x-eventd-overlay-icon") == 0 )
			notify_plus_data.overlay_icon = FALSE;
		else if ( g_strcmp0(cap_name, "x-canonical-append") == 0 )
			notify_plus_data.modify_notification = FALSE;
		else if ( g_strcmp0(cap_name, "actions") == 0 )
			notify_plus_data.actions = TRUE;

		g_free(cap_name);
	}

	g_list_free(capabilities);
}
void
ring_notify_init()
{
#if USE_LIBNOTIFY
    notify_init("Ring");

    /* get notify server info */
    if (notify_get_server_info(&server_info.name,
                               &server_info.vendor,
                               &server_info.version,
                               &server_info.spec)) {
        g_debug("notify server name: %s, vendor: %s, version: %s, spec: %s",
                server_info.name, server_info.vendor, server_info.version, server_info.spec);
    }

    /* check  notify server capabilities */
    auto list = notify_get_server_caps();
    while (list) {
        if (g_strcmp0((const char *)list->data, "append") == 0 ||
            g_strcmp0((const char *)list->data, "x-canonical-append") == 0) {
            server_info.append = TRUE;
        }
        if (g_strcmp0((const char *)list->data, "actions") == 0) {
            server_info.actions = TRUE;
        }

        list = g_list_next(list);
    }

    g_list_free_full(list, g_free);
#endif
}
int
main (int argc, char **argv)
{
        GList          *l, *caps;
        char           *name, *vendor, *version, *spec_version;

        notify_init ("TestCaps");

        if (!notify_get_server_info (&name, &vendor, &version, &spec_version)) {
                fprintf (stderr, "Failed to receive server info.\n");
                exit (1);
        }

        printf ("Name:         %s\n", name);
        printf ("Vendor:       %s\n", vendor);
        printf ("Version:      %s\n", version);
        printf ("Spec Version: %s\n", spec_version);
        printf ("Capabilities:\n");

        caps = notify_get_server_caps ();

        if (caps == NULL) {
                fprintf (stderr, "Failed to receive server caps.\n");
                exit (1);
        }

        for (l = caps; l != NULL; l = l->next)
                printf ("\t%s\n", (char *) l->data);

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

        return 0;
}
static void
empathy_notify_manager_init (EmpathyNotifyManager *self)
{
  EmpathyNotifyManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
    EMPATHY_TYPE_NOTIFY_MANAGER, EmpathyNotifyManagerPriv);
  GList *list, *l;

  self->priv = priv;

  priv->capabilities = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
      NULL);

  /* fetch capabilities */
  list = notify_get_server_caps ();
  for (l = list; l != NULL; l = g_list_next (l))
    {
      gchar *cap = l->data;

      DEBUG ("add capability: %s", cap);
      /* owernship of the string is transfered to the hash table */
      g_hash_table_insert (priv->capabilities, cap, GUINT_TO_POINTER (TRUE));
    }
  g_list_free (list);

  priv->account_manager = tp_account_manager_dup ();

  tp_account_manager_prepare_async (priv->account_manager, NULL,
      account_manager_prepared_cb, self);
}
Пример #5
0
int main() {
  GList *caps;
  notify_init("cap dumper");
  caps=notify_get_server_caps();
  if(caps) {
    g_list_foreach(caps, (GFunc)PrintString, NULL);
    g_list_foreach(caps, (GFunc)g_free, NULL);
    g_list_free(caps);
  }
  notify_uninit();
}
Пример #6
0
static gboolean
notify_manager_has_capability (const gchar *cap)
{                                                     
	gboolean ret;
	GList *list = NULL;

	list  =  notify_get_server_caps ();
	ret = ( g_list_find_custom ( list, cap, notify_str_equal) != NULL );

	g_list_free_full ( list, g_free);

	return ret;
}
Пример #7
0
gboolean notification_supports_actions (void)
{
	gboolean supports_actions = FALSE;
	GList *caps = NULL;

	caps = notify_get_server_caps ();
	if (g_list_find_custom(caps, "actions", (GCompareFunc)g_strcmp0) != NULL)
		supports_actions = TRUE;

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

	return supports_actions;
}
bool NotificationBackendLibnotify::init()
{
    bindtextdomain (GETTEXT_PACKAGE, SYNCEVOLUTION_LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

#ifdef NOTIFY_COMPATIBILITY
    void *dlhandle = NULL;
    int i;
    for (i = 1; i <= 4; i++) {
        dlhandle = dlopen(StringPrintf("libnotify.so.%d", i).c_str(), RTLD_LAZY|RTLD_GLOBAL);
        if (!dlhandle) {
            SE_LOG_DEBUG(NULL, NULL, "failed to load libnotify.so.%d: %s", i, dlerror());
        } else {
            break;
        }
    }
    if (!dlhandle) {
        return false;
    }

#define LOOKUP(_x) ((_x = reinterpret_cast<typeof(_x)>(dlsym(dlhandle, #_x))) || \
                    NotFound(#_x))

    if (!LOOKUP(notify_init) ||
        !LOOKUP(notify_get_server_caps) ||
        !LOOKUP(notify_notification_new) ||
        !LOOKUP(notify_notification_add_action) ||
        !LOOKUP(notify_notification_clear_actions) ||
        !LOOKUP(notify_notification_close) ||
        !LOOKUP(notify_notification_show)) {
        return false;
    }
    SE_LOG_DEBUG(NULL, NULL, "using libnotify.so.%d", i);
#endif

    m_initialized = notify_init("SyncEvolution");
    if(m_initialized) {
        GStringListFreeCXX list(notify_get_server_caps());
        BOOST_FOREACH (const char *cap, list) {
            if(boost::iequals(cap, "actions")) {
                m_acceptsActions = true;
            }
        }
        return true;
    }

    return false;
}
Пример #9
0
int
notification_backend_init (void)
{
	GList* server_caps;

	if (!notify_init (PACKAGE_NAME))
		return 0;

	server_caps = notify_get_server_caps ();
	if (g_list_find_custom (server_caps, "body-markup", (GCompareFunc)g_strcmp0))
		strip_markup = TRUE;
	g_list_free_full (server_caps, g_free);

	return 1;
}
static gboolean
server_has_persistence (void)
{
        gboolean retval;
        GList *caps, *l;

        caps = notify_get_server_caps ();
        if (caps == NULL) {
                return FALSE;
        }

        l = g_list_find_custom (caps, "persistence", (GCompareFunc) g_strcmp0);
        retval = (l != NULL);

	g_list_free_full (caps, g_free);

        return retval;
}
Пример #11
0
/*****************************************************************************
 * Open: initialize and create stuff
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t   *p_intf = (intf_thread_t *)p_this;
    intf_sys_t      *p_sys  = malloc( sizeof( *p_sys ) );

    if( !p_sys )
        return VLC_ENOMEM;

    if( !notify_init( APPLICATION_NAME ) )
    {
        free( p_sys );
        msg_Err( p_intf, "can't find notification daemon" );
        return VLC_EGENERIC;
    }
    p_intf->p_sys = p_sys;

    vlc_mutex_init( &p_sys->lock );
    p_sys->notification = NULL;
    p_sys->b_has_actions = false;

    GList *p_caps = notify_get_server_caps ();
    if( p_caps )
    {
        for( GList *c = p_caps; c != NULL; c = c->next )
        {
            if( !strcmp( (char*)c->data, "actions" ) )
            {
                p_sys->b_has_actions = true;
                break;
            }
        }
        g_list_foreach( p_caps, (GFunc)g_free, NULL );
        g_list_free( p_caps );
    }

    /* */
    playlist_t *p_playlist = pl_Hold( p_intf );
    var_AddCallback( p_playlist, "item-current", ItemChange, p_intf );
    pl_Release( p_intf );

    return VLC_SUCCESS;
}
static gboolean
server_has_actions (void)
{
        gboolean has;
        GList   *caps;
        GList   *l;

        caps = notify_get_server_caps ();
        if (caps == NULL) {
                fprintf (stderr, "Failed to receive server caps.\n");
                return FALSE;
        }

        l = g_list_find_custom (caps, "actions", (GCompareFunc)strcmp);
        has = l != NULL;

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

        return has;
}
Пример #13
0
static gboolean
notification_server_supports_actions (void)
{
	GList * caps = notify_get_server_caps ();
	GList * l;
	gboolean ret = FALSE;

	for (l = caps; l; l = l->next) {
		gchar *cap = (gchar *) l->data;
		if (!cap) {
			continue;
		}
		if (!strcmp (cap, "actions")) {
			ret = TRUE;
			break;
		}
	}
	g_list_foreach (caps, (GFunc)g_free, NULL);
	g_list_free (caps);

	return ret;
}
Пример #14
0
void 
xvd_notify_init(XvdInstance *Inst, 
				const gchar *appname)
{
	GList *caps_list = NULL;

	Inst->gauge_notifications = TRUE;
	notify_init (appname);
	
	caps_list = notify_get_server_caps ();
	
	if (caps_list)
	{
		GList *node;

		node = g_list_find_custom (caps_list, LAYOUT_ICON_ONLY, (GCompareFunc) g_strcmp0);
		if (!node)
			Inst->gauge_notifications = FALSE;
		
/*		node = g_list_find_custom (caps_list, SYNCHRONOUS, (GCompareFunc) g_strcmp0);*/
/*		if (!node)*/
/*			Inst->gauge_notifications = FALSE;*/
		
		g_list_free (caps_list);
	}
	
#ifdef NOTIFY_CHECK_VERSION
#if NOTIFY_CHECK_VERSION (0, 7, 0)
	Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL);
#else
	Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
#endif
#else
	Inst->notification = notify_notification_new ("Xfce4-Volumed", NULL, NULL, NULL);
#endif
}
Пример #15
0
static gboolean
notif_libnotify_init (void)
{
	GList *caps;

	/* Check whether the notification daemon supports actions, per Actions
	   in http://www.galago-project.org/specs/notification/0.9/x81.html */
	if (notify_init ("liferea")) {
		caps = notify_get_server_caps ();

		if (g_list_find_custom (caps, "actions", (GCompareFunc) strcmp))
			supports_actions = TRUE;
		if (g_list_find_custom (caps, "append", (GCompareFunc) strcmp))
			supports_append = TRUE;

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

		return TRUE;
	} else {
		debug0 (DEBUG_GUI, "libnotify.c: notify_init returned FALSE");
		return FALSE;
	}
}
Пример #16
0
DejaDupShellEnv deja_dup_get_shell (void) {
	DejaDupShellEnv result = 0;
	DejaDupShellEnv _tmp0_;
	DejaDupShellEnv _tmp10_;
	_tmp0_ = deja_dup_shell;
	if (_tmp0_ == DEJA_DUP_SHELL_ENV_NONE) {
		{
			GList* _tmp1_ = NULL;
			GList* caps;
			gboolean persistence;
			gboolean actions;
			GList* _tmp2_;
			gboolean _tmp6_ = FALSE;
			gboolean _tmp7_;
			gboolean _tmp9_;
			_tmp1_ = notify_get_server_caps ();
			caps = _tmp1_;
			persistence = FALSE;
			actions = FALSE;
			_tmp2_ = caps;
			{
				GList* cap_collection = NULL;
				GList* cap_it = NULL;
				cap_collection = _tmp2_;
				for (cap_it = cap_collection; cap_it != NULL; cap_it = cap_it->next) {
					gchar* _tmp3_;
					gchar* cap = NULL;
					_tmp3_ = g_strdup ((const gchar*) cap_it->data);
					cap = _tmp3_;
					{
						const gchar* _tmp4_;
						_tmp4_ = cap;
						if (g_strcmp0 (_tmp4_, "persistence") == 0) {
							persistence = TRUE;
						} else {
							const gchar* _tmp5_;
							_tmp5_ = cap;
							if (g_strcmp0 (_tmp5_, "actions") == 0) {
								actions = TRUE;
							}
						}
						_g_free0 (cap);
					}
				}
			}
			_tmp7_ = persistence;
			if (_tmp7_) {
				gboolean _tmp8_;
				_tmp8_ = actions;
				_tmp6_ = _tmp8_;
			} else {
				_tmp6_ = FALSE;
			}
			_tmp9_ = _tmp6_;
			if (_tmp9_) {
				deja_dup_shell = DEJA_DUP_SHELL_ENV_GNOME;
			} else {
				deja_dup_shell = DEJA_DUP_SHELL_ENV_LEGACY;
			}
		}
	}
	_tmp10_ = deja_dup_shell;
	result = _tmp10_;
	return result;
}
Пример #17
0
void
fe_tray_set_balloon (const char *title, const char *text)
{
#ifndef WIN32
#if 0
	const char *argv[8];
	const char *path;
	char time[16];
#endif
	WinStatus ws;

	/* no balloons if the window is focused */
	ws = tray_get_window_status ();
	if ((prefs.hex_away_omit_alerts && hexchat_get_info(ph, "away")) ||
		(prefs.hex_gui_focus_omitalerts && ws == WS_FOCUSED))
		return;

	/* bit 1 of flags means "no balloons unless hidden/iconified" */
	if (ws != WS_HIDDEN && prefs.hex_gui_tray_quiet)
		return;

	/* FIXME: this should close the current balloon */
	if (!text)
		return;

#ifdef USE_LIBNOTIFY
	static int notify_text_strip_flags = STRIP_ALL;
	NotifyNotification *notification;
	char *notify_text, *notify_title;

	if (!notify_is_initted())
	{
		notify_init(PACKAGE_NAME);

		GList* server_caps = notify_get_server_caps ();
		if (g_list_find_custom (server_caps, "body-markup", (GCompareFunc)strcmp))
		{
			notify_text_strip_flags |= STRIP_ESCMARKUP;
		}
		g_list_free_full (server_caps, g_free);
	}

	notify_text = strip_color (text, -1, notify_text_strip_flags);
	notify_title = strip_color (title, -1, STRIP_ALL);

	notification = XC_NOTIFY_NEW (notify_title, notify_text, HEXCHATSHAREDIR "/icons/hicolor/scalable/apps/hexchat.svg", NULL);

#if NOTIFY_CHECK_VERSION(0,7,0)
	notify_notification_set_hint (notification, "desktop-entry", g_variant_new_string ("hexchat"));
#endif

	g_free ((char *)notify_title);
	g_free ((char *)notify_text);

	notify_notification_set_timeout (notification, prefs.hex_input_balloon_time*1000);
	notify_notification_show (notification, NULL);

	g_object_unref (notification);
#endif
#endif
}
Пример #18
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;
}
Пример #19
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;
}
nsresult
nsAlertsIconListener::InitAlertAsync(const nsAString & aImageUrl,
                                     const nsAString & aAlertTitle, 
                                     const nsAString & aAlertText,
                                     bool aAlertTextClickable,
                                     const nsAString & aAlertCookie,
                                     nsIObserver * aAlertListener)
{
  if (!notify_is_initted()) {
    // Give the name of this application to libnotify
    nsCOMPtr<nsIStringBundleService> bundleService = 
      do_GetService(NS_STRINGBUNDLE_CONTRACTID);

    nsCAutoString appShortName;
    if (bundleService) {
      nsCOMPtr<nsIStringBundle> bundle;
      bundleService->CreateBundle("chrome://branding/locale/brand.properties",
                                  getter_AddRefs(bundle));
      nsAutoString appName;

      if (bundle) {
        bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
                                  getter_Copies(appName));
        appShortName = NS_ConvertUTF16toUTF8(appName);
      } else {
        NS_WARNING("brand.properties not present, using default application name");
        appShortName.AssignLiteral("Mozilla");
      }
    } else {
      appShortName.AssignLiteral("Mozilla");
    }

    if (!notify_init(appShortName.get()))
      return NS_ERROR_FAILURE;

    GList *server_caps = notify_get_server_caps();
    if (server_caps) {
      for (GList* cap = server_caps; cap != NULL; cap = cap->next) {
        if (!strcmp((char*) cap->data, "actions")) {
          gHasActions = true;
          break;
        }
      }
      g_list_foreach(server_caps, (GFunc)g_free, NULL);
      g_list_free(server_caps);
    }
  }

  if (!gHasActions && aAlertTextClickable)
    return NS_ERROR_FAILURE; // No good, fallback to XUL

  nsCOMPtr<nsIObserverService> obsServ =
      do_GetService("@mozilla.org/observer-service;1");
  if (obsServ)
    obsServ->AddObserver(this, "quit-application", true);

  // Workaround for a libnotify bug - blank titles aren't dealt with
  // properly so we use a space
  if (aAlertTitle.IsEmpty()) {
    mAlertTitle = NS_LITERAL_CSTRING(" ");
  } else {
    mAlertTitle = NS_ConvertUTF16toUTF8(aAlertTitle);
  }

  mAlertText = NS_ConvertUTF16toUTF8(aAlertText);
  mAlertHasAction = aAlertTextClickable;

  mAlertListener = aAlertListener;
  mAlertCookie = aAlertCookie;

  return StartRequest(aImageUrl);
}
Пример #21
0
static void
do_notify (RBNotificationPlugin *plugin,
	   guint timeout,
	   const char *primary,
	   const char *secondary,
	   const char *image_uri,
	   gboolean playback)
{
	GError *error = NULL;
	NotifyNotification *notification;

	if (notify_is_initted () == FALSE) {
		GList *caps;

		if (notify_init ("Rhythmbox") == FALSE) {
			g_warning ("libnotify initialization failed");
			return;
		}

		/* ask the notification server if it supports actions */
		caps = notify_get_server_caps ();
		if (g_list_find_custom (caps, "actions", (GCompareFunc)g_strcmp0) != NULL) {
			rb_debug ("notification server supports actions");
			plugin->notify_supports_actions = TRUE;

			if (g_list_find_custom (caps, "action-icons", (GCompareFunc)g_strcmp0) != NULL) {
				rb_debug ("notifiction server supports icon buttons");
				plugin->notify_supports_icon_buttons = TRUE;
			}
		} else {
			rb_debug ("notification server does not support actions");
		}
		if (g_list_find_custom (caps, "persistence", (GCompareFunc)g_strcmp0) != NULL) {
			rb_debug ("notification server supports persistence");
			plugin->notify_supports_persistence = TRUE;
		} else {
			rb_debug ("notification server does not support persistence");
		}

		rb_list_deep_free (caps);
	}

	if (primary == NULL)
		primary = "";

	if (secondary == NULL)
		secondary = "";

	if (playback) {
		notification = plugin->notification;
	} else {
		notification = plugin->misc_notification;
	}

	if (notification == NULL) {
		notification = notify_notification_new (primary, secondary, RB_APP_ICON);

		g_signal_connect_object (notification,
					 "closed",
					 G_CALLBACK (notification_closed_cb),
					 plugin, 0);
		if (playback) {
			plugin->notification = notification;
		} else {
			plugin->misc_notification = notification;
		}
	} else {
		notify_notification_clear_hints (notification);
		notify_notification_update (notification, primary, secondary, RB_APP_ICON);
	}

	notify_notification_set_timeout (notification, timeout);

	if (image_uri != NULL) {
		notify_notification_clear_hints (notification);
		notify_notification_set_hint (notification,
					      "image_path",
					      g_variant_new_string (image_uri));
	}

        if (playback)
        	notify_notification_set_category (notification, "x-gnome.music");
        notify_notification_set_hint (notification, "desktop-entry",
                                      g_variant_new_string ("rhythmbox"));

	notify_notification_clear_actions (notification);
	if (playback && plugin->notify_supports_actions) {
		gboolean rtl;
		const char *play_icon;

		rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
		play_icon = rtl ? "media-playback-start-rtl" : "media-playback-start";

		if (plugin->notify_supports_icon_buttons) {
			gboolean playing = FALSE;
			rb_shell_player_get_playing (plugin->shell_player, &playing, NULL);

			notify_notification_add_action (notification,
							rtl ? "media-skip-backward-rtl" : "media-skip-backward",
							_("Previous"),
							(NotifyActionCallback) notification_previous_cb,
							plugin,
							NULL);
			notify_notification_add_action (notification,
							playing ? "media-playback-pause" : play_icon,
							playing ? _("Pause") : _("Play"),
							(NotifyActionCallback) notification_playpause_cb,
							plugin,
							NULL);
			notify_notification_set_hint (notification, "action-icons", g_variant_new_boolean (TRUE));
		}

		notify_notification_add_action (notification,
						rtl ? "media-skip-forward-rtl" : "media-skip-forward",
						_("Next"),
						(NotifyActionCallback) notification_next_cb,
						plugin,
						NULL);
	}

	if (plugin->notify_supports_persistence) {
		const char *hint;

		if (playback) {
			hint = "resident";
		} else {
			hint = "transient";
		}
		notify_notification_set_hint (notification, hint, g_variant_new_boolean (TRUE));
	}

	if (notify_notification_show (notification, &error) == FALSE) {
		g_warning ("Failed to send notification (%s): %s", primary, error->message);
		g_error_free (error);
	}
}