Akonadi Contacts

nameeditdialog.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "nameeditdialog.h"
10
11#include <KComboBox>
12#include <KLineEdit>
13#include <KLocalizedString>
14
15#include <QDialogButtonBox>
16#include <QFormLayout>
17#include <QPushButton>
18using namespace Akonadi;
19NameEditDialog::NameEditDialog(QWidget *parent)
20 : QDialog(parent)
21{
22 setWindowTitle(i18nc("@title:window", "Edit Contact Name"));
23
24 auto mainLayout = new QVBoxLayout(this);
25
26 auto layout = new QFormLayout;
27 mainLayout->addLayout(layout);
28
29 mPrefixCombo = new KComboBox(this);
30 mPrefixCombo->setDuplicatesEnabled(false);
31 mPrefixCombo->setEditable(true);
32
33 mGivenNameEdit = new KLineEdit(this);
34 mGivenNameEdit->setTrapReturnKey(true);
35
36 mAdditionalNameEdit = new KLineEdit(this);
37 mAdditionalNameEdit->setTrapReturnKey(true);
38
39 mFamilyNameEdit = new KLineEdit(this);
40 mFamilyNameEdit->setTrapReturnKey(true);
41
42 mSuffixCombo = new KComboBox(this);
43 mSuffixCombo->setDuplicatesEnabled(false);
44 mSuffixCombo->setEditable(true);
45
46 mDisplayNameEdit = new DisplayNameEditWidget(this);
47
48 layout->addRow(i18n("Honorific prefixes:"), mPrefixCombo);
49 layout->addRow(i18n("Given name:"), mGivenNameEdit);
50 layout->addRow(i18n("Additional names:"), mAdditionalNameEdit);
51 layout->addRow(i18n("Family names:"), mFamilyNameEdit);
52 layout->addRow(i18n("Honorific suffixes:"), mSuffixCombo);
53 layout->addRow(i18n("Display:"), mDisplayNameEdit);
54
55 QStringList prefixList;
56 prefixList += QString();
57 prefixList += i18n("Dr.");
58 prefixList += i18n("Miss");
59 prefixList += i18n("Mr.");
60 prefixList += i18n("Mrs.");
61 prefixList += i18n("Ms.");
62 prefixList += i18n("Prof.");
63 prefixList.sort();
64
65 QStringList suffixList;
66 suffixList += QString();
67 suffixList += i18n("I");
68 suffixList += i18n("II");
69 suffixList += i18n("III");
70 suffixList += i18n("Jr.");
71 suffixList += i18n("Sr.");
72 suffixList.sort();
73
74 mPrefixCombo->addItems(prefixList);
75 mSuffixCombo->addItems(suffixList);
76
77 mPrefixCombo->lineEdit()->setFocus();
79 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
80 okButton->setDefault(true);
82 connect(buttonBox, &QDialogButtonBox::accepted, this, &NameEditDialog::accept);
83 connect(buttonBox, &QDialogButtonBox::rejected, this, &NameEditDialog::reject);
84 mainLayout->addWidget(buttonBox);
85}
86
87void NameEditDialog::setFamilyName(const QString &name)
88{
89 mFamilyNameEdit->setText(name);
90}
91
92QString NameEditDialog::familyName() const
93{
94 return mFamilyNameEdit->text();
95}
96
97void NameEditDialog::setGivenName(const QString &name)
98{
99 mGivenNameEdit->setText(name);
100}
101
102QString NameEditDialog::givenName() const
103{
104 return mGivenNameEdit->text();
105}
106
107void NameEditDialog::setPrefix(const QString &prefix)
108{
109 mPrefixCombo->setItemText(mPrefixCombo->currentIndex(), prefix);
110}
111
112QString NameEditDialog::prefix() const
113{
114 return mPrefixCombo->currentText();
115}
116
117void NameEditDialog::setSuffix(const QString &suffix)
118{
119 mSuffixCombo->setItemText(mSuffixCombo->currentIndex(), suffix);
120}
121
122QString NameEditDialog::suffix() const
123{
124 return mSuffixCombo->currentText();
125}
126
127void NameEditDialog::setAdditionalName(const QString &name)
128{
129 mAdditionalNameEdit->setText(name);
130}
131
132QString NameEditDialog::additionalName() const
133{
134 return mAdditionalNameEdit->text();
135}
136
137void NameEditDialog::loadContact(const KContacts::Addressee &contact)
138{
139 setPrefix(contact.prefix());
140 setGivenName(contact.givenName());
141 setAdditionalName(contact.additionalName());
142 setFamilyName(contact.familyName());
143 setSuffix(contact.suffix());
144 mDisplayNameEdit->loadContact(contact);
145}
146
147void NameEditDialog::storeContact(KContacts::Addressee &contact) const
148{
149 contact.setPrefix(prefix());
150 contact.setGivenName(givenName());
151 contact.setAdditionalName(additionalName());
152 contact.setFamilyName(familyName());
153 contact.setSuffix(suffix());
154
155 mDisplayNameEdit->changeName(contact);
156 mDisplayNameEdit->storeContact(contact);
157}
158
159void NameEditDialog::setDisplayType(DisplayNameEditWidget::DisplayType type)
160{
161 mDisplayNameEdit->setDisplayType(type);
162}
163
164DisplayNameEditWidget::DisplayType NameEditDialog::displayType() const
165{
166 return mDisplayNameEdit->displayType();
167}
168
169#include "moc_nameeditdialog.cpp"
void setAdditionalName(const QString &additionalName)
QString familyName() const
void setPrefix(const QString &prefix)
QString prefix() const
void setSuffix(const QString &suffix)
QString suffix() const
void setGivenName(const QString &givenName)
QString additionalName() const
QString givenName() const
void setFamilyName(const QString &familyName)
virtual void setText(const QString &)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void setShortcut(const QKeySequence &key)
void setItemText(int index, const QString &text)
void setDefault(bool)
void sort(Qt::CaseSensitivity cs)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:20 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.