11#include <QtCore/QFile>
12#include <QtCore/QFileInfo>
13#include <QtCore/QFileSystemWatcher>
14#include <QtCore/QTextStream>
16#include <QtWidgets/QMessageBox>
17#include <QtWidgets/QApplication>
19#include <QtHelp/QHelpEngine>
20#include <QtHelp/QHelpFilterEngine>
21#include <QtHelp/QHelpIndexWidget>
22#include <QtHelp/QHelpLink>
23#include <QtHelp/QHelpSearchQueryWidget>
26# include "stdinlistener_win.h"
33using namespace Qt::StringLiterals;
37 , m_mainWindow(mainWindow)
41 connect(m_mainWindow, &MainWindow::initDone,
42 this, &RemoteControl::applyCache);
45 connect(l, &StdInListener::receivedCommand,
46 this, &RemoteControl::handleCommandString);
50void RemoteControl::handleCommandString(
const QString &cmdString)
53 const QStringList &commands = cmdString.split(u';');
54 for (
const QString &command : commands) {
56 splitInputString(command, cmd, arg);
59 QMessageBox::information(
nullptr, tr(
"Debugging Remote Control"),
60 tr(
"Received Command: %1 %2").arg(cmd).arg(arg));
62 if (cmd ==
"debug"_L1)
63 handleDebugCommand(arg);
64 else if (cmd ==
"show"_L1)
65 handleShowOrHideCommand(arg,
true);
66 else if (cmd ==
"hide"_L1)
67 handleShowOrHideCommand(arg,
false);
68 else if (cmd ==
"setsource"_L1)
69 handleSetSourceCommand(arg);
70 else if (cmd ==
"synccontents"_L1)
71 handleSyncContentsCommand();
72 else if (cmd ==
"activatekeyword"_L1)
73 handleActivateKeywordCommand(arg);
74 else if (cmd ==
"activateidentifier"_L1)
75 handleActivateIdentifierCommand(arg);
76 else if (cmd ==
"expandtoc"_L1)
77 handleExpandTocCommand(arg);
78 else if (cmd ==
"setcurrentfilter"_L1)
79 handleSetCurrentFilterCommand(arg);
80 else if (cmd ==
"register"_L1)
81 handleRegisterCommand(arg);
82 else if (cmd ==
"unregister"_L1)
83 handleUnregisterCommand(arg);
87 m_mainWindow->raise();
88 m_mainWindow->activateWindow();
91void RemoteControl::splitInputString(
const QString &input, QString &cmd,
95 QString cmdLine = input.trimmed();
96 int i = cmdLine.indexOf(u' ');
97 cmd = cmdLine.left(i);
98 arg = cmdLine.mid(i + 1);
105 m_debug = arg ==
"on"_L1;
108void RemoteControl::handleShowOrHideCommand(
const QString &arg,
bool show)
111 if (arg.toLower() ==
"contents"_L1)
112 m_mainWindow->setContentsVisible(show);
113 else if (arg.toLower() ==
"index"_L1)
115 else if (arg.toLower() ==
"bookmarks"_L1)
117 else if (arg.toLower() ==
"search"_L1)
121void RemoteControl::handleSetSourceCommand(
const QString &arg)
126 if (url.isRelative())
141 m_syncContents =
true;
146void RemoteControl::handleActivateKeywordCommand(
const QString &arg)
151 m_activateKeyword = arg;
153 m_mainWindow->setIndexString(arg);
154 if (!arg.isEmpty()) {
159 if (QHelpSearchQueryWidget *w = se->queryWidget()) {
160 w->collapseExtendedSearch();
161 w->setSearchInput(arg);
173void RemoteControl::handleActivateIdentifierCommand(
const QString &arg)
178 m_activateIdentifier = arg;
180 const auto docs = helpEngine.documentsForIdentifier(arg);
186void RemoteControl::handleExpandTocCommand(
const QString &arg)
192 depth = arg.toInt(&ok);
193 if (!ok || depth < -2)
198 else if (depth != -2)
202void RemoteControl::handleSetCurrentFilterCommand(
const QString &arg)
208 m_currentFilter = arg;
218 const QString &absFileName = QFileInfo(arg).absoluteFilePath();
219 if (helpEngine.registeredDocumentations().
220 contains(QHelpEngineCore::namespaceName(absFileName)))
222 if (helpEngine.registerDocumentation(absFileName))
226void RemoteControl::handleUnregisterCommand(
const QString &arg)
229 const QString &absFileName = QFileInfo(arg).absoluteFilePath();
230 const QString &ns = QHelpEngineCore::namespaceName(absFileName);
231 if (helpEngine.registeredDocumentations().contains(ns)) {
233 if (helpEngine.unregisterDocumentation(ns))
241 if (m_setSource.isValid()) {
242 CentralWidget::instance()->setSource(m_setSource);
243 }
else if (!m_activateKeyword.isEmpty()) {
244 m_mainWindow->setIndexString(m_activateKeyword);
246 }
else if (!m_activateIdentifier.isEmpty()) {
248 helpEngine.documentsForIdentifier(m_activateIdentifier);
251 }
else if (!m_currentFilter.isEmpty()) {
252 helpEngine.filterEngine()->setActiveFilter(m_currentFilter);
258 Q_ASSERT(m_expandTOC >= -2);
259 if (m_expandTOC != -2)
268 m_currentFilter.clear();
270 m_syncContents =
false;
271 m_activateKeyword.clear();
272 m_activateIdentifier.clear();
QHelpFilterEngine * filterEngine() const
QHelpSearchEngine * searchEngine() const
bool fullTextSearchFallbackEnabled() const
QHelpIndexWidget * indexWidget()
static HelpEngineWrapper & instance()
void setBookmarksVisible(bool visible)
void expandTOC(int depth)
void setIndexVisible(bool visible)
void setSearchVisible(bool visible)
static OpenPagesManager * instance()
Combined button and popup list for selecting options.