File indexing completed on 2022-11-29 15:04:34

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "environment.h"
0007 
0008 // Qt
0009 #include <QDebug>
0010 #include <QProcess>
0011 
0012 // Plasma
0013 #include <plasma/version.h>
0014 
0015 #define LONGDURATION 240
0016 #define SHORTDURATION 40
0017 
0018 namespace Latte{
0019 
0020 const int Environment::SeparatorLength;
0021 
0022 Environment::Environment(QObject *parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 int Environment::separatorLength() const
0028 {
0029     return SeparatorLength;
0030 }
0031 
0032 uint Environment::shortDuration() const
0033 {
0034     return SHORTDURATION;
0035 }
0036 
0037 uint Environment::longDuration() const
0038 {
0039     return LONGDURATION;
0040 }
0041 
0042 uint Environment::frameworksVersion() const
0043 {
0044     return Plasma::version();
0045 }
0046 
0047 uint Environment::plasmaDesktopVersion()
0048 {
0049     if (m_plasmaDesktopVersion == -1) {
0050         m_plasmaDesktopVersion = identifyPlasmaDesktopVersion();
0051     }
0052 
0053     return m_plasmaDesktopVersion;
0054 }
0055 
0056 uint Environment::makeVersion(uint major, uint minor, uint release) const
0057 {
0058     return (((major) << 16) | ((minor) << 8) | (release));
0059 }
0060 
0061 uint Environment::identifyPlasmaDesktopVersion()
0062 {
0063     //! Identify Plasma Desktop version
0064     QProcess process;
0065     process.start("plasmashell", QStringList() << "-v");
0066     process.waitForFinished();
0067     QString output(process.readAllStandardOutput());
0068 
0069     QStringList stringSplit = output.split(" ");
0070 
0071     if (stringSplit.count() >= 2) {
0072         qDebug() << " /////////////////////////";
0073         QString cleanVersionString = stringSplit[1].remove("\n");
0074         QStringList plasmaDesktopVersionParts = cleanVersionString.split(".");
0075 
0076         if (plasmaDesktopVersionParts.count() == 3) {
0077             uint maj = plasmaDesktopVersionParts[0].toUInt();
0078             uint min = plasmaDesktopVersionParts[1].toUInt();
0079             uint rel = plasmaDesktopVersionParts[2].toUInt();
0080 
0081             if (maj > 0) {
0082 
0083                 uint desktopVersion = makeVersion(maj, min, rel);
0084 
0085                 QString message("Plasma Desktop version:  " + QString::number(maj) + "."
0086                                 + QString::number(min) + "." + QString::number(rel)
0087                                 + " (" + QString::number(desktopVersion) + ")");
0088                 qDebug() << message;
0089                 qDebug() << " /////////////////////////";
0090 
0091                 return desktopVersion;
0092             }
0093         }
0094 
0095         qDebug() << " /////////////////////////";
0096     }
0097 
0098     return 0;
0099 }
0100 
0101 }