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 3e2cecc33..5cf3adc14 100644 Binary files a/src/data/data/browsedata.db and b/src/data/data/browsedata.db differ 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);