blob: f53e62625a5e54266c4f12609e60f5e6fbec2643 [file] [log] [blame]
Stepan Salenikovich6f687072015-03-26 10:43:37 -04001/*
2 * Copyright (C) 2015 Savoir-Faire Linux Inc.
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.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
24 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
30
31#ifndef EDSCONTACTBACKEND_H
32#define EDSCONTACTBACKEND_H
33
34/**
35 * QT_NO_KEYWORDS is needed to resolve the conflict between the symbols used
36 * in this C library (ie: signals) and Qt keywords
37 */
38#define QT_NO_KEYWORDS
39#include <libebook/libebook.h>
40#undef QT_NO_KEYWORDS
41
42#include <collectioninterface.h>
43#include <memory>
44
45class Person;
46
47template<typename T> class CollectionMediator;
48
49void load_eds_sources(GCancellable *cancellable);
50
51class EdsContactBackend : public CollectionInterface
52{
53public:
Stepan Salenikovichdc7178b2015-04-13 17:38:46 -040054 /* load 300 contacts every 10ms; this is fast enough to load
55 * 1M contacts in about 30s, but can be increased if need be
56 */
57 /* this sets how many contacts will be added at a time */
58 constexpr static int CONTACT_ADD_LIMIT {300};
59 /* this sets the interval in miliseconds to wait before adding
60 * more contacts */
61 constexpr static int CONTACT_ADD_INTERVAL {10};
62
Stepan Salenikovichb53e9c02015-04-14 17:41:10 -040063#if EDS_CHECK_VERSION(3,16,0)
64 /* The wait_for_connected_seconds argument had been added since 3.16, to let
65 * the caller decide how long to wait for the backend to fully connect to
66 * its (possibly remote) data store. This is required due to a change in the
67 * authentication process, which is fully asynchronous and done on the
68 * client side, while not every client is supposed to response to
69 * authentication requests. In case the backend will not connect within the
70 * set interval, then it is opened in an offline mode. A special value -1
71 * can be used to not wait for the connected state at all.
Edric Milaret66c50a32015-05-06 10:38:42 -040072 */
Stepan Salenikovichb53e9c02015-04-14 17:41:10 -040073 constexpr static guint32 WAIT_FOR_CONNECTED_SECONDS {5};
74#endif
75
Stepan Salenikovich6f687072015-03-26 10:43:37 -040076 explicit EdsContactBackend(CollectionMediator<Person>* mediator, EClient *client, CollectionInterface* parent = nullptr);
77 virtual ~EdsContactBackend();
78
79 virtual bool load() override;
80 virtual bool reload() override;
81 virtual bool clear() override;
82 virtual QString name () const override;
83 virtual QString category () const override;
84 virtual bool isEnabled() const override;
85 virtual QByteArray id () const override;
Stepan Salenikovich4e409932015-04-24 12:12:39 -040086 virtual FlagPack<SupportedFeatures> supportedFeatures() const override;
Stepan Salenikovich6f687072015-03-26 10:43:37 -040087
Stepan Salenikovich8e882cd2015-05-28 14:18:06 -040088 void addClientView(std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view);
89 void addContacts(std::unique_ptr<GSList, void(*)(GSList *)> contacts);
Stepan Salenikovich21366ed2015-06-26 17:11:45 -040090 void removeContacts(std::unique_ptr<GSList, void(*)(GSList *)> contacts);
Stepan Salenikovichdc7178b2015-04-13 17:38:46 -040091 void parseContact(EContact *contact);
92 void lastContactAdded();
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040093 bool addNewPerson(Person *item);
Stepan Salenikovich0cf247d2015-07-24 17:36:32 -040094 bool savePerson(const Person *item);
Stepan Salenikovich6f687072015-03-26 10:43:37 -040095
96private:
97 CollectionMediator<Person>* mediator_;
98 std::unique_ptr<EClient, decltype(g_object_unref)&> client_;
99 std::unique_ptr<GCancellable, decltype(g_object_unref)&> cancellable_;
Stepan Salenikovich8e882cd2015-05-28 14:18:06 -0400100 std::unique_ptr<EBookClientView, void(*)(EBookClientView *)> client_view_;
Stepan Salenikovichdc7178b2015-04-13 17:38:46 -0400101
102 guint add_contacts_source_id {0};
Stepan Salenikovichf4149272015-07-16 16:12:19 -0400103
104 QString name_;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400105};
106
Stepan Salenikovich8e882cd2015-05-28 14:18:06 -0400107#endif /* EDSCONTACTBACKEND_H */