accounts-qt: Accounts/service-type.cpp Source File

accounts-qt 1.12

- Main Page
- Related Pages
- Classes
- Files

- File List

service-type.cpp
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /*
3 * This file is part of libaccounts-qt
4 *
5 * Copyright (C) 2009-2011 Nokia Corporation.
6 * Copyright (C) 2012 Canonical Ltd.
7 * Copyright (C) 2012 Intel Corporation.
8 *
9 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
10 * Contact: Jussi Laako <jussi.laako@linux.intel.com>
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * version 2.1 as published by the Free Software Foundation.
15 *
16 * This library is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 */
26
27 #include "service-type.h"
28
29 #undef signals
30 #include <libaccounts-glib/ag-service-type.h>
31
32 using namespace Accounts;
33
34 namespace Accounts {
46 }; // namespace
47
48 ServiceType::ServiceType(AgServiceType *serviceType, ReferenceMode mode):
49 m_serviceType(serviceType),
50 m_tags(0)
51 {
52 if (m_serviceType != 0 && mode == AddReference)
53 ag_service_type_ref(m_serviceType);
54 }
55
59 ServiceType::ServiceType():
60 m_serviceType(0),
61 m_tags(0)
62 {
63 }
64
69 ServiceType::ServiceType(const ServiceType &other):
70 m_serviceType(other.m_serviceType),
71 m_tags(0)
72 {
73 if (m_serviceType != 0)
74 ag_service_type_ref(m_serviceType);
75 }
76
77 ServiceType &ServiceType::operator=(const ServiceType &other)
78 {
79 if (m_serviceType == other.m_serviceType) return *this;
80 if (m_serviceType != 0)
81 ag_service_type_unref(m_serviceType);
82 m_serviceType = other.m_serviceType;
83 if (m_serviceType != 0)
84 ag_service_type_ref(m_serviceType);
85 return *this;
86 }
87
88 ServiceType::~ServiceType()
89 {
90 if (m_serviceType != 0) {
91 ag_service_type_unref(m_serviceType);
92 m_serviceType = 0;
93 }
94 if (m_tags != 0) {
95 delete m_tags;
96 m_tags = 0;
97 }
98 }
99
104 bool ServiceType::isValid() const
105 {
106 return m_serviceType != 0;
107 }
108
112 QString ServiceType::name() const
113 {
114 if (Q_UNLIKELY(!isValid())) return QString();
115 return UTF8(ag_service_type_get_name(m_serviceType));
116 }
117
126 QString ServiceType::displayName() const
127 {
128 const gchar *id;
129
130 /* libaccounts-glib returns the display name untranslated. */
131 id = ag_service_type_get_display_name(m_serviceType);
132 if (id != NULL) {
133 return qtTrId(id);
134 } else {
135 return QString();
136 }
137 }
138
143 QString ServiceType::trCatalog() const
144 {
145 return ASCII(ag_service_type_get_i18n_domain(m_serviceType));
146 }
147
151 QString ServiceType::iconName() const
152 {
153 return ASCII(ag_service_type_get_icon_name(m_serviceType));
154 }
155
163 bool ServiceType::hasTag(const QString &tag) const
164 {
165 return ag_service_type_has_tag(m_serviceType, tag.toUtf8().constData());
166 }
167
173 QSet<QString> ServiceType::tags() const
174 {
175 if (m_tags)
176 return *m_tags;
177
178 m_tags = new QSet<QString>;
179 GList *list = ag_service_type_get_tags(m_serviceType);
180 GList *iter = list;
181 while (iter != NULL) {
182 m_tags->insert(UTF8(reinterpret_cast<const gchar *> (iter->data)));
183 iter = g_list_next(iter);
184 }
185 g_list_free(list);
186 return *m_tags;
187 }
188
192 const QDomDocument ServiceType::domDocument() const
193 {
194 const gchar *data;
195 gsize len;
196
197 ag_service_type_get_file_contents(m_serviceType, &data, &len);
198
199 QDomDocument doc;
200 QString errorStr;
201 int errorLine;
202 int errorColumn;
203 if (!doc.setContent(QByteArray(data, len), true,
204 &errorStr, &errorLine, &errorColumn)) {
205 QString message(ASCII("Parse error reading serviceType file "
206 "at line %1, column %2:\n%3"));
207 message.arg(errorLine).arg(errorColumn).arg(errorStr);
208 qWarning() << __PRETTY_FUNCTION__ << message;
209 }
210
211 return doc;
212 }
213
Accounts::ServiceType::iconName
QString iconName() const
Definition: service-type.cpp:151
Accounts::ServiceType::trCatalog
QString trCatalog() const
Definition: service-type.cpp:143
Accounts::ServiceType
Representation of an account service type.
Definition: service-type.h:49
Accounts::ServiceType::ServiceType
ServiceType()
Construct an invalid serviceType.
Definition: service-type.cpp:59
Accounts::ServiceType::hasTag
bool hasTag(const QString &tag) const
Check if this service type has a tag.
Definition: service-type.cpp:163
Accounts::ServiceType::domDocument
const QDomDocument domDocument() const
Definition: service-type.cpp:192
Accounts::ServiceType::displayName
QString displayName() const
Definition: service-type.cpp:126
Accounts::ServiceType::isValid
bool isValid() const
Check whether this object represents a ServiceType.
Definition: service-type.cpp:104
Accounts::ServiceType::tags
QSet< QString > tags() const
Return all tags of the service type as a set.
Definition: service-type.cpp:173
Accounts::ServiceType::name
QString name() const
Returns the name (ID) of the service type.
Definition: service-type.cpp:112