File indexing completed on 2024-11-24 04:39:35

0001 /*
0002     This file is part of Akonadi Contact.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "akonadi-contact-widgets_export.h"
0012 
0013 #include <Akonadi/ItemMonitor>
0014 
0015 #include <QWidget>
0016 
0017 #include <memory>
0018 
0019 namespace KContacts
0020 {
0021 class Address;
0022 class Addressee;
0023 }
0024 
0025 namespace Akonadi
0026 {
0027 class AbstractContactFormatter;
0028 class ContactViewerPrivate;
0029 
0030 /**
0031  * @short A viewer component for contacts in Akonadi.
0032  *
0033  * This widgets provides a way to show a contact from the
0034  * Akonadi storage or a raw contact object.
0035  *
0036  * Examples:
0037  *
0038  * @code
0039  *
0040  * using namespace Akonadi;
0041  *
0042  * const Item contact = ...
0043  *
0044  * ContactViewer *viewer = new ContactViewer( this );
0045  * viewer->setContact( contact );
0046  *
0047  * @endcode
0048 
0049  * @code
0050  *
0051  * using namespace Akonadi;
0052  *
0053  * const KContacts::Addressee contact = ...
0054  *
0055  * ContactViewer *viewer = new ContactViewer( this );
0056  * viewer->setContact( contact );
0057  *
0058  * @endcode
0059  *
0060  * @author Tobias Koenig <tokoe@kde.org>
0061  * @since 4.4
0062  */
0063 class AKONADI_CONTACT_WIDGETS_EXPORT ContactViewer : public QWidget, public Akonadi::ItemMonitor
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068     /**
0069      * Creates a new contact viewer.
0070      *
0071      * @param parent The parent widget.
0072      */
0073     explicit ContactViewer(QWidget *parent = nullptr);
0074 
0075     /**
0076      * Destroys the contact viewer.
0077      */
0078     ~ContactViewer() override;
0079 
0080     /**
0081      * Returns the contact that is currently displayed.
0082      *
0083      * @note The returned contact is only valid if it was
0084      *       set with setContact() before.
0085      */
0086     [[nodiscard]] Akonadi::Item contact() const;
0087 
0088     /**
0089      * Returns the raw contact that is currently displayed.
0090      *
0091      * @since 4.5
0092      */
0093     [[nodiscard]] KContacts::Addressee rawContact() const;
0094 
0095     /**
0096      * Sets the contact @p formatter that should be used for formatting the
0097      * contact. If formatter is @c 0, the standard formatter will be used.
0098      * @param formatter the contact formatter to set
0099      * @note The contact viewer won't take ownership of the formatter.
0100      *
0101      * @since 4.6
0102      */
0103     void setContactFormatter(Akonadi::AbstractContactFormatter *formatter);
0104     /**
0105      * @since 5.1
0106      */
0107     void updateView();
0108 
0109     /**
0110      * @since 5.2
0111      */
0112     void setShowQRCode(bool b);
0113     [[nodiscard]] bool showQRCode() const;
0114 public Q_SLOTS:
0115     /**
0116      * Sets the @p contact that shall be displayed in the viewer.
0117      */
0118     void setContact(const Akonadi::Item &contact);
0119 
0120     /**
0121      * Sets the raw @p contact object that shall be displayed in the viewer.
0122      * @param contact the contact object to set
0123      * @since 4.5
0124      */
0125     void setRawContact(const KContacts::Addressee &contact);
0126 
0127 Q_SIGNALS:
0128     /**
0129      * This signal is emitted whenever the user has clicked on
0130      * a url (e.g. homepage or blog url) in the viewer.
0131      *
0132      * @param url The url that has been clicked.
0133      */
0134     void urlClicked(const QUrl &url);
0135 
0136     /**
0137      * This signal is emitted whenever the user has clicked on an
0138      * address in the viewer.
0139      *
0140      * @param address The corresponding address.
0141      */
0142     void addressClicked(const KContacts::Address &address);
0143 
0144 private:
0145     /**
0146      * This method is called whenever the displayed contact has been changed.
0147      */
0148     void itemChanged(const Akonadi::Item &contact) override;
0149 
0150     /**
0151      * This method is called whenever the displayed contact has been
0152      * removed from Akonadi.
0153      */
0154     void itemRemoved() override;
0155 
0156 private:
0157     //@cond PRIVATE
0158     std::unique_ptr<ContactViewerPrivate> const d;
0159 
0160     Q_PRIVATE_SLOT(d, void slotUrlClicked(const QUrl &))
0161     Q_PRIVATE_SLOT(d, void slotParentCollectionFetched(KJob *))
0162     //@endcond
0163 };
0164 }