addresseslocationwidget.cpp 3.32 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1 2 3 4
/*
    This file is part of Akonadi Contact.

    Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
Laurent Montel's avatar
Laurent Montel committed
5
    Copyright (C) 2016-2017 Laurent Montel <laurent.montel@kdab.com>
Laurent Montel's avatar
Laurent Montel committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 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 Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#include "addresseslocationwidget.h"
24
#include "webengine/addresseslocationengineviewer.h"
Laurent Montel's avatar
Laurent Montel committed
25
#include "addresslocationwidget.h"
Laurent Montel's avatar
Laurent Montel committed
26
using namespace Akonadi;
Laurent Montel's avatar
Laurent Montel committed
27 28

AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
Laurent Montel's avatar
Laurent Montel committed
29
    : QSplitter(parent)
Laurent Montel's avatar
Laurent Montel committed
30
{
Laurent Montel's avatar
Laurent Montel committed
31
    setChildrenCollapsible(false);
Laurent Montel's avatar
Laurent Montel committed
32 33
    mAddressLocationWidget = new AddressLocationWidget(this);
    mAddressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
Laurent Montel's avatar
Laurent Montel committed
34
    addWidget(mAddressLocationWidget);
35 36 37 38 39
    mAddressesLocationViewer = new AddressesLocationEngineViewer(this);
    mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
    addWidget(mAddressesLocationViewer);
    connect(mAddressesLocationViewer, &AddressesLocationEngineViewer::modifyAddress, mAddressLocationWidget, &AddressLocationWidget::slotModifyAddress);
    connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::addAddress);
40
    connect(mAddressLocationWidget, &AddressLocationWidget::updateAddressCanceled, mAddressesLocationViewer, &AddressesLocationEngineViewer::updateAddressCanceled);
41
    connect(mAddressLocationWidget, &AddressLocationWidget::updateAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::replaceAddress);
Laurent Montel's avatar
Laurent Montel committed
42
    setSizes(QList<int>() << 400 << 300);
Laurent Montel's avatar
Laurent Montel committed
43 44 45 46 47 48 49
}

AddressesLocationWidget::~AddressesLocationWidget()
{

}

Laurent Montel's avatar
Laurent Montel committed
50
void AddressesLocationWidget::loadContact(const KContacts::Addressee &contact)
Laurent Montel's avatar
Laurent Montel committed
51
{
Laurent Montel's avatar
Laurent Montel committed
52
    mAddressesLocationViewer->setAddresses(contact.addresses());
Laurent Montel's avatar
Laurent Montel committed
53 54
}

Laurent Montel's avatar
Laurent Montel committed
55
void AddressesLocationWidget::storeContact(KContacts::Addressee &contact) const
Laurent Montel's avatar
Laurent Montel committed
56
{
Laurent Montel's avatar
Laurent Montel committed
57 58
    // delete all previous addresses
    const KContacts::Address::List oldAddresses = contact.addresses();
59 60
    const int numberOfOldAddresses(oldAddresses.count());
    for (int i = 0; i < numberOfOldAddresses; ++i) {
Laurent Montel's avatar
Laurent Montel committed
61 62 63 64 65
        contact.removeAddress(oldAddresses.at(i));
    }

    const KContacts::Address::List addressList = mAddressesLocationViewer->addresses();
    // insert the new ones
66 67
    const int numberOfAddress(addressList.count());
    for (int i = 0; i < numberOfAddress; ++i) {
Laurent Montel's avatar
Laurent Montel committed
68 69 70 71 72
        const KContacts::Address address(addressList.at(i));
        if (!address.isEmpty()) {
            contact.insertAddress(address);
        }
    }
Laurent Montel's avatar
Laurent Montel committed
73
}
Laurent Montel's avatar
Laurent Montel committed
74 75 76 77 78 79

void AddressesLocationWidget::setReadOnly(bool readOnly)
{
    mAddressesLocationViewer->setReadOnly(readOnly);
    mAddressLocationWidget->setReadOnly(readOnly);
}