From 7eb573a67ea883228ff7905190ff46c0f29593b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 17 Dec 2017 13:25:38 +0100 Subject: ProfileView dialog --- src/forms/profilesdialog.cpp | 98 -------------------------------- src/forms/profilesdialog.h | 55 ------------------ src/forms/profilesdialog.ui | 115 -------------------------------------- src/forms/profileview.cpp | 5 +- src/forms/profileview.h | 6 +- src/forms/profileview.ui | 7 +++ src/mainwindow.cpp | 7 +++ src/mainwindow.h | 2 + src/widgets/mainwindowmenubar.cpp | 34 ++++++----- src/widgets/mainwindowmenubar.h | 4 +- 10 files changed, 46 insertions(+), 287 deletions(-) delete mode 100644 src/forms/profilesdialog.cpp delete mode 100644 src/forms/profilesdialog.h delete mode 100644 src/forms/profilesdialog.ui (limited to 'src') 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 . - ** - ******************************************************************************/ - -#include "profilesdialog.h" -#include "ui_profilesdialog.h" - -#include "browser.h" -#include -#include -#include -#include -#include - -#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 . - ** - ******************************************************************************/ - -#ifndef PROFILESDIALOG_H -#define PROFILESDIALOG_H - -#include -#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 @@ - - - ProfilesDialog - - - - 0 - 0 - 580 - 620 - - - - Profiles - - - - - - - - - - - - - - - New - - - - - - - false - - - Clone - - - - - - - false - - - Delete - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Save - - - - - - - - - - - buttonBox - accepted() - ProfilesDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ProfilesDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - 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 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 +#include 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 @@ + + + + QDialogButtonBox::Close|QDialogButtonBox::Save + + + 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 &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 &widget); void setDownloadsWidget(std::shared_ptr &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 #include #include -#include "forms/profilesdialog.h" +#include "forms/profileview.h" #include "mainwindow.h" #include +#include "browser.h" + MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr config, MainWindow *parent) : QMenuBar(parent) { @@ -74,9 +76,16 @@ MainWindowMenuBar::MainWindowMenuBar(std::shared_ptr 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(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 -- cgit v1.2.1