Skip to content

Commit

Permalink
Allow to copy in Qt Quick GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Martchus committed Jun 16, 2018
1 parent 68c3133 commit fa8e6a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qml/EntriesPage.qml
Expand Up @@ -172,6 +172,14 @@ Kirigami.ScrollablePage {
fieldsListView.model.index(index, 0),
model.isPassword ? 0 : 1, 0x0100 + 1)
}
Controls.MenuItem {
icon.name: "edit-copy"
text: qsTr("Copy password")
onClicked: showPassiveNotification(
nativeInterface.copyToClipboard(
model.actualValue) ? qsTr("Copied") : qsTr(
"Unable to access clipboard"))
}
Controls.MenuItem {
icon.name: "edit-delete"
text: qsTr("Delete field")
Expand Down
18 changes: 18 additions & 0 deletions quickgui/controller.cpp
Expand Up @@ -8,8 +8,12 @@
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/path.h>

#ifndef QT_NO_CLIPBOARD
#include <QClipboard>
#endif
#include <QDir>
#include <QFileInfo>
#include <QGuiApplication>
#include <QIcon>
#include <QSettings>
#include <QStringBuilder>
Expand Down Expand Up @@ -191,6 +195,20 @@ QStringList Controller::pasteEntries(const QModelIndex &destinationParent, int r
return successfullyMovedEntries;
}

bool Controller::copyToClipboard(const QString &text) const
{
#ifndef QT_NO_CLIPBOARD
auto *clipboard(QGuiApplication::clipboard());
if (!clipboard) {
return false;
}
clipboard->setText(text);
return true;
#else
return false;
#endif
}

void Controller::resetFileStatus()
{
setFileOpen(false);
Expand Down
1 change: 1 addition & 0 deletions quickgui/controller.h
Expand Up @@ -50,6 +50,7 @@ class Controller : public QObject {
QString currentAccountName() const;
Q_INVOKABLE void cutEntry(const QModelIndex &entryIndex);
Q_INVOKABLE QStringList pasteEntries(const QModelIndex &destinationParent, int row = -1);
Q_INVOKABLE bool copyToClipboard(const QString &text) const;
bool canPaste() const;
const QStringList &recentFiles() const;

Expand Down

0 comments on commit fa8e6a7

Please sign in to comment.