/* $Id$ */
/** @file
* VBox Qt GUI - UIAddDiskEncryptionPasswordDialog class implementation.
*/
/*
* Copyright (C) 2006-2015 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
# include <precomp.h>
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Qt includes: */
# include <QVBoxLayout>
# include <QLabel>
# include <QLineEdit>
# include <QTableView>
# include <QHeaderView>
# include <QPushButton>
# include <QItemEditorFactory>
# include <QAbstractTableModel>
# include <QStandardItemEditorCreator>
/* GUI includes: */
# include "UIMedium.h"
# include "UIIconPool.h"
# include "VBoxGlobal.h"
# include "QIDialogButtonBox.h"
# include "QIWithRetranslateUI.h"
# include "QIStyledItemDelegate.h"
# include "UIAddDiskEncryptionPasswordDialog.h"
/* Other VBox includes: */
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
/** UIEncryptionDataTable field indexes. */
{
};
/** QLineEdit reimplementation used as
* the embedded password editor for the UIEncryptionDataTable. */
{
/** Holds the current password of the editor. */
/** Notifies listeners about data should be committed. */
void sigEnterKeyTriggered();
public:
/** Constructor.
* @param pParent being passed to the base-class. */
private slots:
/** Handles @s strPassword changes. */
private:
/** Prepare routine. */
void prepare();
/** Key press @a pEvent handler. */
/** Property: Returns the current password of the editor. */
/** Property: Defines the current @a strPassword of the editor. */
};
/** QAbstractTableModel reimplementation used as
* the data representation model for the UIEncryptionDataTable. */
{
public:
/** Constructor.
* @param pParent being passed to the base-class,
* @param encryptedMediums contains the lists of medium ids (values) encrypted with passwords with ids (keys). */
/** Returns the shallow copy of the encryption password map instance. */
/** Returns whether the model is valid. */
bool isValid() const;
/** Returns the row count, taking optional @a parent instead of root if necessary. */
/** Returns the column count, taking optional @a parent instead of root if necessary. */
/** Returns the @a index flags. */
/** Returns the header data for the @a iSection, @a orientation and @a iRole. */
/** Returns the @a index data for the @a iRole. */
/** Defines the @a index data for the @a iRole as @a value. */
private:
/** Prepare routine. */
void prepare();
/** Returns whether passed @a strPassword is valid for medium with passed @a strMediumId. */
/** Holds the encrypted medium map reference. */
/** Holds the encryption password map instance. */
/** Holds the encryption password status map instance. */
};
/** QTableView reimplementation used to
* allow the UIAddDiskEncryptionPasswordDialog to enter
* disk encryption passwords for particular password ids. */
{
/** Notifies listeners about data change. */
void sigDataChanged();
void sigEditorEnterKeyTriggered();
public:
/** Constructor.
* @param pParent being passed to the base-class. */
/** Returns the shallow copy of the encryption password map
* acquired from the UIEncryptionDataModel instance. */
EncryptionPasswordMap encryptionPasswords() const;
/** Returns whether the table is valid. */
bool isValid() const;
/** Initiates the editor for the first index available. */
void editFirstIndex();
private:
/** Prepare routine. */
void prepare();
/** Holds the encrypted medium map reference. */
/** Holds the encryption-data model instance. */
};
{
/* Prepare: */
prepare();
}
{
/* Commit data to the listener: */
emit sigCommitData(this);
}
{
/* Set echo mode: */
/* Listen for the text changes: */
}
{
/* Call to base-class: */
{
case Qt::Key_Return:
break;
default:
break;
}
}
UIEncryptionDataModel::UIEncryptionDataModel(QObject *pParent, const EncryptedMediumMap &encryptedMediums)
{
/* Prepare: */
prepare();
}
{
/* Check whether the model contains invalid passwords: */
if (!fValue)
return false;
/* Valid by default: */
return true;
}
{
return m_encryptionPasswords.size();
}
{
return UIEncryptionDataTableSection_Max;
}
{
/* Check index validness: */
return Qt::NoItemFlags;
/* Depending on column index: */
{
case UIEncryptionDataTableSection_Password: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
default: break;
}
/* No flags by default: */
return Qt::NoItemFlags;
}
QVariant UIEncryptionDataModel::headerData(int iSection, Qt::Orientation orientation, int iRole) const
{
/* Check argument validness: */
return QVariant();
/* Depending on column index: */
switch (iSection)
{
default: break;
}
/* Null value by default: */
return QVariant();
}
QVariant UIEncryptionDataModel::data(const QModelIndex &index, int iRole /* = Qt::DisplayRole */) const
{
/* Check index validness: */
return QVariant();
/* Depending on role: */
switch (iRole)
{
case Qt::DecorationRole:
{
/* Depending on column index: */
{
default:
return QVariant();
}
break;
}
case Qt::DisplayRole:
{
/* Depending on column index: */
{
return QString().fill('*', m_encryptionPasswords.value(m_encryptionPasswords.keys().at(index.row())).size());
default:
return QVariant();
}
break;
}
{
/* Depending on column index: */
{
default:
return QVariant();
}
break;
}
case Qt::ToolTipRole:
{
/* We are generating tool-tip here and not in retranslateUi() because of the tricky plural form handling,
* but be quiet, it's safe enough because the tool-tip being re-acquired every time on mouse-hovering. */
const QStringList encryptedMediums = m_encryptedMediums.values(m_encryptionPasswords.keys().at(index.row()));
return tr("<nobr>Used by the following %n hard drive(s):</nobr><br>%1",
"This text is never used with n == 0. "
"Feel free to drop the %n where possible, "
"we only included it because of problems with Qt Linguist "
"(but the user can see how many hard drives are in the tool-tip "
"and doesn't need to be told).",
}
default:
break;
}
/* Null value by default: */
return QVariant();
}
bool UIEncryptionDataModel::setData(const QModelIndex &index, const QVariant &value, int iRole /* = Qt::EditRole */)
{
/* Check index validness: */
return false;
/* Check argument validness: */
return false;
/* Depending on column index: */
{
{
/* Update password: */
/* Update password status: */
/* Initiate explicit password status update: */
break;
}
default:
break;
}
/* Nothing to set by default: */
return false;
}
{
/* Populate the map of passwords and statuses. */
{
}
}
{
/* Look for the medium with passed ID: */
{
/* Check wrapped medium for validity: */
{
/* Check whether the password is suitable for that medium. */
}
}
/* False by default: */
return false;
}
{
/* Prepare: */
prepare();
}
{
return m_pModelEncryptionData->encryptionPasswords();
}
{
AssertPtrReturn(m_pModelEncryptionData, false);
return m_pModelEncryptionData->isValid();
}
{
/* Compose the password field index of the first available table record: */
/* Navigate table to the corresponding index: */
/* Compose the fake mouse-event which will trigger the embedded editor: */
QMouseEvent event(QEvent::MouseButtonPress, QPoint(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
/* Initiate the embedded editor for the corresponding index: */
}
{
/* Create encryption-data model: */
{
/* Assign configured model to table: */
/* Configure encryption-data model: */
this, SIGNAL(sigDataChanged()));
}
/* Create item delegate: */
{
/* Create item editor factory: */
{
/* Create item editor creator: */
QStandardItemEditorCreator<UIPasswordEditor> *pQStringItemEditorCreator = new QStandardItemEditorCreator<UIPasswordEditor>();
{
/* Register UIPasswordEditor as the QString editor: */
}
/* Assign configured item editor factory to table delegate: */
}
/* Assign configured item delegate to table: */
delete itemDelegate();
/* Configure item delegate: */
this, SIGNAL(sigEditorEnterKeyTriggered()));
}
/* Configure table: */
setTabKeyNavigation(false);
/* Configure headers: */
verticalHeader()->hide();
horizontalHeader()->setStretchLastSection(false);
horizontalHeader()->setResizeMode(UIEncryptionDataTableSection_Status, QHeaderView::ResizeToContents);
}
const QString &strMachineName,
const EncryptedMediumMap &encryptedMediums)
, m_pLabelDescription(0)
, m_pButtonBox(0)
{
/* Prepare: */
prepare();
/* Translate: */
/* Validate: */
revalidate();
}
{
return m_pTableEncryptionData->encryptionPasswords();
}
{
accept();
}
{
/* Configure self: */
/* Create main-layout: */
{
/* Create input-layout: */
{
/* Create description label: */
m_pLabelDescription = new QLabel;
{
/* Add label into layout: */
}
/* Create encryption-data table: */
{
/* Configure encryption-data table: */
this, SLOT(sltDataChanged()));
this, SLOT(sltEditorEnterKeyTriggered()));
/* Add label into layout: */
}
/* Add layout into parent: */
}
/* Create button-box: */
m_pButtonBox = new QIDialogButtonBox;
{
/* Configure button-box: */
/* Add button-box into layout: */
}
}
}
{
/* Translate the dialog title: */
/* Translate the description label: */
"Please enter the %n encryption password(s) below.",
"This text is never used with n == 0. "
"Feel free to drop the %n where possible, "
"we only included it because of problems with Qt Linguist "
"(but the user can see how many passwords are in the list "
"and doesn't need to be told).",
m_encryptedMediums.size()));
}
{
/* Validate: */
}
#include "UIAddDiskEncryptionPasswordDialog.moc"