diff --git a/dbus/org.nemo.ssu.xml b/dbus/org.nemo.ssu.xml index ec19790..8bcd9b0 100644 --- a/dbus/org.nemo.ssu.xml +++ b/dbus/org.nemo.ssu.xml @@ -25,6 +25,7 @@ + @@ -34,12 +35,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rndssucli/rndssucli.cpp b/rndssucli/rndssucli.cpp index bad85b6..8aadcea 100644 --- a/rndssucli/rndssucli.cpp +++ b/rndssucli/rndssucli.cpp @@ -32,6 +32,10 @@ RndSsuCli::RndSsuCli(): QObject(){ state = Idle; } +RndSsuCli::~RndSsuCli(){ + ssuProxy->quit(); +} + void RndSsuCli::handleResponse(){ QTextStream qout(stdout); @@ -76,6 +80,7 @@ void RndSsuCli::optDomain(QStringList opt){ void RndSsuCli::optFlavour(QStringList opt){ QTextStream qout(stdout); + QTextStream qerr(stderr); if (opt.count() == 3 && opt.at(2) == "-s"){ qout << ssu.flavour(); @@ -83,11 +88,17 @@ void RndSsuCli::optFlavour(QStringList opt){ } else if (opt.count() == 3){ qout << "Changing flavour from " << ssu.flavour() << " to " << opt.at(2) << endl; - ssu.setFlavour(opt.at(2)); - SsuRepoManager repoManager; - repoManager.update(); - uidWarning(); + QDBusPendingReply<> reply = ssuProxy->setFlavour(opt.at(2)); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + ssu.setFlavour(opt.at(2)); + + SsuRepoManager repoManager; + repoManager.update(); + uidWarning(); + } state = Idle; } else if (opt.count() == 2) { @@ -98,6 +109,7 @@ void RndSsuCli::optFlavour(QStringList opt){ void RndSsuCli::optMode(QStringList opt){ QTextStream qout(stdout); + QTextStream qerr(stderr); // TODO: allow setting meaningful names instead of numbers @@ -128,11 +140,17 @@ void RndSsuCli::optMode(QStringList opt){ } else if (opt.count() == 3){ qout << "Setting device mode from " << ssu.deviceMode() << " to " << opt.at(2) << endl; - ssu.setDeviceMode(opt.at(2).toInt()); - SsuRepoManager repoManager; - repoManager.update(); - uidWarning(); + QDBusPendingReply<> reply = ssuProxy->setDeviceMode(opt.at(2).toInt()); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + ssu.setDeviceMode(opt.at(2).toInt()); + + SsuRepoManager repoManager; + repoManager.update(); + uidWarning(); + } state = Idle; } @@ -158,27 +176,33 @@ void RndSsuCli::optModifyRepo(int action, QStringList opt){ QTextStream qerr(stderr); if (opt.count() == 3){ - switch(action){ - case Add: - repoManager.add(opt.at(2)); - repoManager.update(); - uidWarning(); - break; - case Remove: - repoManager.remove(opt.at(2)); - repoManager.update(); - uidWarning(); - break; - case Disable: - repoManager.disable(opt.at(2)); - repoManager.update(); - uidWarning(); - break; - case Enable: - repoManager.enable(opt.at(2)); - repoManager.update(); - uidWarning(); - break; + QDBusPendingReply<> reply = ssuProxy->modifyRepo(action, opt.at(2)); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + + switch(action){ + case Add: + repoManager.add(opt.at(2)); + repoManager.update(); + uidWarning(); + break; + case Remove: + repoManager.remove(opt.at(2)); + repoManager.update(); + uidWarning(); + break; + case Disable: + repoManager.disable(opt.at(2)); + repoManager.update(); + uidWarning(); + break; + case Enable: + repoManager.enable(opt.at(2)); + repoManager.update(); + uidWarning(); + break; + } } } else if (opt.count() == 4 && action == Add){ QString url, repo; @@ -194,9 +218,14 @@ void RndSsuCli::optModifyRepo(int action, QStringList opt){ return; } - repoManager.add(repo, url); - repoManager.update(); - uidWarning(); + QDBusPendingReply<> reply = ssuProxy->addRepo(repo, url); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + repoManager.add(repo, url); + repoManager.update(); + uidWarning(); + } } } @@ -244,6 +273,7 @@ void RndSsuCli::optRegister(QStringList opt){ void RndSsuCli::optRelease(QStringList opt){ QTextStream qout(stdout); + QTextStream qerr(stderr); if (opt.count() == 3){ if (opt.at(2) == "-r"){ @@ -253,11 +283,17 @@ void RndSsuCli::optRelease(QStringList opt){ qout << "Changing release from " << ssu.release() << " to " << opt.at(2) << endl; qout << "Your device is now in release mode!" << endl; - ssu.setRelease(opt.at(2)); - SsuRepoManager repoManager; - repoManager.update(); - uidWarning(); + QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(2), false); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + ssu.setRelease(opt.at(2)); + + SsuRepoManager repoManager; + repoManager.update(); + uidWarning(); + } state = Idle; } @@ -268,11 +304,17 @@ void RndSsuCli::optRelease(QStringList opt){ qout << "Changing release (RnD) from " << ssu.release(true) << " to " << opt.at(3) << endl; qout << "Your device is now in RnD mode!" << endl; - ssu.setRelease(opt.at(3), true); - SsuRepoManager repoManager; - repoManager.update(); - uidWarning(); + QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(3), true); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + ssu.setRelease(opt.at(3), true); + + SsuRepoManager repoManager; + repoManager.update(); + uidWarning(); + } state = Idle; } @@ -478,16 +520,28 @@ void RndSsuCli::optUpdateCredentials(QStringList opt){ } void RndSsuCli::optUpdateRepos(){ - SsuRepoManager repoManager; - repoManager.update(); - uidWarning(); + QTextStream qerr(stdout); + + QDBusPendingReply<> reply = ssuProxy->updateRepos(); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + SsuRepoManager repoManager; + repoManager.update(); + uidWarning(); + } } void RndSsuCli::run(){ QTextStream qout(stdout); + QTextStream qerr(stderr); QStringList arguments = QCoreApplication::arguments(); + SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); + if (!ssuSettings->isWritable()) + qerr << "WARNING: ssu.ini does not seem to be writable. Setting values might not work." << endl; + if (arguments.at(0).endsWith("rndssu")) qout << "NOTE: this binary is now called ssu. The rndssu symlink will go away after some time" << endl; diff --git a/rndssucli/rndssucli.h b/rndssucli/rndssucli.h index a1519e8..f1dba49 100644 --- a/rndssucli/rndssucli.h +++ b/rndssucli/rndssucli.h @@ -21,6 +21,7 @@ class RndSsuCli: public QObject { public: RndSsuCli(); + ~RndSsuCli(); public slots: void run(); @@ -45,10 +46,10 @@ class RndSsuCli: public QObject { void optUpdateRepos(); enum Actions { - Remove, - Add, - Disable, - Enable + Remove = 0, + Add = 1, + Disable = 2, + Enable = 3, }; enum State { diff --git a/rpm/ssu.spec b/rpm/ssu.spec index 04dcaf1..c0e2b69 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -126,7 +126,7 @@ Group: Documentation %build mkdir -p build && cd build -qmake -qt=5 DEFINES+='TARGET_ARCH=\\\"\"%{_target_cpu}\"\\\"' -recursive .. +%qmake5 DEFINES+='TARGET_ARCH=\\\"\"%{_target_cpu}\"\\\"' -recursive .. make %{?_smp_mflags} cd .. && doxygen doc/Doxyfile diff --git a/ssud/ssud.cpp b/ssud/ssud.cpp index b8189ce..1298a1a 100644 --- a/ssud/ssud.cpp +++ b/ssud/ssud.cpp @@ -9,6 +9,7 @@ #include "ssuadaptor.h" #include "libssu/ssudeviceinfo.h" +#include "libssu/ssurepomanager.h" #include @@ -42,13 +43,25 @@ QString Ssud::deviceModel(){ SsuDeviceInfo deviceInfo; return deviceInfo.deviceModel(); -}; +} + +QString Ssud::deviceFamily(){ + SsuDeviceInfo deviceInfo; + + return deviceInfo.deviceFamily(); +} QString Ssud::deviceUid(){ SsuDeviceInfo deviceInfo; return deviceInfo.deviceUid(); -}; +} + +QString Ssud::deviceVariant(){ + SsuDeviceInfo deviceInfo; + + return deviceInfo.deviceVariant(); +} bool Ssud::error(){ return ssu.error(); @@ -58,14 +71,14 @@ QString Ssud::lastError(){ return ssu.lastError(); } -bool Ssud::isRegistered(){ - return ssu.isRegistered(); -} - void Ssud::quit(){ QCoreApplication::quit(); } +bool Ssud::isRegistered(){ + return ssu.isRegistered(); +} + void Ssud::registerDevice(const QString &username, const QString &password){ ssu.sendRegistration(username, password); } @@ -73,3 +86,70 @@ void Ssud::registerDevice(const QString &username, const QString &password){ void Ssud::unregisterDevice(){ ssu.unregister(); }; + + +int Ssud::deviceMode(){ + return ssu.deviceMode(); +} + +void Ssud::setDeviceMode(int mode){ + ssu.setDeviceMode(mode); + + SsuRepoManager repoManager; + repoManager.update(); +} + +QString Ssud::flavour(){ + return ssu.flavour(); +} + +void Ssud::setFlavour(const QString &flavour){ + ssu.setFlavour(flavour); + + SsuRepoManager repoManager; + repoManager.update(); +} + + +QString Ssud::release(bool rnd){ + return ssu.release(rnd); +} + +void Ssud::setRelease(const QString &release, bool rnd){ + ssu.setRelease(release, rnd); + + SsuRepoManager repoManager; + repoManager.update(); +} + +void Ssud::modifyRepo(int action, const QString &repo){ + SsuRepoManager repoManager; + + switch(action){ + case Add: + repoManager.add(repo); + break; + case Remove: + repoManager.remove(repo); + break; + case Disable: + repoManager.disable(repo); + break; + case Enable: + repoManager.enable(repo); + break; + } + + repoManager.update(); +} + +void Ssud::addRepo(const QString &repo, const QString &url){ + SsuRepoManager repoManager; + repoManager.add(repo, url); + repoManager.update(); +} + +void Ssud::updateRepos(){ + SsuRepoManager repoManager; + repoManager.update(); +} diff --git a/ssud/ssud.h b/ssud/ssud.h index b442186..93cd7db 100644 --- a/ssud/ssud.h +++ b/ssud/ssud.h @@ -21,14 +21,31 @@ class Ssud: public QObject { virtual ~Ssud(); public slots: + /* device info */ QString deviceModel(); + QString deviceFamily(); QString deviceUid(); - bool error(); - QString lastError(); + QString deviceVariant(); + /* credential management */ bool isRegistered(); - void quit(); void registerDevice(const QString &username, const QString &password); void unregisterDevice(); + /* repository management */ + int deviceMode(); + void setDeviceMode(int mode); + QString flavour(); + void setFlavour(const QString &release); + QString release(bool rnd); + void setRelease(const QString &release, bool rnd); + void modifyRepo(int action, const QString &repo); + void addRepo(const QString &repo, const QString &url); + void updateRepos(); + + bool error(); + QString lastError(); + + void quit(); + signals: void done(); @@ -39,6 +56,13 @@ class Ssud: public QObject { Ssu ssu; static const char *SERVICE_NAME; static const char *OBJECT_PATH; + + enum Actions { + Remove = 0, + Add = 1, + Disable = 2, + Enable = 3, + }; }; #endif