Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote control command to change window size #3433

Merged
merged 3 commits into from Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugins/RemoteControl/doc/remoteControlApi.doxygen
Expand Up @@ -239,6 +239,13 @@ The last parameter style provides the view in altitude/azimuth spherical coordin
Parameters: <tt>fov (Number)</tt>\n
Sets the current field-of-view using StelCore::setFov

\paragraph rcMainServiceWindow window
Parameters: <tt>w (int) h (int)</tt>\n
Sets the window size using StelMainView::setWindowSize()
This can be useful e.g. when Stellarium provides image background inserts via spout.



\subsection rcObjectService ObjectService operations (/api/objects/)
\subsubsection rcObjectServiceGET GET operations
Implemented by ObjectService::getImpl
Expand Down
8 changes: 4 additions & 4 deletions plugins/RemoteControl/src/APIController.hpp
Expand Up @@ -21,7 +21,7 @@
#define APIHANDLER_HPP

#include "httpserver/httprequesthandler.h"
#include "AbstractAPIService.hpp"
#include "RemoteControlServiceInterface.hpp"

//! @ingroup remoteControl
//! This class handles the API-specific requests and dispatches them to the correct RemoteControlServiceInterface implementation.
Expand All @@ -34,8 +34,8 @@ class APIController : public HttpRequestHandler
//! Constructs an APIController
//! @param prefixLength Determines how many characters to strip from the front of the request path
//! @param parent passed on to QObject constructor
APIController(int prefixLength, QObject* parent = Q_NULLPTR);
virtual ~APIController() Q_DECL_OVERRIDE;
APIController(int prefixLength, QObject* parent = nullptr);
~APIController() override;

//! Should be called each frame from the main thread, like from StelModule::update.
//! Passed on to each AbstractAPIService::update method for optional processing.
Expand All @@ -47,7 +47,7 @@ class APIController : public HttpRequestHandler
//! method depending on the HTTP request type.
//! If RemoteControlServiceInterface::isThreadSafe is false, these methods are called in the Stellarium main thread
//! using QMetaObject::invokeMethod, otherwise they are directly executed in the current thread (HTTP worker thread).
virtual void service(HttpRequest& request, HttpResponse& response) Q_DECL_OVERRIDE;
void service(HttpRequest& request, HttpResponse& response) override;

//! Registers a service with the APIController.
//! The RemoteControlServiceInterface::getPath() determines the request path of the service.
Expand Down
10 changes: 5 additions & 5 deletions plugins/RemoteControl/src/AbstractAPIService.hpp
Expand Up @@ -33,19 +33,19 @@ class AbstractAPIService : public QObject, public RemoteControlServiceInterface
Q_INTERFACES(RemoteControlServiceInterface)
public:
//! Only calls QObject constructor
AbstractAPIService(QObject* parent = Q_NULLPTR) : QObject(parent)
AbstractAPIService(QObject* parent = nullptr) : QObject(parent)
{
}

// Provides a default implementation which returns false.
virtual bool isThreadSafe() const Q_DECL_OVERRIDE;
bool isThreadSafe() const override;
//! Called in the main thread each frame. Default implementation does nothing.
//! Can be used for ongoing actions, for example movement control.
virtual void update(double deltaTime) Q_DECL_OVERRIDE;
void update(double deltaTime) override;
//! Provides a default implementation which returns an error message.
virtual void get(const QByteArray &operation, const APIParameters &parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray &operation, const APIParameters &parameters, APIServiceResponse& response) override;
//! Provides a default implementation which returns an error message.
virtual void post(const QByteArray &operation, const APIParameters &parameters, const QByteArray& data, APIServiceResponse& response) Q_DECL_OVERRIDE;
void post(const QByteArray &operation, const APIParameters &parameters, const QByteArray& data, APIServiceResponse& response) override;

protected:
//! This defines the connection type QMetaObject::invokeMethod has to use inside a service: either Qt::DirectConnection for main thread handling, or
Expand Down
8 changes: 4 additions & 4 deletions plugins/RemoteControl/src/LocationSearchService.hpp
Expand Up @@ -33,15 +33,15 @@ class LocationSearchService : public AbstractAPIService
{
Q_OBJECT
public:
LocationSearchService(QObject* parent = Q_NULLPTR);
LocationSearchService(QObject* parent = nullptr);

//! We work on a copy of the StelLocationMgr, to prevent hitches as the web user is typing
//! @returns true
virtual bool isThreadSafe() const Q_DECL_OVERRIDE { return true; }
virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("locationsearch"); }
bool isThreadSafe() const override { return true; }
QLatin1String getPath() const override { return QLatin1String("locationsearch"); }
//! @brief Implements the GET method.
//! @see \ref rcLocationSearchServiceGET
virtual void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) override;
private slots:
// connected to the main location manager in the main thread
void mainLocationManagerUpdated();
Expand Down
8 changes: 4 additions & 4 deletions plugins/RemoteControl/src/LocationService.hpp
Expand Up @@ -34,15 +34,15 @@ class LocationService : public AbstractAPIService
{
Q_OBJECT
public:
LocationService(QObject* parent = Q_NULLPTR);
LocationService(QObject* parent = nullptr);

virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("location"); }
QLatin1String getPath() const override { return QLatin1String("location"); }
//! @brief Implements the HTTP GET requests
//! @see \ref rcLocationServiceGET
virtual void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) override;
//! @brief Implements the HTTP POST requests
//! @see \ref rcLocationServicePOST
virtual void post(const QByteArray &operation, const APIParameters& parameters, const QByteArray &data, APIServiceResponse &response) Q_DECL_OVERRIDE;
void post(const QByteArray &operation, const APIParameters& parameters, const QByteArray &data, APIServiceResponse &response) override;
private:
StelCore* core;
StelLocationMgr* locMgr;
Expand Down
25 changes: 24 additions & 1 deletion plugins/RemoteControl/src/MainService.cpp
Expand Up @@ -511,10 +511,28 @@ void MainService::post(const QByteArray& operation, const APIParameters &paramet

response.setData("ok");
}
else if(operation == "window")
{
bool wOk,hOk;

double w = parameters.value("w").toDouble(&wOk);
double h = parameters.value("h").toDouble(&hOk);

if(wOk && hOk)
{
QMetaObject::invokeMethod(this,"setWindowSize", SERVICE_DEFAULT_INVOKETYPE,
Q_ARG(int,w),
Q_ARG(int,h));

response.setData("ok");
}
else
response.writeRequestError("requires w and h parameters");
}
else
{
//TODO some sort of service description?
response.writeRequestError("unsupported operation. POST: time,focus,move,view,fov");
response.writeRequestError("unsupported operation. POST: time,focus,move,view,fov,window");
}
}

Expand Down Expand Up @@ -621,6 +639,11 @@ void MainService::setFov(double fov)
mvmgr->zoomTo(fov,0.25f);
}

void MainService::setWindowSize(const int width, const int height)
{
StelMainView::getInstance().setWindowSize(width, height);
}

void MainService::actionToggled(const QString &id, bool val)
{
actionMutex.lock();
Expand Down
11 changes: 6 additions & 5 deletions plugins/RemoteControl/src/MainService.hpp
Expand Up @@ -58,17 +58,17 @@ class MainService : public AbstractAPIService
};
Q_ENUM(SelectionMode)

MainService(QObject* parent = Q_NULLPTR);
MainService(QObject* parent = nullptr);

//! Used to implement move functionality
virtual void update(double deltaTime) Q_DECL_OVERRIDE;
virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("main"); }
void update(double deltaTime) override;
QLatin1String getPath() const override { return QLatin1String("main"); }
//! @brief Implements the GET operations
//! @see @ref rcMainServiceGET
virtual void get(const QByteArray& operation,const APIParameters &parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters &parameters, APIServiceResponse& response) override;
//! @brief Implements the HTTP POST operations
//! @see @ref rcMainServicePOST
virtual void post(const QByteArray &operation, const APIParameters &parameters, const QByteArray &data, APIServiceResponse &response) Q_DECL_OVERRIDE;
void post(const QByteArray &operation, const APIParameters &parameters, const QByteArray &data, APIServiceResponse &response) override;

private slots:
StelObjectP getSelectedObject();
Expand All @@ -84,6 +84,7 @@ private slots:
// Allow azimut/altitude changes. Values must be in Radians.
void updateView(double az, double alt, bool azUpdated, bool altUpdated);
void setFov(double fov);
void setWindowSize(const int width, const int height);

void actionToggled(const QString& id, bool val);
void propertyChanged(StelProperty* prop, const QVariant &val);
Expand Down
6 changes: 3 additions & 3 deletions plugins/RemoteControl/src/ObjectService.hpp
Expand Up @@ -36,12 +36,12 @@ class ObjectService : public AbstractAPIService
{
Q_OBJECT
public:
ObjectService(QObject* parent = Q_NULLPTR);
ObjectService(QObject* parent = nullptr);

virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("objects"); }
QLatin1String getPath() const override { return QLatin1String("objects"); }
//! @brief Implements the HTTP GET method
//! @see \ref rcObjectServiceGET
virtual void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) override;

private slots:
//! Executed in Stellarium main thread to avoid multiple QMetaObject::invoke calls
Expand Down
16 changes: 8 additions & 8 deletions plugins/RemoteControl/src/RemoteControl.cpp
Expand Up @@ -62,8 +62,8 @@ StelPluginInfo RemoteControlStelPluginInterface::getPluginInfo() const
}

RemoteControl::RemoteControl()
: httpListener(Q_NULLPTR)
, requestHandler(Q_NULLPTR)
: httpListener(nullptr)
, requestHandler(nullptr)
, enabled(false)
, autoStart(false)
, usePassword(false)
Expand All @@ -73,7 +73,7 @@ RemoteControl::RemoteControl()
, port(8090)
, minThreads(1)
, maxThreads(30)
, toolbarButton(Q_NULLPTR)
, toolbarButton(nullptr)
{
setObjectName("RemoteControl");

Expand All @@ -92,7 +92,7 @@ RemoteControl::~RemoteControl()
//we manually delete the listener here to make sure
//all connections are closed before the requesthandler is deleted
delete httpListener;
httpListener = Q_NULLPTR;
httpListener = nullptr;
}
}

Expand Down Expand Up @@ -154,9 +154,9 @@ void RemoteControl::init()
try
{
StelGui* gui = dynamic_cast<StelGui*>(app.getGui());
if (gui!=Q_NULLPTR)
if (gui!=nullptr)
{
toolbarButton = new StelButton(Q_NULLPTR,
toolbarButton = new StelButton(nullptr,
QPixmap(":/RemoteControl/resources/bt_remote_on.png"),
QPixmap(":/RemoteControl/resources/bt_remote_off.png"),
QPixmap(":/graphicGui/miscGlow32x32.png"),
Expand Down Expand Up @@ -260,7 +260,7 @@ void RemoteControl::setPort(const int port)

void RemoteControl::startServer()
{
Q_ASSERT(httpListener == Q_NULLPTR);
Q_ASSERT(httpListener == nullptr);

//set request handler password settings
requestHandler->setPassword(password);
Expand All @@ -279,7 +279,7 @@ void RemoteControl::stopServer()
if(httpListener)
{
delete httpListener;
httpListener = Q_NULLPTR;
httpListener = nullptr;
}
}

Expand Down
20 changes: 10 additions & 10 deletions plugins/RemoteControl/src/RemoteControl.hpp
Expand Up @@ -63,19 +63,19 @@ class RemoteControl : public StelModule
NOTIFY flagEnableCorsChanged)
public:
RemoteControl();
virtual ~RemoteControl() Q_DECL_OVERRIDE;
~RemoteControl() override;

///////////////////////////////////////////////////////////////////////////
// Methods defined in the StelModule class
virtual void init() Q_DECL_OVERRIDE;
virtual void update(double deltaTime) Q_DECL_OVERRIDE;
virtual void draw(StelCore* core) Q_DECL_OVERRIDE;
virtual double getCallOrder(StelModuleActionName actionName) const Q_DECL_OVERRIDE;
virtual void handleKeys(QKeyEvent* event) Q_DECL_OVERRIDE {event->setAccepted(false);}
void init() override;
void update(double deltaTime) override;
void draw(StelCore* core) override;
double getCallOrder(StelModuleActionName actionName) const override;
void handleKeys(QKeyEvent* event) override {event->setAccepted(false);}

//virtual void handleMouseClicks(class QMouseEvent* event);
//virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
virtual bool configureGui(bool show=true) Q_DECL_OVERRIDE;
bool configureGui(bool show=true) override;
///////////////////////////////////////////////////////////////////////////
// Property getters
bool getFlagEnabled() const {return enabled;}
Expand Down Expand Up @@ -186,9 +186,9 @@ class RemoteControlStelPluginInterface : public QObject, public StelPluginInterf
Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
Q_INTERFACES(StelPluginInterface)
public:
virtual StelModule* getStelModule() const Q_DECL_OVERRIDE;
virtual StelPluginInfo getPluginInfo() const Q_DECL_OVERRIDE;
//virtual QObjectList getExtensionList() const Q_DECL_OVERRIDE { return QObjectList(); }
StelModule* getStelModule() const override;
StelPluginInfo getPluginInfo() const override;
//QObjectList getExtensionList() const override { return QObjectList(); }
};

#endif /*REMOTECONTROL_HPP*/
Expand Down
4 changes: 2 additions & 2 deletions plugins/RemoteControl/src/RequestHandler.cpp
Expand Up @@ -49,7 +49,7 @@ class HtmlTranslationProvider : public ITemplateTranslationProvider
{
rcTranslator = localInstance;
}
QString getTranslation(const QString &key) Q_DECL_OVERRIDE
QString getTranslation(const QString &key) override
{
//try to get a RemoteControl specific translation first
QString trans = rcTranslator->tryQtranslate(key);
Expand All @@ -70,7 +70,7 @@ class JsTranslationProvider : public ITemplateTranslationProvider
rcTranslator = localInstance;
}

QString getTranslation(const QString &key) Q_DECL_OVERRIDE
QString getTranslation(const QString &key) override
{
//try to get a RemoteControl specific translation first
QString trans = rcTranslator->tryQtranslate(key);
Expand Down
6 changes: 3 additions & 3 deletions plugins/RemoteControl/src/RequestHandler.hpp
Expand Up @@ -37,9 +37,9 @@ class RequestHandler : public HttpRequestHandler
//! and an APIController.
//!
//! To see the default services that are registered here, see \ref rcApiReference.
RequestHandler(const StaticFileControllerSettings& settings, QObject* parent = Q_NULLPTR);
RequestHandler(const StaticFileControllerSettings& settings, QObject* parent = nullptr);
//! The internal APIController, and all registered services are deleted
virtual ~RequestHandler() Q_DECL_OVERRIDE;
~RequestHandler() override;

//! Called in the main thread each frame, only passed on to APIController::update
void update(double deltaTime);
Expand All @@ -56,7 +56,7 @@ class RequestHandler : public HttpRequestHandler
//! - Otherwise, it is passed to a StaticFileController that has been set up for the \c data/webroot folder.
//!
//! @note This method runs in an HTTP worker thread, not in the Stellarium main thread, so take caution.
virtual void service(HttpRequest& request, HttpResponse& response) Q_DECL_OVERRIDE;
void service(HttpRequest& request, HttpResponse& response) override;

public slots:
//! Sets whether a password set with setPassword() is required by all requests.
Expand Down
8 changes: 4 additions & 4 deletions plugins/RemoteControl/src/ScriptService.hpp
Expand Up @@ -34,15 +34,15 @@ class ScriptService : public AbstractAPIService
{
Q_OBJECT
public:
ScriptService(QObject* parent = Q_NULLPTR);
ScriptService(QObject* parent = nullptr);

virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("scripts"); }
QLatin1String getPath() const override { return QLatin1String("scripts"); }
//! @brief Implements the HTTP GET method
//! @see \ref rcScriptServiceGET
virtual void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) override;
//! @brief Implements the HTTP POST method
//! @see \ref rcScriptServicePOST
virtual void post(const QByteArray &operation, const APIParameters& parameters, const QByteArray &data, APIServiceResponse &response) Q_DECL_OVERRIDE;
void post(const QByteArray &operation, const APIParameters& parameters, const QByteArray &data, APIServiceResponse &response) override;
private:
StelScriptMgr* scriptMgr;
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/RemoteControl/src/SimbadService.cpp
Expand Up @@ -46,7 +46,7 @@ class SimbadLookupTask :public QRunnable
setAutoDelete(false);
}

void run() Q_DECL_OVERRIDE
void run() override
{
//make sure this is really a separate thread (QtConcurrent does NOT guarantee that)
Q_ASSERT(parentThread!=QThread::currentThread());
Expand Down
8 changes: 4 additions & 4 deletions plugins/RemoteControl/src/SimbadService.hpp
Expand Up @@ -34,14 +34,14 @@ class SimbadService : public AbstractAPIService
{
Q_OBJECT
public:
SimbadService(QObject* parent = Q_NULLPTR);
SimbadService(QObject* parent = nullptr);

//! Simbad lookups dont block the main thread
virtual bool isThreadSafe() const Q_DECL_OVERRIDE { return true; }
virtual QLatin1String getPath() const Q_DECL_OVERRIDE { return QLatin1String("simbad"); }
bool isThreadSafe() const override { return true; }
QLatin1String getPath() const override { return QLatin1String("simbad"); }
//! @brief Implements the HTTP GET method
//! @see \ref rcSimbadServiceGET
virtual void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) Q_DECL_OVERRIDE;
void get(const QByteArray& operation,const APIParameters& parameters, APIServiceResponse& response) override;
private:
QString simbadServerUrl;
};
Expand Down