summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorDan Sinclair <dj2>2007-02-05 21:16:55 +0000
committerDan Sinclair <dj2@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2007-02-05 21:16:55 +0000
commit1ebb0bad206c6c74c85fbca3e4a7f261991517aa (patch)
treee6e695e39da5d9f59a40b6fb65f0dc4f3a9995ba /legacy/efreet
parentbbd63d7f6bd8fc46b1c864268772143930ac59a9 (diff)
- setup the internal types (APPLICATION, DIRECTORY and LINK) to use the type
registration system SVN revision: 28257
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/bin/ef_desktop.c14
-rw-r--r--legacy/efreet/src/lib/efreet_desktop.c130
-rw-r--r--legacy/efreet/src/lib/efreet_desktop.h32
3 files changed, 78 insertions, 98 deletions
diff --git a/legacy/efreet/src/bin/ef_desktop.c b/legacy/efreet/src/bin/ef_desktop.c
index c731bb1eb0..6127dd3282 100644
--- a/legacy/efreet/src/bin/ef_desktop.c
+++ b/legacy/efreet/src/bin/ef_desktop.c
@@ -125,6 +125,12 @@ ef_cb_desktop_save(void)
125 125
126 printf("\n"); 126 printf("\n");
127 desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test.desktop"); 127 desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test.desktop");
128 if (!desktop)
129 {
130 printf("Failed to get Desktop file\n");
131 return 0;
132 }
133
128 printf("save data: %d\n", efreet_desktop_save(desktop)); 134 printf("save data: %d\n", efreet_desktop_save(desktop));
129 135
130 desktop = efreet_desktop_empty_new("/tmp/test.desktop"); 136 desktop = efreet_desktop_empty_new("/tmp/test.desktop");
@@ -361,12 +367,8 @@ ef_cb_desktop_type_parse(void)
361 char *val; 367 char *val;
362 368
363 /* add my custom desktop type to efreet */ 369 /* add my custom desktop type to efreet */
364 my_type = efreet_desktop_type_add("My_Type", cb_type_parse, (Efreet_Desktop_Type_Free_Cb)free); 370 my_type = efreet_desktop_type_add("My_Type", cb_type_parse, NULL,
365 if (my_type <= EFREET_DESKTOP_TYPE_MAX) 371 (Efreet_Desktop_Type_Free_Cb)free);
366 {
367 printf("Error adding desktop type.");
368 return 0;
369 }
370 372
371 desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test_type.desktop"); 373 desktop = efreet_desktop_get(PACKAGE_DATA_DIR"/efreet/test/test_type.desktop");
372 if (!desktop) 374 if (!desktop)
diff --git a/legacy/efreet/src/lib/efreet_desktop.c b/legacy/efreet/src/lib/efreet_desktop.c
index 30b0c68ffb..0382c9e3d4 100644
--- a/legacy/efreet/src/lib/efreet_desktop.c
+++ b/legacy/efreet/src/lib/efreet_desktop.c
@@ -30,6 +30,10 @@ static int efreet_desktop_command_file_id = 0;
30 30
31static int init = 0; 31static int init = 0;
32 32
33int EFREET_DESKTOP_TYPE_APPLICATION = 0;
34int EFREET_DESKTOP_TYPE_LINK = 0;
35int EFREET_DESKTOP_TYPE_DIRECTORY = 0;
36
33/** 37/**
34 * @internal 38 * @internal
35 * Information about custom types 39 * Information about custom types
@@ -37,20 +41,22 @@ static int init = 0;
37typedef struct Efreet_Desktop_Type_Info Efreet_Desktop_Type_Info; 41typedef struct Efreet_Desktop_Type_Info Efreet_Desktop_Type_Info;
38struct Efreet_Desktop_Type_Info 42struct Efreet_Desktop_Type_Info
39{ 43{
44 int id;
40 char *type; 45 char *type;
41 Efreet_Desktop_Type_Parse_Cb parse_func; 46 Efreet_Desktop_Type_Parse_Cb parse_func;
47 Efreet_Desktop_Type_Save_Cb save_func;
42 Efreet_Desktop_Type_Free_Cb free_func; 48 Efreet_Desktop_Type_Free_Cb free_func;
43}; 49};
44 50
45static Efreet_Desktop *efreet_desktop_new(const char *file); 51static Efreet_Desktop *efreet_desktop_new(const char *file);
46static Efreet_Desktop_Type efreet_desktop_type_parse(const char *type_str); 52static Efreet_Desktop_Type_Info *efreet_desktop_type_parse(const char *type_str);
47static Ecore_List *efreet_desktop_string_list_parse(const char *string); 53static Ecore_List *efreet_desktop_string_list_parse(const char *string);
48static char *efreet_desktop_string_list_join(Ecore_List *list); 54static char *efreet_desktop_string_list_join(Ecore_List *list);
49static int efreet_desktop_application_fields_parse(Efreet_Desktop *desktop, 55static void *efreet_desktop_application_fields_parse(Efreet_Desktop *desktop,
50 Efreet_Ini *ini); 56 Efreet_Ini *ini);
51static void efreet_desktop_application_fields_save(Efreet_Desktop *desktop, 57static void efreet_desktop_application_fields_save(Efreet_Desktop *desktop,
52 Efreet_Ini *ini); 58 Efreet_Ini *ini);
53static int efreet_desktop_link_fields_parse(Efreet_Desktop *desktop, 59static void *efreet_desktop_link_fields_parse(Efreet_Desktop *desktop,
54 Efreet_Ini *ini); 60 Efreet_Ini *ini);
55static void efreet_desktop_link_fields_save(Efreet_Desktop *desktop, 61static void efreet_desktop_link_fields_save(Efreet_Desktop *desktop,
56 Efreet_Ini *ini); 62 Efreet_Ini *ini);
@@ -115,7 +121,18 @@ efreet_desktop_init(void)
115 ECORE_FREE_CB(efreet_desktop_free)); 121 ECORE_FREE_CB(efreet_desktop_free));
116 122
117 efreet_desktop_types = ecore_list_new(); 123 efreet_desktop_types = ecore_list_new();
118 ecore_list_set_free_cb(efreet_desktop_types, ECORE_FREE_CB(efreet_desktop_type_info_free)); 124 ecore_list_set_free_cb(efreet_desktop_types,
125 ECORE_FREE_CB(efreet_desktop_type_info_free));
126
127 EFREET_DESKTOP_TYPE_APPLICATION = efreet_desktop_type_add("Application",
128 efreet_desktop_application_fields_parse,
129 efreet_desktop_application_fields_save,
130 NULL);
131 EFREET_DESKTOP_TYPE_LINK = efreet_desktop_type_add("Link",
132 efreet_desktop_link_fields_parse,
133 efreet_desktop_link_fields_save, NULL);
134 EFREET_DESKTOP_TYPE_DIRECTORY = efreet_desktop_type_add("Directory", NULL,
135 NULL, NULL);
119 136
120 return init; 137 return init;
121} 138}
@@ -186,11 +203,6 @@ efreet_desktop_get(const char *file)
186 203
187 desktop = efreet_desktop_new(file); 204 desktop = efreet_desktop_new(file);
188 if (!desktop) return NULL; 205 if (!desktop) return NULL;
189 if (!desktop->type)
190 {
191 efreet_desktop_free(desktop);
192 return NULL;
193 }
194 206
195 ecore_hash_set(efreet_desktop_cache, strdup(file), desktop); 207 ecore_hash_set(efreet_desktop_cache, strdup(file), desktop);
196 return desktop; 208 return desktop;
@@ -253,29 +265,14 @@ efreet_desktop_new(const char *file)
253 265
254 if (!error) 266 if (!error)
255 { 267 {
256 desktop->type = efreet_desktop_type_parse( 268 Efreet_Desktop_Type_Info *info;
257 efreet_ini_string_get(ini, "Type"));
258 desktop->version = efreet_ini_double_get(ini, "Version");
259 269
260 if (desktop->type == EFREET_DESKTOP_TYPE_APPLICATION) 270 info = efreet_desktop_type_parse(efreet_ini_string_get(ini, "Type"));
261 { 271 if (info)
262 if (!efreet_desktop_application_fields_parse(desktop, ini))
263 error = 1;
264 }
265 else if (desktop->type == EFREET_DESKTOP_TYPE_LINK)
266 {
267 if (!efreet_desktop_link_fields_parse(desktop, ini))
268 error = 1;
269 }
270 else if (desktop->type == EFREET_DESKTOP_TYPE_DIRECTORY)
271 { 272 {
272 /* there are no directory specific fields */ 273 desktop->type = info->id;
273 } 274 desktop->version = efreet_ini_double_get(ini, "Version");
274 else if (desktop->type >= (EFREET_DESKTOP_TYPE_MAX + 1)) 275
275 {
276 Efreet_Desktop_Type_Info *info;
277 info = ecore_list_goto_index(efreet_desktop_types,
278 (desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
279 if (info->parse_func) 276 if (info->parse_func)
280 desktop->type_data = info->parse_func(desktop, ini); 277 desktop->type_data = info->parse_func(desktop, ini);
281 } 278 }
@@ -307,6 +304,7 @@ efreet_desktop_new(const char *file)
307int 304int
308efreet_desktop_save(Efreet_Desktop *desktop) 305efreet_desktop_save(Efreet_Desktop *desktop)
309{ 306{
307 Efreet_Desktop_Type_Info *info;
310 Efreet_Ini *ini; 308 Efreet_Ini *ini;
311 int ok = 1; 309 int ok = 1;
312 310
@@ -314,27 +312,11 @@ efreet_desktop_save(Efreet_Desktop *desktop)
314 efreet_ini_section_add(ini, "Desktop Entry"); 312 efreet_ini_section_add(ini, "Desktop Entry");
315 efreet_ini_section_set(ini, "Desktop Entry"); 313 efreet_ini_section_set(ini, "Desktop Entry");
316 314
317 if (desktop->type == EFREET_DESKTOP_TYPE_APPLICATION) 315 info = ecore_list_goto_index(efreet_desktop_types, desktop->type);
316 if (info)
318 { 317 {
319 efreet_ini_string_set(ini, "Type", "Application"); 318 efreet_ini_string_set(ini, "Type", info->type);
320 efreet_desktop_application_fields_save(desktop, ini); 319 if (info->save_func) info->save_func(desktop, ini);
321 }
322 else if (desktop->type == EFREET_DESKTOP_TYPE_LINK)
323 {
324 efreet_ini_string_set(ini, "Type", "Link");
325 efreet_desktop_link_fields_save(desktop, ini);
326 }
327 else if (desktop->type == EFREET_DESKTOP_TYPE_DIRECTORY)
328 {
329 efreet_ini_string_set(ini, "Type", "Directory");
330 }
331 else if (desktop->type > EFREET_DESKTOP_TYPE_MAX + 1)
332 {
333 Efreet_Desktop_Type_Info *info;
334 info = ecore_list_goto_index(efreet_desktop_types,
335 (desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
336 if (info)
337 efreet_ini_string_set(ini, "Type", info->type);
338 } 320 }
339 else 321 else
340 ok = 0; 322 ok = 0;
@@ -419,11 +401,10 @@ efreet_desktop_free(Efreet_Desktop *desktop)
419 401
420 IF_FREE_HASH(desktop->x); 402 IF_FREE_HASH(desktop->x);
421 403
422 if (desktop->type >= EFREET_DESKTOP_TYPE_MAX + 1 && desktop->type_data) 404 if (desktop->type_data)
423 { 405 {
424 Efreet_Desktop_Type_Info *info; 406 Efreet_Desktop_Type_Info *info;
425 info = ecore_list_goto_index(efreet_desktop_types, 407 info = ecore_list_goto_index(efreet_desktop_types, desktop->type);
426 (desktop->type - (EFREET_DESKTOP_TYPE_MAX + 1)));
427 if (info->free_func) 408 if (info->free_func)
428 info->free_func(desktop->type_data); 409 info->free_func(desktop->type_data);
429 } 410 }
@@ -527,12 +508,14 @@ efreet_desktop_category_del(Efreet_Desktop *desktop, const char *category)
527/** 508/**
528 * @param type: The type to add to the list of matching types 509 * @param type: The type to add to the list of matching types
529 * @param parse_func: a function to parse out custom fields 510 * @param parse_func: a function to parse out custom fields
511 * @param save_func: a function to save data returned from @a parse_func
530 * @param free_func: a function to free data returned from @a parse_func 512 * @param free_func: a function to free data returned from @a parse_func
531 * @return Returns the id of the new type 513 * @return Returns the id of the new type
532 * @brief Adds the given type to the list of types in the system 514 * @brief Adds the given type to the list of types in the system
533 */ 515 */
534int 516int
535efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_func, 517efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_func,
518 Efreet_Desktop_Type_Save_Cb save_func,
536 Efreet_Desktop_Type_Free_Cb free_func) 519 Efreet_Desktop_Type_Free_Cb free_func)
537{ 520{
538 int id; 521 int id;
@@ -541,14 +524,17 @@ efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_fun
541 info = NEW(Efreet_Desktop_Type_Info, 1); 524 info = NEW(Efreet_Desktop_Type_Info, 1);
542 if (!info) return 0; 525 if (!info) return 0;
543 526
527 id = ecore_list_nodes(efreet_desktop_types);
528
529 info->id = id;
544 info->type = strdup(type); 530 info->type = strdup(type);
545 info->parse_func = parse_func; 531 info->parse_func = parse_func;
532 info->save_func = save_func;
546 info->free_func = free_func; 533 info->free_func = free_func;
547 534
548 id = ecore_list_nodes(efreet_desktop_types);
549 ecore_list_append(efreet_desktop_types, info); 535 ecore_list_append(efreet_desktop_types, info);
550 536
551 return (id + EFREET_DESKTOP_TYPE_MAX + 1); 537 return id;
552} 538}
553 539
554/** 540/**
@@ -580,31 +566,21 @@ efreet_desktop_type_data_get(Efreet_Desktop *desktop)
580 * @return the parsed type 566 * @return the parsed type
581 * @brief parse the type string into an Efreet_Desktop_Type 567 * @brief parse the type string into an Efreet_Desktop_Type
582 */ 568 */
583static Efreet_Desktop_Type 569static Efreet_Desktop_Type_Info *
584efreet_desktop_type_parse(const char *type_str) 570efreet_desktop_type_parse(const char *type_str)
585{ 571{
586 Efreet_Desktop_Type_Info *info; 572 Efreet_Desktop_Type_Info *info;
587 int count = 0; 573
588 574 if (!type_str) return NULL;
589 if (!type_str) return EFREET_DESKTOP_TYPE_UNKNOWN; 575
590
591 if (!strcmp("Application", type_str))
592 return EFREET_DESKTOP_TYPE_APPLICATION;
593 if (!strcmp("Link", type_str))
594 return EFREET_DESKTOP_TYPE_LINK;
595 if (!strcmp("Directory", type_str))
596 return EFREET_DESKTOP_TYPE_DIRECTORY;
597
598 /* check the user added types */
599 ecore_list_goto_first(efreet_desktop_types); 576 ecore_list_goto_first(efreet_desktop_types);
600 while ((info = ecore_list_next(efreet_desktop_types))) 577 while ((info = ecore_list_next(efreet_desktop_types)))
601 { 578 {
602 if (!strcmp(info->type, type_str)) 579 if (!strcmp(info->type, type_str))
603 return (count + EFREET_DESKTOP_TYPE_MAX + 1); 580 return info;
604 count ++;
605 } 581 }
606 582
607 return EFREET_DESKTOP_TYPE_UNKNOWN; 583 return NULL;
608} 584}
609 585
610/** 586/**
@@ -693,10 +669,10 @@ efreet_desktop_string_list_join(Ecore_List *list)
693 * @internal 669 * @internal
694 * @param desktop: the Efreet_Desktop to store parsed fields in 670 * @param desktop: the Efreet_Desktop to store parsed fields in
695 * @param ini: the Efreet_Ini to parse fields from 671 * @param ini: the Efreet_Ini to parse fields from
696 * @return 1 if parsed succesfully, 0 otherwise 672 * @return No value
697 * @brief Parse application specific desktop fields 673 * @brief Parse application specific desktop fields
698 */ 674 */
699static int 675static void *
700efreet_desktop_application_fields_parse(Efreet_Desktop *desktop, Efreet_Ini *ini) 676efreet_desktop_application_fields_parse(Efreet_Desktop *desktop, Efreet_Ini *ini)
701{ 677{
702 const char *val; 678 const char *val;
@@ -721,7 +697,7 @@ efreet_desktop_application_fields_parse(Efreet_Desktop *desktop, Efreet_Ini *ini
721 desktop->terminal = efreet_ini_boolean_get(ini, "Terminal"); 697 desktop->terminal = efreet_ini_boolean_get(ini, "Terminal");
722 desktop->startup_notify = efreet_ini_boolean_get(ini, "StartupNotify"); 698 desktop->startup_notify = efreet_ini_boolean_get(ini, "StartupNotify");
723 699
724 return 1; 700 return NULL;
725} 701}
726 702
727/** 703/**
@@ -770,17 +746,17 @@ efreet_desktop_application_fields_save(Efreet_Desktop *desktop, Efreet_Ini *ini)
770 * @internal 746 * @internal
771 * @param desktop: the Efreet_Desktop to store parsed fields in 747 * @param desktop: the Efreet_Desktop to store parsed fields in
772 * @param ini: the Efreet_Ini to parse fields from 748 * @param ini: the Efreet_Ini to parse fields from
773 * @return 1 if parsed succesfully, 0 otherwise 749 * @return Returns no value
774 * @brief Parse link specific desktop fields 750 * @brief Parse link specific desktop fields
775 */ 751 */
776static int 752static void *
777efreet_desktop_link_fields_parse(Efreet_Desktop *desktop, Efreet_Ini *ini) 753efreet_desktop_link_fields_parse(Efreet_Desktop *desktop, Efreet_Ini *ini)
778{ 754{
779 const char *val; 755 const char *val;
780 756
781 val = efreet_ini_string_get(ini, "URL"); 757 val = efreet_ini_string_get(ini, "URL");
782 if (val) desktop->url = strdup(val); 758 if (val) desktop->url = strdup(val);
783 return 1; 759 return NULL;
784} 760}
785 761
786/** 762/**
diff --git a/legacy/efreet/src/lib/efreet_desktop.h b/legacy/efreet/src/lib/efreet_desktop.h
index 976bb1052c..bb2fb222d6 100644
--- a/legacy/efreet/src/lib/efreet_desktop.h
+++ b/legacy/efreet/src/lib/efreet_desktop.h
@@ -14,17 +14,9 @@
14 * @{ 14 * @{
15 */ 15 */
16 16
17/** 17extern int EFREET_DESKTOP_TYPE_APPLICATION;
18 * Possible types of .desktop files. Unknown files are ignored. 18extern int EFREET_DESKTOP_TYPE_LINK;
19 */ 19extern int EFREET_DESKTOP_TYPE_DIRECTORY;
20enum Efreet_Desktop_Type
21{
22 EFREET_DESKTOP_TYPE_UNKNOWN,
23 EFREET_DESKTOP_TYPE_APPLICATION,
24 EFREET_DESKTOP_TYPE_LINK,
25 EFREET_DESKTOP_TYPE_DIRECTORY,
26 EFREET_DESKTOP_TYPE_MAX
27};
28 20
29/** 21/**
30 * Efreet_Desktop_Type 22 * Efreet_Desktop_Type
@@ -39,12 +31,14 @@ typedef struct Efreet_Desktop Efreet_Desktop;
39/** 31/**
40 * A callback used with efreet_desktop_command_get() 32 * A callback used with efreet_desktop_command_get()
41 */ 33 */
42typedef void (*Efreet_Desktop_Command_Cb) (void *data, Efreet_Desktop *desktop, char *command, int remaining); 34typedef void (*Efreet_Desktop_Command_Cb) (void *data, Efreet_Desktop *desktop,
35 char *command, int remaining);
43 36
44/** 37/**
45 * A callback used to get download progress of remote uris 38 * A callback used to get download progress of remote uris
46 */ 39 */
47typedef int (*Efreet_Desktop_Progress_Cb) (void *data, Efreet_Desktop *desktop, char *uri, long int total, long int current); 40typedef int (*Efreet_Desktop_Progress_Cb) (void *data, Efreet_Desktop *desktop,
41 char *uri, long int total, long int current);
48 42
49/** 43/**
50 * A callback used to parse data for custom types 44 * A callback used to parse data for custom types
@@ -52,6 +46,11 @@ typedef int (*Efreet_Desktop_Progress_Cb) (void *data, Efreet_Desktop *desktop,
52typedef void *(*Efreet_Desktop_Type_Parse_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini); 46typedef void *(*Efreet_Desktop_Type_Parse_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini);
53 47
54/** 48/**
49 * A callback used to save data for custom types
50 */
51typedef void (*Efreet_Desktop_Type_Save_Cb) (Efreet_Desktop *desktop, Efreet_Ini *ini);
52
53/**
55 * A callback used to free data for custom types 54 * A callback used to free data for custom types
56 */ 55 */
57typedef void *(*Efreet_Desktop_Type_Free_Cb) (void *data); 56typedef void *(*Efreet_Desktop_Type_Free_Cb) (void *data);
@@ -62,7 +61,7 @@ typedef void *(*Efreet_Desktop_Type_Free_Cb) (void *data);
62 */ 61 */
63struct Efreet_Desktop 62struct Efreet_Desktop
64{ 63{
65 Efreet_Desktop_Type type; /**< type of desktop file */ 64 int type; /**< type of desktop file */
66 65
67 double version; /**< version of spec file conforms to */ 66 double version; /**< version of spec file conforms to */
68 67
@@ -124,7 +123,10 @@ void efreet_desktop_category_add(Efreet_Desktop *desktop,
124int efreet_desktop_category_del(Efreet_Desktop *desktop, 123int efreet_desktop_category_del(Efreet_Desktop *desktop,
125 const char *category); 124 const char *category);
126 125
127int efreet_desktop_type_add(const char *type, Efreet_Desktop_Type_Parse_Cb parse_func, Efreet_Desktop_Type_Free_Cb free_func); 126int efreet_desktop_type_add(const char *type,
127 Efreet_Desktop_Type_Parse_Cb parse_func,
128 Efreet_Desktop_Type_Save_Cb save_func,
129 Efreet_Desktop_Type_Free_Cb free_func);
128 130
129/** 131/**
130 * @} 132 * @}