21 #include "signatureconfigurator.h"
24 #include <kactioncollection.h>
28 #include <klineedit.h>
29 #include <kurlrequester.h>
30 #include <kshellcompletion.h>
34 #include <KStandardDirs>
36 #include <kpimtextedit/textedit.h>
46 #include <QStackedWidget>
48 #include <QVBoxLayout>
49 #include <QHBoxLayout>
53 using namespace KPIMIdentities;
55 namespace KPIMIdentities {
62 class SignatureConfigurator::Private
70 QString imageLocation;
75 :q( parent ), inlinedHtml( true )
79 void SignatureConfigurator::Private::init()
86 QVBoxLayout * page_vlay;
88 vlay =
new QVBoxLayout( q );
89 vlay->setObjectName(
"main layout" );
93 q->mEnableCheck =
new QCheckBox( i18n(
"&Enable signature" ), q );
94 q->mEnableCheck->setWhatsThis(
95 i18n(
"Check this box if you want KMail to append a signature to mails "
96 "written with this identity." ) );
97 vlay->addWidget( q->mEnableCheck );
100 hlay =
new QHBoxLayout();
101 vlay->addLayout( hlay );
102 q->mSourceCombo =
new KComboBox( q );
103 q->mSourceCombo->setEditable(
false );
104 q->mSourceCombo->setWhatsThis(
105 i18n(
"Click on the widgets below to obtain help on the input methods." ) );
106 q->mSourceCombo->setEnabled(
false );
107 q->mSourceCombo->addItems( QStringList()
108 << i18nc(
"continuation of \"obtain signature text from\"",
109 "Input Field Below" )
110 << i18nc(
"continuation of \"obtain signature text from\"",
112 << i18nc(
"continuation of \"obtain signature text from\"",
113 "Output of Command" ) );
114 label =
new QLabel( i18n(
"Obtain signature &text from:" ), q );
115 label->setBuddy( q->mSourceCombo );
116 label->setEnabled(
false );
117 hlay->addWidget( label );
118 hlay->addWidget( q->mSourceCombo, 1 );
121 QStackedWidget * widgetStack =
new QStackedWidget( q );
122 widgetStack->setEnabled(
false );
123 vlay->addWidget( widgetStack, 1 );
124 q->connect( q->mSourceCombo, SIGNAL(currentIndexChanged(
int)),
125 widgetStack, SLOT(setCurrentIndex(
int)) );
126 q->connect( q->mSourceCombo, SIGNAL(highlighted(
int)),
127 widgetStack, SLOT(setCurrentIndex(
int)) );
130 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
131 q->mSourceCombo, SLOT(setEnabled(
bool)) );
132 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
133 widgetStack, SLOT(setEnabled(
bool)) );
134 q->connect( q->mEnableCheck, SIGNAL(toggled(
bool)),
135 label, SLOT(setEnabled(
bool)) );
137 q->connect( q->mEnableCheck, SIGNAL(clicked()),
138 q->mEnableCheck, SLOT(setFocus()) );
142 page =
new QWidget( widgetStack );
143 widgetStack->insertWidget( pageno, page );
144 page_vlay =
new QVBoxLayout( page );
146 #ifndef QT_NO_TOOLBAR
147 q->mEditToolBar =
new KToolBar( q );
148 q->mEditToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
149 page_vlay->addWidget( q->mEditToolBar, 0 );
151 q->mFormatToolBar =
new KToolBar( q );
152 q->mFormatToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
153 page_vlay->addWidget( q->mFormatToolBar, 1 );
156 q->mTextEdit =
new KPIMTextEdit::TextEdit( q );
157 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableImageActions();
158 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertHtmlActions();
159 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertTableActions();
160 page_vlay->addWidget( q->mTextEdit, 2 );
161 q->mTextEdit->setWhatsThis( i18n(
"Use this field to enter an arbitrary static signature." ) );
163 q->mTextEdit->setRichTextSupport( KRichTextWidget::FullTextFormattingSupport |
164 KRichTextWidget::FullListSupport |
165 KRichTextWidget::SupportAlignment |
166 KRichTextWidget::SupportRuleLine |
167 KRichTextWidget::SupportHyperlinks |
168 KRichTextWidget::SupportFormatPainting );
171 KActionCollection *actionCollection =
new KActionCollection( q );
172 q->mTextEdit->createActions( actionCollection );
173 #ifndef QT_NO_TOOLBAR
174 q->mEditToolBar->addAction( actionCollection->action(
"format_text_bold" ) );
175 q->mEditToolBar->addAction( actionCollection->action(
"format_text_italic" ) );
176 q->mEditToolBar->addAction( actionCollection->action(
"format_text_underline" ) );
177 q->mEditToolBar->addAction( actionCollection->action(
"format_text_strikeout" ) );
178 q->mEditToolBar->addAction( actionCollection->action(
"format_text_foreground_color" ) );
179 q->mEditToolBar->addAction( actionCollection->action(
"format_text_background_color" ) );
180 q->mEditToolBar->addAction( actionCollection->action(
"format_font_family" ) );
181 q->mEditToolBar->addAction( actionCollection->action(
"format_font_size" ) );
182 q->mEditToolBar->addAction( actionCollection->action(
"format_reset" ) );
184 q->mFormatToolBar->addAction( actionCollection->action(
"format_list_style" ) );
185 q->mFormatToolBar->addAction( actionCollection->action(
"format_list_indent_more" ) );
186 q->mFormatToolBar->addAction( actionCollection->action(
"format_list_indent_less" ) );
187 q->mFormatToolBar->addAction( actionCollection->action(
"format_list_indent_less" ) );
188 q->mFormatToolBar->addSeparator();
190 q->mFormatToolBar->addAction( actionCollection->action(
"format_align_left" ) );
191 q->mFormatToolBar->addAction( actionCollection->action(
"format_align_center" ) );
192 q->mFormatToolBar->addAction( actionCollection->action(
"format_align_right" ) );
193 q->mFormatToolBar->addAction( actionCollection->action(
"format_align_justify" ) );
194 q->mFormatToolBar->addSeparator();
196 q->mFormatToolBar->addAction( actionCollection->action(
"insert_horizontal_rule" ) );
197 q->mFormatToolBar->addAction( actionCollection->action(
"manage_link" ) );
198 q->mFormatToolBar->addAction( actionCollection->action(
"format_painter" ) );
200 q->mFormatToolBar->addSeparator();
201 q->mFormatToolBar->addAction( actionCollection->action(
"add_image" ) );
202 q->mFormatToolBar->addSeparator();
203 q->mFormatToolBar->addAction( actionCollection->action(
"insert_html" ) );
204 q->mFormatToolBar->addAction( actionCollection->action(
"insert_table" ) );
207 hlay =
new QHBoxLayout();
208 page_vlay->addLayout( hlay );
209 q->mHtmlCheck =
new QCheckBox( i18n(
"&Use HTML" ), page );
210 q->connect( q->mHtmlCheck, SIGNAL(clicked()),
211 q, SLOT(slotSetHtml()) );
212 hlay->addWidget( q->mHtmlCheck );
215 widgetStack->setCurrentIndex( 0 );
219 page =
new QWidget( widgetStack );
220 widgetStack->insertWidget( pageno, page );
221 page_vlay =
new QVBoxLayout( page );
222 page_vlay->setMargin( 0 );
223 hlay =
new QHBoxLayout();
224 page_vlay->addLayout( hlay );
225 q->mFileRequester =
new KUrlRequester( page );
226 q->mFileRequester->setWhatsThis(
227 i18n(
"Use this requester to specify a text file that contains your "
228 "signature. It will be read every time you create a new mail or "
229 "append a new signature." ) );
230 label =
new QLabel( i18n(
"S&pecify file:" ), page );
231 label->setBuddy( q->mFileRequester );
232 hlay->addWidget( label );
233 hlay->addWidget( q->mFileRequester, 1 );
234 q->mFileRequester->button()->setAutoDefault(
false );
235 q->connect( q->mFileRequester, SIGNAL(textChanged(QString)),
236 q, SLOT(slotEnableEditButton(QString)) );
237 q->mEditButton =
new QPushButton( i18n(
"Edit &File" ), page );
238 q->mEditButton->setWhatsThis( i18n(
"Opens the specified file in a text editor." ) );
239 q->connect( q->mEditButton, SIGNAL(clicked()),
240 q, SLOT(slotEdit()) );
241 q->mEditButton->setAutoDefault(
false );
242 q->mEditButton->setEnabled(
false );
243 hlay->addWidget( q->mEditButton );
244 page_vlay->addStretch( 1 );
248 page =
new QWidget( widgetStack );
249 widgetStack->insertWidget( pageno, page );
250 page_vlay =
new QVBoxLayout( page );
251 page_vlay->setMargin( 0 );
252 hlay =
new QHBoxLayout();
253 page_vlay->addLayout( hlay );
254 q->mCommandEdit =
new KLineEdit( page );
255 q->mCommandEdit->setCompletionObject(
new KShellCompletion() );
256 q->mCommandEdit->setAutoDeleteCompletionObject(
true );
257 q->mCommandEdit->setWhatsThis(
258 i18n(
"You can add an arbitrary command here, either with or without path "
259 "depending on whether or not the command is in your Path. For every "
260 "new mail, KMail will execute the command and use what it outputs (to "
261 "standard output) as a signature. Usual commands for use with this "
262 "mechanism are \"fortune\" or \"ksig -random\"." ) );
263 label =
new QLabel( i18n(
"S&pecify command:" ), page );
264 label->setBuddy( q->mCommandEdit );
265 hlay->addWidget( label );
266 hlay->addWidget( q->mCommandEdit, 1 );
267 page_vlay->addStretch( 1 );
271 : QWidget( parent ), d( new Private( this ) )
283 return mEnableCheck->isChecked();
288 mEnableCheck->setChecked( enable );
293 switch ( mSourceCombo->currentIndex() ) {
294 case 0:
return Signature::Inlined;
295 case 1:
return Signature::FromFile;
296 case 2:
return Signature::FromCommand;
297 default:
return Signature::Disabled;
305 case Signature::Inlined: idx = 0;
break;
306 case Signature::FromFile: idx = 1;
break;
307 case Signature::FromCommand: idx = 2;
break;
308 default: idx = 0;
break;
311 mSourceCombo->setCurrentIndex( idx );
316 mTextEdit->setTextOrHtml( text );
321 QString file = mFileRequester->url().path();
325 if ( !file.isEmpty() && QFileInfo( file ).isRelative() ) {
326 file = QDir::home().absolutePath() + QDir::separator() + file;
333 mFileRequester->setUrl( QUrl(url) );
338 return mCommandEdit->text();
343 mCommandEdit->setText( url );
352 case Signature::Inlined:
354 sig.
setText( d->inlinedHtml ? asCleanedHTML() : mTextEdit->textOrHtml() );
355 if ( d->inlinedHtml ) {
356 if ( !d->imageLocation.isEmpty() ) {
359 KPIMTextEdit::ImageWithNameList images =
static_cast< KPIMTextEdit::TextEdit*
>( mTextEdit )->imagesWithName();
360 foreach (
const KPIMTextEdit::ImageWithNamePtr &image, images ) {
361 sig.
addImage( image->image, image->name );
365 case Signature::FromCommand:
368 case Signature::FromFile:
371 case Signature::Disabled:
376 sig.setType( sigType );
386 mHtmlCheck->setCheckState( Qt::Checked );
388 mHtmlCheck->setCheckState( Qt::Unchecked );
394 KPIMTextEdit::TextEdit *
const pimEdit =
static_cast<KPIMTextEdit::TextEdit*
>( mTextEdit );
397 if ( sig.
type() == Signature::FromFile ) {
403 if ( sig.
type() == Signature::FromCommand ) {
410 void SignatureConfigurator::slotEnableEditButton(
const QString & url )
412 mEditButton->setDisabled( url.trimmed().isEmpty() );
415 void SignatureConfigurator::slotEdit()
419 assert( !url.isEmpty() );
421 (void)KRun::runUrl( KUrl( url ), QString::fromLatin1(
"text/plain" ), this );
424 QString SignatureConfigurator::asCleanedHTML()
const
426 QString text = mTextEdit->toHtml();
429 QTextDocument textDocument;
430 QString html = textDocument.toHtml();
433 foreach (
const QString& line, html.split(
'\n' ) ) {
434 text.remove( line +
'\n' );
440 void SignatureConfigurator::slotSetHtml()
442 if ( mHtmlCheck->checkState() == Qt::Unchecked ) {
443 mHtmlCheck->setText( i18n(
"&Use HTML" ) );
444 #ifndef QT_NO_TOOLBAR
445 mEditToolBar->setVisible(
false );
446 mEditToolBar->setEnabled(
false );
447 mFormatToolBar->setVisible(
false );
448 mFormatToolBar->setEnabled(
false );
450 mTextEdit->switchToPlainText();
451 d->inlinedHtml =
false;
454 mHtmlCheck->setText( i18n(
"&Use HTML (disabling removes formatting)" ) );
455 d->inlinedHtml =
true;
456 #ifndef QT_NO_TOOLBAR
457 mEditToolBar->setVisible(
true );
458 mEditToolBar->setEnabled(
true );
459 mFormatToolBar->setVisible(
true );
460 mFormatToolBar->setEnabled(
true );
462 mTextEdit->enableRichTextMode();
468 d->imageLocation = path;
473 const QString dir = QString(
"emailidentities/%1/" ).arg(
474 QString::number( identity.
uoid() ) );
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 insertIntoTextEdit(KRichTextEdit *textEdit, Placement placement=End, bool addSeparator=true)
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.
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 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.
Abstraction of a signature (aka "footer").
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 setSignature(const Signature &sig)
Convenience method.
SignatureConfigurator(QWidget *parent=0)
Constructor.
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.
void addImage(const QImage &image, const QString &imageName)
Adds the given image to the signature.
bool isSignatureEnabled() const
Indicated if the user wants a signature.
virtual ~SignatureConfigurator()
destructor
Signature signature() const
Conveniece method.