File indexing completed on 2024-04-28 16:49:27

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #include "indicatorresources.h"
0021 #include "indicator.h"
0022 
0023 // Qt
0024 #include <QDebug>
0025 #include <QFileInfo>
0026 
0027 // Plasma
0028 #include <Plasma/Svg>
0029 
0030 namespace Latte {
0031 namespace ViewPart {
0032 namespace IndicatorPart {
0033 
0034 Resources::Resources(Indicator *parent) :
0035     QObject(parent),
0036     m_indicator(parent)
0037 {
0038 }
0039 
0040 Resources::~Resources()
0041 {
0042 }
0043 
0044 QList<QObject *> Resources::svgs() const
0045 {
0046     return m_svgs;
0047 }
0048 
0049 void Resources::setSvgImagePaths(QStringList paths)
0050 {
0051     if (m_svgImagePaths == paths) {
0052         return;
0053     }
0054 
0055     while (!m_svgs.isEmpty()) {
0056         auto svg = m_svgs[0];
0057         m_svgs.removeFirst();
0058         svg->deleteLater();
0059     }
0060 
0061     for(const auto &relPath : paths) {
0062         if (!relPath.isEmpty()) {
0063             Plasma::Svg *svg = new Plasma::Svg(this);
0064 
0065             bool isLocalFile = relPath.contains(".") && !relPath.startsWith("file:");
0066 
0067             QString adjustedPath = isLocalFile ? m_indicator->uiPath() + "/" + relPath : relPath;
0068 
0069             if ( !isLocalFile
0070                  || (isLocalFile && QFileInfo(adjustedPath).exists()) ) {
0071                 svg->setImagePath(adjustedPath);
0072                 m_svgs << svg;
0073             }
0074         }
0075     }
0076 
0077     emit svgsChanged();
0078 }
0079 
0080 }
0081 }
0082 }