File indexing completed on 2023-05-30 11:40:29
0001 /* 0002 Telepathy status message parser class 0003 Copyright (C) 2017 James D. Smith <smithjd15@gmail.com> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Lesser General Public 0007 License as published by the Free Software Foundation; either 0008 version 2.1 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public 0016 License along with this library; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 #ifndef STATUSMESSAGEPARSER_H 0021 #define STATUSMESSAGEPARSER_H 0022 0023 #include <QObject> 0024 0025 #include <QTimer> 0026 #include <QElapsedTimer> 0027 #include <QDateTime> 0028 #include <QHash> 0029 #include <QString> 0030 0031 #include "telepathy-mpris.h" 0032 0033 /** 0034 * This class parses status messages for substitution and command matches, 0035 * substituting tokens for timers and other data sources as necessary. 0036 */ 0037 0038 class StatusMessageParser : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 explicit StatusMessageParser(QObject *parent = 0); 0044 ~StatusMessageParser(); 0045 0046 /** 0047 * \brief Returns a parsed string. 0048 * 0049 * \return The parsed status message. 0050 */ 0051 QString statusMessage() const; 0052 0053 /** 0054 * \brief Returns the tokens with parameters (if any) that were used to construct the status mesage. 0055 * 0056 * \return A QHash<QString, QString>. 0057 */ 0058 QHash<QString, QString> tokens() const; 0059 0060 /** 0061 * \brief Returns a parsed status message, and activates any data sources 0062 * needed for periodic updates. 0063 * 0064 * \param message The string to parse for tokens. 0065 * 0066 * \return The status message. 0067 */ 0068 QString parseStatusMessage(QString message); 0069 0070 /** 0071 * \brief Clear the status message, deactivating all update sources. 0072 */ 0073 void clearStatusMessage(); 0074 0075 Q_SIGNALS: 0076 void statusMessageChanged(const QString &message); 0077 0078 private: 0079 void updateMessage(); 0080 QElapsedTimer *m_elapsedTimer; 0081 QTimer *m_updateTimer; 0082 QTimer *m_expireTimer; 0083 TelepathyMPRIS *m_mpris; 0084 0085 QHash<QString, QString> m_tokens; 0086 QString m_statusMessage; 0087 QString m_parsedMessage; 0088 QString m_followUp; 0089 QString m_timeFormat; 0090 QString m_utcFormat; 0091 QString m_separator; 0092 0093 double m_intervalElapsed; 0094 bool m_nowPlayingExpire; 0095 }; 0096 0097 #endif // STATUS_MESSAGE_PARSER_H