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