/
main.cpp
170 lines (131 loc) · 3.72 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* ============================================================
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published bythe Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#include <iostream>
#include <unistd.h>
// myth
#include <mythcontext.h>
#include <mythversion.h>
#include <mythpluginapi.h>
#include <mythmainwindow.h>
#include <myththemedmenu.h>
#include <mythuihelper.h>
#include <mythlogging.h>
//zone minder
#include "zmsettings.h"
#include "zmconsole.h"
#include "zmliveplayer.h"
#include "zmevents.h"
#include "zmclient.h"
using namespace std;
static bool checkConnection(void)
{
if (!ZMClient::get()->connected())
{
if (!ZMClient::setupZMClient())
return false;
}
return true;
}
static void runZMConsole(void)
{
if (!checkConnection())
return;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
ZMConsole *console = new ZMConsole(mainStack);
if (console->Create())
mainStack->AddScreen(console);
}
static void runZMLiveView(void)
{
if (!checkConnection())
return;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
ZMLivePlayer *player = new ZMLivePlayer(mainStack);
if (player->Create())
mainStack->AddScreen(player);
}
static void runZMEventView(void)
{
if (!checkConnection())
return;
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
ZMEvents *events = new ZMEvents(mainStack);
if (events->Create())
mainStack->AddScreen(events);
}
static void ZoneMinderCallback(void *data, QString &selection)
{
(void) data;
QString sel = selection.toLower();
if (sel == "zm_console")
runZMConsole();
else if (sel == "zm_live_viewer")
runZMLiveView();
else if (sel == "zm_event_viewer")
runZMEventView();
}
static int runMenu(QString which_menu)
{
QString themedir = GetMythUI()->GetThemeDir();
MythThemedMenu *diag = new MythThemedMenu(
themedir, which_menu, GetMythMainWindow()->GetMainStack(),
"zoneminder menu");
diag->setCallback(ZoneMinderCallback, NULL);
diag->setKillable();
if (diag->foundTheme())
{
GetMythMainWindow()->GetMainStack()->AddScreen(diag);
return 0;
}
else
{
LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
.arg(which_menu).arg(themedir));
delete diag;
return -1;
}
}
static void setupKeys(void)
{
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Console"),
"", "", runZMConsole);
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Live View"),
"", "", runZMLiveView);
REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Events"),
"", "", runZMEventView);
}
int mythplugin_init(const char *libversion)
{
if (!gContext->TestPopupVersion("mythzoneminder",
libversion,
MYTH_BINARY_VERSION))
return -1;
setupKeys();
return 0;
}
int mythplugin_run(void)
{
// setup a connection to the mythzmserver
if (!ZMClient::setupZMClient())
{
return -1;
}
return runMenu("zonemindermenu.xml");
}
int mythplugin_config(void)
{
ZMSettings settings;
settings.exec();
return 0;
}