From 328ab40304e50a9c66137e0bd51e4ed4ccedb6e9 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 5 Sep 2015 21:03:08 +0200 Subject: [PATCH] SpeedDial: Fix setting background image --- src/lib/data/html/speeddial.html | 16 ++++++------ .../schemehandlers/qupzillaschemehandler.cpp | 1 + src/lib/plugins/speeddial.cpp | 25 +++++++++++++------ src/lib/plugins/speeddial.h | 4 ++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/lib/data/html/speeddial.html b/src/lib/data/html/speeddial.html index ad60ef058..bf5361636 100644 --- a/src/lib/data/html/speeddial.html +++ b/src/lib/data/html/speeddial.html @@ -347,9 +347,10 @@ function alignPage() { } function bgImageSel() { - external.speedDial.getOpenFileName(function(img) { - if (img) { - document.getElementById('BgImgHold').value = img; + external.speedDial.getOpenFileName(function(arr) { + if (arr.length) { + document.getElementById('BgImgHold').value = arr[0]; + document.getElementById('BgImgHoldUrl').value = arr[1]; } }); } @@ -359,7 +360,7 @@ function saveSettings() { DIAL_WIDTH = parseInt($('#SdSize').val()); SD_CNTR = ($('#SdCntrToggle').attr('checked') ? 1 : 0 ); - external.speedDial.setBackgroundImage($('#BgImgHold').val()); + external.speedDial.setBackgroundImage($('#BgImgHoldUrl').val()); external.speedDial.setBackgroundImageSize($('#BgImgSelSiz').val()); external.speedDial.setPagesInRow(MAX_PAGES_ROW); external.speedDial.setSdSize(DIAL_WIDTH); @@ -371,13 +372,13 @@ function saveSettings() { function bgImgToggle() { var check = document.getElementById('BgImgToggle'); var BgImgSel = document.getElementById('BgImgSel'); - var BgImgHold = document.getElementById('BgImgHold'); + var BgImgHoldUrl = document.getElementById('BgImgHoldUrl'); var BgImgSz = document.getElementById('BgImgSelSiz'); BgImgSel.disabled = (check.checked ? false : true); - BgImgHold.disabled = (check.checked ? false : true); + BgImgHoldUrl.disabled = (check.checked ? false : true); BgImgSz.disabled = (check.checked ? false : true); - BgImgHold.value = (check.checked ? "%IMG_BACKGROUND%" : ''); + BgImgHoldUrl.value = (check.checked ? "%URL_BACKGROUND%" : ''); } function sdSizeToggle() { @@ -487,6 +488,7 @@ if (window.external) {

+

diff --git a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp index 6a4067bd4..3e70da918 100644 --- a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp +++ b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp @@ -312,6 +312,7 @@ QString QupZillaSchemeReply::speeddialPage() page.replace(QLatin1String("%INITIAL-SCRIPT%"), dial->initialScript()); page.replace(QLatin1String("%IMG_BACKGROUND%"), dial->backgroundImage()); + page.replace(QLatin1String("%URL_BACKGROUND%"), dial->backgroundImageUrl()); page.replace(QLatin1String("%B_SIZE%"), dial->backgroundImageSize()); page.replace(QLatin1String("%ROW-PAGES%"), QString::number(dial->pagesInRow())); page.replace(QLatin1String("%SD-SIZE%"), QString::number(dial->sdSize())); diff --git a/src/lib/plugins/speeddial.cpp b/src/lib/plugins/speeddial.cpp index cdd483ab4..9aedfeb3e 100644 --- a/src/lib/plugins/speeddial.cpp +++ b/src/lib/plugins/speeddial.cpp @@ -55,7 +55,7 @@ void SpeedDial::loadSettings() Settings settings; settings.beginGroup("SpeedDial"); QString allPages = settings.value("pages", QString()).toString(); - m_backgroundImage = settings.value("background", QString()).toString(); + setBackgroundImage(settings.value("background", QString()).toString()); m_backgroundImageSize = settings.value("backsize", "auto").toString(); m_maxPagesInRow = settings.value("pagesrow", 4).toInt(); m_sizeOfSpeedDials = settings.value("sdsize", 231).toInt(); @@ -89,7 +89,7 @@ void SpeedDial::saveSettings() Settings settings; settings.beginGroup("SpeedDial"); settings.setValue("pages", generateAllPages()); - settings.setValue("background", m_backgroundImage); + settings.setValue("background", m_backgroundImageUrl); settings.setValue("backsize", m_backgroundImageSize); settings.setValue("pagesrow", m_maxPagesInRow); settings.setValue("sdsize", m_sizeOfSpeedDials); @@ -184,6 +184,11 @@ QString SpeedDial::backgroundImage() return m_backgroundImage; } +QString SpeedDial::backgroundImageUrl() +{ + return m_backgroundImageUrl; +} + QString SpeedDial::backgroundImageSize() { ENSURE_LOADED; @@ -276,16 +281,18 @@ void SpeedDial::removeImageForUrl(const QString &url) } } -QString SpeedDial::getOpenFileName() +QStringList SpeedDial::getOpenFileName() { const QString fileTypes = QString("%3(*.png *.jpg *.jpeg *.bmp *.gif *.svg *.tiff)").arg(tr("Image files")); const QString image = QzTools::getOpenFileName("SpeedDial-GetOpenFileName", 0, tr("Select image..."), QDir::homePath(), fileTypes); - if (image.isEmpty()) { - return image; - } + if (image.isEmpty()) + return QStringList(); - return QUrl::fromLocalFile(image).toEncoded(); + const QByteArray data = QzTools::pixmapToByteArray(QPixmap(image)); + const QByteArray imageData = QByteArrayLiteral("data:image/png;base64,") + data; + + return {imageData, QUrl::fromLocalFile(image).toEncoded()}; } QString SpeedDial::urlFromUserInput(const QString &url) @@ -295,7 +302,9 @@ QString SpeedDial::urlFromUserInput(const QString &url) void SpeedDial::setBackgroundImage(const QString &image) { - m_backgroundImage = image; + const QByteArray data = QzTools::pixmapToByteArray(QPixmap(QUrl::fromEncoded(image.toUtf8()).toLocalFile())); + m_backgroundImage = QByteArrayLiteral("data:image/png;base64,") + data; + m_backgroundImageUrl = image; } void SpeedDial::setBackgroundImageSize(const QString &size) diff --git a/src/lib/plugins/speeddial.h b/src/lib/plugins/speeddial.h index ea79fe437..c95ffe271 100644 --- a/src/lib/plugins/speeddial.h +++ b/src/lib/plugins/speeddial.h @@ -60,6 +60,7 @@ public: int sdCntr(); QString backgroundImage(); + QString backgroundImageUrl(); QString backgroundImageSize(); QString initialScript(); @@ -73,7 +74,7 @@ public slots: void loadThumbnail(const QString &url, bool loadTitle); void removeImageForUrl(const QString &url); - QString getOpenFileName(); + QStringList getOpenFileName(); QString urlFromUserInput(const QString &url); void setBackgroundImage(const QString &image); void setBackgroundImageSize(const QString &size); @@ -94,6 +95,7 @@ private: QString m_initialScript; QString m_thumbnailsDir; QString m_backgroundImage; + QString m_backgroundImageUrl; QString m_backgroundImageSize; int m_maxPagesInRow; int m_sizeOfSpeedDials;