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

Don't remove/edit new address when we are in edit mode

parent 0ae1432c
......@@ -42,6 +42,7 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
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);
#else
mAddressesLocationViewer = new AddressesLocationViewer(this);
......@@ -50,6 +51,7 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
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);
}
......
......@@ -119,7 +119,6 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent)
mPreferredCheckBox = new QCheckBox(i18nc("street/postal", "This is the preferred address"), this);
mPreferredCheckBox->setObjectName(QStringLiteral("preferredcheckbox"));
gridLayout->addWidget(mPreferredCheckBox, 7, 0, 1, 2);
//TODO fix column size
mButtonStack = new QStackedWidget(this);
mButtonStack->setObjectName(QStringLiteral("buttonstacked"));
......@@ -284,6 +283,7 @@ void AddressLocationWidget::slotUpdateAddress()
void AddressLocationWidget::reset()
{
Q_EMIT updateAddressCanceled();
mCurrentAddress = -1;
clear();
}
......
......@@ -57,6 +57,7 @@ public:
Q_SIGNALS:
void addNewAddress(const KContacts::Address &address);
void updateAddress(const KContacts::Address &address, int index);
void updateAddressCanceled();
private Q_SLOTS:
void slotAddAddress();
......
......@@ -32,7 +32,8 @@ using namespace Akonadi;
AddressesLocationEngineViewer::AddressesLocationEngineViewer(QWidget *parent)
: QWebEngineView(parent),
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this))
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this)),
mEditMode(false)
{
AddressesLocationEnginePage *pageEngine = new AddressesLocationEnginePage(this);
......@@ -63,9 +64,13 @@ void AddressesLocationEngineViewer::slotLinkClicked(const QUrl &url)
const QUrlQuery urlQuery(url);
const int addressId = urlQuery.queryItemValue(QStringLiteral("id")).toInt();
if (urlPath == QStringLiteral("removeaddress")) {
removeAddress(addressId);
if (!mEditMode) {
removeAddress(addressId);
}
} else if (urlPath == QStringLiteral("editaddress")) {
editAddress(addressId);
if (!mEditMode) {
editAddress(addressId);
}
} else {
qDebug() << "Unknown url" << url;
}
......@@ -93,7 +98,7 @@ void AddressesLocationEngineViewer::editAddress(int index)
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
// TODO disable allow to remove address in edit mode
mEditMode = true;
Q_EMIT modifyAddress(mAddresses.at(index), index);
}
}
......@@ -106,6 +111,12 @@ void AddressesLocationEngineViewer::replaceAddress(const KContacts::Address &add
mAddresses[index] = address;
updateView();
}
mEditMode = false;
}
void AddressesLocationEngineViewer::updateAddressCanceled()
{
mEditMode = false;
}
void AddressesLocationEngineViewer::updateView()
......
......@@ -41,6 +41,7 @@ public:
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);
......@@ -54,6 +55,7 @@ private:
void removeAddress(int index);
KContacts::Address::List mAddresses;
AddressesLocationGrantleeFormater *mAddressesLocationGrantleeFormatter;
bool mEditMode;
};
}
#endif
......@@ -32,7 +32,8 @@ using namespace Akonadi;
AddressesLocationViewer::AddressesLocationViewer(QWidget *parent)
: QWebView(parent),
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this))
mAddressesLocationGrantleeFormatter(new AddressesLocationGrantleeFormater(this)),
mEditMode(false)
{
setContextMenuPolicy(Qt::CustomContextMenu);
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
......@@ -63,9 +64,13 @@ void AddressesLocationViewer::slotLinkClicked(const QUrl &url)
const QUrlQuery urlQuery(url);
const int addressId = urlQuery.queryItemValue(QStringLiteral("id")).toInt();
if (urlPath == QStringLiteral("removeaddress")) {
removeAddress(addressId);
if (!mEditMode) {
removeAddress(addressId);
}
} else if (urlPath == QStringLiteral("editaddress")) {
editAddress(addressId);
if (!mEditMode) {
editAddress(addressId);
}
} else {
qDebug() << "Unknown url" << url;
}
......@@ -93,7 +98,7 @@ void AddressesLocationViewer::editAddress(int index)
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
// TODO disable allow to remove address in edit mode
mEditMode = true;
Q_EMIT modifyAddress(mAddresses.at(index), index);
}
}
......@@ -106,6 +111,12 @@ void AddressesLocationViewer::replaceAddress(const KContacts::Address &address,
mAddresses[index] = address;
updateView();
}
mEditMode = false;
}
void AddressesLocationViewer::updateAddressCanceled()
{
mEditMode = false;
}
void AddressesLocationViewer::updateView()
......
......@@ -42,6 +42,8 @@ public:
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);
......@@ -55,6 +57,7 @@ private:
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