File indexing completed on 2023-10-01 08:41:45
0001 /* 0002 Copyright (C) 2012 Lasath Fernando <kde@lasath.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library 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 GNU 0012 Lesser General Public License for more details. 0013 0014 You should have received a copy of the GNU Lesser General Public 0015 License along with this library; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 0020 #ifndef KTP_MESSAGE_H 0021 #define KTP_MESSAGE_H 0022 0023 #include <TelepathyQt/Message> 0024 0025 #include <KTp/ktpcommoninternals_export.h> 0026 #include <KTp/types.h> 0027 0028 #include <KTp/message-context.h> 0029 0030 #include <QSharedData> 0031 #include <QSharedDataPointer> 0032 0033 namespace KTp 0034 { 0035 0036 /*! 0037 * \par 0038 * An encapsualtion of a Tp::Message that can be procesesd 0039 * by many MessageFilters concurrently. 0040 * 0041 * \par 0042 * Contains multiple parts created by plugins, to be displayed by user 0043 * interfaces. Also contains internal metadata for use by other plugins. 0044 * 0045 * \note 0046 * Methods in this class are currently *not* thread safe. They will be in a 0047 * later version. Setting properties concurrently is undefined. 0048 * 0049 * \author Lasath Fernando <kde@lasath.org> 0050 */ 0051 class KTPCOMMONINTERNALS_EXPORT Message 0052 { 0053 public: 0054 enum MessageDirection { 0055 LocalToRemote, 0056 RemoteToLocal 0057 }; 0058 0059 Message(const KTp::Message &other); 0060 KTp::Message& operator=(const KTp::Message &other); 0061 virtual ~Message(); 0062 0063 /*! \brief The body of the message 0064 * \return the contents of the body of the message, as HTML 0065 */ 0066 QString mainMessagePart() const; 0067 0068 /*! \brief Edit the main component of the message 0069 * 0070 * \param message the string to replace the body with. Must be correct HTML 0071 */ 0072 void setMainMessagePart(const QString &message); 0073 0074 /*! \brief Add new visual content to the end of the message 0075 * 0076 * \par 0077 * Each plugin that adds visual components should call this once thier 0078 * processing is complete. Once a message part is added, it cannot be 0079 * changed! 0080 * 0081 * \param part the content to be added, in valid HTML 0082 */ 0083 void appendMessagePart(const QString &part); 0084 0085 /*! \brief Append a script 0086 * 0087 * \par 0088 * Each plugin that requires to run a script after the page is updated can 0089 * use this method to add a script will be run after the message is appended 0090 */ 0091 void appendScript(const QString &script); 0092 0093 /*! \brief Construct the final procesesd content 0094 * 0095 * \par 0096 * This will concatenate all the visual 'parts' of the message into one 0097 * (Qt supported) HTML string. 0098 * 0099 * \note 0100 * All user interfaces need only care about this 0101 * 0102 */ 0103 QString finalizedMessage() const; 0104 0105 /*! \brief Construct the final script 0106 * 0107 * \par 0108 * This will concatenate all the scripts parts of the message into one 0109 * script that must be executed after the finalized message is appended. 0110 */ 0111 QString finalizedScript() const; 0112 0113 /*! \brief Sets the contents of a property 0114 * \par 0115 * These messages contain meta-data for plugins in the form of 'properties'. 0116 * A property can be set to any QMetaType (i.e type that can stuck in a 0117 * QVariant) and is identified by a string (name). 0118 * 0119 * \par 0120 * These are set by plugins for use in other plugins, creating implicit 0121 * dependencies between plugins. Since these plugins are (or will be) 0122 * run concurrently, calling this method on a property that hasn't been set 0123 * yet will block until it has been set by some plugin. If it isn't set when 0124 * all plugins are finished, this plugin will be cancelled. 0125 * 0126 * \param name the identifier of the property 0127 */ 0128 QVariant property(const char *name) const; 0129 void setProperty(const char *name, const QVariant &value); 0130 0131 /*! \return the time the message was sent*/ 0132 QDateTime time() const; 0133 /*! \return the unique token from the message*/ 0134 QString token() const; 0135 /*! \return the type of the message*/ 0136 Tp::ChannelTextMessageType type() const; 0137 0138 /*! \return the alias of the contact who composed this message */ 0139 QString senderAlias() const; 0140 /*! \return the id of the contact who composed this message */ 0141 QString senderId() const; 0142 0143 /*! \return the contact who composed this message 0144 * @warning This may be null for service messages, log messages and other cases 0145 */ 0146 KTp::ContactPtr sender() const; 0147 0148 /*! \return the number of appended parts */ 0149 int partsSize() const; 0150 0151 /** Returns if the message is history (either from logger or scrollack*/ 0152 bool isHistory() const; 0153 0154 MessageDirection direction() const; 0155 0156 bool operator==(const KTp::Message &other) const; 0157 0158 protected: 0159 class Private; 0160 0161 Message(const Tp::Message &original, const KTp::MessageContext &context); 0162 Message(const Tp::ReceivedMessage &original, const KTp::MessageContext &context); 0163 Message(KTp::Message::Private *dd); 0164 0165 QSharedDataPointer<Private> d; 0166 friend class MessageProcessor; 0167 }; 0168 0169 } 0170 0171 0172 #endif // MESSAGE_H