Akonadi Contacts

nameeditdialog.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  Copyright (c) 2010 Tobias Koenig <[email protected]>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "nameeditdialog.h"
23 #include "displaynameeditwidget.h"
24 
25 #include <KComboBox>
26 #include <KLineEdit>
27 #include <KLocalizedString>
28 
29 #include <QDialogButtonBox>
30 #include <QFormLayout>
31 #include <QPushButton>
32 
33 NameEditDialog::NameEditDialog(QWidget *parent)
34  : QDialog(parent)
35 {
36  setWindowTitle(i18nc("@title:window", "Edit Contact Name"));
37 
38  QVBoxLayout *mainLayout = new QVBoxLayout(this);
39 
41  mainLayout->addLayout(layout);
42 
43  mPrefixCombo = new KComboBox(this);
44  mPrefixCombo->setDuplicatesEnabled(false);
45  mPrefixCombo->setEditable(true);
46 
47  mGivenNameEdit = new KLineEdit(this);
48  mGivenNameEdit->setTrapReturnKey(true);
49 
50  mAdditionalNameEdit = new KLineEdit(this);
51  mAdditionalNameEdit->setTrapReturnKey(true);
52 
53  mFamilyNameEdit = new KLineEdit(this);
54  mFamilyNameEdit->setTrapReturnKey(true);
55 
56  mSuffixCombo = new KComboBox(this);
57  mSuffixCombo->setDuplicatesEnabled(false);
58  mSuffixCombo->setEditable(true);
59 
60  mDisplayNameEdit = new DisplayNameEditWidget(this);
61 
62  layout->addRow(i18n("Honorific prefixes:"), mPrefixCombo);
63  layout->addRow(i18n("Given name:"), mGivenNameEdit);
64  layout->addRow(i18n("Additional names:"), mAdditionalNameEdit);
65  layout->addRow(i18n("Family names:"), mFamilyNameEdit);
66  layout->addRow(i18n("Honorific suffixes:"), mSuffixCombo);
67  layout->addRow(i18n("Display:"), mDisplayNameEdit);
68 
69  QStringList prefixList;
70  prefixList += QString();
71  prefixList += i18n("Dr.");
72  prefixList += i18n("Miss");
73  prefixList += i18n("Mr.");
74  prefixList += i18n("Mrs.");
75  prefixList += i18n("Ms.");
76  prefixList += i18n("Prof.");
77  prefixList.sort();
78 
79  QStringList suffixList;
80  suffixList += QString();
81  suffixList += i18n("I");
82  suffixList += i18n("II");
83  suffixList += i18n("III");
84  suffixList += i18n("Jr.");
85  suffixList += i18n("Sr.");
86  suffixList.sort();
87 
88  mPrefixCombo->addItems(prefixList);
89  mSuffixCombo->addItems(suffixList);
90 
91  mPrefixCombo->lineEdit()->setFocus();
93  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
94  okButton->setDefault(true);
95  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
96  connect(buttonBox, &QDialogButtonBox::accepted, this, &NameEditDialog::accept);
97  connect(buttonBox, &QDialogButtonBox::rejected, this, &NameEditDialog::reject);
98  mainLayout->addWidget(buttonBox);
99 }
100 
101 void NameEditDialog::setFamilyName(const QString &name)
102 {
103  mFamilyNameEdit->setText(name);
104 }
105 
106 QString NameEditDialog::familyName() const
107 {
108  return mFamilyNameEdit->text();
109 }
110 
111 void NameEditDialog::setGivenName(const QString &name)
112 {
113  mGivenNameEdit->setText(name);
114 }
115 
116 QString NameEditDialog::givenName() const
117 {
118  return mGivenNameEdit->text();
119 }
120 
121 void NameEditDialog::setPrefix(const QString &prefix)
122 {
123  mPrefixCombo->setItemText(mPrefixCombo->currentIndex(), prefix);
124 }
125 
126 QString NameEditDialog::prefix() const
127 {
128  return mPrefixCombo->currentText();
129 }
130 
131 void NameEditDialog::setSuffix(const QString &suffix)
132 {
133  mSuffixCombo->setItemText(mSuffixCombo->currentIndex(), suffix);
134 }
135 
136 QString NameEditDialog::suffix() const
137 {
138  return mSuffixCombo->currentText();
139 }
140 
141 void NameEditDialog::setAdditionalName(const QString &name)
142 {
143  mAdditionalNameEdit->setText(name);
144 }
145 
146 QString NameEditDialog::additionalName() const
147 {
148  return mAdditionalNameEdit->text();
149 }
150 
151 void NameEditDialog::loadContact(const KContacts::Addressee &contact)
152 {
153  setPrefix(contact.prefix());
154  setGivenName(contact.givenName());
155  setAdditionalName(contact.additionalName());
156  setFamilyName(contact.familyName());
157  setSuffix(contact.suffix());
158  mDisplayNameEdit->loadContact(contact);
159 }
160 
161 void NameEditDialog::storeContact(KContacts::Addressee &contact) const
162 {
163  mDisplayNameEdit->storeContact(contact);
164  contact.setPrefix(prefix());
165  contact.setGivenName(givenName());
166  contact.setAdditionalName(additionalName());
167  contact.setFamilyName(familyName());
168  contact.setSuffix(suffix());
169 }
170 
171 void NameEditDialog::setDisplayType(DisplayNameEditWidget::DisplayType type)
172 {
173  mDisplayNameEdit->setDisplayType(type);
174 }
175 
176 DisplayNameEditWidget::DisplayType NameEditDialog::displayType() const
177 {
178  return mDisplayNameEdit->displayType();
179 }
QLayout * layout() const const
QString familyName() const
QString additionalName() const
void setSuffix(const QString &suffix)
A widget for editing the display name of a contact.
void setPrefix(const QString &prefix)
void setGivenName(const QString &givenName)
void setAdditionalName(const QString &additionalName)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
DisplayType
Describes what the display name should look like.
void setFamilyName(const QString &familyName)
QString suffix() const
void setShortcut(const QKeySequence &key)
void addRow(QWidget *label, QWidget *field)
QString i18n(const char *text, const TYPE &arg...)
void setWindowTitle(const QString &)
void sort(Qt::CaseSensitivity cs)
QPushButton * button(QDialogButtonBox::StandardButton which) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString givenName() const
void setDefault(bool)
Key_Return
QString prefix() const
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 23:06:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.