Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit d09d0b46 authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 342469 - X-Attributes got lost

FIXED-IN: 14.12.2
BUG: 342469
parent ff08e5f9
......@@ -19,6 +19,7 @@
#include "emaileditdialogtest.h"
#include "../emaileditwidget.h"
#include "kabc/email.h"
#include <qtest_kde.h>
#include <KListWidget>
#include <qpushbutton.h>
......@@ -54,7 +55,10 @@ void EmailEditDialogTest::shouldAddItems()
{
EmailEditDialog dlg;
KListWidget *listwidget = qFindChild<KListWidget *>(&dlg, QLatin1String("emailListBox"));
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli");
KABC::Email::List lst;
lst << KABC::Email(QLatin1String("foo"));
lst << KABC::Email(QLatin1String("bla"));
lst << KABC::Email(QLatin1String("bli"));
dlg.setEmailList(lst);
QCOMPARE(listwidget->count(), lst.count());
}
......@@ -63,7 +67,11 @@ void EmailEditDialogTest::shouldDontAddTwiceItem()
{
EmailEditDialog dlg;
KListWidget *listwidget = qFindChild<KListWidget *>(&dlg, QLatin1String("emailListBox"));
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli") << QLatin1String("bli");
KABC::Email::List lst;
lst << KABC::Email(QLatin1String("foo"));
lst << KABC::Email(QLatin1String("bla"));
lst << KABC::Email(QLatin1String("bli"));
lst << KABC::Email(QLatin1String("bli"));
dlg.setEmailList(lst);
QCOMPARE(listwidget->count(), (lst.count()-1));
}
......
......@@ -73,6 +73,16 @@ public:
format();
}
void setEmail(const KABC::Email &email)
{
mEmail = email;
}
KABC::Email email() const
{
return mEmail;
}
void setPreferred(bool preferred)
{
mPreferred = preferred;
......@@ -92,6 +102,7 @@ private:
}
private:
KABC::Email mEmail;
bool mPreferred;
};
......@@ -103,12 +114,14 @@ EmailEditWidget::EmailEditWidget(QWidget *parent)
layout->setSpacing(KDialog::spacingHint());
mEmailEdit = new KLineEdit;
mEmailEdit->setObjectName(QLatin1String("emailedit"));
new EmailAddressExtracter(mEmailEdit);
connect(mEmailEdit, SIGNAL(textChanged(QString)),
SLOT(textChanged(QString)));
layout->addWidget(mEmailEdit);
mEditButton = new QToolButton;
mEditButton->setObjectName(QLatin1String("editbutton"));
mEditButton->setText(QLatin1String("..."));
connect(mEditButton, SIGNAL(clicked()), SLOT(edit()));
layout->addWidget(mEditButton);
......@@ -128,41 +141,29 @@ void EmailEditWidget::setReadOnly(bool readOnly)
void EmailEditWidget::loadContact(const KABC::Addressee &contact)
{
mEmailList = contact.emails();
mList = contact.emailList();
if (!mEmailList.isEmpty()) {
mEmailEdit->setText(mEmailList.first());
} else {
if (mList.isEmpty()) {
mEmailEdit->setText(QString());
} else {
mEmailEdit->setText(mList.first().mail());
}
}
void EmailEditWidget::storeContact(KABC::Addressee &contact) const
{
QStringList emails(mEmailList);
// the preferred address is always the first one, remove it...
if (!emails.isEmpty()) {
emails.removeFirst();
}
// ... and prepend the one from the line edit
if (!mEmailEdit->text().isEmpty()) {
emails.prepend(mEmailEdit->text().toLower());
}
contact.setEmails(emails);
contact.setEmailList(mList);
}
void EmailEditWidget::edit()
{
AutoQPointer<EmailEditDialog> dlg = new EmailEditDialog(this);
dlg->setEmailList(mEmailList);
dlg->setEmailList(mList);
if (dlg->exec()) {
if (dlg->changed()) {
mEmailList = dlg->emails();
if (!mEmailList.isEmpty()) {
mEmailEdit->setText(mEmailList.first());
mList = dlg->emailList();
if (!mList.isEmpty()) {
mEmailEdit->setText(mList.first().mail());
} else {
mEmailEdit->setText(QString());
}
......@@ -172,11 +173,11 @@ void EmailEditWidget::edit()
void EmailEditWidget::textChanged(const QString &text)
{
if (!mEmailList.isEmpty()) {
mEmailList.removeFirst();
if (mList.isEmpty()) {
mList.append(KABC::Email(text));
} else {
mList.first().setEmail(text);
}
mEmailList.prepend(text);
}
EmailEditDialog::EmailEditDialog(QWidget *parent)
......@@ -256,22 +257,26 @@ void EmailEditDialog::writeConfig()
group.writeEntry("Size", size());
}
QStringList EmailEditDialog::emails() const
KABC::Email::List EmailEditDialog::emailList() const
{
QStringList emails;
KABC::Email::List lst;
for (int i = 0; i < mEmailListBox->count(); ++i) {
EmailItem *item = static_cast<EmailItem *>(mEmailListBox->item(i));
KABC::Email email = item->email();
email.setEmail(item->text());
if (item->preferred()) {
emails.prepend(item->text());
lst.prepend(email);
} else {
emails.append(item->text());
lst.append(email);
}
}
return emails;
return lst;
}
void EmailEditDialog::add()
{
bool ok = false;
......@@ -354,27 +359,18 @@ bool EmailEditDialog::changed() const
return mChanged;
}
void EmailEditDialog::setEmailList(const QStringList &list)
void EmailEditDialog::setEmailList(const KABC::Email::List &list)
{
QStringList items = list;
if (items.removeAll(QLatin1String("")) > 0) {
mChanged = true;
} else {
mChanged = false;
}
QStringList::ConstIterator it;
bool preferred = true;
QStringList::ConstIterator end(items.constEnd());
QStringList emails;
for (it = items.constBegin(); it != end; ++it) {
if (!emails.contains(*it)) {
new EmailItem(*it, mEmailListBox, preferred);
emails << *it;
bool preferred = true;
Q_FOREACH(const KABC::Email &email, list) {
if (!emails.contains(email.mail())) {
EmailItem *emailItem = new EmailItem(email.mail(), mEmailListBox, preferred);
emailItem->setEmail(email);
emails << email.mail();
preferred = false;
}
}
}
void EmailEditDialog::standard()
......
......@@ -23,7 +23,7 @@
#define EMAILEDITWIDGET_H
#include <kdialog.h>
#include <kabc/email.h>
namespace KABC
{
class Addressee;
......@@ -59,7 +59,7 @@ private Q_SLOTS:
private:
KLineEdit *mEmailEdit;
QToolButton *mEditButton;
QStringList mEmailList;
KABC::Email::List mList;
};
class EmailEditDialog : public KDialog
......@@ -70,10 +70,11 @@ public:
explicit EmailEditDialog(QWidget *parent = 0);
~EmailEditDialog();
QStringList emails() const;
bool changed() const;
void setEmailList(const QStringList &list);
KABC::Email::List emailList() const;
void setEmailList(const KABC::Email::List &list);
protected Q_SLOTS:
void add();
void edit();
......
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