• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
kncomposerview.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2007 the KNode authors.
4  See file AUTHORS for details
5  Copyright (c) 2010 Olivier Trichet <nive@nivalis.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  You should have received a copy of the GNU General Public License
12  along with this program; if not, write to the Free Software Foundation,
13  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
14 */
15 
16 #include "kncomposerview.h"
17 
18 #include "kncomposereditor.h"
19 #include "knglobals.h"
20 #include "settings.h"
21 
22 #include <KLocale>
23 #include <KPIMIdentities/IdentityCombo>
24 #include <KPIMIdentities/Identity>
25 #include <KPIMIdentities/IdentityManager>
26 #include <KPIMUtils/Email>
27 
28 
29 namespace KNode {
30 namespace Composer {
31 
32 
33 View::View( KNComposer *composer )
34  : QSplitter( Qt::Vertical, composer ),
35  mAttachmentSetup( false )
36 {
37  setupUi( this );
38 
39  setChildrenCollapsible( false );
40  mAttachmentWidget->hide();
41 
42  //From
43  mFromEdit->setView( this );
44  mFromEdit->enableCompletion( false );
45  mEdtList.append( mFromEdit );
46  showFrom( false );
47 
48  //To
49  mToEdit->setView( this );
50  mToEdit->enableCompletion( true );
51  mEdtList.append( mToEdit );
52  connect( mToButton, SIGNAL(clicked(bool)),
53  parent(), SLOT(slotToBtnClicked()) );
54 
55  //Newsgroups
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()) );
63 
64  //Followup-to
65  connect( mFollowuptoEdit, SIGNAL(focused()),
66  this, SLOT(hideFollowuptoHint()) );
67 
68  //subject
69  mSubjectEdit->setView( this );
70  mSubjectEdit->enableCompletion( false );
71  mEdtList.append( mSubjectEdit );
72  connect( mSubjectEdit, SIGNAL(textChanged(QString)),
73  parent(), SLOT(slotSubjectChanged(QString)) );
74 
75  //Editors
76  mEditor->switchToPlainText();
77  mEditor->setMinimumHeight(50);
78 
79  connect( mExternalKillSwitch, SIGNAL(clicked(bool)),
80  this, SIGNAL(closeExternalEditor()) );
81  hideExternalNotification();
82  mExternalKillSwitch->setIcon( KIcon( "application-exit" ) );
83 
84  // Identities
85  connect( mIdentitySelector, SIGNAL(identityChanged(uint)),
86  this, SLOT(slotIdentityChanged(uint)) );
87  setIdentity( KNGlobals::self()->identityManager()->defaultIdentity().uoid() );
88 }
89 
90 
91 View::~View()
92 {
93  if ( mAttachmentsList->topLevelItemCount() > 0 ) { // The attachment view was visible
94  KConfigGroup conf( knGlobals.config(), "POSTNEWS");
95 
96  conf.writeEntry("Att_Splitter",sizes()); // save splitter pos
97 
98  QList<int> lst; // save header sizes
99  QHeaderView *h = mAttachmentsList->header();
100  for ( int i = 0 ; i < h->count() ; ++i ) {
101  lst << h->sectionSize(i);
102  }
103  conf.writeEntry("Att_Headers",lst);
104  }
105 }
106 
107 
108 void View::completeSetup( bool firstEdit, KNComposer::MessageMode mode )
109 {
110  if ( firstEdit ) {
111  // now we place the cursor at the end of the quoted text / below the attribution line
112  if ( KNGlobals::self()->settings()->cursorOnTop() ) {
113  // FIXME: hack: counting the number of \n\n to catch end of introduction (see KNArticleFactory::createReply())
114  int dbleLfCount = KNGlobals::self()->settings()->intro().count( "%L%L" );
115  const QString text = mEditor->textOrHtml();
116  int pos = 0;
117  while ( dbleLfCount >= 0 ) {
118  pos = text.indexOf( QLatin1String( "\n\n" ), pos );
119  pos += 2;
120  --dbleLfCount;
121  }
122  mEditor->setCursorPositionFromStart( pos - 1 );
123  } else {
124  mEditor->setCursorPositionFromStart( mEditor->document()->characterCount() - 1 );
125  }
126 
127  if ( knGlobals.settings()->appendOwnSignature() ) {
128  appendSignature();
129  }
130  } else {
131  mEditor->setCursorPositionFromStart( 0 );
132  }
133  mEditor->document()->setModified( false );
134 
135  setMessageMode( mode );
136 
137  // Focus
138  mEditor->setFocus();
139  if ( mSubjectEdit->text().length() == 0 ) {
140  mSubjectEdit->setFocus();
141  }
142  if ( mGroupsEdit->text().length() == 0 && mode == KNComposer::news ) {
143  mGroupsEdit->setFocus();
144  }
145  if ( mToEdit->text().length() == 0 && mode == KNComposer::mail ) {
146  mToEdit->setFocus();
147  }
148 }
149 
150 
151 void View::focusNextPrevEdit( const QWidget *aCur, bool aNext )
152 {
153  QList<QWidget*>::Iterator it;
154 
155  if ( !aCur ) {
156  it = --( mEdtList.end() );
157  } else {
158  for ( QList<QWidget*>::Iterator it2 = mEdtList.begin(); it2 != mEdtList.end(); ++it2 ) {
159  if ( (*it2) == aCur ) {
160  it = it2;
161  break;
162  }
163  }
164  if ( it == mEdtList.end() )
165  return;
166  if ( aNext )
167  ++it;
168  else {
169  if ( it != mEdtList.begin() )
170  --it;
171  else
172  return;
173  }
174  }
175  if ( it != mEdtList.end() ) {
176  if ( (*it)->isVisible() )
177  (*it)->setFocus();
178  } else if ( aNext )
179  mEditor->setFocus();
180 }
181 
182 void View::setComposingFont( const QFont &font )
183 {
184  mSubjectEdit->setFont( font );
185  mToEdit->setFont( font );
186  mGroupsEdit->setFont( font );
187  mFollowuptoEdit->setFont( font );
188  mEditor->setFontForWholeText( font );
189 }
190 
191 
192 void View::setMessageMode( KNComposer::MessageMode mode )
193 {
194  showTo( mode != KNComposer::news );
195 
196  showGroups( mode != KNComposer::mail );
197  showFollowupto( mode != KNComposer::mail );
198 }
199 
200 
201 uint View::selectedIdentity() const
202 {
203  return mIdentitySelector->currentIdentity();
204 }
205 
206 void View::setIdentity( uint uoid )
207 {
208  mIdentitySelector->setCurrentIdentity( uoid );
209  // mIdentitySelector will emit its identityChanged(uint) signal
210  // that is connected to slotIdentityChanged(uint)
211 }
212 
213 void View::slotIdentityChanged( uint uoid )
214 {
215  KPIMIdentities::IdentityManager *im = KNGlobals::self()->identityManager();
216  KPIMIdentities::Identity identity = im->identityForUoid( uoid );
217  setFrom( identity.fullEmailAddr() );
218  if ( KPIMUtils::isValidAddress( from() ) != KPIMUtils::AddressOk ) {
219  showFrom( true );
220  }
221 }
222 
223 
224 const QString View::from()
225 {
226  return mFromEdit->text();
227 }
228 
229 void View::setFrom( const QString& from )
230 {
231  mFromEdit->setText( from );
232 }
233 
234 
235 const QStringList View::groups() const
236 {
237  const QRegExp r = QRegExp( "\\s*,\\s*", Qt::CaseInsensitive, QRegExp::RegExp2 );
238  return mGroupsEdit->text().split( r, QString::SkipEmptyParts );
239 }
240 
241 void View::setGroups( const QString &groups )
242 {
243  mGroupsEdit->setText( groups );
244  slotGroupsChanged(); // update the followup-to
245 }
246 
247 void View::slotGroupsChanged()
248 {
249  QStringList groupsList = groups();
250  int groupsCount = groupsList.size();
251  groupsList.append( QString() );
252 
253  const QString currFup2 = mFollowuptoEdit->currentText();
254  int i = groupsList.indexOf( currFup2 );
255  if ( i == -1 ) {
256  groupsList.prepend( currFup2 );
257  } else {
258  groupsList.move( i, 0 );
259  }
260 
261  mFollowuptoEdit->clear();
262  mFollowuptoEdit->addItems( groupsList );
263 
264  // Display an hint about fu2
265  if ( groupsCount > 1 ) {
266  displayFollowuptoHint();
267  } else {
268  hideFollowuptoHint();
269  }
270 }
271 
272 
273 const QString View::emailRecipient() const
274 {
275  return mToEdit->text();
276 }
277 
278 void View::setEmailRecipient( const QString& to )
279 {
280  mToEdit->setText( to );
281 }
282 
283 
284 const QStringList View::followupTo() const
285 {
286  const QRegExp r = QRegExp( "\\s*,\\s*", Qt::CaseInsensitive, QRegExp::RegExp2 );
287  return mFollowuptoEdit->currentText().split( r, QString::SkipEmptyParts );
288 }
289 
290 void View::setFollowupTo( const QString &followupTo )
291 {
292  hideFollowuptoHint();
293  mFollowuptoEdit->setEditText( followupTo );
294 }
295 
296 void View::displayFollowuptoHint()
297 {
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 );
307  l->setText( hint );
308  }
309 }
310 
311 void View::hideFollowuptoHint()
312 {
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() );
323  }
324 }
325 
326 
327 const QString View::subject() const
328 {
329  return mSubjectEdit->text();
330 }
331 
332 void View::setSubject( const QString &subject )
333 {
334  mSubjectEdit->setText( subject );
335 }
336 
337 
338 KNComposerEditor * View::editor() const
339 {
340  return mEditor;
341 }
342 
343 
344 
345 void View::appendSignature()
346 {
347  KPIMIdentities::IdentityManager *im = KNGlobals::self()->identityManager();
348  KPIMIdentities::Identity identity = im->identityForUoid( selectedIdentity() );
349  identity.signature().insertIntoTextEdit( KPIMIdentities::Signature::End,
350  KPIMIdentities::Signature::AddSeparator,
351  mEditor );
352 }
353 
354 
355 
356 void View::showIdentity( bool show )
357 {
358  mIdentitySelectorLabel->setVisible( show );
359  mIdentitySelector->setVisible( show );
360 }
361 
362 void View::showFrom( bool show )
363 {
364  mFromLabel->setVisible( show );
365  mFromEdit->setVisible( show );
366 }
367 
368 void View::showTo( bool show )
369 {
370  mToLabel->setVisible( show );
371  mToEdit->setVisible( show );
372  mToButton->setVisible( show );
373 }
374 
375 void View::showGroups( bool show )
376 {
377  mGroupsLabel->setVisible( show );
378  mGroupsEdit->setVisible( show );
379  mGroupsButton->setVisible( show );
380 }
381 
382 void View::showFollowupto( bool show )
383 {
384  mFollowuptoLabel->setVisible( show );
385  mFollowuptoEdit->setVisible( show );
386 }
387 
388 void View::showSubject( bool show )
389 {
390  mSubjetLabel->setVisible( show );
391  mSubjectEdit->setVisible( show );
392 }
393 
394 
395 
396 void View::showAttachmentView()
397 {
398  if ( !mAttachmentSetup ) {
399  mAttachmentSetup = true;
400 
401  //connections
402  connect( mAttachmentsList, SIGNAL(itemSelectionChanged()),
403  this, SLOT(slotAttachmentSelectionChanged()) );
404 
405  connect( mAttachmentsList, SIGNAL(contextMenuRequested(QPoint)),
406  parent(), SLOT(slotAttachmentPopup(QPoint)) );
407 
408  connect( mAttachmentsList, SIGNAL(deletePressed()),
409  this, SLOT(removeCurrentAttachment()) );
410  connect( mAttachmentsList, SIGNAL(attachmentRemoved(KNAttachment::Ptr,bool)),
411  parent(), SLOT(slotAttachmentRemoved(KNAttachment::Ptr,bool)) );
412 
413  connect( mAttachmentsList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
414  mAttachmentsList, SLOT(editCurrentAttachment()) );
415  connect( mAttachmentsList, SIGNAL(returnPressed()),
416  mAttachmentsList, SLOT(editCurrentAttachment()) );
417  connect( mAttachmentsList, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
418  parent(), SLOT(slotAttachmentChanged()) );
419 
420  //buttons
421  connect( mAttachmentAddButton, SIGNAL(clicked()),
422  parent(), SLOT(slotAttachFile()) );
423 
424  mAttachmentRemoveButton->setEnabled( false );
425  connect( mAttachmentRemoveButton, SIGNAL(clicked()),
426  this, SLOT(removeCurrentAttachment()) );
427 
428  mAttachmentPropertiesButton->setEnabled( false );
429  connect( mAttachmentPropertiesButton, SIGNAL(clicked()),
430  mAttachmentsList, SLOT(editCurrentAttachment()) );
431  }
432 
433  if ( !mAttachmentWidget->isVisible() ) {
434  mAttachmentWidget->show();
435 
436  KConfigGroup conf(knGlobals.config(), "POSTNEWS");
437 
438  QList<int> lst = conf.readEntry("Att_Splitter",QList<int>());
439  if(lst.count()!=2)
440  lst << 267 << 112;
441  setSizes(lst);
442 
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 ] );
448  }
449  }
450  }
451 }
452 
453 void View::hideAttachmentView()
454 {
455  mAttachmentWidget->hide();
456 }
457 
458 void View::addAttachment( KNAttachment::Ptr attachment )
459 {
460  AttachmentViewItem *item = new AttachmentViewItem( mAttachmentsList, attachment );
461  mAttachmentsList->addTopLevelItem( item );
462 }
463 
464 const QList<KNAttachment::Ptr> View::attachments() const
465 {
466  return mAttachmentsList->attachments();
467 }
468 
469 void View::removeCurrentAttachment()
470 {
471  mAttachmentsList->removeCurrentAttachment();
472 }
473 
474 void View::editCurrentAttachment()
475 {
476  mAttachmentsList->editCurrentAttachment();
477 }
478 
479 void View::slotAttachmentSelectionChanged()
480 {
481  bool e = !mAttachmentsList->selectedItems().isEmpty();
482  mAttachmentRemoveButton->setEnabled( e );
483  mAttachmentPropertiesButton->setEnabled( e );
484 }
485 
486 
487 
488 void View::showExternalNotification()
489 {
490  mEditorsStack->setCurrentWidget( mExternalEditorNotification );
491 }
492 
493 
494 void View::hideExternalNotification()
495 {
496  mEditorsStack->setCurrentWidget( mEditor );
497 }
498 
499 
500 } // namespace Composer
501 } // namespace KNode
502 
503 #include "kncomposerview.moc"
KNode::Composer::View::emailRecipient
const QString emailRecipient() const
Returns the email recipient of this message (as type by the user in the To: field).
Definition: kncomposerview.cpp:273
KNode::Composer::View::focusNextPrevEdit
void focusNextPrevEdit(const QWidget *aCur, bool aNext)
Gives the focus to the next/previous edition widget (group, to, subject, body, etc.)
Definition: kncomposerview.cpp:151
kncomposereditor.h
KNode::Composer::View::from
const QString from()
Returns the sender full name and email address to use in a From: header of a message.
Definition: kncomposerview.cpp:224
KNode::Composer::View::View
View(KNComposer *_composer)
Constructor.
Definition: kncomposerview.cpp:33
KNode::Composer::AttachmentViewItem
Item of the AttachmentView.
Definition: attachment_view.h:120
KNode::Composer::View::setIdentity
void setIdentity(uint uoid)
Changes the selected identity and update related edit lines.
Definition: kncomposerview.cpp:206
KNode::Composer::View::appendSignature
void appendSignature()
Appends the signature to the editor.
Definition: kncomposerview.cpp:345
text
virtual QByteArray text(quint32 serialNumber) const =0
KNode::Composer::View::editCurrentAttachment
void editCurrentAttachment()
Edit the currently selected attachment.
Definition: kncomposerview.cpp:474
QWidget
KNode::Composer::View::setEmailRecipient
void setEmailRecipient(const QString &to)
Sets the email recipient list as a string.
Definition: kncomposerview.cpp:278
KNGlobals::self
static KNGlobals * self()
Return the KNGlobals instance.
Definition: knglobals.cpp:72
from
QString from() const
KNode::SettingsBase::intro
QString intro() const
Get Introduction phrase.
Definition: settings_base.h:1312
KNode::Composer::View::setMessageMode
void setMessageMode(KNComposer::MessageMode mode)
Set the message mode to.
Definition: kncomposerview.cpp:192
KNode::Composer::View::hideExternalNotification
void hideExternalNotification()
Definition: kncomposerview.cpp:494
KNode::Composer::View::setFrom
void setFrom(const QString &from)
Set the name and email address of the sender of the message.
Definition: kncomposerview.cpp:229
KNComposer
Message composer window.
Definition: kncomposer.h:41
KNode::Composer::View::removeCurrentAttachment
void removeCurrentAttachment()
Remove the currently selected attachment if there is a selection.
Definition: kncomposerview.cpp:469
KNode::Composer::View::~View
virtual ~View()
Destructor.
Definition: kncomposerview.cpp:91
KNGlobals::identityManager
KPIMIdentities::IdentityManager * identityManager()
Returns the identity manager.
Definition: knglobals.cpp:167
KNComposer::MessageMode
MessageMode
Definition: kncomposer.h:50
KNode::Composer::View::followupTo
const QStringList followupTo() const
Returns the followup-to list of groups (name are trimmed).
Definition: kncomposerview.cpp:284
KNode::Composer::View::subject
const QString subject() const
Returns the subject text.
Definition: kncomposerview.cpp:327
KNComposerEditor
Definition: kncomposereditor.h:28
to
QString to() const
subject
QString subject() const
KNode::Composer::View::showAttachmentView
void showAttachmentView()
Definition: kncomposerview.cpp:396
KNGlobals::settings
KNode::Settings * settings()
Returns the KConfigXT generated settings object.
Definition: knglobals.cpp:182
KNode::Composer::View::closeExternalEditor
void closeExternalEditor()
This signal is emitted when the user request the external body editor to be closed.
KNode::Composer::View::setComposingFont
void setComposingFont(const QFont &font)
Changes the font used in edition widget within this ComposerView.
Definition: kncomposerview.cpp:182
QTreeWidgetItem
KNode::Composer::View::setFollowupTo
void setFollowupTo(const QString &followupTo)
Sets the followup-to list as a string (must be a coma separated list of groups).
Definition: kncomposerview.cpp:290
KNComposer::mail
Message is to be sent by e-mail.
Definition: kncomposer.h:52
knglobals.h
KNode::Composer::View::showExternalNotification
void showExternalNotification()
Definition: kncomposerview.cpp:488
KNode::Composer::View::groups
const QStringList groups() const
Returns the followup-to list of groups (name are trimmed).
Definition: kncomposerview.cpp:235
KNode::Composer::View::attachments
const QList< KNAttachment::Ptr > attachments() const
Returns the list of attachments of this message.
Definition: kncomposerview.cpp:464
KNode::Composer::View::displayFollowuptoHint
void displayFollowuptoHint()
Display an indication to the user about followup-to.
Definition: kncomposerview.cpp:296
KNode::Composer::View::addAttachment
void addAttachment(KNAttachment::Ptr attachment)
Adds an attachment to the message.
Definition: kncomposerview.cpp:458
settings.h
KNode::Composer::View::editor
KNComposerEditor * editor() const
Returns the main text editor.
Definition: kncomposerview.cpp:338
kncomposerview.h
KNode::Composer::View::hideAttachmentView
void hideAttachmentView()
Definition: kncomposerview.cpp:453
KNode::Composer::View::setSubject
void setSubject(const QString &subject)
Sets the subject.
Definition: kncomposerview.cpp:332
knGlobals
#define knGlobals
Keep compatibility with the old way.
Definition: knglobals.h:28
KNAttachment::Ptr
boost::shared_ptr< KNAttachment > Ptr
Shared pointer to a KNAttachment.
Definition: knarticle.h:281
KNComposer::news
Message is to be sent to a newsgroup.
Definition: kncomposer.h:51
QSplitter
KNode::Composer::View::completeSetup
void completeSetup(bool firstEdit, KNComposer::MessageMode mode)
Completes the setup of this view.
Definition: kncomposerview.cpp:108
KNode::Composer::View::selectedIdentity
uint selectedIdentity() const
Return the UOID of the selected identity.
Definition: kncomposerview.cpp:201
QList< int >
KNode::Composer::View::setGroups
void setGroups(const QString &groups)
Sets the group list as a string (must be coma separated).
Definition: kncomposerview.cpp:241
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal