832d63da7222769cb548cfe7b86af78849672c9a
[framework/uifw/e17.git] / src / modules / everything / evry_plug_collection.c
1 #include "e_mod_main.h"
2
3
4 typedef struct _Plugin Plugin;
5
6 struct _Plugin
7 {
8   Evry_Plugin base;
9
10   Eina_List *plugins;
11 };
12
13 static Eina_List *plugins = NULL;
14 static const char _module_icon[] = "preferences-plugin";
15 static Evry_Type COLLECTION_PLUGIN;
16 static Plugin_Config plugin_config;
17
18 static Evry_Plugin *
19 _browse(Evry_Plugin *plugin, const Evry_Item *item)
20 {
21    Evry_Plugin *inst;
22    Evry_Plugin *pp;
23
24    Plugin_Config *pc;
25
26    if (!CHECK_TYPE(item, COLLECTION_PLUGIN))
27      return NULL;
28
29    if (item->plugin != plugin)
30      return NULL;
31
32    pc = item->data;
33    pp = pc->plugin;
34
35    if (pp->begin && (inst = pp->begin(pp, NULL)))
36      {
37         if (!strcmp(plugin->name, "Plugins"))
38           inst->config = &plugin_config;
39         else
40           inst->config = pc;
41
42         return inst;
43      }
44
45    return NULL;
46 }
47
48 static Evry_Item *
49 _add_item(Plugin *p, Plugin_Config *pc)
50 {
51    Evry_Plugin *pp;
52    Evry_Item *it = NULL;
53
54    if (pc->enabled && (pp = evry_plugin_find(pc->name)))
55      {
56         pc->plugin = pp;
57
58         GET_ITEM(itp, pp);
59         it = EVRY_ITEM_NEW(Evry_Item, EVRY_PLUGIN(p), itp->label, NULL, NULL);
60         if (itp->icon) it->icon = eina_stringshare_ref(itp->icon);
61         it->icon_get = itp->icon_get;
62         it->data = pc;
63         it->browseable = EINA_TRUE;
64         it->detail = eina_stringshare_ref(EVRY_ITEM(p)->label);
65         p->plugins = eina_list_append(p->plugins, it);
66      }
67    return it;
68 }
69
70 static Evry_Plugin *
71 _begin(Evry_Plugin *plugin, const Evry_Item *item __UNUSED__)
72 {
73    Plugin_Config *pc;
74    Eina_List *l;
75    Plugin *p;
76
77    EVRY_PLUGIN_INSTANCE(p, plugin);
78
79    EINA_LIST_FOREACH(plugin->config->plugins, l, pc)
80      _add_item(p, pc);
81
82    return EVRY_PLUGIN(p);
83 }
84
85 static Evry_Plugin *
86 _begin_all(Evry_Plugin *plugin, const Evry_Item *item __UNUSED__)
87 {
88    Plugin_Config *pc;
89    Eina_List *l;
90    Plugin *p;
91
92    EVRY_PLUGIN_INSTANCE(p, plugin);
93
94    EINA_LIST_FOREACH(evry_conf->conf_subjects, l, pc)
95      {
96         if (!strcmp(pc->name, "All") ||
97             !strcmp(pc->name, "Actions") ||
98             !strcmp(pc->name, "Calculator") ||
99             !strcmp(pc->name, "Plugins"))
100           continue;
101
102      _add_item(p, pc);
103      }
104
105    return EVRY_PLUGIN(p);
106 }
107
108 static void
109 _finish(Evry_Plugin *plugin)
110 {
111    Evry_Item *it;
112
113    GET_PLUGIN(p, plugin);
114
115    EVRY_PLUGIN_ITEMS_CLEAR(p);
116
117    EINA_LIST_FREE(p->plugins, it)
118      EVRY_ITEM_FREE(it);
119    
120    E_FREE(p);
121 }
122
123 static int
124 _fetch(Evry_Plugin *plugin, const char *input)
125 {
126    GET_PLUGIN(p, plugin);
127
128    EVRY_PLUGIN_ITEMS_CLEAR(p);
129
130    EVRY_PLUGIN_ITEMS_ADD(p, p->plugins, input, 1, 0);
131
132    return !!(plugin->items);
133 }
134
135 static Evry_Plugin *
136 _add_plugin(const char *name)
137 {
138    Evry_Plugin *p;
139    char path[4096];
140    char title[4096];
141
142    p = EVRY_PLUGIN_NEW(Evry_Plugin, N_(name),
143                        _module_icon, COLLECTION_PLUGIN,
144                        _begin, _finish, _fetch, NULL);
145    p->browse = &_browse;
146
147    snprintf(path, sizeof(path), "launcher/everything-%s", p->name);
148
149    snprintf(title, sizeof(title), "%s: %s", _("Everything Plugin"), p->base.label);
150
151    e_configure_registry_item_params_add
152      (path, 110, title, NULL, p->base.icon, evry_collection_conf_dialog, p->name);
153
154    p->config_path = eina_stringshare_add(path);
155
156    plugins = eina_list_append(plugins, p);
157
158    return p;
159 }
160
161 Eina_Bool
162 evry_plug_collection_init(void)
163 {
164    Evry_Plugin *p;
165    Plugin_Config *pc;
166    Eina_List *l;
167
168    plugin_config.min_query = 0;
169    plugin_config.top_level = EINA_TRUE;
170    plugin_config.aggregate = EINA_FALSE;
171    plugin_config.view_mode = VIEW_MODE_DETAIL;
172
173    COLLECTION_PLUGIN = evry_type_register("COLLECTION_PLUGIN");
174
175    p = _add_plugin("Plugins");
176    p->begin = &_begin_all;
177    if (evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 100))
178      {
179         p->config->aggregate = EINA_TRUE;
180         p->config->top_level = EINA_TRUE;
181         p->config->view_mode = VIEW_MODE_THUMB;
182      }
183
184    EINA_LIST_FOREACH(evry_conf->collections, l, pc)
185      {
186         p = _add_plugin(pc->name); 
187         p->config = pc;
188         pc->plugin = p;
189
190         if (evry_plugin_register(p, EVRY_PLUGIN_SUBJECT, 1))
191           p->config->aggregate = EINA_FALSE;
192      }
193
194    return EINA_TRUE;
195 }
196
197 void
198 evry_plug_collection_shutdown(void)
199 {
200    Evry_Plugin *p;
201
202    EINA_LIST_FREE(plugins, p)
203      {
204         if (p->config_path)
205           {
206              e_configure_registry_item_del(p->config_path);
207              eina_stringshare_del(p->config_path);
208           }
209
210         EVRY_PLUGIN_FREE(p);
211      }
212 }