Commit aac8bb0e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve it

parent c1f017ce
...@@ -22,7 +22,10 @@ ...@@ -22,7 +22,10 @@
#include "addresseslocationviewer.h" #include "addresseslocationviewer.h"
#include "addresseslocationgrantleeformater.h" #include "addresseslocationgrantleeformater.h"
#include <QUrlQuery>
#include <QWebSettings> #include <QWebSettings>
#include <QDebug>
AddressesLocationViewer::AddressesLocationViewer(QWidget *parent) AddressesLocationViewer::AddressesLocationViewer(QWidget *parent)
: QWebView(parent), : QWebView(parent),
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this)) mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this))
...@@ -43,14 +46,46 @@ AddressesLocationViewer::~AddressesLocationViewer() ...@@ -43,14 +46,46 @@ AddressesLocationViewer::~AddressesLocationViewer()
void AddressesLocationViewer::slotLinkClicked(const QUrl &url) 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")) {
removeAddress(addressId);
} else if (urlPath == QStringLiteral("editaddress")) {
editAddress(addressId);
} else {
qDebug() << "Unknown url" << url;
}
}
}
}
void AddressesLocationViewer::removeAddress(int index)
{
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
mAddresses.remove(index);
updateView();
}
}
void AddressesLocationViewer::editAddress(int index)
{
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
//TODO remove it from list ?
editAddress(mAddresses.at(index));
}
} }
void AddressesLocationViewer::updateView() void AddressesLocationViewer::updateView()
{ {
const QString html = mAddressesLocationGrantleeFormatter->formatAddresses(mAddresses); const QString html = mAddressesLocationGrantleeFormatter->formatAddresses(mAddresses);
//TODO setHtml(html, QUrl(QStringLiteral("file://")));
//TODO
} }
void AddressesLocationViewer::addAddress(const KContacts::Address &address) void AddressesLocationViewer::addAddress(const KContacts::Address &address)
......
...@@ -43,8 +43,13 @@ public: ...@@ -43,8 +43,13 @@ public:
private Q_SLOTS: private Q_SLOTS:
void slotLinkClicked(const QUrl &url); void slotLinkClicked(const QUrl &url);
Q_SIGNALS:
void editAddress(const KContacts::Address &address);
private: private:
void updateView(); void updateView();
void editAddress(int index);
void removeAddress(int index);
KContacts::Address::List mAddresses; KContacts::Address::List mAddresses;
AddressesLocationGrantleeFormater *mAddressesLocationGrantleeFormatter; AddressesLocationGrantleeFormater *mAddressesLocationGrantleeFormatter;
}; };
......
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