Skip to content

Latest commit

 

History

History
220 lines (180 loc) · 5.11 KB

gui.c

File metadata and controls

220 lines (180 loc) · 5.11 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Dec 9, 2006
Dec 9, 2006
10
#include "platform.h"
11
12
13
14
15
#include "fileio.h"
typedef struct S_PLUGINLIST
{
void *lib;
Dec 7, 2006
Dec 7, 2006
16
const MojoGui *gui;
17
18
19
20
MojoGuiPluginPriority priority;
struct S_PLUGINLIST *next;
} PluginList;
Dec 7, 2006
Dec 7, 2006
21
22
const MojoGui *GGui = NULL;
static PluginList *pluginDetails = NULL;
Dec 7, 2006
Dec 7, 2006
24
static const MojoGuiEntryPoint staticGui[] =
Mar 27, 2006
Mar 27, 2006
25
{
Nov 29, 2006
Nov 29, 2006
26
#if GUI_STATIC_LINK_STDIO
Mar 27, 2006
Mar 27, 2006
27
MojoGuiPlugin_stdio,
Nov 29, 2006
Nov 29, 2006
28
#endif
May 6, 2009
May 6, 2009
29
30
#if GUI_STATIC_LINK_COCOA
MojoGuiPlugin_cocoa,
Dec 1, 2006
Dec 1, 2006
31
#endif
May 10, 2007
May 10, 2007
32
33
#if GUI_STATIC_LINK_GTKPLUS2
MojoGuiPlugin_gtkplus2,
May 19, 2007
May 19, 2007
34
#endif
Jun 1, 2007
Jun 1, 2007
35
36
37
#if GUI_STATIC_LINK_WWW
MojoGuiPlugin_www,
#endif
May 19, 2007
May 19, 2007
38
39
#if GUI_STATIC_LINK_NCURSES
MojoGuiPlugin_ncurses,
Nov 29, 2006
Nov 29, 2006
40
41
#endif
NULL
Mar 27, 2006
Mar 27, 2006
42
43
44
};
Dec 7, 2006
Dec 7, 2006
45
static MojoGuiPluginPriority calcGuiPriority(const MojoGui *gui)
Mar 27, 2006
Mar 27, 2006
46
47
48
{
MojoGuiPluginPriority retval;
Nov 21, 2007
Nov 21, 2007
49
retval = gui->priority(MojoPlatform_istty());
Mar 27, 2006
Mar 27, 2006
50
51
52
53
54
// If the plugin isn't saying "don't try me at all" then see if the
// user explicitly wants this one.
if (retval != MOJOGUI_PRIORITY_NEVER_TRY)
{
Dec 10, 2006
Dec 10, 2006
55
56
57
static const char *envr = NULL;
if (envr == NULL)
envr = cmdlinestr("ui", "MOJOSETUP_UI", NULL);
Dec 7, 2006
Dec 7, 2006
58
if ((envr != NULL) && (strcasecmp(envr, gui->name()) == 0))
Mar 27, 2006
Mar 27, 2006
59
60
61
62
63
64
65
retval = MOJOGUI_PRIORITY_USER_REQUESTED;
} // if
return retval;
} // calcGuiPriority
Mar 27, 2006
Mar 27, 2006
66
67
68
69
70
71
72
73
static PluginList *initGuiPluginsByPriority(PluginList *plugins)
{
MojoGuiPluginPriority p;
for (p = MOJOGUI_PRIORITY_USER_REQUESTED; p < MOJOGUI_PRIORITY_TOTAL; p++)
{
PluginList *i;
for (i = plugins->next; i != NULL; i = i->next)
{
Dec 7, 2006
Dec 7, 2006
74
if ( (i->priority == p) && (i->gui->init()) )
May 18, 2007
May 18, 2007
75
{
Jan 12, 2008
Jan 12, 2008
76
logInfo("Selected '%0' UI.", i->gui->name());
Mar 27, 2006
Mar 27, 2006
77
return i;
May 18, 2007
May 18, 2007
78
} // if
Mar 27, 2006
Mar 27, 2006
79
80
81
82
83
84
85
86
87
88
89
90
} // for
} // for
return NULL;
} // initGuiPluginsByPriority
static void deleteGuiPlugin(PluginList *plugin)
{
if (plugin != NULL)
{
if (plugin->gui)
Dec 7, 2006
Dec 7, 2006
91
plugin->gui->deinit();
Mar 27, 2006
Mar 27, 2006
92
if (plugin->lib)
Dec 9, 2006
Dec 9, 2006
93
MojoPlatform_dlclose(plugin->lib);
Mar 27, 2006
Mar 27, 2006
94
95
96
97
98
free(plugin);
} // if
} // deleteGuiPlugin
Dec 9, 2006
Dec 9, 2006
99
static boolean tryGuiPlugin(PluginList *plugins, MojoGuiEntryPoint entry)
Mar 27, 2006
Mar 27, 2006
100
{
Dec 9, 2006
Dec 9, 2006
101
102
103
boolean retval = false;
const MojoGui *gui = entry(MOJOGUI_INTERFACE_REVISION, &GEntryPoints);
if (gui != NULL)
Mar 27, 2006
Mar 27, 2006
104
{
Dec 9, 2006
Dec 9, 2006
105
PluginList *plug = xmalloc(sizeof (PluginList));
Mar 27, 2006
Mar 27, 2006
106
107
108
109
110
plug->lib = NULL;
plug->gui = gui;
plug->priority = calcGuiPriority(gui);
plug->next = plugins->next;
plugins->next = plug;
Dec 9, 2006
Dec 9, 2006
111
112
113
114
115
116
117
118
119
120
121
retval = true;
} // if
return retval;
} // tryGuiPlugin
static void loadStaticGuiPlugins(PluginList *plugins)
{
int i;
for (i = 0; staticGui[i] != NULL; i++)
Dec 9, 2006
Dec 9, 2006
122
tryGuiPlugin(plugins, staticGui[i]);
Mar 27, 2006
Mar 27, 2006
123
124
125
} // loadStaticGuiPlugins
Dec 9, 2006
Dec 9, 2006
126
static boolean loadDynamicGuiPlugin(PluginList *plugins, MojoArchive *ar)
Dec 9, 2006
Dec 9, 2006
128
boolean rc = false;
129
130
void *lib = NULL;
MojoInput *io = ar->openCurrentEntry(ar);
Dec 9, 2006
Dec 9, 2006
131
if (io != NULL)
Dec 9, 2006
Dec 9, 2006
133
134
const uint32 imglen = (uint32) io->length(io);
uint8 *img = (uint8 *) xmalloc(imglen);
Sep 25, 2007
Sep 25, 2007
135
const uint32 br = (uint32) io->read(io, img, imglen);
Dec 9, 2006
Dec 9, 2006
136
137
138
139
140
io->close(io);
if (br == imglen)
lib = MojoPlatform_dlopen(img, imglen);
free(img);
} // if
Dec 9, 2006
Dec 9, 2006
142
if (lib != NULL)
Dec 9, 2006
Dec 9, 2006
144
145
146
void *addr = MojoPlatform_dlsym(lib, MOJOGUI_ENTRY_POINT_STR);
MojoGuiEntryPoint entry = (MojoGuiEntryPoint) addr;
if (entry != NULL)
Dec 9, 2006
Dec 9, 2006
148
149
if ((rc = tryGuiPlugin(plugins, entry)) == false)
MojoPlatform_dlclose(lib);
150
151
152
} // if
} // if
Dec 9, 2006
Dec 9, 2006
153
return rc;
Mar 27, 2006
Mar 27, 2006
154
} // loadDynamicGuiPlugin
Mar 27, 2006
Mar 27, 2006
157
static void loadDynamicGuiPlugins(PluginList *plugins)
May 4, 2007
May 4, 2007
159
if (GBaseArchive->enumerate(GBaseArchive))
Apr 29, 2007
Apr 29, 2007
161
const MojoArchiveEntry *entinfo;
Mar 27, 2006
Mar 27, 2006
162
while ((entinfo = GBaseArchive->enumNext(GBaseArchive)) != NULL)
Mar 27, 2006
Mar 27, 2006
164
165
if (entinfo->type != MOJOARCHIVE_ENTRY_FILE)
continue;
May 4, 2007
May 4, 2007
167
168
169
if (strncmp(entinfo->filename, "guis/", 5) != 0)
continue;
Dec 9, 2006
Dec 9, 2006
170
loadDynamicGuiPlugin(plugins, GBaseArchive);
Mar 27, 2006
Mar 27, 2006
171
} // while
Mar 27, 2006
Mar 27, 2006
173
} // loadDynamicGuiPlugins
Dec 7, 2006
Dec 7, 2006
176
const MojoGui *MojoGui_initGuiPlugin(void)
177
178
{
PluginList plugins;
Dec 13, 2006
Dec 13, 2006
179
PluginList *i = NULL;
180
181
182
183
184
if (pluginDetails != NULL)
return pluginDetails->gui;
memset(&plugins, '\0', sizeof (plugins));
Mar 26, 2006
Mar 26, 2006
185
assert(GGui == NULL);
Mar 27, 2006
Mar 27, 2006
187
loadDynamicGuiPlugins(&plugins);
Mar 27, 2006
Mar 27, 2006
188
loadStaticGuiPlugins(&plugins);
189
190
191
192
pluginDetails = initGuiPluginsByPriority(&plugins);
// cleanout unused plugins...
Dec 13, 2006
Dec 13, 2006
193
i = plugins.next;
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
while (i != NULL)
{
PluginList *next = i->next;
if (i != pluginDetails)
deleteGuiPlugin(i);
i = next;
} // while
if (pluginDetails != NULL)
{
GGui = pluginDetails->gui;
pluginDetails->next = NULL;
} // if
return GGui;
} // MojoGui_findGuiPlugin
void MojoGui_deinitGuiPlugin(void)
{
GGui = NULL;
deleteGuiPlugin(pluginDetails);
pluginDetails = NULL;
} // MojoGui_deinitGuiPlugin
// end of gui.c ...