aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
blob: e6be694cf68fbeaf3cc00511649322afd70c3657 (plain)
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
45
46
47
#include "browser.h"
#include "mainwindow.h"
#include "settings.h"
#include <QtWebEngine>

Browser::Browser(QString configPath, QObject *parent) : QObject(parent)
{
    if(configPath.isEmpty()) {
        // set default config path
        Settings::setFilepath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini");
    } else {
        // set custom config path
        Settings::setFilepath(configPath);
    }

    // TODO Restore previous session

    QtWebEngine::initialize();
}

Browser::~Browser()
{
    // TODO Save session

    // cleanup
    qDeleteAll(m_windows);
    m_windows.clear();
}

void Browser::addWindow(MainWindow *window)
{
    if(m_windows.contains(window)) {
        return;
    }

    m_windows.append(window);
    connect(window, &QObject::destroyed, [this, window]() {
        this->removeWindow(window);
    });

    window->show();
}

void Browser::removeWindow(MainWindow *window)
{
    m_windows.removeOne(window);
}