37 #include "xfaceconfigurator.h"
39 #include <kactivelabel.h>
41 #include <tdefiledialog.h>
42 #include <tdeglobalsettings.h>
44 #include <tdelocale.h>
45 #include <tdemessagebox.h>
47 #include <tdeio/netaccess.h>
48 using namespace TDEIO;
51 #include <tdeabc/stdaddressbook.h>
52 #include <tdeabc/addressee.h>
53 using namespace TDEABC;
56 #include <tqcheckbox.h>
57 #include <tqcombobox.h>
61 #include <tqpushbutton.h>
62 #include <tqwhatsthis.h>
63 #include <tqwidgetstack.h>
68 using namespace KMail;
73 XFaceConfigurator::XFaceConfigurator( TQWidget * parent,
const char * name )
74 : TQWidget( parent, name )
79 KActiveLabel * label2;
83 TQVBoxLayout * page_vlay;
84 TQPushButton * mFromFileBtn;
85 TQPushButton * mFromAddrbkBtn;
87 vlay =
new TQVBoxLayout(
this, 0, KDialog::spacingHint(),
"main layout" );
88 hlay =
new TQHBoxLayout( vlay );
91 mEnableCheck =
new TQCheckBox( i18n(
"&Send picture with every message"),
this );
92 TQWhatsThis::add( mEnableCheck,
93 i18n(
"Check this box if you want KMail to add a so-called X-Face header to messages "
94 "written with this identity. An X-Face is a small (48x48 pixels) black and "
95 "white image that some mail clients are able to display." ) );
96 hlay->addWidget( mEnableCheck, TQt::AlignLeft | TQt::AlignVCenter );
98 mXFaceLabel =
new TQLabel(
this );
99 TQWhatsThis::add(mXFaceLabel,
100 i18n(
"This is a preview of the picture selected/entered below." ) );
101 mXFaceLabel->setFixedSize(48, 48);
102 mXFaceLabel->setFrameShape( TQFrame::Box );
103 hlay->addWidget( mXFaceLabel );
109 hlay =
new TQHBoxLayout( vlay );
110 mSourceCombo =
new TQComboBox(
false,
this );
111 TQWhatsThis::add(mSourceCombo,
112 i18n(
"Click on the widgets below to obtain help on the input methods."));
113 mSourceCombo->setEnabled(
false );
114 mSourceCombo->insertStringList( TQStringList()
115 << i18n(
"continuation of \"obtain picture from\"",
117 << i18n(
"continuation of \"obtain picture from\"",
118 "Input Field Below" ) );
119 label =
new TQLabel( mSourceCombo,
120 i18n(
"Obtain pic&ture from:"),
this );
121 label->setEnabled(
false );
122 hlay->addWidget( label );
123 hlay->addWidget( mSourceCombo, 1 );
126 TQWidgetStack * widgetStack =
new TQWidgetStack(
this );
127 widgetStack->setEnabled(
false );
128 vlay->addWidget( widgetStack, 1 );
129 connect( mSourceCombo, TQ_SIGNAL(highlighted(
int)),
130 widgetStack, TQ_SLOT(raiseWidget(
int)) );
131 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
132 mSourceCombo, TQ_SLOT(setEnabled(
bool)) );
133 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
134 widgetStack, TQ_SLOT(setEnabled(
bool)) );
135 connect( mEnableCheck, TQ_SIGNAL(toggled(
bool)),
136 label, TQ_SLOT(setEnabled(
bool)) );
138 connect( mEnableCheck, TQ_SIGNAL(clicked()),
139 mEnableCheck, TQ_SLOT(setFocus()) );
143 page =
new TQWidget( widgetStack );
144 widgetStack->addWidget( page, pageno );
145 page_vlay =
new TQVBoxLayout( page, 0, KDialog::spacingHint() );
146 hlay =
new TQHBoxLayout( page_vlay );
147 mFromFileBtn =
new TQPushButton( i18n(
"Select File..."), page );
148 TQWhatsThis::add( mFromFileBtn,
149 i18n(
"Use this to select an image file to create the picture from. "
150 "The image should be of high contrast and nearly quadratic shape. "
151 "A light background helps improve the result." ) );
152 mFromFileBtn->setAutoDefault(
false );
153 page_vlay->addWidget( mFromFileBtn, 1 );
154 connect( mFromFileBtn, TQ_SIGNAL(released()),
155 this, TQ_SLOT(slotSelectFile()) );
156 mFromAddrbkBtn =
new TQPushButton( i18n(
"Set From Address Book"), page );
157 TQWhatsThis::add( mFromAddrbkBtn,
158 i18n(
"You can use a scaled-down version of the picture "
159 "you have set in your address book entry." ) );
160 mFromAddrbkBtn->setAutoDefault(
false );
161 page_vlay->addWidget( mFromAddrbkBtn, 1 );
162 connect( mFromAddrbkBtn, TQ_SIGNAL(released()),
163 this, TQ_SLOT(slotSelectFromAddressbook()) );
164 label1 =
new TQLabel( i18n(
"<qt>KMail can send a small (48x48 pixels), low-quality, "
165 "monochrome picture with every message. "
166 "For example, this could be a picture of you or a glyph. "
167 "It is shown in the recipient's mail client (if supported)." ), page );
168 label1->setAlignment( TQLabel::WordBreak | TQLabel::AlignVCenter );
169 page_vlay->addWidget( label1 );
171 widgetStack->raiseWidget( 0 );
175 page =
new TQWidget( widgetStack );
176 widgetStack->addWidget( page, pageno );
177 page_vlay =
new TQVBoxLayout( page, 0, KDialog::spacingHint() );
178 mTextEdit =
new TQTextEdit( page );
179 page_vlay->addWidget( mTextEdit );
180 TQWhatsThis::add( mTextEdit, i18n(
"Use this field to enter an arbitrary X-Face string." ) );
181 mTextEdit->setFont( TDEGlobalSettings::fixedFont() );
182 mTextEdit->setWrapPolicy( TQTextEdit::Anywhere );
183 mTextEdit->setTextFormat( TQt::PlainText );
184 label2 =
new KActiveLabel( i18n(
"Examples are available at <a href=\"http://www.xs4all.nl/~ace/X-Faces/\">http://www.xs4all.nl/~ace/X-Faces/</a>."), page );
185 page_vlay->addWidget( label2 );
188 connect(mTextEdit, TQ_SIGNAL(textChanged()),
this, TQ_SLOT(slotUpdateXFace()));
191 XFaceConfigurator::~XFaceConfigurator() {
195 bool XFaceConfigurator::isXFaceEnabled()
const {
196 return mEnableCheck->isChecked();
199 void XFaceConfigurator::setXFaceEnabled(
bool enable ) {
200 mEnableCheck->setChecked( enable );
203 TQString XFaceConfigurator::xface()
const {
204 return mTextEdit->text();
207 void XFaceConfigurator::setXFace(
const TQString & text ) {
208 mTextEdit->setText( text );
211 void XFaceConfigurator::setXfaceFromFile(
const KURL &url )
214 if( TDEIO::NetAccess::download( url, tmpFile,
this ) )
217 mTextEdit->setText( xf.fromImage( TQImage( tmpFile ) ) );
218 TDEIO::NetAccess::removeTempFile( tmpFile );
220 KMessageBox::error(
this, TDEIO::NetAccess::lastErrorString() );
224 void XFaceConfigurator::slotSelectFile()
226 TQStringList mimeTypes = KImageIO::mimeTypes (KImageIO::Reading);
227 TQString filter = mimeTypes.join (
" ");
228 KURL url = KFileDialog::getOpenURL( TQString(), filter,
this, TQString() );
229 if ( !url.isEmpty() )
230 setXfaceFromFile( url );
233 void XFaceConfigurator::slotSelectFromAddressbook()
235 StdAddressBook *ab = StdAddressBook::self(
true );
236 Addressee me = ab->whoAmI();
239 if ( me.photo().isIntern() )
241 TQImage photo = me.photo().data();
242 if ( !photo.isNull() )
245 mTextEdit->setText( xf.fromImage( photo ) );
248 KMessageBox::information(
this, i18n(
"No picture set for your address book entry."), i18n(
"No Picture") );
253 KURL url = me.photo().url();
255 setXfaceFromFile( url );
257 KMessageBox::information(
this, i18n(
"No picture set for your address book entry."), i18n(
"No Picture") );
261 KMessageBox::information(
this, i18n(
"You do not have your own contact defined in the address book."), i18n(
"No Picture") );
264 void XFaceConfigurator::slotUpdateXFace()
266 TQString str = mTextEdit->text();
267 if ( !str.isEmpty() )
269 if ( str.startsWith(
"x-face:",
false) )
271 str = str.remove(
"x-face:",
false);
272 mTextEdit->setText(str);
275 TQPixmap p( 48, 48,
true );
276 p.convertFromImage( xf.toImage(str) );
277 mXFaceLabel->setPixmap( p );
280 mXFaceLabel->setPixmap( 0L );
285 #include "xfaceconfigurator.moc"