1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 2 3 This file is part of the Trojita Qt IMAP e-mail client, 4 http://trojita.flaska.net/ 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of 9 the License or (at your option) version 3 or any later version 10 accepted by the membership of KDE e.V. (or its successor approved 11 by the membership of KDE e.V.), which shall act as a proxy 12 defined in Section 14 of version 3 of the license. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 #ifndef TROJITA_UIUTILS_FORMATTING_H 23 #define TROJITA_UIUTILS_FORMATTING_H 24 25 #include <QDateTime> 26 #include <QModelIndex> 27 #include <QObject> 28 29 class QSettings; 30 class QSslCertificate; 31 class QSslError; 32 class QQmlEngine; 33 class QJSEngine; 34 35 namespace UiUtils { 36 37 class Formatting: public QObject 38 { 39 Q_OBJECT 40 public: 41 /** @short Shamelessly stolen from QMessageBox */ 42 enum class IconType { 43 NoIcon = 0, 44 Information = 1, 45 Warning = 2, 46 Critical = 3, 47 Question = 4 48 }; 49 50 Q_INVOKABLE static QString prettySize(quint64 bytes); 51 Q_INVOKABLE static QString prettyDate(const QDateTime &dateTime); 52 Q_INVOKABLE static QString htmlizedTextPart(const QModelIndex &partIndex, const QFont &font, 53 const QColor &backgroundColor, const QColor &textColor, 54 const QColor &linkColor, const QColor &visitedLinkColor); 55 56 static QString sslChainToHtml(const QList<QSslCertificate> &sslChain); 57 static QString sslErrorsToHtml(const QList<QSslError> &sslErrors); 58 59 static void formatSslState(const QList<QSslCertificate> &sslChain, const QByteArray &oldPubKey, 60 const QList<QSslError> &sslErrors, QString *title, QString *message, IconType *icon); 61 62 static QString htmlHexifyByteArray(const QByteArray &rawInput); 63 64 static QString htmlEscaped(const QString &input); 65 66 static QObject *factory(QQmlEngine *engine, QJSEngine *scriptEngine); 67 68 private: 69 Formatting(QObject *parent); 70 }; 71 72 bool elideAddress(QString &address); 73 74 } 75 76 #endif 77