summaryrefslogtreecommitdiffstats
path: root/src/designer/src/designer
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2020-11-24 16:20:36 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-27 07:41:09 +0000
commit58816260c0f84ce60bf398a12935807d00575fa3 (patch)
treeccc5f626770fd0bc576c5055ba1033cb4d2c23bd /src/designer/src/designer
parente37700138dd143009233c17ee44de9d83925ec95 (diff)
Revert "Designer: Use QDesktopServices to show designer help"
This reverts commit 5f238adc4c652e6e1bb34752f201cf8e377cbc25 and commit 1d994b1471bd43d7003697b47e3f7d2ebfc808df Reason for revert: Qt Assistant is enabled again Change-Id: If28fdcf10686750a43e3cc88b5b846d69ec82cd5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> (cherry picked from commit a1caa657d8f2f561b52b39cf4355dd7b9d217f45) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/designer/src/designer')
-rw-r--r--src/designer/src/designer/.prev_CMakeLists.txt1
-rw-r--r--src/designer/src/designer/CMakeLists.txt1
-rw-r--r--src/designer/src/designer/assistantclient.cpp180
-rw-r--r--src/designer/src/designer/assistantclient.h72
-rw-r--r--src/designer/src/designer/designer.pro2
-rw-r--r--src/designer/src/designer/qdesigner_actions.cpp39
-rw-r--r--src/designer/src/designer/qdesigner_actions.h5
7 files changed, 275 insertions, 25 deletions
diff --git a/src/designer/src/designer/.prev_CMakeLists.txt b/src/designer/src/designer/.prev_CMakeLists.txt
index a95b2c0fa..0437ab492 100644
--- a/src/designer/src/designer/.prev_CMakeLists.txt
+++ b/src/designer/src/designer/.prev_CMakeLists.txt
@@ -9,6 +9,7 @@ qt_internal_add_app(designer
../../../shared/fontpanel/fontpanel.cpp ../../../shared/fontpanel/fontpanel.h
../../../shared/qttoolbardialog/qttoolbardialog.cpp ../../../shared/qttoolbardialog/qttoolbardialog.h ../../../shared/qttoolbardialog/qttoolbardialog.ui
appfontdialog.cpp appfontdialog.h
+ assistantclient.cpp assistantclient.h
designer_enums.h
main.cpp
mainwindow.cpp mainwindow.h
diff --git a/src/designer/src/designer/CMakeLists.txt b/src/designer/src/designer/CMakeLists.txt
index c60be4c8a..5de06465d 100644
--- a/src/designer/src/designer/CMakeLists.txt
+++ b/src/designer/src/designer/CMakeLists.txt
@@ -9,6 +9,7 @@ qt_internal_add_app(designer
../../../shared/fontpanel/fontpanel.cpp ../../../shared/fontpanel/fontpanel.h
../../../shared/qttoolbardialog/qttoolbardialog.cpp ../../../shared/qttoolbardialog/qttoolbardialog.h ../../../shared/qttoolbardialog/qttoolbardialog.ui
appfontdialog.cpp appfontdialog.h
+ assistantclient.cpp assistantclient.h
designer_enums.h
main.cpp
mainwindow.cpp mainwindow.h
diff --git a/src/designer/src/designer/assistantclient.cpp b/src/designer/src/designer/assistantclient.cpp
new file mode 100644
index 000000000..45fee4393
--- /dev/null
+++ b/src/designer/src/designer/assistantclient.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Designer of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "assistantclient.h"
+
+#include <QtCore/qstring.h>
+#include <QtCore/qprocess.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qlibraryinfo.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qfileinfo.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qtextstream.h>
+#include <QtCore/qcoreapplication.h>
+
+QT_BEGIN_NAMESPACE
+
+enum { debugAssistantClient = 0 };
+
+AssistantClient::AssistantClient() = default;
+
+AssistantClient::~AssistantClient()
+{
+ if (isRunning()) {
+ m_process->terminate();
+ m_process->waitForFinished();
+ }
+ delete m_process;
+}
+
+bool AssistantClient::showPage(const QString &path, QString *errorMessage)
+{
+ QString cmd = QStringLiteral("SetSource ");
+ cmd += path;
+ return sendCommand(cmd, errorMessage);
+}
+
+bool AssistantClient::activateIdentifier(const QString &identifier, QString *errorMessage)
+{
+ QString cmd = QStringLiteral("ActivateIdentifier ");
+ cmd += identifier;
+ return sendCommand(cmd, errorMessage);
+}
+
+bool AssistantClient::activateKeyword(const QString &keyword, QString *errorMessage)
+{
+ QString cmd = QStringLiteral("ActivateKeyword ");
+ cmd += keyword;
+ return sendCommand(cmd, errorMessage);
+}
+
+bool AssistantClient::sendCommand(const QString &cmd, QString *errorMessage)
+{
+ if (debugAssistantClient)
+ qDebug() << "sendCommand " << cmd;
+ if (!ensureRunning(errorMessage))
+ return false;
+ if (!m_process->isWritable() || m_process->bytesToWrite() > 0) {
+ *errorMessage = QCoreApplication::translate("AssistantClient", "Unable to send request: Assistant is not responding.");
+ return false;
+ }
+ QTextStream str(m_process);
+ str << cmd << QLatin1Char('\n') << Qt::endl;
+ return true;
+}
+
+bool AssistantClient::isRunning() const
+{
+ return m_process && m_process->state() != QProcess::NotRunning;
+}
+
+QString AssistantClient::binary()
+{
+ QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QDir::separator();
+#if !defined(Q_OS_MACOS)
+ app += QStringLiteral("assistant");
+#else
+ app += QStringLiteral("Assistant.app/Contents/MacOS/Assistant");
+#endif
+
+#if defined(Q_OS_WIN)
+ app += QStringLiteral(".exe");
+#endif
+
+ return app;
+}
+
+void AssistantClient::readyReadStandardError()
+{
+ qWarning("%s: %s",
+ qPrintable(QDir::toNativeSeparators(m_process->program())),
+ m_process->readAllStandardError().constData());
+}
+
+void AssistantClient::processTerminated(int exitCode, QProcess::ExitStatus exitStatus)
+{
+ const QString binary = QDir::toNativeSeparators(m_process->program());
+ if (exitStatus != QProcess::NormalExit)
+ qWarning("%s: crashed.", qPrintable(binary));
+ else if (exitCode != 0)
+ qWarning("%s: terminated with exit code %d.", qPrintable(binary), exitCode);
+}
+
+bool AssistantClient::ensureRunning(QString *errorMessage)
+{
+ if (isRunning())
+ return true;
+
+ if (!m_process) {
+ m_process = new QProcess;
+ QObject::connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
+ this, &AssistantClient::processTerminated);
+ QObject::connect(m_process, &QProcess::readyReadStandardError,
+ this, &AssistantClient::readyReadStandardError);
+ }
+
+ const QString app = binary();
+ if (!QFileInfo(app).isFile()) {
+ *errorMessage = QCoreApplication::translate("AssistantClient", "The binary '%1' does not exist.").arg(app);
+ return false;
+ }
+ if (debugAssistantClient)
+ qDebug() << "Running " << app;
+ // run
+ QStringList args(QStringLiteral("-enableRemoteControl"));
+ m_process->start(app, args);
+ if (!m_process->waitForStarted()) {
+ *errorMessage = QCoreApplication::translate("AssistantClient", "Unable to launch assistant (%1).").arg(app);
+ return false;
+ }
+ return true;
+}
+
+QString AssistantClient::documentUrl(const QString &module, int qtVersion)
+{
+ if (qtVersion == 0)
+ qtVersion = QT_VERSION;
+ QString rc;
+ QTextStream(&rc) << "qthelp://org.qt-project." << module << '.'
+ << (qtVersion >> 16) << ((qtVersion >> 8) & 0xFF) << (qtVersion & 0xFF)
+ << '/' << module << '/';
+ return rc;
+}
+
+QString AssistantClient::designerManualUrl(int qtVersion)
+{
+ return documentUrl(QStringLiteral("qtdesigner"), qtVersion);
+}
+
+QString AssistantClient::qtReferenceManualUrl(int qtVersion)
+{
+ return documentUrl(QStringLiteral("qtdoc"), qtVersion);
+}
+
+QT_END_NAMESPACE
diff --git a/src/designer/src/designer/assistantclient.h b/src/designer/src/designer/assistantclient.h
new file mode 100644
index 000000000..94618662a
--- /dev/null
+++ b/src/designer/src/designer/assistantclient.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Designer of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ASSISTANTCLIENT_H
+#define ASSISTANTCLIENT_H
+
+#include <QtCore/qprocess.h>
+
+QT_BEGIN_NAMESPACE
+
+class QString;
+
+class AssistantClient : public QObject
+{
+ Q_OBJECT
+
+public:
+ AssistantClient();
+ ~AssistantClient();
+
+ bool showPage(const QString &path, QString *errorMessage);
+ bool activateIdentifier(const QString &identifier, QString *errorMessage);
+ bool activateKeyword(const QString &keyword, QString *errorMessage);
+
+ bool isRunning() const;
+
+ static QString documentUrl(const QString &prefix, int qtVersion = 0);
+ // Root of the Qt Designer documentation
+ static QString designerManualUrl(int qtVersion = 0);
+ // Root of the Qt Reference documentation
+ static QString qtReferenceManualUrl(int qtVersion = 0);
+
+private slots:
+ void readyReadStandardError();
+ void processTerminated(int exitCode, QProcess::ExitStatus exitStatus);
+
+private:
+ static QString binary();
+ bool sendCommand(const QString &cmd, QString *errorMessage);
+ bool ensureRunning(QString *errorMessage);
+
+ QProcess *m_process = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // ASSISTANTCLIENT_H
diff --git a/src/designer/src/designer/designer.pro b/src/designer/src/designer/designer.pro
index cddef1fbc..6a925202a 100644
--- a/src/designer/src/designer/designer.pro
+++ b/src/designer/src/designer/designer.pro
@@ -33,6 +33,7 @@ HEADERS += \
designer_enums.h \
appfontdialog.h \
preferencesdialog.h \
+ assistantclient.h \
mainwindow.h
SOURCES += main.cpp \
@@ -49,6 +50,7 @@ SOURCES += main.cpp \
versiondialog.cpp \
appfontdialog.cpp \
preferencesdialog.cpp \
+ assistantclient.cpp \
mainwindow.cpp
PRECOMPILED_HEADER=qdesigner_pch.h
diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp
index 55e250283..4b98d6493 100644
--- a/src/designer/src/designer/qdesigner_actions.cpp
+++ b/src/designer/src/designer/qdesigner_actions.cpp
@@ -70,12 +70,9 @@
#include <QtGui/qaction.h>
#include <QtGui/qactiongroup.h>
-#include <QtGui/qcursor.h>
-#include <QtGui/qdesktopservices.h>
#include <QtGui/qevent.h>
#include <QtGui/qicon.h>
#include <QtGui/qimage.h>
-#include <QtGui/qpainter.h>
#include <QtGui/qpixmap.h>
#include <QtGui/qscreen.h>
#if defined(QT_PRINTSUPPORT_LIB) // Some platforms may not build QtPrintSupport
@@ -86,7 +83,9 @@
# define HAS_PRINTER
# endif
#endif
+#include <QtGui/qpainter.h>
#include <QtGui/qtransform.h>
+#include <QtGui/qcursor.h>
#include <QtCore/qsize.h>
#include <QtCore/qlibraryinfo.h>
@@ -988,32 +987,23 @@ QAction *QDesignerActions::minimizeAction() const
void QDesignerActions::showDesignerHelp()
{
- showHelp("qtdesigner-manual.html");
+ QString url = AssistantClient::designerManualUrl();
+ url += QStringLiteral("qtdesigner-manual.html");
+ showHelp(url);
}
void QDesignerActions::helpRequested(const QString &manual, const QString &document)
{
- Q_UNUSED(manual);
- showHelp(document);
+ QString url = AssistantClient::documentUrl(manual);
+ url += document;
+ showHelp(url);
}
-bool QDesignerActions::showHelp(const QString &htmlFile)
+void QDesignerActions::showHelp(const QString &url)
{
- const int qtVersion = QT_VERSION;
- QString url;
- QTextStream(&url) << "https://doc.qt.io/qt-" << (qtVersion >> 16)
-// TODO: uncomment the line below just before Qt 6.0 release
-// we should have then https://doc.qt.io/qt-6.0/ link valid (like in case of 5.x series).
-// Currently it redirects to Qt 6 snapshot.
-// << "." << ((qtVersion >> 8) & 0xFF)
- << '/' << htmlFile;
-
- return QDesktopServices::openUrl(QUrl(url));
-}
-
-bool QDesignerActions::showIdentifier(const QString &identifier)
-{
- return showHelp(identifier.toLower() + ".html");
+ QString errorMessage;
+ if (!m_assistantClient.showPage(url, &errorMessage))
+ QMessageBox::warning(core()->topLevel(), tr("Assistant"), errorMessage);
}
void QDesignerActions::aboutDesigner()
@@ -1042,7 +1032,10 @@ void QDesignerActions::showWidgetSpecificHelp()
return;
}
- showIdentifier(helpId);
+ QString errorMessage;
+ const bool rc = m_assistantClient.activateIdentifier(helpId, &errorMessage);
+ if (!rc)
+ QMessageBox::warning(core()->topLevel(), tr("Assistant"), errorMessage);
}
void QDesignerActions::updateCloseAction()
diff --git a/src/designer/src/designer/qdesigner_actions.h b/src/designer/src/designer/qdesigner_actions.h
index 715388b4e..4192a002b 100644
--- a/src/designer/src/designer/qdesigner_actions.h
+++ b/src/designer/src/designer/qdesigner_actions.h
@@ -29,6 +29,7 @@
#ifndef QDESIGNER_ACTIONS_H
#define QDESIGNER_ACTIONS_H
+#include "assistantclient.h"
#include "qdesigner_settings.h"
#include <QtCore/qobject.h>
@@ -142,8 +143,7 @@ private:
bool saveFormAs(QDesignerFormWindowInterface *fw);
void updateRecentFileActions();
void addRecentFile(const QString &fileName);
- bool showIdentifier(const QString &identifier);
- bool showHelp(const QString &htmlFile);
+ void showHelp(const QString &help);
void closePreview();
QRect fixDialogRect(const QRect &rect) const;
QString fixResourceFileBackupPath(QDesignerFormWindowInterface *fwi, const QDir& backupDir);
@@ -158,6 +158,7 @@ private:
QDesignerWorkbench *m_workbench;
QDesignerFormEditorInterface *m_core;
QDesignerSettings m_settings;
+ AssistantClient m_assistantClient;
QString m_openDirectory;
QString m_saveDirectory;