Commit 55481249 authored by Rinigus Saar's avatar Rinigus Saar
Browse files

make suggested changes and add missing copyright statements

parent 75ad92ea
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#include "bookmarkshistorymodel.h"
#include "browsermanager.h"
......@@ -5,7 +27,7 @@
#include <QDebug>
#include <QSqlError>
#define QUERY_LIMIT 1000
constexpr int QUERY_LIMIT=1000;
BookmarksHistoryModel::BookmarksHistoryModel()
{
......
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#ifndef BOOKMARKSHISTORYMODEL_H
#define BOOKMARKSHISTORYMODEL_H
......
......@@ -28,9 +28,9 @@
BrowserManager *BrowserManager::s_instance = nullptr;
BrowserManager::BrowserManager(QObject *parent) : QObject(parent), m_settings(new QSettings(this))
BrowserManager::BrowserManager(QObject *parent) : QObject(parent), m_dbmanager(new DBManager), m_settings(new QSettings(this))
{
connect(&m_dbmanager, &DBManager::databaseTableChanged, this, &BrowserManager::databaseTableChanged);
connect(m_dbmanager, &DBManager::databaseTableChanged, this, &BrowserManager::databaseTableChanged);
}
BrowserManager::~BrowserManager()
......@@ -41,34 +41,34 @@ void BrowserManager::addBookmark(const QVariantMap &bookmarkdata)
{
qDebug() << "Add bookmark";
qDebug() << " data: " << bookmarkdata;
m_dbmanager.addBookmark(bookmarkdata);
m_dbmanager->addBookmark(bookmarkdata);
}
void BrowserManager::removeBookmark(const QString &url)
{
m_dbmanager.removeBookmark(url);
m_dbmanager->removeBookmark(url);
}
void BrowserManager::addToHistory(const QVariantMap &pagedata)
{
// qDebug() << "Add History";
// qDebug() << " data: " << pagedata;
m_dbmanager.addToHistory(pagedata);
m_dbmanager->addToHistory(pagedata);
}
void BrowserManager::removeFromHistory(const QString &url)
{
m_dbmanager.removeFromHistory(url);
m_dbmanager->removeFromHistory(url);
}
void BrowserManager::lastVisited(const QString &url)
{
m_dbmanager.lastVisited(url);
m_dbmanager->lastVisited(url);
}
void BrowserManager::updateIcon(const QString &url, const QString &iconSource)
{
m_dbmanager.updateIcon(url, iconSource);
m_dbmanager->updateIcon(url, iconSource);
}
void BrowserManager::setHomepage(const QString &homepage)
......
......@@ -83,7 +83,7 @@ private:
// BrowserManager should only be createdd by calling the instance() function
BrowserManager(QObject *parent = nullptr);
DBManager m_dbmanager;
DBManager *m_dbmanager;
QSettings *m_settings;
......
......@@ -44,10 +44,12 @@ DBManager::DBManager(QObject *parent) : QObject(parent)
QSqlDatabase database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
database.setDatabaseName(dbname);
if (!database.open()) {
qCritical() << "Failed to open database" << dbname;
throw std::runtime_error("Failed to open database " + dbname.toStdString());
}
if (!migrate()) {
qCritical() << "Failed to initialize or migrate the schema in" << dbname;
throw std::runtime_error("Failed to initialize or migrate the schema in " + dbname.toStdString());
}
......
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#include "iconimageprovider.h"
#include <QByteArray>
......@@ -31,6 +53,7 @@ QString IconImageProvider::storeImage(const QString &iconSource)
QLatin1String prefix_favicon = QLatin1String("image://favicon/");
if (!iconSource.startsWith(prefix_favicon)) {
// don't know what to do with it, return as it is
qWarning() << Q_FUNC_INFO << "Don't know how to store image" << iconSource;
return iconSource;
}
......@@ -56,7 +79,7 @@ QString IconImageProvider::storeImage(const QString &iconSource)
query_check.finish();
// Store new icon
QQuickImageProvider *provider = dynamic_cast<QQuickImageProvider *>(s_engine->imageProvider("favicon"));
QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(s_engine->imageProvider("favicon"));
if (provider == nullptr) {
qWarning() << Q_FUNC_INFO << "Failed to load image provider" << url;
return iconSource; // as something is wrong
......@@ -66,22 +89,27 @@ QString IconImageProvider::storeImage(const QString &iconSource)
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
QSize sz_requested;
QSize sz_obtained;
QSize szRequested;
QSize szObtained;
QString providerIconName = iconSource.mid(prefix_favicon.size());
if (provider->imageType() == QQmlImageProviderBase::Image) {
QImage image = provider->requestImage(providerIconName, &sz_obtained, sz_requested);
switch (provider->imageType()) {
case QQmlImageProviderBase::Image: {
QImage image = provider->requestImage(providerIconName, &szObtained, szRequested);
if (!image.save(&buffer, "PNG")) {
qWarning() << Q_FUNC_INFO << "Failed to save image" << url;
return iconSource; // as something is wrong
qWarning() << Q_FUNC_INFO << "Failed to save image" << url;
return iconSource; // as something is wrong
}
} else if (provider->imageType() == QQmlImageProviderBase::Pixmap) {
QPixmap image = provider->requestPixmap(providerIconName, &sz_obtained, sz_requested);
break;
}
case QQmlImageProviderBase::Pixmap: {
QPixmap image = provider->requestPixmap(providerIconName, &szObtained, szRequested);
if (!image.save(&buffer, "PNG")) {
qWarning() << Q_FUNC_INFO << "Failed to save pixmap" << url;
return iconSource; // as something is wrong
qWarning() << Q_FUNC_INFO << "Failed to save pixmap" << url;
return iconSource; // as something is wrong
}
} else {
break;
}
default:
qWarning() << Q_FUNC_INFO << "Unsupported image provider" << provider->imageType();
return iconSource; // as something is wrong
}
......@@ -113,7 +141,7 @@ QImage IconImageProvider::requestImage(const QString &id, QSize *size, const QSi
}
if (query.next()) {
QImage image = QImage::fromData( query.value(0).toByteArray() );
QImage image = QImage::fromData(query.value(0).toByteArray());
if (size) {
size->setHeight(image.height());
size->setWidth(image.width());
......
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
#ifndef ICONIMAGEPROVIDER_H
#define ICONIMAGEPROVIDER_H
......
// From https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
// Based on https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML
#include "sqlquerymodel.h"
......
// From https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
// Based on https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML
#ifndef SQLQUERYMODEL_H
#define SQLQUERYMODEL_H
......
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