Changeset afb4025 in mainline


Ignore:
Timestamp:
2025-01-20T17:32:37Z (34 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
2e08f2b6
Parents:
41dcabc
Message:

Show error message when UI shutdown fails.

File:
1 edited

Legend:

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

    r41dcabc rafb4025  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141#include <ui/fixed.h>
    4242#include <ui/label.h>
     43#include <ui/msgdialog.h>
    4344#include <ui/resource.h>
    4445#include <ui/ui.h>
     
    4849static void wnd_close(ui_window_t *, void *);
    4950static errno_t bg_wnd_paint(ui_window_t *, void *);
     51static void shutdown_progress_destroy(shutdown_progress_t *);
     52static errno_t shutdown_failed_msg_create(shutdown_dlg_t *);
    5053
    5154static ui_window_cb_t bg_window_cb = {
     
    6467        .shutdown_complete = sd_shutdown_complete,
    6568        .shutdown_failed = sd_shutdown_failed
     69};
     70
     71static void shutdown_failed_msg_button(ui_msg_dialog_t *, void *, unsigned);
     72static void shutdown_failed_msg_close(ui_msg_dialog_t *, void *);
     73
     74static ui_msg_dialog_cb_t shutdown_failed_msg_cb = {
     75        .button = shutdown_failed_msg_button,
     76        .close = shutdown_failed_msg_close
    6677};
    6778
     
    90101
    91102        ui_lock(sddlg->ui);
    92         (void)ui_label_set_text(sddlg->progress->label, "Shutdown failed.");
    93         (void)ui_window_paint(sddlg->progress->window);
     103        shutdown_progress_destroy(sddlg->progress);
     104        sddlg->progress = NULL;
     105        ui_window_destroy(sddlg->bgwindow);
     106        sddlg->bgwindow = NULL;
     107        (void)shutdown_failed_msg_create(sddlg);
    94108        ui_unlock(sddlg->ui);
    95109}
     
    135149
    136150        return EOK;
     151}
     152
     153/** Create 'shutdown failed' message dialog.
     154 *
     155 * @param sddlg Shutdown dialog
     156 * @return EOK on success or an error code
     157 */
     158static errno_t shutdown_failed_msg_create(shutdown_dlg_t *sddlg)
     159{
     160        ui_msg_dialog_params_t params;
     161        ui_msg_dialog_t *dialog;
     162        errno_t rc;
     163
     164        ui_msg_dialog_params_init(&params);
     165        params.caption = "Shutdown failed";
     166        params.text = "The system failed to shut down properly.";
     167
     168        rc = ui_msg_dialog_create(sddlg->ui, &params, &dialog);
     169        if (rc != EOK)
     170                return rc;
     171
     172        ui_msg_dialog_set_cb(dialog, &shutdown_failed_msg_cb, sddlg);
     173
     174        return EOK;
     175}
     176
     177/** Shutdown failed message dialog button press.
     178 *
     179 * @param dialog Message dialog
     180 * @param arg Argument (ui_demo_t *)
     181 * @param bnum Button number
     182 */
     183static void shutdown_failed_msg_button(ui_msg_dialog_t *dialog,
     184    void *arg, unsigned bnum)
     185{
     186        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
     187
     188        ui_msg_dialog_destroy(dialog);
     189        ui_quit(sddlg->ui);
     190}
     191
     192/** Message dialog close request.
     193 *
     194 * @param dialog Message dialog
     195 * @param arg Argument (ui_demo_t *)
     196 */
     197static void shutdown_failed_msg_close(ui_msg_dialog_t *dialog, void *arg)
     198{
     199        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
     200
     201        ui_msg_dialog_destroy(dialog);
     202        ui_quit(sddlg->ui);
    137203}
    138204
     
    245311static void shutdown_progress_destroy(shutdown_progress_t *progress)
    246312{
     313        if (progress == NULL)
     314                return;
     315
    247316        ui_window_destroy(progress->window);
    248317        free(progress);
     
    254323        ui_t *ui = NULL;
    255324        ui_wnd_params_t params;
    256         ui_window_t *window = NULL;
    257325        shutdown_dlg_t sddlg;
    258326        errno_t rc;
     
    285353        sddlg.ui = ui;
    286354
    287         rc = ui_window_create(ui, &params, &window);
     355        rc = ui_window_create(ui, &params, &sddlg.bgwindow);
    288356        if (rc != EOK) {
    289357                printf("Error creating window.\n");
     
    291359        }
    292360
    293         ui_window_set_cb(window, &bg_window_cb, (void *) &sddlg);
    294         sddlg.bgwindow = window;
     361        ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *) &sddlg);
    295362
    296363        rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color);
     
    300367        }
    301368
    302         rc = ui_window_paint(window);
     369        rc = ui_window_paint(sddlg.bgwindow);
    303370        if (rc != EOK) {
    304371                printf("Error painting window.\n");
     
    325392
    326393        shutdown_progress_destroy(sddlg.progress);
    327         ui_window_destroy(window);
     394        if (sddlg.bgwindow != NULL)
     395                ui_window_destroy(sddlg.bgwindow);
    328396        system_close(sddlg.system);
    329397        gfx_color_delete(sddlg.bg_color);
     
    336404        if (sddlg.bg_color != NULL)
    337405                gfx_color_delete(sddlg.bg_color);
    338         if (window != NULL)
    339                 ui_window_destroy(window);
     406        if (sddlg.bgwindow != NULL)
     407                ui_window_destroy(sddlg.bgwindow);
    340408        if (ui != NULL)
    341409                ui_destroy(ui);
Note: See TracChangeset for help on using the changeset viewer.