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  QStringList urls = url.split(" ", Qt::SkipEmptyParts);
33 
35 
36  if (urls[0].startsWith("mythflash://"))
37  {
38  auto *flashplayer = new MythFlashPlayer(mainStack, urls);
39  if (flashplayer->Create())
40  mainStack->AddScreen(flashplayer);
41  else
42  delete flashplayer;
43  }
44  else
45  {
46  auto *mythbrowser = new MythBrowser(mainStack, urls);
47 
48  if (!directory.isEmpty())
49  mythbrowser->setDefaultSaveDirectory(directory);
50 
51  if (!filename.isEmpty())
52  mythbrowser->setDefaultSaveFilename(filename);
53 
54  if (mythbrowser->Create())
55  mainStack->AddScreen(mythbrowser);
56  else
57  delete mythbrowser;
58  }
59 
60  return 0;
61 }
62 
63 static void runBookmarkManager()
64 {
66 }
67 
73 static void runHomepage()
74 {
75  // Get the homepage from the database. The url
76  // that is set as a homepage starts with a space.
78 
79  if (!query.exec("SELECT url FROM `websites` WHERE `homepage` = true;"))
80  LOG(VB_GENERAL, LOG_ERR, "Error loading homepage from DB");
81 
82  if (query.size() > 0)
83  {
84  query.next();
85  handleMedia( query.value(0).toString(), "", "", "", "", 0, 0, "", 0min, "", "", false);
86  }
87  else
88  {
89  // show a dialog that no homepage is specified
90  QString message = "No homepage was specified.\n"
91  "If required you can do this in the bookmark manager";
92 
93  MythScreenStack *m_popupStack =
94  GetMythMainWindow()->GetStack("popup stack");
95 
96  auto *okPopup = new MythConfirmationDialog(m_popupStack, message, false);
97 
98  if (okPopup->Create())
99  m_popupStack->AddScreen(okPopup);
100  }
101 }
102 
103 static void setupKeys(void)
104 {
105  REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls",
106  "Move to next browser tab"), "P");
107  REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls",
108  "Move to previous browser tab"), "");
109 
110  REG_JUMP("Bookmarks", QT_TRANSLATE_NOOP("MythControls",
111  "Show the bookmark manager"), "", runBookmarkManager);
112  REG_JUMP("Homepage", QT_TRANSLATE_NOOP("MythControls",
113  "Show the webbrowser homepage"), "", runHomepage);
114 
115  REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls",
116  "Internal Web Browser"), handleMedia);
117 }
118 
119 int mythplugin_init(const char *libversion)
120 {
121  if (!MythCoreContext::TestPluginVersion("mythbrowser", libversion,
122  MYTH_BINARY_VERSION))
123  return -1;
124 
126 
128 
129  if (gCoreContext->GetSetting("WebBrowserCommand").isEmpty())
130  gCoreContext->SaveSetting("WebBrowserCommand", "Internal");
131 
132  if (gCoreContext->GetSetting("WebBrowserZoomLevel").isEmpty())
133  gCoreContext->SaveSetting("WebBrowserZoomLevel", "1.0");
134 
136 
137  setupKeys();
138 
139  return 0;
140 }
141 
142 int mythplugin_run(void)
143 {
145 
146  auto *manager = new BookmarkManager(mainStack, "bookmarkmanager");
147 
148  if (manager->Create())
149  {
150  mainStack->AddScreen(manager);
151  return 0;
152  }
153  delete manager;
154  return -1;
155 }
156 
158 {
160 
161  auto *config = new BrowserConfig(mainStack, "browserconfig");
162 
163  if (config->Create())
164  {
165  mainStack->AddScreen(config);
166  return 0;
167  }
168  delete config;
169  return -1;
170 }
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:813
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
MythFlashPlayer
Definition: mythflashplayer.h:8
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:214
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:63
mythscreenstack.h
setupKeys
static void setupKeys(void)
Definition: libmythbrowser.cpp:103
bookmarkmanager.h
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
MythScreenStack
Definition: mythscreenstack.h:16
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:619
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:2079
BrowserConfig
Definition: bookmarkmanager.h:31
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:551
browserdbutil.h
mythplugin_config
int mythplugin_config(void)
Definition: libmythbrowser.cpp:157
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
mythflashplayer.h
mythpluginapi.h
mythplugin_run
int mythplugin_run(void)
Definition: libmythbrowser.cpp:142
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: libmythbrowser.cpp:119
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:104
MythCoreContext::ActivateSettingsCache
void ActivateSettingsCache(bool activate=true)
Definition: mythcorecontext.cpp:833
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:323
BookmarkManager
Definition: bookmarkmanager.h:60
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:881
runHomepage
static void runHomepage()
Loads the specified homepage from the database (the name starts with an underscore) and calls handleM...
Definition: libmythbrowser.cpp:73
build_compdb.filename
filename
Definition: build_compdb.py:21
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
mythbrowser.h
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898