MythTV  master
mythplugins/mythzoneminder/mythzoneminder/main.cpp
Go to the documentation of this file.
1 /* ============================================================
2  * This program is free software; you can redistribute it
3  * and/or modify it under the terms of the GNU General
4  * Public License as published bythe Free Software Foundation;
5  * either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * ============================================================ */
14 
15 #include <iostream>
16 #include <unistd.h>
17 
18 // myth
19 #include <mythcontext.h>
20 #include <mythversion.h>
21 #include <mythpluginapi.h>
22 #include <mythmainwindow.h>
23 #include <myththemedmenu.h>
24 #include <mythuihelper.h>
25 #include <mythlogging.h>
26 
27 //zone minder
28 #include "zmsettings.h"
29 #include "zmconsole.h"
30 #include "zmliveplayer.h"
31 #include "zmevents.h"
32 #include "zmclient.h"
33 #include "zmminiplayer.h"
34 #include "alarmnotifythread.h"
35 
36 static bool checkConnection(void)
37 {
38  if (!ZMClient::get()->connected())
39  {
41  return false;
42  }
43 
44  return true;
45 }
46 
47 static void runZMConsole(void)
48 {
49  if (!checkConnection())
50  return;
51 
53 
54  auto *console = new ZMConsole(mainStack);
55 
56  if (console->Create())
57  mainStack->AddScreen(console);
58 }
59 
60 static void runZMLiveView(void)
61 {
62  if (!checkConnection())
63  return;
64 
65 
67 
68  auto *player = new ZMLivePlayer(mainStack);
69 
70  if (player->Create())
71  mainStack->AddScreen(player);
72 }
73 
74 static void runZMEventView(void)
75 {
76  if (!checkConnection())
77  return;
78 
80 
81  auto *events = new ZMEvents(mainStack);
82 
83  if (events->Create())
84  mainStack->AddScreen(events);
85 }
86 
87 static void runZMMiniPlayer(void)
88 {
89  if (!ZMClient::get()->isMiniPlayerEnabled())
90  return;
91 
92  if (!checkConnection())
93  return;
94 
96 
97  auto *miniPlayer = new ZMMiniPlayer(mainStack);
98 
99  if (miniPlayer->Create())
100  mainStack->AddScreen(miniPlayer);
101 }
102 
103 // these point to the the mainmenu callback if found
104 static void (*m_callback)(void *, QString &) = nullptr;
105 static void *m_callbackdata = nullptr;
106 
107 static void ZoneMinderCallback(void *data, QString &selection)
108 {
109  (void) data;
110 
111  QString sel = selection.toLower();
112 
113  if (sel == "zm_console")
114  runZMConsole();
115  else if (sel == "zm_live_viewer")
116  runZMLiveView();
117  else if (sel == "zm_event_viewer")
118  runZMEventView();
119  else
120  {
121  // if we have found the mainmenu callback
122  // pass the selection on to it
123  if (m_callback && m_callbackdata)
124  m_callback(m_callbackdata, selection);
125  }
126 }
127 
128 static int runMenu(const QString& which_menu)
129 {
130  QString themedir = GetMythUI()->GetThemeDir();
131 
132  // find the 'mainmenu' MythThemedMenu so we can use the callback from it
133  MythThemedMenu *mainMenu = nullptr;
134  QObject *parentObject = GetMythMainWindow()->GetMainStack()->GetTopScreen();
135 
136  while (parentObject)
137  {
138  mainMenu = qobject_cast<MythThemedMenu *>(parentObject);
139 
140  if (mainMenu && mainMenu->objectName() == "mainmenu")
141  break;
142 
143  parentObject = parentObject->parent();
144  }
145 
146  auto *diag = new MythThemedMenu(
147  themedir, which_menu, GetMythMainWindow()->GetMainStack(),
148  "zoneminder menu");
149 
150  // save the callback from the main menu
151  if (mainMenu)
152  mainMenu->getCallback(&m_callback, &m_callbackdata);
153  else
154  {
155  m_callback = nullptr;
156  m_callbackdata = nullptr;
157  }
158 
159  diag->setCallback(ZoneMinderCallback, nullptr);
160  diag->setKillable();
161 
162  if (diag->foundTheme())
163  {
165  return 0;
166  }
167  LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
168  .arg(which_menu).arg(themedir));
169  delete diag;
170  return -1;
171 }
172 
173 static void setupKeys(void)
174 {
175  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Console"),
176  "", "", runZMConsole);
177  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Live View"),
178  "", "", runZMLiveView);
179  REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Events"),
180  "", "", runZMEventView);
181  REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Mini Live View"),
182  "", "", runZMMiniPlayer, false);
183 }
184 
185 int mythplugin_init(const char *libversion)
186 {
187  if (!MythCoreContext::TestPluginVersion("mythzoneminder",
188  libversion,
190  return -1;
191 
192  // setup a connection to the mythzmserver
193  (void) checkConnection();
194 
195  setupKeys();
196 
197  // create the alarm polling thread
199 
200  return 0;
201 }
202 
203 int mythplugin_run(void)
204 {
205 
206  return runMenu("zonemindermenu.xml");
207 }
208 
210 {
212  auto *ssd = new StandardSettingDialog(mainStack, "zonemindersettings",
213  new ZMSettings());
214 
215  if (ssd->Create())
216  mainStack->AddScreen(ssd);
217  else
218  delete ssd;
219 
220  return 0;
221 }
222 
224 {
226  delete AlarmNotifyThread::get();
227  delete ZMClient::get();
228 }
229 
themedir
static QString themedir
Definition: mythdirs.cpp:21
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:324
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:288
runZMLiveView
static void runZMLiveView(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:60
runZMMiniPlayer
static void runZMMiniPlayer(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:87
MythScreenStack
Definition: mythscreenstack.h:16
arg
arg(title).arg(filename).arg(doDelete))
ZMClient::setupZMClient
static bool setupZMClient(void)
Definition: zmclient.cpp:45
mythplugin_config
int mythplugin_config(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:209
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythplugin_destroy
void mythplugin_destroy(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:223
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2060
ZMMiniPlayer
Definition: zmminiplayer.h:11
AlarmNotifyThread::stop
void stop(void)
Definition: alarmnotifythread.cpp:30
zmliveplayer.h
mythversion.h
runZMConsole
static void runZMConsole(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:47
alarmnotifythread.h
zmclient.h
zmconsole.h
StandardSettingDialog
Definition: standardsettings.h:469
ZoneMinderCallback
static void ZoneMinderCallback(void *data, QString &selection)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:107
AlarmNotifyThread::get
static AlarmNotifyThread * get(void)
Definition: alarmnotifythread.cpp:13
mythlogging.h
zmevents.h
MythUIThemeHelper::GetThemeDir
QString GetThemeDir()
Definition: mythuithemehelper.cpp:140
ZMEvents
Definition: zmevents.h:31
m_callback
static void(* m_callback)(void *, QString &)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:104
setupKeys
static void setupKeys(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:173
ZMLivePlayer
Definition: zmliveplayer.h:61
REG_JUMP
#define REG_JUMP(a, b, c, d)
Definition: mythmainwindow.h:20
mythplugin_run
int mythplugin_run(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:203
ZMClient::get
static ZMClient * get(void)
Definition: zmclient.cpp:38
ZMConsole
Definition: zmconsole.h:57
runZMEventView
static void runZMEventView(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:74
mythpluginapi.h
zmminiplayer.h
m_callbackdata
static void * m_callbackdata
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:105
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:185
mythuihelper.h
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
MythThemedMenu::getCallback
void getCallback(void(**lcallback)(void *, QString &), void **data)
Get the themed menus callback function and data for that function.
Definition: myththemedmenu.cpp:150
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:108
REG_JUMPEX
#define REG_JUMPEX(a, b, c, d, e)
Definition: mythmainwindow.h:22
MythThemedMenu
Themed menu class, used for main menus in MythTV frontend.
Definition: myththemedmenu.h:58
myththemedmenu.h
GetMythUI
MythUIHelper * GetMythUI()
Definition: mythuihelper.cpp:66
mythmainwindow.h
zmsettings.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
checkConnection
static bool checkConnection(void)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:36
runMenu
static int runMenu(const QString &which_menu)
Definition: mythplugins/mythzoneminder/mythzoneminder/main.cpp:128
MythScreenStack::GetTopScreen
virtual MythScreenType * GetTopScreen(void) const
Definition: mythscreenstack.cpp:182
ZMSettings
Definition: zmsettings.h:13