35 #include <akonadi/contact/contactsearchjob.h>
36 #include <kcombobox.h>
38 #include <kfiledialog.h>
39 #include <kglobalsettings.h>
41 #include <kio/netaccess.h>
43 #include <kmessagebox.h>
44 #include <kpimidentities/identity.h>
45 #include <kpimidentities/identitymanager.h>
46 #include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h"
48 #include <messageviewer/header/kxface.h>
51 #include <QHBoxLayout>
53 #include <QPushButton>
54 #include <QStackedWidget>
55 #include <QVBoxLayout>
59 using namespace KMail;
60 using namespace MessageViewer;
64 XFaceConfigurator::XFaceConfigurator(
QWidget * parent )
75 mEnableCheck =
new QCheckBox( i18n(
"&Send picture with every message"),
this );
77 i18n(
"Check this box if you want KMail to add a so-called X-Face header to messages "
78 "written with this identity. An X-Face is a small (48x48 pixels) black and "
79 "white image that some mail clients are able to display." ) );
80 hlay->
addWidget( mEnableCheck, Qt::AlignLeft | Qt::AlignVCenter );
82 mXFaceLabel =
new QLabel(
this );
84 i18n(
"This is a preview of the picture selected/entered below." ) );
96 sourceCombo->setEditable(
false );
97 sourceCombo->setWhatsThis(
98 i18n(
"Click on the widgets below to obtain help on the input methods."));
99 sourceCombo->setEnabled(
false );
101 << i18nc(
"continuation of \"obtain picture from\"",
103 << i18nc(
"continuation of \"obtain picture from\"",
104 "Input Field Below" ) );
105 QLabel *label =
new QLabel( i18n(
"Obtain pic&ture from:"),
this );
115 connect( sourceCombo, SIGNAL(highlighted(
int)),
116 widgetStack, SLOT(setCurrentIndex(
int)) );
117 connect( sourceCombo, SIGNAL(activated(
int)),
118 widgetStack, SLOT(setCurrentIndex(
int)) );
119 connect( mEnableCheck, SIGNAL(toggled(
bool)),
121 connect( mEnableCheck, SIGNAL(toggled(
bool)),
123 connect( mEnableCheck, SIGNAL(toggled(
bool)),
126 connect( mEnableCheck, SIGNAL(clicked()),
135 page_vlay->
setSpacing( KDialog::spacingHint() );
140 i18n(
"Use this to select an image file to create the picture from. "
141 "The image should be of high contrast and nearly quadratic shape. "
142 "A light background helps improve the result." ) );
144 page_vlay->
addWidget( fromFileButton, 1 );
145 connect( fromFileButton, SIGNAL(released()),
146 this, SLOT(slotSelectFile()) );
149 i18n(
"You can use a scaled-down version of the picture "
150 "you have set in your address book entry." ) );
152 page_vlay->
addWidget( fromAddressBookButton, 1 );
153 connect( fromAddressBookButton, SIGNAL(released()),
154 this, SLOT(slotSelectFromAddressbook()) );
155 QLabel *label1 =
new QLabel( i18n(
"<qt>KMail can send a small (48x48 pixels), low-quality, "
156 "monochrome picture with every message. "
157 "For example, this could be a picture of you or a glyph. "
158 "It is shown in the recipient's mail client (if supported).</qt>" ), page );
167 page =
new QWidget( widgetStack );
171 page_vlay->
setSpacing( KDialog::spacingHint() );
172 mTextEdit =
new PimCommon::PlainTextEditor( page );
174 mTextEdit->setWhatsThis( i18n(
"Use this field to enter an arbitrary X-Face string." ) );
175 mTextEdit->setFont( KGlobalSettings::fixedFont() );
176 mTextEdit->setWordWrapMode( QTextOption::WrapAnywhere);
177 mTextEdit->setSearchSupport(
false);
178 QLabel *label2 =
new QLabel( i18n(
"Examples are available at <a "
179 "href=\"http://ace.home.xs4all.nl/X-Faces/\">"
180 "http://ace.home.xs4all.nl/X-Faces/</a>."), page );
187 connect(mTextEdit, SIGNAL(textChanged()),
this, SLOT(slotUpdateXFace()));
207 return mTextEdit->toPlainText();
212 mTextEdit->setPlainText( text );
215 void XFaceConfigurator::setXfaceFromFile(
const KUrl &url )
218 if (KIO::NetAccess::download( url, tmpFile,
this )) {
220 mTextEdit->setPlainText( xf.fromImage(
QImage( tmpFile ) ) );
221 KIO::NetAccess::removeTempFile( tmpFile );
223 KMessageBox::error(
this, KIO::NetAccess::lastErrorString() );
227 void XFaceConfigurator::slotSelectFile()
229 const QStringList mimeTypes = KImageIO::mimeTypes (KImageIO::Reading);
231 const KUrl url = KFileDialog::getOpenUrl(
QString(), filter,
this,
QString() );
232 if ( !url.isEmpty() )
233 setXfaceFromFile( url );
236 void XFaceConfigurator::slotSelectFromAddressbook()
238 using namespace KPIMIdentities;
240 IdentityManager manager(
true );
241 const Identity defaultIdentity = manager.defaultIdentity();
244 Akonadi::ContactSearchJob *job =
new Akonadi::ContactSearchJob(
this );
246 job->setQuery( Akonadi::ContactSearchJob::Email,
email, Akonadi::ContactSearchJob::ExactMatch );
247 connect( job, SIGNAL(result(
KJob*)), SLOT(slotDelayedSelectFromAddressbook(
KJob*)) );
250 void XFaceConfigurator::slotDelayedSelectFromAddressbook(
KJob *job )
252 const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
254 if ( searchJob->contacts().isEmpty() ) {
255 KMessageBox::information(
this, i18n(
"You do not have your own contact defined in the address book."), i18n(
"No Picture") );
259 const Addressee contact = searchJob->contacts().at(0);
260 if ( contact.photo().isIntern() )
262 const QImage photo = contact.photo().data();
265 mTextEdit->setPlainText( xf.fromImage( photo ) );
267 KMessageBox::information(
this, i18n(
"No picture set for your address book entry."), i18n(
"No Picture") );
273 const KUrl url = contact.photo().url();
275 setXfaceFromFile( url );
277 KMessageBox::information(
this, i18n(
"No picture set for your address book entry."), i18n(
"No Picture") );
281 void XFaceConfigurator::slotUpdateXFace()
283 QString str = mTextEdit->toPlainText();
288 mTextEdit->setPlainText(str);
294 mXFaceLabel->
clear();
virtual QByteArray text(quint32 serialNumber) const =0
void setFrameShape(Shape)
void setOpenExternalLinks(bool open)
void setPixmap(const QPixmap &)
void setAlignment(QFlags< Qt::AlignmentFlag >)
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QString join(const QString &separator) const
QString & remove(int position, int n)
void setXFaceEnabled(bool enable)
void setXFace(const QString &text)
void setBuddy(QWidget *buddy)
void setObjectName(const QString &name)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool isXFaceEnabled() const
void setMargin(int margin)
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
void addStretch(int stretch)
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setWordWrap(bool on)
void setSpacing(int spacing)
void addLayout(QLayout *layout, int stretch)