MythTV  master
mythplugins/mythnetvision/mythfillnetvision/main.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 // libmyth headers
12 #include <exitcodes.h>
13 #include <mythcontext.h>
14 #include <mythdb.h>
15 #include <mythversion.h>
16 #include <remoteutil.h>
17 #include <mythmiscutil.h>
18 #include <netutils.h>
19 #include <mythtranslation.h>
20 #include <mythconfig.h>
21 #include <netgrabbermanager.h>
22 #include <mythrssmanager.h>
23 #include <mythcommandlineparser.h>
24 #include <mythlogging.h>
25 
27 RSSManager *rssMan = nullptr;
28 
30 {
31  public:
33  void LoadArguments(void) override; // MythCommandLineParser
34 };
35 
37  MythCommandLineParser("mythfillnetvision")
39 
41 {
42  addHelp();
43  addVersion();
44  addLogging();
45 
46  add("--refresh-all", "refresh-all", false,
47  "Refresh ALL configured and installed tree grabbers", "");
48  add("--refresh-rss", "refresh-rss", false,
49  "Refresh RSS feeds only", "");
50  add("--refresh-tree", "refresh-tree", false,
51  "Refresh trees only", "");
52 }
53 
54 
55 
56 int main(int argc, char *argv[])
57 {
59  if (!cmdline.Parse(argc, argv))
60  {
63  }
64 
65  if (cmdline.toBool("showhelp"))
66  {
68  return GENERIC_EXIT_OK;
69  }
70 
71  if (cmdline.toBool("showversion"))
72  {
74  return GENERIC_EXIT_OK;
75  }
76 
77  QCoreApplication a(argc, argv);
78  QCoreApplication::setApplicationName("mythfillnetvision");
79 
80  int retval = GENERIC_EXIT_OK;
81  if ((retval = cmdline.ConfigureLogging()) != GENERIC_EXIT_OK)
82  return retval;
83 
85  // Don't listen to console input
86  close(0);
87 
89  if (!gContext->Init(false))
90  {
91  LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
92  delete gContext;
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  delete gContext;
152 
153  LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
154 
155  return GENERIC_EXIT_OK;
156 }
157 
158 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythFillNVCommandLineParser::LoadArguments
void LoadArguments(void) override
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:40
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:288
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
RSSManager::doUpdate
void doUpdate()
Definition: mythrssmanager.cpp:46
MythCommandLineParser
Parent class for defining application command line parsers.
Definition: mythcommandlineparser.h:116
mythdb.h
mythrssmanager.h
RSSManager
Definition: mythrssmanager.h:110
MythContext
Startup context for MythTV.
Definition: mythcontext.h:44
MythCommandLineParser::addVersion
void addVersion(void)
Canned argument definition for –version.
Definition: mythcommandlineparser.cpp:2288
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythFillNVCommandLineParser
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:30
GENERIC_EXIT_INVALID_CMDLINE
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
remoteutil.h
close
#define close
Definition: compat.h:17
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:2385
main
int main(int argc, char *argv[])
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:56
mythversion.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:1435
MythFillNVCommandLineParser::MythFillNVCommandLineParser
MythFillNVCommandLineParser()
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:36
mythlogging.h
netgrabbermanager.h
RSSManager::finished
void finished()
rssMan
RSSManager * rssMan
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:27
netutils.h
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1263
mythtranslation.h
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1279
GrabberDownloadThread::refreshAll
void refreshAll()
Definition: netgrabbermanager.cpp:212
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
findAllDBRSS
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:611
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythtv/programs/mythcommflag/main.cpp:76
gdt
GrabberDownloadThread * gdt
Definition: mythplugins/mythnetvision/mythfillnetvision/main.cpp:26
mythmiscutil.h
MythCommandLineParser::add
CommandLineArg * add(const QString &arg, const QString &name, bool def, QString help, QString longhelp)
Definition: mythcommandlineparser.h:145
MythCommandLineParser::addHelp
void addHelp(void)
Canned argument definition for –help.
Definition: mythcommandlineparser.cpp:2275
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:1941
mythcontext.h
GENERIC_EXIT_NO_MYTHCONTEXT
#define GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:13
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2585
myth_nice
bool myth_nice(int val)
Definition: mythmiscutil.cpp:702
MythCommandLineParser::LoadArguments
virtual void LoadArguments(void)
Definition: mythcommandlineparser.h:134
MythTranslation::load
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
Definition: mythtranslation.cpp:37
exitcodes.h
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:1564
GrabberDownloadThread::finished
void finished()
GrabberDownloadThread
Definition: netgrabbermanager.h:110