provider.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.
*
* Contact: Alberto Mardegan <alberto.mardegan@canonical.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 "provider.h"
#undef signals
#include <libaccounts-glib/ag-provider.h>
using namespace Accounts;
namespace Accounts {
}; // namespace
Provider::Provider(AgProvider *provider, ReferenceMode mode):
m_provider(provider)
{
if (m_provider != nullptr && mode == AddReference)
ag_provider_ref(m_provider);
}
Provider::Provider():
m_provider(nullptr)
{
}
Provider::Provider(const Provider &other):
m_provider(other.m_provider)
{
if (m_provider != nullptr)
ag_provider_ref(m_provider);
}
Provider &Provider::operator=(const Provider &other)
{
if (m_provider == other.m_provider) return *this;
if (m_provider != nullptr)
ag_provider_unref(m_provider);
m_provider = other.m_provider;
if (m_provider != nullptr)
ag_provider_ref(m_provider);
return *this;
}
Provider::~Provider()
{
if (m_provider != nullptr) {
ag_provider_unref(m_provider);
m_provider = nullptr;
}
}
bool Provider::isValid() const
{
return m_provider != nullptr;
}
QString Provider::name() const
{
if (Q_UNLIKELY(!isValid())) return QString();
return UTF8(ag_provider_get_name(m_provider));
}
QString Provider::displayName() const
{
return UTF8(ag_provider_get_display_name(m_provider));
}
QString Provider::description() const
{
return UTF8(ag_provider_get_description(m_provider));
}
QString Provider::pluginName() const
{
return UTF8(ag_provider_get_plugin_name(m_provider));
}
QString Provider::trCatalog() const
{
return ASCII(ag_provider_get_i18n_domain(m_provider));
}
QString Provider::iconName() const
{
return ASCII(ag_provider_get_icon_name(m_provider));
}
QString Provider::domainsRegExp() const
{
return UTF8(ag_provider_get_domains_regex(m_provider));
}
bool Provider::isSingleAccount() const
{
return ag_provider_get_single_account(m_provider);
}
const QDomDocument Provider::domDocument() const
{
const gchar *data;
ag_provider_get_file_contents(m_provider, &data);
QDomDocument doc;
QString errorStr;
int errorLine;
int errorColumn;
if (!doc.setContent(QByteArray(data), true,
&errorStr, &errorLine, &errorColumn))
{
QString message(QStringLiteral("Parse error reading account provider file "
"at line %1, column %2:\n%3"));
message = message.arg(errorLine).arg(errorColumn).arg(errorStr);
qWarning() << __PRETTY_FUNCTION__ << message;
}
return doc;
}
AgProvider *Provider::provider() const
{
return m_provider;
}
Accounts::Provider::isValid
bool isValid() const
Check whether this object represents a Provider.
Definition: provider.cpp:95
Accounts::Provider::domainsRegExp
QString domainsRegExp() const
Definition: provider.cpp:161
Accounts::Provider::isSingleAccount
bool isSingleAccount() const
Definition: provider.cpp:169
Accounts::Provider::description
QString description() const
Get the description of the provider, untranslated.
Definition: provider.cpp:124
Accounts::Provider::trCatalog
QString trCatalog() const
Definition: provider.cpp:144
Accounts::Provider::Provider
Provider()
Construct an invalid provider.
Definition: provider.cpp:56
Accounts::Provider::name
QString name() const
Get the name of the provider.
Definition: provider.cpp:105
Accounts::Provider
Representation of an account provider.
Definition: provider.h:49
Accounts::Provider::displayName
QString displayName() const
Get the display name of the provider, untranslated.
Definition: provider.cpp:115
Accounts::Provider::domDocument
const QDomDocument domDocument() const
Definition: provider.cpp:177
Accounts::Provider::iconName
QString iconName() const
Definition: provider.cpp:152
Accounts::Provider::pluginName
QString pluginName() const
Get the name of the account plugin associated with the provider.
Definition: provider.cpp:135