diff options
-rw-r--r-- | lib/configuration/configuration.cpp | 3 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/browser.cpp | 37 | ||||
-rw-r--r-- | src/browser.h | 8 | ||||
-rw-r--r-- | src/main.cpp | 45 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 164 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 16 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.ui | 118 | ||||
-rw-r--r-- | src/mainwindow/subwindow.cpp | 11 | ||||
-rw-r--r-- | src/mainwindow/subwindow.h | 3 |
10 files changed, 250 insertions, 156 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp index 766dfaf..648eec8 100644 --- a/lib/configuration/configuration.cpp +++ b/lib/configuration/configuration.cpp @@ -50,7 +50,6 @@ Configuration::Configuration(QObject *parent) ("config,c", po::value<std::string>()->default_value(defaultUserConfigLocation()), "Set the configuration file.") ("socket,s", po::value<std::string>()->default_value(defaultSocketPath()), "Local server socket") - ("session", po::value<std::string>(), "Load session data from the specified path.") ("args", po::value<std::vector<std::string>>(), "arguments") ; @@ -59,7 +58,7 @@ Configuration::Configuration(QObject *parent) configuration_desc.add_options() ("browser.stylesheet", po::value<std::string>()) - ("browser.session", po::value<std::string>()) + ("browser.session", po::value<std::string>(), "Load session data from the specified path.") ("browser.locale", po::value<std::string>()) ("browser.translation", po::value<std::string>()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bb8f229..8778b18 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable(poi # main window mainwindow/mainwindow.cpp mainwindow/mainwindow.h + mainwindow/mainwindow.ui mainwindow/subwindow.cpp mainwindow/subwindow.h mainwindow/widgets/dockwidget.cpp diff --git a/src/browser.cpp b/src/browser.cpp index b793bb1..6ffcaaa 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -52,14 +52,16 @@ void Browser::about() dlg->exec(); } -void Browser::setConfiguration(std::shared_ptr<Configuration> &config) +void Browser::setConfiguration(std::unique_ptr<Configuration> &config) { Q_ASSERT(config); - m_config = config; + m_config = std::move(config); } void Browser::registerPlugin(const Plugin &plugin) { + Q_ASSERT(m_config); + if(plugin.instance->inherits("ProfileInterface")) { auto *profileEditor = qobject_cast<ProfileInterface *>(plugin.instance); Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); @@ -88,6 +90,21 @@ void Browser::setup(const QString &defaultProfile) { Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); + auto stylesheet = m_config->value<QString>("browser.stylesheet"); + if(stylesheet) { + QFile f(stylesheet.value()); + if(f.open(QIODevice::ReadOnly)) { + setStyleSheet(f.readAll()); + f.close(); + } + } + + // downloads + m_downloads = std::make_unique<DownloadsWidget>(m_config->value<QString>("downloads.path").value()); + // url request filter + m_urlFilter = std::make_unique<UrlRequestInterceptor>(m_config->value<QString>("filter.path").value()); + // cookie request filter + // load profiles { const auto defaults = m_config->section("profile"); @@ -98,6 +115,8 @@ void Browser::setup(const QString &defaultProfile) for(const QFileInfo &f : entries) { auto *profile = ProfileManager::loadProfile(f.absoluteFilePath(), defaults); + connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); + profile->setRequestInterceptor(m_urlFilter.get()); emit registerProfile(profile); } } @@ -106,26 +125,18 @@ void Browser::setup(const QString &defaultProfile) if(ProfileManager::profile(defaultProfile) == nullptr) { // if this profile has not been added, it doesn't have a path auto *profile = ProfileManager::loadProfile(QString(), defaults); + connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); + profile->setRequestInterceptor(m_urlFilter.get()); emit registerProfile(profile); } WebProfile::setDefaultProfile(ProfileManager::profile(defaultProfile)); } - // url request filter - m_urlFilter = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value())); - WebProfile::defaultProfile()->setRequestInterceptor(m_urlFilter.get()); - - // cookie request filter - // bookmarks m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value())); connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { m_windows.last()->createTab(url); }); - - // downloads - m_downloads = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); - connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); } void Browser::createSession(const QJsonObject &object) @@ -152,7 +163,7 @@ void Browser::createSession(const QJsonObject &object) } } if(window == nullptr) - window = mainwindow->createSubWindow(profile); + window = mainwindow->createSubWindow(m_config, profile); const QJsonArray tabs = subwindow.value("tabs").toArray(); if(tabs.isEmpty()) diff --git a/src/browser.h b/src/browser.h index 0fda721..3405e85 100644 --- a/src/browser.h +++ b/src/browser.h @@ -36,7 +36,7 @@ public slots: void about(); public: - void setConfiguration(std::shared_ptr<Configuration> &config); + void setConfiguration(std::unique_ptr<Configuration> &config); void registerPlugin(const Plugin &plugin); void setup(const QString &defaultProfile); @@ -56,10 +56,10 @@ public slots: private: Q_DISABLE_COPY(Browser) - std::shared_ptr<Configuration> m_config; + std::unique_ptr<Configuration> m_config; std::shared_ptr<BookmarksWidget> m_bookmarks; - std::shared_ptr<DownloadsWidget> m_downloads; - std::shared_ptr<UrlRequestInterceptor> m_urlFilter; + std::unique_ptr<DownloadsWidget> m_downloads; + std::unique_ptr<UrlRequestInterceptor> m_urlFilter; QVector<MainWindow *> m_windows; QVector<Plugin> m_plugins; diff --git a/src/main.cpp b/src/main.cpp index 85bf5f0..00a57d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ int main(int argc, char **argv) { // create and load configuration - std::shared_ptr<Configuration> config = std::make_shared<Configuration>(); + std::unique_ptr<Configuration> config = std::make_unique<Configuration>(nullptr); #ifdef QT_DEBUG QObject::connect(config.get(), &Configuration::settingChanged, [](const std::string &path, const QString &value) { qDebug("!!! setting changed %s=[%s]", path.c_str(), qUtf8Printable(value)); @@ -83,7 +83,6 @@ int main(int argc, char **argv) Browser app(argc, argv); // set this, otherwise the webview becomes black when using a stylesheet app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); - app.setConfiguration(config); // translator if(config->exists("browser.locale")) { @@ -102,15 +101,21 @@ int main(int argc, char **argv) delete translator; } + // command line arguments + auto arguments = config->value<std::vector<std::string>>("args"); + + auto socket = config->value<QString>("socket"); + auto session = config->value<QString>("browser.session"); + auto profile = config->value<QString>("profile.default"); + + app.setConfiguration(config); + app.setup(profile.value()); - app.setup(QString::fromStdString(config->value<std::string>("profile.default").value())); for(const Plugin &plugin : plugins) { app.registerPlugin(plugin); } - auto arguments = config->value<std::vector<std::string>>("args"); QStringList urls; - if(arguments) { for(const auto &u : arguments.value()) { if(pluginCommands.contains(QString::fromStdString(u))) { @@ -122,43 +127,25 @@ int main(int argc, char **argv) } // set up socket - bool isSingleInstance = app.bindLocalSocket(QString::fromStdString(config->value<std::string>("socket").value())); + bool isSingleInstance = app.bindLocalSocket(socket.value()); + if(isSingleInstance) { #ifdef QT_DEBUG - qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(QString::fromStdString(config->value<std::string>("socket").value())), isSingleInstance ? "true" : "false"); + qDebug("Local socket bound"); #endif - // if we are the only instance, set up the browser - if(isSingleInstance) { - auto stylesheet = config->value<std::string>("browser.stylesheet"); - if(stylesheet) { - QFile f(QString::fromStdString(stylesheet.value())); - if(f.open(QIODevice::ReadOnly)) { - app.setStyleSheet(f.readAll()); - f.close(); - } - } - QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession); } - if(config->exists("session")) { - QFile sessionJson(config->value<QString>("session").value()); + if(session) { + QFile sessionJson(session.value()); if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { app.sendMessage(sessionJson.readAll()); sessionJson.close(); } else { qWarning("Could not open session [%s].", qUtf8Printable(sessionJson.fileName())); } - } else if(config->exists("browser.session")) { - QFile sessionJson(config->value<QString>("browser.session").value()); - if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) { - app.sendMessage(sessionJson.readAll()); - sessionJson.close(); - } else { - qWarning("Could not open browser.session [%s].", qUtf8Printable(sessionJson.fileName())); - } } else - app.sendMessage(Session::toJsonObject(config->value<QString>("profile.default").value(), urls)); + app.sendMessage(Session::toJsonObject(profile.value(), urls)); if(isSingleInstance) return app.exec(); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 7adc9db..741b544 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -7,6 +7,7 @@ */ #include "mainwindow.h" +#include "ui_mainwindow.h" #include "addressbar/addressbar.h" #include "browser.h" #include "subwindow.h" @@ -36,12 +37,14 @@ #include <KWindowEffects> #endif -MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) +MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *parent) : QMainWindow(parent) + , ui(new Ui::MainWindow) , mdiArea(new QMdiArea(this)) { Q_ASSERT(config); - m_config = config; + + ui->setupUi(this); #ifdef PLASMA_BLUR setAttribute(Qt::WA_TranslucentBackground, true); @@ -49,14 +52,69 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) #endif // create UI - setWindowTitle(QString::fromStdString(config->value<std::string>("mainwindow.title").value())); + setWindowTitle(config->value<QString>("mainwindow.title").value()); resize(config->value<int>("mainwindow.width").value(), config->value<int>("mainwindow.height").value()); if(config->value<bool>("mainwindow.maximized").value()) { setWindowState(Qt::WindowMaximized); } show(); - createMenuBar(); + // connect smolbote menu + { + connect(ui->actionNewSubwindow, &QAction::triggered, this, [this, &config]() { + auto *profile = WebProfile::defaultProfile(); + auto *window = createSubWindow(config, profile); + window->addTab(profile->newtab(), profile); + }); + config->setShortcut(ui->actionNewSubwindow, "mainwindow.shortcuts.newGroup"); + + connect(ui->actionNewWindow, &QAction::triggered, this, []() { + auto *browser = qobject_cast<Browser *>(qApp); + if(browser) + browser->createWindow(); + }); + config->setShortcut(ui->actionNewWindow, "mainwindow.shortcuts.newWindow"); + + connect(ui->actionAbout, &QAction::triggered, qobject_cast<Browser *>(qApp), &Browser::about); + config->setShortcut(ui->actionAbout, "mainwindow.shortcuts.about"); + + connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt); + + connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit); + config->setShortcut(ui->actionQuit, "mainwindow.shortcuts.quit"); + } + + // connect session menu + { + connect(ui->actionSaveSession, &QAction::triggered, this, [this]() { + const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), QDir::homePath(), tr("JSON (*.json)")); + QFile output(filename); + if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { + output.write(QJsonDocument(Session::toJsonObject(this)).toJson()); + output.close(); + } + }); + connect(ui->actionLoadSession, &QAction::triggered, this, [this]() { + const QString filename = QFileDialog::getOpenFileName(this, tr("Load Session"), QDir::homePath(), tr("JSON (*.json)")); + QFile json(filename); + if(json.open(QIODevice::ReadOnly | QIODevice::Text)) { + auto *browser = qobject_cast<Browser *>(qApp); + browser->sendMessage(json.readAll()); + json.close(); + } + }); + } + + // connect window menu + { + connect(ui->actionTileWindows, &QAction::triggered, mdiArea, &QMdiArea::tileSubWindows); + config->setShortcut(ui->actionTileWindows, "mainwindow.shortcuts.tileWindows"); + + connect(ui->actionCascadeWindows, &QAction::triggered, mdiArea, &QMdiArea::cascadeSubWindows); + config->setShortcut(ui->actionCascadeWindows, "mainwindow.shortcuts.cascadeWindows"); + + subWindowAction = ui->actionCurrentWindow; + } navigationToolBar = new NavigationBar(config->section("navigation"), this); navigationToolBar->setMovable(config->value<bool>("navigation.movable").value()); @@ -117,7 +175,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) // search box auto *searchAction = new QAction(this); - m_config->setShortcut(searchAction, "mainwindow.shortcuts.search"); + config->setShortcut(searchAction, "mainwindow.shortcuts.search"); connect(searchAction, &QAction::triggered, this, [=]() { /* QTBUG-18665 * When focusing out of the search box and hiding it, the first @@ -143,87 +201,11 @@ MainWindow::~MainWindow() disconnect(addressBar); } -void MainWindow::createMenuBar() -{ - Q_CHECK_PTR(mdiArea); - - // smolbote menu - auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName()); - - auto *subwindowAction = smolboteMenu->addAction(tr("New subwindow"), this, [this]() { - createSubWindow(); - }); - m_config->setShortcut(subwindowAction, "mainwindow.shortcuts.newGroup"); - - auto *windowAction = smolboteMenu->addAction(tr("New window"), this, []() { - auto *browser = qobject_cast<Browser *>(qApp); - if(browser) - browser->createWindow(); - }); - m_config->setShortcut(windowAction, "mainwindow.shortcuts.newWindow"); - - smolboteMenu->addSeparator(); - - auto *aboutAction = smolboteMenu->addAction(tr("About"), qobject_cast<Browser *>(qApp), &Browser::about); - m_config->setShortcut(aboutAction, "mainwindow.shortcuts.about"); - smolboteMenu->addAction(tr("About Qt"), qApp, &QApplication::aboutQt); - - smolboteMenu->addSeparator(); - - auto *quitAction = smolboteMenu->addAction(tr("Quit"), qApp, &QApplication::quit); - m_config->setShortcut(quitAction, "mainwindow.shortcuts.quit"); - - // session menu - auto *sessionMenu = menuBar()->addMenu(tr("Session")); - - sessionMenu->addAction(tr("Save Session"), this, [this]() { - const QString filename = QFileDialog::getSaveFileName(this, tr("Save Session"), QDir::homePath(), tr("JSON (*.json)")); - QFile output(filename); - if(output.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - output.write(QJsonDocument(Session::toJsonObject(this)).toJson()); - output.close(); - } - }); - sessionMenu->addAction(tr("Load Session"), this, [this]() { - const QString filename = QFileDialog::getOpenFileName(this, tr("Load Session"), QDir::homePath(), tr("JSON (*.json)")); - QFile json(filename); - if(json.open(QIODevice::ReadOnly | QIODevice::Text)) { - auto *browser = qobject_cast<Browser *>(qApp); - browser->sendMessage(json.readAll()); - json.close(); - } - }); - - // window menu - auto *windowMenu = menuBar()->addMenu(tr("Window")); - - auto *tileAction = windowMenu->addAction(tr("Tile windows"), mdiArea, &QMdiArea::tileSubWindows); - m_config->setShortcut(tileAction, "mainwindow.shortcuts.tileWindows"); - - auto *cascadeAction = windowMenu->addAction(tr("Cascade windows"), mdiArea, &QMdiArea::cascadeSubWindows); - m_config->setShortcut(cascadeAction, "mainwindow.shortcuts.cascadeWindows"); - - subWindowAction = windowMenu->addAction(tr("Current window")); - - // tools menu - toolsMenu = menuBar()->addMenu(tr("Tools")); - - // debug menu -#ifdef QT_DEBUG - auto *debugMenu = menuBar()->addMenu(tr("Debug")); - - debugMenu->addAction(tr("Print window session"), [this]() { - auto json = Session::toJsonObject(this); - qDebug("session data >>>\n%s\n<<<", qUtf8Printable(QJsonDocument(json).toJson())); - }); -#endif -} - void MainWindow::addAction(ActionLocation where, QAction *action) { switch(where) { case ToolsMenu: - toolsMenu->addAction(action); + ui->menuTools->addAction(action); break; default: QMainWindow::addAction(action); @@ -264,7 +246,9 @@ void MainWindow::createTab(const QUrl &url) { auto *w = qobject_cast<SubWindow *>(mdiArea->currentSubWindow()); if(w == nullptr) { - w = createSubWindow(url.toString()); + //w = createSubWindow(url.toString()); +// w = createSubWindow(WebProfile::defaultProfile()); +// w->addTab(url); } else { w->addTab(url); } @@ -287,9 +271,9 @@ SubWindow *MainWindow::currentSubWindow() const return qobject_cast<SubWindow *>(mdiArea->currentSubWindow()); } -SubWindow *MainWindow::createSubWindow(WebProfile *profile) +SubWindow *MainWindow::createSubWindow(const std::unique_ptr<Configuration> &config, WebProfile *profile) { - auto *w = new SubWindow(m_config->section("window"), this); + auto *w = new SubWindow(config, this); w->setProfile(profile); mdiArea->addSubWindow(w); w->showMaximized(); @@ -297,16 +281,6 @@ SubWindow *MainWindow::createSubWindow(WebProfile *profile) return w; } -SubWindow *MainWindow::createSubWindow(const QString &url) -{ - auto *w = new SubWindow(m_config->section("window"), this); - mdiArea->addSubWindow(w); - w->showMaximized(); - w->setFocus(); - w->addTab(url); - return w; -} - void MainWindow::setView(WebView *view) { if(currentView) { diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 287602a..d695dd8 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -22,6 +22,11 @@ class SearchForm; class WebView; class NavigationBar; class WebProfile; + +namespace Ui { +class MainWindow; +} + class MainWindow : public QMainWindow { friend class Browser; @@ -33,12 +38,10 @@ public: ToolsMenu }; - explicit MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent = nullptr); + explicit MainWindow(const std::unique_ptr<Configuration> &config, QWidget *parent = nullptr); Q_DISABLE_COPY(MainWindow) ~MainWindow() override; - void createMenuBar(); - void addAction(ActionLocation where, QAction *action); void addDockWidget(Qt::DockWidgetArea area, QWidget *widget); void removeDockWidget(QWidget *widget); @@ -48,15 +51,16 @@ public: public slots: void createTab(const QUrl &url); - SubWindow *createSubWindow(WebProfile *profile); - SubWindow *createSubWindow(const QString &url = QString()); + SubWindow *createSubWindow(const std::unique_ptr<Configuration> &config, WebProfile *profile); +private slots: void setView(WebView *view); protected: void closeEvent(QCloseEvent *event) override; private: + Ui::MainWindow *ui; QAction *subWindowAction = nullptr; QMenu *toolsMenu = nullptr; @@ -67,8 +71,6 @@ private: QMdiArea *mdiArea; WebView *currentView = nullptr; - std::shared_ptr<Configuration> m_config; - QMetaObject::Connection viewChangedConnection; QMetaObject::Connection searchBoxConnection; QMetaObject::Connection statusBarConnection; diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui new file mode 100644 index 0000000..72e0b39 --- /dev/null +++ b/src/mainwindow/mainwindow.ui @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"/> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>23</height> + </rect> + </property> + <widget class="QMenu" name="menusmolbote"> + <property name="title"> + <string>s&molbote</string> + </property> + <addaction name="actionNewSubwindow"/> + <addaction name="actionNewWindow"/> + <addaction name="separator"/> + <addaction name="actionAbout"/> + <addaction name="actionAboutQt"/> + <addaction name="separator"/> + <addaction name="actionQuit"/> + </widget> + <widget class="QMenu" name="menuSession"> + <property name="title"> + <string>Session</string> + </property> + <addaction name="actionSaveSession"/> + <addaction name="actionLoadSession"/> + </widget> + <widget class="QMenu" name="menuWindow"> + <property name="title"> + <string>Wi&ndow</string> + </property> + <addaction name="actionTileWindows"/> + <addaction name="actionCascadeWindows"/> + <addaction name="separator"/> + <addaction name="actionCurrentWindow"/> + </widget> + <widget class="QMenu" name="menuTools"> + <property name="title"> + <string>Too&ls</string> + </property> + </widget> + <addaction name="menusmolbote"/> + <addaction name="menuSession"/> + <addaction name="menuWindow"/> + <addaction name="menuTools"/> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <action name="actionNewSubwindow"> + <property name="text"> + <string>&New Subwindow</string> + </property> + </action> + <action name="actionNewWindow"> + <property name="text"> + <string>New &Window</string> + </property> + </action> + <action name="actionAbout"> + <property name="text"> + <string>&About</string> + </property> + </action> + <action name="actionAboutQt"> + <property name="text"> + <string>A&bout Qt</string> + </property> + </action> + <action name="actionQuit"> + <property name="text"> + <string>&Quit</string> + </property> + </action> + <action name="actionSaveSession"> + <property name="text"> + <string>&Save Session</string> + </property> + </action> + <action name="actionLoadSession"> + <property name="text"> + <string>&Load Session</string> + </property> + </action> + <action name="actionTileWindows"> + <property name="text"> + <string>Tile Windows</string> + </property> + </action> + <action name="actionCascadeWindows"> + <property name="text"> + <string>Cascade Windows</string> + </property> + </action> + <action name="actionCurrentWindow"> + <property name="text"> + <string>Current Window</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp index 5a1eeda..342fce8 100644 --- a/src/mainwindow/subwindow.cpp +++ b/src/mainwindow/subwindow.cpp @@ -20,8 +20,9 @@ #include <QToolButton> #include <webprofile.h> #include "profilemanager.h" +#include <configuration.h> -SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags) +SubWindow::SubWindow(const std::unique_ptr<Configuration> &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) , tabWidget(new TabWidget(this)) { @@ -62,7 +63,7 @@ SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt: auto *newTab_button = new QToolButton(this); newTab_button->setIcon(style()->standardIcon(QStyle::SP_FileIcon)); newTab_button->setToolTip(tr("Add tab")); - newTab_button->setShortcut(QKeySequence(config.value("window.shortcuts.new"))); + newTab_button->setShortcut(QKeySequence(config->value<QString>("window.shortcuts.new").value())); connect(newTab_button, &QToolButton::clicked, this, [=]() { auto index = addTab(WebProfile::defaultProfile()->newtab()); tabWidget->setCurrentIndex(index); @@ -70,17 +71,17 @@ SubWindow::SubWindow(const QHash<QString, QString> &config, QWidget *parent, Qt: tabWidget->setCornerWidget(newTab_button, Qt::TopRightCorner); // general actions - auto *closeTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.close")), this); + auto *closeTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.close").value()), this); connect(closeTab_shortcut, &QShortcut::activated, this, [=]() { tabWidget->deleteTab(tabWidget->currentIndex()); }); - auto *leftTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.left")), this); + auto *leftTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.left").value()), this); connect(leftTab_shortcut, &QShortcut::activated, this, [=]() { tabWidget->setCurrentIndex(qMax(0, tabWidget->currentIndex() - 1)); }); - auto *rightTab_shortcut = new QShortcut(QKeySequence(config.value("window.shortcuts.right")), this); + auto *rightTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.right").value()), this); connect(rightTab_shortcut, &QShortcut::activated, this, [=]() { tabWidget->setCurrentIndex(qMin(tabWidget->currentIndex() + 1, tabWidget->count() - 1)); }); diff --git a/src/mainwindow/subwindow.h b/src/mainwindow/subwindow.h index 1283481..b7c4aee 100644 --- a/src/mainwindow/subwindow.h +++ b/src/mainwindow/subwindow.h @@ -16,12 +16,13 @@ class TabWidget; class WebView; class WebProfile; +class Configuration; class SubWindow : public QMdiSubWindow { Q_OBJECT public: - explicit SubWindow(const QHash<QString, QString> &config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit SubWindow(const std::unique_ptr<Configuration> &config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~SubWindow() override; WebView *currentView(); |