File indexing completed on 2024-05-19 05:17:29

0001 /*  -*- c++ -*-
0002     SPDX-FileCopyrightText: 2008 Thomas McGuire <Thomas.McGuire@gmx.net>
0003     SPDX-FileCopyrightText: 2008 Edwin Schepers <yez@familieschepers.nl>
0004     SPDX-FileCopyrightText: 2008 Tom Albers <tomalbers@kde.nl>
0005     SPDX-FileCopyrightText: 2004 Marc Mutz <mutz@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.1-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include "kidentitymanagementwidgets_export.h"
0013 #include <KIdentityManagementCore/Signature> // for Signature::Type
0014 #include <QWidget>
0015 #include <memory>
0016 
0017 using KIdentityManagementCore::Signature;
0018 
0019 namespace KIdentityManagementWidgets
0020 {
0021 class SignatureConfiguratorPrivate;
0022 /**
0023  * This widget gives an interface so users can edit their signature.
0024  * You can set a signature via setSignature(), let the user edit the
0025  * signature and when done, read the signature back.
0026  */
0027 class KIDENTITYMANAGEMENTWIDGETS_EXPORT SignatureConfigurator : public QWidget
0028 {
0029     Q_OBJECT
0030 public:
0031     /**
0032      * Constructor
0033      */
0034     explicit SignatureConfigurator(QWidget *parent = nullptr);
0035 
0036     /**
0037      * destructor
0038      */
0039     ~SignatureConfigurator() override;
0040 
0041     /**
0042      * Enum for the different viewmodes.
0043      */
0044     enum ViewMode { ShowCode, ShowHtml };
0045 
0046     /**
0047      * Indicated if the user wants a signature
0048      */
0049     [[nodiscard]] bool isSignatureEnabled() const;
0050 
0051     /**
0052      * Use this to activate the signature.
0053      */
0054     void setSignatureEnabled(bool enable);
0055 
0056     /**
0057      * This returns the type of the signature,
0058      * so that can be Disabled, Inline, fromFile, etc.
0059      */
0060     [[nodiscard]] Signature::Type signatureType() const;
0061 
0062     /**
0063      * Set the signature type to @p type.
0064      */
0065     void setSignatureType(Signature::Type type);
0066 
0067     /**
0068      * Make @p text the text for the signature.
0069      */
0070     void setInlineText(const QString &text);
0071 
0072     /**
0073      * Returns the file url which the user wants
0074      * to use as a signature.
0075      */
0076     [[nodiscard]] QString filePath() const;
0077 
0078     /**
0079      * Set @p url for the file url part of the
0080      * widget.
0081      */
0082     void setFileURL(const QString &url);
0083 
0084     /**
0085      * Returns the url of the command which the
0086      * users wants to use as signature.
0087      */
0088     [[nodiscard]] QString commandPath() const;
0089 
0090     /**
0091      * Sets @p url as the command to execute.
0092      */
0093     void setCommandURL(const QString &url);
0094 
0095     /**
0096        Convenience method.
0097        @return a Signature object representing the state of the widgets.
0098      **/
0099     [[nodiscard]] Signature signature() const;
0100 
0101     /**
0102        Convenience method. Sets the widgets according to @p sig
0103        @param sig the signature to configure
0104     **/
0105     void setSignature(const Signature &sig);
0106 
0107     /**
0108      * Sets the directory where the images used in the HTML signature will be stored.
0109      * Needs to be called before calling setSignature(), as each signature should use
0110      * a different location.
0111      * The directory needs to exist, it will not be created.
0112      * @param path the image location to set
0113      * @since 4.4
0114      * @sa Signature::setImageLocation
0115      */
0116     void setImageLocation(const QString &path);
0117 
0118     /**
0119      * Sets the image location to the image location of a given identity, which is
0120      * emailidentities/<identity-id>/.
0121      *
0122      * @param identity The identity whose unique ID will be used to determine the image
0123      *                 location.
0124      * @since 4.4
0125      */
0126     void setImageLocation(const KIdentityManagementCore::Identity &identity);
0127 
0128 private:
0129     KIDENTITYMANAGEMENTWIDGETS_NO_EXPORT void slotUrlChanged();
0130     KIDENTITYMANAGEMENTWIDGETS_NO_EXPORT void slotEdit();
0131     KIDENTITYMANAGEMENTWIDGETS_NO_EXPORT void slotSetHtml();
0132 
0133     //@cond PRIVATE
0134     friend class SignatureConfiguratorPrivate;
0135     std::unique_ptr<SignatureConfiguratorPrivate> const d;
0136     //@endcond
0137 };
0138 }