FluentUI/example/src/AppInfo.cpp

57 lines
1.3 KiB
C++
Raw Normal View History

2023-05-22 16:17:51 +08:00
#include "AppInfo.h"
2023-05-25 17:00:48 +08:00
#include <QQmlContext>
#include <QDebug>
2023-04-14 17:07:54 +08:00
#include "lang/En.h"
#include "lang/Zh.h"
2023-04-27 15:43:45 +08:00
#define STR(x) #x
#define VER_JOIN(a,b,c,d) STR(a.b.c.d)
#define VER_JOIN_(x) VER_JOIN x
#define VER_STR VER_JOIN_((VERSION))
2023-04-14 17:07:54 +08:00
2023-04-11 18:05:07 +08:00
AppInfo::AppInfo(QObject *parent)
: QObject{parent}
{
2023-04-27 15:43:45 +08:00
version(VER_STR);
2023-04-16 02:28:58 +08:00
lang(new En());
2023-04-14 17:07:54 +08:00
}
2023-05-25 17:00:48 +08:00
void AppInfo::init(QQmlApplicationEngine *engine){
QQmlContext * context = engine->rootContext();
Lang* lang = this->lang();
context->setContextProperty("lang",lang);
QObject::connect(this,&AppInfo::langChanged,this,[=]{
context->setContextProperty("lang",this->lang());
});
context->setContextProperty("appInfo",this);
}
2023-04-14 17:07:54 +08:00
void AppInfo::changeLang(const QString& locale){
if(_lang){
_lang->deleteLater();
}
if(locale=="Zh"){
lang(new Zh());
}else if(locale=="En"){
lang(new En());
}else {
lang(new En());
}
2023-04-11 18:05:07 +08:00
}
2023-05-25 17:00:48 +08:00
bool AppInfo::isOwnerProcess(IPC *ipc){
QString activeWindowEvent = "activeWindow";
if(!ipc->isCurrentOwner()){
ipc->postEvent(activeWindowEvent,QString().toUtf8(),0);
return false;
}
if(ipc->isAttached()){
ipc->registerEventHandler(activeWindowEvent,[=](const QByteArray&){
Q_EMIT this->activeWindow();
return true;
});
}
return true;
}