Ejemplo n.º 1
0
static int walk_menu(GarconMenuElement *element, struct menugen_parser *self, menugen_parser_cb callback, void *arg) {
    void *nextarg = NULL;
    int children = 0;

    if (ISMENU(element)) {

        GarconMenu* menu = (GarconMenu *)element;
        GarconMenuDirectory* directory = garcon_menu_get_directory(menu);
        GList *elements = garcon_menu_get_elements(menu);

        int visible = directory != NULL && garcon_menu_directory_get_visible(directory);
        int haschildred = elements != NULL && elements->data != NULL;

        if (visible && haschildred) {
            struct menu_item item = {
                .type = MENU,
                .name = garcon_menu_directory_get_name(directory),
                .icon = garcon_menu_directory_get_icon_name(directory)
            };
            nextarg = callback(&item, arg);
        }

        if (!nextarg)
            nextarg = arg;

        for (GList *el = elements; el != NULL; el = el->next) {
            GarconMenuElement *me = el->data;
            children += walk_menu(me, self, callback, nextarg);
        }

        g_list_free(elements);

        if (visible && haschildred) {
            struct menu_item item = {
                .type = MENUEND,
                .children = children,
                .name = garcon_menu_directory_get_name(directory),
                .icon = garcon_menu_directory_get_icon_name(directory),
                .prevarg = nextarg
            };
            callback(&item, arg);
        }

    } else if (ISITEM(element)) {
Ejemplo n.º 2
0
/* Fill model */
static GarconMenu* _xfdashboard_applications_menu_model_find_similar_menu(XfdashboardApplicationsMenuModel *self,
																			GarconMenu *inMenu,
																			XfdashboardApplicationsMenuModelFillData *inFillData)
{
	GarconMenu					*parentMenu;
	GSList						*iter;
	GarconMenu					*foundMenu;

	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATIONS_MENU_MODEL(self), NULL);
	g_return_val_if_fail(GARCON_IS_MENU(inMenu), NULL);
	g_return_val_if_fail(inFillData, NULL);

	/* Check if menu is visible. Hidden menus do not need to be checked. */
	if(!garcon_menu_element_get_visible(GARCON_MENU_ELEMENT(inMenu))) return(NULL);

	/* Get parent menu to look for at each menu we iterate */
	parentMenu=garcon_menu_get_parent(inMenu);
	if(!parentMenu) return(NULL);

	/* Iterate through parent menu up to current menu and lookup similar menu.
	 * A similar menu is identified by either they share the same directory
	 * or match in name, description and icon.
	 */
	foundMenu=NULL;
	for(iter=inFillData->populatedMenus; iter && !foundMenu; iter=g_slist_next(iter))
	{
		GarconMenu				*menu;

		/* Get menu element from list */
		menu=GARCON_MENU(iter->data);

		/* We can only process menus which have the same parent menu as the
		 * requested menu and they need to be visible.
		 */
		if(garcon_menu_get_parent(menu) &&
			garcon_menu_element_get_visible(GARCON_MENU_ELEMENT(menu)))
		{
			gboolean			isSimilar;

			/* Check if both menus share the same directory. That will be the
			 * case if iterator point to the menu which was given as function
			 * parameter. So it's safe just to iterate through.
			 */
			isSimilar=garcon_menu_directory_equal(garcon_menu_get_directory(menu),
													garcon_menu_get_directory(inMenu));

			/* If both menus do not share the same directory, check if they
			 * match in name, description and icon.
			 */
			if(!isSimilar)
			{
				const gchar		*left;
				const gchar		*right;

				/* Reset similar flag to TRUE as it will be set to FALSE again
				 * on first item not matching.
				 */
				isSimilar=TRUE;

				/* Check title */
				if(isSimilar)
				{
					left=garcon_menu_element_get_name(GARCON_MENU_ELEMENT(inMenu));
					right=garcon_menu_element_get_name(GARCON_MENU_ELEMENT(menu));
					if(g_strcmp0(left, right)!=0) isSimilar=FALSE;
				}


				/* Check description */
				if(isSimilar)
				{
					left=garcon_menu_element_get_comment(GARCON_MENU_ELEMENT(inMenu));
					right=garcon_menu_element_get_comment(GARCON_MENU_ELEMENT(menu));
					if(g_strcmp0(left, right)!=0) isSimilar=FALSE;
				}


				/* Check icon */
				if(isSimilar)
				{
					left=garcon_menu_element_get_icon_name(GARCON_MENU_ELEMENT(inMenu));
					right=garcon_menu_element_get_icon_name(GARCON_MENU_ELEMENT(menu));
					if(g_strcmp0(left, right)!=0) isSimilar=FALSE;
				}
			}

			/* If we get and we found a similar menu set result to return */
			if(isSimilar) foundMenu=menu;
		}
	}

	/* Return found menu */
	return(foundMenu);
}