aboutsummaryrefslogtreecommitdiff
path: root/include/widgets/BrowserManager.hpp
blob: 8cf265dbbdc850d1d909591e81a03c43105bf469 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include <QStackedLayout>
#include <QWebEngineProfile>
#include <QWebEngineView>
#include <sys/types.h>

enum OpenType { OpenUrl, OpenUrlInTab, OpenUrlInBgTab, OpenUrlInWindow };

class BrowserManager : public QWidget {
  Q_OBJECT

public:
  inline static const QUrl NewtabURL = QUrl("about:blank");

public:
  BrowserManager(QWebEngineProfile *profile = new QWebEngineProfile);

  QUrl currentUrl();
  void setCurrentUrl(QUrl url);

  QWebEngineView *createNewWebView(QUrl url = BrowserManager::NewtabURL,
                                   bool focus = false);

  void openUrl(QUrl url = BrowserManager::NewtabURL,
               OpenType openType = OpenType::OpenUrl);

  std::vector<QUrl> webViewUrls();
  u_int32_t currentWebViewIndex();
  u_int32_t webViewCount();
  void focusWebView(long index);
  void nextWebView();
  void previousWebView();

  void closeWebView(long index);
  void closeCurrentWebView();

  void onNewWebViewRequest(QWebEngineNewWindowRequest &request);

private:
  QWebEngineProfile *profile;
  QStackedLayout *layout;
  QList<QWebEngineView *> webViewList;
};