Changes in / [455241b:74353920] in mainline
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/shutdown-dlg/shutdown-dlg.c
r455241b r74353920 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_confirm_msg_create(shutdown_dlg_t *); 53 static errno_t shutdown_failed_msg_create(shutdown_dlg_t *); 54 static errno_t shutdown_start(shutdown_dlg_t *); 50 55 51 56 static ui_window_cb_t bg_window_cb = { … … 64 69 .shutdown_complete = sd_shutdown_complete, 65 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 79 }; 80 81 static void shutdown_failed_msg_button(ui_msg_dialog_t *, void *, unsigned); 82 static void shutdown_failed_msg_close(ui_msg_dialog_t *, void *); 83 84 static ui_msg_dialog_cb_t shutdown_failed_msg_cb = { 85 .button = shutdown_failed_msg_button, 86 .close = shutdown_failed_msg_close 66 87 }; 67 88 … … 90 111 91 112 ui_lock(sddlg->ui); 92 (void)ui_label_set_text(sddlg->progress->label, "Shutdown failed."); 93 (void)ui_window_paint(sddlg->progress->window); 113 shutdown_progress_destroy(sddlg->progress); 114 sddlg->progress = NULL; 115 ui_window_destroy(sddlg->bgwindow); 116 sddlg->bgwindow = NULL; 117 (void)shutdown_failed_msg_create(sddlg); 94 118 ui_unlock(sddlg->ui); 95 119 } … … 135 159 136 160 return EOK; 161 } 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 189 /** Create 'shutdown failed' message dialog. 190 * 191 * @param sddlg Shutdown dialog 192 * @return EOK on success or an error code 193 */ 194 static errno_t shutdown_failed_msg_create(shutdown_dlg_t *sddlg) 195 { 196 ui_msg_dialog_params_t params; 197 ui_msg_dialog_t *dialog; 198 errno_t rc; 199 200 ui_msg_dialog_params_init(¶ms); 201 params.caption = "Shutdown failed"; 202 params.text = "The system failed to shut down properly."; 203 204 rc = ui_msg_dialog_create(sddlg->ui, ¶ms, &dialog); 205 if (rc != EOK) 206 return rc; 207 208 ui_msg_dialog_set_cb(dialog, &shutdown_failed_msg_cb, sddlg); 209 210 return EOK; 211 } 212 213 /** Shutdown confirm message dialog button press. 214 * 215 * @param dialog Message dialog 216 * @param arg Argument (ui_demo_t *) 217 * @param bnum Button number 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 */ 251 static void shutdown_failed_msg_button(ui_msg_dialog_t *dialog, 252 void *arg, unsigned bnum) 253 { 254 shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg; 255 256 ui_msg_dialog_destroy(dialog); 257 ui_quit(sddlg->ui); 258 } 259 260 /** Shutdown failed message dialog close request. 261 * 262 * @param dialog Message dialog 263 * @param arg Argument (ui_demo_t *) 264 */ 265 static void shutdown_failed_msg_close(ui_msg_dialog_t *dialog, void *arg) 266 { 267 shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg; 268 269 ui_msg_dialog_destroy(dialog); 270 ui_quit(sddlg->ui); 137 271 } 138 272 … … 162 296 params.rect.p0.x = 0; 163 297 params.rect.p0.y = 0; 164 params.rect.p1.x = 24;298 params.rect.p1.x = 64; 165 299 params.rect.p1.y = 5; 166 300 } else { … … 245 379 static void shutdown_progress_destroy(shutdown_progress_t *progress) 246 380 { 381 if (progress == NULL) 382 return; 383 247 384 ui_window_destroy(progress->window); 248 385 free(progress); 249 386 } 250 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 251 413 /** Run shutdown dialog on display. */ 252 414 static errno_t shutdown_dlg(const char *display_spec) 253 415 { 254 416 ui_t *ui = NULL; 417 shutdown_dlg_t sddlg; 255 418 ui_wnd_params_t params; 256 ui_window_t *window = NULL;257 shutdown_dlg_t sddlg;258 419 errno_t rc; 259 420 … … 265 426 goto error; 266 427 } 428 429 sddlg.ui = ui; 267 430 268 431 ui_wnd_params_init(¶ms); … … 271 434 params.placement = ui_wnd_place_full_screen; 272 435 params.flags |= ui_wndf_topmost | ui_wndf_nofocus; 273 if (ui_is_textmode(ui)) { 274 params.rect.p0.x = 0; 275 params.rect.p0.y = 0; 276 params.rect.p1.x = 24; 277 params.rect.p1.y = 5; 436 /* params.rect.p0.x = 0; 437 params.rect.p0.y = 0; 438 params.rect.p1.x = 1; 439 params.rect.p1.y = 1;*/ 440 441 rc = ui_window_create(sddlg.ui, ¶ms, &sddlg.bgwindow); 442 if (rc != EOK) { 443 printf("Error creating window.\n"); 444 goto error; 445 } 446 447 ui_window_set_cb(sddlg.bgwindow, &bg_window_cb, (void *)&sddlg); 448 449 if (ui_is_textmode(sddlg.ui)) { 450 rc = gfx_color_new_ega(0x17, &sddlg.bg_color); 451 if (rc != EOK) { 452 printf("Error allocating color.\n"); 453 goto error; 454 } 278 455 } else { 279 params.rect.p0.x = 0; 280 params.rect.p0.y = 0; 281 params.rect.p1.x = 300; 282 params.rect.p1.y = 60; 283 } 284 285 sddlg.ui = ui; 286 287 rc = ui_window_create(ui, ¶ms, &window); 288 if (rc != EOK) { 289 printf("Error creating window.\n"); 290 goto error; 291 } 292 293 ui_window_set_cb(window, &bg_window_cb, (void *) &sddlg); 294 sddlg.bgwindow = window; 295 296 rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color); 297 if (rc != EOK) { 298 printf("Error allocating color.\n"); 299 goto error; 300 } 301 302 rc = ui_window_paint(window); 456 rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sddlg.bg_color); 457 if (rc != EOK) { 458 printf("Error allocating color.\n"); 459 goto error; 460 } 461 } 462 463 rc = ui_window_paint(sddlg.bgwindow); 303 464 if (rc != EOK) { 304 465 printf("Error painting window.\n"); … … 306 467 } 307 468 308 rc = shutdown_progress_create(&sddlg, &sddlg.progress); 309 if (rc != EOK) 310 return rc; 311 312 rc = system_open(SYSTEM_DEFAULT, &sd_system_cb, &sddlg, &sddlg.system); 313 if (rc != EOK) { 314 printf("Failed opening system control service.\n"); 315 goto error; 316 } 317 318 rc = system_shutdown(sddlg.system); 319 if (rc != EOK) { 320 printf("Failed requesting system shutdown.\n"); 321 goto error; 322 } 469 (void)shutdown_confirm_msg_create(&sddlg); 323 470 324 471 ui_run(ui); 325 472 326 473 shutdown_progress_destroy(sddlg.progress); 327 ui_window_destroy(window); 328 system_close(sddlg.system); 474 if (sddlg.bgwindow != NULL) 475 ui_window_destroy(sddlg.bgwindow); 476 if (sddlg.system != NULL) 477 system_close(sddlg.system); 329 478 gfx_color_delete(sddlg.bg_color); 330 479 ui_destroy(ui); … … 336 485 if (sddlg.bg_color != NULL) 337 486 gfx_color_delete(sddlg.bg_color); 338 if ( window != NULL)339 ui_window_destroy( window);487 if (sddlg.bgwindow != NULL) 488 ui_window_destroy(sddlg.bgwindow); 340 489 if (ui != NULL) 341 490 ui_destroy(ui); -
uspace/app/taskbar/taskbar.sif
r455241b r74353920 25 25 <entry caption="~D~isplay Configuration" cmd="/app/display-cfg -d %d" terminal="n"> 26 26 </entry> 27 <entry caption="Ta ~s~kbarConfiguration" cmd="/app/taskbar-cfg -d %d" terminal="n">27 <entry caption="Taskba~r~ Configuration" cmd="/app/taskbar-cfg -d %d" terminal="n"> 28 28 </entry> 29 29 <entry separator="y"> … … 37 37 <entry caption="~A~bout HelenOS" cmd="/app/aboutos -d %d" terminal="n"> 38 38 </entry> 39 <entry caption="~S~hut Down..." cmd="/app/shutdown-dlg -d %d" terminal="n"> 40 </entry> 39 41 </entries> 40 42 </sif> -
uspace/lib/ata/src/ata.c
r455241b r74353920 260 260 if (rc != EOK) { 261 261 ata_msg_error(chan, "Unable to remove device %d.", i); 262 break; 262 fibril_mutex_unlock(&chan->lock); 263 return rc; 263 264 } 264 265 } … … 266 267 ata_bd_fini_irq(chan); 267 268 fibril_mutex_unlock(&chan->lock); 269 free(chan); 268 270 269 271 return rc; -
uspace/lib/c/generic/thread/fibril_synch.c
r455241b r74353920 263 263 futex_lock(&fibril_synch_futex); 264 264 265 if (!frw->writers ) {265 if (!frw->writers && list_empty(&frw->waiters)) { 266 266 /* Consider the first reader the owner. */ 267 267 if (frw->readers++ == 0) -
uspace/lib/ui/include/types/ui/msgdialog.h
r455241b r74353920 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
r455241b r74353920 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.