Akonadi Contacts

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

KDE's Doxygen guidelines are available online.