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

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • job
openemailaddressjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2010 Tobias Koenig <tokoe@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "openemailaddressjob.h"
21 
22 #include "job/addemailaddressjob.h"
23 
24 #include <akonadi/collectiondialog.h>
25 #include <akonadi/contact/contacteditordialog.h>
26 #include <akonadi/contact/contactsearchjob.h>
27 #include <akonadi/item.h>
28 #include <akonadi/itemcreatejob.h>
29 #include <kabc/addressee.h>
30 #include <klocale.h>
31 #include <kmessagebox.h>
32 
33 using namespace KPIM;
34 
35 class OpenEmailAddressJob::Private
36 {
37  public:
38  Private( OpenEmailAddressJob *qq, const QString &emailString, QWidget *parentWidget )
39  : q( qq ), mCompleteAddress( emailString ), mParentWidget( parentWidget )
40  {
41  KABC::Addressee::parseEmailAddress( emailString, mName, mEmail );
42  }
43 
44  void slotSearchDone( KJob *job )
45  {
46  if ( job->error() ) {
47  q->setError( job->error() );
48  q->setErrorText( job->errorText() );
49  q->emitResult();
50  return;
51  }
52 
53  const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
54 
55  const Akonadi::Item::List contacts = searchJob->items();
56  if ( !contacts.isEmpty() ) {
57  // open the editor with the matching item
58  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::EditMode, mParentWidget );
59  dlg.setContact( contacts.first() );
60  dlg.exec();
61 
62  q->emitResult();
63  return;
64  }
65 
66  AddEmailAddressJob *createJob = new AddEmailAddressJob( mCompleteAddress, mParentWidget, q );
67  q->connect( createJob, SIGNAL(result(KJob*)), SLOT(slotAddContactDone(KJob*)) );
68  createJob->start();
69  }
70 
71  void slotAddContactDone( KJob *job )
72  {
73  if ( job->error() ) {
74  q->setError( job->error() );
75  q->setErrorText( job->errorText() );
76  q->emitResult();
77  return;
78  }
79 
80  const AddEmailAddressJob *createJob = qobject_cast<AddEmailAddressJob*>( job );
81 
82  // open the editor with the matching item
83  Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::EditMode, mParentWidget );
84  dlg.setContact( createJob->contact() );
85  dlg.exec();
86 
87  q->emitResult();
88  }
89 
90  OpenEmailAddressJob *q;
91  QString mCompleteAddress;
92  QString mEmail;
93  QString mName;
94  QWidget *mParentWidget;
95 };
96 
97 OpenEmailAddressJob::OpenEmailAddressJob( const QString &email, QWidget *parentWidget, QObject *parent )
98  : KJob( parent ), d( new Private( this, email, parentWidget ) )
99 {
100 }
101 
102 OpenEmailAddressJob::~OpenEmailAddressJob()
103 {
104  delete d;
105 }
106 
107 void OpenEmailAddressJob::start()
108 {
109  // first check whether a contact with the same email exists already
110  Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob( this );
111  searchJob->setLimit( 1 );
112  searchJob->setQuery( Akonadi::ContactSearchJob::Email, d->mEmail.toLower(),
113  Akonadi::ContactSearchJob::ExactMatch );
114  connect( searchJob, SIGNAL(result(KJob*)), SLOT(slotSearchDone(KJob*)) );
115 }
116 
117 #include "openemailaddressjob.moc"
KPIM::AddEmailAddressJob::contact
Akonadi::Item contact() const
Returns the item that represents the new contact.
Definition: addemailaddressjob.cpp:291
KPIM::OpenEmailAddressJob
A job to open the contact editor for a contact with a given email address.
Definition: openemailaddressjob.h:39
KPIM::OpenEmailAddressJob::start
virtual void start()
Starts the job.
Definition: openemailaddressjob.cpp:107
KPIM::AddEmailAddressJob
A job to add a new contact with a given email address to Akonadi.
Definition: addemailaddressjob.h:40
QWidget
openemailaddressjob.h
QObject
KPIM::OpenEmailAddressJob::~OpenEmailAddressJob
~OpenEmailAddressJob()
Destroys the open email address job.
Definition: openemailaddressjob.cpp:102
KPIM::AddEmailAddressJob::start
virtual void start()
Starts the job.
Definition: addemailaddressjob.cpp:281
addemailaddressjob.h
KJob
KPIM::OpenEmailAddressJob::OpenEmailAddressJob
OpenEmailAddressJob(const QString &email, QWidget *parentWidget, QObject *parent=0)
Creates a new open email address job.
Definition: openemailaddressjob.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

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

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