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>
25
27RSSManager *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
56int 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 = cmdline.ConfigureLogging();
81 if (retval != GENERIC_EXIT_OK)
82 return retval;
83
85 // Don't listen to console input
86 close(0);
87
88 MythContext context {MYTH_BINARY_VERSION};
89 if (!context.Init(false))
90 {
91 LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
93 }
94
95 bool refreshall = cmdline.toBool("refresh-all");
96 bool refreshrss = cmdline.toBool("refresh-rss");
97 bool refreshtree = cmdline.toBool("refresh-tree");
98
99 if (refreshall && (refreshrss || refreshtree))
100 {
101 LOG(VB_GENERAL, LOG_ERR, "--refresh-all must not be accompanied by "
102 "--refresh-rss or --refresh-tree");
104 }
105
106 if (refreshrss && refreshtree)
107 {
108 LOG(VB_GENERAL, LOG_ERR, "--refresh-rss and --refresh-tree are "
109 "mutually exclusive options");
111 }
112
113 if (!refreshall && !refreshrss && !refreshtree)
114 {
115 // Default is to do rss & tree, but not all
116 refreshtree = true;
117 refreshrss = true;
118 }
119
120 myth_nice(19);
121
122 MythTranslation::load("mythfrontend");
123
124 if (refreshall || refreshtree)
125 {
126 QEventLoop treeloop;
127
128 gdt = new GrabberDownloadThread(nullptr);
129 if (refreshall)
130 gdt->refreshAll();
131 gdt->start();
132
133 QObject::connect(gdt, &GrabberDownloadThread::finished, &treeloop, &QEventLoop::quit);
134 treeloop.exec();
135 }
136
137 if ((refreshall || refreshrss) && !findAllDBRSS().empty())
138 {
139 QEventLoop rssloop;
140
141 rssMan = new RSSManager();
142 rssMan->doUpdate();
143
144 QObject::connect(rssMan, &RSSManager::finished, &rssloop, &QEventLoop::quit);
145 rssloop.exec();
146 }
147
148 delete gdt;
149 delete rssMan;
150
151 LOG(VB_GENERAL, LOG_INFO, "MythFillNetvision run complete.");
152
153 return GENERIC_EXIT_OK;
154}
155
156/* 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:30
@ 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
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