Skip to content

Commit

Permalink
UI interface needs to be able to disable the cancel button in the pro…
Browse files Browse the repository at this point in the history
…gress

 page, so people can't cancel uninstalls in progress.
  • Loading branch information
icculus committed Jan 24, 2008
1 parent e787bb6 commit d5ff3ad
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
7 changes: 4 additions & 3 deletions gui.h
Expand Up @@ -80,7 +80,7 @@ struct MojoGuiSplash
#define MOJOGUI_ENTRY_POINT_STR DEFINE_TO_STR(MOJOGUI_ENTRY_POINT)

// Increment this value when MojoGui's structure changes.
#define MOJOGUI_INTERFACE_REVISION 3
#define MOJOGUI_INTERFACE_REVISION 4

typedef struct MojoGui MojoGui;
struct MojoGui
Expand All @@ -102,7 +102,7 @@ struct MojoGui
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);
int percent, const char *item, boolean can_cancel);
void (*final)(const char *msg);
};

Expand Down Expand Up @@ -146,7 +146,8 @@ 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); \
int percent, const char *item, \
boolean can_cancel); \
static void MojoGui_##module##_final(const char *msg); \
const MojoGui *MojoGuiPlugin_##module(int rev, const MojoSetupEntryPoints *e) \
{ \
Expand Down
24 changes: 14 additions & 10 deletions gui_gtkplus2.c
Expand Up @@ -67,7 +67,8 @@ static volatile enum


static void prepare_wizard(const char *name, WizardPages page,
boolean can_back, boolean can_fwd)
boolean can_back, boolean can_fwd,
boolean can_cancel)
{
char *markup = g_markup_printf_escaped(
"<span size='large' weight='bold'>%s</span>",
Expand All @@ -81,6 +82,7 @@ static void prepare_wizard(const char *name, WizardPages page,

gtk_widget_set_sensitive(back, can_back);
gtk_widget_set_sensitive(next, can_fwd);
gtk_widget_set_sensitive(cancel, can_cancel);
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), (gint) page);

assert(click_value == CLICK_NONE);
Expand Down Expand Up @@ -122,10 +124,10 @@ static int pump_events(void)


static int run_wizard(const char *name, WizardPages page,
boolean can_back, boolean can_fwd)
boolean can_back, boolean can_fwd, boolean can_cancel)
{
int retval = CLICK_NONE;
prepare_wizard(name, page, can_back, can_fwd);
prepare_wizard(name, page, can_back, can_fwd, can_cancel);
while (retval == ((int) CLICK_NONE))
retval = wait_event();

Expand Down Expand Up @@ -589,7 +591,7 @@ static int MojoGui_gtkplus2_readme(const char *name, const uint8 *data,
{
GtkTextBuffer *textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(readme));
gtk_text_buffer_set_text(textbuf, (const gchar *) data, datalen);
return run_wizard(name, PAGE_README, can_back, can_fwd);
return run_wizard(name, PAGE_README, can_back, can_fwd, true);
} // MojoGui_gtkplus2_readme


Expand Down Expand Up @@ -735,7 +737,9 @@ static int MojoGui_gtkplus2_options(MojoGuiSetupOptions *opts,

build_options(opts, box, TRUE);

retval = run_wizard(entry->_("Options"), PAGE_OPTIONS, can_back, can_fwd);
retval = run_wizard(entry->_("Options"), PAGE_OPTIONS,
can_back, can_fwd, true);

gtk_widget_destroy(box);
return retval;
} // MojoGui_gtkplus2_options
Expand All @@ -755,7 +759,7 @@ static char *MojoGui_gtkplus2_destination(const char **recommends, int recnum,
gtk_combo_box_set_active (combo, 0);

*command = run_wizard(entry->_("Destination"), PAGE_DESTINATION,
can_back, can_fwd);
can_back, can_fwd, true);

str = gtk_combo_box_get_active_text(combo);

Expand Down Expand Up @@ -791,7 +795,8 @@ 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,
boolean can_cancel)
{
static uint32 lastTicks = 0;
const uint32 ticks = entry->ticks();
Expand All @@ -810,7 +815,7 @@ static boolean MojoGui_gtkplus2_progress(const char *type, const char *component
lastTicks = ticks;
} // if

prepare_wizard(type, PAGE_PROGRESS, false, false);
prepare_wizard(type, PAGE_PROGRESS, false, false, can_cancel);
rc = pump_events();
assert( (rc == ((int) CLICK_CANCEL)) || (rc == ((int) CLICK_NONE)) );
return (rc != CLICK_CANCEL);
Expand All @@ -821,9 +826,8 @@ static void MojoGui_gtkplus2_final(const char *msg)
{
gtk_widget_hide(next);
gtk_widget_show(finish);
gtk_widget_set_sensitive(cancel, FALSE);
gtk_label_set_text(GTK_LABEL(finallabel), msg);
run_wizard(entry->_("Finish"), PAGE_FINAL, false, true);
run_wizard(entry->_("Finish"), PAGE_FINAL, false, true, false);
} // MojoGui_gtkplus2_final

// end of gui_gtkplus2.c ...
Expand Down
3 changes: 2 additions & 1 deletion gui_macosx.c
Expand Up @@ -197,7 +197,8 @@ static boolean MojoGui_macosx_insertmedia(const char *medianame)


static int MojoGui_macosx_progress(const char *type, const char *component,
int percent, const char *item)
int percent, const char *item,
boolean can_cancel)
{
// !!! FIXME: write me.
STUBBED("macosx progress");
Expand Down
16 changes: 11 additions & 5 deletions gui_ncurses.c
Expand Up @@ -81,6 +81,7 @@ typedef struct

static char *lastProgressType = NULL;
static char *lastComponent = NULL;
static boolean lastCanCancel = false;
static uint32 percentTicks = 0;
static char *title = NULL;
static MojoBox *progressBox = NULL;
Expand Down Expand Up @@ -486,7 +487,7 @@ static int upkeepBox(MojoBox **_mojobox, int ch)
case '\n':
case KEY_ENTER:
case ' ':
return mojobox->hoverover;
return (mojobox->buttoncount <= 0) ? -1 : mojobox->hoverover;

case '\e':
return mojobox->buttoncount-1;
Expand Down Expand Up @@ -1357,7 +1358,8 @@ static boolean MojoGui_ncurses_insertmedia(const char *medianame)


static boolean MojoGui_ncurses_progress(const char *type, const char *component,
int percent, const char *item)
int percent, const char *item,
boolean can_cancel)
{
const uint32 now = entry->ticks();
boolean rebuild = (progressBox == NULL);
Expand All @@ -1367,21 +1369,25 @@ static boolean MojoGui_ncurses_progress(const char *type, const char *component,
if ( (lastComponent == NULL) ||
(strcmp(lastComponent, component) != 0) ||
(lastProgressType == NULL) ||
(strcmp(lastProgressType, type) != 0) )
(strcmp(lastProgressType, type) != 0) ||
(lastCanCancel != can_cancel) )
{
free(lastProgressType);
free(lastComponent);
lastProgressType = entry->xstrdup(type);
lastComponent = entry->xstrdup(component);
lastCanCancel = can_cancel;
rebuild = true;
} // if

if (rebuild)
{
int w, h;
char *text = NULL;
char *localized_cancel = entry->xstrdup(entry->_("Cancel"));
char *localized_cancel =
(can_cancel) ? entry->xstrdup(entry->_("Cancel")) : NULL;
char *buttons[] = { localized_cancel };
const int buttoncount = (can_cancel) ? 1 : 0;
char *spacebuf = NULL;
getmaxyx(stdscr, h, w);
w -= 10;
Expand All @@ -1396,7 +1402,7 @@ static boolean MojoGui_ncurses_progress(const char *type, const char *component,
strcat(text, "\n\n ");

freeBox(progressBox, false);
progressBox = makeBox(type, text, buttons, 1, true, true);
progressBox = makeBox(type, text, buttons, buttoncount, true, true);
free(text);
free(localized_cancel);
} // if
Expand Down
3 changes: 2 additions & 1 deletion gui_stdio.c
Expand Up @@ -600,7 +600,8 @@ static boolean MojoGui_stdio_insertmedia(const char *medianame)


static boolean MojoGui_stdio_progress(const char *type, const char *component,
int percent, const char *item)
int percent, const char *item,
boolean can_cancel)
{
const uint32 now = entry->ticks();

Expand Down
3 changes: 2 additions & 1 deletion gui_www.c
Expand Up @@ -1015,7 +1015,8 @@ static boolean MojoGui_www_insertmedia(const char *medianame)


static boolean MojoGui_www_progress(const char *type, const char *component,
int percent, const char *item)
int percent, const char *item,
boolean can_cancel)
{
return true;
} // MojoGui_www_progress
Expand Down
6 changes: 4 additions & 2 deletions lua_glue.c
Expand Up @@ -1465,9 +1465,11 @@ static int luahook_gui_progress(lua_State *L)
{
const char *type = luaL_checkstring(L, 1);
const char *component = luaL_checkstring(L, 2);
int percent = luaL_checkint(L, 3);
const int percent = luaL_checkint(L, 3);
const char *item = luaL_checkstring(L, 4);
return retvalBoolean(L, GGui->progress(type, component, percent, item));
const boolean canstop = lua_toboolean(L, 5);
const boolean rc = GGui->progress(type, component, percent, item, canstop);
return retvalBoolean(L, rc);
} // luahook_gui_progress


Expand Down

0 comments on commit d5ff3ad

Please sign in to comment.