diff --git a/recipientseditor.cpp b/recipientseditor.cpp index 73cb30304..abc81dbd6 100644 --- a/recipientseditor.cpp +++ b/recipientseditor.cpp @@ -374,7 +374,7 @@ void RecipientsView::calculateTotal() } if ( empty == 0 ) addLine(); - + emit totalChanged( count, mLines.count() ); } @@ -502,6 +502,23 @@ Recipient::List RecipientsView::recipients() const return recipients; } +void RecipientsView::removeRecipient( const QString & recipient, + Recipient::Type type ) +{ + // search a line which matches recipient and type + QPtrListIterator it( mLines ); + RecipientLine *line; + while( ( line = it.current() ) ) { + if ( ( line->recipient().email() == recipient ) && + ( line->recipientType() == type ) ) { + break; + } + ++it; + } + if ( line ) + line->clear(); +} + void RecipientsView::setFocus() { if ( mLines.last()->isActive() ) setFocusBottom(); @@ -754,9 +771,7 @@ void RecipientsEditor::setRecipientString( const QString &str, .arg( r.count() ) ); break; } - RecipientLine *line = mRecipientsView->emptyLine(); - if ( !line ) line = mRecipientsView->addLine(); - line->setRecipient( Recipient( *it, type ) ); + addRecipient( *it, type ); } } @@ -778,6 +793,20 @@ QString RecipientsEditor::recipientString( Recipient::Type type ) return str; } +void RecipientsEditor::addRecipient( const QString & recipient, + Recipient::Type type ) +{ + RecipientLine *line = mRecipientsView->emptyLine(); + if ( !line ) line = mRecipientsView->addLine(); + line->setRecipient( Recipient( recipient, type ) ); +} + +void RecipientsEditor::removeRecipient( const QString & recipient, + Recipient::Type type ) +{ + mRecipientsView->removeRecipient( recipient, type ); +} + void RecipientsEditor::clear() { } diff --git a/recipientseditor.h b/recipientseditor.h index 7a9ac6641..f337d21f4 100644 --- a/recipientseditor.h +++ b/recipientseditor.h @@ -167,6 +167,12 @@ class RecipientsView : public QScrollView Recipient::List recipients() const; + /** Removes the recipient provided it can be found and has the given type. + @param recipient The recipient(s) you want to remove. + @param type The recipient type. + */ + void removeRecipient( const QString & recipient, Recipient::Type type ); + void activateLine( RecipientLine * ); void setFirstColumnWidth( int ); @@ -263,6 +269,18 @@ class RecipientsEditor : public QWidget void setRecipientString( const QString &, Recipient::Type ); QString recipientString( Recipient::Type ); + /** Adds a recipient (or multiple recipients) to one line of the editor. + @param recipient The recipient(s) you want to add. + @param type The recipient type. + */ + void addRecipient( const QString & recipient, Recipient::Type type ); + + /** Removes the recipient provided it can be found and has the given type. + @param recipient The recipient(s) you want to remove. + @param type The recipient type. + */ + void removeRecipient( const QString & recipient, Recipient::Type type ); + void setFirstColumnWidth( int ); public slots: