Verified Commit 9c01f6b2 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Move homepage and initialUrl logic to tabsModel

parent 7f55a3a8
......@@ -109,6 +109,16 @@ void BrowserManager::setSearchBaseUrl(const QString &searchBaseUrl)
emit searchBaseUrlChanged();
}
QString BrowserManager::initialUrl() const
{
return m_initialUrl;
}
void BrowserManager::setInitialUrl(const QString &initialUrl)
{
m_initialUrl = initialUrl;
}
QSettings *BrowserManager::settings() const
{
return m_settings;
......
......@@ -46,6 +46,8 @@ class BrowserManager : public QObject
Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY
searchBaseUrlChanged)
Q_PROPERTY(QString initialUrl READ initialUrl WRITE setInitialUrl NOTIFY initialUrlChanged)
public:
BrowserManager(QObject *parent = nullptr);
~BrowserManager() override;
......@@ -60,6 +62,9 @@ public:
QSettings* settings() const;
QString initialUrl() const;
void setInitialUrl(const QString &initialUrl);
signals:
void updated();
void bookmarksChanged();
......@@ -67,6 +72,7 @@ signals:
void homepageChanged();
void searchBaseUrlChanged();
void initialUrlChanged();
public slots:
void reload();
......@@ -85,6 +91,8 @@ private:
UrlModel *m_history = nullptr;
QSettings *m_settings;
QString m_initialUrl;
static BrowserManager *s_instance;
};
......
......@@ -68,14 +68,4 @@ Repeater {
tabs.tabsModel.setTab(index, url)
}
}
Component.onCompleted: {
if (!privateTabsMode && !initialUrl && tabsModel.rowCount() === 1 && tabsModel.tabUrl(0) === "about:blank")
tabsModel.load(BrowserManager.homepage);
else if (initialUrl) {
tabsModel.newTab(initialUrl)
} else {
console.log("in private mode, not loading homepage")
}
}
}
......@@ -350,16 +350,4 @@ Kirigami.ApplicationWindow {
webBrowser.pageStack.pop();
}
}
Component.onCompleted: {
if (!webappcontainer) {
if (initialUrl) {
regularTabs.tabsModel.newTab(initialUrl);
}
} else {
if (initialUrl) {
regularTabs.tabsModel.load(initialUrl);
}
}
}
}
......@@ -65,10 +65,9 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
// initial url command line parameter
QUrl initialUrl;
QString initialUrl;
if (!parser.positionalArguments().isEmpty())
initialUrl = QUrl::fromUserInput(parser.positionalArguments().first());
engine.rootContext()->setContextProperty("initialUrl", initialUrl.url());
initialUrl = QUrl::fromUserInput(parser.positionalArguments().first()).toString();
engine.rootContext()->setContextProperty("webappcontainer", parser.isSet("webapp-container"));
......@@ -82,9 +81,11 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
return static_cast<QObject *>(new AngelFish::UrlUtils());
});
AngelFish::BrowserManager::instance()->setInitialUrl(initialUrl);
// Browser Manager
qmlRegisterSingletonType<AngelFish::BrowserManager>("org.kde.mobile.angelfish", 1, 0, "BrowserManager", [](QQmlEngine *, QJSEngine *) -> QObject * {
return static_cast<QObject *>(new AngelFish::BrowserManager());
return static_cast<QObject *>(AngelFish::BrowserManager::instance());
});
// Load QML
......
......@@ -30,7 +30,14 @@
TabsModel::TabsModel(QObject *parent) : QAbstractListModel(parent) {
// We can only do this once we know whether we are in private mode or not
connect(this, &TabsModel::privateModeChanged, [&] {
loadTabs();
qDebug() << "initialUrl" << AngelFish::BrowserManager::instance()->initialUrl();
if (AngelFish::BrowserManager::instance()->initialUrl().isEmpty()) {
if (!loadTabs() && m_tabs.first().url() == QLatin1String("about:blank") && !m_privateMode) {
load(AngelFish::BrowserManager::instance()->homepage());
}
} else {
load(AngelFish::BrowserManager::instance()->initialUrl());
}
});
connect(this, &TabsModel::currentTabChanged, [this] {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment