21 #include "signatureconfigurator.h"
24 #include <kactioncollection.h>
25 #include <klocalizedstring.h>
28 #include <klineedit.h>
29 #include <kurlrequester.h>
30 #include <kshellcompletion.h>
35 #include <KStandardDirs>
37 #include <kpimtextedit/textedit.h>
47 #include <QStackedWidget>
49 #include <QVBoxLayout>
50 #include <QHBoxLayout>
54 using namespace KPIMIdentities;
56 namespace KPIMIdentities {
63 class SignatureConfigurator::Private
76 :q( parent ), inlinedHtml( true )
80 void SignatureConfigurator::Private::init()
94 q->mEnableCheck =
new QCheckBox( i18n(
"&Enable signature" ), q );
95 q->mEnableCheck->setWhatsThis(
96 i18n(
"Check this box if you want KMail to append a signature to mails "
97 "written with this identity." ) );
103 q->mSourceCombo =
new KComboBox( q );
104 q->mSourceCombo->setEditable(
false );
105 q->mSourceCombo->setWhatsThis(
106 i18n(
"Click on the widgets below to obtain help on the input methods." ) );
107 q->mSourceCombo->setEnabled(
false );
109 << i18nc(
"continuation of \"obtain signature text from\"",
110 "Input Field Below" )
111 << i18nc(
"continuation of \"obtain signature text from\"",
113 << i18nc(
"continuation of \"obtain signature text from\"",
114 "Output of Command" ) );
115 label =
new QLabel( i18n(
"Obtain signature &text from:" ), q );
125 q->connect( q->mSourceCombo, SIGNAL(currentIndexChanged(
int)),
126 widgetStack, SLOT(setCurrentIndex(
int)) );
127 q->connect( q->mSourceCombo, SIGNAL(highlighted(
int)),
128 widgetStack, SLOT(setCurrentIndex(
int)) );
131 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
132 q->mSourceCombo, SLOT(setEnabled(
bool)) );
133 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
134 widgetStack, SLOT(setEnabled(
bool)) );
135 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
136 label, SLOT(setEnabled(
bool)) );
138 q->connect( q->mEnableCheck, SIGNAL(clicked()),
139 q->mEnableCheck, SLOT(setFocus()) );
143 page =
new QWidget( widgetStack );
148 #ifndef QT_NO_TOOLBAR
149 q->mEditToolBar =
new KToolBar( q );
150 q->mEditToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
151 page_vlay->
addWidget( q->mEditToolBar, 0 );
153 q->mFormatToolBar =
new KToolBar( q );
154 q->mFormatToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
155 page_vlay->
addWidget( q->mFormatToolBar, 1 );
158 q->mTextEdit =
new KPIMTextEdit::TextEdit( q );
159 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableImageActions();
160 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertHtmlActions();
161 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertTableActions();
163 q->mTextEdit->setWhatsThis( i18n(
"Use this field to enter an arbitrary static signature." ) );
165 q->mTextEdit->setRichTextSupport( KRichTextWidget::FullTextFormattingSupport |
166 KRichTextWidget::FullListSupport |
167 KRichTextWidget::SupportAlignment |
168 KRichTextWidget::SupportRuleLine |
169 KRichTextWidget::SupportHyperlinks |
170 KRichTextWidget::SupportFormatPainting );
173 KActionCollection *actionCollection =
new KActionCollection( q );
174 q->mTextEdit->createActions( actionCollection );
175 #ifndef QT_NO_TOOLBAR
176 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_bold") ) );
177 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_italic") ) );
178 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_underline") ) );
179 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_strikeout") ) );
180 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_foreground_color") ) );
181 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_text_background_color") ) );
182 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_font_family") ) );
183 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_font_size") ) );
184 q->mEditToolBar->addAction( actionCollection->action(
QLatin1String(
"format_reset") ) );
186 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_list_style") ) );
187 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_list_indent_more") ) );
188 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_list_indent_less") ) );
189 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_list_indent_less") ) );
190 q->mFormatToolBar->addSeparator();
192 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_align_left") ) );
193 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_align_center") ) );
194 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_align_right") ) );
195 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_align_justify") ) );
196 q->mFormatToolBar->addSeparator();
198 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"insert_horizontal_rule") ) );
199 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"manage_link") ) );
200 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"format_painter") ) );
202 q->mFormatToolBar->addSeparator();
203 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"add_image") ) );
204 q->mFormatToolBar->addSeparator();
205 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"insert_html") ) );
206 q->mFormatToolBar->addAction( actionCollection->action(
QLatin1String(
"insert_table" )) );
211 q->mHtmlCheck =
new QCheckBox( i18n(
"&Use HTML" ), page );
212 q->connect( q->mHtmlCheck, SIGNAL(clicked()),
213 q, SLOT(slotSetHtml()) );
221 page =
new QWidget( widgetStack );
227 q->mFileRequester =
new KUrlRequester( page );
228 q->mFileRequester->setWhatsThis(
229 i18n(
"Use this requester to specify a text file that contains your "
230 "signature. It will be read every time you create a new mail or "
231 "append a new signature." ) );
232 label =
new QLabel( i18n(
"S&pecify file:" ), page );
233 label->
setBuddy( q->mFileRequester );
236 q->mFileRequester->button()->setAutoDefault(
false );
237 q->connect( q->mFileRequester, SIGNAL(textChanged(
QString)),
238 q, SLOT(slotEnableEditButton(
QString)) );
239 q->mEditButton =
new QPushButton( i18n(
"Edit &File" ), page );
240 q->mEditButton->setWhatsThis( i18n(
"Opens the specified file in a text editor." ) );
241 q->connect( q->mEditButton, SIGNAL(clicked()),
242 q, SLOT(slotEdit()) );
243 q->mEditButton->setAutoDefault(
false );
244 q->mEditButton->setEnabled(
false );
250 page =
new QWidget( widgetStack );
256 q->mCommandEdit =
new KLineEdit( page );
257 q->mCommandEdit->setClearButtonShown(
true );
258 q->mCommandEdit->setCompletionObject(
new KShellCompletion() );
259 q->mCommandEdit->setAutoDeleteCompletionObject(
true );
260 q->mCommandEdit->setWhatsThis(
261 i18n(
"You can add an arbitrary command here, either with or without path "
262 "depending on whether or not the command is in your Path. For every "
263 "new mail, KMail will execute the command and use what it outputs (to "
264 "standard output) as a signature. Usual commands for use with this "
265 "mechanism are \"fortune\" or \"ksig -random\"." ) );
266 label =
new QLabel( i18n(
"S&pecify command:" ), page );
274 :
QWidget( parent ), d( new Private( this ) )
296 switch ( mSourceCombo->currentIndex() ) {
297 case 0:
return Signature::Inlined;
298 case 1:
return Signature::FromFile;
299 case 2:
return Signature::FromCommand;
300 default:
return Signature::Disabled;
308 case Signature::Inlined: idx = 0;
break;
309 case Signature::FromFile: idx = 1;
break;
310 case Signature::FromCommand: idx = 2;
break;
311 default: idx = 0;
break;
314 mSourceCombo->setCurrentIndex( idx );
319 mTextEdit->setTextOrHtml( text );
324 QString file = mFileRequester->url().path();
336 mFileRequester->setUrl(
QUrl(url) );
341 return mCommandEdit->text();
346 mCommandEdit->setText( url );
355 case Signature::Inlined:
357 sig.
setText( d->inlinedHtml ? asCleanedHTML() : mTextEdit->textOrHtml() );
358 if ( d->inlinedHtml ) {
359 if ( !d->imageLocation.isEmpty() ) {
362 KPIMTextEdit::ImageWithNameList images =
static_cast< KPIMTextEdit::TextEdit*
>( mTextEdit )->imagesWithName();
363 foreach (
const KPIMTextEdit::ImageWithNamePtr &image, images ) {
364 sig.
addImage( image->image, image->name );
368 case Signature::FromCommand:
371 case Signature::FromFile:
374 case Signature::Disabled:
379 sig.setType( sigType );
397 KPIMTextEdit::TextEdit *
const pimEdit =
static_cast<KPIMTextEdit::TextEdit*
>( mTextEdit );
400 if ( sig.
type() == Signature::FromFile ) {
406 if ( sig.
type() == Signature::FromCommand ) {
413 void SignatureConfigurator::slotEnableEditButton(
const QString & url )
418 void SignatureConfigurator::slotEdit()
427 QString SignatureConfigurator::asCleanedHTML()
const
429 QString text = mTextEdit->toHtml();
443 void SignatureConfigurator::slotSetHtml()
445 if ( mHtmlCheck->
checkState() == Qt::Unchecked ) {
446 mHtmlCheck->
setText( i18n(
"&Use HTML" ) );
447 #ifndef QT_NO_TOOLBAR
448 mEditToolBar->setVisible(
false );
449 mEditToolBar->setEnabled(
false );
450 mFormatToolBar->setVisible(
false );
451 mFormatToolBar->setEnabled(
false );
453 mTextEdit->switchToPlainText();
454 d->inlinedHtml =
false;
457 mHtmlCheck->
setText( i18n(
"&Use HTML (disabling removes formatting)" ) );
458 d->inlinedHtml =
true;
459 #ifndef QT_NO_TOOLBAR
460 mEditToolBar->setVisible(
true );
461 mEditToolBar->setEnabled(
true );
462 mFormatToolBar->setVisible(
true );
463 mFormatToolBar->setEnabled(
true );
465 mTextEdit->enableRichTextMode();
471 d->imageLocation = path;
QString fileURL() const
Returns the file url which the user wants to use as a signature.
Don't add any text to the signature.
void setFileURL(const QString &url)
Set url for the file url part of the widget.
The signature is placed at the start of the textedit.
void KPIMIDENTITIES_DEPRECATED insertIntoTextEdit(KRichTextEdit *textEdit, Placement placement=End, bool addSeparator=true)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString commandURL() const
Returns the url of the command which the users wants to use as signature.
void setText(const QString &text)
Set the signature text and mark this signature as being of "inline text" type.
void setSignatureType(Signature::Type type)
Set the signature type to type.
void setImageLocation(const QString &path)
Sets the directory where the images used in the HTML signature will be stored.
QString & remove(int position, int n)
void setCommandURL(const QString &url)
Sets url as the command to execute.
void setImageLocation(const QString &path)
Sets the location where the copies of the signature images will be stored.
uint uoid() const
Unique Object Identifier for this identity.
void setBuddy(QWidget *buddy)
QString number(int n, int base)
void setEnabledSignature(bool enabled)
setEnabledSignature
bool isInlinedHtml() const
void setInlinedHtml(bool isHtml)
Sets the inlined signature to text or html.
void setSignatureEnabled(bool enable)
Use this to activate the signature.
void setObjectName(const QString &name)
Abstraction of a signature (aka "footer").
void setMargin(int margin)
User identity information.
This widget gives an interface so users can edit their signature.
Type
Type of signature (ie.
void setInlineText(const QString &text)
Make text the text for the signature.
void addStretch(int stretch)
QString absolutePath() const
void setSignature(const Signature &sig)
Convenience method.
SignatureConfigurator(QWidget *parent=0)
Constructor.
void setText(const QString &text)
QString fromLatin1(const char *str, int size)
Signature::Type signatureType() const
This returns the type of the signature, so that can be Disabled, Inline, fromFile, etc.
void setUrl(const QString &url, bool isExecutable=false)
Set the signature URL and mark this signature as being of "from file" resp.
Qt::CheckState checkState() const
QString toHtml(const QByteArray &encoding) const
void addImage(const QImage &image, const QString &imageName)
Adds the given image to the signature.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool isSignatureEnabled() const
Indicated if the user wants a signature.
void setCheckState(Qt::CheckState state)
virtual ~SignatureConfigurator()
destructor
Signature signature() const
Conveniece method.
void addLayout(QLayout *layout, int stretch)