accounts-qt  1.13
provider.cpp
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-2014 Canonical Ltd.
00007  *
00008  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public License
00012  * version 2.1 as published by the Free Software Foundation.
00013  *
00014  * This library is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00022  * 02110-1301 USA
00023  */
00024 
00025 #include "provider.h"
00026 
00027 #undef signals
00028 #include <libaccounts-glib/ag-provider.h>
00029 
00030 
00031 using namespace Accounts;
00032 
00033 namespace Accounts {
00044 }; // namespace
00045 
00046 Provider::Provider(AgProvider *provider, ReferenceMode mode):
00047     m_provider(provider)
00048 {
00049     if (m_provider != 0 && mode == AddReference)
00050         ag_provider_ref(m_provider);
00051 }
00052 
00056 Provider::Provider():
00057     m_provider(0)
00058 {
00059 }
00060 
00065 Provider::Provider(const Provider &other):
00066     m_provider(other.m_provider)
00067 {
00068     if (m_provider != 0)
00069         ag_provider_ref(m_provider);
00070 }
00071 
00072 Provider &Provider::operator=(const Provider &other)
00073 {
00074     if (m_provider == other.m_provider) return *this;
00075     if (m_provider != 0)
00076         ag_provider_unref(m_provider);
00077     m_provider = other.m_provider;
00078     if (m_provider != 0)
00079         ag_provider_ref(m_provider);
00080     return *this;
00081 }
00082 
00083 Provider::~Provider()
00084 {
00085     if (m_provider != 0) {
00086         ag_provider_unref(m_provider);
00087         m_provider = 0;
00088     }
00089 }
00090 
00095 bool Provider::isValid() const
00096 {
00097     return m_provider != 0;
00098 }
00099 
00105 QString Provider::name() const
00106 {
00107     if (Q_UNLIKELY(!isValid())) return QString();
00108     return UTF8(ag_provider_get_name(m_provider));
00109 }
00110 
00115 QString Provider::displayName() const
00116 {
00117     return UTF8(ag_provider_get_display_name(m_provider));
00118 }
00119 
00124 QString Provider::description() const
00125 {
00126     return UTF8(ag_provider_get_description(m_provider));
00127 }
00128 
00135 QString Provider::pluginName() const
00136 {
00137     return UTF8(ag_provider_get_plugin_name(m_provider));
00138 }
00139 
00144 QString Provider::trCatalog() const
00145 {
00146     return ASCII(ag_provider_get_i18n_domain(m_provider));
00147 }
00148 
00152 QString Provider::iconName() const
00153 {
00154     return ASCII(ag_provider_get_icon_name(m_provider));
00155 }
00156 
00161 QString Provider::domainsRegExp() const
00162 {
00163     return UTF8(ag_provider_get_domains_regex(m_provider));
00164 }
00165 
00169 bool Provider::isSingleAccount() const
00170 {
00171     return ag_provider_get_single_account(m_provider);
00172 }
00173 
00177 const QDomDocument Provider::domDocument() const
00178 {
00179     const gchar *data;
00180 
00181     ag_provider_get_file_contents(m_provider, &data);
00182 
00183     QDomDocument doc;
00184     QString errorStr;
00185     int errorLine;
00186     int errorColumn;
00187     if (!doc.setContent(QByteArray(data), true,
00188                         &errorStr, &errorLine, &errorColumn))
00189     {
00190         QString message(ASCII("Parse error reading account provider file "
00191                               "at line %1, column %2:\n%3"));
00192         message.arg(errorLine).arg(errorColumn).arg(errorStr);
00193         qWarning() << __PRETTY_FUNCTION__ << message;
00194     }
00195 
00196     return doc;
00197 }
00198 
00199 AgProvider *Provider::provider() const
00200 {
00201     return m_provider;
00202 }
00203