~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/tasks/jt_privatestorage.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /*
 
2
    Copyright (c) 2007      by Olivier Goffart  <ogoffart@kde.org>
 
3
 
 
4
    Kopete    (c) 2007 by the Kopete developers <kopete-devel@kde.org>
 
5
 
 
6
    *************************************************************************
 
7
    *                                                                       *
 
8
    * This program is free software; you can redistribute it and/or modify  *
 
9
    * it under the terms of the GNU General Public License as published by  *
 
10
    * the Free Software Foundation; either version 2 of the License, or     *
 
11
    * (at your option) any later version.                                   *
 
12
    *                                                                       *
 
13
    *************************************************************************
 
14
 */
 
15
 
 
16
#include "jt_privatestorage.h"
 
17
#include "xmpp_xmlcommon.h"
 
18
#include "xmpp_client.h"
 
19
 
 
20
using namespace XMPP;
 
21
 
 
22
 
 
23
 
 
24
//----------------------------------------------------------------------------
 
25
// JT_PrivateStorage
 
26
//----------------------------------------------------------------------------
 
27
class JT_PrivateStorage::Private
 
28
{
 
29
        public:
 
30
                Private() : type(-1) {}
 
31
 
 
32
                QDomElement iq;
 
33
                QDomElement elem;
 
34
                int type;
 
35
};
 
36
 
 
37
JT_PrivateStorage::JT_PrivateStorage(Task *parent)
 
38
        :Task(parent), d(new Private())
 
39
{
 
40
}
 
41
 
 
42
JT_PrivateStorage::~JT_PrivateStorage()
 
43
{
 
44
        delete d;
 
45
}
 
46
 
 
47
void JT_PrivateStorage::get(const QString& tag, const QString& xmlns)
 
48
{
 
49
        d->type = 0;
 
50
        d->iq = createIQ(doc(), "get" , QString() , id() );
 
51
        QDomElement query = doc()->createElement("query");
 
52
        query.setAttribute("xmlns", "jabber:iq:private");
 
53
        d->iq.appendChild(query);
 
54
        QDomElement s = doc()->createElement(tag);
 
55
        if(!xmlns.isEmpty())
 
56
                s.setAttribute("xmlns", xmlns);
 
57
        query.appendChild(s);
 
58
}
 
59
 
 
60
void JT_PrivateStorage::set(const QDomElement& element)
 
61
{
 
62
        d->type = 1;
 
63
        d->elem=element;
 
64
        QDomNode n=doc()->importNode(element,true);
 
65
 
 
66
        d->iq = createIQ(doc(), "set" , QString() , id() );
 
67
        QDomElement query = doc()->createElement("query");
 
68
        query.setAttribute("xmlns", "jabber:iq:private");
 
69
        d->iq.appendChild(query);
 
70
        query.appendChild(n);
 
71
}
 
72
 
 
73
void JT_PrivateStorage::onGo()
 
74
{
 
75
        send(d->iq);
 
76
}
 
77
 
 
78
bool JT_PrivateStorage::take(const QDomElement &x)
 
79
{
 
80
        QString to = client()->host();
 
81
        if(!iqVerify(x, to, id()))
 
82
                return false;
 
83
 
 
84
        if(x.attribute("type") == "result") {
 
85
                if(d->type == 0) {
 
86
                        QDomElement q = queryTag(x);
 
87
                        for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
88
                                QDomElement i = n.toElement();
 
89
                                if(i.isNull())
 
90
                                        continue;
 
91
                                d->elem=i;
 
92
                                break;
 
93
                        }
 
94
                }
 
95
                setSuccess();
 
96
                return true;
 
97
        }
 
98
        else {
 
99
                setError(x);
 
100
        }
 
101
 
 
102
        return true;
 
103
}
 
104
 
 
105
 
 
106
QDomElement JT_PrivateStorage::element( )
 
107
{
 
108
        return d->elem;
 
109
}
 
110
 
 
111
#include "jt_privatestorage.moc"