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

Add support for readonly

parent 3554e5b4
......@@ -28,7 +28,8 @@
AddressesLocationGrantleeFormater::AddressesLocationGrantleeFormater(QObject *parent)
: QObject(parent),
mEngine(new Grantlee::Engine)
mEngine(new Grantlee::Engine),
mReadOnly(false)
{
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
mGrantleeThemePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
......@@ -54,12 +55,18 @@ QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Addr
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);
return contentHtml;
}
void AddressesLocationGrantleeFormater::setReadOnly(bool readOnly)
{
mReadOnly = readOnly;
}
void AddressesLocationGrantleeFormater::changeGrantleePath(const QString &path)
{
if (!mTemplateLoader) {
......
......@@ -40,6 +40,7 @@ public:
~AddressesLocationGrantleeFormater();
QString formatAddresses(const KContacts::Address::List &addresses);
void setReadOnly(bool readOnly);
private:
void changeGrantleePath(const QString &path);
Grantlee::Engine *mEngine;
......@@ -47,6 +48,7 @@ private:
QString mGrantleeThemePath;
QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
Grantlee::Template mSelfcontainedTemplate;
bool mReadOnly;
};
#endif // ADDRESSESLOCATIONGRANTLEEFORMATER_H
......@@ -45,9 +45,14 @@ AddressesLocationViewer::~AddressesLocationViewer()
}
void AddressesLocationViewer::setReadOnly(bool readOnly)
{
mAddressesLocationGrantleeFormatter->setReadOnly(readOnly);
updateView();
}
void AddressesLocationViewer::slotLinkClicked(const QUrl &url)
{
qDebug()<<" url "<<url;
if (url.scheme() == QLatin1String("addresslocationaction")) {
const QString urlPath(url.path());
if (url.hasQuery()) {
......
......@@ -37,6 +37,8 @@ public:
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);
......
......@@ -29,15 +29,15 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
: QSplitter(parent)
{
setChildrenCollapsible(false);
AddressLocationWidget *addressLocationWidget = new AddressLocationWidget(this);
addWidget(addressLocationWidget);
addressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
mAddressLocationWidget = new AddressLocationWidget(this);
addWidget(mAddressLocationWidget);
mAddressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
mAddressesLocationViewer = new AddressesLocationViewer(this);
mAddressesLocationViewer->setObjectName(QStringLiteral("addresseslocationviewer"));
addWidget(mAddressesLocationViewer);
connect(mAddressesLocationViewer, &AddressesLocationViewer::modifyAddress, addressLocationWidget, &AddressLocationWidget::slotModifyAddress);
connect(addressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationViewer::addAddress);
connect(mAddressesLocationViewer, &AddressesLocationViewer::modifyAddress, mAddressLocationWidget, &AddressLocationWidget::slotModifyAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressesLocationViewer, &AddressesLocationViewer::addAddress);
}
AddressesLocationWidget::~AddressesLocationWidget()
......@@ -54,3 +54,9 @@ void AddressesLocationWidget::setAddresses(const KContacts::Address::List &addre
{
mAddressesLocationViewer->setAddresses(addresses);
}
void AddressesLocationWidget::setReadOnly(bool readOnly)
{
mAddressesLocationViewer->setReadOnly(readOnly);
mAddressLocationWidget->setReadOnly(readOnly);
}
......@@ -27,6 +27,7 @@
#include <QSplitter>
#include <KContacts/Address>
class AddressesLocationViewer;
class AddressLocationWidget;
class AddressesLocationWidget : public QSplitter
{
Q_OBJECT
......@@ -37,8 +38,10 @@ public:
KContacts::Address::List addresses() const;
void setAddresses(const KContacts::Address::List &addresses);
void setReadOnly(bool readOnly);
private:
AddressesLocationViewer *mAddressesLocationViewer;
AddressLocationWidget *mAddressLocationWidget;
};
#endif // ADDRESSESLOCATIONWIDGET_H
......@@ -128,6 +128,19 @@ 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);
mAddAddress->setEnabled(!readOnly);
mTypeCombo->setEnabled(!readOnly);
}
void AddressLocationWidget::fillCountryCombo()
{
QStringList countries;
......
......@@ -44,6 +44,9 @@ public:
void slotModifyAddress(const KContacts::Address &address, int currentIndex);
void clear();
void setReadOnly(bool readOnly);
Q_SIGNALS:
void addNewAddress(const KContacts::Address &address);
......
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