21#include "signatureconfigurator.h"
24#include <kactioncollection.h>
25#include <klocalizedstring.h>
29#include <kurlrequester.h>
30#include <kshellcompletion.h>
35#include <KStandardDirs>
37#include <kpimtextedit/textedit.h>
47#include <QStackedWidget>
54using namespace KPIMIdentities;
56namespace KPIMIdentities {
63class SignatureConfigurator::Private
71 QString imageLocation;
76 :q( parent ), inlinedHtml( true )
80void SignatureConfigurator::Private::init()
87 QVBoxLayout * page_vlay;
89 vlay =
new QVBoxLayout( q );
90 vlay->setObjectName( QLatin1String(
"main layout") );
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." ) );
98 vlay->addWidget( q->mEnableCheck );
101 hlay =
new QHBoxLayout();
102 vlay->addLayout( hlay );
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 );
108 q->mSourceCombo->addItems( QStringList()
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 );
116 label->setBuddy( q->mSourceCombo );
117 label->setEnabled(
false );
118 hlay->addWidget( label );
119 hlay->addWidget( q->mSourceCombo, 1 );
122 QStackedWidget * widgetStack =
new QStackedWidget( q );
123 widgetStack->setEnabled(
false );
124 vlay->addWidget( widgetStack, 1 );
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 );
144 widgetStack->insertWidget( pageno, page );
145 page_vlay =
new QVBoxLayout( page );
146 page_vlay->setMargin(0);
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();
162 page_vlay->addWidget( q->mTextEdit, 2 );
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 );
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" )) );
209 hlay =
new QHBoxLayout();
210 page_vlay->addLayout( hlay );
211 q->mHtmlCheck =
new QCheckBox( i18n(
"&Use HTML" ), page );
212 q->connect( q->mHtmlCheck, SIGNAL(clicked()),
213 q, SLOT(slotSetHtml()) );
214 hlay->addWidget( q->mHtmlCheck );
217 widgetStack->setCurrentIndex( 0 );
221 page =
new QWidget( widgetStack );
222 widgetStack->insertWidget( pageno, page );
223 page_vlay =
new QVBoxLayout( page );
224 page_vlay->setMargin( 0 );
225 hlay =
new QHBoxLayout();
226 page_vlay->addLayout( hlay );
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 );
234 hlay->addWidget( label );
235 hlay->addWidget( q->mFileRequester, 1 );
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 );
245 hlay->addWidget( q->mEditButton );
246 page_vlay->addStretch( 1 );
250 page =
new QWidget( widgetStack );
251 widgetStack->insertWidget( pageno, page );
252 page_vlay =
new QVBoxLayout( page );
253 page_vlay->setMargin( 0 );
254 hlay =
new QHBoxLayout();
255 page_vlay->addLayout( hlay );
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 );
267 label->setBuddy( q->mCommandEdit );
268 hlay->addWidget( label );
269 hlay->addWidget( q->mCommandEdit, 1 );
270 page_vlay->addStretch( 1 );
274 : QWidget( parent ), d( new Private( this ) )
286 return mEnableCheck->isChecked();
291 mEnableCheck->setChecked( enable );
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();
328 if ( !file.isEmpty() && QFileInfo( file ).isRelative() ) {
329 file = QDir::home().absolutePath() + QDir::separator() + file;
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 );
389 mHtmlCheck->setCheckState( Qt::Checked );
391 mHtmlCheck->setCheckState( Qt::Unchecked );
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 )
415 mEditButton->setDisabled( url.trimmed().isEmpty() );
418 void SignatureConfigurator::slotEdit()
422 assert( !url.isEmpty() );
424 (void)KRun::runUrl( KUrl( url ), QString::fromLatin1(
"text/plain" ), this );
427 QString SignatureConfigurator::asCleanedHTML()
const
429 QString text = mTextEdit->toHtml();
432 QTextDocument textDocument;
433 QString html = textDocument.toHtml();
436 foreach (
const QString& line, html.split( QLatin1Char(
'\n') ) ) {
437 text.remove( line + QLatin1Char(
'\n') );
443 void SignatureConfigurator::slotSetHtml()
445 if ( mHtmlCheck->checkState() == Qt::Unchecked ) {
446 mHtmlCheck->setText( i18n(
"&Use HTML" ) );
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;
460 mEditToolBar->setVisible(
true );
461 mEditToolBar->setEnabled(
true );
462 mFormatToolBar->setVisible(
true );
463 mFormatToolBar->setEnabled(
true );
465 mTextEdit->enableRichTextMode();
471 d->imageLocation = path;
476 const QString dir = QString::fromLatin1(
"emailidentities/%1/" ).arg(
477 QString::number( identity.
uoid() ) );
User identity information.
uint uoid() const
Unique Object Identifier for this identity.
This widget gives an interface so users can edit their signature.
bool isSignatureEnabled() const
Indicated if the user wants a signature.
Signature::Type signatureType() const
This returns the type of the signature, so that can be Disabled, Inline, fromFile,...
SignatureConfigurator(QWidget *parent=0)
Constructor.
void setCommandURL(const QString &url)
Sets url as the command to execute.
void setFileURL(const QString &url)
Set url for the file url part of the widget.
QString commandURL() const
Returns the url of the command which the users wants to use as signature.
Signature signature() const
Conveniece method.
void setImageLocation(const QString &path)
Sets the directory where the images used in the HTML signature will be stored.
void setInlineText(const QString &text)
Make text the text for the signature.
QString fileURL() const
Returns the file url which the user wants to use as a signature.
void setSignature(const Signature &sig)
Convenience method.
void setSignatureEnabled(bool enable)
Use this to activate the signature.
virtual ~SignatureConfigurator()
destructor
void setSignatureType(Signature::Type type)
Set the signature type to type.
Abstraction of a signature (aka "footer").
void KPIMIDENTITIES_DEPRECATED insertIntoTextEdit(KRichTextEdit *textEdit, Placement placement=End, bool addSeparator=true)
void setText(const QString &text)
Set the signature text and mark this signature as being of "inline text" type.
@ Start
The signature is placed at the start of the textedit.
void setImageLocation(const QString &path)
Sets the location where the copies of the signature images will be stored.
@ AddNothing
Don't add any text to the signature.
void setInlinedHtml(bool isHtml)
Sets the inlined signature to text or html.
void setUrl(const QString &url, bool isExecutable=false)
Set the signature URL and mark this signature as being of "from file" resp.
bool isInlinedHtml() const
void setEnabledSignature(bool enabled)
setEnabledSignature
void addImage(const QImage &image, const QString &imageName)
Adds the given image to the signature.
Type
Type of signature (ie.