Commit 344a776d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use QtWebEngine

parent 4104d0bf
......@@ -25,8 +25,6 @@ set(CALENDARCORE_VERSION "5.2.40")
set(KMIMELIB_VERSION "5.2.40")
set(AKONADI_VERSION "5.2.40")
option(QTWEBENGINE_SUPPORT_OPTION "Enable support for QtWebEngine. False by default." FALSE)
ecm_setup_version(${KDEPIMLIBS_VERSION} VARIABLE_PREFIX AKONADICONTACT
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/akonadi-contact_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiContactConfigVersion.cmake"
......@@ -34,12 +32,7 @@ ecm_setup_version(${KDEPIMLIBS_VERSION} VARIABLE_PREFIX AKONADICONTACT
)
set(QT_REQUIRED_VERSION "5.6.0")
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test)
if(QTWEBENGINE_SUPPORT_OPTION)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets)
else()
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebKitWidgets)
endif()
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test WebEngine WebEngineWidgets)
########### Find packages ###########
find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED)
......
......@@ -86,18 +86,11 @@ set(akonadicontact_editor_generalinfo_SRCS
${akonadicontact_editor_generalinfo_mail_SRCS}
)
if (QTWEBENGINE_SUPPORT_OPTION)
set(akonadicontact_addresslocation_web_editor_SRCS
editor/addresseditor/webengine/addresseslocationengineviewer.cpp
editor/addresseditor/webengine/addresseslocationenginepage.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
else()
set(akonadicontact_addresslocation_web_editor_SRCS
editor/addresseditor/webkit/addresseslocationviewer.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebKitWidgets)
endif()
set(akonadicontact_addresslocation_web_editor_SRCS
editor/addresseditor/webengine/addresseslocationengineviewer.cpp
editor/addresseditor/webengine/addresseslocationenginepage.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
......
#define AKONADI_CONTACT_LIB "${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_LIBDIR}"
#define AKONADI_CONTACT_PREFIX ""
#cmakedefine QTWEBENGINE_SUPPORT_OPTION 1
......@@ -21,11 +21,7 @@
*/
#include "addresseslocationwidget.h"
#ifdef QTWEBENGINE_SUPPORT_OPTION
#include "webengine/addresseslocationengineviewer.h"
#else
#include "webkit/addresseslocationviewer.h"
#endif
#include "addresslocationwidget.h"
using namespace Akonadi;
......@@ -36,7 +32,6 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
mAddressLocationWidget = new AddressLocationWidget(this);
addWidget(mAddressLocationWidget);
mAddressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
#ifdef QTWEBENGINE_SUPPORT_OPTION
mAddressesLocationViewer = new AddressesLocationEngineViewer(this);
mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
addWidget(mAddressesLocationViewer);
......@@ -44,15 +39,6 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::addAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::updateAddressCanceled, mAddressesLocationViewer, &AddressesLocationEngineViewer::updateAddressCanceled);
connect(mAddressLocationWidget, &AddressLocationWidget::updateAddress, mAddressesLocationViewer, &AddressesLocationEngineViewer::replaceAddress);
#else
mAddressesLocationViewer = new AddressesLocationViewer(this);
mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
addWidget(mAddressesLocationViewer);
connect(mAddressesLocationViewer, &AddressesLocationViewer::modifyAddress, mAddressLocationWidget, &AddressLocationWidget::slotModifyAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationViewer::addAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::updateAddress, mAddressesLocationViewer, &AddressesLocationViewer::replaceAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::updateAddressCanceled, mAddressesLocationViewer, &AddressesLocationViewer::updateAddressCanceled);
#endif
setSizes(QList<int>() << 400 << 300);
}
......
......@@ -29,11 +29,7 @@
namespace Akonadi
{
class AddressLocationWidget;
#ifdef QTWEBENGINE_SUPPORT_OPTION
class AddressesLocationEngineViewer;
#else
class AddressesLocationViewer;
#endif
class AddressesLocationWidget : public QSplitter
{
Q_OBJECT
......@@ -46,11 +42,7 @@ public:
void setReadOnly(bool readOnly);
private:
#ifdef QTWEBENGINE_SUPPORT_OPTION
AddressesLocationEngineViewer *mAddressesLocationViewer;
#else
AddressesLocationViewer *mAddressesLocationViewer;
#endif
AddressLocationWidget *mAddressLocationWidget;
};
}
......
include(ECMMarkAsTest)
if (QTWEBENGINE_SUPPORT_OPTION)
set(akonadicontact_addresslocation_web_editor_SRCS
../webengine/addresseslocationengineviewer.cpp
../webengine/addresseslocationenginepage.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
else()
set(akonadicontact_addresslocation_web_editor_SRCS
../webkit/addresseslocationviewer.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebKitWidgets)
endif()
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 akonadi_contact_debug.h IDENTIFIER AKONADICONTACT_LOG CATEGORY_NAME log_akonadi_contact)
......
......@@ -22,11 +22,7 @@
#include "addresseslocationviewertest.h"
#include "config-akonadi-contact.h"
#ifdef QTWEBENGINE_SUPPORT_OPTION
#include "../webengine/addresseslocationengineviewer.h"
#else
#include "../webkit/addresseslocationviewer.h"
#endif
#include <QTest>
using namespace Akonadi;
AddressesLocationViewerTest::AddressesLocationViewerTest(QObject *parent)
......@@ -42,11 +38,7 @@ AddressesLocationViewerTest::~AddressesLocationViewerTest()
void AddressesLocationViewerTest::shouldHaveDefaultValue()
{
#ifdef QTWEBENGINE_SUPPORT_OPTION
AddressesLocationEngineViewer w;
#else
AddressesLocationViewer w;
#endif
QVERIFY(w.addresses().isEmpty());
}
......
......@@ -22,11 +22,7 @@
#include "addresseslocationwidgettest.h"
#include "config-akonadi-contact.h"
#ifdef QTWEBENGINE_SUPPORT_OPTION
#include "../webengine/addresseslocationengineviewer.h"
#else
#include "../webkit/addresseslocationviewer.h"
#endif
#include "../addresseslocationwidget.h"
#include <QTest>
......@@ -50,14 +46,8 @@ void AddressesLocationWidgetTest::shouldHaveDefaultValue()
AddressLocationWidget *addressLocationWidget = w.findChild<AddressLocationWidget *>(QStringLiteral("addresslocationwidget"));
QVERIFY(addressLocationWidget);
#ifdef QTWEBENGINE_SUPPORT_OPTION
AddressesLocationEngineViewer *addressesLocationViewer = w.findChild<AddressesLocationEngineViewer *>(QStringLiteral("addresseslocationviewer"));
QVERIFY(addressesLocationViewer);
#else
AddressesLocationViewer *addressesLocationViewer = w.findChild<AddressesLocationViewer *>(QStringLiteral("addresseslocationviewer"));
QVERIFY(addressesLocationViewer);
#endif
}
QTEST_MAIN(AddressesLocationWidgetTest)
if (QTWEBENGINE_SUPPORT_OPTION)
set(akonadicontact_addresslocation_web_editor_SRCS
../webengine/addresseslocationengineviewer.cpp
../webengine/addresseslocationenginepage.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
else()
set(akonadicontact_addresslocation_web_editor_SRCS
../webkit/addresseslocationviewer.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebKitWidgets)
endif()
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 akonadi_contact_debug.h IDENTIFIER AKONADICONTACT_LOG CATEGORY_NAME log_akonadi_contact)
......
/*
This file is part of Akonadi Contact.
Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
Copyright (C) 2016 Laurent Montel <laurent.montel@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "addresseslocationviewer.h"
#include "../addresseslocationgrantleeformater.h"
#include <KMessageBox>
#include <KLocalizedString>
#include <QUrlQuery>
#include <QWebSettings>
#include <QDebug>
using namespace Akonadi;
AddressesLocationViewer::AddressesLocationViewer(QWidget *parent)
: QWebView(parent),
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this)),
mEditMode(false)
{
setContextMenuPolicy(Qt::CustomContextMenu);
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
settings()->setAttribute(QWebSettings::JavaEnabled, false);
settings()->setAttribute(QWebSettings::PluginsEnabled, false);
settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
connect(this, &AddressesLocationViewer::linkClicked, this, &AddressesLocationViewer::slotLinkClicked);
}
AddressesLocationViewer::~AddressesLocationViewer()
{
}
void AddressesLocationViewer::setReadOnly(bool readOnly)
{
mAddressesLocationGrantleeFormatter->setReadOnly(readOnly);
updateView();
}
void AddressesLocationViewer::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 {
qDebug() << "Unknown url" << url;
}
}
}
}
void AddressesLocationViewer::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 AddressesLocationViewer::editAddress(int index)
{
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
mEditMode = true;
Q_EMIT modifyAddress(mAddresses.at(index), index);
}
}
void AddressesLocationViewer::replaceAddress(const KContacts::Address &address, int index)
{
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
mAddresses[index] = address;
updateView();
}
mEditMode = false;
}
void AddressesLocationViewer::updateAddressCanceled()
{
mEditMode = false;
}
void AddressesLocationViewer::updateView()
{
const QString html = mAddressesLocationGrantleeFormatter->formatAddresses(mAddresses);
setHtml(html, QUrl(QStringLiteral("file://")));
}
void AddressesLocationViewer::addAddress(const KContacts::Address &address)
{
if (!address.isEmpty()) {
mAddresses.append(address);
updateView();
}
}
KContacts::Address::List AddressesLocationViewer::addresses() const
{
return mAddresses;
}
void AddressesLocationViewer::setAddresses(const KContacts::Address::List &addresses)
{
mAddresses = addresses;
updateView();
}
/*
This file is part of Akonadi Contact.
Copyright (C) 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
Copyright (C) 2016 Laurent Montel <laurent.montel@kdab.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef ADDRESSESLOCATIONVIEWER_H
#define ADDRESSESLOCATIONVIEWER_H
#include <QWebView>
#include <KContacts/Address>
namespace Akonadi
{
class AddressesLocationGrantleeFormater;
class AddressesLocationViewer : public QWebView
{
Q_OBJECT
public:
explicit AddressesLocationViewer(QWidget *parent = Q_NULLPTR);
~AddressesLocationViewer();
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;
bool mEditMode;
};
}
#endif // ADDRESSESLOCATIONVIEWER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment