diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-11 15:36:14 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-11 15:36:14 +0100 |
commit | 59aff17b7ff1517dc74537444dc272f8080fad3f (patch) | |
tree | 2acf362513d6a518e1274e96b97aa8de91ea03a3 | |
parent | Added URL positional argument (diff) | |
download | smolbote-59aff17b7ff1517dc74537444dc272f8080fad3f.tar.xz |
Window title bar gets updated
-rw-r--r-- | src/browser.cpp | 12 | ||||
-rw-r--r-- | src/browser.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/mainwindow.cpp | 21 | ||||
-rw-r--r-- | src/mainwindow.h | 4 | ||||
-rw-r--r-- | src/qt-simplebrowser.pro | 6 | ||||
-rw-r--r-- | src/settings.cpp | 18 | ||||
-rw-r--r-- | src/settings.h | 24 | ||||
-rw-r--r-- | test/config.ini | 2 |
9 files changed, 69 insertions, 28 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 7ccd13a..cc68174 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -1,11 +1,11 @@ #include "browser.h"
#include "mainwindow.h"
+#include "settings.h"
#include <QtWebEngine>
Browser::Browser(QString configPath, QObject *parent) : QObject(parent)
{
- // TODO Read Profile
- m_settings = new QSettings(configPath, QSettings::IniFormat, this);
+ Settings::setFilepath(configPath);
// TODO Restore previous session
@@ -14,9 +14,6 @@ Browser::Browser(QString configPath, QObject *parent) : QObject(parent) Browser::~Browser()
{
- // TODO Save Profile
- m_settings->sync();
-
// TODO Save session
// cleanup
@@ -25,11 +22,6 @@ Browser::~Browser() }
-QSettings* Browser::settings()
-{
- return m_settings;
-}
-
QVector<MainWindow*> Browser::windows()
{
return m_windows;
diff --git a/src/browser.h b/src/browser.h index c63d56f..938acda 100644 --- a/src/browser.h +++ b/src/browser.h @@ -3,7 +3,6 @@ #include <QObject>
#include <QVector>
-#include <QSettings>
class MainWindow;
class Browser : public QObject
@@ -14,8 +13,6 @@ public: explicit Browser(QString configPath, QObject *parent = 0);
~Browser();
- QSettings* settings();
-
// what is windows() useful for?
QVector<MainWindow*> windows();
void addWindow(MainWindow* window);
@@ -24,7 +21,6 @@ public slots: void removeWindow(MainWindow* window);
private:
- QSettings *m_settings;
QVector<MainWindow*> m_windows;
};
diff --git a/src/main.cpp b/src/main.cpp index b45fad4..f8c9c7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,12 +26,12 @@ int main(int argc, char *argv[]) if(parser.positionalArguments().length() > 0) {
QUrl url = QUrl::fromUserInput(parser.positionalArguments().at(0));
if(url.isValid()) {
- instance.addWindow(new MainWindow(instance.settings(), url));
+ instance.addWindow(new MainWindow(url));
} else {
- instance.addWindow(new MainWindow(instance.settings()));
+ instance.addWindow(new MainWindow());
}
} else {
- instance.addWindow(new MainWindow(instance.settings()));
+ instance.addWindow(new MainWindow());
}
return app.exec();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7987a87..91d098f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,9 +1,9 @@ #include "mainwindow.h"
#include "ui_mainwindow.h"
-
+#include "settings.h"
#include <QMenu>
-MainWindow::MainWindow(QSettings *settings, QUrl defaultUrl, QWidget *parent) :
+MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
navigationToolBar(new QToolBar(this)),
@@ -11,10 +11,11 @@ MainWindow::MainWindow(QSettings *settings, QUrl defaultUrl, QWidget *parent) : tabBar(new WebViewTabBar(this)),
urlLineEdit(new QLineEdit(navigationToolBar))
{
- settings->beginGroup("defaults");
+ Settings settings;
+ settings.beginGroup("defaults");
ui->setupUi(this);
- resize(settings->value("width", 800).toInt(), settings->value("height", 600).toInt());
+ resize(settings.value("width", 800).toInt(), settings.value("height", 600).toInt());
// Populate the menu bar
// Browser menu - with new window, new tab, open and quit
@@ -39,9 +40,9 @@ MainWindow::MainWindow(QSettings *settings, QUrl defaultUrl, QWidget *parent) : if(!defaultUrl.isEmpty())
createNewTab(defaultUrl);
else
- createNewTab(settings->value("url", QUrl("http://duckduckgo.com")).toUrl());
+ createNewTab(settings.value("url", QUrl("http://duckduckgo.com")).toUrl());
- settings->endGroup(); // "defaults"
+ settings.endGroup(); // "defaults"
}
MainWindow::~MainWindow()
@@ -62,7 +63,9 @@ void MainWindow::handleTabChanged(QWebEngineView *view) disconnect(centralWidget());
setCentralWidget(view);
connect(view, SIGNAL(urlChanged(QUrl)), this, SLOT(handleUrlUpdated(QUrl)));
+ connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
this->handleUrlUpdated(view->url());
+ this->handleTitleUpdated(view->title());
}
void MainWindow::handleUrlChanged()
@@ -74,3 +77,9 @@ void MainWindow::handleUrlUpdated(const QUrl &url) {
urlLineEdit->setText(url.toString());
}
+
+void MainWindow::handleTitleUpdated(const QString &title)
+{
+ Settings settings;
+ setWindowTitle(title + settings.value("defaults/title", "qtwebenginebrowser").toString());
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h index a130087..0ad24b0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -7,7 +7,6 @@ #include <QWebEngineView>
#include <QUrl>
#include "widgets/webviewtabbar.h"
-#include <QSettings>
namespace Ui {
class MainWindow;
@@ -18,7 +17,7 @@ class MainWindow : public QMainWindow Q_OBJECT
public:
- explicit MainWindow(QSettings *settings, QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
+ explicit MainWindow(QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
~MainWindow();
public slots:
@@ -28,6 +27,7 @@ private slots: void handleTabChanged(QWebEngineView *view);
void handleUrlChanged();
void handleUrlUpdated(const QUrl &url);
+ void handleTitleUpdated(const QString &title);
private:
Ui::MainWindow *ui;
diff --git a/src/qt-simplebrowser.pro b/src/qt-simplebrowser.pro index 65dcca6..33b960f 100644 --- a/src/qt-simplebrowser.pro +++ b/src/qt-simplebrowser.pro @@ -14,10 +14,12 @@ TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ browser.cpp \ - widgets/webviewtabbar.cpp + widgets/webviewtabbar.cpp \ + settings.cpp HEADERS += mainwindow.h \ browser.h \ - widgets/webviewtabbar.h + widgets/webviewtabbar.h \ + settings.h FORMS += mainwindow.ui diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..0122f8f --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,18 @@ +#include "settings.h" + +QString Settings::_path = QString(""); + +Settings::Settings(QObject *parent) : + QSettings(_path, QSettings::IniFormat, parent) +{ +} + +Settings::~Settings() +{ + this->sync(); +} + +void Settings::setFilepath(const QString &path) +{ + _path = path; +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..146bfa1 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,24 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include <QSettings> + + +class Settings : public QSettings +{ + Q_OBJECT +public: + explicit Settings(QObject *parent = 0); + ~Settings(); + + static void setFilepath(const QString &path); + +signals: + +public slots: + +private: + static QString _path; +}; + +#endif // SETTINGS_H diff --git a/test/config.ini b/test/config.ini index e65e15c..71e308d 100644 --- a/test/config.ini +++ b/test/config.ini @@ -1,5 +1,5 @@ [defaults] -title=quill +title=" -- QtWebEngine" url=https://duckduckgo.com width=1280 height=720 |