Index: src/XMPPPresence.h ================================================================== --- src/XMPPPresence.h +++ src/XMPPPresence.h @@ -25,10 +25,23 @@ /** * \brief A class describing a presence stanza. */ @interface XMPPPresence: XMPPStanza +{ +/// \cond internal + OFString *status; + OFString *show; + OFNumber *priority; +/// \endcond +} +#ifdef OF_HAVE_PROPERTIES +@property (copy) OFString *status; +@property (copy) OFString *show; +@property (copy) OFNumber *priority; +#endif + /** * \brief Creates a new autoreleased XMPPPresence. * * \return A new autoreleased XMPPPresence */ @@ -87,25 +100,46 @@ */ - initWithType: (OFString*)type ID: (OFString*)ID; /** - * \brief Adds a show element to the presence stanza. + * \brief Sets/Adds the show element of the presence stanza. * * \param show The text content of the show element */ -- (void)addShow: (OFString*)show; +- (void)setShow: (OFString*)show; + +/** + * \brief Returns the text content of the show element of the presence stanza. + * + * \return The text content of the show element of the presence stanza. + */ +- (OFString*)show; /** - * \brief Adds a status element to the presence stanza. + * \brief Sets/Adds the status element of the presence stanza. * * \param status The text content of the status element */ -- (void)addStatus: (OFString*)status; +- (void)setStatus: (OFString*)status; + +/** + * \brief Returns the text content of the status element of the presence stanza. + * + * \return The text content of the status element of the presence stanza. + */ +- (OFString*)status; + +/** + * \brief Sets/Adds the priority element of the presence stanza. + * + * \param priority The numeric content of the priority element + */ +- (void)setPriority: (OFNumber*)priority; /** - * \brief Adds a priority element to the presence stanza. + * \brief Returns the numeric content of the priority element of the presence stanza. * - * \param priority The text content of the priority element + * \return The numeric content of the priority element of the presence stanza. */ -- (void)addPriority: (int8_t)priority; +- (OFNumber*)priority; @end Index: src/XMPPPresence.m ================================================================== --- src/XMPPPresence.m +++ src/XMPPPresence.m @@ -74,36 +74,94 @@ { return [super initWithName: @"presence" type: type_ ID: ID_]; } + +- (void)dealloc +{ + [status release]; + [show release]; + [priority release]; + + [super dealloc]; +} - (OFString*)type { if (type == nil) return @"available"; return [[type copy] autorelease]; } -- (void)addShow: (OFString*)show -{ - [self addChild: [OFXMLElement elementWithName: @"show" - namespace: XMPP_NS_CLIENT - stringValue: show]]; -} - -- (void)addStatus: (OFString*)status -{ - [self addChild: [OFXMLElement elementWithName: @"status" - namespace: XMPP_NS_CLIENT - stringValue: status]]; -} - -- (void)addPriority: (int8_t)priority -{ - OFString* prio = [OFString stringWithFormat: @"%" @PRId8, priority]; +- (void)setShow: (OFString*)show_ +{ + OFXMLElement *oldShow = [self elementForName: @"show" + namespace: XMPP_NS_CLIENT]; + + if (oldShow != nil) + [self removeChild: oldShow]; + + if (show_ != nil) + [self addChild: [OFXMLElement elementWithName: @"show" + namespace: XMPP_NS_CLIENT + stringValue: show_]]; + + OF_SETTER(show, show_, YES, 1); +} + +- (OFString*)show +{ + return [[show copy] autorelease]; +} + +- (void)setStatus: (OFString*)status_ +{ + OFXMLElement *oldStatus = [self elementForName: @"status" + namespace: XMPP_NS_CLIENT]; + + if (oldStatus != nil) + [self removeChild: oldStatus]; + + if (status_ != nil) + [self addChild: [OFXMLElement elementWithName: @"status" + namespace: XMPP_NS_CLIENT + stringValue: status_]]; + + OF_SETTER(status, status_, YES, 1); +} + +- (OFString*)status +{ + return [[status copy] autorelease]; +} + +- (void)setPriority: (OFNumber*)priority_ +{ + intmax_t prio = [priority_ intMaxValue]; + + if ((prio < -128) || (prio > 127)) + @throw [OFInvalidArgumentException + exceptionWithClass: [self class] + selector: _cmd]; + + OFXMLElement *oldPriority = [self elementForName: @"priority" + namespace: XMPP_NS_CLIENT]; + + if (oldPriority != nil) + [self removeChild: oldPriority]; + + OFString* priority_s = + [OFString stringWithFormat: @"%" @PRId8, [priority_ int8Value]]; [self addChild: [OFXMLElement elementWithName: @"priority" namespace: XMPP_NS_CLIENT - stringValue: prio]]; + stringValue: priority_s]]; + + OF_SETTER(priority, priority_, YES, 1); +} + +- (OFString*)priority +{ + return [[priority copy] autorelease]; } @end Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -51,13 +51,13 @@ - (void)applicationDidFinishLaunching { OFArray *arguments = [OFApplication arguments]; XMPPPresence *pres = [XMPPPresence presence]; - [pres addShow: @"chat"]; - [pres addStatus: @"Bored"]; - [pres addPriority: 20]; + [pres setShow: @"chat"]; + [pres setStatus: @"Bored"]; + [pres setPriority: [OFNumber numberWithInt8: 20]]; [pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]]; [pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]]; assert([[pres XMLString] isEqual: @"chat" @"Bored20" @@ -152,12 +152,12 @@ XMPPPresence *pres; of_log(@"Got roster: %@", [roster_ rosterItems]); pres = [XMPPPresence presence]; - [pres addPriority: 10]; - [pres addStatus: @"ObjXMPP test is working!"]; + [pres setPriority: [OFNumber numberWithInt8: 10]]; + [pres setStatus: @"ObjXMPP test is working!"]; [conn sendStanza: pres]; #ifdef OF_HAVE_BLOCKS XMPPIQ *iq = [XMPPIQ IQWithType: @"get"