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 <libmyth/mythcontext.h>
15#include <libmythbase/mythdb.h>
20#include <libmythbase/mythversion.h>
24
26RSSManager *rssMan = nullptr;
27
29{
30 public:
32 void LoadArguments(void) override; // MythCommandLineParser
33};
34
36 MythCommandLineParser("mythfillnetvision")
38
40{
41 addHelp();
42 addVersion();
43 addLogging();
44
45 add("--refresh-all", "refresh-all", false,
46 "Refresh ALL configured and installed tree grabbers", "");
47 add("--refresh-rss", "refresh-rss", false,
48 "Refresh RSS feeds only", "");
49 add("--refresh-tree", "refresh-tree", false,
50 "Refresh trees only", "");
51}
52
53
54
55int main(int argc, char *argv[])
56{
58 if (!cmdline.Parse(argc, argv))
59 {
62 }
63
64 if (cmdline.toBool("showhelp"))
65 {
67 return GENERIC_EXIT_OK;
68 }
69
70 if (cmdline.toBool("showversion"))
71 {
73 return GENERIC_EXIT_OK;
74 }
75
76 QCoreApplication a(argc, argv);
77 QCoreApplication::setApplicationName("mythfillnetvision");
78
79 int retval = cmdline.ConfigureLogging();
80 if (retval != GENERIC_EXIT_OK)
81 return retval;
82
84 // Don't listen to console input
85 close(0);
86
87 MythContext context {MYTH_BINARY_VERSION};
88 if (!context.Init(false))
89 {
90 LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
92 }
93
94 bool refreshall = cmdline.toBool("refresh-all");
95 bool refreshrss = cmdline.toBool("refresh-rss");
96 bool refreshtree = cmdline.toBool("refresh-tree");
97
98 if (refreshall && (refreshrss || refreshtree))
99 {
100 LOG(VB_GENERAL, LOG_ERR, "--refresh-all must not be accompanied by "
101 "--refresh-rss or --refresh-tree");
103 }
104
105 if (refreshrss && refreshtree)
106 {
107 LOG(VB_GENERAL, LOG_ERR, "--refresh-rss and --refresh-tree are "
108 "mutually exclusive options");
110 }
111
112 if (!refreshall && !refreshrss && !refreshtree)
113 {
114 // Default is to do rss & tree, but not all
115 refreshtree = true;
116 refreshrss = true;
117 }
118
119 myth_nice(19);
120
121 MythTranslation::load("mythfrontend");
122
123 if (refreshall || refreshtree)
124 {
125 QEventLoop treeloop;
126
127 gdt = new GrabberDownloadThread(nullptr);
128 if (refreshall)
129 gdt->refreshAll();
130 gdt->start();
131
132 QObject::connect(gdt, &GrabberDownloadThread::finished, &treeloop, &QEventLoop::quit);
133 treeloop.exec();
134 }
135
136 if ((refreshall || refreshrss) && !findAllDBRSS().empty())
137 {
138 QEventLoop rssloop;
139
140 rssMan = new RSSManager();
141 rssMan->doUpdate();
142
143 QObject::connect(rssMan, &RSSManager::finished, &rssloop, &QEventLoop::quit);
144 rssloop.exec();
145 }
146
147 delete gdt;
148 delete rssMan;
149
150 LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
151
152 return GENERIC_EXIT_OK;
153}
154
155/* 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:267
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:28
@ 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:34
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
MythCommFlagCommandLineParser cmdline
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:610