Пример #1
0
void AppMenuView::addMenuItems(QStandardItem* parentItem, MenuCacheDir* dir) {
  GSList* l;
  GSList* list;
  /* Iterate over all menu items in this directory. */
  for(l = list = menu_cache_dir_list_children(dir); l != NULL; l = l->next) {
    /* Get the menu item. */
    MenuCacheItem* menuItem = MENU_CACHE_ITEM(l->data);
    switch(menu_cache_item_get_type(menuItem)) {
    case MENU_CACHE_TYPE_NONE:
    case MENU_CACHE_TYPE_SEP:
      break;
    case MENU_CACHE_TYPE_APP:
    case MENU_CACHE_TYPE_DIR: {
      AppMenuViewItem* newItem = new AppMenuViewItem(menuItem);
      if(parentItem)
        parentItem->insertRow(parentItem->rowCount(), newItem);
      else
        model_->insertRow(model_->rowCount(), newItem);

      if(menu_cache_item_get_type(menuItem) == MENU_CACHE_TYPE_DIR)
        addMenuItems(newItem, MENU_CACHE_DIR(menuItem));
      break;
    }
    }
  }
  g_slist_free_full(list, (GDestroyNotify)menu_cache_item_unref);
}
Пример #2
0
/* called with lock held */
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir)
{
    GtkTreeIter it;
    GSList * l;
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    GSList *list;
#endif
    GIcon* gicon;
    /* Iterate over all menu items in this directory. */
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    for (l = list = menu_cache_dir_list_children(dir); l != NULL; l = l->next)
#else
    for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next)
#endif
    {
        /* Get the menu item. */
        MenuCacheItem* item = MENU_CACHE_ITEM(l->data);
        switch(menu_cache_item_get_type(item))
        {
            case MENU_CACHE_TYPE_NONE:
            case MENU_CACHE_TYPE_SEP:
                break;
            case MENU_CACHE_TYPE_APP:
            case MENU_CACHE_TYPE_DIR:
                if(menu_cache_item_get_icon(item))
                    gicon = G_ICON(fm_icon_from_name(menu_cache_item_get_icon(item)));
                else
                    gicon = NULL;
                gtk_tree_store_append(store, &it, parent_it);
                gtk_tree_store_set(store, &it,
                                   COL_ICON, gicon,
                                   COL_TITLE, menu_cache_item_get_name(item),
                                   COL_ITEM, item, -1);
                if(gicon)
                    g_object_unref(gicon);

                if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR)
                    add_menu_items(&it, MENU_CACHE_DIR(item));
                break;
        }
    }
#if MENU_CACHE_CHECK_VERSION(0, 4, 0)
    g_slist_free_full(list, (GDestroyNotify)menu_cache_item_unref);
#endif
}