Verified Commit 39d7b0c1 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳
Browse files

Reformat code

parent fc951d02
......@@ -31,13 +31,13 @@ constexpr int QUERY_LIMIT = 1000;
BookmarksHistoryModel::BookmarksHistoryModel()
{
connect(BrowserManager::instance(), &BrowserManager::databaseTableChanged,
this, &BookmarksHistoryModel::onDatabaseChanged);
connect(BrowserManager::instance(), &BrowserManager::databaseTableChanged, this, &BookmarksHistoryModel::onDatabaseChanged);
}
void BookmarksHistoryModel::setActive(bool a)
{
if (m_active == a) return;
if (m_active == a)
return;
m_active = a;
if (m_active)
setQuery();
......@@ -48,7 +48,8 @@ void BookmarksHistoryModel::setActive(bool a)
void BookmarksHistoryModel::setBookmarks(bool b)
{
if (m_bookmarks == b) return;
if (m_bookmarks == b)
return;
m_bookmarks = b;
setQuery();
emit bookmarksChanged();
......@@ -56,7 +57,8 @@ void BookmarksHistoryModel::setBookmarks(bool b)
void BookmarksHistoryModel::setHistory(bool h)
{
if (m_history == h) return;
if (m_history == h)
return;
m_history = h;
setQuery();
emit historyChanged();
......@@ -64,7 +66,8 @@ void BookmarksHistoryModel::setHistory(bool h)
void BookmarksHistoryModel::setFilter(const QString &f)
{
if (m_filter == f) return;
if (m_filter == f)
return;
m_filter = f;
setQuery();
emit filterChanged();
......@@ -72,8 +75,7 @@ void BookmarksHistoryModel::setFilter(const QString &f)
void BookmarksHistoryModel::onDatabaseChanged(const QString &table)
{
if ( (table == QLatin1String("bookmarks") && m_bookmarks) ||
(table == QLatin1String("history") && m_history) )
if ((table == QLatin1String("bookmarks") && m_bookmarks) || (table == QLatin1String("history") && m_history))
setQuery();
}
......
......@@ -47,19 +47,30 @@ class BookmarksHistoryModel : public SqlQueryModel
public:
BookmarksHistoryModel();
bool active() const { return m_active; }
bool active() const
{
return m_active;
}
void setActive(bool a);
bool bookmarks() const { return m_bookmarks; }
bool bookmarks() const
{
return m_bookmarks;
}
void setBookmarks(bool b);
bool history() const { return m_history; }
bool history() const
{
return m_history;
}
void setHistory(bool h);
QString filter() const { return m_filter; }
QString filter() const
{
return m_filter;
}
void setFilter(const QString &f);
signals:
void activeChanged();
void bookmarksChanged();
......
......@@ -20,11 +20,11 @@
#include "browsermanager.h"
#include <QDebug>
#include <QUrl>
#include <QSettings>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSettings>
#include <QUrl>
BrowserManager *BrowserManager::s_instance = nullptr;
......@@ -108,8 +108,7 @@ QSettings *BrowserManager::settings() const
QString BrowserManager::searchBaseUrl()
{
return m_settings->value("browser/searchBaseUrl", "https://start.duckduckgo.com/?q=")
.toString();
return m_settings->value("browser/searchBaseUrl", "https://start.duckduckgo.com/?q=").toString();
}
BrowserManager *BrowserManager::instance()
......
......@@ -39,8 +39,7 @@ class BrowserManager : public QObject
Q_OBJECT
Q_PROPERTY(QString homepage READ homepage WRITE setHomepage NOTIFY homepageChanged)
Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY
searchBaseUrlChanged)
Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY searchBaseUrlChanged)
Q_PROPERTY(QString initialUrl READ initialUrl WRITE setInitialUrl NOTIFY initialUrlChanged)
......@@ -52,7 +51,7 @@ public:
QString homepage();
QString searchBaseUrl();
QSettings* settings() const;
QSettings *settings() const;
QString initialUrl() const;
void setInitialUrl(const QString &initialUrl);
......
......@@ -25,10 +25,10 @@
#include <QDateTime>
#include <QDebug>
#include <QStandardPaths>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QStandardPaths>
#include <QVariant>
#include <exception>
......@@ -36,10 +36,10 @@
#define DB_USER_VERSION 1
#define MAX_BROWSER_HISTORY_SIZE 3000
DBManager::DBManager(QObject *parent) : QObject(parent)
DBManager::DBManager(QObject *parent)
: QObject(parent)
{
QString dbname = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
+ QStringLiteral("/angelfish.sqlite");
QString dbname = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QStringLiteral("/angelfish.sqlite");
QSqlDatabase database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
database.setDatabaseName(dbname);
......@@ -72,7 +72,7 @@ int DBManager::version()
void DBManager::setVersion(int v)
{
QSqlQuery query;
query.prepare( QStringLiteral("PRAGMA user_version = %1").arg(v) );
query.prepare(QStringLiteral("PRAGMA user_version = %1").arg(v));
query.exec();
}
......@@ -124,9 +124,7 @@ bool DBManager::migrateTo1()
QString idx_bookmarks = QStringLiteral("CREATE UNIQUE INDEX idx_bookmarks_url ON bookmarks(url)");
QString idx_history = QStringLiteral("CREATE UNIQUE INDEX idx_history_url ON history(url)");
QString idx_icons = QStringLiteral("CREATE UNIQUE INDEX idx_icons_url ON icons(url)");
if (!execute(bookmarks) || !execute(idx_bookmarks) ||
!execute(history) || !execute(idx_history) ||
!execute(icons) || !execute(idx_icons) )
if (!execute(bookmarks) || !execute(idx_bookmarks) || !execute(history) || !execute(idx_history) || !execute(icons) || !execute(idx_icons))
return false;
setVersion(1);
......@@ -136,14 +134,16 @@ bool DBManager::migrateTo1()
void DBManager::trimHistory()
{
execute(QStringLiteral("DELETE FROM history WHERE rowid NOT IN (SELECT rowid FROM history" \
" ORDER BY lastVisited DESC LIMIT %1)").arg(MAX_BROWSER_HISTORY_SIZE));
execute(QStringLiteral("DELETE FROM history WHERE rowid NOT IN (SELECT rowid FROM history"
" ORDER BY lastVisited DESC LIMIT %1)")
.arg(MAX_BROWSER_HISTORY_SIZE));
}
void DBManager::trimIcons()
{
execute(QStringLiteral("DELETE FROM icons WHERE url NOT IN " \
"(SELECT icon FROM history UNION SELECT icon FROM bookmarks)"));
execute(
QStringLiteral("DELETE FROM icons WHERE url NOT IN "
"(SELECT icon FROM history UNION SELECT icon FROM bookmarks)"));
}
void DBManager::addRecord(const QString &table, const QVariantMap &pagedata)
......@@ -153,11 +153,13 @@ void DBManager::addRecord(const QString &table, const QVariantMap &pagedata)
QString icon = pagedata.value("icon").toString();
qint64 lastVisited = QDateTime::currentSecsSinceEpoch();
if (url.isEmpty() || url == "about:blank") return;
if (url.isEmpty() || url == "about:blank")
return;
QSqlQuery query;
query.prepare(QStringLiteral("INSERT OR REPLACE INTO %1 (url, title, icon, lastVisited) " \
"VALUES (:url, :title, :icon, :lastVisited)").arg(table));
query.prepare(QStringLiteral("INSERT OR REPLACE INTO %1 (url, title, icon, lastVisited) "
"VALUES (:url, :title, :icon, :lastVisited)")
.arg(table));
query.bindValue(QStringLiteral(":url"), url);
query.bindValue(QStringLiteral(":title"), title);
query.bindValue(QStringLiteral(":icon"), icon);
......@@ -169,7 +171,8 @@ void DBManager::addRecord(const QString &table, const QVariantMap &pagedata)
void DBManager::removeRecord(const QString &table, const QString &url)
{
if (url.isEmpty()) return;
if (url.isEmpty())
return;
QSqlQuery query;
query.prepare(QStringLiteral("DELETE FROM %1 WHERE url = :url").arg(table));
......@@ -181,7 +184,8 @@ void DBManager::removeRecord(const QString &table, const QString &url)
void DBManager::updateIconRecord(const QString &table, const QString &url, const QString &iconSource)
{
if (url.isEmpty()) return;
if (url.isEmpty())
return;
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE %1 SET icon = :icon WHERE url = :url").arg(table));
......@@ -194,7 +198,8 @@ void DBManager::updateIconRecord(const QString &table, const QString &url, const
void DBManager::setLastVisitedRecord(const QString &table, const QString &url)
{
if (url.isEmpty()) return;
if (url.isEmpty())
return;
qint64 lastVisited = QDateTime::currentSecsSinceEpoch();
QSqlQuery query;
......
......@@ -24,8 +24,8 @@
#define DBMANAGER_H
#include <QObject>
#include <QString>
#include <QSqlQuery>
#include <QString>
/**
* @class DBManager
......
......@@ -22,23 +22,23 @@
#include "iconimageprovider.h"
#include <QByteArray>
#include <QBuffer>
#include <QByteArray>
#include <QDebug>
#include <QImage>
#include <QPixmap>
#include <QQmlApplicationEngine>
#include <QSqlError>
#include <QSqlQuery>
#include <QString>
#include <QQmlApplicationEngine>
// As there is only one instance of the IconImageProvider
// and icons are added into the database using static methods,
// engine has to be accessed via static property
QQmlApplicationEngine *IconImageProvider::s_engine;
IconImageProvider::IconImageProvider(QQmlApplicationEngine *engine) :
QQuickImageProvider(QQmlImageProviderBase::Image)
IconImageProvider::IconImageProvider(QQmlApplicationEngine *engine)
: QQuickImageProvider(QQmlImageProviderBase::Image)
{
s_engine = engine;
}
......@@ -128,7 +128,7 @@ QString IconImageProvider::storeImage(const QString &iconSource)
return url;
}
QImage IconImageProvider::requestImage(const QString &id, QSize *size, const QSize &/*requestedSize*/)
QImage IconImageProvider::requestImage(const QString &id, QSize *size, const QSize & /*requestedSize*/)
{
QSqlQuery query;
query.prepare(QStringLiteral("SELECT icon FROM icons WHERE url LIKE :url LIMIT 1"));
......
......@@ -23,8 +23,8 @@
#ifndef ICONIMAGEPROVIDER_H
#define ICONIMAGEPROVIDER_H
#include <QQuickImageProvider>
#include <QQmlApplicationEngine>
#include <QQuickImageProvider>
class IconImageProvider : public QQuickImageProvider
{
......
......@@ -16,15 +16,15 @@
*/
#include <QApplication>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QUrl>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QtQml>
#include <QtWebEngine>
#include <KLocalizedString>
#include <KLocalizedContext>
#include <KLocalizedString>
#include "bookmarkshistorymodel.h"
#include "browsermanager.h"
......
......@@ -25,12 +25,12 @@
#include "sqlquerymodel.h"
#include <QDebug>
#include <QSqlField>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
SqlQueryModel::SqlQueryModel(QObject *parent) :
QSqlQueryModel(parent)
SqlQueryModel::SqlQueryModel(QObject *parent)
: QSqlQueryModel(parent)
{
}
......@@ -43,7 +43,7 @@ void SqlQueryModel::setQuery(const QSqlQuery &query)
void SqlQueryModel::generateRoleNames()
{
m_roleNames.clear();
for ( int i = 0; i < record().count(); i++ ) {
for (int i = 0; i < record().count(); i++) {
m_roleNames.insert(Qt::UserRole + i + 1, record().fieldName(i).toUtf8());
}
}
......@@ -62,4 +62,3 @@ QHash<int, QByteArray> SqlQueryModel::roleNames() const
{
return m_roleNames;
}
......@@ -19,16 +19,18 @@
#include "tabsmodel.h"
#include <QDebug>
#include <QUrl>
#include <QStandardPaths>
#include <QDir>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QDir>
#include <QStandardPaths>
#include <QUrl>
#include "browsermanager.h"
TabsModel::TabsModel(QObject *parent) : QAbstractListModel(parent) {
TabsModel::TabsModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(this, &TabsModel::currentTabChanged, [this] {
qDebug() << "Current tab changed to" << m_currentTab;
});
......@@ -41,10 +43,7 @@ TabsModel::TabsModel(QObject *parent) : QAbstractListModel(parent) {
QHash<int, QByteArray> TabsModel::roleNames() const
{
return {
{ RoleNames::UrlRole, QByteArrayLiteral("pageurl") },
{ RoleNames::IsMobileRole, QByteArrayLiteral("isMobile") }
};
return {{RoleNames::UrlRole, QByteArrayLiteral("pageurl")}, {RoleNames::IsMobileRole, QByteArrayLiteral("isMobile")}};
}
QVariant TabsModel::data(const QModelIndex &index, int role) const
......@@ -53,7 +52,7 @@ QVariant TabsModel::data(const QModelIndex &index, int role) const
return {};
}
switch(role) {
switch (role) {
case RoleNames::UrlRole:
return m_tabs.at(index.row()).url();
case RoleNames::IsMobileRole:
......@@ -73,7 +72,8 @@ int TabsModel::rowCount(const QModelIndex &parent) const
* @param index
* @return tab at the index
*/
TabState TabsModel::tab(int index) {
TabState TabsModel::tab(int index)
{
if (index < 0 && index >= m_tabs.count())
return {}; // index out of bounds
......@@ -90,22 +90,22 @@ TabState TabsModel::tab(int index) {
void TabsModel::loadInitialTabs()
{
if (!m_privateMode) {
loadTabs();
loadTabs();
}
m_tabsReadOnly = false;
if (!m_privateMode) {
if (BrowserManager::instance()->initialUrl().isEmpty()) {
if (BrowserManager::instance()->initialUrl().isEmpty()) {
if (m_tabs.first().url() == QStringLiteral("about:blank"))
setUrl(0, BrowserManager::instance()->homepage());
} else {
} else {
if (m_tabs.first().url() == QStringLiteral("about:blank"))
setUrl(0, BrowserManager::instance()->initialUrl());
setUrl(0, BrowserManager::instance()->initialUrl());
else
newTab(BrowserManager::instance()->initialUrl());
}
}
newTab(BrowserManager::instance()->initialUrl());
}
}
}
/**
......@@ -144,8 +144,7 @@ bool TabsModel::loadTabs()
{
if (!m_privateMode) {
beginResetModel();
QString input = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
+ QStringLiteral("/angelfish/tabs.json");
QString input = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QStringLiteral("/angelfish/tabs.json");
QFile inputFile(input);
if (!inputFile.exists()) {
......@@ -187,8 +186,7 @@ bool TabsModel::saveTabs() const
{
// only save if not in private mode
if (!m_privateMode && !m_tabsReadOnly) {
QString outputDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
+ QStringLiteral("/angelfish/");
QString outputDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QStringLiteral("/angelfish/");
QFile outputFile(outputDir + QStringLiteral("tabs.json"));
if (!QDir(outputDir).mkpath(".")) {
......@@ -205,7 +203,8 @@ bool TabsModel::saveTabs() const
for (const auto &tab : m_tabs) {
tabsArray.append(tab.toJson());
}
qDebug() << "Wrote to file" << outputFile.fileName() << "(" << tabsArray.count() << "urls" << ")";
qDebug() << "Wrote to file" << outputFile.fileName() << "(" << tabsArray.count() << "urls"
<< ")";
tabsStorage.insert(QLatin1String("tabs"), tabsArray);
tabsStorage.insert(QLatin1String("currentTab"), m_currentTab);
......@@ -258,7 +257,8 @@ void TabsModel::createEmptyTab()
* @param url
* @param isMobile
*/
void TabsModel::newTab(const QString &url) {
void TabsModel::newTab(const QString &url)
{
beginInsertRows({}, m_tabs.count(), m_tabs.count());
m_tabs.append(TabState(url, m_isMobileDefault));
......@@ -275,7 +275,8 @@ void TabsModel::newTab(const QString &url) {
* @brief TabsModel::closeTab removes the tab at the index, handles moving the tabs after it and sets a new currentTab
* @param index
*/
void TabsModel::closeTab(int index) {
void TabsModel::closeTab(int index)
{
if (index < 0 && index >= m_tabs.count())
return; // index out of bounds
......@@ -321,11 +322,10 @@ void TabsModel::setIsMobile(int index, bool isMobile)
m_tabs[index].setIsMobile(isMobile);
QModelIndex mindex = createIndex(index, index);
dataChanged(mindex, mindex, { RoleNames::IsMobileRole });
dataChanged(mindex, mindex, {RoleNames::IsMobileRole});
saveTabs();
}
void TabsModel::setUrl(int index, const QString &url)
{
qDebug() << "Setting URL:" << index << url << "tabs open" << m_tabs.count();
......@@ -335,7 +335,7 @@ void TabsModel::setUrl(int index, const QString &url)
m_tabs[index].setUrl(url);
QModelIndex mindex = createIndex(index, index);
dataChanged(mindex, mindex, { RoleNames::UrlRole });
dataChanged(mindex, mindex, {RoleNames::UrlRole});
saveTabs();
}
......@@ -375,7 +375,7 @@ TabState::TabState(const QString &url, const bool isMobile)
bool TabState::operator==(const TabState &other) const
{
return (m_url == other.url() && m_isMobile == other.isMobile());
return (m_url == other.url() && m_isMobile == other.isMobile());
}
QJsonObject TabState::toJson() const
......
......@@ -22,7 +22,8 @@
#include <QAbstractListModel>
#include <QJsonObject>
class TabState {
class TabState
{
public:
static TabState fromJson(const QJsonObject &obj);
QJsonObject toJson() const;
......@@ -51,10 +52,7 @@ class TabsModel : public QAbstractListModel
Q_PROPERTY(bool isMobileDefault READ isMobileDefault WRITE setIsMobileDefault NOTIFY isMobileDefaultChanged)
Q_PROPERTY(bool privateMode READ privateMode WRITE setPrivateMode NOTIFY privateModeChanged)
enum RoleNames {
UrlRole = Qt::UserRole + 1,
IsMobileRole
};
enum RoleNames { UrlRole = Qt::UserRole + 1, IsMobileRole };
public:
explicit TabsModel(QObject *parent = nullptr);
......
......@@ -23,13 +23,14 @@
#include "urlutils.h"
#include <QDebug>
#include <QUrl>
#include <QSettings>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSettings>
#include <QUrl>
UrlUtils::UrlUtils(QObject *parent) : QObject(parent)
UrlUtils::UrlUtils(QObject *parent)
: QObject(parent)
{
}
......@@ -52,7 +53,8 @@ QString UrlUtils::urlHostPort(const QString &url)
QUrl u(url);
QString r = u.host();
int p = u.port(-1);
if (p > 0) r = QStringLiteral("%1:%2").arg(r).arg(p);
if (p > 0)
r = QStringLiteral("%1:%2").arg(r).arg(p);
return r;
}
......@@ -60,4 +62,3 @@ QString UrlUtils::urlPath(const QString &url)
{
return QUrl::fromUserInput(url).path();
}
......@@ -41,7 +41,6 @@ public:
Q_INVOKABLE static QString urlScheme(const QString &url);
Q_INVOKABLE static QString urlHostPort(const QString &url);
Q_INVOKABLE static QString urlPath(const QString &url);
};
#endif // URLUTILS_H
#include "useragent.h"
#include <QtWebEngine/QtWebEngineVersion>
#include <QtWebEngine/QQuickWebEngineProfile>
#include <QtWebEngine/QtWebEngineVersion>
UserAgent::UserAgent(QObject *parent) : QObject(parent)
UserAgent::UserAgent(QObject *parent)
: QObject(parent)
{
}
QString UserAgent::userAgent() const
{
return QStringLiteral("Mozilla/5.0 (%1) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/%2 "
"Chrome/75.0.3770.116 %3 Safari/537.36")
.arg(m_isMobile ? QStringLiteral("Linux; Plasma Mobile, like Android 9.0")
: QStringLiteral("X11; Linux x86_64"))
.arg(QTWEBENGINE_VERSION_STR)
.arg(m_isMobile ? QStringLiteral("Mobile") : QStringLiteral("Desktop"));
return QStringLiteral(
"Mozilla/5.0 (%1) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/%2 "
"Chrome/75.0.3770.116 %3 Safari/537.36")
.arg(m_isMobile ? QStringLiteral("Linux; Plasma Mobile, like Android 9.0") : QStringLiteral("X11; Linux x86_64"))
.arg(QTWEBENGINE_VERSION_STR)
.arg(m_isMobile ? QStringLiteral("Mobile") : QStringLiteral("Desktop"));
}
bool UserAgent::isMobile() const
......
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