Skip to content

Commit

Permalink
Destination can now command back/next/cancel.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 10, 2007
1 parent a6474c6 commit 1e63a1d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
8 changes: 4 additions & 4 deletions gui.h
Expand Up @@ -55,8 +55,8 @@ struct MojoGui
boolean can_back, boolean can_fwd);
int (*options)(MojoGuiSetupOptions *opts,
boolean can_back, boolean can_fwd);
char * (*destination)(const char **recommendations, int reccount,
boolean can_back, boolean can_fwd);
char * (*destination)(const char **recommendations, int recnum,
int *command, boolean can_back, boolean can_fwd);
boolean (*insertmedia)(const char *medianame);
boolean (*progress)(const char *type, const char *component,
int percent, const char *item);
Expand Down Expand Up @@ -94,8 +94,8 @@ static int MojoGui_##module##_readme(const char *name, const uint8 *data, \
boolean can_fwd); \
static int MojoGui_##module##_options(MojoGuiSetupOptions *opts, \
boolean can_back, boolean can_fwd); \
static char *MojoGui_##module##_destination(const char **r, int reccount, \
boolean can_back, boolean can_fwd); \
static char *MojoGui_##module##_destination(const char **r, int recnum, \
int *command, boolean can_back, boolean can_fwd); \
static boolean MojoGui_##module##_insertmedia(const char *medianame); \
static boolean MojoGui_##module##_progress(const char *typ, const char *comp, \
int percent, const char *item); \
Expand Down
13 changes: 7 additions & 6 deletions gui_gtkplus2.c
Expand Up @@ -338,8 +338,8 @@ static void MojoGui_gtkplus2_stop(void)


static int MojoGui_gtkplus2_readme(const char *name, const uint8 *data,
size_t datalen, boolean can_back,
boolean can_fwd)
size_t datalen, boolean can_back,
boolean can_fwd)
{
GtkTextBuffer *textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(readme));
gtk_text_buffer_set_text(textbuf, (const gchar *) data, datalen);
Expand All @@ -348,15 +348,16 @@ static int MojoGui_gtkplus2_readme(const char *name, const uint8 *data,


static int MojoGui_gtkplus2_options(MojoGuiSetupOptions *opts,
boolean can_back, boolean can_fwd)
boolean can_back, boolean can_fwd)
{
// !!! FIXME: better text.
return run_wizard(entry->_("Options"), PAGE_OPTIONS, can_back, can_fwd);
} // MojoGui_gtkplus2_options


static char *MojoGui_gtkplus2_destination(const char **recommends, int reccount,
boolean can_back, boolean can_fwd)
static char *MojoGui_gtkplus2_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
// !!! FIXME: better text.
run_wizard(entry->_("Destination"), PAGE_DESTINATION, can_back, can_fwd);
Expand All @@ -380,7 +381,7 @@ static boolean MojoGui_gtkplus2_insertmedia(const char *medianame)


static boolean MojoGui_gtkplus2_progress(const char *type, const char *component,
int percent, const char *item)
int percent, const char *item)
{
return true;
} // MojoGui_gtkplus2_progress
Expand Down
12 changes: 7 additions & 5 deletions gui_macosx.c
Expand Up @@ -136,27 +136,29 @@ static void MojoGui_macosx_stop(void)


static int MojoGui_macosx_readme(const char *name, const uint8 *data,
size_t len, boolean can_go_back,
boolean can_go_forward)
size_t len, boolean can_back,
boolean can_fwd)
{
STUBBED("macosx readme");
return 1;
} // MojoGui_macosx_readme


static int MojoGui_macosx_options(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward)
boolean can_back, boolean can_fwd)
{
// !!! FIXME: write me.
STUBBED("macosx options");
return 1;
} // MojoGui_macosx_options

static char *MojoGui_macosx_destination(const char **recommends, int reccount,
boolean can_go_back, boolean can_go_fwd)
static char *MojoGui_macosx_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
// !!! FIXME: write me.
STUBBED("macosx destination");
*command = 1;
return entry->xstrdup("/Applications");
} // MojoGui_macosx_destination

Expand Down
26 changes: 15 additions & 11 deletions gui_stdio.c
Expand Up @@ -137,8 +137,8 @@ static void MojoGui_stdio_stop(void)


static int MojoGui_stdio_readme(const char *name, const uint8 *data,
size_t datalen, boolean can_go_back,
boolean can_go_forward)
size_t datalen, boolean can_back,
boolean can_fwd)
{
boolean getout = false;
int retval = -1;
Expand All @@ -148,7 +148,7 @@ static int MojoGui_stdio_readme(const char *name, const uint8 *data,
while (!getout)
{
printf("%s\n%s\n", name, (const char *) data);
if ((len = readstr(NULL, buf, sizeof (buf), can_go_back, true)) < 0)
if ((len = readstr(NULL, buf, sizeof (buf), can_back, true)) < 0)
getout = true;
else if (len == 0)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ static void print_options(MojoGuiSetupOptions *opts, int *line, int level)


static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
boolean can_go_back, boolean can_go_forward)
boolean can_back, boolean can_fwd)
{
const char *prompt = entry->xstrdup(entry->_("Choose number to change."));
const char *inst_opts_str = entry->xstrdup(entry->_("Install options:"));
Expand All @@ -250,7 +250,7 @@ static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
print_options(opts, &line, 1);
printf("\n");

if ((len = readstr(prompt, buf, sizeof (buf), can_go_back, true)) < 0)
if ((len = readstr(prompt, buf, sizeof (buf), can_back, true)) < 0)
getout = true;
else if (len == 0)
{
Expand All @@ -276,8 +276,9 @@ static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
} // MojoGui_stdio_options


static char *MojoGui_stdio_destination(const char **recommends, int reccount,
boolean can_go_back, boolean can_go_fwd)
static char *MojoGui_stdio_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
const char *instdeststr = entry->xstrdup(entry->_("Install destination:"));
const char *prompt = NULL;
Expand All @@ -287,30 +288,33 @@ static char *MojoGui_stdio_destination(const char **recommends, int reccount,
int len = 0;
int i = 0;

if (reccount > 0)
*command = -1;

if (recnum > 0)
prompt = entry->xstrdup(entry->_("Choose install destination by number, or enter your own."));
else
prompt = entry->xstrdup(entry->_("Enter path where files will be installed."));

while (!getout)
{
printf("\n\n%s\n", instdeststr);
for (i = 0; i < reccount; i++)
for (i = 0; i < recnum; i++)
printf(" %2d %s\n", i+1, recommends[i]);
printf("\n");

if ((len = readstr(prompt, buf, sizeof (buf), can_go_back, false)) < 0)
if ((len = readstr(prompt, buf, sizeof (buf), can_back, false)) < 0)
getout = true;
else if (len > 0)
{
char *endptr = NULL;
int target = (int) strtol(buf, &endptr, 10);
// complete string was a valid number?
if ((*endptr == '\0') && (target > 0) && (target <= reccount))
if ((*endptr == '\0') && (target > 0) && (target <= recnum))
retval = entry->xstrdup(recommends[target-1]);
else
retval = entry->xstrdup(buf);

*command = 1;
getout = true;
} // else
} // while
Expand Down
6 changes: 4 additions & 2 deletions lua_glue.c
Expand Up @@ -1093,6 +1093,7 @@ static int luahook_gui_destination(lua_State *L)
char **recommend = NULL;
size_t reccount = 0;
char *rc = NULL;
int command = 0;

if (lua_istable(L, 1))
{
Expand All @@ -1113,11 +1114,12 @@ static int luahook_gui_destination(lua_State *L)
} // if

rc = GGui->destination((const char **) recommend, reccount,
can_go_back, can_go_fwd);
&command, can_go_back, can_go_fwd);

retvalNumber(L, command);
retvalString(L, rc); // may push nil.
free(rc);
return 1;
return 2;
} // luahook_gui_destination


Expand Down
11 changes: 5 additions & 6 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -502,13 +502,12 @@ local function do_install(install)
local recommend = install.recommended_destinations
-- (recommend) becomes an upvalue in this function.
stages[#stages+1] = function(thisstage, maxstage)
local x = MojoSetup.gui.destination(recommend, thisstage, maxstage)
-- !!! FIXME: need back/forward/cancel.
if x == nil then
return -1 -- go back
local rc, dst
rc, dst = MojoSetup.gui.destination(recommend, thisstage, maxstage)
if rc == 1 then
set_destination(dst)
end
set_destination(x)
return 1 -- go forward
return rc
end
end

Expand Down

0 comments on commit 1e63a1d

Please sign in to comment.