File indexing completed on 2024-06-23 04:03:40

0001 /*
0002  * xmpp_discoitem.cpp
0003  * Copyright (C) 2003  Justin Karneges
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * either version 2
0009    of the License, or (at your option) any later version.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0019  *
0020  */
0021 
0022 #include "xmpp_discoitem.h"
0023 
0024 using namespace XMPP;
0025 
0026 class DiscoItem::Private
0027 {
0028 public:
0029     Private()
0030     {
0031         action = None;
0032     }
0033 
0034     Jid jid;
0035     QString name;
0036     QString node;
0037     Action action;
0038 
0039     Features features;
0040     Identities identities;
0041 };
0042 
0043 DiscoItem::DiscoItem()
0044 {
0045     d = new Private;
0046 }
0047 
0048 DiscoItem::DiscoItem(const DiscoItem &from)
0049 {
0050     d = new Private;
0051     *this = from;
0052 }
0053 
0054 DiscoItem & DiscoItem::operator= (const DiscoItem &from)
0055 {
0056     d->jid = from.d->jid;
0057     d->name = from.d->name;
0058     d->node = from.d->node;
0059     d->action = from.d->action;
0060     d->features = from.d->features;
0061     d->identities = from.d->identities;
0062 
0063     return *this;
0064 }
0065 
0066 DiscoItem::~DiscoItem()
0067 {
0068     delete d;
0069 }
0070 
0071 AgentItem DiscoItem::toAgentItem() const
0072 {
0073     AgentItem ai;
0074 
0075     ai.setJid( jid() );
0076     ai.setName( name() );
0077 
0078     Identity id;
0079     if ( !identities().isEmpty() )
0080         id = identities().first();
0081 
0082     ai.setCategory( id.category );
0083     ai.setType( id.type );
0084 
0085     ai.setFeatures( d->features );
0086 
0087     return ai;
0088 }
0089 
0090 void DiscoItem::fromAgentItem(const AgentItem &ai)
0091 {
0092     setJid( ai.jid() );
0093     setName( ai.name() );
0094 
0095     Identity id;
0096     id.category = ai.category();
0097     id.type = ai.type();
0098     id.name = ai.name();
0099 
0100     Identities idList;
0101     idList << id;
0102 
0103     setIdentities( idList );
0104 
0105     setFeatures( ai.features() );
0106 }
0107 
0108 const Jid &DiscoItem::jid() const
0109 {
0110     return d->jid;
0111 }
0112 
0113 void DiscoItem::setJid(const Jid &j)
0114 {
0115     d->jid = j;
0116 }
0117 
0118 const QString &DiscoItem::name() const
0119 {
0120     return d->name;
0121 }
0122 
0123 void DiscoItem::setName(const QString &n)
0124 {
0125     d->name = n;
0126 }
0127 
0128 const QString &DiscoItem::node() const
0129 {
0130     return d->node;
0131 }
0132 
0133 void DiscoItem::setNode(const QString &n)
0134 {
0135     d->node = n;
0136 }
0137 
0138 DiscoItem::Action DiscoItem::action() const
0139 {
0140     return d->action;
0141 }
0142 
0143 void DiscoItem::setAction(Action a)
0144 {
0145     d->action = a;
0146 }
0147 
0148 const Features &DiscoItem::features() const
0149 {
0150     return d->features;
0151 }
0152 
0153 void DiscoItem::setFeatures(const Features &f)
0154 {
0155     d->features = f;
0156 }
0157 
0158 const DiscoItem::Identities &DiscoItem::identities() const
0159 {
0160     return d->identities;
0161 }
0162 
0163 void DiscoItem::setIdentities(const Identities &i)
0164 {
0165     d->identities = i;
0166 
0167     if ( name().isEmpty() && i.count() )
0168         setName( i.first().name );
0169 }
0170 
0171 
0172 DiscoItem::Action DiscoItem::string2action(QString s)
0173 {
0174     Action a;
0175 
0176     if ( s == "update" )
0177         a = Update;
0178     else if ( s == "remove" )
0179         a = Remove;
0180     else
0181         a = None;
0182 
0183     return a;
0184 }
0185 
0186 QString DiscoItem::action2string(Action a)
0187 {
0188     QString s;
0189 
0190     if ( a == Update )
0191         s = "update";
0192     else if ( a == Remove )
0193         s = "remove";
0194     else
0195         s = QString();
0196 
0197     return s;
0198 }
0199 
0200