~kyrofa/junk/pay-service-2

« back to all changes in this revision

Viewing changes to service/token-grabber-u1.cpp

  • Committer: CI bot
  • Author(s): Ted Gould
  • Date: 2014-06-18 18:47:04 UTC
  • mfrom: (8.1.10 devel)
  • Revision ID: ps-jenkins@lists.canonical.com-20140618184704-roe2dx6dwvvw37km
Fixes from integration work to make the pay demo come together. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *   Ted Gould <ted.gould@canonical.com>
 
18
 */
 
19
 
 
20
#include "token-grabber-u1.h"
 
21
#include "qtbridge.h"
 
22
 
 
23
#include <ssoservice.h>
 
24
#include <token.h>
 
25
 
 
26
class TokenGrabberU1Qt: public QObject
 
27
{
 
28
    Q_OBJECT
 
29
 
 
30
public:
 
31
    explicit TokenGrabberU1Qt (QObject* parent = 0);
 
32
    void run (void);
 
33
    std::string signUrl(std::string url, std::string type);
 
34
 
 
35
private Q_SLOTS:
 
36
    void handleCredentialsFound(const UbuntuOne::Token& token);
 
37
    void handleCredentialsNotFound();
 
38
 
 
39
private:
 
40
    UbuntuOne::Token token;
 
41
    UbuntuOne::SSOService service;
 
42
};
 
43
 
 
44
TokenGrabberU1Qt::TokenGrabberU1Qt (QObject* parent) :
 
45
    QObject(parent)
 
46
{
 
47
    std::cout << "Token grabber built" << std::endl;
 
48
}
 
49
 
 
50
void TokenGrabberU1Qt::run (void)
 
51
{
 
52
    std::cout << "Token grabber running" << std::endl;
 
53
 
 
54
    QObject::connect(&service,
 
55
                     &UbuntuOne::SSOService::credentialsFound,
 
56
                     this,
 
57
                     &TokenGrabberU1Qt::handleCredentialsFound);
 
58
    QObject::connect(&service,
 
59
                     &UbuntuOne::SSOService::credentialsNotFound,
 
60
                     this,
 
61
                     &TokenGrabberU1Qt::handleCredentialsNotFound);
 
62
 
 
63
    service.getCredentials();
 
64
}
 
65
 
 
66
void TokenGrabberU1Qt::handleCredentialsFound(const UbuntuOne::Token& in_token)
 
67
{
 
68
    token = in_token;
 
69
    std::cout << "Got a Token" << std::endl;
 
70
}
 
71
 
 
72
void TokenGrabberU1Qt::handleCredentialsNotFound()
 
73
{
 
74
    std::cout << "No Token :-(" << std::endl;
 
75
}
 
76
 
 
77
std::string TokenGrabberU1Qt::signUrl (std::string url, std::string type)
 
78
{
 
79
    std::string retval;
 
80
 
 
81
    auto qretval = token.signUrl(url.c_str(), type.c_str());
 
82
    retval = std::string(qretval.toUtf8());
 
83
 
 
84
    return retval;
 
85
}
 
86
 
 
87
TokenGrabberU1::TokenGrabberU1 (void)
 
88
{
 
89
    //qt = std::make_shared<TokenGrabberU1Qt>();
 
90
    qtfuture = qt::core::world::enter_with_task_and_expect_result<std::shared_ptr<TokenGrabberU1Qt>>([]()
 
91
    {
 
92
        auto qtgrabber = std::make_shared<TokenGrabberU1Qt>();
 
93
        qtgrabber->run();
 
94
        return qtgrabber;
 
95
    });
 
96
}
 
97
 
 
98
TokenGrabberU1::~TokenGrabberU1 (void)
 
99
{
 
100
}
 
101
 
 
102
std::string TokenGrabberU1::signUrl (std::string url, std::string type)
 
103
{
 
104
    if (qtfuture.valid())
 
105
    {
 
106
        return qtfuture.get()->signUrl(url, type);
 
107
    }
 
108
 
 
109
    std::string retval;
 
110
    return retval;
 
111
}
 
112
 
 
113
#include "token-grabber-u1.moc"