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 using namespace std;
7 
8 // Qt headers
9 #include <QCoreApplication>
10 #include <QEventLoop>
11 
12 // libmyth headers
13 #include <exitcodes.h>
14 #include <mythcontext.h>
15 #include <mythdb.h>
16 #include <mythversion.h>
17 #include <remoteutil.h>
18 #include <mythmiscutil.h>
19 #include <netutils.h>
20 #include <mythtranslation.h>
21 #include <mythconfig.h>
22 #include <netgrabbermanager.h>
23 #include <mythrssmanager.h>
24 #include <mythcommandlineparser.h>
25 #include <mythlogging.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 
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, SIGNAL(finished(void)), &treeloop, SLOT(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, SIGNAL(finished(void)), &rssloop, SLOT(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: */
void start(QThread::Priority=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:294
Startup context for MythTV.
Definition: mythcontext.h:42
CommandLineArg * add(QString arg, QString name, bool def, QString help, QString longhelp)
RSSSite::rssList findAllDBRSS()
Definition: netutils.cpp:607
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
#define MPUBLIC
Definition: mythexp.h:10
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Parent class for defining application command line parsers.
void addVersion(void)
Canned argument definition for –version.
void addLogging(const QString &defaultVerbosity="general", LogLevel_t defaultLogLevel=LOG_INFO)
Canned argument definition for all logging options, including –verbose, –logpath, –quiet,...
void addHelp(void)
Canned argument definition for –help.
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:63
#define close
Definition: compat.h:16
int main(int argc, char *argv[])
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
MythCommFlagCommandLineParser cmdline
GrabberDownloadThread * gdt
bool myth_nice(int val)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
bool Init(const bool gui=true, const bool promptForBackend=false, const bool disableAutoDiscovery=false, const bool ignoreDB=false)
#define GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
Definition: exitcodes.h:13
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
int ConfigureLogging(const QString &mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.