| 300 | void MythThemedMenu::doMenu() |
| 301 | { |
| 302 | |
| 303 | if (m_menuPopup) |
| 304 | return; |
| 305 | int allowsd = GetMythDB()->GetNumSetting("AllowQuitShutdown"); |
| 306 | int override_menu = GetMythDB()->GetNumSetting("OverRideExitMenu"); |
| 307 | QString label = "System Menu"; |
| 308 | MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); |
| 309 | m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup"); |
| 310 | if (m_menuPopup->Create()) |
| 311 | mainStack->AddScreen(m_menuPopup); |
| 312 | if ( override_menu == 0 ) |
| 313 | { |
| 314 | if ( allowsd != 0 && allowsd !=4 ) |
| 315 | { |
| 316 | m_menuPopup->SetReturnEvent(this,"popmenu_exit"); |
| 317 | m_menuPopup->AddButton("Shutdown"); |
| 318 | m_menuPopup->AddButton("Reboot"); |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | m_menuPopup->SetReturnEvent(this,"popmenu_noexit"); |
| 323 | } |
| 324 | } |
| 325 | if ( override_menu == 5 ) |
| 326 | { // reboot |
| 327 | m_menuPopup->SetReturnEvent(this,"popmenu_reboot"); |
| 328 | m_menuPopup->AddButton("Reboot"); |
| 329 | } |
| 330 | else if ( override_menu == 2 || override_menu == 4 ) |
| 331 | { // shutdown |
| 332 | m_menuPopup->SetReturnEvent(this,"popmenu_shutdown"); |
| 333 | m_menuPopup->AddButton("Shutdown"); |
| 334 | } |
| 335 | else if ( override_menu == 3 || override_menu == 6 ) |
| 336 | { // both |
| 337 | m_menuPopup->SetReturnEvent(this,"popmenu_exit"); |
| 338 | m_menuPopup->AddButton("Shutdown"); |
| 339 | m_menuPopup->AddButton("Reboot"); |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | m_menuPopup->SetReturnEvent(this,"popmenu_noexit"); |
| 344 | } |
| 345 | |
| 346 | m_menuPopup->AddButton("About"); |
| 347 | m_menuPopup->AddButton("Cancel"); |
| 348 | |
| 349 | } |
| 350 | void MythThemedMenu::aboutScreen() |
| 351 | { |
| 352 | |
| 353 | extern const char *myth_source_version; |
| 354 | extern const char *myth_source_path; |
| 355 | QString distro_line; |
| 356 | distro_line=""; |
| 357 | |
| 358 | QFile file("/etc/os_myth_release"); |
| 359 | if ( file.open(QFile::ReadOnly)) |
| 360 | { |
| 361 | QTextStream t( &file ); // use a text stream |
| 362 | distro_line = t.readLine(); |
| 363 | file.close(); |
| 364 | } |
| 365 | |
| 366 | QString label = ""; |
| 367 | label.append(QObject::tr("Revision: ") + myth_source_version + " \n Branch:" + myth_source_path + "\n" + distro_line ); |
| 368 | |
| 369 | MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); |
| 370 | m_menuPopup = new MythDialogBox(label, mainStack, "About"); |
| 371 | if (m_menuPopup->Create()) |
| 372 | mainStack->AddScreen(m_menuPopup); |
| 373 | |
| 374 | m_menuPopup->SetReturnEvent(this,"About"); |
| 375 | m_menuPopup->AddButton("OK!"); |
| 376 | |
| 377 | } |
| 378 | |
| 379 | void MythThemedMenu::customEvent(QEvent *event) |
| 380 | { |
| 381 | if (event->type() == kMythDialogBoxCompletionEventType) |
| 382 | { |
| 383 | DialogCompletionEvent *dce = |
| 384 | dynamic_cast<DialogCompletionEvent*>(event); |
| 385 | QString resultid= dce->GetId(); |
| 386 | int buttonnum = dce->GetResult(); |
| 387 | QString halt_cmd=GetMythDB()->GetSetting("HaltCommand"); |
| 388 | QString reboot_cmd=GetMythDB()->GetSetting("RebootCommand"); |
| 389 | |
| 390 | if (resultid == "popmenu_exit") |
| 391 | { |
| 392 | if (buttonnum == 0) |
| 393 | { |
| 394 | if (!halt_cmd.isEmpty() ) |
| 395 | system(halt_cmd.toAscii()); |
| 396 | } |
| 397 | |
| 398 | if (buttonnum == 1) |
| 399 | { |
| 400 | if (!reboot_cmd.isEmpty() ) |
| 401 | system(reboot_cmd.toAscii()); |
| 402 | } |
| 403 | |
| 404 | if (buttonnum == 2) |
| 405 | { |
| 406 | aboutScreen(); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | if (resultid == "popmenu_noexit") |
| 411 | { |
| 412 | if (buttonnum == 0) |
| 413 | aboutScreen(); |
| 414 | } |
| 415 | |
| 416 | if (resultid == "popmenu_reboot") |
| 417 | { |
| 418 | if (buttonnum == 0) |
| 419 | { |
| 420 | if (!reboot_cmd.isEmpty() ) |
| 421 | system(reboot_cmd.toAscii()); |
| 422 | } |
| 423 | |
| 424 | if (buttonnum == 1) |
| 425 | { |
| 426 | aboutScreen(); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (resultid == "popmenu_shutdown") |
| 431 | { |
| 432 | if (buttonnum == 0) |
| 433 | { |
| 434 | if (!halt_cmd.isEmpty() ) |
| 435 | system(halt_cmd.toAscii()); |
| 436 | } |
| 437 | |
| 438 | if (buttonnum == 1) |
| 439 | { |
| 440 | aboutScreen(); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | m_menuPopup = NULL; |
| 445 | } |
| 446 | } |
| 447 | |