aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/window.cpp35
-rw-r--r--src/mainwindow/window.h2
2 files changed, 32 insertions, 5 deletions
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp
index 47f8489..e3d5516 100644
--- a/src/mainwindow/window.cpp
+++ b/src/mainwindow/window.cpp
@@ -18,6 +18,7 @@
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
+#include "browser.h"
Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags)
: QMdiSubWindow(parent, flags)
@@ -31,15 +32,28 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo
profile = WebProfile::defaultProfile();
-#ifdef QT_DEBUG
{
auto *menu = systemMenu();
-
menu->addSeparator();
- menu->addAction(tr("Debug menu"))->setEnabled(false);
- menu->addAction(tr("Profile: %1").arg(profile->isOffTheRecord() ? tr("off-the-record") : profile->storageName()))->setEnabled(false);
+ auto *profileName_action = menu->addAction(tr("Profile: %1").arg(profile->isOffTheRecord() ? tr("off-the-record") : profile->storageName()));
+ profileName_action->setEnabled(false);
+ auto *loadProfile_menu = menu->addMenu(tr("Load profile"));
+
+ Browser *instance = qobject_cast<Browser*>(qApp);
+ Q_ASSERT_X(instance != nullptr, "Window::Window", "Could not cast instance");
+ for(const QString &name : instance->profiles()) {
+ auto *loadAction = loadProfile_menu->addAction(name);
+ connect(loadAction, &QAction::triggered, this, [name, instance, profileName_action, this]() {
+ auto *profile = instance->profile(name);
+ this->setProfile(profile);
+ profileName_action->setText(tr("Profile: %1").arg(name));
+ });
+ }
+
+#ifdef QT_DEBUG
menu->addSeparator();
+ menu->addAction(tr("Debug menu"))->setEnabled(false);
auto *saveSession_action = menu->addAction(tr("Save session"));
menu->addAction(tr("Load session"))->setEnabled(false);
setSystemMenu(menu);
@@ -48,8 +62,8 @@ Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::Windo
QJsonDocument doc(session());
qDebug("%s", qUtf8Printable(doc.toJson()));
});
- }
#endif
+ }
// new tab button
auto *newTab_button = new QToolButton(this);
@@ -117,6 +131,17 @@ WebView *Window::view(int index) const
return qobject_cast<WebView *>(tabWidget->widget(index));
}
+void Window::setProfile(WebProfile *profile)
+{
+ Q_ASSERT_X(profile != nullptr, "Window::setProfile", "Tried to set null profile");
+ for(int i = 0; i < tabWidget->count(); ++i) {
+ auto *view = qobject_cast<WebView *>(tabWidget->widget(i));
+ const auto url = view->url();
+ view->setPage(new WebPage(profile, view));
+ view->load(url);
+ }
+}
+
int Window::addTab(const QUrl &url)
{
auto *view = new WebView(profile, this);
diff --git a/src/mainwindow/window.h b/src/mainwindow/window.h
index a569214..6431466 100644
--- a/src/mainwindow/window.h
+++ b/src/mainwindow/window.h
@@ -27,6 +27,8 @@ public:
WebView *currentView();
WebView *view(int index) const;
+ void setProfile(WebProfile *profile);
+
QJsonObject session() const;
void restoreSession(const QJsonObject &sessionData);