Skip to content

Commit

Permalink
[developermode] Add DeveloperModeSettings::developerModeAccountProvid…
Browse files Browse the repository at this point in the history
…er. Contributes to JB#39097

This value refers to the first known account provider that provides a
service of the "developermode" type.
  • Loading branch information
blammit committed Mar 12, 2018
1 parent eb2dfc6 commit e1cc12e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions rpm/nemo-qml-plugin-systemsettings.spec
Expand Up @@ -26,6 +26,7 @@ BuildRequires: pkgconfig(nemomodels-qt5)
BuildRequires: pkgconfig(libsailfishkeyprovider) >= 0.0.14
BuildRequires: pkgconfig(connman-qt5)
BuildRequires: pkgconfig(ssu-sysinfo) >= 1.1.0
BuildRequires: pkgconfig(sailfishaccounts)

%description
%{summary}.
Expand Down
50 changes: 50 additions & 0 deletions src/developermodesettings.cpp
Expand Up @@ -32,11 +32,17 @@

#include "developermodesettings.h"

/* libsailfishaccounts */
#include <accountmanager.h>
#include <provider.h>
#include <service.h>

#include <QDebug>
#include <QFile>
#include <QDir>
#include <QDBusReply>
#include <QNetworkInterface>

#include <getdef.h>
#include <pwd.h>

Expand All @@ -55,6 +61,9 @@
/* A file that is provided by the developer mode package */
#define DEVELOPER_MODE_PROVIDED_FILE "/usr/bin/devel-su"

/* The service name for developer mode services offered by an account provider */
#define DEVELOPER_MODE_ACCOUNT_SERVICE "developermode"

/* D-Bus service */
#define PACKAGEKIT_SERVICE "org.freedesktop.PackageKit"
#define PACKAGEKIT_PATH "/org/freedesktop/PackageKit"
Expand Down Expand Up @@ -140,6 +149,7 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
: QObject(parent)
, m_usbModeDaemon(USB_MODED_SERVICE, USB_MODED_PATH, USB_MODED_INTERFACE,
QDBusConnection::systemBus())
, m_accountManager(new AccountManager(this))
, m_pendingPackageKitCall(nullptr)
, m_packageKitCommand(nullptr)
, m_wlanIpAddress("-")
Expand All @@ -160,6 +170,10 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
qWarning() << "Failed to return username using getpwuid()";
}

updateAccountProvider();
connect(m_accountManager, &AccountManager::providerNamesChanged,
this, &DeveloperModeSettings::updateAccountProvider);

if (!m_developerModeEnabled) {
m_workerStatus = CheckingStatus;
executePackageKitCommand(&DeveloperModeSettings::resolvePackageId, DEVELOPER_MODE_PACKAGE);
Expand Down Expand Up @@ -194,6 +208,11 @@ DeveloperModeSettings::username() const
return m_username;
}

QString DeveloperModeSettings::developerModeAccountProvider() const
{
return m_developerModeAccountProvider;
}

bool DeveloperModeSettings::developerModeAvailable() const
{
return m_developerModeEnabled || !m_developerModePackageId.isEmpty();
Expand Down Expand Up @@ -539,3 +558,34 @@ void DeveloperModeSettings::transactionFinished(uint exit, uint)
emit workerStatusChanged();
emit workerProgressChanged();
}

void DeveloperModeSettings::updateAccountProvider()
{
// Find all account providers with the developer-mode service. If m_developerModeAccountProvider
// is already set to the name of one of these providers, just return. Otherwise, set it to the
// first provider found with a matching service.
QList<Provider *> accountProviders;
for (const QString &providerName : m_accountManager->providerNames()) {
if (Provider *accountProvider = m_accountManager->provider(providerName)) {
for (const QString &serviceName : accountProvider->serviceNames()) {
if (Service *accountService = m_accountManager->service(serviceName)) {
if (accountService->serviceType() == DEVELOPER_MODE_ACCOUNT_SERVICE) {
if (m_developerModeAccountProvider == providerName) {
return;
} else {
accountProviders.append(accountProvider);
break;
}
}
}
}
}
}

if (!accountProviders.isEmpty()) {
if (m_developerModeAccountProvider != accountProviders.first()->name()) {
m_developerModeAccountProvider = accountProviders.first()->name();
emit developerModeAccountProviderChanged();
}
}
}
12 changes: 11 additions & 1 deletion src/developermodesettings.h
Expand Up @@ -41,6 +41,7 @@

QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
class AccountManager;
QT_END_NAMESPACE

class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
Expand All @@ -64,6 +65,10 @@ class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
READ developerModeAvailable
NOTIFY developerModeAvailableChanged)

Q_PROPERTY(QString developerModeAccountProvider
READ developerModeAccountProvider
NOTIFY developerModeAccountProviderChanged)

Q_PROPERTY(bool developerModeEnabled
READ developerModeEnabled
NOTIFY developerModeEnabledChanged)
Expand Down Expand Up @@ -96,6 +101,7 @@ class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
QString username() const;
bool developerModeAvailable() const;
bool developerModeEnabled() const;
QString developerModeAccountProvider() const;
bool remoteLoginEnabled() const;
enum DeveloperModeSettings::Status workerStatus() const;
int workerProgress() const;
Expand All @@ -109,6 +115,7 @@ class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
void wlanIpAddressChanged();
void usbIpAddressChanged();
void developerModeAvailableChanged();
void developerModeAccountProviderChanged();
void developerModeEnabledChanged();
void remoteLoginEnabledChanged();
void workerWorkingChanged();
Expand All @@ -133,10 +140,12 @@ private slots:
void executePackageKitCommand(
QDBusPendingCallWatcher *(DeveloperModeSettings::*command)(const QString &),
const QString &argument);
void resolveDeveloperModePackageId();

void updateAccountProvider();

QDBusInterface m_usbModeDaemon;
QDBusObjectPath m_packageKitTransaction;
AccountManager *m_accountManager;
QDBusPendingCallWatcher *m_pendingPackageKitCall;
QDBusPendingCallWatcher *(DeveloperModeSettings::*m_packageKitCommand)(const QString &packageId);

Expand All @@ -145,6 +154,7 @@ private slots:
QString m_usbIpAddress;
QString m_username;
QString m_developerModePackageId;
QString m_developerModeAccountProvider;
bool m_developerModeEnabled;
bool m_remoteLoginEnabled;
DeveloperModeSettings::Status m_workerStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -6,7 +6,7 @@ QT += qml dbus systeminfo
QT -= gui

CONFIG += c++11 hide_symbols link_pkgconfig
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5 sailfishaccounts
PKGCONFIG += ssu-sysinfo

system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
Expand Down

0 comments on commit e1cc12e

Please sign in to comment.