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