diff --git a/kaddressbook/CMakeLists.txt b/kaddressbook/CMakeLists.txt --- a/kaddressbook/CMakeLists.txt +++ b/kaddressbook/CMakeLists.txt @@ -1,4 +1,3 @@ add_subdirectory( editorpages ) add_subdirectory( plugins ) add_subdirectory( importexportplugins ) -add_subdirectory( contacteditor ) diff --git a/kaddressbook/contacteditor/CMakeLists.txt b/kaddressbook/contacteditor/CMakeLists.txt deleted file mode 100644 --- a/kaddressbook/contacteditor/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 --- a/kaddressbook/contacteditor/Messages.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /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.h b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -#include -#include -#include -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 mTemplateLoader; - Grantlee::Template mSelfcontainedTemplate; - bool mReadOnly; -}; -#endif // ADDRESSESLOCATIONGRANTLEEFORMATER_H diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp b/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresseslocationgrantleeformater.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include - -AddressesLocationGrantleeFormater::AddressesLocationGrantleeFormater(QObject *parent) - : QObject(parent) - , mEngine(new Grantlee::Engine) - , mReadOnly(false) -{ - mTemplateLoader = QSharedPointer(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 lstAddress; - lstAddress.reserve(nbAddress); - for (int i = 0; i < nbAddress; ++i) { - AddressGrantleeObject *addressObj = new AddressGrantleeObject(addresses.at(i), i); - addressList << QVariant::fromValue(static_cast(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(new Grantlee::FileSystemTemplateLoader); - } - mTemplateLoader->setTemplateDirs(QStringList() << path); - mEngine->addTemplateLoader(mTemplateLoader); - - mSelfcontainedTemplate = mEngine->loadByName(QStringLiteral("addresseslocation.html")); - if (mSelfcontainedTemplate->error()) { - mErrorMessage += mSelfcontainedTemplate->errorString() + QLatin1String("
"); - } -} diff --git a/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -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/addresseslocationwidget.cpp b/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresseslocationwidget.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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() << 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/addressgrantleeobject.h b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include - -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/addressgrantleeobject.cpp b/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addressgrantleeobject.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include - -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("\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("\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("\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/addresslocationwidget.h b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresslocationwidget.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -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/addresslocationwidget.cpp b/kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresslocationwidget.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include - -#include -#include -#include -#include -#include -struct LocaleAwareLessThan : std::binary_function { - 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->setContentsMargins(0, 0, 0, 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->setContentsMargins(0, 0, 0, 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 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/addresstypedialog.h b/kaddressbook/contacteditor/addresseditor/addresstypedialog.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresstypedialog.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (c) 2009 Tobias Koenig - - 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 -#include -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/addresstypedialog.cpp b/kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/addresstypedialog.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (c) 2009 Tobias Koenig - - 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 -#include -#include -#include -#include -#include -#include - -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->setContentsMargins(0, 0, 0, 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(mGroup->buttons().at(i)); - if (box && box->isChecked()) { - type |= mTypeList[i]; - } - } - - return type; -} diff --git a/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -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 addresslocationeditorplugin_debug.h IDENTIFIER - ADDRESSLOCATIONEDITORPLUGIN_LOG CATEGORY_NAME org.kde.pim.addresslocationeditorplugin) - -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.h b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -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/addresseslocationviewertest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationviewertest.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 "../webengine/addresseslocationengineviewer.h" -#include -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/addresseslocationwidgettest.h b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -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/addresseslocationwidgettest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresseslocationwidgettest.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 "../webengine/addresseslocationengineviewer.h" - -#include "../addresseslocationwidget.h" -#include "../addresslocationwidget.h" -#include - -AddressesLocationWidgetTest::AddressesLocationWidgetTest(QObject *parent) - : QObject(parent) -{ -} - -AddressesLocationWidgetTest::~AddressesLocationWidgetTest() -{ -} - -void AddressesLocationWidgetTest::shouldHaveDefaultValue() -{ - AddressesLocationWidget w; - AddressLocationWidget *addressLocationWidget = w.findChild(QStringLiteral("addresslocationwidget")); - QVERIFY(addressLocationWidget); - - AddressesLocationEngineViewer *addressesLocationViewer = w.findChild(QStringLiteral("addresseslocationviewer")); - QVERIFY(addressesLocationViewer); -} - -QTEST_MAIN(AddressesLocationWidgetTest) diff --git a/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -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/autotests/addresslocationwidgettest.cpp b/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/autotests/addresslocationwidgettest.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include -#include -#include -#include -#include "../selectaddresstypecombobox.h" -AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent) - : QObject(parent) -{ -} - -AddressLocationWidgetTest::~AddressLocationWidgetTest() -{ -} - -void AddressLocationWidgetTest::shouldHaveDefaultValue() -{ - AddressLocationWidget w; - - SelectAddressTypeComboBox *typeAddress = w.findChild(QStringLiteral("typeaddress")); - QVERIFY(typeAddress); - - QLabel *streetlabel = w.findChild(QStringLiteral("streetlabel")); - QVERIFY(streetlabel); - KLineEdit *mStreetEdit = w.findChild(QStringLiteral("streetlineedit")); - QVERIFY(mStreetEdit); - - QLabel *postofficeboxlabel = w.findChild(QStringLiteral("postofficeboxlabel")); - QVERIFY(postofficeboxlabel); - KLineEdit *postofficeboxlineedit = w.findChild(QStringLiteral("postofficeboxlineedit")); - QVERIFY(postofficeboxlineedit); - - QLabel *localitylabel = w.findChild(QStringLiteral("localitylabel")); - QVERIFY(localitylabel); - KLineEdit *localitylineedit = w.findChild(QStringLiteral("localitylineedit")); - QVERIFY(localitylineedit); - - QLabel *regionlabel = w.findChild(QStringLiteral("regionlabel")); - QVERIFY(regionlabel); - KLineEdit *regionlineedit = w.findChild(QStringLiteral("regionlineedit")); - QVERIFY(regionlineedit); - - QLabel *postalcodelabel = w.findChild(QStringLiteral("postalcodelabel")); - QVERIFY(postalcodelabel); - KLineEdit *postalcodelineedit = w.findChild(QStringLiteral("postalcodelineedit")); - QVERIFY(postalcodelineedit); - - QLabel *countrylabel = w.findChild(QStringLiteral("countrylabel")); - QVERIFY(countrylabel); - KComboBox *countrycombobox = w.findChild(QStringLiteral("countrycombobox")); - QVERIFY(countrycombobox); - - QCheckBox *preferredcheckbox = w.findChild(QStringLiteral("preferredcheckbox")); - QVERIFY(preferredcheckbox); - - QPushButton *addbuttonaddress = w.findChild(QStringLiteral("addbuttonaddress")); - QVERIFY(addbuttonaddress); - - QPushButton *modifybuttonaddress = w.findChild(QStringLiteral("modifybuttonaddress")); - QVERIFY(modifybuttonaddress); - - QPushButton *cancelbuttonaddress = w.findChild(QStringLiteral("cancelbuttonaddress")); - QVERIFY(cancelbuttonaddress); -} - -void AddressLocationWidgetTest::shouldChangeReadOnlyStatus() -{ - AddressLocationWidget w; - - w.setReadOnly(true); - SelectAddressTypeComboBox *typeAddress = w.findChild(QStringLiteral("typeaddress")); - QCOMPARE(typeAddress->isEnabled(), false); - KLineEdit *mStreetEdit = w.findChild(QStringLiteral("streetlineedit")); - QCOMPARE(mStreetEdit->isReadOnly(), true); - KLineEdit *postofficeboxlineedit = w.findChild(QStringLiteral("postofficeboxlineedit")); - QCOMPARE(postofficeboxlineedit->isReadOnly(), true); - KLineEdit *localitylineedit = w.findChild(QStringLiteral("localitylineedit")); - QCOMPARE(localitylineedit->isReadOnly(), true); - KLineEdit *regionlineedit = w.findChild(QStringLiteral("regionlineedit")); - QCOMPARE(regionlineedit->isReadOnly(), true); - KLineEdit *postalcodelineedit = w.findChild(QStringLiteral("postalcodelineedit")); - QCOMPARE(postalcodelineedit->isReadOnly(), true); - KComboBox *countrycombobox = w.findChild(QStringLiteral("countrycombobox")); - QCOMPARE(countrycombobox->isEnabled(), false); - QCheckBox *preferredcheckbox = w.findChild(QStringLiteral("preferredcheckbox")); - QCOMPARE(preferredcheckbox->isEnabled(), false); - QPushButton *addbuttonaddress = w.findChild(QStringLiteral("addbuttonaddress")); - QCOMPARE(addbuttonaddress->isEnabled(), false); - QPushButton *modifybuttonaddress = w.findChild(QStringLiteral("modifybuttonaddress")); - QCOMPARE(modifybuttonaddress->isEnabled(), false); - QPushButton *cancelbuttonaddress = w.findChild(QStringLiteral("cancelbuttonaddress")); - QCOMPARE(cancelbuttonaddress->isEnabled(), false); -} - -QTEST_MAIN(AddressLocationWidgetTest) diff --git a/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/html/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -install(DIRECTORY default DESTINATION ${KDE_INSTALL_DATADIR}/contacteditor/grantleetheme ) diff --git a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.html +++ /dev/null @@ -1,29 +0,0 @@ - - - -. - - - -{% if addresses %} -{% for address in addresses %} -
-
{{ address.addressType }}
-
- {% if readOnly %} - {% else %} - {{ address.modifyAddressAction|safe}} {{ address.removeAddressAction|safe}} - {% endif %} -
- -
-
{{ address.formattedAddress }}
- -
-
-
-{% endfor %} -{% endif %} - - - diff --git a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css b/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/html/default/addresseslocation.css +++ /dev/null @@ -1,16 +0,0 @@ -#headeraddress { -} - -#addresstype { - float: left; - color: #0000FF; -} - -#actiontype { - float: right; - text-align: right; -} - -#address { - float: left; -} diff --git a/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp b/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/iconnamecache.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2009 Thomas McGuire - - 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 -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 deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/iconnamecache_p.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2009 Thomas McGuire - - 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 -#include -/** - * 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 mCachedEntries; -}; -#endif diff --git a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include - -/** - * @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 mTypeList; -}; -#endif diff --git a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp b/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/selectaddresstypecombobox.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -#include - -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(&KComboBox::activated), this, &SelectAddressTypeComboBox::selected); -} - -SelectAddressTypeComboBox::~SelectAddressTypeComboBox() -{ -} - -void SelectAddressTypeComboBox::setType(KContacts::Address::Type type) -{ - if (!mTypeList.contains(static_cast(type))) { - // insert at the end, but before the 'Others...' entry - mTypeList.insert(mTypeList.at(mTypeList.count() - 1), static_cast(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 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/tests/CMakeLists.txt b/kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/tests/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -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 addresslocationeditorplugin_debug.h IDENTIFIER - ADDRESSLOCATIONEDITORPLUGIN_LOG CATEGORY_NAME org.kde.pim.addresslocationeditorplugin) - -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 deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/tests/main.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com - Copyright (C) 2016-2019 Laurent Montel - - 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 - -#include "../addresseslocationwidget.h" -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.h b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016-2019 Laurent Montel - - 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 - -class AddressesLocationEnginePage : public QWebEnginePage -{ - Q_OBJECT -public: - explicit AddressesLocationEnginePage(QObject *parent = nullptr); - ~AddressesLocationEnginePage() override; - -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/addresseslocationenginepage.cpp b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationenginepage.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include -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); - -// FreeBSD actually ships QtWebengine 5.9 with Qt 5.10/5.11, so these enums do not exist there -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) && !defined(Q_OS_FREEBSD) - settings()->setAttribute(QWebEngineSettings::ShowScrollBars, true); - settings()->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, false); -#endif -#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) && !defined(Q_OS_FREEBSD) - settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false); - settings()->setAttribute(QWebEngineSettings::JavascriptCanPaste, false); - settings()->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, false); -#endif -#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 13, 0) - settings()->setAttribute(QWebEngineSettings::PdfViewerEnabled, false); -#endif - - profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); -} - -AddressesLocationEnginePage::~AddressesLocationEnginePage() -{ -} - -bool AddressesLocationEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) -{ - Q_UNUSED(type); - Q_UNUSED(isMainFrame); - if (url.scheme() == QLatin1String("data")) { - return true; - } - - Q_EMIT urlClicked(url); - return false; -} diff --git a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -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/addresseditor/webengine/addresseslocationengineviewer.cpp b/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresseditor/webengine/addresseslocationengineviewer.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - This file is part of Contact Editor. - - Copyright (C) 2016-2019 Laurent Montel - - 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 -#include -#include - -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 == QLatin1String("removeaddress")) { - if (!mEditMode) { - removeAddress(addressId); - } - } else if (urlPath == QLatin1String("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/addresslocationeditorplugin.h b/kaddressbook/contacteditor/addresslocationeditorplugin.h deleted file mode 100644 --- a/kaddressbook/contacteditor/addresslocationeditorplugin.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2017-2019 Montel Laurent - - 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 -class AddressesLocationWidget; -class AddressLocationEditor : public ContactEditor::AbstractAddressLocationWidget -{ - Q_OBJECT -public: - explicit AddressLocationEditor(QWidget *parent = nullptr, const QList & = - { - }); - ~AddressLocationEditor() override; - - void loadContact(const KContacts::Addressee &contact) override; - void storeContact(KContacts::Addressee &contact) const override; - void setReadOnly(bool readOnly) override; -private: - AddressesLocationWidget *mAddressesLocationWidget = nullptr; -}; - -#endif // ADDRESSLOCATIONEDITORPLUGIN_H diff --git a/kaddressbook/contacteditor/addresslocationeditorplugin.cpp b/kaddressbook/contacteditor/addresslocationeditorplugin.cpp deleted file mode 100644 --- a/kaddressbook/contacteditor/addresslocationeditorplugin.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (C) 2017-2019 Montel Laurent - - 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 - -#include "addresseditor/addresseslocationwidget.h" - -#include - -K_PLUGIN_CLASS_WITH_JSON(AddressLocationEditor, "addresslocationeditorplugin.json") - -AddressLocationEditor::AddressLocationEditor(QWidget *parent, const QList &) - : ContactEditor::AbstractAddressLocationWidget(parent) -{ - QHBoxLayout *mainLayout = new QHBoxLayout(this); - mainLayout->setObjectName(QStringLiteral("mainlayout")); - mainLayout->setContentsMargins(0, 0, 0, 0); - mAddressesLocationWidget = new AddressesLocationWidget(this); - mAddressesLocationWidget->setObjectName(QStringLiteral("addresseslocationwidget")); - mainLayout->addWidget(mAddressesLocationWidget); -} - -AddressLocationEditor::~AddressLocationEditor() -{ -} - -void AddressLocationEditor::loadContact(const KContacts::Addressee &contact) -{ - mAddressesLocationWidget->loadContact(contact); -} - -void AddressLocationEditor::storeContact(KContacts::Addressee &contact) const -{ - mAddressesLocationWidget->storeContact(contact); -} - -void AddressLocationEditor::setReadOnly(bool readOnly) -{ - mAddressesLocationWidget->setReadOnly(readOnly); -} - -#include "addresslocationeditorplugin.moc" diff --git a/kaddressbook/contacteditor/addresslocationeditorplugin.json b/kaddressbook/contacteditor/addresslocationeditorplugin.json deleted file mode 100644 --- a/kaddressbook/contacteditor/addresslocationeditorplugin.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "KPlugin": { - "Id": "addresslocationeditorplugin", - "Name": "Contact Address Location Editor", - "Name[ca]": "Editor per a la ubicació de l'adreça del contacte", - "Name[cs]": "Editor kontaktních adres", - "Name[en_GB]": "Contact Address Location Editor", - "Name[es]": "Editor de ubicación de direcciones de contacto", - "Name[fr]": "Éditeur d'emplacement de l'adresse du contact", - "Name[gl]": "Editor de enderezos físicos de contactos", - "Name[it]": "Editor per gli indirizzi dei contatti", - "Name[nl]": "Bewerker van locatie-adres van contactpersoon", - "Name[pl]": "Edytor adresu kontaktu", - "Name[pt]": "Editor da Localização do Endereço do Contacto", - "Name[pt_BR]": "Editor da localização do endereço do contato", - "Name[sv]": "Editor för kontaktadressplats", - "Name[uk]": "Редактор адреси контакту", - "Name[x-test]": "xxContact Address Location Editorxx", - "ServiceTypes": [ - "ContactEditor/AddressLocationEditor" - ], - "Version": "1.0" - } -}