Commit 1aa5e77e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Start to implement qwebengine support

parent 38f79318
......@@ -25,6 +25,13 @@ set(CALENDARCORE_VERSION "5.1.40")
set(KMIMELIB_VERSION "5.1.40")
set(AKONADI_VERSION "5.1.52")
option(QTWEBENGINE_EXPERIMENTAL_OPTION "Enable support for qtwebengine. False by default." FALSE)
if (QTWEBENGINE_EXPERIMENTAL_OPTION)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets)
endif()
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"
......
......@@ -53,6 +53,7 @@ set(akonadicontact_editor_generalinfo_phone_SRCS
editor/generalinfoeditor/phone/phonewidget.cpp
editor/generalinfoeditor/phone/phonelistwidget.cpp
editor/generalinfoeditor/phone/phonecomboboxtype.cpp
editor/generalinfoeditor/phone/phonetypedialog.cpp
)
set(akonadicontact_editor_generalinfo_web_SRCS
......@@ -85,9 +86,19 @@ set(akonadicontact_editor_generalinfo_SRCS
${akonadicontact_editor_generalinfo_mail_SRCS}
)
if (QTWEBENGINE_EXPERIMENTAL_OPTION)
set(akonadicontact_addresslocation_webengine_editor_SRCS
editor/addresseditor/webengine/addresseslocationengineviewer.cpp
)
set(akonadicontact_webengine_LIB Qt5::WebEngine Qt5::WebEngineWidgets)
endif()
set(akonadicontact_addresslocation_editor_SRCS
${akonadicontact_addresslocation_webengine_editor_SRCS}
editor/addresseditor/addresslocationwidget.cpp
editor/addresseditor/addresseslocationviewer.cpp
editor/addresseditor/webkit/addresseslocationviewer.cpp
editor/addresseditor/addresseslocationgrantleeformater.cpp
editor/addresseditor/addressgrantleeobject.cpp
editor/addresseditor/iconnamecache.cpp
......@@ -214,6 +225,7 @@ target_link_libraries(KF5AkonadiContact
KF5::XmlGui
Grantlee5::Templates
Qt5::WebKitWidgets
${akonadicontact_webengine_LIB}
)
if(KF5Prison_FOUND)
......
......@@ -22,7 +22,7 @@
#include "addresseslocationwidget.h"
#include "addresseslocationviewer.h"
#include "webkit/addresseslocationviewer.h"
#include "addresslocationwidget.h"
using namespace Akonadi;
......
set(addresseslocationviewer_SRCS addresseslocationviewertest.cpp ../addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp
set(addresseslocationviewer_SRCS addresseslocationviewertest.cpp ../webkit/addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp
../addressgrantleeobject.cpp ../iconnamecache.cpp)
add_executable(addresseslocationviewer ${addresseslocationviewer_SRCS})
add_test(addresseslocationviewer addresseslocationviewer)
......@@ -13,7 +13,7 @@ add_test(addresslocationwidget addresslocationwidget)
ecm_mark_as_test(addresslocationwidget)
target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::AkonadiContact KF5::Contacts KF5::I18n KF5::Completion)
set(addresseslocationwidget_SRCS addresseslocationwidgettest.cpp ../addresseslocationwidget.cpp ../addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp
set(addresseslocationwidget_SRCS addresseslocationwidgettest.cpp ../addresseslocationwidget.cpp ../webkit/addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp
../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp ../addresstypedialog.cpp)
add_executable(addresseslocationwidget ${addresseslocationwidget_SRCS})
add_test(addresseslocationwidget addresseslocationwidget)
......
......@@ -21,7 +21,7 @@
*/
#include "addresseslocationviewertest.h"
#include "../addresseslocationviewer.h"
#include "../webkit/addresseslocationviewer.h"
#include <QTest>
using namespace Akonadi;
AddressesLocationViewerTest::AddressesLocationViewerTest(QObject *parent)
......
......@@ -23,7 +23,7 @@
#include "addresseslocationwidgettest.h"
#include "../addresseslocationwidget.h"
#include <QTest>
#include <editor/addresseditor/addresseslocationviewer.h>
#include <editor/addresseditor/webkit/addresseslocationviewer.h>
#include <editor/addresseditor/addresslocationwidget.h>
using namespace Akonadi;
AddressesLocationWidgetTest::AddressesLocationWidgetTest(QObject *parent)
......
set(addresseditor_SRCS
main.cpp
../addresseslocationwidget.cpp
../addresseslocationviewer.cpp
../webkit/addresseslocationviewer.cpp
../addresseslocationgrantleeformater.cpp
../addressgrantleeobject.cpp
../iconnamecache.cpp
......
/*
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 "addresseslocationengineviewer.h"
#include "../addresseslocationgrantleeformater.h"
#include <KMessageBox>
#include <KLocalizedString>
#include <QUrlQuery>
#include <QWebEngineSettings>
#include <QDebug>
using namespace Akonadi;
AddressesLocationEngineViewer::AddressesLocationEngineViewer(QWidget *parent)
: QWebEngineView(parent),
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this))
{
setContextMenuPolicy(Qt::CustomContextMenu);
//TODO porting
//page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
//settings()->setAttribute(QWebEngineSettings::JavaEnabled, false);
//settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
//settings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true);
settings()->setAttribute(QWebEngineSettings::AutoLoadImages, true);
//TODO porting
//connect(this, &AddressesLocationEngineViewer::linkClicked, this, &AddressesLocationEngineViewer::slotLinkClicked);
}
AddressesLocationEngineViewer::~AddressesLocationEngineViewer()
{
}
void AddressesLocationEngineViewer::setReadOnly(bool readOnly)
{
mAddressesLocationGrantleeFormatter->setReadOnly(readOnly);
updateView();
}
void AddressesLocationEngineViewer::slotLinkClicked(const QUrl &url)
{
if (url.scheme() == QLatin1String("addresslocationaction")) {
const QString urlPath(url.path());
if (url.hasQuery()) {
const QUrlQuery urlQuery(url);
const int addressId = urlQuery.queryItemValue(QStringLiteral("id")).toInt();
if (urlPath == QStringLiteral("removeaddress")) {
removeAddress(addressId);
} else if (urlPath == QStringLiteral("editaddress")) {
editAddress(addressId);
} else {
qDebug() << "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()) {
// TODO disable allow to remove address in edit mode
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();
}
}
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();
}
/*
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 AddressesLocationEngineViewer_H
#define AddressesLocationEngineViewer_H
#include <QWebEngineView>
#include <KContacts/Address>
namespace Akonadi
{
class AddressesLocationGrantleeFormater;
class AddressesLocationEngineViewer : public QWebEngineView
{
Q_OBJECT
public:
explicit AddressesLocationEngineViewer(QWidget *parent = Q_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);
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;
};
}
#endif
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