configurationmanager_wrap.h 32.9 KB
Newer Older
Philippe's avatar
Philippe committed
1
/******************************************************************************
Sébastien Blin's avatar
Sébastien Blin committed
2
 *    Copyright (C) 2014-2020 Savoir-faire Linux Inc.                               *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *   Author : Philippe Groarke <philippe.groarke@savoirfairelinux.com>        *
 *   Author : Alexandre Lision <alexandre.lision@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 Lesser GNU General Public License *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
 *****************************************************************************/
Guillaume Roguez's avatar
Guillaume Roguez committed
19
#pragma once
Philippe's avatar
Philippe committed
20 21 22 23 24

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
Alexandre Lision's avatar
Alexandre Lision committed
25
#include <QtCore/QTimer>
Philippe's avatar
Philippe committed
26 27 28 29 30 31
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

#include <future>

32
#include <configurationmanager_interface.h>
Guillaume Roguez's avatar
Guillaume Roguez committed
33
#include <datatransfer_interface.h>
34
#include <account_const.h>
35 36

#include "typedefs.h"
Philippe's avatar
Philippe committed
37 38 39
#include "conversions_wrap.hpp"

/*
40
 * Proxy class for interface org.ring.Ring.ConfigurationManager
Philippe's avatar
Philippe committed
41 42 43 44 45 46
 */
class ConfigurationManagerInterface: public QObject
{
    Q_OBJECT

public:
47
    std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
Guillaume Roguez's avatar
Guillaume Roguez committed
48
    std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> dataXferHandlers;
49 50 51 52 53 54

    ConfigurationManagerInterface() {
        setObjectName("ConfigurationManagerInterface");
        using DRing::exportable_callback;
        using DRing::ConfigurationSignal;
        using DRing::AudioSignal;
Guillaume Roguez's avatar
Guillaume Roguez committed
55
        using DRing::DataTransferSignal;
56
        using DRing::DebugSignal;
57 58 59 60 61 62 63 64 65 66 67

        setObjectName("ConfigurationManagerInterface");
        confHandlers = {
            exportable_callback<ConfigurationSignal::VolumeChanged>(
                [this] (const std::string &device, double value) {
                    Q_EMIT this->volumeChanged(QString(device.c_str()), value);
                }),
            exportable_callback<ConfigurationSignal::AccountsChanged>(
                [this] () {
                    Q_EMIT this->accountsChanged();
                }),
68 69 70 71 72 73
            exportable_callback<ConfigurationSignal::AccountDetailsChanged>(
                [this] (const std::string& account_id,
                        const std::map<std::string, std::string>& details) {
                    Q_EMIT this->accountDetailsChanged(QString(account_id.c_str()),
                                                       convertMap(details));
                }),
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
            exportable_callback<ConfigurationSignal::StunStatusFailed>(
                [this] (const std::string &reason) {
                    Q_EMIT this->stunStatusFailure(QString(reason.c_str()));
                }),
            exportable_callback<ConfigurationSignal::RegistrationStateChanged>(
                [this] (const std::string &accountID, const std::string& registration_state,
                        unsigned detail_code,
                        const std::string& detail_str) {
                    Q_EMIT this->registrationStateChanged(QString(accountID.c_str()),
                                                          QString(registration_state.c_str()),
                                                          detail_code,
                                                          QString(detail_str.c_str()));
                }),
            exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(
                [this] (const std::string &accountID, const std::map<std::string, std::string>& details) {
                    Q_EMIT this->volatileAccountDetailsChanged(QString(accountID.c_str()), convertMap(details));
                }),
            exportable_callback<ConfigurationSignal::Error>(
                [this] (int code) {
                    Q_EMIT this->errorAlert(code);
                }),
            exportable_callback<ConfigurationSignal::CertificateExpired>(
                [this] (const std::string &certId) {
                    Q_EMIT this->certificateExpired(QString(certId.c_str()));
                }),
            exportable_callback<ConfigurationSignal::CertificatePinned>(
                [this] (const std::string &certId) {
                    Q_EMIT this->certificatePinned(QString(certId.c_str()));
                }),
            exportable_callback<ConfigurationSignal::CertificatePathPinned>(
                [this] (const std::string &certPath, const std::vector<std::string>& list) {
                    Q_EMIT this->certificatePathPinned(QString(certPath.c_str()),convertStringList(list));
                }),
            exportable_callback<ConfigurationSignal::CertificateStateChanged>(
                [this] (const std::string &accountID, const std::string &certId, const std::string &state) {
                    QTimer::singleShot(
                        0, [this, accountID, certId, state] {
                            Q_EMIT this->certificateStateChanged(QString(accountID.c_str()), QString(certId.c_str()), QString(state.c_str()));
                        });
                }),
            exportable_callback<DRing::ConfigurationSignal::AccountMessageStatusChanged>(
                [this] (const std::string& accountID, uint64_t id, const std::string& to, int status) {
                    Q_EMIT this->accountMessageStatusChanged(QString(accountID.c_str()), id, QString(to.c_str()), status);
                }),
            exportable_callback<ConfigurationSignal::IncomingTrustRequest>(
                [this] (const std::string &accountId, const std::string &certId, const std::vector<uint8_t> &payload, time_t timestamp) {
                    Q_EMIT this->incomingTrustRequest(QString(accountId.c_str()), QString(certId.c_str()), QByteArray(reinterpret_cast<const char*>(payload.data()), payload.size()), timestamp);
                }),
            exportable_callback<ConfigurationSignal::KnownDevicesChanged>(
                [this] (const std::string &accountId, const std::map<std::string, std::string>& devices) {
                    Q_EMIT this->knownDevicesChanged(QString(accountId.c_str()), convertMap(devices));
                }),
126 127 128
            exportable_callback<ConfigurationSignal::DeviceRevocationEnded>(
                [this] (const std::string &accountId, const std::string &device, int status) {
                    Q_EMIT this->deviceRevocationEnded(QString(accountId.c_str()), QString(device.c_str()), status);
129
                }),
130 131 132
            exportable_callback<ConfigurationSignal::AccountProfileReceived>(
                [this](const std::string& accountId, const std::string& displayName, const std::string& userPhoto) {
                    Q_EMIT this->accountProfileReceived(QString(accountId.c_str()), QString(displayName.c_str()), QString(userPhoto.c_str()));
133
                }),
134 135
            exportable_callback<ConfigurationSignal::ExportOnRingEnded>(
                [this] (const std::string &accountId, int status, const std::string &pin) {
Alexandre Lision's avatar
Alexandre Lision committed
136
                    Q_EMIT this->exportOnRingEnded(QString(accountId.c_str()), status, QString(pin.c_str()));
137 138 139 140
                }),
            exportable_callback<ConfigurationSignal::NameRegistrationEnded>(
                [this] (const std::string &accountId, int status, const std::string &name) {
                    Q_EMIT this->nameRegistrationEnded(QString(accountId.c_str()), status, QString(name.c_str()));
141

142 143
                }),
            exportable_callback<ConfigurationSignal::RegisteredNameFound>(
144
                [this] (const std::string &accountId, int status, const std::string &address, const std::string &name) {
145 146 147
                    Q_EMIT this->registeredNameFound(QString(accountId.c_str()), status, QString(address.c_str()), QString(name.c_str()));
                }),
            exportable_callback<ConfigurationSignal::IncomingAccountMessage>(
148 149
                [this] (const std::string& account_id, const std::string& msgId, const std::string& from, const std::map<std::string, std::string>& payloads) {
                    Q_EMIT this->incomingAccountMessage(QString(account_id.c_str()), QString(msgId.c_str()), QString(from.c_str()), convertMap(payloads));
150 151 152 153 154 155 156 157 158
                }),
            exportable_callback<ConfigurationSignal::MediaParametersChanged>(
                [this] (const std::string& account_id) {
                    Q_EMIT this->mediaParametersChanged(QString(account_id.c_str()));
                }),
            exportable_callback<AudioSignal::DeviceEvent>(
                [this] () {
                    Q_EMIT this->audioDeviceEvent();
                }),
159 160 161 162
            exportable_callback<AudioSignal::AudioMeter>(
                [this](const std::string& id, float level) {
                    Q_EMIT this->audioMeter(QString(id.c_str()), level);
                }),
163 164 165 166 167 168 169 170
            exportable_callback<ConfigurationSignal::MigrationEnded>(
                [this] (const std::string& account_id, const std::string& result) {
                    Q_EMIT this->migrationEnded(QString(account_id.c_str()), QString(result.c_str()));
                }),
            exportable_callback<ConfigurationSignal::ContactAdded>(
                [this] (const std::string& account_id, const std::string& uri, const bool& confirmed) {
                    Q_EMIT this->contactAdded(QString(account_id.c_str()), QString(uri.c_str()), confirmed);
                }),
171 172 173 174
            exportable_callback<ConfigurationSignal::ProfileReceived>(
                    [this] (const std::string& accountID, const std::string& peer, const std::string& vCard) {
                        Q_EMIT this->profileReceived(QString(accountID.c_str()), QString(peer.c_str()), QString(vCard.c_str()));
            }),
175 176 177 178
            exportable_callback<ConfigurationSignal::ContactRemoved>(
                [this] (const std::string& account_id, const std::string& uri, const bool& banned) {
                    Q_EMIT this->contactRemoved(QString(account_id.c_str()), QString(uri.c_str()), banned);
                }),
179 180
            exportable_callback<DebugSignal::MessageSend>(
                [this](const std::string& message) {
181
                    Q_EMIT this->debugMessageReceived(QString(message.c_str()));
182
                }),
183 184 185 186
            exportable_callback<ConfigurationSignal::ComposingStatusChanged>(
                [this](const std::string& account_id, const std::string& from, int status) {
                    Q_EMIT this->composingStatusChanged(QString(account_id.c_str()), QString(from.c_str()), status > 0 ? true : false);
                }),
187
        };
Guillaume Roguez's avatar
Guillaume Roguez committed
188 189 190 191 192 193 194

        dataXferHandlers = {
            exportable_callback<DataTransferSignal::DataTransferEvent>(
                [this] (const uint64_t& transfer_id, const uint32_t& code) {
                    Q_EMIT this->dataTransferEvent(transfer_id, code);
                }),
        };
195 196 197
    }

    ~ConfigurationManagerInterface() {}
Philippe's avatar
Philippe committed
198 199

public Q_SLOTS: // METHODS
200 201 202 203 204 205 206 207 208
    QString addAccount(MapStringString details) {
        QString temp(DRing::addAccount(convertMap(details)).c_str());
        return temp;
    }

    bool exportOnRing(const QString& accountID, const QString& password) {
        return DRing::exportOnRing(accountID.toStdString(), password.toStdString());
    }

209 210
    bool exportToFile(const QString& accountID, const QString& destinationPath, const QString& password = {}) {
        return DRing::exportToFile(accountID.toStdString(), destinationPath.toStdString(), password.toStdString());
211 212
    }

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
    MapStringString getKnownRingDevices(const QString& accountID) {
        MapStringString temp = convertMap(DRing::getKnownRingDevices(accountID.toStdString()));
        return temp;
    }

    bool lookupName(const QString& accountID, const QString& nameServiceURL, const QString& name) {
        return DRing::lookupName(accountID.toStdString(), nameServiceURL.toStdString(), name.toStdString());
    }

    bool lookupAddress(const QString& accountID, const QString& nameServiceURL, const QString& address) {
        return DRing::lookupAddress(accountID.toStdString(), nameServiceURL.toStdString(), address.toStdString());
    }

    bool registerName(const QString& accountID, const QString& password, const QString& name) {
        return DRing::registerName(accountID.toStdString(), password.toStdString(), name.toStdString());
    }

    MapStringString getAccountDetails(const QString& accountID) {
        MapStringString temp = convertMap(DRing::getAccountDetails(accountID.toStdString()));
        return temp;
    }

    QStringList getAccountList() {
        QStringList temp =
            convertStringList(DRing::getAccountList());
        return temp;
    }

    MapStringString getAccountTemplate(const QString& accountType) {
        MapStringString temp = convertMap(DRing::getAccountTemplate(accountType.toStdString()));
        return temp;
    }

    // TODO: works?
    VectorUInt getActiveCodecList(const QString& accountID) {
        return QVector<unsigned int>::fromStdVector(DRing::getActiveCodecList(accountID.toStdString()));
    }

    QString getAddrFromInterfaceName(const QString& interface) {
        QString temp(DRing::getAddrFromInterfaceName(interface.toStdString()).c_str());
        return temp;
    }

    QStringList getAllIpInterface() {
        QStringList temp = convertStringList(DRing::getAllIpInterface());
        return temp;
    }

    QStringList getAllIpInterfaceByName() {
        QStringList temp = convertStringList(DRing::getAllIpInterfaceByName());
        return temp;
    }

    MapStringString getCodecDetails(const QString& accountID, int payload) {
        MapStringString temp = convertMap(DRing::getCodecDetails(accountID.toStdString().c_str(), payload));
        return temp;
    }

    VectorUInt getCodecList() {
        return QVector<unsigned int>::fromStdVector(DRing::getCodecList());
    }

    VectorMapStringString getContacts(const QString &accountID) {
        VectorMapStringString temp;
        for (const auto& x : DRing::getContacts(accountID.toStdString())) {
            temp.push_back(convertMap(x));
        }
        return temp;
    }

    int getAudioInputDeviceIndex(const QString& devname) {
        return DRing::getAudioInputDeviceIndex(devname.toStdString());
    }

    QStringList getAudioInputDeviceList() {
        QStringList temp = convertStringList(DRing::getAudioInputDeviceList());
        return temp;
    }

    QString getAudioManager() {
        QString temp(DRing::getAudioManager().c_str());
        return temp;
    }

    int getAudioOutputDeviceIndex(const QString& devname) {
        return DRing::getAudioOutputDeviceIndex(devname.toStdString());
    }

    QStringList getAudioOutputDeviceList() {
        QStringList temp = convertStringList(DRing::getAudioOutputDeviceList());
        return temp;
    }

    QStringList getAudioPluginList() {
        QStringList temp = convertStringList(DRing::getAudioPluginList());
        return temp;
    }

    VectorMapStringString getCredentials(const QString& accountID) {
        VectorMapStringString temp;
        for (auto x : DRing::getCredentials(accountID.toStdString())) {
            temp.push_back(convertMap(x));
        }
        return temp;
    }

    QStringList getCurrentAudioDevicesIndex() {
        QStringList temp = convertStringList(DRing::getCurrentAudioDevicesIndex());
        return temp;
    }

    QString getCurrentAudioOutputPlugin() {
        QString temp(DRing::getCurrentAudioOutputPlugin().c_str());
        return temp;
    }

    int getHistoryLimit() {
        return DRing::getHistoryLimit();
    }

    MapStringString getHookSettings() {
        MapStringString temp = convertMap(DRing::getHookSettings());
        return temp;
    }

    bool getIsAlwaysRecording() {
        return DRing::getIsAlwaysRecording();
    }

    bool getNoiseSuppressState() {
        return DRing::getNoiseSuppressState();
    }

    QString getRecordPath() {
        QString temp(DRing::getRecordPath().c_str());
        return temp;
    }

Philippe Gorley's avatar
Philippe Gorley committed
351 352 353 354 355 356 357 358
    bool getRecordPreview() {
        return DRing::getRecordPreview();
    }

    int getRecordQuality() {
        return DRing::getRecordQuality();
    }

359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
    QStringList getSupportedAudioManagers() {
        QStringList temp;
        return temp;
    }

    MapStringString getShortcuts() {
        MapStringString temp = convertMap(DRing::getShortcuts());
        return temp;
    }

    QStringList getSupportedTlsMethod() {
        QStringList temp = convertStringList(DRing::getSupportedTlsMethod());
        return temp;
    }

    MapStringString validateCertificate(const QString& unused, const QString& certificate) {
        MapStringString temp = convertMap(DRing::validateCertificate(unused.toStdString(),
                                                                     certificate.toStdString()));
        return temp;
    }

    MapStringString validateCertificatePath(const QString& unused,
                                            const QString& certificate,
                                            const QString& privateKey,
                                            const QString& privateKeyPass,
                                            const QString& caListPath) {
        MapStringString temp = convertMap(DRing::validateCertificatePath(unused.toStdString(),
                                                                         certificate.toStdString(),
                                                                         privateKey.toStdString(),
                                                                         privateKeyPass.toStdString(),
                                                                         caListPath.toStdString()));
        return temp;
    }

    MapStringString getCertificateDetails(const QString& certificate) {
        MapStringString temp = convertMap(DRing::getCertificateDetails(certificate.toStdString()));
        return temp;
    }

    MapStringString getCertificateDetailsPath(const QString& certificate,
                                              const QString& privateKey,
                                              const QString& privateKeyPass) {
        MapStringString temp = convertMap(DRing::getCertificateDetailsPath(certificate.toStdString(),
                                                                           privateKey.toStdString(),
                                                                           privateKeyPass.toStdString()));
        return temp;
    }

    QStringList getSupportedCiphers(const QString& accountID) {
        QStringList temp = convertStringList(DRing::getSupportedCiphers(accountID.toStdString()));
        return temp;
    }

    MapStringString getTlsDefaultSettings() {
        MapStringString temp = convertMap(DRing::getTlsDefaultSettings());
        return temp;
    }

    double getVolume(const QString& device) {
        return DRing::getVolume(device.toStdString());
    }

    bool isAgcEnabled() {
        return DRing::isAgcEnabled();
    }

    bool isCaptureMuted() {
        return DRing::isCaptureMuted();
    }

    bool isDtmfMuted() {
        return DRing::isDtmfMuted();
    }

    bool isPlaybackMuted() {
        return DRing::isPlaybackMuted();
    }

    void muteCapture(bool mute) {
        DRing::muteCapture(mute);
    }

    void muteDtmf(bool mute) {
        DRing::muteDtmf(mute);
    }

    void mutePlayback(bool mute) {
        DRing::mutePlayback(mute);
    }

    void registerAllAccounts() {
        DRing::registerAllAccounts();
    }

    void removeAccount(const QString& accountID) {
        DRing::removeAccount(accountID.toStdString());
    }

    int  exportAccounts(const QStringList& accountIDs, const QString& filePath, const QString& password) {
        return DRing::exportAccounts(convertStringList(accountIDs), filePath.toStdString(), password.toStdString());
    }

    int importAccounts(const QString& filePath, const QString& password) {
        return DRing::importAccounts(filePath.toStdString(), password.toStdString());
    }

    bool changeAccountPassword(const QString& id, const QString& currentPassword, const QString& newPassword) {
        return DRing::changeAccountPassword(id.toStdString(), currentPassword.toStdString(), newPassword.toStdString());
    }

    void sendRegister(const QString& accountID, bool enable) {
        DRing::sendRegister(accountID.toStdString(), enable);
    }

    void setAccountDetails(const QString& accountID, MapStringString details) {
        DRing::setAccountDetails(accountID.toStdString(),
                                 convertMap(details));
    }

    void setAccountsOrder(const QString& order) {
        DRing::setAccountsOrder(order.toStdString());
    }

    void setActiveCodecList(const QString& accountID, VectorUInt &list) {
        //const std::vector<unsigned int> converted = convertStringList(list);
        DRing::setActiveCodecList(accountID.toStdString(),
                                  list.toStdVector());
    }

    void setAgcState(bool enabled) {
        DRing::setAgcState(enabled);
    }

    void setAudioInputDevice(int index) {
        DRing::setAudioInputDevice(index);
    }

    bool setAudioManager(const QString& api) {
        return DRing::setAudioManager(api.toStdString());
    }

    void setAudioOutputDevice(int index) {
        DRing::setAudioOutputDevice(index);
    }

    void setAudioPlugin(const QString& audioPlugin) {
        DRing::setAudioPlugin(audioPlugin.toStdString());
    }

    void setAudioRingtoneDevice(int index) {
        DRing::setAudioRingtoneDevice(index);
    }

    void setCredentials(const QString& accountID, VectorMapStringString credentialInformation) {
        std::vector<std::map<std::string, std::string> > temp;
        for (auto x : credentialInformation) {
            temp.push_back(convertMap(x));
        }
        DRing::setCredentials(accountID.toStdString(), temp);
    }

    void setHistoryLimit(int days) {
        DRing::setHistoryLimit(days);
    }

    void setHookSettings(MapStringString settings) {
        DRing::setHookSettings(convertMap(settings));
    }

    void setIsAlwaysRecording(bool enabled) {
        DRing::setIsAlwaysRecording(enabled);
    }

    void setNoiseSuppressState(bool state) {
        DRing::setNoiseSuppressState(state);
    }

536 537
    bool isAudioMeterActive(const QString& id) {
        return DRing::isAudioMeterActive(id.toStdString());
538 539
    }

540 541
    void setAudioMeterState(const QString& id, bool state) {
        DRing::setAudioMeterState(id.toStdString(), state);
542 543
    }

544 545 546 547
    void setRecordPath(const QString& rec) {
        DRing::setRecordPath(rec.toStdString());
    }

Philippe Gorley's avatar
Philippe Gorley committed
548 549 550 551 552 553 554 555
    void setRecordPreview(const bool& rec) {
        DRing::setRecordPreview(rec);
    }

    void setRecordQuality(const int& quality) {
        DRing::setRecordQuality(quality);
    }

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
    void setVolume(const QString& device, double value) {
        DRing::setVolume(device.toStdString(), value);
    }

    MapStringString getVolatileAccountDetails(const QString& accountID) {
        MapStringString temp = convertMap(DRing::getVolatileAccountDetails(accountID.toStdString()));
        return temp;
    }

    QStringList getPinnedCertificates() {
        QStringList temp = convertStringList(DRing::getPinnedCertificates());
        return temp;
    }

    QStringList pinCertificate(const QByteArray& content, bool local) {
        std::vector<unsigned char> raw(content.begin(), content.end());
        return convertStringList(DRing::pinCertificate(raw,local));
    }

    bool unpinCertificate(const QString& certId) {
        return DRing::unpinCertificate(certId.toStdString());
    }

    void pinCertificatePath(const QString& certPath) {
        DRing::pinCertificatePath(certPath.toStdString());
    }

    uint unpinCertificatePath(const QString& certPath) {
        return DRing::unpinCertificatePath(certPath.toStdString());
    }

    bool pinRemoteCertificate(const QString& accountId, const QString& certPath) {
        return DRing::pinRemoteCertificate(accountId.toStdString(), certPath.toStdString());
    }

    bool setCertificateStatus(const QString& accountId, const QString& certPath, const QString& status) {
        return DRing::setCertificateStatus(accountId.toStdString(), certPath.toStdString(), status.toStdString());
    }

    QStringList getCertificatesByStatus(const QString& accountId, const QString& status) {
        return convertStringList(DRing::getCertificatesByStatus(accountId.toStdString(), status.toStdString()));
    }

    VectorMapStringString getTrustRequests(const QString& accountId) {
        return convertVecMap(DRing::getTrustRequests(accountId.toStdString()));
    }

    bool acceptTrustRequest(const QString& accountId, const QString& from) {
        return DRing::acceptTrustRequest(accountId.toStdString(), from.toStdString());
    }

    bool discardTrustRequest(const QString& accountId, const QString& from) {
        return DRing::discardTrustRequest(accountId.toStdString(), from.toStdString());
    }

    void sendTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload) {
        std::vector<unsigned char> raw(payload.begin(), payload.end());
        DRing::sendTrustRequest(accountId.toStdString(), from.toStdString(), raw);
    }

    void removeContact(const QString &accountId, const QString &uri, bool ban) {
        DRing::removeContact(accountId.toStdString(), uri.toStdString(), ban);
    }

620 621 622 623
    void revokeDevice(const QString &accountId, const QString &password, const QString &deviceId) {
        DRing::revokeDevice(accountId.toStdString(), password.toStdString(), deviceId.toStdString());
    }

624 625 626 627 628 629 630 631
    void addContact(const QString &accountId, const QString &uri) {
        DRing::addContact(accountId.toStdString(), uri.toStdString());
    }

    uint64_t sendTextMessage(const QString& accountId, const QString& to, const QMap<QString,QString>& payloads) {
        return DRing::sendAccountTextMessage(accountId.toStdString(), to.toStdString(), convertMap(payloads));
    }

632 633 634 635 636 637 638 639
    QVector<Message> getLastMessages(const QString& accountID, const uint64_t& base_timestamp) {
        QVector<Message> result;
        for (auto& message : DRing::getLastMessages(accountID.toStdString(), base_timestamp)) {
            result.append({message.from.c_str(), convertMap(message.payloads), message.received});
        }
        return result;
    }

640 641 642 643 644 645 646 647
    bool setCodecDetails(const QString& accountId, unsigned int codecId, const MapStringString& details) {
        return DRing::setCodecDetails(accountId.toStdString(), codecId, convertMap(details));
    }

    int getMessageStatus(uint64_t id) {
        return DRing::getMessageStatus(id);
    }

648 649 650 651
    MapStringString getNearbyPeers(const QString &accountID){
        return convertMap(DRing::getNearbyPeers(accountID.toStdString()));
    }

652 653 654 655 656 657 658
    void connectivityChanged() {
        DRing::connectivityChanged();
    }

    MapStringString getContactDetails(const QString &accountID, const QString &uri) {
        return convertMap(DRing::getContactDetails(accountID.toStdString(), uri.toStdString()));
    }
659

Guillaume Roguez's avatar
Guillaume Roguez committed
660 661 662 663
    VectorULongLong dataTransferList() {
        return convertVectorULongLong(DRing::dataTransferList());
    }

Anthony Léonard's avatar
Anthony Léonard committed
664 665 666 667 668 669 670 671
    uint32_t sendFile(const DataTransferInfo& lrc_info, uint64_t& id) {
        DRing::DataTransferInfo dring_info;
        dring_info.accountId = lrc_info.accountId.toStdString();
        dring_info.lastEvent = decltype(dring_info.lastEvent)(lrc_info.lastEvent);
        dring_info.flags = lrc_info.flags;
        dring_info.totalSize = lrc_info.totalSize;
        dring_info.bytesProgress = lrc_info.bytesProgress;
        dring_info.peer = lrc_info.peer.toStdString();
672 673
        dring_info.displayName = lrc_info.displayName.toStdString();
        dring_info.path = lrc_info.path.toStdString();
Anthony Léonard's avatar
Anthony Léonard committed
674 675 676 677 678 679 680 681 682 683
        dring_info.mimetype = lrc_info.mimetype.toStdString();
        return uint32_t(DRing::sendFile(dring_info, id));
    }

    uint32_t dataTransferInfo(uint64_t transfer_id, DataTransferInfo& lrc_info) {
        DRing::DataTransferInfo dring_info;
        auto error = uint32_t(DRing::dataTransferInfo(transfer_id, dring_info));
        lrc_info.accountId = QString::fromStdString(dring_info.accountId);
        lrc_info.lastEvent = quint32(dring_info.lastEvent);
        lrc_info.flags = dring_info.flags;
Guillaume Roguez's avatar
Guillaume Roguez committed
684 685
        lrc_info.totalSize = dring_info.totalSize;
        lrc_info.bytesProgress = dring_info.bytesProgress;
Anthony Léonard's avatar
Anthony Léonard committed
686
        lrc_info.peer = QString::fromStdString(dring_info.peer);
Guillaume Roguez's avatar
Guillaume Roguez committed
687 688
        lrc_info.displayName = QString::fromStdString(dring_info.displayName);
        lrc_info.path = QString::fromStdString(dring_info.path);
Anthony Léonard's avatar
Anthony Léonard committed
689 690
        lrc_info.mimetype = QString::fromStdString(dring_info.mimetype);
        return error;
Guillaume Roguez's avatar
Guillaume Roguez committed
691 692
    }

Anthony Léonard's avatar
Anthony Léonard committed
693 694
    uint64_t dataTransferBytesProgress(uint64_t transfer_id, int64_t& total, int64_t& progress) {
        return uint32_t(DRing::dataTransferBytesProgress(transfer_id, total, progress));
Guillaume Roguez's avatar
Guillaume Roguez committed
695 696
    }

Anthony Léonard's avatar
Anthony Léonard committed
697 698
    uint32_t acceptFileTransfer(uint64_t transfer_id, const QString& file_path, int64_t offset) {
        return uint32_t(DRing::acceptFileTransfer(transfer_id, file_path.toStdString(), offset));
Guillaume Roguez's avatar
Guillaume Roguez committed
699 700
    }

Anthony Léonard's avatar
Anthony Léonard committed
701 702
    uint32_t cancelDataTransfer(int64_t transfer_id) {
        return uint32_t(DRing::cancelDataTransfer(transfer_id));
Guillaume Roguez's avatar
Guillaume Roguez committed
703
    }
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718

    void enableProxyClient(const QString& accountID, bool enable)
    {
        DRing::enableProxyClient(accountID.toStdString(), enable);
    }

    void setPushNotificationToken(const QString& token)
    {
        DRing::setPushNotificationToken(token.toStdString());
    }

    void pushNotificationReceived(const QString& from, const MapStringString& data)
    {
        DRing::pushNotificationReceived(from.toStdString(), convertMap(data));
    }
Guillaume Roguez's avatar
Guillaume Roguez committed
719

720 721 722 723
    void setIsComposing(const QString& accountId, const QString& contactId, bool isComposing) {
        DRing::setIsComposing(accountId.toStdString(), contactId.toStdString(), isComposing);
    }

724 725 726 727
    bool setMessageDisplayed(const QString& accountId, const QString& contactId, const QString& messageId, int status) {
        DRing::setMessageDisplayed(accountId.toStdString(), contactId.toStdString(), messageId.toStdString(), status);
    }

Philippe's avatar
Philippe committed
728
Q_SIGNALS: // SIGNALS
729 730
    void volumeChanged(const QString& device, double value);
    void accountsChanged();
731
    void accountDetailsChanged(const QString& accountId, const MapStringString& details);
732 733 734 735 736 737 738 739 740 741 742 743 744
    void historyChanged();
    void stunStatusFailure(const QString& reason);
    void registrationStateChanged(const QString& accountID, const QString& registration_state, unsigned detail_code, const QString& detail_str);
    void stunStatusSuccess(const QString& message);
    void errorAlert(int code);
    void volatileAccountDetailsChanged(const QString& accountID, MapStringString details);
    void certificatePinned(const QString& certId);
    void certificatePathPinned(const QString& path, const QStringList& certIds);
    void certificateExpired(const QString& certId);
    void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status);
    void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp);
    void knownDevicesChanged(const QString& accountId, const MapStringString& devices);
    void exportOnRingEnded(const QString& accountId, int status, const QString& pin);
745
    void incomingAccountMessage(const QString& accountId, const QString msgId, const QString& from, const MapStringString& payloads);
746 747
    void mediaParametersChanged(const QString& accountId);
    void audioDeviceEvent();
748
    void audioMeter(const QString& id, float level);
749 750 751 752 753 754
    void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status);
    void nameRegistrationEnded(const QString& accountId, int status, const QString& name);
    void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name);
    void migrationEnded(const QString &accountID, const QString &result);
    void contactAdded(const QString &accountID, const QString &uri, bool banned);
    void contactRemoved(const QString &accountID, const QString &uri, bool banned);
755
    void profileReceived(const QString &accountID, const QString &peer, const QString &vCard);
Guillaume Roguez's avatar
Guillaume Roguez committed
756
    void dataTransferEvent(qulonglong transfer_id, uint code);
757
    void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status);
758
    void accountProfileReceived(const QString& accountId, const QString& displayName, const QString& userPhoto);
759
    void debugMessageReceived(const QString& message);
760
    void composingStatusChanged(const QString& accountId, const QString& contactId, bool isComposing);
Philippe's avatar
Philippe committed
761 762
};

763 764 765
namespace org { namespace ring { namespace Ring {
typedef ::ConfigurationManagerInterface ConfigurationManager;
}}}