23 #include <KPIMIdentities/IdentityCombo>
24 #include <KPIMIdentities/Identity>
25 #include <KPIMIdentities/IdentityManager>
26 #include <KPIMUtils/Email>
35 mAttachmentSetup( false )
39 setChildrenCollapsible(
false );
40 mAttachmentWidget->hide();
43 mFromEdit->setView(
this );
44 mFromEdit->enableCompletion(
false );
45 mEdtList.append( mFromEdit );
49 mToEdit->setView(
this );
50 mToEdit->enableCompletion(
true );
51 mEdtList.append( mToEdit );
52 connect( mToButton, SIGNAL(clicked(
bool)),
53 parent(), SLOT(slotToBtnClicked()) );
56 mGroupsEdit->setView(
this );
57 mGroupsEdit->enableCompletion(
false );
58 mEdtList.append( mGroupsEdit );
59 connect( mGroupsEdit, SIGNAL(editingFinished()),
60 this, SLOT(slotGroupsChanged()) );
61 connect( mGroupsButton, SIGNAL(clicked()),
62 parent(), SLOT(slotGroupsBtnClicked()) );
65 connect( mFollowuptoEdit, SIGNAL(focused()),
66 this, SLOT(hideFollowuptoHint()) );
69 mSubjectEdit->setView(
this );
70 mSubjectEdit->enableCompletion(
false );
71 mEdtList.append( mSubjectEdit );
72 connect( mSubjectEdit, SIGNAL(textChanged(QString)),
73 parent(), SLOT(slotSubjectChanged(QString)) );
76 mEditor->switchToPlainText();
77 mEditor->setMinimumHeight(50);
79 connect( mExternalKillSwitch, SIGNAL(clicked(
bool)),
82 mExternalKillSwitch->setIcon( KIcon(
"application-exit" ) );
85 connect( mIdentitySelector, SIGNAL(identityChanged(uint)),
86 this, SLOT(slotIdentityChanged(uint)) );
93 if ( mAttachmentsList->topLevelItemCount() > 0 ) {
94 KConfigGroup conf(
knGlobals.config(),
"POSTNEWS");
96 conf.writeEntry(
"Att_Splitter",sizes());
99 QHeaderView *h = mAttachmentsList->header();
100 for (
int i = 0 ; i < h->count() ; ++i ) {
101 lst << h->sectionSize(i);
103 conf.writeEntry(
"Att_Headers",lst);
115 const QString
text = mEditor->textOrHtml();
117 while ( dbleLfCount >= 0 ) {
118 pos = text.indexOf( QLatin1String(
"\n\n" ), pos );
122 mEditor->setCursorPositionFromStart( pos - 1 );
124 mEditor->setCursorPositionFromStart( mEditor->document()->characterCount() - 1 );
127 if (
knGlobals.settings()->appendOwnSignature() ) {
131 mEditor->setCursorPositionFromStart( 0 );
133 mEditor->document()->setModified(
false );
139 if ( mSubjectEdit->text().length() == 0 ) {
140 mSubjectEdit->setFocus();
143 mGroupsEdit->setFocus();
156 it = --( mEdtList.end() );
159 if ( (*it2) == aCur ) {
164 if ( it == mEdtList.end() )
169 if ( it != mEdtList.begin() )
175 if ( it != mEdtList.end() ) {
176 if ( (*it)->isVisible() )
184 mSubjectEdit->setFont( font );
185 mToEdit->setFont( font );
186 mGroupsEdit->setFont( font );
187 mFollowuptoEdit->setFont( font );
188 mEditor->setFontForWholeText( font );
203 return mIdentitySelector->currentIdentity();
208 mIdentitySelector->setCurrentIdentity( uoid );
213 void View::slotIdentityChanged( uint uoid )
216 KPIMIdentities::Identity identity = im->identityForUoid( uoid );
217 setFrom( identity.fullEmailAddr() );
218 if ( KPIMUtils::isValidAddress(
from() ) != KPIMUtils::AddressOk ) {
226 return mFromEdit->text();
231 mFromEdit->setText( from );
237 const QRegExp r = QRegExp(
"\\s*,\\s*", Qt::CaseInsensitive, QRegExp::RegExp2 );
238 return mGroupsEdit->text().split( r, QString::SkipEmptyParts );
243 mGroupsEdit->setText( groups );
247 void View::slotGroupsChanged()
249 QStringList groupsList =
groups();
250 int groupsCount = groupsList.size();
251 groupsList.append( QString() );
253 const QString currFup2 = mFollowuptoEdit->currentText();
254 int i = groupsList.indexOf( currFup2 );
256 groupsList.prepend( currFup2 );
258 groupsList.move( i, 0 );
261 mFollowuptoEdit->clear();
262 mFollowuptoEdit->addItems( groupsList );
265 if ( groupsCount > 1 ) {
268 hideFollowuptoHint();
275 return mToEdit->text();
280 mToEdit->setText( to );
286 const QRegExp r = QRegExp(
"\\s*,\\s*", Qt::CaseInsensitive, QRegExp::RegExp2 );
287 return mFollowuptoEdit->currentText().split( r, QString::SkipEmptyParts );
292 hideFollowuptoHint();
293 mFollowuptoEdit->setEditText( followupTo );
298 const QString hint = i18nc(
"@info/plain This message is place, as an inactive text, in the Followup-To "
299 "line edit of the message composer when the user select more than one "
300 "group to post his/her message.",
301 "Choose an appropriate group to redirect replies..." );
302 if ( mFollowuptoEdit->currentText().isEmpty() ) {
303 QLineEdit *l = mFollowuptoEdit->lineEdit();
304 QPalette palette = l->palette();
305 KColorScheme::adjustForeground( palette, KColorScheme::InactiveText );
306 l->setPalette( palette );
311 void View::hideFollowuptoHint()
313 const QString hint = i18nc(
"@info/plain This message is place, as an inactive text, in the Followup-To "
314 "line edit of the message composer when the user select more than one "
315 "group to post his/her message.",
316 "Choose an appropriate group to redirect replies..." );
317 if ( mFollowuptoEdit->currentText() == hint ) {
318 QLineEdit *l = mFollowuptoEdit->lineEdit();
319 QPalette palette = l->palette();
320 KColorScheme::adjustForeground( palette, KColorScheme::NormalText );
321 l->setPalette( palette );
322 l->setText( QString() );
329 return mSubjectEdit->text();
334 mSubjectEdit->setText( subject );
348 KPIMIdentities::Identity identity = im->identityForUoid(
selectedIdentity() );
349 identity.signature().insertIntoTextEdit( KPIMIdentities::Signature::End,
350 KPIMIdentities::Signature::AddSeparator,
356 void View::showIdentity(
bool show )
358 mIdentitySelectorLabel->setVisible( show );
359 mIdentitySelector->setVisible( show );
362 void View::showFrom(
bool show )
364 mFromLabel->setVisible( show );
365 mFromEdit->setVisible( show );
368 void View::showTo(
bool show )
370 mToLabel->setVisible( show );
371 mToEdit->setVisible( show );
372 mToButton->setVisible( show );
375 void View::showGroups(
bool show )
377 mGroupsLabel->setVisible( show );
378 mGroupsEdit->setVisible( show );
379 mGroupsButton->setVisible( show );
382 void View::showFollowupto(
bool show )
384 mFollowuptoLabel->setVisible( show );
385 mFollowuptoEdit->setVisible( show );
388 void View::showSubject(
bool show )
390 mSubjetLabel->setVisible( show );
391 mSubjectEdit->setVisible( show );
398 if ( !mAttachmentSetup ) {
399 mAttachmentSetup =
true;
402 connect( mAttachmentsList, SIGNAL(itemSelectionChanged()),
403 this, SLOT(slotAttachmentSelectionChanged()) );
405 connect( mAttachmentsList, SIGNAL(contextMenuRequested(QPoint)),
406 parent(), SLOT(slotAttachmentPopup(QPoint)) );
408 connect( mAttachmentsList, SIGNAL(deletePressed()),
413 connect( mAttachmentsList, SIGNAL(itemDoubleClicked(
QTreeWidgetItem*,
int)),
415 connect( mAttachmentsList, SIGNAL(returnPressed()),
418 parent(), SLOT(slotAttachmentChanged()) );
421 connect( mAttachmentAddButton, SIGNAL(clicked()),
422 parent(), SLOT(slotAttachFile()) );
424 mAttachmentRemoveButton->setEnabled(
false );
425 connect( mAttachmentRemoveButton, SIGNAL(clicked()),
428 mAttachmentPropertiesButton->setEnabled(
false );
429 connect( mAttachmentPropertiesButton, SIGNAL(clicked()),
433 if ( !mAttachmentWidget->isVisible() ) {
434 mAttachmentWidget->show();
436 KConfigGroup conf(
knGlobals.config(),
"POSTNEWS");
443 lst=conf.readEntry(
"Att_Headers",
QList<int>());
444 QHeaderView *h = mAttachmentsList->header();
445 if ( lst.count() == h->count() ) {
446 for(
int i = 0 ; i < h->count() ; ++i) {
447 h->resizeSection( i, lst[ i ] );
455 mAttachmentWidget->hide();
461 mAttachmentsList->addTopLevelItem( item );
466 return mAttachmentsList->attachments();
471 mAttachmentsList->removeCurrentAttachment();
476 mAttachmentsList->editCurrentAttachment();
479 void View::slotAttachmentSelectionChanged()
481 bool e = !mAttachmentsList->selectedItems().isEmpty();
482 mAttachmentRemoveButton->setEnabled( e );
483 mAttachmentPropertiesButton->setEnabled( e );
490 mEditorsStack->setCurrentWidget( mExternalEditorNotification );
496 mEditorsStack->setCurrentWidget( mEditor );
503 #include "kncomposerview.moc"
const QString emailRecipient() const
Returns the email recipient of this message (as type by the user in the To: field).
void focusNextPrevEdit(const QWidget *aCur, bool aNext)
Gives the focus to the next/previous edition widget (group, to, subject, body, etc.)
const QString from()
Returns the sender full name and email address to use in a From: header of a message.
View(KNComposer *_composer)
Constructor.
Item of the AttachmentView.
void setIdentity(uint uoid)
Changes the selected identity and update related edit lines.
void appendSignature()
Appends the signature to the editor.
virtual QByteArray text(quint32 serialNumber) const =0
void editCurrentAttachment()
Edit the currently selected attachment.
void setEmailRecipient(const QString &to)
Sets the email recipient list as a string.
static KNGlobals * self()
Return the KNGlobals instance.
QString intro() const
Get Introduction phrase.
void setMessageMode(KNComposer::MessageMode mode)
Set the message mode to.
void hideExternalNotification()
void setFrom(const QString &from)
Set the name and email address of the sender of the message.
void removeCurrentAttachment()
Remove the currently selected attachment if there is a selection.
virtual ~View()
Destructor.
KPIMIdentities::IdentityManager * identityManager()
Returns the identity manager.
const QStringList followupTo() const
Returns the followup-to list of groups (name are trimmed).
const QString subject() const
Returns the subject text.
void showAttachmentView()
KNode::Settings * settings()
Returns the KConfigXT generated settings object.
void closeExternalEditor()
This signal is emitted when the user request the external body editor to be closed.
void setComposingFont(const QFont &font)
Changes the font used in edition widget within this ComposerView.
void setFollowupTo(const QString &followupTo)
Sets the followup-to list as a string (must be a coma separated list of groups).
Message is to be sent by e-mail.
void showExternalNotification()
const QStringList groups() const
Returns the followup-to list of groups (name are trimmed).
const QList< KNAttachment::Ptr > attachments() const
Returns the list of attachments of this message.
void displayFollowuptoHint()
Display an indication to the user about followup-to.
void addAttachment(KNAttachment::Ptr attachment)
Adds an attachment to the message.
KNComposerEditor * editor() const
Returns the main text editor.
void hideAttachmentView()
void setSubject(const QString &subject)
Sets the subject.
#define knGlobals
Keep compatibility with the old way.
boost::shared_ptr< KNAttachment > Ptr
Shared pointer to a KNAttachment.
Message is to be sent to a newsgroup.
void completeSetup(bool firstEdit, KNComposer::MessageMode mode)
Completes the setup of this view.
uint selectedIdentity() const
Return the UOID of the selected identity.
void setGroups(const QString &groups)
Sets the group list as a string (must be coma separated).