diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-05-28 12:46:11 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-05-28 12:46:11 +0200 |
commit | 27742143d60e80bc925439e44664cc23c472f433 (patch) | |
tree | f6554dfe136ae290f1cce6da7a3dc36453c937c4 | |
parent | Profile improvements (diff) | |
download | smolbote-27742143d60e80bc925439e44664cc23c472f433.tar.xz |
Profiles dialog
-rw-r--r-- | smolbote.qbs | 6 | ||||
-rw-r--r-- | src/forms/profilesdialog.cpp | 17 | ||||
-rw-r--r-- | src/forms/profilesdialog.h | 3 | ||||
-rw-r--r-- | src/forms/profilesdialog.ui | 9 | ||||
-rw-r--r-- | src/forms/profileview.cpp (renamed from src/forms/profiledialog.cpp) | 60 | ||||
-rw-r--r-- | src/forms/profileview.h (renamed from src/forms/profiledialog.h) | 14 | ||||
-rw-r--r-- | src/forms/profileview.ui (renamed from src/forms/profiledialog.ui) | 50 | ||||
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 11 | ||||
-rw-r--r-- | src/webengine/webengineprofile.h | 9 |
10 files changed, 92 insertions, 89 deletions
diff --git a/smolbote.qbs b/smolbote.qbs index 18112f0..573706c 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -146,12 +146,12 @@ Project { "src/forms/cookiesform.cpp", "src/forms/cookiesform.h", "src/forms/cookiesform.ui", - "src/forms/profiledialog.cpp", - "src/forms/profiledialog.h", - "src/forms/profiledialog.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", "src/webengine/webengineprofile.cpp", "src/webengine/webengineprofile.h", ] diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp index c77208d..cf6791c 100644 --- a/src/forms/profilesdialog.cpp +++ b/src/forms/profilesdialog.cpp @@ -23,14 +23,19 @@ #include "browser.h" #include <QListWidget> +#include <QHBoxLayout> ProfilesDialog::ProfilesDialog(MainWindow *window, QWidget *parent) : QDialog(parent), ui(new Ui::ProfilesDialog) { - ui->setupUi(this); m_window = window; + m_view = new ProfileView(0, this); + ui->setupUi(this); + ui->horizontalLayout->addWidget(m_view); + + connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(viewProfile(int))); connect(this, SIGNAL(accepted()), this, SLOT(loadSelectedProfile())); } @@ -43,12 +48,18 @@ int ProfilesDialog::exec() { qDebug("Showing..."); for(QString name : qApp->profiles()) { - ui->listWidget->addItem(name); + QListWidgetItem *item = new QListWidgetItem(qApp->profile(name)->name(), ui->listWidget); + item->setData(Qt::UserRole, name); } return QDialog::exec(); } void ProfilesDialog::loadSelectedProfile() { - m_window->setProfile(qApp->profile(ui->listWidget->currentItem()->text())); + m_window->setProfile(qApp->profile(ui->listWidget->currentItem()->data(Qt::UserRole).toString())); +} + +void ProfilesDialog::viewProfile(int index) +{ + m_view->setProfile(qApp->profile(ui->listWidget->item(index)->data(Qt::UserRole).toString())); } diff --git a/src/forms/profilesdialog.h b/src/forms/profilesdialog.h index bb6655b..302bf82 100644 --- a/src/forms/profilesdialog.h +++ b/src/forms/profilesdialog.h @@ -22,6 +22,7 @@ #define PROFILESDIALOG_H #include <QDialog> +#include "forms/profileview.h" namespace Ui { class ProfilesDialog; @@ -41,9 +42,11 @@ public slots: private slots: void loadSelectedProfile(); + void viewProfile(int index); private: Ui::ProfilesDialog *ui; + ProfileView *m_view; MainWindow *m_window; }; diff --git a/src/forms/profilesdialog.ui b/src/forms/profilesdialog.ui index 880e441..7675a9d 100644 --- a/src/forms/profilesdialog.ui +++ b/src/forms/profilesdialog.ui @@ -6,12 +6,12 @@ <rect> <x>0</x> <y>0</y> - <width>564</width> - <height>458</height> + <width>580</width> + <height>620</height> </rect> </property> <property name="windowTitle"> - <string>Dialog</string> + <string>Profiles</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> @@ -19,9 +19,6 @@ <item> <widget class="QListWidget" name="listWidget"/> </item> - <item> - <widget class="QWidget" name="widget" native="true"/> - </item> </layout> </item> <item> diff --git a/src/forms/profiledialog.cpp b/src/forms/profileview.cpp index 4d6c047..9d2e9ed 100644 --- a/src/forms/profiledialog.cpp +++ b/src/forms/profileview.cpp @@ -18,8 +18,8 @@ ** ******************************************************************************/ -#include "profiledialog.h" -#include "ui_profiledialog.h" +#include "profileview.h" +#include "ui_profileview.h" #include <QLineEdit> #include <QPlainTextEdit> @@ -28,13 +28,38 @@ #include "webengine/webengineprofile.h" #include "forms/cookiesform.h" -ProfileDialog::ProfileDialog(WebEngineProfile *profile, QWidget *parent) : - QDialog(parent), - ui(new Ui::ProfileDialog) -{ - _profile = profile; +#include <QDialogButtonBox> +ProfileView::ProfileView(WebEngineProfile *profile, QWidget *parent) : + QWidget(parent), + ui(new Ui::ProfileView) +{ ui->setupUi(this); + setProfile(profile); + + // actions + connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { + this->_profile->clearHttpCache(); + }); + connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { + this->_profile->clearAllVisitedLinks(); + }); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateProfile())); +} + +ProfileView::~ProfileView() +{ + delete ui; +} + +void ProfileView::setProfile(WebEngineProfile *profile) +{ + if(!profile) { + return; + } + + _profile = profile; if(!_profile->storageName().isEmpty()) { setWindowTitle(_profile->storageName()); } else { @@ -56,36 +81,21 @@ ProfileDialog::ProfileDialog(WebEngineProfile *profile, QWidget *parent) : // policy ui->cookiePolicy->setCurrentIndex(_profile->persistentCookiesPolicy()); - - // actions - connect(ui->clearCache_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearHttpCache(); - }); - connect(ui->clearHistory_pushButton, &QPushButton::clicked, [this]() { - this->_profile->clearAllVisitedLinks(); - }); - - connect(this, SIGNAL(accepted()), this, SLOT(updateProfile())); -} - -ProfileDialog::~ProfileDialog() -{ - delete ui; } -void ProfileDialog::showProfile() +void ProfileView::showProfile() { ui->tabWidget->setCurrentIndex(0); show(); } -void ProfileDialog::showCookies() +void ProfileView::showCookies() { ui->tabWidget->setCurrentIndex(4); show(); } -void ProfileDialog::updateProfile() +void ProfileView::updateProfile() { qDebug("Updating profile..."); diff --git a/src/forms/profiledialog.h b/src/forms/profileview.h index 613ed80..5dbdb59 100644 --- a/src/forms/profiledialog.h +++ b/src/forms/profileview.h @@ -21,21 +21,23 @@ #ifndef PROFILEDIALOG_H #define PROFILEDIALOG_H -#include <QDialog> +#include <QWidget> namespace Ui { -class ProfileDialog; +class ProfileView; } class WebEngineProfile; class CookiesForm; -class ProfileDialog : public QDialog +class ProfileView : public QWidget { Q_OBJECT public: - explicit ProfileDialog(WebEngineProfile *profile, QWidget *parent = 0); - ~ProfileDialog(); + explicit ProfileView(WebEngineProfile *profile, QWidget *parent = 0); + ~ProfileView(); + + void setProfile(WebEngineProfile *profile); public slots: void showProfile(); @@ -46,7 +48,7 @@ private slots: private: WebEngineProfile *_profile; - Ui::ProfileDialog *ui; + Ui::ProfileView *ui; CookiesForm *m_cookiesForm; }; diff --git a/src/forms/profiledialog.ui b/src/forms/profileview.ui index 528d672..e7bcbae 100644 --- a/src/forms/profiledialog.ui +++ b/src/forms/profileview.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>ProfileDialog</class> - <widget class="QDialog" name="ProfileDialog"> + <class>ProfileView</class> + <widget class="QWidget" name="ProfileView"> <property name="geometry"> <rect> <x>0</x> @@ -10,6 +10,12 @@ <height>640</height> </rect> </property> + <property name="minimumSize"> + <size> + <width>200</width> + <height>0</height> + </size> + </property> <property name="windowTitle"> <string>Profile</string> </property> @@ -188,49 +194,13 @@ </item> <item> <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> <property name="standardButtons"> - <set>QDialogButtonBox::Close|QDialogButtonBox::Save</set> + <set>QDialogButtonBox::Save</set> </property> </widget> </item> </layout> </widget> <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>ProfileDialog</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>ProfileDialog</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> + <connections/> </ui> diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 79552d6..851ee9e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -231,7 +231,7 @@ void MainWindow::handleUrlChanged() void MainWindow::handleTitleUpdated(const QString &title) { - setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->storageName())); + setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->name())); } void MainWindow::profileAction() diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 89cc301..2fed937 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -27,11 +27,13 @@ WebEngineProfile::WebEngineProfile(QObject *parent) : QWebEngineProfile(parent) { // Off-the-record constructor + m_name = tr("Off-the-record"); } WebEngineProfile::WebEngineProfile(const QString &storageName, QObject *parent) : QWebEngineProfile(storageName, parent) { + m_name = storageName; setPersistentStoragePath(sSettings->value("browser.profile.path").toString() + storageName); setCachePath(sSettings->value("browser.profile.path").toString() + storageName); @@ -111,10 +113,15 @@ WebEngineProfile::~WebEngineProfile() } } -ProfileDialog *WebEngineProfile::dialog() +QString WebEngineProfile::name() const +{ + return m_name; +} + +ProfileView *WebEngineProfile::dialog() { if(m_profileDialog == nullptr) { - m_profileDialog = new ProfileDialog(this); + m_profileDialog = new ProfileView(this); } return m_profileDialog; } diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h index 4b36940..9a7be22 100644 --- a/src/webengine/webengineprofile.h +++ b/src/webengine/webengineprofile.h @@ -22,7 +22,7 @@ #define WEBENGINEPROFILE_H #include <QWebEngineProfile> -#include "forms/profiledialog.h" +#include "forms/profileview.h" class WebEngineProfile : public QWebEngineProfile { @@ -33,7 +33,9 @@ public: ~WebEngineProfile(); - ProfileDialog *dialog(); + QString name() const; + + ProfileView *dialog(); signals: @@ -41,7 +43,8 @@ public slots: void saveProfile(); private: - ProfileDialog *m_profileDialog = nullptr; + QString m_name; + ProfileView *m_profileDialog = nullptr; }; #endif // WEBENGINEPROFILE_H |