refactor(@desktop/general): status custom events and os notification moved to the status namespace
- DockShowAppEvent - OSThemeEvent - OSNotification are now part of our `Status` namespace Corresponding files are renamed and moved to appropriate Status folder.
This commit is contained in:
parent
15b44e7b8f
commit
ca536cf714
|
@ -82,11 +82,11 @@ DOS_API void DOS_CALL dos_qguiapplication_delete(void);
|
|||
|
||||
DOS_API void DOS_CALL dos_qguiapplication_icon(const char *filename);
|
||||
|
||||
DOS_API void dos_qguiapplication_installEventFilter(DosStatusEventObject *vptr);
|
||||
DOS_API void dos_qguiapplication_installEventFilter(DosEvent *vptr);
|
||||
|
||||
DOS_API void dos_qapplication_clipboard_setText(const char* text);
|
||||
|
||||
DOS_API void dos_qapplication_installEventFilter(DosStatusEventObject *vptr);
|
||||
DOS_API void dos_qapplication_installEventFilter(DosEvent *vptr);
|
||||
|
||||
DOS_API void dos_qapplication_clipboard_setImage(const char *text);
|
||||
|
||||
|
@ -998,16 +998,25 @@ DOS_API void DOS_CALL dos_singleinstance_delete(DosSingleInstance *vptr);
|
|||
|
||||
/// @}
|
||||
|
||||
/// Status event object
|
||||
DOS_API DosStatusEventObject* dos_statusevent_create_showAppEvent(DosQQmlApplicationEngine* vptr);
|
||||
DOS_API DosStatusEventObject* dos_statusevent_create_osThemeEvent(DosQQmlApplicationEngine* vptr);
|
||||
DOS_API void dos_statusevent_delete(DosStatusEventObject* vptr);
|
||||
#pragma region Events exposed methods
|
||||
|
||||
/// Status notification object
|
||||
DOS_API DosStatusOSNotificationObject* dos_statusosnotification_create();
|
||||
DOS_API void dos_statusosnotification_show_notification(DosStatusOSNotificationObject* vptr,
|
||||
DOS_API DosEvent* dos_event_create_showAppEvent(DosQQmlApplicationEngine* vptr);
|
||||
DOS_API DosEvent* dos_event_create_osThemeEvent(DosQQmlApplicationEngine* vptr);
|
||||
DOS_API void dos_event_delete(DosEvent* vptr);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region OS notification exposed methods
|
||||
|
||||
DOS_API DosOSNotification* dos_osnotification_create();
|
||||
DOS_API void dos_osnotification_show_notification(DosOSNotification* vptr,
|
||||
const char* title, const char* message, const char* identifier);
|
||||
DOS_API void dos_statusosnotification_delete(DosStatusOSNotificationObject* vptr);
|
||||
DOS_API void dos_osnotification_delete(DosOSNotification* vptr);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma endregion
|
||||
|
||||
DOS_API char *dos_to_local_file(const char* fileUrl);
|
||||
|
||||
|
|
|
@ -98,11 +98,13 @@ typedef void DosPixmap;
|
|||
/// A pointer to SingleInstance
|
||||
typedef void DosSingleInstance;
|
||||
|
||||
/// A pointer to a status event object which is actualy a QObject
|
||||
typedef void DosStatusEventObject;
|
||||
/// A pointer to a event object which is actualy a QObject
|
||||
typedef void DosEvent;
|
||||
|
||||
/// A pointer to a os notification object which is actualy a QObject
|
||||
typedef DosQObject DosOSNotification;
|
||||
|
||||
|
||||
/// A pointer to a status os notification object which is actualy a QObject
|
||||
typedef DosQObject DosStatusOSNotificationObject;
|
||||
|
||||
/// A pixmap callback to be supplied to an image provider
|
||||
/// \param id Image source id
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef STATUS_DOCK_SHOW_APP_EVENT_H
|
||||
#define STATUS_DOCK_SHOW_APP_EVENT_H
|
||||
|
||||
#include "../DOtherSideTypes.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
namespace Status
|
||||
{
|
||||
class DockShowAppEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DockShowAppEvent(DosQQmlApplicationEngine* vptr, QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
Qt::ApplicationState m_prevAppState;
|
||||
QQmlApplicationEngine* m_engine;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef STATUS_OS_NOTIFICATION_H
|
||||
#define STATUS_OS_NOTIFICATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#elif defined Q_OS_MACOS
|
||||
class NotificationHelper;
|
||||
#endif
|
||||
|
||||
namespace Status
|
||||
{
|
||||
class OSNotification : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OSNotification(QObject *parent = nullptr);
|
||||
~OSNotification();
|
||||
|
||||
void showNotification(const QString& title, const QString& message,
|
||||
const QString& identifier);
|
||||
|
||||
signals:
|
||||
void notificationClicked(QString identifier);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
public:
|
||||
QHash<uint, QString> m_identifiers;
|
||||
|
||||
private:
|
||||
bool initNotificationWin();
|
||||
void stringToLimitedWCharArray(QString in, wchar_t* target, int maxLength);
|
||||
|
||||
private:
|
||||
HWND m_hwnd;
|
||||
|
||||
#elif defined Q_OS_MACOS
|
||||
private:
|
||||
void initNotificationMacOs();
|
||||
void showNotificationMacOs(QString title, QString message, QString identifier);
|
||||
|
||||
private:
|
||||
NotificationHelper *m_notificationHelper;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef STATUS_OS_THEME_EVENT_H
|
||||
#define STATUS_OS_THEME_EVENT_H
|
||||
|
||||
#include "../DOtherSideTypes.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
namespace Status
|
||||
{
|
||||
class OSThemeEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OSThemeEvent(DosQQmlApplicationEngine* vptr, QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
QQmlApplicationEngine* m_engine;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef STATUS_DOCK_SHOW_APP_EVENT_H
|
||||
#define STATUS_DOCK_SHOW_APP_EVENT_H
|
||||
|
||||
#include "../DOtherSideTypes.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
class StatusDockShowAppEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StatusDockShowAppEvent(DosQQmlApplicationEngine* vptr, QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
Qt::ApplicationState m_prevAppState;
|
||||
QQmlApplicationEngine* m_engine;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef STATUS_OS_THEME_EVENT_H
|
||||
#define STATUS_OS_THEME_EVENT_H
|
||||
|
||||
#include "../DOtherSideTypes.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
class StatusOSThemeEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StatusOSThemeEvent(DosQQmlApplicationEngine* vptr, QObject* parent = nullptr);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||
|
||||
private:
|
||||
QQmlApplicationEngine* m_engine;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef STATUS_OS_NOTIFICATION_H
|
||||
#define STATUS_OS_NOTIFICATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "windows.h"
|
||||
#elif defined Q_OS_MACOS
|
||||
class NotificationHelper;
|
||||
#endif
|
||||
|
||||
class StatusOSNotification : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StatusOSNotification(QObject *parent = nullptr);
|
||||
~StatusOSNotification();
|
||||
|
||||
void showNotification(const QString& title, const QString& message,
|
||||
const QString& identifier);
|
||||
|
||||
signals:
|
||||
void notificationClicked(QString identifier);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
public:
|
||||
QHash<uint, QString> m_identifiers;
|
||||
|
||||
private:
|
||||
bool initNotificationWin();
|
||||
void stringToLimitedWCharArray(QString in, wchar_t* target, int maxLength);
|
||||
|
||||
private:
|
||||
HWND m_hwnd;
|
||||
|
||||
#elif defined Q_OS_MACOS
|
||||
private:
|
||||
void initNotificationMacOs();
|
||||
void showNotificationMacOs(QString title, QString message, QString identifier);
|
||||
|
||||
private:
|
||||
NotificationHelper *m_notificationHelper;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
|
@ -62,9 +62,9 @@
|
|||
#include "DOtherSide/DOtherSideSingleInstance.h"
|
||||
#include "DOtherSide/DOtherSideStatusSyntaxHighlighter.h"
|
||||
|
||||
#include "DOtherSide/StatusEvents/StatusDockShowAppEvent.h"
|
||||
#include "DOtherSide/StatusEvents/StatusOSThemeEvent.h"
|
||||
#include "DOtherSide/StatusNotification/StatusOSNotification.h"
|
||||
#include "DOtherSide/Status/DockShowAppEvent.h"
|
||||
#include "DOtherSide/Status/OSThemeEvent.h"
|
||||
#include "DOtherSide/Status/OSNotification.h"
|
||||
#include "DOtherSide/DosSpellchecker.h"
|
||||
|
||||
namespace {
|
||||
|
@ -203,7 +203,7 @@ void dos_qguiapplication_icon(const char *filename)
|
|||
qGuiApp->setWindowIcon(QIcon(filename));
|
||||
}
|
||||
|
||||
void dos_qguiapplication_installEventFilter(::DosStatusEventObject* vptr)
|
||||
void dos_qguiapplication_installEventFilter(::DosEvent* vptr)
|
||||
{
|
||||
auto qobject = static_cast<QObject*>(vptr);
|
||||
qGuiApp->installEventFilter(qobject);
|
||||
|
@ -240,7 +240,7 @@ void dos_qapplication_quit()
|
|||
QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void dos_qapplication_installEventFilter(::DosStatusEventObject* vptr)
|
||||
void dos_qapplication_installEventFilter(::DosEvent* vptr)
|
||||
{
|
||||
auto qobject = static_cast<QObject*>(vptr);
|
||||
qApp->installEventFilter(qobject);
|
||||
|
@ -1355,44 +1355,50 @@ bool dos_singleinstance_isfirst(DosSingleInstance *vptr)
|
|||
return false;
|
||||
}
|
||||
|
||||
::DosStatusEventObject* dos_statusevent_create_showAppEvent(::DosQQmlApplicationEngine* vptr)
|
||||
#pragma region Events
|
||||
::DosEvent* dos_event_create_showAppEvent(::DosQQmlApplicationEngine* vptr)
|
||||
{
|
||||
auto engine = static_cast<QQmlApplicationEngine*>(vptr);
|
||||
return new StatusDockShowAppEvent(engine);
|
||||
return new Status::DockShowAppEvent(engine);
|
||||
}
|
||||
|
||||
::DosStatusEventObject* dos_statusevent_create_osThemeEvent(::DosQQmlApplicationEngine* vptr)
|
||||
::DosEvent* dos_event_create_osThemeEvent(::DosQQmlApplicationEngine* vptr)
|
||||
{
|
||||
auto engine = static_cast<QQmlApplicationEngine*>(vptr);
|
||||
return new StatusOSThemeEvent(engine);
|
||||
return new Status::OSThemeEvent(engine);
|
||||
}
|
||||
|
||||
void dos_statusevent_delete(DosStatusEventObject* vptr)
|
||||
void dos_event_delete(DosEvent* vptr)
|
||||
{
|
||||
auto qobject = static_cast<QObject*>(vptr);
|
||||
qobject->deleteLater();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
::DosStatusOSNotificationObject* dos_statusosnotification_create()
|
||||
#pragma region OSNotification
|
||||
|
||||
::DosOSNotification* dos_osnotification_create()
|
||||
{
|
||||
return new StatusOSNotification();
|
||||
return new Status::OSNotification();
|
||||
}
|
||||
|
||||
void dos_statusosnotification_show_notification(DosStatusOSNotificationObject* vptr,
|
||||
void dos_osnotification_show_notification(DosOSNotification* vptr,
|
||||
const char* title, const char* message, const char* identifier)
|
||||
{
|
||||
auto notificationObj = static_cast<StatusOSNotification*>(vptr);
|
||||
auto notificationObj = static_cast<Status::OSNotification*>(vptr);
|
||||
if(notificationObj)
|
||||
notificationObj->showNotification(title, message, identifier);
|
||||
}
|
||||
|
||||
void dos_statusosnotification_delete(DosStatusOSNotificationObject* vptr)
|
||||
void dos_osnotification_delete(DosOSNotification* vptr)
|
||||
{
|
||||
auto qobject = static_cast<QObject*>(vptr);
|
||||
if(qobject)
|
||||
qobject->deleteLater();
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
char* dos_to_local_file(const char* fileUrl)
|
||||
{
|
||||
return convert_to_cstring(QUrl(QString::fromUtf8(fileUrl)).toLocalFile());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "DOtherSide/StatusEvents/StatusDockShowAppEvent.h"
|
||||
#include "DOtherSide/Status/DockShowAppEvent.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
|
@ -9,14 +9,16 @@
|
|||
installing filters.
|
||||
*/
|
||||
|
||||
StatusDockShowAppEvent::StatusDockShowAppEvent(DosQQmlApplicationEngine* vptr,
|
||||
using namespace Status;
|
||||
|
||||
DockShowAppEvent::DockShowAppEvent(DosQQmlApplicationEngine* vptr,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_engine = static_cast<QQmlApplicationEngine*>(vptr);
|
||||
}
|
||||
|
||||
bool StatusDockShowAppEvent::eventFilter(QObject* obj, QEvent* event)
|
||||
bool DockShowAppEvent::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
if (event->type() == QEvent::ApplicationStateChange)
|
|
@ -1,4 +1,4 @@
|
|||
#include "DOtherSide/StatusNotification/StatusOSNotification.h"
|
||||
#include "DOtherSide/StatusNotification/OSNotification.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <shellapi.h>
|
||||
|
@ -7,12 +7,16 @@
|
|||
#include <winuser.h>
|
||||
#include <comdef.h>
|
||||
|
||||
using namespace Status;
|
||||
|
||||
static const UINT NOTIFYICONID = 0;
|
||||
|
||||
static std::pair<HWND, StatusOSNotification *> HWND_INSTANCE_PAIR;
|
||||
static std::pair<HWND, OSNotification *> HWND_INSTANCE_PAIR;
|
||||
#endif
|
||||
|
||||
StatusOSNotification::StatusOSNotification(QObject *parent)
|
||||
using namespace Status;
|
||||
|
||||
OSNotification::OSNotification(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -24,7 +28,7 @@ StatusOSNotification::StatusOSNotification(QObject *parent)
|
|||
#endif
|
||||
}
|
||||
|
||||
StatusOSNotification::~StatusOSNotification()
|
||||
OSNotification::~OSNotification()
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
if(m_notificationHelper)
|
||||
|
@ -52,7 +56,7 @@ LRESULT CALLBACK StatusWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
void StatusOSNotification::stringToLimitedWCharArray(QString in, wchar_t* target,
|
||||
void OSNotification::stringToLimitedWCharArray(QString in, wchar_t* target,
|
||||
int maxLength)
|
||||
{
|
||||
const int length = qMin(maxLength - 1, in.size());
|
||||
|
@ -62,7 +66,7 @@ void StatusOSNotification::stringToLimitedWCharArray(QString in, wchar_t* target
|
|||
target[length] = wchar_t(0);
|
||||
}
|
||||
|
||||
bool StatusOSNotification::initNotificationWin()
|
||||
bool OSNotification::initNotificationWin()
|
||||
{
|
||||
// m_hwnd should be init only once, but that would be a case if we create system
|
||||
// tray window from here. But since we already have system tray added in the
|
||||
|
@ -98,7 +102,7 @@ bool StatusOSNotification::initNotificationWin()
|
|||
|
||||
ATOM atom = RegisterClassEx(&wc);
|
||||
if (!atom)
|
||||
printf("StatusOsNotification registering window class failed.\n");
|
||||
printf("Status::OsNotification registering window class failed.\n");
|
||||
|
||||
m_hwnd = FindWindowExA(0, 0, className, windowName);
|
||||
if(m_hwnd)
|
||||
|
@ -111,7 +115,7 @@ bool StatusOSNotification::initNotificationWin()
|
|||
}
|
||||
#endif
|
||||
|
||||
void StatusOSNotification::showNotification(const QString& title,
|
||||
void OSNotification::showNotification(const QString& title,
|
||||
const QString& message, const QString& identifier)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
|
@ -1,18 +1,20 @@
|
|||
#include "DOtherSide/StatusNotification/StatusOSNotification.h"
|
||||
#include "DOtherSide/StatusNotification/OSNotification.h"
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
using namespace Status;
|
||||
|
||||
@interface NotificationDelegate : NSObject <NSUserNotificationCenterDelegate>
|
||||
- (instancetype)initStatusOSNotification:(StatusOSNotification*) instance;
|
||||
- (instancetype)initOSNotification:(OSNotification*) instance;
|
||||
@end
|
||||
|
||||
class NotificationHelper
|
||||
{
|
||||
public:
|
||||
NotificationHelper(StatusOSNotification* instance) {
|
||||
delegate = [[NotificationDelegate alloc] initStatusOSNotification:instance];
|
||||
NotificationHelper(OSNotification* instance) {
|
||||
delegate = [[NotificationDelegate alloc] initOSNotification:instance];
|
||||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate;
|
||||
}
|
||||
|
||||
|
@ -26,7 +28,7 @@ public:
|
|||
NotificationDelegate* delegate;
|
||||
};
|
||||
|
||||
void StatusOSNotification::initNotificationMacOs()
|
||||
void OSNotification::initNotificationMacOs()
|
||||
{
|
||||
if (!m_notificationHelper)
|
||||
{
|
||||
|
@ -34,7 +36,7 @@ void StatusOSNotification::initNotificationMacOs()
|
|||
}
|
||||
}
|
||||
|
||||
void StatusOSNotification::showNotificationMacOs(QString title, QString message,
|
||||
void OSNotification::showNotificationMacOs(QString title, QString message,
|
||||
QString identifier)
|
||||
{
|
||||
if (!m_notificationHelper)
|
||||
|
@ -54,10 +56,10 @@ void StatusOSNotification::showNotificationMacOs(QString title, QString message,
|
|||
}
|
||||
|
||||
@implementation NotificationDelegate {
|
||||
StatusOSNotification* instance;
|
||||
OSNotification* instance;
|
||||
}
|
||||
|
||||
- (instancetype)initStatusOSNotification:(StatusOSNotification*)ins
|
||||
- (instancetype)initOSNotification:(OSNotification*)ins
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
|
@ -1,14 +1,16 @@
|
|||
#include "DOtherSide/StatusEvents/StatusOSThemeEvent.h"
|
||||
#include "DOtherSide/Status/OSThemeEvent.h"
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
StatusOSThemeEvent::StatusOSThemeEvent(DosQQmlApplicationEngine* vptr, QObject* parent)
|
||||
using namespace Status;
|
||||
|
||||
OSThemeEvent::OSThemeEvent(DosQQmlApplicationEngine* vptr, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_engine = static_cast<QQmlApplicationEngine*>(vptr);
|
||||
}
|
||||
|
||||
bool StatusOSThemeEvent::eventFilter(QObject *obj, QEvent *event)
|
||||
bool OSThemeEvent::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::PaletteChange ||
|
||||
event->type() == QEvent::ApplicationPaletteChange)
|
Loading…
Reference in New Issue