Welcome to mirror list, hosted at ThFree Co, Russian Federation.

userstatusselectormodel.h « gui « src - github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c60fc8926aa2d65af9a918468aea399e2ce59d3d (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright (C) by Felix Weilbach <felix.weilbach@nextcloud.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 */

#pragma once

#include "common/result.h"

#include <userstatusconnector.h>
#include <datetimeprovider.h>

#include <QObject>
#include <QMetaType>
#include <QtNumeric>

#include <cstddef>
#include <memory>
#include <vector>

namespace OCC {

class UserStatusSelectorModel : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString userStatusMessage READ userStatusMessage NOTIFY userStatusChanged)
    Q_PROPERTY(QString userStatusEmoji READ userStatusEmoji WRITE setUserStatusEmoji NOTIFY userStatusChanged)
    Q_PROPERTY(OCC::UserStatus::OnlineStatus onlineStatus READ onlineStatus WRITE setOnlineStatus NOTIFY onlineStatusChanged)
    Q_PROPERTY(int predefinedStatusesCount READ predefinedStatusesCount NOTIFY predefinedStatusesChanged)
    Q_PROPERTY(QStringList clearAtValues READ clearAtValues CONSTANT)
    Q_PROPERTY(QString clearAt READ clearAt NOTIFY clearAtChanged)
    Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
    Q_PROPERTY(QUrl onlineIcon READ onlineIcon CONSTANT)
    Q_PROPERTY(QUrl awayIcon READ awayIcon CONSTANT)
    Q_PROPERTY(QUrl dndIcon READ dndIcon CONSTANT)
    Q_PROPERTY(QUrl invisibleIcon READ invisibleIcon CONSTANT)

public:
    explicit UserStatusSelectorModel(QObject *parent = nullptr);

    explicit UserStatusSelectorModel(std::shared_ptr<UserStatusConnector> userStatusConnector,
        QObject *parent = nullptr);

    explicit UserStatusSelectorModel(std::shared_ptr<UserStatusConnector> userStatusConnector,
        std::unique_ptr<DateTimeProvider> dateTimeProvider,
        QObject *parent = nullptr);

    explicit UserStatusSelectorModel(const UserStatus &userStatus,
        std::unique_ptr<DateTimeProvider> dateTimeProvider,
        QObject *parent = nullptr);

    explicit UserStatusSelectorModel(const UserStatus &userStatus,
        QObject *parent = nullptr);

    Q_INVOKABLE void load(int id);

    Q_REQUIRED_RESULT UserStatus::OnlineStatus onlineStatus() const;
    Q_INVOKABLE void setOnlineStatus(OCC::UserStatus::OnlineStatus status);

    Q_REQUIRED_RESULT QUrl onlineIcon() const;
    Q_REQUIRED_RESULT QUrl awayIcon() const;
    Q_REQUIRED_RESULT QUrl dndIcon() const;
    Q_REQUIRED_RESULT QUrl invisibleIcon() const;

    Q_REQUIRED_RESULT QString userStatusMessage() const;
    Q_INVOKABLE void setUserStatusMessage(const QString &message);
    void setUserStatusEmoji(const QString &emoji);
    Q_REQUIRED_RESULT QString userStatusEmoji() const;

    Q_INVOKABLE void setUserStatus();
    Q_INVOKABLE void clearUserStatus();

    Q_REQUIRED_RESULT int predefinedStatusesCount() const;
    Q_INVOKABLE UserStatus predefinedStatus(int index) const;
    Q_INVOKABLE QString predefinedStatusClearAt(int index) const;
    Q_INVOKABLE void setPredefinedStatus(int index);

    Q_REQUIRED_RESULT QStringList clearAtValues() const;
    Q_REQUIRED_RESULT QString clearAt() const;
    Q_INVOKABLE void setClearAt(int index);

    Q_REQUIRED_RESULT QString errorMessage() const;

signals:
    void errorMessageChanged();
    void userStatusChanged();
    void onlineStatusChanged();
    void clearAtChanged();
    void predefinedStatusesChanged();
    void finished();

private:
    enum class ClearStageType {
        DontClear,
        HalfHour,
        OneHour,
        FourHour,
        Today,
        Week
    };

    void init();
    void reset();
    void onUserStatusFetched(const UserStatus &userStatus);
    void onPredefinedStatusesFetched(const std::vector<UserStatus> &statuses);
    void onUserStatusSet();
    void onMessageCleared();
    void onError(UserStatusConnector::Error error);

    Q_REQUIRED_RESULT QString clearAtStageToString(ClearStageType stage) const;
    Q_REQUIRED_RESULT QString clearAtReadable(const Optional<ClearAt> &clearAt) const;
    Q_REQUIRED_RESULT QString timeDifferenceToString(int differenceSecs) const;
    Q_REQUIRED_RESULT Optional<ClearAt> clearStageTypeToDateTime(ClearStageType type) const;
    void setError(const QString &reason);
    void clearError();

    std::shared_ptr<UserStatusConnector> _userStatusConnector {};
    std::vector<UserStatus> _predefinedStatuses;
    UserStatus _userStatus;
    std::unique_ptr<DateTimeProvider> _dateTimeProvider;

    QString _errorMessage;

    std::vector<ClearStageType> _clearStages = {
        ClearStageType::DontClear,
        ClearStageType::HalfHour,
        ClearStageType::OneHour,
        ClearStageType::FourHour,
        ClearStageType::Today,
        ClearStageType::Week
    };
};
}