Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 3 | * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef EDSCONTACTBACKEND_H |
| 21 | #define EDSCONTACTBACKEND_H |
| 22 | |
| 23 | /** |
| 24 | * QT_NO_KEYWORDS is needed to resolve the conflict between the symbols used |
| 25 | * in this C library (ie: signals) and Qt keywords |
| 26 | */ |
| 27 | #define QT_NO_KEYWORDS |
| 28 | #include <libebook/libebook.h> |
| 29 | #undef QT_NO_KEYWORDS |
| 30 | |
| 31 | #include <collectioninterface.h> |
| 32 | #include <memory> |
| 33 | |
| 34 | class Person; |
| 35 | |
| 36 | template<typename T> class CollectionMediator; |
| 37 | |
| 38 | void load_eds_sources(GCancellable *cancellable); |
| 39 | |
| 40 | class EdsContactBackend : public CollectionInterface |
| 41 | { |
| 42 | public: |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 43 | /* load 300 contacts every 10ms; this is fast enough to load |
| 44 | * 1M contacts in about 30s, but can be increased if need be |
| 45 | */ |
| 46 | /* this sets how many contacts will be added at a time */ |
| 47 | constexpr static int CONTACT_ADD_LIMIT {300}; |
| 48 | /* this sets the interval in miliseconds to wait before adding |
| 49 | * more contacts */ |
| 50 | constexpr static int CONTACT_ADD_INTERVAL {10}; |
| 51 | |
Stepan Salenikovich | b53e9c0 | 2015-04-14 17:41:10 -0400 | [diff] [blame] | 52 | #if EDS_CHECK_VERSION(3,16,0) |
| 53 | /* The wait_for_connected_seconds argument had been added since 3.16, to let |
| 54 | * the caller decide how long to wait for the backend to fully connect to |
| 55 | * its (possibly remote) data store. This is required due to a change in the |
| 56 | * authentication process, which is fully asynchronous and done on the |
| 57 | * client side, while not every client is supposed to response to |
| 58 | * authentication requests. In case the backend will not connect within the |
| 59 | * set interval, then it is opened in an offline mode. A special value -1 |
| 60 | * can be used to not wait for the connected state at all. |
Edric Milaret | 66c50a3 | 2015-05-06 10:38:42 -0400 | [diff] [blame] | 61 | */ |
Stepan Salenikovich | b53e9c0 | 2015-04-14 17:41:10 -0400 | [diff] [blame] | 62 | constexpr static guint32 WAIT_FOR_CONNECTED_SECONDS {5}; |
| 63 | #endif |
| 64 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 65 | explicit EdsContactBackend(CollectionMediator<Person>* mediator, EClient *client, CollectionInterface* parent = nullptr); |
| 66 | virtual ~EdsContactBackend(); |
| 67 | |
| 68 | virtual bool load() override; |
| 69 | virtual bool reload() override; |
| 70 | virtual bool clear() override; |
| 71 | virtual QString name () const override; |
| 72 | virtual QString category () const override; |
| 73 | virtual bool isEnabled() const override; |
| 74 | virtual QByteArray id () const override; |
Stepan Salenikovich | 4e40993 | 2015-04-24 12:12:39 -0400 | [diff] [blame] | 75 | virtual FlagPack<SupportedFeatures> supportedFeatures() const override; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 76 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 77 | void addClientView(std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view); |
| 78 | void addContacts(std::unique_ptr<GSList, void(*)(GSList *)> contacts); |
Stepan Salenikovich | 21366ed | 2015-06-26 17:11:45 -0400 | [diff] [blame] | 79 | void removeContacts(std::unique_ptr<GSList, void(*)(GSList *)> contacts); |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 80 | void parseContact(EContact *contact); |
| 81 | void lastContactAdded(); |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame] | 82 | bool addNewPerson(Person *item); |
aviau | ff72795 | 2016-01-29 16:23:07 -0500 | [diff] [blame] | 83 | bool removePerson(const Person *item); |
Stepan Salenikovich | 0cf247d | 2015-07-24 17:36:32 -0400 | [diff] [blame] | 84 | bool savePerson(const Person *item); |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | CollectionMediator<Person>* mediator_; |
| 88 | std::unique_ptr<EClient, decltype(g_object_unref)&> client_; |
| 89 | std::unique_ptr<GCancellable, decltype(g_object_unref)&> cancellable_; |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 90 | std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view_; |
Stepan Salenikovich | dc7178b | 2015-04-13 17:38:46 -0400 | [diff] [blame] | 91 | |
| 92 | guint add_contacts_source_id {0}; |
Stepan Salenikovich | f414927 | 2015-07-16 16:12:19 -0400 | [diff] [blame] | 93 | |
| 94 | QString name_; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 95 | }; |
| 96 | |
Stepan Salenikovich | 8e882cd | 2015-05-28 14:18:06 -0400 | [diff] [blame] | 97 | #endif /* EDSCONTACTBACKEND_H */ |