File indexing completed on 2024-04-14 04:38:31

0001 /*
0002     This file is part of the PolKit1-qt project
0003     SPDX-FileCopyrightText: 2009 Radek Novacek <rnovacek@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "polkitqt1-temporaryauthorization.h"
0009 #include "polkitqt1-authority.h"
0010 
0011 #include <polkit/polkit.h>
0012 
0013 namespace PolkitQt1
0014 {
0015 
0016 class Q_DECL_HIDDEN TemporaryAuthorization::Data : public QSharedData
0017 {
0018 public:
0019     Data() {}
0020     Data(const Data& other)
0021         : QSharedData(other)
0022         , id(other.id)
0023         , actionId(other.actionId)
0024         , subject(other.subject)
0025         , timeObtained(other.timeObtained)
0026         , timeExpires(other.timeExpires)
0027     {
0028     }
0029     ~Data() {}
0030 
0031     QString id;
0032     QString actionId;
0033     Subject subject;
0034     QDateTime timeObtained;
0035     QDateTime timeExpires;
0036 };
0037 
0038 TemporaryAuthorization::TemporaryAuthorization(PolkitTemporaryAuthorization *pkTemporaryAuthorization)
0039         : d(new Data)
0040 {
0041     d->id = QString::fromUtf8(polkit_temporary_authorization_get_id(pkTemporaryAuthorization));
0042     d->actionId = QString::fromUtf8(polkit_temporary_authorization_get_action_id(pkTemporaryAuthorization));
0043     d->subject = Subject::fromString(polkit_subject_to_string(polkit_temporary_authorization_get_subject(pkTemporaryAuthorization)));
0044     d->timeObtained = QDateTime::fromSecsSinceEpoch(polkit_temporary_authorization_get_time_obtained(pkTemporaryAuthorization));
0045     d->timeExpires = QDateTime::fromSecsSinceEpoch(polkit_temporary_authorization_get_time_expires(pkTemporaryAuthorization));
0046     g_object_unref(pkTemporaryAuthorization);
0047 }
0048 
0049 TemporaryAuthorization::TemporaryAuthorization(const PolkitQt1::TemporaryAuthorization& other)
0050         : d(other.d)
0051 {
0052 
0053 }
0054 
0055 TemporaryAuthorization::TemporaryAuthorization()
0056         : d(new Data)
0057 {
0058 
0059 }
0060 
0061 TemporaryAuthorization& TemporaryAuthorization::operator=(const PolkitQt1::TemporaryAuthorization& other)
0062 {
0063     d = other.d;
0064     return *this;
0065 }
0066 
0067 TemporaryAuthorization::~TemporaryAuthorization()
0068 {
0069 }
0070 
0071 QString TemporaryAuthorization::id() const
0072 {
0073     return d->id;
0074 }
0075 
0076 QString TemporaryAuthorization::actionId() const
0077 {
0078     return d->actionId;
0079 }
0080 
0081 Subject TemporaryAuthorization::subject() const
0082 {
0083     //qFatal(polkit_subject_to_string(polkit_temporary_authorization_get_subject(d->temporaryAuthorization)));
0084     return d->subject;//Subject::fromString(polkit_subject_to_string(d->subject));
0085 }
0086 
0087 QDateTime TemporaryAuthorization::obtainedAt() const
0088 {
0089     return d->timeObtained;
0090 }
0091 
0092 QDateTime TemporaryAuthorization::expirationTime() const
0093 {
0094     return d->timeExpires;
0095 }
0096 
0097 bool TemporaryAuthorization::revoke()
0098 {
0099     Authority::instance()->revokeTemporaryAuthorization(id());
0100     return true;
0101 }
0102 
0103 }