Enlightenment CVS committal
Author : englebass
Project : e17
Module : libs/efreet
Dir : e17/libs/efreet/src/lib
Modified Files:
efreet_menu.c efreet_menu.h efreet_utils.c efreet_utils.h
Log Message:
Function to add a new desktop to an existing menu.
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_menu.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- efreet_menu.c 7 Feb 2007 01:12:25 -0000 1.4
+++ efreet_menu.c 7 Feb 2007 02:14:46 -0000 1.5
@@ -794,6 +794,51 @@
/**
* @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 indent: The indent level to print the menu at
* @return Returns no value
* @brief Dumps the contents of the menu to the command line
@@ -820,13 +865,13 @@
while ((entry = ecore_list_next(menu->entries)))
{
if (entry->type == EFREET_MENU_ENTRY_SEPARATOR)
- printf("%s|---\n", indent);
+ printf("%s|---\n", new_indent);
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)
efreet_menu_dump(entry, new_indent);
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);
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_menu.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- efreet_menu.h 6 Feb 2007 02:16:33 -0000 1.2
+++ efreet_menu.h 7 Feb 2007 02:14:46 -0000 1.3
@@ -56,6 +56,8 @@
int efreet_menu_save(Efreet_Menu *menu, const char *path);
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);
/**
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_utils.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- efreet_utils.c 7 Feb 2007 01:13:08 -0000 1.1
+++ efreet_utils.c 7 Feb 2007 02:14:46 -0000 1.2
@@ -2,11 +2,11 @@
#include "Efreet.h"
#include "efreet_private.h"
-int
+char *
efreet_util_path_in_default(const char *section, const char *path)
{
Ecore_List *dirs;
- int ret = 0;
+ char *ret = NULL;
char *dir;
dirs = efreet_default_dirs_get(efreet_data_home_get(),
efreet_data_dirs_get(),
@@ -20,11 +20,33 @@
len = strlen(dir);
if (!strncmp(path, dir, strlen(dir)))
{
- ret = 1;
+ ret = strdup(dir);
break;
}
}
ecore_list_destroy(dirs);
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;
}
===================================================================
RCS file: /cvs/e/e17/libs/efreet/src/lib/efreet_utils.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- efreet_utils.h 7 Feb 2007 01:13:08 -0000 1.1
+++ efreet_utils.h 7 Feb 2007 02:14:46 -0000 1.2
@@ -2,6 +2,7 @@
#ifndef 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
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs