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 runZMConsole();
114 else if (sel == "zm_live_viewer")
116 else if (sel == "zm_event_viewer")
118 else
119 {
120 // if we have found the mainmenu callback
121 // pass the selection on to it
123 m_callback(m_callbackdata, selection);
124 }
125}
126
127static int runMenu(const QString& which_menu)
128{
129 QString themedir = GetMythUI()->GetThemeDir();
130
131 // find the 'mainmenu' MythThemedMenu so we can use the callback from it
132 MythThemedMenu *mainMenu = nullptr;
133 QObject *parentObject = GetMythMainWindow()->GetMainStack()->GetTopScreen();
134
135 while (parentObject)
136 {
137 mainMenu = qobject_cast<MythThemedMenu *>(parentObject);
138
139 if (mainMenu && mainMenu->objectName() == "mainmenu")
140 break;
141
142 parentObject = parentObject->parent();
143 }
144
145 auto *diag = new MythThemedMenu(
146 themedir, which_menu, GetMythMainWindow()->GetMainStack(),
147 "zoneminder menu");
148
149 // save the callback from the main menu
150 if (mainMenu)
152 else
153 {
154 m_callback = nullptr;
155 m_callbackdata = nullptr;
156 }
157
158 diag->setCallback(ZoneMinderCallback, nullptr);
159 diag->setKillable();
160
161 if (diag->foundTheme())
162 {
164 return 0;
165 }
166 LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
167 .arg(which_menu, themedir));
168 delete diag;
169 return -1;
170}
171
172static void setupKeys(void)
173{
174 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Console"),
175 "", "", runZMConsole);
176 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Live View"),
177 "", "", runZMLiveView);
178 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Events"),
179 "", "", runZMEventView);
180 REG_JUMPEX(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Mini Live View"),
181 "", "", runZMMiniPlayer, false);
182}
183
184int mythplugin_init(const char *libversion)
185{
186 if (!MythCoreContext::TestPluginVersion("mythzoneminder",
187 libversion,
188 MYTH_BINARY_VERSION))
189 return -1;
190
191 // setup a connection to the mythzmserver
192 (void) checkConnection();
193
194 setupKeys();
195
196 // create the alarm polling thread
198
199 return 0;
200}
201
203{
204
205 return runMenu("zonemindermenu.xml");
206}
207
209{
211 auto *ssd = new StandardSettingDialog(mainStack, "zonemindersettings",
212 new ZMSettings());
213
214 if (ssd->Create())
215 mainStack->AddScreen(ssd);
216 else
217 delete ssd;
218
219 return 0;
220}
221
223{
225 delete AlarmNotifyThread::get();
226 delete ZMClient::get();
227}
228
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:283
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:23
#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)