From 0555c884251c0ecc16924cd7a3a1cc2fad63cb7a Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 10 Dec 2015 14:56:15 +0100 Subject: [PATCH] User Sharing: Match user names and case insensitive #4269 --- src/gui/sharee.cpp | 18 +++++++++++++----- src/gui/shareusergroupwidget.cpp | 20 ++++++++++++++++++-- src/gui/shareusergroupwidget.h | 1 + 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp index 86f6a2032..5ff2aff6b 100644 --- a/src/gui/sharee.cpp +++ b/src/gui/sharee.cpp @@ -196,11 +196,19 @@ QVariant ShareeModel::data(const QModelIndex &index, int role) const 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(); diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 348b5f886..313c0b324 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -65,6 +65,7 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sh 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 @@ -74,7 +75,13 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sh connect(_manager, SIGNAL(sharesFetched(QList>)), SLOT(slotSharesFetched(QList>))); connect(_manager, SIGNAL(shareCreated(QSharedPointer)), 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)), @@ -111,7 +118,9 @@ void ShareUserGroupWidget::slotLineEditReturn() 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; } @@ -214,6 +223,13 @@ void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index) _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, bool isFile, QWidget *parent) : diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index ba8bbd699..0b821b78e 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -106,6 +106,7 @@ private slots: void slotLineEditReturn(); void slotCompleterActivated(const QModelIndex & index); + void slotCompleterHighlighted(const QModelIndex & index); void slotShareesReady(); void slotAdjustScrollWidgetSize(); -- 2.30.2