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.Xml.Dom;
25 
26 namespace agsXMPP.protocol.extensions.commands
27 {
28     /*
29       <xs:element name='actions'>
30         <xs:complexType>
31           <xs:sequence>
32             <xs:element name='prev' type='empty' minOccurs='0'/>
33             <xs:element name='next' type='empty' minOccurs='0'/>
34             <xs:element name='complete' type='empty' minOccurs='0'/>
35           </xs:sequence>
36           <xs:attribute name='execute' use='optional'>
37             <xs:simpleType>
38               <xs:restriction base='xs:NCName'>
39                 <xs:enumeration value='complete'/>
40                 <xs:enumeration value='next'/>
41                 <xs:enumeration value='prev'/>
42               </xs:restriction>
43             </xs:simpleType>
44           </xs:attribute>
45         </xs:complexType>
46       </xs:element>
47 
48       <actions execute='complete'>
49         <prev/>
50         <complete/>
51       </actions>
52     */
53     public class Actions : Element
54     {
Actions()55         public Actions()
56         {
57             this.TagName    = "actions";
58             this.Namespace  = Uri.COMMANDS;
59         }
60 
61         /// <summary>
62         /// Optional Execute Action, only complete, next and previous is allowed
63         /// </summary>
64         public Action Execute
65         {
66 			get
67 			{
68 				return (Action) GetAttributeEnum("execute", typeof(Action));
69 			}
70 			set
71 			{
72 				if (value == Action.NONE)
73                     RemoveAttribute("execute");
74 				else
75                     SetAttribute("execute", value.ToString());
76 			}
77 		}
78 
79 
80         /// <summary>
81         ///
82         /// </summary>
83         public bool Complete
84         {
85             get { return HasTag("complete"); }
86             set
87             {
88                 if (value)
89                     this.SetTag("complete");
90                 else
91                     this.RemoveTag("complete");
92             }
93         }
94 
95         public bool Next
96         {
97             get { return HasTag("next"); }
98             set
99             {
100                 if (value)
101                     this.SetTag("next");
102                 else
103                     this.RemoveTag("next");
104             }
105         }
106 
107         public bool Previous
108         {
109             get { return HasTag("prev"); }
110             set
111             {
112                 if (value)
113                     this.SetTag("prev");
114                 else
115                     this.RemoveTag("prev");
116             }
117         }
118 
119         /// <summary>
120         /// Actions, only complete, prev and next are allowed here and can be combined
121         /// </summary>
122         public Action Action
123         {
124             get
125             {
126                 Action res = 0;
127 
128                 if (Complete)
129                     res |= Action.complete;
130                 if (Previous)
131                     res |= Action.prev;
132                 if (Next)
133                     res |= Action.next;
134 
135                 if (res == 0)
136                     return Action.NONE;
137                 else
138                     return res;
139             }
140             set
141             {
142                 if (value == Action.NONE)
143                 {
144                     Complete    = false;
145                     Previous    = false;
146                     Next        = false;
147                 }
148                 else
149                 {
150                     Complete    = ((value & Action.complete) == Action.complete);
151                     Previous    = ((value & Action.prev) == Action.prev);
152                     Next        = ((value & Action.next) == Action.next);
153                 }
154             }
155         }
156     }
157 }