Akonadi Contacts

contactviewer.h
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#pragma once
10
11#include "akonadi-contact-widgets_export.h"
12
13#include <Akonadi/ItemMonitor>
14
15#include <QWidget>
16
17#include <memory>
18
19namespace KContacts
20{
21class Address;
22class Addressee;
23}
24
25namespace Akonadi
26{
27class AbstractContactFormatter;
28class ContactViewerPrivate;
29
30/**
31 * @short A viewer component for contacts in Akonadi.
32 *
33 * This widgets provides a way to show a contact from the
34 * Akonadi storage or a raw contact object.
35 *
36 * Examples:
37 *
38 * @code
39 *
40 * using namespace Akonadi;
41 *
42 * const Item contact = ...
43 *
44 * ContactViewer *viewer = new ContactViewer( this );
45 * viewer->setContact( contact );
46 *
47 * @endcode
48
49 * @code
50 *
51 * using namespace Akonadi;
52 *
53 * const KContacts::Addressee contact = ...
54 *
55 * ContactViewer *viewer = new ContactViewer( this );
56 * viewer->setContact( contact );
57 *
58 * @endcode
59 *
60 * @author Tobias Koenig <tokoe@kde.org>
61 * @since 4.4
62 */
63class AKONADI_CONTACT_WIDGETS_EXPORT ContactViewer : public QWidget, public Akonadi::ItemMonitor
64{
65 Q_OBJECT
66
67public:
68 /**
69 * Creates a new contact viewer.
70 *
71 * @param parent The parent widget.
72 */
73 explicit ContactViewer(QWidget *parent = nullptr);
74
75 /**
76 * Destroys the contact viewer.
77 */
78 ~ContactViewer() override;
79
80 /**
81 * Returns the contact that is currently displayed.
82 *
83 * @note The returned contact is only valid if it was
84 * set with setContact() before.
85 */
86 [[nodiscard]] Akonadi::Item contact() const;
87
88 /**
89 * Returns the raw contact that is currently displayed.
90 *
91 * @since 4.5
92 */
93 [[nodiscard]] KContacts::Addressee rawContact() const;
94
95 /**
96 * Sets the contact @p formatter that should be used for formatting the
97 * contact. If formatter is @c 0, the standard formatter will be used.
98 * @param formatter the contact formatter to set
99 * @note The contact viewer won't take ownership of the formatter.
100 *
101 * @since 4.6
102 */
103 void setContactFormatter(Akonadi::AbstractContactFormatter *formatter);
104 /**
105 * @since 5.1
106 */
107 void updateView();
108
109 /**
110 * @since 5.2
111 */
112 void setShowQRCode(bool b);
113 [[nodiscard]] bool showQRCode() const;
114public Q_SLOTS:
115 /**
116 * Sets the @p contact that shall be displayed in the viewer.
117 */
118 void setContact(const Akonadi::Item &contact);
119
120 /**
121 * Sets the raw @p contact object that shall be displayed in the viewer.
122 * @param contact the contact object to set
123 * @since 4.5
124 */
125 void setRawContact(const KContacts::Addressee &contact);
126
127Q_SIGNALS:
128 /**
129 * This signal is emitted whenever the user has clicked on
130 * a url (e.g. homepage or blog url) in the viewer.
131 *
132 * @param url The url that has been clicked.
133 */
134 void urlClicked(const QUrl &url);
135
136 /**
137 * This signal is emitted whenever the user has clicked on an
138 * address in the viewer.
139 *
140 * @param address The corresponding address.
141 */
142 void addressClicked(const KContacts::Address &address);
143
144private:
145 /**
146 * This method is called whenever the displayed contact has been changed.
147 */
148 void itemChanged(const Akonadi::Item &contact) override;
149
150 /**
151 * This method is called whenever the displayed contact has been
152 * removed from Akonadi.
153 */
154 void itemRemoved() override;
155
156private:
157 //@cond PRIVATE
158 std::unique_ptr<ContactViewerPrivate> const d;
159
160 Q_PRIVATE_SLOT(d, void slotUrlClicked(const QUrl &))
161 Q_PRIVATE_SLOT(d, void slotParentCollectionFetched(KJob *))
162 //@endcond
163};
164}
The interface for all contact formatters.
A viewer component for contacts in Akonadi.
void addressClicked(const KContacts::Address &address)
This signal is emitted whenever the user has clicked on an address in the viewer.
void urlClicked(const QUrl &url)
This signal is emitted whenever the user has clicked on a url (e.g.
~ContactViewer() override
Destroys the contact viewer.
A widget for editing the display name of a contact.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.