File indexing completed on 2024-10-06 07:38:13
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 "polleditorbackend.h" 0007 #include "post.h" 0008 0009 class AttachmentEditorModel; 0010 0011 class PostEditorBackend : public QObject 0012 { 0013 Q_OBJECT 0014 QML_ELEMENT 0015 0016 Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged) 0017 Q_PROPERTY(QString inReplyTo READ inReplyTo WRITE setInReplyTo NOTIFY inReplyToChanged) 0018 Q_PROPERTY(QString spoilerText READ spoilerText WRITE setSpoilerText NOTIFY spoilerTextChanged) 0019 Q_PROPERTY(Post::Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged) 0020 Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) 0021 Q_PROPERTY(QDateTime scheduledAt READ scheduledAt WRITE setScheduledAt NOTIFY scheduledAtChanged) 0022 Q_PROPERTY(QStringList mentions READ mentions WRITE setMentions NOTIFY mentionsChanged) 0023 Q_PROPERTY(AttachmentEditorModel *attachmentEditorModel READ attachmentEditorModel CONSTANT) 0024 Q_PROPERTY(bool sensitive READ sensitive WRITE setSensitive NOTIFY sensitiveChanged) 0025 Q_PROPERTY(PollEditorBackend *poll MEMBER m_poll CONSTANT) 0026 Q_PROPERTY(bool pollEnabled MEMBER m_pollEnabled NOTIFY pollEnabledChanged) 0027 Q_PROPERTY(int charactersLeft READ charactersLeft NOTIFY statusChanged) 0028 0029 Q_PROPERTY(AbstractAccount *account READ account WRITE setAccount NOTIFY accountChanged) 0030 0031 public: 0032 explicit PostEditorBackend(QObject *parent = nullptr); 0033 ~PostEditorBackend() override; 0034 0035 QString id() const; 0036 void setId(const QString &id); 0037 0038 QString status() const; 0039 void setStatus(const QString &status); 0040 0041 QString spoilerText() const; 0042 void setSpoilerText(const QString &spoilerText); 0043 0044 QString inReplyTo() const; 0045 void setInReplyTo(const QString &inReplyTo); 0046 0047 Post::Visibility visibility() const; 0048 void setVisibility(Post::Visibility visibility); 0049 0050 QString language() const; 0051 void setLanguage(const QString &language); 0052 0053 QDateTime scheduledAt() const; 0054 void setScheduledAt(const QDateTime &scheduledAt); 0055 0056 QStringList mentions() const; 0057 void setMentions(const QStringList &mentions); 0058 0059 AttachmentEditorModel *attachmentEditorModel() const; 0060 0061 bool sensitive() const; 0062 void setSensitive(bool sensitive); 0063 0064 AbstractAccount *account() const; 0065 void setAccount(AbstractAccount *account); 0066 0067 int charactersLeft() const; 0068 0069 public Q_SLOTS: 0070 void save(); 0071 void edit(); 0072 0073 Q_SIGNALS: 0074 0075 void statusChanged(); 0076 0077 void spoilerTextChanged(); 0078 0079 void inReplyToChanged(); 0080 0081 void visibilityChanged(); 0082 0083 void languageChanged(); 0084 0085 void scheduledAtChanged(); 0086 0087 void mentionsChanged(); 0088 0089 void accountChanged(); 0090 0091 void sensitiveChanged(); 0092 void editComplete(QJsonObject object); 0093 0094 void posted(QString error); 0095 0096 void pollEnabledChanged(); 0097 0098 private: 0099 QJsonDocument toJsonDocument() const; 0100 0101 QString m_id; 0102 QString m_status; 0103 QString m_idenpotencyKey; 0104 QString m_spoilerText; 0105 QString m_inReplyTo; 0106 QString m_language; 0107 QDateTime m_scheduledAt; 0108 QStringList m_mentions; 0109 bool m_sensitive = false; 0110 PollEditorBackend *m_poll = nullptr; 0111 bool m_pollEnabled = false; 0112 Post::Visibility m_visibility = Post::Visibility::Public; 0113 AbstractAccount *m_account = nullptr; 0114 AttachmentEditorModel *m_attachmentEditorModel = nullptr; 0115 };