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

remove unused classes

parent 19d0fbab
......@@ -4,22 +4,22 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test Sql)
include_directories(../src)
ecm_add_test(urlmodeltest.cpp ../src/urlmodel.cpp
TEST_NAME urlmodeltest
LINK_LIBRARIES Qt5::Test
)
#ecm_add_test(urlmodeltest.cpp ../src/urlmodel.cpp
# TEST_NAME urlmodeltest
# LINK_LIBRARIES Qt5::Test
#)
ecm_add_test(useragenttest.cpp ../src/useragent.cpp
TEST_NAME useragenttest
LINK_LIBRARIES Qt5::Test
)
ecm_add_test(browsermanagertest.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp ../src/urlmodel.cpp ../src/urlutils.cpp
ecm_add_test(browsermanagertest.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp ../src/urlutils.cpp
TEST_NAME browsermanagertest
LINK_LIBRARIES Qt5::Test Qt5::Sql
)
ecm_add_test(tabsmodeltest.cpp ../src/tabsmodel.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp ../src/urlmodel.cpp
ecm_add_test(tabsmodeltest.cpp ../src/tabsmodel.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp
TEST_NAME tabsmodeltest
LINK_LIBRARIES Qt5::Test Qt5::Sql
)
......@@ -4,8 +4,6 @@ set(angelfish_SRCS
dbmanager.cpp
bookmarkshistorymodel.cpp
sqlquerymodel.cpp
urlmodel.cpp
urlfilterproxymodel.cpp
urlutils.cpp
useragent.cpp
tabsmodel.cpp
......
......@@ -37,41 +37,17 @@ BrowserManager::BrowserManager(QObject *parent) : QObject(parent), m_settings(ne
BrowserManager::~BrowserManager()
{
history()->save();
bookmarks()->save();
}
UrlModel *BrowserManager::bookmarks()
{
// qDebug() << "BookmarksManager::bookmarks()";
if (!m_bookmarks) {
m_bookmarks = new UrlModel(QStringLiteral("bookmarks.json"), this);
m_bookmarks->load();
}
return m_bookmarks;
}
UrlModel *BrowserManager::history()
{
// qDebug() << "BrowserManager::history()";
if (!m_history) {
m_history = new UrlModel(QStringLiteral("history.json"), this);
m_history->load();
}
return m_history;
}
void BrowserManager::addBookmark(const QVariantMap &bookmarkdata)
{
qDebug() << "Add bookmark";
qDebug() << " data: " << bookmarkdata;
bookmarks()->add(QJsonObject::fromVariantMap(bookmarkdata));
m_dbmanager.addBookmark(bookmarkdata);
}
void BrowserManager::removeBookmark(const QString &url)
{
bookmarks()->remove(url);
m_dbmanager.removeBookmark(url);
}
......@@ -79,15 +55,11 @@ void BrowserManager::addToHistory(const QVariantMap &pagedata)
{
// qDebug() << "Add History";
// qDebug() << " data: " << pagedata;
history()->add(QJsonObject::fromVariantMap(pagedata));
emit historyChanged();
m_dbmanager.addToHistory(pagedata);
}
void BrowserManager::removeFromHistory(const QString &url)
{
history()->remove(url);
emit historyChanged();
m_dbmanager.removeFromHistory(url);
}
......
......@@ -25,7 +25,6 @@
#include <QObject>
#include "dbmanager.h"
#include "urlmodel.h"
class QSettings;
......@@ -40,9 +39,6 @@ class BrowserManager : public QObject
{
Q_OBJECT
Q_PROPERTY(QAbstractListModel *bookmarks READ bookmarks NOTIFY bookmarksChanged)
Q_PROPERTY(QAbstractListModel *history READ history NOTIFY historyChanged)
Q_PROPERTY(QString homepage READ homepage WRITE setHomepage NOTIFY homepageChanged)
Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY
searchBaseUrlChanged)
......@@ -54,9 +50,6 @@ public:
static BrowserManager *instance();
UrlModel *bookmarks();
UrlModel *history();
QString homepage();
QString searchBaseUrl();
......@@ -67,8 +60,6 @@ public:
signals:
void updated();
void bookmarksChanged();
void historyChanged();
void homepageChanged();
void searchBaseUrlChanged();
......@@ -95,8 +86,6 @@ private:
DBManager m_dbmanager;
UrlModel *m_bookmarks = nullptr;
UrlModel *m_history = nullptr;
QSettings *m_settings;
QString m_initialUrl;
......
......@@ -29,8 +29,6 @@
#include "bookmarkshistorymodel.h"
#include "browsermanager.h"
#include "tabsmodel.h"
#include "urlfilterproxymodel.h"
#include "urlmodel.h"
#include "urlutils.h"
#include "useragent.h"
......@@ -76,7 +74,6 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
// Exported types
qmlRegisterType<BookmarksHistoryModel>("org.kde.mobile.angelfish", 1, 0, "BookmarksHistoryModel");
qmlRegisterType<UrlFilterProxyModel>("org.kde.mobile.angelfish", 1, 0, "UrlFilterProxyModel");
qmlRegisterType<UserAgent>("org.kde.mobile.angelfish", 1, 0, "UserAgentGenerator");
qmlRegisterType<TabsModel>("org.kde.mobile.angelfish", 1, 0, "TabsModel");
......
......@@ -22,6 +22,7 @@
#include <QUrl>
#include <QStandardPaths>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QDir>
......
/***************************************************************************
* *
* Copyright 2019 Simon Schmeisser <s.schmeisser@gmx.net> *
* *
* 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 "urlfilterproxymodel.h"
#include "browsermanager.h"
#include <QDateTime>
#include "urlmodel.h"
using namespace AngelFish;
UrlFilterProxyModel::UrlFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{
setFilterCaseSensitivity(Qt::CaseInsensitive);
connect(this, &UrlFilterProxyModel::sourceModelChanged, this, [this] {
sort(0, Qt::DescendingOrder);
});
}
bool UrlFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return (sourceModel()->data(index, UrlModel::url).toString().contains(filterRegExp())
|| sourceModel()->data(index, UrlModel::title).toString().contains(filterRegExp()));
}
bool UrlFilterProxyModel::lessThan(const QModelIndex &source_left,
const QModelIndex &source_right) const
{
auto leftDate = QDateTime::fromString(
sourceModel()->data(source_left, UrlModel::lastVisited).toString(), Qt::ISODate);
auto rightDate = QDateTime::fromString(
sourceModel()->data(source_right, UrlModel::lastVisited).toString(), Qt::ISODate);
return leftDate < rightDate;
}
/***************************************************************************
* *
* Copyright 2019 Simon Schmeisser <s.schmeisser@gmx.net> *
* *
* 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 URLFILTERPROXYMODEL_H
#define URLFILTERPROXYMODEL_H
#include <QtCore/QSortFilterProxyModel>
#include <QAbstractItemModel>
namespace AngelFish {
class UrlFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
UrlFilterProxyModel(QObject *parent = nullptr);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
signals:
void sourceModelChanged();
};
} // namespace
#endif // URLFILTERPROXYMODEL_H
/***************************************************************************
* *
* Copyright 2014-2015 Sebastian Kügler <sebas@kde.org> *
* *
* 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 "urlmodel.h"
#include <QDebug>
#include <QByteArray>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfo>
//#include <QIcon>
#include <QStandardPaths>
#include <QJsonDocument>
using namespace AngelFish;
UrlModel::UrlModel(const QString &fileName, QObject *parent)
: QAbstractListModel(parent), m_fileName(fileName)
{
m_roleNames.insert(url, "url");
m_roleNames.insert(title, "title");
m_roleNames.insert(icon, "icon");
m_roleNames.insert(preview, "preview");
m_roleNames.insert(lastVisited, "lastVisited");
m_roleNames.insert(bookmarked, "bookmarked");
// m_fakeData = fakeData();
// setSourceData(&m_fakeData);
// save();
}
void UrlModel::setSourceData(QJsonArray &data)
{
if (m_data != data) {
m_data = data;
// modelReset(); ??
}
}
QJsonArray UrlModel::sourceData() const
{
return m_data;
}
QHash<int, QByteArray> UrlModel::roleNames() const
{
return m_roleNames;
}
int UrlModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
if (m_data.isEmpty()) {
return 0;
}
return m_data.size();
}
QVariant UrlModel::data(const QModelIndex &index, int role) const
{
if (index.isValid()) {
QJsonObject currentData = m_data.at(index.row()).toObject();
switch (role) {
case lastVisited:
return QDateTime::fromString(currentData.value(key(role)).toString(), Qt::ISODate);
case bookmarked:
return currentData.value(key(role)).toBool();
}
if (currentData.value(key(role)).isUndefined()) {
return QVariant();
}
return currentData.value(key(role)).toString();
}
return QVariant();
}
void UrlModel::update()
{
// FIXME: Can we be more fine-grained, please?
beginResetModel();
endResetModel();
// emit QAbstractItemModel::modelReset();
// auto topleft = index(0);
// auto bottomright = index(rowCount(topleft));
// emit dataChanged(topleft, bottomright);
}
bool UrlModel::updateIcon(const QString &url, const QString &iconSource)
{
qDebug() << "updateIcon: " << url << " " << iconSource;
bool found = false;
for (int i = 0; i < m_data.count(); i++) {
const QString u = m_data.at(i).toObject()[key(UrlModel::url)].toString();
if (u == url) {
auto obj = m_data[i].toObject();
obj[key(UrlModel::icon)] = iconSource;
m_data[i] = obj;
emit dataChanged(index(i), index(i), { UrlModel::Roles::icon });
found = true;
}
}
return found;
}
QString UrlModel::filePath() const
{
QFileInfo fi(m_fileName);
if (fi.isAbsolute()) {
return m_fileName;
}
return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
+ QStringLiteral("/angelfish/") + m_fileName;
}
bool UrlModel::load()
{
QFile jsonFile(filePath());
if (!jsonFile.exists()) {
return false;
}
if (!jsonFile.open(QIODevice::ReadOnly)) {
qDebug() << "Could not open" << m_fileName;
return false;
}
// QJsonDocument jdoc = QJsonDocument::fromBinaryData(jsonFile.readAll());
QJsonDocument jdoc = QJsonDocument::fromJson(jsonFile.readAll());
jsonFile.close();
qDebug() << "Loaded from file:" << jdoc.array().count() << filePath();
QJsonArray plugins = jdoc.array();
setSourceData(plugins);
return true;
}
bool UrlModel::save()
{
QVariantMap vm;
vm[QStringLiteral("Version")] = QStringLiteral("1.0");
vm[QStringLiteral("Timestamp")] = QDateTime::currentMSecsSinceEpoch();
QJsonArray urls;
for (const auto &url : qAsConst(m_data)) {
urls << url;
}
QJsonDocument jdoc;
jdoc.setArray(urls);
QString destfile = m_fileName;
QString destdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
+ QStringLiteral("/angelfish/");
QDir dir(destdir);
const QFileInfo fi(m_fileName);
if (!fi.isAbsolute()) {
destfile = destdir + m_fileName;
}
if (!dir.mkpath(".")) {
qDebug() << "Destdir doesn't exist and I can't create it: " << destdir;
return false;
}
QFile file(destfile);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Failed to open " << destfile;
return false;
}
file.write(jdoc.toJson());
// file.write(jdoc.toBinaryData());
qWarning() << "Wrote " << destfile << " (" << urls.count() << " urls) "; // << jdoc.toJson();
return true;
}
QString UrlModel::key(int role) const
{
return QString::fromLocal8Bit(m_roleNames[role]);
}
void UrlModel::add(const QJsonObject &data)
{
int i = 0;
for (const auto &urldata : qAsConst(m_data)) {
if (urldata == data) {
if (i + 1 < m_data.size()) {
beginMoveRows(QModelIndex(), i, i, QModelIndex(), m_data.size());
m_data.removeAt(i);
m_data.append(data);
endMoveRows();
} else {
// Qt Model Api does not allow overlapping moves, so we need to make sure
// not to move down the last entry
m_data[i] = data;
}
// notify about lastVisited changed
emit dataChanged(index(m_data.size()), index(m_data.size()));
return;
}
++i;
}
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append(data);
endInsertRows();
save();
}
void UrlModel::remove(const QString &url)
{
for (int i = 0; i < m_data.count(); i++) {
const QString u = m_data.at(i).toObject()[key(UrlModel::url)].toString();
if (u == url) {
beginRemoveRows(QModelIndex(), i, i);
m_data.removeAt(i);
endRemoveRows();
// int n = m_data.count();
// qDebug() << "!!! Removed: " << url << " now" << m_data.count() << " was " << n;
save();
return;
}
}
}
/***************************************************************************
* *
* Copyright 2014-2015 Sebastian Kügler <sebas@kde.org> *
* *
* 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 URLMODEL_H
#define URLMODEL_H
#include <QAbstractListModel>
#include <QJsonArray>
#include <QJsonObject>
namespace AngelFish {
class UrlModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles { url = Qt::UserRole + 1, title, icon, preview, lastVisited, bookmarked };
explicit UrlModel(const QString &filename, QObject *parent = nullptr);
void setSourceData(QJsonArray &data);
QJsonArray sourceData() const;
QString key(int role) const;
bool load();
bool save();
void add(const QJsonObject &data);
void remove(const QString &url);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
void update();
Q_INVOKABLE bool updateIcon(const QString &url, const QString &iconSource);
QJsonArray fakeData();
QString filePath() const;
private:
QJsonArray m_data;
QHash<int, QByteArray> m_roleNames;
QString m_fileName;
};
} // namespace
#endif // URLMODEL_H
......@@ -25,8 +25,6 @@
#include <QObject>
#include "urlmodel.h"
namespace AngelFish {
/**
* @class UrlUtils
......
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