|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qcontactactiondescriptor.h" |
|
43 #include "qcontactactiondescriptor_p.h" |
|
44 #include <QHash> |
|
45 |
|
46 QTM_BEGIN_NAMESPACE |
|
47 |
|
48 /*! |
|
49 \class QContactActionDescriptor |
|
50 \brief The QContactActionDescriptor class provides information that |
|
51 uniquely identifies a specific implementation of an action |
|
52 \ingroup contacts-actions |
|
53 */ |
|
54 |
|
55 /*! |
|
56 * Constructs a new action descriptor for the implementation of the action identified by the given \a actionName |
|
57 * of the given implementation \a vendorVersion, as implemented by the vendor identified by the given \a vendorName |
|
58 */ |
|
59 QContactActionDescriptor::QContactActionDescriptor(const QString& actionName, const QString& vendorName, int vendorVersion) |
|
60 : d(new QContactActionDescriptorPrivate(actionName, vendorName, vendorVersion)) |
|
61 { |
|
62 } |
|
63 |
|
64 /*! |
|
65 * Constructs a copy of the \a other action descriptor |
|
66 */ |
|
67 QContactActionDescriptor::QContactActionDescriptor(const QContactActionDescriptor& other) |
|
68 : d(other.d) |
|
69 { |
|
70 } |
|
71 |
|
72 /*! |
|
73 * Assigns this action descriptor to be equal to \a other |
|
74 */ |
|
75 QContactActionDescriptor& QContactActionDescriptor::operator=(const QContactActionDescriptor& other) |
|
76 { |
|
77 d = other.d; |
|
78 return *this; |
|
79 } |
|
80 |
|
81 /*! |
|
82 * Cleans up any memory in use by the action descriptor |
|
83 */ |
|
84 QContactActionDescriptor::~QContactActionDescriptor() |
|
85 { |
|
86 } |
|
87 |
|
88 /*! |
|
89 * Sets the name of the action identified by this action descriptor to \a actionName |
|
90 */ |
|
91 void QContactActionDescriptor::setActionName(const QString& actionName) |
|
92 { |
|
93 d->m_actionName = actionName; |
|
94 } |
|
95 |
|
96 /*! |
|
97 * Sets the name of the vendor of the action implementation identified by this action descriptor to \a vendorName |
|
98 */ |
|
99 void QContactActionDescriptor::setVendorName(const QString& vendorName) |
|
100 { |
|
101 d->m_vendorName = vendorName; |
|
102 } |
|
103 |
|
104 /*! |
|
105 * Sets the vendor-specified implementation version of the action implementation identified by this action descriptor to \a implementationVersion |
|
106 */ |
|
107 void QContactActionDescriptor::setImplementationVersion(int implementationVersion) |
|
108 { |
|
109 d->m_implementationVersion = implementationVersion; |
|
110 } |
|
111 |
|
112 /*! |
|
113 * Returns the name of the action which is identified by the action descriptor |
|
114 */ |
|
115 QString QContactActionDescriptor::actionName() const |
|
116 { |
|
117 return d->m_actionName; |
|
118 } |
|
119 |
|
120 /*! |
|
121 * Returns the name of the vendor of the action implementation which is identified by the action descriptor |
|
122 */ |
|
123 QString QContactActionDescriptor::vendorName() const |
|
124 { |
|
125 return d->m_vendorName; |
|
126 } |
|
127 |
|
128 /*! |
|
129 * Returns the vendor-specified version of the action implementation which is identified by the action descriptor |
|
130 */ |
|
131 int QContactActionDescriptor::implementationVersion() const |
|
132 { |
|
133 return d->m_implementationVersion; |
|
134 } |
|
135 |
|
136 /*! |
|
137 * Returns true if either the name, vendor and version of the descriptor are missing from the descriptor. |
|
138 * An empty descriptor cannot uniquely identify an action. |
|
139 */ |
|
140 bool QContactActionDescriptor::isEmpty() const |
|
141 { |
|
142 if (d->m_actionName.isEmpty()) |
|
143 return true; |
|
144 if (d->m_vendorName.isEmpty()) |
|
145 return true; |
|
146 if (d->m_implementationVersion <= 0) |
|
147 return true; |
|
148 return false; |
|
149 } |
|
150 |
|
151 /*! |
|
152 * Returns true if the action name, vendor name and vendor-specified implementation version |
|
153 * specified by this action descriptor are equal to those specified by \a other |
|
154 */ |
|
155 bool QContactActionDescriptor::operator==(const QContactActionDescriptor& other) const |
|
156 { |
|
157 return d->m_actionName == other.d->m_actionName |
|
158 && d->m_vendorName == other.d->m_vendorName |
|
159 && d->m_implementationVersion == other.d->m_implementationVersion; |
|
160 } |
|
161 |
|
162 /*! |
|
163 * Returns true if the action name, vendor name or vendor-specified implementation version |
|
164 * specified by this action descriptor are different to that specified by \a other |
|
165 */ |
|
166 bool QContactActionDescriptor::operator!=(const QContactActionDescriptor& other) const |
|
167 { |
|
168 return !(*this == other); |
|
169 } |
|
170 |
|
171 /*! |
|
172 * Returns true if the action descriptor is less than the \a other action descriptor. The |
|
173 * comparison is performed first on the vendor name, then the action name, then the implementation |
|
174 * version. |
|
175 */ |
|
176 bool QContactActionDescriptor::operator<(const QContactActionDescriptor& other) const |
|
177 { |
|
178 int comp = d->m_vendorName.compare(other.d->m_vendorName); |
|
179 if (comp != 0) |
|
180 return comp < 0; |
|
181 comp = d->m_actionName.compare(other.d->m_actionName); |
|
182 if (comp != 0) |
|
183 return comp < 0; |
|
184 return d->m_implementationVersion < other.d->m_implementationVersion; |
|
185 } |
|
186 |
|
187 /*! Returns the hash value for \a key. */ |
|
188 uint qHash(const QContactActionDescriptor& key) |
|
189 { |
|
190 return QT_PREPEND_NAMESPACE(qHash)(key.vendorName()) |
|
191 + QT_PREPEND_NAMESPACE(qHash)(key.actionName()) |
|
192 + QT_PREPEND_NAMESPACE(qHash)(key.implementationVersion()); |
|
193 } |
|
194 |
|
195 QTM_END_NAMESPACE |