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.
22static 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
64static void runBookmarkManager()
65{
67}
68
74static 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
104static 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
120int 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
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}
bool UpgradeBrowserDatabaseSchema(void)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
QVariant value(int i) const
Definition: mythdbcon.h:204
int size(void) const
Definition: mythdbcon.h:214
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
Dialog asking for user confirmation.
void ActivateSettingsCache(bool activate=true)
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
static bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
MythScreenStack * GetMainStack()
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
int mythplugin_config(void)
static void runBookmarkManager()
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)
static void setupKeys(void)
int mythplugin_run(void)
int mythplugin_init(const char *libversion)
static void runHomepage()
Loads the specified homepage from the database (the name starts with an underscore) and calls handleM...
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static void REG_MEDIAPLAYER(const QString &Name, const QString &Desc, MediaPlayCallback Func)
static void REG_JUMP(const QString &Destination, const QString &Description, const QString &Key, void(*Callback)(void))
static void REG_KEY(const QString &Context, const QString &Action, const QString &Description, const QString &Key)
static MythSystemLegacyManager * manager