24 #include <Akonadi/Collection>
25 #include <Akonadi/CollectionDialog>
26 #include <Akonadi/EntityTreeModel>
27 #include <Akonadi/Item>
28 #include <Akonadi/ItemCreateJob>
31 #include <KMessageBox>
32 #include <KProgressDialog>
34 #include <QtCore/QPointer>
35 #include <QtCore/QSignalMapper>
37 #include <QItemSelectionModel>
41 :
QObject( parent ), mSelectionModel( 0 ),
42 mParentWidget( parent ), mImportProgressDialog( 0 )
44 mImportMapper =
new QSignalMapper(
this );
45 mExportMapper =
new QSignalMapper(
this );
47 connect( mImportMapper, SIGNAL(mapped(QString)),
48 this, SLOT(slotImport(QString)) );
49 connect( mExportMapper, SIGNAL(mapped(QString)),
50 this, SLOT(slotExport(QString)) );
59 mImportMapper->setMapping( action, identifier );
60 connect( action, SIGNAL(triggered(
bool)), mImportMapper, SLOT(map()) );
65 mExportMapper->setMapping( action, identifier );
66 connect( action, SIGNAL(triggered(
bool)), mExportMapper, SLOT(map()) );
71 mSelectionModel = selectionModel;
76 mDefaultAddressBook = addressBook;
79 void XXPortManager::slotImport(
const QString &identifier )
90 if ( contacts.isEmpty() ) {
94 const QStringList mimeTypes( KABC::Addressee::mimeType() );
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" ) );
101 i18n(
"Select the address book the imported contact(s) shall be saved in:" ) );
102 dlg->setDefaultCollection( mDefaultAddressBook );
104 if ( !dlg->exec() || !dlg ) {
109 const Akonadi::Collection collection = dlg->selectedCollection();
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() );
122 mImportProgressDialog->show();
124 for (
int i = 0; i < contacts.count(); ++i ) {
126 item.setPayload<KABC::Addressee>( contacts.at( i ) );
127 item.setMimeType( KABC::Addressee::mimeType() );
129 Akonadi::ItemCreateJob *job =
new Akonadi::ItemCreateJob( item, collection );
130 connect( job, SIGNAL(result(KJob*)), SLOT(slotImportJobDone(KJob*)) );
134 void XXPortManager::slotImportJobDone( KJob * )
136 if ( !mImportProgressDialog ) {
140 QProgressBar *progressBar = mImportProgressDialog->progressBar();
142 progressBar->setValue( progressBar->value() + 1 );
145 if ( progressBar->value() == progressBar->maximum() ) {
146 mImportProgressDialog->deleteLater();
147 mImportProgressDialog = 0;
151 void XXPortManager::slotExport(
const QString &identifier )
153 if ( !mSelectionModel ) {
157 QPointer<ContactSelectionDialog> dlg =
159 dlg->setMessageText( i18n(
"Which contact do you want to export?" ) );
160 dlg->setDefaultAddressBook( mDefaultAddressBook );
161 if ( !dlg->exec() || !dlg ) {
166 const KABC::AddresseeList contacts = dlg->selectedContacts();
169 if ( contacts.isEmpty() ) {
170 KMessageBox::sorry( 0, i18n(
"You have not selected any contacts to export." ) );
184 #include "xxportmanager.moc"
virtual bool exportContacts(const KABC::Addressee::List &contacts) const =0
Exports the list of contacts.
XXPortManager(QWidget *parent=0)
Creates a new xxport manager.
void setSelectionModel(QItemSelectionModel *model)
Sets the model that contains the current selection.
void setDefaultAddressBook(const Akonadi::Collection &addressBook)
Sets the addressBook that shall be preselected in the ContactSelectionDialog.
void addImportAction(QAction *action, const QString &identifier)
Adds a new action to import contacts.
The base class for all import/export modules.
virtual KABC::Addressee::List importContacts() const =0
Imports a list of contacts.
~XXPortManager()
Destroys the xxport manager.
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...
void addExportAction(QAction *action, const QString &identifier)
Adds a new action to export contacts.