<commit_before>/*
    This file is part of KMail.

    Copyright (c) 2005 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
    
    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "distributionlistdialog.h"

#include <libemailfunctions/email.h>
#include <kabc/stdaddressbook.h>
#include <kabc/distributionlist.h>

#include <klistview.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kinputdialog.h>

#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>

class RecipientItem : public QCheckListItem
{
  public:
    RecipientItem( QListView *list, const KABC::Addressee &addressee )
      : QCheckListItem( list, addressee.realName(), CheckBox ),
        mAddressee( addressee )
    {
      setText( 1, addressee.preferredEmail() );
    }

    KABC::Addressee addressee() const
    {
      return mAddressee;
    }
    
  private:
    KABC::Addressee mAddressee;
};


DistributionListDialog::DistributionListDialog( QWidget *parent )
  : KDialogBase( Plain, i18n("Create Distribution List"), User1 | Cancel,
                 Cancel, parent, 0, false, false, i18n("Create List") )
{
  QFrame *topFrame = plainPage();
  
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );
  topLayout->setSpacing( spacingHint() );
  
  QBoxLayout *titleLayout = new QHBoxLayout( topLayout );
  
  QLabel *label = new QLabel( i18n("Name:"), topFrame );
  titleLayout->addWidget( label );
  
  mTitleEdit = new QLineEdit( topFrame );
  titleLayout->addWidget( mTitleEdit );
  
  mRecipientsList = new KListView( topFrame );
  mRecipientsList->addColumn( i18n("Recipients") );
  topLayout->addWidget( mRecipientsList );
}

void DistributionListDialog::setRecipients( const Recipient::List &recipients )
{
  Recipient::List::ConstIterator it;
  for( it = recipients.begin(); it != recipients.end(); ++it ) {
    QStringList emails = KPIM::splitEmailAddrList( (*it).email() );
    QStringList::ConstIterator it2;
    for( it2 = emails.begin(); it2 != emails.end(); ++it2 ) {
      QString email = KPIM::getEmailAddress( *it2 );
      if ( !email.isEmpty() ) {
        KABC::Addressee::List addressees =
          KABC::StdAddressBook::self( true )->findByEmail( email );
        KABC::Addressee::List::ConstIterator it3;
        for( it3 = addressees.begin(); it3 != addressees.end(); ++it3 ) {
          RecipientItem *item = new RecipientItem( mRecipientsList, *it3 );
          if ( it3 == addressees.begin() ) item->setOn( true );
        }
      }
    }
  }
}

void DistributionListDialog::slotUser1()
{
  kdDebug() << "Create Distribution List '" << mTitleEdit->text() << "':"
    << endl;

  KABC::Addressee::List addressees;

  KABC::StdAddressBook *ab = KABC::StdAddressBook::self( true );

  QListViewItem *i = mRecipientsList->firstChild();
  while( i ) {
    RecipientItem *item = static_cast<RecipientItem *>( i );
    if ( item->isOn() ) {
      kdDebug() << "  " << item->addressee().fullEmail() << endl;
      addressees.append( item->addressee() );
    }
    i = i->nextSibling();<commit_msg>--enable-final: Rename for name clash with recipientspicker.h<commit_after>/*
    This file is part of KMail.

    Copyright (c) 2005 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
    
    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "distributionlistdialog.h"

#include <libemailfunctions/email.h>
#include <kabc/stdaddressbook.h>
#include <kabc/distributionlist.h>

#include <klistview.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kinputdialog.h>

#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>

class NewStyleRecipientItem : public QCheckListItem
{
  public:
    NewStyleRecipientItem( QListView *list, const KABC::Addressee &addressee )
      : QCheckListItem( list, addressee.realName(), CheckBox ),
        mAddressee( addressee )
    {
      setText( 1, addressee.preferredEmail() );
    }

    KABC::Addressee addressee() const
    {
      return mAddressee;
    }
    
  private:
    KABC::Addressee mAddressee;
};


DistributionListDialog::DistributionListDialog( QWidget *parent )
  : KDialogBase( Plain, i18n("Create Distribution List"), User1 | Cancel,
                 Cancel, parent, 0, false, false, i18n("Create List") )
{
  QFrame *topFrame = plainPage();
  
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );
  topLayout->setSpacing( spacingHint() );
  
  QBoxLayout *titleLayout = new QHBoxLayout( topLayout );
  
  QLabel *label = new QLabel( i18n("Name:"), topFrame );
  titleLayout->addWidget( label );
  
  mTitleEdit = new QLineEdit( topFrame );
  titleLayout->addWidget( mTitleEdit );
  
  mRecipientsList = new KListView( topFrame );
  mRecipientsList->addColumn( i18n("Recipients") );
  topLayout->addWidget( mRecipientsList );
}

void DistributionListDialog::setRecipients( const Recipient::List &recipients )
{
  Recipient::List::ConstIterator it;
  for( it = recipients.begin(); it != recipients.end(); ++it ) {
    QStringList emails = KPIM::splitEmailAddrList( (*it).email() );
    QStringList::ConstIterator it2;
    for( it2 = emails.begin(); it2 != emails.end(); ++it2 ) {
      QString email = KPIM::getEmailAddress( *it2 );
      if ( !email.isEmpty() ) {
        KABC::Addressee::List addressees =
          KABC::StdAddressBook::self( true )->findByEmail( email );
        KABC::Addressee::List::ConstIterator it3;
        for( it3 = addressees.begin(); it3 != addressees.end(); ++it3 ) {
          NewStyleRecipientItem *item = new NewStyleRecipientItem( mRecipientsList, *it3 );
          if ( it3 == addressees.begin() ) item->setOn( true );
        }
      }
    }
  }
}

void DistributionListDialog::slotUser1()
{
  kdDebug() << "Create Distribution List '" << mTitleEdit->text() << "':"
    << endl;

  KABC::Addressee::List addressees;

  KABC::StdAddressBook *ab = KABC::StdAddressBook::self( true );

  QListViewItem *i = mRecipientsList->firstChild();
  while( i ) {
    NewStyleRecipientItem *item = static_cast<NewStyleRecipientItem *>( i );
    if ( item->isOn() ) {
      kdDebug() << "  " << item->addressee().fullEmail() << endl;
      addressees.append( item->addressee() );
    }
    i = i->nextSibling();
{'fraction_non_alphanumeric': 0.12324966974900925, 'fraction_numerical': 0.011096433289299868, 'mean_word_length': 3.5746223564954684, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6590970', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2370, 'n_words': 657}