cd-rec-status.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <obs-module.h>
  2. #include <obs-frontend-api.h>
  3. #include <QLabel>
  4. #include <QFile>
  5. #include <QTimer>
  6. #include <QVBoxLayout>
  7. #include <QWidget>
  8. #include <QDockWidget>
  9. OBS_DECLARE_MODULE()
  10. OBS_MODULE_USE_DEFAULT_LOCALE("show_cd_rec_status", "en-US")
  11. class CDStatusDock : public QWidget {
  12. public:
  13. CDStatusDock(QWidget *parent = nullptr) : QWidget(parent) {
  14. QVBoxLayout *layout = new QVBoxLayout(this);
  15. statusLabel = new QLabel("Loading...", this);
  16. layout->addWidget(statusLabel);
  17. setLayout(layout);
  18. QTimer *timer = new QTimer(this);
  19. connect(timer, &QTimer::timeout, this, &CDStatusDock::updateStatus);
  20. timer->start(1000);
  21. }
  22. private:
  23. QLabel *statusLabel;
  24. void updateStatus() {
  25. QFile f("/tmp/cd_status.txt");
  26. if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
  27. QString text = f.readAll();
  28. statusLabel->setText(text);
  29. } else {
  30. statusLabel->setText("Status file not found");
  31. }
  32. }
  33. };
  34. static void *create_cd_status_dock(obs_source_t *) {
  35. return new CDStatusDock();
  36. }
  37. bool obs_module_load(void)
  38. {
  39. QDockWidget *dock = new QDockWidget("CD Rec Status");
  40. dock->setObjectName("cd-rec-status-dock");
  41. dock->setWidget(new CDStatusDock());
  42. obs_frontend_add_custom_qdock("cd_status_dock", (void *)dock);
  43. blog(LOG_INFO, "CD Rec Status Dock loaded!");
  44. return true;
  45. }
  46. MODULE_EXPORT const char *obs_module_description(void)
  47. {
  48. return obs_module_text("Description");
  49. }
  50. MODULE_EXPORT const char *obs_module_name(void)
  51. {
  52. return obs_module_text("CD Rec Status");
  53. }