VirtualBox

Changeset 45246 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 29, 2013 9:20:51 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84627
Message:

FE/Qt: Message-center: Basic inter-threading support for all the messages.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r45245 r45246  
    9595                             const QString &strButton3 /* = QString() */) const
    9696{
    97     /* Choose the 'default' button: */
    98     if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0)
    99         iButton1 = QIMessageBox::Ok | QIMessageBox::Default;
    100 
    101     /* Check if message-box was auto-confirmed before: */
    102     CVirtualBox vbox;
    103     QStringList confirmedMessageList;
    104     if (pcszAutoConfirmId)
    105     {
    106         vbox = vboxGlobal().virtualBox();
    107         confirmedMessageList = vbox.GetExtraData(GUI_SuppressMessages).split(',');
    108         if (confirmedMessageList.contains(pcszAutoConfirmId))
    109         {
    110             int iResultCode = AutoConfirmed;
    111             if (iButton1 & QIMessageBox::Default)
    112                 iResultCode |= (iButton1 & QIMessageBox::ButtonMask);
    113             if (iButton2 & QIMessageBox::Default)
    114                 iResultCode |= (iButton2 & QIMessageBox::ButtonMask);
    115             if (iButton3 & QIMessageBox::Default)
    116                 iResultCode |= (iButton3 & QIMessageBox::ButtonMask);
    117             return iResultCode;
    118         }
    119     }
    120 
    121     /* Choose title and icon: */
    122     QString title;
    123     QIMessageBox::Icon icon;
    124     switch (type)
    125     {
    126         default:
    127         case MessageType_Info:
    128             title = tr("VirtualBox - Information", "msg box title");
    129             icon = QIMessageBox::Information;
    130             break;
    131         case MessageType_Question:
    132             title = tr("VirtualBox - Question", "msg box title");
    133             icon = QIMessageBox::Question;
    134             break;
    135         case MessageType_Warning:
    136             title = tr("VirtualBox - Warning", "msg box title");
    137             icon = QIMessageBox::Warning;
    138             break;
    139         case MessageType_Error:
    140             title = tr("VirtualBox - Error", "msg box title");
    141             icon = QIMessageBox::Critical;
    142             break;
    143         case MessageType_Critical:
    144             title = tr("VirtualBox - Critical Error", "msg box title");
    145             icon = QIMessageBox::Critical;
    146             break;
    147         case MessageType_GuruMeditation:
    148             title = "VirtualBox - Guru Meditation"; /* don't translate this */
    149             icon = QIMessageBox::GuruMeditation;
    150             break;
    151     }
    152 
    153     /* Create message-box: */
    154     QWidget *pMessageBoxParent = mwManager().realParentWindow(pParent);
    155     QPointer<QIMessageBox> pMessageBox = new QIMessageBox(title, strMessage, icon,
    156                                                           iButton1, iButton2, iButton3,
    157                                                           pMessageBoxParent, pcszAutoConfirmId);
    158     mwManager().registerNewParent(pMessageBox, pMessageBoxParent);
    159 
    160     /* Prepare auto-confirmation check-box: */
    161     if (pcszAutoConfirmId)
    162     {
    163         pMessageBox->setFlagText(tr("Do not show this message again", "msg box flag"));
    164         pMessageBox->setFlagChecked(false);
    165     }
    166 
    167     /* Configure details: */
    168     if (!strDetails.isEmpty())
    169         pMessageBox->setDetailsText(strDetails);
    170 
    171     /* Configure button-text: */
    172     if (!strButton1.isNull())
    173         pMessageBox->setButtonText(0, strButton1);
    174     if (!strButton2.isNull())
    175         pMessageBox->setButtonText(1, strButton2);
    176     if (!strButton3.isNull())
    177         pMessageBox->setButtonText(2, strButton3);
    178 
    179     /* Show message-box: */
    180     int iResultCode = pMessageBox->exec();
    181 
    182     /* Make sure message-box still valid: */
    183     if (!pMessageBox)
    184         return iResultCode;
    185 
    186     /* Remember auto-confirmation check-box value: */
    187     if (pcszAutoConfirmId)
    188     {
    189         if (pMessageBox->isFlagChecked())
    190         {
    191             confirmedMessageList << pcszAutoConfirmId;
    192             vbox.SetExtraData(GUI_SuppressMessages, confirmedMessageList.join(","));
    193         }
    194     }
    195 
    196     /* Delete message-box: */
    197     delete pMessageBox;
    198 
    199     /* Return result-code: */
    200     return iResultCode;
     97    /* If this is NOT a GUI thread: */
     98    if (thread() != QThread::currentThread())
     99    {
     100        /* We have to throw a blocking signal
     101         * to show a message-box in the GUI thread: */
     102        emit sigToShowMessageBox(pParent, type,
     103                                 strMessage, strDetails,
     104                                 iButton1, iButton2, iButton3,
     105                                 strButton1, strButton2, strButton3,
     106                                 QString(pcszAutoConfirmId));
     107        /* Inter-thread communications are not yet implemented: */
     108        return 0;
     109    }
     110    /* In usual case we can chow a message-box directly: */
     111    return showMessageBox(pParent, type,
     112                          strMessage, strDetails,
     113                          iButton1, iButton2, iButton3,
     114                          strButton1, strButton2, strButton3,
     115                          QString(pcszAutoConfirmId));
    201116}
    202117
     
    28562771}
    28572772
     2773void UIMessageCenter::sltShowMessageBox(QWidget *pParent, MessageType type,
     2774                                        const QString &strMessage, const QString &strDetails,
     2775                                        int iButton1, int iButton2, int iButton3,
     2776                                        const QString &strButton1, const QString &strButton2, const QString &strButton3,
     2777                                        const QString &strAutoConfirmId) const
     2778{
     2779    /* Now we can show a message-box directly: */
     2780    showMessageBox(pParent, type,
     2781                   strMessage, strDetails,
     2782                   iButton1, iButton2, iButton3,
     2783                   strButton1, strButton2, strButton3,
     2784                   strAutoConfirmId);
     2785}
     2786
    28582787void UIMessageCenter::sltCannotCreateHostInterface(const CHost &host, QWidget *pParent)
    28592788{
     
    30282957    qRegisterMetaType<StorageSlot>();
    30292958
     2959    /* Prepare interthread connection: */
     2960    qRegisterMetaType<MessageType>();
     2961    connect(this, SIGNAL(sigToShowMessageBox(QWidget*, MessageType,
     2962                                             const QString&, const QString&,
     2963                                             int, int, int,
     2964                                             const QString&, const QString&, const QString&,
     2965                                             const QString&)),
     2966            this, SLOT(sltShowMessageBox(QWidget*, MessageType,
     2967                                         const QString&, const QString&,
     2968                                         int, int, int,
     2969                                         const QString&, const QString&, const QString&,
     2970                                         const QString&)),
     2971            Qt::BlockingQueuedConnection);
     2972
    30302973    /* Prepare required connections: */
    3031     connect(this, SIGNAL(sigCannotCreateHostInterface(const CHost&, QWidget*)),
    3032             this, SLOT(sltCannotCreateHostInterface(const CHost&, QWidget*)),
    3033             Qt::BlockingQueuedConnection);
    3034     connect(this, SIGNAL(sigCannotCreateHostInterface(const CProgress&, QWidget*)),
    3035             this, SLOT(sltCannotCreateHostInterface(const CProgress&, QWidget*)),
    3036             Qt::BlockingQueuedConnection);
    3037     connect(this, SIGNAL(sigCannotRemoveHostInterface(const CHost&, const CHostNetworkInterface&, QWidget*)),
    3038             this, SLOT(sltCannotRemoveHostInterface(const CHost&, const CHostNetworkInterface&, QWidget*)),
    3039             Qt::BlockingQueuedConnection);
    3040     connect(this, SIGNAL(sigCannotRemoveHostInterface(const CProgress&, const CHostNetworkInterface&, QWidget*)),
    3041             this, SLOT(sltCannotRemoveHostInterface(const CProgress&, const CHostNetworkInterface&, QWidget*)),
    3042             Qt::BlockingQueuedConnection);
    30432974    connect(this, SIGNAL(sigCannotAttachDevice(const CMachine&, UIMediumType, const QString&, const StorageSlot&, QWidget*)),
    30442975            this, SLOT(sltCannotAttachDevice(const CMachine&, UIMediumType, const QString&, const StorageSlot&, QWidget*)),
     
    31603091}
    31613092
     3093int UIMessageCenter::showMessageBox(QWidget *pParent, MessageType type,
     3094                                    const QString &strMessage, const QString &strDetails,
     3095                                    int iButton1, int iButton2, int iButton3,
     3096                                    const QString &strButton1, const QString &strButton2, const QString &strButton3,
     3097                                    const QString &strAutoConfirmId) const
     3098{
     3099    /* Choose the 'default' button: */
     3100    if (iButton1 == 0 && iButton2 == 0 && iButton3 == 0)
     3101        iButton1 = QIMessageBox::Ok | QIMessageBox::Default;
     3102
     3103    /* Check if message-box was auto-confirmed before: */
     3104    CVirtualBox vbox;
     3105    QStringList confirmedMessageList;
     3106    if (!strAutoConfirmId.isEmpty())
     3107    {
     3108        vbox = vboxGlobal().virtualBox();
     3109        confirmedMessageList = vbox.GetExtraData(GUI_SuppressMessages).split(',');
     3110        if (confirmedMessageList.contains(strAutoConfirmId))
     3111        {
     3112            int iResultCode = AutoConfirmed;
     3113            if (iButton1 & QIMessageBox::Default)
     3114                iResultCode |= (iButton1 & QIMessageBox::ButtonMask);
     3115            if (iButton2 & QIMessageBox::Default)
     3116                iResultCode |= (iButton2 & QIMessageBox::ButtonMask);
     3117            if (iButton3 & QIMessageBox::Default)
     3118                iResultCode |= (iButton3 & QIMessageBox::ButtonMask);
     3119            return iResultCode;
     3120        }
     3121    }
     3122
     3123    /* Choose title and icon: */
     3124    QString title;
     3125    QIMessageBox::Icon icon;
     3126    switch (type)
     3127    {
     3128        default:
     3129        case MessageType_Info:
     3130            title = tr("VirtualBox - Information", "msg box title");
     3131            icon = QIMessageBox::Information;
     3132            break;
     3133        case MessageType_Question:
     3134            title = tr("VirtualBox - MessageType_Question", "msg box title");
     3135            icon = QIMessageBox::Question;
     3136            break;
     3137        case MessageType_Warning:
     3138            title = tr("VirtualBox - MessageType_Warning", "msg box title");
     3139            icon = QIMessageBox::Warning;
     3140            break;
     3141        case MessageType_Error:
     3142            title = tr("VirtualBox - MessageType_Error", "msg box title");
     3143            icon = QIMessageBox::Critical;
     3144            break;
     3145        case MessageType_Critical:
     3146            title = tr("VirtualBox - MessageType_Critical MessageType_Error", "msg box title");
     3147            icon = QIMessageBox::Critical;
     3148            break;
     3149        case MessageType_GuruMeditation:
     3150            title = "VirtualBox - Guru Meditation"; /* don't translate this */
     3151            icon = QIMessageBox::GuruMeditation;
     3152            break;
     3153    }
     3154
     3155    /* Create message-box: */
     3156    QWidget *pMessageBoxParent = mwManager().realParentWindow(pParent);
     3157    QPointer<QIMessageBox> pMessageBox = new QIMessageBox(title, strMessage, icon,
     3158                                                          iButton1, iButton2, iButton3,
     3159                                                          pMessageBoxParent, strAutoConfirmId.toAscii().constData());
     3160    mwManager().registerNewParent(pMessageBox, pMessageBoxParent);
     3161
     3162    /* Prepare auto-confirmation check-box: */
     3163    if (!strAutoConfirmId.isEmpty())
     3164    {
     3165        pMessageBox->setFlagText(tr("Do not show this message again", "msg box flag"));
     3166        pMessageBox->setFlagChecked(false);
     3167    }
     3168
     3169    /* Configure details: */
     3170    if (!strDetails.isEmpty())
     3171        pMessageBox->setDetailsText(strDetails);
     3172
     3173    /* Configure button-text: */
     3174    if (!strButton1.isNull())
     3175        pMessageBox->setButtonText(0, strButton1);
     3176    if (!strButton2.isNull())
     3177        pMessageBox->setButtonText(1, strButton2);
     3178    if (!strButton3.isNull())
     3179        pMessageBox->setButtonText(2, strButton3);
     3180
     3181    /* Show message-box: */
     3182    int iResultCode = pMessageBox->exec();
     3183
     3184    /* Make sure message-box still valid: */
     3185    if (!pMessageBox)
     3186        return iResultCode;
     3187
     3188    /* Remember auto-confirmation check-box value: */
     3189    if (!strAutoConfirmId.isEmpty())
     3190    {
     3191        if (pMessageBox->isFlagChecked())
     3192        {
     3193            confirmedMessageList << strAutoConfirmId;
     3194            vbox.SetExtraData(GUI_SuppressMessages, confirmedMessageList.join(","));
     3195        }
     3196    }
     3197
     3198    /* Delete message-box: */
     3199    delete pMessageBox;
     3200
     3201    /* Return result-code: */
     3202    return iResultCode;
     3203}
     3204
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r45245 r45246  
    5757
    5858signals:
     59
     60    /* Notifier: Interthreading stuff: */
     61    void sigToShowMessageBox(QWidget *pParent, MessageType type,
     62                             const QString &strMessage, const QString &strDetails,
     63                             int iButton1, int iButton2, int iButton3,
     64                             const QString &strButton1, const QString &strButton2, const QString &strButton3,
     65                             const QString &strAutoConfirmId) const;
    5966
    6067    /* Stuff supporting interthreading: */
     
    422429private slots:
    423430
     431    /* Handler: Interthreading stuff: */
     432    void sltShowMessageBox(QWidget *pParent, MessageType type,
     433                           const QString &strMessage, const QString &strDetails,
     434                           int iButton1, int iButton2, int iButton3,
     435                           const QString &strButton1, const QString &strButton2, const QString &strButton3,
     436                           const QString &strAutoConfirmId) const;
     437
    424438    /* Stuff supporting interthreading: */
    425439    void sltCannotCreateHostInterface(const CHost &host, QWidget *pParent);
     
    452466    static QString errorInfoToString(const COMErrorInfo &info, HRESULT wrapperRC = S_OK);
    453467
     468    /* Helper: Message-box stuff: */
     469    int showMessageBox(QWidget *pParent, MessageType type,
     470                       const QString &strMessage, const QString &strDetails,
     471                       int iButton1, int iButton2, int iButton3,
     472                       const QString &strButton1, const QString &strButton2, const QString &strButton3,
     473                       const QString &strAutoConfirmId) const;
     474
    454475    /* Variables: */
    455476    QStringList m_warnings;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette