Akonadi Contacts

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

KDE's Doxygen guidelines are available online.