| 2601 | void MythThemedMenu::doMenu() |
| 2602 | { |
| 2603 | int allowsd = gContext->GetNumSetting("AllowQuitShutdown"); |
| 2604 | |
| 2605 | if ( allowsd != 0 && allowsd !=4 ) |
| 2606 | { |
| 2607 | if (m_menuPopup) |
| 2608 | return; |
| 2609 | QString label = "System Menu"; |
| 2610 | MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); |
| 2611 | m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup"); |
| 2612 | if (m_menuPopup->Create()) |
| 2613 | mainStack->AddScreen(m_menuPopup); |
| 2614 | |
| 2615 | m_menuPopup->SetReturnEvent(this,"popmenu"); |
| 2616 | m_menuPopup->AddButton("Shutdown"); |
| 2617 | m_menuPopup->AddButton("Reboot"); |
| 2618 | m_menuPopup->AddButton("Cancel"); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | void MythThemedMenu::customEvent(QCustomEvent *event) |
| 2623 | { |
| 2624 | if (event->type() == kMythDialogBoxCompletionEventType) |
| 2625 | { |
| 2626 | DialogCompletionEvent *dce = |
| 2627 | dynamic_cast<DialogCompletionEvent*>(event); |
| 2628 | |
| 2629 | QString resultid= dce->GetId(); |
| 2630 | int buttonnum = dce->GetResult(); |
| 2631 | |
| 2632 | if (buttonnum == 0) |
| 2633 | { |
| 2634 | QString halt_cmd = gContext->GetSetting("HaltCommand", |
| 2635 | "sudo /sbin/halt -p"); |
| 2636 | if (!halt_cmd.isEmpty()) |
| 2637 | system(halt_cmd.ascii()); |
| 2638 | } |
| 2639 | |
| 2640 | if (buttonnum == 1) |
| 2641 | { |
| 2642 | QString reboot_cmd = gContext->GetSetting("RebootCommand", |
| 2643 | "sudo /sbin/reboot"); |
| 2644 | if (!reboot_cmd.isEmpty()) |
| 2645 | system(reboot_cmd.ascii()); |
| 2646 | } |
| 2647 | |
| 2648 | m_menuPopup = NULL; |
| 2649 | } |
| 2650 | } |