File indexing completed on 2023-12-03 08:28:36

0001 /*
0002     Copyright (C) 2014  Marcin ZiemiƄski   <zieminn@gmail.com>
0003 
0004     This program is free software: you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation, either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016 */
0017 
0018 #ifndef OTR_CHANNEL_ADAPTER_HEADER
0019 #define OTR_CHANNEL_ADAPTER_HEADER
0020 
0021 #include "types.h"
0022 #include "constants.h"
0023 
0024 #include "ktpotr_export.h"
0025 
0026 #include <QObject>
0027 
0028 #include <TelepathyQt/Types>
0029 #include <TelepathyQt/TextChannel>
0030 #include <TelepathyQt/PendingOperation>
0031 #include <TelepathyQt/RefCounted>
0032 
0033 namespace KTp {
0034 
0035 class KTPOTR_EXPORT ChannelAdapter : public QObject, public Tp::RefCounted
0036 {
0037     Q_OBJECT
0038 
0039     public:
0040         ChannelAdapter(const Tp::TextChannelPtr &textChannel, QObject *parent = nullptr);
0041         ~ChannelAdapter() override;
0042 
0043         Tp::TextChannelPtr textChannel();
0044 
0045         KTp::OTRTrustLevel otrTrustLevel() const;
0046         bool isOTRsuppored() const;
0047         QString remoteFingerprint() const;
0048         QDBusPendingReply<> trustFingerprint(const QString &fingerprint, bool trust);
0049 
0050         bool isValid() const;
0051 
0052         void initializeOTR();
0053         void stopOTR();
0054         /** question answer peer authentication */
0055         void startPeerAuthenticationQA(const QString &question, const QString &answer);
0056         /** shared secret peer authentication*/
0057         void startPeerAuthenticationSS(const QString &secret);
0058         void respondPeerAuthentication(const QString &secret);
0059         void abortPeerAuthentication();
0060 
0061         void acknowledge(const QList<Tp::ReceivedMessage> &messages);
0062         void send(const QString& text,
0063                 Tp::ChannelTextMessageType type = Tp::ChannelTextMessageTypeNormal,
0064                 Tp::MessageSendingFlags flags = nullptr);
0065 
0066         bool supportsMessageType(Tp::ChannelTextMessageType messageType) const;
0067         QList<Tp::ChannelTextMessageType> supportedMessageTypes() const;
0068         QStringList supportedContentTypes() const;
0069         Tp::MessagePartSupportFlags messagePartSupport() const;
0070         Tp::DeliveryReportingSupportFlags deliveryReportingSupport() const;
0071 
0072         QList<Tp::ReceivedMessage> messageQueue() const;
0073 
0074     private:
0075         void setChannel(const Tp::TextChannelPtr &textChannel);
0076         void setupOTRChannel();
0077         void setupTextChannel();
0078 
0079     private Q_SLOTS:
0080         void onTrustLevelPropertyGet(Tp::PendingOperation *op);
0081         void onPendingMessagesPropertyGet(Tp::PendingOperation *op);
0082         void onRemoteFingerprintPropertyGet(Tp::PendingOperation *op);
0083         void onMessageReceived(const Tp::MessagePartList &message);
0084         void onPendingMessagesRemoved(const Tp::UIntList &messageIDs);
0085         void onMessageSent(const Tp::MessagePartList &content, uint flags, const QString &messageToken);
0086         void onTrustLevelChanged(uint trustLevel);
0087         void onPeerAuthenticationRequested(const QString &question);
0088 
0089     Q_SIGNALS:
0090         void messageSent(const Tp::Message &message,
0091                 Tp::MessageSendingFlags flags,
0092                 const QString &sentMessageToken);
0093         void messageReceived(const Tp::ReceivedMessage &message);
0094         void pendingMessageRemoved( const Tp::ReceivedMessage &message);
0095 
0096         void otrTrustLevelChanged(KTp::OTRTrustLevel newStatus, KTp::OTRTrustLevel oldStatus);
0097         void sessionRefreshed();
0098         void peerAuthenticationRequestedQA(const QString &question);
0099         void peerAuthenticationRequestedSS();
0100         void peerAuthenticationConcluded(bool authenticated);
0101         void peerAuthenticationInProgress();
0102         void peerAuthenticationAborted();
0103         void peerAuthenticationError();
0104         void peerAuthenticationCheated();
0105 
0106     private:
0107         struct Private;
0108         friend struct Private;
0109         Private *d;
0110 };
0111 
0112 typedef Tp::SharedPtr<ChannelAdapter> ChannelAdapterPtr;
0113 
0114 } /* namespace KTp */
0115 
0116 #endif