summaryrefslogtreecommitdiffstats
path: root/examples/agent/tqtlistener.cpp
blob: 90a327faff87de585c162273958273a5f74e6a05 (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
// This is an example not a library
/*
 * This file is part of the Polkit-tqt 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.
 */

#include "tqstringlist.h"
#include "tqinputdialog.h"

#include "polkit-tqt-identity.h"
#include "polkit-tqt-details.h"
#include "polkit-tqt-agent-session.h"
#include "tqtlistener.h"


using namespace PolkitTQt::Agent;

TQtListener::TQtListener(TQObject *parent) : Listener(parent)
{
  tqDebug("Registering TQt listener");
}

void TQtListener::initiateAuthentication(const TQString &actionId, const TQString &message,
        const TQString &iconName, const PolkitTQt::Details &details, const TQString &cookie,
        const PolkitTQt::Identity::List &identities, AsyncResult *result)
{
  tqDebug(TQString("Initiate authentication for %1 with message %2").arg(actionId).arg(message));
  tqDebug(TQString("    iconName %1").arg(iconName));
  TQStringList dkeys = details.keys();
  for (const TQString &dkey : dkeys)
  {
    tqDebug(TQString("    key %1").arg(dkey));
  }
  tqDebug(TQString("    cookie %1").arg(cookie));

  for (const PolkitTQt::Identity &identity : identities)
  {
    tqDebug(identity.toString());
    Session *session = new Session(identity, cookie, result);
    connect(session, TQ_SIGNAL(request(const TQString&, bool)), this,
            TQ_SLOT(request(const TQString&, bool)));
    connect(session, TQ_SIGNAL(completed(bool)), this, TQ_SLOT(completed(bool)));
    connect(session, TQ_SIGNAL(showError(const TQString&)), this,
            TQ_SLOT(showError(const TQString&)));
    connect(session, TQ_SIGNAL(showInfo(const TQString&)), this,
            TQ_SLOT(showInfo(const TQString&)));
    session->initiate();
  }
}

bool TQtListener::initiateAuthenticationFinish()
{
  tqDebug("InitiateAuthenticationFinish() done");
  return true;
}

void TQtListener::cancelAuthentication()
{
  tqDebug("Cancelling authentication");
}

void TQtListener::request(const TQString &request, bool echo)
{
  tqDebug(TQString("Request: %1").arg(request));
  Session *session = (Session*)sender();
  bool ok;
  TQString text = TQInputDialog::getText("TQt Agent", "Enter authorization password:",
      TQLineEdit::Password, TQString::null, &ok, nullptr );
  if (ok && !text.isEmpty())
  {
    session->setResponse(text);
  }
  else
  {
    session->setResponse(TQString::null);
  }
}

void TQtListener::completed(bool gainedAuthorization)
{
  tqDebug(TQString("Completed: %1").arg(gainedAuthorization ? "true" : "false"));
  Session *session = (Session*)sender();
  session->result()->setCompleted();
  delete session;
}

void TQtListener::showError(const TQString &text)
{
  tqDebug(TQString("Error: %1").arg(text));
}

void TQtListener::showInfo(const TQString &text)
{
  tqDebug(TQString("Info: %1").arg(text));
}

#include "tqtlistener.moc"