Ignore:
File:
1 edited

Legend:

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

    r0ae9e18 rf35749e  
    4141#include <ui/fixed.h>
    4242#include <ui/label.h>
    43 #include <ui/list.h>
    4443#include <ui/msgdialog.h>
    4544#include <ui/resource.h>
    46 #include <ui/selectdialog.h>
    4745#include <ui/ui.h>
    4846#include <ui/window.h>
     
    5250static errno_t bg_wnd_paint(ui_window_t *, void *);
    5351static void shutdown_progress_destroy(shutdown_progress_t *);
    54 static errno_t shutdown_confirm_create(shutdown_dlg_t *);
     52static errno_t shutdown_confirm_msg_create(shutdown_dlg_t *);
    5553static errno_t shutdown_failed_msg_create(shutdown_dlg_t *);
    56 static errno_t shutdown_start(shutdown_dlg_t *, sd_action_t);
     54static errno_t shutdown_start(shutdown_dlg_t *);
    5755
    5856static ui_window_cb_t bg_window_cb = {
     
    7371};
    7472
    75 static void shutdown_confirm_bok(ui_select_dialog_t *, void *, void *);
    76 static void shutdown_confirm_bcancel(ui_select_dialog_t *, void *);
    77 static void shutdown_confirm_close(ui_select_dialog_t *, void *);
    78 
    79 static ui_select_dialog_cb_t shutdown_confirm_cb = {
    80         .bok = shutdown_confirm_bok,
    81         .bcancel = shutdown_confirm_bcancel,
    82         .close = shutdown_confirm_close
     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
    8379};
    8480
     
    170166 * @return EOK on success or an error code
    171167 */
    172 static errno_t shutdown_confirm_create(shutdown_dlg_t *sddlg)
    173 {
    174         ui_select_dialog_params_t params;
    175         ui_select_dialog_t *dialog;
    176         ui_list_entry_attr_t attr;
    177         errno_t rc;
    178 
    179         ui_select_dialog_params_init(&params);
     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);
    180175        params.caption = "Shutdown";
    181         params.prompt = "Do you want to shut the system down?";
    182         params.flags |= usdf_topmost | usdf_center;
    183 
    184         rc = ui_select_dialog_create(sddlg->ui, &params, &dialog);
     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);
    185181        if (rc != EOK)
    186182                return rc;
    187183
    188         /* Need an entry to select */
    189         ui_list_entry_attr_init(&attr);
    190 
    191         attr.caption = "Power off";
    192         attr.arg = (void *)sd_poweroff;
    193         rc = ui_select_dialog_append(dialog, &attr);
    194         if (rc != EOK)
    195                 goto error;
    196 
    197         attr.caption = "Restart";
    198         attr.arg = (void *)sd_restart;
    199         rc = ui_select_dialog_append(dialog, &attr);
    200         if (rc != EOK)
    201                 goto error;
    202 
    203         ui_select_dialog_set_cb(dialog, &shutdown_confirm_cb, sddlg);
    204 
    205         (void)ui_select_dialog_paint(dialog);
     184        ui_msg_dialog_set_cb(dialog, &shutdown_confirm_msg_cb, sddlg);
    206185
    207186        return EOK;
    208 error:
    209         ui_select_dialog_destroy(dialog);
    210         return rc;
    211187}
    212188
     
    235211}
    236212
    237 /** Shutdown confirm dialog OK button press.
     213/** Shutdown confirm message dialog button press.
    238214 *
    239215 * @param dialog Message dialog
    240216 * @param arg Argument (ui_demo_t *)
    241  * @param earg Entry argument
    242  */
    243 static void shutdown_confirm_bok(ui_select_dialog_t *dialog, void *arg,
    244     void *earg)
     217 * @param bnum Button number
     218 */
     219static void shutdown_confirm_msg_button(ui_msg_dialog_t *dialog,
     220    void *arg, unsigned bnum)
    245221{
    246222        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
    247223
    248         ui_select_dialog_destroy(dialog);
    249 
    250         shutdown_start(sddlg, (sd_action_t)earg);
    251 }
    252 
    253 /** Shutdown confirm dialog Cancel button press.
     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.
    254233 *
    255234 * @param dialog Message dialog
    256235 * @param arg Argument (ui_demo_t *)
    257236 */
    258 static void shutdown_confirm_bcancel(ui_select_dialog_t *dialog, void *arg)
     237static void shutdown_confirm_msg_close(ui_msg_dialog_t *dialog, void *arg)
    259238{
    260239        shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
    261240
    262         ui_select_dialog_destroy(dialog);
    263         ui_quit(sddlg->ui);
    264 }
    265 
    266 /** Shutdown confirm message dialog close request.
    267  *
    268  * @param dialog Message dialog
    269  * @param arg Argument (ui_demo_t *)
    270  */
    271 static void shutdown_confirm_close(ui_select_dialog_t *dialog, void *arg)
    272 {
    273         shutdown_dlg_t *sddlg = (shutdown_dlg_t *) arg;
    274 
    275         ui_select_dialog_destroy(dialog);
     241        ui_msg_dialog_destroy(dialog);
    276242        ui_quit(sddlg->ui);
    277243}
     
    420386}
    421387
    422 /** Start shutdown.
    423  *
    424  * @param sddlg Shutdown dialog
    425  * @param action Shutdown actin
    426  * @return EOK on success or an error code
    427  */
    428 static errno_t shutdown_start(shutdown_dlg_t *sddlg, sd_action_t action)
     388static errno_t shutdown_start(shutdown_dlg_t *sddlg)
    429389{
    430390        errno_t rc;
     
    440400        }
    441401
    442         rc = EINVAL;
    443 
    444         switch (action) {
    445         case sd_poweroff:
    446                 rc = system_poweroff(sddlg->system);
    447                 break;
    448         case sd_restart:
    449                 rc = system_restart(sddlg->system);
    450                 break;
    451         }
    452 
     402        rc = system_poweroff(sddlg->system);
    453403        if (rc != EOK) {
    454404                printf("Failed requesting system shutdown.\n");
     
    519469        }
    520470
    521         (void)shutdown_confirm_create(&sddlg);
     471        (void)shutdown_confirm_msg_create(&sddlg);
    522472
    523473        ui_run(ui);
Note: See TracChangeset for help on using the changeset viewer.