Function to add a new desktop to an existing menu.
SVN revision: 28283
This commit is contained in:
parent
987db7b896
commit
cd5c85a7d2
|
@ -15,6 +15,7 @@ ef_ini.c \
|
||||||
ef_locale.c \
|
ef_locale.c \
|
||||||
ef_desktop.c \
|
ef_desktop.c \
|
||||||
ef_menu.c \
|
ef_menu.c \
|
||||||
|
ef_utils.c \
|
||||||
main.c
|
main.c
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* vim: set sw=4 ts=4 sts=4 et: */
|
||||||
#include "Efreet.h"
|
#include "Efreet.h"
|
||||||
#include "efreet_private.h"
|
#include "efreet_private.h"
|
||||||
|
|
||||||
|
@ -36,38 +37,85 @@ ef_cb_menu_get(void)
|
||||||
printf("efreet_menu_get() returned NULL\n");
|
printf("efreet_menu_get() returned NULL\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
if (strcmp(menu->name.internal, "Applications"))
|
|
||||||
{
|
|
||||||
printf("menu name didn't match\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!menu->moves || ecore_list_nodes(menu->moves) != 2)
|
|
||||||
{
|
|
||||||
printf("Missing moves\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (menu->current_move)
|
|
||||||
{
|
|
||||||
printf("Current move still set\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (menu->filters)
|
|
||||||
{
|
|
||||||
printf("Have filters when we shouldn't\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ef_menu_desktop_exec(menu);
|
|
||||||
#endif
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
efreet_menu_dump(menu, "");
|
efreet_menu_dump(menu, "");
|
||||||
unlink("/tmp/test.menu");
|
|
||||||
efreet_menu_save(menu, "/tmp/test.menu");
|
|
||||||
efreet_menu_free(menu);
|
efreet_menu_free(menu);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ef_cb_menu_save(void)
|
||||||
|
{
|
||||||
|
Efreet_Menu *menu;
|
||||||
|
|
||||||
|
// menu = efreet_menu_get();
|
||||||
|
menu = efreet_menu_parse(PACKAGE_DATA_DIR"/efreet/test/test.menu");
|
||||||
|
if (!menu)
|
||||||
|
{
|
||||||
|
printf("efreet_menu_get() returned NULL\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
unlink("/tmp/test.menu");
|
||||||
|
return efreet_menu_save(menu, "/tmp/test.menu");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ef_cb_menu_edit(void)
|
||||||
|
{
|
||||||
|
Efreet_Menu *menu, *entry;
|
||||||
|
Efreet_Desktop *desktop;
|
||||||
|
|
||||||
|
// menu = efreet_menu_get();
|
||||||
|
menu = efreet_menu_parse(PACKAGE_DATA_DIR"/efreet/test/test.menu");
|
||||||
|
if (!menu)
|
||||||
|
{
|
||||||
|
printf("efreet_menu_get() returned NULL\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
printf("\n");
|
||||||
|
efreet_menu_dump(menu, "");
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test.desktop");
|
||||||
|
if (!desktop)
|
||||||
|
{
|
||||||
|
printf("No desktop found.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
efreet_menu_desktop_insert(menu, desktop, 0);
|
||||||
|
#if 0
|
||||||
|
printf("\n");
|
||||||
|
efreet_menu_dump(menu, "");
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
ecore_list_goto_first(menu->entries);
|
||||||
|
entry = ecore_list_current(menu->entries);
|
||||||
|
if (desktop != entry->desktop) return 0;
|
||||||
|
|
||||||
|
efreet_menu_desktop_insert(menu, desktop, 2);
|
||||||
|
#if 0
|
||||||
|
printf("\n");
|
||||||
|
efreet_menu_dump(menu, "");
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
ecore_list_goto_index(menu->entries, 2);
|
||||||
|
entry = ecore_list_current(menu->entries);
|
||||||
|
if (desktop != entry->desktop) return 0;
|
||||||
|
|
||||||
|
efreet_menu_desktop_insert(menu, desktop, -1);
|
||||||
|
#if 0
|
||||||
|
printf("\n");
|
||||||
|
efreet_menu_dump(menu, "");
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
ecore_list_goto_last(menu->entries);
|
||||||
|
entry = ecore_list_current(menu->entries);
|
||||||
|
if (desktop != entry->desktop) return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* vim: set sw=4 ts=4 sts=4 et: */
|
||||||
|
#include "Efreet.h"
|
||||||
|
#include "efreet_private.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
ef_cb_utils(void)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = efreet_util_path_in_default("applications",
|
||||||
|
"/usr/share/applications/test.desktop");
|
||||||
|
if (strcmp(tmp, "/usr/share/applications"))
|
||||||
|
{
|
||||||
|
free(tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
tmp = efreet_util_path_to_file_id("/usr/share/applications",
|
||||||
|
"/usr/share/applications/this/tmp/test.desktop");
|
||||||
|
if (strcmp(tmp, "this-tmp-test.desktop"))
|
||||||
|
{
|
||||||
|
free(tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -22,7 +22,10 @@ int ef_cb_desktop_type_parse(void);
|
||||||
int ef_cb_desktop_file_id(void);
|
int ef_cb_desktop_file_id(void);
|
||||||
#endif
|
#endif
|
||||||
int ef_cb_menu_get(void);
|
int ef_cb_menu_get(void);
|
||||||
|
int ef_cb_menu_save(void);
|
||||||
|
int ef_cb_menu_edit(void);
|
||||||
int ef_cb_ini_long_line(void);
|
int ef_cb_ini_long_line(void);
|
||||||
|
int ef_cb_utils(void);
|
||||||
|
|
||||||
typedef struct Efreet_Test Efreet_Test;
|
typedef struct Efreet_Test Efreet_Test;
|
||||||
struct Efreet_Test
|
struct Efreet_Test
|
||||||
|
@ -51,6 +54,9 @@ static Efreet_Test tests[] = {
|
||||||
{"Desktop File ID", ef_cb_desktop_file_id},
|
{"Desktop File ID", ef_cb_desktop_file_id},
|
||||||
#endif
|
#endif
|
||||||
{"Menu Parsing", ef_cb_menu_get},
|
{"Menu Parsing", ef_cb_menu_get},
|
||||||
|
{"Menu Save", ef_cb_menu_save},
|
||||||
|
{"Menu Edit", ef_cb_menu_edit},
|
||||||
|
{"Utils", ef_cb_utils},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -792,6 +792,51 @@ efreet_menu_save_indent(FILE *f, int indent)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param menu: The menu to work with
|
||||||
|
* @param desktop: The desktop to insert
|
||||||
|
* @return Returns 1 on success, 0 on failure
|
||||||
|
* @brief Insert a desktop element in a menu structure. Only accepts desktop files
|
||||||
|
* in default directories.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos)
|
||||||
|
{
|
||||||
|
Efreet_Menu *entry;
|
||||||
|
char *path;
|
||||||
|
char *id;
|
||||||
|
|
||||||
|
if (!desktop || !menu) return 0;
|
||||||
|
path = efreet_util_path_in_default("applications", desktop->orig_path);
|
||||||
|
if (!path) return 0;
|
||||||
|
id = efreet_util_path_to_file_id(path, desktop->orig_path);
|
||||||
|
|
||||||
|
entry = efreet_menu_entry_new();
|
||||||
|
entry->type = EFREET_MENU_ENTRY_DESKTOP;
|
||||||
|
entry->id = ecore_string_instance(id);
|
||||||
|
entry->name = ecore_string_instance(desktop->name);
|
||||||
|
if (desktop->icon) entry->icon = ecore_string_instance(desktop->icon);
|
||||||
|
entry->desktop = desktop;
|
||||||
|
|
||||||
|
if (!menu->entries)
|
||||||
|
{
|
||||||
|
menu->entries = ecore_list_new();
|
||||||
|
ecore_list_set_free_cb(menu->entries, ECORE_FREE_CB(efreet_menu_free));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos < 0 || pos >= ecore_list_nodes(menu->entries))
|
||||||
|
ecore_list_append(menu->entries, entry);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ecore_list_goto_index(menu->entries, pos);
|
||||||
|
ecore_list_insert(menu->entries, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(id);
|
||||||
|
free(path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param menu: The menu to work with
|
* @param menu: The menu to work with
|
||||||
* @param indent: The indent level to print the menu at
|
* @param indent: The indent level to print the menu at
|
||||||
|
@ -820,13 +865,13 @@ efreet_menu_dump(Efreet_Menu *menu, const char *indent)
|
||||||
while ((entry = ecore_list_next(menu->entries)))
|
while ((entry = ecore_list_next(menu->entries)))
|
||||||
{
|
{
|
||||||
if (entry->type == EFREET_MENU_ENTRY_SEPARATOR)
|
if (entry->type == EFREET_MENU_ENTRY_SEPARATOR)
|
||||||
printf("%s|---\n", indent);
|
printf("%s|---\n", new_indent);
|
||||||
else if (entry->type == EFREET_MENU_ENTRY_DESKTOP)
|
else if (entry->type == EFREET_MENU_ENTRY_DESKTOP)
|
||||||
printf("%s|-%s\n", indent, entry->name);
|
printf("%s|-%s\n", new_indent, entry->name);
|
||||||
else if (entry->type == EFREET_MENU_ENTRY_MENU)
|
else if (entry->type == EFREET_MENU_ENTRY_MENU)
|
||||||
efreet_menu_dump(entry, new_indent);
|
efreet_menu_dump(entry, new_indent);
|
||||||
else if (entry->type == EFREET_MENU_ENTRY_HEADER)
|
else if (entry->type == EFREET_MENU_ENTRY_HEADER)
|
||||||
printf("%s|---%s\n", indent, entry->name);
|
printf("%s|---%s\n", new_indent, entry->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE(new_indent);
|
FREE(new_indent);
|
||||||
|
|
|
@ -56,6 +56,8 @@ Efreet_Menu *efreet_menu_parse(const char *path);
|
||||||
int efreet_menu_save(Efreet_Menu *menu, const char *path);
|
int efreet_menu_save(Efreet_Menu *menu, const char *path);
|
||||||
void efreet_menu_free(Efreet_Menu *menu);
|
void efreet_menu_free(Efreet_Menu *menu);
|
||||||
|
|
||||||
|
int efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos);
|
||||||
|
|
||||||
void efreet_menu_dump(Efreet_Menu *menu, const char *indent);
|
void efreet_menu_dump(Efreet_Menu *menu, const char *indent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
#include "Efreet.h"
|
#include "Efreet.h"
|
||||||
#include "efreet_private.h"
|
#include "efreet_private.h"
|
||||||
|
|
||||||
int
|
char *
|
||||||
efreet_util_path_in_default(const char *section, const char *path)
|
efreet_util_path_in_default(const char *section, const char *path)
|
||||||
{
|
{
|
||||||
Ecore_List *dirs;
|
Ecore_List *dirs;
|
||||||
int ret = 0;
|
char *ret = NULL;
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
|
dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
|
||||||
|
@ -20,7 +20,7 @@ efreet_util_path_in_default(const char *section, const char *path)
|
||||||
len = strlen(dir);
|
len = strlen(dir);
|
||||||
if (!strncmp(path, dir, strlen(dir)))
|
if (!strncmp(path, dir, strlen(dir)))
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = strdup(dir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,25 @@ efreet_util_path_in_default(const char *section, const char *path)
|
||||||
ecore_list_destroy(dirs);
|
ecore_list_destroy(dirs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
efreet_util_path_to_file_id(const char *base, const char *path)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char *id, *p;
|
||||||
|
|
||||||
|
len = strlen(base);
|
||||||
|
#if 0
|
||||||
|
if (strlen(path) <= len) return NULL;
|
||||||
|
if (!strncmp(path, base, len)) return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
id = strdup(path + len + 1);
|
||||||
|
p = id;
|
||||||
|
while (*p)
|
||||||
|
{
|
||||||
|
if (*p == '/') *p = '-';
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#ifndef EFREET_UTILS_H
|
#ifndef EFREET_UTILS_H
|
||||||
#define EFREET_UTILS_H
|
#define EFREET_UTILS_H
|
||||||
|
|
||||||
int efreet_util_path_in_default(const char *section, const char *path);
|
char *efreet_util_path_in_default(const char *section, const char *path);
|
||||||
|
char *efreet_util_path_to_file_id(const char *base, const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue