Akonadi Contacts

contactviewerdialog.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "contactviewerdialog.h"
10#include "contactviewer.h"
11
12#include <Akonadi/Item>
13using namespace Akonadi;
14
15#include <KConfig>
16#include <KLocalizedString>
17
18#include <KConfigGroup>
19#include <QDesktopServices>
20#include <QDialogButtonBox>
21#include <QPushButton>
22#include <QVBoxLayout>
23
24namespace
25{
26static const char myContactViewerDialogGroupName[] = "ContactViewer";
27}
28class Akonadi::ContactViewerDialogPrivate
29{
30public:
31 explicit ContactViewerDialogPrivate(ContactViewerDialog *parent)
32 : q(parent)
33 {
34 }
35
36 void readConfig()
37 {
38 KConfig config(QStringLiteral("akonadi_contactrc"));
39 KConfigGroup group(&config, QLatin1StringView(myContactViewerDialogGroupName));
40 const QSize size = group.readEntry("Size", QSize(500, 600));
41 if (size.isValid()) {
42 q->resize(size);
43 }
44 }
45
46 void writeConfig()
47 {
48 KConfig config(QStringLiteral("akonadi_contactrc"));
49 KConfigGroup group(&config, QLatin1StringView(myContactViewerDialogGroupName));
50 group.writeEntry("Size", q->size());
51 group.sync();
52 }
53
54 ContactViewerDialog *const q;
55 Akonadi::ContactViewer *mViewer = nullptr;
56};
57
58using namespace Akonadi;
59
61 : QDialog(parent)
62 , d(new ContactViewerDialogPrivate(this))
63{
64 setWindowTitle(i18nc("@title:window", "Show Contact"));
65 auto mainLayout = new QVBoxLayout(this);
66
67 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this);
68 auto mainWidget = new QWidget(this);
69 mainLayout->addWidget(mainWidget);
70 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
71 okButton->setDefault(true);
75
76 auto layout = new QVBoxLayout(mainWidget);
77
78 d->mViewer = new Akonadi::ContactViewer(this);
79 layout->addWidget(d->mViewer);
80
81 connect(d->mViewer, &Akonadi::ContactViewer::urlClicked, this, [](const QUrl &url) {
82 QDesktopServices::openUrl(url);
83 });
84
85 mainLayout->addWidget(buttonBox);
86
87 d->readConfig();
88}
89
91{
92 d->writeConfig();
93}
94
96{
97 return d->mViewer->contact();
98}
99
101{
102 return d->mViewer;
103}
104
106{
107 d->mViewer->setContact(contact);
108}
109
110#include "moc_contactviewerdialog.cpp"
A dialog for displaying a contact in Akonadi.
ContactViewerDialog(QWidget *parent=nullptr)
Creates a new contact viewer dialog.
Akonadi::Item contact() const
Returns the contact that is currently displayed.
ContactViewer * viewer() const
Returns the ContactViewer that is used by this dialog.
void setContact(const Akonadi::Item &contact)
Sets the contact that shall be displayed in the dialog.
~ContactViewerDialog() override
Destroys the contact viewer dialog.
A viewer component for contacts in Akonadi.
void urlClicked(const QUrl &url)
This signal is emitted whenever the user has clicked on a url (e.g.
void setContact(const Akonadi::Item &contact)
Sets the contact that shall be displayed in the viewer.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void setShortcut(const QKeySequence &key)
virtual void accept()
virtual void reject()
void addWidget(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setDefault(bool)
bool isValid() const const
Key_Return
QWidget(QWidget *parent, Qt::WindowFlags f)
QLayout * layout() const const
void resize(const QSize &)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.