20 #include "signatureconfigurator.h"
22 #include <tdelocale.h>
24 #include <klineedit.h>
25 #include <kurlrequester.h>
26 #include <kshellcompletion.h>
29 #include <tqcheckbox.h>
30 #include <tqcombobox.h>
32 #include <tqfileinfo.h>
35 #include <tqtextedit.h>
36 #include <tqwhatsthis.h>
37 #include <tqwidgetstack.h>
41 using namespace KMail;
45 SignatureConfigurator::SignatureConfigurator( TQWidget * parent,
const char * name )
46 : TQWidget( parent, name )
53 TQVBoxLayout * page_vlay;
55 vlay =
new TQVBoxLayout(
this, 0, KDialog::spacingHint(),
"main layout" );
58 mEnableCheck =
new TQCheckBox( i18n(
"&Enable signature"),
this );
59 TQWhatsThis::add(mEnableCheck,
60 i18n(
"Check this box if you want KMail to append a signature to mails "
61 "written with this identity."));
62 vlay->addWidget( mEnableCheck );
65 hlay =
new TQHBoxLayout( vlay );
66 mSourceCombo =
new TQComboBox(
false,
this );
67 TQWhatsThis::add(mSourceCombo,
68 i18n(
"Click on the widgets below to obtain help on the input methods."));
69 mSourceCombo->setEnabled(
false );
70 mSourceCombo->insertStringList( TQStringList()
71 << i18n(
"continuation of \"obtain signature text from\"",
73 << i18n(
"continuation of \"obtain signature text from\"",
75 << i18n(
"continuation of \"obtain signature text from\"",
78 label =
new TQLabel( mSourceCombo,
79 i18n(
"Obtain signature &text from:"),
this );
80 label->setEnabled(
false );
81 hlay->addWidget( label );
82 hlay->addWidget( mSourceCombo, 1 );
85 TQWidgetStack * widgetStack =
new TQWidgetStack(
this );
86 widgetStack->setEnabled(
false );
87 vlay->addWidget( widgetStack, 1 );
88 connect( mSourceCombo, TQ_SIGNAL(highlighted(
int)),
89 widgetStack, TQ_SLOT(raiseWidget(
int)) );
92 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
93 mSourceCombo, TQ_SLOT(setEnabled(
bool)) );
94 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
95 widgetStack, TQ_SLOT(setEnabled(
bool)) );
96 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
97 label, TQ_SLOT(setEnabled(
bool)) );
99 connect( mEnableCheck, TQ_SIGNAL(clicked()),
100 mEnableCheck, TQ_SLOT(setFocus()) );
104 mTextEdit =
new TQTextEdit( widgetStack );
105 TQWhatsThis::add(mTextEdit,
106 i18n(
"Use this field to enter an arbitrary static signature."));
107 widgetStack->addWidget( mTextEdit, pageno );
108 mTextEdit->setFont( TDEGlobalSettings::fixedFont() );
109 mTextEdit->setWordWrap( TQTextEdit::NoWrap );
110 mTextEdit->setTextFormat( TQt::PlainText );
112 widgetStack->raiseWidget( 0 );
116 page =
new TQWidget( widgetStack );
117 widgetStack->addWidget( page, pageno );
118 page_vlay =
new TQVBoxLayout( page, 0, KDialog::spacingHint() );
119 hlay =
new TQHBoxLayout( page_vlay );
120 mFileRequester =
new KURLRequester( page );
121 TQWhatsThis::add(mFileRequester,
122 i18n(
"Use this requester to specify a text file that contains your "
123 "signature. It will be read every time you create a new mail or "
124 "append a new signature."));
125 hlay->addWidget(
new TQLabel( mFileRequester,
126 i18n(
"S&pecify file:"), page ) );
127 hlay->addWidget( mFileRequester, 1 );
128 mFileRequester->button()->setAutoDefault(
false );
129 connect( mFileRequester, TQ_SIGNAL(textChanged(
const TQString &)),
130 this, TQ_SLOT(slotEnableEditButton(
const TQString &)) );
131 mEditButton =
new TQPushButton( i18n(
"Edit &File"), page );
132 TQWhatsThis::add(mEditButton, i18n(
"Opens the specified file in a text editor."));
133 connect( mEditButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotEdit()) );
134 mEditButton->setAutoDefault(
false );
135 mEditButton->setEnabled(
false );
136 hlay->addWidget( mEditButton );
137 page_vlay->addStretch( 1 );
141 page =
new TQWidget( widgetStack );
142 widgetStack->addWidget( page, pageno );
143 page_vlay =
new TQVBoxLayout( page, 0, KDialog::spacingHint() );
144 hlay =
new TQHBoxLayout( page_vlay );
145 mCommandEdit =
new KLineEdit( page );
146 mCommandEdit->setCompletionObject(
new KShellCompletion() );
147 mCommandEdit->setAutoDeleteCompletionObject(
true );
148 TQWhatsThis::add(mCommandEdit,
149 i18n(
"You can add an arbitrary command here, either with or without path "
150 "depending on whether or not the command is in your Path. For every "
151 "new mail, KMail will execute the command and use what it outputs (to "
152 "standard output) as a signature. Usual commands for use with this "
153 "mechanism are \"fortune\" or \"ksig -random\"."));
154 hlay->addWidget(
new TQLabel( mCommandEdit,
155 i18n(
"S&pecify command:"), page ) );
156 hlay->addWidget( mCommandEdit, 1 );
157 page_vlay->addStretch( 1 );
161 SignatureConfigurator::~SignatureConfigurator() {
165 bool SignatureConfigurator::isSignatureEnabled()
const {
166 return mEnableCheck->isChecked();
169 void SignatureConfigurator::setSignatureEnabled(
bool enable ) {
170 mEnableCheck->setChecked( enable );
173 Signature::Type SignatureConfigurator::signatureType()
const {
174 if ( !isSignatureEnabled() )
return Signature::Disabled;
176 switch ( mSourceCombo->currentItem() ) {
177 case 0:
return Signature::Inlined;
178 case 1:
return Signature::FromFile;
179 case 2:
return Signature::FromCommand;
180 default:
return Signature::Disabled;
184 void SignatureConfigurator::setSignatureType( Signature::Type type ) {
185 setSignatureEnabled( type != Signature::Disabled );
189 case Signature::Inlined: idx = 0;
break;
190 case Signature::FromFile: idx = 1;
break;
191 case Signature::FromCommand: idx = 2;
break;
192 default: idx = 0;
break;
195 mSourceCombo->setCurrentItem( idx );
198 TQString SignatureConfigurator::inlineText()
const {
199 return mTextEdit->text();
202 void SignatureConfigurator::setInlineText(
const TQString & text ) {
203 mTextEdit->setText( text );
206 TQString SignatureConfigurator::fileURL()
const {
207 TQString file = mFileRequester->url().stripWhiteSpace();
211 if ( !file.isEmpty() && TQFileInfo( file ).isRelative() )
212 file = TQDir::home().absPath() + TQDir::separator() + file;
217 void SignatureConfigurator::setFileURL(
const TQString & url ) {
218 mFileRequester->setURL( url );
221 TQString SignatureConfigurator::commandURL()
const {
222 return mCommandEdit->text();
225 void SignatureConfigurator::setCommandURL(
const TQString & url ) {
226 mCommandEdit->setText( url );
230 Signature SignatureConfigurator::signature()
const {
232 sig.setType( signatureType() );
233 sig.setText( inlineText() );
234 if ( signatureType() == Signature::FromCommand )
235 sig.setUrl( commandURL(),
true );
236 if ( signatureType() == Signature::FromFile )
237 sig.setUrl( fileURL(),
false );
241 void SignatureConfigurator::setSignature(
const Signature & sig ) {
242 setSignatureType( sig.type() );
243 setInlineText( sig.text() );
244 if ( sig.type() == Signature::FromFile )
245 setFileURL( sig.url() );
247 setFileURL( TQString() );
248 if ( sig.type() == Signature::FromCommand )
249 setCommandURL( sig.url() );
251 setCommandURL( TQString() );
254 void SignatureConfigurator::slotEnableEditButton(
const TQString & url ) {
255 mEditButton->setDisabled( url.stripWhiteSpace().isEmpty() );
258 void SignatureConfigurator::slotEdit() {
259 TQString url = fileURL();
261 assert( !url.isEmpty() );
263 (void)KRun::runURL( KURL( url ), TQString::fromLatin1(
"text/plain") );
268 #include "signatureconfigurator.moc"