Commit 13827680 authored by Laurent Montel's avatar Laurent Montel 😁

Astylekdelibs

parent 1801d658
......@@ -25,13 +25,13 @@
#include <KLocalizedString>
AboutData::AboutData()
: K4AboutData( "kaddressbook", 0, ki18n( "KAddressBook" ),
KDEPIM_VERSION, ki18n( "The KDE Address Book Application" ),
: K4AboutData("kaddressbook", 0, ki18n("KAddressBook"),
KDEPIM_VERSION, ki18n("The KDE Address Book Application"),
K4AboutData::License_GPL_V2,
ki18n( "Copyright © 2007–2014 KAddressBook authors" ) )
ki18n("Copyright © 2007–2014 KAddressBook authors"))
{
addAuthor( ki18n( "Laurent Montel" ), ki18n( "Current maintainer" ), "montel@kde.org" );
addAuthor( ki18n( "Tobias Koenig" ), ki18n( "Previous maintainer" ), "tokoe@kde.org" );
addAuthor(ki18n("Laurent Montel"), ki18n("Current maintainer"), "montel@kde.org");
addAuthor(ki18n("Tobias Koenig"), ki18n("Previous maintainer"), "tokoe@kde.org");
}
AboutData::~AboutData()
......
This diff is collapsed.
......@@ -32,7 +32,6 @@
using namespace Akonadi;
class CategoryFilterProxyModelPrivate : public QObject
{
Q_OBJECT
......@@ -48,7 +47,6 @@ private:
CategoryFilterProxyModel *q_ptr;
};
CategoryFilterProxyModelPrivate::CategoryFilterProxyModelPrivate(CategoryFilterProxyModel *parent)
: QObject(),
filterEnabled(false),
......@@ -56,7 +54,6 @@ CategoryFilterProxyModelPrivate::CategoryFilterProxyModelPrivate(CategoryFilterP
{
}
CategoryFilterProxyModel::CategoryFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent),
d_ptr(new CategoryFilterProxyModelPrivate(this))
......@@ -64,13 +61,11 @@ CategoryFilterProxyModel::CategoryFilterProxyModel(QObject *parent)
setDynamicSortFilter(true);
}
CategoryFilterProxyModel::~CategoryFilterProxyModel()
{
delete d_ptr;
}
bool CategoryFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{
Q_D(const CategoryFilterProxyModel);
......@@ -78,10 +73,16 @@ bool CategoryFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &pare
const QModelIndex index = sourceModel()->index(row, 0, parent);
const Akonadi::Item item = index.data(EntityTreeModel::ItemRole).value<Akonadi::Item>();
if (!d->filterEnabled) return true; // filter not enabled
if (d->filterIdList.isEmpty()) return false; // nothing accepted
// all accepted
if (d->filterIdList.first()==CategorySelectWidget::FilterAll) return true;
if (!d->filterEnabled) {
return true; // filter not enabled
}
if (d->filterIdList.isEmpty()) {
return false; // nothing accepted
}
// all accepted
if (d->filterIdList.first() == CategorySelectWidget::FilterAll) {
return true;
}
//qDebug() << "for row" << row << "item" << item.url() << "filter" << d->filterIdList;
if (item.hasPayload<KABC::Addressee>()) {
......@@ -92,59 +93,55 @@ bool CategoryFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &pare
int validCategories = 0;
int count = categories.count();
for (int i = 0; i<count; ++i) {
for (int i = 0; i < count; ++i) {
const QString cat = categories.at(i);
if (cat.startsWith(QLatin1String("akonadi:"))) {
const int idx = cat.indexOf(QLatin1String("?tag="));
if (idx>=0) {
if (idx >= 0) {
++validCategories;
Tag::Id id = cat.mid(idx+5).toInt();
Tag::Id id = cat.mid(idx + 5).toInt();
if (d->filterIdList.contains(id)) {
//qDebug() << "matches category" << cat;
return true; // a category matches filter
return true; // a category matches filter
}
}
}
}
if (validCategories>0) {
if (validCategories > 0) {
//qDebug() << "valid item but no match";
return false; // categorised but no match
return false; // categorised but no match
} else {
//qDebug() << "item with no categories";
return d->filterIdList.contains(CategorySelectWidget::FilterUntagged);
}
}
else if (item.hasPayload<KABC::ContactGroup>()) { // a contact group item
} else if (item.hasPayload<KABC::ContactGroup>()) { // a contact group item
return d->filterIdList.contains(CategorySelectWidget::FilterGroups);
}
return true; // not a recognised item
return true; // not a recognised item
}
void CategoryFilterProxyModel::setFilterCategories(const QList<Akonadi::Tag::Id> &idList)
{
Q_D(CategoryFilterProxyModel);
if (idList!=d->filterIdList) {
if (idList != d->filterIdList) {
//qDebug() << idList;
d->filterIdList = idList;
invalidateFilter();
}
}
void CategoryFilterProxyModel::setFilterEnabled(bool enable)
{
Q_D(CategoryFilterProxyModel);
if (enable!=d->filterEnabled) {
if (enable != d->filterEnabled) {
//qDebug() << enable;
d->filterEnabled = enable;
invalidateFilter();
}
}
#include "categoryfilterproxymodel.moc"
......@@ -26,7 +26,6 @@
class CategoryFilterProxyModelPrivate;
/**
* @short A proxy model to filter contacts by categories (tags).
*
......@@ -80,7 +79,7 @@ protected:
virtual bool filterAcceptsRow(int row, const QModelIndex &parent) const;
private:
CategoryFilterProxyModelPrivate * const d_ptr;
CategoryFilterProxyModelPrivate *const d_ptr;
};
#endif // CATEGORYFILTERPROXYMODEL_H
#endif // CATEGORYFILTERPROXYMODEL_H
......@@ -33,9 +33,7 @@
using namespace Akonadi;
static const int FILTER_ROLE = Qt::UserRole+1;
static const int FILTER_ROLE = Qt::UserRole + 1;
class CategorySelectWidgetPrivate : public QObject
{
......@@ -70,7 +68,6 @@ private:
CategorySelectWidget *q_ptr;
};
CategorySelectWidgetPrivate::CategorySelectWidgetPrivate(CategorySelectWidget *parent)
: QObject(),
tagModel(0),
......@@ -81,7 +78,6 @@ CategorySelectWidgetPrivate::CategorySelectWidgetPrivate(CategorySelectWidget *p
{
}
void CategorySelectWidgetPrivate::init()
{
Q_Q(CategorySelectWidget);
......@@ -141,26 +137,23 @@ void CategorySelectWidgetPrivate::init()
rowOffset = itemModel()->rowCount();
}
QStandardItemModel *CategorySelectWidgetPrivate::itemModel() const
{
QStandardItemModel *m = qobject_cast<QStandardItemModel *>(checkCombo->model());
Q_ASSERT(m!=NULL);
Q_ASSERT(m != NULL);
return m;
}
void CategorySelectWidgetPrivate::slotTagsRemoved(const QModelIndex &parent, int start, int end)
{
itemModel()->removeRows(start+rowOffset, end+rowOffset, parent);
itemModel()->removeRows(start + rowOffset, end + rowOffset, parent);
}
void CategorySelectWidgetPrivate::slotTagsChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
for (int row = topLeft.row(); row<=bottomRight.row(); ++row) {
QStandardItem *it = itemModel()->item(row+rowOffset);
Q_ASSERT(it!=NULL);
for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
QStandardItem *it = itemModel()->item(row + rowOffset);
Q_ASSERT(it != NULL);
QModelIndex idx = tagModel->index(row, 0);
it->setText(tagModel->data(idx, TagModel::NameRole).toString());
......@@ -169,16 +162,15 @@ void CategorySelectWidgetPrivate::slotTagsChanged(const QModelIndex &topLeft, co
}
}
void CategorySelectWidgetPrivate::slotTagsInserted(const QModelIndex &parent, int start, int end)
{
for (int row = start; row<=end; ++row) {
for (int row = start; row <= end; ++row) {
QModelIndex idx = tagModel->index(row, 0, parent);
#if 0
qDebug() << "idx" << idx << "=" << tagModel->data(idx, Qt::DisplayRole).toString()
<< "name" << tagModel->data(idx, TagModel::NameRole).toString()
<< "tag" << tagModel->data(idx, TagModel::TagRole)
<< "id" << tagModel->data(idx, TagModel::IdRole).toInt();
<< "name" << tagModel->data(idx, TagModel::NameRole).toString()
<< "tag" << tagModel->data(idx, TagModel::TagRole)
<< "id" << tagModel->data(idx, TagModel::IdRole).toInt();
#endif
QStandardItem *it = new QStandardItem(tagModel->data(idx, TagModel::NameRole).toString());
it->setIcon(tagModel->data(idx, Qt::DecorationRole).value<QIcon>());
......@@ -190,61 +182,56 @@ void CategorySelectWidgetPrivate::slotTagsInserted(const QModelIndex &parent, in
// tags, as is required in Akonadi::TagModel.
//
// FIXME: not tested (no way to create hierarchial tags at present)
if (parent!=QModelIndex()) {
if (parent != QModelIndex()) {
const Tag::Id parentId = tagModel->data(idx, TagModel::IdRole).value<Tag::Id>();
QModelIndexList matchList = itemModel()->match(itemModel()->index(0, 0), FILTER_ROLE,
parentId, 1,
Qt::MatchExactly|Qt::MatchRecursive);
if (matchList.count()==1) { // found the parent tag
parentId, 1,
Qt::MatchExactly | Qt::MatchRecursive);
if (matchList.count() == 1) { // found the parent tag
QModelIndex parentIndex = matchList.first();
itemModel()->itemFromIndex(parentIndex)->appendRow(it);
} else {
qWarning() << "Cannot find parent with ID" << parentId;
itemModel()->insertRow(row+rowOffset, it);
itemModel()->insertRow(row + rowOffset, it);
}
} else {
itemModel()->insertRow(row+rowOffset, it);
itemModel()->insertRow(row + rowOffset, it);
}
}
}
void CategorySelectWidgetPrivate::selectAll(Qt::CheckState state) const
{
for (int row = 0; row<itemModel()->rowCount(); ++row) {
for (int row = 0; row < itemModel()->rowCount(); ++row) {
QStandardItem *it = itemModel()->item(row);
it->setCheckState(state);
}
}
void CategorySelectWidgetPrivate::slotSelectAll()
{
selectAll(Qt::Checked);
}
void CategorySelectWidgetPrivate::slotSelectNone()
{
selectAll(Qt::Unchecked);
}
void CategorySelectWidgetPrivate::slotCheckedItemsChanged()
{
updateTimer->start();
}
void CategorySelectWidgetPrivate::slotCheckedItemsTimer()
{
Q_Q(CategorySelectWidget);
bool allOn = true;
for (int row = 0; row<itemModel()->rowCount(); ++row) {
for (int row = 0; row < itemModel()->rowCount(); ++row) {
const QStandardItem *it = itemModel()->item(row);
Qt::CheckState rowState = static_cast<Qt::CheckState>(it->data(Qt::CheckStateRole).toInt());
if (rowState!=Qt::Checked) {
if (rowState != Qt::Checked) {
allOn = false;
break;
}
......@@ -268,17 +255,18 @@ void CategorySelectWidgetPrivate::slotCheckedItemsTimer()
emit q->filterChanged(filterTags());
}
QList<Akonadi::Tag::Id> CategorySelectWidgetPrivate::filterTags() const
{
QList<Tag::Id> filter;
bool allOn = true;
for (int row = 0; row<itemModel()->rowCount(); ++row) {
for (int row = 0; row < itemModel()->rowCount(); ++row) {
const QStandardItem *it = itemModel()->item(row);
Q_ASSERT(it!=NULL);
if (it->checkState()==Qt::Checked) {
Q_ASSERT(it != NULL);
if (it->checkState() == Qt::Checked) {
Tag::Id id = it->data(FILTER_ROLE).toInt();
if (id!=0) filter.append(id);
if (id != 0) {
filter.append(id);
}
} else {
allOn = false;
}
......@@ -293,7 +281,6 @@ QList<Akonadi::Tag::Id> CategorySelectWidgetPrivate::filterTags() const
return filter;
}
CategorySelectWidget::CategorySelectWidget(QWidget *parent)
: QWidget(parent),
d_ptr(new CategorySelectWidgetPrivate(this))
......@@ -302,18 +289,15 @@ CategorySelectWidget::CategorySelectWidget(QWidget *parent)
d->init();
}
CategorySelectWidget::~CategorySelectWidget()
{
delete d_ptr;
}
QList<Akonadi::Tag::Id> CategorySelectWidget::filterTags() const
{
Q_D(const CategorySelectWidget);
return d->filterTags();
}
#include "categoryselectwidget.moc"
......@@ -53,11 +53,10 @@ public:
/**
* Special @c Akonadi::Tag::Id values for filtering.
**/
enum FilterTag
{
FilterAll = -2, /**< All items */
FilterUntagged = -3, /**< Untagged items */
FilterGroups = -4 /**< Contact groups */
enum FilterTag {
FilterAll = -2, /**< All items */
FilterUntagged = -3, /**< Untagged items */
FilterGroups = -4 /**< Contact groups */
};
/**
......@@ -81,7 +80,7 @@ signals:
void filterChanged(const QList<Akonadi::Tag::Id> &idList);
private:
CategorySelectWidgetPrivate * const d_ptr;
CategorySelectWidgetPrivate *const d_ptr;
};
#endif // CATEGORYSELECTWIDGET_H
#endif // CATEGORYSELECTWIDGET_H
This diff is collapsed.
......@@ -97,7 +97,7 @@ public:
/**
* Returns the i18n label for the @p field.
*/
static QString label( Field field );
static QString label(Field field);
/**
* Returns a list of all available fields.
......@@ -107,12 +107,12 @@ public:
/**
* Sets the @p value of the @p field for the @p contact.
*/
static void setValue( Field field, const QString &value, KABC::Addressee &contact );
static void setValue(Field field, const QString &value, KABC::Addressee &contact);
/**
* Returns the value for the @p field of the @p contact.
*/
static QString value( Field field, const KABC::Addressee &contact );
static QString value(Field field, const KABC::Addressee &contact);
};
#endif
......@@ -25,13 +25,13 @@
#include <QPushButton>
#include <QVBoxLayout>
ContactSelectionDialog::ContactSelectionDialog( QItemSelectionModel *selectionModel,
QWidget *parent )
: QDialog( parent )
ContactSelectionDialog::ContactSelectionDialog(QItemSelectionModel *selectionModel,
QWidget *parent)
: QDialog(parent)
{
setWindowTitle( i18n( "Select Contacts" ) );
setWindowTitle(i18n("Select Contacts"));
//PORTING SCRIPT: Move QDialogButtonBox at the end of init of widget to add it in layout.
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
......@@ -42,22 +42,21 @@ ContactSelectionDialog::ContactSelectionDialog( QItemSelectionModel *selectionMo
connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactSelectionDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactSelectionDialog::reject);
mSelectionWidget = new ContactSelectionWidget( selectionModel, this );
mSelectionWidget = new ContactSelectionWidget(selectionModel, this);
mainLayout->addWidget(mSelectionWidget);
mainLayout->addWidget(buttonBox);
resize( QSize( 450, 220 ) );
resize(QSize(450, 220));
}
void ContactSelectionDialog::setMessageText( const QString &message )
void ContactSelectionDialog::setMessageText(const QString &message)
{
mSelectionWidget->setMessageText( message );
mSelectionWidget->setMessageText(message);
}
void ContactSelectionDialog::setDefaultAddressBook( const Akonadi::Collection &addressBook )
void ContactSelectionDialog::setDefaultAddressBook(const Akonadi::Collection &addressBook)
{
mSelectionWidget->setDefaultAddressBook( addressBook );
mSelectionWidget->setDefaultAddressBook(addressBook);
}
KABC::Addressee::List ContactSelectionDialog::selectedContacts() const
......
......@@ -48,17 +48,17 @@ 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, QWidget *parent = 0);
/**
* Sets the @p message text.
*/
void setMessageText( const QString &message );
void setMessageText(const QString &message);
/**
* Sets the default addressbook.
*/
void setDefaultAddressBook( const Akonadi::Collection &addressBook );
void setDefaultAddressBook(const Akonadi::Collection &addressBook);
/**
* Returns the list of selected contacts.
......
......@@ -37,44 +37,44 @@
#include <QRadioButton>
#include <QVBoxLayout>
ContactSelectionWidget::ContactSelectionWidget( QItemSelectionModel *selectionModel,
QWidget *parent )
: QWidget( parent ), mSelectionModel( selectionModel )
ContactSelectionWidget::ContactSelectionWidget(QItemSelectionModel *selectionModel,
QWidget *parent)
: QWidget(parent), mSelectionModel(selectionModel)
{
initGui();
mSelectedContactsButton->setEnabled( mSelectionModel->hasSelection() );
mAddressBookSelection->setEnabled( false );
mAddressBookSelectionRecursive->setEnabled( false );
mSelectedContactsButton->setEnabled(mSelectionModel->hasSelection());
mAddressBookSelection->setEnabled(false);
mAddressBookSelectionRecursive->setEnabled(false);
connect(mAddressBookContactsButton, &QRadioButton::toggled, mAddressBookSelection, &Akonadi::CollectionComboBox::setEnabled);
connect(mAddressBookContactsButton, &QRadioButton::toggled, mAddressBookSelectionRecursive, &QCheckBox::setEnabled);
// apply default configuration
if ( mSelectionModel->hasSelection() ) {
mSelectedContactsButton->setChecked( true );
if (mSelectionModel->hasSelection()) {
mSelectedContactsButton->setChecked(true);
} else {
mAllContactsButton->setChecked( true );
mAllContactsButton->setChecked(true);
}
}
void ContactSelectionWidget::setMessageText( const QString &message )
void ContactSelectionWidget::setMessageText(const QString &message)
{
mMessageLabel->setText( message );
mMessageLabel->setText(message);
}
void ContactSelectionWidget::setDefaultAddressBook( const Akonadi::Collection &addressBook )
void ContactSelectionWidget::setDefaultAddressBook(const Akonadi::Collection &addressBook)
{
mAddressBookSelection->setDefaultCollection( addressBook );
mAddressBookSelection->setDefaultCollection(addressBook);
}
KABC::Addressee::List ContactSelectionWidget::selectedContacts() const
{
if ( mAllContactsButton->isChecked() ) {
if (mAllContactsButton->isChecked()) {
return collectAllContacts();
} else if ( mSelectedContactsButton->isChecked() ) {
} else if (mSelectedContactsButton->isChecked()) {
return collectSelectedContacts();
} else if ( mAddressBookContactsButton->isChecked() ) {
} else if (mAddressBookContactsButton->isChecked()) {
return collectAddressBookContacts();
}
......@@ -83,105 +83,104 @@ KABC::Addressee::List ContactSelectionWidget::selectedContacts() const
Akonadi::Item::List ContactSelectionWidget::selectedContactsItem() const
{
if ( mAllContactsButton->isChecked() ) {
if (mAllContactsButton->isChecked()) {
return collectAllContactsItem();
} else if ( mSelectedContactsButton->isChecked() ) {
} else if (mSelectedContactsButton->isChecked()) {
return collectSelectedContactsItem();
} else if ( mAddressBookContactsButton->isChecked() ) {
} else if (mAddressBookContactsButton->isChecked()) {
return collectAddressBookContactsItem();
}
return Akonadi::Item::List();
}
void ContactSelectionWidget::initGui()
{