Skip to content
Snippets Groups Projects
Commit 8bc888e4 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

collection: Partially implement the new collection extension system

This commit allow to create, register and manage extensions

The API may change

Refs #70825
parent b0356a5f
No related branches found
No related tags found
No related merge requests found
Showing
with 476 additions and 69 deletions
...@@ -212,6 +212,7 @@ SET( libringclient_LIB_SRCS ...@@ -212,6 +212,7 @@ SET( libringclient_LIB_SRCS
src/securityevaluationmodel.cpp src/securityevaluationmodel.cpp
src/personmodel.cpp src/personmodel.cpp
src/collectionmodel.cpp src/collectionmodel.cpp
src/collectionextensionmodel.cpp
src/collectionmanagerinterface.cpp src/collectionmanagerinterface.cpp
src/networkinterfacemodel.cpp src/networkinterfacemodel.cpp
src/certificatemodel.cpp src/certificatemodel.cpp
...@@ -263,6 +264,7 @@ SET( libringclient_LIB_SRCS ...@@ -263,6 +264,7 @@ SET( libringclient_LIB_SRCS
#Extension #Extension
src/extensions/presencecollectionextension.cpp src/extensions/presencecollectionextension.cpp
src/extensions/securityevaluationextension.cpp
) )
IF(${ENABLE_LIBWRAP} MATCHES true) IF(${ENABLE_LIBWRAP} MATCHES true)
...@@ -311,6 +313,8 @@ SET( libringclient_LIB_HDRS ...@@ -311,6 +313,8 @@ SET( libringclient_LIB_HDRS
src/personmodel.h src/personmodel.h
src/transitionalpersonbackend.h src/transitionalpersonbackend.h
src/collectionmodel.h src/collectionmodel.h
src/collectionextensionmodel.h
src/collectionextensionmodel.hpp
src/hookmanager.h src/hookmanager.h
src/uri.h src/uri.h
src/itembase.h src/itembase.h
...@@ -361,6 +365,7 @@ SET(libringclient_audio_LIB_HDRS ...@@ -361,6 +365,7 @@ SET(libringclient_audio_LIB_HDRS
SET(libringclient_extensions_LIB_HDRS SET(libringclient_extensions_LIB_HDRS
src/extensions/presencecollectionextension.h src/extensions/presencecollectionextension.h
src/extensions/securityevaluationextension.h
) )
SET(libringclient_delegates_LIB_HDRS SET(libringclient_delegates_LIB_HDRS
......
...@@ -25,20 +25,38 @@ ...@@ -25,20 +25,38 @@
class CollectionInterface; class CollectionInterface;
/**
* This interface can be used to extend the collection system.
*
* It is a business logic container. The interface will eventually be extended
* to allow various callbacks at key ItemBase lifecycle moment.
*
* Subclasses need to call DECLARE_COLLECTION_EXTENSION in the .cpp and
* include collectionextensionmodel.h
*/
class LIB_EXPORT CollectionExtensionInterface : public QObject class LIB_EXPORT CollectionExtensionInterface : public QObject
{ {
Q_OBJECT Q_OBJECT
friend class CollectionExtensionModel;
public: public:
explicit CollectionExtensionInterface(QObject* parent); explicit CollectionExtensionInterface(QObject* parent);
virtual QVariant data (CollectionInterface* backend, const QModelIndex& index, int role = Qt::DisplayRole ) const = 0; virtual QVariant data(int role) const = 0;
virtual Qt::ItemFlags flags (CollectionInterface* backend, const QModelIndex& index ) const = 0;
virtual bool setData (CollectionInterface* backend, const QModelIndex& index, const QVariant &value, int role ) = 0;
virtual QString headerName() const = 0;
Q_SIGNALS: Q_SIGNALS:
void dataChanged(const QModelIndex& idx); void dataChanged(const QModelIndex& idx);
}; };
#define DECLARE_COLLECTION_EXTENSION_M1(x, y) x ## y
#define DECLARE_COLLECTION_EXTENSION_M2(x, y) DECLARE_COLLECTION_EXTENSION_M1(x, y)
#define DECLARE_COLLECTION_EXTENSION(T) \
static auto DECLARE_COLLECTION_EXTENSION_M2(val,__COUNTER__) = []{\
CollectionExtensionModel::registerExtension<T>();\
return 0;\
}();
#endif #endif
/****************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "collectionextensionmodel.h"
#include "collectionextensioninterface.h"
QList<CollectionExtensionInterface*> CollectionExtensionModelSpecific::m_slEntries;
class CollectionExtensionModelPrivate
{
public:
static CollectionExtensionModel* m_spInstance;
};
CollectionExtensionModel* CollectionExtensionModelPrivate::m_spInstance = nullptr;
CollectionExtensionModel* CollectionExtensionModel::instance()
{
if (!CollectionExtensionModelPrivate::m_spInstance)
CollectionExtensionModelPrivate::m_spInstance = new CollectionExtensionModel();
return CollectionExtensionModelPrivate::m_spInstance;
}
QVariant CollectionExtensionModel::data( const QModelIndex& index, int role ) const
{
if (!index.isValid())
return QVariant();
return CollectionExtensionModelSpecific::m_slEntries[index.row()]->data(role);
}
int CollectionExtensionModel::rowCount( const QModelIndex& parent) const
{
return parent.isValid() ? 0 : CollectionExtensionModelSpecific::m_slEntries.size();
}
Qt::ItemFlags CollectionExtensionModel::flags( const QModelIndex& index) const
{
return index.isValid() ? Qt::ItemIsEnabled : Qt::NoItemFlags;
}
bool CollectionExtensionModel::setData( const QModelIndex& index, const QVariant &value, int role)
{
Q_UNUSED(index)
Q_UNUSED(value)
Q_UNUSED(role)
return false;
}
QHash<int,QByteArray> CollectionExtensionModel::roleNames() const
{
return {};
}
/****************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef COLLECTIONEXTENSIONMODEL_H
#define COLLECTIONEXTENSIONMODEL_H
#include <QtCore/QAbstractListModel>
#include <typedefs.h>
class CollectionExtensionInterface;
class CollectionExtensionModelPrivate;
/**
* This model expose the collections available to the managers
*/
class LIB_EXPORT CollectionExtensionModel : public QAbstractListModel
{
Q_OBJECT
public:
//Model functions
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override;
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override;
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override;
virtual QHash<int,QByteArray> roleNames() const override;
/**
* Register an extension available to all type of collections
*
* This does **NOT** activate the extension
*/
template<class T>
static int registerExtension();
/**
* Return an unique identifier for that extension type
*/
template<class T>
static int getExtensionId();
/**
* Get the instance of a particular extension
*
* This function will register the type if it isn't already registered
*/
template<class T>
static T* getExtension();
//Singleton
static CollectionExtensionModel* instance();
private:
CollectionExtensionModelPrivate* d_ptr;
Q_DECLARE_PRIVATE(CollectionExtensionModel)
};
#include <collectionextensionmodel.hpp>
#endif
\ No newline at end of file
/****************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
class CollectionExtensionModelSpecific
{
public:
static QList<CollectionExtensionInterface*> m_slEntries;
};
template<class T>
int CollectionExtensionModel::registerExtension()
{
static bool typeInit = false;
static int typeId = CollectionExtensionModelSpecific::m_slEntries.size();
if (!typeInit) {
CollectionExtensionModelSpecific::m_slEntries << new T(CollectionExtensionModel::instance());
}
return typeId;
}
template<class T>
int CollectionExtensionModel::getExtensionId()
{
return registerExtension<T>();
}
template<class T>
T* CollectionExtensionModel::getExtension()
{
return CollectionExtensionModelSpecific::m_slEntries[registerExtension<T>()];
}
\ No newline at end of file
/************************************************************************************ /************************************************************************************
* Copyright (C) 2014-2015 by Savoir-Faire Linux * * Copyright (C) 2014-2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* * * *
* This library is free software; you can redistribute it and/or * * This library is free software; you can redistribute it and/or *
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "call.h" #include "call.h"
#include "contactmethod.h" #include "contactmethod.h"
#include "collectioneditor.h" #include "collectioneditor.h"
#include "collectionextensionmodel.h"
#include "itembase.h" #include "itembase.h"
#include "delegates/pixmapmanipulationdelegate.h" #include "delegates/pixmapmanipulationdelegate.h"
...@@ -34,14 +35,84 @@ ...@@ -34,14 +35,84 @@
//Qt //Qt
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QIdentityProxyModel>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
class EnabledExtensionsProxy : public QIdentityProxyModel
{
Q_OBJECT
public:
EnabledExtensionsProxy(QAbstractItemModel* parent);
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
virtual bool setData ( const QModelIndex& index, const QVariant& value,int role ) override;
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override;
private:
QHash<int,bool> m_Disabled;
};
class CollectionInterfacePrivate
{
public:
explicit CollectionInterfacePrivate();
//Attributes
EnabledExtensionsProxy* m_pEnabledExtensions;
};
EnabledExtensionsProxy::EnabledExtensionsProxy(QAbstractItemModel* parent) : QIdentityProxyModel(parent)
{
setSourceModel(parent);
}
CollectionInterfacePrivate::CollectionInterfacePrivate(): m_pEnabledExtensions(nullptr)
{
}
void CollectionInterface::init()
{
d_ptr2 = new CollectionInterfacePrivate();
}
///Destructor ///Destructor
CollectionInterface::~CollectionInterface() CollectionInterface::~CollectionInterface()
{ {
delete d_ptr; delete d_ptr;
} }
QVariant EnabledExtensionsProxy::data( const QModelIndex& index, int role) const
{
if (index.isValid() && role == Qt::CheckStateRole)
return m_Disabled[index.row()] ? Qt::Unchecked : Qt::Checked;
return QIdentityProxyModel::data(index,role);
}
bool EnabledExtensionsProxy::setData( const QModelIndex& index, const QVariant& value,int role )
{
if (index.isValid() && role == Qt::CheckStateRole) {
m_Disabled[index.row()] = value == Qt::Unchecked;
return true;
}
return false;
}
Qt::ItemFlags EnabledExtensionsProxy::flags( const QModelIndex& index) const
{
return QIdentityProxyModel::flags(index) | Qt::ItemIsUserCheckable;
}
QAbstractItemModel* CollectionInterface::extensionsModel() const
{
if (!d_ptr2->m_pEnabledExtensions)
d_ptr2->m_pEnabledExtensions = new EnabledExtensionsProxy(CollectionExtensionModel::instance());
return d_ptr2->m_pEnabledExtensions;
}
CollectionInterface* CollectionInterface::parent () const CollectionInterface* CollectionInterface::parent () const
{ {
return d_ptr->m_pParent; return d_ptr->m_pParent;
...@@ -164,3 +235,5 @@ void CollectionInterface::setConfigurator(std::function<CollectionConfigurationI ...@@ -164,3 +235,5 @@ void CollectionInterface::setConfigurator(std::function<CollectionConfigurationI
{ {
d_ptr->m_fConfigurator = getter; d_ptr->m_fConfigurator = getter;
} }
#include <collectioninterface.moc>
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
#include <functional> #include <functional>
//Ring //Ring
class CollectionInterfacePrivateT;
class CollectionInterfacePrivate; class CollectionInterfacePrivate;
class CollectionExtensionInterface;
class CollectionEditorBase; class CollectionEditorBase;
class CollectionConfigurationInterface; class CollectionConfigurationInterface;
template<typename T> class CollectionEditor; template<typename T> class CollectionEditor;
...@@ -248,12 +250,44 @@ public: ...@@ -248,12 +250,44 @@ public:
/** /**
* Return an object that has been associated with this collection type * Return an object that has been associated with this collection type
* *
* It can be set using registerConfigarator() available in every collection * It can be set using registerConfigarator() available in every collection
* manager objects such as PersonModel, CategorizedHistoryModel and others. * manager objects such as PersonModel, CategorizedHistoryModel and others.
*/ */
CollectionConfigurationInterface* configurator() const; CollectionConfigurationInterface* configurator() const;
/**
* Attach or detach an extension to this collection
*/
template<class T>
bool attachExtension(bool enable);
/**
* Get a model with all available extensions with possibility to activate
* or deactivate them.
*/
QAbstractItemModel* extensionsModel() const;
/**
* Register extensions only to a subset of all collections
*
* @see template<class T> static bool registerExtension();
*/
// template<class T, typename Ts...>
// static bool registerExtension();
/**
* Check if an extension type is active
*/
template<class T>
bool isExtensionActive() const;
/**
* Get extension "T"
*/
template<class T>
CollectionExtensionInterface* extension() const;
protected: protected:
//Constructor //Constructor
...@@ -273,7 +307,9 @@ protected: ...@@ -273,7 +307,9 @@ protected:
QMetaObject metaObject(); QMetaObject metaObject();
private: private:
CollectionInterfacePrivate* d_ptr; CollectionInterfacePrivateT* d_ptr ;
CollectionInterfacePrivate * d_ptr2;
void init();
}; };
DECLARE_ENUM_FLAGS(CollectionInterface::SupportedFeatures) DECLARE_ENUM_FLAGS(CollectionInterface::SupportedFeatures)
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
//TODO don't do this //TODO don't do this
template<typename T> class ItemBase; template<typename T> class ItemBase;
class CollectionInterfacePrivate { class CollectionInterfacePrivateT {
public: public:
CollectionInterfacePrivate() : m_pParent(nullptr){} CollectionInterfacePrivateT() : m_pParent(nullptr){}
///The backend parent of nullptr ///The backend parent of nullptr
CollectionInterface* m_pParent ; CollectionInterface* m_pParent ;
...@@ -47,8 +47,9 @@ public: ...@@ -47,8 +47,9 @@ public:
template<typename T> template<typename T>
CollectionInterface::CollectionInterface(CollectionEditor<T>* editor, CollectionInterface* parent) : CollectionInterface::CollectionInterface(CollectionEditor<T>* editor, CollectionInterface* parent) :
d_ptr(new CollectionInterfacePrivate()) d_ptr(new CollectionInterfacePrivateT())
{ {
init();
//Ensure the type is based on QObject (required) //Ensure the type is based on QObject (required)
d_ptr->m_pParent = parent; d_ptr->m_pParent = parent;
// d_ptr->m_pEditorType = T::staticMetaObject(); // d_ptr->m_pEditorType = T::staticMetaObject();
......
...@@ -103,8 +103,8 @@ QVariant CollectionModel::data (const QModelIndex& idx, int role) const ...@@ -103,8 +103,8 @@ QVariant CollectionModel::data (const QModelIndex& idx, int role) const
if (idx.isValid()) { if (idx.isValid()) {
CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer()); CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer());
if (idx.column() > 0 && item->collection) /*if (idx.column() > 0 && item->collection)
return d_ptr->m_lExtensions[idx.column()-1]->data(item->collection,idx,role); return d_ptr->m_lExtensions[idx.column()-1]->data(item->collection,idx,role);*/
if (item->collection) { if (item->collection) {
switch(role) { switch(role) {
...@@ -172,11 +172,11 @@ Qt::ItemFlags CollectionModel::flags(const QModelIndex& idx) const ...@@ -172,11 +172,11 @@ Qt::ItemFlags CollectionModel::flags(const QModelIndex& idx) const
if (!item->collection) if (!item->collection)
return Qt::ItemIsEnabled; return Qt::ItemIsEnabled;
if (idx.column() > 0) { /*if (idx.column() > 0) {
//Make sure the cell is disabled if the row is //Make sure the cell is disabled if the row is
Qt::ItemFlags f = d_ptr->m_lExtensions[idx.column()-1]->flags(item->collection,idx); Qt::ItemFlags f = d_ptr->m_lExtensions[idx.column()-1]->flags(item->collection,idx);
return (((f&Qt::ItemIsEnabled)&&(!item->collection->isEnabled()))?f^Qt::ItemIsEnabled:f); return (((f&Qt::ItemIsEnabled)&&(!item->collection->isEnabled()))?f^Qt::ItemIsEnabled:f);
} }*/
const bool checkable = item->collection->supportedFeatures() & (CollectionInterface::SupportedFeatures::ENABLEABLE | const bool checkable = item->collection->supportedFeatures() & (CollectionInterface::SupportedFeatures::ENABLEABLE |
CollectionInterface::SupportedFeatures::DISABLEABLE | CollectionInterface::SupportedFeatures::MANAGEABLE ); CollectionInterface::SupportedFeatures::DISABLEABLE | CollectionInterface::SupportedFeatures::MANAGEABLE );
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | (checkable?Qt::ItemIsUserCheckable:Qt::NoItemFlags); return Qt::ItemIsEnabled | Qt::ItemIsSelectable | (checkable?Qt::ItemIsUserCheckable:Qt::NoItemFlags);
...@@ -187,10 +187,10 @@ bool CollectionModel::setData (const QModelIndex& idx, const QVariant &value, in ...@@ -187,10 +187,10 @@ bool CollectionModel::setData (const QModelIndex& idx, const QVariant &value, in
Q_UNUSED(idx) Q_UNUSED(idx)
Q_UNUSED(value) Q_UNUSED(value)
Q_UNUSED(role) Q_UNUSED(role)
if (idx.isValid() && idx.column() > 0) { /*if (idx.isValid() && idx.column() > 0) {
CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer()); CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer());
return (!item->collection)?false : d_ptr->m_lExtensions[idx.column()-1]->setData(item->collection,idx,value,role); return (!item->collection)?false : d_ptr->m_lExtensions[idx.column()-1]->setData(item->collection,idx,value,role);
} }*/
if (role == Qt::CheckStateRole && idx.column() == 0) { if (role == Qt::CheckStateRole && idx.column() == 0) {
CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer()); CollectionModelPrivate::ProxyItem* item = static_cast<CollectionModelPrivate::ProxyItem*>(idx.internalPointer());
...@@ -254,8 +254,8 @@ QVariant CollectionModel::headerData(int section, Qt::Orientation orientation, i ...@@ -254,8 +254,8 @@ QVariant CollectionModel::headerData(int section, Qt::Orientation orientation, i
{ {
Q_UNUSED(section) Q_UNUSED(section)
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (section > 0) /*if (section > 0)
return d_ptr->m_lExtensions[section-1]->headerName(); return d_ptr->m_lExtensions[section-1]->headerName();*/
return QVariant(tr("Name")); return QVariant(tr("Name"));
} }
return QVariant(); return QVariant();
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
#include "contactmethod.h" #include "contactmethod.h"
#include "person.h" #include "person.h"
#include "presencestatusmodel.h" #include "presencestatusmodel.h"
#include "collectionextensionmodel.h"
DECLARE_COLLECTION_EXTENSION(PresenceCollectionExtension)
PresenceCollectionExtension::PresenceCollectionExtension(QObject* parent) : PresenceCollectionExtension::PresenceCollectionExtension(QObject* parent) :
CollectionExtensionInterface(parent) CollectionExtensionInterface(parent)
...@@ -27,54 +30,13 @@ PresenceCollectionExtension::PresenceCollectionExtension(QObject* parent) : ...@@ -27,54 +30,13 @@ PresenceCollectionExtension::PresenceCollectionExtension(QObject* parent) :
} }
QVariant PresenceCollectionExtension::data(CollectionInterface* backend, const QModelIndex& index, int role ) const QVariant PresenceCollectionExtension::data(int role) const
{
if ((!backend) || (!index.isValid()))
return QVariant();
switch (role) {
case Qt::CheckStateRole:
return PresenceStatusModel::instance()->isAutoTracked(backend)?Qt::Checked:Qt::Unchecked;
};
return QVariant();
}
Qt::ItemFlags PresenceCollectionExtension::flags(CollectionInterface* backend, const QModelIndex& index ) const
{ {
Q_UNUSED(backend) Q_UNUSED(role)
Q_UNUSED(index)
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
bool PresenceCollectionExtension::setData(CollectionInterface* backend, const QModelIndex& index, const QVariant &value, int role ) if (role == Qt::DisplayRole) {
{ return QObject::tr("Presence tracking");
Q_UNUSED(backend)
if (index.isValid() && role == Qt::CheckStateRole) {
switch(value.toInt()){
case Qt::Checked:
foreach(Person* c, backend->items<Person>()) {
foreach(ContactMethod* n,c->phoneNumbers()) {
n->setTracked(true);
}
}
PresenceStatusModel::instance()->setAutoTracked(backend,true);
emit dataChanged(index);
break;
case Qt::Unchecked:
foreach(Person* c, backend->items<Person>()) {
foreach(ContactMethod* n,c->phoneNumbers()) {
n->setTracked(false);
}
}
PresenceStatusModel::instance()->setAutoTracked(backend,false);
emit dataChanged(index);
break;
};
return true;
} }
return false;
}
QString PresenceCollectionExtension::headerName() const return QVariant();
{
return tr("Track presence");
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define PRESENCEITEMBACKENDMODELEXTENSION_H #define PRESENCEITEMBACKENDMODELEXTENSION_H
#include <collectionextensioninterface.h> #include <collectionextensioninterface.h>
#include <collectionextensionmodel.h>
#include <typedefs.h> #include <typedefs.h>
...@@ -34,10 +35,7 @@ class LIB_EXPORT PresenceCollectionExtension : public CollectionExtensionInterfa ...@@ -34,10 +35,7 @@ class LIB_EXPORT PresenceCollectionExtension : public CollectionExtensionInterfa
public: public:
explicit PresenceCollectionExtension(QObject* parent); explicit PresenceCollectionExtension(QObject* parent);
virtual QVariant data (CollectionInterface* backend, const QModelIndex& index, int role = Qt::DisplayRole ) const override; virtual QVariant data(int role) const override;
virtual Qt::ItemFlags flags (CollectionInterface* backend, const QModelIndex& index ) const override;
virtual bool setData (CollectionInterface* backend, const QModelIndex& index, const QVariant &value, int role ) override;
virtual QString headerName() const override;
}; };
#endif #endif
/****************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "securityevaluationextension.h"
#include "collectioninterface.h"
#include "contactmethod.h"
#include "person.h"
#include "presencestatusmodel.h"
#include "collectionextensionmodel.h"
DECLARE_COLLECTION_EXTENSION(SecurityEvaluationExtension)
SecurityEvaluationExtension::SecurityEvaluationExtension(QObject* parent) :
CollectionExtensionInterface(parent)
{
}
QVariant SecurityEvaluationExtension::data(int role) const
{
Q_UNUSED(role)
if (role == Qt::DisplayRole) {
return QObject::tr("Security evaluation");
}
return QVariant();
}
\ No newline at end of file
/****************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
* *
* 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 General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef PRESENCECOLLECTIONEXTENSION_H
#define PRESENCECOLLECTIONEXTENSION_H
#include <collectionextensioninterface.h>
#include <collectionextensionmodel.h>
#include <typedefs.h>
#include <QtCore/QVariant>
#include <QtCore/QModelIndex>
class CollectionInterface;
class LIB_EXPORT SecurityEvaluationExtension : public CollectionExtensionInterface
{
Q_OBJECT
public:
explicit SecurityEvaluationExtension(QObject* parent);
virtual QVariant data(int role) const override;
};
#endif
...@@ -35,6 +35,13 @@ public: ...@@ -35,6 +35,13 @@ public:
explicit ItemBase(T* parent = nullptr); explicit ItemBase(T* parent = nullptr);
virtual CollectionInterface* collection() const final; virtual CollectionInterface* collection() const final;
//Extension system
template<typename T2>
bool hasExtenstion() const;
template<typename T2>
T2* extenstion() const;
//Mutator methods //Mutator methods
bool save () const; bool save () const;
bool edit () ; bool edit () ;
......
...@@ -83,3 +83,17 @@ bool ItemBase<Base>::isActive() const ...@@ -83,3 +83,17 @@ bool ItemBase<Base>::isActive() const
{ {
return d_ptr->m_pBackend->isEnabled() && d_ptr->m_isActive; return d_ptr->m_pBackend->isEnabled() && d_ptr->m_isActive;
} }
template<typename Base>
template<typename T2>
bool ItemBase<Base>::hasExtenstion() const
{
return d_ptr->m_pBackend->isExtensionActive<T2>();
}
template<typename Base>
template<typename T2>
T2* ItemBase<Base>::extenstion() const
{
return d_ptr->m_pBackend->extension<T2>();
}
...@@ -130,11 +130,24 @@ private: ...@@ -130,11 +130,24 @@ private:
int m_Flags; int m_Flags;
}; };
#define DO_PRAGMA(x) _Pragma (#x)
//Globally disable the "-Wunused-function" warning for GCC
//refs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
#if ((__GNUC_MINOR__ > 8) || (__GNUC_MINOR__ == 8))
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
#define DECLARE_ENUM_FLAGS(T)\ #define DECLARE_ENUM_FLAGS(T)\
DO_PRAGMA(GCC diagnostic push)\
DO_PRAGMA(GCC diagnostic ignored "-Wunused-function")\
static FlagPack<T> operator|(const T& first, const T& second) { \ static FlagPack<T> operator|(const T& first, const T& second) { \
FlagPack<T> p (first); \ FlagPack<T> p (first); \
return p | second; \ return p | second; \
} } \
DO_PRAGMA(GCC diagnostic pop)
#endif //TYPEDEFS_H #endif //TYPEDEFS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment