edscontactbackend.h 4.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 *  Copyright (C) 2015 Savoir-Faire Linux Inc.
 *  Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

#ifndef EDSCONTACTBACKEND_H
#define EDSCONTACTBACKEND_H

/**
 * QT_NO_KEYWORDS is needed to resolve the conflict between the symbols used
 * in this C library (ie: signals) and Qt keywords
 */
#define QT_NO_KEYWORDS
#include <libebook/libebook.h>
#undef QT_NO_KEYWORDS

#include <collectioninterface.h>
#include <memory>

class Person;

template<typename T> class CollectionMediator;

void load_eds_sources(GCancellable *cancellable);

class EdsContactBackend : public CollectionInterface
{
public:
54
55
56
57
58
59
60
61
62
    /* load 300 contacts every 10ms; this is fast enough to load
     * 1M contacts in about 30s, but can be increased if need be
     */
    /* this sets how many contacts will be added at a time */
    constexpr static int CONTACT_ADD_LIMIT {300};
    /* this sets the interval in miliseconds to wait before adding
     * more contacts */
    constexpr static int CONTACT_ADD_INTERVAL {10};

63
64
65
66
67
68
69
70
71
#if EDS_CHECK_VERSION(3,16,0)
    /* The wait_for_connected_seconds argument had been added since 3.16, to let
     * the caller decide how long to wait for the backend to fully connect to
     * its (possibly remote) data store. This is required due to a change in the
     * authentication process, which is fully asynchronous and done on the
     * client side, while not every client is supposed to response to
     * authentication requests. In case the backend will not connect within the
     * set interval, then it is opened in an offline mode. A special value -1
     * can be used to not wait for the connected state at all.
72
     */
73
74
75
    constexpr static guint32 WAIT_FOR_CONNECTED_SECONDS {5};
#endif

76
77
78
79
80
81
82
83
84
85
    explicit EdsContactBackend(CollectionMediator<Person>* mediator, EClient *client, CollectionInterface* parent = nullptr);
    virtual ~EdsContactBackend();

    virtual bool load() override;
    virtual bool reload() override;
    virtual bool clear() override;
    virtual QString    name     () const override;
    virtual QString    category () const override;
    virtual bool       isEnabled() const override;
    virtual QByteArray id       () const override;
86
    virtual FlagPack<SupportedFeatures>  supportedFeatures() const override;
87

88
89
90
    void addContacts(GSList *contacts);
    void parseContact(EContact *contact);
    void lastContactAdded();
91
92
93
94
95
96
97
98

private:
   CollectionMediator<Person>*  mediator_;
   std::unique_ptr<EClient, decltype(g_object_unref)&> client_;
   std::unique_ptr<GCancellable, decltype(g_object_unref)&> cancellable_;

   static void free_contact_list(GSList *list) { g_slist_free_full(list, g_object_unref); };
   std::unique_ptr<GSList, decltype(free_contact_list)&> contacts_;
99
100

   guint add_contacts_source_id {0};
101
102
103
};

#endif /* EDSCONTACTBACKEND_H */