00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "xfaceconfigurator.h"
00038
00039 #include <kactivelabel.h>
00040 #include <kdialog.h>
00041 #include <kfiledialog.h>
00042 #include <kglobalsettings.h>
00043 #include <kimageio.h>
00044 #include <klocale.h>
00045 #include <kmessagebox.h>
00046 #include <kurl.h>
00047 #include <kio/netaccess.h>
00048 using namespace KIO;
00049 #include <kxface.h>
00050 using namespace KPIM;
00051 #include <kabc/stdaddressbook.h>
00052 #include <kabc/addressee.h>
00053 using namespace KABC;
00054
00055 #include <qbitmap.h>
00056 #include <qcheckbox.h>
00057 #include <qcombobox.h>
00058 #include <qimage.h>
00059 #include <qlabel.h>
00060 #include <qlayout.h>
00061 #include <qpushbutton.h>
00062 #include <qwhatsthis.h>
00063 #include <qwidgetstack.h>
00064
00065
00066
00067
00068 using namespace KMail;
00069 using namespace KPIM;
00070
00071 namespace KMail {
00072
00073 XFaceConfigurator::XFaceConfigurator( QWidget * parent, const char * name )
00074 : QWidget( parent, name )
00075 {
00076
00077 QLabel * label;
00078 QLabel * label1;
00079 KActiveLabel * label2;
00080 QWidget * page;
00081 QVBoxLayout * vlay;
00082 QHBoxLayout * hlay;
00083 QVBoxLayout * page_vlay;
00084 QPushButton * mFromFileBtn;
00085 QPushButton * mFromAddrbkBtn;
00086
00087 vlay = new QVBoxLayout( this, 0, KDialog::spacingHint(), "main layout" );
00088 hlay = new QHBoxLayout( vlay );
00089
00090
00091 mEnableCheck = new QCheckBox( i18n("&Send picture with every message"), this );
00092 QWhatsThis::add( mEnableCheck,
00093 i18n( "Check this box if you want KMail to add a so-called X-Face header to messages "
00094 "written with this identity. An X-Face is a small (48x48 pixels) black and "
00095 "white image that some mail clients are able to display." ) );
00096 hlay->addWidget( mEnableCheck, Qt::AlignLeft | Qt::AlignVCenter );
00097
00098 mXFaceLabel = new QLabel( this );
00099 QWhatsThis::add(mXFaceLabel,
00100 i18n( "This is a preview of the picture selected/entered below." ) );
00101 mXFaceLabel->setFixedSize(48, 48);
00102 mXFaceLabel->setFrameShape( QFrame::Box );
00103 hlay->addWidget( mXFaceLabel );
00104
00105
00106
00107
00108
00109 hlay = new QHBoxLayout( vlay );
00110 mSourceCombo = new QComboBox( false, this );
00111 QWhatsThis::add(mSourceCombo,
00112 i18n("Click on the widgets below to obtain help on the input methods."));
00113 mSourceCombo->setEnabled( false );
00114 mSourceCombo->insertStringList( QStringList()
00115 << i18n( "continuation of \"obtain picture from\"",
00116 "External Source" )
00117 << i18n( "continuation of \"obtain picture from\"",
00118 "Input Field Below" ) );
00119 label = new QLabel( mSourceCombo,
00120 i18n("Obtain pic&ture from:"), this );
00121 label->setEnabled( false );
00122 hlay->addWidget( label );
00123 hlay->addWidget( mSourceCombo, 1 );
00124
00125
00126 QWidgetStack * widgetStack = new QWidgetStack( this );
00127 widgetStack->setEnabled( false );
00128 vlay->addWidget( widgetStack, 1 );
00129 connect( mSourceCombo, SIGNAL(highlighted(int)),
00130 widgetStack, SLOT(raiseWidget(int)) );
00131 connect( mEnableCheck, SIGNAL(toggled(bool)),
00132 mSourceCombo, SLOT(setEnabled(bool)) );
00133 connect( mEnableCheck, SIGNAL(toggled(bool)),
00134 widgetStack, SLOT(setEnabled(bool)) );
00135 connect( mEnableCheck, SIGNAL(toggled(bool)),
00136 label, SLOT(setEnabled(bool)) );
00137
00138 connect( mEnableCheck, SIGNAL(clicked()),
00139 mEnableCheck, SLOT(setFocus()) );
00140
00141 int pageno = 0;
00142
00143 page = new QWidget( widgetStack );
00144 widgetStack->addWidget( page, pageno );
00145 page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
00146 hlay = new QHBoxLayout( page_vlay );
00147 mFromFileBtn = new QPushButton( i18n("Select File..."), page );
00148 QWhatsThis::add( mFromFileBtn,
00149 i18n("Use this to select an image file to create the picture from. "
00150 "The image should be of high contrast and nearly quadratic shape. "
00151 "A light background helps improve the result." ) );
00152 mFromFileBtn->setAutoDefault( false );
00153 page_vlay->addWidget( mFromFileBtn, 1 );
00154 connect( mFromFileBtn, SIGNAL(released()),
00155 this, SLOT(slotSelectFile()) );
00156 mFromAddrbkBtn = new QPushButton( i18n("Set From Address Book"), page );
00157 QWhatsThis::add( mFromAddrbkBtn,
00158 i18n( "You can use a scaled-down version of the picture "
00159 "you have set in your address book entry." ) );
00160 mFromAddrbkBtn->setAutoDefault( false );
00161 page_vlay->addWidget( mFromAddrbkBtn, 1 );
00162 connect( mFromAddrbkBtn, SIGNAL(released()),
00163 this, SLOT(slotSelectFromAddressbook()) );
00164 label1 = new QLabel( i18n("<qt>KMail can send a small (48x48 pixels), low-quality, "
00165 "monochrome picture with every message. "
00166 "For example, this could be a picture of you or a glyph. "
00167 "It is shown in the recipient's mail client (if supported)." ), page );
00168 label1->setAlignment( QLabel::WordBreak | QLabel::AlignVCenter );
00169 page_vlay->addWidget( label1 );
00170
00171 widgetStack->raiseWidget( 0 );
00172
00173
00174 ++pageno;
00175 page = new QWidget( widgetStack );
00176 widgetStack->addWidget( page, pageno );
00177 page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
00178 mTextEdit = new QTextEdit( page );
00179 page_vlay->addWidget( mTextEdit );
00180 QWhatsThis::add( mTextEdit, i18n( "Use this field to enter an arbitrary X-Face string." ) );
00181 mTextEdit->setFont( KGlobalSettings::fixedFont() );
00182 mTextEdit->setWrapPolicy( QTextEdit::Anywhere );
00183 mTextEdit->setTextFormat( Qt::PlainText );
00184 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 );
00185 page_vlay->addWidget( label2 );
00186
00187
00188 connect(mTextEdit, SIGNAL(textChanged()), this, SLOT(slotUpdateXFace()));
00189 }
00190
00191 XFaceConfigurator::~XFaceConfigurator() {
00192
00193 }
00194
00195 bool XFaceConfigurator::isXFaceEnabled() const {
00196 return mEnableCheck->isChecked();
00197 }
00198
00199 void XFaceConfigurator::setXFaceEnabled( bool enable ) {
00200 mEnableCheck->setChecked( enable );
00201 }
00202
00203 QString XFaceConfigurator::xface() const {
00204 return mTextEdit->text();
00205 }
00206
00207 void XFaceConfigurator::setXFace( const QString & text ) {
00208 mTextEdit->setText( text );
00209 }
00210
00211 void XFaceConfigurator::setXfaceFromFile( const KURL &url )
00212 {
00213 QString tmpFile;
00214 if( KIO::NetAccess::download( url, tmpFile, this ) )
00215 {
00216 KXFace xf;
00217 mTextEdit->setText( xf.fromImage( QImage( tmpFile ) ) );
00218 KIO::NetAccess::removeTempFile( tmpFile );
00219 } else {
00220 KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
00221 }
00222 }
00223
00224 void XFaceConfigurator::slotSelectFile()
00225 {
00226 QStringList mimeTypes = KImageIO::mimeTypes (KImageIO::Reading);
00227 QString filter = mimeTypes.join (" ");
00228 KURL url = KFileDialog::getOpenURL( QString::null, filter, this, QString::null );
00229 if ( !url.isEmpty() )
00230 setXfaceFromFile( url );
00231 }
00232
00233 void XFaceConfigurator::slotSelectFromAddressbook()
00234 {
00235 StdAddressBook *ab = StdAddressBook::self( true );
00236 Addressee me = ab->whoAmI();
00237 if ( !me.isEmpty() )
00238 {
00239 if ( me.photo().isIntern() )
00240 {
00241 QImage photo = me.photo().data();
00242 if ( !photo.isNull() )
00243 {
00244 KXFace xf;
00245 mTextEdit->setText( xf.fromImage( photo ) );
00246 }
00247 else
00248 KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );
00249
00250 }
00251 else
00252 {
00253 KURL url = me.photo().url();
00254 if( !url.isEmpty() )
00255 setXfaceFromFile( url );
00256 else
00257 KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );
00258 }
00259 }
00260 else
00261 KMessageBox::information( this, i18n("You do not have your own contact defined in the address book."), i18n("No Picture") );
00262 }
00263
00264 void XFaceConfigurator::slotUpdateXFace()
00265 {
00266 QString str = mTextEdit->text();
00267 if ( !str.isEmpty() )
00268 {
00269 if ( str.startsWith("x-face:", false) )
00270 {
00271 str = str.remove("x-face:", false);
00272 mTextEdit->setText(str);
00273 }
00274 KXFace xf;
00275 QPixmap p( 48, 48, true );
00276 p.convertFromImage( xf.toImage(str) );
00277 mXFaceLabel->setPixmap( p );
00278 }
00279 else
00280 mXFaceLabel->setPixmap( 0L );
00281 }
00282
00283 }
00284
00285 #include "xfaceconfigurator.moc"