00001
00002 #include <unistd.h>
00003
00004
00005 #include <iostream>
00006 using namespace std;
00007
00008
00009 #include <QCoreApplication>
00010 #include <QEventLoop>
00011
00012
00013 #include <exitcodes.h>
00014 #include <mythcontext.h>
00015 #include <mythdb.h>
00016 #include <mythversion.h>
00017 #include <remoteutil.h>
00018 #include <mythmiscutil.h>
00019 #include <netutils.h>
00020 #include <mythtranslation.h>
00021 #include <mythconfig.h>
00022 #include <netgrabbermanager.h>
00023 #include <mythrssmanager.h>
00024 #include <mythcommandlineparser.h>
00025 #include <mythlogging.h>
00026
00027 GrabberDownloadThread *gdt = 0;
00028 RSSManager *rssMan = 0;
00029
00030 class MPUBLIC MythFillNVCommandLineParser : public MythCommandLineParser
00031 {
00032 public:
00033 MythFillNVCommandLineParser();
00034 void LoadArguments(void);
00035 };
00036
00037 MythFillNVCommandLineParser::MythFillNVCommandLineParser() :
00038 MythCommandLineParser("mythfillnetvision")
00039 { LoadArguments(); }
00040
00041 void MythFillNVCommandLineParser::LoadArguments(void)
00042 {
00043 addHelp();
00044 addVersion();
00045 addLogging();
00046
00047 add("--refresh-all", "refresh-all", false,
00048 "Refresh ALL configured and installed tree grabbers", "");
00049 add("--refresh-rss", "refresh-rss", false,
00050 "Refresh RSS feeds only", "");
00051 add("--refresh-tree", "refresh-tree", false,
00052 "Refresh trees only", "");
00053 }
00054
00055
00056
00057 int main(int argc, char *argv[])
00058 {
00059 MythFillNVCommandLineParser cmdline;
00060 if (!cmdline.Parse(argc, argv))
00061 {
00062 cmdline.PrintHelp();
00063 return GENERIC_EXIT_INVALID_CMDLINE;
00064 }
00065
00066 if (cmdline.toBool("showhelp"))
00067 {
00068 cmdline.PrintHelp();
00069 return GENERIC_EXIT_OK;
00070 }
00071
00072 if (cmdline.toBool("showversion"))
00073 {
00074 cmdline.PrintVersion();
00075 return GENERIC_EXIT_OK;
00076 }
00077
00078 QCoreApplication a(argc, argv);
00079 QCoreApplication::setApplicationName("mythfillnetvision");
00080
00081 int retval;
00082 if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
00083 return retval;
00084
00086
00087 close(0);
00088
00089 gContext = new MythContext(MYTH_BINARY_VERSION);
00090 if (!gContext->Init(false))
00091 {
00092 LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
00093 delete gContext;
00094 return GENERIC_EXIT_NO_MYTHCONTEXT;
00095 }
00096
00097 bool refreshall = cmdline.toBool("refresh-all");
00098 bool refreshrss = cmdline.toBool("refresh-rss");
00099 bool refreshtree = cmdline.toBool("refresh-tree");
00100
00101 if (refreshall && (refreshrss || refreshtree))
00102 {
00103 LOG(VB_GENERAL, LOG_ERR, "--refresh-all must not be accompanied by "
00104 "--refresh-rss or --refresh-tree");
00105 return GENERIC_EXIT_INVALID_CMDLINE;
00106 }
00107
00108 if (refreshrss && refreshtree)
00109 {
00110 LOG(VB_GENERAL, LOG_ERR, "--refresh-rss and --refresh-tree are "
00111 "mutually exclusive options");
00112 return GENERIC_EXIT_INVALID_CMDLINE;
00113 }
00114
00115 if (!refreshall && !refreshrss && !refreshtree)
00116 {
00117
00118 refreshtree = true;
00119 refreshrss = true;
00120 }
00121
00122 myth_nice(19);
00123
00124 MythTranslation::load("mythfrontend");
00125
00126 if (refreshall || refreshtree)
00127 {
00128 QEventLoop treeloop;
00129
00130 gdt = new GrabberDownloadThread(NULL);
00131 if (refreshall)
00132 gdt->refreshAll();
00133 gdt->start();
00134
00135 QObject::connect(gdt, SIGNAL(finished(void)), &treeloop, SLOT(quit()));
00136 treeloop.exec();
00137 }
00138
00139 if ((refreshall || refreshrss) && findAllDBRSS().count())
00140 {
00141 QEventLoop rssloop;
00142
00143 rssMan = new RSSManager();
00144 rssMan->doUpdate();
00145
00146 QObject::connect(rssMan, SIGNAL(finished(void)), &rssloop, SLOT(quit()));
00147 rssloop.exec();
00148 }
00149
00150 delete gdt;
00151 delete rssMan;
00152 delete gContext;
00153
00154 LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
00155
00156 return GENERIC_EXIT_OK;
00157 }
00158
00159