obs-app.hpp 2.8 KB

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