void ContactInfoDialog::Private::addInfoRow(InfoRowIndex index, const QString &value)
{
    InfoRow *row = &InfoRows[index];

    // I18N_NOOP only marks the string for translation, the actual lookup of
    // translated row->title happens here
    QLabel *descriptionLabel = new QLabel(i18n(row->title), q);
    QFont font = descriptionLabel->font();
    font.setBold(true);
    descriptionLabel->setFont(font);

    if (editable) {
        if (index == Birthday) {
            KDateComboBox *combo = new KDateComboBox(q);
            combo->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker);
            combo->setMinimumWidth(200);
            combo->setDate(QDate::fromString(value));
            connect(combo, SIGNAL(dateChanged(QDate)), q, SLOT(onInfoDataChanged()));

            infoValueWidgets.insert(index, combo);
        } else {
            QLineEdit *edit = new QLineEdit(q);
            edit->setMinimumWidth(200);
            edit->setText(value);
            connect(edit, SIGNAL(textChanged(QString)), q, SLOT(onInfoDataChanged()));

            infoValueWidgets.insert(index, edit);
        }
    } else {
        QLabel *label = new QLabel(q);
        label->setOpenExternalLinks(true);
        label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
        if (index == Email) {
            label->setText(QString::fromLatin1("<a href=\"mailto:%1\">%1</a>").arg(value));
        } else if (index == Homepage) {
            QString format;
            if (!value.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) {
                format = QLatin1String("<a href=\"http://%1\">%1</a>");
            } else {
                format = QLatin1String("<a href=\"%1\">%1</a>");
            }
            label->setText(format.arg(value));
        } else {
            label->setText(value);
        }

        infoValueWidgets.insert(index, label);
    }

    infoLayout->addRow(descriptionLabel, infoValueWidgets.value(index));
}
void ContactInfoDialog::slotButtonClicked(QAbstractButton *button)
{
    if (button == d->buttonBox->button(QDialogButtonBox::Save)) {
        if (d->avatarChanged) {
            Tp::Avatar avatar;
            if (!d->newAvatarFile.isEmpty()) {
                QFile file(d->newAvatarFile);
                file.open(QIODevice::ReadOnly);

                QFileInfo fi(file);

                avatar.avatarData = file.readAll();
                file.seek(0); // reset before passing to KMimeType

                QMimeDatabase db;
                avatar.MIMEType = db.mimeTypeForFileNameAndData(d->newAvatarFile, &file).name();
            }

            d->account->setAvatar(avatar);
        }

        if (d->infoDataChanged) {
            Tp::ContactInfoFieldList fieldList;

            for (InfoRowIndex index = (InfoRowIndex) 0; index < _InfoRowCount; index = (InfoRowIndex) (index + 1)) {
                InfoRow *row = &InfoRows[index];

                Tp::ContactInfoField field;
                field.fieldName = row->fieldName;

                if (index == Birthday) {
                    KDateComboBox *combo = qobject_cast<KDateComboBox*>(d->infoValueWidgets.value(index));
                    field.fieldValue << combo->date().toString();
                } else {
                    QLineEdit *lineEdit = qobject_cast<QLineEdit*>(d->infoValueWidgets.value(index));
                    field.fieldValue << lineEdit->text();
                }

                fieldList << field;
            }

#if 0   // This method does not exist in TpQt (yet)
            d->account->connection()->setContactInfo(fieldList);
#endif
        }

        accept();
        return;
    }
}