File indexing completed on 2024-07-14 15:14:05

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