Commit 67baa6c6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Remove custom parsers of the /etc/os-release file

Use instead the implementation we have in KCoreAddons
parent a0cdde8e
......@@ -19,6 +19,7 @@
***************************************************************************/
#include "AppStreamIntegration.h"
#include <KOSRelease>
AppStreamIntegration * AppStreamIntegration::global()
{
......
......@@ -23,6 +23,7 @@
#include "discovercommon_export.h"
#include <QObject>
#include <KOSRelease>
#include "OdrsReviewsBackend.h"
class DISCOVERCOMMON_EXPORT AppStreamIntegration : public QObject
......@@ -32,9 +33,11 @@ public:
static AppStreamIntegration* global();
QSharedPointer<OdrsReviewsBackend> reviews();
KOSRelease* osRelease() { return &m_osrelease; }
private:
QWeakPointer<OdrsReviewsBackend> m_reviews;
KOSRelease m_osrelease;
AppStreamIntegration() {}
};
......
......@@ -20,6 +20,7 @@
***************************************************************************/
#include "OdrsReviewsBackend.h"
#include "AppStreamIntegration.h"
#include <ReviewsBackend/Review.h>
#include <ReviewsBackend/Rating.h>
......@@ -91,33 +92,7 @@ void OdrsReviewsBackend::ratingsFetched(KJob *job)
static QString osName()
{
//TODO: port to KOSRelease
QString osReleaseFilename;
if (QFileInfo::exists(QStringLiteral("/etc/os-release"))) {
osReleaseFilename = QStringLiteral("/etc/os-release");
} else if (QFileInfo::exists(QStringLiteral("/usr/lib/os-release"))) {
osReleaseFilename = QStringLiteral("/usr/lib/os-release");
}
if (osReleaseFilename.isEmpty()) {
return QStringLiteral("Unknown");
}
QFile osReleaseFile(osReleaseFilename);
if (osReleaseFile.open(QIODevice::ReadOnly)) {
QString line;
QTextStream stream(&osReleaseFile);
while (stream.readLineInto(&line)) {
if (line.startsWith(QStringLiteral("NAME"))) {
QStringRef name = line.midRef(5).trimmed();
if (name.startsWith(QLatin1Char('\"')) && name.endsWith(QLatin1Char('\"')))
name = name.mid(1, name.size()-2);
return name.toString();
}
}
}
return QStringLiteral("Unknown");
return AppStreamIntegration::global()->osRelease()->osName();
}
static QString userHash()
......
......@@ -654,41 +654,9 @@ AbstractReviewsBackend* PackageKitBackend::reviewsBackend() const
return m_reviews.data();
}
static QString readDistroName()
{
const QStringList osreleasenames = (QStringList() << QStringLiteral("/etc/os-release")
<< QStringLiteral("/usr/lib/os-release"));
foreach (QString osrelease, osreleasenames)
{
QFile file(osrelease);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray line;
while (!file.atEnd()) {
line = file.readLine().trimmed();
if (line.startsWith("NAME=")) {
auto output = line.right(line.length()-5);
output = output.replace('\"',"");
return QString::fromLocal8Bit(output);
}
}
}
}
QProcess process;
process.setEnvironment({QStringLiteral("LC_ALL=C")});
process.start(QStringLiteral("lsb_release"), {QStringLiteral("-sd")});
process.waitForFinished();
auto output = process.readAll().trimmed();
if (output.startsWith('\"') && output.endsWith('\"'))
output = output.mid(1, output.length()-2);
return QString::fromLocal8Bit(output);
}
QString PackageKitBackend::displayName() const
{
static const QString distro = readDistroName();
return distro;
return AppStreamIntegration::global()->osRelease()->prettyName();
}
#include "PackageKitBackend.moc"
Markdown is supported
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