Changeset afb4025 in mainline
- Timestamp:
- 2025-01-20T17:32:37Z (34 hours ago)
- Branches:
- master
- Children:
- 2e08f2b6
- Parents:
- 41dcabc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/shutdown-dlg/shutdown-dlg.c
r41dcabc rafb4025 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <ui/fixed.h> 42 42 #include <ui/label.h> 43 #include <ui/msgdialog.h> 43 44 #include <ui/resource.h> 44 45 #include <ui/ui.h> … … 48 49 static void wnd_close(ui_window_t *, void *); 49 50 static errno_t bg_wnd_paint(ui_window_t *, void *); 51 static void shutdown_progress_destroy(shutdown_progress_t *); 52 static errno_t shutdown_failed_msg_create(shutdown_dlg_t *); 50 53 51 54 static ui_window_cb_t bg_window_cb = { … … 64 67 .shutdown_complete = sd_shutdown_complete, 65 68 .shutdown_failed = sd_shutdown_failed 69 }; 70 71 static void shutdown_failed_msg_button(ui_msg_dialog_t *, void *, unsigned); 72 static void shutdown_failed_msg_close(ui_msg_dialog_t *, void *); 73 74 static ui_msg_dialog_cb_t shutdown_failed_msg_cb = { 75 .button = shutdown_failed_msg_button, 76 .close = shutdown_failed_msg_close 66 77 }; 67 78 … … 90 101 91 102 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); 94 108 ui_unlock(sddlg->ui); 95 109 } … … 135 149 136 150 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 */ 158 static 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(¶ms); 165 params.caption = "Shutdown failed"; 166 params.text = "The system failed to shut down properly."; 167 168 rc = ui_msg_dialog_create(sddlg->ui, ¶ms, &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 */ 183 static 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 */ 197 static 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); 137 203 } 138 204 … … 245 311 static void shutdown_progress_destroy(shutdown_progress_t *progress) 246 312 { 313 if (progress == NULL) 314 return; 315 247 316 ui_window_destroy(progress->window); 248 317 free(progress); … … 254 323 ui_t *ui = NULL; 255 324 ui_wnd_params_t params; 256 ui_window_t *window = NULL;257 325 shutdown_dlg_t sddlg; 258 326 errno_t rc; … … 285 353 sddlg.ui = ui; 286 354 287 rc = ui_window_create(ui, ¶ms, & window);355 rc = ui_window_create(ui, ¶ms, &sddlg.bgwindow); 288 356 if (rc != EOK) { 289 357 printf("Error creating window.\n"); … … 291 359 } 292 360 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); 295 362 296 363 rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color); … … 300 367 } 301 368 302 rc = ui_window_paint( window);369 rc = ui_window_paint(sddlg.bgwindow); 303 370 if (rc != EOK) { 304 371 printf("Error painting window.\n"); … … 325 392 326 393 shutdown_progress_destroy(sddlg.progress); 327 ui_window_destroy(window); 394 if (sddlg.bgwindow != NULL) 395 ui_window_destroy(sddlg.bgwindow); 328 396 system_close(sddlg.system); 329 397 gfx_color_delete(sddlg.bg_color); … … 336 404 if (sddlg.bg_color != NULL) 337 405 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); 340 408 if (ui != NULL) 341 409 ui_destroy(ui);
Note:
See TracChangeset
for help on using the changeset viewer.