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 = GENERIC_EXIT_OK;
82  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
83  return retval;
84 
86  // Don't listen to console input
87  close(0);
88 
89  gContext = new MythContext(MYTH_BINARY_VERSION);
90  if (!gContext->Init(false))
91  {
92  LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
93  delete gContext;
95  }
96 
97  bool refreshall = cmdline.toBool("refresh-all");
98  bool refreshrss = cmdline.toBool("refresh-rss");
99  bool refreshtree = cmdline.toBool("refresh-tree");
100 
101  if (refreshall && (refreshrss || refreshtree))
102  {
103  LOG(VB_GENERAL, LOG_ERR, "--refresh-all must not be accompanied by "
104  "--refresh-rss or --refresh-tree");
106  }
107 
108  if (refreshrss && refreshtree)
109  {
110  LOG(VB_GENERAL, LOG_ERR, "--refresh-rss and --refresh-tree are "
111  "mutually exclusive options");
113  }
114 
115  if (!refreshall && !refreshrss && !refreshtree)
116  {
117  // Default is to do rss & tree, but not all
118  refreshtree = true;
119  refreshrss = true;
120  }
121 
122  myth_nice(19);
123 
124  MythTranslation::load("mythfrontend");
125 
126  if (refreshall || refreshtree)
127  {
128  QEventLoop treeloop;
129 
130  gdt = new GrabberDownloadThread(nullptr);
131  if (refreshall)
132  gdt->refreshAll();
133  gdt->start();
134 
135  QObject::connect(gdt, &GrabberDownloadThread::finished, &treeloop, &QEventLoop::quit);
136  treeloop.exec();
137  }
138 
139  if ((refreshall || refreshrss) && !findAllDBRSS().empty())
140  {
141  QEventLoop rssloop;
142 
143  rssMan = new RSSManager();
144  rssMan->doUpdate();
145 
146  QObject::connect(rssMan, &RSSManager::finished, &rssloop, &QEventLoop::quit);
147  rssloop.exec();
148  }
149 
150  delete gdt;
151  delete rssMan;
152  delete gContext;
153 
154  LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
155 
156  return GENERIC_EXIT_OK;
157 }
158 
159 /* 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:45
MythCommandLineParser
Parent class for defining application command line parsers.
Definition: mythcommandlineparser.h:116
mythdb.h
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
RSSManager
Definition: rssmanager.h:111
MythContext
Startup context for MythTV.
Definition: mythcontext.h:43
MythCommandLineParser::addVersion
void addVersion(void)
Canned argument definition for –version.
Definition: mythcommandlineparser.cpp:2534
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythFillNVCommandLineParser
Definition: mythfillnetvision.cpp:30
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
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:2638
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:1544
MythCommandLineParser::add
CommandLineArg * add(const QString &arg, const QString &name, bool def, QString help, QString longhelp)
Definition: mythcommandlineparser.cpp:1760
MythFillNVCommandLineParser::MythFillNVCommandLineParser
MythFillNVCommandLineParser()
Definition: mythfillnetvision.cpp:37
mythlogging.h
GENERIC_EXIT_NO_MYTHCONTEXT
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:14
rssmanager.h
netgrabbermanager.h
RSSManager::finished
void finished()
netutils.h
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1372
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:1388
GrabberDownloadThread::refreshAll
void refreshAll()
Definition: netgrabbermanager.cpp:193
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:2521
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2187
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:2849
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:37
exitcodes.h
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:16
mythcommandlineparser.h
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
MythContext::Init
bool Init(bool gui=true, bool promptForBackend=false, bool disableAutoDiscovery=false, bool ignoreDB=false)
Definition: mythcontext.cpp:1603
GrabberDownloadThread::finished
void finished()
GrabberDownloadThread
Definition: netgrabbermanager.h:115