~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to iris/xmpp-im/types.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
//Added by qt3to4:
27
27
#include <QList>
28
28
 
 
29
#include "xmpp_xmlcommon.h"
29
30
#define NS_XML     "http://www.w3.org/XML/1998/namespace"
30
31
 
31
 
static QDomElement textTag(QDomDocument *doc, const QString &name, const QString &content)
32
 
{
33
 
        QDomElement tag = doc->createElement(name);
34
 
        QDomText text = doc->createTextNode(content);
35
 
        tag.appendChild(text);
36
 
 
37
 
        return tag;
38
 
}
39
 
 
40
 
static QString tagContent(const QDomElement &e)
41
 
{
42
 
        // look for some tag content
43
 
        for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
44
 
                QDomText i = n.toText();
45
 
                if(i.isNull())
46
 
                        continue;
47
 
                return i.data();
48
 
        }
49
 
 
50
 
        return "";
51
 
}
52
 
 
53
 
static QDateTime stamp2TS(const QString &ts)
54
 
{
55
 
        if(ts.length() != 17)
56
 
                return QDateTime();
57
 
 
58
 
        int year  = ts.mid(0,4).toInt();
59
 
        int month = ts.mid(4,2).toInt();
60
 
        int day   = ts.mid(6,2).toInt();
61
 
 
62
 
        int hour  = ts.mid(9,2).toInt();
63
 
        int min   = ts.mid(12,2).toInt();
64
 
        int sec   = ts.mid(15,2).toInt();
65
 
 
66
 
        QDate xd;
67
 
        xd.setYMD(year, month, day);
68
 
        if(!xd.isValid())
69
 
                return QDateTime();
70
 
 
71
 
        QTime xt;
72
 
        xt.setHMS(hour, min, sec);
73
 
        if(!xt.isValid())
74
 
                return QDateTime();
75
 
 
76
 
        return QDateTime(xd, xt);
77
 
}
78
 
 
79
 
static QString TS2stamp(const QDateTime &d)
80
 
{
81
 
        QString str;
82
 
 
83
 
        str.sprintf("%04d%02d%02dT%02d:%02d:%02d",
84
 
                d.date().year(),
85
 
                d.date().month(),
86
 
                d.date().day(),
87
 
                d.time().hour(),
88
 
                d.time().minute(),
89
 
                d.time().second());
90
 
 
91
 
        return str;
92
 
}
93
 
 
94
32
namespace XMPP
95
33
{
96
34
 
902
840
{
903
841
}
904
842
 
905
 
HTMLElement::HTMLElement(const QDomElement &body) : body_(body) {}
 
843
HTMLElement::HTMLElement(const QDomElement &body) { setBody(body); }
906
844
 
907
845
void HTMLElement::setBody(const QDomElement &body)
908
846
{
909
 
        body_ = body;
 
847
        body_ = doc_.importNode(body, true).toElement();
910
848
}
911
849
 
912
850
const QDomElement& HTMLElement::body() const
970
908
        QString eventId;
971
909
        QString xencrypted, invite;
972
910
        ChatState chatState;
 
911
        MessageReceipt messageReceipt;
973
912
        QString nick;
974
913
        HttpAuthRequest httpAuthRequest;
975
914
        XData xdata;
976
915
        QMap<QString,HTMLElement> htmlElements;
977
 
        QDomElement wb;
 
916
        QDomElement sxe;
978
917
        
979
918
        int mucStatus;
980
919
        QList<MUCInvite> mucInvites;
981
920
        MUCDecline mucDecline;
982
921
        QString mucPassword;
983
 
        int mucHistoryMaxChars, mucHistoryMaxStanzas, mucHistorySeconds;
984
922
 
985
923
        bool spooled, wasEncrypted;
986
924
};
1003
941
        d->errorCode = -1;*/
1004
942
        d->chatState = StateNone;
1005
943
        d->mucStatus = -1;
 
944
        d->messageReceipt = ReceiptNone;
1006
945
}
1007
946
 
1008
947
//! \brief Constructs a copy of Message object
1332
1271
        d->chatState = state;
1333
1272
}
1334
1273
 
 
1274
MessageReceipt Message::messageReceipt() const
 
1275
{
 
1276
        return d->messageReceipt;
 
1277
}
 
1278
 
 
1279
void Message::setMessageReceipt(MessageReceipt messageReceipt)
 
1280
{
 
1281
        d->messageReceipt = messageReceipt;
 
1282
}
 
1283
 
1335
1284
QString Message::xencrypted() const
1336
1285
{
1337
1286
        return d->xencrypted;
1427
1376
        return d->xdata;
1428
1377
}
1429
1378
 
1430
 
const QDomElement& Message::whiteboard() const
 
1379
const QDomElement& Message::sxe() const
1431
1380
{
1432
 
        return d->wb;
 
1381
        return d->sxe;
1433
1382
}
1434
1383
 
1435
 
void Message::setWhiteboard(const QDomElement& e)
 
1384
void Message::setSxe(const QDomElement& e)
1436
1385
{
1437
 
        d->wb = e;
 
1386
        d->sxe = e;
1438
1387
}
1439
1388
 
1440
1389
bool Message::spooled() const
1569
1518
                }
1570
1519
        }
1571
1520
 
 
1521
        // message receipt
 
1522
        QString messageReceiptNS = "urn:xmpp:receipts";
 
1523
        if (d->messageReceipt != ReceiptNone) {
 
1524
                switch(d->messageReceipt) {
 
1525
                        case ReceiptRequest:
 
1526
                                s.appendChild(s.createElement(messageReceiptNS, "request"));
 
1527
                                break;
 
1528
                        case ReceiptReceived:
 
1529
                                s.appendChild(s.createElement(messageReceiptNS, "received"));
 
1530
                                break;
 
1531
                        default: 
 
1532
                                break;
 
1533
                }
 
1534
        }
 
1535
 
1572
1536
        // xencrypted
1573
1537
        if(!d->xencrypted.isEmpty())
1574
1538
                s.appendChild(s.createTextElement("jabber:x:encrypted", "x", d->xencrypted));
1603
1567
                s.appendChild(s.createTextElement("http://jabber.org/protocol/nick", "nick", d->nick));
1604
1568
        }
1605
1569
 
1606
 
        // wb
1607
 
        if(!d->wb.isNull()) {
1608
 
                s.appendChild(d->wb);
 
1570
        // sxe
 
1571
        if(!d->sxe.isNull()) {
 
1572
                s.appendChild(d->sxe);
1609
1573
        }
1610
1574
 
1611
1575
        // muc
1657
1621
 
1658
1622
        QDomElement root = s.element();
1659
1623
 
1660
 
        QDomNodeList nl = root.childNodes();
 
1624
        XDomNodeList nl = root.childNodes();
1661
1625
        int n;
1662
1626
        for(n = 0; n < nl.count(); ++n) {
1663
1627
                QDomNode i = nl.item(n);
1707
1671
                d->error = s.error();
1708
1672
 
1709
1673
        // xhtml-im
1710
 
        nl = root.elementsByTagNameNS("http://jabber.org/protocol/xhtml-im", "html");
 
1674
        nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/xhtml-im", "html");
1711
1675
        if (nl.count()) {
1712
1676
                nl = nl.item(0).childNodes();
1713
1677
                for(n = 0; n < nl.count(); ++n) {
1720
1684
        }
1721
1685
 
1722
1686
        // timestamp
1723
 
        QDomElement t = root.elementsByTagNameNS("jabber:x:delay", "x").item(0).toElement();
 
1687
        QDomElement t = childElementsByTagNameNS(root, "jabber:x:delay", "x").item(0).toElement();
1724
1688
        if(!t.isNull()) {
1725
1689
                d->timeStamp = stamp2TS(t.attribute("stamp"));
1726
1690
                d->timeStamp = d->timeStamp.addSecs(timeZoneOffset * 3600);
1733
1697
 
1734
1698
        // urls
1735
1699
        d->urlList.clear();
1736
 
        nl = root.elementsByTagNameNS("jabber:x:oob", "x");
 
1700
        nl = childElementsByTagNameNS(root, "jabber:x:oob", "x");
1737
1701
        for(n = 0; n < nl.count(); ++n) {
1738
1702
                QDomElement t = nl.item(n).toElement();
1739
1703
                Url u;
1744
1708
        
1745
1709
    // events
1746
1710
        d->eventList.clear();
1747
 
        nl = root.elementsByTagNameNS("jabber:x:event", "x");
 
1711
        nl = childElementsByTagNameNS(root, "jabber:x:event", "x");
1748
1712
        if (nl.count()) {
1749
1713
                nl = nl.item(0).childNodes();
1750
1714
                for(n = 0; n < nl.count(); ++n) {
1765
1729
 
1766
1730
        // Chat states
1767
1731
        QString chatStateNS = "http://jabber.org/protocol/chatstates";
1768
 
        t = root.elementsByTagNameNS(chatStateNS, "active").item(0).toElement();
 
1732
        t = childElementsByTagNameNS(root, chatStateNS, "active").item(0).toElement();
1769
1733
        if(!t.isNull())
1770
1734
                d->chatState = StateActive;
1771
 
        t = root.elementsByTagNameNS(chatStateNS, "composing").item(0).toElement();
 
1735
        t = childElementsByTagNameNS(root, chatStateNS, "composing").item(0).toElement();
1772
1736
        if(!t.isNull())
1773
1737
                d->chatState = StateComposing;
1774
 
        t = root.elementsByTagNameNS(chatStateNS, "paused").item(0).toElement();
 
1738
        t = childElementsByTagNameNS(root, chatStateNS, "paused").item(0).toElement();
1775
1739
        if(!t.isNull())
1776
1740
                d->chatState = StatePaused;
1777
 
        t = root.elementsByTagNameNS(chatStateNS, "inactive").item(0).toElement();
 
1741
        t = childElementsByTagNameNS(root, chatStateNS, "inactive").item(0).toElement();
1778
1742
        if(!t.isNull())
1779
1743
                d->chatState = StateInactive;
1780
 
        t = root.elementsByTagNameNS(chatStateNS, "gone").item(0).toElement();
 
1744
        t = childElementsByTagNameNS(root, chatStateNS, "gone").item(0).toElement();
1781
1745
        if(!t.isNull())
1782
1746
                d->chatState = StateGone;
1783
 
        
 
1747
 
 
1748
        // message receipts
 
1749
        QString messageReceiptNS = "urn:xmpp:receipts";
 
1750
        t = childElementsByTagNameNS(root, messageReceiptNS, "request").item(0).toElement();
 
1751
        if(!t.isNull())
 
1752
                d->messageReceipt = ReceiptRequest;
 
1753
        t = childElementsByTagNameNS(root, messageReceiptNS, "received").item(0).toElement();
 
1754
        if(!t.isNull())
 
1755
                d->messageReceipt = ReceiptReceived;
1784
1756
 
1785
1757
        // xencrypted
1786
 
        t = root.elementsByTagNameNS("jabber:x:encrypted", "x").item(0).toElement();
 
1758
        t = childElementsByTagNameNS(root, "jabber:x:encrypted", "x").item(0).toElement();
1787
1759
        if(!t.isNull())
1788
1760
                d->xencrypted = t.text();
1789
1761
        else
1791
1763
                
1792
1764
        // addresses
1793
1765
        d->addressList.clear();
1794
 
        nl = root.elementsByTagNameNS("http://jabber.org/protocol/address", "addresses");
 
1766
        nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/address", "addresses");
1795
1767
        if (nl.count()) {
1796
1768
                QDomElement t = nl.item(0).toElement();
1797
1769
                nl = t.elementsByTagName("address");
1802
1774
        
1803
1775
        // roster item exchange
1804
1776
        d->rosterExchangeItems.clear();
1805
 
        nl = root.elementsByTagNameNS("http://jabber.org/protocol/rosterx", "x");
 
1777
        nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/rosterx", "x");
1806
1778
        if (nl.count()) {
1807
1779
                QDomElement t = nl.item(0).toElement();
1808
1780
                nl = t.elementsByTagName("item");
1814
1786
        }
1815
1787
 
1816
1788
        // invite
1817
 
        t = root.elementsByTagNameNS("jabber:x:conference", "x").item(0).toElement();
 
1789
        t = childElementsByTagNameNS(root, "jabber:x:conference", "x").item(0).toElement();
1818
1790
        if(!t.isNull())
1819
1791
                d->invite = t.attribute("jid");
1820
1792
        else
1821
1793
                d->invite = QString();
1822
1794
        
1823
1795
        // nick
1824
 
        t = root.elementsByTagNameNS("http://jabber.org/protocol/nick", "nick").item(0).toElement();
 
1796
        t = childElementsByTagNameNS(root, "http://jabber.org/protocol/nick", "nick").item(0).toElement();
1825
1797
        if(!t.isNull())
1826
1798
                d->nick = t.text();
1827
1799
        else
1828
1800
                d->nick = QString();
1829
1801
 
1830
 
        // wb
1831
 
        t = root.elementsByTagNameNS("http://jabber.org/protocol/svgwb", "wb").item(0).toElement();
 
1802
        // sxe
 
1803
        t = childElementsByTagNameNS(root, "http://jabber.org/protocol/sxe", "sxe").item(0).toElement();
1832
1804
        if(!t.isNull())
1833
 
                d->wb = t;
 
1805
                d->sxe = t;
1834
1806
        else
1835
 
                d->wb = QDomElement();
 
1807
                d->sxe = QDomElement();
1836
1808
 
1837
 
        t = root.elementsByTagNameNS("http://jabber.org/protocol/muc#user", "x").item(0).toElement();
 
1809
        t = childElementsByTagNameNS(root, "http://jabber.org/protocol/muc#user", "x").item(0).toElement();
1838
1810
        if(!t.isNull()) {
1839
1811
                for(QDomNode muc_n = t.firstChild(); !muc_n.isNull(); muc_n = muc_n.nextSibling()) {
1840
1812
                        QDomElement muc_e = muc_n.toElement();
1858
1830
        }
1859
1831
 
1860
1832
        // http auth
1861
 
        t = root.elementsByTagNameNS("http://jabber.org/protocol/http-auth", "confirm").item(0).toElement();
 
1833
        t = childElementsByTagNameNS(root, "http://jabber.org/protocol/http-auth", "confirm").item(0).toElement();
1862
1834
        if(!t.isNull()){
1863
1835
                d->httpAuthRequest = HttpAuthRequest(t);
1864
1836
        }
1867
1839
        }
1868
1840
 
1869
1841
        // data form
1870
 
        t = root.elementsByTagNameNS("jabber:x:data", "x").item(0).toElement();
 
1842
        t = childElementsByTagNameNS(root, "jabber:x:data", "x").item(0).toElement();
1871
1843
        if(!t.isNull()){
1872
1844
                d->xdata.fromXml(t);
1873
1845
        }
2258
2230
 
2259
2231
bool Status::isAway() const
2260
2232
{
2261
 
        if(v_show == "away" || v_show == "xa" || v_show == "dnd")
2262
 
                return true;
2263
 
 
2264
 
        return false;
 
2233
        return (v_show == "away" || v_show == "xa" || v_show == "dnd");
2265
2234
}
2266
2235
 
2267
2236
bool Status::isInvisible() const