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>
63 class SignatureConfigurator::Private
71 QString imageLocation;
76 :q( parent ), inlinedHtml( true )
80 void 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 );
147 #ifndef QT_NO_TOOLBAR
148 q->mEditToolBar =
new KToolBar( q );
149 q->mEditToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
150 page_vlay->addWidget( q->mEditToolBar, 0 );
152 q->mFormatToolBar =
new KToolBar( q );
153 q->mFormatToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );
154 page_vlay->addWidget( q->mFormatToolBar, 1 );
157 q->mTextEdit =
new KPIMTextEdit::TextEdit( q );
158 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableImageActions();
159 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertHtmlActions();
160 static_cast<KPIMTextEdit::TextEdit*
>( q->mTextEdit )->enableInsertTableActions();
161 page_vlay->addWidget( q->mTextEdit, 2 );
162 q->mTextEdit->setWhatsThis( i18n(
"Use this field to enter an arbitrary static signature." ) );
164 q->mTextEdit->setRichTextSupport( KRichTextWidget::FullTextFormattingSupport |
165 KRichTextWidget::FullListSupport |
166 KRichTextWidget::SupportAlignment |
167 KRichTextWidget::SupportRuleLine |
168 KRichTextWidget::SupportHyperlinks |
169 KRichTextWidget::SupportFormatPainting );
172 KActionCollection *actionCollection =
new KActionCollection( q );
173 q->mTextEdit->createActions( actionCollection );
174 #ifndef QT_NO_TOOLBAR
175 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_bold") ) );
176 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_italic") ) );
177 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_underline") ) );
178 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_strikeout") ) );
179 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_foreground_color") ) );
180 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_text_background_color") ) );
181 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_font_family") ) );
182 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_font_size") ) );
183 q->mEditToolBar->addAction( actionCollection->action( QLatin1String(
"format_reset") ) );
185 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_list_style") ) );
186 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_list_indent_more") ) );
187 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_list_indent_less") ) );
188 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_list_indent_less") ) );
189 q->mFormatToolBar->addSeparator();
191 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_align_left") ) );
192 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_align_center") ) );
193 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_align_right") ) );
194 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_align_justify") ) );
195 q->mFormatToolBar->addSeparator();
197 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"insert_horizontal_rule") ) );
198 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"manage_link") ) );
199 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"format_painter") ) );
201 q->mFormatToolBar->addSeparator();
202 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"add_image") ) );
203 q->mFormatToolBar->addSeparator();
204 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"insert_html") ) );
205 q->mFormatToolBar->addAction( actionCollection->action( QLatin1String(
"insert_table" )) );
208 hlay =
new QHBoxLayout();
209 page_vlay->addLayout( hlay );
210 q->mHtmlCheck =
new QCheckBox( i18n(
"&Use HTML" ), page );
211 q->connect( q->mHtmlCheck, SIGNAL(clicked()),
212 q, SLOT(slotSetHtml()) );
213 hlay->addWidget( q->mHtmlCheck );
216 widgetStack->setCurrentIndex( 0 );
220 page =
new QWidget( widgetStack );
221 widgetStack->insertWidget( pageno, page );
222 page_vlay =
new QVBoxLayout( page );
223 page_vlay->setMargin( 0 );
224 hlay =
new QHBoxLayout();
225 page_vlay->addLayout( hlay );
226 q->mFileRequester =
new KUrlRequester( page );
227 q->mFileRequester->setWhatsThis(
228 i18n(
"Use this requester to specify a text file that contains your "
229 "signature. It will be read every time you create a new mail or "
230 "append a new signature." ) );
231 label =
new QLabel( i18n(
"S&pecify file:" ), page );
232 label->setBuddy( q->mFileRequester );
233 hlay->addWidget( label );
234 hlay->addWidget( q->mFileRequester, 1 );
235 q->mFileRequester->button()->setAutoDefault(
false );
236 q->connect( q->mFileRequester, SIGNAL(textChanged(QString)),
237 q, SLOT(slotEnableEditButton(QString)) );
238 q->mEditButton =
new QPushButton( i18n(
"Edit &File" ), page );
239 q->mEditButton->setWhatsThis( i18n(
"Opens the specified file in a text editor." ) );
240 q->connect( q->mEditButton, SIGNAL(clicked()),
241 q, SLOT(slotEdit()) );
242 q->mEditButton->setAutoDefault(
false );
243 q->mEditButton->setEnabled(
false );
244 hlay->addWidget( q->mEditButton );
245 page_vlay->addStretch( 1 );
249 page =
new QWidget( widgetStack );
250 widgetStack->insertWidget( pageno, page );
251 page_vlay =
new QVBoxLayout( page );
252 page_vlay->setMargin( 0 );
253 hlay =
new QHBoxLayout();
254 page_vlay->addLayout( hlay );
255 q->mCommandEdit =
new KLineEdit( page );
256 q->mCommandEdit->setClearButtonShown(
true );
257 q->mCommandEdit->setCompletionObject(
new KShellCompletion() );
258 q->mCommandEdit->setAutoDeleteCompletionObject(
true );
259 q->mCommandEdit->setWhatsThis(
260 i18n(
"You can add an arbitrary command here, either with or without path "
261 "depending on whether or not the command is in your Path. For every "
262 "new mail, KMail will execute the command and use what it outputs (to "
263 "standard output) as a signature. Usual commands for use with this "
264 "mechanism are \"fortune\" or \"ksig -random\"." ) );
265 label =
new QLabel( i18n(
"S&pecify command:" ), page );
266 label->setBuddy( q->mCommandEdit );
267 hlay->addWidget( label );
268 hlay->addWidget( q->mCommandEdit, 1 );
269 page_vlay->addStretch( 1 );
273 : QWidget( parent ), d( new Private( this ) )
285 return mEnableCheck->isChecked();
290 mEnableCheck->setChecked( enable );
295 switch ( mSourceCombo->currentIndex() ) {
296 case 0:
return Signature::Inlined;
297 case 1:
return Signature::FromFile;
298 case 2:
return Signature::FromCommand;
299 default:
return Signature::Disabled;
307 case Signature::Inlined: idx = 0;
break;
308 case Signature::FromFile: idx = 1;
break;
309 case Signature::FromCommand: idx = 2;
break;
310 default: idx = 0;
break;
313 mSourceCombo->setCurrentIndex( idx );
318 mTextEdit->setTextOrHtml( text );
323 QString file = mFileRequester->url().path();
327 if ( !file.isEmpty() && QFileInfo( file ).isRelative() ) {
328 file = QDir::home().absolutePath() + QDir::separator() + file;
335 mFileRequester->setUrl( QUrl(url) );
340 return mCommandEdit->text();
345 mCommandEdit->setText( url );
354 case Signature::Inlined:
356 sig.
setText( d->inlinedHtml ? asCleanedHTML() : mTextEdit->textOrHtml() );
357 if ( d->inlinedHtml ) {
358 if ( !d->imageLocation.isEmpty() ) {
361 KPIMTextEdit::ImageWithNameList images =
static_cast< KPIMTextEdit::TextEdit*
>( mTextEdit )->imagesWithName();
362 foreach (
const KPIMTextEdit::ImageWithNamePtr &image, images ) {
363 sig.
addImage( image->image, image->name );
367 case Signature::FromCommand:
370 case Signature::FromFile:
373 case Signature::Disabled:
378 sig.setType( sigType );
388 mHtmlCheck->setCheckState( Qt::Checked );
390 mHtmlCheck->setCheckState( Qt::Unchecked );
396 KPIMTextEdit::TextEdit *
const pimEdit =
static_cast<KPIMTextEdit::TextEdit*
>( mTextEdit );
399 if ( sig.
type() == Signature::FromFile ) {
405 if ( sig.
type() == Signature::FromCommand ) {
412 void SignatureConfigurator::slotEnableEditButton(
const QString & url )
414 mEditButton->setDisabled( url.trimmed().isEmpty() );
417 void SignatureConfigurator::slotEdit()
421 assert( !url.isEmpty() );
423 (void)KRun::runUrl( KUrl( url ), QString::fromLatin1(
"text/plain" ), this );
426 QString SignatureConfigurator::asCleanedHTML()
const
428 QString text = mTextEdit->toHtml();
431 QTextDocument textDocument;
432 QString html = textDocument.toHtml();
435 foreach (
const QString& line, html.split( QLatin1Char(
'\n') ) ) {
436 text.remove( line + QLatin1Char(
'\n') );
442 void SignatureConfigurator::slotSetHtml()
444 if ( mHtmlCheck->checkState() == Qt::Unchecked ) {
445 mHtmlCheck->setText( i18n(
"&Use HTML" ) );
446 #ifndef QT_NO_TOOLBAR
447 mEditToolBar->setVisible(
false );
448 mEditToolBar->setEnabled(
false );
449 mFormatToolBar->setVisible(
false );
450 mFormatToolBar->setEnabled(
false );
452 mTextEdit->switchToPlainText();
453 d->inlinedHtml =
false;
456 mHtmlCheck->setText( i18n(
"&Use HTML (disabling removes formatting)" ) );
457 d->inlinedHtml =
true;
458 #ifndef QT_NO_TOOLBAR
459 mEditToolBar->setVisible(
true );
460 mEditToolBar->setEnabled(
true );
461 mFormatToolBar->setVisible(
true );
462 mFormatToolBar->setEnabled(
true );
464 mTextEdit->enableRichTextMode();
470 d->imageLocation = path;
475 const QString dir = QString::fromLatin1(
"emailidentities/%1/" ).arg(
476 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 KPIMIDENTITIES_DEPRECATED 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.