File indexing completed on 2024-06-02 05:15:55

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 Akonadi
0020 {
0021 class AbstractContactGroupFormatter;
0022 class ContactGroupViewerPrivate;
0023 
0024 /**
0025  * @short A viewer component for contact groups in Akonadi.
0026  *
0027  * This widgets provides a way to show a contact group from the
0028  * Akonadi storage.
0029  *
0030  * Example:
0031  *
0032  * @code
0033  *
0034  * using namespace Akonadi;
0035  *
0036  * const Item group = ...
0037  *
0038  * ContactGroupViewer *viewer = new ContactGroupViewer( this );
0039  * viewer->setContactGroup( group );
0040  *
0041  * @endcode
0042  *
0043  * @author Tobias Koenig <tokoe@kde.org>
0044  * @since 4.4
0045  */
0046 class AKONADI_CONTACT_WIDGETS_EXPORT ContactGroupViewer : public QWidget, public Akonadi::ItemMonitor
0047 {
0048     Q_OBJECT
0049 
0050 public:
0051     /**
0052      * Creates a new contact group viewer.
0053      *
0054      * @param parent The parent widget.
0055      */
0056     explicit ContactGroupViewer(QWidget *parent = nullptr);
0057 
0058     /**
0059      * Destroys the contact group viewer.
0060      */
0061     ~ContactGroupViewer() override;
0062 
0063     /**
0064      * Returns the contact group that is currently displayed.
0065      */
0066     Akonadi::Item contactGroup() const;
0067 
0068     /**
0069      * Sets the contact group @p formatter that should be used for formatting the
0070      * contact group. If formatter is @c 0, the standard formatter will be used.
0071      * @param formatter the formatter to use
0072      * @note The contact viewer won't take ownership of the formatter.
0073      * @since 4.6
0074      */
0075     void setContactGroupFormatter(Akonadi::AbstractContactGroupFormatter *formatter);
0076 
0077     /**
0078      * @since 5.20.41
0079      */
0080     void updateView();
0081 
0082 public Q_SLOTS:
0083     /**
0084      * Sets the contact @p group that shall be displayed in the viewer.
0085      */
0086     void setContactGroup(const Akonadi::Item &group);
0087 
0088 Q_SIGNALS:
0089     /**
0090      * This signal is emitted whenever the user has clicked on
0091      * a URL in the viewer (e.g. a mailto: link).
0092      *
0093      * @param url The url that has been clicked.
0094      */
0095     void urlClicked(const QUrl &url);
0096 
0097 private:
0098     /**
0099      * This method is called whenever the displayed contact @p group has been changed.
0100      */
0101     AKONADI_CONTACT_WIDGETS_NO_EXPORT void itemChanged(const Akonadi::Item &group) override;
0102 
0103     /**
0104      * This method is called whenever the displayed contact group has been
0105      * removed from Akonadi.
0106      */
0107     AKONADI_CONTACT_WIDGETS_NO_EXPORT void itemRemoved() override;
0108 
0109 private:
0110     //@cond PRIVATE
0111     std::unique_ptr<ContactGroupViewerPrivate> const d;
0112     //@endcond
0113 };
0114 }