예제 #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
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir)
{
    GtkTreeIter it;
    GSList * l;
    GIcon* gicon;
    /* Iterate over all menu items in this directory. */
    for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next)
    {
        /* 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))
                {
                    if(g_path_is_absolute(menu_cache_item_get_icon(item)))
                    {
                        GFile* gf = g_file_new_for_path(menu_cache_item_get_icon(item));
                        gicon = g_file_icon_new(gf);
                        g_object_unref(gf);
                    }
                    else
                    {
                        char* dot = strrchr((char*)menu_cache_item_get_icon(item), '.');
                        if(dot && (strcmp(dot+1, "png") == 0 || strcmp(dot+1, "svg") == 0 || strcmp(dot+1, "xpm") == 0))
                        {
                            char* name = g_strndup(menu_cache_item_get_icon(item), dot - menu_cache_item_get_icon(item));
                            gicon = g_themed_icon_new(name);
                            g_free(name);
                        }
                        else
                            gicon = g_themed_icon_new(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;
        }
    }
}
예제 #3
0
FmPath* AppMenuView::selectedAppDesktopPath() {
  AppMenuViewItem* item = selectedItem();
  if(item && item->isApp()) {
    char* mpath = menu_cache_dir_make_path(MENU_CACHE_DIR(item));
    FmPath* path = fm_path_new_relative(fm_path_get_apps_menu(),
                                        mpath + 13 /* skip "/Applications" */);
    g_free(mpath);
    return path;
  }
  return NULL;
}
예제 #4
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
}
예제 #5
0
/**
 * fm_app_menu_view_dup_selected_app_desktop_path
 * @view: a widget
 *
 * Retrieves #FmPath to selected application from the widget as a child
 * below fm_path_get_apps_menu() root path. Return %NULL if there is no
 * application selected.
 * The returned data should be freed with fm_path_unref() after usage.
 *
 * Returns: (transfer full): path to selected application file.
 *
 * Since: 1.2.0
 */
FmPath * fm_app_menu_view_dup_selected_app_desktop_path(GtkTreeView* view)
{
    GtkTreeIter it;
    GtkTreeSelection* sel = gtk_tree_view_get_selection(view);
    /* FIXME: this should be checked if it's exactly app menu tree! */
    if(gtk_tree_selection_get_selected(sel, NULL, &it))
    {
        MenuCacheItem* item;
        gtk_tree_model_get(GTK_TREE_MODEL(store), &it, COL_ITEM, &item, -1);
        if(item && menu_cache_item_get_type(item) == MENU_CACHE_TYPE_APP)
        {
            char *mpath = menu_cache_dir_make_path(MENU_CACHE_DIR(item));
            FmPath *path = fm_path_new_relative(fm_path_get_apps_menu(),
                                                mpath+13 /* skip "/Applications" */);
            g_free(mpath);
            return path;
        }
    }
    return NULL;
}
예제 #6
0
/****f* pekwm-menu/generate_pekwm_menu
 * FUNCTION
 *   main routine of menu creation.
 *
 * NOTES
 *   It calls itself when 'dir' type is MENU_CACHE_TYPE_DIR.
 ****/
void
generate_pekwm_menu (MenuCacheDir *dir, OB_Menu *context)
{
	GSList *l = NULL;

	for (l = menu_cache_dir_get_children (dir); l; l = l->next)
		switch ((guint) menu_cache_item_get_type (MENU_CACHE_ITEM(l->data)))
		{
			case MENU_CACHE_TYPE_DIR:
				menu_directory (l->data, context);
				generate_pekwm_menu (MENU_CACHE_DIR(l->data), context);
				g_string_append (context->builder, "}\n");
				break;

			case MENU_CACHE_TYPE_SEP:
				g_string_append (context->builder, "Separator {}\n");
				break;

			case MENU_CACHE_TYPE_APP:
				if (app_is_visible (MENU_CACHE_APP(l->data), 0))
					menu_application (l->data, context);
		}
}