Akonadi Contacts

businesseditorwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "businesseditorwidget.h"
10 #include "../utils/utils.h"
11 
12 #include <KLineEdit>
13 #include <KLocalizedString>
14 #include <QGridLayout>
15 #include <QLabel>
16 
17 #include "../widgets/imagewidget.h"
18 #include "freebusyeditwidget.h"
19 
20 #include <KContacts/Addressee>
21 
22 using namespace ContactEditor;
23 
24 BusinessEditorWidget::BusinessEditorWidget(QWidget *parent)
25  : QWidget(parent)
26 {
27  auto topLayout = new QHBoxLayout(this);
28 
29  auto logoLayout = new QVBoxLayout;
30  topLayout->addLayout(logoLayout);
31 
32  // setup general group box
33  mLogoWidget = new ImageWidget(ImageWidget::Logo, this);
34  logoLayout->addWidget(mLogoWidget, Qt::AlignTop);
35  logoLayout->addStretch(0);
36 
37  auto generalLayout = new QGridLayout;
38  topLayout->addLayout(generalLayout);
39 
40  auto label = new QLabel(i18nc("@label The organization of a contact", "Organization:"), this);
41  generalLayout->addWidget(label, 0, 0);
42 
43  mOrganizationWidget = new KLineEdit(this);
44  mOrganizationWidget->setTrapReturnKey(true);
45  mOrganizationWidget->setPlaceholderText(i18n("Add organization's name"));
46  label->setBuddy(mOrganizationWidget);
47  generalLayout->addWidget(mOrganizationWidget, 1, 0);
48 
49  label = new QLabel(i18nc("@label The profession of a contact", "Profession:"));
50  generalLayout->addWidget(label, 0, 1);
51 
52  mProfessionWidget = new KLineEdit(this);
53  mProfessionWidget->setPlaceholderText(i18n("Add profession"));
54  mProfessionWidget->setTrapReturnKey(true);
55  label->setBuddy(mProfessionWidget);
56  generalLayout->addWidget(mProfessionWidget, 1, 1);
57 
58  label = new QLabel(i18nc("@label The title of a contact", "Title:"));
59  generalLayout->addWidget(label, 3, 0);
60 
61  mTitleWidget = new KLineEdit(this);
62  mTitleWidget->setPlaceholderText(i18n("Add the title"));
63  mTitleWidget->setTrapReturnKey(true);
64  label->setBuddy(mTitleWidget);
65  generalLayout->addWidget(mTitleWidget, 4, 0);
66 
67  label = new QLabel(i18nc("@label The department of a contact", "Department:"));
68  generalLayout->addWidget(label, 3, 1);
69 
70  mDepartmentWidget = new KLineEdit(this);
71  mDepartmentWidget->setPlaceholderText(i18n("Add the department"));
72  mDepartmentWidget->setTrapReturnKey(true);
73  label->setBuddy(mDepartmentWidget);
74  generalLayout->addWidget(mDepartmentWidget, 4, 1);
75 
76  label = new QLabel(i18nc("@label The office of a contact", "Office:"), this);
77  generalLayout->addWidget(label, 5, 0);
78 
79  mOfficeWidget = new KLineEdit(this);
80  mOfficeWidget->setTrapReturnKey(true);
81  mOfficeWidget->setPlaceholderText(i18n("Add the office"));
82 
83  label->setBuddy(mOfficeWidget);
84  generalLayout->addWidget(mOfficeWidget, 6, 0);
85 
86  label = new QLabel(i18nc("@label The manager's name of a contact", "Manager's name:"));
87  generalLayout->addWidget(label, 5, 1);
88 
89  mManagerWidget = new KLineEdit(this);
90  mManagerWidget->setPlaceholderText(i18n("Add manager's name"));
91  mManagerWidget->setTrapReturnKey(true);
92  label->setBuddy(mManagerWidget);
93  generalLayout->addWidget(mManagerWidget, 6, 1);
94 
95  label = new QLabel(i18nc("@label The assistant's name of a contact", "Assistant's name:"));
96  generalLayout->addWidget(label, 7, 0);
97 
98  mAssistantWidget = new KLineEdit(this);
99  mAssistantWidget->setPlaceholderText(i18n("Add assistant's name"));
100  mAssistantWidget->setTrapReturnKey(true);
101  label->setBuddy(mAssistantWidget);
102  generalLayout->addWidget(mAssistantWidget, 8, 0);
103 
104  // setup groupware group box
105  label = new QLabel(i18nc("@label The free/busy information of a contact", "Free/Busy:"));
106  generalLayout->addWidget(label, 7, 1);
107 
108  mFreeBusyWidget = new FreeBusyEditWidget(this);
109  label->setBuddy(mFreeBusyWidget);
110  generalLayout->addWidget(mFreeBusyWidget, 8, 1);
111  generalLayout->setRowStretch(9, 1);
112  connect(mOrganizationWidget, &KLineEdit::textChanged, this, &BusinessEditorWidget::organizationChanged);
113 }
114 
115 BusinessEditorWidget::~BusinessEditorWidget()
116 {
117 }
118 
119 void BusinessEditorWidget::loadContact(const KContacts::Addressee &contact)
120 {
121  mLogoWidget->loadContact(contact);
122  mOrganizationWidget->setText(contact.organization());
123  mProfessionWidget->setText(contact.profession());
124  mTitleWidget->setText(contact.title());
125  mDepartmentWidget->setText(contact.department());
126  mOfficeWidget->setText(contact.office());
127  mManagerWidget->setText(contact.managersName());
128  mAssistantWidget->setText(contact.assistantsName());
129 
130  // groupware group
131  mFreeBusyWidget->loadContact(contact);
132 }
133 
134 void BusinessEditorWidget::storeContact(KContacts::Addressee &contact)
135 {
136  // general group
137  mLogoWidget->storeContact(contact);
138  contact.setOrganization(mOrganizationWidget->text());
139  contact.setProfession(mProfessionWidget->text().trimmed());
140  contact.setTitle(mTitleWidget->text().trimmed());
141  contact.setDepartment(mDepartmentWidget->text().trimmed());
142  contact.setOffice(mOfficeWidget->text().trimmed());
143  contact.setManagersName(mManagerWidget->text().trimmed());
144  contact.setAssistantsName(mAssistantWidget->text().trimmed());
145 
146  // groupware group
147  mFreeBusyWidget->storeContact(contact);
148 }
149 
150 void BusinessEditorWidget::setReadOnly(bool readOnly)
151 {
152  mLogoWidget->setReadOnly(readOnly);
153  mOrganizationWidget->setReadOnly(readOnly);
154  mProfessionWidget->setReadOnly(readOnly);
155  mTitleWidget->setReadOnly(readOnly);
156  mDepartmentWidget->setReadOnly(readOnly);
157  mOfficeWidget->setReadOnly(readOnly);
158  mManagerWidget->setReadOnly(readOnly);
159  mAssistantWidget->setReadOnly(readOnly);
160 
161  // widgets from groupware group
162  mFreeBusyWidget->setReadOnly(readOnly);
163 }
QString assistantsName() const
QString organization() const
void textChanged(const QString &text)
void setDepartment(const QString &department)
AlignTop
QString managersName() const
void setAssistantsName(const QString &assistantsName)
QString profession() const
QString title() const
void setOrganization(const QString &organization)
void setTitle(const QString &title)
void setOffice(const QString &office)
void setProfession(const QString &profession)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
QString i18n(const char *text, const TYPE &arg...)
void addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment)
QString department() const
QString office() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addLayout(QLayout *layout, int stretch)
void setManagersName(const QString &managersName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jun 22 2021 23:08:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.