Commit 97a95aa8 authored by Lukas Appelhans's avatar Lukas Appelhans
Browse files

Use the async version instead of the sync one and then block with a QEventLoop

parent ab815c16
......@@ -83,6 +83,7 @@ qt4_automoc(${AKABEI_OPERATION_SRCS})
# There are some files which are not detected by automoc, add them
qt4_wrap_cpp(AKABEI_MISSING_MOCS
akabeibackend_p.h
akabeihelpers_p.h
operations/akabeiplainscriptletoperation_p.h
)
......
......@@ -325,13 +325,34 @@ Permissions permissionsOfPath(const QString &path)
return perm;
}
AuthorityLoop::AuthorityLoop(QObject* parent)
: QEventLoop(parent)
{}
AuthorityLoop::~AuthorityLoop() {}
PolkitQt1::Authority::Result AuthorityLoop::result()
{
return m_result;
}
void AuthorityLoop::quit(PolkitQt1::Authority::Result res)
{
m_result = res;
QEventLoop::quit();
}
bool checkAuthorizationSync(const QString &action)
{
PolkitQt1::Authority::Result auth = PolkitQt1::Authority::instance()->checkAuthorizationSync(action,
AuthorityLoop e;
QObject::connect(PolkitQt1::Authority::instance(), SIGNAL(checkAuthorizationFinished(PolkitQt1::Authority::Result)), &e, SLOT(quit(PolkitQt1::Authority::Result)));
PolkitQt1::Authority::instance()->checkAuthorization(action,
PolkitQt1::UnixProcessSubject(static_cast<uint>(QCoreApplication::applicationPid())),
PolkitQt1::Authority::AllowUserInteraction);
return (auth == PolkitQt1::Authority::Yes);
e.exec();
return e.result();//(auth == PolkitQt1::Authority::Yes);
}
///////
......
......@@ -14,6 +14,8 @@
#include <akabeihelpers.h>
#include <QStringList>
#include <QEventLoop>
#include <polkit-qt-1/polkitqt1-authority.h>
namespace Akabei
{
......@@ -22,6 +24,23 @@ namespace Helpers
int compare_versions(QString const& a, QString const& b);
QStringList stringlistFromDb(const QString &);
QByteArray md5sumOfFileWithoutPolkit(const QString &file);
class AuthorityLoop : public QEventLoop
{
Q_OBJECT
Q_DISABLE_COPY(AuthorityLoop)
public:
AuthorityLoop(QObject* parent = 0);
virtual ~AuthorityLoop();
PolkitQt1::Authority::Result result();
public slots:
virtual void quit(PolkitQt1::Authority::Result res);
private:
PolkitQt1::Authority::Result m_result;
};
}
}
......
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