Add basic clipboard support for copying tokens
parent
1a1c531dd3
commit
41d94024c2
|
@ -8,7 +8,6 @@ Some todo items include,
|
|||
|
||||
- QR code scanning
|
||||
- Backup and Restore of accounts
|
||||
- Clipboard support to automatically copy code.
|
||||
- Encrypted storage of the secret token
|
||||
|
||||
This code is largely based on the [authenticator-ng](https://github.com/dobey/authenticator-ng) application by the Rodney Dawes and Michael Zanetti for the Ubuntu Touch.
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
*/
|
||||
#include "keysmith.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QClipboard>
|
||||
#include <QGuiApplication>
|
||||
|
||||
namespace app
|
||||
{
|
||||
|
@ -20,6 +21,15 @@ namespace app
|
|||
}
|
||||
}
|
||||
|
||||
void Keysmith::copyToClipboard(const QString &text)
|
||||
{
|
||||
QClipboard * clipboard = QGuiApplication::clipboard();
|
||||
if (clipboard) {
|
||||
clipboard->setText(text);
|
||||
}
|
||||
// TODO warn about this
|
||||
}
|
||||
|
||||
model::SimpleAccountListModel * Keysmith::accountListModel(void)
|
||||
{
|
||||
return new model::SimpleAccountListModel(storage(), this);
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace app
|
|||
public:
|
||||
explicit Keysmith(QObject *parent = nullptr);
|
||||
virtual ~Keysmith();
|
||||
Q_INVOKABLE void copyToClipboard(const QString &text);
|
||||
Q_INVOKABLE model::SimpleAccountListModel * accountListModel(void);
|
||||
private:
|
||||
accounts::AccountStorage * storage(void);
|
||||
|
|
|
@ -8,6 +8,7 @@ import QtQuick.Layouts 1.2
|
|||
import QtQuick.Controls 2.0 as Controls
|
||||
import org.kde.kirigami 2.4 as Kirigami
|
||||
|
||||
import Keysmith.Application 1.0
|
||||
import Keysmith.Models 1.0 as Models
|
||||
|
||||
Kirigami.SwipeListItem {
|
||||
|
@ -15,6 +16,7 @@ Kirigami.SwipeListItem {
|
|||
property Models.Account account: null
|
||||
property int phase : account && account.isTotp ? account.millisecondsLeftForToken() : 0
|
||||
property int interval: account && account.isTotp ? 1000 * account.timeStep : 0
|
||||
property bool tokenAvailable: account && account.token && account.token.length > 0
|
||||
|
||||
property real healthIndicator: 0
|
||||
|
||||
|
@ -59,7 +61,7 @@ Kirigami.SwipeListItem {
|
|||
horizontalAlignment: Text.AlignRight
|
||||
Layout.fillWidth: true
|
||||
font.weight: Font.Bold
|
||||
text: account && account.token && account.token.length > 0 ? account.token : i18nc("placeholder text if no token is available", "(refresh)")
|
||||
text: tokenAvailable ? account.token : i18nc("placeholder text if no token is available", "(refresh)")
|
||||
}
|
||||
}
|
||||
Timer {
|
||||
|
@ -112,4 +114,12 @@ Kirigami.SwipeListItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
// TODO convert to C++ helper, have proper logging?
|
||||
if (tokenAvailable) {
|
||||
Keysmith.copyToClipboard(account.token);
|
||||
}
|
||||
// TODO warn if not
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue