aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-17 13:25:38 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-17 13:25:38 +0100
commit7eb573a67ea883228ff7905190ff46c0f29593b1 (patch)
treedcad511c1c844419b107f127ee07203e379b62ff
parentFixed release builds defining QT_DEBUG (diff)
downloadsmolbote-7eb573a67ea883228ff7905190ff46c0f29593b1.tar.xz
ProfileView dialog
-rw-r--r--smolbote.qbs3
-rw-r--r--src/forms/profilesdialog.cpp98
-rw-r--r--src/forms/profilesdialog.h55
-rw-r--r--src/forms/profilesdialog.ui115
-rw-r--r--src/forms/profileview.cpp5
-rw-r--r--src/forms/profileview.h6
-rw-r--r--src/forms/profileview.ui7
-rw-r--r--src/mainwindow.cpp7
-rw-r--r--src/mainwindow.h2
-rw-r--r--src/widgets/mainwindowmenubar.cpp34
-rw-r--r--src/widgets/mainwindowmenubar.h4
11 files changed, 46 insertions, 290 deletions
diff --git a/smolbote.qbs b/smolbote.qbs
index c0f794b..0fb4000 100644
--- a/smolbote.qbs
+++ b/smolbote.qbs
@@ -129,9 +129,6 @@ Project {
"src/forms/cookiesform.cpp",
"src/forms/cookiesform.h",
"src/forms/cookiesform.ui",
- "src/forms/profilesdialog.cpp",
- "src/forms/profilesdialog.h",
- "src/forms/profilesdialog.ui",
"src/forms/profileview.cpp",
"src/forms/profileview.h",
"src/forms/profileview.ui",
diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp
deleted file mode 100644
index b295675..0000000
--- a/src/forms/profilesdialog.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "profilesdialog.h"
-#include "ui_profilesdialog.h"
-
-#include "browser.h"
-#include <QListWidget>
-#include <QHBoxLayout>
-#include <QDialogButtonBox>
-#include <QPushButton>
-#include <QInputDialog>
-
-#include "mainwindow.h"
-
-ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::ProfilesDialog)
-{
- m_window = window;
-
- m_view = new ProfileView(nullptr, this);
-
- // Hide the profile view because we're fancy
- // Give focus to the top widget because otherwise the listwidget gains focus
- // which causes it to select the first item in it, which in turn triggers the signal
- // and so the profile view gets shown even though the user hasn't selected anything
- // and so we get to be less fancy, defeating the point of the exercise
- // [on linux; other OS's not checked]
- m_view->hide();
- this->setFocus();
-
- ui->setupUi(this);
- ui->horizontalLayout->addWidget(m_view);
- ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Load"));
-
- connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(viewProfile(int)));
- connect(ui->new_toolButton, SIGNAL(released()), this, SLOT(newProfile()));
- disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(loadSelectedProfile()));
- connect(ui->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), m_view, SLOT(updateProfile()));
-
- loadProfiles();
-}
-
-ProfilesDialog::~ProfilesDialog()
-{
- delete ui;
-}
-
-void ProfilesDialog::loadProfiles()
-{
- ui->listWidget->clear();
-
-// for(QString name : browser->profiles()) {
-// QListWidgetItem *item = new QListWidgetItem(browser->profile(name)->name(), ui->listWidget);
-// item->setData(Qt::UserRole, name);
-// }
-}
-
-void ProfilesDialog::newProfile()
-{
- bool ok;
- QString name = QInputDialog::getText(this, tr("Profile Name"), tr("Profile Name:"), QLineEdit::Normal, tr("Default"), &ok);
-
-// if(ok) {
-// browser->profile(name);
-// loadProfiles();
-// }
-}
-
-void ProfilesDialog::loadSelectedProfile()
-{
- //m_window->setProfile(browser->profile(ui->listWidget->currentItem()->data(Qt::UserRole).toString()));
-}
-
-void ProfilesDialog::viewProfile(int index)
-{
- //m_view->setProfile(browser->profile(ui->listWidget->item(index)->data(Qt::UserRole).toString()));
- m_view->show();
-}
diff --git a/src/forms/profilesdialog.h b/src/forms/profilesdialog.h
deleted file mode 100644
index 066fa7c..0000000
--- a/src/forms/profilesdialog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef PROFILESDIALOG_H
-#define PROFILESDIALOG_H
-
-#include <QDialog>
-#include "forms/profileview.h"
-
-namespace Ui {
-class ProfilesDialog;
-}
-
-class MainWindow;
-class ProfilesDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit ProfilesDialog(MainWindow *window, QWidget *parent = nullptr);
- ~ProfilesDialog();
-
-public slots:
- void loadProfiles();
-
- void newProfile();
-
-private slots:
- void loadSelectedProfile();
- void viewProfile(int index);
-
-private:
- Ui::ProfilesDialog *ui;
- ProfileView *m_view;
- MainWindow *m_window;
-};
-
-#endif // PROFILESDIALOG_H
diff --git a/src/forms/profilesdialog.ui b/src/forms/profilesdialog.ui
deleted file mode 100644
index 7e8bad5..0000000
--- a/src/forms/profilesdialog.ui
+++ /dev/null
@@ -1,115 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ProfilesDialog</class>
- <widget class="QDialog" name="ProfilesDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>580</width>
- <height>620</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Profiles</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QListWidget" name="listWidget"/>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="buttons_horizontalLayout">
- <item>
- <widget class="QToolButton" name="new_toolButton">
- <property name="text">
- <string>New</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="clone_toolButton">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Clone</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="delete_toolButton">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>Delete</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Save</set>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>ProfilesDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>ProfilesDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/forms/profileview.cpp b/src/forms/profileview.cpp
index 6977b61..5e02179 100644
--- a/src/forms/profileview.cpp
+++ b/src/forms/profileview.cpp
@@ -33,7 +33,7 @@
#include <QFormLayout>
ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) :
- QWidget(parent),
+ QDialog(parent),
ui(new Ui::ProfileView)
{
ui->setupUi(this);
@@ -47,7 +47,8 @@ ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) :
this->m_profile->clearAllVisitedLinks();
});
- //connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateProfile()));
+ connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ProfileView::updateProfile);
+ connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProfileView::close);
}
ProfileView::~ProfileView()
diff --git a/src/forms/profileview.h b/src/forms/profileview.h
index a2ac98e..54ef019 100644
--- a/src/forms/profileview.h
+++ b/src/forms/profileview.h
@@ -21,7 +21,7 @@
#ifndef PROFILEDIALOG_H
#define PROFILEDIALOG_H
-#include <QWidget>
+#include <QDialog>
namespace Ui {
class ProfileView;
@@ -29,12 +29,12 @@ class ProfileView;
class WebEngineProfile;
class CookiesForm;
-class ProfileView : public QWidget
+class ProfileView : public QDialog
{
Q_OBJECT
public:
- explicit ProfileView(WebEngineProfile *profile, QWidget *parent = 0);
+ explicit ProfileView(WebEngineProfile *profile, QWidget *parent = nullptr);
~ProfileView();
void setProfile(WebEngineProfile *profile);
diff --git a/src/forms/profileview.ui b/src/forms/profileview.ui
index 5823d02..7590e87 100644
--- a/src/forms/profileview.ui
+++ b/src/forms/profileview.ui
@@ -216,6 +216,13 @@
</widget>
</widget>
</item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 297b571..16e0ed0 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -218,6 +218,13 @@ void MainWindow::setProfile(WebEngineProfile *profile)
{
Q_CHECK_PTR(profile);
tabBar->setProfile(profile);
+ menuBar->setProfileName(profile->name());
+}
+
+WebEngineProfile *MainWindow::profile()
+{
+ Q_CHECK_PTR(tabBar->profile());
+ return tabBar->profile();
}
void MainWindow::setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d0fb139..1062d64 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -60,6 +60,8 @@ public slots:
void newWindow(const QUrl &url = QUrl(""));
void setProfile(WebEngineProfile *profile);
+ WebEngineProfile *profile();
+
void setBookmarksWidget(std::shared_ptr<BookmarksWidget> &widget);
void setDownloadsWidget(std::shared_ptr<DownloadsWidget> &widget);
diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp
index 5ef0618..dfd8b5b 100644
--- a/src/widgets/mainwindowmenubar.cpp
+++ b/src/widgets/mainwindowmenubar.cpp
@@ -22,10 +22,12 @@
#include <QApplication>
#include <QMenu>
#include <QInputDialog>
-#include "forms/profilesdialog.h"
+#include "forms/profileview.h"
#include "mainwindow.h"
#include <settings/configuration.h>
+#include "browser.h"
+
MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, MainWindow *parent) :
QMenuBar(parent)
{
@@ -74,9 +76,16 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr<Configuration> config, Main
//toolsMenu->addAction(tr("Filter"), browser->blocklists(), SLOT(show()), QKeySequence::fromString(browser->settings()->value("blocker.shortcut").toString()));
// Profile menu
- QMenu *profileMenu = new QMenu(tr("Profile"), this);
- addMenu(profileMenu);
- //profileMenu->addAction(tr("Profiles"), this, SLOT(handleLoadProfile()));
+ QMenu *profileMenu = addMenu(tr("Profile"));
+ m_profileAction = profileMenu->addAction(tr("Current profile"));
+ connect(m_profileAction, &QAction::triggered, this, [parent]() {
+ ProfileView *dlg = new ProfileView(parent->profile(), parent);
+ dlg->exec();
+ delete dlg;
+ });
+
+ QMenu *loadMenu = profileMenu->addMenu(tr("Load"));
+ loadMenu->setEnabled(false);
}
QAction *MainWindowMenuBar::bookmarksAction()
@@ -91,14 +100,13 @@ QAction *MainWindowMenuBar::downloadsAction()
return m_downloadsAction;
}
-void MainWindowMenuBar::handleLoadProfile(MainWindow *window)
+void MainWindowMenuBar::setProfileName(const QString &name)
+{
+ Q_CHECK_PTR(m_profileAction);
+ m_profileAction->setText(tr("Current: %1").arg(name));
+}
+
+void MainWindowMenuBar::handleLoadProfile(const QString &name, MainWindow *window)
{
- ProfilesDialog *dlg = new ProfilesDialog(window, this);
- dlg->exec();
-
-// bool ok;
-// QString _name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok);
-// if(ok) {
-// m_parentWindow->setProfile(qApp->profile(_name));
-// }
+ window->setProfile(static_cast<Browser*>(qApp->instance())->profile(name));
}
diff --git a/src/widgets/mainwindowmenubar.h b/src/widgets/mainwindowmenubar.h
index 5a7094b..31f01bb 100644
--- a/src/widgets/mainwindowmenubar.h
+++ b/src/widgets/mainwindowmenubar.h
@@ -34,13 +34,15 @@ public:
QAction *bookmarksAction();
QAction *downloadsAction();
+ void setProfileName(const QString &name);
private slots:
- void handleLoadProfile(MainWindow *window);
+ void handleLoadProfile(const QString &name, MainWindow *window);
private:
QAction *m_bookmarksAction;
QAction *m_downloadsAction;
+ QAction *m_profileAction;
};
#endif // MAINWINDOWMENUBAR_H