summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2014-10-24 16:24:37 +0400
committerAlexander Volkov <a.volkov@rusbitech.ru>2014-12-22 16:59:37 +0100
commit58bd34016974dbbd0d99adfd497b9aab8ad273bf (patch)
treedd2deb64fadd859e94cc4873f189d74e3686143c
parentb0bd62581b1181d6c0955fc10c10dfe1b1aeb288 (diff)
Assistant: Extract StdInListener class from RemoteControl
Also rename StdInListenerWin to StdInListener and select the needed version during compilation. Change-Id: I4ef45feee71bae47ef3dfb63e91b7e3154886006 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com> Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r--src/assistant/assistant/assistant.pro9
-rw-r--r--src/assistant/assistant/remotecontrol.cpp79
-rw-r--r--src/assistant/assistant/remotecontrol.h1
-rw-r--r--src/assistant/assistant/stdinlistener.cpp73
-rw-r--r--src/assistant/assistant/stdinlistener.h61
-rw-r--r--src/assistant/assistant/stdinlistener_win.cpp84
-rw-r--r--src/assistant/assistant/stdinlistener_win.h (renamed from src/assistant/assistant/remotecontrol_win.h)10
7 files changed, 236 insertions, 81 deletions
diff --git a/src/assistant/assistant/assistant.pro b/src/assistant/assistant/assistant.pro
index 5f96377e3..6e82b076c 100644
--- a/src/assistant/assistant/assistant.pro
+++ b/src/assistant/assistant/assistant.pro
@@ -41,7 +41,6 @@ HEADERS += aboutdialog.h \
openpageswidget.h \
openpagesmanager.h \
openpagesswitcher.h
-win32:HEADERS += remotecontrol_win.h
SOURCES += aboutdialog.cpp \
bookmarkdialog.cpp \
@@ -78,6 +77,14 @@ qtHaveModule(webkitwidgets):!contains(QT_CONFIG, static) {
SOURCES += helpviewer_qtb.cpp
}
+win32 {
+ HEADERS += stdinlistener_win.h
+ SOURCES += stdinlistener_win.cpp
+} else {
+ HEADERS += stdinlistener.h
+ SOURCES += stdinlistener.cpp
+}
+
FORMS += bookmarkdialog.ui \
bookmarkmanagerwidget.ui \
bookmarkwidget.ui \
diff --git a/src/assistant/assistant/remotecontrol.cpp b/src/assistant/assistant/remotecontrol.cpp
index c5bf7dd92..7758e104f 100644
--- a/src/assistant/assistant/remotecontrol.cpp
+++ b/src/assistant/assistant/remotecontrol.cpp
@@ -41,9 +41,7 @@
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QFileSystemWatcher>
-#include <QtCore/QThread>
#include <QtCore/QTextStream>
-#include <QtCore/QSocketNotifier>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QApplication>
@@ -53,57 +51,12 @@
#include <QtHelp/QHelpSearchQueryWidget>
#ifdef Q_OS_WIN
-# include "remotecontrol_win.h"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#ifdef Q_OS_WIN
-
-StdInListenerWin::StdInListenerWin(QObject *parent)
- : QThread(parent)
-{
- TRACE_OBJ
-}
-
-StdInListenerWin::~StdInListenerWin()
-{
- TRACE_OBJ
- terminate();
- wait();
-}
-
-void StdInListenerWin::run()
-{
- TRACE_OBJ
- bool ok = true;
- char chBuf[4096];
- DWORD dwRead;
-
-#ifndef Q_OS_WINCE
- HANDLE hStdin, hStdinDup;
-
- hStdin = GetStdHandle(STD_INPUT_HANDLE);
- if (hStdin == INVALID_HANDLE_VALUE)
- return;
-
- DuplicateHandle(GetCurrentProcess(), hStdin,
- GetCurrentProcess(), &hStdinDup,
- 0, false, DUPLICATE_SAME_ACCESS);
-
- CloseHandle(hStdin);
+# include "stdinlistener_win.h"
#else
- HANDLE hStdinDup;
- hStdinDup = stdin;
+# include "stdinlistener.h"
#endif
- while (ok) {
- ok = ReadFile(hStdinDup, chBuf, sizeof(chBuf), &dwRead, NULL);
- if (ok && dwRead != 0)
- emit receivedCommand(QString::fromLocal8Bit(chBuf, dwRead));
- }
-}
-#endif
+QT_BEGIN_NAMESPACE
RemoteControl::RemoteControl(MainWindow *mainWindow)
: QObject(mainWindow)
@@ -117,33 +70,11 @@ RemoteControl::RemoteControl(MainWindow *mainWindow)
{
TRACE_OBJ
connect(m_mainWindow, SIGNAL(initDone()), this, SLOT(applyCache()));
-#ifdef Q_OS_WIN
- StdInListenerWin *l = new StdInListenerWin(this);
+
+ StdInListener *l = new StdInListener(this);
connect(l, SIGNAL(receivedCommand(QString)),
this, SLOT(handleCommandString(QString)));
l->start();
-#else
- QSocketNotifier *notifier = new QSocketNotifier(fileno(stdin),
- QSocketNotifier::Read, this);
- connect(notifier, SIGNAL(activated(int)), this, SLOT(receivedData()));
- notifier->setEnabled(true);
-#endif
-}
-
-void RemoteControl::receivedData()
-{
- TRACE_OBJ
- QByteArray ba;
- while (true) {
- const int c = getc(stdin);
- if (c == EOF || c == '\0')
- break;
- if (c)
- ba.append(char(c));
- if (c == '\n')
- break;
- }
- handleCommandString(QString::fromLocal8Bit(ba));
}
void RemoteControl::handleCommandString(const QString &cmdString)
diff --git a/src/assistant/assistant/remotecontrol.h b/src/assistant/assistant/remotecontrol.h
index 088a9dcb6..6602681b4 100644
--- a/src/assistant/assistant/remotecontrol.h
+++ b/src/assistant/assistant/remotecontrol.h
@@ -51,7 +51,6 @@ public:
RemoteControl(MainWindow *mainWindow);
private slots:
- void receivedData();
void handleCommandString(const QString &cmdString);
void applyCache();
diff --git a/src/assistant/assistant/stdinlistener.cpp b/src/assistant/assistant/stdinlistener.cpp
new file mode 100644
index 000000000..36cf8fb59
--- /dev/null
+++ b/src/assistant/assistant/stdinlistener.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stdinlistener.h"
+
+#include "tracer.h"
+
+QT_BEGIN_NAMESPACE
+
+StdInListener::StdInListener(QObject *parent)
+ : QSocketNotifier(fileno(stdin), QSocketNotifier::Read, parent)
+{
+ TRACE_OBJ
+ connect(this, SIGNAL(activated(int)), this, SLOT(receivedData()));
+}
+
+StdInListener::~StdInListener()
+{
+ TRACE_OBJ
+}
+
+void StdInListener::start()
+{
+ setEnabled(true);
+}
+
+void StdInListener::receivedData()
+{
+ TRACE_OBJ
+ QByteArray ba;
+ while (true) {
+ const int c = getc(stdin);
+ if (c == EOF || c == '\0')
+ break;
+ if (c)
+ ba.append(char(c));
+ if (c == '\n')
+ break;
+ }
+ emit receivedCommand(QString::fromLocal8Bit(ba));
+}
+
+QT_END_NAMESPACE
diff --git a/src/assistant/assistant/stdinlistener.h b/src/assistant/assistant/stdinlistener.h
new file mode 100644
index 000000000..6278b04aa
--- /dev/null
+++ b/src/assistant/assistant/stdinlistener.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STDINLISTENER_H
+#define STDINLISTENER_H
+
+#include <QtCore/QSocketNotifier>
+
+QT_BEGIN_NAMESPACE
+
+class StdInListener : public QSocketNotifier
+{
+ Q_OBJECT
+
+public:
+ StdInListener(QObject *parent);
+ ~StdInListener();
+
+public slots:
+ void start();
+
+signals:
+ void receivedCommand(const QString &cmd);
+
+private slots:
+ void receivedData();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/assistant/assistant/stdinlistener_win.cpp b/src/assistant/assistant/stdinlistener_win.cpp
new file mode 100644
index 000000000..9d80b600d
--- /dev/null
+++ b/src/assistant/assistant/stdinlistener_win.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stdinlistener_win.h"
+
+#include "tracer.h"
+
+QT_BEGIN_NAMESPACE
+
+StdInListener::StdInListener(QObject *parent)
+ : QThread(parent)
+{
+ TRACE_OBJ
+}
+
+StdInListener::~StdInListener()
+{
+ TRACE_OBJ
+ terminate();
+ wait();
+}
+
+void StdInListener::run()
+{
+ TRACE_OBJ
+ bool ok = true;
+ char chBuf[4096];
+ DWORD dwRead;
+
+#ifndef Q_OS_WINCE
+ HANDLE hStdin, hStdinDup;
+
+ hStdin = GetStdHandle(STD_INPUT_HANDLE);
+ if (hStdin == INVALID_HANDLE_VALUE)
+ return;
+
+ DuplicateHandle(GetCurrentProcess(), hStdin,
+ GetCurrentProcess(), &hStdinDup,
+ 0, false, DUPLICATE_SAME_ACCESS);
+
+ CloseHandle(hStdin);
+#else
+ HANDLE hStdinDup;
+ hStdinDup = stdin;
+#endif
+
+ while (ok) {
+ ok = ReadFile(hStdinDup, chBuf, sizeof(chBuf), &dwRead, NULL);
+ if (ok && dwRead != 0)
+ emit receivedCommand(QString::fromLocal8Bit(chBuf, dwRead));
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/assistant/assistant/remotecontrol_win.h b/src/assistant/assistant/stdinlistener_win.h
index 5a046a10b..a74047948 100644
--- a/src/assistant/assistant/remotecontrol_win.h
+++ b/src/assistant/assistant/stdinlistener_win.h
@@ -31,21 +31,21 @@
**
****************************************************************************/
-#ifndef REMOTECONTROL_WIN_H
-#define REMOTECONTROL_WIN_H
+#ifndef STDINLISTENER_WIN_H
+#define STDINLISTENER_WIN_H
#include <windows.h>
#include <QtCore/QThread>
QT_BEGIN_NAMESPACE
-class StdInListenerWin : public QThread
+class StdInListener : public QThread
{
Q_OBJECT
public:
- StdInListenerWin(QObject *parent);
- ~StdInListenerWin();
+ StdInListener(QObject *parent);
+ ~StdInListener();
signals:
void receivedCommand(const QString &cmd);