23 #include <Akonadi/CollectionComboBox> 
   24 #include <Akonadi/EntityTreeModel> 
   25 #include <Akonadi/ItemFetchJob> 
   26 #include <Akonadi/ItemFetchScope> 
   27 #include <Akonadi/RecursiveItemFetchJob> 
   29 #include <KLocalizedString> 
   31 #include <QButtonGroup> 
   33 #include <QGridLayout> 
   35 #include <QItemSelectionModel> 
   37 #include <QRadioButton> 
   38 #include <QVBoxLayout> 
   42     : 
QWidget( parent ), mSelectionModel( selectionModel ), mAddContactGroup(false)
 
   47     mAddressBookSelection->setEnabled( 
false );
 
   48     mAddressBookSelectionRecursive->
setEnabled( 
false );
 
   50     connect( mAddressBookContactsButton, SIGNAL(toggled(
bool)),
 
   51              mAddressBookSelection, SLOT(
setEnabled(
bool)) );
 
   52     connect( mAddressBookContactsButton, SIGNAL(toggled(
bool)),
 
   53              mAddressBookSelectionRecursive, SLOT(
setEnabled(
bool)) );
 
   65     mMessageLabel->
setText( message );
 
   70     mAddressBookSelection->setDefaultCollection( addressBook );
 
   76         return collectAllContacts();
 
   77     } 
else if ( mSelectedContactsButton->
isChecked() ) {
 
   78         return collectSelectedContacts();
 
   79     } 
else if ( mAddressBookContactsButton->
isChecked() ) {
 
   80         return collectAddressBookContacts();
 
   89     mAddContactGroup = addGroupContact;
 
   93 void ContactSelectionWidget::initGui()
 
   97     mMessageLabel = 
new QLabel;
 
  107     mAllContactsButton = 
new QRadioButton( i18nc( 
"@option:radio", 
"All contacts" ) );
 
  109                 i18nc( 
"@info:tooltip", 
"All contacts from all your address books" ) );
 
  111                 i18nc( 
"@info:whatsthis",
 
  112                        "Choose this option you want to select all your contacts from " 
  113                        "all your address books." ) );
 
  115     mSelectedContactsButton = 
new QRadioButton( i18nc( 
"@option:radio",
"Selected contacts" ) );
 
  117                 i18nc( 
"@info:tooltip", 
"Only the contacts currently selected" ) );
 
  119                 i18nc( 
"@info:whatsthis",
 
  120                        "Choose this option if you want only the contacts you have already " 
  121                        "selected in the graphical interface." ) );
 
  123     mAddressBookContactsButton = 
new QRadioButton( i18nc( 
"@option:radio", 
"All contacts from:" ) );
 
  125                 i18nc( 
"@info:tooltip", 
"All contacts from a chosen address book" ) );
 
  127                 i18nc( 
"@info:whatsthis",
 
  128                        "Choose this option if you want to select all the contacts from only one " 
  129                        "of your address books.  Once this option is clicked you will be provided " 
  130                        "a drop down box listing all those address books and permitted to select " 
  131                        "the one you want." ) );
 
  133     mAddressBookSelection = 
new Akonadi::CollectionComboBox;
 
  134     mAddressBookSelection->setMimeTypeFilter( 
QStringList() << KABC::Addressee::mimeType() );
 
  135     mAddressBookSelection->setAccessRightsFilter( Akonadi::Collection::ReadOnly );
 
  136     mAddressBookSelection->setExcludeVirtualCollections( 
true );
 
  137     mAddressBookSelectionRecursive = 
new QCheckBox( i18nc( 
"@option:check", 
"Include Subfolders" ) );
 
  139                 i18nc( 
"@info:tooltip", 
"Select all subfolders including the top-level folder" ) );
 
  141                 i18nc( 
"@info:whatsthis",
 
  142                        "Check this box if you want to select all contacts from this folder, " 
  143                        "including all subfolders.  If you only want the contacts from the " 
  144                        "top-level folder then leave this box unchecked." ) );
 
  147     group->
addButton( mSelectedContactsButton );
 
  148     group->
addButton( mAddressBookContactsButton );
 
  150     boxLayout->
addWidget( mAllContactsButton, 0, 0, 1, 2 );
 
  151     boxLayout->
addWidget( mSelectedContactsButton, 1, 0, 1, 2 );
 
  152     boxLayout->
addWidget( mAddressBookContactsButton, 2, 0, Qt::AlignTop );
 
  156     addressBookLayout->
addWidget( mAddressBookSelection );
 
  157     addressBookLayout->
addWidget( mAddressBookSelectionRecursive );
 
  159     boxLayout->
addLayout( addressBookLayout, 2, 1 );
 
  165 ContactList ContactSelectionWidget::collectAllContacts()
 const 
  168     Akonadi::RecursiveItemFetchJob *job =
 
  169             new Akonadi::RecursiveItemFetchJob( Akonadi::Collection::root(),
 
  171     job->fetchScope().fetchFullPayload();
 
  173     if ( !job->exec() ) {
 
  177     foreach ( 
const Akonadi::Item &item, job->items() ) {
 
  178         if ( item.isValid() ) {
 
  179             if (item.hasPayload<KABC::Addressee>() ) {
 
  180                 contacts.
append( item.payload<KABC::Addressee>() );
 
  189 ContactList ContactSelectionWidget::collectSelectedContacts()
 const 
  193     const QModelIndexList indexes = mSelectionModel->
selectedRows( 0 );
 
  194     for ( 
int i = 0; i < indexes.count(); ++i ) {
 
  197             const Akonadi::Item item =
 
  198                     index.
data( Akonadi::EntityTreeModel::ItemRole ).
value<Akonadi::Item>();
 
  199             if ( item.isValid() ) {
 
  200                 if (item.hasPayload<KABC::Addressee>() ) {
 
  201                     contacts.
append( item.payload<KABC::Addressee>() );
 
  210 ContactList ContactSelectionWidget::collectAddressBookContacts()
 const 
  214     const Akonadi::Collection collection = mAddressBookSelection->currentCollection();
 
  215     if ( !collection.isValid() ) {
 
  219     if ( mAddressBookSelectionRecursive->
isChecked() ) {
 
  220         Akonadi::RecursiveItemFetchJob *job =
 
  221                 new Akonadi::RecursiveItemFetchJob( collection,
 
  223         job->fetchScope().fetchFullPayload();
 
  225         if ( !job->exec() ) {
 
  229         foreach ( 
const Akonadi::Item &item, job->items() ) {
 
  230             if ( item.hasPayload<KABC::Addressee>() ) {
 
  231                 contacts.
append( item.payload<KABC::Addressee>() );
 
  235         Akonadi::ItemFetchJob *job = 
new Akonadi::ItemFetchJob( collection );
 
  236         job->fetchScope().fetchFullPayload();
 
  238         if ( !job->exec() ) {
 
  242         foreach ( 
const Akonadi::Item &item, job->items() ) {
 
  243             if ( item.hasPayload<KABC::Addressee>() ) {
 
  244                 contacts.
append( item.payload<KABC::Addressee>() );
 
QModelIndexList selectedRows(int column) const
bool hasSelection() const
void setText(const QString &)
void setMargin(int margin)
void addLayout(QLayout *layout, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QVariant data(int role) const
void addStretch(int stretch)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)