Changeset 2e08f2b6 in mainline


Ignore:
Timestamp:
2025-01-20T17:35:12Z (34 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
5162f6e
Parents:
afb4025
Message:

Confirm shutdown in shutdown dialog.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/shutdown-dlg/shutdown-dlg.c

    rafb4025 r2e08f2b6  
    5050static errno_t bg_wnd_paint(ui_window_t *, void *);
    5151static void shutdown_progress_destroy(shutdown_progress_t *);
     52static errno_t shutdown_confirm_msg_create(shutdown_dlg_t *);
    5253static errno_t shutdown_failed_msg_create(shutdown_dlg_t *);
     54static errno_t shutdown_start(shutdown_dlg_t *);
    5355
    5456static ui_window_cb_t bg_window_cb = {
     
    6769        .shutdown_complete = sd_shutdown_complete,
    6870        .shutdown_failed = sd_shutdown_failed
     71};
     72
     73static void shutdown_confirm_msg_button(ui_msg_dialog_t *, void *, unsigned);
     74static void shutdown_confirm_msg_close(ui_msg_dialog_t *, void *);
     75
     76static ui_msg_dialog_cb_t shutdown_confirm_msg_cb = {
     77        .button = shutdown_confirm_msg_button,
     78        .close = shutdown_confirm_msg_close
    6979};
    7080
     
    151161}
    152162
     163/** Create shutdown confirmation dialog.
     164 *
     165 * @param sddlg Shutdown dialog
     166 * @return EOK on success or an error code
     167 */
     168static errno_t shutdown_confirm_msg_create(shutdown_dlg_t *sddlg)
     169{
     170        ui_msg_dialog_params_t params;
     171        ui_msg_dialog_t *dialog;
     172        errno_t rc;
     173
     174        ui_msg_dialog_params_init(&params);
     175        params.caption = "Shutdown";
     176        params.text = "Do you want to shut the system down?";
     177        params.choice = umdc_ok_cancel;
     178        params.flags |= umdf_topmost | umdf_center;
     179
     180        rc = ui_msg_dialog_create(sddlg->ui, &params, &dialog);
     181        if (rc != EOK)
     182                return rc;
     183
     184        ui_msg_dialog_set_cb(dialog, &shutdown_confirm_msg_cb, sddlg);
     185
     186        return EOK;
     187}
     188
    153189/** Create 'shutdown failed' message dialog.
    154190 *
     
    175211}
    176212
    177 /** Shutdown failed message dialog button press.
     213/** Shutdown confirm message dialog button press.
    178214 *
    179215 * @param dialog Message dialog
     
    181217 * @param bnum Button number
    182218 */
     219static void shutdown_confirm_msg_button(ui_msg_dialog_t *dialog,
     220    void *arg, unsigned bnum)
     221{
     222        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
     223
     224        ui_msg_dialog_destroy(dialog);
     225
     226        if (bnum == 0)
     227                shutdown_start(sddlg);
     228        else
     229                ui_quit(sddlg->ui);
     230}
     231
     232/** Shutdown confirm message dialog close request.
     233 *
     234 * @param dialog Message dialog
     235 * @param arg Argument (ui_demo_t *)
     236 */
     237static void shutdown_confirm_msg_close(ui_msg_dialog_t *dialog, void *arg)
     238{
     239        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
     240
     241        ui_msg_dialog_destroy(dialog);
     242        ui_quit(sddlg->ui);
     243}
     244
     245/** Shutdown faield message dialog button press.
     246 *
     247 * @param dialog Message dialog
     248 * @param arg Argument (ui_demo_t *)
     249 * @param bnum Button number
     250 */
    183251static void shutdown_failed_msg_button(ui_msg_dialog_t *dialog,
    184252    void *arg, unsigned bnum)
     
    190258}
    191259
    192 /** Message dialog close request.
     260/** Shutdown failed message dialog close request.
    193261 *
    194262 * @param dialog Message dialog
     
    318386}
    319387
     388static errno_t shutdown_start(shutdown_dlg_t *sddlg)
     389{
     390        errno_t rc;
     391
     392        rc = shutdown_progress_create(sddlg, &sddlg->progress);
     393        if (rc != EOK)
     394                return rc;
     395
     396        rc = system_open(SYSTEM_DEFAULT, &sd_system_cb, sddlg, &sddlg->system);
     397        if (rc != EOK) {
     398                printf("Failed opening system control service.\n");
     399                goto error;
     400        }
     401
     402        rc = system_shutdown(sddlg->system);
     403        if (rc != EOK) {
     404                printf("Failed requesting system shutdown.\n");
     405                goto error;
     406        }
     407
     408        return EOK;
     409error:
     410        return rc;
     411}
     412
    320413/** Run shutdown dialog on display. */
    321414static errno_t shutdown_dlg(const char *display_spec)
    322415{
    323416        ui_t *ui = NULL;
     417        shutdown_dlg_t sddlg;
    324418        ui_wnd_params_t params;
    325         shutdown_dlg_t sddlg;
    326419        errno_t rc;
    327420
     
    333426                goto error;
    334427        }
     428
     429        sddlg.ui = ui;
    335430
    336431        ui_wnd_params_init(&params);
     
    339434        params.placement = ui_wnd_place_full_screen;
    340435        params.flags |= ui_wndf_topmost | ui_wndf_nofocus;
    341         if (ui_is_textmode(ui)) {
     436        if (ui_is_textmode(sddlg.ui)) {
    342437                params.rect.p0.x = 0;
    343438                params.rect.p0.y = 0;
     
    351446        }
    352447
    353         sddlg.ui = ui;
    354 
    355         rc = ui_window_create(ui, &params, &sddlg.bgwindow);
     448        rc = ui_window_create(sddlg.ui, &params, &sddlg.bgwindow);
    356449        if (rc != EOK) {
    357450                printf("Error creating window.\n");
     
    359452        }
    360453
    361         ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *) &sddlg);
     454        ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *)&sddlg);
    362455
    363456        rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color);
     
    373466        }
    374467
    375         rc = shutdown_progress_create(&sddlg, &sddlg.progress);
    376         if (rc != EOK)
    377                 return rc;
    378 
    379         rc = system_open(SYSTEM_DEFAULT, &sd_system_cb, &sddlg, &sddlg.system);
    380         if (rc != EOK) {
    381                 printf("Failed opening system control service.\n");
    382                 goto error;
    383         }
    384 
    385         rc = system_shutdown(sddlg.system);
    386         if (rc != EOK) {
    387                 printf("Failed requesting system shutdown.\n");
    388                 goto error;
    389         }
     468        (void)shutdown_confirm_msg_create(&sddlg);
    390469
    391470        ui_run(ui);
     
    394473        if (sddlg.bgwindow != NULL)
    395474                ui_window_destroy(sddlg.bgwindow);
    396         system_close(sddlg.system);
     475        if (sddlg.system != NULL)
     476                system_close(sddlg.system);
    397477        gfx_color_delete(sddlg.bg_color);
    398478        ui_destroy(ui);
  • uspace/lib/ui/include/types/ui/msgdialog.h

    rafb4025 r2e08f2b6  
    5858} ui_msg_dialog_choice_t;
    5959
     60/** Message dialog flags */
     61typedef enum {
     62        /** Topmost window */
     63        umdf_topmost = 0x1,
     64        /** Place to the center of the screen */
     65        umdf_center = 0x2
     66} ui_msg_dialog_flags_t;
     67
    6068/** Message dialog parameters */
    6169typedef struct {
     
    6674        /** The choice that the user is given */
    6775        ui_msg_dialog_choice_t choice;
     76        /** Flags */
     77        ui_msg_dialog_flags_t flags;
    6878} ui_msg_dialog_params_t;
    6979
  • uspace/lib/ui/src/msgdialog.c

    rafb4025 r2e08f2b6  
    111111        ui_wnd_params_init(&wparams);
    112112        wparams.caption = params->caption;
     113        if ((params->flags & umdf_topmost) != 0)
     114                wparams.flags |= wndf_topmost;
     115        if ((params->flags & umdf_center) != 0)
     116                wparams.placement = ui_wnd_place_center;
    113117
    114118        /* FIXME: Auto layout */
Note: See TracChangeset for help on using the changeset viewer.