Commit 82a9a1b0 authored by Tobias Koenig's avatar Tobias Koenig
Browse files

Set default address book of the selection dialog for

export and printing based on the current user selection.

svn path=/trunk/KDE/kdepim/kaddressbook/; revision=1022335
parent 0e14d3dc
......@@ -34,7 +34,6 @@ ContactSelectionDialog::ContactSelectionDialog( QAbstractItemModel *model, QItem
connect( mSelectionWidget, SIGNAL( selectedContacts( const KABC::Addressee::List& ) ),
this, SLOT( slotSelectedContacts( const KABC::Addressee::List& ) ) );
connect( this, SIGNAL( okClicked() ), this, SLOT( slotOkClicked() ) );
setInitialSize( QSize( 450, 220 ) );
}
......@@ -44,6 +43,11 @@ void ContactSelectionDialog::setMessageText( const QString &message )
mSelectionWidget->setMessageText( message );
}
void ContactSelectionDialog::setDefaultAddressBook( const Akonadi::Collection &addressBook )
{
mSelectionWidget->setDefaultAddressBook( addressBook );
}
KABC::Addressee::List ContactSelectionDialog::selectedContacts() const
{
return mContacts;
......
......@@ -28,6 +28,11 @@ class ContactSelectionWidget;
class QAbstractItemModel;
class QItemSelectionModel;
namespace Akonadi
{
class Collection;
}
/**
* @short A dialog to select a group of contacts.
*
......@@ -52,6 +57,11 @@ class ContactSelectionDialog : public KDialog
*/
void setMessageText( const QString &message );
/**
* Sets the default addressbook.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressBook );
/**
* Returns the list of selected contacts.
*/
......
......@@ -58,6 +58,11 @@ void ContactSelectionWidget::setMessageText( const QString &message )
mMessageLabel->setText( message );
}
void ContactSelectionWidget::setDefaultAddressBook( const Akonadi::Collection &addressBook )
{
mAddressBookSelection->setDefaultAddressBook( addressBook );
}
void ContactSelectionWidget::requestSelectedContacts()
{
if ( mAllContactsButton->isChecked() )
......
......@@ -34,6 +34,7 @@ class KJob;
namespace Akonadi
{
class AddressBookComboBox;
class Collection;
}
/**
......@@ -60,6 +61,11 @@ class ContactSelectionWidget : public QWidget
*/
void setMessageText( const QString &message );
/**
* Sets the default addressbook.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressBook );
/**
* Requests the list of selected contacts.
* The list is made available via the selectedContacts() signal.
......
......@@ -127,6 +127,9 @@ MainWidget::MainWidget( KXMLGUIClient *guiClient, QWidget *parent )
mCollectionView->header()->setDefaultAlignment( Qt::AlignCenter );
mCollectionView->header()->setSortIndicatorShown( false );
connect( mCollectionView, SIGNAL( currentChanged( const Akonadi::Collection& ) ),
mXXPortManager, SLOT( setDefaultAddressBook( const Akonadi::Collection& ) ) );
KSelectionProxyModel *selectionProxyModel = new KSelectionProxyModel( mCollectionView->selectionModel(),
this );
selectionProxyModel->setSourceModel( GlobalContactModel::instance()->model() );
......@@ -355,20 +358,15 @@ void MainWidget::print()
KABPrinting::PrintingWizard wizard( &printer, allContactsModel(),
mItemView->selectionModel(), this );
wizard.setDefaultAddressBook( currentAddressBook() );
wizard.exec();
}
void MainWidget::newContact()
{
Akonadi::ContactEditorDialog dlg( Akonadi::ContactEditorDialog::CreateMode, this );
if ( mCollectionView->selectionModel() && mCollectionView->selectionModel()->hasSelection() ) {
const QModelIndex index = mCollectionView->selectionModel()->selectedIndexes().first();
const Akonadi::Collection collection = index.data( Akonadi::EntityTreeModel::CollectionRole )
.value<Akonadi::Collection>();
dlg.setDefaultAddressBook( collection );
}
dlg.setDefaultAddressBook( currentAddressBook() );
dlg.exec();
}
......@@ -376,6 +374,8 @@ void MainWidget::newContact()
void MainWidget::newGroup()
{
Akonadi::ContactGroupEditorDialog dlg( Akonadi::ContactGroupEditorDialog::CreateMode, this );
dlg.setDefaultAddressBook( currentAddressBook() );
dlg.exec();
}
......@@ -458,6 +458,19 @@ void MainWidget::editGroup( const Akonadi::Item &group )
dlg.exec();
}
Akonadi::Collection MainWidget::currentAddressBook() const
{
if ( mCollectionView->selectionModel() && mCollectionView->selectionModel()->hasSelection() ) {
const QModelIndex index = mCollectionView->selectionModel()->selectedIndexes().first();
const Akonadi::Collection collection = index.data( Akonadi::EntityTreeModel::CollectionRole )
.value<Akonadi::Collection>();
return collection;
}
return Akonadi::Collection();
}
QAbstractItemModel* MainWidget::allContactsModel()
{
if ( !mAllContactsModel ) {
......
......@@ -79,6 +79,13 @@ class KADDRESSBOOK_EXPORT MainWidget : public QWidget
QAbstractItemModel* allContactsModel();
/**
* Returns the address book collection that is currently
* selected by the user or an invalid collection if no
* address book is selected.
*/
Akonadi::Collection currentAddressBook() const;
Akonadi::EntityFilterProxyModel *mCollectionTree;
Akonadi::EntityFilterProxyModel *mItemTree;
Akonadi::EntityFilterProxyModel *mAllContactsModel;
......
......@@ -74,6 +74,11 @@ PrintingWizard::~PrintingWizard()
{
}
void PrintingWizard::setDefaultAddressBook( const Akonadi::Collection &addressBook )
{
mSelectionPage->setDefaultAddressBook( addressBook );
}
void PrintingWizard::accept()
{
print();
......
......@@ -39,6 +39,11 @@ class QPrinter;
class ContactSelectionWidget;
class StylePage;
namespace Akonadi
{
class Collection;
}
namespace KABPrinting {
class PrintProgress;
......@@ -72,6 +77,11 @@ class PrintingWizard : public KAssistantDialog
*/
~PrintingWizard();
/**
* Sets the default addressbook of the contact selection.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressBook );
/**
* Registers all available printing styles.
*/
......
......@@ -74,6 +74,11 @@ void XXPortManager::setSelectionModel( QItemSelectionModel *selectionModel )
mSelectionModel = selectionModel;
}
void XXPortManager::setDefaultAddressBook( const Akonadi::Collection &addressBook )
{
mDefaultAddressBook = addressBook;
}
void XXPortManager::slotImport( const QString &identifier )
{
const XXPort* xxport = mFactory.createXXPort( identifier, mParentWidget );
......@@ -110,6 +115,7 @@ void XXPortManager::slotExport( const QString &identifier )
ContactSelectionDialog dlg( mItemModel, mSelectionModel, mParentWidget );
dlg.setMessageText( i18n( "Which contact do you want to export?" ) );
dlg.setDefaultAddressBook( mDefaultAddressBook );
if ( !dlg.exec() )
return;
......
......@@ -23,6 +23,8 @@
#include "xxport/xxportfactory.h"
#include <akonadi/collection.h>
#include <QtCore/QObject>
class QAbstractItemModel;
......@@ -30,19 +32,62 @@ class QAction;
class QItemSelectionModel;
class QSignalMapper;
/**
* @short The class that manages import and export of contacts.
*/
class XXPortManager : public QObject
{
Q_OBJECT
public:
/**
* Creates a new xxport manager.
*
* @param parent The widget that is used as parent for dialogs.
*/
XXPortManager( QWidget *parent = 0 );
/**
* Destroys the xxport manager.
*/
~XXPortManager();
/**
* Adds a new action to import contacts.
*
* @param action The action object.
* @param identifier The identifier that will be passed to the xxport module.
*/
void addImportAction( QAction *action, const QString &identifier );
/**
* Adds a new action to export contacts.
*
* @param action The action object.
* @param identifier The identifier that will be passed to the xxport module.
*/
void addExportAction( QAction *action, const QString &identifier );
void setItemModel( QAbstractItemModel *itemModel );
void setSelectionModel( QItemSelectionModel *selectionModel );
/**
* Sets the @p model that contains a list of all contacts.
*
* @note This model is used by the ContactSelectionDialog.
*/
void setItemModel( QAbstractItemModel *model );
/**
* Sets the @p model that contains the current selection.
*
* @note This model is used by the ContactSelectionDialog.
*/
void setSelectionModel( QItemSelectionModel *model );
public Q_SLOTS:
/**
* Sets the @p addressBook that shall be preselected in the
* ContactSelectionDialog.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressBook );
private Q_SLOTS:
void slotImport( const QString& );
......@@ -55,6 +100,7 @@ class XXPortManager : public QObject
XXPortFactory mFactory;
QSignalMapper *mImportMapper;
QSignalMapper *mExportMapper;
Akonadi::Collection mDefaultAddressBook;
};
#endif
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