obs-app.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <util/lexer.h>
  18. #include <util/util.hpp>
  19. #include <string>
  20. #include <memory>
  21. #include "window-main.hpp"
  22. std::string CurrentTimeString();
  23. std::string CurrentDateTimeString();
  24. struct BaseLexer {
  25. lexer lex;
  26. public:
  27. inline BaseLexer() {lexer_init(&lex);}
  28. inline ~BaseLexer() {lexer_free(&lex);}
  29. operator lexer*() {return &lex;}
  30. };
  31. class OBSTranslator : public QTranslator {
  32. Q_OBJECT
  33. public:
  34. virtual bool isEmpty() const override {return false;}
  35. virtual QString translate(const char *context, const char *sourceText,
  36. const char *disambiguation, int n) const override;
  37. };
  38. class OBSApp : public QApplication {
  39. Q_OBJECT
  40. private:
  41. std::string locale;
  42. ConfigFile globalConfig;
  43. TextLookup textLookup;
  44. std::unique_ptr<OBSMainWindow> mainWindow;
  45. bool InitGlobalConfig();
  46. bool InitGlobalConfigDefaults();
  47. bool InitLocale();
  48. public:
  49. OBSApp(int &argc, char **argv);
  50. void OBSInit();
  51. inline QMainWindow *GetMainWindow() const {return mainWindow.get();}
  52. inline config_t GlobalConfig() const {return globalConfig;}
  53. inline const char *GetLocale() const
  54. {
  55. return locale.c_str();
  56. }
  57. inline lookup_t GetTextLookup() const {return textLookup;}
  58. inline const char *GetString(const char *lookupVal) const
  59. {
  60. return textLookup.GetString(lookupVal);
  61. }
  62. const char *GetLastLog() const;
  63. const char *GetCurrentLog() const;
  64. std::string GetVersionString() const;
  65. const char *InputAudioSource() const;
  66. const char *OutputAudioSource() const;
  67. const char *GetRenderModule() const;
  68. };
  69. inline OBSApp *App() {return static_cast<OBSApp*>(qApp);}
  70. inline config_t GetGlobalConfig() {return App()->GlobalConfig();}
  71. inline const char *Str(const char *lookup) {return App()->GetString(lookup);}
  72. #define QTStr(lookupVal) QString::fromUtf8(Str(lookupVal))