aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp14
-rw-r--r--src/mainwindow/mainwindow.cpp17
-rw-r--r--src/mainwindow/mainwindow.h5
-rw-r--r--src/mainwindow/window.cpp9
4 files changed, 33 insertions, 12 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 3f4805a..ddaf345 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -83,16 +83,20 @@ void Browser::createSession(const QString &profileName, bool newWindow, const QS
auto *mainwindow = m_windows.last();
if(newWindow) {
- QUrl firstUrl = WebProfile::defaultProfile()->homepage();
+ QString firstUrl;// = WebProfile::defaultProfile()->homepage();
if(!urls.isEmpty())
- firstUrl = QUrl::fromUserInput(urls.at(0));
+ firstUrl = urls.at(0);
auto *w = mainwindow->createSubWindow(firstUrl);
for(int i = 1; i < urls.count() - 1; i++) {
w->addTab(QUrl::fromUserInput(urls.at(i)));
}
} else {
- for(const QString &url : urls) {
- mainwindow->createTab(QUrl::fromUserInput(url));
+ if(urls.isEmpty())
+ mainwindow->createTab(WebProfile::defaultProfile()->homepage());
+ else {
+ for(const QString &url : urls) {
+ mainwindow->createTab(QUrl::fromUserInput(url));
+ }
}
}
}
@@ -102,7 +106,7 @@ MainWindow *Browser::createWindow()
// the window will delete itself when it closes, so we don't need to delete it
MainWindow *window = new MainWindow(m_config);
connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search);
- window->createSubWindow(WebProfile::defaultProfile()->newtab());
+ //window->createSubWindow(WebProfile::defaultProfile()->newtab());
auto *bookmarksAction = new QAction(tr("Bookmarks"), window);
bookmarksAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value<std::string>("bookmarks.shortcut").value())));
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 35cc598..f83c2a7 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -102,7 +102,7 @@ void MainWindow::createMenuBar()
auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName());
smolboteMenu->addAction(tr("New tab group"), this, [this]() {
- createSubWindow(QUrl::fromUserInput("about:blank"));
+ createSubWindow();
},
QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newGroup").value().c_str()));
smolboteMenu->addAction(tr("New window"))->setEnabled(false);
@@ -160,13 +160,18 @@ void MainWindow::createTab(const QUrl &url)
{
auto *w = qobject_cast<Window *>(mdiArea->currentSubWindow());
if(w == nullptr) {
- w = createSubWindow(url);
+ w = createSubWindow(url.toString());
} else {
w->addTab(url);
}
}
-Window *MainWindow::createSubWindow(const QUrl &url)
+Window *MainWindow::currentSubWindow() const
+{
+ return qobject_cast<Window *>(mdiArea->currentSubWindow());
+}
+
+Window *MainWindow::createSubWindow(const QString &url)
{
auto *w = new Window(m_config->section("window"), this);
mdiArea->addSubWindow(w);
@@ -176,11 +181,11 @@ Window *MainWindow::createSubWindow(const QUrl &url)
QJsonObject session;
session.insert("profile", "");
QJsonArray urls;
- urls.append(url.toString());
+ if(!url.isEmpty())
+ urls.append(url);
session.insert("tabs", urls);
- //w->addTab(url);
- //w->restoreSession(session);
+ w->restoreSession(session);
return w;
}
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index 489075f..2532189 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -11,6 +11,7 @@
#include <QMainWindow>
#include <memory>
+#include <QUrl>
class Browser;
class QMdiArea;
@@ -40,9 +41,11 @@ public:
void addAction(ActionLocation where, QAction *action);
void addDockWidget(Qt::DockWidgetArea area, QWidget *widget);
+ Window *currentSubWindow() const;
+
public slots:
void createTab(const QUrl &url);
- Window *createSubWindow(const QUrl &url);
+ Window *createSubWindow(const QString &url = QString());
void setView(WebView *view);
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp
index fb4eb07..055d945 100644
--- a/src/mainwindow/window.cpp
+++ b/src/mainwindow/window.cpp
@@ -152,6 +152,15 @@ void Window::restoreSession(const QJsonObject &sessionData)
Q_ASSERT_X(sessionData.value("tabs") != QJsonValue::Undefined, "Window::restoreSession", "no tabs in json");
const QJsonArray tabs = sessionData.value("tabs").toArray();
+
+ if(tabs.count() == 0) {
+ // open a newtab
+ auto *view = new WebView(profile, this);
+ view->load(profile->newtab());
+ tabWidget->addTab(view);
+ return;
+ }
+
for(const auto tab : tabs) {
auto *view = new WebView(profile, this);
view->load(QUrl::fromUserInput(tab.toString()));