| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /*
- * 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 "owncloudlib.h"
- #include <QObject>
- #include <QString>
- #include <QMetaType>
- #include <QUrl>
- #include <QDateTime>
- #include <QtGlobal>
- #include <QVariant>
- #include <vector>
- namespace OCC {
- enum class OWNCLOUDSYNC_EXPORT ClearAtType {
- Period,
- EndOf,
- Timestamp
- };
- // TODO: If we can use C++17 make it a std::variant
- struct OWNCLOUDSYNC_EXPORT ClearAt
- {
- ClearAtType _type = ClearAtType::Period;
- quint64 _timestamp = 0ULL;
- int _period = 0;
- QString _endof;
- };
- class OWNCLOUDSYNC_EXPORT UserStatus
- {
- Q_GADGET
- Q_PROPERTY(QString id MEMBER _id)
- Q_PROPERTY(QString message MEMBER _message)
- Q_PROPERTY(QString icon MEMBER _icon)
- Q_PROPERTY(OnlineStatus state MEMBER _state)
- public:
- enum class OnlineStatus : quint8 {
- Online,
- DoNotDisturb,
- Away,
- Offline,
- Invisible
- };
- Q_ENUM(OnlineStatus);
- UserStatus();
- UserStatus(const QString &id, const QString &message, const QString &icon,
- OnlineStatus state, bool messagePredefined, const Optional<ClearAt> &clearAt = {});
- Q_REQUIRED_RESULT QString id() const;
- Q_REQUIRED_RESULT QString message() const;
- Q_REQUIRED_RESULT QString icon() const;
- Q_REQUIRED_RESULT OnlineStatus state() const;
- Q_REQUIRED_RESULT Optional<ClearAt> clearAt() const;
- [[nodiscard]] QString clearAtDisplayString() const;
- void setId(const QString &id);
- void setMessage(const QString &message);
- void setState(OnlineStatus state);
- void setIcon(const QString &icon);
- void setMessagePredefined(bool value);
- void setClearAt(const Optional<ClearAt> &dateTime);
- Q_REQUIRED_RESULT bool messagePredefined() const;
- Q_REQUIRED_RESULT QUrl stateIcon() const;
- private:
- QString _id;
- QString _message;
- QString _icon;
- OnlineStatus _state = OnlineStatus::Online;
- bool _messagePredefined = false;
- Optional<ClearAt> _clearAt;
- };
- class OWNCLOUDSYNC_EXPORT UserStatusConnector : public QObject
- {
- Q_OBJECT
- public:
- enum class Error {
- CouldNotFetchUserStatus,
- CouldNotFetchPredefinedUserStatuses,
- UserStatusNotSupported,
- EmojisNotSupported,
- CouldNotSetUserStatus,
- CouldNotClearMessage
- };
- Q_ENUM(Error)
- explicit UserStatusConnector(QObject *parent = nullptr);
- ~UserStatusConnector() override;
- virtual void fetchUserStatus() = 0;
- virtual void fetchPredefinedStatuses() = 0;
- virtual void setUserStatus(const UserStatus &userStatus) = 0;
- virtual void clearMessage() = 0;
- [[nodiscard]] virtual UserStatus userStatus() const = 0;
- signals:
- void userStatusFetched(const OCC::UserStatus &userStatus);
- void predefinedStatusesFetched(const QVector<OCC::UserStatus> &statuses);
- void userStatusSet();
- void serverUserStatusChanged();
- void messageCleared();
- void error(OCC::UserStatusConnector::Error error);
- };
- }
- Q_DECLARE_METATYPE(OCC::UserStatusConnector *)
- Q_DECLARE_METATYPE(OCC::UserStatus)
|