From cb5242f98c92852c9f1a6b80f6972498d0d4511e Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 17 Jan 2012 19:27:24 +0100 Subject: [PATCH] Using QImage for storing icons in database. - fixed issue on some pages when icon was shown correctly in locationbar, but not on tab - using QImage for storing icons will help to have BookmarksModel in separate thread - unfortunately, all currently saved icons won't be possible to load so I recommend erasing all icons (to not waste space in db) --- src/app/proxystyle.cpp | 9 +++++ src/app/proxystyle.h | 1 + src/app/qupzilla.cpp | 6 +-- src/bookmarks/bookmarksmanager.cpp | 6 +-- src/bookmarks/bookmarksmodel.cpp | 20 ++++++---- src/bookmarks/bookmarksmodel.h | 2 +- src/bookmarks/bookmarkstoolbar.cpp | 10 ++--- src/bookmarksimport/bookmarksimportdialog.cpp | 12 +++--- src/data/data/browsedata.db | Bin 20480 -> 20480 bytes src/opensearch/searchenginesmanager.cpp | 2 +- src/rss/rssmanager.cpp | 16 ++++---- src/sidebar/bookmarkssidebar.cpp | 2 +- src/tools/iconprovider.cpp | 35 +++++++++++------- src/tools/iconprovider.h | 14 ++++--- src/webview/webpage.cpp | 6 +++ src/webview/webview.cpp | 14 +++---- src/webview/webview.h | 1 - 17 files changed, 91 insertions(+), 65 deletions(-) diff --git a/src/app/proxystyle.cpp b/src/app/proxystyle.cpp index 7c10b0155..3b6c83cef 100644 --- a/src/app/proxystyle.cpp +++ b/src/app/proxystyle.cpp @@ -13,3 +13,12 @@ int ProxyStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWid return QProxyStyle::styleHint(hint, option, widget, returnData); } + +//int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const +//{ +// if (metric == PM_TabBarTabHSpace) { +// return 8; +// } + +// return QProxyStyle::pixelMetric(metric, option, widget); +//} diff --git a/src/app/proxystyle.h b/src/app/proxystyle.h index 1bad04def..01fe2b124 100644 --- a/src/app/proxystyle.h +++ b/src/app/proxystyle.h @@ -10,6 +10,7 @@ public: explicit ProxyStyle(); int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const; +// int pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const; signals: diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 95e836597..3d49bfbce 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -625,7 +625,7 @@ void QupZilla::aboutToShowBookmarksMenu() while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); - QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query.value(2).toByteArray())); if (title.length() > 40) { title.truncate(40); title += ".."; @@ -645,7 +645,7 @@ void QupZilla::aboutToShowBookmarksMenu() while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); - QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query.value(2).toByteArray())); if (title.length() > 40) { title.truncate(40); title += ".."; @@ -673,7 +673,7 @@ void QupZilla::aboutToShowBookmarksMenu() while (query2.next()) { QString title = query2.value(0).toString(); QUrl url = query2.value(1).toUrl(); - QIcon icon = IconProvider::iconFromBase64(query2.value(2).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query2.value(2).toByteArray())); if (title.length() > 40) { title.truncate(40); title += ".."; diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index afe197789..36d015c85 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -293,7 +293,7 @@ void BookmarksManager::refreshTable() QUrl url = query.value(1).toUrl(); int id = query.value(2).toInt(); QString folder = query.value(3).toString(); - QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query.value(4).toByteArray())); QTreeWidgetItem* item = new QTreeWidgetItem(); if (folder == "bookmarksMenu") { folder = _bookmarksMenu; @@ -335,7 +335,7 @@ void BookmarksManager::refreshTable() QString title = query2.value(0).toString(); QUrl url = query2.value(1).toUrl(); int id = query2.value(2).toInt(); - QIcon icon = IconProvider::iconFromBase64(query2.value(3).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query2.value(3).toByteArray())); QTreeWidgetItem* item = new QTreeWidgetItem(newItem); item->setText(0, title); @@ -363,7 +363,7 @@ void BookmarksManager::addBookmark(const BookmarksModel::Bookmark &bookmark) item->setText(0, bookmark.title); item->setText(1, bookmark.url.toEncoded()); item->setWhatsThis(1, QString::number(bookmark.id)); - item->setIcon(0, bookmark.icon); + item->setIcon(0, IconProvider::iconFromImage(bookmark.image)); item->setToolTip(0, bookmark.title); item->setToolTip(1, bookmark.url.toEncoded()); item->setFlags(item->flags() | Qt::ItemIsEditable); diff --git a/src/bookmarks/bookmarksmodel.cpp b/src/bookmarks/bookmarksmodel.cpp index 0c50eefc5..a636696e1 100644 --- a/src/bookmarks/bookmarksmodel.cpp +++ b/src/bookmarks/bookmarksmodel.cpp @@ -115,7 +115,7 @@ BookmarksModel::Bookmark BookmarksModel::getBookmark(int id) bookmark.url = query.value(0).toUrl(); bookmark.title = query.value(1).toString(); bookmark.folder = query.value(2).toString(); - bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); + bookmark.image = QImage::fromData(query.value(3).toByteArray()); bookmark.inSubfolder = isSubfolder(bookmark.folder); } return bookmark; @@ -127,12 +127,18 @@ bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const Q return false; } + QImage image = icon.pixmap(16, 16).toImage(); + QSqlQuery query; query.prepare("INSERT INTO bookmarks (url, title, folder, icon) VALUES (?,?,?,?)"); query.bindValue(0, url.toString()); query.bindValue(1, title); query.bindValue(2, folder); - query.bindValue(3, IconProvider::iconToBase64(icon)); + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + query.bindValue(3, buffer.data()); query.exec(); Bookmark bookmark; @@ -140,7 +146,7 @@ bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const Q bookmark.url = url; bookmark.title = title; bookmark.folder = folder; - bookmark.icon = icon; + bookmark.image = image; bookmark.inSubfolder = isSubfolder(bookmark.folder); emit bookmarkAdded(bookmark); @@ -168,7 +174,7 @@ bool BookmarksModel::removeBookmark(int id) bookmark.url = query.value(0).toUrl(); bookmark.title = query.value(1).toString(); bookmark.folder = query.value(2).toString(); - bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); + bookmark.image = QImage::fromData(query.value(3).toByteArray()); bookmark.inSubfolder = isSubfolder(bookmark.folder); if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) { @@ -227,7 +233,7 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, before.title = query.value(0).toString(); before.url = query.value(1).toUrl(); before.folder = query.value(2).toString(); - before.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); + before.image = QImage::fromData(query.value(3).toByteArray()); before.inSubfolder = isSubfolder(before.folder); Bookmark after; @@ -235,7 +241,7 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, after.title = title.isEmpty() ? before.title : title; after.url = url.isEmpty() ? before.url : url; after.folder = folder.isEmpty() ? before.folder : folder; - after.icon = before.icon; + after.image = before.image; after.inSubfolder = isSubfolder(after.folder); query.prepare("UPDATE bookmarks SET title=?, url=?, folder=? WHERE id = ?"); @@ -349,7 +355,7 @@ QList BookmarksModel::folderBookmarks(const QString &name) bookmark.url = query.value(1).toUrl(); bookmark.title = query.value(2).toString(); bookmark.folder = query.value(3).toString(); - bookmark.icon = IconProvider::iconFromBase64(query.value(4).toByteArray()); + bookmark.image = QImage::fromData(query.value(4).toByteArray()); bookmark.inSubfolder = isSubfolder(bookmark.folder); list.append(bookmark); diff --git a/src/bookmarks/bookmarksmodel.h b/src/bookmarks/bookmarksmodel.h index 8ddcaf2ca..5e7c7bbb6 100644 --- a/src/bookmarks/bookmarksmodel.h +++ b/src/bookmarks/bookmarksmodel.h @@ -40,7 +40,7 @@ public: QString title; QString folder; QUrl url; - QIcon icon; + QImage image; bool inSubfolder; Bookmark() { diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index a0d76cbc9..0d5c0be84 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -321,7 +321,7 @@ void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark) ToolButton* button = new ToolButton(this); button->setText(title); button->setData(v); - button->setIcon(bookmark.icon); + button->setIcon(IconProvider::iconFromImage(bookmark.image)); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); button->setToolTip(bookmark.url.toEncoded()); button->setAutoRaise(true); @@ -389,7 +389,7 @@ void BookmarksToolbar::bookmarkEdited(const BookmarksModel::Bookmark &before, co button->setText(title); button->setData(v); - button->setIcon(after.icon); + button->setIcon(IconProvider::iconFromImage(after.image)); button->setToolTip(after.url.toEncoded()); button->setWhatsThis(after.title); return; @@ -407,7 +407,7 @@ void BookmarksToolbar::refreshBookmarks() bookmark.id = query.value(0).toInt(); bookmark.title = query.value(1).toString(); bookmark.url = query.value(2).toUrl(); - bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); + bookmark.image = QImage::fromData(query.value(3).toByteArray()); bookmark.folder = "bookmarksToolbar"; QString title = bookmark.title; if (title.length() > 15) { @@ -421,7 +421,7 @@ void BookmarksToolbar::refreshBookmarks() ToolButton* button = new ToolButton(this); button->setText(title); button->setData(v); - button->setIcon(bookmark.icon); + button->setIcon(IconProvider::iconFromImage(bookmark.image)); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); button->setToolTip(bookmark.url.toEncoded()); button->setWhatsThis(bookmark.title); @@ -484,7 +484,7 @@ void BookmarksToolbar::aboutToShowFolderMenu() b.title += ".."; } - Action* act = new Action(b.icon, b.title); + Action* act = new Action(IconProvider::iconFromImage(b.image), b.title); act->setData(b.url); connect(act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl())); connect(act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewNotSelectedTab())); diff --git a/src/bookmarksimport/bookmarksimportdialog.cpp b/src/bookmarksimport/bookmarksimportdialog.cpp index bfada8f7f..1203eccab 100644 --- a/src/bookmarksimport/bookmarksimportdialog.cpp +++ b/src/bookmarksimport/bookmarksimportdialog.cpp @@ -23,6 +23,7 @@ #include "htmlimporter.h" #include "mainapplication.h" #include "iconfetcher.h" +#include "iconprovider.h" #include "networkmanager.h" BookmarksImportDialog::BookmarksImportDialog(QWidget* parent) @@ -39,10 +40,6 @@ BookmarksImportDialog::BookmarksImportDialog(QWidget* parent) connect(ui->chooseFile, SIGNAL(clicked()), this, SLOT(setFile())); connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(close())); connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stopDownloading())); - - HtmlImporter html(this); - html.setFile("/home/david/bookmarks.html"); - html.exportBookmarks(); } void BookmarksImportDialog::nextPage() @@ -169,7 +166,7 @@ void BookmarksImportDialog::iconFetched(const QIcon &icon) foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) { if (b.url == url) { m_exportedBookmarks.removeOne(b); - b.icon = icon; + b.image = icon.pixmap(16, 16).toImage(); m_exportedBookmarks.append(b); break; } @@ -266,8 +263,9 @@ void BookmarksImportDialog::addExportedBookmarks() model->createFolder(m_exportedBookmarks.at(0).folder); } - foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) - model->saveBookmark(b.url, b.title, b.icon, b.folder); + foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) { + model->saveBookmark(b.url, b.title, IconProvider::iconFromImage(b.image), b.folder); + } qApp->restoreOverrideCursor(); } diff --git a/src/data/data/browsedata.db b/src/data/data/browsedata.db index 3e2cecc33b11edf31b1a43ef9d686d40386aa33b..5cf3adc144aa22f91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I>6eDTXY}-k1TDqDW zXH?X$6%1^I7G|5_TK3hJqI5lUu3yNRUdcO`{oZu3$upBht$?B0GEEj&>2yiM7As+( z7DriULI|d-8;k)wPV=)?v7cRNi-N9Y1g@)?9$m`Km{w`PEYIu8N_$wA#jev8hBHOgd_$xRifZun+&B$N(^_k}nULLLsj<+q(-H&9tSDRK z)dVzk#y$&;GX1bJfgiv4E1Cq|3)2Njp7+k>nIZNm3HMA;}Ha>PyDpkx;d$yS}D;liQS%*S5 z4w_CEmP<@#x!F);$6|+XaA1S?-Sg3Uz+tVfraH^|LiXoV$+Tzrtc{f#q?+MTO!ck2 z!c_*h_f5dqa~rSKWyPBK+^m(B2&3Z8mcffK{(>%ZHepri_ME_~E8dtW8uRuhJG~O!CS+KQQLB&UZab8BUhurmQrY)QHHO=S`BbXu3kv zJOJ(*80}GcS(qD>mD#P*BhsV$gkJ6X3lo(x6HQlIvua~d68YIesPN+)O;bG3hZxFd z#^Z`URWO<|`LRUK`rMepJxmt+=mHlrO`^+=%}UFzEk|R(QUcA^=lq1Fi7r;J)+Wr5 z>n<%uBy~c-^}0u*b%X2`m*Yltpf4$&2kd|&4G(K(P|#v!ttwBs+!sH)@4a6V9JyJvtUQ>B0iM7g^dvh_B%!9{Mksk@@gXw!)<&es)C#)=@_ zbF4xk->6mObdiBK@`+q%juKq!J{owDW2Ls!cAb1rBE&*@}fJ?xKw*)lQssDfT F|9`oanB4#X diff --git a/src/opensearch/searchenginesmanager.cpp b/src/opensearch/searchenginesmanager.cpp index 7907fda75..9810546e8 100644 --- a/src/opensearch/searchenginesmanager.cpp +++ b/src/opensearch/searchenginesmanager.cpp @@ -28,7 +28,7 @@ QIcon SearchEnginesManager::iconForSearchEngine(const QUrl &url) { - QIcon ic = mApp->iconProvider()->iconForDomain(url); + QIcon ic = IconProvider::iconFromImage(mApp->iconProvider()->iconForDomain(url)); if (ic.isNull()) { ic = QIcon(":icons/menu/search-icon.png"); } diff --git a/src/rss/rssmanager.cpp b/src/rss/rssmanager.cpp index e438c170e..48cf3ad31 100644 --- a/src/rss/rssmanager.cpp +++ b/src/rss/rssmanager.cpp @@ -77,7 +77,7 @@ void RSSManager::refreshTable() while (query.next()) { QUrl address = query.value(0).toUrl(); QString title = query.value(1).toString(); - QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); + QIcon icon = IconProvider::iconFromImage(QImage::fromData(query.value(2).toByteArray())); TreeWidget* tree = new TreeWidget(); tree->setHeaderLabel(tr("News")); tree->setContextMenuPolicy(Qt::CustomContextMenu); @@ -373,18 +373,20 @@ bool RSSManager::addRssFeed(const QString &address, const QString &title, const QSqlQuery query; query.exec("SELECT id FROM rss WHERE address='" + address + "'"); if (!query.next()) { + QImage image = icon.pixmap(16, 16).toImage(); QByteArray iconData; - if (icon.pixmap(16, 16).toImage() == QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic).toImage()) { - iconData = IconProvider::iconToBase64(QIcon(":icons/other/feed.png")); - } - else { - iconData = IconProvider::iconToBase64(icon); + if (image == QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic).toImage()) { + image.load(":icons/other/feed.png"); } query.prepare("INSERT INTO rss (address, title, icon) VALUES(?,?,?)"); query.bindValue(0, address); query.bindValue(1, title); - query.bindValue(2, iconData); + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + query.bindValue(2, buffer.data()); mApp->dbWriter()->executeQuery(query); return true; } diff --git a/src/sidebar/bookmarkssidebar.cpp b/src/sidebar/bookmarkssidebar.cpp index 43bb5a0d2..feb2c3614 100644 --- a/src/sidebar/bookmarkssidebar.cpp +++ b/src/sidebar/bookmarkssidebar.cpp @@ -126,7 +126,7 @@ void BookmarksSideBar::addBookmark(const BookmarksModel::Bookmark &bookmark) item->setText(0, bookmark.title); item->setText(1, bookmark.url.toEncoded()); item->setWhatsThis(0, QString::number(bookmark.id)); - item->setIcon(0, bookmark.icon); + item->setIcon(0, IconProvider::iconFromImage(bookmark.image)); item->setToolTip(0, bookmark.url.toEncoded()); if (bookmark.folder != "unsorted") { diff --git a/src/tools/iconprovider.cpp b/src/tools/iconprovider.cpp index 0d6cbbf4b..1504a5473 100644 --- a/src/tools/iconprovider.cpp +++ b/src/tools/iconprovider.cpp @@ -33,29 +33,27 @@ IconProvider::IconProvider(QObject* parent) void IconProvider::saveIcon(WebView* view) { Icon item; - item.icon = view->icon(); + item.image = view->icon().pixmap(16, 16).toImage(); item.url = view->url(); - if (item.icon.isNull()) { + if (item.image.isNull()) { return; } - QPixmap iconPixmap = item.icon.pixmap(16, 16); foreach(Icon ic, m_iconBuffer) { - if (ic.url == item.url && ic.icon.pixmap(16, 16).toImage() == iconPixmap.toImage()) { + if (ic.url == item.url && ic.image == item.image) { return; } } - item.icon = QIcon(iconPixmap); m_iconBuffer.append(item); } -QIcon IconProvider::iconForUrl(const QUrl &url) +QImage IconProvider::iconForUrl(const QUrl &url) { foreach(Icon ic, m_iconBuffer) { if (ic.url == url) { - return ic.icon; + return ic.image; } } @@ -64,27 +62,27 @@ QIcon IconProvider::iconForUrl(const QUrl &url) query.bindValue(0, url.toEncoded(QUrl::RemoveFragment)); query.exec(); if (query.next()) { - return iconFromBase64(query.value(0).toByteArray()); + return QImage::fromData(query.value(0).toByteArray()); } - return QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic); + return QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic).toImage(); } -QIcon IconProvider::iconForDomain(const QUrl &url) +QImage IconProvider::iconForDomain(const QUrl &url) { foreach(Icon ic, m_iconBuffer) { if (ic.url.host() == url.host()) { - return ic.icon; + return ic.image; } } QSqlQuery query; query.exec("SELECT icon FROM icons WHERE url LIKE '%" + url.host() + "%'"); if (query.next()) { - return iconFromBase64(query.value(0).toByteArray()); + return QImage::fromData(query.value(0).toByteArray()); } - return QIcon(); + return QImage(); } void IconProvider::saveIconsToDatabase() @@ -102,7 +100,11 @@ void IconProvider::saveIconsToDatabase() query.prepare("INSERT INTO icons (icon, url) VALUES (?,?)"); } - query.bindValue(0, iconToBase64(ic.icon)); + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + ic.image.save(&buffer, "PNG"); + query.bindValue(0, buffer.data()); query.bindValue(1, ic.url.toEncoded(QUrl::RemoveFragment)); mApp->dbWriter()->executeQuery(query); } @@ -200,6 +202,11 @@ QIcon IconProvider::fromTheme(const QString &icon) } } +QIcon IconProvider::iconFromImage(const QImage &image) +{ + return QIcon(QPixmap::fromImage(image)); +} + QIcon IconProvider::iconFromBase64(const QByteArray &data) { QIcon image; diff --git a/src/tools/iconprovider.h b/src/tools/iconprovider.h index 5519312f1..ee4a297dd 100644 --- a/src/tools/iconprovider.h +++ b/src/tools/iconprovider.h @@ -18,7 +18,7 @@ #ifndef ICONPROVIDER_H #define ICONPROVIDER_H -#define _iconForUrl(url) mApp->iconProvider()->iconForUrl(url) +#define _iconForUrl(url) IconProvider::iconFromImage(mApp->iconProvider()->iconForUrl(url)) #include #include @@ -36,12 +36,14 @@ public: explicit IconProvider(QObject* parent = 0); ~IconProvider(); - void saveIcon(WebView* view); - QIcon iconForUrl(const QUrl &url); - QIcon iconForDomain(const QUrl &url); - void clearIconDatabase(); + void saveIcon(WebView* view); + QImage iconForUrl(const QUrl &url); + QImage iconForDomain(const QUrl &url); + + static QIcon iconFromImage(const QImage &image); + static QIcon iconFromBase64(const QByteArray &data); static QByteArray iconToBase64(const QIcon &icon); @@ -59,7 +61,7 @@ private: struct Icon { QUrl url; - QIcon icon; + QImage image; }; QList m_iconBuffer; diff --git a/src/webview/webpage.cpp b/src/webview/webpage.cpp index fdc3680cb..0914d5f5a 100644 --- a/src/webview/webpage.cpp +++ b/src/webview/webpage.cpp @@ -210,6 +210,10 @@ bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &r } } + if (!frame && type != QWebPage::NavigationTypeOther) { + qDebug() << "coming from javascript"; + } + // TabWidget::OpenUrlIn openIn= frame ? TabWidget::CurrentTab: TabWidget::NewTab; bool accept = QWebPage::acceptNavigationRequest(frame, request, type); @@ -242,6 +246,8 @@ QWebPage* WebPage::createWindow(QWebPage::WebWindowType type) // QWebView* view = new QWebView(); // view->show(); // return view->page(); + + qDebug() << "createWindow"; Q_UNUSED(type); int index = p_QupZilla->tabWidget()->addView(QUrl(), tr("New tab"), TabWidget::CleanSelectedPage); return p_QupZilla->weView(index)->page(); diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 52bfd5345..eb526be4d 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -101,11 +101,15 @@ void WebView::slotIconChanged() { m_siteIcon = icon(); - if (url().scheme() == "file" || title().contains(tr("Failed loading page"))) { + if (url().scheme() == "file" || url().scheme() == "qupzilla" || title().contains(tr("Failed loading page"))) { return; } mApp->iconProvider()->saveIcon(this); + + if (!m_isLoading) { + iconChanged(); + } } void WebView::copyText() @@ -234,11 +238,6 @@ void WebView::loadFinished(bool state) iconChanged(); m_lastUrl = url(); - //Icon is sometimes not available at the moment of finished loading - if (icon().isNull()) { - QTimer::singleShot(1000, this, SLOT(iconChanged())); - } - titleChanged(); mApp->autoFill()->completePage(this); QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo))); @@ -259,7 +258,6 @@ QLabel* WebView::animationLoading(int index, bool addMovie) QLabel* loadingAnimation = qobject_cast(tabWidget()->getTabBar()->tabButton(index, QTabBar::LeftSide)); if (!loadingAnimation) { loadingAnimation = new QLabel(); -// loadingAnimation->setStyleSheet("margin: 0px; padding: 0px; width: 16px; height: 16px;"); } if (addMovie && !loadingAnimation->movie()) { QMovie* movie = new QMovie(":icons/other/progress.gif", QByteArray(), loadingAnimation); @@ -315,8 +313,6 @@ void WebView::titleChanged() void WebView::iconChanged() { - emit siteIconChanged(); - if (m_isLoading) { return; } diff --git a/src/webview/webview.h b/src/webview/webview.h index 9facda106..be694e684 100644 --- a/src/webview/webview.h +++ b/src/webview/webview.h @@ -72,7 +72,6 @@ public: signals: void showUrl(QUrl url); - void siteIconChanged(); void wantsCloseTab(int index); void changed(); void ipChanged(QString ip);