From 585e23d06c7754b4cdbf3cf0096fe5b4bba278d1 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 3 Mar 2017 16:37:22 +0100 Subject: Allow pasting a newline separated list of JIDs in blocking dialog Furthermore the dialog will alphabetically sort the list of blocked JIDs before showing it in the dialog. Test-Information: Tested on macOS 10.12.3 with Qt 5.7.1 that it sorts the list it receives from the server before presenting it in the UI. Successfully pasted a newline spereated list of JIDs in the dialog. Change-Id: I8fe6969821bccad0193180cee9433da43285aaef diff --git a/Swift/QtUI/QtBlockListEditorWindow.cpp b/Swift/QtUI/QtBlockListEditorWindow.cpp index 30c939f..a6eca0e 100644 --- a/Swift/QtUI/QtBlockListEditorWindow.cpp +++ b/Swift/QtUI/QtBlockListEditorWindow.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2014-2016 Isode Limited. + * Copyright (c) 2014-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -106,6 +107,25 @@ QtBlockListEditorWindow::QtBlockListEditorWindow() : QWidget(), ui(new Ui::QtBlo QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x"); item->setFlags(item->flags() | Qt::ItemIsEditable); ui->blockListTreeWidget->addTopLevelItem(item); + + // Allow pasting a newline seperated list of JIDs into the dialog. + auto pasteShortcut = new QShortcut(QKeySequence::Paste, this); + connect(pasteShortcut, &QShortcut::activated, [&](){ + auto currentBlocklist = getCurrentBlockList(); + + auto clipboardText = QGuiApplication::clipboard()->text(); + auto stringList = clipboardText.split("\n"); + for (const auto& string : stringList) { + auto jid = JID(Q2PSTRING(string.trimmed())); + if (jid.isValid()) { + if (std::find(currentBlocklist.begin(), currentBlocklist.end(), jid) == currentBlocklist.end()) { + currentBlocklist.push_back(jid); + } + } + } + setCurrentBlockList(currentBlocklist); + }); + } QtBlockListEditorWindow::~QtBlockListEditorWindow() { @@ -157,8 +177,14 @@ void QtBlockListEditorWindow::applyChanges() { void QtBlockListEditorWindow::setCurrentBlockList(const std::vector &blockedJIDs) { ui->blockListTreeWidget->clear(); + QStringList blockedStrings; for (const auto& jid : blockedJIDs) { - QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << ""); + blockedStrings << P2QSTRING(jid.toString()); + } + blockedStrings.sort(); + + for (const auto& jid : blockedStrings) { + QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(jid) << ""); item->setFlags(item->flags() | Qt::ItemIsEditable); ui->blockListTreeWidget->addTopLevelItem(item); } -- cgit v0.10.2-6-g49f6