MythTV  master
mythplugins/mythbrowser/mythbrowser/main.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <unistd.h>
3 
4 // qt
5 #include <QApplication>
6 
7 // myth
8 #include <mythcontext.h>
9 #include <mythversion.h>
10 #include <mythscreenstack.h>
11 #include <mythmainwindow.h>
12 #include <mythpluginapi.h>
13 
14 // mythbrowser
15 #include "bookmarkmanager.h"
16 #include "browserdbutil.h"
17 #include "mythbrowser.h"
18 #include "mythflashplayer.h"
19 
20 // Based on MediaPlayCallback. Parameters only seem to have local significance.
21 static int handleMedia(const QString &url, const QString &directory, const QString &filename,
22  const QString & /*unused*/, const QString & /*unused*/, int /*unused*/,
23  int /*unused*/, const QString & /*unused*/, int /*unused*/,
24  const QString & /*unused*/, const QString & /*unused*/, bool /*unused*/)
25 {
26  if (url.isEmpty())
27  {
28  LOG(VB_GENERAL, LOG_ERR, "MythBrowser: handleMedia got empty url!");
29  return 1;
30  }
31 
32 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
33  QStringList urls = url.split(" ", QString::SkipEmptyParts);
34 #else
35  QStringList urls = url.split(" ", Qt::SkipEmptyParts);
36 #endif
37 
39 
40  if (urls[0].startsWith("mythflash://"))
41  {
42  auto *flashplayer = new MythFlashPlayer(mainStack, urls);
43  if (flashplayer->Create())
44  mainStack->AddScreen(flashplayer);
45  else
46  delete flashplayer;
47  }
48  else
49  {
50  auto *mythbrowser = new MythBrowser(mainStack, urls);
51 
52  if (!directory.isEmpty())
53  mythbrowser->setDefaultSaveDirectory(directory);
54 
55  if (!filename.isEmpty())
56  mythbrowser->setDefaultSaveFilename(filename);
57 
58  if (mythbrowser->Create())
59  mainStack->AddScreen(mythbrowser);
60  else
61  delete mythbrowser;
62  }
63 
64  return 0;
65 }
66 
67 static void runBookmarkManager()
68 {
70 }
71 
77 static void runHomepage()
78 {
79  // Get the homepage from the database. The url
80  // that is set as a homepage starts with a space.
82 
83  if (!query.exec("SELECT url FROM `websites` WHERE `homepage` = true;"))
84  LOG(VB_GENERAL, LOG_ERR, "Error loading homepage from DB");
85 
86  if (query.size() > 0)
87  {
88  query.next();
89  handleMedia( query.value(0).toString(), "", "", "", "", 0, 0, "", 0, "", "", false);
90  }
91  else
92  {
93  // show a dialog that no homepage is specified
94  QString message = "No homepage was specified.\n"
95  "If required you can do this in the bookmark manager";
96 
97  MythScreenStack *m_popupStack =
98  GetMythMainWindow()->GetStack("popup stack");
99 
100  auto *okPopup = new MythConfirmationDialog(m_popupStack, message, false);
101 
102  if (okPopup->Create())
103  m_popupStack->AddScreen(okPopup);
104  }
105 }
106 
107 static void setupKeys(void)
108 {
109  REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls",
110  "Move to next browser tab"), "P");
111  REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls",
112  "Move to previous browser tab"), "");
113 
114  REG_JUMP("Bookmarks", QT_TRANSLATE_NOOP("MythControls",
115  "Show the bookmark manager"), "", runBookmarkManager);
116  REG_JUMP("Homepage", QT_TRANSLATE_NOOP("MythControls",
117  "Show the webbrowser homepage"), "", runHomepage);
118 
119  REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls",
120  "Internal Web Browser"), handleMedia);
121 }
122 
123 int mythplugin_init(const char *libversion)
124 {
125  if (!MythCoreContext::TestPluginVersion("mythbrowser", libversion,
127  return -1;
128 
130 
132 
133  if (gCoreContext->GetSetting("WebBrowserCommand").isEmpty())
134  gCoreContext->SaveSetting("WebBrowserCommand", "Internal");
135 
136  if (gCoreContext->GetSetting("WebBrowserZoomLevel").isEmpty())
137  gCoreContext->SaveSetting("WebBrowserZoomLevel", "1.0");
138 
140 
141  setupKeys();
142 
143  return 0;
144 }
145 
146 int mythplugin_run(void)
147 {
149 
150  auto *manager = new BookmarkManager(mainStack, "bookmarkmanager");
151 
152  if (manager->Create())
153  {
154  mainStack->AddScreen(manager);
155  return 0;
156  }
157  delete manager;
158  return -1;
159 }
160 
162 {
164 
165  auto *config = new BrowserConfig(mainStack, "browserconfig");
166 
167  if (config->Create())
168  {
169  mainStack->AddScreen(config);
170  return 0;
171  }
172  delete config;
173  return -1;
174 }
manager
static MythSystemLegacyManager * manager
Definition: mythsystemunix.cpp:56
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:126
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:324
MythFlashPlayer
Definition: mythflashplayer.h:9
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:203
UpgradeBrowserDatabaseSchema
bool UpgradeBrowserDatabaseSchema(void)
Definition: browserdbutil.cpp:17
setupKeys
static void setupKeys(void)
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:107
mythscreenstack.h
REG_MEDIAPLAYER
#define REG_MEDIAPLAYER(a, b, c)
Definition: mythmainwindow.h:23
bookmarkmanager.h
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
MythScreenStack
Definition: mythscreenstack.h:16
runHomepage
static void runHomepage()
Loads the specified homepage from the database (the name starts with an underscore) and calls handleM...
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:77
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
runBookmarkManager
static void runBookmarkManager()
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:67
mythplugin_run
int mythplugin_run(void)
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:146
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2060
BrowserConfig
Definition: bookmarkmanager.h:34
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:329
mythversion.h
REG_KEY
#define REG_KEY(a, b, c, d)
Definition: mythmainwindow.h:18
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
browserdbutil.h
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
REG_JUMP
#define REG_JUMP(a, b, c, d)
Definition: mythmainwindow.h:20
mythplugin_config
int mythplugin_config(void)
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:161
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
mythflashplayer.h
mythpluginapi.h
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
MythBrowser
Definition: mythbrowser.h:18
MythConfirmationDialog
Dialog asking for user confirmation.
Definition: mythdialogbox.h:271
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:108
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:854
BookmarkManager
Definition: bookmarkmanager.h:63
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:902
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
query
MSqlQuery query(MSqlQuery::InitCon())
handleMedia
static int handleMedia(const QString &url, const QString &directory, const QString &filename, const QString &, const QString &, int, int, const QString &, int, const QString &, const QString &, bool)
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:21
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: mythplugins/mythbrowser/mythbrowser/main.cpp:123
mythbrowser.h
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919