1/* -*- c++ -*-
2 Copyright 2008 Thomas McGuire <Thomas.McGuire@gmx.net>
3 Copyright 2008 Edwin Schepers <yez@familieschepers.nl>
4 Copyright 2008 Tom Albers <tomalbers@kde.nl>
5 Copyright 2004 Marc Mutz <mutz@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef KPIMIDENTITIES_SIGNATURECONFIGURATOR_H
22#define KPIMIDENTITIES_SIGNATURECONFIGURATOR_H
23
24#include "kpimidentities_export.h"
25#include "signature.h" // for Signature::Type
26#include <QWidget>
27
28using KPIMIdentities::Signature;
29
30class QCheckBox;
31class KComboBox;
32class KUrlRequester;
33class KLineEdit;
34class KToolBar;
35class KRichTextWidget;
36class QString;
37class QPushButton;
38class QTextEdit;
39class QTextCharFormat;
40
41namespace KPIMIdentities {
42
43 /**
44 * This widget gives an interface so users can edit their signature.
45 * You can set a signature via setSignature(), let the user edit the
46 * signature and when done, read the signature back.
47 */
48class KPIMIDENTITIES_EXPORT SignatureConfigurator : public QWidget
49{
50 Q_OBJECT
51 public:
52 /**
53 * Constructor
54 */
55 explicit SignatureConfigurator( QWidget * parent = 0 );
56
57 /**
58 * destructor
59 */
60 virtual ~SignatureConfigurator();
61
62 /**
63 * Enum for the different viemodes.
64 */
65 enum ViewMode { ShowCode, ShowHtml };
66
67 /**
68 * Indicated if the user wants a signature
69 */
70 bool isSignatureEnabled() const;
71
72 /**
73 * Use this to activate the signature.
74 */
75 void setSignatureEnabled( bool enable );
76
77 /**
78 * This returns the type of the signature,
79 * so that can be Disabled, Inline, fromFile, etc.
80 */
81 Signature::Type signatureType() const;
82
83 /**
84 * Set the signature type to @p type.
85 */
86 void setSignatureType( Signature::Type type );
87
88 /**
89 * Returns the inline text, only useful
90 * when this is the appropriate Signature::Type
91 */
92 QString inlineText() const;
93
94 /**
95 * Make @p text the text for the signature.
96 */
97 void setInlineText( const QString & text );
98
99 /**
100 * Returns the file url which the user wants
101 * to use as a signature.
102 */
103 QString fileURL() const;
104
105 /**
106 * Set @p url for the file url part of the
107 * widget.
108 */
109 void setFileURL( const QString & url );
110
111 /**
112 * Returns the url of the command which the
113 * users wants to use as signature.
114 */
115 QString commandURL() const;
116
117 /**
118 * Sets @p url as the command to execute.
119 */
120 void setCommandURL( const QString & url );
121
122 /**
123 Conveniece method.
124 @return a Signature object representing the state of the widgets.
125 **/
126 Signature signature() const;
127
128 /**
129 Convenience method. Sets the widgets according to @p sig
130 @param sig the signature to configure
131 **/
132 void setSignature( const Signature & sig );
133
134 /**
135 * Sets the directory where the images used in the HTML signature will be stored.
136 * Needs to be called before calling setSignature(), as each signature should use
137 * a different location.
138 * The directory needs to exist, it will not be created.
139 * @param path the image location to set
140 * @since 4.4
141 * @sa Signature::setImageLocation
142 */
143 void setImageLocation( const QString &path );
144
145 /**
146 * Sets the image location to the image location of a given identity, which is
147 * emailidentities/<identity-id>/.
148 *
149 * @param identity The identity whose unique ID will be used to determine the image
150 * location.
151 * @since 4.4
152 */
153 void setImageLocation( const Identity &identity );
154
155 private:
156 void toggleHtmlBtnState( ViewMode state );
157
158 void initHtmlState();
159
160 // Returns the current text of the textedit as HTML code, but strips
161 // unnecessary tags Qt inserts
162 QString asCleanedHTML() const;
163
164 protected Q_SLOTS:
165 void slotEnableEditButton( const QString & );
166 void slotEdit();
167 void slotSetHtml();
168
169 protected:
170
171 // TODO: KDE5: BIC: Move to private class!
172 QCheckBox * mEnableCheck;
173 QCheckBox * mHtmlCheck;
174 KComboBox * mSourceCombo;
175 KUrlRequester * mFileRequester;
176 QPushButton * mEditButton;
177 KLineEdit * mCommandEdit;
178 KToolBar * mEditToolBar;
179 KToolBar * mFormatToolBar;
180 KRichTextWidget * mTextEdit; // Grmbl, why is this not in the private class?
181 // This is a KPIMTextEdit::TextEdit, really.
182
183 private:
184 //@cond PRIVATE
185 class Private;
186 Private *const d;
187 //@endcond
188};
189
190}
191
192#endif
193