summaryrefslogtreecommitdiff
path: root/src/modules/wizard/page_030.c
blob: 559b1428a52a716f612c932c626018a07a8728a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"
#include "e_mod_main.h"

static char *xdg_sel = NULL;
static Eina_List *menus = NULL;

EAPI int
wizard_page_init(E_Wizard_Page *pg)
{
   const char *dirs[] = 
     {
	"/etc/xdg",
	  "/usr/etc/xdg",
	  "/usr/local/etc/xdg",
	  "/usr/opt/etc/xdg",
	  "/usr/opt/xdg",
	  // FIXME: add more "known locations"
	  NULL
     };
   int i;

   for (i = 0; dirs[i]; i++)
     {
	Ecore_List *files;
	char buf[PATH_MAX], *file;
	
	snprintf(buf, sizeof(buf), "%s/menus", dirs[i]);
	files = ecore_file_ls(buf);
	if (files)
	  {
	     ecore_list_first_goto(files);
	     while ((file = ecore_list_current(files)))
	       {
		  if (e_util_glob_match(file, "*.menu"))
		    {
		       snprintf(buf, sizeof(buf), "%s/menus/%s", dirs[i], file);
		       menus = eina_list_append(menus, strdup(buf));
		    }
		  ecore_list_next(files);
	       }
	     ecore_list_destroy(files);
	  }
     }
   return 1;
}
EAPI int
wizard_page_shutdown(E_Wizard_Page *pg)
{
   // FIXME: free menus
   return 1;
}
EAPI int
wizard_page_show(E_Wizard_Page *pg)
{
   Evas_Object *o, *of, *ob;
   Eina_List *l;
   int i, sel = -1;
   
   o = e_widget_list_add(pg->evas, 1, 0);
   e_wizard_title_set(_("Menus"));
   of = e_widget_framelist_add(pg->evas, _("Select application menu"), 0);
   
   ob = e_widget_ilist_add(pg->evas, 32 * e_scale, 32 * e_scale, &xdg_sel);
   e_widget_min_size_set(ob, 140 * e_scale, 140 * e_scale);
   
   e_widget_ilist_freeze(ob);
   for (i = 0, l = menus; l; l = l->next, i++)
     {
	char buf[PATH_MAX], *file, *p, *p2, *tlabel, *tdesc;
	const char *label;
	
	file = l->data;
	label = file;
	tlabel = NULL;
	tdesc = NULL;
	if (!strcmp("/etc/xdg/menus/applications.menu", file))
	  {
	     label = _("System Default");
	     sel = i;
	  }
	else
	  {
	     p = strrchr(file, '/');
	     if (p)
	       {
		  p++;
		  p2 = strchr(p, '-');
		  if (!p2) p2 = strrchr(p, '.');
		  if (p2)
		    {
		       tlabel = malloc(p2 - p + 1);
		       if (tlabel)
			 {
			    strncpy(tlabel, p, p2 - p);
			    tlabel[p2 - p] = 0;
			    tlabel[0] = toupper(tlabel[0]);
			    if (*p2 == '-')
			      {
				 p2++;
				 p = strrchr(p2, '.');
				 if (p)
				   {
				      tdesc = malloc(p - p2 + 1);
				      if (tdesc)
					{
					   strncpy(tdesc, p2, p - p2);
					   tdesc[p - p2] = 0;
					   tdesc[0] = toupper(tdesc[0]);
					   snprintf(buf, sizeof(buf), "%s (%s)", tlabel, tdesc);
					}
				      else
					snprintf(buf, sizeof(buf), "%s", tlabel);
				   }
				 else
				   snprintf(buf, sizeof(buf), "%s", tlabel);
			      }
			    else
			      snprintf(buf, sizeof(buf), "%s", tlabel);
			    label = buf;
			 }
		    }
		  else
		    label = p;
	       }
	  }
	e_widget_ilist_append(ob, NULL, label, NULL, NULL, file);
	if (tlabel) free(tlabel);
	if (tdesc) free(tdesc);
	free(file);
     }
   if (!menus)
     {
	e_widget_ilist_append(ob, NULL, _("No menus found"), NULL, NULL, NULL);
	sel = 0;
     }
   if (menus) evas_list_free(menus);
   e_widget_ilist_go(ob);
   e_widget_ilist_thaw(ob);
   
   if (sel >= 0) e_widget_ilist_selected_set(ob, sel);
   
   e_widget_framelist_object_append(of, ob);
   e_widget_list_object_append(o, of, 0, 0, 0.5);

   evas_object_show(ob);
   evas_object_show(of);
   e_wizard_page_show(o);
   pg->data = of;
   return 1; /* 1 == show ui, and wait for user, 0 == just continue */
}
EAPI int
wizard_page_hide(E_Wizard_Page *pg)
{
   evas_object_del(pg->data);
   return 1;
}
EAPI int
wizard_page_apply(E_Wizard_Page *pg)
{
   if (!strcmp("/etc/xdg/menus/applications.menu", xdg_sel))
     xdg_sel = NULL;
   if (xdg_sel)
     e_config->default_system_menu = eina_stringshare_add(xdg_sel);
   else
     e_config->default_system_menu = NULL;
   efreet_menu_file_set(e_config->default_system_menu);
   // FIXME: no normal config dialog to change this!
   return 1;
}