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
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->setCompletionObject(
new KShellCompletion() );
257 q->mCommandEdit->setAutoDeleteCompletionObject(
true );
258 q->mCommandEdit->setWhatsThis(
259 i18n(
"You can add an arbitrary command here, either with or without path "
260 "depending on whether or not the command is in your Path. For every "
261 "new mail, KMail will execute the command and use what it outputs (to "
262 "standard output) as a signature. Usual commands for use with this "
263 "mechanism are \"fortune\" or \"ksig -random\"." ) );
264 label =
new QLabel( i18n(
"S&pecify command:" ), page );
265 label->setBuddy( q->mCommandEdit );
266 hlay->addWidget( label );
267 hlay->addWidget( q->mCommandEdit, 1 );
268 page_vlay->addStretch( 1 );
272 : QWidget( parent ), d( new Private( this ) )
284 return mEnableCheck->isChecked();
289 mEnableCheck->setChecked( enable );
294 switch ( mSourceCombo->currentIndex() ) {
295 case 0:
return Signature::Inlined;
296 case 1:
return Signature::FromFile;
297 case 2:
return Signature::FromCommand;
298 default:
return Signature::Disabled;
306 case Signature::Inlined: idx = 0;
break;
307 case Signature::FromFile: idx = 1;
break;
308 case Signature::FromCommand: idx = 2;
break;
309 default: idx = 0;
break;
312 mSourceCombo->setCurrentIndex( idx );
317 mTextEdit->setTextOrHtml( text );
322 QString file = mFileRequester->url().path();
326 if ( !file.isEmpty() && QFileInfo( file ).isRelative() ) {
327 file = QDir::home().absolutePath() + QDir::separator() + file;
334 mFileRequester->setUrl( QUrl(url) );
339 return mCommandEdit->text();
344 mCommandEdit->setText( url );
353 case Signature::Inlined:
355 sig.
setText( d->inlinedHtml ? asCleanedHTML() : mTextEdit->textOrHtml() );
356 if ( d->inlinedHtml ) {
357 if ( !d->imageLocation.isEmpty() ) {
360 KPIMTextEdit::ImageWithNameList images =
static_cast< KPIMTextEdit::TextEdit*
>( mTextEdit )->imagesWithName();
361 foreach (
const KPIMTextEdit::ImageWithNamePtr &image, images ) {
362 sig.
addImage( image->image, image->name );
366 case Signature::FromCommand:
369 case Signature::FromFile:
372 case Signature::Disabled:
377 sig.setType( sigType );
387 mHtmlCheck->setCheckState( Qt::Checked );
389 mHtmlCheck->setCheckState( Qt::Unchecked );
395 KPIMTextEdit::TextEdit *
const pimEdit =
static_cast<KPIMTextEdit::TextEdit*
>( mTextEdit );
398 if ( sig.
type() == Signature::FromFile ) {
404 if ( sig.
type() == Signature::FromCommand ) {
411 void SignatureConfigurator::slotEnableEditButton(
const QString & url )
413 mEditButton->setDisabled( url.trimmed().isEmpty() );
416 void SignatureConfigurator::slotEdit()
420 assert( !url.isEmpty() );
422 (void)KRun::runUrl( KUrl( url ), QString::fromLatin1(
"text/plain" ), this );
425 QString SignatureConfigurator::asCleanedHTML()
const
427 QString text = mTextEdit->toHtml();
430 QTextDocument textDocument;
431 QString html = textDocument.toHtml();
434 foreach (
const QString& line, html.split( QLatin1Char(
'\n') ) ) {
435 text.remove( line + QLatin1Char(
'\n') );
441 void SignatureConfigurator::slotSetHtml()
443 if ( mHtmlCheck->checkState() == Qt::Unchecked ) {
444 mHtmlCheck->setText( i18n(
"&Use HTML" ) );
445 #ifndef QT_NO_TOOLBAR
446 mEditToolBar->setVisible(
false );
447 mEditToolBar->setEnabled(
false );
448 mFormatToolBar->setVisible(
false );
449 mFormatToolBar->setEnabled(
false );
451 mTextEdit->switchToPlainText();
452 d->inlinedHtml =
false;
455 mHtmlCheck->setText( i18n(
"&Use HTML (disabling removes formatting)" ) );
456 d->inlinedHtml =
true;
457 #ifndef QT_NO_TOOLBAR
458 mEditToolBar->setVisible(
true );
459 mEditToolBar->setEnabled(
true );
460 mFormatToolBar->setVisible(
true );
461 mFormatToolBar->setEnabled(
true );
463 mTextEdit->enableRichTextMode();
469 d->imageLocation = path;
474 const QString dir = QString::fromLatin1(
"emailidentities/%1/" ).arg(
475 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.