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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • dialog
addemailtoexistingcontactdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "addemailtoexistingcontactdialog.h"
19 #include "kmkernel.h"
20 
21 #include <Akonadi/Contact/EmailAddressSelectionWidget>
22 #include <Akonadi/Session>
23 #include <Akonadi/ItemFetchScope>
24 #include <Akonadi/EntityDisplayAttribute>
25 #include <Akonadi/Contact/ContactsTreeModel>
26 #include <Akonadi/ChangeRecorder>
27 
28 #include <KABC/Addressee>
29 
30 #include <KLocalizedString>
31 
32 #include <QTreeView>
33 
34 
35 AddEmailToExistingContactDialog::AddEmailToExistingContactDialog(QWidget *parent)
36  : KDialog(parent)
37 {
38  setCaption( i18n( "Select Contact" ) );
39  setButtons( Ok|Cancel );
40  setDefaultButton( Ok );
41  setButtonText(KDialog::Ok, i18n("Select"));
42  setModal( true );
43 
44  Akonadi::Session *session = new Akonadi::Session( "AddEmailToExistingContactDialog", this );
45 
46  Akonadi::ItemFetchScope scope;
47  scope.fetchFullPayload( true );
48  scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
49 
50  Akonadi::ChangeRecorder *changeRecorder = new Akonadi::ChangeRecorder( this );
51  changeRecorder->setSession( session );
52  changeRecorder->fetchCollection( true );
53  changeRecorder->setItemFetchScope( scope );
54  changeRecorder->setCollectionMonitored( Akonadi::Collection::root() );
55  //Just select address no group
56  changeRecorder->setMimeTypeMonitored( KABC::Addressee::mimeType(), true );
57 
58  Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( changeRecorder, this );
59 
60  mEmailSelectionWidget = new Akonadi::EmailAddressSelectionWidget(false, model, this);
61  setMainWidget(mEmailSelectionWidget);
62  mEmailSelectionWidget->view()->setSelectionMode(QAbstractItemView::SingleSelection);
63  readConfig();
64  connect(mEmailSelectionWidget->view()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged()));
65  enableButtonOk(false);
66 }
67 
68 AddEmailToExistingContactDialog::~AddEmailToExistingContactDialog()
69 {
70  writeConfig();
71 }
72 
73 void AddEmailToExistingContactDialog::slotSelectionChanged()
74 {
75  enableButtonOk(!mEmailSelectionWidget->selectedAddresses().isEmpty());
76 }
77 
78 void AddEmailToExistingContactDialog::readConfig()
79 {
80  KConfigGroup group( KMKernel::self()->config(), "AddEmailToExistingContactDialog" );
81  const QSize size = group.readEntry( "Size", QSize(600, 400) );
82  if ( size.isValid() ) {
83  resize( size );
84  }
85 }
86 
87 void AddEmailToExistingContactDialog::writeConfig()
88 {
89  KConfigGroup group( KMKernel::self()->config(), "AddEmailToExistingContactDialog" );
90  group.writeEntry( "Size", size() );
91  group.sync();
92 }
93 
94 Akonadi::Item AddEmailToExistingContactDialog::selectedContact() const
95 {
96  Akonadi::Item item;
97  Akonadi::EmailAddressSelection::List lst = mEmailSelectionWidget->selectedAddresses();
98  if (!lst.isEmpty()) {
99  item = lst.first().item();
100  }
101  return item;
102 }
103 
104 #include "moc_addemailtoexistingcontactdialog.cpp"
QWidget
QSize::isValid
bool isValid() const
addemailtoexistingcontactdialog.h
KDialog
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1471
AddEmailToExistingContactDialog::AddEmailToExistingContactDialog
AddEmailToExistingContactDialog(QWidget *parent)
Definition: addemailtoexistingcontactdialog.cpp:35
AddEmailToExistingContactDialog::selectedContact
Akonadi::Item selectedContact() const
Definition: addemailtoexistingcontactdialog.cpp:94
QSize
QItemSelection
kmkernel.h
AddEmailToExistingContactDialog::~AddEmailToExistingContactDialog
~AddEmailToExistingContactDialog()
Definition: addemailtoexistingcontactdialog.cpp:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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
  • pimprint

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