appevent.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef APPEVENT_H
  2. #define APPEVENT_H
  3. #include <QIODevice>
  4. #include <QObject>
  5. #include <QVariant>
  6. class AppEvent : public QObject
  7. {
  8. Q_OBJECT
  9. explicit AppEvent(QObject *parent = nullptr);
  10. ~AppEvent();
  11. public:
  12. static AppEvent *instance(); // 静态方法返回单例实例
  13. static qint64 time();
  14. static QString formatElapsedTime(qint64 ms);
  15. static void captureDesktop(QIODevice *device, const char *format = nullptr, int quality = -1);
  16. static void captureDesktop(const QString &path);
  17. static void saveTimeFile(qint64 elapsed, const QString &path);
  18. QString machineCode() const;
  19. // 语言设置
  20. QString locale() const;
  21. void setLocale(const QString &locale);
  22. //判断是否登录
  23. bool isLogin();
  24. void setJwtToken(const QString &token);
  25. QString jwtToken() const;
  26. bool isRefreshToken() const;
  27. void setRefreshTime(qint64 time) const;
  28. // 是否启用自动刷新令牌
  29. bool isEnableRefreshToken() const;
  30. void setEnableRefreshToken(bool enable);
  31. void setRoles(const QStringList &roles);
  32. QStringList roles() const;
  33. bool hasRole(const QString &role);
  34. // 配置
  35. bool setConfigValue(const QString &key, const QVariant &value);
  36. QVariant configValue(const QString &key);
  37. QVariant configReadValue(const QString &key, bool *isok = nullptr);
  38. bool configLoadJson(const QJsonObject &object);
  39. bool configLoad();
  40. bool configSave();
  41. QJsonObject config() const;
  42. void serverLink(bool);
  43. void unLockScreen();
  44. signals:
  45. void refreshTokenNeeded(); // 通知需要刷新 token
  46. void serverLinkSignals(int time);
  47. void unLockScreenSignals();
  48. void connectionStateChanged(bool); // websocket 在线标识
  49. // 登录过期的信号
  50. void loginExpired(bool expired);
  51. // 错误消息信号
  52. void errorMessage(const QString &message);
  53. private:
  54. class AppEventPrivate *d;
  55. };
  56. #endif // APPEVENT_H