diff --git a/CMakeLists.txt b/CMakeLists.txt index d4a5ca50364ad7b30134031c6b66d93a18019e7b..0654f84ab754c777308ad2697d75f992432a25c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,7 +215,7 @@ SET( libringclient_LIB_SRCS src/audio/settings.cpp - #Data backends + #Data collections src/transitionalpersonbackend.cpp src/collectioninterface.cpp src/collectioneditor.cpp diff --git a/src/backendmanagerinterface.hpp b/src/backendmanagerinterface.hpp index 5bf70ba7200eb7c20c32972d48846b5cc9cca5f5..7818eb7ee98b2e4e64b476352a8c53981703527b 100644 --- a/src/backendmanagerinterface.hpp +++ b/src/backendmanagerinterface.hpp @@ -57,7 +57,7 @@ CollectionInterface* BackendManagerInterface<T>::addBackend(const LoadOptions op if (options & LoadOptions::FORCE_ENABLED) { //TODO check is the backend is checked - //Some backends can fail to load directly + //Some collections can fail to load directly //eventually it will necessary to add an async version of this //to load the backend only when it is loaded if (backend->load()) @@ -74,32 +74,32 @@ BackendManagerInterface<T>::BackendManagerInterface() : d_ptr(new BackendManager } template<class T> -const QVector< CollectionInterface* > BackendManagerInterface<T>::backends() const +const QVector< CollectionInterface* > BackendManagerInterface<T>::collections() const { return d_ptr->m_lBackends; } template<class T> -const QVector< CollectionInterface* > BackendManagerInterface<T>::enabledBackends() const +const QVector< CollectionInterface* > BackendManagerInterface<T>::enabledCollections() const { return d_ptr->m_lEnabledBackends; } -/// Do this manager have active backends +/// Do this manager have active collections template<class T> -bool BackendManagerInterface<T>::hasEnabledBackends() const +bool BackendManagerInterface<T>::hasEnabledCollections() const { return d_ptr->m_lEnabledBackends.size(); } template<class T> -bool BackendManagerInterface<T>::hasBackends() const +bool BackendManagerInterface<T>::hasCollections() const { return d_ptr->m_lBackends.size(); } template<class T> -bool BackendManagerInterface<T>::clearAllBackends() const +bool BackendManagerInterface<T>::clearAllCollections() const { return false; } diff --git a/src/bookmarkmodel.cpp b/src/bookmarkmodel.cpp index 4c63b0a153bc69b3c15fc7df56d1b25c3018bd29..e0f45f4c9263d34c8026a6f51d936fb0a139cd27 100644 --- a/src/bookmarkmodel.cpp +++ b/src/bookmarkmodel.cpp @@ -465,7 +465,7 @@ bool BookmarkModelPrivate::displayFrequentlyUsed() const QVector<ContactMethod*> BookmarkModelPrivate::bookmarkList() const { - return (q_ptr->backends().size() > 0) ? q_ptr->backends()[0]->items<ContactMethod>() : QVector<ContactMethod*>(); + return (q_ptr->collections().size() > 0) ? q_ptr->collections()[0]->items<ContactMethod>() : QVector<ContactMethod*>(); } BookmarkTopLevelItem::BookmarkTopLevelItem(QString name) @@ -499,8 +499,8 @@ bool BookmarkModel::removeRows( int row, int count, const QModelIndex & parent) void BookmarkModel::addBookmark(ContactMethod* number) { Q_UNUSED(number) - if (backends().size()) - backends()[0]->editor<ContactMethod>()->append(number); + if (collections().size()) + collections()[0]->editor<ContactMethod>()->addNew(number); else qWarning() << "No bookmark backend is set"; } @@ -539,12 +539,12 @@ void BookmarkModelPrivate::slotIndexChanged(const QModelIndex& idx) } -// bool BookmarkModel::hasBackends() const +// bool BookmarkModel::hasCollections() const // { // return d_ptr->m_lBackends.size(); // } -// bool BookmarkModel::hasEnabledBackends() const +// bool BookmarkModel::hasEnabledCollections() const // { // foreach(CollectionInterface* b, d_ptr->m_lBackends) { // if (b->isEnabled()) @@ -553,26 +553,26 @@ void BookmarkModelPrivate::slotIndexChanged(const QModelIndex& idx) // return false; // } -// const QVector<CollectionInterface*> BookmarkModel::backends() const +// const QVector<CollectionInterface*> BookmarkModel::collections() const // { // return d_ptr->m_lBackends; // } -bool BookmarkModel::addItemCallback(ContactMethod* item) +bool BookmarkModel::addItemCallback(const ContactMethod* item) { Q_UNUSED(item) reloadCategories(); //TODO this is far from optimal return true; } -bool BookmarkModel::removeItemCallback(ContactMethod* item) +bool BookmarkModel::removeItemCallback(const ContactMethod* item) { Q_UNUSED(item) return false; } -// const QVector<CollectionInterface*> BookmarkModel::enabledBackends() const +// const QVector<CollectionInterface*> BookmarkModel::enabledCollections() const // { // return d_ptr->m_lBackends; //TODO filter them // } @@ -582,9 +582,9 @@ bool BookmarkModel::removeItemCallback(ContactMethod* item) // return nullptr; //TODO // } -bool BookmarkModel::clearAllBackends() const +bool BookmarkModel::clearAllCollections() const { - foreach (CollectionInterface* backend, backends()) { + foreach (CollectionInterface* backend, collections()) { if (backend->supportedFeatures() & CollectionInterface::ADD) { backend->clear(); } @@ -607,7 +607,7 @@ bool BookmarkModel::clearAllBackends() const // backend->load(); // } -void BookmarkModel::backendAddedCallback(CollectionInterface* backend) +void BookmarkModel::collectionAddedCallback(CollectionInterface* backend) { Q_UNUSED(backend) } diff --git a/src/bookmarkmodel.h b/src/bookmarkmodel.h index be9165c3b6172ed2568cbc694d55c4b5011e621c..83067a300b6a28da30eefb10745efd1ea662d105 100644 --- a/src/bookmarkmodel.h +++ b/src/bookmarkmodel.h @@ -53,7 +53,7 @@ public: void setShowAll(bool showAll); //Backend model implementation - virtual bool clearAllBackends() const override; + virtual bool clearAllCollections() const override; //Model implementation virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; @@ -88,9 +88,9 @@ private: Q_DECLARE_PRIVATE(BookmarkModel) //Backend interface - virtual void backendAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback(ContactMethod* item) override; - virtual bool removeItemCallback(ContactMethod* item) override; + virtual void collectionAddedCallback(CollectionInterface* backend) override; + virtual bool addItemCallback(const ContactMethod* item) override; + virtual bool removeItemCallback(const ContactMethod* item) override; public Q_SLOTS: void reloadCategories(); diff --git a/src/call.cpp b/src/call.cpp index 6ab460dcfa66ee7093839f4257d6058bea5bdb3c..3234bf80451830a2caf593482d27a582abf0fa05 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -1263,7 +1263,7 @@ void CallPrivate::call() //Warning: m_pDialNumber can become nullptr when linking directly callManager.placeCall(m_Account->id(), m_CallId, m_pDialNumber->uri()); - if (PersonModel::instance()->hasBackends()) { + if (PersonModel::instance()->hasCollections()) { if (q_ptr->peerContactMethod()->contact()) m_PeerName = q_ptr->peerContactMethod()->contact()->formattedName(); } diff --git a/src/callmodel.cpp b/src/callmodel.cpp index dfea2898c9ff59a3a0688de0d32f31f967b5fbf2..4b55d17d9428ea6fa9c11b758750397ad801de4d 100644 --- a/src/callmodel.cpp +++ b/src/callmodel.cpp @@ -1015,7 +1015,8 @@ void CallModelPrivate::slotCallStateChanged(const QString& callID, const QString //Add to history if (call->lifeCycleState() == Call::LifeCycleState::FINISHED) { - HistoryModel::instance()->add(call); + //HistoryModel::instance()->add(call); + //FIXME check all collection with a "::ADD" filter and add the call } emit q_ptr->callStateChanged(call,previousState); diff --git a/src/collectioneditor.h b/src/collectioneditor.h index 776c8c58b6c621f49b02af5b7c13c6596c5355d2..b60b03bcabc7776be421bc19a14d0b764041c5ab 100644 --- a/src/collectioneditor.h +++ b/src/collectioneditor.h @@ -57,18 +57,17 @@ public: CollectionMediator<T>* mediator() const; virtual bool save(const T* item) =0; - virtual bool append(const T* item) =0; virtual bool batchSave(const QList<T*> contacts); - virtual bool remove(T* item); + virtual bool remove(const T* item); ///Edit 'item', the implementation may be a GUI or something else virtual bool edit ( T* item ) = 0; ///Add a new item to the backend - virtual bool addNew ( T* item ) = 0; + virtual bool addNew (const T* item ) = 0; ///Add an existing item to the collection - virtual bool addExisting( T* item ) = 0; + virtual bool addExisting(const T* item ) = 0; ///Add a new phone number to an existing item virtual bool addContactMethod( T* item , ContactMethod* number ); diff --git a/src/collectioneditor.hpp b/src/collectioneditor.hpp index 64907230169dd92cda412c7ce6ae25841447b24c..d6caaf7fc42f56d68e21c100fe65e449649c3fdd 100644 --- a/src/collectioneditor.hpp +++ b/src/collectioneditor.hpp @@ -46,7 +46,7 @@ QMetaObject metaObject() return T::staticMetaObject(); } -///Default batch saving implementation, some backends have better APIs +///Default batch saving implementation, some collections have better APIs template <class T> bool CollectionEditor<T>::batchSave(const QList<T*> contacts) { bool ret = true; @@ -65,7 +65,7 @@ bool CollectionEditor<T>::addContactMethod( T* item , ContactMethod* numbe } template <class T> -bool CollectionEditor<T>::remove(T* item) +bool CollectionEditor<T>::remove(const T* item) { Q_UNUSED(item) return false; diff --git a/src/collectioninterface.h b/src/collectioninterface.h index 849ce03195981e775d88b31632da1a3eb6991a28..3b70a3e536164fa3c893192d6146bf3a9eccca96 100644 --- a/src/collectioninterface.h +++ b/src/collectioninterface.h @@ -34,7 +34,7 @@ template<typename T> class CollectionMediator; template<typename T> class ItemBase; /** - * This is the interface that must be implemented by each item backends to + * This is the interface that must be implemented by each item collections to * be used by a CollectionManager. * * The class need to be extended with a template constructor: @@ -42,7 +42,7 @@ template<typename T> class ItemBase; * MyBackend::MyBackend<Person>(CollectionMediator<Person>* mediator, CollectionInterface* parent = nullptr) : * CollectionMediator<Person>(mediator,parent) {} * - * Each backends also need to implement that constructor or they wont load. + * Each collections also need to implement that constructor or they wont load. */ class LIB_EXPORT CollectionInterface { @@ -61,13 +61,13 @@ public: LOAD = 0x1 << 0, /*!< Load this backend, DO NOT load anything before "load" is called */ SAVE = 0x1 << 1, /*!< Save an item */ EDIT = 0x1 << 2, /*!< Edit, but **DOT NOT**, save an item) */ - PROBE = 0x1 << 3, /*!< Check if the backend has new items (some backends do this automagically)*/ + PROBE = 0x1 << 3, /*!< Check if the backend has new items (some collections do this automagically)*/ ADD = 0x1 << 4, /*!< Add (and save) a new item to the backend */ SAVE_ALL = 0x1 << 5, /*!< Save all items at once, this may or may not be faster than "add" */ CLEAR = 0x1 << 6, /*!< Clear all items from this backend */ REMOVE = 0x1 << 7, /*!< Remove a single item */ - EXPORT = 0x1 << 8, /*!< Export all items, format and output need to be defined by each backends */ - IMPORT = 0x1 << 9, /*!< Import items from an external source, details defined by each backends */ + EXPORT = 0x1 << 8, /*!< Export all items, format and output need to be defined by each collections */ + IMPORT = 0x1 << 9, /*!< Import items from an external source, details defined by each collections */ ENABLEABLE = 0x1 << 10, /*!< Can be enabled, I know, it is not a word, but Java use it too */ DISABLEABLE = 0x1 << 11, /*!< Can be disabled, I know, it is not a word, but Java use it too */ MANAGEABLE = 0x1 << 12, /*!< Can be managed the config GUI */ @@ -88,7 +88,7 @@ public: virtual QString name () const = 0; /** - * Each MANAGEABLE backends can be part of a meta category. This category + * Each MANAGEABLE collections can be part of a meta category. This category * will be the top level element of the BackendManagerModel. This name * must never change once it is set. */ @@ -172,7 +172,7 @@ public: QVector<T*> items() const; /** - * Some backends can be hierarchical, for example, a email backend + * Some collections can be hierarchical, for example, a email backend * can have multiple "folders" where mails are stored, a contact backend * can have multiple contact groups and an history one can have an archived * section for previous years. This method return the parent when applicable. @@ -181,7 +181,7 @@ public: /** * As explained in the "parent()" method, this method return the backend children - * backends. This can be used by a client to implement different behaviour depending + * collections. This can be used by a client to implement different behaviour depending * on the backend at a finer level. */ QVector<CollectionInterface*> children() const; diff --git a/src/collectionmanagerinterface.h b/src/collectionmanagerinterface.h index 572a354b7e0724ce42cdb2a077c56e78d1120e10..626ed06437ad53f5d43bbab42c4a87c09e2a9797 100644 --- a/src/collectionmanagerinterface.h +++ b/src/collectionmanagerinterface.h @@ -43,27 +43,27 @@ template <class T> class CollectionManagerInterfacePrivate; /** - * This is the base for all models based on the itembackend framework. + * This is the base for all models based on the itemcollection framework. * * This interface has to be implemented by each models. The abstract - * private methods will be called when the managed backends need + * private methods will be called when the managed collections need * to interact with the model. * - * All implementation should define their item backend type in the + * All implementation should define their item collection type in the * class declaration like: * * template <typename T > using CollectionMediator = CollectionMediator<Person>; * - * And individual backends should extend that alias. For example: + * And individual collections should extend that alias. For example: * * class MyPersonSourceBackend : public CollectionInterface { * public: * MyPersonSourceBackend(CollectionInterfaceMediator* mediator) * }; * - * The mediator is used to bridge the model and the item backends. The mediator + * The mediator is used to bridge the model and the item collections. The mediator * implement the common logic that should otherwise have been copy pasted in each - * backends. + * collections. */ template <class T> class LIB_EXPORT CollectionManagerInterface { friend class CollectionMediator<T>; @@ -81,50 +81,50 @@ public: virtual ~CollectionManagerInterface() {}; /** - * This method is used to add a backend to a model. The LoadOptions + * This method is used to add a collection to a model. The LoadOptions * can be used to enforce some parameters. Please note this function is - * a variadic template. If the backend require some arguments to be passed + * a variadic template. If the collection require some arguments to be passed * to its constructor, they can be added as extra parameters. * - * Please note that each backend need to take a CollectionMediator as first + * Please note that each collection need to take a CollectionMediator as first * argument. * - * @return The newly created backend + * @return The newly created collection */ template <class T2, typename ...Ts> T2* addBackend(Ts... args, const LoadOptions options = LoadOptions::NONE); - /// Do this manager have active backends - virtual bool hasEnabledBackends () const final; - virtual bool hasBackends () const final; + /// Do this manager have active collections + virtual bool hasEnabledCollections () const final; + virtual bool hasCollections () const final; - /// List all backends - virtual const QVector< CollectionInterface* > backends () const final; - virtual const QVector< CollectionInterface* > enabledBackends() const final; + /// List all Collections + virtual const QVector< CollectionInterface* > collections () const final; + virtual const QVector< CollectionInterface* > enabledCollections() const final; - ///Enable / disable a backend - virtual bool enableBackend( CollectionInterface* backend, bool enabled) final; + ///Enable / disable a collection + virtual bool enableBackend( CollectionInterface* collection, bool enabled) final; - virtual bool clearAllBackends() const; + virtual bool clearAllCollections() const; /** - * Delete the item from the model and from its backend. This + * Delete the item from the model and from its collection. This * is permanent and cannot be undone. * * Please note that certain type of items, while removed from the view * will continue to exist after being removed. This include items part - * of multiple backends or items generated from runtime data. + * of multiple Collections or items generated from runtime data. * - * @return true if successful, false is the backend doesn't support removing items or the operation failed. + * @return true if successful, false is the collection doesn't support removing items or the operation failed. */ bool deleteItem(T* item); private: /** - * This method is called when a new backend is added. Some models + * This method is called when a new collection is added. Some models * may need to act on such action, other don't. */ - virtual void backendAddedCallback(CollectionInterface* backend); + virtual void collectionAddedCallback(CollectionInterface* collection); /** * This method implement the logic necessary to add the item to @@ -132,8 +132,11 @@ private: * * This method can be called with items already part of the model. * All implementation must handle that. + * + * Please note that the constness is expected to be broken when using + * setData(), but not otherwise. */ - virtual bool addItemCallback (T* item) = 0; + virtual bool addItemCallback (const T* item) = 0; /** * Remove an item from the model. Subclasses must implement the logic @@ -142,7 +145,7 @@ private: * This function can be called with nullptr or with items not part * of the model. All implementations must handle that. */ - virtual bool removeItemCallback(T* item) = 0; + virtual bool removeItemCallback(const T* item) = 0; CollectionManagerInterfacePrivate<T>* d_ptr; }; diff --git a/src/collectionmanagerinterface.hpp b/src/collectionmanagerinterface.hpp index 9f77c5d8fad62e9bb8ea8c4a6cbab1e35019a079..397677682477c78f188657f200334c10dc1bf398 100644 --- a/src/collectionmanagerinterface.hpp +++ b/src/collectionmanagerinterface.hpp @@ -26,8 +26,8 @@ public: {} ~CollectionManagerInterfacePrivate(); - QVector< CollectionInterface* > m_lBackends; - QVector< CollectionInterface* > m_lEnabledBackends; + QVector< CollectionInterface* > m_lCollections; + QVector< CollectionInterface* > m_lEnabledCollections; mutable CollectionMediator<T>* m_pMediator; QAbstractItemModel* q_ptr; CollectionManagerInterface<T>* i_ptr; @@ -55,22 +55,22 @@ template<class T> template <class T2, typename ...Ts> T2* CollectionManagerInterface<T>::addBackend(Ts... args, const LoadOptions options) { - T2* backend = new T2(d_ptr->itemMediator(),args...); + T2* collection = new T2(d_ptr->itemMediator(),args...); //This will force the T2 to be a CollectionInterface subclass - CollectionInterface* b = backend; - d_ptr->m_lBackends << b; + CollectionInterface* b = collection; + d_ptr->m_lCollections << b; - if (options & LoadOptions::FORCE_ENABLED) { //TODO check is the backend is checked + if (options & LoadOptions::FORCE_ENABLED) { //TODO check is the collection is checked - //Some backends can fail to load directly + //Some collections can fail to load directly //eventually it will necessary to add an async version of this - //to load the backend only when it is loaded - if (backend->load()) - d_ptr->m_lEnabledBackends << backend; + //to load the collection only when it is loaded + if (collection->load()) + d_ptr->m_lEnabledCollections << collection; } - return backend; + return collection; } template<class T> @@ -80,52 +80,52 @@ CollectionManagerInterface<T>::CollectionManagerInterface(QAbstractItemModel* se } template<class T> -const QVector< CollectionInterface* > CollectionManagerInterface<T>::backends() const +const QVector< CollectionInterface* > CollectionManagerInterface<T>::collections() const { - return d_ptr->m_lBackends; + return d_ptr->m_lCollections; } template<class T> -const QVector< CollectionInterface* > CollectionManagerInterface<T>::enabledBackends() const +const QVector< CollectionInterface* > CollectionManagerInterface<T>::enabledCollections() const { - return d_ptr->m_lEnabledBackends; + return d_ptr->m_lEnabledCollections; } -/// Do this manager have active backends +/// Do this manager have active collections template<class T> -bool CollectionManagerInterface<T>::hasEnabledBackends() const +bool CollectionManagerInterface<T>::hasEnabledCollections() const { - return d_ptr->m_lEnabledBackends.size(); + return d_ptr->m_lEnabledCollections.size(); } template<class T> -bool CollectionManagerInterface<T>::hasBackends() const +bool CollectionManagerInterface<T>::hasCollections() const { - return d_ptr->m_lBackends.size(); + return d_ptr->m_lCollections.size(); } template<class T> -bool CollectionManagerInterface<T>::clearAllBackends() const +bool CollectionManagerInterface<T>::clearAllCollections() const { return false; } template<class T> -void CollectionManagerInterface<T>::backendAddedCallback(CollectionInterface* backend) +void CollectionManagerInterface<T>::collectionAddedCallback(CollectionInterface* collection) { - Q_UNUSED(backend) + Q_UNUSED(collection) } template<class T> bool CollectionManagerInterface<T>::deleteItem(T* item) { - if (item->backend()->model() == (QAbstractItemModel*) this) { - if (item->backend()->supportedFeatures() & CollectionInterface::SupportedFeatures::REMOVE) { - static_cast<CollectionInterface*>(item->backend())->editor<T>()->remove(item); + if (item->collection()->model() == (QAbstractItemModel*) this) { + if (item->collection()->supportedFeatures() & CollectionInterface::SupportedFeatures::REMOVE) { + static_cast<CollectionInterface*>(item->collection())->editor<T>()->remove(item); return true; } else - qDebug() << item << "cannot be deleted, the backend doesn't support removing items"; + qDebug() << item << "cannot be deleted, the collection doesn't support removing items"; } else qDebug() << item << "cannot be deleted, it is not managed by" << this; @@ -133,9 +133,9 @@ bool CollectionManagerInterface<T>::deleteItem(T* item) } template<class T> -bool CollectionManagerInterface<T>::enableBackend( CollectionInterface* backend, bool enabled) +bool CollectionManagerInterface<T>::enableBackend( CollectionInterface* collection, bool enabled) { Q_UNUSED(enabled) //TODO implement it - backend->load(); + collection->load(); return true; } diff --git a/src/collectionmediator.h b/src/collectionmediator.h index bbb3cf7beb196f72eacbe661d62236d7aad70684..ad1c61ea35d9165ff120c8eb9fdba0e3b02a52ec 100644 --- a/src/collectionmediator.h +++ b/src/collectionmediator.h @@ -29,7 +29,7 @@ class CollectionMediatorPrivate; /** * This is the base class for each BackendMediator. A backend mediator * is a intermediary object between the backend and the model responsible - * to manage the backends objects. The purpose of this layer are: + * to manage the collections objects. The purpose of this layer are: * * * Isolate the item gestion away from the manager public API * * Work around the lack of polymorphic generics for template objects @@ -40,8 +40,8 @@ template<typename T> class LIB_EXPORT CollectionMediator { public: CollectionMediator(CollectionManagerInterface<T>* parentManager, QAbstractItemModel* m); - bool addItem (T* item); - bool removeItem(T* item); + bool addItem (const T* item); + bool removeItem(const T* item); QAbstractItemModel* model() const; diff --git a/src/collectionmediator.hpp b/src/collectionmediator.hpp index f97732a97b6b0b5fd73930e16a43786c0ec01ba8..56806cd810e4b47353c1e533805e25c6b825755d 100644 --- a/src/collectionmediator.hpp +++ b/src/collectionmediator.hpp @@ -35,13 +35,13 @@ CollectionMediator<T>::CollectionMediator(CollectionManagerInterface<T>* parentM } template<typename T> -bool CollectionMediator<T>::addItem(T* item) +bool CollectionMediator<T>::addItem(const T* item) { return d_ptr->m_pParent->addItemCallback(item); } template<typename T> -bool CollectionMediator<T>::removeItem(T* item) +bool CollectionMediator<T>::removeItem(const T* item) { return d_ptr->m_pParent->removeItemCallback(item); //TODO wrong } diff --git a/src/collectionmodel.cpp b/src/collectionmodel.cpp index 31da2772b6b8fe035b11c3825a50ad971ffc58ac..535b3af2c21db966c79ac454c55fd55feaac7334 100644 --- a/src/collectionmodel.cpp +++ b/src/collectionmodel.cpp @@ -121,11 +121,11 @@ QVariant CollectionModel::data (const QModelIndex& idx, int role) const int CollectionModel::rowCount (const QModelIndex& parent) const { if (!parent.isValid()) { - static bool init = false; //FIXME this doesn't allow dynamic backends + static bool init = false; //FIXME this doesn't allow dynamic collections static int result = 0; if (!init) { - for(int i=0;i<PersonModel::instance()->backends().size();i++) - result += PersonModel::instance()->backends()[i]->parent()==nullptr?1:0; + for(int i=0;i<PersonModel::instance()->collections().size();i++) + result += PersonModel::instance()->collections()[i]->parent()==nullptr?1:0; init = true; } return result; @@ -216,11 +216,11 @@ QModelIndex CollectionModel::index( int row, int column, const QModelIndex& pare item = d_ptr->m_lTopLevelBackends[row]; else { - if (row >= PersonModel::instance()->backends().size()) + if (row >= PersonModel::instance()->collections().size()) return QModelIndex(); item = new CollectionModelPrivate::ProxyItem(); - item->backend = PersonModel::instance()->backends()[row]; + item->backend = PersonModel::instance()->collections()[row]; d_ptr->m_lTopLevelBackends << item; } item->row = row; @@ -249,7 +249,7 @@ bool CollectionModel::save() { if (ItemModelStateSerializationDelegate::instance()) { - //Load newly enabled backends + //Load newly enabled collections foreach(CollectionModelPrivate::ProxyItem* top, d_ptr->m_lTopLevelBackends) { CollectionInterface* current = top->backend; bool check = ItemModelStateSerializationDelegate::instance()->isChecked(current); diff --git a/src/delegates/pixmapmanipulationdelegate.cpp b/src/delegates/pixmapmanipulationdelegate.cpp index d94aa9e255a3756bb4f8cf0c301c45a78ddbaeda..1578825f30a3250f10cdc4f4cdbf1da8e65accc7 100644 --- a/src/delegates/pixmapmanipulationdelegate.cpp +++ b/src/delegates/pixmapmanipulationdelegate.cpp @@ -80,6 +80,7 @@ QByteArray PixmapManipulationDelegate::toByteArray(const QVariant& pxm) QVariant PixmapManipulationDelegate::profilePhoto(const QByteArray& data, const QString& type) { Q_UNUSED(data) + Q_UNUSED(type) return QVariant(); } diff --git a/src/fallbackpersoncollection.cpp b/src/fallbackpersoncollection.cpp index 55fe7b3d0fdc308b899fdb07dbefa6bab29007d6..bff3e538a10083c653fff49f26d5494b83a99c0f 100644 --- a/src/fallbackpersoncollection.cpp +++ b/src/fallbackpersoncollection.cpp @@ -38,11 +38,10 @@ class FallbackPersonBackendEditor : public CollectionEditor<Person> public: FallbackPersonBackendEditor(CollectionMediator<Person>* m) : CollectionEditor<Person>(m) {} virtual bool save ( const Person* item ) override; - virtual bool append ( const Person* item ) override; - virtual bool remove ( Person* item ) override; + virtual bool remove ( const Person* item ) override; virtual bool edit ( Person* item ) override; - virtual bool addNew ( Person* item ) override; - virtual bool addExisting( Person* item ) override; + virtual bool addNew ( const Person* item ) override; + virtual bool addExisting( const Person* item ) override; QVector<Person*> m_lItems; @@ -81,13 +80,7 @@ bool FallbackPersonBackendEditor::save(const Person* item) return true; } -bool FallbackPersonBackendEditor::append(const Person* item) -{ - Q_UNUSED(item) - return false; -} - -bool FallbackPersonBackendEditor::remove(Person* item) +bool FallbackPersonBackendEditor::remove(const Person* item) { Q_UNUSED(item) return false; @@ -99,17 +92,15 @@ bool FallbackPersonBackendEditor::edit( Person* item) return false; } -bool FallbackPersonBackendEditor::addNew( Person* item) +bool FallbackPersonBackendEditor::addNew(const Person* item) { Q_UNUSED(item) return false; } -bool FallbackPersonBackendEditor::addExisting( Person* item) +bool FallbackPersonBackendEditor::addExisting(const Person* item) { - Q_UNUSED(item) - - m_lItems << item; + m_lItems << const_cast<Person*>(item); mediator()->addItem(item); return true; } diff --git a/src/historymodel.cpp b/src/historymodel.cpp index c305d01f86f078794af76eb76ab8b62ebc62beb2..da0bb0d82c95317eee5696cf49f177c637f3b5ba 100644 --- a/src/historymodel.cpp +++ b/src/historymodel.cpp @@ -71,7 +71,6 @@ public: //Attributes static CallMap m_sHistoryCalls; - QVector<CollectionInterface*> m_lBackends; //Model categories QVector<HistoryTopLevelItem*> m_lCategoryCounter ; @@ -84,6 +83,7 @@ private: HistoryModel* q_ptr; public Q_SLOTS: + void add(Call* call); void reloadCategories(); void slotChanged(const QModelIndex& idx); }; @@ -295,7 +295,7 @@ const CallMap HistoryModel::getHistoryCalls() const } ///Add to history -void HistoryModel::add(Call* call) +void HistoryModelPrivate::add(Call* call) { if (!call || call->lifeCycleState() != Call::LifeCycleState::FINISHED || !call->startTimeStamp()) { return; @@ -306,33 +306,33 @@ void HistoryModel::add(Call* call) // m_HavePersonModel = true; // }//TODO implement reordering - emit newHistoryCall(call); - emit layoutAboutToBeChanged(); - HistoryTopLevelItem* tl = d_ptr->getCategory(call); - const QModelIndex& parentIdx = index(tl->modelRow,0); - beginInsertRows(parentIdx,tl->m_lChildren.size(),tl->m_lChildren.size()); + emit q_ptr->newHistoryCall(call); + emit q_ptr->layoutAboutToBeChanged(); + HistoryTopLevelItem* tl = getCategory(call); + const QModelIndex& parentIdx = q_ptr->index(tl->modelRow,0); + q_ptr->beginInsertRows(parentIdx,tl->m_lChildren.size(),tl->m_lChildren.size()); HistoryModelPrivate::HistoryItem* item = new HistoryModelPrivate::HistoryItem(call); item->m_pParent = tl; - item->m_pNode = new HistoryItemNode(this,call,item); - connect(item->m_pNode,SIGNAL(changed(QModelIndex)),d_ptr.data(),SLOT(slotChanged(QModelIndex))); + item->m_pNode = new HistoryItemNode(q_ptr,call,item); + connect(item->m_pNode,SIGNAL(changed(QModelIndex)),this,SLOT(slotChanged(QModelIndex))); item->m_Index = tl->m_lChildren.size(); tl->m_lChildren << item; //Try to prevent startTimeStamp() collisions, it technically doesn't work as time_t are signed //we don't care - d_ptr->m_sHistoryCalls[(call->startTimeStamp() << 10)+qrand()%1024] = call; - endInsertRows(); - emit layoutChanged(); + m_sHistoryCalls[(call->startTimeStamp() << 10)+qrand()%1024] = call; + q_ptr->endInsertRows(); + emit q_ptr->layoutChanged(); LastUsedNumberModel::instance()->addCall(call); - emit historyChanged(); + emit q_ptr->historyChanged(); // Loop until it find a compatible backend //HACK only support a single active history backend - if (!call->backend()) { - foreach (CollectionInterface* backend, d_ptr->m_lBackends) { + if (!call->collection()) { + foreach (CollectionInterface* backend, q_ptr->collections()) { if (backend->supportedFeatures() & CollectionInterface::ADD) { - if (backend->editor<Call>()->append(call)) { - call->setBackend(backend); + if (backend->editor<Call>()->addNew(call)) { + call->setCollection(backend); break; } } @@ -598,40 +598,15 @@ bool HistoryModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, in return false; } - -// bool HistoryModel::hasBackends() const -// { -// return d_ptr->m_lBackends.size(); -// } - -// bool HistoryModel::hasEnabledBackends() const -// { -// return d_ptr->m_lBackends.size(); -// } - -// void HistoryModel::addBackend(CollectionInterface* backend, LoadOptions options) -// { -// d_ptr->m_lBackends << backend; -// connect(backend,SIGNAL(newHistoryCallAdded(Call*)),this,SLOT(add(Call*))); -// if (options & LoadOptions::FORCE_ENABLED || ItemModelStateSerializationDelegate::instance()->isChecked(backend)) -// backend->load(); -// emit newBackendAdded(backend); -// } - -// QString HistoryModel::backendCategoryName() const -// { -// return tr("History"); -// } - -void HistoryModel::backendAddedCallback(CollectionInterface* backend) +void HistoryModel::collectionAddedCallback(CollectionInterface* backend) { Q_UNUSED(backend) } -///Call all backends that support clearing -bool HistoryModel::clearAllBackends() const +///Call all collections that support clearing +bool HistoryModel::clearAllCollections() const { - foreach (CollectionInterface* backend, d_ptr->m_lBackends) { + foreach (CollectionInterface* backend, collections()) { if (backend->supportedFeatures() & CollectionInterface::ADD) { backend->clear(); } @@ -644,41 +619,18 @@ bool HistoryModel::clearAllBackends() const return true; } - -// bool HistoryModel::enableBackend(CollectionInterface* backend, bool enabled) -// { -// Q_UNUSED(backend) -// Q_UNUSED(enabled) -// return false;//TODO -// } - -// CommonCollectionModel* HistoryModel::backendModel() const -// { -// return nullptr; //TODO -// } - -// const QVector<CollectionInterface*> HistoryModel::backends() const -// { -// return d_ptr->m_lBackends; -// } - -bool HistoryModel::addItemCallback(Call* item) +bool HistoryModel::addItemCallback(const Call* item) { - add(item); + d_ptr->add(const_cast<Call*>(item)); return true; } -bool HistoryModel::removeItemCallback(Call* item) +bool HistoryModel::removeItemCallback(const Call* item) { Q_UNUSED(item) return false; } -// const QVector<CollectionInterface*> HistoryModel::enabledBackends() const -// { -// return d_ptr->m_lBackends; -// } - ///Return valid payload types int HistoryModel::acceptedPayloadTypes() const { diff --git a/src/historymodel.h b/src/historymodel.h index af0e034057750c77f0a39c93cdd97a242cfba94a..b7475493346aa5b3d994c251a7d691aaf0de1c78 100644 --- a/src/historymodel.h +++ b/src/historymodel.h @@ -48,7 +48,7 @@ public: friend class HistoryTopLevelItem; //Properties - Q_PROPERTY(bool hasBackends READ hasBackends ) + Q_PROPERTY(bool hasCollections READ hasCollections ) //Singleton static HistoryModel* instance(); @@ -60,7 +60,7 @@ public: const CallMap getHistoryCalls () const; //Backend model implementation - virtual bool clearAllBackends () const override; + virtual bool clearAllCollections() const override; //Setters void setCategoryRole(Call::Role role); @@ -94,19 +94,15 @@ private: static HistoryModel* m_spInstance; //Backend interface - virtual void backendAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback(Call* item) override; - virtual bool removeItemCallback(Call* item) override; - -public Q_SLOTS: - void add(Call* call); + virtual void collectionAddedCallback(CollectionInterface* collection) override; + virtual bool addItemCallback(const Call* item) override; + virtual bool removeItemCallback(const Call* item) override; Q_SIGNALS: ///Emitted when the history change (new items, cleared) void historyChanged ( ); ///Emitted when a new item is added to prevent full reload void newHistoryCall ( Call* call ); - void newBackendAdded(AbstractHistoryBackend* backend); }; #endif diff --git a/src/itembase.h b/src/itembase.h index da876e060c0194c955f8019526648954bf2ded36..808c2b8a1aa95fe7a2f772d9dba3e7fc7da4410b 100644 --- a/src/itembase.h +++ b/src/itembase.h @@ -33,7 +33,7 @@ class LIB_EXPORT ItemBase : public T { public: //Constructor explicit ItemBase(T* parent = nullptr); - virtual CollectionInterface* backend() final; + virtual CollectionInterface* collection() const final; //Mutator methods bool save() const; @@ -41,7 +41,7 @@ public: bool remove() ; //Setter - void setBackend(CollectionInterface* backend); + void setCollection(CollectionInterface* backend); protected: private: diff --git a/src/itembase.hpp b/src/itembase.hpp index 1db529ac517c7b562eeade88ff19a8e431529c35..ff7c946d506604a39bd6a550a3af3337214598fd 100644 --- a/src/itembase.hpp +++ b/src/itembase.hpp @@ -33,13 +33,13 @@ ItemBase<Base>::ItemBase(Base* parent) :Base(parent), d_ptr(new ItemBasePrivate( } template<typename Base> -CollectionInterface* ItemBase<Base>::backend() +CollectionInterface* ItemBase<Base>::collection() const { return d_ptr->m_pBackend; } template<typename Base> -void ItemBase<Base>::setBackend(CollectionInterface* backend) +void ItemBase<Base>::setCollection(CollectionInterface* backend) { d_ptr->m_pBackend = backend; } diff --git a/src/person.cpp b/src/person.cpp index 5bb4d83d501a6495251e9e96157e9ec3d8bb5709..c05e5f8b47acb9a54fd94b0b9af016a41dd61420 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -229,7 +229,7 @@ Person* Person::ContactMethods::contact() const Person::Person(CollectionInterface* parent): ItemBase<QObject>(nullptr), d_ptr(new PersonPrivate(this)) { - setBackend(parent?parent:TransitionalPersonBackend::instance()); + setCollection(parent?parent:TransitionalPersonBackend::instance()); d_ptr->m_isPlaceHolder = false; d_ptr->m_lParents << this; } diff --git a/src/personmodel.cpp b/src/personmodel.cpp index 009ba075cc1302e02c6a90e026446768c9baa219..d50002a2d35c8c365122b6ee12333a7baaf80f8f 100644 --- a/src/personmodel.cpp +++ b/src/personmodel.cpp @@ -45,7 +45,6 @@ public: //Attributes // QVector<CollectionInterface*> m_lBackends; - CommonCollectionModel* m_pBackendModel; QHash<QByteArray,PersonPlaceHolder*> m_hPlaceholders; //Indexes @@ -60,8 +59,7 @@ private Q_SLOTS: // void slotPersonAdded(Person* c); }; -PersonModelPrivate::PersonModelPrivate(PersonModel* parent) : QObject(parent), q_ptr(parent), -m_pBackendModel(nullptr) +PersonModelPrivate::PersonModelPrivate(PersonModel* parent) : QObject(parent), q_ptr(parent) { } @@ -239,7 +237,7 @@ Person* PersonModel::getPlaceHolder(const QByteArray& uid ) return ct2; } -///Return if there is backends +///Return if there is collections // bool PersonModel::hasBackends() const // { // return d_ptr->m_lBackends.size(); @@ -269,22 +267,22 @@ Person* PersonModel::getPlaceHolder(const QByteArray& uid ) // return tr("Persons"); // } -void PersonModel::backendAddedCallback(CollectionInterface* backend) +void PersonModel::collectionAddedCallback(CollectionInterface* backend) { Q_UNUSED(backend) } -// const QVector<CollectionInterface*> PersonModel::backends() const +// const QVector<CollectionInterface*> PersonModel::collections() const // { // return d_ptr->m_lBackends; // } -bool PersonModel::addItemCallback(Person* c) +bool PersonModel::addItemCallback(const Person* c) { //Add to the model beginInsertRows(QModelIndex(),d_ptr->m_lPersons.size(),d_ptr->m_lPersons.size()); - d_ptr->m_lPersons << c; - d_ptr->m_hPersonsByUid[c->uid()] = c; + d_ptr->m_lPersons << const_cast<Person*>(c); + d_ptr->m_hPersonsByUid[c->uid()] = const_cast<Person*>(c); endInsertRows(); emit newPersonAdded(c); @@ -292,14 +290,14 @@ bool PersonModel::addItemCallback(Person* c) if (d_ptr->m_hPlaceholders.contains(c->uid())) { PersonPlaceHolder* c2 = d_ptr->m_hPlaceholders[c->uid()]; if (c2) { - c2->merge(c); + c2->merge(const_cast<Person*>(c)); d_ptr->m_hPlaceholders[c->uid()] = nullptr; } } return true; } -bool PersonModel::removeItemCallback(Person* item) +bool PersonModel::removeItemCallback(const Person* item) { Q_UNUSED(item) return false; @@ -317,8 +315,8 @@ bool PersonModel::addPerson(Person* c) { if (!c) return false; - if (backends().size()) //TODO this is wrong, it work for now because profilemodel is [0] - backends()[0]->add(c); + if (collections().size()) //TODO this is wrong, it work for now because profilemodel is [0] + collections()[0]->add(c); return true; } @@ -346,10 +344,10 @@ const PersonList PersonModel::contacts() const bool PersonModel::addNewPerson(Person* c, CollectionInterface* backend) { - if ((!backend) || (!backends().size())) + if ((!backend) || (!collections().size())) return false; - return (backend?backend:backends()[0])->editor<Person>()->addNew(c); + return (backend?backend:collections()[0])->editor<Person>()->addNew(c); } diff --git a/src/personmodel.h b/src/personmodel.h index 1888b91c3de2533380f0f889e5e246ae9291b167..361629cb2976ac9650aafb749120fab026514c81 100644 --- a/src/personmodel.h +++ b/src/personmodel.h @@ -95,16 +95,16 @@ private: static PersonModel* m_spInstance; //Backend interface - virtual void backendAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback(Person* item) override; - virtual bool removeItemCallback(Person* item) override; + virtual void collectionAddedCallback(CollectionInterface* backend) override; + virtual bool addItemCallback(const Person* item) override; + virtual bool removeItemCallback(const Person* item) override; public Q_SLOTS: bool addNewPerson(Person* c, CollectionInterface* backend = nullptr); Q_SIGNALS: void reloaded(); - void newPersonAdded(Person* c); + void newPersonAdded(const Person* c); void newBackendAdded(CollectionInterface* backend); }; diff --git a/src/profilemodel.cpp b/src/profilemodel.cpp index 40f68ccbd62b59e6cbfc97faa5a605fef4cc04de..458ba649d1b99ad84a960390d08edd8fa8cc5d36 100644 --- a/src/profilemodel.cpp +++ b/src/profilemodel.cpp @@ -51,11 +51,10 @@ public: ProfileEditor(CollectionMediator<Person>* m) : CollectionEditor<Person>(m) {}; ~ProfileEditor(); virtual bool save ( const Person* item ) override; - virtual bool append ( const Person* item ) override; - virtual bool remove ( Person* item ) override; - virtual bool edit ( Person* item ) override; - virtual bool addNew ( Person* item ) override; - virtual bool addExisting( Person* item ) override; + virtual bool remove ( const Person* item ) override; + virtual bool edit ( Person* item ) override; + virtual bool addNew ( const Person* item ) override; + virtual bool addExisting( const Person* item ) override; Node* getProfileById(const QByteArray& id); QList<Account*> getAccountsForProfile(const QString& id); @@ -144,13 +143,7 @@ ProfileEditor::~ProfileEditor() } } -bool ProfileEditor::append(const Person* item) -{ - Q_UNUSED(item) - return false; -} - -bool ProfileEditor::remove(Person* item) +bool ProfileEditor::remove(const Person* item) { Q_UNUSED(item) mediator()->removeItem(item); @@ -163,19 +156,19 @@ bool ProfileEditor::edit( Person* contact) return false; } -bool ProfileEditor::addNew( Person* contact) +bool ProfileEditor::addNew(const Person* contact) { qDebug() << "Creating new profile" << contact->uid(); - m_lProfilePersons << contact; + m_lProfilePersons << const_cast<Person*>(contact); mediator()->addItem(contact); save(contact); // load(); //FIXME return true; } -bool ProfileEditor::addExisting( Person* contact) +bool ProfileEditor::addExisting(const Person* contact) { - m_lProfilePersons << contact; + m_lProfilePersons << const_cast<Person*>(contact); mediator()->addItem(contact); return true; } diff --git a/src/transitionalpersonbackend.cpp b/src/transitionalpersonbackend.cpp index 95b933e530220407352b23f7b80989957f66aca3..1fe73981b42c6cbe96975cd3a8f186cfba29766e 100644 --- a/src/transitionalpersonbackend.cpp +++ b/src/transitionalpersonbackend.cpp @@ -30,11 +30,10 @@ class TransitionalPersonEditor : public CollectionEditor<Person> public: TransitionalPersonEditor(CollectionMediator<Person>* m) : CollectionEditor<Person>(m) {} virtual bool save ( const Person* item ) override; - virtual bool append ( const Person* item ) override; - virtual bool remove ( Person* item ) override; + virtual bool remove ( const Person* item ) override; virtual bool edit ( Person* item ) override; - virtual bool addNew ( Person* item ) override; - virtual bool addExisting( Person* item ) override; + virtual bool addNew ( const Person* item ) override; + virtual bool addExisting( const Person* item ) override; private: virtual QVector<Person*> items() const override; @@ -46,13 +45,7 @@ bool TransitionalPersonEditor::save(const Person* item) return false; } -bool TransitionalPersonEditor::append(const Person* item) -{ - Q_UNUSED(item) - return false; -} - -bool TransitionalPersonEditor::remove(Person* item) +bool TransitionalPersonEditor::remove(const Person* item) { Q_UNUSED(item) return false; @@ -64,13 +57,13 @@ bool TransitionalPersonEditor::edit( Person* item) return false; } -bool TransitionalPersonEditor::addNew( Person* item) +bool TransitionalPersonEditor::addNew(const Person* item) { Q_UNUSED(item) return false; } -bool TransitionalPersonEditor::addExisting( Person* item) +bool TransitionalPersonEditor::addExisting(const Person* item) { Q_UNUSED(item) return false;