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

Improve features

parent 89775a88
......@@ -69,6 +69,7 @@ void AddressesLocationViewer::removeAddress(int index)
if (index < 0) {
return;
} else if (index < mAddresses.count()) {
//TODO add KMessageBox here.
mAddresses.remove(index);
updateView();
}
......
......@@ -28,6 +28,7 @@
AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
: QSplitter(parent)
{
setChildrenCollapsible(false);
AddressLocationWidget *addressLocationWidget = new AddressLocationWidget(this);
addWidget(addressLocationWidget);
addressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
......
......@@ -61,6 +61,17 @@ QString AddressGrantleeObject::createActionUrl(const QString &actionName) const
return url.toDisplayString();
}
QString AddressGrantleeObject::preferredAddressAction() const
{
QString text;
if (preferredAddress()) {
const QString iconPath = IconNameCache::instance()->iconPath(QStringLiteral("bookmarks"), KIconLoader::Small);
text = QStringLiteral("<img class=\"headimage\" title=\"%1\" src=\"file:///%2\"></a>\n")
.arg(i18n("Remove Address"), iconPath );
}
return text;
}
QString AddressGrantleeObject::removeAddressAction() const
{
const QString iconPath = IconNameCache::instance()->iconPath(QStringLiteral("edit-delete"), KIconLoader::Small);
......
......@@ -31,6 +31,7 @@ class AddressGrantleeObject : public QObject
Q_PROPERTY(QString removeAddressAction READ removeAddressAction)
Q_PROPERTY(QString modifyAddressAction READ modifyAddressAction)
Q_PROPERTY(QString formattedAddress READ formattedAddress)
Q_PROPERTY(QString preferredAddressAction READ preferredAddressAction)
Q_PROPERTY(QString type READ type)
Q_PROPERTY(bool preferredAddress READ preferredAddress)
public:
......@@ -42,6 +43,7 @@ public:
QString formattedAddress() const;
QString type() const;
bool preferredAddress() const;
QString preferredAddressAction() const;
private:
QString createActionUrl(const QString &actionName) const;
KContacts::Address mAddress;
......
......@@ -34,6 +34,13 @@
#include <QPushButton>
#include <QDebug>
struct LocaleAwareLessThan : std::binary_function<QString, QString, bool> {
bool operator()(const QString &s1, const QString &s2) const
{
return QString::localeAwareCompare(s1, s2) < 0;
}
};
AddressLocationWidget::AddressLocationWidget(QWidget *parent)
: QWidget(parent)
{
......@@ -113,6 +120,7 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent)
connect(mAddAddress, &QPushButton::clicked, this, &AddressLocationWidget::slotAddAddress);
topLayout->addWidget(mAddAddress, 8, 0);
topLayout->setRowStretch(9, 1);
fillCountryCombo();
}
AddressLocationWidget::~AddressLocationWidget()
......@@ -120,6 +128,31 @@ AddressLocationWidget::~AddressLocationWidget()
}
void AddressLocationWidget::fillCountryCombo()
{
QStringList countries;
const QList<QLocale> localeList = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
countries.reserve(localeList.count());
foreach (const QLocale &locale, localeList) {
const QString localeStr = QLocale::countryToString(locale.country());
if (countries.contains(localeStr)) {
continue;
}
countries.append(localeStr);
}
qSort(countries.begin(), countries.end(), LocaleAwareLessThan());
mCountryCombo->addItems(countries);
mCountryCombo->setAutoCompletion(true);
mCountryCombo->completionObject()->setItems(countries);
mCountryCombo->completionObject()->setIgnoreCase(true);
const QString currentCountry = QLocale::countryToString(QLocale().country());
mCountryCombo->setCurrentIndex(mCountryCombo->findText(currentCountry));
}
void AddressLocationWidget::slotAddAddress()
{
KContacts::Address addr = address();
......@@ -139,15 +172,12 @@ void AddressLocationWidget::setAddress(const KContacts::Address &address)
mPostalCodeEdit->setText(address.postalCode());
mPOBoxEdit->setText(address.postOfficeBox());
mPreferredCheckBox->setChecked(address.type() &KContacts::Address::Pref);
#if 0
if (address.isEmpty()) {
mCountryCombo->setItemText(mCountryCombo->currentIndex(),
QLocale::countryToString(QLocale().country()));
} else {
mCountryCombo->setItemText(mCountryCombo->currentIndex(), mAddress.country());
}
#endif
//TODO
}
KContacts::Address AddressLocationWidget::address() const
......
......@@ -51,6 +51,7 @@ private Q_SLOTS:
void slotAddAddress();
private:
void fillCountryCombo();
KContacts::Address mAddress;
QCheckBox *mPreferredCheckBox;
KLineEdit *mPOBoxEdit;
......
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