Esempio n. 1
0
void MythThemedMenu::customEvent(QEvent *event)
{
    if (event->type() == DialogCompletionEvent::kEventType)
    {
        DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);

        QString resultid = dce->GetId();
        //int buttonnum = dce->GetResult();
        QString halt_cmd = GetMythDB()->GetSetting("HaltCommand");
        QString reboot_cmd = GetMythDB()->GetSetting("RebootCommand");

        if (resultid == "popmenu")
        {
            QString action = dce->GetData().toString();
            if (action == "shutdown")
            {
                if (!halt_cmd.isEmpty())
                    myth_system(halt_cmd);
            }
            else if (action == "reboot")
            {
                if (!reboot_cmd.isEmpty())
                    myth_system(reboot_cmd);
            }
            else if (action == "about")
            {
                aboutScreen();
            }
            else if (action == "standby")
            {
                QString arg("standby_mode");
                m_state->m_callback(m_state->m_callbackdata, arg);
            }
        }
        else if (resultid == "password")
        {
            QString text = dce->GetResultText();
            MythUIButtonListItem *item = m_buttonList->GetItemCurrent();
            ThemedButton button = item->GetData().value<ThemedButton>();
            QString password = GetMythDB()->GetSetting(button.password);
            if (text == password)
            {
                QString timestamp_setting = QString("%1Time").arg(button.password);
                QDateTime curr_time = QDateTime::currentDateTime();
                QString last_time_stamp = curr_time.toString(Qt::TextDate);
                GetMythDB()->SetSetting(timestamp_setting, last_time_stamp);
                GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp);
                buttonAction(item, true);
            }
        }

        m_menuPopup = NULL;
    }
}
Esempio n. 2
0
/** \brief keyboard/LIRC event handler.
 *
 *  This translates key presses through the "Main Menu" context into MythTV
 *  actions and then handles them as appropriate.
 */
bool MythThemedMenu::keyPressEvent(QKeyEvent *event)
{
    if (m_ignorekeys)
        return false;

    m_ignorekeys = true;

    MythUIType *type = GetFocusWidget();
    if (type && type->keyPressEvent(event))
    {
        m_ignorekeys = false;
        return true;
    }

    QStringList actions;
    bool handled = false;

    handled = GetMythMainWindow()->TranslateKeyPress("Main Menu", event,
                                                     actions);

    for (int i = 0; i < actions.size() && !handled; i++)
    {
        QString action = actions[i];
        handled = true;

        if (action == "ESCAPE" || action == "EXIT" || action == "EXITPROMPT")
        {
            bool    callbacks  = m_state->m_callback;
            bool    lastScreen = (GetMythMainWindow()->GetMainStack()
                                                     ->TotalScreens() == 1);
            QString menuaction = "UPMENU";
            QString selExit    = "EXITING_APP_PROMPT";
            if (action == "EXIT")
                selExit = "EXITING_APP";

            if (!m_allocedstate)
                handleAction(menuaction);
            else if (m_state->m_killable)
            {
                m_wantpop = true;
                if (callbacks)
                {
                    QString sel = "EXITING_MENU";
                    m_state->m_callback(m_state->m_callbackdata, sel);
                }

                if (lastScreen)
                {
                    if (callbacks)
                        m_state->m_callback(m_state->m_callbackdata, selExit);
                    QCoreApplication::exit();
                }
            }
            else if ((action == "EXIT" || action == "EXITPROMPT" ||
                      (action == "ESCAPE" &&
                       (QCoreApplication::applicationName() ==
                        MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen)
            {
                if (callbacks)
                    m_state->m_callback(m_state->m_callbackdata, selExit);
                else
                {
                    QCoreApplication::exit();
                    m_wantpop = true;
                }
            }
        }
        else if (action == "HELP")
        {
            aboutScreen();
        }
        else if (action == "EJECT")
        {
            handleAction(action);
        }
        else
            handled = false;
    }

    if (!handled && MythScreenType::keyPressEvent(event))
        handled = true;

    m_ignorekeys = false;

    if (m_wantpop)
        m_ScreenStack->PopScreen();

    return handled;
}
Esempio n. 3
0
void MythThemedMenu::customEvent(QEvent *event)
{
    if (event->type() == DialogCompletionEvent::kEventType)
    {
        DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);

        QString resultid = dce->GetId();
        int buttonnum = dce->GetResult();
        QString halt_cmd = GetMythDB()->GetSetting("HaltCommand");
        QString reboot_cmd = GetMythDB()->GetSetting("RebootCommand");

        if (resultid == "popmenu_exit")
        {
            switch (buttonnum)
            {
                case 0:
                    if (!halt_cmd.isEmpty())
                        myth_system(halt_cmd);
                    break;
                case 1:
                    if (!reboot_cmd.isEmpty())
                        myth_system(reboot_cmd);
                    break;
                case 2:
                    aboutScreen();
                    break;
            }
        }
        else if (resultid == "popmenu_noexit")
        {
            if (buttonnum == 0)
                aboutScreen();
        }
        else if (resultid == "popmenu_reboot")
        {
            switch (buttonnum)
            {
                case 0:
                    if (!reboot_cmd.isEmpty())
                        myth_system(reboot_cmd);
                    break;
                case 1:
                    aboutScreen();
                    break;
            }
        }
        else if (resultid == "popmenu_shutdown")
        {
            switch (buttonnum)
            {
                case 0:
                    if (!halt_cmd.isEmpty())
                        myth_system(halt_cmd);
                    break;
                case 1:
                    aboutScreen();
                    break;
            }
        }
        else if (resultid == "password")
        {
            QString text = dce->GetResultText();
            MythUIButtonListItem *item = m_buttonList->GetItemCurrent();
            ThemedButton button = item->GetData().value<ThemedButton>();
            QString password = GetMythDB()->GetSetting(button.password);
            if (text == password)
            {
                QString timestamp_setting = QString("%1Time").arg(button.password);
                QDateTime curr_time = QDateTime::currentDateTime();
                QString last_time_stamp = curr_time.toString(Qt::TextDate);
                GetMythDB()->SetSetting(timestamp_setting, last_time_stamp);
                GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp);
                buttonAction(item, true);
            }
        }

        m_menuPopup = NULL;
    }
}