1 /* 2 SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #include "indicatorresources.h" 7 #include "indicator.h" 8 9 // Qt 10 #include <QDebug> 11 #include <QFileInfo> 12 13 // Plasma 14 #include <Plasma/Svg> 15 16 namespace Latte { 17 namespace ViewPart { 18 namespace IndicatorPart { 19 Resources(Indicator * parent)20Resources::Resources(Indicator *parent) : 21 QObject(parent), 22 m_indicator(parent) 23 { 24 } 25 ~Resources()26Resources::~Resources() 27 { 28 } 29 svgs() const30QList<QObject *> Resources::svgs() const 31 { 32 return m_svgs; 33 } 34 setSvgImagePaths(QStringList paths)35void Resources::setSvgImagePaths(QStringList paths) 36 { 37 if (m_svgImagePaths == paths) { 38 return; 39 } 40 41 while (!m_svgs.isEmpty()) { 42 auto svg = m_svgs[0]; 43 m_svgs.removeFirst(); 44 svg->deleteLater(); 45 } 46 47 for(const auto &relPath : paths) { 48 if (!relPath.isEmpty()) { 49 Plasma::Svg *svg = new Plasma::Svg(this); 50 51 bool isLocalFile = relPath.contains(".") && !relPath.startsWith("file:"); 52 53 QString adjustedPath = isLocalFile ? m_indicator->uiPath() + "/" + relPath : relPath; 54 55 if ( !isLocalFile 56 || (isLocalFile && QFileInfo(adjustedPath).exists()) ) { 57 svg->setImagePath(adjustedPath); 58 m_svgs << svg; 59 } 60 } 61 } 62 63 emit svgsChanged(); 64 } 65 66 } 67 } 68 } 69