00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <unistd.h>
00017
00018
00019 #include <mythcontext.h>
00020 #include <mythversion.h>
00021 #include <mythpluginapi.h>
00022 #include <mythmainwindow.h>
00023 #include <myththemedmenu.h>
00024 #include <mythuihelper.h>
00025 #include <mythlogging.h>
00026
00027
00028 #include "zmsettings.h"
00029 #include "zmconsole.h"
00030 #include "zmliveplayer.h"
00031 #include "zmevents.h"
00032 #include "zmclient.h"
00033
00034 using namespace std;
00035
00036
00037
00038 static bool checkConnection(void)
00039 {
00040 if (!ZMClient::get()->connected())
00041 {
00042 if (!ZMClient::setupZMClient())
00043 return false;
00044 }
00045
00046 return true;
00047 }
00048
00049 static void runZMConsole(void)
00050 {
00051 if (!checkConnection())
00052 return;
00053
00054 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00055
00056 ZMConsole *console = new ZMConsole(mainStack);
00057
00058 if (console->Create())
00059 mainStack->AddScreen(console);
00060 }
00061
00062 static void runZMLiveView(void)
00063 {
00064 if (!checkConnection())
00065 return;
00066
00067
00068 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00069
00070 ZMLivePlayer *player = new ZMLivePlayer(mainStack);
00071
00072 if (player->Create())
00073 mainStack->AddScreen(player);
00074 }
00075
00076 static void runZMEventView(void)
00077 {
00078 if (!checkConnection())
00079 return;
00080
00081 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00082
00083 ZMEvents *events = new ZMEvents(mainStack);
00084
00085 if (events->Create())
00086 mainStack->AddScreen(events);
00087 }
00088
00089 static void ZoneMinderCallback(void *data, QString &selection)
00090 {
00091 (void) data;
00092
00093 QString sel = selection.toLower();
00094
00095 if (sel == "zm_console")
00096 runZMConsole();
00097 else if (sel == "zm_live_viewer")
00098 runZMLiveView();
00099 else if (sel == "zm_event_viewer")
00100 runZMEventView();
00101 }
00102
00103 static int runMenu(QString which_menu)
00104 {
00105 QString themedir = GetMythUI()->GetThemeDir();
00106
00107 MythThemedMenu *diag = new MythThemedMenu(
00108 themedir, which_menu, GetMythMainWindow()->GetMainStack(),
00109 "zoneminder menu");
00110
00111 diag->setCallback(ZoneMinderCallback, NULL);
00112 diag->setKillable();
00113
00114 if (diag->foundTheme())
00115 {
00116 GetMythMainWindow()->GetMainStack()->AddScreen(diag);
00117 return 0;
00118 }
00119 else
00120 {
00121 LOG(VB_GENERAL, LOG_ERR, QString("Couldn't find menu %1 or theme %2")
00122 .arg(which_menu).arg(themedir));
00123 delete diag;
00124 return -1;
00125 }
00126 }
00127
00128 static void setupKeys(void)
00129 {
00130 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Console"),
00131 "", "", runZMConsole);
00132 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Live View"),
00133 "", "", runZMLiveView);
00134 REG_JUMP(QT_TRANSLATE_NOOP("MythControls", "ZoneMinder Events"),
00135 "", "", runZMEventView);
00136 }
00137
00138 int mythplugin_init(const char *libversion)
00139 {
00140 if (!gContext->TestPopupVersion("mythzoneminder",
00141 libversion,
00142 MYTH_BINARY_VERSION))
00143 return -1;
00144
00145 setupKeys();
00146
00147 return 0;
00148 }
00149
00150 int mythplugin_run(void)
00151 {
00152
00153 if (!ZMClient::setupZMClient())
00154 {
00155 return -1;
00156 }
00157
00158 return runMenu("zonemindermenu.xml");
00159 }
00160
00161 int mythplugin_config(void)
00162 {
00163 ZMSettings settings;
00164 settings.exec();
00165
00166 return 0;
00167 }
00168
00169
00170