accounts-qt
1.15
|
00001 /* vi: set et sw=4 ts=4 cino=t0,(0: */ 00002 /* 00003 * This file is part of libaccounts-qt 00004 * 00005 * Copyright (C) 2009-2011 Nokia Corporation. 00006 * Copyright (C) 2012-2016 Canonical Ltd. 00007 * Copyright (C) 2012 Intel Corporation. 00008 * 00009 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00010 * Contact: Jussi Laako <jussi.laako@linux.intel.com> 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public License 00014 * version 2.1 as published by the Free Software Foundation. 00015 * 00016 * This library is distributed in the hope that it will be useful, but 00017 * WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00024 * 02110-1301 USA 00025 */ 00026 00027 #include "service.h" 00028 00029 #undef signals 00030 #include <libaccounts-glib/ag-service.h> 00031 00032 using namespace Accounts; 00033 00034 namespace Accounts { 00046 }; // namespace 00047 00048 Service::Service(AgService *service, ReferenceMode mode): 00049 m_service(service), 00050 m_tags(0) 00051 { 00052 if (m_service != 0 && mode == AddReference) 00053 ag_service_ref(m_service); 00054 } 00055 00059 Service::Service(): 00060 m_service(0), 00061 m_tags(0) 00062 { 00063 } 00064 00069 Service::Service(const Service &other): 00070 m_service(other.m_service), 00071 m_tags(0) 00072 { 00073 if (m_service != 0) 00074 ag_service_ref(m_service); 00075 } 00076 00077 Service &Service::operator=(const Service &other) 00078 { 00079 if (m_service == other.m_service) return *this; 00080 if (m_service != 0) 00081 ag_service_unref(m_service); 00082 m_service = other.m_service; 00083 if (m_service != 0) 00084 ag_service_ref(m_service); 00085 return *this; 00086 } 00087 00088 Service::~Service() 00089 { 00090 if (m_service != 0) { 00091 ag_service_unref(m_service); 00092 m_service = 0; 00093 } 00094 if (m_tags != 0) { 00095 delete m_tags; 00096 m_tags = 0; 00097 } 00098 } 00099 00104 bool Service::isValid() const 00105 { 00106 return m_service != 0; 00107 } 00108 00114 QString Service::name() const 00115 { 00116 if (Q_UNLIKELY(!isValid())) return QString(); 00117 return UTF8(ag_service_get_name(m_service)); 00118 } 00119 00124 QString Service::displayName() const 00125 { 00126 return UTF8(ag_service_get_display_name(m_service)); 00127 } 00128 00133 QString Service::serviceType() const 00134 { 00135 return ASCII(ag_service_get_service_type(m_service)); 00136 } 00137 00141 QString Service::trCatalog() const 00142 { 00143 return ASCII(ag_service_get_i18n_domain(m_service)); 00144 } 00145 00150 QString Service::provider() const 00151 { 00152 return UTF8(ag_service_get_provider(m_service)); 00153 } 00154 00159 QString Service::iconName() const 00160 { 00161 return ASCII(ag_service_get_icon_name(m_service)); 00162 } 00163 00171 bool Service::hasTag(const QString &tag) const 00172 { 00173 return ag_service_has_tag(m_service, tag.toUtf8().constData()); 00174 } 00175 00181 QSet<QString> Service::tags() const 00182 { 00183 if (m_tags) 00184 return *m_tags; 00185 00186 m_tags = new QSet<QString>; 00187 GList *list = ag_service_get_tags(m_service); 00188 GList *iter = list; 00189 while (iter != NULL) { 00190 m_tags->insert(UTF8(reinterpret_cast<const gchar *> (iter->data))); 00191 iter = g_list_next(iter); 00192 } 00193 g_list_free(list); 00194 return *m_tags; 00195 } 00196 00201 const QDomDocument Service::domDocument() const 00202 { 00203 const gchar *data; 00204 00205 ag_service_get_file_contents(m_service, &data, NULL); 00206 00207 QDomDocument doc; 00208 QString errorStr; 00209 int errorLine; 00210 int errorColumn; 00211 if (!doc.setContent(QByteArray(data), true, 00212 &errorStr, &errorLine, &errorColumn)) 00213 { 00214 QString message(QStringLiteral("Parse error reading account service file " 00215 "at line %1, column %2:\n%3")); 00216 message = message.arg(errorLine).arg(errorColumn).arg(errorStr); 00217 qWarning() << __PRETTY_FUNCTION__ << message; 00218 } 00219 return doc; 00220 } 00221 00222 AgService *Service::service() const 00223 { 00224 return m_service; 00225 } 00226