| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qhelp_global.h" |
| 5 | #include <QtTools/qttools-config.h> |
| 6 | |
| 7 | #include <QtCore/qcoreapplication.h> |
| 8 | #include <QtCore/qhash.h> |
| 9 | #include <QtCore/qmutex.h> |
| 10 | #if QT_CONFIG(fullqthelp) |
| 11 | # include <QtGui/qtextdocument.h> |
| 12 | #endif |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | using namespace Qt::StringLiterals; |
| 17 | |
| 18 | QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer) |
| 19 | { |
| 20 | static QMutex mutex; |
| 21 | QMutexLocker locker(&mutex); |
| 22 | static QHash<QString, quint16> idHash; |
| 23 | return QString::asprintf(format: "%ls-%p-%d" , qUtf16Printable(name), pointer, ++idHash[name]); |
| 24 | } |
| 25 | |
| 26 | QString QHelpGlobal::documentTitle(const QString &content) |
| 27 | { |
| 28 | #if QT_CONFIG(fullqthelp) |
| 29 | QString title = QCoreApplication::translate(context: "QHelp" , key: "Untitled" ); |
| 30 | if (!content.isEmpty()) { |
| 31 | const int start = content.indexOf(s: "<title>"_L1 , from: 0, cs: Qt::CaseInsensitive) + 7; |
| 32 | const int end = content.indexOf(s: "</title>"_L1 , from: 0, cs: Qt::CaseInsensitive); |
| 33 | if ((end - start) > 0) { |
| 34 | title = content.mid(position: start, n: end - start); |
| 35 | if (Qt::mightBeRichText(title) || title.contains(c: u'&')) { |
| 36 | QTextDocument doc; |
| 37 | doc.setHtml(title); |
| 38 | title = doc.toPlainText(); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | return title; |
| 43 | #else |
| 44 | Q_UNUSED(content); |
| 45 | return {}; |
| 46 | #endif |
| 47 | } |
| 48 | |
| 49 | QT_END_NAMESPACE |
| 50 | |