mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Support Quit event
This commit is contained in:
		| @@ -13,7 +13,8 @@ enum class Event | |||||||
| 	ResumeIdle, | 	ResumeIdle, | ||||||
| 	ToggleIdle, | 	ToggleIdle, | ||||||
| 	Reload, | 	Reload, | ||||||
| 	Restart | 	Restart, | ||||||
|  | 	Quit | ||||||
| }; | }; | ||||||
|  |  | ||||||
| inline const char* eventToString(Event event) | inline const char* eventToString(Event event) | ||||||
| @@ -24,6 +25,7 @@ inline const char* eventToString(Event event) | |||||||
| 	case Event::Resume:        return "Resume"; | 	case Event::Resume:        return "Resume"; | ||||||
| 	case Event::ToggleSuspend: return "ToggleSuspend"; | 	case Event::ToggleSuspend: return "ToggleSuspend"; | ||||||
| 	case Event::Idle:          return "Idle"; | 	case Event::Idle:          return "Idle"; | ||||||
|  | 	case Event::Quit:          return "Quit"; | ||||||
| 	case Event::ResumeIdle:    return "ResumeIdle"; | 	case Event::ResumeIdle:    return "ResumeIdle"; | ||||||
| 	case Event::ToggleIdle:    return "ToggleIdle"; | 	case Event::ToggleIdle:    return "ToggleIdle"; | ||||||
| 	case Event::Reload:        return "Reload"; | 	case Event::Reload:        return "Reload"; | ||||||
| @@ -39,6 +41,7 @@ inline Event stringToEvent(const QString& event) | |||||||
| 	if (event.compare("Resume")==0)        return Event::Resume; | 	if (event.compare("Resume")==0)        return Event::Resume; | ||||||
| 	if (event.compare("ToggleSuspend")==0) return Event::ToggleSuspend; | 	if (event.compare("ToggleSuspend")==0) return Event::ToggleSuspend; | ||||||
| 	if (event.compare("Idle")==0)          return Event::Idle; | 	if (event.compare("Idle")==0)          return Event::Idle; | ||||||
|  | 	if (event.compare("Quit")==0)          return Event::Quit; | ||||||
| 	if (event.compare("ResumeIdle")==0)    return Event::ResumeIdle; | 	if (event.compare("ResumeIdle")==0)    return Event::ResumeIdle; | ||||||
| 	if (event.compare("ToggleIdle")==0)    return Event::ToggleIdle; | 	if (event.compare("ToggleIdle")==0)    return Event::ToggleIdle; | ||||||
| 	if (event.compare("Reload")==0)        return Event::Reload; | 	if (event.compare("Reload")==0)        return Event::Reload; | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ public: | |||||||
| public slots: | public slots: | ||||||
| 	void suspend(bool sleep); | 	void suspend(bool sleep); | ||||||
| 	void lock(bool isLocked); | 	void lock(bool isLocked); | ||||||
|  | 	void quit(); | ||||||
|  |  | ||||||
| 	virtual void handleSettingsUpdate(settings::type type, const QJsonDocument& config); | 	virtual void handleSettingsUpdate(settings::type type, const QJsonDocument& config); | ||||||
|  |  | ||||||
| @@ -101,6 +102,7 @@ public: | |||||||
|  |  | ||||||
| 	void handleSignal(int signum); | 	void handleSignal(int signum); | ||||||
|  |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	static OsEventHandlerLinux* getInstance(); | 	static OsEventHandlerLinux* getInstance(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -144,7 +144,7 @@ void EventHandler::handleEvent(Event event) | |||||||
| { | { | ||||||
| 	QObject *senderObj = QObject::sender(); | 	QObject *senderObj = QObject::sender(); | ||||||
| 	QString senderObjectClass; | 	QString senderObjectClass; | ||||||
| 	if (senderObj) | 	if (senderObj != nullptr) | ||||||
| 	{ | 	{ | ||||||
| 		senderObjectClass = senderObj->metaObject()->className(); | 		senderObjectClass = senderObj->metaObject()->className(); | ||||||
| 	} else | 	} else | ||||||
| @@ -188,6 +188,10 @@ void EventHandler::handleEvent(Event event) | |||||||
| 		Process::restartHyperion(11); | 		Process::restartHyperion(11); | ||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
|  | 	case Event::Quit: | ||||||
|  | 		emit signalEvent(Event::Quit); | ||||||
|  | 		break; | ||||||
|  |  | ||||||
| 	default: | 	default: | ||||||
| 		Error(_log,"Unkonwn Event '%d' received", event); | 		Error(_log,"Unkonwn Event '%d' received", event); | ||||||
| 		break; | 		break; | ||||||
|   | |||||||
| @@ -35,7 +35,7 @@ OsEventHandlerBase::OsEventHandlerBase() | |||||||
| 	_log = Logger::getInstance("EVENTS-OS"); | 	_log = Logger::getInstance("EVENTS-OS"); | ||||||
|  |  | ||||||
| 	QCoreApplication* app = QCoreApplication::instance(); | 	QCoreApplication* app = QCoreApplication::instance(); | ||||||
| 	if (!qobject_cast<QApplication*>(app)) | 	if (qobject_cast<QApplication*>(app) == nullptr) | ||||||
| 	{ | 	{ | ||||||
| 		_isService = true; | 		_isService = true; | ||||||
| 	} | 	} | ||||||
| @@ -46,6 +46,7 @@ OsEventHandlerBase::OsEventHandlerBase() | |||||||
|  |  | ||||||
| OsEventHandlerBase::~OsEventHandlerBase() | OsEventHandlerBase::~OsEventHandlerBase() | ||||||
| { | { | ||||||
|  | 	quit(); | ||||||
| 	QObject::disconnect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); | 	QObject::disconnect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent); | ||||||
|  |  | ||||||
| 	OsEventHandlerBase::unregisterLockHandler(); | 	OsEventHandlerBase::unregisterLockHandler(); | ||||||
| @@ -130,6 +131,11 @@ void OsEventHandlerBase::lock(bool isLocked) | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void OsEventHandlerBase::quit() | ||||||
|  | { | ||||||
|  | 	emit signalEvent(Event::Quit); | ||||||
|  | } | ||||||
|  |  | ||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
|  |  | ||||||
| OsEventHandlerWindows* OsEventHandlerWindows::getInstance() | OsEventHandlerWindows* OsEventHandlerWindows::getInstance() | ||||||
|   | |||||||
| @@ -84,10 +84,8 @@ void SysTray::createTrayIcon() | |||||||
|  |  | ||||||
| 	restartAction = new QAction(tr("&Restart"), this); | 	restartAction = new QAction(tr("&Restart"), this); | ||||||
| 	restartAction->setIcon(QPixmap(":/restart.svg")); | 	restartAction->setIcon(QPixmap(":/restart.svg")); | ||||||
| 	connect(restartAction, &QAction::triggered, this , [=](){ Process::restartHyperion(12); }); | 	connect(restartAction, &QAction::triggered, this , [=](){ emit signalEvent(Event::Restart); }); | ||||||
|  |  | ||||||
|  |  | ||||||
| 	// TODO: Check if can be done with SystemEvents |  | ||||||
| 	suspendAction = new QAction(tr("&Suspend"), this); | 	suspendAction = new QAction(tr("&Suspend"), this); | ||||||
| 	suspendAction->setIcon(QPixmap(":/suspend.svg")); | 	suspendAction->setIcon(QPixmap(":/suspend.svg")); | ||||||
| 	connect(suspendAction, &QAction::triggered, this, [this]() { emit signalEvent(Event::Suspend); }); | 	connect(suspendAction, &QAction::triggered, this, [this]() { emit signalEvent(Event::Suspend); }); | ||||||
| @@ -129,7 +127,9 @@ void SysTray::createTrayIcon() | |||||||
|  |  | ||||||
| 	// add seperator if custom effects exists | 	// add seperator if custom effects exists | ||||||
| 	if (!_trayIconEfxMenu->isEmpty()) | 	if (!_trayIconEfxMenu->isEmpty()) | ||||||
|  | 	{ | ||||||
| 		_trayIconEfxMenu->addSeparator(); | 		_trayIconEfxMenu->addSeparator(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// build in effects | 	// build in effects | ||||||
| 	for (const auto &efx : efxs) | 	for (const auto &efx : efxs) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user