File indexing completed on 2024-04-28 16:13:16

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 #include <QUrl>
0008 
0009 class AbstractAccount;
0010 
0011 /// Class responsible for editing the account personal information and preferences
0012 class ProfileEditorBackend : public QObject
0013 {
0014     Q_OBJECT
0015 
0016     /// This property holds the account we want to update.
0017     Q_PROPERTY(AbstractAccount *account READ account WRITE setAccount NOTIFY accountChanged)
0018 
0019     /// This property holds the display name of the account.
0020     Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
0021 
0022     /// This property holds the note (bio) of the account.
0023     Q_PROPERTY(QString note READ note WRITE setNote NOTIFY noteChanged)
0024 
0025     /// This property holds the default post privacy to be used for new statuses.
0026     Q_PROPERTY(QString privacy READ privacy WRITE setPrivacy NOTIFY privacyChanged)
0027 
0028     /// This property holds whether new statuses should be marked sensitive by default.
0029     Q_PROPERTY(bool sensitive READ sensitive WRITE setSensitive NOTIFY sensitiveChanged)
0030 
0031     /// This property holds whether this account is a bot.
0032     Q_PROPERTY(bool bot READ bot WRITE setBot NOTIFY botChanged)
0033 
0034     /// This property holds the the image banner that is shown above the profile
0035     /// and in profile cards.
0036     Q_PROPERTY(QUrl backgroundUrl READ backgroundUrl WRITE setBackgroundUrl NOTIFY backgroundUrlChanged)
0037 
0038     /// This property holds the the image banner that is shown above the profile
0039     /// and in profile cards.
0040     Q_PROPERTY(QUrl avatarUrl READ avatarUrl WRITE setAvatarUrl NOTIFY avatarUrlChanged)
0041 
0042     /// This property holds whether the current backgroundUrl has an error
0043     Q_PROPERTY(QString backgroundUrlError READ backgroundUrlError NOTIFY backgroundUrlChanged)
0044 
0045     /// This property holds whether the current avatarUrl has an error
0046     Q_PROPERTY(QString avatarUrlError READ avatarUrlError NOTIFY avatarUrlChanged)
0047 
0048     Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged)
0049 
0050     Q_PROPERTY(bool discoverable READ discoverable WRITE setDiscoverable NOTIFY discoverableChanged)
0051 
0052 public:
0053     explicit ProfileEditorBackend(QObject *parent = nullptr);
0054     ~ProfileEditorBackend() override;
0055 
0056     AbstractAccount *account() const;
0057     void setAccount(AbstractAccount *account);
0058 
0059     QString displayName() const;
0060     void setDisplayName(const QString &displayName);
0061 
0062     QString note() const;
0063     void setNote(const QString &note);
0064 
0065     bool sensitive() const;
0066     void setSensitive(bool sensitive);
0067 
0068     QString privacy() const;
0069     void setPrivacy(const QString &privacy);
0070 
0071     bool bot() const;
0072     void setBot(bool bot);
0073 
0074     QString language() const;
0075     void setLanguage(const QString &language);
0076 
0077     QUrl avatarUrl() const;
0078     QString avatarUrlError() const;
0079     void setAvatarUrl(const QUrl &avatarUrl);
0080 
0081     QUrl backgroundUrl() const;
0082     QString backgroundUrlError() const;
0083     void setBackgroundUrl(const QUrl &backgroundUrl);
0084 
0085     bool discoverable() const;
0086     void setDiscoverable(bool discoverable);
0087 
0088     bool locked() const;
0089     void setLocked(bool locked);
0090 
0091 public Q_SLOTS:
0092     void save();
0093     void fetchAccountInfo();
0094 
0095 Q_SIGNALS:
0096     void accountChanged();
0097     void displayNameChanged();
0098     void noteChanged();
0099     void sensitiveChanged();
0100     void privacyChanged();
0101     void botChanged();
0102     void languageChanged();
0103     void avatarUrlChanged();
0104     void backgroundUrlChanged();
0105     void discoverableChanged();
0106     void lockedChanged();
0107     void sendNotification(const QString &message, const QString &type = QStringLiteral("info"));
0108 
0109 private:
0110     AbstractAccount *m_account = nullptr;
0111     QString m_displayName;
0112     QString m_note;
0113     QString m_privacy = QStringLiteral("public");
0114     bool m_sensitive = false;
0115     bool m_bot = false;
0116     QString m_language;
0117     QUrl m_avatarUrl;
0118     QUrl m_backgroundUrl;
0119     bool m_discoverable = true;
0120     bool m_locked = false;
0121 };