Verified Commit 052f78b0 authored by Fushan Wen's avatar Fushan Wen
Browse files

wallpapers/potd: Pass screen size and devicePixelRatio from QML to BingProvider

The wallpaper knows the size of the screen where it lives, so no need
to use primary screen.
parent b25e129d
Pipeline #156336 passed with stage
in 3 minutes and 29 seconds
......@@ -5,6 +5,8 @@
*/
import QtQuick 2.5
import QtQuick.Window 2.15
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kquickcontrolsaddons 2.0
......@@ -16,8 +18,16 @@ Rectangle {
PotdProviderModel {
id: engine
identifier: wallpaper.configuration.Provider
// Needs to specify category for unsplash provider
arguments: identifier === "unsplash" ? [wallpaper.configuration.Category] : []
arguments: {
if (identifier === "unsplash") {
// Needs to specify category for unsplash provider
return [wallpaper.configuration.Category];
} else if (identifier === "bing") {
// Bing supports 1366/1920/UHD resolutions
return [Screen.width, Screen.height, Screen.devicePixelRatio];
}
return [];
}
running: true
}
......
......@@ -7,16 +7,17 @@
#include "bingprovider.h"
#include <QDebug>
#include <QGuiApplication>
#include <QJsonArray>
#include <QJsonDocument>
#include <QScreen>
#include <KIO/Job>
#include <KPluginFactory>
BingProvider::BingProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: PotdProvider(parent, data, args)
, m_screenDPI(args.size() >= 3 ? args[2].toDouble() : 1)
, m_screenWidth(args.size() >= 2 ? args[0].toInt() * m_screenDPI : 0)
, m_screenHeight(args.size() >= 2 ? args[1].toInt() * m_screenDPI : 0)
{
const QUrl url(QStringLiteral("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"));
......@@ -55,7 +56,7 @@ void BingProvider::pageRequestFinished(KJob *_job)
urlString = QStringLiteral("https://www.bing.com/") + urlString;
if (const QSize size = qGuiApp->primaryScreen()->size(); size.width() > 1920 || size.height() > 1080) {
if (m_screenWidth > 1920 || m_screenHeight > 1080) {
// Use 4k wallpaper
urlString += QStringLiteral("_UHD.jpg");
} else {
......
......@@ -30,6 +30,10 @@ public:
private:
void pageRequestFinished(KJob *job);
void imageRequestFinished(KJob *job);
double m_screenDPI;
int m_screenWidth;
int m_screenHeight;
};
#endif
Supports Markdown
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