MythTV  master
mythfillnetvision.cpp
Go to the documentation of this file.
1 // C headers
2 #include <unistd.h>
3 
4 // C++ headers
5 #include <iostream>
6 
7 // Qt headers
8 #include <QCoreApplication>
9 #include <QEventLoop>
10 
11 // MythTV headers
12 #include <mythconfig.h>
13 #include <libmyth/mythcontext.h>
14 #include <libmythbase/exitcodes.h>
16 #include <libmythbase/mythdb.h>
21 #include <libmythbase/mythversion.h>
23 #include <libmythbase/netutils.h>
24 #include <libmythbase/remoteutil.h>
25 #include <libmythbase/rssmanager.h>
26 
28 RSSManager *rssMan = nullptr;
29 
31 {
32  public:
34  void LoadArguments(void) override; // MythCommandLineParser
35 };
36 
38  MythCommandLineParser("mythfillnetvision")
40 
42 {
43  addHelp();
44  addVersion();
45  addLogging();
46 
47  add("--refresh-all", "refresh-all", false,
48  "Refresh ALL configured and installed tree grabbers", "");
49  add("--refresh-rss", "refresh-rss", false,
50  "Refresh RSS feeds only", "");
51  add("--refresh-tree", "refresh-tree", false,
52  "Refresh trees only", "");
53 }
54 
55 
56 
57 int main(int argc, char *argv[])
58 {
60  if (!cmdline.Parse(argc, argv))
61  {
64  }
65 
66  if (cmdline.toBool("showhelp"))
67  {
69  return GENERIC_EXIT_OK;
70  }
71 
72  if (cmdline.toBool("showversion"))
73  {
75  return GENERIC_EXIT_OK;
76  }
77 
78  QCoreApplication a(argc, argv);
79  QCoreApplication::setApplicationName("mythfillnetvision");
80 
81  int retval = cmdline.ConfigureLogging();
82  if (retval != GENERIC_EXIT_OK)
83  return retval;
84 
86  // Don't listen to console input
87  close(0);
88 
89  MythContext context {MYTH_BINARY_VERSION};
90  if (!context.Init(false))
91  {
92  LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
94  }
95 
96  bool refreshall = cmdline.toBool("refresh-all");
97  bool refreshrss = cmdline.toBool("refresh-rss");
98  bool refreshtree = cmdline.toBool("refresh-tree");
99 
100  if (refreshall && (refreshrss || refreshtree))
101  {
102  LOG(VB_GENERAL, LOG_ERR, "--refresh-all must not be accompanied by "
103  "--refresh-rss or --refresh-tree");
105  }
106 
107  if (refreshrss && refreshtree)
108  {
109  LOG(VB_GENERAL, LOG_ERR, "--refresh-rss and --refresh-tree are "
110  "mutually exclusive options");
112  }
113 
114  if (!refreshall && !refreshrss && !refreshtree)
115  {
116  // Default is to do rss & tree, but not all
117  refreshtree = true;
118  refreshrss = true;
119  }
120 
121  myth_nice(19);
122 
123  MythTranslation::load("mythfrontend");
124 
125  if (refreshall || refreshtree)
126  {
127  QEventLoop treeloop;
128 
129  gdt = new GrabberDownloadThread(nullptr);
130  if (refreshall)
131  gdt->refreshAll();
132  gdt->start();
133 
134  QObject::connect(gdt, &GrabberDownloadThread::finished, &treeloop, &QEventLoop::quit);
135  treeloop.exec();
136  }
137 
138  if ((refreshall || refreshrss) && !findAllDBRSS().empty())
139  {
140  QEventLoop rssloop;
141 
142  rssMan = new RSSManager();
143  rssMan->doUpdate();
144 
145  QObject::connect(rssMan, &RSSManager::finished, &rssloop, &QEventLoop::quit);
146  rssloop.exec();
147  }
148 
149  delete gdt;
150  delete rssMan;
151 
152  LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
153 
154  return GENERIC_EXIT_OK;
155 }
156 
157 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythFillNVCommandLineParser::LoadArguments
void LoadArguments(void) override
Definition: mythfillnetvision.cpp:41
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
RSSManager::doUpdate
void doUpdate()
Definition: rssmanager.cpp:44
MythCommandLineParser
Parent class for defining application command line parsers.
Definition: mythcommandlineparser.h:116
mythdb.h
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:63
RSSManager
Definition: rssmanager.h:111
MythContext
Startup context for MythTV.
Definition: mythcontext.h:19
MythCommandLineParser::addVersion
void addVersion(void)
Canned argument definition for –version.
Definition: mythcommandlineparser.cpp:2558
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythFillNVCommandLineParser
Definition: mythfillnetvision.cpp:30
remoteutil.h
close
#define close
Definition: compat.h:43
MythCommandLineParser::addLogging
void addLogging(const QString &defaultVerbosity="general", LogLevel_t defaultLogLevel=LOG_INFO)
Canned argument definition for all logging options, including –verbose, –logpath, –quiet,...
Definition: mythcommandlineparser.cpp:2662
mythpluginexport.h
quit
@ quit
Definition: lirc_client.h:30
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1558
MythCommandLineParser::add
CommandLineArg * add(const QString &arg, const QString &name, bool def, QString help, QString longhelp)
Definition: mythcommandlineparser.cpp:1776
MythFillNVCommandLineParser::MythFillNVCommandLineParser
MythFillNVCommandLineParser()
Definition: mythfillnetvision.cpp:37
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
mythlogging.h
rssmanager.h
netgrabbermanager.h
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
RSSManager::finished
void finished()
netutils.h
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1386
mythtranslation.h
gdt
GrabberDownloadThread * gdt
Definition: mythfillnetvision.cpp:27
rssMan
RSSManager * rssMan
Definition: mythfillnetvision.cpp:28
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1402
GrabberDownloadThread::refreshAll
void refreshAll()
Definition: netgrabbermanager.cpp:197
findAllDBRSS
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:610
mythmiscutil.h
main
int main(int argc, char *argv[])
Definition: mythfillnetvision.cpp:57
MythCommandLineParser::addHelp
void addHelp(void)
Canned argument definition for –help.
Definition: mythcommandlineparser.cpp:2545
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2203
MPLUGIN_PUBLIC
#define MPLUGIN_PUBLIC
Definition: mythpluginexport.h:9
mythcontext.h
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2876
myth_nice
bool myth_nice(int val)
Definition: mythmiscutil.cpp:656
MythCommandLineParser::LoadArguments
virtual void LoadArguments(void)
Definition: mythcommandlineparser.h:137
MythTranslation::load
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
Definition: mythtranslation.cpp:38
exitcodes.h
mythcommandlineparser.h
GrabberDownloadThread::finished
void finished()
GrabberDownloadThread
Definition: netgrabbermanager.h:115
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16