service.cpp
/* vi: set et sw=4 ts=4 cino=t0,(0: */
/*
* This file is part of libaccounts-qt
*
* Copyright (C) 2009-2011 Nokia Corporation.
* Copyright (C) 2012-2016 Canonical Ltd.
* Copyright (C) 2012 Intel Corporation.
*
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
* Contact: Jussi Laako <jussi.laako@linux.intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "service.h"
#undef signals
#include <libaccounts-glib.h>
using namespace Accounts;
namespace Accounts {
}; // namespace
Service::Service(AgService *service, ReferenceMode mode):
m_service(service),
m_tags(nullptr)
{
if (m_service != nullptr && mode == AddReference)
ag_service_ref(m_service);
}
Service::Service():
m_service(nullptr),
m_tags(nullptr)
{
}
Service::Service(const Service &other):
m_service(other.m_service),
m_tags(nullptr)
{
if (m_service != nullptr)
ag_service_ref(m_service);
}
Service &Service::operator=(const Service &other)
{
if (m_service == other.m_service) return *this;
if (m_service != nullptr)
ag_service_unref(m_service);
m_service = other.m_service;
if (m_service != nullptr)
ag_service_ref(m_service);
return *this;
}
Service::~Service()
{
if (m_service != nullptr) {
ag_service_unref(m_service);
m_service = nullptr;
}
if (m_tags != nullptr) {
delete m_tags;
m_tags = nullptr;
}
}
bool Service::isValid() const
{
return m_service != nullptr;
}
QString Service::name() const
{
if (Q_UNLIKELY(!isValid())) return QString();
return UTF8(ag_service_get_name(m_service));
}
QString Service::description() const
{
return UTF8(ag_service_get_description(m_service));
}
QString Service::displayName() const
{
return UTF8(ag_service_get_display_name(m_service));
}
QString Service::serviceType() const
{
return ASCII(ag_service_get_service_type(m_service));
}
QString Service::trCatalog() const
{
return ASCII(ag_service_get_i18n_domain(m_service));
}
QString Service::provider() const
{
return UTF8(ag_service_get_provider(m_service));
}
QString Service::iconName() const
{
return ASCII(ag_service_get_icon_name(m_service));
}
bool Service::hasTag(const QString &tag) const
{
return ag_service_has_tag(m_service, tag.toUtf8().constData());
}
QSet<QString> Service::tags() const
{
if (m_tags)
return *m_tags;
m_tags = new QSet<QString>;
GList *list = ag_service_get_tags(m_service);
GList *iter = list;
while (iter != NULL) {
m_tags->insert(UTF8(reinterpret_cast<const gchar *> (iter->data)));
iter = g_list_next(iter);
}
g_list_free(list);
return *m_tags;
}
const QDomDocument Service::domDocument() const
{
const gchar *data;
ag_service_get_file_contents(m_service, &data, NULL);
QDomDocument doc;
QString errorStr;
int errorLine;
int errorColumn;
if (!doc.setContent(QByteArray(data), true,
&errorStr, &errorLine, &errorColumn))
{
QString message(QStringLiteral("Parse error reading account service file "
"at line %1, column %2:\n%3"));
message = message.arg(errorLine).arg(errorColumn).arg(errorStr);
qWarning() << __PRETTY_FUNCTION__ << message;
}
return doc;
}
AgService *Service::service() const
{
return m_service;
}
Accounts::Service
Representation of an account service.
Definition service.h:49
Accounts::Service::tags
QSet< QString > tags() const
Return all tags of the service as a set.
Definition service.cpp:190
Accounts::Service::Service
Service()
Construct an invalid service.
Definition service.cpp:59
Accounts::Service::serviceType
QString serviceType() const
Get the service type ID of the service.
Definition service.cpp:142
Accounts::Service::isValid
bool isValid() const
Check whether this object represents a Service.
Definition service.cpp:104
Accounts::Service::name
QString name() const
Get the name of the service.
Definition service.cpp:114
Accounts::Service::iconName
QString iconName() const
Get the icon name for this service.
Definition service.cpp:168
Accounts::Service::displayName
QString displayName() const
Get the display name of the service, untranslated.
Definition service.cpp:133
Accounts::Service::description
QString description() const
Get the description of the service.
Definition service.cpp:124
Accounts::Service::provider
QString provider() const
Get the provider ID of the service.
Definition service.cpp:159
Accounts::Service::hasTag
bool hasTag(const QString &tag) const
Check if this service has a tag.
Definition service.cpp:180
Accounts::Service::trCatalog
QString trCatalog() const
Definition service.cpp:150
Accounts::Service::domDocument
const QDomDocument domDocument() const
Get the contents of the service XML file.
Definition service.cpp:210