Lomiri
Loading...
Searching...
No Matches
platform.cpp
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "platform.h"
18
19#include <QDBusConnection>
20#include <QSet>
21#include <QString>
22
23Platform::Platform(QObject *parent)
24 : QObject(parent), m_isPC(true), m_isMultiSession(true)
25{
26 QMetaObject::invokeMethod(this, "init");
27}
28
29void Platform::init()
30{
31 QDBusInterface iface("org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1",
32 QDBusConnection::systemBus(), this);
33 QDBusInterface seatIface("org.freedesktop.login1", "/org/freedesktop/login1/seat/self", "org.freedesktop.login1.Seat",
34 QDBusConnection::systemBus(), this);
35
36 // From the source at https://cgit.freedesktop.org/systemd/systemd/tree/src/hostname/hostnamed.c#n130
37 // "vm\0"
38 // "container\0"
39 // "desktop\0"
40 // "laptop\0"
41 // "server\0"
42 // "tablet\0"
43 // "handset\0"
44 // "watch\0"
45 // "embedded\0",
46 m_chassis = iface.property("Chassis").toString();
47
48 // A PC is not a handset, tablet or watch.
49 m_isPC = !QSet<QString>{"handset", "tablet", "watch"}.contains(m_chassis);
50 m_isMultiSession = seatIface.property("CanMultiSession").toBool() && seatIface.property("CanGraphical").toBool();
51}
52
53QString Platform::chassis() const
54{
55 return m_chassis;
56}
57
58bool Platform::isPC() const
59{
60 return m_isPC;
61}
62
63bool Platform::isMultiSession() const
64{
65 return m_isMultiSession;
66}
bool isPC
Definition platform.h:40
bool isMultiSession
Definition platform.h:44
QString chassis
Definition platform.h:36