obs-app.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QApplication>
  16. #include <QTranslator>
  17. #include <QPointer>
  18. #include <util/lexer.h>
  19. #include <util/util.hpp>
  20. #include <string>
  21. #include <memory>
  22. #include <vector>
  23. #include "window-main.hpp"
  24. std::string CurrentTimeString();
  25. std::string CurrentDateTimeString();
  26. std::string GenerateTimeDateFilename(const char *extension);
  27. QObject *CreateShortcutFilter();
  28. struct BaseLexer {
  29. lexer lex;
  30. public:
  31. inline BaseLexer() {lexer_init(&lex);}
  32. inline ~BaseLexer() {lexer_free(&lex);}
  33. operator lexer*() {return &lex;}
  34. };
  35. class OBSTranslator : public QTranslator {
  36. Q_OBJECT
  37. public:
  38. virtual bool isEmpty() const override {return false;}
  39. virtual QString translate(const char *context, const char *sourceText,
  40. const char *disambiguation, int n) const override;
  41. };
  42. class OBSApp : public QApplication {
  43. Q_OBJECT
  44. private:
  45. std::string locale;
  46. std::string theme;
  47. ConfigFile globalConfig;
  48. TextLookup textLookup;
  49. QPointer<OBSMainWindow> mainWindow;
  50. bool InitGlobalConfig();
  51. bool InitGlobalConfigDefaults();
  52. bool InitLocale();
  53. bool InitTheme();
  54. public:
  55. OBSApp(int &argc, char **argv);
  56. void AppInit();
  57. bool OBSInit();
  58. inline QMainWindow *GetMainWindow() const {return mainWindow.data();}
  59. inline config_t *GlobalConfig() const {return globalConfig;}
  60. inline const char *GetLocale() const
  61. {
  62. return locale.c_str();
  63. }
  64. inline const char *GetTheme() const {return theme.c_str();}
  65. bool SetTheme(std::string name, std::string path = "");
  66. inline lookup_t *GetTextLookup() const {return textLookup;}
  67. inline const char *GetString(const char *lookupVal) const
  68. {
  69. return textLookup.GetString(lookupVal);
  70. }
  71. const char *GetLastLog() const;
  72. const char *GetCurrentLog() const;
  73. std::string GetVersionString() const;
  74. const char *InputAudioSource() const;
  75. const char *OutputAudioSource() const;
  76. const char *GetRenderModule() const;
  77. };
  78. inline OBSApp *App() {return static_cast<OBSApp*>(qApp);}
  79. inline config_t *GetGlobalConfig() {return App()->GlobalConfig();}
  80. std::vector<std::pair<std::string, std::string>> GetLocaleNames();
  81. inline const char *Str(const char *lookup) {return App()->GetString(lookup);}
  82. #define QTStr(lookupVal) QString::fromUtf8(Str(lookupVal))