Changeset 86896 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 16, 2020 5:43:13 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141367
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
r86894 r86896 25 25 #include <QStandardPaths> 26 26 #include <QStatusBar> 27 #include <QStyle> 27 28 #include <QTextEdit> 28 29 #ifndef VBOX_WS_WIN … … 34 35 #include "QIDialogButtonBox.h" 35 36 #include "QIFileDialog.h" 37 #include "QIRichTextLabel.h" 36 38 #include "UIActionPoolManager.h" 37 39 #include "UICloudConsoleManager.h" … … 40 42 #include "UICloudProfileManager.h" 41 43 #include "UIDesktopServices.h" 44 #include "UIDesktopWidgetWatchdog.h" 42 45 #include "UIErrorString.h" 43 46 #include "UIExtraDataManager.h" … … 118 121 private slots: 119 122 123 /** Handles help-viewer @a link click. */ 124 void sltHandleHelpViewerLinkClick(const QUrl &link); 125 120 126 /** Handles abstract @a pButton click. */ 121 127 void sltHandleButtonClicked(QAbstractButton *pButton); … … 142 148 /** Returns a list of default key folders. */ 143 149 QStringList defaultKeyFolders() const; 150 /** Returns a list of key generation tools. */ 151 QStringList keyGenerationTools() const; 144 152 145 153 /** Loads file contents. … … 147 155 bool loadFileContents(const QString &strPath, bool fIgnoreErrors = false); 148 156 157 /** Holds the help-viewer instance. */ 158 QIRichTextLabel *m_pHelpViewer; 149 159 /** Holds the text-editor instance. */ 150 160 QTextEdit *m_pTextEditor; … … 160 170 UIAcquirePublicKeyDialog::UIAcquirePublicKeyDialog(QWidget *pParent /* = 0 */) 161 171 : QIWithRetranslateUI<QDialog>(pParent) 172 , m_pHelpViewer(0) 162 173 , m_pTextEditor(0) 163 174 , m_pButtonBox(0) … … 170 181 { 171 182 return m_pTextEditor->toPlainText(); 183 } 184 185 void 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); 172 192 } 173 193 … … 204 224 { 205 225 setWindowTitle(tr("Public key")); 226 227 /* Generating help-viewer text: */ 228 QStringList folders; 229 foreach (const QString &strFolder, defaultKeyFolders()) 230 folders << QString(" %1").arg(strFolder); 231 const QStringList initialTools = keyGenerationTools(); 232 QStringList tools; 233 foreach (const QString &strTool, initialTools) 234 tools << QString(" <a href=#%1><img src='manager://copy'/></a> %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 206 259 m_pTextEditor->setPlaceholderText(tr("Paste public key")); 207 260 m_pButtonBox->button(QDialogButtonBox::Open)->setText(tr("Browse")); … … 219 272 /* Resize to suitable size: */ 220 273 const int iMinimumHeightHint = minimumSizeHint().height(); 221 resize(iMinimumHeightHint * 2, iMinimumHeightHint);274 resize(iMinimumHeightHint * 1.618, iMinimumHeightHint); 222 275 } 223 276 … … 228 281 if (pLayout) 229 282 { 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 230 299 /* Prepare text-editor: */ 231 300 m_pTextEditor = new QTextEdit(this); … … 233 302 { 234 303 connect(m_pTextEditor, &QTextEdit::textChanged, this, &UIAcquirePublicKeyDialog::sltRevalidate); 235 pLayout->addWidget(m_pTextEditor );304 pLayout->addWidget(m_pTextEditor, 1); 236 305 } 237 306 … … 284 353 fFileLoaded = loadFileContents(strAbsoluteFilePathWeNeed, true /* ignore errors */); 285 354 } 355 356 /* Show/hide help-viewer depending on 357 * whether we were able to load the file: */ 358 m_pHelpViewer->setHidden(fFileLoaded); 286 359 } 287 360 … … 296 369 folders << QDir::toNativeSeparators(QDir(QDir::homePath()).absoluteFilePath(".ssh")); 297 370 return folders; 371 } 372 373 QStringList 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; 298 385 } 299 386
Note:
See TracChangeset
for help on using the changeset viewer.