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
|
// SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef PASSWORDSMODEL_H_
#define PASSWORDSMODEL_H_
#include <QAbstractItemModel>
#include <QDir>
#include <QFileSystemWatcher>
#include <memory>
namespace PlasmaPass
{
class PasswordsModel : public QAbstractItemModel
{
Q_OBJECT
struct Node;
public:
enum EntryType {
FolderEntry,
PasswordEntry,
};
Q_ENUM(EntryType)
enum Roles {
NameRole = Qt::DisplayRole,
EntryTypeRole = Qt::UserRole,
FullNameRole,
PathRole,
PasswordRole,
OTPRole,
HasPasswordRole,
HasOTPRole
};
explicit PasswordsModel(QObject *parent = nullptr);
~PasswordsModel() override;
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
QVariant data(const QModelIndex &index, int role) const override;
private:
void populate();
void populateDir(const QDir &dir, Node *parent);
static Node *node(const QModelIndex &index);
QFileSystemWatcher mWatcher;
QDir mPassStore;
std::unique_ptr<Node> mRoot;
};
}
#endif
|