Changeset 56953 in vbox
- Timestamp:
- Jul 16, 2015 2:04:58 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r56180 r56953 537 537 .arg(strKey, CMachine(machine).GetName(), strValue), 538 538 formatErrorInfo(machine)); 539 } 540 541 void UIMessageCenter::warnAboutInvalidEncryptionPassword(const QString &strPasswordId, QWidget *pParent /* = 0 */) 542 { 543 alert(pParent, MessageType_Error, 544 tr("Encryption password for <nobr>ID = '%1'</nobr> is invalid.") 545 .arg(strPasswordId)); 539 546 } 540 547 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r55547 r56953 174 174 void cannotSetExtraData(const CVirtualBox &vbox, const QString &strKey, const QString &strValue); 175 175 void cannotSetExtraData(const CMachine &machine, const QString &strKey, const QString &strValue); 176 void warnAboutInvalidEncryptionPassword(const QString &strPasswordId, QWidget *pParent = 0); 176 177 177 178 /* API: Selector warnings: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.cpp
r56213 r56953 35 35 # include "UIIconPool.h" 36 36 # include "VBoxGlobal.h" 37 # include "UIMessageCenter.h" 37 38 # include "QIDialogButtonBox.h" 38 39 # include "QIWithRetranslateUI.h" … … 48 49 enum UIEncryptionDataTableSection 49 50 { 50 UIEncryptionDataTableSection_Status,51 51 UIEncryptionDataTableSection_Id, 52 52 UIEncryptionDataTableSection_Password, … … 79 79 private slots: 80 80 81 /** Handles @s strPassword changes. */82 void slt PasswordChanged(const QString &strPassword);81 /** Commits data to the listeners. */ 82 void sltCommitData() { emit sigCommitData(this); } 83 83 84 84 private: … … 112 112 EncryptionPasswordMap encryptionPasswords() const { return m_encryptionPasswords; } 113 113 114 /** Returns whether the model is valid. */115 bool isValid() const;116 117 114 /** Returns the row count, taking optional @a parent instead of root if necessary. */ 118 115 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; … … 136 133 void prepare(); 137 134 138 /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */139 bool isPasswordValid(const QString strMediumId, const QString strPassword);140 141 135 /** Holds the encrypted medium map reference. */ 142 136 const EncryptedMediumMap &m_encryptedMediums; … … 144 138 /** Holds the encryption password map instance. */ 145 139 EncryptionPasswordMap m_encryptionPasswords; 146 /** Holds the encryption password status map instance. */147 EncryptionPasswordStatusMap m_encryptionPasswordStatus;148 140 }; 149 141 … … 157 149 signals: 158 150 159 /** Notifies listeners about data change. */160 void sigDataChanged();161 162 151 /** Notifies listeners about editor's Enter/Return key triggering. */ 163 152 void sigEditorEnterKeyTriggered(); … … 173 162 EncryptionPasswordMap encryptionPasswords() const; 174 163 175 /** Returns whether the table is valid. */176 bool isValid() const;177 178 164 /** Initiates the editor for the first index available. */ 179 165 void editFirstIndex(); … … 196 182 /* Prepare: */ 197 183 prepare(); 198 }199 200 void UIPasswordEditor::sltPasswordChanged(const QString &strPassword)201 {202 Q_UNUSED(strPassword);203 /* Commit data to the listener: */204 emit sigCommitData(this);205 184 } 206 185 … … 211 190 /* Listen for the text changes: */ 212 191 connect(this, SIGNAL(textChanged(const QString&)), 213 this, SLOT(slt PasswordChanged(const QString&)));192 this, SLOT(sltCommitData())); 214 193 } 215 194 … … 237 216 /* Prepare: */ 238 217 prepare(); 239 }240 241 bool UIEncryptionDataModel::isValid() const242 {243 /* Check whether the model contains invalid passwords: */244 foreach (const bool &fValue, m_encryptionPasswordStatus.values())245 if (!fValue)246 return false;247 /* Valid by default: */248 return true;249 218 } 250 219 … … 269 238 switch (index.column()) 270 239 { 271 case UIEncryptionDataTableSection_Status: return Qt::ItemIsEnabled | Qt::ItemIsSelectable;272 240 case UIEncryptionDataTableSection_Id: return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 273 241 case UIEncryptionDataTableSection_Password: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; … … 286 254 switch (iSection) 287 255 { 288 case UIEncryptionDataTableSection_Status: return UIAddDiskEncryptionPasswordDialog::tr("Status", "password table field");289 256 case UIEncryptionDataTableSection_Id: return UIAddDiskEncryptionPasswordDialog::tr("ID", "password table field"); 290 257 case UIEncryptionDataTableSection_Password: return UIAddDiskEncryptionPasswordDialog::tr("Password", "password table field"); … … 297 264 QVariant UIEncryptionDataModel::data(const QModelIndex &index, int iRole /* = Qt::DisplayRole */) const 298 265 { 299 /* Check indexvalidness: */266 /* Check argument validness: */ 300 267 if (!index.isValid()) 301 268 return QVariant(); … … 303 270 switch (iRole) 304 271 { 305 case Qt::DecorationRole:306 {307 /* Depending on column index: */308 switch (index.column())309 {310 case UIEncryptionDataTableSection_Status:311 return m_encryptionPasswordStatus.value(m_encryptionPasswordStatus.keys().at(index.row())) ?312 UIIconPool::iconSet(":/status_check_16px.png") : UIIconPool::iconSet(":/status_error_16px.png");313 default:314 return QVariant();315 }316 break;317 }318 272 case Qt::DisplayRole: 319 273 { … … 365 319 bool UIEncryptionDataModel::setData(const QModelIndex &index, const QVariant &value, int iRole /* = Qt::EditRole */) 366 320 { 367 /* Check index validness: */368 if (!index.isValid())369 return false;370 321 /* Check argument validness: */ 371 if ( iRole != Qt::EditRole)322 if (!index.isValid() || iRole != Qt::EditRole) 372 323 return false; 373 324 /* Depending on column index: */ … … 381 332 const QString strKey = m_encryptionPasswords.keys().at(iRow); 382 333 m_encryptionPasswords[strKey] = strPassword; 383 /* Update password status: */384 const QString strMediumId = m_encryptedMediums.values(strKey).first();385 const bool fPasswordStatus = isPasswordValid(strMediumId, strPassword);386 m_encryptionPasswordStatus[strKey] = fPasswordStatus;387 /* Initiate explicit password status update: */388 const QModelIndex statusIndex = createIndex(iRow, UIEncryptionDataTableSection_Status);389 emit dataChanged(statusIndex, statusIndex);390 334 break; 391 335 } … … 399 343 void UIEncryptionDataModel::prepare() 400 344 { 401 /* Populate the map of passwords and statuses .*/345 /* Populate the map of passwords and statuses: */ 402 346 foreach (const QString &strPasswordId, m_encryptedMediums.keys()) 403 {404 347 m_encryptionPasswords.insert(strPasswordId, QString()); 405 m_encryptionPasswordStatus.insert(strPasswordId, false);406 }407 }408 409 bool UIEncryptionDataModel::isPasswordValid(const QString strMediumId, const QString strPassword)410 {411 /* Look for the medium with passed ID: */412 const UIMedium uimedium = vboxGlobal().medium(strMediumId);413 if (!uimedium.isNull())414 {415 /* Check wrapped medium for validity: */416 const CMedium medium = uimedium.medium();417 if (!medium.isNull())418 {419 /* Check whether the password is suitable for that medium. */420 medium.CheckEncryptionPassword(strPassword);421 return medium.isOk();422 }423 }424 /* False by default: */425 return false;426 348 } 427 349 … … 438 360 AssertPtrReturn(m_pModelEncryptionData, EncryptionPasswordMap()); 439 361 return m_pModelEncryptionData->encryptionPasswords(); 440 }441 442 bool UIEncryptionDataTable::isValid() const443 {444 AssertPtrReturn(m_pModelEncryptionData, false);445 return m_pModelEncryptionData->isValid();446 362 } 447 363 … … 467 383 /* Assign configured model to table: */ 468 384 setModel(m_pModelEncryptionData); 469 /* Configure encryption-data model: */470 connect(m_pModelEncryptionData, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),471 this, SIGNAL(sigDataChanged()));472 385 } 473 386 … … 510 423 verticalHeader()->setDefaultSectionSize((int)(verticalHeader()->minimumSectionSize() * 1.33)); 511 424 horizontalHeader()->setStretchLastSection(false); 512 horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Status, QHeaderView::ResizeToContents);513 425 horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Id, QHeaderView::Interactive); 514 426 horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Password, QHeaderView::Stretch); … … 529 441 /* Translate: */ 530 442 retranslateUi(); 531 /* Validate: */532 revalidate();533 443 } 534 444 … … 539 449 } 540 450 541 void UIAddDiskEncryptionPasswordDialog::sltEditorEnterKeyTriggered() 542 { 543 if (m_pButtonBox->button(QDialogButtonBox::Ok)->isEnabled()) 544 accept(); 451 void UIAddDiskEncryptionPasswordDialog::accept() 452 { 453 /* Validate passwords status: */ 454 foreach (const QString &strPasswordId, m_encryptedMediums.uniqueKeys()) 455 { 456 const QString strMediumId = m_encryptedMediums.values(strPasswordId).first(); 457 const QString strPassword = m_pTableEncryptionData->encryptionPasswords().value(strPasswordId); 458 if (!isPasswordValid(strMediumId, strPassword)) 459 return msgCenter().warnAboutInvalidEncryptionPassword(strPasswordId, this); 460 } 461 /* Call to base-class: */ 462 QIWithRetranslateUI<QDialog>::accept(); 545 463 } 546 464 … … 570 488 { 571 489 /* Configure encryption-data table: */ 572 connect(m_pTableEncryptionData, SIGNAL(sigDataChanged()),573 this, SLOT(sltDataChanged()));574 490 connect(m_pTableEncryptionData, SIGNAL(sigEditorEnterKeyTriggered()), 575 491 this, SLOT(sltEditorEnterKeyTriggered())); … … 613 529 } 614 530 615 void UIAddDiskEncryptionPasswordDialog::revalidate() 616 { 617 /* Validate: */ 618 AssertPtrReturnVoid(m_pButtonBox); 619 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(m_pTableEncryptionData->isValid()); 531 /* static */ 532 bool UIAddDiskEncryptionPasswordDialog::isPasswordValid(const QString strMediumId, const QString strPassword) 533 { 534 /* Look for the medium with passed ID: */ 535 const UIMedium uimedium = vboxGlobal().medium(strMediumId); 536 if (!uimedium.isNull()) 537 { 538 /* Check wrapped medium for validity: */ 539 const CMedium medium = uimedium.medium(); 540 if (!medium.isNull()) 541 { 542 /* Check whether the password is suitable for that medium: */ 543 medium.CheckEncryptionPassword(strPassword); 544 return medium.isOk(); 545 } 546 } 547 /* False by default: */ 548 return false; 620 549 } 621 550 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIAddDiskEncryptionPasswordDialog.h
r55401 r56953 57 57 private slots: 58 58 59 /** Handles the data change. */60 void slt DataChanged() { revalidate(); }59 /** Handles editor's Enter/Return key triggering. */ 60 void sltEditorEnterKeyTriggered() { accept(); } 61 61 62 /** Handles editor's Enter/Return key triggering. */ 63 void sltEditorEnterKeyTriggered(); 62 /** Performs passwords validation. 63 * If all passwords are valid, 64 * this slot calls to base-class. */ 65 void accept(); 64 66 65 67 private: … … 71 73 void retranslateUi(); 72 74 73 /** Validation routine. */74 void revalidate();75 /** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */ 76 static bool isPasswordValid(const QString strMediumId, const QString strPassword); 75 77 76 78 /** Holds the name of the machine we show this dialog for. */
Note:
See TracChangeset
for help on using the changeset viewer.