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>
16#include <libmythbase/mythdb.h>
21#include <libmythbase/mythversion.h>
26
28RSSManager *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
57int 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: */
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
Parent class for defining application command line parsers.
void addVersion(void)
Canned argument definition for –version.
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
void addLogging(const QString &defaultVerbosity="general", LogLevel_t defaultLogLevel=LOG_INFO)
Canned argument definition for all logging options, including –verbose, –logpath, –quiet,...
static void PrintVersion(void)
Print application version information.
CommandLineArg * add(const QString &arg, const QString &name, bool def, QString help, QString longhelp)
void addHelp(void)
Canned argument definition for –help.
virtual void LoadArguments(void)
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
Definition: mythcontext.h:20
void LoadArguments(void) override
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
void doUpdate()
Definition: rssmanager.cpp:44
void finished()
#define close
Definition: compat.h:39
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:16
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
@ quit
Definition: lirc_client.h:30
MythCommFlagCommandLineParser cmdline
int main(int argc, char *argv[])
GrabberDownloadThread * gdt
RSSManager * rssMan
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
bool myth_nice(int val)
#define MPLUGIN_PUBLIC
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:610