File indexing completed on 2024-05-12 05:04:09
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 <QtQml> 0007 0008 class AbstractAccount; 0009 0010 /// Class responsible for editing the account personal information and preferences 0011 class ProfileEditorBackend : public QObject 0012 { 0013 Q_OBJECT 0014 QML_ELEMENT 0015 0016 Q_PROPERTY(AbstractAccount *account READ account WRITE setAccount NOTIFY accountChanged) 0017 Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) 0018 Q_PROPERTY(QString displayNameHtml READ displayNameHtml NOTIFY displayNameChanged) 0019 Q_PROPERTY(QString note READ note WRITE setNote NOTIFY noteChanged) 0020 Q_PROPERTY(bool bot READ bot WRITE setBot NOTIFY botChanged) 0021 Q_PROPERTY(QUrl backgroundUrl READ backgroundUrl WRITE setBackgroundUrl NOTIFY backgroundUrlChanged) 0022 Q_PROPERTY(QUrl avatarUrl READ avatarUrl WRITE setAvatarUrl NOTIFY avatarUrlChanged) 0023 Q_PROPERTY(QString backgroundUrlError READ backgroundUrlError NOTIFY backgroundUrlChanged) 0024 Q_PROPERTY(QString avatarUrlError READ avatarUrlError NOTIFY avatarUrlChanged) 0025 Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged) 0026 Q_PROPERTY(bool discoverable READ discoverable WRITE setDiscoverable NOTIFY discoverableChanged) 0027 0028 public: 0029 explicit ProfileEditorBackend(QObject *parent = nullptr); 0030 ~ProfileEditorBackend() override; 0031 0032 /// Returns the account we're updating 0033 AbstractAccount *account() const; 0034 0035 /// Sets the account to edit 0036 /// \param account The account to edit 0037 void setAccount(AbstractAccount *account); 0038 0039 /// Returns the display name of the account 0040 QString displayName() const; 0041 0042 /// Returns the display name of the account, processed to HTML (for custom emojis) 0043 QString displayNameHtml() const; 0044 0045 /// Sets a new display name for the account 0046 /// \param displayName The new display name, should be plain text 0047 void setDisplayName(const QString &displayName); 0048 0049 /// Returns the biography text for the account 0050 QString note() const; 0051 0052 /// Sets a new biography text for the account 0053 /// \param note The new bio 0054 void setNote(const QString ¬e); 0055 0056 /// Returns if the account should be marked as a bot 0057 bool bot() const; 0058 0059 /// Sets if the account should be marked as a bot 0060 /// \param bot If true, the account is marked as a bot and will be visible on the profile 0061 void setBot(bool bot); 0062 0063 /// Returns the current avatar URL for the account 0064 QUrl avatarUrl() const; 0065 0066 /// Returns a localized error if the new avatar failed to upload 0067 QString avatarUrlError() const; 0068 0069 /// Sets a new avatar URL for the account 0070 /// \param avatarUrl The new media URL for the avatar 0071 void setAvatarUrl(const QUrl &avatarUrl); 0072 0073 /// Returns the current background URL for the account 0074 QUrl backgroundUrl() const; 0075 0076 /// Returns a localized error if the new background failed to upload 0077 QString backgroundUrlError() const; 0078 0079 /// Sets a new background URL for the account 0080 /// \param backgroundUrl The new media URL for the background 0081 void setBackgroundUrl(const QUrl &backgroundUrl); 0082 0083 /// Whether the account should be discoverable on the server directory 0084 bool discoverable() const; 0085 0086 /// Sets whether the account should be discoverable on the server directory 0087 /// \param discoverable If set to true, the account will be listed on the server's directory 0088 void setDiscoverable(bool discoverable); 0089 0090 /// Whether the account is locked 0091 bool locked() const; 0092 0093 /// Sets if the account is locked or not 0094 /// \param locked If true, the account is locked 0095 void setLocked(bool locked); 0096 0097 public Q_SLOTS: 0098 void save(); 0099 void fetchAccountInfo(); 0100 0101 Q_SIGNALS: 0102 void accountChanged(); 0103 void displayNameChanged(); 0104 void noteChanged(); 0105 void botChanged(); 0106 void avatarUrlChanged(); 0107 void backgroundUrlChanged(); 0108 void discoverableChanged(); 0109 void lockedChanged(); 0110 void sendNotification(const QString &message, const QString &type = QStringLiteral("info")); 0111 0112 private: 0113 AbstractAccount *m_account = nullptr; 0114 QString m_displayName; 0115 QString m_note; 0116 bool m_bot = false; 0117 QUrl m_avatarUrl; 0118 QUrl m_backgroundUrl; 0119 bool m_discoverable = true; 0120 bool m_locked = false; 0121 };