aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-04-02 15:47:17 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2017-04-02 15:47:17 +0200
commitde247a9ccff6903c7c7b956dd4d85e4f0c3b9445 (patch)
tree1199f2a5b8493507a8ab26fe39a6e96ff5de4266 /src
parentMoved CookiesForm into the ProfileDialog (diff)
downloadsmolbote-de247a9ccff6903c7c7b956dd4d85e4f0c3b9445.tar.xz
Some code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp67
-rw-r--r--src/browser.h11
-rw-r--r--src/forms/aboutdialog.cpp12
-rw-r--r--src/main.cpp5
-rw-r--r--src/mainwindow.cpp44
-rw-r--r--src/mainwindow.h7
6 files changed, 82 insertions, 64 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 0135a4c..4df7eb9 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -30,6 +30,13 @@ Browser::Browser(int &argc, char *argv[]) :
// This lets the web view automatically scale on high-dpi displays.
setAttribute(Qt::AA_EnableHighDpiScaling);
+
+ m_settings = nullptr;
+ m_localServer = nullptr;
+
+ m_networkAccessManager = nullptr;
+ m_bookmarksManager = nullptr;
+ m_downloadManager = nullptr;
}
Browser::~Browser()
@@ -37,9 +44,17 @@ Browser::~Browser()
qDeleteAll(m_windows);
m_windows.clear();
- delete m_networkAccessManager;
- delete m_bookmarksManager;
- delete m_downloadManager;
+ if(m_networkAccessManager) {
+ delete m_networkAccessManager;
+ }
+
+ if(m_bookmarksManager) {
+ delete m_bookmarksManager;
+ }
+
+ if(m_downloadManager) {
+ delete m_downloadManager;
+ }
}
QString Browser::applicationLongVersion() const
@@ -51,23 +66,7 @@ QString Browser::applicationLongVersion() const
#endif
}
-/*!
- * Check if the settings are empty
- */
-void Browser::firstRun()
-{
- if(m_settings->isEmpty()) {
- // There are no keys in the settings
- QMessageBox::information(0,
- tr("Configuration is empty"),
- tr("The configuration file <i>%1</i> is empty. Using default values").arg(m_settings->filePath()));
- }
-}
-
-/*!
- * Anything that needs to run after the QCommandLineParser but before showing a main window
- */
-bool Browser::preLaunch(QStringList urls)
+bool Browser::prepare(QStringList urls)
{
if(m_settings->value("browser.singleInstance", true).toBool()) {
QString serverName = m_settings->value("browser.localSocket", "smolbote-singlelock").toString();
@@ -98,6 +97,13 @@ bool Browser::preLaunch(QStringList urls)
}
}
+ if(m_settings->isEmpty()) {
+ // There are no keys in the settings
+ QMessageBox::information(0,
+ tr("Configuration is empty"),
+ tr("The configuration file <i>%1</i> is empty. Using default values").arg(m_settings->filePath()));
+ }
+
m_networkAccessManager = new QNetworkAccessManager();
m_bookmarksManager = new BookmarksWidget;
m_downloadManager = new DownloadsWidget;
@@ -187,6 +193,27 @@ void Browser::removeWindow(MainWindow *window)
m_windows.removeOne(window);
}
+WebEngineProfile* Browser::profile(const QString name)
+{
+ if(!m_profiles.contains(name)) {
+ // name can be empty --> off-the-record profile
+ if(name.isEmpty()) {
+ m_profiles.insert(name, new WebEngineProfile(this));
+ } else {
+ m_profiles.insert(name, new WebEngineProfile(name, this));
+ }
+
+ // TODO: UrlRequestInterceptor
+ // UrlRequestInterceptor *interceptor = new UrlRequestInterceptor(this);
+ // interceptor->setSubscription(blocklistManager);
+ // m_profile->setRequestInterceptor(interceptor);
+
+ connect(m_profiles[name], SIGNAL(downloadRequested(QWebEngineDownloadItem*)), downloads(), SLOT(addDownload(QWebEngineDownloadItem*)));
+ }
+
+ return m_profiles[name];
+}
+
void Browser::handleNewConnection()
{
QLocalSocket *socket = m_localServer->nextPendingConnection();
diff --git a/src/browser.h b/src/browser.h
index 9d75036..bb4a6bf 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -28,6 +28,7 @@
#include <QLocalServer>
#include "settings.h"
#include <QNetworkAccessManager>
+#include "webengine/webengineprofile.h"
#ifdef qApp
#undef qApp
@@ -47,8 +48,7 @@ public:
QString applicationLongVersion() const;
- void firstRun();
- bool preLaunch(QStringList urls);
+ bool prepare(QStringList urls);
static Browser *instance();
@@ -61,6 +61,8 @@ public:
void addWindow(MainWindow* window);
MainWindow *mainWindow();
+ WebEngineProfile *profile(const QString name);
+
public slots:
void removeWindow(MainWindow* window);
@@ -70,7 +72,10 @@ private slots:
private:
Settings *m_settings;
QLocalServer *m_localServer;
- QVector<MainWindow*> m_windows;
+
+ QVector<MainWindow *> m_windows;
+ QHash<QString, WebEngineProfile *> m_profiles;
+
QNetworkAccessManager *m_networkAccessManager;
BookmarksWidget *m_bookmarksManager;
DownloadsWidget *m_downloadManager;
diff --git a/src/forms/aboutdialog.cpp b/src/forms/aboutdialog.cpp
index 1edaac4..dd26e91 100644
--- a/src/forms/aboutdialog.cpp
+++ b/src/forms/aboutdialog.cpp
@@ -43,9 +43,15 @@ AboutDialog::AboutDialog(QWidget *parent) :
QLabel *detailsLabel = new QLabel(this);
detailsLabel->setWordWrap(true);
- detailsLabel->setText(tr("<p>"
- "Long version: %1<br>"
- "Configuration: %2"
+ detailsLabel->setText(tr("<h3>Version %1</h3>"
+ "<p>"
+ "Based on Qt " QT_VERSION_STR "<br>"
+#if defined __clang__
+ "Compiled with Clang " __clang_version__ "<br>"
+#elif defined __GNUC__
+ "Compiled with GCC " __VERSION__ "<br>"
+#endif
+ "Configuration lives in %2"
"</p>")
.arg(qApp->applicationLongVersion())
.arg(sSettings->filePath()));
diff --git a/src/main.cpp b/src/main.cpp
index a99e5de..964a226 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -45,12 +45,9 @@ int main(int argc, char *argv[])
parser.addOption(profileOption);
parser.process(app);
-
- // set config path
app.setConfigPath(parser.value(configOption));
- app.firstRun();
- if(!app.preLaunch(parser.positionalArguments())) {
+ if(!app.prepare(parser.positionalArguments())) {
return 0;
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 465d02a..5c6f0ca 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -73,8 +73,8 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
// Profile menu
QMenu *profileMenu = new QMenu(tr("Profile"), menuBar);
menuBar->addMenu(profileMenu);
- profileMenu->addAction(tr("View profile"), this, SLOT(execProfileEditor()));
- profileMenu->addAction(tr("Load profile"), this, SLOT(loadProfileGUI()));
+ profileMenu->addAction(tr("View profile"), this, SLOT(profileAction()));
+ profileMenu->addAction(tr("Load profile"), this, SLOT(loadProfile()));
//profileMenu->addAction(tr("Settings"));
profileMenu->addAction(tr("Cookies"), this, SLOT(cookiesAction()));
@@ -96,7 +96,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*)));
// Load profile
- loadProfile(sSettings->value("browser.profile.default").toString());
+ m_profile = qApp->profile(sSettings->value("browser.profile.default").toString());
// loading bar
ui->statusBar->addPermanentWidget(progressBar);
@@ -183,36 +183,20 @@ void MainWindow::about()
dlg->exec();
}
-void MainWindow::loadProfile(const QString &name)
+void MainWindow::loadProfile(const QString name)
{
- if(m_profile) {
- m_profile->deleteLater();
- }
-
if(name.isEmpty()) {
- //profileName = tr("Off the record");
- m_profile = new WebEngineProfile(this);
- qDebug("Creating off-the-record profile");
+ bool ok;
+ QString _name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok);
+ if(ok) {
+ m_profile = qApp->profile(_name);
+ } else {
+ return;
+ }
} else {
- //profileName = name;
- m_profile = new WebEngineProfile(name, this);
- qDebug("Using profile: %s", qUtf8Printable(m_profile->storageName()));
- }
-
- UrlRequestInterceptor *interceptor = new UrlRequestInterceptor(this);
- interceptor->setSubscription(blocklistManager);
- m_profile->setRequestInterceptor(interceptor);
- connect(m_profile, SIGNAL(downloadRequested(QWebEngineDownloadItem*)), Browser::instance()->downloads(), SLOT(addDownload(QWebEngineDownloadItem*)));
-}
-
-void MainWindow::loadProfileGUI()
-{
- bool ok;
- QString name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok);
- if(ok) {
- loadProfile(name);
- tabBar->setProfile(m_profile);
+ m_profile = qApp->profile(name);
}
+ tabBar->setProfile(m_profile);
}
void MainWindow::handleNewWindow(const QUrl &url)
@@ -256,7 +240,7 @@ void MainWindow::handleTitleUpdated(const QString &title)
setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->storageName()));
}
-void MainWindow::execProfileEditor()
+void MainWindow::profileAction()
{
m_profile->dialog()->showProfile();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9d858f5..2865fa9 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -47,20 +47,19 @@ public:
void addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget);
- void loadProfile(const QString &name);
-
public slots:
void addNewTab(const QUrl &url = QUrl(""));
void focusAddress();
+ void loadProfile(const QString name = "");
+
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void about();
- void loadProfileGUI();
- void execProfileEditor();
+ void profileAction();
void cookiesAction();
void handleNewWindow(const QUrl &url = QUrl(""));