MythTV master
mythzoneminder.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// C++
16#include <iostream>
17#include <unistd.h>
18
19// MythTV
23#include <libmythbase/mythversion.h>
27
28//zone minder
29#include "zmsettings.h"
30#include "zmconsole.h"
31#include "zmliveplayer.h"
32#include "zmevents.h"
33#include "zmclient.h"
34#include "zmminiplayer.h"
35#include "alarmnotifythread.h"
36
37static bool checkConnection(void)
38{
39 if (!ZMClient::get()->connected())
40 {
42 return false;
43 }
44
45 return true;
46}
47
48static void runZMConsole(void)
49{
50 if (!checkConnection())
51 return;
52
54
55 auto *console = new ZMConsole(mainStack);
56
57 if (console->Create())
58 mainStack->AddScreen(console);
59}
60
61static void runZMLiveView(void)
62{
63 if (!checkConnection())
64 return;
65
66
68
69 auto *player = new ZMLivePlayer(mainStack);
70
71 if (player->Create())
72 mainStack->AddScreen(player);
73}
74
75static void runZMEventView(void)
76{
77 if (!checkConnection())
78 return;
79
81
82 auto *events = new ZMEvents(mainStack);
83
84 if (events->Create())
85 mainStack->AddScreen(events);
86}
87
88static void runZMMiniPlayer(void)
89{
90 if (!ZMClient::get()->isMiniPlayerEnabled())
91 return;
92
93 if (!checkConnection())
94 return;
95
97
98 auto *miniPlayer = new ZMMiniPlayer(mainStack);
99
100 if (miniPlayer->Create())
101 mainStack->AddScreen(miniPlayer);
102}
103
104// these point to the the mainmenu callback if found
105static void (*m_callback)(void *, QString &) = nullptr;
106static void *m_callbackdata = nullptr;
107
108static void ZoneMinderCallback([[maybe_unused]] void *data, QString &selection)
109{
110 QString sel = selection.toLower();
111
112 if (sel == "zm_console")
113 {
114 runZMConsole();
115 }
116 else if (sel == "zm_live_viewer")
117 {
119 }
120 else if (sel == "zm_event_viewer")
121 {
123 }
124 else
125 {
126 // if we have found the mainmenu callback
127 // pass the selection on to it
129 m_callback(m_callbackdata, selection);
130 }
131}
132
133static int runMenu(const QString& which_menu)
134{
135 QString themedir = GetMythUI()->GetThemeDir();
136
137 // find the 'mainmenu' MythThemedMenu so we can use the callback from it
138 MythThemedMenu *mainMenu = nullptr;
139 QObject *parentObject = GetMythMainWindow()->GetMainStack()->GetTopScreen();
140
141 while (parentObject)
142 {
143 mainMenu = qobject_cast<MythThemedMenu *>(parentObject);
144
145 if (mainMenu && mainMenu->objectName() == "mainmenu")
146 break;
147
148 parentObject = parentObject->parent();
149 }
150
151 auto *diag = new MythThemedMenu(
152 themedir, which_menu, GetMythMainWindow()->GetMainStack(),
153 "zoneminder menu");
154
155 // save the callback from the main menu
156 if (mainMenu)
157 {
159 }
160 else
161 {
162 m_callback = nullptr;
163 m_callbackdata = nullptr;
164 }
165
166 diag->setCallback(ZoneMinderCallback, nullptr);
167 diag->setKillable();
168
169 if (diag->foundTheme())
170 {
172 return 0;
173 }
174 LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
175 .arg(which_menu, themedir));
176 delete diag;
177 return -1;
178}
179
180static void setupKeys(void)
181{
182 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Console"),
183 "", "", runZMConsole);
184 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Live View"),
185 "", "", runZMLiveView);
186 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Events"),
187 "", "", runZMEventView);
188 REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Mini Live View"),
189 "", "", runZMMiniPlayer, false);
190}
191
192int mythplugin_init(const char *libversion)
193{
194 if (!MythCoreContext::TestPluginVersion("mythzoneminder",
195 libversion,
196 MYTH_BINARY_VERSION))
197 return -1;
198
199 // setup a connection to the mythzmserver
200 (void) checkConnection();
201
202 setupKeys();
203
204 // create the alarm polling thread
206
207 return 0;
208}
209
211{
212
213 return runMenu("zonemindermenu.xml");
214}
215
217{
219 auto *ssd = new StandardSettingDialog(mainStack, "zonemindersettings",
220 new ZMSettings());
221
222 if (ssd->Create())
223 mainStack->AddScreen(ssd);
224 else
225 delete ssd;
226
227 return 0;
228}
229
231{
233 delete AlarmNotifyThread::get();
234 delete ZMClient::get();
235}
236
static AlarmNotifyThread * get(void)
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:267
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
virtual MythScreenType * GetTopScreen(void) const
Themed menu class, used for main menus in MythTV frontend.
void getCallback(void(**lcallback)(void *, QString &), void **data)
Get the themed menus callback function and data for that function.
static ZMClient * get(void)
Definition: zmclient.cpp:37
static bool setupZMClient(void)
Definition: zmclient.cpp:44
static QString themedir
Definition: mythdirs.cpp:26
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static void REG_JUMPEX(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void), bool ExitToMain)
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
MythUIHelper * GetMythUI()
int mythplugin_config(void)
static void(* m_callback)(void *, QString &)
void mythplugin_destroy(void)
static void runZMLiveView(void)
static void ZoneMinderCallback(void *data, QString &selection)
static void runZMMiniPlayer(void)
static void setupKeys(void)
static int runMenu(const QString &which_menu)
static void runZMEventView(void)
int mythplugin_run(void)
static bool checkConnection(void)
int mythplugin_init(const char *libversion)
static void * m_callbackdata
static void runZMConsole(void)