User Sharing: Match user names and case insensitive #4269
authorChristian Kamm <mail@ckamm.de>
Thu, 10 Dec 2015 13:56:15 +0000 (14:56 +0100)
committerChristian Kamm <mail@ckamm.de>
Thu, 10 Dec 2015 13:56:15 +0000 (14:56 +0100)
src/gui/sharee.cpp
src/gui/shareusergroupwidget.cpp
src/gui/shareusergroupwidget.h

index 86f6a2032ab6cf5ca52c479cbaf60011691cdea8..5ff2aff6b28f17f959ffb9fe82cf0038633a7a09 100644 (file)
@@ -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();
index 348b5f886b2f3183f5034dd49774689149f0f4a1..313c0b32461b2522813768118e3501181155d974 100644 (file)
@@ -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<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)),
@@ -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> share,
                          bool isFile,
                          QWidget *parent) :
index ba8bbd699142750803079b158c1203c8737e037c..0b821b78e0f133d84be899d0d16cad64ad55d336 100644 (file)
@@ -106,6 +106,7 @@ private slots:
 
     void slotLineEditReturn();
     void slotCompleterActivated(const QModelIndex & index);
+    void slotCompleterHighlighted(const QModelIndex & index);
     void slotShareesReady();
     void slotAdjustScrollWidgetSize();