Commit a0c55fa6 authored by Guy Maurel's avatar Guy Maurel

Coding Style

REVIEWS: 121242 121243 121246
parent 82dc4f1d
......@@ -29,75 +29,75 @@ using namespace Akonadi;
class ContactGroupSearchJob::Private
{
public:
public:
int mLimit;
};
ContactGroupSearchJob::ContactGroupSearchJob( QObject * parent )
: ItemSearchJob( QString(), parent ), d( new Private )
ContactGroupSearchJob::ContactGroupSearchJob(QObject *parent)
: ItemSearchJob(QString(), parent)
, d(new Private)
{
fetchScope().fetchFullPayload();
d->mLimit = -1;
fetchScope().fetchFullPayload();
d->mLimit = -1;
setMimeTypes( QStringList() << KContacts::ContactGroup::mimeType() );
setMimeTypes(QStringList() << KContacts::ContactGroup::mimeType());
// by default search for all contact groups
Akonadi::SearchQuery query;
query.addTerm( ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual) );
ItemSearchJob::setQuery( query );
// by default search for all contact groups
Akonadi::SearchQuery query;
query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual));
ItemSearchJob::setQuery(query);
}
ContactGroupSearchJob::~ContactGroupSearchJob()
{
delete d;
delete d;
}
void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value )
void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value)
{
// Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
// else as default
setQuery( criterion, value, ExactMatch );
// Exact match was the default in 4.4, so we have to keep it and ContactSearchJob has something
// else as default
setQuery(criterion, value, ExactMatch);
}
static Akonadi::SearchTerm::Condition matchType( ContactGroupSearchJob::Match match )
static Akonadi::SearchTerm::Condition matchType(ContactGroupSearchJob::Match match)
{
switch( match ) {
switch (match) {
case ContactGroupSearchJob::ExactMatch:
return Akonadi::SearchTerm::CondEqual;
return Akonadi::SearchTerm::CondEqual;
case ContactGroupSearchJob::StartsWithMatch:
case ContactGroupSearchJob::ContainsMatch:
return Akonadi::SearchTerm::CondContains;
}
return Akonadi::SearchTerm::CondEqual;
return Akonadi::SearchTerm::CondContains;
}
return Akonadi::SearchTerm::CondEqual;
}
void ContactGroupSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
void ContactGroupSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
{
Akonadi::SearchQuery query;
if ( criterion == Name ) {
query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
}
Akonadi::SearchQuery query;
if (criterion == Name) {
query.addTerm(ContactSearchTerm(ContactSearchTerm::Name, value, matchType(match)));
}
query.setLimit( d->mLimit );
query.setLimit(d->mLimit);
ItemSearchJob::setQuery( query );
ItemSearchJob::setQuery(query);
}
void ContactGroupSearchJob::setLimit( int limit )
void ContactGroupSearchJob::setLimit(int limit)
{
d->mLimit = limit;
d->mLimit = limit;
}
KContacts::ContactGroup::List ContactGroupSearchJob::contactGroups() const
{
KContacts::ContactGroup::List contactGroups;
KContacts::ContactGroup::List contactGroups;
foreach ( const Item &item, items() ) {
if ( item.hasPayload<KContacts::ContactGroup>() ) {
contactGroups.append( item.payload<KContacts::ContactGroup>() );
foreach (const Item &item, items()) {
if (item.hasPayload<KContacts::ContactGroup>()) {
contactGroups.append(item.payload<KContacts::ContactGroup>());
}
}
}
return contactGroups;
return contactGroups;
}
......@@ -44,97 +44,99 @@ using namespace Akonadi;
class ContactGroupViewer::Private
{
public:
Private( ContactGroupViewer *parent )
: mParent( parent ), mExpandJob( 0 ), mParentCollectionFetchJob( 0 )
public:
Private(ContactGroupViewer *parent)
: mParent(parent)
, mExpandJob(0)
, mParentCollectionFetchJob(0)
{
mBrowser = new TextBrowser;
mBrowser = new TextBrowser;
static QPixmap groupPixmap = QIcon::fromTheme( QLatin1String( "x-mail-distribution-list" ) ).pixmap( QSize( 100, 100 ) );
mBrowser->document()->addResource( QTextDocument::ImageResource,
QUrl( QLatin1String( "group_photo" ) ),
groupPixmap );
static QPixmap groupPixmap = QIcon::fromTheme(QLatin1String("x-mail-distribution-list")).pixmap(QSize(100, 100));
mBrowser->document()->addResource(QTextDocument::ImageResource,
QUrl(QLatin1String("group_photo")),
groupPixmap);
mStandardContactGroupFormatter = new StandardContactGroupFormatter;
mContactGroupFormatter = mStandardContactGroupFormatter;
mStandardContactGroupFormatter = new StandardContactGroupFormatter;
mContactGroupFormatter = mStandardContactGroupFormatter;
}
~Private()
{
delete mStandardContactGroupFormatter;
delete mStandardContactGroupFormatter;
}
void updateView()
{
mParent->setWindowTitle( i18n( "Contact Group %1", mCurrentGroupName ) );
mParent->setWindowTitle(i18n("Contact Group %1", mCurrentGroupName));
KContacts::ContactGroup group;
group.setName( mCurrentGroupName );
foreach ( const KContacts::Addressee &contact, mCurrentContacts ) {
group.append( KContacts::ContactGroup::Data( contact.realName(), contact.preferredEmail() ) );
}
KContacts::ContactGroup group;
group.setName(mCurrentGroupName);
foreach (const KContacts::Addressee &contact, mCurrentContacts) {
group.append(KContacts::ContactGroup::Data(contact.realName(), contact.preferredEmail()));
}
mContactGroupFormatter->setContactGroup( group );
mContactGroupFormatter->setContactGroup(group);
QList<QVariantMap> additionalFields;
QList<QVariantMap> additionalFields;
if ( !mCurrentAddressBookName.isEmpty() ) {
QVariantMap addressBookName;
addressBookName.insert( QLatin1String( "title" ), i18n( "Address Book" ) );
addressBookName.insert( QLatin1String( "value" ), mCurrentAddressBookName );
if (!mCurrentAddressBookName.isEmpty()) {
QVariantMap addressBookName;
addressBookName.insert(QLatin1String("title"), i18n("Address Book"));
addressBookName.insert(QLatin1String("value"), mCurrentAddressBookName);
additionalFields << addressBookName;
}
additionalFields << addressBookName;
}
mContactGroupFormatter->setAdditionalFields( additionalFields );
mContactGroupFormatter->setAdditionalFields(additionalFields);
mBrowser->setHtml( mContactGroupFormatter->toHtml() );
mBrowser->setHtml(mContactGroupFormatter->toHtml());
}
void slotMailClicked( const QUrl&email )
void slotMailClicked(const QUrl &email)
{
QString name, address;
QString name, address;
// remove the 'mailto:' and split into name and email address
KContacts::Addressee::parseEmailAddress( email.path(), name, address );
// remove the 'mailto:' and split into name and email address
KContacts::Addressee::parseEmailAddress(email.path(), name, address);
emit mParent->emailClicked( name, address );
emit mParent->emailClicked(name, address);
}
void _k_expandResult( KJob *job )
void _k_expandResult(KJob *job)
{
mExpandJob = 0;
mExpandJob = 0;
if ( !job->error() ) {
ContactGroupExpandJob *expandJob = qobject_cast<ContactGroupExpandJob*>( job );
mCurrentContacts = expandJob->contacts();
}
if (!job->error()) {
ContactGroupExpandJob *expandJob = qobject_cast<ContactGroupExpandJob *>(job);
mCurrentContacts = expandJob->contacts();
}
// stop any running fetch job
if ( mParentCollectionFetchJob ) {
mParent->disconnect( mParentCollectionFetchJob, SIGNAL(result(KJob*)), mParent, SLOT(slotParentCollectionFetched(KJob*)) );
delete mParentCollectionFetchJob;
mParentCollectionFetchJob = 0;
}
// stop any running fetch job
if (mParentCollectionFetchJob) {
mParent->disconnect(mParentCollectionFetchJob, SIGNAL(result(KJob*)), mParent, SLOT(slotParentCollectionFetched(KJob*)));
delete mParentCollectionFetchJob;
mParentCollectionFetchJob = 0;
}
mParentCollectionFetchJob = new CollectionFetchJob( mCurrentItem.parentCollection(), CollectionFetchJob::Base, mParent );
mParent->connect( mParentCollectionFetchJob, SIGNAL(result(KJob*)), SLOT(slotParentCollectionFetched(KJob*)) );
mParentCollectionFetchJob = new CollectionFetchJob(mCurrentItem.parentCollection(), CollectionFetchJob::Base, mParent);
mParent->connect(mParentCollectionFetchJob, SIGNAL(result(KJob*)), SLOT(slotParentCollectionFetched(KJob*)));
}
void slotParentCollectionFetched( KJob *job )
void slotParentCollectionFetched(KJob *job)
{
mParentCollectionFetchJob = 0;
mCurrentAddressBookName.clear();
if ( !job->error() ) {
CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
if ( !fetchJob->collections().isEmpty() ) {
const Collection collection = fetchJob->collections().first();
mCurrentAddressBookName = collection.displayName();
mParentCollectionFetchJob = 0;
mCurrentAddressBookName.clear();
if (!job->error()) {
CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob *>(job);
if (!fetchJob->collections().isEmpty()) {
const Collection collection = fetchJob->collections().first();
mCurrentAddressBookName = collection.displayName();
}
}
}
updateView();
updateView();
}
ContactGroupViewer *mParent;
......@@ -149,69 +151,70 @@ class ContactGroupViewer::Private
AbstractContactGroupFormatter *mContactGroupFormatter;
};
ContactGroupViewer::ContactGroupViewer( QWidget *parent )
: QWidget( parent ), d( new Private( this ) )
ContactGroupViewer::ContactGroupViewer(QWidget *parent)
: QWidget(parent)
, d(new Private(this))
{
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 0 );
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
connect( d->mBrowser, SIGNAL(anchorClicked(QUrl)),
this, SLOT(slotMailClicked(QUrl)) );
connect(d->mBrowser, SIGNAL(anchorClicked(QUrl)),
this, SLOT(slotMailClicked(QUrl)));
layout->addWidget( d->mBrowser );
layout->addWidget(d->mBrowser);
// always fetch full payload for contact groups
fetchScope().fetchFullPayload();
fetchScope().setAncestorRetrieval( ItemFetchScope::Parent );
// always fetch full payload for contact groups
fetchScope().fetchFullPayload();
fetchScope().setAncestorRetrieval(ItemFetchScope::Parent);
}
ContactGroupViewer::~ContactGroupViewer()
{
delete d;
delete d;
}
Akonadi::Item ContactGroupViewer::contactGroup() const
{
return ItemMonitor::item();
return ItemMonitor::item();
}
void ContactGroupViewer::setContactGroup( const Akonadi::Item &group )
void ContactGroupViewer::setContactGroup(const Akonadi::Item &group)
{
ItemMonitor::setItem( group );
ItemMonitor::setItem(group);
}
void ContactGroupViewer::setContactGroupFormatter( AbstractContactGroupFormatter *formatter )
void ContactGroupViewer::setContactGroupFormatter(AbstractContactGroupFormatter *formatter)
{
if ( formatter == 0 ) {
d->mContactGroupFormatter = d->mStandardContactGroupFormatter;
} else {
d->mContactGroupFormatter = formatter;
}
if (formatter == 0) {
d->mContactGroupFormatter = d->mStandardContactGroupFormatter;
} else {
d->mContactGroupFormatter = formatter;
}
}
void ContactGroupViewer::itemChanged( const Item &item )
void ContactGroupViewer::itemChanged(const Item &item)
{
if ( !item.hasPayload<KContacts::ContactGroup>() ) {
return;
}
const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>();
d->mCurrentGroupName = group.name();
d->mCurrentItem = item;
if ( d->mExpandJob ) {
disconnect( d->mExpandJob, SIGNAL(result(KJob*)), this, SLOT(_k_expandResult(KJob*)) );
d->mExpandJob->kill();
}
d->mExpandJob = new ContactGroupExpandJob( group );
connect( d->mExpandJob, SIGNAL(result(KJob*)), SLOT(_k_expandResult(KJob*)) );
d->mExpandJob->start();
if (!item.hasPayload<KContacts::ContactGroup>()) {
return;
}
const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>();
d->mCurrentGroupName = group.name();
d->mCurrentItem = item;
if (d->mExpandJob) {
disconnect(d->mExpandJob, SIGNAL(result(KJob*)), this, SLOT(_k_expandResult(KJob*)));
d->mExpandJob->kill();
}
d->mExpandJob = new ContactGroupExpandJob(group);
connect(d->mExpandJob, SIGNAL(result(KJob*)), SLOT(_k_expandResult(KJob*)));
d->mExpandJob->start();
}
void ContactGroupViewer::itemRemoved()
{
d->mBrowser->clear();
d->mBrowser->clear();
}
#include "moc_contactgroupviewer.cpp"
......@@ -34,46 +34,46 @@ using namespace Akonadi;
class ContactGroupViewerDialog::Private
{
public:
public:
ContactGroupViewer *mViewer;
};
ContactGroupViewerDialog::ContactGroupViewerDialog( QWidget *parent )
: QDialog( parent ), d( new Private )
ContactGroupViewerDialog::ContactGroupViewerDialog(QWidget *parent)
: QDialog(parent)
, d(new Private)
{
setWindowTitle( i18n( "Show Contact Group" ) );
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactGroupViewerDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactGroupViewerDialog::reject);
mainLayout->addWidget(d->mViewer);
mainLayout->addWidget(buttonBox);
resize( QSize( 500, 600 ) );
setWindowTitle(i18n("Show Contact Group"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactGroupViewerDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactGroupViewerDialog::reject);
mainLayout->addWidget(d->mViewer);
mainLayout->addWidget(buttonBox);
resize(QSize(500, 600));
}
ContactGroupViewerDialog::~ContactGroupViewerDialog()
{
delete d;
delete d;
}
Akonadi::Item ContactGroupViewerDialog::contactGroup() const
{
return d->mViewer->contactGroup();
return d->mViewer->contactGroup();
}
ContactGroupViewer* ContactGroupViewerDialog::viewer() const
ContactGroupViewer *ContactGroupViewerDialog::viewer() const
{
return d->mViewer;
return d->mViewer;
}
void ContactGroupViewerDialog::setContactGroup( const Akonadi::Item &group )
void ContactGroupViewerDialog::setContactGroup(const Akonadi::Item &group)
{
d->mViewer->setContactGroup( group );
d->mViewer->setContactGroup(group);
}
......@@ -27,56 +27,56 @@ using namespace Akonadi;
class ContactMetaDataAttribute::Private
{
public:
public:
QVariantMap mData;
};
ContactMetaDataAttribute::ContactMetaDataAttribute()
: d( new Private )
: d(new Private)
{
}
ContactMetaDataAttribute::~ContactMetaDataAttribute()
{
delete d;
delete d;
}
void ContactMetaDataAttribute::setMetaData( const QVariantMap &data )
void ContactMetaDataAttribute::setMetaData(const QVariantMap &data)
{
d->mData = data;
d->mData = data;
}
QVariantMap ContactMetaDataAttribute::metaData() const
{
return d->mData;
return d->mData;
}
QByteArray ContactMetaDataAttribute::type() const
{
return "contactmetadata";
return "contactmetadata";
}
Attribute* ContactMetaDataAttribute::clone() const
Attribute *ContactMetaDataAttribute::clone() const
{
ContactMetaDataAttribute *copy = new ContactMetaDataAttribute;
copy->setMetaData( d->mData );
ContactMetaDataAttribute *copy = new ContactMetaDataAttribute;
copy->setMetaData(d->mData);
return copy;
return copy;
}
QByteArray ContactMetaDataAttribute::serialized() const
{
QByteArray data;
QDataStream s( &data, QIODevice::WriteOnly );
s.setVersion( QDataStream::Qt_4_5 );
s << d->mData;
QByteArray data;
QDataStream s(&data, QIODevice::WriteOnly);
s.setVersion(QDataStream::Qt_4_5);
s << d->mData;
return data;
return data;
}
void ContactMetaDataAttribute::deserialize( const QByteArray &data )
void ContactMetaDataAttribute::deserialize(const QByteArray &data)
{
QDataStream s( data );
s.setVersion( QDataStream::Qt_4_5 );
s >> d->mData;
QDataStream s(data);
s.setVersion(QDataStream::Qt_4_5);
s >> d->mData;
}
......@@ -28,79 +28,79 @@ using namespace Akonadi;
class ContactSearchJob::Private
{
public:
public:
int mLimit;
};
ContactSearchJob::ContactSearchJob( QObject * parent )
: ItemSearchJob( QString(), parent ), d( new Private() )
ContactSearchJob::ContactSearchJob(QObject *parent)
: ItemSearchJob(QString(), parent)
, d(new Private())
{
fetchScope().fetchFullPayload();
d->mLimit = -1;
fetchScope().fetchFullPayload();
d->mLimit = -1;
setMimeTypes( QStringList() << KContacts::Addressee::mimeType() );
setMimeTypes(QStringList() << KContacts::Addressee::mimeType());
// by default search for all contacts
Akonadi::SearchQuery query;
query.addTerm( ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual) );
ItemSearchJob::setQuery( query );
// by default search for all contacts
Akonadi::SearchQuery query;
query.addTerm(ContactSearchTerm(ContactSearchTerm::All, QVariant(), SearchTerm::CondEqual));
ItemSearchJob::setQuery(query);
}
ContactSearchJob::~ContactSearchJob()
{
delete d;
delete d;
}
static Akonadi::SearchTerm::Condition matchType( ContactSearchJob::Match match )
static Akonadi::SearchTerm::Condition matchType(ContactSearchJob::Match match)
{
switch ( match ) {
switch (match) {
case ContactSearchJob::ExactMatch:
return Akonadi::SearchTerm::CondEqual;
return Akonadi::SearchTerm::CondEqual;
case ContactSearchJob::StartsWithMatch:
case ContactSearchJob::ContainsWordBoundaryMatch:
case ContactSearchJob::ContainsMatch:
return Akonadi::SearchTerm::CondContains;
}
return Akonadi::SearchTerm::CondEqual;
return Akonadi::SearchTerm::CondContains;
}
return Akonadi::SearchTerm::CondEqual;
}
void ContactSearchJob::setQuery( Criterion criterion, const QString &value, Match match )
void ContactSearchJob::setQuery(Criterion criterion, const QString &value, Match match)
{
Akonadi::SearchQuery query( SearchTerm::RelOr) ;