MythTV  master
libmythbrowser.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <unistd.h>
3 
4 // qt
5 #include <QApplication>
6 
7 // MythTV
8 #include <libmyth/mythcontext.h>
10 #include <libmythbase/mythversion.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*/, std::chrono::minutes /*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, "", 0min, "", "", 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,
126  MYTH_BINARY_VERSION))
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:54
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:807
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:315
MythFlashPlayer
Definition: mythflashplayer.h:8
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:215
REG_KEY
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
Definition: mythmainwindow.h:175
UpgradeBrowserDatabaseSchema
bool UpgradeBrowserDatabaseSchema(void)
Definition: browserdbutil.cpp:17
runBookmarkManager
static void runBookmarkManager()
Definition: libmythbrowser.cpp:67
mythscreenstack.h
setupKeys
static void setupKeys(void)
Definition: libmythbrowser.cpp:107
bookmarkmanager.h
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:205
MythScreenStack
Definition: mythscreenstack.h:16
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:608
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythCoreContext::TestPluginVersion
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
Definition: mythcorecontext.cpp:2049
BrowserConfig
Definition: bookmarkmanager.h:31
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:540
browserdbutil.h
mythplugin_config
int mythplugin_config(void)
Definition: libmythbrowser.cpp:161
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
mythflashplayer.h
mythpluginapi.h
mythplugin_run
int mythplugin_run(void)
Definition: libmythbrowser.cpp:146
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: libmythbrowser.cpp:123
handleMedia
static int handleMedia(const QString &url, const QString &directory, const QString &filename, const QString &, const QString &, int, int, const QString &, std::chrono::minutes, const QString &, const QString &, bool)
Definition: libmythbrowser.cpp:21
MythBrowser
Definition: mythbrowser.h:18
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:272
REG_JUMP
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
Definition: mythmainwindow.h:188
mythcontext.h
REG_MEDIAPLAYER
static void REG_MEDIAPLAYER(const QString &Name, const QString &Desc, MediaPlayCallback Func)
Definition: mythmainwindow.h:209
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:831
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
BookmarkManager
Definition: bookmarkmanager.h:60
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:879
runHomepage
static void runHomepage()
Loads the specified homepage from the database (the name starts with an underscore) and calls handleM...
Definition: libmythbrowser.cpp:77
build_compdb.filename
filename
Definition: build_compdb.py:21
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:50
mythbrowser.h
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:896