summaryrefslogtreecommitdiffstats
path: root/examples/agent/tqtlistener.cpp
blob: 59cfd40f2a6a8ccc52e47bdee0d71b42db2de94d (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
// 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("Initiate authentication for " + actionId + " with message " + message);
  tqDebug("    iconName " + iconName);
  TQStringList dkeys = details.keys();
  for (const TQString &dkey : dkeys)
  {
    tqDebug("    key " + dkey);
  }
  tqDebug("    cookie " + cookie);

  for (const PolkitTQt::Identity &identity : identities)
  {
    tqDebug(identity.toString());
    Session *session = new Session(identity, cookie, result);
    connect(session, TQT_SIGNAL(request(const TQString&, bool)), this,
            TQT_SLOT(request(const TQString&, bool)));
    connect(session, TQT_SIGNAL(completed(bool)), this, TQT_SLOT(completed(bool)));
    connect(session, TQT_SIGNAL(showError(const TQString&)), this,
            TQT_SLOT(showError(const TQString&)));
    connect(session, TQT_SIGNAL(showInfo(const TQString&)), this,
            TQT_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("Request: " + 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: ") + (gainedAuthorization ? "true" : "false"));
  Session *session = (Session*)sender();
  session->result()->setCompleted();
  delete session;
}

void TQtListener::showError(const TQString &text)
{
  tqDebug("Error: " + text);
}

void TQtListener::showInfo(const TQString &text)
{
  tqDebug("Info: " + text);
}

#include "tqtlistener.moc"