1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef PROVIDERBASE_H_
#define PROVIDERBASE_H_
#include <QObject>
#include <QTimer>
#include "klipperutils.h"
#include <memory>
class QDBusPendingCallWatcher;
class KJob;
class QMimeData;
namespace Plasma5Support
{
class DataEngineConsumer;
}
namespace PlasmaPass
{
class PasswordsModel;
class ProviderBase : public QObject
{
Q_OBJECT
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
Q_PROPERTY(int timeout READ timeout NOTIFY timeoutChanged)
Q_PROPERTY(int defaultTimeout READ defaultTimeout CONSTANT)
Q_PROPERTY(QString secret READ secret NOTIFY secretChanged)
Q_PROPERTY(bool hasError READ hasError NOTIFY errorChanged)
Q_PROPERTY(QString error READ error NOTIFY errorChanged)
friend class PasswordsModel;
public:
~ProviderBase() override;
QString secret() const;
bool isValid() const;
int timeout() const;
int defaultTimeout() const; // in milliseconds
bool hasError() const;
QString error() const;
public Q_SLOTS:
void reset();
Q_SIGNALS:
void secretChanged();
void validChanged();
void timeoutChanged();
void errorChanged();
protected:
explicit ProviderBase(const QString &path, QObject *parent = nullptr);
void setSecret(const QString &secret);
void setSecretTimeout(std::chrono::seconds timeout);
void setError(const QString &error);
enum class HandlingResult {
Continue,
Stop
};
virtual HandlingResult handleSecret(QStringView secret) = 0;
private Q_SLOTS:
void start();
void onPlasmaServiceRemovePasswordResult(KJob *job);
private:
void expireSecret();
void removePasswordFromClipboard(const QString &password);
static void clearClipboard();
std::unique_ptr<Plasma5Support::DataEngineConsumer> mEngineConsumer;
QString mPath;
QString mError;
QString mSecret;
QTimer mTimer;
int mTimeout = 0;
std::chrono::seconds mSecretTimeout;
static KlipperUtils::State sKlipperState;
};
}
#endif
|