Commit 4422f1cd authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

I didn't like to have two dialog to export as vcard

parent 9ccf8ad3
......@@ -80,7 +80,8 @@ set(kaddressbook_xxport_SRCS
xxport/xxportfactory.cpp
xxport/xxportmanager.cpp
xxport/vcard/vcardviewerdialog.cpp
xxport/vcard/vcardexportselectiondialog.cpp
xxport/vcard/vcardexportselectionwidget.cpp
xxport/contactselectiondialog.cpp
)
set(kaddressbook_merge_SRCS
......@@ -106,7 +107,6 @@ set(kaddressbook_LIB_SRCS
categoryfilterproxymodel.cpp
categoryselectwidget.cpp
contactfields.cpp
contactselectiondialog.cpp
contactselectionwidget.cpp
contactsorter.cpp
contactswitcher.cpp
......
<!DOCTYPE kpartgui>
<kpartgui name="kaddressbook" version="25">
<kpartgui name="kaddressbook" version="26">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
......@@ -32,9 +32,9 @@
<Action name="file_print"/>
<Action name="file_print_preview"/>
<!-- <Separator/>
<Action name="merge_contacts"/>
<Action name="merge_contacts"/> -->
<Action name="search_duplicate_contacts"/>
<Separator/> -->
<Separator/>
<Action name="file_quit"/>
</Menu>
......
......@@ -20,17 +20,31 @@
#include "contactselectiondialog.h"
#include "contactselectionwidget.h"
#include <QVBoxLayout>
#include <KLocalizedString>
ContactSelectionDialog::ContactSelectionDialog( QItemSelectionModel *selectionModel,
ContactSelectionDialog::ContactSelectionDialog( QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport,
QWidget *parent )
: KDialog( parent )
: KDialog( parent ),
mVCardExport(0)
{
setCaption( i18n( "Select Contacts" ) );
setButtons( Ok | Cancel );
mSelectionWidget = new ContactSelectionWidget( selectionModel, this );
setMainWidget( mSelectionWidget );
if (allowToSelectTypeToExport) {
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainWidget->setLayout(mainLayout);
mainLayout->addWidget(mSelectionWidget);
mVCardExport = new VCardExportSelectionWidget;
mainLayout->addWidget(mVCardExport);
setMainWidget(mainWidget);
} else {
setMainWidget( mSelectionWidget );
}
setInitialSize( QSize( 450, 220 ) );
}
......@@ -50,3 +64,12 @@ KABC::Addressee::List ContactSelectionDialog::selectedContacts() const
return mSelectionWidget->selectedContacts();
}
VCardExportSelectionWidget::ExportFields ContactSelectionDialog::exportType() const
{
if (mVCardExport) {
return mVCardExport->exportType();
} else {
return VCardExportSelectionWidget::None;
}
}
......@@ -22,11 +22,10 @@
#include <KABC/Addressee>
#include <KDialog>
class ContactSelectionWidget;
#include <xxport/vcard/vcardexportselectionwidget.h>
class QItemSelectionModel;
class ContactSelectionWidget;
namespace Akonadi
{
class Collection;
......@@ -48,7 +47,7 @@ public:
* @param selectionModel The model that contains the currently selected contacts.
* @param parent The parent widget.
*/
explicit ContactSelectionDialog( QItemSelectionModel *selectionModel, QWidget *parent = 0 );
explicit ContactSelectionDialog(QItemSelectionModel *selectionModel, bool allowToSelectTypeToExport, QWidget *parent = 0 );
/**
* Sets the @p message text.
......@@ -65,8 +64,10 @@ public:
*/
KABC::Addressee::List selectedContacts() const;
VCardExportSelectionWidget::ExportFields exportType() const;
private:
ContactSelectionWidget *mSelectionWidget;
VCardExportSelectionWidget *mVCardExport;
};
#endif
......@@ -39,7 +39,7 @@ CsvXXPort::CsvXXPort( QWidget *parent )
{
}
bool CsvXXPort::exportContacts( const KABC::Addressee::List &contacts ) const
bool CsvXXPort::exportContacts(const KABC::Addressee::List &contacts , VCardExportSelectionWidget::ExportFields ) const
{
KUrl url = KFileDialog::getSaveUrl( KUrl( QLatin1String("addressbook.csv") ) );
if ( url.isEmpty() ) {
......
......@@ -29,7 +29,7 @@ class CsvXXPort : public XXPort
public:
explicit CsvXXPort( QWidget *parent = 0 );
bool exportContacts( const KABC::Addressee::List &contacts ) const;
bool exportContacts( const KABC::Addressee::List &contacts, VCardExportSelectionWidget::ExportFields ) const;
KABC::Addressee::List importContacts() const;
private:
......
......@@ -341,7 +341,7 @@ KABC::Addressee::List GMXXXPort::importContacts() const
/* export */
bool GMXXXPort::exportContacts( const KABC::AddresseeList &list ) const
bool GMXXXPort::exportContacts( const KABC::AddresseeList &list, VCardExportSelectionWidget::ExportFields ) const
{
KUrl url = KFileDialog::getSaveUrl(
KUrl( QDir::homePath() + QLatin1String("/addressbook.gmx") ), GMX_FILESELECTION_STRING );
......
......@@ -35,7 +35,7 @@ class GMXXXPort : public XXPort
public:
explicit GMXXXPort( QWidget *parent = 0 );
bool exportContacts( const KABC::AddresseeList &list ) const;
bool exportContacts(const KABC::AddresseeList &list , VCardExportSelectionWidget::ExportFields) const;
KABC::Addressee::List importContacts() const;
private:
......
......@@ -49,7 +49,7 @@ KABC::Addressee::List LDAPXXPort::importContacts() const
return contacts;
}
bool LDAPXXPort::exportContacts( const KABC::Addressee::List & ) const
bool LDAPXXPort::exportContacts( const KABC::Addressee::List &, VCardExportSelectionWidget::ExportFields ) const
{
return false;
}
......@@ -33,7 +33,7 @@ class LDAPXXPort : public XXPort
public:
explicit LDAPXXPort( QWidget *parent = 0 );
KABC::Addressee::List importContacts() const;
bool exportContacts( const KABC::Addressee::List &contacts ) const;
bool exportContacts(const KABC::Addressee::List &contacts , VCardExportSelectionWidget::ExportFields) const;
};
#endif
......@@ -92,7 +92,7 @@ KABC::Addressee::List LDIFXXPort::importContacts() const
return contacts;
}
bool LDIFXXPort::exportContacts( const KABC::Addressee::List &list ) const
bool LDIFXXPort::exportContacts( const KABC::Addressee::List &list, VCardExportSelectionWidget::ExportFields ) const
{
const KUrl url =
KFileDialog::getSaveUrl( KUrl( QDir::homePath() + QLatin1String("/addressbook.ldif") ), QLatin1String("text/x-ldif") );
......
......@@ -32,7 +32,7 @@ class LDIFXXPort : public XXPort
public:
explicit LDIFXXPort( QWidget *parent = 0 );
bool exportContacts( const KABC::Addressee::List &contacts ) const;
bool exportContacts(const KABC::Addressee::List &contacts , VCardExportSelectionWidget::ExportFields) const;
KABC::Addressee::List importContacts() const;
};
......
......@@ -33,7 +33,7 @@ KABC::Addressee::List XXPort::importContacts() const
return KABC::Addressee::List();
}
bool XXPort::exportContacts( const KABC::Addressee::List & ) const
bool XXPort::exportContacts(const KABC::Addressee::List & , VCardExportSelectionWidget::ExportFields) const
{
return false;
}
......
......@@ -21,6 +21,7 @@
#define XXPORT_H
#include <KABC/Addressee>
#include "xxport/vcard/vcardexportselectionwidget.h"
#include <QtCore/QHash>
......@@ -53,7 +54,7 @@ public:
/**
* Exports the list of @p contacts.
*/
virtual bool exportContacts( const KABC::Addressee::List &contacts ) const = 0;
virtual bool exportContacts( const KABC::Addressee::List &contacts, VCardExportSelectionWidget::ExportFields ) const = 0;
/**
* Sets module specific options.
......
......@@ -20,7 +20,7 @@
#include "vcard_xxport.h"
#include "vcardviewerdialog.h"
#include "vcardexportselectiondialog.h"
#include "vcardexportselectionwidget.h"
#include "pimcommon/widgets/renamefiledialog.h"
......@@ -56,12 +56,12 @@ VCardXXPort::VCardXXPort( QWidget *parent )
{
}
bool VCardXXPort::exportContacts( const KABC::Addressee::List &contacts ) const
bool VCardXXPort::exportContacts( const KABC::Addressee::List &contacts, VCardExportSelectionWidget::ExportFields exportFields) const
{
KABC::VCardConverter converter;
KUrl url;
const KABC::Addressee::List list = filterContacts( contacts );
const KABC::Addressee::List list = filterContacts( contacts, exportFields );
if ( list.isEmpty() ) { // no contact selected
return true;
}
......@@ -268,7 +268,7 @@ bool VCardXXPort::doExport( const KUrl &url, const QByteArray &data ) const
return KIO::NetAccess::upload( tmpFile.fileName(), newUrl, parentWidget() );
}
KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &addrList ) const
KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &addrList, VCardExportSelectionWidget::ExportFields exportFieldType ) const
{
KABC::Addressee::List list;
......@@ -276,12 +276,6 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
return addrList;
}
QPointer<VCardExportSelectionDialog> dlg = new VCardExportSelectionDialog( parentWidget() );
if ( !dlg->exec() || !dlg ) {
delete dlg;
return list;
}
VCardExportSelectionDialog::ExportFields exportFieldType = dlg->exportType();
KABC::Addressee::List::ConstIterator it;
KABC::Addressee::List::ConstIterator end( addrList.end() );
for ( it = addrList.begin(); it != end; ++it ) {
......@@ -291,7 +285,7 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
addr.setFormattedName( (*it).formattedName() );
bool addrDone = false;
if ( exportFieldType & VCardExportSelectionDialog::DiplayName ) { // output display name as N field
if ( exportFieldType & VCardExportSelectionWidget::DiplayName ) { // output display name as N field
QString fmtName = (*it).formattedName();
QStringList splitNames = fmtName.split( QLatin1Char(' '), QString::SkipEmptyParts );
if ( splitNames.count() >= 2 ) {
......@@ -331,24 +325,24 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
addr.setMembers( (*it).members() );
addr.setRelationShips( (*it).relationShips() );
if ( exportFieldType & VCardExportSelectionDialog::Private ) {
if ( exportFieldType & VCardExportSelectionWidget::Private ) {
addr.setBirthday( (*it).birthday() );
addr.setNote( (*it).note() );
}
if ( exportFieldType & VCardExportSelectionDialog::Picture ) {
if ( exportFieldType & VCardExportSelectionDialog::Private ) {
if ( exportFieldType & VCardExportSelectionWidget::Picture ) {
if ( exportFieldType & VCardExportSelectionWidget::Private ) {
addr.setPhoto( (*it).photo() );
addr.setExtraPhotoList( (*it).extraPhotoList() );
}
if ( exportFieldType & VCardExportSelectionDialog::Business ) {
if ( exportFieldType & VCardExportSelectionWidget::Business ) {
addr.setLogo( (*it).logo() );
addr.setExtraLogoList( (*it).extraLogoList() );
}
}
if ( exportFieldType & VCardExportSelectionDialog::Business ) {
if ( exportFieldType & VCardExportSelectionWidget::Business ) {
addr.setTitle( (*it).title() );
addr.setRole( (*it).role() );
addr.setOrganization( (*it).organization() );
......@@ -372,11 +366,11 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
int phoneType = (*phoneIt).type();
if ( (phoneType & KABC::PhoneNumber::Home) && (exportFieldType & VCardExportSelectionDialog::Private) ) {
if ( (phoneType & KABC::PhoneNumber::Home) && (exportFieldType & VCardExportSelectionWidget::Private) ) {
addr.insertPhoneNumber( *phoneIt );
} else if ( (phoneType & KABC::PhoneNumber::Work) && (exportFieldType & VCardExportSelectionDialog::Business) ) {
} else if ( (phoneType & KABC::PhoneNumber::Work) && (exportFieldType & VCardExportSelectionWidget::Business) ) {
addr.insertPhoneNumber( *phoneIt );
} else if ( (exportFieldType & VCardExportSelectionDialog::Other) ) {
} else if ( (exportFieldType & VCardExportSelectionWidget::Other) ) {
addr.insertPhoneNumber( *phoneIt );
}
}
......@@ -386,20 +380,20 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
int addressType = (*addrIt).type();
if ( (addressType & KABC::Address::Home) && exportFieldType & VCardExportSelectionDialog::Private ) {
if ( (addressType & KABC::Address::Home) && exportFieldType & VCardExportSelectionWidget::Private ) {
addr.insertAddress( *addrIt );
} else if ( (addressType & KABC::Address::Work) && (exportFieldType & VCardExportSelectionDialog::Business) ) {
} else if ( (addressType & KABC::Address::Work) && (exportFieldType & VCardExportSelectionWidget::Business) ) {
addr.insertAddress( *addrIt );
} else if ( exportFieldType & VCardExportSelectionDialog::Other ) {
} else if ( exportFieldType & VCardExportSelectionWidget::Other ) {
addr.insertAddress( *addrIt );
}
}
if ( exportFieldType & VCardExportSelectionDialog::Other ) {
if ( exportFieldType & VCardExportSelectionWidget::Other ) {
addr.setCustoms( (*it).customs() );
}
if ( exportFieldType & VCardExportSelectionDialog::Encryption ) {
if ( exportFieldType & VCardExportSelectionWidget::Encryption ) {
addKey( addr, KABC::Key::PGP );
addKey( addr, KABC::Key::X509 );
}
......@@ -407,8 +401,6 @@ KABC::Addressee::List VCardXXPort::filterContacts( const KABC::Addressee::List &
list.append( addr );
}
delete dlg;
return list;
}
......
......@@ -27,7 +27,7 @@ class VCardXXPort : public XXPort
public:
explicit VCardXXPort( QWidget *parent = 0 );
bool exportContacts( const KABC::Addressee::List &contacts ) const;
bool exportContacts( const KABC::Addressee::List &contacts, VCardExportSelectionWidget::ExportFields exportFieldType ) const;
KABC::Addressee::List importContacts() const;
private:
......@@ -36,7 +36,7 @@ private:
void addKey( KABC::Addressee &addr, KABC::Key::Type type ) const;
KABC::Addressee::List filterContacts( const KABC::Addressee::List & ) const;
KABC::Addressee::List filterContacts(const KABC::Addressee::List & , VCardExportSelectionWidget::ExportFields exportFieldType) const;
};
#endif
......@@ -15,41 +15,27 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "vcardexportselectionwidget.h"
#include "vcardexportselectiondialog.h"
#include <QFrame>
#include <KLocalizedString>
#include <QGridLayout>
#include <QGroupBox>
#include <QCheckBox>
#include <kconfig.h>
#include <KConfigGroup>
#include <qcheckbox.h>
#include <qgridlayout.h>
#include <qgroupbox.h>
// ---------- VCardExportSelection Dialog ---------------- //
VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
: KDialog( parent )
VCardExportSelectionWidget::VCardExportSelectionWidget(QWidget *parent)
: QWidget(parent)
{
setCaption( i18nc( "@title:window", "Select vCard Fields" ) );
setButtons( Ok | Cancel );
setDefaultButton( Ok );
setModal( true );
showButtonSeparator( true );
QFrame *page = new QFrame( this );
setMainWidget( page );
QGridLayout *layout = new QGridLayout( page );
layout->setSpacing( spacingHint() );
layout->setMargin( marginHint() );
QGridLayout *layout = new QGridLayout( this );
QGroupBox *gbox = new QGroupBox(
i18nc( "@title:group", "Fields to be exported" ), page );
i18nc( "@title:group", "Fields to be exported" ), this );
gbox->setFlat( true );
layout->addWidget( gbox, 0, 0, 1, 2 );
mPrivateBox = new QCheckBox( i18nc( "@option:check", "Private fields" ), page );
mPrivateBox = new QCheckBox( i18nc( "@option:check", "Private fields" ), this );
mPrivateBox->setToolTip(
i18nc( "@info:tooltip", "Export private fields" ) );
mPrivateBox->setWhatsThis(
......@@ -58,7 +44,7 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
"private fields to the vCard output file." ) );
layout->addWidget( mPrivateBox, 1, 0 );
mBusinessBox = new QCheckBox( i18nc( "@option:check", "Business fields" ), page );
mBusinessBox = new QCheckBox( i18nc( "@option:check", "Business fields" ), this );
mBusinessBox->setToolTip(
i18nc( "@info:tooltip", "Export business fields" ) );
mBusinessBox->setWhatsThis(
......@@ -67,7 +53,7 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
"business fields to the vCard output file." ) );
layout->addWidget( mBusinessBox, 2, 0 );
mOtherBox = new QCheckBox( i18nc( "@option:check", "Other fields" ), page );
mOtherBox = new QCheckBox( i18nc( "@option:check", "Other fields" ), this );
mOtherBox->setToolTip(
i18nc( "@info:tooltip", "Export other fields" ) );
mOtherBox->setWhatsThis(
......@@ -76,7 +62,7 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
"other fields to the vCard output file." ) );
layout->addWidget( mOtherBox, 3, 0 );
mEncryptionKeys = new QCheckBox( i18nc( "@option:check", "Encryption keys" ), page );
mEncryptionKeys = new QCheckBox( i18nc( "@option:check", "Encryption keys" ), this );
mEncryptionKeys->setToolTip(
i18nc( "@info:tooltip", "Export encryption keys" ) );
mEncryptionKeys->setWhatsThis(
......@@ -85,7 +71,7 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
"encryption keys to the vCard output file." ) );
layout->addWidget( mEncryptionKeys, 1, 1 );
mPictureBox = new QCheckBox( i18nc( "@option:check", "Pictures" ), page );
mPictureBox = new QCheckBox( i18nc( "@option:check", "Pictures" ), this );
mPictureBox->setToolTip(
i18nc( "@info:tooltip", "Export pictures" ) );
mPictureBox->setWhatsThis(
......@@ -95,11 +81,11 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
layout->addWidget( mPictureBox, 2, 1 );
gbox = new QGroupBox(
i18nc( "@title:group", "Export options" ), page );
i18nc( "@title:group", "Export options" ), this );
gbox->setFlat( true );
layout->addWidget( gbox, 4, 0, 1, 2 );
mDisplayNameBox = new QCheckBox( i18nc( "@option:check", "Display name as full name" ), page );
mDisplayNameBox = new QCheckBox( i18nc( "@option:check", "Display name as full name" ), this );
mDisplayNameBox->setToolTip(
i18nc( "@info:tooltip", "Export display name as full name" ) );
mDisplayNameBox->setWhatsThis(
......@@ -118,9 +104,10 @@ VCardExportSelectionDialog::VCardExportSelectionDialog( QWidget *parent )
mEncryptionKeys->setChecked( group.readEntry( "ExportEncryptionKeys", true ) );
mPictureBox->setChecked( group.readEntry( "ExportPictureFields", true ) );
mDisplayNameBox->setChecked( group.readEntry( "ExportDisplayName", false ) );
}
VCardExportSelectionDialog::~VCardExportSelectionDialog()
VCardExportSelectionWidget::~VCardExportSelectionWidget()
{
KConfig config( QLatin1String("kaddressbookrc") );
KConfigGroup group( &config, "XXPortVCard" );
......@@ -133,9 +120,9 @@ VCardExportSelectionDialog::~VCardExportSelectionDialog()
group.writeEntry( "ExportDisplayName", mDisplayNameBox->isChecked() );
}
VCardExportSelectionDialog::ExportFields VCardExportSelectionDialog::exportType() const
VCardExportSelectionWidget::ExportFields VCardExportSelectionWidget::exportType() const
{
VCardExportSelectionDialog::ExportFields type = None;
ExportFields type = None;
if (mPrivateBox->isChecked()) {
type |= Private;
}
......@@ -156,4 +143,3 @@ VCardExportSelectionDialog::ExportFields VCardExportSelectionDialog::exportType(
}
return type;
}
......@@ -15,18 +15,18 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef VCARDEXPORTSELECTIONDIALOG_H
#define VCARDEXPORTSELECTIONDIALOG_H
#ifndef VCARDEXPORTSELECTIONWIDGET_H
#define VCARDEXPORTSELECTIONWIDGET_H
#include <KDialog>
class QCheckBox;
#include <QWidget>
class VCardExportSelectionDialog : public KDialog
class QCheckBox;
class VCardExportSelectionWidget : public QWidget
{
Q_OBJECT
public:
VCardExportSelectionDialog( QWidget *parent );
~VCardExportSelectionDialog();
explicit VCardExportSelectionWidget(QWidget *parent=0);
~VCardExportSelectionWidget();
enum ExportField {
None = 0,
Private = 1,
......@@ -40,7 +40,6 @@ public:
Q_DECLARE_FLAGS(ExportFields, ExportField)
ExportFields exportType() const;
private:
QCheckBox *mPrivateBox;
QCheckBox *mBusinessBox;
......@@ -50,4 +49,4 @@ private:
QCheckBox *mDisplayNameBox;
};
#endif // VCARDEXPORTSELECTIONDIALOG_H
#endif // VCARDEXPORTSELECTIONWIDGET_H
......@@ -181,8 +181,9 @@ void XXPortManager::slotExport( const QString &identifier )
return;
}
const bool selectExportType = (identifier == QLatin1String("vcard21") || identifier == QLatin1String("vcard30") || identifier == QLatin1String("vcard40"));
QPointer<ContactSelectionDialog> dlg =
new ContactSelectionDialog( mSelectionModel, mParentWidget );
new ContactSelectionDialog( mSelectionModel, selectExportType, mParentWidget );
dlg->setMessageText( i18n( "Which contact do you want to export?" ) );
dlg->setDefaultAddressBook( mDefaultAddressBook );
if ( !dlg->exec() || !dlg ) {
......@@ -191,6 +192,7 @@ void XXPortManager::slotExport( const QString &identifier )
}
const KABC::AddresseeList contacts = dlg->selectedContacts();
const VCardExportSelectionWidget::ExportFields exportFields = dlg->exportType();
delete dlg;
if ( contacts.isEmpty() ) {
......@@ -203,7 +205,7 @@ void XXPortManager::slotExport( const QString &identifier )
return;
}
xxport->exportContacts( contacts );
xxport->exportContacts( contacts, exportFields );
delete xxport;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment