File indexing completed on 2024-04-21 05:31:04

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "indicatorresources.h"
0007 #include "indicator.h"
0008 
0009 // Qt
0010 #include <QDebug>
0011 #include <QFileInfo>
0012 
0013 // Plasma
0014 #include <Plasma/Svg>
0015 
0016 namespace Latte {
0017 namespace ViewPart {
0018 namespace IndicatorPart {
0019 
0020 Resources::Resources(Indicator *parent) :
0021     QObject(parent),
0022     m_indicator(parent)
0023 {
0024 }
0025 
0026 Resources::~Resources()
0027 {
0028 }
0029 
0030 QList<QObject *> Resources::svgs() const
0031 {
0032     return m_svgs;
0033 }
0034 
0035 void Resources::setSvgImagePaths(QStringList paths)
0036 {
0037     if (m_svgImagePaths == paths) {
0038         return;
0039     }
0040 
0041     while (!m_svgs.isEmpty()) {
0042         auto svg = m_svgs[0];
0043         m_svgs.removeFirst();
0044         svg->deleteLater();
0045     }
0046 
0047     for(const auto &relPath : paths) {
0048         if (!relPath.isEmpty()) {
0049             Plasma::Svg *svg = new Plasma::Svg(this);
0050 
0051             bool isLocalFile = relPath.contains(".") && !relPath.startsWith("file:");
0052 
0053             QString adjustedPath = isLocalFile ? m_indicator->uiPath() + "/" + relPath : relPath;
0054 
0055             if ( !isLocalFile
0056                  || (isLocalFile && QFileInfo(adjustedPath).exists()) ) {
0057                 svg->setImagePath(adjustedPath);
0058                 m_svgs << svg;
0059             }
0060         }
0061     }
0062 
0063     emit svgsChanged();
0064 }
0065 
0066 }
0067 }
0068 }