obs-app.hpp 2.9 KB

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