summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-10-10 23:20:49 +0200
committerMontel Laurent <[email protected]>2017-10-10 23:21:24 +0200
commit16b2dc84723a9caf0ee36e78f0d53678df468956 (patch)
tree533f12011da6231430a7c48c0c85f2b875297254
parent2b4c0d07ebabbe9eeb85b68dda51604ec4b8971a (diff)
Create plugin for contact editor
-rw-r--r--CMakeLists.txt2
-rw-r--r--kaddressbook/contacteditor/CMakeLists.txt43
-rw-r--r--kaddressbook/contacteditor/Messages.sh2
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp87
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h52
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp77
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h45
-rw-r--r--kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp128
-rw-r--r--kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h67
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp293
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresslocationwidget.h83
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp92
-rw-r--r--kaddressbook/contacteditor/addresseditor/addresstypedialog.h48
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt31
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp43
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h38
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp51
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h39
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp121
-rw-r--r--kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h40
-rw-r--r--kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt1
-rw-r--r--kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css16
-rw-r--r--kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html29
-rw-r--r--kaddressbook/contacteditor/addresseditor/iconnamecache.cpp54
-rw-r--r--kaddressbook/contacteditor/addresseditor/iconnamecache_p.h51
-rw-r--r--kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp114
-rw-r--r--kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h71
-rw-r--r--kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt34
-rw-r--r--kaddressbook/contacteditor/addresseditor/tests/main.cpp35
-rw-r--r--kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp60
-rw-r--r--kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h41
-rw-r--r--kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp139
-rw-r--r--kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h58
-rw-r--r--kaddressbook/contacteditor/addresslocationeditorplugin.cpp49
-rw-r--r--kaddressbook/contacteditor/addresslocationeditorplugin.h41
-rw-r--r--kaddressbook/contacteditor/addresslocationeditorplugin.json10
36 files changed, 2184 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bf9c577..def5683 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,7 +84,7 @@ set(KPIMTEXTEDIT_LIB_VERSION "5.6.40")
set(KIMAP_LIB_VERSION "5.6.40")
set(LIBKSIEVE_LIB_VERSION_LIB "5.6.40")
set(KMAILTRANSPORT_LIB_VERSION "5.6.40")
-set(AKONADICONTACT_LIB_VERSION "5.6.40")
+set(AKONADICONTACT_LIB_VERSION "5.6.41")
set(IMPORTWIZARD_LIB_VERSION "5.6.40")
set(MAILIMPORTER_LIB_VERSION "5.6.40")
diff --git a/kaddressbook/contacteditor/CMakeLists.txt b/kaddressbook/contacteditor/CMakeLists.txt
index e69de29..6bb0145 100644
--- a/kaddressbook/contacteditor/CMakeLists.txt
+++ b/kaddressbook/contacteditor/CMakeLists.txt
@@ -0,0 +1,43 @@
+add_definitions(-DTRANSLATION_DOMAIN=\"kaddressbook_contacteditor\")
+
+set(contacteditor_addresslocationeditor_plugin_SRCS
+ addresseditor/addresseslocationgrantleeformater.cpp
+ addresseditor/addresseslocationwidget.cpp
+ addresseditor/addressgrantleeobject.cpp
+ addresseditor/addresslocationwidget.cpp
+ addresseditor/addresstypedialog.cpp
+ addresseditor/iconnamecache.cpp
+ addresseditor/selectaddresstypecombobox.cpp
+ addresseditor/webengine/addresseslocationenginepage.cpp
+ addresseditor/webengine/addresseslocationengineviewer.cpp
+ )
+ecm_qt_declare_logging_category(contacteditor_addresslocationeditor_plugin_SRCS HEADER addresslocationeditorplugin_debug.h IDENTIFIER
+ ADDRESSLOCATIONEDITORPLUGIN_LOG CATEGORY_NAME org.kde.pim.addresslocationeditorplugin)
+
+
+#if(BUILD_TESTING)
+# add_subdirectory(addresseditor/tests)
+# add_subdirectory(addresseditor/autotests)
+#endif()
+
+
+set(addresslocationeditorplugin_SRCS
+ addresslocationeditorplugin.cpp
+ ${contacteditor_addresslocationeditor_plugin_SRCS}
+ )
+
+kcoreaddons_add_plugin(addresslocationeditorplugin JSON addresslocationeditorplugin.json SOURCES
+ ${addresslocationeditorplugin_SRCS} INSTALL_NAMESPACE contacteditor)
+
+target_link_libraries(addresslocationeditorplugin
+ KF5::I18n
+ KF5::AkonadiContact
+ KF5::ContactEditor
+ Grantlee5::Templates
+ Qt5::WebEngine
+ Qt5::WebEngineWidgets
+ KF5::IconThemes
+ KF5::Completion
+ )
+
+add_subdirectory(addresseditor/html)
diff --git a/kaddressbook/contacteditor/Messages.sh b/kaddressbook/contacteditor/Messages.sh
new file mode 100644
index 0000000..49b4ac3
--- /dev/null
+++ b/kaddressbook/contacteditor/Messages.sh
@@ -0,0 +1,2 @@
+#! /bin/sh
+$XGETTEXT `find . -name '*.cpp' -o -name '*.h' | grep -v '/tests/' | grep -v '/autotests/'` -o $podir/kaddressbook_contacteditor.pot
diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp
new file mode 100644
index 0000000..b64a8ee
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp
@@ -0,0 +1,87 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresseslocationgrantleeformater.h"
+#include "addressgrantleeobject.h"
+#include <grantlee/engine.h>
+#include <QVariantList>
+#include <QStandardPaths>
+
+AddressesLocationGrantleeFormater::AddressesLocationGrantleeFormater(QObject *parent)
+ : QObject(parent)
+ , mEngine(new Grantlee::Engine)
+ , mReadOnly(false)
+{
+ mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
+ mGrantleeThemePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
+ QStringLiteral("contacteditor/grantleetheme/default/"),
+ QStandardPaths::LocateDirectory);
+ changeGrantleePath(mGrantleeThemePath);
+}
+
+AddressesLocationGrantleeFormater::~AddressesLocationGrantleeFormater()
+{
+ delete mEngine;
+ mTemplateLoader.clear();
+}
+
+QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Address::List &addresses)
+{
+ QVariantList addressList;
+ const int nbAddress(addresses.count());
+ addressList.reserve(nbAddress);
+ QList<AddressGrantleeObject *> lstAddress;
+ lstAddress.reserve(nbAddress);
+ for (int i = 0; i < nbAddress; ++i) {
+ AddressGrantleeObject *addressObj = new AddressGrantleeObject(addresses.at(i), i);
+ addressList << QVariant::fromValue(static_cast<QObject *>(addressObj));
+ lstAddress.append(addressObj);
+ }
+ QVariantHash addressHash;
+ addressHash.insert(QStringLiteral("addresses"), addressList);
+ addressHash.insert(QStringLiteral("absoluteThemePath"), mGrantleeThemePath);
+ addressHash.insert(QStringLiteral("readOnly"), mReadOnly);
+
+ Grantlee::Context context(addressHash);
+ const QString contentHtml = mSelfcontainedTemplate->render(&context);
+ qDeleteAll(lstAddress);
+ return contentHtml;
+}
+
+void AddressesLocationGrantleeFormater::setReadOnly(bool readOnly)
+{
+ mReadOnly = readOnly;
+}
+
+void AddressesLocationGrantleeFormater::changeGrantleePath(const QString &path)
+{
+ if (!mTemplateLoader) {
+ mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
+ }
+ mTemplateLoader->setTemplateDirs(QStringList() << path);
+ mEngine->addTemplateLoader(mTemplateLoader);
+
+ mSelfcontainedTemplate = mEngine->loadByName(QStringLiteral("addresseslocation.html"));
+ if (mSelfcontainedTemplate->error()) {
+ mErrorMessage += mSelfcontainedTemplate->errorString() + QLatin1String("<br>");
+ }
+}
diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h
new file mode 100644
index 0000000..f010ce6
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSESLOCATIONGRANTLEEFORMATER_H
+#define ADDRESSESLOCATIONGRANTLEEFORMATER_H
+
+#include <QObject>
+
+#include <KContacts/Address>
+#include <QSharedPointer>
+#include <grantlee/templateloader.h>
+namespace Grantlee {
+class Engine;
+}
+class AddressesLocationGrantleeFormater : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationGrantleeFormater(QObject *parent = nullptr);
+ ~AddressesLocationGrantleeFormater();
+
+ QString formatAddresses(const KContacts::Address::List &addresses);
+ void setReadOnly(bool readOnly);
+private:
+ void changeGrantleePath(const QString &path);
+ Grantlee::Engine *mEngine = nullptr;
+ QString mErrorMessage;
+ QString mGrantleeThemePath;
+ QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
+ Grantlee::Template mSelfcontainedTemplate;
+ bool mReadOnly;
+};
+#endif // ADDRESSESLOCATIONGRANTLEEFORMATER_H
diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp
new file mode 100644
index 0000000..25a9c08
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp
@@ -0,0 +1,77 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "webengine/addresseslocationengineviewer.h"
+#include "addresslocationwidget.h"
+
+AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
+ : QSplitter(parent)
+{
+ setChildrenCollapsible(false);
+ mAddressLocationWidget = new AddressLocationWidget(this);
+ mAddressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
+ addWidget(mAddressLocationWidget);
+ mAddressesLocationViewer = new AddressesLocationEngineViewer(this);
+ mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
+ addWidget(mAddressesLocationViewer);
+ connect(mAddressesLocationViewer, &AddressesLocationEngineViewer::modifyAddress, mAddressLocationWidget, &AddressLocationWidget::slotModifyAddress);
+ connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::addAddress);
+ connect(mAddressLocationWidget, &AddressLocationWidget::updateAddressCanceled, mAddressesLocationViewer, &AddressesLocationEngineViewer::updateAddressCanceled);
+ connect(mAddressLocationWidget, &AddressLocationWidget::updateAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::replaceAddress);
+ setSizes(QList<int>() << 400 << 300);
+}
+
+AddressesLocationWidget::~AddressesLocationWidget()
+{
+}
+
+void AddressesLocationWidget::loadContact(const KContacts::Addressee &contact)
+{
+ mAddressesLocationViewer->setAddresses(contact.addresses());
+}
+
+void AddressesLocationWidget::storeContact(KContacts::Addressee &contact) const
+{
+ // delete all previous addresses
+ const KContacts::Address::List oldAddresses = contact.addresses();
+ const int numberOfOldAddresses(oldAddresses.count());
+ for (int i = 0; i < numberOfOldAddresses; ++i) {
+ contact.removeAddress(oldAddresses.at(i));
+ }
+
+ const KContacts::Address::List addressList = mAddressesLocationViewer->addresses();
+ // insert the new ones
+ const int numberOfAddress(addressList.count());
+ for (int i = 0; i < numberOfAddress; ++i) {
+ const KContacts::Address address(addressList.at(i));
+ if (!address.isEmpty()) {
+ contact.insertAddress(address);
+ }
+ }
+}
+
+void AddressesLocationWidget::setReadOnly(bool readOnly)
+{
+ mAddressesLocationViewer->setReadOnly(readOnly);
+ mAddressLocationWidget->setReadOnly(readOnly);
+}
diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h
new file mode 100644
index 0000000..2caf7af
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 <QSplitter>
+#include <KContacts/Addressee>
+class AddressLocationWidget;
+class AddressesLocationEngineViewer;
+class AddressesLocationWidget : public QSplitter
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationWidget(QWidget *parent = nullptr);
+ ~AddressesLocationWidget();
+
+ void loadContact(const KContacts::Addressee &contact);
+ void storeContact(KContacts::Addressee &contact) const;
+
+ void setReadOnly(bool readOnly);
+private:
+ AddressesLocationEngineViewer *mAddressesLocationViewer = nullptr;
+ AddressLocationWidget *mAddressLocationWidget = nullptr;
+};
+#endif // ADDRESSESLOCATIONWIDGET_H
diff --git a/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp
new file mode 100644
index 0000000..1353d3f
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp
@@ -0,0 +1,128 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addressgrantleeobject.h"
+#include "iconnamecache_p.h"
+#include <KIconLoader>
+#include <KLocalizedString>
+#include <QUrlQuery>
+
+AddressGrantleeObject::AddressGrantleeObject(const KContacts::Address &address, int addressIndex, QObject *parent)
+ : QObject(parent)
+ , mAddress(address)
+ , mAddressIndex(addressIndex)
+{
+ mIconSize = KIconLoader::global()->currentSize(KIconLoader::Small);
+}
+
+AddressGrantleeObject::~AddressGrantleeObject()
+{
+}
+
+QString AddressGrantleeObject::formattedAddress() const
+{
+ QString str;
+ if (mAddress.label().isEmpty()) {
+ str = mAddress.formattedAddress().trimmed().toHtmlEscaped();
+ } else {
+ str = mAddress.label().toHtmlEscaped();
+ }
+ 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::preferredAddressAction() const
+{
+ QString text;
+ if (preferredAddress()) {
+ const QString iconPath = QUrl::fromLocalFile(IconNameCache::instance()->iconPath(QStringLiteral("bookmarks"), KIconLoader::Small)).url();
+ text = QStringLiteral("<img class=\"headimage\" height=\"%3\" width=\"%3\" title=\"%1\" src=\"%2\"></a>\n")
+ .arg(i18n("Remove Address"), iconPath, QString::number(mIconSize));
+ }
+ return text;
+}
+
+QString AddressGrantleeObject::postOfficeBox() const
+{
+ return mAddress.postOfficeBox();
+}
+
+QString AddressGrantleeObject::street() const
+{
+ return mAddress.street();
+}
+
+QString AddressGrantleeObject::locality() const
+{
+ return mAddress.locality();
+}
+
+QString AddressGrantleeObject::region() const
+{
+ return mAddress.region();
+}
+
+QString AddressGrantleeObject::postalCode() const
+{
+ return mAddress.postalCode();
+}
+
+QString AddressGrantleeObject::country() const
+{
+ return mAddress.country();
+}
+
+QString AddressGrantleeObject::removeAddressAction() const
+{
+ const QString iconPath = QUrl::fromLocalFile(IconNameCache::instance()->iconPath(QStringLiteral("edit-delete"), KIconLoader::Small)).url();
+ const QString text = QStringLiteral("<a href=\"%1\"><img class=\"headimage\" height=\"%4\" width=\"%4\" title=\"%3\" src=\"%2\"></a>\n")
+ .arg(createActionUrl(QStringLiteral("removeaddress")), iconPath, i18n("Remove Address"), QString::number(mIconSize));
+ return text;
+}
+
+QString AddressGrantleeObject::modifyAddressAction() const
+{
+ const QString iconPath = QUrl::fromLocalFile(IconNameCache::instance()->iconPath(QStringLiteral("document-edit"), KIconLoader::Small)).url();
+ const QString text = QStringLiteral("<a href=\"%1\"><img class=\"headimage\" height=\"%4\" width=\"%4\" title=\"%3\" src=\"%2\"></a>\n")
+ .arg(createActionUrl(QStringLiteral("editaddress")), iconPath, i18n("Edit Address"), QString::number(mIconSize));
+ return text;
+}
+
+QString AddressGrantleeObject::addressType() const
+{
+ return KContacts::Address::typeLabel(mAddress.type());
+}
+
+bool AddressGrantleeObject::preferredAddress() const
+{
+ return mAddress.type() & KContacts::Address::Pref;
+}
diff --git a/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h
new file mode 100644
index 0000000..d7ae628
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h
@@ -0,0 +1,67 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSGRANTLEEOBJECT_H
+#define ADDRESSGRANTLEEOBJECT_H
+
+#include <QObject>
+#include <KContacts/Address>
+
+class AddressGrantleeObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString removeAddressAction READ removeAddressAction)
+ Q_PROPERTY(QString modifyAddressAction READ modifyAddressAction)
+ Q_PROPERTY(QString formattedAddress READ formattedAddress)
+ Q_PROPERTY(QString preferredAddressAction READ preferredAddressAction)
+ Q_PROPERTY(QString addressType READ addressType)
+ Q_PROPERTY(QString postOfficeBox READ postOfficeBox)
+ Q_PROPERTY(QString street READ street)
+ Q_PROPERTY(QString locality READ locality)
+ Q_PROPERTY(QString region READ region)
+ Q_PROPERTY(QString postalCode READ postalCode)
+ Q_PROPERTY(QString country READ country)
+ Q_PROPERTY(bool preferredAddress READ preferredAddress)
+public:
+ explicit AddressGrantleeObject(const KContacts::Address &address, int addressIndex, QObject *parent = nullptr);
+ ~AddressGrantleeObject();
+
+ QString removeAddressAction() const;
+ QString modifyAddressAction() const;
+ QString formattedAddress() const;
+ QString addressType() const;
+ bool preferredAddress() const;
+ QString preferredAddressAction() const;
+ QString postOfficeBox() const;
+ QString street() const;
+ QString locality() const;
+ QString region() const;
+ QString postalCode() const;
+ QString country() const;
+
+private:
+ QString createActionUrl(const QString &actionName) const;
+ KContacts::Address mAddress;
+ int mAddressIndex;
+ int mIconSize;
+};
+#endif // ADDRESSGRANTLEEOBJECT_H
diff --git a/kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp
new file mode 100644
index 0000000..3d148c2
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp
@@ -0,0 +1,293 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresslocationwidget.h"
+#include "selectaddresstypecombobox.h"
+
+#include <KComboBox>
+#include <KLineEdit>
+#include <KLocalizedString>
+
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QStackedWidget>
+struct LocaleAwareLessThan : std::binary_function<QString, QString, bool> {
+ bool operator()(const QString &s1, const QString &s2) const
+ {
+ return QString::localeAwareCompare(s1, s2) < 0;
+ }
+};
+
+AddressLocationWidget::AddressLocationWidget(QWidget *parent)
+ : QWidget(parent)
+ , mCurrentAddress(-1)
+ , mCurrentMode(CreateAddress)
+{
+ QVBoxLayout *topLayout = new QVBoxLayout(this);
+
+ QGridLayout *gridLayout = new QGridLayout;
+ topLayout->addLayout(gridLayout);
+
+ mTypeCombo = new SelectAddressTypeComboBox(this);
+ mTypeCombo->setObjectName(QStringLiteral("typeaddress"));
+ gridLayout->addWidget(mTypeCombo, 0, 0, 1, 2);
+
+ QLabel *label = new QLabel(KContacts::Address::streetLabel(), this);
+ label->setObjectName(QStringLiteral("streetlabel"));
+ gridLayout->addWidget(label, 1, 0);
+
+ mStreetEdit = new KLineEdit(this);
+ mStreetEdit->setPlaceholderText(i18n("Add Street"));
+ mStreetEdit->setObjectName(QStringLiteral("streetlineedit"));
+ mStreetEdit->setTrapReturnKey(true);
+ gridLayout->addWidget(mStreetEdit, 2, 0);
+
+ label = new QLabel(KContacts::Address::postOfficeBoxLabel(), this);
+ label->setObjectName(QStringLiteral("postofficeboxlabel"));
+ gridLayout->addWidget(label, 1, 1);
+
+ mPOBoxEdit = new KLineEdit(this);
+ mPOBoxEdit->setPlaceholderText(i18n("Add Post Office Box"));
+ mPOBoxEdit->setObjectName(QStringLiteral("postofficeboxlineedit"));
+ mPOBoxEdit->setTrapReturnKey(true);
+ gridLayout->addWidget(mPOBoxEdit, 2, 1);
+
+ label = new QLabel(KContacts::Address::postalCodeLabel(), this);
+ label->setObjectName(QStringLiteral("postalcodelabel"));
+ gridLayout->addWidget(label, 3, 0);
+ mPostalCodeEdit = new KLineEdit(this);
+ mPostalCodeEdit->setPlaceholderText(i18n("Add Postal Code"));
+ mPostalCodeEdit->setObjectName(QStringLiteral("postalcodelineedit"));
+ mPostalCodeEdit->setTrapReturnKey(true);
+ gridLayout->addWidget(mPostalCodeEdit, 4, 0);
+
+ label = new QLabel(KContacts::Address::localityLabel(), this);
+ label->setObjectName(QStringLiteral("localitylabel"));
+ gridLayout->addWidget(label, 3, 1);
+ mLocalityEdit = new KLineEdit(this);
+ mLocalityEdit->setPlaceholderText(i18n("Add Locality"));
+ mLocalityEdit->setObjectName(QStringLiteral("localitylineedit"));
+ mLocalityEdit->setTrapReturnKey(true);
+ gridLayout->addWidget(mLocalityEdit, 4, 1);
+
+ label = new QLabel(KContacts::Address::regionLabel(), this);
+ label->setObjectName(QStringLiteral("regionlabel"));
+ gridLayout->addWidget(label, 5, 0);
+ mRegionEdit = new KLineEdit(this);
+ mRegionEdit->setPlaceholderText(i18n("Add Region"));
+ mRegionEdit->setObjectName(QStringLiteral("regionlineedit"));
+ mRegionEdit->setTrapReturnKey(true);
+ gridLayout->addWidget(mRegionEdit, 6, 0);
+
+ label = new QLabel(KContacts::Address::countryLabel(), this);
+ label->setObjectName(QStringLiteral("countrylabel"));
+ gridLayout->addWidget(label, 5, 1);
+ mCountryCombo = new KComboBox(this);
+ KLineEdit *edit = new KLineEdit(this);
+ edit->setTrapReturnKey(true);
+ mCountryCombo->setLineEdit(edit);
+ mCountryCombo->setObjectName(QStringLiteral("countrycombobox"));
+ mCountryCombo->setEditable(true);
+ mCountryCombo->lineEdit()->setPlaceholderText(i18n("Add a Country"));
+ mCountryCombo->setDuplicatesEnabled(false);
+ gridLayout->addWidget(mCountryCombo, 6, 1);
+
+ mPreferredCheckBox = new QCheckBox(i18nc("street/postal", "This is the preferred address"), this);
+ mPreferredCheckBox->setObjectName(QStringLiteral("preferredcheckbox"));
+ gridLayout->addWidget(mPreferredCheckBox, 7, 0, 1, 2);
+
+ mButtonStack = new QStackedWidget(this);
+ mButtonStack->setObjectName(QStringLiteral("buttonstacked"));
+ topLayout->addWidget(mButtonStack);
+
+ QWidget *addButtonWidget = new QWidget(this);
+ QHBoxLayout *addButtonWidgetLayout = new QHBoxLayout(addButtonWidget);
+ addButtonWidgetLayout->setMargin(0);
+ mAddAddress = new QPushButton(i18n("Add Address"), this);
+ mAddAddress->setObjectName(QStringLiteral("addbuttonaddress"));
+ connect(mAddAddress, &QPushButton::clicked, this, &AddressLocationWidget::slotAddAddress);
+ addButtonWidgetLayout->addWidget(mAddAddress);
+ addButtonWidgetLayout->addStretch(1);
+ mButtonStack->addWidget(addButtonWidget);
+
+ QWidget *modifyButtonWidget = new QWidget(this);
+ QHBoxLayout *modifyButtonWidgetLayout = new QHBoxLayout(modifyButtonWidget);
+ modifyButtonWidgetLayout->setMargin(0);
+ mButtonStack->addWidget(modifyButtonWidget);
+
+ mModifyAddress = new QPushButton(i18n("Update Address"), this);
+ mModifyAddress->setObjectName(QStringLiteral("modifybuttonaddress"));
+ modifyButtonWidgetLayout->addWidget(mModifyAddress);
+ connect(mModifyAddress, &QPushButton::clicked, this, &AddressLocationWidget::slotUpdateAddress);
+
+ mCancelAddress = new QPushButton(i18n("Cancel"), this);
+ mCancelAddress->setObjectName(QStringLiteral("cancelbuttonaddress"));
+ connect(mCancelAddress, &QPushButton::clicked, this, &AddressLocationWidget::slotCancelModifyAddress);
+ modifyButtonWidgetLayout->addWidget(mCancelAddress);
+ modifyButtonWidgetLayout->addStretch(1);
+ const int buttonWidth = qMax(mCancelAddress->width(), mModifyAddress->width());
+ mModifyAddress->setMinimumWidth(buttonWidth);
+ mCancelAddress->setMinimumWidth(buttonWidth);
+
+ topLayout->addStretch(1);
+ fillCountryCombo();
+ switchMode();
+}
+
+AddressLocationWidget::~AddressLocationWidget()
+{
+}
+
+void AddressLocationWidget::setReadOnly(bool readOnly)
+{
+ mPreferredCheckBox->setEnabled(!readOnly);
+ mPOBoxEdit->setReadOnly(readOnly);
+ mLocalityEdit->setReadOnly(readOnly);
+ mRegionEdit->setReadOnly(readOnly);
+ mPostalCodeEdit->setReadOnly(readOnly);
+ mStreetEdit->setReadOnly(readOnly);
+ mCountryCombo->setEnabled(!readOnly);
+ mTypeCombo->setEnabled(!readOnly);
+
+ mAddAddress->setEnabled(!readOnly);
+ mModifyAddress->setEnabled(!readOnly);
+ mCancelAddress->setEnabled(!readOnly);
+}
+
+void AddressLocationWidget::fillCountryCombo()
+{
+ QStringList countries;
+ const QList<QLocale> localeList = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
+ countries.reserve(localeList.count());
+ for (const QLocale &locale : localeList) {
+ const QString localeStr = QLocale::countryToString(locale.country());
+ if (countries.contains(localeStr)) {
+ continue;
+ }
+ countries.append(localeStr);
+ }
+
+ std::sort(countries.begin(), countries.end(), LocaleAwareLessThan());
+
+ mCountryCombo->addItems(countries);
+ mCountryCombo->setAutoCompletion(true);
+ mCountryCombo->completionObject()->setItems(countries);
+ mCountryCombo->completionObject()->setIgnoreCase(true);
+
+ const QString currentCountry = QLocale::countryToString(QLocale().country());
+ mCountryCombo->setCurrentIndex(mCountryCombo->findText(currentCountry));
+}
+
+void AddressLocationWidget::slotAddAddress()
+{
+ KContacts::Address addr = address();
+ if (!addr.isEmpty()) {
+ Q_EMIT addNewAddress(addr);
+ reset();
+ }
+}
+
+void AddressLocationWidget::setAddress(const KContacts::Address &address)
+{
+ mAddress = address;
+ mTypeCombo->setType(mAddress.type());
+ mStreetEdit->setText(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 (address.isEmpty()) {
+ mCountryCombo->setItemText(mCountryCombo->currentIndex(),
+ QLocale::countryToString(QLocale().country()));
+ } else {
+ mCountryCombo->setItemText(mCountryCombo->currentIndex(), mAddress.country());
+ }
+}
+
+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(mStreetEdit->text());
+ if (mPreferredCheckBox->isChecked()) {
+ address.setType(address.type() | KContacts::Address::Pref);
+ } else {
+ address.setType(address.type() & ~(KContacts::Address::Pref));
+ }
+ return address;
+}
+
+void AddressLocationWidget::switchMode()
+{
+ switch (mCurrentMode) {
+ case CreateAddress:
+ mButtonStack->setCurrentIndex(0);
+ break;
+ case ModifyAddress:
+ mButtonStack->setCurrentIndex(1);
+ break;
+ }
+}
+
+void AddressLocationWidget::slotModifyAddress(const KContacts::Address &address, int currentIndex)
+{
+ setAddress(address);
+ mCurrentMode = ModifyAddress;
+ mCurrentAddress = currentIndex;
+ switchMode();
+}
+
+void AddressLocationWidget::clear()
+{
+ mCurrentMode = CreateAddress;
+ setAddress(KContacts::Address());
+ switchMode();
+}
+
+void AddressLocationWidget::slotUpdateAddress()
+{
+ if (mCurrentMode == ModifyAddress) {
+ Q_EMIT updateAddress(address(), mCurrentAddress);
+ reset();
+ }
+}
+
+void AddressLocationWidget::reset()
+{
+ Q_EMIT updateAddressCanceled();
+ mCurrentAddress = -1;
+ clear();
+}
+
+void AddressLocationWidget::slotCancelModifyAddress()
+{
+ reset();
+}
diff --git a/kaddressbook/contacteditor/addresseditor/addresslocationwidget.h b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.h
new file mode 100644
index 0000000..3f92959
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.h
@@ -0,0 +1,83 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSLOCATIONWIDGET_H
+#define ADDRESSLOCATIONWIDGET_H
+
+#include <QWidget>
+#include <KContacts/Address>
+class QStackedWidget;
+class QCheckBox;
+class KLineEdit;
+class KComboBox;
+class QPushButton;
+class SelectAddressTypeComboBox;
+class AddressLocationWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ enum Mode {
+ CreateAddress = 0,
+ ModifyAddress
+ };
+
+ explicit AddressLocationWidget(QWidget *parent = nullptr);
+ ~AddressLocationWidget();
+
+ void setAddress(const KContacts::Address &address);
+ KContacts::Address address() const;
+
+ void slotModifyAddress(const KContacts::Address &address, int currentIndex);
+
+ void clear();
+
+ void setReadOnly(bool readOnly);
+
+Q_SIGNALS:
+ void addNewAddress(const KContacts::Address &address);
+ void updateAddress(const KContacts::Address &address, int index);
+ void updateAddressCanceled();
+
+private:
+ void slotAddAddress();
+ void slotUpdateAddress();
+ void slotCancelModifyAddress();
+ void fillCountryCombo();
+ void switchMode();
+ void reset();
+ KContacts::Address mAddress;
+ QCheckBox *mPreferredCheckBox = nullptr;
+ KLineEdit *mPOBoxEdit = nullptr;
+ KLineEdit *mLocalityEdit = nullptr;
+ KLineEdit *mRegionEdit = nullptr;
+ KLineEdit *mPostalCodeEdit = nullptr;
+ KLineEdit *mStreetEdit = nullptr;
+ KComboBox *mCountryCombo = nullptr;
+ QPushButton *mAddAddress = nullptr;
+ QPushButton *mModifyAddress = nullptr;
+ QPushButton *mCancelAddress = nullptr;
+ QStackedWidget *mButtonStack = nullptr;
+ SelectAddressTypeComboBox *mTypeCombo = nullptr;
+ int mCurrentAddress;
+ Mode mCurrentMode;
+};
+#endif // ADDRESSLOCATIONWIDGET_H
diff --git a/kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp b/kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp
new file mode 100644
index 0000000..b7b7451
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp
@@ -0,0 +1,92 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (c) 2009 Tobias Koenig <[email protected]>
+
+ 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 "addresstypedialog.h"
+#include <KLocalizedString>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QGroupBox>
+#include <QCheckBox>
+#include <QButtonGroup>
+
+AddressTypeDialog::AddressTypeDialog(KContacts::Address::Type type, QWidget *parent)
+ : QDialog(parent)
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ setWindowTitle(i18nc("street/postal", "Edit Address Type"));
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
+ QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
+ okButton->setDefault(true);
+ okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+
+ QWidget *page = new QWidget(this);
+ mainLayout->addWidget(page);
+ mainLayout->addWidget(buttonBox);
+ QVBoxLayout *layout = new QVBoxLayout(page);
+ layout->setMargin(0);
+
+ QGroupBox *box = new QGroupBox(i18nc("street/postal", "Address Types"), page);
+ mainLayout->addWidget(box);
+ layout->addWidget(box);
+ mGroup = new QButtonGroup(box);
+ mGroup->setExclusive(false);
+
+ QGridLayout *buttonLayout = new QGridLayout(box);
+
+ mTypeList = KContacts::Address::typeList();
+ mTypeList.removeAll(KContacts::Address::Pref);
+
+ KContacts::Address::TypeList::ConstIterator it;
+ int i = 0;
+ int row = 0;
+ KContacts::Address::TypeList::ConstIterator end(mTypeList.constEnd());
+ for (it = mTypeList.constBegin(); it != end; ++it, ++i) {
+ QCheckBox *cb = new QCheckBox(KContacts::Address::typeLabel(*it), box);
+ cb->setChecked(type & mTypeList[i]);
+ buttonLayout->addWidget(cb, row, i % 3);
+
+ if (i % 3 == 2) {
+ ++row;
+ }
+ mGroup->addButton(cb);
+ }
+}
+
+AddressTypeDialog::~AddressTypeDialog()
+{
+}
+
+KContacts::Address::Type AddressTypeDialog::type() const
+{
+ KContacts::Address::Type type;
+ const int numberOfButtons(mGroup->buttons().count());
+ for (int i = 0; i < numberOfButtons; ++i) {
+ QCheckBox *box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
+ if (box && box->isChecked()) {
+ type |= mTypeList[i];
+ }
+ }
+
+ return type;
+}
diff --git a/kaddressbook/contacteditor/addresseditor/addresstypedialog.h b/kaddressbook/contacteditor/addresseditor/addresstypedialog.h
new file mode 100644
index 0000000..178e75e
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/addresstypedialog.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (c) 2009 Tobias Koenig <[email protected]>
+
+ 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 ADDRESSTYPEDIALOG_H
+#define ADDRESSTYPEDIALOG_H
+
+#include <QDialog>
+#include <KContacts/Address>
+class QButtonGroup;
+/**
+ * Dialog for creating a new address types.
+ *
+ * @note This dialog is only used by AddressTypeCombo.
+ */
+class AddressTypeDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ AddressTypeDialog(KContacts::Address::Type type, QWidget *parent);
+ ~AddressTypeDialog();
+
+ KContacts::Address::Type type() const;
+
+private:
+ QButtonGroup *mGroup = nullptr;
+
+ KContacts::Address::TypeList mTypeList;
+};
+
+#endif // ADDRESSTYPEDIALOG_H
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt
new file mode 100644
index 0000000..ac641a0
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt
@@ -0,0 +1,31 @@
+include(ECMMarkAsTest)
+
+set(contacteditor_addresslocation_web_editor_SRCS
+ ../webengine/addresseslocationengineviewer.cpp
+ ../webengine/addresseslocationenginepage.cpp
+ )
+set(contacteditor_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
+
+ecm_qt_declare_logging_category(contacteditor_addresslocation_web_editor_SRCS HEADER contacteditor_debug.h IDENTIFIER CONTACTEDITOR_LOG CATEGORY_NAME org.kde.pim.contacteditor)
+
+set(addresseslocationviewer_SRCS addresseslocationviewertest.cpp ${contacteditor_addresslocation_web_editor_SRCS} ../addresseslocationgrantleeformater.cpp
+ ../addressgrantleeobject.cpp ../iconnamecache.cpp)
+add_executable(addresseslocationviewer ${addresseslocationviewer_SRCS})
+add_test(NAME addresseslocationviewer COMMAND addresseslocationviewer)
+ecm_mark_as_test(addresseslocationviewer)
+target_link_libraries(addresseslocationviewer Qt5::Test Qt5::Widgets KF5::ContactEditor KF5::Contacts KF5::I18n ${contacteditor_webengine_LIB} Grantlee5::Templates
+ KF5::IconThemes KF5::WidgetsAddons)
+
+set(addresslocationwidget_SRCS addresslocationwidgettest.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp ../addresstypedialog.cpp)
+add_executable(addresslocationwidget ${addresslocationwidget_SRCS})
+add_test(NAME addresslocationwidget COMMAND addresslocationwidget)
+ecm_mark_as_test(addresslocationwidget)
+target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::ContactEditor KF5::Contacts KF5::I18n KF5::Completion)
+
+set(addresseslocationwidget_SRCS addresseslocationwidgettest.cpp ../addresseslocationwidget.cpp ${contacteditor_addresslocation_web_editor_SRCS} ../addresseslocationgrantleeformater.cpp
+ ../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp ../addresstypedialog.cpp)
+add_executable(addresseslocationwidget ${addresseslocationwidget_SRCS})
+add_test(NAME addresseslocationwidget COMMAND addresseslocationwidget)
+ecm_mark_as_test(addresseslocationwidget)
+target_link_libraries(addresseslocationwidget Qt5::Test Qt5::Widgets KF5::ContactEditor KF5::Contacts KF5::I18n KF5::Completion ${contacteditor_webengine_LIB}
+ Grantlee5::Templates KF5::IconThemes KF5::WidgetsAddons)
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp
new file mode 100644
index 0000000..35d8ff4
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp
@@ -0,0 +1,43 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresseslocationviewertest.h"
+#include "config-contact-editor.h"
+#include "../webengine/addresseslocationengineviewer.h"
+#include <QTest>
+using namespace ContactEditor;
+AddressesLocationViewerTest::AddressesLocationViewerTest(QObject *parent)
+ : QObject(parent)
+{
+}
+
+AddressesLocationViewerTest::~AddressesLocationViewerTest()
+{
+}
+
+void AddressesLocationViewerTest::shouldHaveDefaultValue()
+{
+ AddressesLocationEngineViewer w;
+ QVERIFY(w.addresses().isEmpty());
+}
+
+QTEST_MAIN(AddressesLocationViewerTest)
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h
new file mode 100644
index 0000000..b862790
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSESLOCATIONVIEWERTEST_H
+#define ADDRESSESLOCATIONVIEWERTEST_H
+
+#include <QObject>
+
+class AddressesLocationViewerTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationViewerTest(QObject *parent = nullptr);
+ ~AddressesLocationViewerTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif // ADDRESSESLOCATIONVIEWERTEST_H
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp
new file mode 100644
index 0000000..ecbe3d5
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp
@@ -0,0 +1,51 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresseslocationwidgettest.h"
+#include "config-contact-editor.h"
+#include "../webengine/addresseslocationengineviewer.h"
+
+#include "../addresseslocationwidget.h"
+#include <QTest>
+
+#include <editor/addresseditor/addresslocationwidget.h>
+using namespace ContactEditor;
+AddressesLocationWidgetTest::AddressesLocationWidgetTest(QObject *parent)
+ : QObject(parent)
+{
+}
+
+AddressesLocationWidgetTest::~AddressesLocationWidgetTest()
+{
+}
+
+void AddressesLocationWidgetTest::shouldHaveDefaultValue()
+{
+ AddressesLocationWidget w;
+ AddressLocationWidget *addressLocationWidget = w.findChild<AddressLocationWidget *>(QStringLiteral("addresslocationwidget"));
+ QVERIFY(addressLocationWidget);
+
+ AddressesLocationEngineViewer *addressesLocationViewer = w.findChild<AddressesLocationEngineViewer *>(QStringLiteral("addresseslocationviewer"));
+ QVERIFY(addressesLocationViewer);
+}
+
+QTEST_MAIN(AddressesLocationWidgetTest)
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h
new file mode 100644
index 0000000..b5ac349
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSESLOCATIONWIDGETTEST_H
+#define ADDRESSESLOCATIONWIDGETTEST_H
+
+#include <QObject>
+
+class AddressesLocationWidgetTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationWidgetTest(QObject *parent = nullptr);
+ ~AddressesLocationWidgetTest();
+
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif // ADDRESSESLOCATIONWIDGETTEST_H
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp
new file mode 100644
index 0000000..03c2302
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp
@@ -0,0 +1,121 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresslocationwidgettest.h"
+#include "../addresslocationwidget.h"
+#include <QLabel>
+#include <QPushButton>
+#include <KComboBox>
+#include <KLineEdit>
+#include <QTest>
+#include <QCheckBox>
+#include <editor/addresseditor/selectaddresstypecombobox.h>
+using namespace ContactEditor;
+AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent)
+ : QObject(parent)
+{
+}
+
+AddressLocationWidgetTest::~AddressLocationWidgetTest()
+{
+}
+
+void AddressLocationWidgetTest::shouldHaveDefaultValue()
+{
+ AddressLocationWidget w;
+
+ SelectAddressTypeComboBox *typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
+ QVERIFY(typeAddress);
+
+ QLabel *streetlabel = w.findChild<QLabel *>(QStringLiteral("streetlabel"));
+ QVERIFY(streetlabel);
+ KLineEdit *mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
+ QVERIFY(mStreetEdit);
+
+ QLabel *postofficeboxlabel = w.findChild<QLabel *>(QStringLiteral("postofficeboxlabel"));
+ QVERIFY(postofficeboxlabel);
+ KLineEdit *postofficeboxlineedit = w.findChild<KLineEdit *>(QStringLiteral("postofficeboxlineedit"));
+ QVERIFY(postofficeboxlineedit);
+
+ QLabel *localitylabel = w.findChild<QLabel *>(QStringLiteral("localitylabel"));
+ QVERIFY(localitylabel);
+ KLineEdit *localitylineedit = w.findChild<KLineEdit *>(QStringLiteral("localitylineedit"));
+ QVERIFY(localitylineedit);
+
+ QLabel *regionlabel = w.findChild<QLabel *>(QStringLiteral("regionlabel"));
+ QVERIFY(regionlabel);
+ KLineEdit *regionlineedit = w.findChild<KLineEdit *>(QStringLiteral("regionlineedit"));
+ QVERIFY(regionlineedit);
+
+ QLabel *postalcodelabel = w.findChild<QLabel *>(QStringLiteral("postalcodelabel"));
+ QVERIFY(postalcodelabel);
+ KLineEdit *postalcodelineedit = w.findChild<KLineEdit *>(QStringLiteral("postalcodelineedit"));
+ QVERIFY(postalcodelineedit);
+
+ QLabel *countrylabel = w.findChild<QLabel *>(QStringLiteral("countrylabel"));
+ QVERIFY(countrylabel);
+ KComboBox *countrycombobox = w.findChild<KComboBox *>(QStringLiteral("countrycombobox"));
+ QVERIFY(countrycombobox);
+
+ QCheckBox *preferredcheckbox = w.findChild<QCheckBox *>(QStringLiteral("preferredcheckbox"));
+ QVERIFY(preferredcheckbox);
+
+ QPushButton *addbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("addbuttonaddress"));
+ QVERIFY(addbuttonaddress);
+
+ QPushButton *modifybuttonaddress = w.findChild<QPushButton *>(QStringLiteral("modifybuttonaddress"));
+ QVERIFY(modifybuttonaddress);
+
+ QPushButton *cancelbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("cancelbuttonaddress"));
+ QVERIFY(cancelbuttonaddress);
+}
+
+void AddressLocationWidgetTest::shouldChangeReadOnlyStatus()
+{
+ AddressLocationWidget w;
+
+ w.setReadOnly(true);
+ SelectAddressTypeComboBox *typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
+ QCOMPARE(typeAddress->isEnabled(), false);
+ KLineEdit *mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
+ QCOMPARE(mStreetEdit->isReadOnly(), true);
+ KLineEdit *postofficeboxlineedit = w.findChild<KLineEdit *>(QStringLiteral("postofficeboxlineedit"));
+ QCOMPARE(postofficeboxlineedit->isReadOnly(), true);
+ KLineEdit *localitylineedit = w.findChild<KLineEdit *>(QStringLiteral("localitylineedit"));
+ QCOMPARE(localitylineedit->isReadOnly(), true);
+ KLineEdit *regionlineedit = w.findChild<KLineEdit *>(QStringLiteral("regionlineedit"));
+ QCOMPARE(regionlineedit->isReadOnly(), true);
+ KLineEdit *postalcodelineedit = w.findChild<KLineEdit *>(QStringLiteral("postalcodelineedit"));
+ QCOMPARE(postalcodelineedit->isReadOnly(), true);
+ KComboBox *countrycombobox = w.findChild<KComboBox *>(QStringLiteral("countrycombobox"));
+ QCOMPARE(countrycombobox->isEnabled(), false);
+ QCheckBox *preferredcheckbox = w.findChild<QCheckBox *>(QStringLiteral("preferredcheckbox"));
+ QCOMPARE(preferredcheckbox->isEnabled(), false);
+ QPushButton *addbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("addbuttonaddress"));
+ QCOMPARE(addbuttonaddress->isEnabled(), false);
+ QPushButton *modifybuttonaddress = w.findChild<QPushButton *>(QStringLiteral("modifybuttonaddress"));
+ QCOMPARE(modifybuttonaddress->isEnabled(), false);
+ QPushButton *cancelbuttonaddress = w.findChild<QPushButton *>(QStringLiteral("cancelbuttonaddress"));
+ QCOMPARE(cancelbuttonaddress->isEnabled(), false);
+}
+
+QTEST_MAIN(AddressLocationWidgetTest)
diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h
new file mode 100644
index 0000000..2f7d2a9
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSLOCATIONWIDGETTEST_H
+#define ADDRESSLOCATIONWIDGETTEST_H
+
+#include <QObject>
+
+class AddressLocationWidgetTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit AddressLocationWidgetTest(QObject *parent = nullptr);
+ ~AddressLocationWidgetTest();
+
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+ void shouldChangeReadOnlyStatus();
+};
+
+#endif // ADDRESSLOCATIONWIDGETTEST_H
diff --git a/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt
new file mode 100644
index 0000000..b6d28f7
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt
@@ -0,0 +1 @@
+install(DIRECTORY default DESTINATION ${KDE_INSTALL_DATADIR}/contacteditor/grantleetheme )
diff --git a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css
new file mode 100644
index 0000000..02d83b3
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css
@@ -0,0 +1,16 @@
+#headeraddress {
+}
+
+#addresstype {
+ float: left;
+ color: #0000FF;
+}
+
+#actiontype {
+ float: right;
+ text-align: right;
+}
+
+#address {
+ float: left;
+}
diff --git a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html
new file mode 100644
index 0000000..345015b
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
+<html>
+<head>
+<title>.</title>
+<link href="{{ absoluteThemePath }}/addresseslocation.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+{% if addresses %}
+{% for address in addresses %}
+ <div id="headeraddress">
+ <div id="addresstype">{{ address.addressType }}</div>
+ <div id="actiontype">
+ {% if readOnly %}
+ {% else %}
+ {{ address.modifyAddressAction|safe}} {{ address.removeAddressAction|safe}}
+ {% endif %}
+ </div>
+
+ <br>
+ <div id="address" > {{ address.formattedAddress }} </div>
+
+ <br style="clear: both;"/>
+ <br/>
+ </div>
+{% endfor %}
+{% endif %}
+
+</body>
+
diff --git a/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp b/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp
new file mode 100644
index 0000000..2728ff5
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp
@@ -0,0 +1,54 @@
+/* Copyright 2009 Thomas McGuire <[email protected]>
+
+ 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 ) version 3 or, at the discretion of KDE e.V.
+ ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "iconnamecache_p.h"
+
+#include <KIconLoader>
+Q_GLOBAL_STATIC(IconNameCache, s_iconNameCache)
+
+IconNameCache *IconNameCache::instance()
+{
+ return s_iconNameCache;
+}
+
+bool IconNameCache::Entry::operator <(const Entry &other) const
+{
+ const int fileNameCompare = fileName.compare(other.fileName);
+ if (fileNameCompare != 0) {
+ return fileNameCompare < 0;
+ } else {
+ return size < other.size;
+ }
+}
+
+QString IconNameCache::iconPath(const QString &name, int size) const
+{
+ Entry entry;
+ entry.fileName = name;
+ entry.size = size;
+
+ const QString path = mCachedEntries.value(entry);
+ if (!path.isEmpty()) {
+ return path;
+ }
+
+ const QString fileName = KIconLoader::global()->iconPath(name, size);
+ mCachedEntries.insert(entry, fileName);
+ return fileName;
+}
diff --git a/kaddressbook/contacteditor/addresseditor/iconnamecache_p.h b/kaddressbook/contacteditor/addresseditor/iconnamecache_p.h
new file mode 100644
index 0000000..0096acb
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/iconnamecache_p.h
@@ -0,0 +1,51 @@
+/* Copyright 2009 Thomas McGuire <[email protected]>
+
+ 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 ) version 3 or, at the discretion of KDE e.V.
+ ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 ICONNAMECACHE_H
+#define ICONNAMECACHE_H
+
+#include <QMap>
+#include <QString>
+/**
+ * This class is a replacement for KIconLoader::iconPath(), because the iconPath()
+ * function can be slow for non-existing icons or icons that fall back to a generic icon.
+ * Reason is that KIconLoader does slow system calls for finding the icons.
+ *
+ * The IconNameCache caches the result of iconPath() in a map and solves the slowness.
+ */
+class IconNameCache
+{
+public:
+
+ static IconNameCache *instance();
+ QString iconPath(const QString &name, int size) const;
+
+private:
+
+ class Entry
+ {
+ public:
+ QString fileName;
+ int size;
+
+ bool operator <(const Entry &other) const;
+ };
+
+ mutable QMap<Entry, QString> mCachedEntries;
+};
+#endif
diff --git a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp
new file mode 100644
index 0000000..1bb3f08
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp
@@ -0,0 +1,114 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "selectaddresstypecombobox.h"
+#include "addresstypedialog.h"
+#include <QPointer>
+
+#include <KLocalizedString>
+
+SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent)
+ : KComboBox(parent)
+ , mType(KContacts::Address::Home)
+ , mLastSelected(0)
+{
+ const int count = KContacts::Address::typeList().count();
+ mTypeList.reserve(count + 2);
+ mTypeList.append(-2); // Add initial message
+ for (int i = 0; i < count; ++i) {
+ mTypeList.append(KContacts::Address::typeList().at(i));
+ }
+ mTypeList.append(-1); // Others...
+
+ update();
+
+ connect(this, QOverload<int>::of(&KComboBox::activated), this, &SelectAddressTypeComboBox::selected);
+}
+
+SelectAddressTypeComboBox::~SelectAddressTypeComboBox()
+{
+}
+
+void SelectAddressTypeComboBox::setType(KContacts::Address::Type type)
+{
+ if (!mTypeList.contains(static_cast<int>(type))) {
+ // insert at the end, but before the 'Others...' entry
+ mTypeList.insert(mTypeList.at(mTypeList.count() - 1), static_cast<int>(type));
+ }
+
+ mType = type;
+ update();
+}
+
+KContacts::Address::Type SelectAddressTypeComboBox::type() const
+{
+ return mType;
+}
+
+void SelectAddressTypeComboBox::update()
+{
+ bool blocked = signalsBlocked();
+ blockSignals(true);
+
+ clear();
+ const int numberOfType(mTypeList.count());
+ for (int i = 0; i < numberOfType; ++i) {
+ if (mTypeList.at(i) == -1) { // "Other..." entry
+ addItem(i18nc("@item:inlistbox Category of contact info field", "Other..."));
+ } else if (mTypeList.at(i) == -2) {
+ addItem(i18nc("@item:inlistbox Category of contact info field", "New Address Type"));
+ } else {
+ addItem(KContacts::Address::typeLabel(KContacts::Address::Type(mTypeList.at(i))));
+ }
+ }
+
+ setCurrentIndex(mLastSelected = mTypeList.indexOf(mType));
+
+ blockSignals(blocked);
+}
+
+void SelectAddressTypeComboBox::selected(int pos)
+{
+ if (mTypeList.at(pos) == -1) {
+ otherSelected();
+ } else if (mTypeList.at(pos) == -2) {
+ return;
+ } else {
+ mType = KContacts::Address::Type(mTypeList.at(pos));
+ mLastSelected = pos;
+ }
+}
+
+void SelectAddressTypeComboBox::otherSelected()
+{
+ QPointer<AddressTypeDialog> dlg = new AddressTypeDialog(mType, this);
+ if (dlg->exec()) {
+ mType = dlg->type();
+ if (!mTypeList.contains(mType)) {
+ mTypeList.insert(mTypeList.at(mTypeList.count() - 1), mType);
+ }
+ } else {
+ setType(KContacts::Address::Type(mTypeList.at(mLastSelected)));
+ }
+ delete dlg;
+ update();
+}
diff --git a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h
new file mode 100644
index 0000000..9790dc7
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h
@@ -0,0 +1,71 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 SELECTADDRESSTYPECOMBOBOX_H
+#define SELECTADDRESSTYPECOMBOBOX_H
+
+#include <KComboBox>
+#include <KContacts/Address>
+
+/**
+ * @short A widget for selecting the type of an address.
+ */
+class SelectAddressTypeComboBox : public KComboBox
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Creates a new address type combo.
+ *
+ * @param parent The parent widget.
+ */
+ explicit SelectAddressTypeComboBox(QWidget *parent = nullptr);
+
+ /**
+ * Destroys the address type combo.
+ */
+ ~SelectAddressTypeComboBox();
+
+ /**
+ * Sets the type that shall be selected in the combobox.
+ * @param type KABC address type to set.
+ */
+ void setType(KContacts::Address::Type type);
+
+ /**
+ * Returns the type that is currently selected.
+ */
+ KContacts::Address::Type type() const;
+
+private Q_SLOTS:
+ void selected(int);
+ void otherSelected();
+
+private:
+ void update();
+
+ KContacts::Address::Type mType;
+ int mLastSelected;
+ QList<int> mTypeList;
+};
+#endif
diff --git a/kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt
new file mode 100644
index 0000000..3198e47
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt
@@ -0,0 +1,34 @@
+set(akonadicontact_addresslocation_web_editor_SRCS
+ ../webengine/addresseslocationengineviewer.cpp
+ ../webengine/addresseslocationenginepage.cpp
+ )
+set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
+
+ecm_qt_declare_logging_category(akonadicontact_addresslocation_web_editor_SRCS HEADER contacteditor_debug.h IDENTIFIER CONTACTEDITOR_LOG CATEGORY_NAME org.kde.pim.akonadi_contact)
+
+set(addresseditor_SRCS
+ ${akonadicontact_addresslocation_web_editor_SRCS}
+ main.cpp
+ ../addresseslocationwidget.cpp
+ ../addresseslocationgrantleeformater.cpp
+ ../addressgrantleeobject.cpp
+ ../iconnamecache.cpp
+ ../addresslocationwidget.cpp
+ ../selectaddresstypecombobox.cpp
+ ../addresstypedialog.cpp
+ )
+
+add_executable(addresseditortest ${addresseditor_SRCS})
+
+target_link_libraries(addresseditortest
+ Qt5::Widgets
+ KF5::AkonadiContact
+ KF5::Contacts
+ KF5::I18n
+ KF5::Completion
+ Grantlee5::Templates
+ KF5::IconThemes
+ KF5::WidgetsAddons
+ ${akonadicontact_webengine_LIB}
+ )
+
diff --git a/kaddressbook/contacteditor/addresseditor/tests/main.cpp b/kaddressbook/contacteditor/addresseditor/tests/main.cpp
new file mode 100644
index 0000000..405eb34
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/tests/main.cpp
@@ -0,0 +1,35 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, [email protected]
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 <QApplication>
+
+#include "../addresseslocationwidget.h"
+using namespace ContactEditor;
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressesLocationWidget *addresseslocationwidget = new AddressesLocationWidget;
+ addresseslocationwidget->show();
+
+ return app.exec();
+}
diff --git a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp
new file mode 100644
index 0000000..f08fee4
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp
@@ -0,0 +1,60 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresseslocationenginepage.h"
+#include <QWebEngineSettings>
+#include <QWebEngineProfile>
+
+AddressesLocationEnginePage::AddressesLocationEnginePage(QObject *parent)
+ : QWebEnginePage(parent)
+{
+ settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
+ settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
+ settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, false);
+ settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, false);
+ settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
+ settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false);
+ settings()->setAttribute(QWebEngineSettings::Accelerated2dCanvasEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::WebGLEnabled, false);
+
+ settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false);
+ settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, false);
+ profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
+}
+
+AddressesLocationEnginePage::~AddressesLocationEnginePage()
+{
+}
+
+bool AddressesLocationEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
+{
+ Q_UNUSED(type);
+ Q_UNUSED(isMainFrame);
+ Q_EMIT urlClicked(url);
+ return false;
+}
diff --git a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h
new file mode 100644
index 0000000..7f95d5b
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 ADDRESSESLOCATIONENGINEPAGE_H
+#define ADDRESSESLOCATIONENGINEPAGE_H
+
+#include <QWebEnginePage>
+
+class AddressesLocationEnginePage : public QWebEnginePage
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationEnginePage(QObject *parent = nullptr);
+ ~AddressesLocationEnginePage();
+
+Q_SIGNALS:
+ void urlClicked(const QUrl &url);
+
+protected:
+ bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override;
+};
+
+#endif // ADDRESSESLOCATIONENGINEPAGE_H
diff --git a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp
new file mode 100644
index 0000000..d64f35c
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp
@@ -0,0 +1,139 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 "addresseslocationengineviewer.h"
+#include "addresseslocationenginepage.h"
+#include "addresslocationeditorplugin_debug.h"
+#include "../addresseslocationgrantleeformater.h"
+#include <KMessageBox>
+#include <KLocalizedString>
+#include <QUrlQuery>
+
+AddressesLocationEngineViewer::AddressesLocationEngineViewer(QWidget *parent)
+ : QWebEngineView(parent)
+ , mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this))
+{
+ AddressesLocationEnginePage *pageEngine = new AddressesLocationEnginePage(this);
+ setPage(pageEngine);
+
+ setFocusPolicy(Qt::WheelFocus);
+ connect(pageEngine, &AddressesLocationEnginePage::urlClicked, this, &AddressesLocationEngineViewer::slotLinkClicked);
+
+ setContextMenuPolicy(Qt::CustomContextMenu);
+}
+
+AddressesLocationEngineViewer::~AddressesLocationEngineViewer()
+{
+}
+
+void AddressesLocationEngineViewer::setReadOnly(bool readOnly)
+{
+ mAddressesLocationGrantleeFormatter->setReadOnly(readOnly);
+ updateView();
+}
+
+void AddressesLocationEngineViewer::slotLinkClicked(const QUrl &url)
+{
+ if (url.scheme() == QLatin1String("addresslocationaction")) {
+ const QString urlPath(url.path());
+ if (url.hasQuery()) {
+ const QUrlQuery urlQuery(url);
+ const int addressId = urlQuery.queryItemValue(QStringLiteral("id")).toInt();
+ if (urlPath == QStringLiteral("removeaddress")) {
+ if (!mEditMode) {
+ removeAddress(addressId);
+ }
+ } else if (urlPath == QStringLiteral("editaddress")) {
+ if (!mEditMode) {
+ editAddress(addressId);
+ }
+ } else {
+ qCDebug(ADDRESSLOCATIONEDITORPLUGIN_LOG) << "Unknown url" << url;
+ }
+ }
+ }
+}
+
+void AddressesLocationEngineViewer::removeAddress(int index)
+{
+ if (index < 0) {
+ return;
+ } else if (index < mAddresses.count()) {
+ const int result = KMessageBox::questionYesNo(this, i18n("Do you really want to delete this address?"));
+
+ if (result != KMessageBox::Yes) {
+ return;
+ }
+ mAddresses.remove(index);
+ updateView();
+ }
+}
+
+void AddressesLocationEngineViewer::editAddress(int index)
+{
+ if (index < 0) {
+ return;
+ } else if (index < mAddresses.count()) {
+ mEditMode = true;
+ Q_EMIT modifyAddress(mAddresses.at(index), index);
+ }
+}
+
+void AddressesLocationEngineViewer::replaceAddress(const KContacts::Address &address, int index)
+{
+ if (index < 0) {
+ return;
+ } else if (index < mAddresses.count()) {
+ mAddresses[index] = address;
+ updateView();
+ }
+ mEditMode = false;
+}
+
+void AddressesLocationEngineViewer::updateAddressCanceled()
+{
+ mEditMode = false;
+}
+
+void AddressesLocationEngineViewer::updateView()
+{
+ const QString html = mAddressesLocationGrantleeFormatter->formatAddresses(mAddresses);
+ setHtml(html, QUrl(QStringLiteral("file://")));
+}
+
+void AddressesLocationEngineViewer::addAddress(const KContacts::Address &address)
+{
+ if (!address.isEmpty()) {
+ mAddresses.append(address);
+ updateView();
+ }
+}
+
+KContacts::Address::List AddressesLocationEngineViewer::addresses() const
+{
+ return mAddresses;
+}
+
+void AddressesLocationEngineViewer::setAddresses(const KContacts::Address::List &addresses)
+{
+ mAddresses = addresses;
+ updateView();
+}
diff --git a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h
new file mode 100644
index 0000000..d73ed60
--- /dev/null
+++ b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of Contact Editor.
+
+ Copyright (C) 2016-2017 Laurent Montel <[email protected]>
+
+ 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 AddressesLocationEngineViewer_H
+#define AddressesLocationEngineViewer_H
+
+#include <QWebEngineView>
+#include <KContacts/Address>
+class AddressesLocationGrantleeFormater;
+class AddressesLocationEngineViewer : public QWebEngineView
+{
+ Q_OBJECT
+public:
+ explicit AddressesLocationEngineViewer(QWidget *parent = nullptr);
+ ~AddressesLocationEngineViewer();
+
+ KContacts::Address::List addresses() const;
+ void setAddresses(const KContacts::Address::List &addresses);
+ void setReadOnly(bool readOnly);
+
+public Q_SLOTS:
+ void addAddress(const KContacts::Address &address);
+ void replaceAddress(const KContacts::Address &address, int index);
+ void updateAddressCanceled();
+
+private Q_SLOTS:
+ void slotLinkClicked(const QUrl &url);
+
+Q_SIGNALS:
+ void modifyAddress(const KContacts::Address &address, int currentIndex);
+
+private:
+ void updateView();
+ void editAddress(int index);
+ void removeAddress(int index);
+ KContacts::Address::List mAddresses;
+ AddressesLocationGrantleeFormater *mAddressesLocationGrantleeFormatter = nullptr;
+ bool mEditMode = false;
+};
+#endif
diff --git a/kaddressbook/contacteditor/addresslocationeditorplugin.cpp b/kaddressbook/contacteditor/addresslocationeditorplugin.cpp
new file mode 100644
index 0000000..e94ff97
--- /dev/null
+++ b/kaddressbook/contacteditor/addresslocationeditorplugin.cpp
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2017 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "addresslocationeditorplugin.h"
+#include <kpluginfactory.h>
+
+#include <QHBoxLayout>
+
+K_PLUGIN_FACTORY_WITH_JSON(AddressLocationEditorFactory, "addresslocationeditorplugin.json", registerPlugin<AddressLocationEditor>();)
+
+AddressLocationEditor::AddressLocationEditor(QWidget *parent, const QList<QVariant> &)
+ : ContactEditor::AbstractAddressLocationWidget(parent)
+{
+}
+
+AddressLocationEditor::~AddressLocationEditor()
+{
+}
+
+void AddressLocationEditor::loadContact(const KContacts::Addressee &contact)
+{
+
+}
+
+void AddressLocationEditor::storeContact(KContacts::Addressee &contact) const
+{
+}
+
+void AddressLocationEditor::setReadOnly(bool readOnly)
+{
+}
+
+#include "addresslocationeditorplugin.moc"
diff --git a/kaddressbook/contacteditor/addresslocationeditorplugin.h b/kaddressbook/contacteditor/addresslocationeditorplugin.h
new file mode 100644
index 0000000..8b0934a
--- /dev/null
+++ b/kaddressbook/contacteditor/addresslocationeditorplugin.h
@@ -0,0 +1,41 @@
+/*
+ Copyright (C) 2017 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef ADDRESSLOCATIONEDITORPLUGIN_H
+#define ADDRESSLOCATIONEDITORPLUGIN_H
+
+#include <QWidget>
+#include <ContactEditor/AbstractAddressLocationWidget>
+class QLineEdit;
+class QToolButton;
+class AddressLocationEditor : public ContactEditor::AbstractAddressLocationWidget
+{
+ Q_OBJECT
+public:
+ explicit AddressLocationEditor(QWidget *parent = nullptr, const QList<QVariant> & =
+ {
+ });
+ ~AddressLocationEditor();
+
+ void loadContact(const KContacts::Addressee &contact) override;
+ void storeContact(KContacts::Addressee &contact) const override;
+ void setReadOnly(bool readOnly) override;
+};
+
+#endif // ADDRESSLOCATIONEDITORPLUGIN_H
diff --git a/kaddressbook/contacteditor/addresslocationeditorplugin.json b/kaddressbook/contacteditor/addresslocationeditorplugin.json
new file mode 100644
index 0000000..a2c2f0d
--- /dev/null
+++ b/kaddressbook/contacteditor/addresslocationeditorplugin.json
@@ -0,0 +1,10 @@
+{
+ "KPlugin": {
+ "Id": "addresslocationeditorplugin",
+ "Name": "RegexpEditorLineEdit",
+ "ServiceTypes": [
+ "ContactEditor/AddressLocationEditor"
+ ],
+ "Version": "1.0"
+ }
+}