예제 #1
0
static void
print_directory(GMenuTreeDirectory *directory)
{
  GSList     *items;
  GSList     *tmp;
  const char *path;
  char       *freeme;

  freeme = make_path(directory);

  if (!strcmp(freeme, "/"))
    path = freeme;
  else
    path = freeme + 1;

  items = gmenu_tree_directory_get_contents(directory);

  tmp = items;

  while (tmp != NULL)
  {
    GMenuTreeItem *item = tmp->data;

    switch (gmenu_tree_item_get_type(item))
    {

      case GMENU_TREE_ITEM_ENTRY:
        print_entry(GMENU_TREE_ENTRY(item), path);
        break;

      case GMENU_TREE_ITEM_DIRECTORY:
        print_directory(GMENU_TREE_DIRECTORY(item));
        break;

      case GMENU_TREE_ITEM_HEADER:

      case GMENU_TREE_ITEM_SEPARATOR:
        break;

      case GMENU_TREE_ITEM_ALIAS:
      {
        GMenuTreeItem *aliased_item;

        aliased_item = gmenu_tree_alias_get_item(GMENU_TREE_ALIAS(item));

        if (gmenu_tree_item_get_type(aliased_item) == GMENU_TREE_ITEM_ENTRY)
          print_entry(GMENU_TREE_ENTRY(aliased_item), path);
      }

      break;

      default:
        g_assert_not_reached();
        break;
    }

    gmenu_tree_item_unref(tmp->data);

    tmp = tmp->next;
  }

  g_slist_free(items);

  g_free(freeme);
}
예제 #2
0
static void
fill_er_up(GMenuTreeDirectory *directory, GSList**p)
{
  GSList*  data = *p;
  GSList     *items;
  GSList     *tmp;
  const char *path;
  char       *freeme;

  freeme = make_path(directory);

  if (!strcmp(freeme, "/"))
    path = freeme;
  else
    path = freeme + 1;

  items = gmenu_tree_directory_get_contents(directory);

  tmp = items;

  while (tmp != NULL)
  {
    GMenuTreeItem *item = tmp->data;

    switch (gmenu_tree_item_get_type(item))
    {

      case GMENU_TREE_ITEM_ENTRY:
        // print_entry (GMENU_TREE_ENTRY (item), path);
        add_entry(GMENU_TREE_ENTRY(item), path, &data);
        break;

      case GMENU_TREE_ITEM_DIRECTORY:
      {
        Menu_list_item * dir_item;
        dir_item = g_malloc(sizeof(Menu_list_item));
        dir_item->item_type = MENU_ITEM_DIRECTORY;
        dir_item->name = gmenu_tree_directory_get_name(item);
        dir_item->desktop = gmenu_tree_directory_get_desktop_file_path(item);
        dir_item->comment = NULL;
        dir_item->null = NULL;
        dir_item->comment = gmenu_tree_directory_get_comment(item);
        dir_item->icon = gmenu_tree_directory_get_icon(item);
        dir_item->sublist = NULL;
        data = g_slist_append(data, dir_item);
        fill_er_up(GMENU_TREE_DIRECTORY(item), &dir_item->sublist);
        dir_item->sublist = g_slist_prepend(dir_item->sublist, get_blank());
        dir_item->sublist = g_slist_append(dir_item->sublist, get_blank());
      }

      break;

      case GMENU_TREE_ITEM_HEADER:
//    printf("GMENU_TREE_ITEM_HEADER\n");
        break;

      case GMENU_TREE_ITEM_SEPARATOR:
//    printf("GMENU_TREE_ITEM_HEADER\n");
        break;

      case GMENU_TREE_ITEM_ALIAS:
//    printf("GMENU_TREE_ITEM_ALIAS\n");
        /*      {
             GMenuTreeItem *aliased_item;

             aliased_item = gmenu_tree_alias_get_item (GMENU_TREE_ALIAS (item));
             if (gmenu_tree_item_get_type (aliased_item) == GMENU_TREE_ITEM_ENTRY)
                print_entry (GMENU_TREE_ENTRY (aliased_item), path);
              }*/
        break;

      default:
        g_assert_not_reached();
        break;
    }

    gmenu_tree_item_unref(tmp->data);

    tmp = tmp->next;
  }

  g_slist_free(items);

  g_free(freeme);
  *p = data;
}
예제 #3
0
/*=============================================================================
 * This function processes a directory entry and all it's child nodes
 */
void process_directory(GMenuTreeDirectory *directory, gboolean isRoot)
{
    int hasSeparator = 0;
    int hasMenu = 0;
    GMenuTreeItemType entryType;
    GSList *entryList = gmenu_tree_directory_get_contents (directory);
    GSList *l;
    
    if (option_do_not_use_categories == 00 && isRoot == 0 &&
    g_slist_length(entryList) > 0)
    {
        hasMenu = 1;
        
        if (option_show_amount_of_entries == 1)
        {
            g_printf(
              "<menu id=\"xdg-menu-%s\" label=\"%s (%d)\">\n",
              gmenu_tree_directory_get_name(directory),
              gmenu_tree_directory_get_name(directory),
              g_slist_length(entryList));
        }
        else
        {
            g_printf(
              "<menu id=\"xdg-menu-%s\" label=\"%s\">\n",
              gmenu_tree_directory_get_name(directory),
              gmenu_tree_directory_get_name(directory));
        }
    }

    for (l = entryList; l; l = l->next)
    {
        GMenuTreeItem *item = l->data;
        
        entryType = gmenu_tree_item_get_type (GMENU_TREE_ITEM(item));
        
        switch (entryType)
        {
            case GMENU_TREE_ITEM_DIRECTORY:
                if (hasSeparator)
                {
                    process_separator(GMENU_TREE_SEPARATOR(item));
                    hasSeparator = 0;
                }
                process_directory(GMENU_TREE_DIRECTORY(item), 0);
                break;
            case GMENU_TREE_ITEM_ENTRY:
                if (hasSeparator)
                {
                    process_separator(GMENU_TREE_SEPARATOR(item));
                    hasSeparator = 0;
                }
                process_entry(GMENU_TREE_ENTRY(item));
                break;
            case GMENU_TREE_ITEM_SEPARATOR:
                hasSeparator = 1;
                break;
        }
        
        gmenu_tree_item_unref (item);
    }
    
    if (hasMenu == 1)
    {
        g_printf("</menu>\n");
    }
    
    g_slist_free (entryList);
}