From c299a5e9c1ce2cd7af2eb02645993b21b9448f34 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 28 May 2018 11:42:09 +0200 Subject: Changing Window profile --- src/mainwindow/window.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/mainwindow/window.cpp') 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 #include #include +#include "browser.h" Window::Window(const QHash &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) @@ -31,15 +32,28 @@ Window::Window(const QHash &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(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 &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(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(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); -- cgit v1.2.1