etesyncclientstate.h 2.09 KB
Newer Older
1
/*
2
 * SPDX-FileCopyrightText: 2020 Shashwat Jolly <shashwat.jolly@gmail.com>
Laurent Montel's avatar
Laurent Montel committed
3
 *
4
 * SPDX-License-Identifier: GPL-2.0-or-later
5 6 7 8 9
 */

#ifndef ETESYNCCLIENTSTATE_H
#define ETESYNCCLIENTSTATE_H

Shashwat Jolly's avatar
Shashwat Jolly committed
10
#include "etebaseadapter.h"
11 12
#include "settings.h"

13 14 15
#include <KWallet/KWallet>
#include <QPointer>

16 17 18 19
class EteSyncClientState : public QObject
{
    Q_OBJECT
public:
20
    typedef std::unique_ptr<EteSyncClientState> Ptr;
21
    explicit EteSyncClientState(const QString &agentId, WId winId);
22 23

    void init();
24
    void saveSettings();
25
    void invalidateToken();
Shashwat Jolly's avatar
Shashwat Jolly committed
26
    bool login(const QString &serverUrl, const QString &username, const QString &password);
27
    void logout();
28
    bool accountStatus();
29 30
    bool openWalletFolder();
    void deleteWalletEntry();
31
    void saveAccount();
32 33 34 35 36 37 38 39
    void loadAccount();
    void saveEtebaseCollectionCache(const EtebaseCollection *etesyncCollection) const;
    void saveEtebaseItemCache(const EtebaseItem *etesyncItem, const EtebaseCollection *parentCollection) const;
    EtebaseCollectionPtr getEtebaseCollectionFromCache(const QString &collectionUid) const;
    EtebaseItemPtr getEtebaseItemFromCache(const QString &itemUid, const EtebaseCollection *parentCollection) const;
    void deleteEtebaseCollectionCache(const QString &collectionUid);
    void deleteEtebaseItemCache(const QString &itemUid, const EtebaseCollection *parentCollection);
    void deleteEtebaseUserCache();
40

41 42
    EtebaseAccount *account() const
    {
Shashwat Jolly's avatar
Shashwat Jolly committed
43
        return mAccount.get();
44 45
    }

Shashwat Jolly's avatar
Shashwat Jolly committed
46
    QString username() const
47 48 49 50
    {
        return mUsername;
    }

51 52 53 54 55 56 57 58 59 60
    QString serverUrl() const
    {
        return mServerUrl;
    }

    bool isInitialized()
    {
        return !mServerUrl.isEmpty();
    }

61 62 63
public Q_SLOTS:
    void refreshToken();

64 65
Q_SIGNALS:
    void clientInitialised(bool successful);
66
    void tokenRefreshed(bool successful);
67 68

private:
Shashwat Jolly's avatar
Shashwat Jolly committed
69 70
    EtebaseClientPtr mClient;
    EtebaseAccountPtr mAccount;
71
    EtebaseFileSystemCachePtr mEtebaseCache;
72 73 74
    QString mUsername;
    QString mPassword;
    QString mServerUrl;
75
    const QString mAgentId;
76
    WId mWinId;
77
    QPointer<KWallet::Wallet> mWallet;
78 79
};

Shashwat Jolly's avatar
Shashwat Jolly committed
80
#endif // ETESYNCSETTINGS_H