diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -5,6 +5,7 @@ allcontactsmonitor.cpp defaultcontactmonitor.cpp abstractpersonaction.cpp + abstracteditablecontact.cpp ) add_library (KF5::PeopleBackend ALIAS KF5PeopleBackend) @@ -26,6 +27,7 @@ ecm_generate_headers(KPeopleBackend_CamelCase_HEADERS HEADER_NAMES AbstractContact + AbstractEditableContact AbstractPersonAction AllContactsMonitor BasePersonsDataSource diff --git a/src/backends/abstractcontact.h b/src/backends/abstractcontact.h --- a/src/backends/abstractcontact.h +++ b/src/backends/abstractcontact.h @@ -74,6 +74,9 @@ /** QVariantList property that lists the emails the contact has */ static const QString AllEmailsProperty; + /** QByteArray with the raw vcard information */ + static const QString VCardProperty; + /** * Generic method to access a random contact property * diff --git a/src/backends/abstractcontact.cpp b/src/backends/abstractcontact.cpp --- a/src/backends/abstractcontact.cpp +++ b/src/backends/abstractcontact.cpp @@ -27,6 +27,7 @@ const QString AbstractContact::PresenceProperty = QStringLiteral("presence"); const QString AbstractContact::AllEmailsProperty = QStringLiteral("all-email"); const QString AbstractContact::PictureProperty = QStringLiteral("picture"); +const QString AbstractContact::VCardProperty = QStringLiteral("vcard"); const QString AbstractContact::GroupsProperty = QStringLiteral("all-groups"); AbstractContact::AbstractContact() diff --git a/src/backends/abstracteditablecontact.h b/src/backends/abstracteditablecontact.h new file mode 100644 --- /dev/null +++ b/src/backends/abstracteditablecontact.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2019 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_ABSTRACT_EDITABLE_CONTACT_H +#define KPEOPLE_ABSTRACT_EDITABLE_CONTACT_H + +#include "abstractcontact.h" +#include + +namespace KPeople +{ +/** + * @brief Additionally to @class AbstractContact features, it will allow us + * to suggest the backend property values for a said key. + * + * @since 5.60 + * @internal + */ + +class KPEOPLEBACKEND_EXPORT AbstractEditableContact : public AbstractContact +{ +public: + typedef QExplicitlySharedDataPointer Ptr; + typedef QList List; + AbstractEditableContact(); + virtual ~AbstractEditableContact(); + + /** + * @p key @see AbstractContact for key identifiers + * @p value suggested value + * + * @returns whether the change was successful + */ + virtual bool setCustomProperty(const QString &key, const QVariant &value) = 0; + +private: + Q_DISABLE_COPY(AbstractEditableContact) +}; + +} + +Q_DECLARE_METATYPE(KPeople::AbstractEditableContact::List) +Q_DECLARE_METATYPE(KPeople::AbstractEditableContact::Ptr) + +#endif diff --git a/src/backends/abstracteditablecontact.cpp b/src/backends/abstracteditablecontact.cpp new file mode 100644 --- /dev/null +++ b/src/backends/abstracteditablecontact.cpp @@ -0,0 +1,26 @@ +/* + Copyright (C) 2019 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 +*/ + +#include "abstracteditablecontact.h" + +using namespace KPeople; + +AbstractEditableContact::AbstractEditableContact() +{} + +AbstractEditableContact::~AbstractEditableContact() = default; diff --git a/src/persondata.h b/src/persondata.h --- a/src/persondata.h +++ b/src/persondata.h @@ -93,6 +93,8 @@ */ Q_SCRIPTABLE QVariant contactCustomProperty(const QString &key) const; + Q_SCRIPTABLE bool setContactCustomProperty(const QString &key, const QVariant &value); + /** * Returns the contact's online presence. */ diff --git a/src/persondata.cpp b/src/persondata.cpp --- a/src/persondata.cpp +++ b/src/persondata.cpp @@ -24,6 +24,7 @@ #include "backends/basepersonsdatasource.h" #include "backends/contactmonitor.h" #include "backends/abstractcontact.h" +#include "backends/abstracteditablecontact.h" #include #include "kpeople_debug.h" @@ -155,6 +156,14 @@ return d->metaContact.personAddressee()->customProperty(key); } +bool KPeople::PersonData::setContactCustomProperty(const QString& key, const QVariant& value) +{ + Q_D(PersonData); + auto contact = dynamic_cast(d->metaContact.personAddressee().data()); + + return contact && contact->setCustomProperty(key, value); +} + QString PersonData::presenceIconName() const { QString contactPresence = contactCustomProperty(QStringLiteral("telepathy-presence")).toString();