VirtualBox

Ignore:
Timestamp:
Jul 26, 2011 1:46:39 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt4: add a "copy to clipboard" button to the error message boxes

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.cpp

    r31319 r38185  
    3838#include <QToolButton>
    3939#include <QKeyEvent>
     40#include <QClipboard>
    4041
    4142#ifdef Q_WS_MAC
     
    164165        connect (mButton2PB, SIGNAL (clicked()), SLOT (done2()));
    165166
     167    /* If this is an error message add an "Copy to clipboard" button for easier
     168     * bug reports. */
     169    if (aIcon == QIMessageBox::Critical)
     170    {
     171        QPushButton *pCopyButton = createButton(Copy);
     172        pCopyButton->setToolTip(tr("Copy all errors to the clipboard"));
     173        connect(pCopyButton, SIGNAL(clicked()), SLOT(copy()));
     174    }
     175
    166176    /* this call is a must -- it initializes mFlagCB and mSpacer */
    167177    setDetailsShown (false);
     
    258268    switch (aButton & ButtonMask)
    259269    {
    260         case Ok:        text = tr ("OK"); role = QDialogButtonBox::AcceptRole; break;
    261         case Yes:       text = tr ("Yes"); role = QDialogButtonBox::YesRole; break;
    262         case No:        text = tr ("No"); role = QDialogButtonBox::NoRole; break;
    263         case Cancel:    text = tr ("Cancel"); role = QDialogButtonBox::RejectRole; break;
    264         case Ignore:    text = tr ("Ignore"); role = QDialogButtonBox::AcceptRole; break;
     270        case Ok:     text = tr("OK");     role = QDialogButtonBox::AcceptRole; break;
     271        case Yes:    text = tr("Yes");    role = QDialogButtonBox::YesRole; break;
     272        case No:     text = tr("No");     role = QDialogButtonBox::NoRole; break;
     273        case Cancel: text = tr("Cancel"); role = QDialogButtonBox::RejectRole; break;
     274        case Ignore: text = tr("Ignore"); role = QDialogButtonBox::AcceptRole; break;
     275        case Copy:   text = tr("Copy");   role = QDialogButtonBox::ActionRole; break;
    265276        default:
    266             AssertMsgFailed (("Type %d is not implemented", aButton));
     277            AssertMsgFailed(("Type %d is not implemented", aButton));
    267278            return NULL;
    268279    }
     
    455466}
    456467
     468void QIMessageBox::copy() const
     469{
     470    /* Create the error string with all errors. First the html version. */
     471    QString strError = "<html><body><p>" + mText + "</p>";
     472    for (size_t i = 0; i < mDetailsList.size(); ++i)
     473        strError += mDetailsList.at(i).first + mDetailsList.at(i).second + "<br>";
     474    strError += "</body></html>";
     475    strError.remove(QRegExp("</+qt>"));
     476    strError = strError.replace(QRegExp("&nbsp;"), " ");
     477    /* Create a new mime data object holding both the html and the plain text version. */
     478    QMimeData *pMd = new QMimeData();
     479    pMd->setHtml(strError);
     480    /* Replace all the html entities. */
     481    strError = strError.replace(QRegExp("<br>|</tr>"), "\n");
     482    strError = strError.replace(QRegExp("</p>"), "\n\n");
     483    strError = strError.remove(QRegExp("<[^>]*>"));
     484    pMd->setText(strError);
     485    /* Add the mime data to the global clipboard. */
     486    QClipboard *pClipboard = QApplication::clipboard();
     487    pClipboard->setMimeData(pMd);
     488}
     489
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h

    r36011 r38185  
    6666    {
    6767        NoButton = 0, Ok = 1, Cancel = 2, Yes = 3, No = 4, Abort = 5,
    68         Retry = 6, Ignore = 7, YesAll = 8, NoAll = 9,
     68        Retry = 6, Ignore = 7, YesAll = 8, NoAll = 9, Copy = 10,
    6969        ButtonMask = 0xFF,
    7070
     
    114114    void reject();
    115115
     116    void copy() const;
     117
    116118private:
    117119
Note: See TracChangeset for help on using the changeset viewer.

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