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
11 #include <libmythbase/mythversion.h>
14 
15 // mythbrowser
16 #include "bookmarkmanager.h"
17 #include "browserdbutil.h"
18 #include "mythbrowser.h"
19 #include "mythflashplayer.h"
20 
21 // Based on MediaPlayCallback. Parameters only seem to have local significance.
22 static int handleMedia(const QString &url, const QString &directory, const QString &filename,
23  const QString & /*unused*/, const QString & /*unused*/, int /*unused*/,
24  int /*unused*/, const QString & /*unused*/, std::chrono::minutes /*unused*/,
25  const QString & /*unused*/, const QString & /*unused*/, bool /*unused*/)
26 {
27  if (url.isEmpty())
28  {
29  LOG(VB_GENERAL, LOG_ERR, "MythBrowser: handleMedia got empty url!");
30  return 1;
31  }
32 
33  QStringList urls = url.split(" ", Qt::SkipEmptyParts);
34 
36 
37  if (urls[0].startsWith("mythflash://"))
38  {
39  auto *flashplayer = new MythFlashPlayer(mainStack, urls);
40  if (flashplayer->Create())
41  mainStack->AddScreen(flashplayer);
42  else
43  delete flashplayer;
44  }
45  else
46  {
47  auto *mythbrowser = new MythBrowser(mainStack, urls);
48 
49  if (!directory.isEmpty())
50  mythbrowser->setDefaultSaveDirectory(directory);
51 
52  if (!filename.isEmpty())
53  mythbrowser->setDefaultSaveFilename(filename);
54 
55  if (mythbrowser->Create())
56  mainStack->AddScreen(mythbrowser);
57  else
58  delete mythbrowser;
59  }
60 
61  return 0;
62 }
63 
64 static void runBookmarkManager()
65 {
67 }
68 
74 static void runHomepage()
75 {
76  // Get the homepage from the database. The url
77  // that is set as a homepage starts with a space.
79 
80  if (!query.exec("SELECT url FROM `websites` WHERE `homepage` = true;"))
81  LOG(VB_GENERAL, LOG_ERR, "Error loading homepage from DB");
82 
83  if (query.size() > 0)
84  {
85  query.next();
86  handleMedia( query.value(0).toString(), "", "", "", "", 0, 0, "", 0min, "", "", false);
87  }
88  else
89  {
90  // show a dialog that no homepage is specified
91  QString message = "No homepage was specified.\n"
92  "If required you can do this in the bookmark manager";
93 
94  MythScreenStack *m_popupStack =
95  GetMythMainWindow()->GetStack("popup stack");
96 
97  auto *okPopup = new MythConfirmationDialog(m_popupStack, message, false);
98 
99  if (okPopup->Create())
100  m_popupStack->AddScreen(okPopup);
101  }
102 }
103 
104 static void setupKeys(void)
105 {
106  REG_KEY("Browser", "NEXTTAB", QT_TRANSLATE_NOOP("MythControls",
107  "Move to next browser tab"), "P,Media Play");
108  REG_KEY("Browser", "PREVTAB", QT_TRANSLATE_NOOP("MythControls",
109  "Move to previous browser tab"), "");
110 
111  REG_JUMP("Bookmarks", QT_TRANSLATE_NOOP("MythControls",
112  "Show the bookmark manager"), "", runBookmarkManager);
113  REG_JUMP("Homepage", QT_TRANSLATE_NOOP("MythControls",
114  "Show the webbrowser homepage"), "", runHomepage);
115 
116  REG_MEDIAPLAYER("WebBrowser", QT_TRANSLATE_NOOP("MythControls",
117  "Internal Web Browser"), handleMedia);
118 }
119 
120 int mythplugin_init(const char *libversion)
121 {
122  if (!MythCoreContext::TestPluginVersion("mythbrowser", libversion,
123  MYTH_BINARY_VERSION))
124  return -1;
125 
127 
129 
130  if (gCoreContext->GetSetting("WebBrowserCommand").isEmpty())
131  gCoreContext->SaveSetting("WebBrowserCommand", "Internal");
132 
133  if (gCoreContext->GetSetting("WebBrowserZoomLevel").isEmpty())
134  gCoreContext->SaveSetting("WebBrowserZoomLevel", "1.0");
135 
137 
138  setupKeys();
139 
140  return 0;
141 }
142 
143 int mythplugin_run(void)
144 {
146 
147  auto *manager = new BookmarkManager(mainStack, "bookmarkmanager");
148 
149  if (manager->Create())
150  {
151  mainStack->AddScreen(manager);
152  return 0;
153  }
154  delete manager;
155  return -1;
156 }
157 
159 {
161 
162  auto *config = new BrowserConfig(mainStack, "browserconfig");
163 
164  if (config->Create())
165  {
166  mainStack->AddScreen(config);
167  return 0;
168  }
169  delete config;
170  return -1;
171 }
manager
static MythSystemLegacyManager * manager
Definition: mythsystemunix.cpp:53
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:317
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:18
runBookmarkManager
static void runBookmarkManager()
Definition: libmythbrowser.cpp:64
mythscreenstack.h
setupKeys
static void setupKeys(void)
Definition: libmythbrowser.cpp:104
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:618
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:2089
BrowserConfig
Definition: bookmarkmanager.h:31
mythlogging.h
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
browserdbutil.h
mythplugin_config
int mythplugin_config(void)
Definition: libmythbrowser.cpp:158
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
mythflashplayer.h
mythpluginapi.h
mythplugin_run
int mythplugin_run(void)
Definition: libmythbrowser.cpp:143
mythplugin_init
int mythplugin_init(const char *libversion)
Definition: libmythbrowser.cpp:120
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:22
MythBrowser
Definition: mythbrowser.h:18
MythConfirmationDialog
Dialog asking for user confirmation. Ok and optional Cancel button.
Definition: mythdialogbox.h:271
mythcorecontext.h
REG_JUMP
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
Definition: mythmainwindow.h:188
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:839
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
BookmarkManager
Definition: bookmarkmanager.h:60
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:887
runHomepage
static void runHomepage()
Loads the specified homepage from the database (the name starts with an underscore) and calls handleM...
Definition: libmythbrowser.cpp:74
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:904