00001 #include <mythtv/mythcontext.h>
00002 #include <mythtv/mythdbcon.h>
00003 #include <mythtv/mythpluginapi.h>
00004
00005 #include "moviesui.h"
00006 #include "moviessettings.h"
00007
00008 void runMovies(void);
00009 int setupDatabase();
00010 MythPopupBox *configPopup;
00011 const QString dbVersion = "4";
00012
00013 void setupKeys(void)
00014 {
00015
00016 }
00017
00018 int mythplugin_init(const char *libversion)
00019 {
00020 if (!gContext->TestPopupVersion("mythmovies", libversion,
00021 MYTH_BINARY_VERSION))
00022 {
00023 VERBOSE(VB_IMPORTANT,
00024 QString("libmythmovies.so/main.o: binary version mismatch"));
00025 return -1;
00026 }
00027 int dbSetup = setupDatabase();
00028 if (dbSetup == -1)
00029 {
00030 VERBOSE(VB_IMPORTANT, "MythMovies cannot continue without"
00031 "a proper database setup.");
00032 return -1;
00033 }
00034 setupKeys();
00035 return 0;
00036 }
00037
00038 void runMovies(void)
00039 {
00040 gContext->addCurrentLocation("mythmovies");
00041 MoviesUI moviesui(gContext->GetMainWindow(), "moviesui", "movies-");
00042 moviesui.exec();
00043 gContext->removeCurrentLocation();
00044 }
00045
00046 void runConfig()
00047 {
00048 MoviesSettings settings;
00049 settings.exec();
00050 }
00051
00052 int mythplugin_run(void)
00053 {
00054 gContext->ActivateSettingsCache(false);
00055 if (gContext->GetSetting("MythMovies.ZipCode") == "" ||
00056 gContext->GetSetting("MythMovies.Radius") == "" ||
00057 gContext->GetSetting("MythMovies.Grabber") == "")
00058 {
00059 runConfig();
00060 }
00061 if (gContext->GetSetting("MythMovies.ZipCode") == "" ||
00062 gContext->GetSetting("MythMovies.Radius") == "" ||
00063 gContext->GetSetting("MythMovies.Grabber") == "")
00064 {
00065 VERBOSE(VB_IMPORTANT,
00066 QString("Invalid configuration options supplied."));
00067 gContext->ActivateSettingsCache(true);
00068 return 0;
00069 }
00070 gContext->ActivateSettingsCache(true);
00071 runMovies();
00072 return 0;
00073 }
00074
00075 int mythplugin_config(void)
00076 {
00077 runConfig();
00078 return 0;
00079 }
00080
00081 int setupDatabase()
00082 {
00083
00084
00085 if (dbVersion == gContext->GetSetting("MythMovies.DatabaseVersion"))
00086 return 0;
00087
00088 gContext->SaveSetting("MythMovies.LastGrabDate", "");
00089
00090 VERBOSE(VB_GENERAL, "Setting Up MythMovies Database Tables");
00091
00092 MSqlQuery query(MSqlQuery::InitCon());
00093 if (query.exec("DROP TABLE IF EXISTS movies_showtimes, movies_theaters, movies_movies"))
00094 {
00095 bool a = query.exec("CREATE TABLE movies_theaters ("
00096 "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
00097 "theatername VARCHAR(100),"
00098 "theateraddress VARCHAR(100)"
00099 ");");
00100
00101 bool b = query.exec("CREATE TABLE movies_movies ("
00102 "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
00103 "moviename VARCHAR(255),"
00104 "rating VARCHAR(10),"
00105 "runningtime VARCHAR(50)"
00106 ");");
00107
00108 bool c = query.exec("CREATE TABLE movies_showtimes ("
00109 "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
00110 "theaterid INT NOT NULL,"
00111 "movieid INT NOT NULL,"
00112 "showtimes VARCHAR(255)"
00113 ");");
00114
00115 if (!a || !b || !c)
00116 {
00117 VERBOSE(VB_IMPORTANT, "Failed to create MythMovies Tables");
00118 return -1;
00119 }
00120 else
00121 {
00122 gContext->SaveSetting("MythMovies.DatabaseVersion", dbVersion);
00123 VERBOSE(VB_GENERAL, "MythMovies Database Setup Complete");
00124 return 0;
00125 }
00126 }
00127 else
00128 {
00129 VERBOSE(VB_IMPORTANT, "Failed to delete old MythMovies Tables");
00130 return -1;
00131 }
00132 }
00133