1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright (c) 2003-2012 by AG-Software 											 *
3  * All Rights Reserved.																 *
4  * Contact information for AG-Software is available at http://www.ag-software.de	 *
5  *																					 *
6  * Licence:																			 *
7  * The agsXMPP SDK is released under a dual licence									 *
8  * agsXMPP can be used under either of two licences									 *
9  * 																					 *
10  * A commercial licence which is probably the most appropriate for commercial 		 *
11  * corporate use and closed source projects. 										 *
12  *																					 *
13  * The GNU Public License (GPL) is probably most appropriate for inclusion in		 *
14  * other open source projects.														 *
15  *																					 *
16  * See README.html for details.														 *
17  *																					 *
18  * For general enquiries visit our website at:										 *
19  * http://www.ag-software.de														 *
20  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 
22 using System;
23 
24 using agsXMPP.protocol.extensions.primary;
25 using agsXMPP.protocol.extensions.nickname;
26 using agsXMPP.protocol.extensions.caps;
27 
28 namespace agsXMPP.protocol.client
29 {
30 	/// <summary>
31 	/// Zusammenfassung f�r Presence.
32 	/// </summary>
33 	public class Presence : Base.StanzaWithError
34     {
35         #region << Constructors >>
Presence()36         public Presence()
37 		{
38 			this.TagName	= "presence";
39 			this.Namespace	= Uri.CLIENT;
40 		}
41 
Presence(ShowType show, string status)42 		public Presence(ShowType show, string status) : this()
43 		{
44 			this.Show		= show;
45 			this.Status		= status;
46 		}
47 
Presence(ShowType show, string status, int priority)48 		public Presence(ShowType show, string status, int priority) : this(show, status)
49 		{
50 			this.Priority	= priority;
51         }
52         #endregion
53 
54         /// <summary>
55         /// The OPTIONAL statuc contains a natural-language description of availability status.
56         /// It is normally used in conjunction with the show element to provide a detailed description of an availability state
57         /// (e.g., "In a meeting").
58         /// </summary>
59 		public string Status
60 		{
61 			get { return GetTag("status"); }
62 			set { SetTag("status", value); }
63 		}
64 
65         /// <summary>
66         /// The type of a presence stanza is OPTIONAL.
67         /// A presence stanza that does not possess a type attribute is used to signal to the server that the sender is online and available
68         /// for communication. If included, the type attribute specifies a lack of availability, a request to manage a subscription
69         /// to another entity's presence, a request for another entity's current presence, or an error related to a previously-sent
70         /// presence stanza.
71         /// </summary>
72 		public PresenceType Type
73 		{
74 			get
75 			{
76 				return (PresenceType) GetAttributeEnum("type", typeof(PresenceType));
77 			}
78 			set
79 			{
80 				// dont add type="available"
81 				if (value == PresenceType.available)
82 					RemoveAttribute("type");
83 				else
84 					SetAttribute("type", value.ToString());
85 			}
86 
87 		}
88 
89         /// <summary>
90         /// The OPTIONAL show element contains non-human-readable XML character data that specifies the particular availability
91         /// status of an entity or specific resource.
92         /// </summary>
93 		public ShowType Show
94 		{
95 			get { return (ShowType) GetTagEnum("show", typeof(ShowType)); }
96 			set
97 			{
98                 if (value != ShowType.NONE)
99                     SetTag("show", value.ToString());
100                 else
101                     RemoveAttribute("show");
102 			}
103 		}
104 
105 		/// <summary>
106         /// The priority level of the resource. The value MUST be an integer between -128 and +127.
107         /// If no priority is provided, a server SHOULD consider the priority to be zero.
108 		/// </summary>
109         /// <remarks>
110         /// For information regarding the semantics of priority values in stanza routing
111         /// within instant messaging and presence applications, refer to Server Rules
112         /// for Handling XML StanzasServer Rules for Handling XML Stanzas.
113         /// </remarks>
114 		public int Priority
115 		{
116 			get
117 			{
118 				try
119 				{
120 					return int.Parse(GetTag("priority"));
121 				}
122 				catch
123 				{
124 					return 0;
125 				}
126 			}
127 			set { SetTag("priority", value.ToString()); }
128 		}
129 
130 		public x.Delay XDelay
131 		{
132 			get	{ return SelectSingleElement(typeof(x.Delay)) as x.Delay; }
133 			set
134             {
135                 if (HasTag(typeof(x.Delay)))
136                     RemoveTag(typeof(x.Delay));
137 
138                 if (value != null)
139                     this.AddChild(value);
140             }
141 		}
142 
143 		public bool IsPrimary
144 		{
145 			get
146 			{
147 				return GetTag(typeof(Primary)) == null ? false : true;
148 			}
149 			set
150 			{
151 				if (value)
152 					SetTag(typeof(Primary));
153 				else
154 					RemoveTag(typeof(Primary));
155 			}
156 		}
157 
158         /// <summary>
159         ///
160         /// </summary>
161         public x.muc.User MucUser
162         {
163             get { return SelectSingleElement(typeof(x.muc.User)) as x.muc.User; }
164             set
165             {
166                 if (HasTag(typeof(x.muc.User)))
167                     RemoveTag(typeof(x.muc.User));
168 
169                 if (value != null)
170                     this.AddChild(value);
171             }
172         }
173 
174         /// <summary>
175         /// The muc element. Doesn't have much use
176         /// </summary>
177         public x.muc.Muc Muc
178         {
179             get { return SelectSingleElement(typeof(x.muc.Muc)) as x.muc.Muc; }
180             set
181             {
182                 if (HasTag(typeof(x.muc.Muc)))
183                     RemoveTag(typeof(x.muc.Muc));
184 
185                 if (value != null)
186                     this.AddChild(value);
187             }
188         }
189 
190         /// <summary>
191         /// in case of away, says how long the user was idle
192         /// </summary>
193         public iq.last.Last Last
194         {
195             get { return SelectSingleElement(typeof(iq.last.Last)) as iq.last.Last; }
196             set
197             {
198                 if (HasTag(typeof(iq.last.Last)))
199                     RemoveTag(typeof(iq.last.Last));
200 
201                 if (value != null)
202                     this.AddChild(value);
203             }
204         }
205 
206         /// <summary>
207         /// Nickname Element
208         /// </summary>
209         public Nickname Nickname
210         {
211             get
212             {
213                 return SelectSingleElement(typeof(Nickname)) as Nickname;
214             }
215             set
216             {
217                 if (HasTag(typeof(Nickname)))
218                     RemoveTag(typeof(Nickname));
219 
220                 if (value != null)
221                     AddChild(value);
222             }
223         }
224 
225         public Capabilities Capabilities
226         {
227             get
228             {
229                 return SelectSingleElement<Capabilities>();
230             }
231             set
232             {
233                 RemoveTag<Capabilities>();
234 
235                 if (value != null)
236                     AddChild(value);
237             }
238         }
239 	}
240 }
241