VirtualBox

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


Ignore:
Timestamp:
Nov 16, 2020 5:43:13 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141367
Message:

FE/Qt: bugref:9722: VirtualBox Manager: Propose user a set of external tools to generate public key if none was found.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r86894 r86896  
    2525#include <QStandardPaths>
    2626#include <QStatusBar>
     27#include <QStyle>
    2728#include <QTextEdit>
    2829#ifndef VBOX_WS_WIN
     
    3435#include "QIDialogButtonBox.h"
    3536#include "QIFileDialog.h"
     37#include "QIRichTextLabel.h"
    3638#include "UIActionPoolManager.h"
    3739#include "UICloudConsoleManager.h"
     
    4042#include "UICloudProfileManager.h"
    4143#include "UIDesktopServices.h"
     44#include "UIDesktopWidgetWatchdog.h"
    4245#include "UIErrorString.h"
    4346#include "UIExtraDataManager.h"
     
    118121private slots:
    119122
     123    /** Handles help-viewer @a link click. */
     124    void sltHandleHelpViewerLinkClick(const QUrl &link);
     125
    120126    /** Handles abstract @a pButton click. */
    121127    void sltHandleButtonClicked(QAbstractButton *pButton);
     
    142148    /** Returns a list of default key folders. */
    143149    QStringList defaultKeyFolders() const;
     150    /** Returns a list of key generation tools. */
     151    QStringList keyGenerationTools() const;
    144152
    145153    /** Loads file contents.
     
    147155    bool loadFileContents(const QString &strPath, bool fIgnoreErrors = false);
    148156
     157    /** Holds the help-viewer instance. */
     158    QIRichTextLabel   *m_pHelpViewer;
    149159    /** Holds the text-editor instance. */
    150160    QTextEdit         *m_pTextEditor;
     
    160170UIAcquirePublicKeyDialog::UIAcquirePublicKeyDialog(QWidget *pParent /* = 0 */)
    161171    : QIWithRetranslateUI<QDialog>(pParent)
     172    , m_pHelpViewer(0)
    162173    , m_pTextEditor(0)
    163174    , m_pButtonBox(0)
     
    170181{
    171182    return m_pTextEditor->toPlainText();
     183}
     184
     185void UIAcquirePublicKeyDialog::sltHandleHelpViewerLinkClick(const QUrl &link)
     186{
     187    /* Parse the link meta and use it to get tool path to copy to clipboard: */
     188    bool fOk = false;
     189    const uint uToolNumber = link.toString().section('#', 1, 1).toUInt(&fOk);
     190    if (fOk)
     191        QApplication::clipboard()->setText(keyGenerationTools().value(uToolNumber), QClipboard::Clipboard);
    172192}
    173193
     
    204224{
    205225    setWindowTitle(tr("Public key"));
     226
     227    /* Generating help-viewer text: */
     228    QStringList folders;
     229    foreach (const QString &strFolder, defaultKeyFolders())
     230        folders << QString("&nbsp;%1").arg(strFolder);
     231    const QStringList initialTools = keyGenerationTools();
     232    QStringList tools;
     233    foreach (const QString &strTool, initialTools)
     234        tools << QString("&nbsp;<a href=#%1><img src='manager://copy'/></a>&nbsp;&nbsp;%2")
     235                         .arg(initialTools.indexOf(strTool))
     236                         .arg(strTool);
     237#ifdef VBOX_WS_WIN
     238    m_pHelpViewer->setText(tr("We haven't found public key id_rsa[.pub] in suitable locations. "
     239                              "If you have one, please put it under one of those folders OR copy "
     240                              "content to the edit box below:<br><br>"
     241                              "%1<br><br>"
     242                              "If you don't have one, please consider using one of the following "
     243                              "tools to generate it:<br><br>"
     244                              "%2")
     245                           .arg(folders.join("<br>"))
     246                           .arg(tools.join("<br>")));
     247#else
     248    m_pHelpViewer->setText(tr("We haven't found public key id_rsa[.pub] in suitable location. "
     249                              "If you have one, please put it under specified folder OR copy "
     250                              "content to the edit box below:<br><br>"
     251                              "%1<br><br>"
     252                              "If you don't have one, please consider using the following "
     253                              "tool to generate it:<br><br>"
     254                              "%2")
     255                           .arg(folders.join("<br>"))
     256                           .arg(tools.join("<br>")));
     257#endif
     258
    206259    m_pTextEditor->setPlaceholderText(tr("Paste public key"));
    207260    m_pButtonBox->button(QDialogButtonBox::Open)->setText(tr("Browse"));
     
    219272    /* Resize to suitable size: */
    220273    const int iMinimumHeightHint = minimumSizeHint().height();
    221     resize(iMinimumHeightHint * 2, iMinimumHeightHint);
     274    resize(iMinimumHeightHint * 1.618, iMinimumHeightHint);
    222275}
    223276
     
    228281    if (pLayout)
    229282    {
     283        /* Create help-viewer: */
     284        m_pHelpViewer = new QIRichTextLabel(this);
     285        if (m_pHelpViewer)
     286        {
     287            /* Prepare icon and size as well: */
     288            const QIcon icon = UIIconPool::iconSet(":/file_manager_copy_16px.png");
     289            const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 2 / 3;
     290
     291            /* Configure help-viewer: */
     292            m_pHelpViewer->setHidden(true);
     293            m_pHelpViewer->setMinimumTextWidth(gpDesktop->screenGeometry(window()).width() / 5);
     294            m_pHelpViewer->registerPixmap(icon.pixmap(window()->windowHandle(), QSize(iMetric, iMetric)), "manager://copy");
     295            connect(m_pHelpViewer, &QIRichTextLabel::sigLinkClicked, this, &UIAcquirePublicKeyDialog::sltHandleHelpViewerLinkClick);
     296            pLayout->addWidget(m_pHelpViewer, 2);
     297        }
     298
    230299        /* Prepare text-editor: */
    231300        m_pTextEditor = new QTextEdit(this);
     
    233302        {
    234303            connect(m_pTextEditor, &QTextEdit::textChanged, this, &UIAcquirePublicKeyDialog::sltRevalidate);
    235             pLayout->addWidget(m_pTextEditor);
     304            pLayout->addWidget(m_pTextEditor, 1);
    236305        }
    237306
     
    284353            fFileLoaded = loadFileContents(strAbsoluteFilePathWeNeed, true /* ignore errors */);
    285354    }
     355
     356    /* Show/hide help-viewer depending on
     357     * whether we were able to load the file: */
     358    m_pHelpViewer->setHidden(fFileLoaded);
    286359}
    287360
     
    296369    folders << QDir::toNativeSeparators(QDir(QDir::homePath()).absoluteFilePath(".ssh"));
    297370    return folders;
     371}
     372
     373QStringList UIAcquirePublicKeyDialog::keyGenerationTools() const
     374{
     375    QStringList tools;
     376#ifdef VBOX_WS_WIN
     377    // WORKAROUND:
     378    // There is additional key generation tool on Windows:
     379    tools << "puttygen.exe";
     380    tools << "ssh-keygen.exe -m PEM -t rsa -b 4096";
     381#else
     382    tools << "ssh-keygen -m PEM -t rsa -b 4096";
     383#endif
     384    return tools;
    298385}
    299386
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