aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-30 13:34:44 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-30 13:34:44 +0100
commitaffad4abfdd065a3c329ef40c1a46042c0562f2f (patch)
tree49368a9f941ef4192c3a5e10bd7007ce84867100
parentAdded profile and plugin list to About dialog (diff)
downloadsmolbote-affad4abfdd065a3c329ef40c1a46042c0562f2f.tar.xz
Profile menu lists loadable profiles
-rw-r--r--src/mainwindow/mainwindow.cpp17
-rw-r--r--src/mainwindow/mainwindow.h1
-rw-r--r--src/widgets/mainwindowmenubar.cpp21
-rw-r--r--src/widgets/mainwindowmenubar.h5
4 files changed, 19 insertions, 25 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index b0195a5..5ee0a78 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -177,7 +177,7 @@ void MainWindow::newTab(const QUrl &url)
MainWindow *MainWindow::newWindow(const QUrl &url)
{
- Browser *instance = static_cast<Browser *>(qApp->instance());
+ auto *instance = dynamic_cast<Browser *>(QApplication::instance());
return instance->createSession(m_profile->storageName(), true, QStringList(url.toString()));
}
@@ -195,22 +195,16 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::about()
{
- AboutDialog *dlg = new AboutDialog(this);
+ auto *dlg = new AboutDialog(this);
dlg->exec();
}
-void MainWindow::showSettingsDialog()
-{
- //SettingsDialog *dlg = new SettingsDialog(m_config, this);
- //dlg->exec();
-}
-
void MainWindow::setProfile(std::shared_ptr<WebEngineProfile> profile)
{
Q_ASSERT(profile);
m_profile = profile;
tabBar->setProfile(profile.get());
- menuBar->setProfileName(profile->name());
+ menuBar->profileAction()->setText(tr("Current profile: %1").arg(profile->name()));
}
WebEngineProfile *MainWindow::profile()
@@ -297,9 +291,8 @@ void MainWindow::addPlugins(const QVector<Browser::Plugin> &plugins)
if(iProfilePlugin) {
QWidget *w = iProfilePlugin->createWidget(m_profile.get(), this);
- auto *profileAction = new QAction(tr("Profile Action"), this);
- ui->navigationToolBar->addAction(profileAction);
- connect(profileAction, &QAction::triggered, this, [this, w]() {
+ menuBar->profileAction()->setEnabled(true);
+ connect(menuBar->profileAction(), &QAction::triggered, this, [this, w]() {
w->setVisible(!w->isVisible());
if(w->isVisible()) {
QPoint pos = ui->navigationToolBar->pos();
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index 0965b43..f9e0515 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -53,7 +53,6 @@ public:
public slots:
void about();
- void showSettingsDialog();
void newTab(const QUrl &url = QUrl(""));
MainWindow *newWindow(const QUrl &url = QUrl(""));
diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp
index d24f273..3c5b042 100644
--- a/src/widgets/mainwindowmenubar.cpp
+++ b/src/widgets/mainwindowmenubar.cpp
@@ -7,6 +7,7 @@
*/
#include "mainwindowmenubar.h"
+#include "browser.h"
#include "downloads/downloadswidget.h"
#include "src/mainwindow/mainwindow.h"
#include <QInputDialog>
@@ -19,6 +20,8 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
+ auto *browser = dynamic_cast<Browser *>(QApplication::instance());
+
// Browser menu
QMenu *browserMenu = new QMenu(qApp->applicationName(), this);
addMenu(browserMenu);
@@ -36,7 +39,7 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main
newTabAction->setShortcut(QKeySequence(config->value<std::string>("browser.shortcuts.newTab").value().c_str()));
browserMenu->addSeparator();
- browserMenu->addAction(tr("Settings"), parent, &MainWindow::showSettingsDialog);
+ //browserMenu->addAction(tr("Settings"), parent, &MainWindow::showSettingsDialog);
browserMenu->addAction(tr("About"), parent, &MainWindow::about, QKeySequence(config->value<std::string>("browser.shortcuts.about").value().c_str()));
browserMenu->addAction(tr("About Qt"), qApp, &QApplication::aboutQt);
browserMenu->addSeparator();
@@ -67,7 +70,13 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main
m_profileAction->setEnabled(false);
QMenu *loadMenu = profileMenu->addMenu(tr("Load"));
- loadMenu->setEnabled(false);
+
+ for(const QString &name : browser->profiles()) {
+ QAction *profileAction = loadMenu->addAction(browser->profile(name)->name());
+ connect(profileAction, &QAction::triggered, this, [browser, parent, name] {
+ parent->setProfile(browser->profile(name));
+ });
+ }
}
QAction *MainWindowMenuBar::bookmarksAction()
@@ -76,13 +85,9 @@ QAction *MainWindowMenuBar::bookmarksAction()
return m_bookmarksAction;
}
-void MainWindowMenuBar::setProfileName(const QString &name)
+QAction *MainWindowMenuBar::profileAction() const
{
Q_CHECK_PTR(m_profileAction);
- m_profileAction->setText(tr("Current: %1").arg(name));
+ return m_profileAction;
}
-void MainWindowMenuBar::handleLoadProfile(const QString &name, MainWindow *window)
-{
- window->setProfile(static_cast<Browser *>(qApp->instance())->profile(name));
-}
diff --git a/src/widgets/mainwindowmenubar.h b/src/widgets/mainwindowmenubar.h
index 334829f..11c8beb 100644
--- a/src/widgets/mainwindowmenubar.h
+++ b/src/widgets/mainwindowmenubar.h
@@ -21,10 +21,7 @@ public:
explicit MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent = nullptr);
QAction *bookmarksAction();
- void setProfileName(const QString &name);
-
-private slots:
- void handleLoadProfile(const QString &name, MainWindow *window);
+ QAction *profileAction() const;
private:
QAction *m_bookmarksAction;