static void _xfdashboard_applications_menu_model_fill_model(XfdashboardApplicationsMenuModel *self)
{
	XfdashboardApplicationsMenuModelPrivate		*priv;
	GError										*error;
	GarconMenuItemCache							*cache;
	XfdashboardApplicationsMenuModelFillData	fillData;

	g_return_if_fail(XFDASHBOARD_IS_APPLICATIONS_MENU_MODEL(self));

	priv=self->priv;
	error=NULL;

	/* Clear model data */
	_xfdashboard_applications_menu_model_clear(self);

	/* Clear garcon's menu item cache otherwise some items will not be loaded
	 * if this is a reload of the model or a second(, third, ...) instance of model
	 */
	cache=garcon_menu_item_cache_get_default();
	garcon_menu_item_cache_invalidate(cache);
	g_object_unref(cache);

	/* Load root menu */
	priv->rootMenu=garcon_menu_new_applications();
	if(garcon_menu_load(priv->rootMenu, NULL, &error)==FALSE)
	{
		g_warning(_("Could not load applications menu: %s"), error ? error->message : _("Unknown error"));
		if(error) g_error_free(error);
		g_object_unref(priv->rootMenu);
		priv->rootMenu=NULL;

		/* Emit "loaded" signal even if it fails */
		g_signal_emit(self, XfdashboardApplicationsMenuModelSignals[SIGNAL_LOADED], 0);
		return;
	}

	/* Iterate through menus recursively to add them to model */
	fillData.sequenceID=0;
	fillData.populatedMenus=NULL;
	_xfdashboard_applications_menu_model_fill_model_collect_menu(self, priv->rootMenu, NULL, &fillData);

	/* Emit signal */
	g_signal_emit(self, XfdashboardApplicationsMenuModelSignals[SIGNAL_LOADED], 0);
}
Пример #2
0
struct menugen_parser *menugen_parser_init(char *desktop, char *menufile) {
    if (desktop)
        garcon_set_environment(desktop);

    struct menugen_parser *result;

    GarconMenu *menu = menufile != NULL ? garcon_menu_new_for_path(menufile) : garcon_menu_new_applications();
    GError *error = NULL;

    if (!garcon_menu_load(menu, NULL, &error)) {
        printf("Error loading menu: %s\n", error->message);
        free(error);
        return NULL;
    }

    result = malloc(sizeof(struct menugen_parser));
    result->menu = menu;

    // compile regex
    for (int i = 0; i < REG_COUNT; ++i) {
        GError *error = NULL;
        struct regex_it *rit = (regex_items + i);
        GRegex *regex = g_regex_new(rit->pattern, 0, 0, &error);

        if (!regex) {
            printf("Error compiling regex (BUG) -> %s\n", error->message);
            g_error_free(error);
            exit(EXIT_FAILURE);
        }

        result->regex[i] = regex;
    }

    return result;

}