return QVariant();
}
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- return _sharees.at(index.row())->format();
- }
- if (role == Qt::UserRole) {
- return QVariant::fromValue(_sharees.at(index.row()));
+ const auto & sharee = _sharees.at(index.row());
+ if (role == Qt::DisplayRole) {
+ return sharee->format();
+
+ } else if (role == Qt::EditRole) {
+ // This role is used by the completer - it should match
+ // the full name and the user name and thus we include both
+ // in the output here. But we need to take care this string
+ // doesn't leak to the user.
+ return QString(sharee->displayName() + " (" + sharee->shareWith() + ")");
+
+ } else if (role == Qt::UserRole) {
+ return QVariant::fromValue(sharee);
}
return QVariant();
connect(_completerModel, SIGNAL(shareesReady()), this, SLOT(slotShareesReady()));
_completer->setModel(_completerModel);
+ _completer->setCaseSensitivity(Qt::CaseInsensitive);
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
_completer->setFilterMode(Qt::MatchContains);
#endif
connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
connect(_manager, SIGNAL(shareCreated(QSharedPointer<Share>)), SLOT(getShares()));
connect(_ui->shareeLineEdit, SIGNAL(returnPressed()), SLOT(slotLineEditReturn()));
- connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)));
+
+ // By making the next two QueuedConnections we can override
+ // the strings the completer sets on the line edit.
+ connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)),
+ Qt::QueuedConnection);
+ connect(_completer, SIGNAL(highlighted(QModelIndex)), SLOT(slotCompleterHighlighted(QModelIndex)),
+ Qt::QueuedConnection);
// Queued connection so this signal is recieved after textChanged
connect(_ui->shareeLineEdit, SIGNAL(textEdited(QString)),
const auto text = _ui->shareeLineEdit->text();
for (int i = 0; i < _completerModel->rowCount(); ++i) {
const auto sharee = _completerModel->getSharee(i);
- if (sharee->format() == text) {
+ if (sharee->format() == text
+ || sharee->displayName() == text
+ || sharee->shareWith() == text) {
slotCompleterActivated(_completerModel->index(i));
break;
}
_ui->shareeLineEdit->setText(QString());
}
+void ShareUserGroupWidget::slotCompleterHighlighted(const QModelIndex & index)
+{
+ // By default the completer would set the text to EditRole,
+ // override that here.
+ _ui->shareeLineEdit->setText(index.data(Qt::DisplayRole).toString());
+}
+
ShareWidget::ShareWidget(QSharedPointer<Share> share,
bool isFile,
QWidget *parent) :