Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • beta/202506161038
  • stable/20250613.0
  • nightly/20250613.0
  • beta/202506101658
  • stable/20250610.0
  • nightly/20250610.0
  • beta/202506091027
  • beta/202506061543
  • nightly/20250605.0
  • beta/202506051039
  • beta/202506051002
  • beta/202506041611
  • beta/202506041335
  • beta/202505231812
  • stable/20250523.0
  • nightly/20250523.0
  • nightly/20250515.0
  • nightly/20250510.0
  • nightly/20250509.1
  • nightly/20250509.0
21 results

namedirectory.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    namedirectory.cpp 5.11 KiB
    /****************************************************************************
     *    Copyright (C) 2016-2024 Savoir-faire Linux Inc.                       *
     *   Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com>          *
     *                                                                          *
     *   This library is free software; you can redistribute it and/or          *
     *   modify it under the terms of the GNU Lesser General Public             *
     *   License as published by the Free Software Foundation; either           *
     *   version 2.1 of the License, or (at your option) any later version.     *
     *                                                                          *
     *   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 General Public License      *
     *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
     ***************************************************************************/
    
    #include <QCoreApplication>
    
    #include "namedirectory.h"
    #include "private/namedirectory_p.h"
    #include "dbus/configurationmanager.h"
    
    NameDirectoryPrivate::NameDirectoryPrivate(NameDirectory* q)
        : q_ptr(q)
    {
        ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
    
        connect(&configurationManager,
                &ConfigurationManagerInterface::nameRegistrationEnded,
                this,
                &NameDirectoryPrivate::slotNameRegistrationEnded,
                Qt::QueuedConnection);
        connect(&configurationManager,
                &ConfigurationManagerInterface::registeredNameFound,
                this,
                &NameDirectoryPrivate::slotRegisteredNameFound,
                Qt::QueuedConnection);
        connect(&configurationManager,
                &ConfigurationManagerInterface::exportOnRingEnded,
                this,
                &NameDirectoryPrivate::slotExportOnRingEnded,
                Qt::QueuedConnection);
    }
    
    NameDirectory::NameDirectory()
        : QObject(QCoreApplication::instance())
        , d_ptr(new NameDirectoryPrivate(this))
    {}
    
    /// Singleton
    NameDirectory&
    NameDirectory::instance()
    {
        static auto instance = new NameDirectory;
        return *instance;
    }
    
    // Name registration ended
    void
    NameDirectoryPrivate::slotNameRegistrationEnded(const QString& accountId,
                                                    int status,
                                                    const QString& name)
    {
        LC_DBG << "Name registration ended. Account:" << accountId << "status:" << status
               << "name:" << name;
    
        Q_EMIT q_ptr->nameRegistrationEnded(static_cast<NameDirectory::RegisterNameStatus>(status),
                                            name);
    }
    
    // Registered Name found
    void
    NameDirectoryPrivate::slotRegisteredNameFound(const QString& accountId,
                                                  int status,
                                                  const QString& address,
                                                  const QString& name)
    {
        switch (static_cast<NameDirectory::LookupStatus>(status)) {
        case NameDirectory::LookupStatus::INVALID_NAME:
            LC_DBG << "lookup name is INVALID: address: " << address << " name: " << name
                   << " accountId: " << accountId;
            break;
        case NameDirectory::LookupStatus::NOT_FOUND:
            LC_DBG << "lookup name NOT FOUND: address: " << address << " name: " << name
                   << " accountId: " << accountId;
            break;
        case NameDirectory::LookupStatus::ERROR:
            LC_DBG << "lookup name ERROR: address: " << address << " name: " << name
                   << " accountId: " << accountId;
            break;
        case NameDirectory::LookupStatus::SUCCESS:
            break;
        }
    
        Q_EMIT q_ptr->registeredNameFound(static_cast<NameDirectory::LookupStatus>(status),
                                          address,
                                          name);
    }
    
    // Export account has ended with pin generated
    void
    NameDirectoryPrivate::slotExportOnRingEnded(const QString& accountId, int status, const QString& pin)
    {
        LC_DBG << "Export on ring ended for account: " << accountId << "status: " << status
               << "PIN: " << pin;
    
        Q_EMIT q_ptr->exportOnRingEnded(static_cast<NameDirectory::ExportOnRingStatus>(status), pin);
    }
    
    // Lookup a name
    bool
    NameDirectory::lookupName(const QString& accountId,
                              const QString& name,
                              const QString& nameServiceURL) const
    {
        return ConfigurationManager::instance().lookupName(accountId, nameServiceURL, name);
    }
    
    // Lookup an address
    bool
    NameDirectory::lookupAddress(const QString& accountId,
                                 const QString& address,
                                 const QString& nameServiceURL) const
    {
        return ConfigurationManager::instance().lookupAddress(accountId, nameServiceURL, address);
    }
    
    NameDirectory::~NameDirectory()
    {
        delete d_ptr;
    }