Ticket #5615: mythdialogbox.diff

File mythdialogbox.diff, 4.7 KB (added by paulh, 17 years ago)

Non blocking popup patch

  • libs/libmythui/mythdialogbox.cpp

     
    44#include "mythdialogbox.h"
    55#include "mythmainwindow.h"
    66#include "mythfontproperties.h"
     7#include "mythverbose.h"
    78
    89MythDialogBox::MythDialogBox(const QString &text,
    910                             MythScreenStack *parent, const char *name)
     
    203204
    204205/////////////////////////////////////////////////////////////////
    205206
     207MythConfirmationDialog2::MythConfirmationDialog2(MythScreenStack *parent,
     208                                               const QString &message,
     209                                               bool showCancel)
     210                       : MythScreenType(parent, "mythconfirmpopup")
     211{
     212    m_message = message;
     213    m_showCancel = showCancel;
     214
     215    m_result = -1;
     216    m_initialized = false;
     217}
     218
     219MythConfirmationDialog2::MythConfirmationDialog2(const QString &message,
     220                                                 bool showCancel)
     221    : MythScreenType(GetMythMainWindow()->GetStack("popup stack"),
     222                     "mythconfirmpopup")
     223{
     224    m_message = message;
     225    m_showCancel = showCancel;
     226
     227    m_result = -1;
     228    m_initialized = false;
     229}
     230
     231bool MythConfirmationDialog2::Create(void)
     232{
     233    if (!CopyWindowFromBase("MythConfirmationDialog", this))
     234        return false;
     235
     236    MythUIText *messageText = dynamic_cast<MythUIText *>
     237                                            (GetChild("message"));
     238    MythUIButton *okButton = dynamic_cast<MythUIButton *>
     239                                         (GetChild("ok"));
     240    MythUIButton *cancelButton = dynamic_cast<MythUIButton *>
     241                                         (GetChild("cancel"));
     242
     243    if (!messageText || !okButton || !cancelButton)
     244        return false;
     245
     246    if (m_showCancel)
     247    {
     248        connect(cancelButton, SIGNAL(buttonPressed()), SLOT(Cancel()));
     249    }
     250    else
     251        cancelButton->SetVisible(false);
     252
     253    connect(okButton, SIGNAL(buttonPressed()), SLOT(Confirm()));
     254
     255    okButton->SetText(tr("Ok"));
     256    cancelButton->SetText(tr("Cancel"));
     257
     258    messageText->SetText(m_message);
     259
     260    BuildFocusList();
     261
     262    return true;
     263}
     264
     265bool MythConfirmationDialog2::Exec(void)
     266{
     267    if (!m_initialized)
     268    {
     269        if (!Create())
     270        {
     271            VERBOSE(VB_IMPORTANT, "MythConfirmationDialog: Failed to create dialog");
     272            return false;
     273        }
     274
     275        m_initialized = true;
     276    }
     277
     278    GetScreenStack()->AddScreen(this);
     279
     280    while (m_result == -1)
     281    {
     282        qApp->processEvents();
     283        usleep(500);
     284    }
     285
     286    Close();
     287
     288    return (m_result == 1);
     289}
     290
     291void MythConfirmationDialog2::Confirm()
     292{
     293    m_result = 1;
     294}
     295
     296void MythConfirmationDialog2::Cancel()
     297{
     298    m_result = 0;
     299}
     300
     301bool MythConfirmationDialog2::keyPressEvent(QKeyEvent *event)
     302{
     303    if (GetFocusWidget()->keyPressEvent(event))
     304        return true;
     305
     306    bool handled = false;
     307    QStringList actions;
     308    if (GetMythMainWindow()->TranslateKeyPress("qt", event, actions))
     309    {
     310        for (int i = 0; i < actions.size() && !handled; i++)
     311        {
     312            QString action = actions[i];
     313            handled = true;
     314
     315            if (action == "ESCAPE" || action == "MENU")
     316            {
     317                m_result = 0;
     318            }
     319            else
     320                handled = false;
     321        }
     322    }
     323
     324    if (!handled)
     325        MythScreenType::keyPressEvent(event);
     326
     327    // we don't want another screen to get these while the popup is visible
     328    return true;
     329}
     330
     331
     332/////////////////////////////////////////////////////////////////
     333
    206334MythTextInputDialog::MythTextInputDialog(MythScreenStack *parent,
    207335                                         const QString &message,
    208336                                         InputFilter filter,
  • libs/libmythui/mythdialogbox.h

     
    9393    void Cancel();
    9494};
    9595
     96class MythConfirmationDialog2 : public MythScreenType
     97{
     98    Q_OBJECT
     99
     100  public:
     101    MythConfirmationDialog2(MythScreenStack *parent, const QString &message,
     102                           bool showCancel = true);
     103    MythConfirmationDialog2(const QString &message, bool showCancel = true);
     104
     105    bool Create(void);
     106    bool Exec(void);
     107
     108    virtual bool keyPressEvent(QKeyEvent *event);
     109
     110  private:
     111    QString m_message;
     112    bool m_showCancel;
     113    int  m_result;
     114    bool m_initialized;
     115
     116  private slots:
     117    void Confirm(void);
     118    void Cancel();
     119};
     120
    96121class MythTextInputDialog : public MythScreenType
    97122{
    98123    Q_OBJECT