Commit a76bd5ac authored by Simon Schmeißer's avatar Simon Schmeißer
Browse files

Fix favicons in History and Bookmarks

... somewhat. There is no cache apparently so they will be gone after
restart. But at least they are displayed now.

Reason for updateIcon is that the icon might be set later than the "loading complete" signal

Also cleaned up UrlModel a bit
parent 8d0c6206
......@@ -89,7 +89,7 @@ ColumnLayout {
var request = new Object;// FIXME
request.url = currentWebView.url;
request.title = currentWebView.title;
request.iconSource = currentWebView.iconSource;
request.icon = currentWebView.icon;
request.bookmarked = true;
browserManager.addBookmark(request);
options.state = "hidden"
......
......@@ -42,10 +42,11 @@ Controls.ItemDelegate {
signal removed
Kirigami.Icon {
Image {
id: urlIcon
width: height
fillMode: Image.PreserveAspectFit
anchors {
left: parent.left
......@@ -55,7 +56,7 @@ Controls.ItemDelegate {
bottom: parent.bottom
margins: Kirigami.Units.smallSpacing
}
source: icon
source: model.icon ? model.icon : ""
}
......
......@@ -84,9 +84,15 @@ WebEngineView {
// contentView.state = "hidden";
// }
// }
Component.onCompleted: {
print("WebView completed.");
var settings = webEngineView.settings;
print("Settings: " + settings);
}
onIconChanged: {
if (icon)
browserManager.history.updateIcon(url, icon)
}
}
......@@ -108,7 +108,24 @@ void UrlModel::update()
//emit QAbstractItemModel::modelReset();
// auto topleft = index(0);
// auto bottomright = index(rowCount(topleft));
// emit dataChanged(topleft, bottomright);
// 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
......@@ -155,7 +172,7 @@ bool UrlModel::save()
QJsonArray urls;
Q_FOREACH (auto url, m_data) {
Q_FOREACH (const auto &url, m_data) {
urls << url;
}
......@@ -194,13 +211,14 @@ QString UrlModel::key(int role) const
void UrlModel::add(const QJsonObject &data)
{
foreach (auto urldata, m_data) {
foreach (const auto &urldata, m_data) {
if (urldata == data) {
return;
}
}
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append(data);
update();
endInsertRows();
}
void UrlModel::remove(const QString& url)
......@@ -208,10 +226,11 @@ 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;
update();
return;
}
}
......
......@@ -59,6 +59,7 @@ public:
virtual QVariant data(const QModelIndex &index, int role) const;
void update();
Q_INVOKABLE bool updateIcon(const QString &url, const QString &iconSource);
QJsonArray fakeData();
......
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