Commit e62eaab3 authored by Laurent Montel's avatar Laurent Montel 😁

Add addresseslocationwidget

parent 44e7ac19
......@@ -38,6 +38,7 @@ set(akonadicontact_addresslocation_editor_SRCS
editor/addresseditor/addresseslocationgrantleeformater.cpp
editor/addresseditor/addressgrantleeobject.cpp
editor/addresseditor/iconnamecache.cpp
editor/addresseditor/addresseslocationwidget.cpp
)
set(akonadicontact_editor_SRCS
......
......@@ -78,7 +78,7 @@ void AddressesLocationViewer::editAddress(int index)
return;
} else if (index < mAddresses.count()) {
//TODO remove it from list ?
editAddress(mAddresses.at(index));
modifyAddress(mAddresses.at(index), index);
}
}
......
......@@ -44,7 +44,7 @@ private Q_SLOTS:
void slotLinkClicked(const QUrl &url);
Q_SIGNALS:
void editAddress(const KContacts::Address &address);
void modifyAddress(const KContacts::Address &address, int currentIndex);
private:
void updateView();
......
/*
This file is part of Akonadi Contact.
Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
Copyright (C) 2016 Laurent Montel <laurent.montel@kdab.com>
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"
#include "addresseslocationviewer.h"
#include "addresslocationwidget.h"
#include <QHBoxLayout>
AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->setMargin(0);
AddressLocationWidget *addressLocationWidget = new AddressLocationWidget(this);
addressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
topLayout->addWidget(addressLocationWidget);
mAddressesLocationViewer = new AddressesLocationViewer(this);
mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
topLayout->addWidget(mAddressesLocationViewer);
connect(mAddressesLocationViewer, &AddressesLocationViewer::modifyAddress, addressLocationWidget, &AddressLocationWidget::slotModifyAddress);
setLayout(topLayout);
}
AddressesLocationWidget::~AddressesLocationWidget()
{
}
KContacts::Address::List AddressesLocationWidget::addresses() const
{
return mAddressesLocationViewer->addresses();
}
void AddressesLocationWidget::setAddresses(const KContacts::Address::List &addresses)
{
mAddressesLocationViewer->setAddresses(addresses);
}
/*
This file is part of Akonadi Contact.
Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
Copyright (C) 2016 Laurent Montel <laurent.montel@kdab.com>
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.
*/
#ifndef ADDRESSESLOCATIONWIDGET_H
#define ADDRESSESLOCATIONWIDGET_H
#include <QWidget>
#include <KContacts/Address>
class AddressesLocationViewer;
class AddressesLocationWidget : public QWidget
{
Q_OBJECT
public:
explicit AddressesLocationWidget(QWidget *parent = Q_NULLPTR);
~AddressesLocationWidget();
KContacts::Address::List addresses() const;
void setAddresses(const KContacts::Address::List &addresses);
private:
AddressesLocationViewer *mAddressesLocationViewer;
};
#endif // ADDRESSESLOCATIONWIDGET_H
......@@ -22,6 +22,9 @@
#include "addressgrantleeobject.h"
#include "iconnamecache_p.h"
#include <KIconLoader>
#include <KLocalizedString>
#include <QUrlQuery>
AddressGrantleeObject::AddressGrantleeObject(const KContacts::Address &address, int addressIndex, QObject *parent)
: QObject(parent),
......@@ -47,16 +50,33 @@ QString AddressGrantleeObject::formattedAddress() const
return str;
}
QString AddressGrantleeObject::createActionUrl(const QString &actionName) const
{
QUrl url;
url.setScheme(QStringLiteral("addresslocationaction"));
url.setPath(actionName);
QUrlQuery query;
query.addQueryItem(QStringLiteral("id"), QString::number(mAddressIndex));
url.setQuery(query);
return url.toDisplayString();
}
QString AddressGrantleeObject::removeAddressAction() const
{
//TODO
return {};
//TODO fix icons
const QString iconPath = IconNameCache::instance()->iconPath(QStringLiteral("window-new"), KIconLoader::Small);
const QString text = QStringLiteral("<a href=\"%1\"><img class=\"headimage\" title=\"%3\" src=\"file:///%2\"></a>\n")
.arg(createActionUrl(QStringLiteral("removeaddress")), iconPath, i18n("Remove Address"));
return text;
}
QString AddressGrantleeObject::modifyAddressAction() const
{
//TODO
return {};
//TODO fix icons
const QString iconPath = IconNameCache::instance()->iconPath(QStringLiteral("window-new"), KIconLoader::Small);
const QString text = QStringLiteral("<a href=\"%1\"><img class=\"headimage\" title=\"%3\" src=\"file:///%2\"></a>\n")
.arg(createActionUrl(QStringLiteral("editaddress")), iconPath, i18n("Edit Address"));
return text;
}
QString AddressGrantleeObject::type() const
......
......@@ -43,6 +43,7 @@ public:
QString type() const;
bool preferredAddress() const;
private:
QString createActionUrl(const QString &actionName) const;
KContacts::Address mAddress;
int mAddressIndex;
};
......
......@@ -116,10 +116,50 @@ AddressLocationWidget::~AddressLocationWidget()
void AddressLocationWidget::setAddress(const KContacts::Address &address)
{
mAddress = address;
//mTypeCombo->setType(mAddress.type());
//mStreetTextEdit->setPlainText(mAddress.street());
mRegionEdit->setText(address.region());
mLocalityEdit->setText(address.locality());
mPostalCodeEdit->setText(address.postalCode());
mPOBoxEdit->setText(address.postOfficeBox());
mPreferredCheckBox->setChecked(address.type() &KContacts::Address::Pref);
#if 0
if (address.isEmpty()) {
mCountryCombo->setItemText(mCountryCombo->currentIndex(),
QLocale::countryToString(QLocale().country()));
} else {
mCountryCombo->setItemText(mCountryCombo->currentIndex(), mAddress.country());
}
#endif
//TODO
}
KContacts::Address AddressLocationWidget::address() const
{
KContacts::Address address(mAddress);
//address.setType(mTypeCombo->type());
address.setLocality(mLocalityEdit->text());
address.setRegion(mRegionEdit->text());
address.setPostalCode(mPostalCodeEdit->text());
address.setCountry(mCountryCombo->currentText());
address.setPostOfficeBox(mPOBoxEdit->text());
//address.setStreet(mStreetTextEdit->toPlainText());
//address.setLabel(mLabel);
#if 0
if (mPreferredCheckBox->isChecked()) {
address.setType(address.type() | KContacts::Address::Pref);
} else {
address.setType(address.type() & ~(KContacts::Address::Pref));
}
#endif
return address;
return KContacts::Address();
}
void AddressLocationWidget::slotModifyAddress(const KContacts::Address &address, int currentIndex)
{
//TODO
}
......@@ -40,6 +40,8 @@ public:
void setAddress(const KContacts::Address &address);
KContacts::Address address() const;
void slotModifyAddress(const KContacts::Address &address, int currentIndex);
private:
QCheckBox *mPreferredCheckBox;
KLineEdit *mPOBoxEdit;
......@@ -49,6 +51,7 @@ private:
KLineEdit *mStreetEdit;
KComboBox *mCountryCombo;
QPushButton *mAddAddress;
KContacts::Address mAddress;
};
#endif // ADDRESSLOCATIONWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment