Akonadi Contacts

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

KDE's Doxygen guidelines are available online.