| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef TEXTFACTORY_H |
| 4 | #define TEXTFACTORY_H |
| 5 | |
| 6 | #include "definitions/definitions.h" |
| 7 | |
| 8 | #include <QDateTime> |
| 9 | #include <QFontMetrics> |
| 10 | |
| 11 | class RSSGUARD_DLLSPEC TextFactory { |
| 12 | private: |
| 13 | // Constructors and destructors. |
| 14 | TextFactory(); |
| 15 | |
| 16 | public: |
| 17 | static QColor generateColorFromText(const QString& text); |
| 18 | static QColor generateRandomColor(); |
| 19 | |
| 20 | static QString extractUsernameFromEmail(const QString& email_address); |
| 21 | static int stringHeight(const QString& string, const QFontMetrics& metrics); |
| 22 | static int stringWidth(const QString& string, const QFontMetrics& metrics); |
| 23 | |
| 24 | static bool couldBeHtml(const QString& string); |
| 25 | |
| 26 | // Tries to parse input textual date/time representation. |
| 27 | // Returns invalid date/time if processing fails. |
| 28 | // NOTE: This method tries to always return time in UTC. |
| 29 | static QDateTime parseDateTime(const QString& date_time, QString* used_dt_format = nullptr); |
| 30 | |
| 31 | // Converts 1970-epoch miliseconds to date/time. |
| 32 | // NOTE: This method tries to always return time in UTC. |
| 33 | static QDateTime parseDateTime(qint64 milis_from_epoch); |
| 34 | static QStringList dateTimePatterns(bool with_tzs); |
| 35 | static QString encrypt(const QString& text, quint64 key = 0); |
| 36 | static QString decrypt(const QString& text, quint64 key = 0); |
| 37 | static QString newline(); |
| 38 | static QString capitalizeFirstLetter(const QString& sts); |
| 39 | static QStringList tokenizeProcessArguments(const QString& command); |
| 40 | |
| 41 | // Shortens input string according to given length limit. |
| 42 | static QString shorten(const QString& input, int text_length_limit = TEXT_TITLE_LIMIT); |
| 43 | |
| 44 | private: |
| 45 | static quint64 initializeSecretEncryptionKey(); |
| 46 | static quint64 generateSecretEncryptionKey(); |
| 47 | static quint64 s_encryptionKey; |
| 48 | }; |
| 49 | |
| 50 | #endif // TEXTFACTORY_H |