00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#ifdef HAVE_CONFIG_H
00017
#include <config.h>
00018
#endif
00019
00020
#include "signatureconfigurator.h"
00021
00022
#include <klocale.h>
00023
#include <kdialog.h>
00024
#include <klineedit.h>
00025
#include <kurlrequester.h>
00026
#include <kshellcompletion.h>
00027
#include <krun.h>
00028
00029
#include <qlabel.h>
00030
#include <qlayout.h>
00031
#include <qcheckbox.h>
00032
#include <qcombobox.h>
00033
#include <qwidgetstack.h>
00034
#include <qtextedit.h>
00035
00036
#include <assert.h>
00037
00038
using namespace KMail;
00039
00040
namespace KMail {
00041
00042 SignatureConfigurator::SignatureConfigurator( QWidget * parent,
const char * name )
00043 : QWidget( parent, name )
00044 {
00045
00046 QLabel * label;
00047 QWidget * page;
00048 QHBoxLayout * hlay;
00049 QVBoxLayout * vlay;
00050 QVBoxLayout * page_vlay;
00051
00052 vlay =
new QVBoxLayout(
this, 0, KDialog::spacingHint(),
"main layout" );
00053
00054
00055 mEnableCheck =
new QCheckBox( i18n(
"&Enable signature"),
this );
00056 vlay->addWidget( mEnableCheck );
00057
00058
00059 hlay =
new QHBoxLayout( vlay );
00060 mSourceCombo =
new QComboBox(
false,
this );
00061 mSourceCombo->setEnabled(
false );
00062 mSourceCombo->insertStringList( QStringList()
00063 << i18n(
"continuation of \"obtain signature text from\"",
00064
"File")
00065 << i18n(
"continuation of \"obtain signature text from\"",
00066
"Output of Command")
00067 << i18n(
"continuation of \"obtain signature text from\"",
00068
"Input Field Below") );
00069 label =
new QLabel( mSourceCombo,
00070 i18n(
"Obtain signature &text from:"),
this );
00071 label->setEnabled(
false );
00072 hlay->addWidget( label );
00073 hlay->addWidget( mSourceCombo, 1 );
00074
00075
00076 QWidgetStack * widgetStack =
new QWidgetStack(
this );
00077 widgetStack->setEnabled(
false );
00078 vlay->addWidget( widgetStack, 1 );
00079 connect( mSourceCombo, SIGNAL(highlighted(
int)),
00080 widgetStack, SLOT(raiseWidget(
int)) );
00081
00082
00083 connect( mEnableCheck, SIGNAL(toggled(
bool)),
00084 mSourceCombo, SLOT(setEnabled(
bool)) );
00085 connect( mEnableCheck, SIGNAL(toggled(
bool)),
00086 widgetStack, SLOT(setEnabled(
bool)) );
00087 connect( mEnableCheck, SIGNAL(toggled(
bool)),
00088 label, SLOT(setEnabled(
bool)) );
00089
00090 connect( mEnableCheck, SIGNAL(clicked()),
00091 mEnableCheck, SLOT(setFocus()) );
00092
00093
00094
int pageno = 0;
00095 page =
new QWidget( widgetStack );
00096 widgetStack->addWidget( page, pageno );
00097 page_vlay =
new QVBoxLayout( page, 0, KDialog::spacingHint() );
00098 hlay =
new QHBoxLayout( page_vlay );
00099 mFileRequester =
new KURLRequester( page );
00100 hlay->addWidget(
new QLabel( mFileRequester,
00101 i18n(
"S&pecify file:"), page ) );
00102 hlay->addWidget( mFileRequester, 1 );
00103 mFileRequester->button()->setAutoDefault(
false );
00104 connect( mFileRequester, SIGNAL(textChanged(
const QString &)),
00105
this, SLOT(slotEnableEditButton(
const QString &)) );
00106 mEditButton =
new QPushButton( i18n(
"Edit &File"), page );
00107 connect( mEditButton, SIGNAL(clicked()), SLOT(slotEdit()) );
00108 mEditButton->setAutoDefault(
false );
00109 mEditButton->setEnabled(
false );
00110 hlay->addWidget( mEditButton );
00111 page_vlay->addStretch( 1 );
00112
00113
00114 ++pageno;
00115 page =
new QWidget( widgetStack );
00116 widgetStack->addWidget( page, pageno );
00117 page_vlay =
new QVBoxLayout( page, 0, KDialog::spacingHint() );
00118 hlay =
new QHBoxLayout( page_vlay );
00119 mCommandEdit =
new KLineEdit( page );
00120 mCommandEdit->setCompletionObject(
new KShellCompletion() );
00121 mCommandEdit->setAutoDeleteCompletionObject(
true );
00122 hlay->addWidget(
new QLabel( mCommandEdit,
00123 i18n(
"S&pecify command:"), page ) );
00124 hlay->addWidget( mCommandEdit, 1 );
00125 page_vlay->addStretch( 1 );
00126
00127
00128 ++pageno;
00129 mTextEdit =
new QTextEdit( widgetStack );
00130 widgetStack->addWidget( mTextEdit, pageno );
00131 mTextEdit->setFont( KGlobalSettings::fixedFont() );
00132 mTextEdit->setWordWrap( QTextEdit::NoWrap );
00133 mTextEdit->setTextFormat( Qt::PlainText );
00134
00135 widgetStack->raiseWidget( 0 );
00136
00137 }
00138
00139 SignatureConfigurator::~SignatureConfigurator() {
00140
00141 }
00142
00143
bool SignatureConfigurator::isSignatureEnabled()
const {
00144
return mEnableCheck->isChecked();
00145 }
00146
00147
void SignatureConfigurator::setSignatureEnabled(
bool enable ) {
00148 mEnableCheck->setChecked( enable );
00149 }
00150
00151
Signature::Type SignatureConfigurator::signatureType()
const {
00152
if ( !isSignatureEnabled() )
return Signature::Disabled;
00153
00154
switch ( mSourceCombo->currentItem() ) {
00155
case 0:
return Signature::FromFile;
00156
case 1:
return Signature::FromCommand;
00157
case 2:
return Signature::Inlined;
00158
default:
return Signature::Disabled;
00159 }
00160 }
00161
00162
void SignatureConfigurator::setSignatureType( Signature::Type type ) {
00163 setSignatureEnabled( type != Signature::Disabled );
00164
00165
int idx = 0;
00166
switch( type ) {
00167
case Signature::Inlined: idx = 2;
break;
00168
case Signature::FromCommand: idx = 1;
break;
00169
case Signature::FromFile:
00170
default: idx = 0;
break;
00171 };
00172
00173 mSourceCombo->setCurrentItem( idx );
00174 }
00175
00176 QString SignatureConfigurator::inlineText()
const {
00177
return mTextEdit->text();
00178 }
00179
00180
void SignatureConfigurator::setInlineText(
const QString & text ) {
00181 mTextEdit->setText( text );
00182 }
00183
00184 QString SignatureConfigurator::fileURL()
const {
00185
return mFileRequester->url();
00186 }
00187
00188
void SignatureConfigurator::setFileURL(
const QString & url ) {
00189 mFileRequester->setURL( url );
00190 }
00191
00192 QString SignatureConfigurator::commandURL()
const {
00193
return mCommandEdit->text();
00194 }
00195
00196
void SignatureConfigurator::setCommandURL(
const QString & url ) {
00197 mCommandEdit->setText( url );
00198 }
00199
00200
00201
Signature SignatureConfigurator::signature()
const {
00202
switch ( signatureType() ) {
00203
case Signature::Inlined:
00204
return Signature( inlineText() );
00205
case Signature::FromCommand:
00206
return Signature( commandURL(),
true );
00207
case Signature::FromFile:
00208
return Signature( fileURL(),
false );
00209
case Signature::Disabled:
00210
default:
00211
return Signature();
00212 };
00213 }
00214
00215
void SignatureConfigurator::setSignature(
const Signature & sig ) {
00216 setSignatureType( sig.
type() );
00217
if ( sig.
type() == Signature::Inlined )
00218 setInlineText( sig.
text() );
00219
else
00220 setInlineText( QString::null );
00221
if ( sig.
type() == Signature::FromFile )
00222 setFileURL( sig.
url() );
00223
else
00224 setFileURL( QString::null );
00225
if ( sig.
type() == Signature::FromCommand )
00226 setCommandURL( sig.
url() );
00227
else
00228 setCommandURL( QString::null );
00229 }
00230
00231
void SignatureConfigurator::slotEnableEditButton(
const QString & url ) {
00232 mEditButton->setDisabled( url.stripWhiteSpace().isEmpty() );
00233 }
00234
00235
void SignatureConfigurator::slotEdit() {
00236 QString url = mFileRequester->url().stripWhiteSpace();
00237
00238 assert( !url.isEmpty() );
00239
00240 (
void)KRun::runURL( KURL( url ), QString::fromLatin1(
"text/plain") );
00241 }
00242
00243 }
00244
00245
#include "signatureconfigurator.moc"