diff --git a/autotests/personsmodeltest.cpp b/autotests/personsmodeltest.cpp index 3e5b9a5..2432bc4 100644 --- a/autotests/personsmodeltest.cpp +++ b/autotests/personsmodeltest.cpp @@ -1,188 +1,188 @@ /* * Copyright (C) 2013 David Edmundson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "personsmodeltest.h" #include #include #include #include //private includes #include "personmanager_p.h" #include "personpluginmanager_p.h" //public kpeople includes #include #include "fakecontactsource.h" QTEST_GUILESS_MAIN(PersonsModelTest) using namespace KPeople; void PersonsModelTest::initTestCase() { QVERIFY(m_database.open()); // Called before the first testfunction is executed PersonManager::instance(m_database.fileName()); m_source = new FakeContactSource(nullptr); //don't own. PersonPluginManager removes it on destruction QHash sources; sources[QStringLiteral("fakesource")] = m_source; PersonPluginManager::setDataSourcePlugins(sources); m_model = new KPeople::PersonsModel(this); QSignalSpy modelInit(m_model, SIGNAL(modelInitialized(bool))); QTRY_COMPARE(modelInit.count(), 1); QCOMPARE(modelInit.first().at(0).toBool(), true); } void PersonsModelTest::cleanupTestCase() { // Called after the last testfunction was executed m_database.close(); } void PersonsModelTest::loadModel() { QCOMPARE(m_model->rowCount(), 4); QCOMPARE(m_model->data(m_model->index(0)).toString(), QStringLiteral("Contact 1")); QCOMPARE(m_model->data(m_model->index(1)).toString(), QStringLiteral("Contact 2")); QCOMPARE(m_model->data(m_model->index(2)).toString(), QStringLiteral("Contact 3")); QCOMPARE(m_model->data(m_model->index(3)).toString(), QStringLiteral("Contact 4")); m_source->changeProperty(AbstractContact::NameProperty, QStringLiteral("Contact A")); QCOMPARE(m_model->rowCount(), 4); QCOMPARE(m_model->data(m_model->index(0)).toString(), QStringLiteral("Contact A")); QCOMPARE(m_model->data(m_model->index(1)).toString(), QStringLiteral("Contact 2")); QCOMPARE(m_model->data(m_model->index(2)).toString(), QStringLiteral("Contact 3")); QCOMPARE(m_model->data(m_model->index(3)).toString(), QStringLiteral("Contact 4")); } void PersonsModelTest::mergeContacts() { QStringList uris{QStringLiteral("fakesource://contact1"), QStringLiteral("fakesource://contact2")}; QSignalSpy modelRowsInsert(m_model, SIGNAL(rowsInserted(QModelIndex,int,int))); QCOMPARE(m_model->rowCount(), 4); QString newUri = KPeople::mergeContacts(uris); QCOMPARE(newUri, QStringLiteral("kpeople://1")); // TODO: replace with actual model signals spying QTRY_COMPARE(m_model->rowCount(), 3); QCOMPARE(m_model->rowCount(m_model->indexForPersonUri(newUri)), 2); // There needs to be 2 rows inserted - one for the new Person // and one for the new contact added to it (the other contact // is already a child of the person; merging just takes all // contacts from one person and adds them to the other) QCOMPARE(modelRowsInsert.count(), 2); // The first inserted Person must have invalid parent index QCOMPARE(modelRowsInsert.first().at(0).toModelIndex(), QModelIndex()); // Second inserted row, the Contact, must have the Person index as parent QCOMPARE(modelRowsInsert.at(1).at(0).toModelIndex(), m_model->indexForPersonUri(newUri)); modelRowsInsert.clear(); QStringList uris2{QStringLiteral("fakesource://contact3"), newUri}; QString newUri2 = KPeople::mergeContacts(uris2); QCOMPARE(newUri2, QStringLiteral("kpeople://1")); QTest::qWait(2000); QCOMPARE(m_model->rowCount(), 2); QCOMPARE(m_model->rowCount(m_model->indexForPersonUri(newUri2)), 3); QCOMPARE(modelRowsInsert.count(), 1); QCOMPARE(modelRowsInsert.first().at(0).toModelIndex(), m_model->indexForPersonUri(newUri)); } void PersonsModelTest::gettersTests() { // Find the index for "kpeople://1" using the QAIModel method QModelIndexList indexList = m_model->match(m_model->index(0,0,QModelIndex()), KPeople::PersonsModel::PersonUriRole, QVariant(QStringLiteral("kpeople://1")), 1); QModelIndex personIndex = indexList.first(); // Now get the index using our method QModelIndex indexForPerson = m_model->indexForPersonUri(QStringLiteral("kpeople://1")); // Now compare QCOMPARE(personIndex, indexForPerson); // TODO: also test the get() method? } void PersonsModelTest::unmergeContacts() { QModelIndex personIndex = m_model->indexForPersonUri(QStringLiteral("kpeople://1")); QSignalSpy modelRowsInsert(m_model, SIGNAL(rowsInserted(QModelIndex,int,int))); QSignalSpy modelRowsRemove(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QCOMPARE(m_model->rowCount(), 2); QCOMPARE(m_model->rowCount(personIndex), 3); KPeople::unmergeContact(QStringLiteral("fakesource://contact3")); QTest::qWait(2000); QCOMPARE(m_model->rowCount(), 3); QCOMPARE(m_model->rowCount(personIndex), 2); // The unmerged Contact is turned into new Person (the fake Person where Person == Contact) // There must be 1 insertion and the parent must be invalid index QCOMPARE(modelRowsInsert.count(), 1); QCOMPARE(modelRowsInsert.first().at(0).toModelIndex(), QModelIndex()); - // Similarily, there must be one row removed and the parent must be + // Similarly, there must be one row removed and the parent must be // the old Person index QCOMPARE(modelRowsRemove.count(), 1); QCOMPARE(modelRowsRemove.first().at(0).toModelIndex(), personIndex); modelRowsInsert.clear(); modelRowsRemove.clear(); KPeople::unmergeContact(QStringLiteral("kpeople://1")); QTest::qWait(2000); QCOMPARE(m_model->rowCount(), 4); // Check that the person is gone from the model QCOMPARE(m_model->indexForPersonUri(QStringLiteral("kpeople://1")), QModelIndex()); QCOMPARE(modelRowsInsert.count(), 2); QCOMPARE(modelRowsInsert.first().at(0).toModelIndex(), QModelIndex()); QCOMPARE(modelRowsInsert.at(1).at(0).toModelIndex(), QModelIndex()); // There must be exactly 3 rows removed when unmerging a Person // with 2 contacts - first the subcontacts are removed and then // the parent Person itself QCOMPARE(modelRowsRemove.count(), 3); // The first two Contacts must have parent the Person index // and both should have 0 0 as the "first last" args of removeRows QCOMPARE(modelRowsRemove.first().at(0).toModelIndex(), personIndex); QCOMPARE(modelRowsRemove.first().at(1).toInt(), 0); QCOMPARE(modelRowsRemove.first().at(2).toInt(), 0); QCOMPARE(modelRowsRemove.at(1).at(0).toModelIndex(), personIndex); QCOMPARE(modelRowsRemove.at(1).at(1).toInt(), 0); QCOMPARE(modelRowsRemove.at(1).at(2).toInt(), 0); // The parent Person should have just invalid index as parent // (and we don't care about the position) QCOMPARE(modelRowsRemove.at(2).at(0).toModelIndex(), QModelIndex()); } diff --git a/src/backends/abstractcontact.h b/src/backends/abstractcontact.h index 933ff09..787eda7 100644 --- a/src/backends/abstractcontact.h +++ b/src/backends/abstractcontact.h @@ -1,93 +1,93 @@ /* Copyright (C) 2014 Aleix Pol i Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef KPEOPLE_CONTACT -#define KPEOPLE_CONTACT +#ifndef KPEOPLE_ABSTRACT_CONTACT_H +#define KPEOPLE_ABSTRACT_CONTACT_H #include #include #include namespace KPeople { /** * @brief KPeople::AbstractContact is the class to provide the data from a given * contact by the backends. * * To obtain it from a front-end application PersonData and PersonsModel * should be used. * * @since 5.8 * @internal */ class KPEOPLEBACKEND_EXPORT AbstractContact : public QSharedData { public: typedef QExplicitlySharedDataPointer Ptr; typedef QList List; AbstractContact(); virtual ~AbstractContact(); // well-known properties /** String property representing the display name of the contact */ static const QString NameProperty; /** String property representing the preferred name of the contact */ static const QString EmailProperty; /** String property representing the preferred phone number of the contact */ static const QString PhoneNumberProperty; /** QVariantList property that lists all phone numbers the contact has */ static const QString AllPhoneNumbersProperty; /** * String property representing the IM presence of the contact. * @sa KPeople::iconNameForPresenceString() */ static const QString PresenceProperty; /** * QUrl or QPixmap property representing the contacts' avatar */ static const QString PictureProperty; /** QVariantList property that lists the groups the contacts belongs to */ static const QString GroupsProperty; /** QVariantList property that lists the emails the contact has */ static const QString AllEmailsProperty; /** * Generic method to access a random contact property * * @returns the value for the @p key property. */ virtual QVariant customProperty(const QString &key) const = 0; private: Q_DISABLE_COPY(AbstractContact) }; } Q_DECLARE_METATYPE(KPeople::AbstractContact::List) Q_DECLARE_METATYPE(KPeople::AbstractContact::Ptr) #endif diff --git a/src/personssortfilterproxymodel.h b/src/personssortfilterproxymodel.h index c411f48..3be1028 100644 --- a/src/personssortfilterproxymodel.h +++ b/src/personssortfilterproxymodel.h @@ -1,63 +1,63 @@ /* Copyright (C) 2015 Aleix Pol i Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PERSONSSORTFILTERMODEL_H -#define PERSONSSORTFILTERMODEL_H +#ifndef PERSONSSORTFILTERPROXYMODEL_H +#define PERSONSSORTFILTERPROXYMODEL_H #include #include #include namespace KPeople { class PersonsSortFilterProxyModelPrivate; /** * Helps filtering and sorting PresonsModel * * Especially useful for creating interfaces around specific properties rather * than the complete set as a whole. * * @sa PersonsModel * @since 5.12 */ class KPEOPLE_EXPORT PersonsSortFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT /** Specifies the properties that should be provided by the contact for the contact to be shown. */ Q_PROPERTY(QStringList requiredProperties READ requiredProperties WRITE setRequiredProperties) public: explicit PersonsSortFilterProxyModel(QObject *parent = nullptr); ~PersonsSortFilterProxyModel() override; QStringList requiredProperties() const; void setRequiredProperties(const QStringList &props); bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; private: Q_DISABLE_COPY(PersonsSortFilterProxyModel) QScopedPointer const d_ptr; Q_DECLARE_PRIVATE(PersonsSortFilterProxyModel) }; } -#endif // PERSONSSORTFILTERMODEL_H +#endif // PERSONSSORTFILTERPROXYMODEL_H diff --git a/src/widgets/actions.h b/src/widgets/actions.h index cbac2d5..870a157 100644 --- a/src/widgets/actions.h +++ b/src/widgets/actions.h @@ -1,54 +1,54 @@ /* Copyright (C) 2013 David Edmundson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef KPEOPLEWIDGETS_GLOBAL_H -#define KPEOPLEWIDGETS_GLOBAL_H +#ifndef KPEOPLEWIDGETS_ACTIONS_H +#define KPEOPLEWIDGETS_ACTIONS_H #include #include class QString; class QObject; class QAction; namespace KPeople { class PersonData; /** * Each action returned in the list can be one of these * types, however the Type is not mandatory with the action * * The type should be set as QObject property "actionType" */ enum ActionType { TextChatAction, AudioCallAction, VideoCallAction, SendEmailAction, SendFileAction, OtherAction = 100 }; /** * Returns a list of actions relevant to the specified @p contactUri where * each QAction will have @p parent passed as its parent QObject */ KPEOPLEWIDGETS_EXPORT QList actionsForPerson(const QString &contactUri, QObject *parent); } -#endif // KPEOPLEWIDGETS_GLOBAL_H +#endif // KPEOPLEWIDGETS_ACTIONS_H diff --git a/src/widgets/plugins/mergecontactswidget.h b/src/widgets/plugins/mergecontactswidget.h index be02753..1941dba 100644 --- a/src/widgets/plugins/mergecontactswidget.h +++ b/src/widgets/plugins/mergecontactswidget.h @@ -1,62 +1,62 @@ /* Copyright (C) 2013 Franck Arrecot This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MERGE_CONTACT_WIDGET_H -#define MERGE_CONTACT_WIDGET_H +#ifndef MERGE_CONTACTS_WIDGET_H +#define MERGE_CONTACTS_WIDGET_H #include "abstractpersondetailswidget.h" #include "QPersistentModelIndex" class QPushButton; class PersonPresentationWidget; namespace KPeople { class DuplicatesFinder; } class MergeContactsWidget : public KPeople::AbstractPersonDetailsWidget { Q_OBJECT public: explicit MergeContactsWidget(QWidget *parent, const QVariantList &args); void setPerson(KPeople::PersonData *person); void setPersonsModel(KPeople::PersonsModel *model); void searchForDuplicates(); void fillDuplicatesWidget(const QList &duplicates); QList duplicateBusterFromPerson(const QUrl &uri) const; QList getContactsCheckedToMerge() const; private Q_SLOTS: void onMergeButtonPressed(); void onMergePossibilitiesButtonPressed(); void searchForDuplicatesFinished(); private: KPeople::PersonData *m_person; KPeople::PersonsModel *m_model; QPushButton *m_mergeButton; QWidget *m_containerListDetails; KPeople::DuplicatesFinder *m_duplicatesBuster; QList< QPair > m_listMergeContacts; }; -#endif // MERGE_CONTACT_WIDGET_H +#endif // MERGE_CONTACTS_WIDGET_H