summaryrefslogtreecommitdiffstats
path: root/agent/polkitqtlistener.cpp
blob: ea0ad2dbf7a0bd6d90a6a1007b386869c68af2d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * This file is part of the Polkit-qt project
 * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * polkit-qt-listener based on code by David Zeuthen <davidz@redhat.com>
 */


#include "polkitqtlistener_p.h"
#include <stdio.h>

#include <TQtCore/TQDebug>

#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1

using namespace PolkitTQt1::Agent;

/**
  * \internal
  */
struct _PolkitTQtListener {
    PolkitAgentListener parent_instance;
};

/**
  * \internal
  */
struct _PolkitTQtListenerClass {
    PolkitAgentListenerClass parent_class;
};

static void polkit_qt_listener_initiate_authentication(PolkitAgentListener  *listener,
        const gchar          *action_id,
        const gchar          *message,
        const gchar          *icon_name,
        PolkitDetails        *details,
        const gchar          *cookie,
        GList                *identities,
        GCancellable         *cancellable,
        GAsyncReadyCallback   callback,
        gpointer              user_data);

static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener  *listener,
        GAsyncResult         *res,
        GError              **error);

G_DEFINE_TYPE(PolkitTQtListener, polkit_qt_listener, POLKIT_AGENT_TYPE_LISTENER);

static void polkit_qt_listener_init(PolkitTQtListener *listener)
{
    g_type_init();
}

static void polkit_qt_listener_finalize(GObject *object)
{
    PolkitTQtListener *listener;

    listener = POLKIT_QT_LISTENER(object);

    if (G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize != NULL) {
        G_OBJECT_CLASS(polkit_qt_listener_parent_class)->finalize(object);
    }
}

static void polkit_qt_listener_class_init(PolkitTQtListenerClass *klass)
{
    GObjectClass *gobject_class;
    PolkitAgentListenerClass *listener_class;

    gobject_class = G_OBJECT_CLASS(klass);
    listener_class = POLKIT_AGENT_LISTENER_CLASS(klass);

    gobject_class->finalize = polkit_qt_listener_finalize;

    listener_class->initiate_authentication          = polkit_qt_listener_initiate_authentication;
    listener_class->initiate_authentication_finish   = polkit_qt_listener_initiate_authentication_finish;
}

PolkitAgentListener *polkit_qt_listener_new(void)
{
    return POLKIT_AGENT_LISTENER(g_object_new(POLKIT_QT_TYPE_LISTENER, NULL));
}

static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
{
    ListenerAdapter::instance()->cancelled_cb((PolkitAgentListener *)user_data);
}

static void polkit_qt_listener_initiate_authentication(PolkitAgentListener  *agent_listener,
        const gchar          *action_id,
        const gchar          *message,
        const gchar          *icon_name,
        PolkitDetails        *details,
        const gchar          *cookie,
        GList                *identities,
        GCancellable         *cancellable,
        GAsyncReadyCallback   callback,
        gpointer              user_data)
{
    tqDebug() << "Listener adapter polkit_qt_listener_initiate_authentication";
    PolkitTQtListener *listener = POLKIT_QT_LISTENER(agent_listener);

    // The result of asynchronous method will be created here and it will be pushed to the listener.
    GSimpleAsyncResult *result = g_simple_async_result_new((GObject *) listener, callback, user_data, agent_listener);
    tqDebug() << "GSimpleAsyncResult:" << result;

    ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication(agent_listener,
            action_id,
            message,
            icon_name,
            details,
            cookie,
            identities,
            cancellable,
            result);

    if (cancellable != NULL) {
        g_signal_connect(cancellable,
                         "cancelled",
                         G_CALLBACK(cancelled_cb),
                         agent_listener);
    }

}

static gboolean polkit_qt_listener_initiate_authentication_finish(PolkitAgentListener  *listener,
        GAsyncResult         *res,
        GError              **error)
{
    tqDebug() << "Listener adapter polkit_qt_listener_initiate_authentication_finish";
    return ListenerAdapter::instance()->polkit_qt_listener_initiate_authentication_finish(listener,
            res,
            error);
}