summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2007-02-07 02:14:46 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2007-02-07 02:14:46 +0000
commitcd5c85a7d2fd941df89a16bb0e4047849187b2ac (patch)
treebffcddc5a4ea344bca733cd68650ea7bf793cde3 /legacy/efreet
parent987db7b89616875d0c7805b3de6c41bc9b9260e2 (diff)
Function to add a new desktop to an existing menu.
SVN revision: 28283
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/bin/Makefile.am1
-rw-r--r--legacy/efreet/src/bin/ef_menu.c80
-rw-r--r--legacy/efreet/src/bin/ef_utils.c28
-rw-r--r--legacy/efreet/src/bin/main.c6
-rw-r--r--legacy/efreet/src/lib/efreet_menu.c51
-rw-r--r--legacy/efreet/src/lib/efreet_menu.h2
-rw-r--r--legacy/efreet/src/lib/efreet_utils.c28
-rw-r--r--legacy/efreet/src/lib/efreet_utils.h3
8 files changed, 176 insertions, 23 deletions
diff --git a/legacy/efreet/src/bin/Makefile.am b/legacy/efreet/src/bin/Makefile.am
index 46dbfbd5e0..7e0ea17775 100644
--- a/legacy/efreet/src/bin/Makefile.am
+++ b/legacy/efreet/src/bin/Makefile.am
@@ -15,6 +15,7 @@ ef_ini.c \
15ef_locale.c \ 15ef_locale.c \
16ef_desktop.c \ 16ef_desktop.c \
17ef_menu.c \ 17ef_menu.c \
18ef_utils.c \
18main.c 19main.c
19 20
20 21
diff --git a/legacy/efreet/src/bin/ef_menu.c b/legacy/efreet/src/bin/ef_menu.c
index c274ee1960..c0db839dc3 100644
--- a/legacy/efreet/src/bin/ef_menu.c
+++ b/legacy/efreet/src/bin/ef_menu.c
@@ -1,3 +1,4 @@
1/* vim: set sw=4 ts=4 sts=4 et: */
1#include "Efreet.h" 2#include "Efreet.h"
2#include "efreet_private.h" 3#include "efreet_private.h"
3 4
@@ -36,37 +37,84 @@ ef_cb_menu_get(void)
36 printf("efreet_menu_get() returned NULL\n"); 37 printf("efreet_menu_get() returned NULL\n");
37 return 0; 38 return 0;
38 } 39 }
39#if 0 40 printf("\n");
40 if (strcmp(menu->name.internal, "Applications")) 41 efreet_menu_dump(menu, "");
41 { 42 efreet_menu_free(menu);
42 printf("menu name didn't match\n"); 43
43 return 0; 44 return 1;
44 } 45}
45 46
46 if (!menu->moves || ecore_list_nodes(menu->moves) != 2) 47int
48ef_cb_menu_save(void)
49{
50 Efreet_Menu *menu;
51
52// menu = efreet_menu_get();
53 menu = efreet_menu_parse(PACKAGE_DATA_DIR"/efreet/test/test.menu");
54 if (!menu)
47 { 55 {
48 printf("Missing moves\n"); 56 printf("efreet_menu_get() returned NULL\n");
49 return 0; 57 return 0;
50 } 58 }
59 unlink("/tmp/test.menu");
60 return efreet_menu_save(menu, "/tmp/test.menu");
61}
51 62
52 if (menu->current_move) 63int
64ef_cb_menu_edit(void)
65{
66 Efreet_Menu *menu, *entry;
67 Efreet_Desktop *desktop;
68
69// menu = efreet_menu_get();
70 menu = efreet_menu_parse(PACKAGE_DATA_DIR"/efreet/test/test.menu");
71 if (!menu)
53 { 72 {
54 printf("Current move still set\n"); 73 printf("efreet_menu_get() returned NULL\n");
55 return 0; 74 return 0;
56 } 75 }
76#if 0
77 printf("\n");
78 efreet_menu_dump(menu, "");
79 printf("\n");
80#endif
57 81
58 if (menu->filters) 82 desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test.desktop");
83 if (!desktop)
59 { 84 {
60 printf("Have filters when we shouldn't\n"); 85 printf("No desktop found.\n");
61 return 0; 86 return 0;
62 } 87 }
63 ef_menu_desktop_exec(menu); 88
89 efreet_menu_desktop_insert(menu, desktop, 0);
90#if 0
91 printf("\n");
92 efreet_menu_dump(menu, "");
93 printf("\n");
94#endif
95 ecore_list_goto_first(menu->entries);
96 entry = ecore_list_current(menu->entries);
97 if (desktop != entry->desktop) return 0;
98
99 efreet_menu_desktop_insert(menu, desktop, 2);
100#if 0
101 printf("\n");
102 efreet_menu_dump(menu, "");
103 printf("\n");
64#endif 104#endif
105 ecore_list_goto_index(menu->entries, 2);
106 entry = ecore_list_current(menu->entries);
107 if (desktop != entry->desktop) return 0;
108
109 efreet_menu_desktop_insert(menu, desktop, -1);
110#if 0
65 printf("\n"); 111 printf("\n");
66 efreet_menu_dump(menu, ""); 112 efreet_menu_dump(menu, "");
67 unlink("/tmp/test.menu"); 113 printf("\n");
68 efreet_menu_save(menu, "/tmp/test.menu"); 114#endif
69 efreet_menu_free(menu); 115 ecore_list_goto_last(menu->entries);
116 entry = ecore_list_current(menu->entries);
117 if (desktop != entry->desktop) return 0;
70 118
71 return 1; 119 return 1;
72} 120}
diff --git a/legacy/efreet/src/bin/ef_utils.c b/legacy/efreet/src/bin/ef_utils.c
new file mode 100644
index 0000000000..8e8f75f340
--- /dev/null
+++ b/legacy/efreet/src/bin/ef_utils.c
@@ -0,0 +1,28 @@
1/* vim: set sw=4 ts=4 sts=4 et: */
2#include "Efreet.h"
3#include "efreet_private.h"
4
5int
6ef_cb_utils(void)
7{
8 char *tmp;
9
10 tmp = efreet_util_path_in_default("applications",
11 "/usr/share/applications/test.desktop");
12 if (strcmp(tmp, "/usr/share/applications"))
13 {
14 free(tmp);
15 return 0;
16 }
17 free(tmp);
18
19 tmp = efreet_util_path_to_file_id("/usr/share/applications",
20 "/usr/share/applications/this/tmp/test.desktop");
21 if (strcmp(tmp, "this-tmp-test.desktop"))
22 {
23 free(tmp);
24 return 0;
25 }
26 free(tmp);
27 return 1;
28}
diff --git a/legacy/efreet/src/bin/main.c b/legacy/efreet/src/bin/main.c
index 58c62029e6..21246e86de 100644
--- a/legacy/efreet/src/bin/main.c
+++ b/legacy/efreet/src/bin/main.c
@@ -22,7 +22,10 @@ int ef_cb_desktop_type_parse(void);
22int ef_cb_desktop_file_id(void); 22int ef_cb_desktop_file_id(void);
23#endif 23#endif
24int ef_cb_menu_get(void); 24int ef_cb_menu_get(void);
25int ef_cb_menu_save(void);
26int ef_cb_menu_edit(void);
25int ef_cb_ini_long_line(void); 27int ef_cb_ini_long_line(void);
28int ef_cb_utils(void);
26 29
27typedef struct Efreet_Test Efreet_Test; 30typedef struct Efreet_Test Efreet_Test;
28struct Efreet_Test 31struct Efreet_Test
@@ -51,6 +54,9 @@ static Efreet_Test tests[] = {
51 {"Desktop File ID", ef_cb_desktop_file_id}, 54 {"Desktop File ID", ef_cb_desktop_file_id},
52#endif 55#endif
53 {"Menu Parsing", ef_cb_menu_get}, 56 {"Menu Parsing", ef_cb_menu_get},
57 {"Menu Save", ef_cb_menu_save},
58 {"Menu Edit", ef_cb_menu_edit},
59 {"Utils", ef_cb_utils},
54 {NULL, NULL} 60 {NULL, NULL}
55}; 61};
56 62
diff --git a/legacy/efreet/src/lib/efreet_menu.c b/legacy/efreet/src/lib/efreet_menu.c
index 73783b21f4..8a0ce70de3 100644
--- a/legacy/efreet/src/lib/efreet_menu.c
+++ b/legacy/efreet/src/lib/efreet_menu.c
@@ -794,6 +794,51 @@ efreet_menu_save_indent(FILE *f, int indent)
794 794
795/** 795/**
796 * @param menu: The menu to work with 796 * @param menu: The menu to work with
797 * @param desktop: The desktop to insert
798 * @return Returns 1 on success, 0 on failure
799 * @brief Insert a desktop element in a menu structure. Only accepts desktop files
800 * in default directories.
801 */
802int
803efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos)
804{
805 Efreet_Menu *entry;
806 char *path;
807 char *id;
808
809 if (!desktop || !menu) return 0;
810 path = efreet_util_path_in_default("applications", desktop->orig_path);
811 if (!path) return 0;
812 id = efreet_util_path_to_file_id(path, desktop->orig_path);
813
814 entry = efreet_menu_entry_new();
815 entry->type = EFREET_MENU_ENTRY_DESKTOP;
816 entry->id = ecore_string_instance(id);
817 entry->name = ecore_string_instance(desktop->name);
818 if (desktop->icon) entry->icon = ecore_string_instance(desktop->icon);
819 entry->desktop = desktop;
820
821 if (!menu->entries)
822 {
823 menu->entries = ecore_list_new();
824 ecore_list_set_free_cb(menu->entries, ECORE_FREE_CB(efreet_menu_free));
825 }
826
827 if (pos < 0 || pos >= ecore_list_nodes(menu->entries))
828 ecore_list_append(menu->entries, entry);
829 else
830 {
831 ecore_list_goto_index(menu->entries, pos);
832 ecore_list_insert(menu->entries, entry);
833 }
834
835 free(id);
836 free(path);
837 return 1;
838}
839
840/**
841 * @param menu: The menu to work with
797 * @param indent: The indent level to print the menu at 842 * @param indent: The indent level to print the menu at
798 * @return Returns no value 843 * @return Returns no value
799 * @brief Dumps the contents of the menu to the command line 844 * @brief Dumps the contents of the menu to the command line
@@ -820,13 +865,13 @@ efreet_menu_dump(Efreet_Menu *menu, const char *indent)
820 while ((entry = ecore_list_next(menu->entries))) 865 while ((entry = ecore_list_next(menu->entries)))
821 { 866 {
822 if (entry->type == EFREET_MENU_ENTRY_SEPARATOR) 867 if (entry->type == EFREET_MENU_ENTRY_SEPARATOR)
823 printf("%s|---\n", indent); 868 printf("%s|---\n", new_indent);
824 else if (entry->type == EFREET_MENU_ENTRY_DESKTOP) 869 else if (entry->type == EFREET_MENU_ENTRY_DESKTOP)
825 printf("%s|-%s\n", indent, entry->name); 870 printf("%s|-%s\n", new_indent, entry->name);
826 else if (entry->type == EFREET_MENU_ENTRY_MENU) 871 else if (entry->type == EFREET_MENU_ENTRY_MENU)
827 efreet_menu_dump(entry, new_indent); 872 efreet_menu_dump(entry, new_indent);
828 else if (entry->type == EFREET_MENU_ENTRY_HEADER) 873 else if (entry->type == EFREET_MENU_ENTRY_HEADER)
829 printf("%s|---%s\n", indent, entry->name); 874 printf("%s|---%s\n", new_indent, entry->name);
830 } 875 }
831 876
832 FREE(new_indent); 877 FREE(new_indent);
diff --git a/legacy/efreet/src/lib/efreet_menu.h b/legacy/efreet/src/lib/efreet_menu.h
index 9b9efbbaf7..49b85d72c2 100644
--- a/legacy/efreet/src/lib/efreet_menu.h
+++ b/legacy/efreet/src/lib/efreet_menu.h
@@ -56,6 +56,8 @@ Efreet_Menu *efreet_menu_parse(const char *path);
56int efreet_menu_save(Efreet_Menu *menu, const char *path); 56int efreet_menu_save(Efreet_Menu *menu, const char *path);
57void efreet_menu_free(Efreet_Menu *menu); 57void efreet_menu_free(Efreet_Menu *menu);
58 58
59int efreet_menu_desktop_insert(Efreet_Menu *menu, Efreet_Desktop *desktop, int pos);
60
59void efreet_menu_dump(Efreet_Menu *menu, const char *indent); 61void efreet_menu_dump(Efreet_Menu *menu, const char *indent);
60 62
61/** 63/**
diff --git a/legacy/efreet/src/lib/efreet_utils.c b/legacy/efreet/src/lib/efreet_utils.c
index 532414b529..6d387e664a 100644
--- a/legacy/efreet/src/lib/efreet_utils.c
+++ b/legacy/efreet/src/lib/efreet_utils.c
@@ -2,11 +2,11 @@
2#include "Efreet.h" 2#include "Efreet.h"
3#include "efreet_private.h" 3#include "efreet_private.h"
4 4
5int 5char *
6efreet_util_path_in_default(const char *section, const char *path) 6efreet_util_path_in_default(const char *section, const char *path)
7{ 7{
8 Ecore_List *dirs; 8 Ecore_List *dirs;
9 int ret = 0; 9 char *ret = NULL;
10 char *dir; 10 char *dir;
11 11
12 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(), 12 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)
20 len = strlen(dir); 20 len = strlen(dir);
21 if (!strncmp(path, dir, strlen(dir))) 21 if (!strncmp(path, dir, strlen(dir)))
22 { 22 {
23 ret = 1; 23 ret = strdup(dir);
24 break; 24 break;
25 } 25 }
26 } 26 }
@@ -28,3 +28,25 @@ efreet_util_path_in_default(const char *section, const char *path)
28 ecore_list_destroy(dirs); 28 ecore_list_destroy(dirs);
29 return ret; 29 return ret;
30} 30}
31
32char *
33efreet_util_path_to_file_id(const char *base, const char *path)
34{
35 size_t len;
36 char *id, *p;
37
38 len = strlen(base);
39#if 0
40 if (strlen(path) <= len) return NULL;
41 if (!strncmp(path, base, len)) return NULL;
42#endif
43
44 id = strdup(path + len + 1);
45 p = id;
46 while (*p)
47 {
48 if (*p == '/') *p = '-';
49 p++;
50 }
51 return id;
52}
diff --git a/legacy/efreet/src/lib/efreet_utils.h b/legacy/efreet/src/lib/efreet_utils.h
index 36e8f6cabc..c28aa1c6da 100644
--- a/legacy/efreet/src/lib/efreet_utils.h
+++ b/legacy/efreet/src/lib/efreet_utils.h
@@ -2,6 +2,7 @@
2#ifndef EFREET_UTILS_H 2#ifndef EFREET_UTILS_H
3#define EFREET_UTILS_H 3#define EFREET_UTILS_H
4 4
5int efreet_util_path_in_default(const char *section, const char *path); 5char *efreet_util_path_in_default(const char *section, const char *path);
6char *efreet_util_path_to_file_id(const char *base, const char *path);
6 7
7#endif 8#endif