aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp56
1 files changed, 26 insertions, 30 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 15a7029..c0289a6 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -43,10 +43,6 @@ Browser::~Browser()
qDeleteAll(m_windows);
m_windows.clear();
- if(m_networkAccessManager) {
- delete m_networkAccessManager;
- }
-
if(m_bookmarksManager) {
delete m_bookmarksManager;
}
@@ -112,10 +108,7 @@ void Browser::loadProfiles()
//qDebug("Creating new window for [%s]", qUtf8Printable(params["urls"].toString()));
- MainWindow *w = addWindow(params["urls"].toStringList());
- if(params.contains("profile")) {
- w->setProfile(profile(params["profile"].toString()));
- }
+ createWindow(params);
});
}
@@ -126,15 +119,8 @@ Browser *Browser::instance()
Settings *Browser::settings()
{
- return m_settings;
-}
-
-QNetworkAccessManager *Browser::network()
-{
- if(!m_networkAccessManager) {
- m_networkAccessManager = new QNetworkAccessManager();
- }
- return m_networkAccessManager;
+ Q_ASSERT(m_settings);
+ return m_settings.get();
}
BookmarksWidget *Browser::bookmarks()
@@ -194,7 +180,7 @@ void Browser::loadSettings(const QString &path)
defaultsLocation = ":/poi.toml";
}
- m_settings = new Settings(configLocation, defaultsLocation);
+ m_settings = std::unique_ptr<Settings>(new Settings(configLocation, defaultsLocation));
#ifdef QT_DEBUG
if(m_settings->isEmpty()) {
@@ -210,7 +196,7 @@ void Browser::loadSettings(const QString &path)
MainWindow *Browser::activeWindow()
{
if(m_windows.empty()) {
- addWindow(new MainWindow());
+ return nullptr;
}
for(auto it = m_windows.cbegin(); it != m_windows.cend(); it++) {
@@ -221,22 +207,32 @@ MainWindow *Browser::activeWindow()
return m_windows.first().data();
}
-void Browser::addWindow(MainWindow *window)
+MainWindow *Browser::createWindow(const QHash<QString, QVariant> options)
{
- Q_ASSERT(window != nullptr);
+ Q_ASSERT(options.contains("urls"));
+
+ MainWindow *w = new MainWindow();
- m_windows.append(QPointer<MainWindow>(window));
- connect(window, &QObject::destroyed, this, [&]() {
- this->clean();
+ m_windows.append(QPointer<MainWindow>(w));
+ connect(w, &MainWindow::destroyed, this, [&]() {
+ clean();
});
- window->show();
-}
+ QString profileName;
+ if(options.contains("profile")) {
+ profileName = options.value("profile").toString();
+ }
+ const QStringList urls = options.value("urls").toStringList();
+ if(urls.isEmpty()) {
+ w->newTab(profile(profileName)->homepage());
+ } else {
+ for(const QString url : urls) {
+ w->newTab(QUrl::fromUserInput(url));
+ }
+ }
+
+ w->show();
-MainWindow *Browser::addWindow(const QStringList params)
-{
- MainWindow *w = new MainWindow(params);
- addWindow(w);
return w;
}