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

kaddressbook

  • sources
  • kde-4.12
  • kdepim
  • kaddressbook
xxportmanager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KAddressBook.
3 
4  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include "xxportmanager.h"
22 #include "contactselectiondialog.h"
23 
24 #include <Akonadi/Collection>
25 #include <Akonadi/CollectionDialog>
26 #include <Akonadi/EntityTreeModel>
27 #include <Akonadi/Item>
28 #include <Akonadi/ItemCreateJob>
29 
30 #include <KLocale>
31 #include <KMessageBox>
32 #include <KProgressDialog>
33 
34 #include <QtCore/QPointer>
35 #include <QtCore/QSignalMapper>
36 #include <QAction>
37 #include <QItemSelectionModel>
38 #include <QWidget>
39 
40 XXPortManager::XXPortManager( QWidget *parent )
41  : QObject( parent ), mSelectionModel( 0 ),
42  mParentWidget( parent ), mImportProgressDialog( 0 )
43 {
44  mImportMapper = new QSignalMapper( this );
45  mExportMapper = new QSignalMapper( this );
46 
47  connect( mImportMapper, SIGNAL(mapped(QString)),
48  this, SLOT(slotImport(QString)) );
49  connect( mExportMapper, SIGNAL(mapped(QString)),
50  this, SLOT(slotExport(QString)) );
51 }
52 
53 XXPortManager::~XXPortManager()
54 {
55 }
56 
57 void XXPortManager::addImportAction( QAction *action, const QString &identifier )
58 {
59  mImportMapper->setMapping( action, identifier );
60  connect( action, SIGNAL(triggered(bool)), mImportMapper, SLOT(map()) );
61 }
62 
63 void XXPortManager::addExportAction( QAction *action, const QString &identifier )
64 {
65  mExportMapper->setMapping( action, identifier );
66  connect( action, SIGNAL(triggered(bool)), mExportMapper, SLOT(map()) );
67 }
68 
69 void XXPortManager::setSelectionModel( QItemSelectionModel *selectionModel )
70 {
71  mSelectionModel = selectionModel;
72 }
73 
74 void XXPortManager::setDefaultAddressBook( const Akonadi::Collection &addressBook )
75 {
76  mDefaultAddressBook = addressBook;
77 }
78 
79 void XXPortManager::slotImport( const QString &identifier )
80 {
81  const XXPort *xxport = mFactory.createXXPort( identifier, mParentWidget );
82  if( !xxport ) {
83  return;
84  }
85 
86  const KABC::Addressee::List contacts = xxport->importContacts();
87 
88  delete xxport;
89 
90  if ( contacts.isEmpty() ) { // nothing to import
91  return;
92  }
93 
94  const QStringList mimeTypes( KABC::Addressee::mimeType() );
95 
96  QPointer<Akonadi::CollectionDialog> dlg = new Akonadi::CollectionDialog( mParentWidget );
97  dlg->setMimeTypeFilter( mimeTypes );
98  dlg->setAccessRightsFilter( Akonadi::Collection::CanCreateItem );
99  dlg->setCaption( i18n( "Select Address Book" ) );
100  dlg->setDescription(
101  i18n( "Select the address book the imported contact(s) shall be saved in:" ) );
102  dlg->setDefaultCollection( mDefaultAddressBook );
103 
104  if ( !dlg->exec() || !dlg ) {
105  delete dlg;
106  return;
107  }
108 
109  const Akonadi::Collection collection = dlg->selectedCollection();
110  delete dlg;
111 
112  if ( !mImportProgressDialog ) {
113  mImportProgressDialog = new KProgressDialog( mParentWidget, i18n( "Import Contacts" ) );
114  mImportProgressDialog->setLabelText(
115  i18np( "Importing one contact to %2", "Importing %1 contacts to %2",
116  contacts.count(), collection.name() ) );
117  mImportProgressDialog->setAllowCancel( false );
118  mImportProgressDialog->setAutoClose( true );
119  mImportProgressDialog->progressBar()->setRange( 1, contacts.count() );
120  }
121 
122  mImportProgressDialog->show();
123 
124  for ( int i = 0; i < contacts.count(); ++i ) {
125  Akonadi::Item item;
126  item.setPayload<KABC::Addressee>( contacts.at( i ) );
127  item.setMimeType( KABC::Addressee::mimeType() );
128 
129  Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection );
130  connect( job, SIGNAL(result(KJob*)), SLOT(slotImportJobDone(KJob*)) );
131  }
132 }
133 
134 void XXPortManager::slotImportJobDone( KJob * )
135 {
136  if ( !mImportProgressDialog ) {
137  return;
138  }
139 
140  QProgressBar *progressBar = mImportProgressDialog->progressBar();
141 
142  progressBar->setValue( progressBar->value() + 1 );
143 
144  // cleanup on last step
145  if ( progressBar->value() == progressBar->maximum() ) {
146  mImportProgressDialog->deleteLater();
147  mImportProgressDialog = 0;
148  }
149 }
150 
151 void XXPortManager::slotExport( const QString &identifier )
152 {
153  if ( !mSelectionModel ) {
154  return;
155  }
156 
157  QPointer<ContactSelectionDialog> dlg =
158  new ContactSelectionDialog( mSelectionModel, mParentWidget );
159  dlg->setMessageText( i18n( "Which contact do you want to export?" ) );
160  dlg->setDefaultAddressBook( mDefaultAddressBook );
161  if ( !dlg->exec() || !dlg ) {
162  delete dlg;
163  return;
164  }
165 
166  const KABC::AddresseeList contacts = dlg->selectedContacts();
167  delete dlg;
168 
169  if ( contacts.isEmpty() ) {
170  KMessageBox::sorry( 0, i18n( "You have not selected any contacts to export." ) );
171  return;
172  }
173 
174  const XXPort *xxport = mFactory.createXXPort( identifier, mParentWidget );
175  if ( !xxport ) {
176  return;
177  }
178 
179  xxport->exportContacts( contacts );
180 
181  delete xxport;
182 }
183 
184 #include "xxportmanager.moc"
XXPort::exportContacts
virtual bool exportContacts(const KABC::Addressee::List &contacts) const =0
Exports the list of contacts.
Definition: xxport.cpp:36
QObject
xxportmanager.h
XXPortManager::XXPortManager
XXPortManager(QWidget *parent=0)
Creates a new xxport manager.
Definition: xxportmanager.cpp:40
XXPortManager::setSelectionModel
void setSelectionModel(QItemSelectionModel *model)
Sets the model that contains the current selection.
Definition: xxportmanager.cpp:69
XXPortManager::setDefaultAddressBook
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the addressBook that shall be preselected in the ContactSelectionDialog.
Definition: xxportmanager.cpp:74
XXPortManager::addImportAction
void addImportAction(QAction *action, const QString &identifier)
Adds a new action to import contacts.
Definition: xxportmanager.cpp:57
XXPort
The base class for all import/export modules.
Definition: xxport.h:32
XXPort::importContacts
virtual KABC::Addressee::List importContacts() const =0
Imports a list of contacts.
Definition: xxport.cpp:31
XXPortManager::~XXPortManager
~XXPortManager()
Destroys the xxport manager.
Definition: xxportmanager.cpp:53
ContactSelectionDialog
A dialog to select a group of contacts.
Definition: contactselectiondialog.h:40
contactselectiondialog.h
XXPortFactory::createXXPort
XXPort * createXXPort(const QString &identifier, QWidget *parentWidget) const
Returns a new import/export module that matches the given identifier or a null pointer if the identif...
Definition: xxportfactory.cpp:28
XXPortManager::addExportAction
void addExportAction(QAction *action, const QString &identifier)
Adds a new action to export contacts.
Definition: xxportmanager.cpp:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • 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

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