Changeset 2e08f2b6 in mainline
- Timestamp:
- 2025-01-20T17:35:12Z (34 hours ago)
- Branches:
- master
- Children:
- 5162f6e
- Parents:
- afb4025
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/shutdown-dlg/shutdown-dlg.c
rafb4025 r2e08f2b6 50 50 static errno_t bg_wnd_paint(ui_window_t *, void *); 51 51 static void shutdown_progress_destroy(shutdown_progress_t *); 52 static errno_t shutdown_confirm_msg_create(shutdown_dlg_t *); 52 53 static errno_t shutdown_failed_msg_create(shutdown_dlg_t *); 54 static errno_t shutdown_start(shutdown_dlg_t *); 53 55 54 56 static ui_window_cb_t bg_window_cb = { … … 67 69 .shutdown_complete = sd_shutdown_complete, 68 70 .shutdown_failed = sd_shutdown_failed 71 }; 72 73 static void shutdown_confirm_msg_button(ui_msg_dialog_t *, void *, unsigned); 74 static void shutdown_confirm_msg_close(ui_msg_dialog_t *, void *); 75 76 static ui_msg_dialog_cb_t shutdown_confirm_msg_cb = { 77 .button = shutdown_confirm_msg_button, 78 .close = shutdown_confirm_msg_close 69 79 }; 70 80 … … 151 161 } 152 162 163 /** Create shutdown confirmation dialog. 164 * 165 * @param sddlg Shutdown dialog 166 * @return EOK on success or an error code 167 */ 168 static 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(¶ms); 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, ¶ms, &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 153 189 /** Create 'shutdown failed' message dialog. 154 190 * … … 175 211 } 176 212 177 /** Shutdown failedmessage dialog button press.213 /** Shutdown confirm message dialog button press. 178 214 * 179 215 * @param dialog Message dialog … … 181 217 * @param bnum Button number 182 218 */ 219 static 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 */ 237 static 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 */ 183 251 static void shutdown_failed_msg_button(ui_msg_dialog_t *dialog, 184 252 void *arg, unsigned bnum) … … 190 258 } 191 259 192 /** Message dialog close request.260 /** Shutdown failed message dialog close request. 193 261 * 194 262 * @param dialog Message dialog … … 318 386 } 319 387 388 static 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; 409 error: 410 return rc; 411 } 412 320 413 /** Run shutdown dialog on display. */ 321 414 static errno_t shutdown_dlg(const char *display_spec) 322 415 { 323 416 ui_t *ui = NULL; 417 shutdown_dlg_t sddlg; 324 418 ui_wnd_params_t params; 325 shutdown_dlg_t sddlg;326 419 errno_t rc; 327 420 … … 333 426 goto error; 334 427 } 428 429 sddlg.ui = ui; 335 430 336 431 ui_wnd_params_init(¶ms); … … 339 434 params.placement = ui_wnd_place_full_screen; 340 435 params.flags |= ui_wndf_topmost | ui_wndf_nofocus; 341 if (ui_is_textmode( ui)) {436 if (ui_is_textmode(sddlg.ui)) { 342 437 params.rect.p0.x = 0; 343 438 params.rect.p0.y = 0; … … 351 446 } 352 447 353 sddlg.ui = ui; 354 355 rc = ui_window_create(ui, ¶ms, &sddlg.bgwindow); 448 rc = ui_window_create(sddlg.ui, ¶ms, &sddlg.bgwindow); 356 449 if (rc != EOK) { 357 450 printf("Error creating window.\n"); … … 359 452 } 360 453 361 ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *) 454 ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *)&sddlg); 362 455 363 456 rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color); … … 373 466 } 374 467 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); 390 469 391 470 ui_run(ui); … … 394 473 if (sddlg.bgwindow != NULL) 395 474 ui_window_destroy(sddlg.bgwindow); 396 system_close(sddlg.system); 475 if (sddlg.system != NULL) 476 system_close(sddlg.system); 397 477 gfx_color_delete(sddlg.bg_color); 398 478 ui_destroy(ui); -
uspace/lib/ui/include/types/ui/msgdialog.h
rafb4025 r2e08f2b6 58 58 } ui_msg_dialog_choice_t; 59 59 60 /** Message dialog flags */ 61 typedef 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 60 68 /** Message dialog parameters */ 61 69 typedef struct { … … 66 74 /** The choice that the user is given */ 67 75 ui_msg_dialog_choice_t choice; 76 /** Flags */ 77 ui_msg_dialog_flags_t flags; 68 78 } ui_msg_dialog_params_t; 69 79 -
uspace/lib/ui/src/msgdialog.c
rafb4025 r2e08f2b6 111 111 ui_wnd_params_init(&wparams); 112 112 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; 113 117 114 118 /* FIXME: Auto layout */
Note:
See TracChangeset
for help on using the changeset viewer.